bridge: Verify that a vlan is allowed to egress on given port
authorVlad Yasevich <vyasevic@redhat.com>
Wed, 13 Feb 2013 12:00:11 +0000 (12:00 +0000)
committerDavid S. Miller <davem@davemloft.net>
Thu, 14 Feb 2013 00:41:46 +0000 (19:41 -0500)
When bridge forwards a frame, make sure that a frame is allowed
to egress on that port.

Signed-off-by: Vlad Yasevich <vyasevic@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/bridge/br_forward.c
net/bridge/br_input.c
net/bridge/br_private.h
net/bridge/br_vlan.c

index 02015a505d2a41ddbf5c6abea3867613fe7030e8..35b0671f135d108a945a0a5cafe6b19516b984d1 100644 (file)
@@ -31,6 +31,7 @@ static inline int should_deliver(const struct net_bridge_port *p,
                                 const struct sk_buff *skb)
 {
        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);
 }
 
index 4ef3f6b17bd036520f4b533a5818a4da244ca3a3..787d7dad6b7e90e55b1c683d8ff0dee38ad3799a 100644 (file)
@@ -35,6 +35,16 @@ static int br_pass_frame_up(struct sk_buff *skb)
        brstats->rx_bytes += skb->len;
        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;
        skb->dev = brdev;
 
index ed7c764ee9dad5d4c5789c10dfe3cdc6e4e4291b..f0f24610d1119703c87f972124894d35a1f52f08 100644 (file)
@@ -554,6 +554,9 @@ static inline void br_mdb_uninit(void)
 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
 extern bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
                               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_delete(struct net_bridge *br, u16 vid);
 extern void br_vlan_flush(struct net_bridge *br);
@@ -598,6 +601,13 @@ static inline bool br_allowed_ingress(struct net_bridge *br,
        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)
 {
        return -EOPNOTSUPP;
index 8b4bcd8ff46e3e5ffde53a026b2ec7770722899c..d8690bfe63d4512def257ed3dff6520a6a3ae788 100644 (file)
@@ -89,6 +89,26 @@ bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
        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 */
 int br_vlan_add(struct net_bridge *br, u16 vid)
 {