diff options
| author | Vlad Yasevich <vyasevic@redhat.com> | 2013-02-13 07:00:15 -0500 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2013-02-13 19:42:15 -0500 |
| commit | 552406c488ec2cf1aaf8b5bd24d1750c9fd6d8cc (patch) | |
| tree | a107b251cc39ce383b1fad2dff97f0c088b3c172 | |
| parent | 7885198861fc9a3dfdc6bb90dc0ba12689d6cd57 (diff) | |
bridge: Add the ability to configure pvid
A user may designate a certain vlan as PVID. This means that
any ingress frame that does not contain a vlan tag is assigned to
this vlan and any forwarding decisions are made with this vlan in mind.
Signed-off-by: Vlad Yasevich <vyasevic@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
| -rw-r--r-- | include/uapi/linux/if_bridge.h | 1 | ||||
| -rw-r--r-- | net/bridge/br_netlink.c | 11 | ||||
| -rw-r--r-- | net/bridge/br_private.h | 8 | ||||
| -rw-r--r-- | net/bridge/br_vlan.c | 47 |
4 files changed, 50 insertions, 17 deletions
diff --git a/include/uapi/linux/if_bridge.h b/include/uapi/linux/if_bridge.h index 3ca9817ca7e8..c6c30e28f396 100644 --- a/include/uapi/linux/if_bridge.h +++ b/include/uapi/linux/if_bridge.h | |||
| @@ -120,6 +120,7 @@ enum { | |||
| 120 | #define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1) | 120 | #define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1) |
| 121 | 121 | ||
| 122 | #define BRIDGE_VLAN_INFO_MASTER (1<<0) /* Operate on Bridge device as well */ | 122 | #define BRIDGE_VLAN_INFO_MASTER (1<<0) /* Operate on Bridge device as well */ |
| 123 | #define BRIDGE_VLAN_INFO_PVID (1<<1) /* VLAN is PVID, ingress untagged */ | ||
| 123 | 124 | ||
| 124 | struct bridge_vlan_info { | 125 | struct bridge_vlan_info { |
| 125 | u16 flags; | 126 | u16 flags; |
diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index fe1980d5a7e4..e044cc0b5650 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c | |||
| @@ -120,6 +120,7 @@ static int br_fill_ifinfo(struct sk_buff *skb, | |||
| 120 | const struct net_port_vlans *pv; | 120 | const struct net_port_vlans *pv; |
| 121 | struct bridge_vlan_info vinfo; | 121 | struct bridge_vlan_info vinfo; |
| 122 | u16 vid; | 122 | u16 vid; |
| 123 | u16 pvid; | ||
| 123 | 124 | ||
| 124 | if (port) | 125 | if (port) |
| 125 | pv = nbp_get_vlan_info(port); | 126 | pv = nbp_get_vlan_info(port); |
| @@ -133,12 +134,15 @@ static int br_fill_ifinfo(struct sk_buff *skb, | |||
| 133 | if (!af) | 134 | if (!af) |
| 134 | goto nla_put_failure; | 135 | goto nla_put_failure; |
| 135 | 136 | ||
| 137 | pvid = br_get_pvid(pv); | ||
| 136 | for (vid = find_first_bit(pv->vlan_bitmap, BR_VLAN_BITMAP_LEN); | 138 | for (vid = find_first_bit(pv->vlan_bitmap, BR_VLAN_BITMAP_LEN); |
| 137 | vid < BR_VLAN_BITMAP_LEN; | 139 | vid < BR_VLAN_BITMAP_LEN; |
| 138 | vid = find_next_bit(pv->vlan_bitmap, | 140 | vid = find_next_bit(pv->vlan_bitmap, |
| 139 | BR_VLAN_BITMAP_LEN, vid+1)) { | 141 | BR_VLAN_BITMAP_LEN, vid+1)) { |
| 140 | vinfo.vid = vid; | 142 | vinfo.vid = vid; |
| 141 | vinfo.flags = 0; | 143 | vinfo.flags = 0; |
| 144 | if (vid == pvid) | ||
| 145 | vinfo.flags |= BRIDGE_VLAN_INFO_PVID; | ||
| 142 | if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO, | 146 | if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO, |
| 143 | sizeof(vinfo), &vinfo)) | 147 | sizeof(vinfo), &vinfo)) |
| 144 | goto nla_put_failure; | 148 | goto nla_put_failure; |
| @@ -239,14 +243,15 @@ static int br_afspec(struct net_bridge *br, | |||
| 239 | switch (cmd) { | 243 | switch (cmd) { |
| 240 | case RTM_SETLINK: | 244 | case RTM_SETLINK: |
| 241 | if (p) { | 245 | if (p) { |
| 242 | err = nbp_vlan_add(p, vinfo->vid); | 246 | err = nbp_vlan_add(p, vinfo->vid, vinfo->flags); |
| 243 | if (err) | 247 | if (err) |
| 244 | break; | 248 | break; |
| 245 | 249 | ||
| 246 | if (vinfo->flags & BRIDGE_VLAN_INFO_MASTER) | 250 | if (vinfo->flags & BRIDGE_VLAN_INFO_MASTER) |
| 247 | err = br_vlan_add(p->br, vinfo->vid); | 251 | err = br_vlan_add(p->br, vinfo->vid, |
| 252 | vinfo->flags); | ||
| 248 | } else | 253 | } else |
| 249 | err = br_vlan_add(br, vinfo->vid); | 254 | err = br_vlan_add(br, vinfo->vid, vinfo->flags); |
| 250 | 255 | ||
| 251 | if (err) | 256 | if (err) |
| 252 | break; | 257 | break; |
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index ea8e7efd9137..1ae6395a0369 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h | |||
| @@ -562,11 +562,11 @@ extern bool br_allowed_egress(struct net_bridge *br, | |||
| 562 | extern struct sk_buff *br_handle_vlan(struct net_bridge *br, | 562 | extern struct sk_buff *br_handle_vlan(struct net_bridge *br, |
| 563 | const struct net_port_vlans *v, | 563 | const struct net_port_vlans *v, |
| 564 | struct sk_buff *skb); | 564 | struct sk_buff *skb); |
| 565 | extern int br_vlan_add(struct net_bridge *br, u16 vid); | 565 | extern int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags); |
| 566 | extern int br_vlan_delete(struct net_bridge *br, u16 vid); | 566 | extern int br_vlan_delete(struct net_bridge *br, u16 vid); |
| 567 | extern void br_vlan_flush(struct net_bridge *br); | 567 | extern void br_vlan_flush(struct net_bridge *br); |
| 568 | extern int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val); | 568 | extern int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val); |
| 569 | extern int nbp_vlan_add(struct net_bridge_port *port, u16 vid); | 569 | extern int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags); |
| 570 | extern int nbp_vlan_delete(struct net_bridge_port *port, u16 vid); | 570 | extern int nbp_vlan_delete(struct net_bridge_port *port, u16 vid); |
| 571 | extern void nbp_vlan_flush(struct net_bridge_port *port); | 571 | extern void nbp_vlan_flush(struct net_bridge_port *port); |
| 572 | 572 | ||
| @@ -633,7 +633,7 @@ static inline struct sk_buff *br_handle_vlan(struct net_bridge *br, | |||
| 633 | return skb; | 633 | return skb; |
| 634 | } | 634 | } |
| 635 | 635 | ||
| 636 | static inline int br_vlan_add(struct net_bridge *br, u16 vid) | 636 | static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags) |
| 637 | { | 637 | { |
| 638 | return -EOPNOTSUPP; | 638 | return -EOPNOTSUPP; |
| 639 | } | 639 | } |
| @@ -647,7 +647,7 @@ static inline void br_vlan_flush(struct net_bridge *br) | |||
| 647 | { | 647 | { |
| 648 | } | 648 | } |
| 649 | 649 | ||
| 650 | static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid) | 650 | static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags) |
| 651 | { | 651 | { |
| 652 | return -EOPNOTSUPP; | 652 | return -EOPNOTSUPP; |
| 653 | } | 653 | } |
diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index 20057de56db0..c79940cff3a1 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c | |||
| @@ -5,12 +5,33 @@ | |||
| 5 | 5 | ||
| 6 | #include "br_private.h" | 6 | #include "br_private.h" |
| 7 | 7 | ||
| 8 | static int __vlan_add(struct net_port_vlans *v, u16 vid) | 8 | static void __vlan_add_pvid(struct net_port_vlans *v, u16 vid) |
| 9 | { | ||
| 10 | if (v->pvid == vid) | ||
| 11 | return; | ||
| 12 | |||
| 13 | smp_wmb(); | ||
| 14 | v->pvid = vid; | ||
| 15 | } | ||
| 16 | |||
| 17 | static void __vlan_delete_pvid(struct net_port_vlans *v, u16 vid) | ||
| 18 | { | ||
| 19 | if (v->pvid != vid) | ||
| 20 | return; | ||
| 21 | |||
| 22 | smp_wmb(); | ||
| 23 | v->pvid = 0; | ||
| 24 | } | ||
| 25 | |||
| 26 | static int __vlan_add(struct net_port_vlans *v, u16 vid, u16 flags) | ||
| 9 | { | 27 | { |
| 10 | int err; | 28 | int err; |
| 11 | 29 | ||
| 12 | if (test_bit(vid, v->vlan_bitmap)) | 30 | if (test_bit(vid, v->vlan_bitmap)) { |
| 13 | return -EEXIST; | 31 | if (flags & BRIDGE_VLAN_INFO_PVID) |
| 32 | __vlan_add_pvid(v, vid); | ||
| 33 | return 0; | ||
| 34 | } | ||
| 14 | 35 | ||
| 15 | if (v->port_idx && vid) { | 36 | if (v->port_idx && vid) { |
| 16 | struct net_device *dev = v->parent.port->dev; | 37 | struct net_device *dev = v->parent.port->dev; |
| @@ -29,6 +50,9 @@ static int __vlan_add(struct net_port_vlans *v, u16 vid) | |||
| 29 | 50 | ||
| 30 | set_bit(vid, v->vlan_bitmap); | 51 | set_bit(vid, v->vlan_bitmap); |
| 31 | v->num_vlans++; | 52 | v->num_vlans++; |
| 53 | if (flags & BRIDGE_VLAN_INFO_PVID) | ||
| 54 | __vlan_add_pvid(v, vid); | ||
| 55 | |||
| 32 | return 0; | 56 | return 0; |
| 33 | } | 57 | } |
| 34 | 58 | ||
| @@ -37,6 +61,8 @@ static int __vlan_del(struct net_port_vlans *v, u16 vid) | |||
| 37 | if (!test_bit(vid, v->vlan_bitmap)) | 61 | if (!test_bit(vid, v->vlan_bitmap)) |
| 38 | return -EINVAL; | 62 | return -EINVAL; |
| 39 | 63 | ||
| 64 | __vlan_delete_pvid(v, vid); | ||
| 65 | |||
| 40 | if (v->port_idx && vid) { | 66 | if (v->port_idx && vid) { |
| 41 | struct net_device *dev = v->parent.port->dev; | 67 | struct net_device *dev = v->parent.port->dev; |
| 42 | 68 | ||
| @@ -58,6 +84,8 @@ static int __vlan_del(struct net_port_vlans *v, u16 vid) | |||
| 58 | 84 | ||
| 59 | static void __vlan_flush(struct net_port_vlans *v) | 85 | static void __vlan_flush(struct net_port_vlans *v) |
| 60 | { | 86 | { |
| 87 | smp_wmb(); | ||
| 88 | v->pvid = 0; | ||
| 61 | bitmap_zero(v->vlan_bitmap, BR_VLAN_BITMAP_LEN); | 89 | bitmap_zero(v->vlan_bitmap, BR_VLAN_BITMAP_LEN); |
| 62 | if (v->port_idx) | 90 | if (v->port_idx) |
| 63 | rcu_assign_pointer(v->parent.port->vlan_info, NULL); | 91 | rcu_assign_pointer(v->parent.port->vlan_info, NULL); |
| @@ -185,7 +213,7 @@ bool br_allowed_egress(struct net_bridge *br, | |||
| 185 | } | 213 | } |
| 186 | |||
