Skip to contentSkip to conversation

client socket and source port selection

DISCUSSION joël Winteregg 3 participants 3 messages Nov 27, 2004 – Nov 29, 2004

lore
Share & tools
lore
#0 lore raw

HI,

For the project i'm doing, i must know how the Linux kernel allocate sockets source port (from the dynamic range of the (2**16)-1 ports). I looked on the Web but it's really hard to find the algoritm of the source port allocation...

Someone maybe know how it's work or if there is a paper on the web that explain this source port selection ?

Thanks a lot for your help !

Joël.W

#1 lore raw
Quoted 9 lines

HI,

For the project i'm doing, i must know how the Linux kernel allocate sockets source port (from the dynamic range of the (2**16)-1 ports). I looked on the Web but it's really hard to find the algoritm of the source port allocation...

Someone maybe know how it's work or if there is a paper on the web that explain this source port selection ?

I think it starts at 1024 when it boots, and increments whenever a socket is created.

Jan Engelhardt

Signature · 2 lines
Gesellschaft für Wissenschaftliche Datenverarbeitung
Am Fassberg, 37077 Göttingen, www.gwdg.de
#2 lore raw
In reply to joël Winteregg

Hello,

Quoted 4 lines

For the project i'm doing, i must know how the Linux kernel allocate sockets source port (from the dynamic range of the (2**16)-1 ports). I looked on the Web but it's really hard to find the algoritm of the source port allocation...

Check the source ;). There is a proc-fs entry which relates to the source port range setting. Over this entry point you get in case of TCP sockets to ../net/ipv4/tcp_ipv4.c:tcp_v4_get_port(...). For UDP sockets you need to peek into ../net/ipv4/udp.c:udp_v4_get_port().

Quoted 2 lines

Someone maybe know how it's work or if there is a paper on the web that explain this source port selection ?

Not likely, but reading the source should help. You can set the local port range via /proc/sys/net/ipv4/ip_local_port_range. It's documented.

HTH and best regards,
Roberto Nibali, ratz

Signature · 1 line
echo '[q]sa[ln0=aln256%Pln256/snlbx]sb3135071790101768542287578439snlbxq' | dc