netfilter: flowtable: infer TCP state and timeout before flow teardown
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/1 netfilter: flowtable: infer TCP state and timeout before flow teardown
In case that either FIN or RST packet is seen, infer current TCP state based on the TCP packet flags before setting the _TEARDOWN flag:
- FIN packets result in TCP_CONNTRACK_FIN_WAIT which uses a default timeout of 2 minutes.
- RST packets lead to tcp_state TCP_CONNTRACK_CLOSE of 10 seconds.
Therefore, TCP established state with a low timeout is not used anymore when handing over the flow to the classic conntrack path, otherwise a FIN packet coming in the reply direction could re-offload this flow again.
If flow teardown is required for other reasons, eg. no traffic seen after NF_FLOW_TIMEOUT, then use TCP established state but set timeout to TCP_CONNTRACK_UNACK state which is used in conntrack to pick up connections from the middle (default is 5 minutes).
---
Compile-tested only.
include/net/netfilter/nf_flow_table.h | 1 + net/netfilter/nf_flow_table_core.c | 45 +++++++++++++++++++++------ net/netfilter/nf_flow_table_ip.c | 2 +- 3 files changed, 37 insertions(+), 11 deletions(-)
include/net/netfilter/nf_flow_table.h +1 -0
@@ -293,6 +293,7 @@ int nf_flow_table_init(struct nf_flowtable *flow_table);void nf_flow_table_free (struct nf_flowtable *flow_table);void flow_offload_teardown (struct flow_offload *flow); +void flow_offload_teardown_tcp (struct flow_offload *flow,bool fin); void nf_flow_snat_port(const struct flow_offload *flow, struct sk_buff *skb, unsigned int thoff,
net/netfilter/nf_flow_table_core.c +35 -10
69 lines not on this page · raw message
net/netfilter/nf_flow_table_ip.c +1 -1
@@ -29,7 +29,7 @@ static int nf_flow_state_check(struct flow_offload *flow, int proto, tcph = (void *)(skb_network_header (skb) + thoff);if (unlikely (tcph->fin || tcph->rst)) { -flow_offload_teardown (flow); +flow_offload_teardown_tcp (flow, tcph->fin);return -1 ; }
Signature · 1 line
2.30.2
Quoted 17 lines · Pablo Neira Ayuso
In case that either FIN or RST packet is seen, infer current TCP state based on the TCP packet flags before setting the
_TEARDOWNflag:- FIN packets result in
TCP_CONNTRACK_FIN_WAITwhich uses a default timeout of 2 minutes.
- RST packets lead totcp_stateTCP_CONNTRACK_CLOSEof 10 seconds.Therefore, TCP established state with a low timeout is not used anymore when handing over the flow to the classic conntrack path, otherwise a FIN packet coming in the reply direction could re-offload this flow again.
If flow teardown is required for other reasons, eg. no traffic seen after
NF_FLOW_TIMEOUT, then use TCP established state but set timeout toTCP_CONNTRACK_UNACKstate which is used in conntrack to pick up connections from the middle (default is 5 minutes).
Quoted 4 lines
Fixes e5eaac2beb54 ("netfilter: flowtable: fix TCP flow teardown")Signed-off-by Pablo Neira Ayuso <[email protected]>---
Compile-tested only.
Thanks Pablo, I will test both patches on a production system this week and give you feedback.
Both patches look good to me though and should fix the timout problem.
Quoted 110 lines
include/net/netfilter/nf_flow_table.h | 1 + net/netfilter/nf_flow_table_core.c | 45 +++++++++++++++++++++------ net/netfilter/nf_flow_table_ip.c | 2 +- 3 files changed, 37 insertions(+), 11 deletions(-)include/net/netfilter/nf_flow_table.h +1
-0@@ -293,6 +293,7 @@ int nf_flow_table_init(struct nf_flowtable *flow_table);void nf_flow_table_free (struct nf_flowtable *flow_table);void flow_offload_teardown (struct flow_offload *flow); +void flow_offload_teardown_tcp (struct flow_offload *flow,bool fin); void nf_flow_snat_port(const struct flow_offload *flow, struct sk_buff *skb, unsigned int thoff,net/netfilter/nf_flow_table_core.c +35
-10@@ -165,10 +165,22 @@ void flow_offload_route_init(struct flow_offload *flow, }EXPORT_SYMBOL_GPL (flow_offload_route_init); -static void flow_offload_fixup_tcp (struct ip_ct_tcp *tcp) +static s32 flow_offload_fixup_tcp (struct net *net,struct nf_conn *ct, +enum tcp_conntrack tcp_state) { - tcp->seen[0 ].td_maxwin =0 ; - tcp->seen[1 ].td_maxwin =0 ; +struct nf_tcp_net *tn =nf_tcp_pernet (net); + + ct->proto.tcp.state = tcp_state; + ct->proto.tcp.seen[0 ].td_maxwin =0 ; + ct->proto.tcp.seen[1 ].td_maxwin =0 ; + +/* Similar to mid-connection pickup with loose=1. +* Avoid large ESTABLISHED timeout. +*/ +if (tcp_state ==TCP_CONNTRACK_ESTABLISHED ) +return tn->timeouts[TCP_CONNTRACK_UNACK ]; + +return tn->timeouts[tcp_state]; }static void flow_offload_fixup_ct (struct nf_conn *ct)@@ -178,12 +190,8 @@ static void flow_offload_fixup_ct(struct nf_conn *ct)s32 timeout;if (l4num ==IPPROTO_TCP ) { -struct nf_tcp_net *tn =nf_tcp_pernet (net); - -flow_offload_fixup_tcp (&ct->proto.tcp); - - timeout = tn->timeouts[ct->proto.tcp.state]; - timeout -= tn->offload_timeout; + timeout =flow_offload_fixup_tcp (net, ct, +TCP_CONNTRACK_ESTABLISHED ); }else if (l4num ==IPPROTO_UDP ) {struct nf_udp_net *tn =nf_udp_pernet (net); enum udp_conntrack state =@@ -346,12 +354,29 @@ static void flow_offload_del(struct nf_flowtable *flow_table,void flow_offload_teardown (struct flow_offload *flow) { +flow_offload_fixup_ct (flow->ct); +smp_mb__before_atomic ();clear_bit (IPS_OFFLOAD_BIT , &flow->ct->status);set_bit (NF_FLOW_TEARDOWN , &flow->flags); -flow_offload_fixup_ct (flow->ct); }EXPORT_SYMBOL_GPL (flow_offload_teardown); +void flow_offload_teardown_tcp (struct flow_offload *flow,bool fin) +{ +enum tcp_conntrack tcp_state; + +if (fin) + tcp_state =TCP_CONNTRACK_FIN_WAIT ; +else /* rst */ + tcp_state =TCP_CONNTRACK_CLOSE ; + +flow_offload_fixup_tcp (nf_ct_net (flow->ct), flow->ct, tcp_state); +smp_mb__before_atomic (); +clear_bit (IPS_OFFLOAD_BIT , &flow->ct->status); +set_bit (NF_FLOW_TEARDOWN , &flow->flags); +} +EXPORT_SYMBOL_GPL (flow_offload_teardown_tcp); +struct flow_offload_tuple_rhash *flow_offload_lookup (struct nf_flowtable *flow_table,struct flow_offload_tuple *tuple)net/netfilter/nf_flow_table_ip.c +1
-1@@ -29,7 +29,7 @@ static int nf_flow_state_check(struct flow_offload *flow, int proto, tcph = (void *)(skb_network_header (skb) + thoff);if (unlikely (tcph->fin || tcph->rst)) { -flow_offload_teardown (flow); +flow_offload_teardown_tcp (flow, tcph->fin);return -1 ; }Signature · 1 line
2.30.2
Quoted 54 lines · Pablo Neira Ayuso
In case that either FIN or RST packet is seen, infer current TCP state based on the TCP packet flags before setting the
_TEARDOWNflag:- FIN packets result in
TCP_CONNTRACK_FIN_WAITwhich uses a default timeout of 2 minutes.
- RST packets lead totcp_stateTCP_CONNTRACK_CLOSEof 10 seconds.Therefore, TCP established state with a low timeout is not used anymore when handing over the flow to the classic conntrack path, otherwise a FIN packet coming in the reply direction could re-offload this flow again.
If flow teardown is required for other reasons, eg. no traffic seen after
NF_FLOW_TIMEOUT, then use TCP established state but set timeout toTCP_CONNTRACK_UNACKstate which is used in conntrack to pick up connections from the middle (default is 5 minutes).Fixes e5eaac2beb54 ("netfilter: flowtable: fix TCP flow teardown")Signed-off-by Pablo Neira Ayuso <[email protected]>---
Compile-tested only.include/net/netfilter/nf_flow_table.h | 1 + net/netfilter/nf_flow_table_core.c | 45 +++++++++++++++++++++------ net/netfilter/nf_flow_table_ip.c | 2 +- 3 files changed, 37 insertions(+), 11 deletions(-)include/net/netfilter/nf_flow_table.h +1
-0@@ -293,6 +293,7 @@ int nf_flow_table_init(struct nf_flowtable *flow_table);void nf_flow_table_free (struct nf_flowtable *flow_table);void flow_offload_teardown (struct flow_offload *flow); +void flow_offload_teardown_tcp (struct flow_offload *flow,bool fin); void nf_flow_snat_port(const struct flow_offload *flow, struct sk_buff *skb, unsigned int thoff,net/netfilter/nf_flow_table_core.c +3
-3@@ -165,10 +165,22 @@ void flow_offload_route_init(struct flow_offload *flow, }EXPORT_SYMBOL_GPL (flow_offload_route_init); -static void flow_offload_fixup_tcp (struct ip_ct_tcp *tcp) +static s32 flow_offload_fixup_tcp (struct net *net,struct nf_conn *ct, +enum tcp_conntrack tcp_state) { - tcp->seen[0 ].td_maxwin =0 ; - tcp->seen[1 ].td_maxwin =0 ; +struct nf_tcp_net *tn =nf_tcp_pernet (net);
net/netfilter/nf_flow_table_core.c void flow_offload_route_init(struct flow_offload *flow, · line 181
Quoted 10 lines
net/netfilter/nf_flow_table_core.c +10
-0+ + ct->proto.tcp.state = tcp_state; + ct->proto.tcp.seen[0 ].td_maxwin =0 ; + ct->proto.tcp.seen[1 ].td_maxwin =0 ; + +/* Similar to mid-connection pickup with loose=1. +* Avoid large ESTABLISHED timeout. +*/ +if (tcp_state ==TCP_CONNTRACK_ESTABLISHED ) +return tn->timeouts[TCP_CONNTRACK_UNACK ];
Hi Pablo,
I tested the patch but the part that sets the timout to UNACK is not very practical.
For example my long running SSH connections get killed off by the firewall regularly now while beeing ESTABLISHED:
[NEW] tcp 6 120 SYN_SENT src=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 [UNREPLIED] src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 60 SYN_RECV src=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 86400 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 [OFFLOAD] mark=16777216
[DESTROY] tcp 6 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=54941 dport=22 packets=133 bytes=13033 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=54941 packets=95 bytes=15004 [ASSURED] mark=16777216 delta-time=1036
I would remove the if case here.
Quoted 67 lines
net/netfilter/nf_flow_table_core.c +22
-7+ +return tn->timeouts[tcp_state]; }static void flow_offload_fixup_ct (struct nf_conn *ct)@@ -178,12 +190,8 @@ static void flow_offload_fixup_ct(struct nf_conn *ct)s32 timeout;if (l4num ==IPPROTO_TCP ) { -struct nf_tcp_net *tn =nf_tcp_pernet (net); - -flow_offload_fixup_tcp (&ct->proto.tcp); - - timeout = tn->timeouts[ct->proto.tcp.state]; - timeout -= tn->offload_timeout; + timeout =flow_offload_fixup_tcp (net, ct, +TCP_CONNTRACK_ESTABLISHED ); }else if (l4num ==IPPROTO_UDP ) {struct nf_udp_net *tn =nf_udp_pernet (net); enum udp_conntrack state =@@ -346,12 +354,29 @@ static void flow_offload_del(struct nf_flowtable *flow_table,void flow_offload_teardown (struct flow_offload *flow) { +flow_offload_fixup_ct (flow->ct); +smp_mb__before_atomic ();clear_bit (IPS_OFFLOAD_BIT , &flow->ct->status);set_bit (NF_FLOW_TEARDOWN , &flow->flags); -flow_offload_fixup_ct (flow->ct); }EXPORT_SYMBOL_GPL (flow_offload_teardown); +void flow_offload_teardown_tcp (struct flow_offload *flow,bool fin) +{ +enum tcp_conntrack tcp_state; + +if (fin) + tcp_state =TCP_CONNTRACK_FIN_WAIT ; +else /* rst */ + tcp_state =TCP_CONNTRACK_CLOSE ; + +flow_offload_fixup_tcp (nf_ct_net (flow->ct), flow->ct, tcp_state); +smp_mb__before_atomic (); +clear_bit (IPS_OFFLOAD_BIT , &flow->ct->status); +set_bit (NF_FLOW_TEARDOWN , &flow->flags); +} +EXPORT_SYMBOL_GPL (flow_offload_teardown_tcp); +struct flow_offload_tuple_rhash *flow_offload_lookup (struct nf_flowtable *flow_table,struct flow_offload_tuple *tuple)net/netfilter/nf_flow_table_ip.c +1
-1@@ -29,7 +29,7 @@ static int nf_flow_state_check(struct flow_offload *flow, int proto, tcph = (void *)(skb_network_header (skb) + thoff);if (unlikely (tcph->fin || tcph->rst)) { -flow_offload_teardown (flow); +flow_offload_teardown_tcp (flow, tcph->fin);return -1 ; }Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerHi Sven,
Quoted 1 line · Sven Auhagen
On Mon, Mar 18, 2024 at 10:39:15AM +0100, Pablo Neira Ayuso wrote:
[...]
Quoted 33 lines
Quoted 15 lines
net/netfilter/nf_flow_table_core.c +3
-3@@ -165,10 +165,22 @@ void flow_offload_route_init(struct flow_offload *flow, }EXPORT_SYMBOL_GPL (flow_offload_route_init); -static void flow_offload_fixup_tcp (struct ip_ct_tcp *tcp) +static s32 flow_offload_fixup_tcp (struct net *net,struct nf_conn *ct, +enum tcp_conntrack tcp_state) { - tcp->seen[0 ].td_maxwin =0 ; - tcp->seen[1 ].td_maxwin =0 ; +struct nf_tcp_net *tn =nf_tcp_pernet (net);net/netfilter/nf_flow_table_core.c void flow_offload_route_init(struct flow_offload *flow, · line 181
Quoted 10 lines
net/netfilter/nf_flow_table_core.c +10
-0+ + ct->proto.tcp.state = tcp_state; + ct->proto.tcp.seen[0 ].td_maxwin =0 ; + ct->proto.tcp.seen[1 ].td_maxwin =0 ; + +/* Similar to mid-connection pickup with loose=1. +* Avoid large ESTABLISHED timeout. +*/ +if (tcp_state ==TCP_CONNTRACK_ESTABLISHED ) +return tn->timeouts[TCP_CONNTRACK_UNACK ];Hi Pablo,
I tested the patch but the part that sets the timout to UNACK is not very practical.
For example my long running SSH connections get killed off by the firewall regularly now while beeing ESTABLISHED:
Quoted 7 lines
[NEW] tcp 6 120
SYN_SENTsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 [UNREPLIED] src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 60SYN_RECVsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 86400 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 [OFFLOAD] mark=16777216[DESTROY] tcp 6 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=54941 dport=22 packets=133 bytes=13033 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=54941 packets=95 bytes=15004 [ASSURED] mark=16777216 delta-time=1036
I would remove the if case here.
OK, I remove it and post a v2. Thanks!
Quoted 5 lines
Quoted 5 lines
net/netfilter/nf_flow_table_core.c +2
-0+ +return tn->timeouts[tcp_state]; }static void flow_offload_fixup_ct (struct nf_conn *ct)
Quoted 42 lines · Pablo Neira Ayuso
Hi Sven,
Quoted 1 line · Sven Auhagen
On Mon, Mar 18, 2024 at 10:39:15AM +0100, Pablo Neira Ayuso wrote:
[...]
Quoted 37 lines
Quoted 15 lines
net/netfilter/nf_flow_table_core.c +3
-3@@ -165,10 +165,22 @@ void flow_offload_route_init(struct flow_offload *flow, }EXPORT_SYMBOL_GPL (flow_offload_route_init); -static void flow_offload_fixup_tcp (struct ip_ct_tcp *tcp) +static s32 flow_offload_fixup_tcp (struct net *net,struct nf_conn *ct, +enum tcp_conntrack tcp_state) { - tcp->seen[0 ].td_maxwin =0 ; - tcp->seen[1 ].td_maxwin =0 ; +struct nf_tcp_net *tn =nf_tcp_pernet (net);net/netfilter/nf_flow_table_core.c void flow_offload_route_init(struct flow_offload *flow, · line 181
Quoted 10 lines
net/netfilter/nf_flow_table_core.c +10
-0+ + ct->proto.tcp.state = tcp_state; + ct->proto.tcp.seen[0 ].td_maxwin =0 ; + ct->proto.tcp.seen[1 ].td_maxwin =0 ; + +/* Similar to mid-connection pickup with loose=1. +* Avoid large ESTABLISHED timeout. +*/ +if (tcp_state ==TCP_CONNTRACK_ESTABLISHED ) +return tn->timeouts[TCP_CONNTRACK_UNACK ];Hi Pablo,
I tested the patch but the part that sets the timout to UNACK is not very practical.
For example my long running SSH connections get killed off by the firewall regularly now while beeing ESTABLISHED:[NEW] tcp 6 120
SYN_SENTsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 [UNREPLIED] src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 60SYN_RECVsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 86400 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 [OFFLOAD] mark=16777216
Quoted 5 lines
Quoted 3 lines
[DESTROY] tcp 6 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=54941 dport=22 packets=133 bytes=13033 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=54941 packets=95 bytes=15004 [ASSURED] mark=16777216 delta-time=1036
I would remove the if case here.
OK, I remove it and post a v2. Thanks!
Thanks and also the hardcoded TCP_CONNTRACK_ESTABLISHED in flow_offload_fixup_ct should be reverted to the real tcp state ct->proto.tcp.state.
This way we always set the current TCP timeout.
I am doing more tests with that now.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
net/netfilter/nf_flow_table_core.c +2
-0+ +return tn->timeouts[tcp_state]; }static void flow_offload_fixup_ct (struct nf_conn *ct)
Pablo Neira Ayuso
maintainerQuoted 43 lines · Sven Auhagen
Quoted 42 lines · Pablo Neira Ayuso
Hi Sven,
Quoted 1 line · Sven Auhagen
On Mon, Mar 18, 2024 at 10:39:15AM +0100, Pablo Neira Ayuso wrote:
[...]
Quoted 37 lines
Quoted 15 lines
net/netfilter/nf_flow_table_core.c +3
-3@@ -165,10 +165,22 @@ void flow_offload_route_init(struct flow_offload *flow, }EXPORT_SYMBOL_GPL (flow_offload_route_init); -static void flow_offload_fixup_tcp (struct ip_ct_tcp *tcp) +static s32 flow_offload_fixup_tcp (struct net *net,struct nf_conn *ct, +enum tcp_conntrack tcp_state) { - tcp->seen[0 ].td_maxwin =0 ; - tcp->seen[1 ].td_maxwin =0 ; +struct nf_tcp_net *tn =nf_tcp_pernet (net);net/netfilter/nf_flow_table_core.c void flow_offload_route_init(struct flow_offload *flow, · line 181
Quoted 10 lines
net/netfilter/nf_flow_table_core.c +10
-0+ + ct->proto.tcp.state = tcp_state; + ct->proto.tcp.seen[0 ].td_maxwin =0 ; + ct->proto.tcp.seen[1 ].td_maxwin =0 ; + +/* Similar to mid-connection pickup with loose=1. +* Avoid large ESTABLISHED timeout. +*/ +if (tcp_state ==TCP_CONNTRACK_ESTABLISHED ) +return tn->timeouts[TCP_CONNTRACK_UNACK ];Hi Pablo,
I tested the patch but the part that sets the timout to UNACK is not very practical.
For example my long running SSH connections get killed off by the firewall regularly now while beeing ESTABLISHED:[NEW] tcp 6 120
SYN_SENTsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 [UNREPLIED] src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 60SYN_RECVsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 86400 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 [OFFLOAD] mark=16777216
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
[DESTROY] tcp 6 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=54941 dport=22 packets=133 bytes=13033 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=54941 packets=95 bytes=15004 [ASSURED] mark=16777216 delta-time=1036
I would remove the if case here.
OK, I remove it and post a v2. Thanks!
Thanks and also the hardcoded
TCP_CONNTRACK_ESTABLISHEDinflow_offload_fixup_ctshould be reverted to the real tcp statect->proto.tcp.state.
ct->proto.tcp.state contains the state that was observed before handling over this flow to the flowtable, in most cases, this should be TCP_CONNTRACK_ESTABLISHED.
Quoted 1 line
This way we always set the current TCP timeout.
I can keep it to ct->proto.tcp.state but I wonder if it is better to use a well known state such as TCP_CONNTRACK_ESTABLISHED to pick up from.
Quoted 1 line
I am doing more tests with that now.
Thanks!
Quoted 53 lines · Pablo Neira Ayuso
Quoted 43 lines · Sven Auhagen
Quoted 42 lines · Pablo Neira Ayuso
Hi Sven,
Quoted 1 line · Sven Auhagen
On Mon, Mar 18, 2024 at 10:39:15AM +0100, Pablo Neira Ayuso wrote:
[...]
Quoted 37 lines
Quoted 15 lines
net/netfilter/nf_flow_table_core.c +3
-3@@ -165,10 +165,22 @@ void flow_offload_route_init(struct flow_offload *flow, }EXPORT_SYMBOL_GPL (flow_offload_route_init); -static void flow_offload_fixup_tcp (struct ip_ct_tcp *tcp) +static s32 flow_offload_fixup_tcp (struct net *net,struct nf_conn *ct, +enum tcp_conntrack tcp_state) { - tcp->seen[0 ].td_maxwin =0 ; - tcp->seen[1 ].td_maxwin =0 ; +struct nf_tcp_net *tn =nf_tcp_pernet (net);net/netfilter/nf_flow_table_core.c void flow_offload_route_init(struct flow_offload *flow, · line 181
Quoted 10 lines
net/netfilter/nf_flow_table_core.c +10
-0+ + ct->proto.tcp.state = tcp_state; + ct->proto.tcp.seen[0 ].td_maxwin =0 ; + ct->proto.tcp.seen[1 ].td_maxwin =0 ; + +/* Similar to mid-connection pickup with loose=1. +* Avoid large ESTABLISHED timeout. +*/ +if (tcp_state ==TCP_CONNTRACK_ESTABLISHED ) +return tn->timeouts[TCP_CONNTRACK_UNACK ];Hi Pablo,
I tested the patch but the part that sets the timout to UNACK is not very practical.
For example my long running SSH connections get killed off by the firewall regularly now while beeing ESTABLISHED:[NEW] tcp 6 120
SYN_SENTsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 [UNREPLIED] src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 60SYN_RECVsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 86400 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 [OFFLOAD] mark=16777216Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
[DESTROY] tcp 6 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=54941 dport=22 packets=133 bytes=13033 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=54941 packets=95 bytes=15004 [ASSURED] mark=16777216 delta-time=1036
I would remove the if case here.
OK, I remove it and post a v2. Thanks!
Thanks and also the hardcoded
TCP_CONNTRACK_ESTABLISHEDinflow_offload_fixup_ctshould be reverted to the real tcp statect->proto.tcp.state.
Quoted 8 lines
ct->proto.tcp.statecontains the state that was observed before handling over this flow to the flowtable, in most cases, this should beTCP_CONNTRACK_ESTABLISHED.Quoted 1 line
This way we always set the current TCP timeout.
I can keep it to
ct->proto.tcp.statebut I wonder if it is better to use a well known state such asTCP_CONNTRACK_ESTABLISHEDto pick up from.
In case of a race condition or if something is off like my TCP_FIN that is beeing offloaded again setting to to ESTABLISHED hard coded will make the e.g. FIN or CLOSE a very long state.
It is not guaranteed that we are still in ESTABLISHED when this code runs. Also for example we could have seen both FIN already before the flowtable gc runs.
Quoted 4 lines
Quoted 2 lines
I am doing more tests with that now.
Thanks!
Pablo Neira Ayuso
maintainerQuoted 63 lines · Sven Auhagen
Quoted 53 lines · Pablo Neira Ayuso
Quoted 43 lines · Sven Auhagen
Quoted 42 lines · Pablo Neira Ayuso
Hi Sven,
Quoted 1 line · Sven Auhagen
On Mon, Mar 18, 2024 at 10:39:15AM +0100, Pablo Neira Ayuso wrote:
[...]
Quoted 37 lines
Quoted 15 lines
net/netfilter/nf_flow_table_core.c +3
-3@@ -165,10 +165,22 @@ void flow_offload_route_init(struct flow_offload *flow, }EXPORT_SYMBOL_GPL (flow_offload_route_init); -static void flow_offload_fixup_tcp (struct ip_ct_tcp *tcp) +static s32 flow_offload_fixup_tcp (struct net *net,struct nf_conn *ct, +enum tcp_conntrack tcp_state) { - tcp->seen[0 ].td_maxwin =0 ; - tcp->seen[1 ].td_maxwin =0 ; +struct nf_tcp_net *tn =nf_tcp_pernet (net);net/netfilter/nf_flow_table_core.c void flow_offload_route_init(struct flow_offload *flow, · line 181
Quoted 10 lines
net/netfilter/nf_flow_table_core.c +10
-0+ + ct->proto.tcp.state = tcp_state; + ct->proto.tcp.seen[0 ].td_maxwin =0 ; + ct->proto.tcp.seen[1 ].td_maxwin =0 ; + +/* Similar to mid-connection pickup with loose=1. +* Avoid large ESTABLISHED timeout. +*/ +if (tcp_state ==TCP_CONNTRACK_ESTABLISHED ) +return tn->timeouts[TCP_CONNTRACK_UNACK ];Hi Pablo,
I tested the patch but the part that sets the timout to UNACK is not very practical.
For example my long running SSH connections get killed off by the firewall regularly now while beeing ESTABLISHED:[NEW] tcp 6 120
SYN_SENTsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 [UNREPLIED] src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 60SYN_RECVsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 86400 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 [OFFLOAD] mark=16777216Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
[DESTROY] tcp 6 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=54941 dport=22 packets=133 bytes=13033 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=54941 packets=95 bytes=15004 [ASSURED] mark=16777216 delta-time=1036
I would remove the if case here.
OK, I remove it and post a v2. Thanks!
Thanks and also the hardcoded
TCP_CONNTRACK_ESTABLISHEDinflow_offload_fixup_ctshould be reverted to the real tcp statect->proto.tcp.state.Quoted 8 lines
ct->proto.tcp.statecontains the state that was observed before handling over this flow to the flowtable, in most cases, this should beTCP_CONNTRACK_ESTABLISHED.Quoted 1 line
This way we always set the current TCP timeout.
I can keep it to
ct->proto.tcp.statebut I wonder if it is better to use a well known state such asTCP_CONNTRACK_ESTABLISHEDto pick up from.
Quoted 6 lines
In case of a race condition or if something is off like my
TCP_FINthat is beeing offloaded again setting to to ESTABLISHED hard coded will make the e.g. FIN or CLOSE a very long state.
It is not guaranteed that we are still in ESTABLISHED when this code runs. Also for example we could have seen both FIN already before the flowtable gc runs.
OK, I just posted a v2, leave things as is. I agree it is better to only address the issue you are observing at this time, it is possible to revisit later.
Thanks!
Quoted 71 lines · Pablo Neira Ayuso
Quoted 63 lines · Sven Auhagen
Quoted 53 lines · Pablo Neira Ayuso
Quoted 43 lines · Sven Auhagen
Quoted 42 lines · Pablo Neira Ayuso
Hi Sven,
Quoted 1 line · Sven Auhagen
On Mon, Mar 18, 2024 at 10:39:15AM +0100, Pablo Neira Ayuso wrote:
[...]
Quoted 37 lines
Quoted 15 lines
net/netfilter/nf_flow_table_core.c +3
-3@@ -165,10 +165,22 @@ void flow_offload_route_init(struct flow_offload *flow, }EXPORT_SYMBOL_GPL (flow_offload_route_init); -static void flow_offload_fixup_tcp (struct ip_ct_tcp *tcp) +static s32 flow_offload_fixup_tcp (struct net *net,struct nf_conn *ct, +enum tcp_conntrack tcp_state) { - tcp->seen[0 ].td_maxwin =0 ; - tcp->seen[1 ].td_maxwin =0 ; +struct nf_tcp_net *tn =nf_tcp_pernet (net);net/netfilter/nf_flow_table_core.c void flow_offload_route_init(struct flow_offload *flow, · line 181
Quoted 10 lines
net/netfilter/nf_flow_table_core.c +10
-0+ + ct->proto.tcp.state = tcp_state; + ct->proto.tcp.seen[0 ].td_maxwin =0 ; + ct->proto.tcp.seen[1 ].td_maxwin =0 ; + +/* Similar to mid-connection pickup with loose=1. +* Avoid large ESTABLISHED timeout. +*/ +if (tcp_state ==TCP_CONNTRACK_ESTABLISHED ) +return tn->timeouts[TCP_CONNTRACK_UNACK ];Hi Pablo,
I tested the patch but the part that sets the timout to UNACK is not very practical.
For example my long running SSH connections get killed off by the firewall regularly now while beeing ESTABLISHED:[NEW] tcp 6 120
SYN_SENTsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 [UNREPLIED] src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 60SYN_RECVsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 86400 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 [OFFLOAD] mark=16777216Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
[DESTROY] tcp 6 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=54941 dport=22 packets=133 bytes=13033 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=54941 packets=95 bytes=15004 [ASSURED] mark=16777216 delta-time=1036
I would remove the if case here.
OK, I remove it and post a v2. Thanks!
Thanks and also the hardcoded
TCP_CONNTRACK_ESTABLISHEDinflow_offload_fixup_ctshould be reverted to the real tcp statect->proto.tcp.state.Quoted 8 lines
ct->proto.tcp.statecontains the state that was observed before handling over this flow to the flowtable, in most cases, this should beTCP_CONNTRACK_ESTABLISHED.Quoted 1 line
This way we always set the current TCP timeout.
I can keep it to
ct->proto.tcp.statebut I wonder if it is better to use a well known state such asTCP_CONNTRACK_ESTABLISHEDto pick up from.Quoted 6 lines
In case of a race condition or if something is off like my
TCP_FINthat is beeing offloaded again setting to to ESTABLISHED hard coded will make the e.g. FIN or CLOSE a very long state.
It is not guaranteed that we are still in ESTABLISHED when this code runs. Also for example we could have seen both FIN already before the flowtable gc runs.
Quoted 5 lines
OK, I just posted a v2, leave things as is. I agree it is better to only address the issue you are observing at this time, it is possible to revisit later.
Thanks!
Thanks, I will give it another try.
I think for it to be foolproof we need
to migrate the TCP state as well in flow_offload_teardown_tcp to FIN or CLOSE. They way thinks are right now we are open to a race condition from the reverse side of the connection to reoffload the connection while a FIN or RST is not processed by the netfilter code running after the flowtable code.
The conenction is still in TCP established during that window and another packet can just push it back to the flowtable while the FIN or RST is not processed yet.
Pablo Neira Ayuso
maintainerQuoted 76 lines · Sven Auhagen
Quoted 75 lines · Pablo Neira Ayuso
Quoted 63 lines · Sven Auhagen
Quoted 53 lines · Pablo Neira Ayuso
Quoted 43 lines · Sven Auhagen
Quoted 42 lines · Pablo Neira Ayuso
Hi Sven,
Quoted 1 line · Sven Auhagen
On Mon, Mar 18, 2024 at 10:39:15AM +0100, Pablo Neira Ayuso wrote:
[...]
Quoted 37 lines
Quoted 15 lines
net/netfilter/nf_flow_table_core.c +3
-3@@ -165,10 +165,22 @@ void flow_offload_route_init(struct flow_offload *flow, }EXPORT_SYMBOL_GPL (flow_offload_route_init); -static void flow_offload_fixup_tcp (struct ip_ct_tcp *tcp) +static s32 flow_offload_fixup_tcp (struct net *net,struct nf_conn *ct, +enum tcp_conntrack tcp_state) { - tcp->seen[0 ].td_maxwin =0 ; - tcp->seen[1 ].td_maxwin =0 ; +struct nf_tcp_net *tn =nf_tcp_pernet (net);net/netfilter/nf_flow_table_core.c void flow_offload_route_init(struct flow_offload *flow, · line 181
Quoted 10 lines
net/netfilter/nf_flow_table_core.c +10
-0+ + ct->proto.tcp.state = tcp_state; + ct->proto.tcp.seen[0 ].td_maxwin =0 ; + ct->proto.tcp.seen[1 ].td_maxwin =0 ; + +/* Similar to mid-connection pickup with loose=1. +* Avoid large ESTABLISHED timeout. +*/ +if (tcp_state ==TCP_CONNTRACK_ESTABLISHED ) +return tn->timeouts[TCP_CONNTRACK_UNACK ];Hi Pablo,
I tested the patch but the part that sets the timout to UNACK is not very practical.
For example my long running SSH connections get killed off by the firewall regularly now while beeing ESTABLISHED:[NEW] tcp 6 120
SYN_SENTsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 [UNREPLIED] src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 60SYN_RECVsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 86400 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 [OFFLOAD] mark=16777216Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
[DESTROY] tcp 6 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=54941 dport=22 packets=133 bytes=13033 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=54941 packets=95 bytes=15004 [ASSURED] mark=16777216 delta-time=1036
I would remove the if case here.
OK, I remove it and post a v2. Thanks!
Thanks and also the hardcoded
TCP_CONNTRACK_ESTABLISHEDinflow_offload_fixup_ctshould be reverted to the real tcp statect->proto.tcp.state.Quoted 8 lines
ct->proto.tcp.statecontains the state that was observed before handling over this flow to the flowtable, in most cases, this should beTCP_CONNTRACK_ESTABLISHED.Quoted 1 line
This way we always set the current TCP timeout.
I can keep it to
ct->proto.tcp.statebut I wonder if it is better to use a well known state such asTCP_CONNTRACK_ESTABLISHEDto pick up from.Quoted 6 lines
In case of a race condition or if something is off like my
TCP_FINthat is beeing offloaded again setting to to ESTABLISHED hard coded will make the e.g. FIN or CLOSE a very long state.
It is not guaranteed that we are still in ESTABLISHED when this code runs. Also for example we could have seen both FIN already before the flowtable gc runs.OK, I just posted a v2, leave things as is. I agree it is better to only address the issue you are observing at this time, it is possible to revisit later.
Quoted 5 lines
Quoted 1 line
Thanks!
Thanks, I will give it another try.
I think for it to be foolproof we need
to migrate the TCP state as well inflow_offload_teardown_tcpto FIN or CLOSE.
My patch already does it:
+void flow_offload_teardown_tcp(struct flow_offload *flow, bool fin) +{
+ enum tcp_conntrack tcp_state;
+
+ if (fin)
+ tcp_state = TCP_CONNTRACK_FIN_WAIT;
+ else /* rst */
+ tcp_state = TCP_CONNTRACK_CLOSE;
+
+ flow_offload_fixup_tcp(nf_ct_net(flow->ct), flow->ct, tcp_state);
flow_offload_fixup_tcp() updates the TCP state to FIN / CLOSE state.
Quoted 5 lines
They way thinks are right now we are open to a race condition from the reverse side of the connection to reoffload the connection while a FIN or RST is not processed by the netfilter code running after the flowtable code.
The conenction is still in TCP established during that window and another packet can just push it back to the flowtable while the FIN or RST is not processed yet.
I don't see how:
static void nft_flow_offload_eval(const struct nft_expr *expr,
...
switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) {
case IPPROTO_TCP:
tcph = skb_header_pointer(pkt->skb, nft_thoff(pkt),
sizeof(_tcph), &_tcph);
if (unlikely(!tcph || tcph->fin || tcph->rst ||
!nf_conntrack_tcp_established(ct)))
goto out;this would now be either in FIN/CLOSE state.
FIN, RST packet does not trigger re-offload. And ACK packet would find the entry in !nf_conntrack_tcp_established(ct).
What path could trigger re-offload after my latest patch?
For the flow timeout case (where flow entry is released and packets goes back to classic conntrack path) re-offload is possible, but that is a feature.
Quoted 96 lines · Pablo Neira Ayuso
Quoted 76 lines · Sven Auhagen
Quoted 75 lines · Pablo Neira Ayuso
Quoted 63 lines · Sven Auhagen
Quoted 53 lines · Pablo Neira Ayuso
Quoted 43 lines · Sven Auhagen
Quoted 42 lines · Pablo Neira Ayuso
Hi Sven,
Quoted 1 line · Sven Auhagen
On Mon, Mar 18, 2024 at 10:39:15AM +0100, Pablo Neira Ayuso wrote:
[...]
Quoted 37 lines
Quoted 15 lines
net/netfilter/nf_flow_table_core.c +3
-3@@ -165,10 +165,22 @@ void flow_offload_route_init(struct flow_offload *flow, }EXPORT_SYMBOL_GPL (flow_offload_route_init); -static void flow_offload_fixup_tcp (struct ip_ct_tcp *tcp) +static s32 flow_offload_fixup_tcp (struct net *net,struct nf_conn *ct, +enum tcp_conntrack tcp_state) { - tcp->seen[0 ].td_maxwin =0 ; - tcp->seen[1 ].td_maxwin =0 ; +struct nf_tcp_net *tn =nf_tcp_pernet (net);net/netfilter/nf_flow_table_core.c void flow_offload_route_init(struct flow_offload *flow, · line 181
Quoted 10 lines
net/netfilter/nf_flow_table_core.c +10
-0+ + ct->proto.tcp.state = tcp_state; + ct->proto.tcp.seen[0 ].td_maxwin =0 ; + ct->proto.tcp.seen[1 ].td_maxwin =0 ; + +/* Similar to mid-connection pickup with loose=1. +* Avoid large ESTABLISHED timeout. +*/ +if (tcp_state ==TCP_CONNTRACK_ESTABLISHED ) +return tn->timeouts[TCP_CONNTRACK_UNACK ];Hi Pablo,
I tested the patch but the part that sets the timout to UNACK is not very practical.
For example my long running SSH connections get killed off by the firewall regularly now while beeing ESTABLISHED:[NEW] tcp 6 120
SYN_SENTsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 [UNREPLIED] src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 60SYN_RECVsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 86400 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 [OFFLOAD] mark=16777216Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
[DESTROY] tcp 6 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=54941 dport=22 packets=133 bytes=13033 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=54941 packets=95 bytes=15004 [ASSURED] mark=16777216 delta-time=1036
I would remove the if case here.
OK, I remove it and post a v2. Thanks!
Thanks and also the hardcoded
TCP_CONNTRACK_ESTABLISHEDinflow_offload_fixup_ctshould be reverted to the real tcp statect->proto.tcp.state.Quoted 8 lines
ct->proto.tcp.statecontains the state that was observed before handling over this flow to the flowtable, in most cases, this should beTCP_CONNTRACK_ESTABLISHED.Quoted 1 line
This way we always set the current TCP timeout.
I can keep it to
ct->proto.tcp.statebut I wonder if it is better to use a well known state such asTCP_CONNTRACK_ESTABLISHEDto pick up from.Quoted 6 lines
In case of a race condition or if something is off like my
TCP_FINthat is beeing offloaded again setting to to ESTABLISHED hard coded will make the e.g. FIN or CLOSE a very long state.
It is not guaranteed that we are still in ESTABLISHED when this code runs. Also for example we could have seen both FIN already before the flowtable gc runs.OK, I just posted a v2, leave things as is. I agree it is better to only address the issue you are observing at this time, it is possible to revisit later.
Quoted 5 lines
Quoted 1 line
Thanks!
Thanks, I will give it another try.
I think for it to be foolproof we need
to migrate the TCP state as well inflow_offload_teardown_tcpto FIN or CLOSE.My patch already does it:
(quoted diff) +10
-0+void flow_offload_teardown_tcp(struct flow_offload *flow, bool fin) +{ + enum tcp_conntrack tcp_state; + + if (fin) + tcp_state = TCP_CONNTRACK_FIN_WAIT; + else /* rst */ + tcp_state = TCP_CONNTRACK_CLOSE; + + flow_offload_fixup_tcp(nf_ct_net(flow->ct), flow->ct, tcp_state);
Quoted 1 line
flow_offload_fixup_tcp()updates the TCP state to FIN / CLOSE state.
Ah you are correct.
Never the less I can tell you that I still see this problem with the patch attached:
[UPDATE] tcp 6 120 FIN_WAIT src=192.168.7.105 dst=17.253.57.219 sport=49574 dport=443 src=17.253.57.219 dst=87.138.198.79 sport=443 dport=5078 [OFFLOAD] mark=25165825
[UPDATE] tcp 6 30 LAST_ACK src=192.168.7.105 dst=17.253.57.219 sport=49574 dport=443 src=17.253.57.219 dst=87.138.198.79 sport=443 dport=5078 [ASSURED] mark=25165825
[UPDATE] tcp 6 10 CLOSE src=192.168.7.105 dst=17.253.57.219 sport=49574 dport=443 src=17.253.57.219 dst=87.138.198.79 sport=443 dport=5078 [ASSURED] mark=25165825
[DESTROY] tcp 6 CLOSE src=192.168.7.105 dst=17.253.57.219 sport=49574 dport=443 packets=15 bytes=2688 src=17.253.57.219 dst=87.138.198.79 sport=443 dport=5078 packets=18 bytes=7172 [ASSURED] mark=25165825 delta-time=126
Quoted 30 lines
Quoted 6 lines
They way thinks are right now we are open to a race condition from the reverse side of the connection to reoffload the connection while a FIN or RST is not processed by the netfilter code running after the flowtable code.
The conenction is still in TCP established during that window and another packet can just push it back to the flowtable while the FIN or RST is not processed yet.I don't see how:
static void nft_flow_offload_eval(const struct
nft_expr*expr,... switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) { case IPPROTO_TCP: tcph = skb_header_pointer(pkt->skb, nft_thoff(pkt), sizeof(_tcph), &_tcph); if (unlikely(!tcph || tcph->fin || tcph->rst || !nf_conntrack_tcp_established(ct))) goto out;this would now be either in FIN/CLOSE state.
FIN, RST packet does not trigger re-offload. And ACK packet would find the entry in !nf_conntrack_tcp_established(ct).
What path could trigger re-offload after my latest patch?
For the flow timeout case (where flow entry is released and packets goes back to classic conntrack path) re-offload is possible, but that is a feature.
Pablo Neira Ayuso
maintainerQuoted 4 lines · Sven Auhagen
Quoted 3 lines · Pablo Neira Ayuso
Quoted 2 lines · Sven Auhagen
Quoted 1 line · Pablo Neira Ayuso
On Wed, Mar 20, 2024 at 10:20:29AM +0100, Sven Auhagen wrote:
[...]
Quoted 21 lines
Quoted 16 lines
Quoted 2 lines
I think for it to be foolproof we need
to migrate the TCP state as well inflow_offload_teardown_tcpto FIN or CLOSE.My patch already does it:
(quoted diff) +10
-0+void flow_offload_teardown_tcp(struct flow_offload *flow, bool fin) +{ + enum tcp_conntrack tcp_state; + + if (fin) + tcp_state = TCP_CONNTRACK_FIN_WAIT; + else /* rst */ + tcp_state = TCP_CONNTRACK_CLOSE; + + flow_offload_fixup_tcp(nf_ct_net(flow->ct), flow->ct, tcp_state);Quoted 1 line
flow_offload_fixup_tcp()updates the TCP state to FIN / CLOSE state.Ah you are correct.
Never the less I can tell you that I still see this problem with the patch attached:
Quoted 4 lines
[UPDATE] tcp 6 120
FIN_WAITsrc=192.168.7.105 dst=17.253.57.219 sport=49574 dport=443 src=17.253.57.219 dst=87.138.198.79 sport=443 dport=5078 [OFFLOAD] mark=25165825
[UPDATE] tcp 6 30LAST_ACKsrc=192.168.7.105 dst=17.253.57.219 sport=49574 dport=443 src=17.253.57.219 dst=87.138.198.79 sport=443 dport=5078 [ASSURED] mark=25165825
[UPDATE] tcp 6 10 CLOSE src=192.168.7.105 dst=17.253.57.219 sport=49574 dport=443 src=17.253.57.219 dst=87.138.198.79 sport=443 dport=5078 [ASSURED] mark=25165825
[DESTROY] tcp 6 CLOSE src=192.168.7.105 dst=17.253.57.219 sport=49574 dport=443 packets=15 bytes=2688 src=17.253.57.219 dst=87.138.198.79 sport=443 dport=5078 packets=18 bytes=7172 [ASSURED] mark=25165825 delta-time=126
Just to make sure, are you testing with these two patches?
https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/
https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/
Quoted 32 lines · Pablo Neira Ayuso
Quoted 4 lines · Sven Auhagen
Quoted 3 lines · Pablo Neira Ayuso
Quoted 2 lines · Sven Auhagen
Quoted 1 line · Pablo Neira Ayuso
On Wed, Mar 20, 2024 at 10:20:29AM +0100, Sven Auhagen wrote:
[...]
Quoted 21 lines
Quoted 16 lines
Quoted 2 lines
I think for it to be foolproof we need
to migrate the TCP state as well inflow_offload_teardown_tcpto FIN or CLOSE.My patch already does it:
(quoted diff) +10
-0+void flow_offload_teardown_tcp(struct flow_offload *flow, bool fin) +{ + enum tcp_conntrack tcp_state; + + if (fin) + tcp_state = TCP_CONNTRACK_FIN_WAIT; + else /* rst */ + tcp_state = TCP_CONNTRACK_CLOSE; + + flow_offload_fixup_tcp(nf_ct_net(flow->ct), flow->ct, tcp_state);Quoted 1 line
flow_offload_fixup_tcp()updates the TCP state to FIN / CLOSE state.Ah you are correct.
Never the less I can tell you that I still see this problem with the patch attached:Quoted 4 lines
[UPDATE] tcp 6 120
FIN_WAITsrc=192.168.7.105 dst=17.253.57.219 sport=49574 dport=443 src=17.253.57.219 dst=87.138.198.79 sport=443 dport=5078 [OFFLOAD] mark=25165825
[UPDATE] tcp 6 30LAST_ACKsrc=192.168.7.105 dst=17.253.57.219 sport=49574 dport=443 src=17.253.57.219 dst=87.138.198.79 sport=443 dport=5078 [ASSURED] mark=25165825
[UPDATE] tcp 6 10 CLOSE src=192.168.7.105 dst=17.253.57.219 sport=49574 dport=443 src=17.253.57.219 dst=87.138.198.79 sport=443 dport=5078 [ASSURED] mark=25165825
[DESTROY] tcp 6 CLOSE src=192.168.7.105 dst=17.253.57.219 sport=49574 dport=443 packets=15 bytes=2688 src=17.253.57.219 dst=87.138.198.79 sport=443 dport=5078 packets=18 bytes=7172 [ASSURED] mark=25165825 delta-time=126
Quoted 4 lines
Just to make sure, are you testing with these two patches?
https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/
https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/
I am currently testing with v1 of these patches.
I need to wait until later today to reboot the production system for v2.
Quoted 117 lines · Pablo Neira Ayuso
Quoted 76 lines · Sven Auhagen
Quoted 75 lines · Pablo Neira Ayuso
Quoted 63 lines · Sven Auhagen
Quoted 53 lines · Pablo Neira Ayuso
Quoted 43 lines · Sven Auhagen
Quoted 42 lines · Pablo Neira Ayuso
Hi Sven,
Quoted 1 line · Sven Auhagen
On Mon, Mar 18, 2024 at 10:39:15AM +0100, Pablo Neira Ayuso wrote:
[...]
Quoted 37 lines
Quoted 15 lines
net/netfilter/nf_flow_table_core.c +3
-3@@ -165,10 +165,22 @@ void flow_offload_route_init(struct flow_offload *flow, }EXPORT_SYMBOL_GPL (flow_offload_route_init); -static void flow_offload_fixup_tcp (struct ip_ct_tcp *tcp) +static s32 flow_offload_fixup_tcp (struct net *net,struct nf_conn *ct, +enum tcp_conntrack tcp_state) { - tcp->seen[0 ].td_maxwin =0 ; - tcp->seen[1 ].td_maxwin =0 ; +struct nf_tcp_net *tn =nf_tcp_pernet (net);net/netfilter/nf_flow_table_core.c void flow_offload_route_init(struct flow_offload *flow, · line 181
Quoted 10 lines
net/netfilter/nf_flow_table_core.c +10
-0+ + ct->proto.tcp.state = tcp_state; + ct->proto.tcp.seen[0 ].td_maxwin =0 ; + ct->proto.tcp.seen[1 ].td_maxwin =0 ; + +/* Similar to mid-connection pickup with loose=1. +* Avoid large ESTABLISHED timeout. +*/ +if (tcp_state ==TCP_CONNTRACK_ESTABLISHED ) +return tn->timeouts[TCP_CONNTRACK_UNACK ];Hi Pablo,
I tested the patch but the part that sets the timout to UNACK is not very practical.
For example my long running SSH connections get killed off by the firewall regularly now while beeing ESTABLISHED:[NEW] tcp 6 120
SYN_SENTsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 [UNREPLIED] src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 60SYN_RECVsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 86400 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 [OFFLOAD] mark=16777216Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
[DESTROY] tcp 6 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=54941 dport=22 packets=133 bytes=13033 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=54941 packets=95 bytes=15004 [ASSURED] mark=16777216 delta-time=1036
I would remove the if case here.
OK, I remove it and post a v2. Thanks!
Thanks and also the hardcoded
TCP_CONNTRACK_ESTABLISHEDinflow_offload_fixup_ctshould be reverted to the real tcp statect->proto.tcp.state.Quoted 8 lines
ct->proto.tcp.statecontains the state that was observed before handling over this flow to the flowtable, in most cases, this should beTCP_CONNTRACK_ESTABLISHED.Quoted 1 line
This way we always set the current TCP timeout.
I can keep it to
ct->proto.tcp.statebut I wonder if it is better to use a well known state such asTCP_CONNTRACK_ESTABLISHEDto pick up from.Quoted 6 lines
In case of a race condition or if something is off like my
TCP_FINthat is beeing offloaded again setting to to ESTABLISHED hard coded will make the e.g. FIN or CLOSE a very long state.
It is not guaranteed that we are still in ESTABLISHED when this code runs. Also for example we could have seen both FIN already before the flowtable gc runs.OK, I just posted a v2, leave things as is. I agree it is better to only address the issue you are observing at this time, it is possible to revisit later.
Quoted 5 lines
Quoted 1 line
Thanks!
Thanks, I will give it another try.
I think for it to be foolproof we need
to migrate the TCP state as well inflow_offload_teardown_tcpto FIN or CLOSE.My patch already does it:
(quoted diff) +10
-0+void flow_offload_teardown_tcp(struct flow_offload *flow, bool fin) +{ + enum tcp_conntrack tcp_state; + + if (fin) + tcp_state = TCP_CONNTRACK_FIN_WAIT; + else /* rst */ + tcp_state = TCP_CONNTRACK_CLOSE; + + flow_offload_fixup_tcp(nf_ct_net(flow->ct), flow->ct, tcp_state);
flow_offload_fixup_tcp()updates the TCP state to FIN / CLOSE state.Quoted 5 lines
They way thinks are right now we are open to a race condition from the reverse side of the connection to reoffload the connection while a FIN or RST is not processed by the netfilter code running after the flowtable code.
The conenction is still in TCP established during that window and another packet can just push it back to the flowtable while the FIN or RST is not processed yet.I don't see how:
static void nft_flow_offload_eval(const struct
nft_expr*expr,... switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) { case IPPROTO_TCP: tcph = skb_header_pointer(pkt->skb, nft_thoff(pkt), sizeof(_tcph), &_tcph); if (unlikely(!tcph || tcph->fin || tcph->rst || !nf_conntrack_tcp_established(ct))) goto out;
Quoted 6 lines
this would now be either in FIN/CLOSE state.
FIN, RST packet does not trigger re-offload. And ACK packet would find the entry in !nf_conntrack_tcp_established(ct).
What path could trigger re-offload after my latest patch?
From looking through the nf conntrack tcp code you need to spin_lock the TCP state change to avoid a race with another packet.
Quoted 4 lines
For the flow timeout case (where flow entry is released and packets goes back to classic conntrack path) re-offload is possible, but that is a feature.
Pablo Neira Ayuso
maintainerQuoted 120 lines · Sven Auhagen
Quoted 119 lines · Pablo Neira Ayuso
Quoted 76 lines · Sven Auhagen
Quoted 75 lines · Pablo Neira Ayuso
Quoted 63 lines · Sven Auhagen
Quoted 53 lines · Pablo Neira Ayuso
Quoted 43 lines · Sven Auhagen
Quoted 42 lines · Pablo Neira Ayuso
Hi Sven,
Quoted 1 line · Sven Auhagen
On Mon, Mar 18, 2024 at 10:39:15AM +0100, Pablo Neira Ayuso wrote:
[...]
Quoted 37 lines
Quoted 15 lines
net/netfilter/nf_flow_table_core.c +3
-3@@ -165,10 +165,22 @@ void flow_offload_route_init(struct flow_offload *flow, }EXPORT_SYMBOL_GPL (flow_offload_route_init); -static void flow_offload_fixup_tcp (struct ip_ct_tcp *tcp) +static s32 flow_offload_fixup_tcp (struct net *net,struct nf_conn *ct, +enum tcp_conntrack tcp_state) { - tcp->seen[0 ].td_maxwin =0 ; - tcp->seen[1 ].td_maxwin =0 ; +struct nf_tcp_net *tn =nf_tcp_pernet (net);net/netfilter/nf_flow_table_core.c void flow_offload_route_init(struct flow_offload *flow, · line 181
Quoted 10 lines
net/netfilter/nf_flow_table_core.c +10
-0+ + ct->proto.tcp.state = tcp_state; + ct->proto.tcp.seen[0 ].td_maxwin =0 ; + ct->proto.tcp.seen[1 ].td_maxwin =0 ; + +/* Similar to mid-connection pickup with loose=1. +* Avoid large ESTABLISHED timeout. +*/ +if (tcp_state ==TCP_CONNTRACK_ESTABLISHED ) +return tn->timeouts[TCP_CONNTRACK_UNACK ];Hi Pablo,
I tested the patch but the part that sets the timout to UNACK is not very practical.
For example my long running SSH connections get killed off by the firewall regularly now while beeing ESTABLISHED:[NEW] tcp 6 120
SYN_SENTsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 [UNREPLIED] src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 60SYN_RECVsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 86400 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 [OFFLOAD] mark=16777216Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
[DESTROY] tcp 6 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=54941 dport=22 packets=133 bytes=13033 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=54941 packets=95 bytes=15004 [ASSURED] mark=16777216 delta-time=1036
I would remove the if case here.
OK, I remove it and post a v2. Thanks!
Thanks and also the hardcoded
TCP_CONNTRACK_ESTABLISHEDinflow_offload_fixup_ctshould be reverted to the real tcp statect->proto.tcp.state.Quoted 8 lines
ct->proto.tcp.statecontains the state that was observed before handling over this flow to the flowtable, in most cases, this should beTCP_CONNTRACK_ESTABLISHED.Quoted 1 line
This way we always set the current TCP timeout.
I can keep it to
ct->proto.tcp.statebut I wonder if it is better to use a well known state such asTCP_CONNTRACK_ESTABLISHEDto pick up from.Quoted 6 lines
In case of a race condition or if something is off like my
TCP_FINthat is beeing offloaded again setting to to ESTABLISHED hard coded will make the e.g. FIN or CLOSE a very long state.
It is not guaranteed that we are still in ESTABLISHED when this code runs. Also for example we could have seen both FIN already before the flowtable gc runs.OK, I just posted a v2, leave things as is. I agree it is better to only address the issue you are observing at this time, it is possible to revisit later.
Quoted 5 lines
Quoted 1 line
Thanks!
Thanks, I will give it another try.
I think for it to be foolproof we need
to migrate the TCP state as well inflow_offload_teardown_tcpto FIN or CLOSE.My patch already does it:
(quoted diff) +10
-0+void flow_offload_teardown_tcp(struct flow_offload *flow, bool fin) +{ + enum tcp_conntrack tcp_state; + + if (fin) + tcp_state = TCP_CONNTRACK_FIN_WAIT; + else /* rst */ + tcp_state = TCP_CONNTRACK_CLOSE; + + flow_offload_fixup_tcp(nf_ct_net(flow->ct), flow->ct, tcp_state);
flow_offload_fixup_tcp()updates the TCP state to FIN / CLOSE state.Quoted 5 lines
They way thinks are right now we are open to a race condition from the reverse side of the connection to reoffload the connection while a FIN or RST is not processed by the netfilter code running after the flowtable code.
The conenction is still in TCP established during that window and another packet can just push it back to the flowtable while the FIN or RST is not processed yet.I don't see how:
static void nft_flow_offload_eval(const struct
nft_expr*expr,... switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) { case IPPROTO_TCP: tcph = skb_header_pointer(pkt->skb, nft_thoff(pkt), sizeof(_tcph), &_tcph); if (unlikely(!tcph || tcph->fin || tcph->rst || !nf_conntrack_tcp_established(ct))) goto out;this would now be either in FIN/CLOSE state.
Quoted 7 lines
Quoted 4 lines
FIN, RST packet does not trigger re-offload. And ACK packet would find the entry in !nf_conntrack_tcp_established(ct).
What path could trigger re-offload after my latest patch?
From looking through the nf conntrack tcp code you need to
spin_lockthe TCP state change to avoid a race with another packet.
The flowtable owns the flow, packets belonging the flow cannot update the TCP state while the flow is offloaded to the flowtable.
Once _TEARDOWN flag is set on, then packets get back to classic conntrack path.
I don't see how such race can happen.
Quoted 126 lines · Pablo Neira Ayuso
Quoted 125 lines · Sven Auhagen
Quoted 123 lines · Pablo Neira Ayuso
Quoted 76 lines · Sven Auhagen
Quoted 75 lines · Pablo Neira Ayuso
Quoted 63 lines · Sven Auhagen
Quoted 53 lines · Pablo Neira Ayuso
Quoted 43 lines · Sven Auhagen
Quoted 42 lines · Pablo Neira Ayuso
Hi Sven,
Quoted 1 line · Sven Auhagen
On Mon, Mar 18, 2024 at 10:39:15AM +0100, Pablo Neira Ayuso wrote:
[...]
Quoted 37 lines
Quoted 15 lines
net/netfilter/nf_flow_table_core.c +3
-3@@ -165,10 +165,22 @@ void flow_offload_route_init(struct flow_offload *flow, }EXPORT_SYMBOL_GPL (flow_offload_route_init); -static void flow_offload_fixup_tcp (struct ip_ct_tcp *tcp) +static s32 flow_offload_fixup_tcp (struct net *net,struct nf_conn *ct, +enum tcp_conntrack tcp_state) { - tcp->seen[0 ].td_maxwin =0 ; - tcp->seen[1 ].td_maxwin =0 ; +struct nf_tcp_net *tn =nf_tcp_pernet (net);net/netfilter/nf_flow_table_core.c void flow_offload_route_init(struct flow_offload *flow, · line 181
Quoted 10 lines
net/netfilter/nf_flow_table_core.c +10
-0+ + ct->proto.tcp.state = tcp_state; + ct->proto.tcp.seen[0 ].td_maxwin =0 ; + ct->proto.tcp.seen[1 ].td_maxwin =0 ; + +/* Similar to mid-connection pickup with loose=1. +* Avoid large ESTABLISHED timeout. +*/ +if (tcp_state ==TCP_CONNTRACK_ESTABLISHED ) +return tn->timeouts[TCP_CONNTRACK_UNACK ];Hi Pablo,
I tested the patch but the part that sets the timout to UNACK is not very practical.
For example my long running SSH connections get killed off by the firewall regularly now while beeing ESTABLISHED:[NEW] tcp 6 120
SYN_SENTsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 [UNREPLIED] src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 60SYN_RECVsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 86400 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 [OFFLOAD] mark=16777216Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
[DESTROY] tcp 6 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=54941 dport=22 packets=133 bytes=13033 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=54941 packets=95 bytes=15004 [ASSURED] mark=16777216 delta-time=1036
I would remove the if case here.
OK, I remove it and post a v2. Thanks!
Thanks and also the hardcoded
TCP_CONNTRACK_ESTABLISHEDinflow_offload_fixup_ctshould be reverted to the real tcp statect->proto.tcp.state.Quoted 8 lines
ct->proto.tcp.statecontains the state that was observed before handling over this flow to the flowtable, in most cases, this should beTCP_CONNTRACK_ESTABLISHED.Quoted 1 line
This way we always set the current TCP timeout.
I can keep it to
ct->proto.tcp.statebut I wonder if it is better to use a well known state such asTCP_CONNTRACK_ESTABLISHEDto pick up from.Quoted 6 lines
In case of a race condition or if something is off like my
TCP_FINthat is beeing offloaded again setting to to ESTABLISHED hard coded will make the e.g. FIN or CLOSE a very long state.
It is not guaranteed that we are still in ESTABLISHED when this code runs. Also for example we could have seen both FIN already before the flowtable gc runs.OK, I just posted a v2, leave things as is. I agree it is better to only address the issue you are observing at this time, it is possible to revisit later.
Quoted 5 lines
Quoted 1 line
Thanks!
Thanks, I will give it another try.
I think for it to be foolproof we need
to migrate the TCP state as well inflow_offload_teardown_tcpto FIN or CLOSE.My patch already does it:
(quoted diff) +10
-0+void flow_offload_teardown_tcp(struct flow_offload *flow, bool fin) +{ + enum tcp_conntrack tcp_state; + + if (fin) + tcp_state = TCP_CONNTRACK_FIN_WAIT; + else /* rst */ + tcp_state = TCP_CONNTRACK_CLOSE; + + flow_offload_fixup_tcp(nf_ct_net(flow->ct), flow->ct, tcp_state);
flow_offload_fixup_tcp()updates the TCP state to FIN / CLOSE state.Quoted 5 lines
They way thinks are right now we are open to a race condition from the reverse side of the connection to reoffload the connection while a FIN or RST is not processed by the netfilter code running after the flowtable code.
The conenction is still in TCP established during that window and another packet can just push it back to the flowtable while the FIN or RST is not processed yet.I don't see how:
static void nft_flow_offload_eval(const struct
nft_expr*expr,... switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) { case IPPROTO_TCP: tcph = skb_header_pointer(pkt->skb, nft_thoff(pkt), sizeof(_tcph), &_tcph); if (unlikely(!tcph || tcph->fin || tcph->rst || !nf_conntrack_tcp_established(ct))) goto out;this would now be either in FIN/CLOSE state.
FIN, RST packet does not trigger re-offload. And ACK packet would find the entry in !nf_conntrack_tcp_established(ct).
What path could trigger re-offload after my latest patch?
Quoted 8 lines
Quoted 2 lines
From looking through the nf conntrack tcp code you need to
spin_lockthe TCP state change to avoid a race with another packet.The flowtable owns the flow, packets belonging the flow cannot update the TCP state while the flow is offloaded to the flowtable.
Once
_TEARDOWNflag is set on, then packets get back to classic conntrack path.
Hmm alright, something is going wrong somewhere and it looks a lot like a race condition :)
I mean just in theory it is not guaranteed that both directions send all packets through the flowtable just because it is offloaded. A variety of error checks might send a packet back to the slow path.
Quoted 2 lines
I don't see how such race can happen.
Pablo Neira Ayuso
maintainerQuoted 130 lines · Sven Auhagen
Quoted 129 lines · Pablo Neira Ayuso
Quoted 127 lines · Sven Auhagen
Quoted 117 lines · Pablo Neira Ayuso
Quoted 76 lines · Sven Auhagen
Quoted 75 lines · Pablo Neira Ayuso
Quoted 63 lines · Sven Auhagen
Quoted 53 lines · Pablo Neira Ayuso
Quoted 43 lines · Sven Auhagen
Quoted 42 lines · Pablo Neira Ayuso
Hi Sven,
Quoted 1 line · Sven Auhagen
On Mon, Mar 18, 2024 at 10:39:15AM +0100, Pablo Neira Ayuso wrote:
[...]
Quoted 37 lines
Quoted 15 lines
net/netfilter/nf_flow_table_core.c +3
-3@@ -165,10 +165,22 @@ void flow_offload_route_init(struct flow_offload *flow, }EXPORT_SYMBOL_GPL (flow_offload_route_init); -static void flow_offload_fixup_tcp (struct ip_ct_tcp *tcp) +static s32 flow_offload_fixup_tcp (struct net *net,struct nf_conn *ct, +enum tcp_conntrack tcp_state) { - tcp->seen[0 ].td_maxwin =0 ; - tcp->seen[1 ].td_maxwin =0 ; +struct nf_tcp_net *tn =nf_tcp_pernet (net);net/netfilter/nf_flow_table_core.c void flow_offload_route_init(struct flow_offload *flow, · line 181
Quoted 10 lines
net/netfilter/nf_flow_table_core.c +10
-0+ + ct->proto.tcp.state = tcp_state; + ct->proto.tcp.seen[0 ].td_maxwin =0 ; + ct->proto.tcp.seen[1 ].td_maxwin =0 ; + +/* Similar to mid-connection pickup with loose=1. +* Avoid large ESTABLISHED timeout. +*/ +if (tcp_state ==TCP_CONNTRACK_ESTABLISHED ) +return tn->timeouts[TCP_CONNTRACK_UNACK ];Hi Pablo,
I tested the patch but the part that sets the timout to UNACK is not very practical.
For example my long running SSH connections get killed off by the firewall regularly now while beeing ESTABLISHED:[NEW] tcp 6 120
SYN_SENTsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 [UNREPLIED] src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 60SYN_RECVsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 86400 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 [OFFLOAD] mark=16777216Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
[DESTROY] tcp 6 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=54941 dport=22 packets=133 bytes=13033 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=54941 packets=95 bytes=15004 [ASSURED] mark=16777216 delta-time=1036
I would remove the if case here.
OK, I remove it and post a v2. Thanks!
Thanks and also the hardcoded
TCP_CONNTRACK_ESTABLISHEDinflow_offload_fixup_ctshould be reverted to the real tcp statect->proto.tcp.state.Quoted 8 lines
ct->proto.tcp.statecontains the state that was observed before handling over this flow to the flowtable, in most cases, this should beTCP_CONNTRACK_ESTABLISHED.Quoted 1 line
This way we always set the current TCP timeout.
I can keep it to
ct->proto.tcp.statebut I wonder if it is better to use a well known state such asTCP_CONNTRACK_ESTABLISHEDto pick up from.Quoted 6 lines
In case of a race condition or if something is off like my
TCP_FINthat is beeing offloaded again setting to to ESTABLISHED hard coded will make the e.g. FIN or CLOSE a very long state.
It is not guaranteed that we are still in ESTABLISHED when this code runs. Also for example we could have seen both FIN already before the flowtable gc runs.OK, I just posted a v2, leave things as is. I agree it is better to only address the issue you are observing at this time, it is possible to revisit later.
Quoted 5 lines
Quoted 1 line
Thanks!
Thanks, I will give it another try.
I think for it to be foolproof we need
to migrate the TCP state as well inflow_offload_teardown_tcpto FIN or CLOSE.My patch already does it:
(quoted diff) +10
-0+void flow_offload_teardown_tcp(struct flow_offload *flow, bool fin) +{ + enum tcp_conntrack tcp_state; + + if (fin) + tcp_state = TCP_CONNTRACK_FIN_WAIT; + else /* rst */ + tcp_state = TCP_CONNTRACK_CLOSE; + + flow_offload_fixup_tcp(nf_ct_net(flow->ct), flow->ct, tcp_state);
flow_offload_fixup_tcp()updates the TCP state to FIN / CLOSE state.Quoted 5 lines
They way thinks are right now we are open to a race condition from the reverse side of the connection to reoffload the connection while a FIN or RST is not processed by the netfilter code running after the flowtable code.
The conenction is still in TCP established during that window and another packet can just push it back to the flowtable while the FIN or RST is not processed yet.I don't see how:
static void nft_flow_offload_eval(const struct
nft_expr*expr,... switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) { case IPPROTO_TCP: tcph = skb_header_pointer(pkt->skb, nft_thoff(pkt), sizeof(_tcph), &_tcph); if (unlikely(!tcph || tcph->fin || tcph->rst || !nf_conntrack_tcp_established(ct))) goto out;Quoted 6 lines
this would now be either in FIN/CLOSE state.
FIN, RST packet does not trigger re-offload. And ACK packet would find the entry in !nf_conntrack_tcp_established(ct).
What path could trigger re-offload after my latest patch?
From looking through the nf conntrack tcp code you need to
spin_lockthe TCP state change to avoid a race with another packet.
Quoted 8 lines
Quoted 5 lines
The flowtable owns the flow, packets belonging the flow cannot update the TCP state while the flow is offloaded to the flowtable.
Once
_TEARDOWNflag is set on, then packets get back to classic conntrack path.Hmm alright, something is going wrong somewhere and it looks a lot like a race condition :)
This check is racy, another packet could alter the ct state right after it evaluates true.
switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) {
case IPPROTO_TCP:
tcph = skb_header_pointer(pkt->skb, nft_thoff(pkt),
sizeof(_tcph), &_tcph);
if (unlikely(!tcph || tcph->fin || tcph->rst ||
!nf_conntrack_tcp_established(ct))) <-------
goto out;Sequence would be:
1) flow expires (after 30 seconds), goes back to conntrack in established state
2) packet re-offloads the flow and nf_conntrack_tcp_established(ct) evaluates true.
3) FIN packet races to update conntrack getting to FIN_WAIT while re-offloading the flow.
then you see FIN_WAIT and offload, it could happen with an expired flow that goes back to conntrack.
But I am not sure yet if this is the case you're observing there.
Quoted 3 lines
I mean just in theory it is not guaranteed that both directions send all packets through the flowtable just because it is offloaded. A variety of error checks might send a packet back to the slow path.
There is the mtu check that is lacking the teardown, but that should only affect UDP traffic. A patch from Felix decided has cached the mtu in the flow entry. That is also probably convenient to have, but it looks like a different issue, I will also post a patch for this issue.
net/netfilter/nf_flow_table_ip.c +6 -2
@@ -372,8 +372,10 @@ static int nf_flow_offload_forward(struct nf_flowtable_ctx *ctx, flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); mtu = flow->tuplehash[dir].tuple.mtu + ctx->offset; -if (unlikely (nf_flow_exceeds_mtu (skb, mtu))) +if (unlikely (nf_flow_exceeds_mtu (skb, mtu))) { +flow_offload_teardown (flow);return 0 ; + } iph = (struct iphdr *)(skb_network_header (skb) + ctx->offset); thoff = (iph->ihl *4 ) + ctx->offset;
@@ -651,8 +653,10 @@ static int nf_flow_offload_ipv6_forward(struct nf_flowtable_ctx *ctx, flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); mtu = flow->tuplehash[dir].tuple.mtu + ctx->offset; -if (unlikely (nf_flow_exceeds_mtu (skb, mtu))) +if (unlikely (nf_flow_exceeds_mtu (skb, mtu))) { +flow_offload_teardown (flow);return 0 ; + } ip6h = (struct ipv6hdr *)(skb_network_header (skb) + ctx->offset); thoff =sizeof (*ip6h) + ctx->offset;
Quoted 163 lines · Pablo Neira Ayuso
Quoted 130 lines · Sven Auhagen
Quoted 129 lines · Pablo Neira Ayuso
Quoted 127 lines · Sven Auhagen
Quoted 117 lines · Pablo Neira Ayuso
Quoted 76 lines · Sven Auhagen
Quoted 75 lines · Pablo Neira Ayuso
Quoted 63 lines · Sven Auhagen
Quoted 53 lines · Pablo Neira Ayuso
Quoted 43 lines · Sven Auhagen
Quoted 42 lines · Pablo Neira Ayuso
Hi Sven,
Quoted 1 line · Sven Auhagen
On Mon, Mar 18, 2024 at 10:39:15AM +0100, Pablo Neira Ayuso wrote:
[...]
Quoted 37 lines
Quoted 25 lines
diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index a0571339239c..481fe3d96bbc 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -165,10 +165,22 @@ void flow_offload_route_init(struct flow_offload *flow,
}
EXPORT_SYMBOL_GPL(flow_offload_route_init);-static void flow_offload_fixup_tcp(struct ip_ct_tcp *tcp)
+static s32 flow_offload_fixup_tcp(struct net *net, struct nf_conn *ct,
+ enum tcp_conntrack tcp_state)
{
- tcp->seen[0].td_maxwin = 0;
- tcp->seen[1].td_maxwin = 0;
+ struct nf_tcp_net *tn = nf_tcp_pernet(net);
+
+ ct->proto.tcp.state = tcp_state;
+ ct->proto.tcp.seen[0].td_maxwin = 0;
+ ct->proto.tcp.seen[1].td_maxwin = 0;
+
+ /* Similar to mid-connection pickup with loose=1.
+ * Avoid large ESTABLISHED timeout.
+ */
+ if (tcp_state == TCP_CONNTRACK_ESTABLISHED)
+ return tn->timeouts[TCP_CONNTRACK_UNACK];Hi Pablo,
I tested the patch but the part that sets the timout to UNACK is not very practical.
For example my long running SSH connections get killed off by the firewall regularly now while beeing ESTABLISHED:[NEW] tcp 6 120
SYN_SENTsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 [UNREPLIED] src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 60SYN_RECVsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 86400 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 [OFFLOAD] mark=16777216Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
[DESTROY] tcp 6 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=54941 dport=22 packets=133 bytes=13033 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=54941 packets=95 bytes=15004 [ASSURED] mark=16777216 delta-time=1036
I would remove the if case here.
OK, I remove it and post a v2. Thanks!
Thanks and also the hardcoded
TCP_CONNTRACK_ESTABLISHEDinflow_offload_fixup_ctshould be reverted to the real tcp statect->proto.tcp.state.Quoted 8 lines
ct->proto.tcp.statecontains the state that was observed before handling over this flow to the flowtable, in most cases, this should beTCP_CONNTRACK_ESTABLISHED.Quoted 1 line
This way we always set the current TCP timeout.
I can keep it to
ct->proto.tcp.statebut I wonder if it is better to use a well known state such asTCP_CONNTRACK_ESTABLISHEDto pick up from.Quoted 6 lines
In case of a race condition or if something is off like my
TCP_FINthat is beeing offloaded again setting to to ESTABLISHED hard coded will make the e.g. FIN or CLOSE a very long state.
It is not guaranteed that we are still in ESTABLISHED when this code runs. Also for example we could have seen both FIN already before the flowtable gc runs.OK, I just posted a v2, leave things as is. I agree it is better to only address the issue you are observing at this time, it is possible to revisit later.
Quoted 5 lines
Quoted 1 line
Thanks!
Thanks, I will give it another try.
I think for it to be foolproof we need
to migrate the TCP state as well inflow_offload_teardown_tcpto FIN or CLOSE.My patch already does it:
(quoted diff) +10
-0+void flow_offload_teardown_tcp(struct flow_offload *flow, bool fin) +{ + enum tcp_conntrack tcp_state; + + if (fin) + tcp_state = TCP_CONNTRACK_FIN_WAIT; + else /* rst */ + tcp_state = TCP_CONNTRACK_CLOSE; + + flow_offload_fixup_tcp(nf_ct_net(flow->ct), flow->ct, tcp_state);
flow_offload_fixup_tcp()updates the TCP state to FIN / CLOSE state.Quoted 5 lines
They way thinks are right now we are open to a race condition from the reverse side of the connection to reoffload the connection while a FIN or RST is not processed by the netfilter code running after the flowtable code.
The conenction is still in TCP established during that window and another packet can just push it back to the flowtable while the FIN or RST is not processed yet.I don't see how:
static void nft_flow_offload_eval(const struct
nft_expr*expr,... switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) { case IPPROTO_TCP: tcph = skb_header_pointer(pkt->skb, nft_thoff(pkt), sizeof(_tcph), &_tcph); if (unlikely(!tcph || tcph->fin || tcph->rst || !nf_conntrack_tcp_established(ct))) goto out;Quoted 6 lines
this would now be either in FIN/CLOSE state.
FIN, RST packet does not trigger re-offload. And ACK packet would find the entry in !nf_conntrack_tcp_established(ct).
What path could trigger re-offload after my latest patch?
From looking through the nf conntrack tcp code you need to
spin_lockthe TCP state change to avoid a race with another packet.Quoted 8 lines
Quoted 5 lines
The flowtable owns the flow, packets belonging the flow cannot update the TCP state while the flow is offloaded to the flowtable.
Once
_TEARDOWNflag is set on, then packets get back to classic conntrack path.Hmm alright, something is going wrong somewhere and it looks a lot like a race condition :)
This check is racy, another packet could alter the ct state right after it evaluates true.
switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) { case IPPROTO_TCP: tcph = skb_header_pointer(pkt->skb, nft_thoff(pkt), sizeof(_tcph), &_tcph); if (unlikely(!tcph || tcph->fin || tcph->rst || !nf_conntrack_tcp_established(ct))) <------- goto out;Sequence would be:
1) flow expires (after 30 seconds), goes back to conntrack in established state
2) packet re-offloads the flow andnf_conntrack_tcp_established(ct)evaluates true.
3) FIN packet races to update conntrack getting toFIN_WAITwhile re-offloading the flow.then you see
FIN_WAITand offload, it could happen with an expired flow that goes back to conntrack.But I am not sure yet if this is the case you're observing there.
Quoted 8 lines
Quoted 3 lines
I mean just in theory it is not guaranteed that both directions send all packets through the flowtable just because it is offloaded. A variety of error checks might send a packet back to the slow path.
There is the mtu check that is lacking the teardown, but that should only affect UDP traffic. A patch from Felix decided has cached the mtu in the flow entry. That is also probably convenient to have, but it looks like a different issue, I will also post a patch for this issue.
I would be suprised if the MTU is an issue.
I will also add a counter/printk to the two checks from your patch just to make sure. I will report back with my testing of v2 of the patches.
Quoted 163 lines · Pablo Neira Ayuso
Quoted 130 lines · Sven Auhagen
Quoted 129 lines · Pablo Neira Ayuso
Quoted 127 lines · Sven Auhagen
Quoted 117 lines · Pablo Neira Ayuso
Quoted 76 lines · Sven Auhagen
Quoted 75 lines · Pablo Neira Ayuso
Quoted 63 lines · Sven Auhagen
Quoted 53 lines · Pablo Neira Ayuso
Quoted 43 lines · Sven Auhagen
Quoted 42 lines · Pablo Neira Ayuso
Hi Sven,
Quoted 1 line · Sven Auhagen
On Mon, Mar 18, 2024 at 10:39:15AM +0100, Pablo Neira Ayuso wrote:
[...]
Quoted 37 lines
Quoted 25 lines
diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index a0571339239c..481fe3d96bbc 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -165,10 +165,22 @@ void flow_offload_route_init(struct flow_offload *flow,
}
EXPORT_SYMBOL_GPL(flow_offload_route_init);-static void flow_offload_fixup_tcp(struct ip_ct_tcp *tcp)
+static s32 flow_offload_fixup_tcp(struct net *net, struct nf_conn *ct,
+ enum tcp_conntrack tcp_state)
{
- tcp->seen[0].td_maxwin = 0;
- tcp->seen[1].td_maxwin = 0;
+ struct nf_tcp_net *tn = nf_tcp_pernet(net);
+
+ ct->proto.tcp.state = tcp_state;
+ ct->proto.tcp.seen[0].td_maxwin = 0;
+ ct->proto.tcp.seen[1].td_maxwin = 0;
+
+ /* Similar to mid-connection pickup with loose=1.
+ * Avoid large ESTABLISHED timeout.
+ */
+ if (tcp_state == TCP_CONNTRACK_ESTABLISHED)
+ return tn->timeouts[TCP_CONNTRACK_UNACK];Hi Pablo,
I tested the patch but the part that sets the timout to UNACK is not very practical.
For example my long running SSH connections get killed off by the firewall regularly now while beeing ESTABLISHED:[NEW] tcp 6 120
SYN_SENTsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 [UNREPLIED] src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 60SYN_RECVsrc=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 mark=16777216
[UPDATE] tcp 6 86400 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=55582 dport=22 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=55582 [OFFLOAD] mark=16777216Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
[DESTROY] tcp 6 ESTABLISHED src=192.168.6.55 dst=192.168.10.22 sport=54941 dport=22 packets=133 bytes=13033 src=192.168.10.22 dst=192.168.6.55 sport=22 dport=54941 packets=95 bytes=15004 [ASSURED] mark=16777216 delta-time=1036
I would remove the if case here.
OK, I remove it and post a v2. Thanks!
Thanks and also the hardcoded
TCP_CONNTRACK_ESTABLISHEDinflow_offload_fixup_ctshould be reverted to the real tcp statect->proto.tcp.state.Quoted 8 lines
ct->proto.tcp.statecontains the state that was observed before handling over this flow to the flowtable, in most cases, this should beTCP_CONNTRACK_ESTABLISHED.Quoted 1 line
This way we always set the current TCP timeout.
I can keep it to
ct->proto.tcp.statebut I wonder if it is better to use a well known state such asTCP_CONNTRACK_ESTABLISHEDto pick up from.Quoted 6 lines
In case of a race condition or if something is off like my
TCP_FINthat is beeing offloaded again setting to to ESTABLISHED hard coded will make the e.g. FIN or CLOSE a very long state.
It is not guaranteed that we are still in ESTABLISHED when this code runs. Also for example we could have seen both FIN already before the flowtable gc runs.OK, I just posted a v2, leave things as is. I agree it is better to only address the issue you are observing at this time, it is possible to revisit later.
Quoted 5 lines
Quoted 1 line
Thanks!
Thanks, I will give it another try.
I think for it to be foolproof we need
to migrate the TCP state as well inflow_offload_teardown_tcpto FIN or CLOSE.My patch already does it:
(quoted diff) +10
-0+void flow_offload_teardown_tcp(struct flow_offload *flow, bool fin) +{ + enum tcp_conntrack tcp_state; + + if (fin) + tcp_state = TCP_CONNTRACK_FIN_WAIT; + else /* rst */ + tcp_state = TCP_CONNTRACK_CLOSE; + + flow_offload_fixup_tcp(nf_ct_net(flow->ct), flow->ct, tcp_state);
flow_offload_fixup_tcp()updates the TCP state to FIN / CLOSE state.Quoted 5 lines
They way thinks are right now we are open to a race condition from the reverse side of the connection to reoffload the connection while a FIN or RST is not processed by the netfilter code running after the flowtable code.
The conenction is still in TCP established during that window and another packet can just push it back to the flowtable while the FIN or RST is not processed yet.I don't see how:
static void nft_flow_offload_eval(const struct
nft_expr*expr,... switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) { case IPPROTO_TCP: tcph = skb_header_pointer(pkt->skb, nft_thoff(pkt), sizeof(_tcph), &_tcph); if (unlikely(!tcph || tcph->fin || tcph->rst || !nf_conntrack_tcp_established(ct))) goto out;Quoted 6 lines
this would now be either in FIN/CLOSE state.
FIN, RST packet does not trigger re-offload. And ACK packet would find the entry in !nf_conntrack_tcp_established(ct).
What path could trigger re-offload after my latest patch?
From looking through the nf conntrack tcp code you need to
spin_lockthe TCP state change to avoid a race with another packet.Quoted 8 lines
Quoted 5 lines
The flowtable owns the flow, packets belonging the flow cannot update the TCP state while the flow is offloaded to the flowtable.
Once
_TEARDOWNflag is set on, then packets get back to classic conntrack path.Hmm alright, something is going wrong somewhere and it looks a lot like a race condition :)
This check is racy, another packet could alter the ct state right after it evaluates true.
switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) { case IPPROTO_TCP: tcph = skb_header_pointer(pkt->skb, nft_thoff(pkt), sizeof(_tcph), &_tcph); if (unlikely(!tcph || tcph->fin || tcph->rst || !nf_conntrack_tcp_established(ct))) <------- goto out;Sequence would be:
1) flow expires (after 30 seconds), goes back to conntrack in established state
2) packet re-offloads the flow andnf_conntrack_tcp_established(ct)evaluates true.
3) FIN packet races to update conntrack getting toFIN_WAITwhile re-offloading the flow.then you see
FIN_WAITand offload, it could happen with an expired flow that goes back to conntrack.But I am not sure yet if this is the case you're observing there.
Quoted 8 lines
Quoted 3 lines
I mean just in theory it is not guaranteed that both directions send all packets through the flowtable just because it is offloaded. A variety of error checks might send a packet back to the slow path.
There is the mtu check that is lacking the teardown, but that should only affect UDP traffic. A patch from Felix decided has cached the mtu in the flow entry. That is also probably convenient to have, but it looks like a different issue, I will also post a patch for this issue.
Hi Pablo,
after some testing the problem only happens very rarely now. I suspect it happens only on connections that are at some point one way only or in some other way not in a correct state anymore. Never the less your latest patches are very good and reduce the problem to an absolute minimum that FIN WAIT is offlodaded and the timeout is correct now.
Here is one example if a flow that still is in FIN WAIT:
[NEW] tcp 6 120 SYN_SENT src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 [UNREPLIED] src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 mark=16777216
[UPDATE] tcp 6 60 SYN_RECV src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 mark=16777216 [UPDATE] tcp 6 86400 ESTABLISHED src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 [OFFLOAD] mark=16777216 [UPDATE] tcp 6 120 FIN_WAIT src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 [OFFLOAD] mark=16777216 [UPDATE] tcp 6 30 LAST_ACK src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 [ASSURED] mark=16777216
[UPDATE] tcp 6 120 TIME_WAIT src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 [ASSURED] mark=16777216
[DESTROY] tcp 6 TIME_WAIT src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 packets=15 bytes=1750 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 packets=13 bytes=6905 [ASSURED] mark=16777216 delta-time=120
Best
Sven
Pablo Neira Ayuso
maintainerHi Sven,
Quoted 8 lines · Sven Auhagen
Hi Pablo,
after some testing the problem only happens very rarely now. I suspect it happens only on connections that are at some point one way only or in some other way not in a correct state anymore. Never the less your latest patches are very good and reduce the problem to an absolute minimum that FIN WAIT is offlodaded and the timeout is correct now.
Thanks for testing, I am going to submit this patch.
If you have a bit more cycles, I still would like to know what corner case scenario is still triggering this so...
Quoted 9 lines
Here is one example if a flow that still is in FIN WAIT:
[NEW] tcp 6 120
SYN_SENTsrc=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 [UNREPLIED] src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 mark=16777216[UPDATE] tcp 6 60 SYN_RECV src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 mark=16777216 [UPDATE] tcp 6 86400 ESTABLISHED src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 [OFFLOAD] mark=16777216 [UPDATE] tcp 6 120 FIN_WAIT src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 [OFFLOAD] mark=16777216 [UPDATE] tcp 6 30 LAST_ACK src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 [ASSURED] mark=16777216[UPDATE] tcp 6 120
TIME_WAITsrc=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 [ASSURED] mark=16777216
[DESTROY] tcp 6TIME_WAITsrc=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 packets=15 bytes=1750 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 packets=13 bytes=6905 [ASSURED] mark=16777216 delta-time=120
... could you run conntrack -E -o timestamp? I'd like to know if this is a flow that is handed over back to classic path after 30 seconds, then being placed in the flowtable again.
Quoted 27 lines · Pablo Neira Ayuso
Hi Sven,
Quoted 8 lines · Sven Auhagen
Hi Pablo,
after some testing the problem only happens very rarely now. I suspect it happens only on connections that are at some point one way only or in some other way not in a correct state anymore. Never the less your latest patches are very good and reduce the problem to an absolute minimum that FIN WAIT is offlodaded and the timeout is correct now.
Thanks for testing, I am going to submit this patch.
If you have a bit more cycles, I still would like to know what corner case scenario is still triggering this so...
Quoted 9 lines
Here is one example if a flow that still is in FIN WAIT:
[NEW] tcp 6 120
SYN_SENTsrc=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 [UNREPLIED] src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 mark=16777216[UPDATE] tcp 6 60 SYN_RECV src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 mark=16777216 [UPDATE] tcp 6 86400 ESTABLISHED src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 [OFFLOAD] mark=16777216 [UPDATE] tcp 6 120 FIN_WAIT src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 [OFFLOAD] mark=16777216 [UPDATE] tcp 6 30 LAST_ACK src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 [ASSURED] mark=16777216[UPDATE] tcp 6 120
TIME_WAITsrc=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 [ASSURED] mark=16777216
[DESTROY] tcp 6TIME_WAITsrc=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 packets=15 bytes=1750 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 packets=13 bytes=6905 [ASSURED] mark=16777216 delta-time=120
Quoted 3 lines
... could you run conntrack -E -o timestamp? I'd like to know if this is a flow that is handed over back to classic path after 30 seconds, then being placed in the flowtable again.
Sure here is a fresh output:
[1712662404.573225] [NEW] tcp 6 120 SYN_SENT src=192.168.7.101 dst=157.240.251.61 sport=52717 dport=5222 [UNREPLIED] src=157.240.251.61 dst=87.138.198.79 sport=5222 dport=26886 mark=25165825 [1712662404.588094] [UPDATE] tcp 6 60 SYN_RECV src=192.168.7.101 dst=157.240.251.61 sport=52717 dport=5222 src=157.240.251.61 dst=87.138.198.79 sport=5222 dport=26886 mark=25165825 [1712662404.591802] [UPDATE] tcp 6 86400 ESTABLISHED src=192.168.7.101 dst=157.240.251.61 sport=52717 dport=5222 src=157.240.251.61 dst=87.138.198.79 sport=5222 dport=26886 [OFFLOAD] mark=25165825 [1712662405.682563] [UPDATE] tcp 6 120 FIN_WAIT src=192.168.7.101 dst=157.240.251.61 sport=52717 dport=5222 src=157.240.251.61 dst=87.138.198.79 sport=5222 dport=26886 [OFFLOAD] mark=25165825 [1712662405.689501] [UPDATE] tcp 6 30 LAST_ACK src=192.168.7.101 dst=157.240.251.61 sport=52717 dport=5222 src=157.240.251.61 dst=87.138.198.79 sport=5222 dport=26886 [ASSURED] mark=25165825 [1712662405.704370] [UPDATE] tcp 6 120 TIME_WAIT src=192.168.7.101 dst=157.240.251.61 sport=52717 dport=5222 src=157.240.251.61 dst=87.138.198.79 sport=5222 dport=26886 [ASSURED] mark=25165825 [1712662451.967906] [DESTROY] tcp 6 ESTABLISHED src=192.168.6.122 dst=52.98.243.2 sport=52717 dport=443 packets=14 bytes=4134 src=52.98.243.2 dst=37.24.174.42 sport=443 dport=20116 packets=17 bytes=13712 [ASSURED] mark=16777216 delta-time=140
Pablo Neira Ayuso
maintainerQuoted 32 lines · Sven Auhagen
Quoted 27 lines · Pablo Neira Ayuso
Hi Sven,
Quoted 8 lines · Sven Auhagen
Hi Pablo,
after some testing the problem only happens very rarely now. I suspect it happens only on connections that are at some point one way only or in some other way not in a correct state anymore. Never the less your latest patches are very good and reduce the problem to an absolute minimum that FIN WAIT is offlodaded and the timeout is correct now.
Thanks for testing, I am going to submit this patch.
If you have a bit more cycles, I still would like to know what corner case scenario is still triggering this so...
Quoted 9 lines
Here is one example if a flow that still is in FIN WAIT:
[NEW] tcp 6 120
SYN_SENTsrc=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 [UNREPLIED] src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 mark=16777216[UPDATE] tcp 6 60 SYN_RECV src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 mark=16777216 [UPDATE] tcp 6 86400 ESTABLISHED src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 [OFFLOAD] mark=16777216 [UPDATE] tcp 6 120 FIN_WAIT src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 [OFFLOAD] mark=16777216 [UPDATE] tcp 6 30 LAST_ACK src=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 [ASSURED] mark=16777216[UPDATE] tcp 6 120
TIME_WAITsrc=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 [ASSURED] mark=16777216
[DESTROY] tcp 6TIME_WAITsrc=fd00::192:168:5:32 dst=2a05:d014:687:ed01::21 sport=58790 dport=443 packets=15 bytes=1750 src=2a05:d014:687:ed01::21 dst=2003:a:c7f:e5e8:a3ae:63f7:7f92:e286 sport=443 dport=60848 packets=13 bytes=6905 [ASSURED] mark=16777216 delta-time=120Quoted 3 lines
... could you run conntrack -E -o timestamp? I'd like to know if this is a flow that is handed over back to classic path after 30 seconds, then being placed in the flowtable again.
Quoted 6 lines
Sure here is a fresh output:
[1712662404.573225] [NEW] tcp 6 120 SYN_SENT src=192.168.7.101 dst=157.240.251.61 sport=52717 dport=5222 [UNREPLIED] src=157.240.251.61 dst=87.138.198.79 sport=5222 dport=26886 mark=25165825 [1712662404.588094] [UPDATE] tcp 6 60 SYN_RECV src=192.168.7.101 dst=157.240.251.61 sport=52717 dport=5222 src=157.240.251.61 dst=87.138.198.79 sport=5222 dport=26886 mark=25165825 [1712662404.591802] [UPDATE] tcp 6 86400 ESTABLISHED src=192.168.7.101 dst=157.240.251.61 sport=52717 dport=5222 src=157.240.251.61 dst=87.138.198.79 sport=5222 dport=26886 [OFFLOAD] mark=25165825 [1712662405.682563] [UPDATE] tcp 6 120 FIN_WAIT src=192.168.7.101 dst=157.240.251.61 sport=52717 dport=5222 src=157.240.251.61 dst=87.138.198.79 sport=5222 dport=26886 [OFFLOAD] mark=25165825
It is happening right away, a bit more of 1 second after.
I can also see IP_CT_TCP_FLAG_CLOSE_INIT is not set on when ct->state is adjusted to _FIN_WAIT state in the fixup routine.
There are also packets that might trigger transitions to sIG (ignored) in TCP tracking. Probably conntrack -E is misleading because this does not allow us to see what actual packets are coming after the fin.
Can you give a try to this untested patch? It applies on top of the two patches you already have for TCP and UDP.
Quoted 2 lines
[1712662405.689501] [UPDATE] tcp 6 30 LAST_ACK src=192.168.7.101 dst=157.240.251.61 sport=52717 dport=5222 src=157.240.251.61 dst=87.138.198.79 sport=5222 dport=26886 [ASSURED] mark=25165825 [1712662405.704370] [UPDATE] tcp 6 120 TIME_WAIT src=192.168.7.101 dst=157.240.251.61 sport=52717 dport=5222 src=157.240.251.61 dst=87.138.198.79 sport=5222 dport=26886 [ASSURED] mark=25165825
Can you also enable -o id,timestamp? The id should tell us if we are always talking on the same object.
Quoted 1 line
[1712662451.967906] [DESTROY] tcp 6 ESTABLISHED src=192.168.6.122 dst=52.98.243.2 sport=52717 dport=443 packets=14 bytes=4134 src=52.98.243.2 dst=37.24.174.42 sport=443 dport=20116 packets=17 bytes=13712 [ASSURED] mark=16777216 delta-time=140
include/net/netfilter/nf_flow_table.h +1 -1
@@ -293,7 +293,7 @@ int nf_flow_table_init(struct nf_flowtable *flow_table);void nf_flow_table_free (struct nf_flowtable *flow_table);void flow_offload_teardown (struct flow_offload *flow); -void flow_offload_teardown_tcp (struct flow_offload *flow,bool fin); +void flow_offload_teardown_tcp (struct flow_offload *flow,bool fin,int dir); void nf_flow_snat_port(const struct flow_offload *flow, struct sk_buff *skb, unsigned int thoff,
net/netfilter/nf_flow_table_core.c +8 -5
@@ -350,18 +350,21 @@ void flow_offload_teardown(struct flow_offload *flow) }EXPORT_SYMBOL_GPL (flow_offload_teardown); -void flow_offload_teardown_tcp (struct flow_offload *flow,bool fin) +void flow_offload_teardown_tcp (struct flow_offload *flow,bool fin,int dir) { +struct nf_conn *ct = flow->ct;enum tcp_conntrack tcp_state; -if (fin) +if (fin) { tcp_state =TCP_CONNTRACK_FIN_WAIT ; -else /* rst */ + ct->proto.tcp.seen[dir].flags |=IP_CT_TCP_FLAG_CLOSE_INIT ; + }else {/* rst */ tcp_state =TCP_CONNTRACK_CLOSE ; + } -flow_offload_fixup_tcp (nf_ct_net (flow->ct), flow->ct, tcp_state); +flow_offload_fixup_tcp (nf_ct_net (ct), ct, tcp_state);smp_mb__before_atomic (); -clear_bit (IPS_OFFLOAD_BIT , &flow->ct->status); +clear_bit (IPS_OFFLOAD_BIT , &ct->status);set_bit (NF_FLOW_TEARDOWN , &flow->flags); }EXPORT_SYMBOL_GPL (flow_offload_teardown_tcp);
net/netfilter/nf_flow_table_ip.c +4 -4
@@ -20,7 +20,7 @@#include <linux/udp.h> static int nf_flow_state_check (struct flow_offload *flow,int proto, -struct sk_buff *skb,unsigned int thoff) +struct sk_buff *skb,unsigned int thoff,int dir) {struct tcphdr *tcph;
@@ -29,7 +29,7 @@ static int nf_flow_state_check(struct flow_offload *flow, int proto, tcph = (void *)(skb_network_header (skb) + thoff);if (unlikely (tcph->fin || tcph->rst)) { -flow_offload_teardown_tcp (flow, tcph->fin); +flow_offload_teardown_tcp (flow, tcph->fin, dir);return -1 ; }
@@ -379,7 +379,7 @@ static int nf_flow_offload_forward(struct nf_flowtable_ctx *ctx, iph = (struct iphdr *)(skb_network_header (skb) + ctx->offset); thoff = (iph->ihl *4 ) + ctx->offset; -if (nf_flow_state_check (flow, iph->protocol, skb, thoff)) +if (nf_flow_state_check (flow, iph->protocol, skb, thoff, dir))return 0 ;if (!nf_flow_dst_check (&tuplehash->tuple)) {
@@ -658,7 +658,7 @@ static int nf_flow_offload_ipv6_forward(struct nf_flowtable_ctx *ctx, ip6h = (struct ipv6hdr *)(skb_network_header (skb) + ctx->offset); thoff =sizeof (*ip6h) + ctx->offset; -if (nf_flow_state_check (flow, ip6h->nexthdr, skb, thoff)) +if (nf_flow_state_check (flow, ip6h->nexthdr, skb, thoff, dir))return 0 ;if (!nf_flow_dst_check (&tuplehash->tuple)) {
Florian Westphal
maintainerQuoted 2 lines · Pablo Neira Ayuso
I can also see
IP_CT_TCP_FLAG_CLOSE_INITis not set on whenct->stateis adjusted to_FIN_WAITstate in the fixup routine.
Unrelated to this patch, but I think that there is an increasing and disturbing amount of code that attempts to 'fix' the ct state.
I don't think its right and I intend to remove all of these "fixups" of the conntrack state from flowtable infra.
I see no reason whatsoever why we need to do this, fin can be passed up to conntrack and conntrack can and should handle this without any extra mucking with the nf_conn state fields from flowtable infra.
The only cases where I see why we need to take action from flowtable layer are:
1. timeout extensions of nf_conn from gc worker to prevent eviction
2. removal of the flowtable entry on RST reception. Don't see why that needs state fixup of nf_conn.
3. removal of the flowtable entry on hard failure of
output routines, e.g. because route is stale.
Don't see why that needs any nf_conn changes either.
My impression is that all these conditionals paper over some other bugs, for example gc_worker extending timeout is racing with the datapath, this needs to be fixed first.
I plan to work on this after the selftest fixups.
Pablo Neira Ayuso
maintainerQuoted 6 lines · Florian Westphal
Quoted 2 lines · Pablo Neira Ayuso
I can also see
IP_CT_TCP_FLAG_CLOSE_INITis not set on whenct->stateis adjusted to_FIN_WAITstate in the fixup routine.Unrelated to this patch, but I think that there is an increasing and disturbing amount of code that attempts to 'fix' the ct state.
I originally started this infrastructure without the fixup, and there was a bit of fuzz about it because people complained that TCP connection somewhat becomes stateless and would get stuck too after fin packet is seen.
There is also connlimit, which would be distorted after the TCP flow becomes stateless when handing it over to the flowtable.
Another reason is that hardware offload folks need this, otherwise hardware entry remains too long in the hardware flowtable.
Quoted 6 lines
I don't think its right and I intend to remove all of these "fixups" of the conntrack state from flowtable infra.
I see no reason whatsoever why we need to do this, fin can be passed up to conntrack and conntrack can and should handle this without any extra mucking with the
nf_connstate fields from flowtable infra.
You mean, just let the fin packet go without tearing down the flow entry?
Quoted 6 lines
The only cases where I see why we need to take action from flowtable layer are:
1. timeout extensions of
nf_connfrom gc worker to prevent eviction
2. removal of the flowtable entry on RST reception. Don't see why that needs state fixup ofnf_conn.
Remove it right away then is what you propose?
Quoted 3 lines
3. removal of the flowtable entry on hard failure of output routines, e.g. because route is stale. Don't see why that needs any
nf_connchanges either.
if dst is stale, packet needs to go back to classic path to get a fresh route.
Quoted 3 lines
My impression is that all these conditionals paper over some other bugs, for example
gc_workerextending timeout is racing with the datapath, this needs to be fixed first.
That sounds good. But I am afraid some folks will not be happy if TCP flow becomes stateless again.
Quoted 1 line
I plan to work on this after the selftest fixups.
Thanks.
Florian Westphal
maintainerQuoted 6 lines · Pablo Neira Ayuso
Quoted 3 lines
I see no reason whatsoever why we need to do this, fin can be passed up to conntrack and conntrack can and should handle this without any extra mucking with the
nf_connstate fields from flowtable infra.You mean, just let the fin packet go without tearing down the flow entry?
Yes, thats what I meant. RST would still remove the flow entry.
Quoted 8 lines
Quoted 6 lines
The only cases where I see why we need to take action from flowtable layer are:
1. timeout extensions of
nf_connfrom gc worker to prevent eviction
2. removal of the flowtable entry on RST reception. Don't see why that needs state fixup ofnf_conn.Remove it right away then is what you propose?
Isn't that what is happeing right now? We set TEARDOWN bit and remove OFFLOAD bit from nf_conn.
I think we should NOT do it for FIN and let conntrack handle this, but we should still do it for RST.
Technically I think we could also skip it for RST but I don't see a big advantage. For FIN it will keep offloading in place which is a win for connetions where one end still sends more data.
Quoted 6 lines
Quoted 3 lines
3. removal of the flowtable entry on hard failure of output routines, e.g. because route is stale. Don't see why that needs any
nf_connchanges either.if dst is stale, packet needs to go back to classic path to get a fresh route.
Yes, sure. But I would keep the teardown in place that we have now, I meant to say that the current code makes sense to me, i.e.:
if (!nf_flow_dst_check(&tuplehash->tuple)) {
flow_offload_teardown(flow);
return 0;
}Quoted 6 lines
Quoted 3 lines
My impression is that all these conditionals paper over some other bugs, for example
gc_workerextending timeout is racing with the datapath, this needs to be fixed first.That sounds good. But I am afraid some folks will not be happy if TCP flow becomes stateless again.
I do not know what that means. There can never be a flowtable entry without a backing nf_conn, so I don't know what stateless means in this context.
Pablo Neira Ayuso
maintainerQuoted 9 lines · Florian Westphal
Quoted 6 lines · Pablo Neira Ayuso
Quoted 3 lines
I see no reason whatsoever why we need to do this, fin can be passed up to conntrack and conntrack can and should handle this without any extra mucking with the
nf_connstate fields from flowtable infra.You mean, just let the fin packet go without tearing down the flow entry?
Yes, thats what I meant. RST would still remove the flow entry.
So flow entry would remain in place if fin packet is seen. Then, an ack packet will follow fastpath while another fin packet in the other direction will follow classic.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
The only cases where I see why we need to take action from flowtable layer are:
1. timeout extensions of
nf_connfrom gc worker to prevent eviction
2. removal of the flowtable entry on RST reception. Don't see why that needs state fixup ofnf_conn.
Quoted 7 lines
Quoted 1 line
Remove it right away then is what you propose?
Isn't that what is happeing right now? We set TEARDOWN bit and remove OFFLOAD bit from
nf_conn.I think we should NOT do it for FIN and let conntrack handle this, but we should still do it for RST.
Conntrack will have to deal then with an entry that is completely out-of-sync, will that work? At least a fixup to disable sequence tracking will be required?
Quoted 3 lines
Technically I think we could also skip it for RST but I don't see a big advantage. For FIN it will keep offloading in place which is a win for connetions where one end still sends more data.
I see.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
3. removal of the flowtable entry on hard failure of output routines, e.g. because route is stale. Don't see why that needs any
nf_connchanges either.if dst is stale, packet needs to go back to classic path to get a fresh route.
Quoted 7 lines
Yes, sure. But I would keep the teardown in place that we have now, I meant to say that the current code makes sense to me, i.e.:
if (!nf_flow_dst_check(&tuplehash->tuple)) { flow_offload_teardown(flow); return 0; }
I see, I misunderstood.
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
My impression is that all these conditionals paper over some other bugs, for example
gc_workerextending timeout is racing with the datapath, this needs to be fixed first.That sounds good. But I am afraid some folks will not be happy if TCP flow becomes stateless again.
I do not know what that means. There can never be a flowtable entry without a backing
nf_conn, so I don't know what stateless means in this context.
If fin does not tear down the flow entry, then the flow entry remains in place and it holds a reference to the conntrack object, which will not be release until 30 seconds of no traffic activity, right?
Maybe I am just missing part of what you have in mind, I still don't see the big picture.
Would you make a quick summary of the proposed new logic?
Thanks!
Quoted 72 lines · Pablo Neira Ayuso
Quoted 9 lines · Florian Westphal
Quoted 6 lines · Pablo Neira Ayuso
Quoted 3 lines
I see no reason whatsoever why we need to do this, fin can be passed up to conntrack and conntrack can and should handle this without any extra mucking with the
nf_connstate fields from flowtable infra.You mean, just let the fin packet go without tearing down the flow entry?
Yes, thats what I meant. RST would still remove the flow entry.
So flow entry would remain in place if fin packet is seen. Then, an ack packet will follow fastpath while another fin packet in the other direction will follow classic.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
The only cases where I see why we need to take action from flowtable layer are:
1. timeout extensions of
nf_connfrom gc worker to prevent eviction
2. removal of the flowtable entry on RST reception. Don't see why that needs state fixup ofnf_conn.Quoted 7 lines
Quoted 1 line
Remove it right away then is what you propose?
Isn't that what is happeing right now? We set TEARDOWN bit and remove OFFLOAD bit from
nf_conn.I think we should NOT do it for FIN and let conntrack handle this, but we should still do it for RST.
Conntrack will have to deal then with an entry that is completely out-of-sync, will that work? At least a fixup to disable sequence tracking will be required?
Quoted 3 lines
Technically I think we could also skip it for RST but I don't see a big advantage. For FIN it will keep offloading in place which is a win for connetions where one end still sends more data.
I see.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
3. removal of the flowtable entry on hard failure of output routines, e.g. because route is stale. Don't see why that needs any
nf_connchanges either.if dst is stale, packet needs to go back to classic path to get a fresh route.
Quoted 7 lines
Yes, sure. But I would keep the teardown in place that we have now, I meant to say that the current code makes sense to me, i.e.:
if (!nf_flow_dst_check(&tuplehash->tuple)) { flow_offload_teardown(flow); return 0; }I see, I misunderstood.
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
My impression is that all these conditionals paper over some other bugs, for example
gc_workerextending timeout is racing with the datapath, this needs to be fixed first.That sounds good. But I am afraid some folks will not be happy if TCP flow becomes stateless again.
I do not know what that means. There can never be a flowtable entry without a backing
nf_conn, so I don't know what stateless means in this context.If fin does not tear down the flow entry, then the flow entry remains in place and it holds a reference to the conntrack object, which will not be release until 30 seconds of no traffic activity, right?
Quoted 6 lines
Maybe I am just missing part of what you have in mind, I still don't see the big picture.
Would you make a quick summary of the proposed new logic?
Thanks!
Hi Pablo,
I tested your last patch but it makes no difference:
[NEW] tcp 6 120 SYN_SENT src=192.168.7.126 dst=157.240.223.63 sport=63461 dport=443 [UNREPLIED] src=157.240.223.63 dst=87.138.198.79 sport=443 dport=13354 mark=25165825 [UPDATE] tcp 6 60 SYN_RECV src=192.168.7.126 dst=157.240.223.63 sport=63461 dport=443 src=157.240.223.63 dst=87.138.198.79 sport=443 dport=13354 mark=25165825 [UPDATE] tcp 6 86400 ESTABLISHED src=192.168.7.126 dst=157.240.223.63 sport=63461 dport=443 src=157.240.223.63 dst=87.138.198.79 sport=443 dport=13354 [OFFLOAD] mark=25165825 [UPDATE] tcp 6 120 FIN_WAIT src=192.168.7.126 dst=157.240.223.63 sport=63461 dport=443 src=157.240.223.63 dst=87.138.198.79 sport=443 dport=13354 [OFFLOAD] mark=25165825 [UPDATE] tcp 6 30 LAST_ACK src=192.168.7.126 dst=157.240.223.63 sport=63461 dport=443 src=157.240.223.63 dst=87.138.198.79 sport=443 dport=13354 [OFFLOAD] mark=25165825 [DESTROY] tcp 6 LAST_ACK src=192.168.7.126 dst=157.240.223.63 sport=63461 dport=443 packets=10 bytes=790 src=157.240.223.63 dst=87.138.198.79 sport=443 dport=13354 packets=19 bytes=5061 [ASSURED] mark=25165825 delta-time=138
Best
Sven