Huge timeout with loose=1 pickup tcp connections
Subsystems (2)
Florian Westphal
maintainerHi.
With nf_conntrack_tcp_loose = 1, stray packets will create conntrack with 5 days-timeout. Is this necessary?
I ask, because I've got following tcp trace:
192.168.x is initiator/origin, 10.184. is responder/reply, connection is establised by usual 3whs,
data was transmitted in both directions)
A 55:07 (id 12053, [DF], TCP, len 40) 192.168.x.52792 > 10.184.y.80: F, 426:426(0) ack 9237 win 255 B 55:07 (id 6129, [DF], TCP, len 40) 10.184.y.80 > 192.168.x.52792: ., ack 427 win 123 C 56:08 (id 6130, [DF], TCP, len 40) 10.184.y.80 > 192.168.x.52792: F, 9237:9237(0) ack 427 win 123 D 56:08 (id 12159, [DF], TCP, len 40) 192.168.x.52792 > 10.184.y.80: ., ack 9238 win 255
D is last packet seen for that connection. Notice 61 second pause between B and C.
Quoted 1 line
From conntrack POV, we have following state transitions:
[NEW] tcp 6 60 SYN_RECV .. [UPDATE] tcp 6 432000 ESTABLISHED .. [UPDATE] tcp 6 120 FIN_WAIT .. (triggered by packet A) [UPDATE] tcp 6 60 CLOSE_WAIT .. (triggered by packet B) [DESTROY] tcp 6 (triggered by 60-second CLOSE_WAIT timeout)
[NEW] tcp 6 432034 ESTABLISHED .. [UNREPLIED] (triggered by packet D)
Result is that, after a couple of hours, conntrack table starts to fill up with UNREPLIED crud.
Follwing changes fix it:
- set loose=0 (avoids bogus NEW connection), OR,
- set net.ipv4.netfilter.ip_conntrack_tcp_timeout_close_wait=65 (avoids NEW connection, new state transitions are:
[UPDATE] tcp 6 60 CLOSE_WAIT .. (triggered by packet B) [UPDATE] tcp 6 30 LAST_ACK .. (triggered by C) [UPDATE] tcp 6 120 TIME_WAIT .. (triggered by D)
However, I think conntrack shouldn't insert a just-picked up connection with default ESTABLISHED timeout value. Suggestion:
net/netfilter/nf_conntrack_proto_tcp.c +5 -0
@@ -1043,6 +1043,11 @@ static int tcp_packet(struct nf_conn *ct,nf_ct_kill_acct (ct, ctinfo, skb);return NF_ACCEPT ; } +/* loose=1 picked up existing connection, avoid large timeout */ +if (old_state ==TCP_CONNTRACK_NONE && + new_state ==TCP_CONNTRACK_ESTABLISHED && + timeout > timeouts[TCP_CONNTRACK_UNACK ]) + timeout = timeouts[TCP_CONNTRACK_UNACK ]; }else if (!test_bit (IPS_ASSURED_BIT , &ct->status) && (old_state ==TCP_CONNTRACK_SYN_RECV || old_state == TCP_CONNTRACK_ESTABLISHED)
Jozsef, If you aggree I would make a formal submission.
Thanks,
Florian
Pablo Neira Ayuso
maintainerQuoted 57 lines · Florian Westphal
Hi.
With
nf_conntrack_tcp_loose= 1, stray packets will create conntrack with 5 days-timeout. Is this necessary?I ask, because I've got following tcp trace:
192.168.x is initiator/origin, 10.184. is responder/reply, connection is establised by usual 3whs,
data was transmitted in both directions)A 55:07 (id 12053, [DF], TCP, len 40) 192.168.x.52792 > 10.184.y.80: F, 426:426(0) ack 9237 win 255 B 55:07 (id 6129, [DF], TCP, len 40) 10.184.y.80 > 192.168.x.52792: ., ack 427 win 123 C 56:08 (id 6130, [DF], TCP, len 40) 10.184.y.80 > 192.168.x.52792: F, 9237:9237(0) ack 427 win 123 D 56:08 (id 12159, [DF], TCP, len 40) 192.168.x.52792 > 10.184.y.80: ., ack 9238 win 255
D is last packet seen for that connection. Notice 61 second pause between B and C.
From conntrack POV, we have following state transitions:
[NEW] tcp 6 60 SYN_RECV .. [UPDATE] tcp 6 432000 ESTABLISHED .. [UPDATE] tcp 6 120 FIN_WAIT .. (triggered by packet A) [UPDATE] tcp 6 60 CLOSE_WAIT .. (triggered by packet B) [DESTROY] tcp 6 (triggered by 60-second CLOSE_WAIT timeout)[NEW] tcp 6 432034 ESTABLISHED .. [UNREPLIED] (triggered by packet D)
Result is that, after a couple of hours, conntrack table starts to fill up with UNREPLIED crud.
Follwing changes fix it:
- set loose=0 (avoids bogus NEW connection), OR,
- set net.ipv4.netfilter.ip_conntrack_tcp_timeout_close_wait=65 (avoids NEW connection, new state transitions are:[UPDATE] tcp 6 60 CLOSE_WAIT .. (triggered by packet B) [UPDATE] tcp 6 30 LAST_ACK .. (triggered by C) [UPDATE] tcp 6 120 TIME_WAIT .. (triggered by D)However, I think conntrack shouldn't insert a just-picked up connection with default ESTABLISHED timeout value. Suggestion:
net/netfilter/nf_conntrack_proto_tcp.c +5
-0@@ -1043,6 +1043,11 @@ static int tcp_packet(struct nf_conn *ct,nf_ct_kill_acct (ct, ctinfo, skb);return NF_ACCEPT ; } +/* loose=1 picked up existing connection, avoid large timeout */ +if (old_state ==TCP_CONNTRACK_NONE && + new_state ==TCP_CONNTRACK_ESTABLISHED && + timeout > timeouts[TCP_CONNTRACK_UNACK ]) + timeout = timeouts[TCP_CONNTRACK_UNACK ]; }else if (!test_bit (IPS_ASSURED_BIT , &ct->status) && (old_state ==TCP_CONNTRACK_SYN_RECV || old_state == TCP_CONNTRACK_ESTABLISHED)
Quoted 1 line
Jozsef, If you aggree I would make a formal submission.
This sounds reasonable to me.
conntrackd is adding entries using a small timeout for recovered flows, which is a similar approach.
Jozsef?
Quoted 54 lines · Florian Westphal
With
nf_conntrack_tcp_loose= 1, stray packets will create conntrack with 5 days-timeout. Is this necessary?I ask, because I've got following tcp trace:
192.168.x is initiator/origin, 10.184. is responder/reply, connection is establised by usual 3whs,
data was transmitted in both directions)A 55:07 (id 12053, [DF], TCP, len 40) 192.168.x.52792 > 10.184.y.80: F, 426:426(0) ack 9237 win 255 B 55:07 (id 6129, [DF], TCP, len 40) 10.184.y.80 > 192.168.x.52792: ., ack 427 win 123 C 56:08 (id 6130, [DF], TCP, len 40) 10.184.y.80 > 192.168.x.52792: F, 9237:9237(0) ack 427 win 123 D 56:08 (id 12159, [DF], TCP, len 40) 192.168.x.52792 > 10.184.y.80: ., ack 9238 win 255
D is last packet seen for that connection. Notice 61 second pause between B and C.
Quoted 1 line
From conntrack POV, we have following state transitions:
[NEW] tcp 6 60 SYN_RECV .. [UPDATE] tcp 6 432000 ESTABLISHED .. [UPDATE] tcp 6 120 FIN_WAIT .. (triggered by packet A) [UPDATE] tcp 6 60 CLOSE_WAIT .. (triggered by packet B) [DESTROY] tcp 6 (triggered by 60-second CLOSE_WAIT timeout)[NEW] tcp 6 432034 ESTABLISHED .. [UNREPLIED] (triggered by packet D)
Result is that, after a couple of hours, conntrack table starts to fill up with UNREPLIED crud.
Follwing changes fix it:
- set loose=0 (avoids bogus NEW connection), OR,
- set net.ipv4.netfilter.ip_conntrack_tcp_timeout_close_wait=65 (avoids NEW connection, new state transitions are:[UPDATE] tcp 6 60 CLOSE_WAIT .. (triggered by packet B) [UPDATE] tcp 6 30 LAST_ACK .. (triggered by C) [UPDATE] tcp 6 120 TIME_WAIT .. (triggered by D)However, I think conntrack shouldn't insert a just-picked up connection with default ESTABLISHED timeout value. Suggestion:
net/netfilter/nf_conntrack_proto_tcp.c +5
-0@@ -1043,6 +1043,11 @@ static int tcp_packet(struct nf_conn *ct,nf_ct_kill_acct (ct, ctinfo, skb);return NF_ACCEPT ; } +/* loose=1 picked up existing connection, avoid large timeout */ +if (old_state ==TCP_CONNTRACK_NONE && + new_state ==TCP_CONNTRACK_ESTABLISHED && + timeout > timeouts[TCP_CONNTRACK_UNACK ]) + timeout = timeouts[TCP_CONNTRACK_UNACK ]; }else if (!test_bit (IPS_ASSURED_BIT , &ct->status) && (old_state ==TCP_CONNTRACK_SYN_RECV || old_state == TCP_CONNTRACK_ESTABLISHED)
Quoted 1 line
Jozsef, If you aggree I would make a formal submission.
I agree with it, it's better to set up a shorter timeout for the just picked up connections at the first packet.
Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences
H-1525 Budapest 114, POB. 49, Hungary