Skip to content

Commit

Permalink
bridge: Check if vlan filtering is enabled only once.
Browse files Browse the repository at this point in the history
The bridge code checks if vlan filtering is enabled on both
ingress and egress.   When the state flip happens, it
is possible for the bridge to currently be forwarding packets
and forwarding behavior becomes non-deterministic.  Bridge
may drop packets on some interfaces, but not others.

This patch solves this by caching the filtered state of the
packet into skb_cb on ingress.  The skb_cb is guaranteed to
not be over-written between the time packet entres bridge
forwarding path and the time it leaves it.  On egress, we
can then check the cached state to see if we need to
apply filtering information.

Signed-off-by: Vladislav Yasevich <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
vyasevich authored and davem330 committed Sep 13, 2014
1 parent 9a72c2d commit 20adfa1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions net/bridge/br_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ struct br_input_skb_cb {
int igmp;
int mrouters_only;
#endif
#ifdef CONFIG_BRIDGE_VLAN_FILTERING
bool vlan_filtered;
#endif
};

#define BR_INPUT_SKB_CB(__skb) ((struct br_input_skb_cb *)(__skb)->cb)
Expand Down
14 changes: 10 additions & 4 deletions net/bridge/br_vlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ struct sk_buff *br_handle_vlan(struct net_bridge *br,
{
u16 vid;

if (!br->vlan_enabled)
/* If this packet was not filtered at input, let it pass */
if (!BR_INPUT_SKB_CB(skb)->vlan_filtered)
goto out;

/* Vlan filter table must be configured at this point. The
Expand Down Expand Up @@ -164,15 +165,18 @@ bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
/* If VLAN filtering is disabled on the bridge, all packets are
* permitted.
*/
if (!br->vlan_enabled)
if (!br->vlan_enabled) {
BR_INPUT_SKB_CB(skb)->vlan_filtered = false;
return true;
}

/* If there are no vlan in the permitted list, all packets are
* rejected.
*/
if (!v)
goto drop;

BR_INPUT_SKB_CB(skb)->vlan_filtered = true;
proto = br->vlan_proto;

/* If vlan tx offload is disabled on bridge device and frame was
Expand Down Expand Up @@ -251,7 +255,8 @@ bool br_allowed_egress(struct net_bridge *br,
{
u16 vid;

if (!br->vlan_enabled)
/* If this packet was not filtered at input, let it pass */
if (!BR_INPUT_SKB_CB(skb)->vlan_filtered)
return true;

if (!v)
Expand All @@ -270,7 +275,8 @@ bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid)
struct net_bridge *br = p->br;
struct net_port_vlans *v;

if (!br->vlan_enabled)
/* If filtering was disabled at input, let it pass. */
if (!BR_INPUT_SKB_CB(skb)->vlan_filtered)
return true;

v = rcu_dereference(p->vlan_info);
Expand Down

0 comments on commit 20adfa1

Please sign in to comment.