Local Ephemeral Ports Usage And Distribution / Inet_csk_get_port()

Home » CentOS » Local Ephemeral Ports Usage And Distribution / Inet_csk_get_port()
CentOS No Comments

Hello

I’m using CentOS Linux release 7.3.1611 (Core) with kernel 3.10.0-514.16.1.el7.x86_64

Using iperf for bond benchmarking, and opening several sockets, I noticed a strange behavior.

My CentOS using iperf as a client to connect to an iperf server (running either CentOS or Debian) requesting N parallel TCP connections.

I notice that the local ephemeral ports used are not consecutive and are always even ports numbers. This can change to “only odd ports numbers” depending on the setting net.ipv4.ip_local_port_range, but basically, the idea is the CentOS
kernel does “+2” when finding a local port for socket, not doing +1.

Doing a netstat, generally speaking, only even (or odd) local ports are used so this does not seem application dependent. It’s possible, however, to request both odd and even local ports, when requesting to bind them explicitly and not letting kernel function
“inet_csk_get_port” determining it. To compare to another distro, Debian 7 3.2.78-1 x86_64 does increment local port number by +1 when opening sockets, using both even and odd local sockets numbers.

This has an influence when doing network interfaces bonding with LACP
801.3ad with layer3+4 hashing policy, because the trafic to one remote host/service will improperly be balanced over bonded interfaces with CentOS.

Is there any known kernel patch or reason to explain this behavior ?

thanks for any hints. best regards

FdeS

LEAVE A COMMENT