bridge: Two small fixes to vlan filtering code.
Subsystems (3)
cover bridge: Two small fixes to vlan filtering code.
This series corrects 2 small issues that I've ran across recently while doing more work with vlan filtering changes.
Thanks
-vlad
Vlad Yasevich (1):
bridge: Check if vlan filtering is enabled only once.
bridge: Allow clearing of pvid and untagged bitmap
net/bridge/br_private.h | 3 +++ net/bridge/br_vlan.c | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-)
Signature · 1 line
1.9.3
PATCH 2/2 bridge: Allow clearing of pvid and untagged bitmap
From: Vlad Yasevich <[email protected]>
Currently, it is possible to modify the vlan filter configuration to add pvid or untagged support. For example:
bridge vlan add vid 10 dev eth0
bridge vlan add vid 10 dev eth0 untagged pvid
The second statement will modify vlan 10 to include untagged and pvid configuration. However, it is currently impossible to go backwards
bridge vlan add vid 10 dev eth0 untagged pvid bridge vlan add vid 10 dev eth0
Here nothing happens. This patch correct this so that any modifiers not supplied are removed from the configuration.
--- net/bridge/br_vlan.c | 4 ++++ 1 file changed, 4 insertions(+)
net/bridge/br_vlan.c +4 -0
@@ -27,9 +27,13 @@ static void __vlan_add_flags(struct net_port_vlans *v, u16 vid, u16 flags) {if (flags &BRIDGE_VLAN_INFO_PVID )__vlan_add_pvid (v, vid); +else +__vlan_delete_pvid (v, vid);if (flags &BRIDGE_VLAN_INFO_UNTAGGED )set_bit (vid, v->untagged_bitmap); +else +clear_bit (vid, v->untagged_bitmap); }static int __vlan_add (struct net_port_vlans *v,u16 vid,u16 flags)
Signature · 1 line
1.9.3
PATCH 1/2 bridge: Check if vlan filtering is enabled only once.
In reply to Vladislav YasevichThe 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.
---
Please consider for stable.
net/bridge/br_private.h | 3 +++ net/bridge/br_vlan.c | 14 ++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-)
net/bridge/br_private.h +3 -0
@@ -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)
net/bridge/br_vlan.c +10 -4
@@ -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
@@ -164,8 +165,10 @@ 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.
@@ -173,6 +176,7 @@ bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,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
@@ -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)
@@ -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);
Signature · 1 line
1.9.3
David Miller
maintainerFrom: Vladislav Yasevich <[email protected]>
Date: Fri, 12 Sep 2014 16:26:15 -0400
Quoted 2 lines
This series corrects 2 small issues that I've ran across recently while doing more work with vlan filtering changes.
Series applied and patch #1 queue up for -stable.
Re: [PATCH 1/2] bridge: Check if vlan filtering is enabled only once.
In reply to Vladislav YasevichQuoted 12 lines · Vladislav Yasevich
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_cbon ingress. Theskb_cbis 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.
...
net/bridge/br_vlan.c bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid) · line 282
Quoted 11 lines
net/bridge/br_vlan.c +2
-1@@ -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);
I'm afraid br_should_learn() is not called after calling br_allowed_ingress(), so vlan_filtered doesn't seem to be initialized at this point.
Thanks,
Toshiaki Makita
Re: [PATCH 1/2] bridge: Check if vlan filtering is enabled only once.
Quoted 23 lines · Toshiaki Makita
Quoted 12 lines · Vladislav Yasevich
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_cbon ingress. Theskb_cbis 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....
Quoted 9 lines
net/bridge/br_vlan.c +2
-1@@ -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;
Quoted 6 lines
net/bridge/br_vlan.c bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid) · line 282
Quoted 2 lines
net/bridge/br_vlan.c +0
-0v =rcu_dereference (p->vlan_info);I'm afraid
br_should_learn()is not called after callingbr_allowed_ingress(), sovlan_filtereddoesn't seem to be initialized at this point.
You are right. This the local input path so it can still use vlan_enabled. I'll resubmit.
Thanks
-vlad
Quoted 3 lines
Thanks,
Toshiaki Makita