br_fill_forward_path() resolves the destination port from the fdb and checks only that the vlan exists on it. A port in STP blocking, learning or disabled state, or an MST vlan that is not forwarding on it, still gets a path, so the flowtable transmits straight to a port the bridge itself does not deliver to (should_deliver()). Add br_port_forwards(), the port and vlan part of should_deliver(), and fill a path only to a port it accepts. Signed-off-by: Julius Bairaktaris --- v10: new; v9 transmitted to a disabled port and in a vlan removed from the port, which the gc then left in place net/bridge/br_device.c | 2 +- net/bridge/br_forward.c | 19 +++++++++++++++++++ net/bridge/br_private.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c index 0a1ce9e59a4d4..f5860e88dbe95 100644 --- a/net/bridge/br_device.c +++ b/net/bridge/br_device.c @@ -402,7 +402,7 @@ static int br_fill_forward_path(struct net_device_path_ctx *ctx, return -1; dst = br_fdb_dst_port(f); - if (!dst) + if (!dst || !br_port_forwards(dst, path->bridge.vlan_id)) return -1; if (br_vlan_fill_forward_path_mode(br, dst, path)) diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c index 54365c6104b5c..9dbe9c9495582 100644 --- a/net/bridge/br_forward.c +++ b/net/bridge/br_forward.c @@ -31,6 +31,25 @@ static bool should_deliver_vlan(const struct br_fwd_dst *fwd, return br_allowed_egress(nbp_vlan_group_rcu(fwd->port), skb); } +/* Called under RCU. Whether @p forwards a frame in @vid, 0 without vlan + * filtering, as should_deliver() decides for a frame filtered at input. + */ +bool br_port_forwards(const struct net_bridge_port *p, u16 vid) +{ + struct net_bridge_vlan *v; + + if (!br_mst_is_enabled(p) && p->state != BR_STATE_FORWARDING) + return false; + + if (!br_opt_get(p->br, BROPT_VLAN_ENABLED)) + return !vid; + + v = br_vlan_find(nbp_vlan_group_rcu(p), vid); + + return v && br_vlan_should_use(v) && + br_vlan_state_allowed(br_vlan_get_state(v), false); +} + /* Don't forward packets to originating port or forwarding disabled */ static __always_inline bool should_deliver(const struct br_fwd_dst *fwd, const struct sk_buff *skb) diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 014d0b8db8c73..2c73d2549eaec 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -1048,6 +1048,7 @@ int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb void br_forward(struct net_bridge_dst dst, struct sk_buff *skb, bool local_rcv, bool local_orig); int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb); +bool br_port_forwards(const struct net_bridge_port *p, u16 vid); void br_flood(struct net_bridge *br, struct net_bridge_vlan *v, struct sk_buff *skb, enum br_pkt_type pkt_type, bool local_rcv, bool local_orig); -- 2.53.0