We can remove more unnecessary VLAN lookups if we pass the port-VLAN entry to the neighbour suppression helpers so they can use it directly instead of resolving it again. Use a vid wrapper for callers which don't have the port-VLAN entry. This removes up to two additional VLAN hash lookups per flooded egress port for packets marked as proxy replied.
Signed-off-by: Nikolay Aleksandrov <[email protected]> --- net/bridge/br_arp_nd_proxy.c | 51 ++++++++++++++++++++---------------- net/bridge/br_forward.c | 5 ++-- net/bridge/br_private.h | 6 +++-- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/net/bridge/br_arp_nd_proxy.c b/net/bridge/br_arp_nd_proxy.c index 9ce8f440e38f..da15f4d7c1ae 100644 --- a/net/bridge/br_arp_nd_proxy.c +++ b/net/bridge/br_arp_nd_proxy.c @@ -40,6 +40,23 @@ void br_recalculate_neigh_suppress_enabled(struct net_bridge *br) } #if IS_ENABLED(CONFIG_INET) +static bool +br_is_neigh_suppress_enabled_vid(const struct net_bridge_port *p, u16 vid) +{ + const struct net_bridge_vlan *v = NULL; + + if (p && vid && test_bit(BR_NEIGH_VLAN_SUPPRESS_BIT, &p->flags)) { + struct net_bridge_vlan_group *vg; + + vg = nbp_vlan_group_rcu(p); + v = br_vlan_find(vg, vid); + if (!v) + return false; + } + + return br_is_neigh_suppress_enabled(p, v); +} + static void br_arp_send(struct net_bridge *br, struct net_bridge_port *p, struct net_device *dev, __be32 dest_ip, __be32 src_ip, const unsigned char *dest_hw, @@ -159,7 +176,7 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, return; if (br_opt_get(br, BROPT_NEIGH_SUPPRESS_ENABLED)) { - if (br_is_neigh_suppress_enabled(p, vid)) + if (br_is_neigh_suppress_enabled_vid(p, vid)) return; if (is_unicast_ether_addr(eth_hdr(skb)->h_dest) && parp->ar_op == htons(ARPOP_REQUEST)) @@ -211,7 +228,7 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, if ((p && test_bit(BR_PROXYARP_BIT, &p->flags)) || (dst && test_bit(BR_PROXYARP_WIFI_BIT, &dst->flags)) || - br_is_neigh_suppress_enabled(dst, vid)) { + br_is_neigh_suppress_enabled_vid(dst, vid)) { if (!vid) br_arp_send(br, p, skb->dev, sip, tip, sha, ha, sha, 0, 0); @@ -424,7 +441,7 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, BR_INPUT_SKB_CB(skb)->proxyarp_replied = 0; BR_INPUT_SKB_CB(skb)->grat_arp = 0; - if (br_is_neigh_suppress_enabled(p, vid)) + if (br_is_neigh_suppress_enabled_vid(p, vid)) return; if (is_unicast_ether_addr(eth_hdr(skb)->h_dest) && @@ -486,7 +503,7 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, const struct net_bridge_port *dst = READ_ONCE(f->dst); bool replied = false; - if (br_is_neigh_suppress_enabled(dst, vid)) { + if (br_is_neigh_suppress_enabled_vid(dst, vid)) { if (vid != 0) br_nd_send(br, p, skb, n, ha, skb->vlan_proto, @@ -509,35 +526,25 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, } #endif -bool br_is_neigh_suppress_enabled(const struct net_bridge_port *p, u16 vid) +bool br_is_neigh_suppress_enabled(const struct net_bridge_port *p, + const struct net_bridge_vlan *v) { if (!p) return false; - if (vid && test_bit(BR_NEIGH_VLAN_SUPPRESS_BIT, &p->flags)) { - struct net_bridge_vlan_group *vg = nbp_vlan_group_rcu(p); - struct net_bridge_vlan *v; - - v = br_vlan_find(vg, vid); - if (!v) - return false; + if (v && test_bit(BR_NEIGH_VLAN_SUPPRESS_BIT, &p->flags)) return !!(READ_ONCE(v->priv_flags) & BR_VLFLAG_NEIGH_SUPPRESS_ENABLED); - } + return test_bit(BR_NEIGH_SUPPRESS_BIT, &p->flags); } -bool br_is_neigh_forward_grat_enabled(const struct net_bridge_port *p, u16 vid) +bool br_is_neigh_forward_grat_enabled(const struct net_bridge_port *p, + const struct net_bridge_vlan *v) { - if (vid && test_bit(BR_NEIGH_VLAN_SUPPRESS_BIT, &p->flags)) { - struct net_bridge_vlan_group *vg = nbp_vlan_group_rcu(p); - struct net_bridge_vlan *v; - - v = br_vlan_find(vg, vid); - if (!v) - return false; + if (v && test_bit(BR_NEIGH_VLAN_SUPPRESS_BIT, &p->flags)) return !!(READ_ONCE(v->priv_flags) & BR_VLFLAG_NEIGH_FORWARD_GRAT_ENABLED); - } + return test_bit(BR_NEIGH_FORWARD_GRAT_BIT, &p->flags); } diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c index d89f1b7d6def..b5eece1ff9e8 100644 --- a/net/bridge/br_forward.c +++ b/net/bridge/br_forward.c @@ -244,7 +244,6 @@ static int br_flood_port(struct br_fwd_dst *prev, enum br_pkt_type pkt_type, bool local_orig) { const struct net_bridge_port *p = fwd->port; - u16 vid = fwd->vlan ? fwd->vlan->vid : 0; /* Do not flood unicast traffic to ports that turn it off, nor * other traffic if flood off, except for traffic we originate @@ -275,9 +274,9 @@ static int br_flood_port(struct br_fwd_dst *prev, /* For gratuitous ARPs/NAs, check neigh_forward_grat. * For regular ARPs/NDs, check only neigh_suppress. */ - if (br_is_neigh_suppress_enabled(p, vid) && + if (br_is_neigh_suppress_enabled(p, fwd->vlan) && (!BR_INPUT_SKB_CB(skb)->grat_arp || - !br_is_neigh_forward_grat_enabled(p, vid))) + !br_is_neigh_forward_grat_enabled(p, fwd->vlan))) return 0; } diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 7c0b1d3e7931..67117fb3dc88 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -2390,6 +2390,8 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, u16 vid, struct net_bridge_port *p, struct nd_msg *msg); struct nd_msg *br_is_nd_neigh_msg(struct sk_buff *skb); -bool br_is_neigh_suppress_enabled(const struct net_bridge_port *p, u16 vid); -bool br_is_neigh_forward_grat_enabled(const struct net_bridge_port *p, u16 vid); +bool br_is_neigh_suppress_enabled(const struct net_bridge_port *p, + const struct net_bridge_vlan *v); +bool br_is_neigh_forward_grat_enabled(const struct net_bridge_port *p, + const struct net_bridge_vlan *v); #endif -- 2.47.3
