time_wait, do not mess with tcp_tw_recycle and net.ipv4.tcp_tw_reuse

Reprinted link: https://vincent.bernat.im/en/blog/2014-tcp-time-wait-state-linux#fn-rfc1337

After the server time_wait full, the same port the client why can normally be requested:

        When a connection is closed actively, it MUST linger in
            TIME-WAIT state for a time 2xMSL (Maximum Segment Lifetime).
            However, it MAY accept a new SYN from the remote TCP to
            reopen the connection directly from TIME-WAIT state, if it:

            (1)  assigns its initial sequence number for the new
                 connection to be larger than the largest sequence
                 number it used on the previous connection incarnation,
                 and

            (2)  returns to TIME-WAIT state if the SYN turns out to be
                 an old duplicate.

https://superuser.com/questions/1179009/ephemeral-port-collision

https://tools.ietf.org/html/rfc1122

Another isn generation rules:

When new connections are created,
  an initial sequence number (ISN) generator is employed which selects a
  new 32 bit ISN.  The generator is bound to a (possibly fictitious) 32
  bit clock whose low order bit is incremented roughly every 4
  microseconds.  Thus, the ISN cycles approximately every 4.55 hours.
  Since we assume that segments will stay in the network no more than
  the Maximum Segment Lifetime (MSL) and that the MSL is less than 4.55
  hours we can reasonably assume that ISN's will be unique.
https://tools.ietf.org/html/rfc793


Other blog: http://blog.csdn.net/justlinux2010/article/details/8725479

If a RST packet, then the system configuration and sysctl_tcp_rfc1337 (default is 0, see, / proc / sys / net / ipv4 / tcp_rfc1337) is 0, then immediately release time_wait transmission control block discard RST packets received.
  If the packet is an ACK, the timer will start TIME_WAIT discarded ACK packets received.
  Next is the handling of SYN packets. Mentioned earlier, if the receiver in the TIME_WAIT state to a sequence number than the sequence number of the connection end of the SYN packet, acceptable, and establish a new connection, the following code is to handle this situation:

[cpp]  view plain  copy
  1. if (th->syn && !th->rst && !th->ack && !paws_reject &&  
  2.     (after(TCP_SKB_CB(skb)->seq, tcptw->tw_rcv_nxt) ||  
  3.      (tmp_opt.saw_tstamp &&  
  4.       (s32)(tcptw->tw_ts_recent - tmp_opt.rcv_tsval) < 0))) {  
  5.     u32 isn = tcptw->tw_snd_nxt + 65535 + 2;  
  6.     if (isn == 0)  
  7.         isn++;  
  8.     TCP_SKB_CB(skb)->when = isn;  
  9.     return TCP_TW_SYN;  
  10. }  

verification:

By raw socket, foldback syn packet,

Tested:

1.server time_wait, assuming that the last received ack: x,

2.client, same ip and port, a syn packet, if isn less than x, then sends the ack: x, and will not be ack + syn, it will not accept the connection, or time_wait

3.client, same ip and port, a syn packet, if isn greater than x, then sends ack: isn + 1 syn and, therefore handshake direct connection, so you can quickly use the 4-tuple tcp


raw socket demo:http://blog.csdn.net/lizhia1221/article/details/51946592

Published 140 original articles · won praise 28 · views 180 000 +

Guess you like

Origin blog.csdn.net/qq_16097611/article/details/79080687