netfilter: nf_flow_table_offload: something fixes
Subsystems (2)
cover netfilter: nf_flow_table_offload: something fixes
From: wenxu <[email protected]>
wenxu (3):
netfilter: nf_flow_table_offload: fix dst_neigh lookup
netfilter: nf_flow_table_offload: check the status of dst_neigh
netfilter: nf_flow_table_offload: fix the nat port mangle.
net/netfilter/nf_flow_table_offload.c | 44 +++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 12 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/3 netfilter: nf_flow_table_offload: fix dst_neigh lookup for dnat
From: wenxu <[email protected]>
Get the dst_neigh through dst_ip, The dst_ip should get through peer tuple.src_v4 fix for dnat case.
--- net/netfilter/nf_flow_table_offload.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/netfilter/nf_flow_table_offload.c +4 -2
@@ -166,14 +166,16 @@ static int flow_offload_eth_dst(struct net *net,enum flow_offload_tuple_dir dir, struct nf_flow_rule *flow_rule) { - const struct flow_offload_tuple *tuple = &flow->tuplehash[dir].tuple; struct flow_action_entry *entry0 = flow_action_entry_next(flow_rule);struct flow_action_entry *entry1 =flow_action_entry_next (flow_rule); +const void *daddr = &flow->tuplehash[!dir].tuple.src_v4; +const struct dst_entry *dst_cache;struct neighbour *n;u32 mask, val;u16 val16; - n =dst_neigh_lookup (tuple->dst_cache, &tuple->dst_v4); + dst_cache = flow->tuplehash[dir].tuple.dst_cache; + n =dst_neigh_lookup (dst_cache, daddr);if (!n)return -ENOENT ;
Signature · 1 line
1.8.3.1
PATCH 2/3 netfilter: nf_flow_table_offload: check the status of dst_neigh
In reply to [email protected]From: wenxu <[email protected]>
It is better to get the dst_neigh with neigh->lock and check the nud_state is VALID
--- net/netfilter/nf_flow_table_offload.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
net/netfilter/nf_flow_table_offload.c +12 -2
@@ -170,8 +170,10 @@ static int flow_offload_eth_dst(struct net *net,struct flow_action_entry *entry1 =flow_action_entry_next (flow_rule);const void *daddr = &flow->tuplehash[!dir].tuple.src_v4;const struct dst_entry *dst_cache; +unsigned char ha[ETH_ALEN ];struct neighbour *n;u32 mask, val; +u8 nud_state;u16 val16; dst_cache = flow->tuplehash[dir].tuple.dst_cache;
@@ -179,13 +181,21 @@ static int flow_offload_eth_dst(struct net *net,if (!n)return -ENOENT ; +read_lock_bh (&n->lock); + nud_state = n->nud_state; +ether_addr_copy (ha, n->ha); +read_unlock_bh (&n->lock); + +if (!(nud_state &NUD_VALID )) +return -ENOENT ; + mask = ~0xffffffff ; -memcpy (&val, n->ha,4 ); +memcpy (&val, ha,4 );flow_offload_mangle (entry0,FLOW_ACT_MANGLE_HDR_TYPE_ETH ,0 , &val, &mask); mask = ~0x0000ffff ; -memcpy (&val16, n->ha +4 ,2 ); +memcpy (&val16, ha +4 ,2 ); val = val16;flow_offload_mangle (entry1,FLOW_ACT_MANGLE_HDR_TYPE_ETH ,4 , &val, &mask);
Signature · 1 line
1.8.3.1
PATCH 3/3 netfilter: nf_flow_table_offload: fix the nat port mangle.
In reply to [email protected]From: wenxu <[email protected]>
For dnat:
The original dir maybe modify the dst port to src port of reply dir The reply dir maybe modify the src port to dst port of origin dir
For snat:
The original dir maybe modify the src port to dst port of reply dir The reply dir maybe modify the dst port to src port of reply dir
--- net/netfilter/nf_flow_table_offload.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
net/netfilter/nf_flow_table_offload.c +16 -8
@@ -347,22 +347,26 @@ static void flow_offload_port_snat(struct net *net, struct nf_flow_rule *flow_rule) {struct flow_action_entry *entry =flow_action_entry_next (flow_rule); -u32 mask = ~htonl (0xffff0000 ), port; +u32 mask, port;u32 offset;switch (dir) {case FLOW_OFFLOAD_DIR_ORIGINAL : port =ntohs (flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY ].tuple.dst_port); offset =0 ;/* offsetof(struct tcphdr, source); */ + port =htonl (port <<16 ); + mask = ~htonl (0xffff0000 );break ;case FLOW_OFFLOAD_DIR_REPLY : port =ntohs (flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL ].tuple.src_port); offset =0 ;/* offsetof(struct tcphdr, dest); */ + port =htonl (port); + mask = ~htonl (0xffff );break ;default :return ; } - port =htonl (port <<16 ); +flow_offload_mangle (entry,flow_offload_l4proto (flow), offset, &port, &mask); }
@@ -373,22 +377,26 @@ static void flow_offload_port_dnat(struct net *net, struct nf_flow_rule *flow_rule) {struct flow_action_entry *entry =flow_action_entry_next (flow_rule); -u32 mask = ~htonl (0xffff ), port; +u32 mask, port;u32 offset;switch (dir) {case FLOW_OFFLOAD_DIR_ORIGINAL : - port =ntohs (flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY ].tuple.dst_port); - offset =0 ;/* offsetof(struct tcphdr, source); */ + port =ntohs (flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY ].tuple.src_port); + offset =0 ;/* offsetof(struct tcphdr, dest); */ + port =htonl (port); + mask = ~htonl (0xffff );break ;case FLOW_OFFLOAD_DIR_REPLY : - port =ntohs (flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL ].tuple.src_port); - offset =0 ;/* offsetof(struct tcphdr, dest); */ + port =ntohs (flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL ].tuple.dst_port); + offset =0 ;/* offsetof(struct tcphdr, source); */ + port =htonl (port <<16 ); + mask = ~htonl (0xffff0000 );break ;default :return ; } - port =htonl (port); +flow_offload_mangle (entry,flow_offload_l4proto (flow), offset, &port, &mask); }
Signature · 1 line
1.8.3.1