I wrote:
> I have a strange situtation. My application tries to connect to port
> 1202 on the same host every 3.75 to 5.00 seconds.
>
> Every once in a while, the connect succeeds, but to itself!
>
> Is this normal!?
Investigation reveals the following:
Richard Stevens, in "Unix Network Programming" Vol1 2nd Ed. pp 42-43
states that ephemeral (local) ports are assigned the range 1024-5000
for BSD derived systems, and 32768-65535 in Solaris.
Linux picks local port numbers in the range 1024-4999. This can be
changed with sysctl, or writing a new range to
/proc/sys/net/ipv4/ip_local_port_range. See also tcp_ipv4.c around
line 114.
At the end is a tcpdump of my application showing the last moments
before the local port 1202 is chosen that results in the connection to
itself. Notice local ports going from 1199 to 1202 (I changed the
connect retry interval to 1 second).
If you know the last local port assigned, you can recreate this using
telnet to the next anticipated local port, ala 'telnet localhost
port'.
For example, run 'tcpdump -i lo' in one window, and 'telnet localhost'
in another. Quit from telnet, and reissue 'telnet localhost port'
where port is the next anticipated local port number. Voila, a
connection.
You can recreate this without tcpdump, by using 'netstat -a' to query
connections. The behaviour is the same on a Solaris 5.5.1 machine.
Is this desired behaviour? I think it's pretty useless for an
application to find it's connected to itself. Yet it can only avoid
this if it knows the local port range chosen by the OS. In the mean
time, I've assigned my local port range to 32768-61000.
I suppose I should just avoid both ranges documented by Stevens for
the location of my server.
Your comments?
regards,
Drago
TCPDUMP of the final moments before my application unintentionally
connects with itself.
12:45:03.069812 10.17.209.126.1199 > 10.17.209.126.1202: S 153996580:153996580(0) win
31072 <mss 3884,sackOK,timestamp 147849312 0,nop,wscale 0> (DF)
12:45:03.069812 10.17.209.126.1199 > 10.17.209.126.1202: S 153996580:153996580(0) win
31072 <mss 3884,sackOK,timestamp 147849312 0,nop,wscale 0> (DF)
12:45:03.069864 10.17.209.126.1202 > 10.17.209.126.1199: R 0:0(0) ack 153996581 win 0
12:45:03.069864 10.17.209.126.1202 > 10.17.209.126.1199: R 0:0(0) ack 1 win 0
12:45:04.069818 10.17.209.126.1200 > 10.17.209.126.1202: S 143495092:143495092(0) win
31072 <mss 3884,sackOK,timestamp 147849412 0,nop,wscale 0> (DF)
12:45:04.069818 10.17.209.126.1200 > 10.17.209.126.1202: S 143495092:143495092(0) win
31072 <mss 3884,sackOK,timestamp 147849412 0,nop,wscale 0> (DF)
12:45:04.069870 10.17.209.126.1202 > 10.17.209.126.1200: R 0:0(0) ack 143495093 win 0
12:45:04.069870 10.17.209.126.1202 > 10.17.209.126.1200: R 0:0(0) ack 1 win 0
12:45:05.069836 10.17.209.126.1201 > 10.17.209.126.1202: S 154964149:154964149(0) win
31072 <mss 3884,sackOK,timestamp 147849512 0,nop,wscale 0> (DF)
12:45:05.069836 10.17.209.126.1201 > 10.17.209.126.1202: S 154964149:154964149(0) win
31072 <mss 3884,sackOK,timestamp 147849512 0,nop,wscale 0> (DF)
12:45:05.069890 10.17.209.126.1202 > 10.17.209.126.1201: R 0:0(0) ack 154964150 win 0
12:45:05.069890 10.17.209.126.1202 > 10.17.209.126.1201: R 0:0(0) ack 1 win 0
12:45:06.069834 10.17.209.126.1202 > 10.17.209.126.1202: S 155091037:155091037(0) win
31072 <mss 3884,sackOK,timestamp 147849612 0,nop,wscale 0> (DF)
12:45:06.069834 10.17.209.126.1202 > 10.17.209.126.1202: S 155091037:155091037(0) win
31072 <mss 3884,sackOK,timestamp 147849612 0,nop,wscale 0> (DF)
12:45:06.069885 10.17.209.126.1202 > 10.17.209.126.1202: S 155091037:155091037(0) ack
155091038 win 31072 <mss 3884,sackOK,timestamp 147849612 147849612,nop,wscale 0> (DF)
12:45:06.069885 10.17.209.126.1202 > 10.17.209.126.1202: S 155091037:155091037(0) ack
155091038 win 31072 <mss 3884,sackOK,timestamp 147849612 147849612,nop,wscale 0> (DF)
12:45:06.069906 10.17.209.126.1202 > 10.17.209.126.1202: . ack 1 win 31072
<nop,nop,timestamp 147849612 147849612> (DF)
12:45:06.069906 10.17.209.126.1202 > 10.17.209.126.1202: . ack 1 win 31072
<nop,nop,timestamp 147849612 147849612> (DF)
12:45:06.070275 10.17.209.126.1202 > 10.17.209.126.1202: P 1:8(7) ack 1 win 31072
<nop,nop,timestamp 147849612 147849612> (DF)
12:45:06.070275 10.17.209.126.1202 > 10.17.209.126.1202: P 1:8(7) ack 1 win 31072
<nop,nop,timestamp 147849612 147849612> (DF)
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to [EMAIL PROTECTED]