netfilter: flow table fixes
Subsystems (3)
Florian Westphal
maintainercover netfilter: flow table fixes
This series fixes several issues I spotted while investigating a 'tcp connection stalls with flow offload on' bug report.
I'm not sure if the original problem is fixed, however, the test script in patch 5 will fail without the fixes from patches 1 and 2.
Patches 3 and 4 fix additional problems, however, these are by code review only.
Florian Westphal (5):
netfilter: nf_flow_table: ignore DF bit setting
netfilter: nft_flow_offload: set liberal tracking mode for tcp
netfilter: nft_flow_offload: don't offload when sequence numbers need adjustment
netfilter: nft_flow_offload: IPCB is only valid for ipv4 family
selftests: netfilter: add flowtable test script
net/netfilter/nf_flow_table_ip.c | 3 net/netfilter/nft_flow_offload.c | 31 +- tools/testing/selftests/netfilter/Makefile | 2 tools/testing/selftests/netfilter/nft_flowtable.sh | 324 +++++++++++++++++++++
Florian Westphal
maintainerPATCH 1/5 netfilter: nf_flow_table: ignore DF bit setting
Its irrelevant if the DF bit is set or not, we must pass packet to stack in either case.
If the DF bit is set, we must pass it to stack so the appropriate ICMP error can be generated.
If the DF is not set, we must pass it to stack for fragmentation.
--- net/netfilter/nf_flow_table_ip.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/netfilter/nf_flow_table_ip.c +1 -2
@@ -243,8 +243,7 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, rt = (struct rtable *)flow->tuplehash[dir].tuple.dst_cache; outdev = rt->dst.dev; -if (unlikely (nf_flow_exceeds_mtu (skb, flow->tuplehash[dir].tuple.mtu)) && - (ip_hdr (skb)->frag_off &htons (IP_DF )) !=0 ) +if (unlikely (nf_flow_exceeds_mtu (skb, flow->tuplehash[dir].tuple.mtu)))return NF_ACCEPT ;if (skb_try_make_writable (skb,sizeof (*iph)))
Signature · 1 line
2.21.0
Florian Westphal
maintainerPATCH 2/5 netfilter: nft_flow_offload: set liberal tracking mode for tcp
In reply to Florian WestphalWithout it, whenever a packet has to be pushed up the stack (e.g. because of mtu mismatch), then conntrack will flag packets as invalid, which in turn breaks NAT.
--- net/netfilter/nft_flow_offload.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/netfilter/nft_flow_offload.c +8 -0
@@ -72,6 +72,7 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,struct nf_flow_route route;struct flow_offload *flow;enum ip_conntrack_dir dir; +bool is_tcp = false;struct nf_conn *ct;int ret;
@@ -84,6 +85,8 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,switch (ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.dst.protonum) {case IPPROTO_TCP : + is_tcp = true; +break ;case IPPROTO_UDP :break ;default :
@@ -108,6 +111,11 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,if (!flow) goto err_flow_alloc; +if (is_tcp) { + ct->proto.tcp.seen[0 ].flags |=IP_CT_TCP_FLAG_BE_LIBERAL ; + ct->proto.tcp.seen[1 ].flags |=IP_CT_TCP_FLAG_BE_LIBERAL ; + } + ret =flow_offload_add (flowtable, flow);if (ret <0 ) goto err_flow_add;
Signature · 1 line
2.21.0
Florian Westphal
maintainerPATCH 3/5 netfilter: nft_flow_offload: don't offload when sequence numbers need adjustment
In reply to Florian WestphalWe can't deal with tcp sequence number rewrite in flow_offload. While at it, simplify helper check, we only need to know if the extension is present, we don't need the helper data.
--- net/netfilter/nft_flow_offload.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
net/netfilter/nft_flow_offload.c +2 -4
@@ -12,7 +12,6 @@#include <net/netfilter/nf_conntrack_core.h> #include <linux/netfilter/nf_conntrack_common.h> #include <net/netfilter/nf_flow_table.h> -#include <net/netfilter/nf_conntrack_helper.h> struct nft_flow_offload {struct nft_flowtable *flowtable;
@@ -67,7 +66,6 @@ static void nft_flow_offload_eval(const struct nft_expr *expr, {struct nft_flow_offload *priv =nft_expr_priv (expr);struct nf_flowtable *flowtable = &priv->flowtable->data; -const struct nf_conn_help *help;enum ip_conntrack_info ctinfo;struct nf_flow_route route;struct flow_offload *flow;
@@ -93,8 +91,8 @@ static void nft_flow_offload_eval(const struct nft_expr *expr, goto out; } - help =nfct_help (ct); -if (help) +if (nf_ct_ext_exist (ct,NF_CT_EXT_HELPER ) || + ct->status &IPS_SEQ_ADJUST ) goto out;if (!nf_ct_is_confirmed (ct))
Signature · 1 line
2.21.0
Florian Westphal
maintainerPATCH 4/5 netfilter: nft_flow_offload: IPCB is only valid for ipv4 family
In reply to Florian WestphalGuard this with a check vs. ipv4, IPCB isn't valid in ipv6 case.
--- net/netfilter/nft_flow_offload.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
net/netfilter/nft_flow_offload.c +11 -6
@@ -48,15 +48,20 @@ static int nft_flow_route(const struct nft_pktinfo *pkt,return 0 ; } -static bool nft_flow_offload_skip (struct sk_buff *skb) +static bool nft_flow_offload_skip (struct sk_buff *skb,int family) { -struct ip_options *opt = &(IPCB (skb)->opt); - -if (unlikely (opt->optlen)) -return true;if (skb_sec_path (skb))return true; +if (family ==NFPROTO_IPV4 ) { +const struct ip_options *opt; + + opt = &(IPCB (skb)->opt); + +if (unlikely (opt->optlen)) +return true; + } +return false; }
@@ -74,7 +79,7 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,struct nf_conn *ct;int ret; -if (nft_flow_offload_skip (pkt->skb)) +if (nft_flow_offload_skip (pkt->skb,nft_pf (pkt))) goto out; ct =nf_ct_get (pkt->skb, &ctinfo);
Signature · 1 line
2.21.0
Florian Westphal
maintainerPATCH 5/5 selftests: netfilter: add flowtable test script
In reply to Florian WestphalExercises 3 cases:
1. no pmtu discovery (need to frag)
2. no PMTUd + NAT (don't flag packets as invalid from conntrack)
3. PMTU + NAT (need to send icmp error)
The first two cases make sure we handle fragments correctly, i.e. pass them to classic forwarding path.
Third case checks we offload everything (in the test case, PMTUd will kick in so all packets should be within link mtu).
Nftables rules will filter packets that are supposed to be handled by the fast-path.
--- tools/testing/selftests/netfilter/Makefile | 2 +- .../selftests/netfilter/nft_flowtable.sh | 324 ++++++++++++++++++ 2 files changed, 325 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/netfilter/nft_flowtable.sh
tools/testing/selftests/netfilter/Makefile +1 -1
@@ -2,6 +2,6 @@ # Makefile for netfilter selftests TEST_PROGS := nft_trans_stress.sh nft_nat.sh bridge_brouter.sh \ - conntrack_icmp_related.sh + conntrack_icmp_related.sh nft_flowtable.sh include ../lib.mk
tools/testing/selftests/netfilter/nft_flowtable.sh new file +324 -0
324 lines not on this page · raw message
Signature · 1 line
2.21.0
Pablo Neira Ayuso
maintainerQuoted 8 lines · Florian Westphal
This series fixes several issues I spotted while investigating a 'tcp connection stalls with flow offload on' bug report.
I'm not sure if the original problem is fixed, however, the test script in patch 5 will fail without the fixes from patches 1 and 2.
Patches 3 and 4 fix additional problems, however, these are by code review only.
Series applied, thanks Florian.