netfilter: flowtable: consolidate skb_try_make_writable() call
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH v2 6/6 netfilter: flowtable: refresh timeout after dst and writable checks
In reply to Pablo Neira AyusoRefresh the timeout (and retry hardware offload) once the skbuff dst is confirmed to be current and after the skbuff is made writable.
---
v2: new patch in this batch
net/netfilter/nf_flow_table_ip.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/netfilter/nf_flow_table_ip.c +4 -4
@@ -246,8 +246,6 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,if (nf_flow_state_check (flow, iph->protocol, skb, thoff))return NF_ACCEPT ; -flow_offload_refresh (flow_table, flow); -if (!dst_check (&rt->dst,0 )) {flow_offload_teardown (flow);return NF_ACCEPT ;
@@ -256,6 +254,8 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,if (skb_try_make_writable (skb, thoff + hdrsize))return NF_DROP ; +flow_offload_refresh (flow_table, flow); + iph =ip_hdr (skb);nf_flow_nat_ip (flow, skb, thoff, dir, iph);
@@ -466,8 +466,6 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb, sizeof(*ip6h)))return NF_ACCEPT ; -flow_offload_refresh (flow_table, flow); -if (!dst_check (&rt->dst,0 )) {flow_offload_teardown (flow);return NF_ACCEPT ;
@@ -476,6 +474,8 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,if (skb_try_make_writable (skb,sizeof (*ip6h) + hdrsize))return NF_DROP ; +flow_offload_refresh (flow_table, flow); + ip6h =ipv6_hdr (skb);nf_flow_nat_ipv6 (flow, skb, dir, ip6h);
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH v2 1/6 netfilter: flowtable: consolidate skb_try_make_writable() call
Fetch the layer 4 header size to be mangled by NAT when building the tuple, then use it to make writable the network and the transport headers. After this update, the NAT routines now assumes that the skbuff area is writable. Do the pointer refetch only after the single skb_try_make_writable() call.
---
v2: no changes.
net/netfilter/nf_flow_table_core.c | 12 ----- net/netfilter/nf_flow_table_ip.c | 74 +++++++++++++----------------- 2 files changed, 31 insertions(+), 55 deletions(-)
net/netfilter/nf_flow_table_core.c +0 -12
@@ -395,9 +395,6 @@ static int nf_flow_nat_port_tcp(struct sk_buff *skb, unsigned int thoff, {struct tcphdr *tcph; -if (skb_try_make_writable (skb, thoff +sizeof (*tcph))) -return -1 ; - tcph = (void *)(skb_network_header (skb) + thoff);inet_proto_csum_replace2 (&tcph->check, skb, port, new_port, false);
@@ -409,9 +406,6 @@ static int nf_flow_nat_port_udp(struct sk_buff *skb, unsigned int thoff, {struct udphdr *udph; -if (skb_try_make_writable (skb, thoff +sizeof (*udph))) -return -1 ; - udph = (void *)(skb_network_header (skb) + thoff);if (udph->check || skb->ip_summed ==CHECKSUM_PARTIAL ) { inet_proto_csum_replace2(&udph->check, skb, port,
@@ -447,9 +441,6 @@ int nf_flow_snat_port(const struct flow_offload *flow,struct flow_ports *hdr;__be16 port, new_port; -if (skb_try_make_writable (skb, thoff +sizeof (*hdr))) -return -1 ; - hdr = (void *)(skb_network_header (skb) + thoff);switch (dir) {
@@ -478,9 +469,6 @@ int nf_flow_dnat_port(const struct flow_offload *flow,struct flow_ports *hdr;__be16 port, new_port; -if (skb_try_make_writable (skb, thoff +sizeof (*hdr))) -return -1 ; - hdr = (void *)(skb_network_header (skb) + thoff);switch (dir) {
net/netfilter/nf_flow_table_ip.c +31 -43
217 lines not on this page · raw message
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH v2 2/6 netfilter: flowtable: move skb_try_make_writable() before NAT in IPv4
For consistency with the IPv6 flowtable datapath and to make sure the skbuff is writable right before the NAT header updates.
---
new patch in this v2.
net/netfilter/nf_flow_table_ip.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/netfilter/nf_flow_table_ip.c +4 -4
@@ -266,10 +266,6 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, iph =ip_hdr (skb); thoff = iph->ihl *4 ; -if (skb_try_make_writable (skb, thoff + hdrsize)) -return NF_DROP ; - - iph =ip_hdr (skb);if (nf_flow_state_check (flow, iph->protocol, skb, thoff))return NF_ACCEPT ;
@@ -280,6 +276,10 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,return NF_ACCEPT ; } +if (skb_try_make_writable (skb, thoff + hdrsize)) +return NF_DROP ; + + iph =ip_hdr (skb);if (nf_flow_nat_ip (flow, skb, thoff, dir, iph) <0 )return NF_DROP ;
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH v2 3/6 netfilter: flowtable: move FLOW_OFFLOAD_DIR_MAX away from enumeration
In reply to Pablo Neira AyusoThis allows to remove the default case which should not ever happen and that was added to avoid gcc warnings on unhandled FLOW_OFFLOAD_DIR_MAX enumeration case.
---
v2: no changes.
include/net/netfilter/nf_flow_table.h | 2 +- net/netfilter/nf_flow_table_core.c | 4 ---- net/netfilter/nf_flow_table_ip.c | 8 -------- 3 files changed, 1 insertion(+), 13 deletions(-)
include/net/netfilter/nf_flow_table.h +1 -1
@@ -86,8 +86,8 @@ static inline bool nf_flowtable_hw_offload(struct nf_flowtable *flowtable)enum flow_offload_tuple_dir {FLOW_OFFLOAD_DIR_ORIGINAL =IP_CT_DIR_ORIGINAL ,FLOW_OFFLOAD_DIR_REPLY =IP_CT_DIR_REPLY , -FLOW_OFFLOAD_DIR_MAX =IP_CT_DIR_MAX }; +#define FLOW_OFFLOAD_DIR_MAX IP_CT_DIR_MAX struct flow_offload_tuple { union {
net/netfilter/nf_flow_table_core.c +0 -4
@@ -454,8 +454,6 @@ int nf_flow_snat_port(const struct flow_offload *flow, new_port = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL ].tuple.src_port; hdr->dest = new_port;break ; -default : -return -1 ; }return nf_flow_nat_port (skb, thoff, protocol, port, new_port);
@@ -482,8 +480,6 @@ int nf_flow_dnat_port(const struct flow_offload *flow, new_port = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL ].tuple.dst_port; hdr->source = new_port;break ; -default : -return -1 ; }return nf_flow_nat_port (skb, thoff, protocol, port, new_port);
net/netfilter/nf_flow_table_ip.c +0 -8
@@ -96,8 +96,6 @@ static int nf_flow_snat_ip(const struct flow_offload *flow, struct sk_buff *skb, new_addr = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL ].tuple.src_v4.s_addr; iph->daddr = new_addr;break ; -default : -return -1 ; }csum_replace4 (&iph->check, addr, new_addr);
@@ -121,8 +119,6 @@ static int nf_flow_dnat_ip(const struct flow_offload *flow, struct sk_buff *skb, new_addr = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL ].tuple.dst_v4.s_addr; iph->saddr = new_addr;break ; -default : -return -1 ; }csum_replace4 (&iph->check, addr, new_addr);
@@ -371,8 +367,6 @@ static int nf_flow_snat_ipv6(const struct flow_offload *flow, new_addr = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL ].tuple.src_v6; ip6h->daddr = new_addr;break ; -default : -return -1 ; }return nf_flow_nat_ipv6_l4proto (skb, ip6h, thoff, &addr, &new_addr);
@@ -396,8 +390,6 @@ static int nf_flow_dnat_ipv6(const struct flow_offload *flow, new_addr = flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL ].tuple.dst_v6; ip6h->saddr = new_addr;break ; -default : -return -1 ; }return nf_flow_nat_ipv6_l4proto (skb, ip6h, thoff, &addr, &new_addr);
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH v2 4/6 netfilter: flowtable: fast NAT functions never fail
In reply to Pablo Neira AyusoSimplify existing fast NAT routines by returning void. After the skb_try_make_writable() call consolidation, these routines cannot ever fail.
---
v2: no changes.
include/net/netfilter/nf_flow_table.h | 12 +-- net/netfilter/nf_flow_table_core.c | 41 +++---- net/netfilter/nf_flow_table_ip.c | 147 +++++++++++--------------- 3 files changed, 84 insertions(+), 116 deletions(-)
include/net/netfilter/nf_flow_table.h +6 -6
@@ -229,12 +229,12 @@ void nf_flow_table_free(struct nf_flowtable *flow_table);void flow_offload_teardown (struct flow_offload *flow); -int nf_flow_snat_port (const struct flow_offload *flow, -struct sk_buff *skb,unsigned int thoff, -u8 protocol,enum flow_offload_tuple_dir dir); -int nf_flow_dnat_port (const struct flow_offload *flow, -struct sk_buff *skb,unsigned int thoff, -u8 protocol,enum flow_offload_tuple_dir dir); +void nf_flow_snat_port (const struct flow_offload *flow, +struct sk_buff *skb,unsigned int thoff, +u8 protocol,enum flow_offload_tuple_dir dir); +void nf_flow_dnat_port (const struct flow_offload *flow, +struct sk_buff *skb,unsigned int thoff, +u8 protocol,enum flow_offload_tuple_dir dir);struct flow_ports {__be16 source, dest;
net/netfilter/nf_flow_table_core.c +16 -25
86 lines not on this page · raw message
net/netfilter/nf_flow_table_ip.c +62 -85
258 lines not on this page · raw message
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH v2 5/6 netfilter: flowtable: call dst_check() to fall back to classic forwarding
In reply to Pablo Neira AyusoIn case the route is stale, pass up the packet to the classic forwarding path for re-evaluation and schedule this flow entry for removal.
---
new patch in this batch
net/netfilter/nf_flow_table_ip.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
net/netfilter/nf_flow_table_ip.c +2 -10
@@ -197,14 +197,6 @@ static bool nf_flow_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)return true; } -static int nf_flow_offload_dst_check (struct dst_entry *dst) -{ -if (unlikely (dst_xfrm (dst))) -return dst_check (dst,0 ) ?0 :-1 ; - -return 0 ; -} -static unsigned int nf_flow_xmit_xfrm (struct sk_buff *skb,const struct nf_hook_state *state,struct dst_entry *dst)
@@ -256,7 +248,7 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,flow_offload_refresh (flow_table, flow); -if (nf_flow_offload_dst_check (&rt->dst)) { +if (!dst_check (&rt->dst,0 )) {flow_offload_teardown (flow);return NF_ACCEPT ; }
@@ -476,7 +468,7 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,flow_offload_refresh (flow_table, flow); -if (nf_flow_offload_dst_check (&rt->dst)) { +if (!dst_check (&rt->dst,0 )) {flow_offload_teardown (flow);return NF_ACCEPT ; }
Signature · 1 line
2.20.1