netfilter: flowtable: remove redundant ifidx field in tuple output union
Subsystems (3)
Pablo Neira Ayuso
maintainerPATCH 1/2 netfilter: flowtable: remove redundant ifidx field in tuple output union
The XMIT_NEIGH and XMIT_DIRECT types use an output ifidx field to determine the destination netdevice. Remove the redundant ifidx field in the flow_offload_tuple union that represents the output path, use the existing struct.
No functional change, this is just a preparation patch.
--- include/net/netfilter/nf_flow_table.h | 3 --- net/netfilter/nf_flow_table_core.c | 2 +- net/netfilter/nf_flow_table_ip.c | 4 ++-- 3 files changed, 3 insertions(+), 6 deletions(-)
include/net/netfilter/nf_flow_table.h +0 -3
@@ -160,9 +160,6 @@ struct flow_offload_tuple {struct dst_entry *dst_cache; union { -struct { -u32 ifidx; - }; struct { u32 ifidx; u8 h_source[ETH_ALEN];
net/netfilter/nf_flow_table_core.c +1 -1
@@ -142,7 +142,7 @@ static int flow_offload_fill_route(struct flow_offload *flow,break ;case FLOW_OFFLOAD_XMIT_XFRM :case FLOW_OFFLOAD_XMIT_NEIGH : - flow_tuple->ifidx = route->tuple[dir].out.ifindex; + flow_tuple->out.ifidx = route->tuple[dir].out.ifindex; flow_tuple->dst_cache = dst; flow_tuple->dst_cookie =flow_offload_dst_cookie (flow_tuple);break ;
net/netfilter/nf_flow_table_ip.c +2 -2
@@ -867,7 +867,7 @@ static int nf_flow_queue_xmit4(struct sk_buff *skb,switch (tuplehash->tuple.xmit_type) {case FLOW_OFFLOAD_XMIT_NEIGH : rt =dst_rtable (tuplehash->tuple.dst_cache); - xmit.outdev =dev_get_by_index_rcu (state->net, tuplehash->tuple.ifidx); + xmit.outdev =dev_get_by_index_rcu (state->net, tuplehash->tuple.out.ifidx);if (!xmit.outdev) {flow_offload_teardown (flow);return NF_DROP ;
@@ -1196,7 +1196,7 @@ static int nf_flow_queue_xmit6(struct sk_buff *skb,switch (tuplehash->tuple.xmit_type) {case FLOW_OFFLOAD_XMIT_NEIGH : rt =dst_rt6_info (tuplehash->tuple.dst_cache); - xmit.outdev =dev_get_by_index_rcu (state->net, tuplehash->tuple.ifidx); + xmit.outdev =dev_get_by_index_rcu (state->net, tuplehash->tuple.out.ifidx);if (!xmit.outdev) {flow_offload_teardown (flow);return NF_DROP ;
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 2/2 netfilter: flowtable: cache destination hw address for XMIT_NEIGH type
Since commit b5964aac51e0 ("netfilter: flowtable: consolidate xmit path"), a flow offloaded with FLOW_OFFLOAD_XMIT_NEIGH keeps being forwarded with destination MAC 00:00:00:00:00:00 after the next hop's neighbour entry has been removed. Nothing resolves the next hop again, so the flow stays black-holed for as long as it keeps sending.
Cache the destination hw address in the flow entry, just like XMIT_DIRECT does. Use the flowtable GC to validate that there is a neighbour entry that is still valid. Otherwise, if the neighbour entry is stale, trigger a probe.
--- net/ipv4/ipip.c | 16 ++++++++ net/ipv6/ip6_tunnel.c | 39 ++++++++++++++------ net/netfilter/nf_flow_table_core.c | 59 ++++++++++++++++++++++++++++-- net/netfilter/nf_flow_table_ip.c | 16 +------- net/netfilter/nf_flow_table_path.c | 11 +++++- 5 files changed, 111 insertions(+), 30 deletions(-)
net/ipv4/ipip.c +16 -0
@@ -358,6 +358,8 @@ static int ipip_fill_forward_path(struct net_device_path_ctx *ctx, {struct ip_tunnel *tunnel =netdev_priv (ctx->dev);const struct iphdr *tiph = &tunnel->parms.iph; +unsigned char ha[ETH_ALEN ]; +struct neighbour *n;struct rtable *rt;if (ctx->ether_type !=cpu_to_be16 (ETH_P_IP ))
@@ -375,6 +377,19 @@ static int ipip_fill_forward_path(struct net_device_path_ctx *ctx,if (IS_ERR (rt))return PTR_ERR (rt); + n =dst_neigh_lookup (&rt->dst, &tiph->daddr); +if (!n) { +ip_rt_put (rt); +return PTR_ERR (n); + } +if (n->dev->addr_len !=ETH_ALEN ) { +ip_rt_put (rt); +neigh_release (n); +return -EINVAL ; + } +neigh_ha_snapshot (ha, n, n->dev); +neigh_release (n); + path->type =DEV_PATH_TUN ; path->tun.src_v4.s_addr = tiph->saddr; path->tun.dst_v4.s_addr = tiph->daddr;
@@ -383,6 +398,7 @@ static int ipip_fill_forward_path(struct net_device_path_ctx *ctx, path->tun.dst = &rt->dst; path->dev = ctx->dev; +memcpy (ctx->daddr, ha,ETH_ALEN ); ctx->dev = rt->dst.dev;return 0 ;
net/ipv6/ip6_tunnel.c +28 -11
@@ -1840,7 +1840,9 @@ static int ip6_tnl_fill_forward_path(struct net_device_path_ctx *ctx, struct net_device_path *path) {struct ip6_tnl *t =netdev_priv (ctx->dev); +unsigned char ha[ETH_ALEN ];struct dst_entry *dst; +struct neighbour *n;struct flowi6 fl6;int err;
@@ -1863,20 +1865,35 @@ static int ip6_tnl_fill_forward_path(struct net_device_path_ctx *ctx, fl6.flowi6_proto =0 ; dst =ip6_route_output (dev_net (ctx->dev),NULL , &fl6); -if (!dst->error) { - path->type =DEV_PATH_TUN ; - path->tun.src_v6 = fl6.saddr; - path->tun.dst_v6 = fl6.daddr; - path->tun.inner_proto =IPPROTO_IPV6 ; - path->tun.encap_proto =AF_INET6 ; - path->tun.dst = dst; - path->dev = ctx->dev; - ctx->dev = dst->dev; + err = dst->error; +if (err) { +dst_release (dst); +return err; } - err = dst->error; -if (err) + n =dst_neigh_lookup (dst, &fl6.daddr); +if (!n) {dst_release (dst); +return PTR_ERR (n); + } +if (n->dev->addr_len !=ETH_ALEN ) { +dst_release (dst); +neigh_release (n); +return -EINVAL ; + } +neigh_ha_snapshot (ha, n, n->dev); +neigh_release (n); + + path->type =DEV_PATH_TUN ; + path->tun.src_v6 = fl6.saddr; + path->tun.dst_v6 = fl6.daddr; + path->tun.inner_proto =IPPROTO_IPV6 ; + path->tun.encap_proto =AF_INET6 ; + path->tun.dst = dst; + path->dev = ctx->dev; + +memcpy (ctx->daddr, ha,ETH_ALEN ); + ctx->dev = dst->dev;return err; }
net/netfilter/nf_flow_table_core.c +56 -3
84 lines not on this page · raw message
net/netfilter/nf_flow_table_ip.c +2 -14
@@ -844,7 +844,6 @@ static int nf_flow_queue_xmit4(struct sk_buff *skb,struct nf_flow_xmit xmit = {};union nf_inet_addr *ip_addr;struct flow_offload *flow; -struct neighbour *neigh;struct rtable *rt;if (unlikely (tuplehash->tuple.xmit_type ==FLOW_OFFLOAD_XMIT_XFRM )) {
@@ -872,12 +871,7 @@ static int nf_flow_queue_xmit4(struct sk_buff *skb,flow_offload_teardown (flow);return NF_DROP ; } - neigh =ip_neigh_gw4 (rt->dst.dev,rt_nexthop (rt, ip_addr->ip)); -if (IS_ERR (neigh)) { -flow_offload_teardown (flow); -return NF_DROP ; - } - xmit.dest = neigh->ha; + xmit.dest = tuplehash->tuple.out.h_dest;skb_dst_drop (skb);skb_dst_set_noref (skb, &rt->dst);break ;
@@ -1173,7 +1167,6 @@ static int nf_flow_queue_xmit6(struct sk_buff *skb,struct nf_flow_xmit xmit = {};union nf_inet_addr *ip_addr;struct flow_offload *flow; -struct neighbour *neigh;struct rt6_info *rt;if (unlikely (tuplehash->tuple.xmit_type ==FLOW_OFFLOAD_XMIT_XFRM )) {
@@ -1201,12 +1194,7 @@ static int nf_flow_queue_xmit6(struct sk_buff *skb,flow_offload_teardown (flow);return NF_DROP ; } - neigh =ip_neigh_gw6 (rt->dst.dev,rt6_nexthop (rt, &ip_addr->in6)); -if (IS_ERR (neigh)) { -flow_offload_teardown (flow); -return NF_DROP ; - } - xmit.dest = neigh->ha; + xmit.dest = tuplehash->tuple.out.h_dest;skb_dst_drop (skb);skb_dst_set_noref (skb, &rt->dst);break ;
net/netfilter/nf_flow_table_path.c +9 -2
@@ -57,6 +57,7 @@ static int nft_dev_fill_forward_path(const struct dst_entry *dst_cache, };struct neighbour *n;u8 nud_state; +int ret;if (!nft_is_valid_ether_device (dev)) {eth_zero_addr (ha);
@@ -79,7 +80,12 @@ static int nft_dev_fill_forward_path(const struct dst_entry *dst_cache, out:ether_addr_copy (ctx.daddr, ha); -return dev_fill_forward_path (&ctx, stack); + ret =dev_fill_forward_path (&ctx, stack); + +if (memcmp (ctx.daddr, ha,ETH_ALEN )) +ether_addr_copy (ha, ctx.daddr); + +return ret; }struct nft_forward_info {
@@ -264,9 +270,10 @@ static int nft_dev_forward_path(const struct nft_pktinfo *pkt, route->tuple[!dir].in.num_encaps = info.num_encaps; route->tuple[!dir].in.ingress_vlans = info.ingress_vlans; +memcpy (route->tuple[dir].out.h_dest, info.h_dest,ETH_ALEN ); +if (info.xmit_type ==FLOW_OFFLOAD_XMIT_DIRECT ) {memcpy (route->tuple[dir].out.h_source, info.h_source,ETH_ALEN ); -memcpy (route->tuple[dir].out.h_dest, info.h_dest,ETH_ALEN ); route->tuple[dir].xmit_type = info.xmit_type; } route->tuple[dir].out.needs_gso_segment = info.needs_gso_segment;
Signature · 1 line
2.47.3