提交 85f46c6b 编写于 作者: V Vlad Yasevich 提交者: David S. Miller

bridge: Verify that a vlan is allowed to egress on given port

When bridge forwards a frame, make sure that a frame is allowed
to egress on that port.
Signed-off-by: NVlad Yasevich <vyasevic@redhat.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 a37b85c9
...@@ -31,6 +31,7 @@ static inline int should_deliver(const struct net_bridge_port *p, ...@@ -31,6 +31,7 @@ static inline int should_deliver(const struct net_bridge_port *p,
const struct sk_buff *skb) const struct sk_buff *skb)
{ {
return (((p->flags & BR_HAIRPIN_MODE) || skb->dev != p->dev) && return (((p->flags & BR_HAIRPIN_MODE) || skb->dev != p->dev) &&
br_allowed_egress(p->br, nbp_get_vlan_info(p), skb) &&
p->state == BR_STATE_FORWARDING); p->state == BR_STATE_FORWARDING);
} }
......
...@@ -35,6 +35,16 @@ static int br_pass_frame_up(struct sk_buff *skb) ...@@ -35,6 +35,16 @@ static int br_pass_frame_up(struct sk_buff *skb)
brstats->rx_bytes += skb->len; brstats->rx_bytes += skb->len;
u64_stats_update_end(&brstats->syncp); u64_stats_update_end(&brstats->syncp);
/* Bridge is just like any other port. Make sure the
* packet is allowed except in promisc modue when someone
* may be running packet capture.
*/
if (!(brdev->flags & IFF_PROMISC) &&
!br_allowed_egress(br, br_get_vlan_info(br), skb)) {
kfree_skb(skb);
return NET_RX_DROP;
}
indev = skb->dev; indev = skb->dev;
skb->dev = brdev; skb->dev = brdev;
......
...@@ -554,6 +554,9 @@ static inline void br_mdb_uninit(void) ...@@ -554,6 +554,9 @@ static inline void br_mdb_uninit(void)
#ifdef CONFIG_BRIDGE_VLAN_FILTERING #ifdef CONFIG_BRIDGE_VLAN_FILTERING
extern bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v, extern bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
struct sk_buff *skb); struct sk_buff *skb);
extern bool br_allowed_egress(struct net_bridge *br,
const struct net_port_vlans *v,
const struct sk_buff *skb);
extern int br_vlan_add(struct net_bridge *br, u16 vid); extern int br_vlan_add(struct net_bridge *br, u16 vid);
extern int br_vlan_delete(struct net_bridge *br, u16 vid); extern int br_vlan_delete(struct net_bridge *br, u16 vid);
extern void br_vlan_flush(struct net_bridge *br); extern void br_vlan_flush(struct net_bridge *br);
...@@ -598,6 +601,13 @@ static inline bool br_allowed_ingress(struct net_bridge *br, ...@@ -598,6 +601,13 @@ static inline bool br_allowed_ingress(struct net_bridge *br,
return true; return true;
} }
static inline bool br_allowed_egress(struct net_bridge *br,
const struct net_port_vlans *v,
const struct sk_buff *skb)
{
return true;
}
static inline int br_vlan_add(struct net_bridge *br, u16 vid) static inline int br_vlan_add(struct net_bridge *br, u16 vid)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
......
...@@ -89,6 +89,26 @@ bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v, ...@@ -89,6 +89,26 @@ bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
return false; return false;
} }
/* Called under RCU. */
bool br_allowed_egress(struct net_bridge *br,
const struct net_port_vlans *v,
const struct sk_buff *skb)
{
u16 vid;
if (!br->vlan_enabled)
return true;
if (!v)
return false;
br_vlan_get_tag(skb, &vid);
if (test_bit(vid, v->vlan_bitmap))
return true;
return false;
}
/* Must be protected by RTNL */ /* Must be protected by RTNL */
int br_vlan_add(struct net_bridge *br, u16 vid) int br_vlan_add(struct net_bridge *br, u16 vid)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册