netfilter: flowtable: consolidate skb_try_make_writable() call
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/3 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.
--- 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 2/3 netfilter: flowtable: move FLOW_OFFLOAD_DIR_MAX away from enumeration
This 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.
--- 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 3/3 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.
--- 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