Skip to contentSkip to conversation

Add basic VLAN support to bridges

PATCH Superseded Vlad Yasevich 3 participants 28 messages Feb 1, 2013 – Feb 7, 2013

Subsystems (4)

v9 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v9 cover Add basic VLAN support to bridges

Changes since v8:
* Unified vlans_to_* calls into a single interface
* Fixed the rest of the issues report by Michal Miroslaw
* Fixed a bug where fdb entries were not created for all added vlans.

Changes since v7:
* Rebases on the latest net-next and removed the vlan wrapper patch from the series.
* Fixed a crash in br_fdb_add/br_fdb_delete.

Changes since v6:
* VLANs are now stored in a VLAN bitmap per port. This allows for O(1) lookup at ingress and egress. We simply check to see if the bit associated with the vlan id is set in the map. The drawback to this approach is that it wastes some space when there is only a small number of VLANs.
* In addition to the build time configuration option, VLAN filtering also has a configuration paramter in sysfs. By default the filtering is turned off and all traffic is permitted. When the filtring is turned on, we do strict matching to the filter configured. Thus, if there is no configuration, all packets are rejected. This was done to make the behavior more streight forward. Without this (and if egress policy patch is rejected), the decision for how to forward untagged traffic that was not filtered at ingress is almost impossible to make. It would not be right to deliver to every port that has PVID set as, each port may have a different PVID.
* Separate egress policy bitmap patch has been isolated and is provided last in the series. This has been a more contentious piece of functionality and I wanted to isolate it so that it could easily be dropped and not block the whole series.

Changes since v5:
- Pulled VLAN filtering into its own file and made it a configuration options.
- Made new vlan filtering option dependent on VLAN_8021Q.
- Got rid of HW filter inlines and moved then vlan_core.c.
(All of the above suggested by Stephen Hemminger)

Changes since v4:
- Pull per-port vlan data into its own structures and give it to the bridge device thus making bridge device behave like a regular port for vlan configuration.
- Add a per-vlan 'untagged' bitmap that determins egress policy. If a port is part of this bitmap, traffic egresses untagged.
- PVID is now used for ingress policy only. Incomming frames without VLAN tag are assigned to the PVID vlan. Egress is determined via bitmap memberships.
- Allow for incremental config of a vlan. Now, PVID and untagged memberships may be set on existing vlans. They however can NOT be cleared separately.
- VLAN deletion is now done via RTM_DELLINK command for PF_BRIDGE family. This cleans up the netlink interface.

Changes since v3:
- Re-integrated compiler problems that got left out last time. Appologies.
- checkpatches.pl errors fixed

Changes since v2:
- Added inline functiosn to manimulate vlan hw filters and re-use in 8021q and bridge code.
- Use rtnl_dereference (Michael Tsirkin)
- Remove synchronize_net() call (Eric Dumazet)
- Fix NULL ptr deref bug I introduced in br_ifinfo_notify.

Changes since v1:
- Fixed some forwarding bugs.
- Add vlan to local fdb entries. New local entries are created per vlan to facilite correct forwarding to bridge interface.
- Allow configuration of vlans directly on the bridge master device in addition to ports.

Changes since rfc v2:
- Per-port vlan bitmap is gone and is replaced with a vlan list.
- Added bridge vlan list, which is referenced by each port. Entries in the birdge vlan list have port bitmap that shows which port are parts of which vlan.
- Netlink API changes.
- Dropped sysfs support for now. If people think this is really usefull, can add it back.
- Support for native/untagged vlans.

Changes since rfc v1:
- Comments addressed regarding formatting and RCU usage
- iocts have been removed and changed over the netlink interface.
- Added support of user added ndb entries.
- changed sysfs interface to export a bitmap. Also added a write interface. I am not sure how much I like it, but it made my testing easier/faster. I might change the write interface to take text instead of binary.

Vlad Yasevich (12):
bridge: Add vlan filtering infrastructure
bridge: Validate that vlan is permitted on ingress
bridge: Verify that a vlan is allowed to egress on give port
bridge: Add netlink interface to configure vlans on bridge ports
bridge: Add the ability to configure pvid
bridge: Implement vlan ingress/egress policy
bridge: Add vlan to unicast fdb entries
bridge: Add vlan id to multicast groups
bridge: Add vlan support to static neighbors
bridge: Add vlan support for local fdb entries
bridge: Dump vlan information from a bridge port
bridge: Separate egress policy bitmap

 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |    5 +-
 drivers/net/macvlan.c                         |    2 +-
 drivers/net/vxlan.c                           |    3 +-
 include/linux/netdevice.h                     |    6 +-
 include/uapi/linux/if_bridge.h                |   13 +-
 include/uapi/linux/neighbour.h                |    1 +
 include/uapi/linux/rtnetlink.h                |    1 +
 net/8021q/vlan_core.c                         |    1 +
 net/bridge/Kconfig                            |   14 +
 net/bridge/Makefile                           |    2 +
 net/bridge/br_device.c                        |    7 +-
 net/bridge/br_fdb.c                           |  259 ++++++++++++---
 net/bridge/br_forward.c                       |    9 +
 net/bridge/br_if.c                            |    4 +-
 net/bridge/br_input.c                         |   28 ++-
 net/bridge/br_multicast.c                     |   69 +++--
 net/bridge/br_netlink.c                       |  239 ++++++++++++--
 net/bridge/br_private.h                       |  152 ++++++++-
 net/bridge/br_sysfs_br.c                      |   21 ++
 net/bridge/br_vlan.c                          |  444 +++++++++++++++++++++++++
 net/core/rtnetlink.c                          |  111 ++++++-
 21 files changed, 1262 insertions(+), 129 deletions(-)
 create mode 100644 net/bridge/br_vlan.c
Signature · 1 line
1.7.7.6
#1 lore raw

PATCH v9 1/12 bridge: Add vlan filtering infrastructure

Adds an optional infrustructure component to bridge that would allow native vlan filtering in the bridge. Each bridge port (as well as the bridge device) now get a VLAN bitmap. Each bit in the bitmap is associated with a vlan id. This way if the bit corresponding to the vid is set in the bitmap that the packet with vid is allowed to enter and exit the port.

Write access the bitmap is protected by RTNL and read access protected by RCU.

Vlan functionality is disabled by default.

---
 net/bridge/Kconfig       |   14 +++
 net/bridge/Makefile      |    2 +
 net/bridge/br_if.c       |    1 +
 net/bridge/br_private.h  |   55 +++++++++++
 net/bridge/br_sysfs_br.c |   21 +++++
 net/bridge/br_vlan.c     |  223 ++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 316 insertions(+), 0 deletions(-)
 create mode 100644 net/bridge/br_vlan.c
net/bridge/Kconfig +14 -0
index 6dee7bf..aa0d3b2 100644
@@ -46,3 +46,17 @@ config BRIDGE_IGMP_SNOOPING
 	  Say N to exclude this support and reduce the binary size.
 
 	  If unsure, say Y.
+
+config BRIDGE_VLAN_FILTERING
+	bool "VLAN filtering"
+	depends on BRIDGE
+	depends on VLAN_8021Q
+	default n
+	---help---
+	  If you say Y here, then the Ethernet bridge will be able selectively
+	  receive and forward traffic based on VLAN information in the packet
+	  any VLAN information configured on the bridge port or bridge device.
+
+	  Say N to exclude this support and reduce the binary size.
+
+	  If unsure, say Y.
net/bridge/Makefile +2 -0
index e859098..e85498b2f 100644
@@ -14,4 +14,6 @@ bridge-$(CONFIG_BRIDGE_NETFILTER) += br_netfilter.o
 
 bridge-$(CONFIG_BRIDGE_IGMP_SNOOPING) += br_multicast.o br_mdb.o
 
+bridge-$(CONFIG_BRIDGE_VLAN_FILTERING) += br_vlan.o
+
 obj-$(CONFIG_BRIDGE_NF_EBTABLES) += netfilter/
net/bridge/br_if.c +1 -0
index 2148d47..af9d65a 100644
@@ -139,6 +139,7 @@ static void del_nbp(struct net_bridge_port *p)
 
 	br_ifinfo_notify(RTM_DELLINK, p);
 
+	nbp_vlan_flush(p);
 	br_fdb_delete_by_port(br, p, 1);
 
 	list_del_rcu(&p->list);
net/bridge/br_private.h +55 -0

91 lines not on this page · raw message

net/bridge/br_sysfs_br.c +21 -0
index 5913a3a..8baa9c0 100644
@@ -691,6 +691,24 @@ static ssize_t store_nf_call_arptables(
 static DEVICE_ATTR(nf_call_arptables, S_IRUGO | S_IWUSR,
 		   show_nf_call_arptables, store_nf_call_arptables);
 #endif
+#ifdef CONFIG_BRIDGE_VLAN_FILTERING
+static ssize_t show_vlan_filtering(struct device *d,
+				   struct device_attribute *attr,
+				   char *buf)
+{
+	struct net_bridge *br = to_bridge(d);
+	return sprintf(buf, "%d\n", br->vlan_enabled);
+}
+
+static ssize_t store_vlan_filtering(struct device *d,
+				    struct device_attribute *attr,
+				    const char *buf, size_t len)
+{
+	return store_bridge_parm(d, buf, len, br_vlan_filter_toggle);
+}
+static DEVICE_ATTR(vlan_filtering, S_IRUGO | S_IWUSR,
+		   show_vlan_filtering, store_vlan_filtering);
+#endif
 
 static struct attribute *bridge_attrs[] = {
 	&dev_attr_forward_delay.attr,
@@ -732,6 +750,9 @@ static struct attribute *bridge_attrs[] = {
 	&dev_attr_nf_call_ip6tables.attr,
 	&dev_attr_nf_call_arptables.attr,
 #endif
+#ifdef CONFIG_BRIDGE_VLAN_FILTERING
+	&dev_attr_vlan_filtering.attr,
+#endif
 	NULL
 };
 
net/bridge/br_vlan.c new file +223 -0

223 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#2 lore raw

Re: [PATCH v9 net-next 01/12] bridge: Add vlan filtering infrastructure

2013/2/1 Vlad Yasevich <[email protected]>:

Quoted 6 lines

Adds an optional infrustructure component to bridge that would allow native vlan filtering in the bridge. Each bridge port (as well as the bridge device) now get a VLAN bitmap. Each bit in the bitmap is associated with a vlan id. This way if the bit corresponding to the vid is set in the bitmap that the packet with vid is allowed to enter and exit the port.

[...]
+struct net_port_vlans {

+       u16                             port_idx;
+       void                            *parent;
+       struct rcu_head                 rcu;
+       unsigned long                   vlan_bitmap[BR_VLAN_BITMAP_LEN];

+};
[later, in br_vlan.c]
+#define vlans_to_parent(type, pv) ((type *)(pv)->parent)

A really don't like this pointer casting. It's easy to get it wrong (and you did in __vlan_del).

1. union { struct net_bridge *br; struct net_bridge_port *port; } parent;

2. inline net_port_vlans __rcu **br_vlan_info_parent_ptr(struct net_port_vlans *v)

{
	return v->port_idx ? &v->parent.port->vlan_info : &v->parent.br->vlan_info;
}

(I'm not insisting on #2. Just think about it. ;)

net/bridge/br_private.h struct net_bridge_port · line 170

Quoted 6 lines
net/bridge/br_private.h +1 -0
@@ -156,6 +166,7 @@ struct net_bridge_port
 #ifdef CONFIG_NET_POLL_CONTROLLER
        struct netpoll                  *np;
 #endif
+       struct net_port_vlans __rcu     *vlan_info;
 };

Missing #ifdef CONFIG_BRIDGE_VLAN_FILTERING?

Quoted 8 lines
net/bridge/br_vlan.c new file +8 -0
+static int __vlan_del(struct net_port_vlans *v, u16 vid)
+{
+       unsigned long first_bit;
+       unsigned long last_bit;
+
+       if (!test_bit(vid, v->vlan_bitmap))
+               return -EINVAL;
+

net/bridge/br_vlan.c line 54

Quoted 10 lines
net/bridge/br_vlan.c new file +10 -0
+       /* Check to see if any other vlans are in this table.  If this
+        * is the last vlan, delete the whole structure.  If this is not the
+        * last vlan, just clear the bit.
+        */
+       first_bit = find_first_bit(v->vlan_bitmap, BR_VLAN_BITMAP_LEN);
+       last_bit = find_last_bit(v->vlan_bitmap, BR_VLAN_BITMAP_LEN);
+
+       if (v->port_idx && vid) {
+               struct net_device *dev =
+                       vlans_to_parent(struct net_bridge, v)->dev;

struct net_bridge_port (or union and v->parent.port)

net/bridge/br_vlan.c line 61

Quoted 7 lines
net/bridge/br_vlan.c new file +7 -0
+
+               if (dev->features & NETIF_F_HW_VLAN_FILTER)
+                       dev->netdev_ops->ndo_vlan_rx_kill_vid(dev, vid);
+       }
+
+       clear_bit(vid, v->vlan_bitmap);
+       if (first_bit == last_bit) {

bitmap_empty() is faster than two times find_xxx_bit().

net/bridge/br_vlan.c line 70

Quoted 9 lines
net/bridge/br_vlan.c new file +9 -0
+               if (v->port_idx) {
+                       struct net_bridge_port *p =
+                               vlans_to_parent(struct net_bridge_port, v);
+                       rcu_assign_pointer(p->vlan_info, NULL);
+               } else {
+                       struct net_bridge *br =
+                               vlans_to_parent(struct net_bridge, v);
+                       rcu_assign_pointer(br->vlan_info, NULL);
+               }

With inline function above:

rcu_assign_pointer(*br_vlan_info_parent_ptr(v), NULL);

Quoted 7 lines
net/bridge/br_vlan.c new file +7 -0
+               kfree_rcu(v, rcu);
+       }
+       return 0;
+}
+
+static void __vlan_flush(struct net_port_vlans *v)
+{

net/bridge/br_vlan.c line 87

Quoted 10 lines
net/bridge/br_vlan.c new file +10 -0
+       bitmap_zero(v->vlan_bitmap, BR_VLAN_BITMAP_LEN);
+       if (v->port_idx) {
+               struct net_bridge_port *p =
+                               vlans_to_parent(struct net_bridge_port, v);
+               rcu_assign_pointer(p->vlan_info, NULL);
+       } else {
+               struct net_bridge *br =
+                               vlans_to_parent(struct net_bridge, v);
+               rcu_assign_pointer(br->vlan_info, NULL);
+       }

Same here.

Review

Quoted 2 lines
(quoted diff) +2 -0
+       kfree_rcu(v, rcu);
+}

Best Regards,
Michał Mirosław

#3 lore raw

Re: [PATCH v9 net-next 01/12] bridge: Add vlan filtering infrastructure

Quoted 22 lines · Michał Mirosław

2013/2/1 Vlad Yasevich <[email protected]>:

Quoted 6 lines

Adds an optional infrustructure component to bridge that would allow native vlan filtering in the bridge. Each bridge port (as well as the bridge device) now get a VLAN bitmap. Each bit in the bitmap is associated with a vlan id. This way if the bit corresponding to the vid is set in the bitmap that the packet with vid is allowed to enter and exit the port.

[...]

net/bridge/br_private.h +6 -0
+struct net_port_vlans {
+       u16                             port_idx;
+       void                            *parent;
+       struct rcu_head                 rcu;
+       unsigned long                   vlan_bitmap[BR_VLAN_BITMAP_LEN];
+};

[later, in br_vlan.c]
+#define vlans_to_parent(type, pv) ((type *)(pv)->parent)

A really don't like this pointer casting. It's easy to get it wrong (and you did in __vlan_del).

1. union { struct net_bridge *br; struct net_bridge_port *port; } parent;

Quoted 7 lines

2. inline net_port_vlans __rcu **br_vlan_info_parent_ptr(struct net_port_vlans *v)

{
	return v->port_idx ? &v->parent.port->vlan_info : &v->parent.br->vlan_info;
}

(I'm not insisting on #2. Just think about it. ;)

I need the parent, not the vlan_info. Sometimes I need to get to the device and I really don't want to then use container_of().

I suppose I could do the union, but that's really not much different then the type casts. Just as easy to goof.

Quoted 9 lines

net/bridge/br_private.h struct net_bridge_port · line 170

Quoted 7 lines
net/bridge/br_private.h +1 -0
@@ -156,6 +166,7 @@ struct net_bridge_port
  #ifdef CONFIG_NET_POLL_CONTROLLER
         struct netpoll                  *np;
  #endif
+       struct net_port_vlans __rcu     *vlan_info;
  };

Missing #ifdef CONFIG_BRIDGE_VLAN_FILTERING?

Yep. Its in net_bridge, but not here. Will fix.

Quoted 13 lines
Quoted 13 lines
net/bridge/br_vlan.c new file +12 -0
+static int __vlan_del(struct net_port_vlans *v, u16 vid)
+{
+       unsigned long first_bit;
+       unsigned long last_bit;
+
+       if (!test_bit(vid, v->vlan_bitmap))
+               return -EINVAL;
+
+       /* Check to see if any other vlans are in this table.  If this
+        * is the last vlan, delete the whole structure.  If this is not the
+        * last vlan, just clear the bit.
+        */
Quoted 8 lines

net/bridge/br_vlan.c line 54

Quoted 6 lines
net/bridge/br_vlan.c new file +6 -0
+       first_bit = find_first_bit(v->vlan_bitmap, BR_VLAN_BITMAP_LEN);
+       last_bit = find_last_bit(v->vlan_bitmap, BR_VLAN_BITMAP_LEN);
+
+       if (v->port_idx && vid) {
+               struct net_device *dev =
+                       vlans_to_parent(struct net_bridge, v)->dev;

struct net_bridge_port (or union and v->parent.port)

Yep. Typo when doing conversions.

Quoted 11 lines

net/bridge/br_vlan.c line 61

Quoted 8 lines
net/bridge/br_vlan.c new file +7 -0
+
+               if (dev->features & NETIF_F_HW_VLAN_FILTER)
+                       dev->netdev_ops->ndo_vlan_rx_kill_vid(dev, vid);
+       }
+
+       clear_bit(vid, v->vlan_bitmap);
+       if (first_bit == last_bit) {

bitmap_empty() is faster than two times find_xxx_bit().

WTH? I did this change and now its gone... Time to see what else I somehow lost...

Quoted 25 lines

net/bridge/br_vlan.c line 70

Quoted 9 lines
net/bridge/br_vlan.c new file +9 -0
+               if (v->port_idx) {
+                       struct net_bridge_port *p =
+                               vlans_to_parent(struct net_bridge_port, v);
+                       rcu_assign_pointer(p->vlan_info, NULL);
+               } else {
+                       struct net_bridge *br =
+                               vlans_to_parent(struct net_bridge, v);
+                       rcu_assign_pointer(br->vlan_info, NULL);
+               }

With inline function above:

rcu_assign_pointer(*br_vlan_info_parent_ptr(v), NULL);

Quoted 11 lines
net/bridge/br_vlan.c new file +11 -0
+               kfree_rcu(v, rcu);
+       }
+       return 0;
+}
+
+static void __vlan_flush(struct net_port_vlans *v)
+{
+       bitmap_zero(v->vlan_bitmap, BR_VLAN_BITMAP_LEN);
+       if (v->port_idx) {
+               struct net_bridge_port *p =
+                               vlans_to_parent(struct net_bridge_port, v);
Quoted 8 lines

net/bridge/br_vlan.c line 70

Quoted 6 lines
net/bridge/br_vlan.c new file +6 -0
+               rcu_assign_pointer(p->vlan_info, NULL);
+       } else {
+               struct net_bridge *br =
+                               vlans_to_parent(struct net_bridge, v);
+               rcu_assign_pointer(br->vlan_info, NULL);
+       }

Same here.

Thanks. I'll probably go with the union for direct reference.

-vlad

Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+       kfree_rcu(v, rcu);
+}

Best Regards,
Michał Mirosław

#4 lore raw

PATCH v9 2/12 bridge: Validate that vlan is permitted on ingress

In reply to Vlad Yasevich

When a frame arrives on a port or transmitted by the bridge, if we have VLANs configured, validate that a given VLAN is allowed to enter the bridge.

---
 net/bridge/br_device.c  |    3 ++
 net/bridge/br_input.c   |    4 +++
 net/bridge/br_private.h |   48 +++++++++++++++++++++++++++++++++++++++++++++++
 net/bridge/br_vlan.c    |   25 ++++++++++++++++++++++++
 4 files changed, 80 insertions(+), 0 deletions(-)
net/bridge/br_device.c +3 -0
index e1bc090..92b5b18 100644
@@ -45,6 +45,9 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
 	brstats->tx_bytes += skb->len;
 	u64_stats_update_end(&brstats->syncp);
 
+	if (!br_allowed_ingress(br, br_get_vlan_info(br), skb))
+		goto out;
+
 	BR_INPUT_SKB_CB(skb)->brdev = dev;
 
 	skb_reset_mac_header(skb);
net/bridge/br_input.c +4 -0
index 4b34207..4ef3f6b 100644
@@ -17,6 +17,7 @@
 #include <linux/etherdevice.h>
 #include <linux/netfilter_bridge.h>
 #include <linux/export.h>
+#include <linux/rculist.h>
 #include "br_private.h"
 
 /* Hook for brouter */
@@ -54,6 +55,9 @@ int br_handle_frame_finish(struct sk_buff *skb)
 	if (!p || p->state == BR_STATE_DISABLED)
 		goto drop;
 
+	if (!br_allowed_ingress(p->br, nbp_get_vlan_info(p), skb))
+		goto drop;
+
 	/* insert into forwarding database after filtering to avoid spoofing */
 	br = p->br;
 	br_fdb_update(br, p, eth_hdr(skb)->h_source);
net/bridge/br_private.h +48 -0

67 lines not on this page · raw message

net/bridge/br_vlan.c +25 -0
index 8d9ded5..c3ae3f9 100644
@@ -88,6 +88,31 @@ static void __vlan_flush(struct net_port_vlans *v)
 	kfree_rcu(v, rcu);
 }
 
+/* Called under RCU */
+bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
+			struct sk_buff *skb)
+{
+	u16 vid;
+
+	/* If VLAN filtering is disabled on the bridge, all packets are
+	 * permitted.
+	 */
+	if (!br->vlan_enabled)
+		return true;
+
+	/* If there are no vlan in the permitted list, all packets are
+	 * rejected.
+	 */
+	if (!v)
+		return false;
+
+	vid = br_vlan_get_tag(skb);
+	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)
 {
Signature · 1 line
1.7.7.6
#5 lore raw

Re: [PATCH v9 net-next 02/12] bridge: Validate that vlan is permitted on ingress

2013/2/1 Vlad Yasevich <[email protected]>:

Quoted 3 lines

When a frame arrives on a port or transmitted by the bridge, if we have VLANs configured, validate that a given VLAN is allowed to enter the bridge.

[...]

net/bridge/br_private.h extern int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val); · line 574

Quoted 11 lines
net/bridge/br_private.h +11 -0
+static inline struct net_port_vlans *br_get_vlan_info(
+                                               const struct net_bridge *br)
+{
+       return rcu_dereference(br->vlan_info);
+}
+
+static inline struct net_port_vlans *nbp_get_vlan_info(
+                                               const struct net_bridge_port *p)
+{
+       return rcu_dereference(p->vlan_info);
+}

Those should go to patch #1.

Best Regards,
Michał Mirosław

#6 lore raw

Re: [PATCH v9 net-next 02/12] bridge: Validate that vlan is permitted on ingress

Quoted 5 lines · Michał Mirosław

2013/2/1 Vlad Yasevich <[email protected]>:

Quoted 3 lines

When a frame arrives on a port or transmitted by the bridge, if we have VLANs configured, validate that a given VLAN is allowed to enter the bridge.

[...]

Quoted 13 lines

net/bridge/br_private.h extern int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val); · line 574

Quoted 11 lines
net/bridge/br_private.h +11 -0
+static inline struct net_port_vlans *br_get_vlan_info(
+                                               const struct net_bridge *br)
+{
+       return rcu_dereference(br->vlan_info);
+}
+
+static inline struct net_port_vlans *nbp_get_vlan_info(
+                                               const struct net_bridge_port *p)
+{
+       return rcu_dereference(p->vlan_info);
+}

Those should go to patch #1.

They are not needed till here. I thought it would read/review better if I kept it together.

-vlad

Quoted 4 lines

Best Regards,
Michał Mirosław

#7 lore raw

PATCH v9 3/12 bridge: Verify that a vlan is allowed to egress on give port

In reply to Vlad Yasevich

When bridge forwards a frame, make sure that a frame is allowed to egress on that port.

---
 net/bridge/br_forward.c |    1 +
 net/bridge/br_input.c   |   10 ++++++++++
 net/bridge/br_private.h |   10 ++++++++++
 net/bridge/br_vlan.c    |   20 ++++++++++++++++++++
 4 files changed, 41 insertions(+), 0 deletions(-)
net/bridge/br_forward.c +1 -0
index 02015a5..35b0671 100644
@@ -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);
 }
 
net/bridge/br_input.c +10 -0
index 4ef3f6b..787d7da 100644
@@ -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;
 
net/bridge/br_private.h +10 -0
index 6db6822..5e7bc90 100644
@@ -553,6 +553,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);
@@ -592,6 +595,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;
net/bridge/br_vlan.c +20 -0
index c3ae3f9..a291bca 100644
@@ -113,6 +113,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;
+
+	vid = br_vlan_get_tag(skb);
+	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)
 {
Signature · 1 line
1.7.7.6
#8 lore raw

PATCH v9 4/12 bridge: Add netlink interface to configure vlans on bridge ports

In reply to Vlad Yasevich

Add a netlink interface to add and remove vlan configuration on bridge port. The interface uses the RTM_SETLINK message and encodes the vlan configuration inside the IFLA_AF_SPEC. It is possble to include multiple vlans to either add or remove in a single message.

---
 include/linux/netdevice.h      |    2 +
 include/uapi/linux/if_bridge.h |    9 +++
 net/bridge/br_device.c         |    1 +
 net/bridge/br_if.c             |    1 +
 net/bridge/br_netlink.c        |  139 ++++++++++++++++++++++++++++++++++-----
 net/bridge/br_private.h        |    1 +
 net/core/rtnetlink.c           |   72 +++++++++++++++++++++
 7 files changed, 207 insertions(+), 18 deletions(-)
include/linux/netdevice.h +2 -0
index 85b0949..51553c7 100644
@@ -1020,6 +1020,8 @@ struct net_device_ops {
 	int			(*ndo_bridge_getlink)(struct sk_buff *skb,
 						      u32 pid, u32 seq,
 						      struct net_device *dev);
+	int			(*ndo_bridge_dellink)(struct net_device *dev,
+						      struct nlmsghdr *nlh);
 	int			(*ndo_change_carrier)(struct net_device *dev,
 						      bool new_carrier);
 };
include/uapi/linux/if_bridge.h +9 -0
index 5db2975..3ca9817 100644
@@ -108,15 +108,24 @@ struct __fdb_entry {
  * [IFLA_AF_SPEC] = {
  *     [IFLA_BRIDGE_FLAGS]
  *     [IFLA_BRIDGE_MODE]
+ *     [IFLA_BRIDGE_VLAN_INFO]
  * }
  */
 enum {
 	IFLA_BRIDGE_FLAGS,
 	IFLA_BRIDGE_MODE,
+	IFLA_BRIDGE_VLAN_INFO,
 	__IFLA_BRIDGE_MAX,
 };
 #define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)
 
+#define BRIDGE_VLAN_INFO_MASTER	(1<<0)	/* Operate on Bridge device as well */
+
+struct bridge_vlan_info {
+	u16 flags;
+	u16 vid;
+};
+
 /* Bridge multicast database attributes
  * [MDBA_MDB] = {
  *     [MDBA_MDB_ENTRY] = {
net/bridge/br_device.c +1 -0
index 92b5b18..d325c2d 100644
@@ -317,6 +317,7 @@ static const struct net_device_ops br_netdev_ops = {
 	.ndo_fdb_dump		 = br_fdb_dump,
 	.ndo_bridge_getlink	 = br_getlink,
 	.ndo_bridge_setlink	 = br_setlink,
+	.ndo_bridge_dellink	 = br_dellink,
 };
 
 static void br_dev_free(struct net_device *dev)
net/bridge/br_if.c +1 -0
index af9d65a..335c60c 100644
@@ -23,6 +23,7 @@
 #include <linux/if_ether.h>
 #include <linux/slab.h>
 #include <net/sock.h>
+#include <linux/if_vlan.h>
 
 #include "br_private.h"
 
net/bridge/br_netlink.c +121 -18

193 lines not on this page · raw message

net/bridge/br_private.h +1 -0
index 5e7bc90..801a707 100644
@@ -707,6 +707,7 @@ extern int br_netlink_init(void);
 extern void br_netlink_fini(void);
 extern void br_ifinfo_notify(int event, struct net_bridge_port *port);
 extern int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg);
+extern int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg);
 extern int br_getlink(struct sk_buff *skb, u32 pid, u32 seq,
 		      struct net_device *dev);
 
net/core/rtnetlink.c +72 -0

84 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#9 lore raw

PATCH v9 5/12 bridge: Add the ability to configure pvid

In reply to Vlad Yasevich

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.

---
 include/uapi/linux/if_bridge.h |    1 +
 net/bridge/br_netlink.c        |    7 +++--
 net/bridge/br_private.h        |    9 ++++---
 net/bridge/br_vlan.c           |   49 +++++++++++++++++++++++++++++++--------
 4 files changed, 49 insertions(+), 17 deletions(-)
include/uapi/linux/if_bridge.h +1 -0
index 3ca9817..c6c30e2 100644
@@ -120,6 +120,7 @@ enum {
 #define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)
 
 #define BRIDGE_VLAN_INFO_MASTER	(1<<0)	/* Operate on Bridge device as well */
+#define BRIDGE_VLAN_INFO_PVID	(1<<1)	/* VLAN is PVID, ingress untagged */
 
 struct bridge_vlan_info {
 	u16 flags;
net/bridge/br_netlink.c +4 -3
index 534a9f4..0089a3f 100644
@@ -198,14 +198,15 @@ static int br_afspec(struct net_bridge *br,
 		switch (cmd) {
 		case RTM_SETLINK:
 			if (p) {
-				err = nbp_vlan_add(p, vinfo->vid);
+				err = nbp_vlan_add(p, vinfo->vid, vinfo->flags);
 				if (err)
 					break;
 
 				if (vinfo->flags & BRIDGE_VLAN_INFO_MASTER)
-					err = br_vlan_add(p->br, vinfo->vid);
+					err = br_vlan_add(p->br, vinfo->vid,
+							  vinfo->flags);
 			} else
-				err = br_vlan_add(br, vinfo->vid);
+				err = br_vlan_add(br, vinfo->vid, vinfo->flags);
 
 			if (err)
 				break;
net/bridge/br_private.h +5 -4
index 801a707..7ad26f5 100644
@@ -68,6 +68,7 @@ struct br_ip
 
 struct net_port_vlans {
 	u16				port_idx;
+	u16				pvid;
 	void				*parent;
 	struct rcu_head			rcu;
 	unsigned long			vlan_bitmap[BR_VLAN_BITMAP_LEN];
@@ -556,11 +557,11 @@ extern bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
 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, u16 flags);
 extern int br_vlan_delete(struct net_bridge *br, u16 vid);
 extern void br_vlan_flush(struct net_bridge *br);
 extern int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val);
-extern int nbp_vlan_add(struct net_bridge_port *port, u16 vid);
+extern int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags);
 extern int nbp_vlan_delete(struct net_bridge_port *port, u16 vid);
 extern void nbp_vlan_flush(struct net_bridge_port *port);
 
@@ -602,7 +603,7 @@ static inline bool br_allowed_egress(struct net_bridge *br,
 	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, u16 flags)
 {
 	return -EOPNOTSUPP;
 }
@@ -616,7 +617,7 @@ static inline void br_vlan_flush(struct net_bridge *br)
 {
 }
 
-static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid)
+static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags)
 {
 	return -EOPNOTSUPP;
 }
net/bridge/br_vlan.c +39 -10

118 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#10 lore raw

Re: [PATCH v9 net-next 05/12] bridge: Add the ability to configure pvid

2013/2/1 Vlad Yasevich <[email protected]>:

Quoted 3 lines

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.

[...]

Quoted 3 lines
 struct net_port_vlans {
        u16                             port_idx;

+ u16 pvid;

I'm confused about the implementation. I would expect pvid field in net_bridge_port and adding a tag if it isn't there on ingress path. The rest would be just like without PVIDs. But here you pvid field to net_port_vlans, and don't do anything with it in receive nor transmit path. Does it work? What am I missing?

Best Regards,
Michał Mirosław

#11 lore raw

Re: [PATCH v9 net-next 05/12] bridge: Add the ability to configure pvid

2013/2/2 Michał Mirosław <[email protected]>:

Quoted 9 lines

2013/2/1 Vlad Yasevich <[email protected]>:

Quoted 3 lines

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.

[...]

Quoted 3 lines
 struct net_port_vlans {
        u16                             port_idx;

+ u16 pvid;

Quoted 5 lines

I'm confused about the implementation. I would expect pvid field in net_bridge_port and adding a tag if it isn't there on ingress path. The rest would be just like without PVIDs. But here you pvid field to net_port_vlans, and don't do anything with it in receive nor transmit path. Does it work? What am I missing?

Found the answer in next patch (you should merge #5 and #6). Still, the implementation looks overly complicated. If you force the packet to canonical form on ingress (keeping outer tag in skb->vlan_tci, and setting skb->vlan_tci = pvid if there is no tag) the code should get simpler.

Best Regards,
Michał Mirosław

#12 lore raw

Re: [PATCH v9 net-next 05/12] bridge: Add the ability to configure pvid

Quoted 10 lines · Michał Mirosław

2013/2/2 Michał Mirosław <[email protected]>:

Quoted 9 lines

2013/2/1 Vlad Yasevich <[email protected]>:

Quoted 3 lines

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.

[...]

Quoted 3 lines
  struct net_port_vlans {
         u16                             port_idx;

+ u16 pvid;

Quoted 7 lines
Quoted 5 lines

I'm confused about the implementation. I would expect pvid field in net_bridge_port and adding a tag if it isn't there on ingress path. The rest would be just like without PVIDs. But here you pvid field to net_port_vlans, and don't do anything with it in receive nor transmit path. Does it work? What am I missing?

Found the answer in next patch (you should merge #5 and #6).

It was split for incremental testing. #5 added the ability to set and delete it without impacting anything. #6 added the actual work that pvid does.

Quoted 5 lines

Still,
the implementation looks overly complicated. If you force the packet to canonical form on ingress (keeping outer tag in skb->vlan_tci, and setting skb->vlan_tci = pvid if there is no tag) the code should get simpler.

What if there is no outer tag? That's what the ingress code is doing. If there is no outer tag, pvid is written to vlan_tci. If there was outer tag in vlan_tci, it's left alone. This way at the end of ingress vlan_tci is always set.
At egress, we grab that tag and compare it against pvid if any. If it matches, it's stripped. If it doesn't, we output with the tag thus adding the header.

The only thing I can simplify is grab the tci directly at egress, but that's what the code will do anyway.

-vlad

Quoted 4 lines

Best Regards,
Michał Mirosław

#13 lore raw

Re: [PATCH v9 net-next 05/12] bridge: Add the ability to configure pvid

2013/2/2 Vlad Yasevich <[email protected]>:

Quoted 39 lines · Michał Mirosław
Quoted 13 lines

2013/2/2 Michał Mirosław <[email protected]>:

Quoted 12 lines

2013/2/1 Vlad Yasevich <[email protected]>:

Quoted 3 lines

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.

[...]

Quoted 4 lines
  struct net_port_vlans {
         u16                             port_idx;

+ u16 pvid;

Quoted 6 lines
Quoted 5 lines

I'm confused about the implementation. I would expect pvid field in net_bridge_port and adding a tag if it isn't there on ingress path. The rest would be just like without PVIDs. But here you pvid field to net_port_vlans, and don't do anything with it in receive nor transmit path. Does it work? What am I missing?

Found the answer in next patch (you should merge #5 and #6).

It was split for incremental testing. #5 added the ability to set and delete it without impacting anything. #6 added the actual work that pvid does.

Quoted 5 lines

Still,
the implementation looks overly complicated. If you force the packet to canonical form on ingress (keeping outer tag in skb->vlan_tci, and setting skb->vlan_tci = pvid if there is no tag) the code should get simpler.

What if there is no outer tag? That's what the ingress code is doing. If there is no outer tag, pvid is written to vlan_tci. If there was outer tag in vlan_tci, it's left alone. This way at the end of ingress vlan_tci is always set.
At egress, we grab that tag and compare it against pvid if any. If it matches, it's stripped. If it doesn't, we output with the tag thus adding the header.

Quoted 2 lines

The only thing I can simplify is grab the tci directly at egress, but that's what the code will do anyway.

... br_allowed_input(..., struct sk_buff **pskb)
{
*pskb = vlan_untag(*pskb);
skb = *pskb;
if (!skb)

    return 0;

if (!skb->vlan_tci && (pvid & VLAN_TAG_PRESENT))

    skb->vlan_tci = pvid;

return check_vlan_allowed(skb->vlan_tci);
}

struct sk_buff *br_handle_vlan(..., struct sk_buff *skb)
{
/* we guaranteed in br_allowed_input() that all packets processed
in bridge code
* will be like received with NETIF_F_HW_VLAN_RX feature enabled. */
if (skb->vlan_tci & (VLAN_VID_MASK|VLAN_TAG_PRESENT) == pvid)

     skb->vlan_tci = 0;  // what about 802.1p?

return skb;
}

BTW, you implement three features: VLAN filtering, PVID handling, per-VLAN FDB. Yet there are 10 patches that mix and match parts of the implementation. It's really hard to review this when you have to jump between patches to understand whats going on. I don't know what the best split would be, but I got the feeling that this is not the presented one.

Best Regards,
Michał Mirosław

#14 lore raw

Re: [PATCH v9 net-next 05/12] bridge: Add the ability to configure pvid

2013/2/3 Michał Mirosław <[email protected]>:

Quoted 48 lines

2013/2/2 Vlad Yasevich <[email protected]>:

Quoted 39 lines · Michał Mirosław
Quoted 13 lines

2013/2/2 Michał Mirosław <[email protected]>:

Quoted 12 lines

2013/2/1 Vlad Yasevich <[email protected]>:

Quoted 3 lines

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.

[...]

Quoted 4 lines
  struct net_port_vlans {
         u16                             port_idx;

+ u16 pvid;

Quoted 6 lines
Quoted 5 lines

I'm confused about the implementation. I would expect pvid field in net_bridge_port and adding a tag if it isn't there on ingress path. The rest would be just like without PVIDs. But here you pvid field to net_port_vlans, and don't do anything with it in receive nor transmit path. Does it work? What am I missing?

Found the answer in next patch (you should merge #5 and #6).

It was split for incremental testing. #5 added the ability to set and delete it without impacting anything. #6 added the actual work that pvid does.

Quoted 5 lines

Still,
the implementation looks overly complicated. If you force the packet to canonical form on ingress (keeping outer tag in skb->vlan_tci, and setting skb->vlan_tci = pvid if there is no tag) the code should get simpler.

What if there is no outer tag? That's what the ingress code is doing. If there is no outer tag, pvid is written to vlan_tci. If there was outer tag in vlan_tci, it's left alone. This way at the end of ingress vlan_tci is always set.
At egress, we grab that tag and compare it against pvid if any. If it matches, it's stripped. If it doesn't, we output with the tag thus adding the header.

Quoted 2 lines

The only thing I can simplify is grab the tci directly at egress, but that's what the code will do anyway.

... br_allowed_input(..., struct sk_buff **pskb)
{
*pskb = vlan_untag(*pskb);
skb = *pskb;
if (!skb)

Quoted 6 lines
    return 0;

if (!skb->vlan_tci && (pvid & VLAN_TAG_PRESENT))

    skb->vlan_tci = pvid;

return check_vlan_allowed(skb->vlan_tci);
}

Or maybe some cheating to save unconditional vlan_untag()ging: since vlan_tci is used only when vlan_tx_tag_present() returns true, we can cache VID there for the bridge code when VLANs are not HW-accelerated. I'm not sure of this one as I don't know if the netfilter part keeps vlan_tci intact (quick grep suggests it does).

... br_allowed_input(..., struct sk_buff **pskb)
{
skb = *pskb;

  if (!vlan_tx_tag_present(skb)) {
    if (!__vlan_get_tag(skb, &skb->vlan_tci))
      skb->vlan_tci &= VLAN_VID_MASK;
    else
      skb->vlan_tci = 0;
  }
  if (!skb->vlan_tci && pvid & VLAN_TAG_PRESENT)  // FIXME:
802.1p-tagged is put in VLAN 0
    skb->vlan_tci = pvid;

return check_vlan_allowed(skb, skb->vlan_tci & VLAN_VID_MASK);
}

struct sk_buff *br_handle_vlan(..., struct sk_buff *skb) {
/* we guaranteed in br_allowed_input() that all packets processed /* in bridge code will be like received with NETIF_F_HW_VLAN_RX
* feature enabled or have VID cached in vlan_tci without
* VLAN_TAG_PRESENT bit set. */

if ((skb->vlan_tci & VLAN_VID_MASK) | VLAN_TAG_PRESENT != pvid)

     return skb;
   if (!vlan_tx_tag_present(skb)) {
      skb = vlan_untag(skb);
      if (!skb)
        return skb;

}
skb->vlan_tci = 0; // FIXME: what about 802.1p? return skb;
}

Best Regards,
Michał Mirosław

#15 lore raw

Re: [PATCH v9 net-next 05/12] bridge: Add the ability to configure pvid

In reply to Michał Mirosław
Quoted 44 lines · Michał Mirosław

2013/2/2 Vlad Yasevich <[email protected]>:

Quoted 39 lines · Michał Mirosław
Quoted 13 lines

2013/2/2 Michał Mirosław <[email protected]>:

Quoted 12 lines

2013/2/1 Vlad Yasevich <[email protected]>:

Quoted 3 lines

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.

[...]

Quoted 4 lines
   struct net_port_vlans {
          u16                             port_idx;

+ u16 pvid;

Quoted 6 lines
Quoted 5 lines

I'm confused about the implementation. I would expect pvid field in net_bridge_port and adding a tag if it isn't there on ingress path. The rest would be just like without PVIDs. But here you pvid field to net_port_vlans, and don't do anything with it in receive nor transmit path. Does it work? What am I missing?

Found the answer in next patch (you should merge #5 and #6).

It was split for incremental testing. #5 added the ability to set and delete it without impacting anything. #6 added the actual work that pvid does.

Quoted 5 lines

Still,
the implementation looks overly complicated. If you force the packet to canonical form on ingress (keeping outer tag in skb->vlan_tci, and setting skb->vlan_tci = pvid if there is no tag) the code should get simpler.

What if there is no outer tag? That's what the ingress code is doing. If there is no outer tag, pvid is written to vlan_tci. If there was outer tag in vlan_tci, it's left alone. This way at the end of ingress vlan_tci is always set.
At egress, we grab that tag and compare it against pvid if any. If it matches, it's stripped. If it doesn't, we output with the tag thus adding the header.

Quoted 2 lines

The only thing I can simplify is grab the tci directly at egress, but that's what the code will do anyway.

... br_allowed_input(..., struct sk_buff **pskb)

Quoted 10 lines
{
   *pskb = vlan_untag(*pskb);
   skb = *pskb;
   if (!skb)
     return 0;

   if (!skb->vlan_tci && (pvid & VLAN_TAG_PRESENT))
     skb->vlan_tci = pvid;
   return check_vlan_allowed(skb->vlan_tci);
}

vlan_untag typically already happens for non-accelerated packets, so no need to call it again. We shouldn't really be touching accelerated packets at ingress, because we may have to undo what we've done on egress. That would be very expensive in case of flooding.

Quoted 10 lines

struct sk_buff *br_handle_vlan(..., struct sk_buff *skb)

{
    /* we guaranteed in br_allowed_input() that all packets processed
in bridge code
     * will be like received with NETIF_F_HW_VLAN_RX feature enabled. */
    if (skb->vlan_tci & (VLAN_VID_MASK|VLAN_TAG_PRESENT) == pvid)
      skb->vlan_tci = 0;  // what about 802.1p?
    return skb;
}

This doesn't work for when you should be sending a tagged frame to the bridge device when receive was non-accelerated. It would mean that the 802.1q header was already stripped, and you have to put it back correctly so that it can go through the vlan interface (think vlan on top of bridge).

Quoted 4 lines

BTW, you implement three features: VLAN filtering, PVID handling, per-VLAN FDB. Yet there are 10 patches that mix and match parts of the implementation.

I've tried to separate them as well as I can. I guess the only ones out
of order are 11 and 12. 12 is last on purpose since its contentious and can be easily dropped from the end. I can and should move 11 in with main vlan filtering code. Essentially 1-5 would be VLAN filtering, 5 & 6 would be PVID, and the rest would FDB.

If you can see a better breakdown, I would appreciate it.

Thanks
-vlad

Quoted 8 lines

It's really hard to review this when you have to jump between patches to understand whats going on. I don't know what the best split would be, but I got the feeling that this is not the presented one.

Best Regards,
Michał Mirosław

#16 lore raw

PATCH v9 6/12 bridge: Implement vlan ingress/egress policy

In reply to Vlad Yasevich

This patch implements the ingress/egress policy. At ingress, any untagged traffic is assigned to the PVID. Any tagged traffic is filtered according to membership bitmap.

At egress, if the vlan matches the pvid, the frame is sent untagged. Otherwise the frame is sent tagged.

---
 net/8021q/vlan_core.c   |    1 +
 net/bridge/br_device.c  |    3 +-
 net/bridge/br_forward.c |    8 ++++
 net/bridge/br_input.c   |    7 +++-
 net/bridge/br_private.h |   31 +++++++++++-----
 net/bridge/br_vlan.c    |   93 +++++++++++++++++++++++++++++++++++++++++++----
 6 files changed, 125 insertions(+), 18 deletions(-)
net/8021q/vlan_core.c +1 -0
index 71b64fd..f3b6f51 100644
@@ -144,6 +144,7 @@ err_free:
 	kfree_skb(skb);
 	return NULL;
 }
+EXPORT_SYMBOL(vlan_untag);
 
 
 /*
net/bridge/br_device.c +2 -1
index d325c2d..bce7a52 100644
@@ -30,6 +30,7 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
 	struct net_bridge_fdb_entry *dst;
 	struct net_bridge_mdb_entry *mdst;
 	struct br_cpu_netstats *brstats = this_cpu_ptr(br->stats);
+	u16 vid = 0;
 
 	rcu_read_lock();
 #ifdef CONFIG_BRIDGE_NETFILTER
@@ -45,7 +46,7 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
 	brstats->tx_bytes += skb->len;
 	u64_stats_update_end(&brstats->syncp);
 
-	if (!br_allowed_ingress(br, br_get_vlan_info(br), skb))
+	if (!br_allowed_ingress(br, br_get_vlan_info(br), skb, &vid))
 		goto out;
 
 	BR_INPUT_SKB_CB(skb)->brdev = dev;
net/bridge/br_forward.c +8 -0
index 35b0671..092b20e 100644
@@ -64,6 +64,10 @@ int br_forward_finish(struct sk_buff *skb)
 
 static void __br_deliver(const struct net_bridge_port *to, struct sk_buff *skb)
 {
+	skb = br_handle_vlan(to->br, nbp_get_vlan_info(to), skb);
+	if (!skb)
+		return;
+
 	skb->dev = to->dev;
 
 	if (unlikely(netpoll_tx_running(to->br->dev))) {
@@ -89,6 +93,10 @@ static void __br_forward(const struct net_bridge_port *to, struct sk_buff *skb)
 		return;
 	}
 
+	skb = br_handle_vlan(to->br, nbp_get_vlan_info(to), skb);
+	if (!skb)
+		return;
+
 	indev = skb->dev;
 	skb->dev = to->dev;
 	skb_forward_csum(skb);
net/bridge/br_input.c +6 -1
index 787d7da..a63f227 100644
@@ -45,6 +45,10 @@ static int br_pass_frame_up(struct sk_buff *skb)
 		return NET_RX_DROP;
 	}
 
+	skb = br_handle_vlan(br, br_get_vlan_info(br), skb);
+	if (!skb)
+		return NET_RX_DROP;
+
 	indev = skb->dev;
 	skb->dev = brdev;
 
@@ -61,11 +65,12 @@ int br_handle_frame_finish(struct sk_buff *skb)
 	struct net_bridge_fdb_entry *dst;
 	struct net_bridge_mdb_entry *mdst;
 	struct sk_buff *skb2;
+	u16 vid = 0;
 
 	if (!p || p->state == BR_STATE_DISABLED)
 		goto drop;
 
-	if (!br_allowed_ingress(p->br, nbp_get_vlan_info(p), skb))
+	if (!br_allowed_ingress(p->br, nbp_get_vlan_info(p), skb, &vid))
 		goto drop;
 
 	/* insert into forwarding database after filtering to avoid spoofing */
net/bridge/br_private.h +22 -9
index 7ad26f5..907b5df 100644
@@ -553,10 +553,13 @@ static inline void br_mdb_uninit(void)
 /* br_vlan.c */
 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
 extern bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
-			       struct sk_buff *skb);
+			       struct sk_buff *skb, u16 *vid);
 extern bool br_allowed_egress(struct net_bridge *br,
 			      const struct net_port_vlans *v,
 			      const struct sk_buff *skb);
+extern struct sk_buff *br_handle_vlan(struct net_bridge *br,
+				      const struct net_port_vlans *v,
+				      struct sk_buff *skb);
 extern int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags);
 extern int br_vlan_delete(struct net_bridge *br, u16 vid);
 extern void br_vlan_flush(struct net_bridge *br);
@@ -577,21 +580,24 @@ static inline struct net_port_vlans *nbp_get_vlan_info(
 	return rcu_dereference(p->vlan_info);
 }
 
-static inline u16 br_vlan_get_tag(const struct sk_buff *skb)
+
+static inline int br_vlan_get_tag(const struct sk_buff *skb, u16 *tag)
 {
-	u16 tag;
+	int rc = 0;
 
 	if (vlan_tx_tag_present(skb))
-		tag = vlan_tx_tag_get(skb);
-	else if (vlan_get_tag(skb, &tag))
-		tag = 0;
+		*tag = vlan_tx_tag_get(skb);
+	else
+		rc = vlan_get_tag(skb, tag);
 
-	return tag & VLAN_VID_MASK;
+	*tag = *tag & VLAN_VID_MASK;
+	return rc;
 }
 #else
 static inline bool br_allowed_ingress(struct net_bridge *br,
 				      struct net_port_vlans *v,
-				      struct sk_buff *skb)
+				      struct sk_buff *skb,
+				      u16 *vid)
 {
 	return true;
 }
@@ -603,6 +609,13 @@ static inline bool br_allowed_egress(struct net_bridge *br,
 	return true;
 }
 
+static inline struct sk_buff *br_handle_vlan(struct net_bridge *br,
+					     const struct net_port_vlans *v,
+					     struct sk_buff *skb)
+{
+	return skb;
+}
+
 static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags)
 {
 	return -EOPNOTSUPP;
@@ -642,7 +655,7 @@ static inline struct net_port_vlans *nbp_get_vlan_info(
 	return NULL;
 }
 
-static inline u16 br_vlan_get_tag(const struct sk_buff *skb)
+static inline u16 br_vlan_get_tag(const struct sk_buff *skb, u16 *tag)
 {
 	return 0;
 }
net/bridge/br_vlan.c +86 -7

120 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#17 lore raw

PATCH v9 7/12 bridge: Add vlan to unicast fdb entries

In reply to Vlad Yasevich

This patch adds vlan to unicast fdb entries that are created for learned addresses (not the manually configured ones). It adds vlan id into the hash mix and uses vlan as an addditional parameter for an entry match.

---
 include/uapi/linux/if_bridge.h |    2 +-
 net/bridge/br_device.c         |    2 +-
 net/bridge/br_fdb.c            |   70 +++++++++++++++++++++++----------------
 net/bridge/br_input.c          |    9 +++--
 net/bridge/br_private.h        |    7 +++-
 5 files changed, 54 insertions(+), 36 deletions(-)
include/uapi/linux/if_bridge.h +1 -1
index c6c30e2..875c9e2 100644
@@ -94,7 +94,7 @@ struct __fdb_entry {
 	__u32 ageing_timer_value;
 	__u8 port_hi;
 	__u8 pad0;
-	__u16 unused;
+	__u16 fdb_vid;
 };
 
 /* Bridge Flags */
net/bridge/br_device.c +1 -1
index bce7a52..d7bb57b 100644
@@ -71,7 +71,7 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
 			br_multicast_deliver(mdst, skb);
 		else
 			br_flood_deliver(br, skb);
-	} else if ((dst = __br_fdb_get(br, dest)) != NULL)
+	} else if ((dst = __br_fdb_get(br, dest, vid)) != NULL)
 		br_deliver(dst->dst, skb);
 	else
 		br_flood_deliver(br, skb);
net/bridge/br_fdb.c +41 -29

213 lines not on this page · raw message

net/bridge/br_input.c +6 -3
index a63f227..4803301 100644
@@ -75,7 +75,7 @@ int br_handle_frame_finish(struct sk_buff *skb)
 
 	/* insert into forwarding database after filtering to avoid spoofing */
 	br = p->br;
-	br_fdb_update(br, p, eth_hdr(skb)->h_source);
+	br_fdb_update(br, p, eth_hdr(skb)->h_source, vid);
 
 	if (!is_broadcast_ether_addr(dest) && is_multicast_ether_addr(dest) &&
 	    br_multicast_rcv(br, p, skb))
@@ -110,7 +110,8 @@ int br_handle_frame_finish(struct sk_buff *skb)
 			skb2 = skb;
 
 		br->dev->stats.multicast++;
-	} else if ((dst = __br_fdb_get(br, dest)) && dst->is_local) {
+	} else if ((dst = __br_fdb_get(br, dest, vid)) &&
+			dst->is_local) {
 		skb2 = skb;
 		/* Do not forward the packet since it's local. */
 		skb = NULL;
@@ -138,8 +139,10 @@ drop:
 static int br_handle_local_finish(struct sk_buff *skb)
 {
 	struct net_bridge_port *p = br_port_get_rcu(skb->dev);
+	u16 vid = 0;
 
-	br_fdb_update(p->br, p, eth_hdr(skb)->h_source);
+	br_vlan_get_tag(skb, &vid);
+	br_fdb_update(p->br, p, eth_hdr(skb)->h_source, vid);
 	return 0;	 /* process further */
 }
 
net/bridge/br_private.h +5 -2
index 907b5df..6dd94df 100644
@@ -85,6 +85,7 @@ struct net_bridge_fdb_entry
 	mac_addr			addr;
 	unsigned char			is_local;
 	unsigned char			is_static;
+	__u16				vlan_id;
 };
 
 struct net_bridge_port_group {
@@ -371,7 +372,8 @@ extern void br_fdb_cleanup(unsigned long arg);
 extern void br_fdb_delete_by_port(struct net_bridge *br,
 				  const struct net_bridge_port *p, int do_all);
 extern struct net_bridge_fdb_entry *__br_fdb_get(struct net_bridge *br,
-						 const unsigned char *addr);
+						 const unsigned char *addr,
+						 __u16 vid);
 extern int br_fdb_test_addr(struct net_device *dev, unsigned char *addr);
 extern int br_fdb_fillbuf(struct net_bridge *br, void *buf,
 			  unsigned long count, unsigned long off);
@@ -380,7 +382,8 @@ extern int br_fdb_insert(struct net_bridge *br,
 			 const unsigned char *addr);
 extern void br_fdb_update(struct net_bridge *br,
 			  struct net_bridge_port *source,
-			  const unsigned char *addr);
+			  const unsigned char *addr,
+			  u16 vid);
 
 extern int br_fdb_delete(struct ndmsg *ndm,
 			 struct net_device *dev,
Signature · 1 line
1.7.7.6
#18 lore raw

PATCH v9 8/12 bridge: Add vlan id to multicast groups

In reply to Vlad Yasevich

Add vlan_id to multicasts groups so that we know which vlan each group belongs to and can correctly forward to appropriate vlan.

---
 net/bridge/br_multicast.c |   69 ++++++++++++++++++++++++++++++++-------------
 net/bridge/br_private.h   |    1 +
 2 files changed, 50 insertions(+), 20 deletions(-)
net/bridge/br_multicast.c +49 -20
index 6d6f265..7d886b0 100644
@@ -39,6 +39,8 @@ static inline int br_ip_equal(const struct br_ip *a, const struct br_ip *b)
 {
 	if (a->proto != b->proto)
 		return 0;
+	if (a->vid != b->vid)
+		return 0;
 	switch (a->proto) {
 	case htons(ETH_P_IP):
 		return a->u.ip4 == b->u.ip4;
@@ -50,16 +52,19 @@ static inline int br_ip_equal(const struct br_ip *a, const struct br_ip *b)
 	return 0;
 }
 
-static inline int __br_ip4_hash(struct net_bridge_mdb_htable *mdb, __be32 ip)
+static inline int __br_ip4_hash(struct net_bridge_mdb_htable *mdb, __be32 ip,
+				__u16 vid)
 {
-	return jhash_1word(mdb->secret, (__force u32)ip) & (mdb->max - 1);
+	return jhash_2words((__force u32)ip, vid, mdb->secret) & (mdb->max - 1);
 }
 
 #if IS_ENABLED(CONFIG_IPV6)
 static inline int __br_ip6_hash(struct net_bridge_mdb_htable *mdb,
-				const struct in6_addr *ip)
+				const struct in6_addr *ip,
+				__u16 vid)
 {
-	return jhash2((__force u32 *)ip->s6_addr32, 4, mdb->secret) & (mdb->max - 1);
+	return jhash_2words(ipv6_addr_hash(ip), vid,
+			    mdb->secret) & (mdb->max - 1);
 }
 #endif
 
@@ -68,10 +73,10 @@ static inline int br_ip_hash(struct net_bridge_mdb_htable *mdb,
 {
 	switch (ip->proto) {
 	case htons(ETH_P_IP):
-		return __br_ip4_hash(mdb, ip->u.ip4);
+		return __br_ip4_hash(mdb, ip->u.ip4, ip->vid);
 #if IS_ENABLED(CONFIG_IPV6)
 	case htons(ETH_P_IPV6):
-		return __br_ip6_hash(mdb, &ip->u.ip6);
+		return __br_ip6_hash(mdb, &ip->u.ip6, ip->vid);
 #endif
 	}
 	return 0;
@@ -101,24 +106,27 @@ struct net_bridge_mdb_entry *br_mdb_ip_get(struct net_bridge_mdb_htable *mdb,
 }
 
 static struct net_bridge_mdb_entry *br_mdb_ip4_get(
-	struct net_bridge_mdb_htable *mdb, __be32 dst)
+	struct net_bridge_mdb_htable *mdb, __be32 dst, __u16 vid)
 {
 	struct br_ip br_dst;
 
 	br_dst.u.ip4 = dst;
 	br_dst.proto = htons(ETH_P_IP);
+	br_dst.vid = vid;
 
 	return br_mdb_ip_get(mdb, &br_dst);
 }
 
 #if IS_ENABLED(CONFIG_IPV6)
 static struct net_bridge_mdb_entry *br_mdb_ip6_get(
-	struct net_bridge_mdb_htable *mdb, const struct in6_addr *dst)
+	struct net_bridge_mdb_htable *mdb, const struct in6_addr *dst,
+	__u16 vid)
 {
 	struct br_ip br_dst;
 
 	br_dst.u.ip6 = *dst;
 	br_dst.proto = htons(ETH_P_IPV6);
+	br_dst.vid = vid;
 
 	return br_mdb_ip_get(mdb, &br_dst);
 }
@@ -694,7 +702,8 @@ err:
 
 static int br_ip4_multicast_add_group(struct net_bridge *br,
 				      struct net_bridge_port *port,
-				      __be32 group)
+				      __be32 group,
+				      __u16 vid)
 {
 	struct br_ip br_group;
 
@@ -703,6 +712,7 @@ static int br_ip4_multicast_add_group(struct net_bridge *br,
 
 	br_group.u.ip4 = group;
 	br_group.proto = htons(ETH_P_IP);
+	br_group.vid = vid;
 
 	return br_multicast_add_group(br, port, &br_group);
 }
@@ -710,7 +720,8 @@ static int br_ip4_multicast_add_group(struct net_bridge *br,
 #if IS_ENABLED(CONFIG_IPV6)
 static int br_ip6_multicast_add_group(struct net_bridge *br,
 				      struct net_bridge_port *port,
-				      const struct in6_addr *group)
+				      const struct in6_addr *group,
+				      __u16 vid)
 {
 	struct br_ip br_group;
 
@@ -719,6 +730,7 @@ static int br_ip6_multicast_add_group(struct net_bridge *br,
 
 	br_group.u.ip6 = *group;
 	br_group.proto = htons(ETH_P_IPV6);
+	br_group.vid = vid;
 
 	return br_multicast_add_group(br, port, &br_group);
 }
@@ -895,10 +907,12 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br,
 	int type;
 	int err = 0;
 	__be32 group;
+	u16 vid = 0;
 
 	if (!pskb_may_pull(skb, sizeof(*ih)))
 		return -EINVAL;
 
+	br_vlan_get_tag(skb, &vid);
 	ih = igmpv3_report_hdr(skb);
 	num = ntohs(ih->ngrec);
 	len = sizeof(*ih);
@@ -930,7 +944,7 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br,
 			continue;
 		}
 
-		err = br_ip4_multicast_add_group(br, port, group);
+		err = br_ip4_multicast_add_group(br, port, group, vid);
 		if (err)
 			break;
 	}
@@ -949,10 +963,12 @@ static int br_ip6_multicast_mld2_report(struct net_bridge *br,
 	int len;
 	int num;
 	int err = 0;
+	u16 vid = 0;
 
 	if (!pskb_may_pull(skb, sizeof(*icmp6h)))
 		return -EINVAL;
 
+	br_vlan_get_tag(skb, &vid);
 	icmp6h = icmp6_hdr(skb);
 	num = ntohs(icmp6h->icmp6_dataun.un_data16[1]);
 	len = sizeof(*icmp6h);
@@ -990,7 +1006,8 @@ static int br_ip6_multicast_mld2_report(struct net_bridge *br,
 			continue;
 		}
 
-		err = br_ip6_multicast_add_group(br, port, &grec->grec_mca);
+		err = br_ip6_multicast_add_group(br, port, &grec->grec_mca,
+						 vid);
 		if (!err)
 			break;
 	}
@@ -1074,6 +1091,7 @@ static int br_ip4_multicast_query(struct net_bridge *br,
 	unsigned long now = jiffies;
 	__be32 group;
 	int err = 0;
+	u16 vid = 0;
 
 	spin_lock(&br->multicast_lock);
 	if (!netif_running(br->dev) ||
@@ -1108,7 +1126,8 @@ static int br_ip4_multicast_query(struct net_bridge *br,
 	if (!group)
 		goto out;
 
-	mp = br_mdb_ip4_get(mlock_dereference(br->mdb, br), group);
+	br_vlan_get_tag(skb, &vid);
+	mp = br_mdb_ip4_get(mlock_dereference(br->mdb, br), group, vid);
 	if (!mp)
 		goto out;
 
@@ -1149,6 +1168,7 @@ static int br_ip6_multicast_query(struct net_bridge *br,
 	unsigned long now = jiffies;
 	const struct in6_addr *group = NULL;
 	int err = 0;
+	u16 vid = 0;
 
 	spin_lock(&br->multicast_lock);
 	if (!netif_running(br->dev) ||
@@ -1180,7 +1200,8 @@ static int br_ip6_multicast_query(struct net_bridge *br,
 	if (!group)
 		goto out;
 
-	mp = br_mdb_ip6_get(mlock_dereference(br->mdb, br), group);
+	br_vlan_get_tag(skb, &vid);
+	mp = br_mdb_ip6_get(mlock_dereference(br->mdb, br), group, vid);
 	if (!mp)
 		goto out;
 
@@ -1286,7 +1307,8 @@ out:
 
 static void br_ip4_multicast_leave_group(struct net_bridge *br,
 					 struct net_bridge_port *port,
-					 __be32 group)
+					 __be32 group,
+					 __u16 vid)
 {
 	struct br_ip br_group;
 
@@ -1295,6 +1317,7 @@ static void br_ip4_multicast_leave_group(struct net_bridge *br,
 
 	br_group.u.ip4 = group;
 	br_group.proto = htons(ETH_P_IP);
+	br_group.vid = vid;
 
 	br_multicast_leave_group(br, port, &br_group);
 }
@@ -1302,7 +1325,8 @@ static void br_ip4_multicast_leave_group(struct net_bridge *br,
 #if IS_ENABLED(CONFIG_IPV6)
 static void br_ip6_multicast_leave_group(struct net_bridge *br,
 					 struct net_bridge_port *port,
-					 const struct in6_addr *group)
+					 const struct in6_addr *group,
+					 __u16 vid)
 {
 	struct br_ip br_group;
 
@@ -1311,6 +1335,7 @@ static void br_ip6_multicast_leave_group(struct net_bridge *br,
 
 	br_group.u.ip6 = *group;
 	br_group.proto = htons(ETH_P_IPV6);
+	br_group.vid = vid;
 
 	br_multicast_leave_group(br, port, &br_group);
 }
@@ -1326,6 +1351,7 @@ static int br_multicast_ipv4_rcv(struct net_bridge *br,
 	unsigned int len;
 	unsigned int offset;
 	int err;
+	u16 vid = 0;
 
 	/* We treat OOM as packet loss for now. */
 	if (!pskb_may_pull(skb, sizeof(*iph)))
@@ -1386,6 +1412,7 @@ static int br_multicast_ipv4_rcv(struct net_bridge *br,
 
 	err = 0;
 
+	br_vlan_get_tag(skb2, &vid);
 	BR_INPUT_SKB_CB(skb)->igmp = 1;
 	ih = igmp_hdr(skb2);
 
@@ -1393,7 +1420,7 @@ static int br_multicast_ipv4_rcv(struct net_bridge *br,
 	case IGMP_HOST_MEMBERSHIP_REPORT:
 	case IGMPV2_HOST_MEMBERSHIP_REPORT:
 		BR_INPUT_SKB_CB(skb)->mrouters_only = 1;
-		err = br_ip4_multicast_add_group(br, port, ih->group);
+		err = br_ip4_multicast_add_group(br, port, ih->group, vid);
 		break;
 	case IGMPV3_HOST_MEMBERSHIP_REPORT:
 		err = br_ip4_multicast_igmp3_report(br, port, skb2);
@@ -1402,7 +1429,7 @@ static int br_multicast_ipv4_rcv(struct net_bridge *br,
 		err = br_ip4_multicast_query(br, port, skb2);
 		break;
 	case IGMP_HOST_LEAVE_MESSAGE:
-		br_ip4_multicast_leave_group(br, port, ih->group);
+		br_ip4_multicast_leave_group(br, port, ih->group, vid);
 		break;
 	}
 
@@ -1427,6 +1454,7 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br,
 	unsigned int len;
 	int offset;
 	int err;
+	u16 vid = 0;
 
 	if (!pskb_may_pull(skb, sizeof(*ip6h)))
 		return -EINVAL;
@@ -1510,6 +1538,7 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br,
 
 	err = 0;
 
+	br_vlan_get_tag(skb, &vid);
 	BR_INPUT_SKB_CB(skb)->igmp = 1;
 
 	switch (icmp6_type) {
@@ -1522,7 +1551,7 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br,
 		}
 		mld = (struct mld_msg *)skb_transport_header(skb2);
 		BR_INPUT_SKB_CB(skb)->mrouters_only = 1;
-		err = br_ip6_multicast_add_group(br, port, &mld->mld_mca);
+		err = br_ip6_multicast_add_group(br, port, &mld->mld_mca, vid);
 		break;
 	    }
 	case ICMPV6_MLD2_REPORT:
@@ -1539,7 +1568,7 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br,
 			goto out;
 		}
 		mld = (struct mld_msg *)skb_transport_header(skb2);
-		br_ip6_multicast_leave_group(br, port, &mld->mld_mca);
+		br_ip6_multicast_leave_group(br, port, &mld->mld_mca, vid);
 	    }
 	}
 
net/bridge/br_private.h +1 -0
index 6dd94df..72000ef 100644
@@ -64,6 +64,7 @@ struct br_ip
 #endif
 	} u;
 	__be16		proto;
+	__u16		vid;
 };
 
 struct net_port_vlans {
Signature · 1 line
1.7.7.6
#19 lore raw

PATCH v9 9/12 bridge: Add vlan support to static neighbors

In reply to Vlad Yasevich

When a user adds bridge neighbors, allow him to specify VLAN id. If the VLAN id is not specified, the neighbor will be added for VLANs currently in the ports filter list. If no VLANs are configured on the port, we use vlan 0 and only add 1 entry.

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |    2 +-
 drivers/net/macvlan.c                         |    2 +-
 drivers/net/vxlan.c                           |    3 +-
 include/linux/netdevice.h                     |    1 +
 include/uapi/linux/neighbour.h                |    1 +
 net/bridge/br_fdb.c                           |  148 ++++++++++++++++++++++---
 net/bridge/br_private.h                       |    6 +-
 net/core/rtnetlink.c                          |   23 +++--
 8 files changed, 154 insertions(+), 32 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +1 -1
index 5989b3f..23fc510 100644
@@ -7001,7 +7001,7 @@ static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 	return err;
 }
 
-static int ixgbe_ndo_fdb_del(struct ndmsg *ndm,
+static int ixgbe_ndo_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
 			     struct net_device *dev,
 			     const unsigned char *addr)
 {
drivers/net/macvlan.c +1 -1
index 7b44ebd..afbea93 100644
@@ -564,7 +564,7 @@ static int macvlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 	return err;
 }
 
-static int macvlan_fdb_del(struct ndmsg *ndm,
+static int macvlan_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
 			   struct net_device *dev,
 			   const unsigned char *addr)
 {
drivers/net/vxlan.c +2 -1
index 656230e..6adeafe 100644
@@ -392,7 +392,8 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 }
 
 /* Delete entry (via netlink) */
-static int vxlan_fdb_delete(struct ndmsg *ndm, struct net_device *dev,
+static int vxlan_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
+			    struct net_device *dev,
 			    const unsigned char *addr)
 {
 	struct vxlan_dev *vxlan = netdev_priv(dev);
include/linux/netdevice.h +1 -0
index 51553c7..2dec09e 100644
@@ -1008,6 +1008,7 @@ struct net_device_ops {
 					       const unsigned char *addr,
 					       u16 flags);
 	int			(*ndo_fdb_del)(struct ndmsg *ndm,
+					       struct nlattr *tb[],
 					       struct net_device *dev,
 					       const unsigned char *addr);
 	int			(*ndo_fdb_dump)(struct sk_buff *skb,
include/uapi/linux/neighbour.h +1 -0
index 275e5d6..adb068c 100644
@@ -20,6 +20,7 @@ enum {
 	NDA_LLADDR,
 	NDA_CACHEINFO,
 	NDA_PROBES,
+	NDA_VLAN,
 	__NDA_MAX
 };
 
net/bridge/br_fdb.c +131 -17

211 lines not on this page · raw message

net/bridge/br_private.h +3 -3
index 72000ef..0bdf138 100644
@@ -386,7 +386,7 @@ extern void br_fdb_update(struct net_bridge *br,
 			  const unsigned char *addr,
 			  u16 vid);
 
-extern int br_fdb_delete(struct ndmsg *ndm,
+extern int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
 			 struct net_device *dev,
 			 const unsigned char *addr);
 extern int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[],
@@ -575,13 +575,13 @@ extern void nbp_vlan_flush(struct net_bridge_port *port);
 static inline struct net_port_vlans *br_get_vlan_info(
 						const struct net_bridge *br)
 {
-	return rcu_dereference(br->vlan_info);
+	return rcu_dereference_rtnl(br->vlan_info);
 }
 
 static inline struct net_port_vlans *nbp_get_vlan_info(
 						const struct net_bridge_port *p)
 {
-	return rcu_dereference(p->vlan_info);
+	return rcu_dereference_rtnl(p->vlan_info);
 }
 
 
net/core/rtnetlink.c +14 -9
index 1aba89f..87b07d8 100644
@@ -2122,7 +2122,7 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
 {
 	struct net *net = sock_net(skb->sk);
 	struct ndmsg *ndm;
-	struct nlattr *llattr;
+	struct nlattr *tb[NDA_MAX+1];
 	struct net_device *dev;
 	int err = -EINVAL;
 	__u8 *addr;
@@ -2130,8 +2130,9 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
 	if (!capable(CAP_NET_ADMIN))
 		return -EPERM;
 
-	if (nlmsg_len(nlh) < sizeof(*ndm))
-		return -EINVAL;
+	err = nlmsg_parse(nlh, sizeof(*ndm), tb, NDA_MAX, NULL);
+	if (err < 0)
+		return err;
 
 	ndm = nlmsg_data(nlh);
 	if (ndm->ndm_ifindex == 0) {
@@ -2145,13 +2146,17 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
 		return -ENODEV;
 	}
 
-	llattr = nlmsg_find_attr(nlh, sizeof(*ndm), NDA_LLADDR);
-	if (llattr == NULL || nla_len(llattr) != ETH_ALEN) {
-		pr_info("PF_BRIGDE: RTM_DELNEIGH with invalid address\n");
+	if (!tb[NDA_LLADDR] || nla_len(tb[NDA_LLADDR]) != ETH_ALEN) {
+		pr_info("PF_BRIDGE: RTM_DELNEIGH with invalid address\n");
+		return -EINVAL;
+	}
+
+	addr = nla_data(tb[NDA_LLADDR]);
+	if (!is_valid_ether_addr(addr)) {
+		pr_info("PF_BRIDGE: RTM_DELNEIGH with invalid ether address\n");
 		return -EINVAL;
 	}
 
-	addr = nla_data(llattr);
 	err = -EOPNOTSUPP;
 
 	/* Support fdb on master device the net/bridge default case */
@@ -2161,7 +2166,7 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
 		const struct net_device_ops *ops = br_dev->netdev_ops;
 
 		if (ops->ndo_fdb_del)
-			err = ops->ndo_fdb_del(ndm, dev, addr);
+			err = ops->ndo_fdb_del(ndm, tb, dev, addr);
 
 		if (err)
 			goto out;
@@ -2171,7 +2176,7 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
 
 	/* Embedded bridge, macvlan, and any other device support */
 	if ((ndm->ndm_flags & NTF_SELF) && dev->netdev_ops->ndo_fdb_del) {
-		err = dev->netdev_ops->ndo_fdb_del(ndm, dev, addr);
+		err = dev->netdev_ops->ndo_fdb_del(ndm, tb, dev, addr);
 
 		if (!err) {
 			rtnl_fdb_notify(dev, addr, RTM_DELNEIGH);
Signature · 1 line
1.7.7.6
#20 lore raw

PATCH v9 10/12 bridge: Add vlan support for local fdb entries

In reply to Vlad Yasevich

When VLAN is added to the port, a local fdb entry for that port (the entry with the mac address of the port) is added for that VLAN. This way we can correctly determine if the traffic is for the bridge itself. If the address of the port changes, we try to change all the local fdb entries we have for that port.

---
 net/bridge/br_fdb.c     |   61 +++++++++++++++++++++++++++---------
 net/bridge/br_if.c      |    2 +-
 net/bridge/br_private.h |   10 +++++-
 net/bridge/br_vlan.c    |   78 +++++++++++++++++++++++++++++++++++++++++-----
 4 files changed, 125 insertions(+), 26 deletions(-)
net/bridge/br_fdb.c +46 -15
index 9553cff..574c1e0 100644
@@ -28,7 +28,7 @@
 
 static struct kmem_cache *br_fdb_cache __read_mostly;
 static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
-		      const unsigned char *addr);
+		      const unsigned char *addr, u16 vid);
 static void fdb_notify(struct net_bridge *br,
 		       const struct net_bridge_fdb_entry *, int);
 
@@ -92,6 +92,7 @@ static void fdb_delete(struct net_bridge *br, struct net_bridge_fdb_entry *f)
 void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr)
 {
 	struct net_bridge *br = p->br;
+	bool no_vlan = (nbp_get_vlan_info(p) == NULL) ? true : false;
 	int i;
 
 	spin_lock_bh(&br->hash_lock);
@@ -106,10 +107,12 @@ void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr)
 			if (f->dst == p && f->is_local) {
 				/* maybe another port has same hw addr? */
 				struct net_bridge_port *op;
+				u16 vid = f->vlan_id;
 				list_for_each_entry(op, &br->port_list, list) {
 					if (op != p &&
 					    ether_addr_equal(op->dev->dev_addr,
-							     f->addr.addr)) {
+							     f->addr.addr) &&
+					    nbp_vlan_find(op, vid)) {
 						f->dst = op;
 						goto insert;
 					}
@@ -117,27 +120,55 @@ void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr)
 
 				/* delete old one */
 				fdb_delete(br, f);
-				goto insert;
+insert:
+				/* insert new address,  may fail if invalid
+				 * address or dup.
+				 */
+				fdb_insert(br, p, newaddr, vid);
+
+				/* if this port has no vlan information
+				 * configured, we can safely be done at
+				 * this point.
+				 */
+				if (no_vlan)
+					goto done;
 			}
 		}
 	}
- insert:
-	/* insert new address,  may fail if invalid address or dup. */
-	fdb_insert(br, p, newaddr);
 
+done:
 	spin_unlock_bh(&br->hash_lock);
 }
 
 void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr)
 {
 	struct net_bridge_fdb_entry *f;
+	struct net_port_vlans *pv;
+	u16 vid = 0;
 
 	/* If old entry was unassociated with any port, then delete it. */
 	f = __br_fdb_get(br, br->dev->dev_addr, 0);
 	if (f && f->is_local && !f->dst)
 		fdb_delete(br, f);
 
-	fdb_insert(br, NULL, newaddr);
+	fdb_insert(br, NULL, newaddr, 0);
+
+	/* Now remove and add entries for every VLAN configured on the
+	 * bridge.  This function runs under RTNL so the bitmap will not
+	 * change from under us.
+	 */
+	pv = br_get_vlan_info(br);
+	if (!pv)
+		return;
+
+	for (vid = find_next_bit(pv->vlan_bitmap, BR_VLAN_BITMAP_LEN, vid);
+	     vid < BR_VLAN_BITMAP_LEN;
+	     vid = find_next_bit(pv->vlan_bitmap, BR_VLAN_BITMAP_LEN, vid+1)) {
+		f = __br_fdb_get(br, br->dev->dev_addr, vid);
+		if (f && f->is_local && !f->dst)
+			fdb_delete(br, f);
+		fdb_insert(br, NULL, newaddr, vid);
+	}
 }
 
 void br_fdb_cleanup(unsigned long _data)
@@ -380,15 +411,15 @@ static struct net_bridge_fdb_entry *fdb_create(struct hlist_head *head,
 }
 
 static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
-		  const unsigned char *addr)
+		  const unsigned char *addr, u16 vid)
 {
-	struct hlist_head *head = &br->hash[br_mac_hash(addr, 0)];
+	struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)];
 	struct net_bridge_fdb_entry *fdb;
 
 	if (!is_valid_ether_addr(addr))
 		return -EINVAL;
 
-	fdb = fdb_find(head, addr, 0);
+	fdb = fdb_find(head, addr, vid);
 	if (fdb) {
 		/* it is okay to have multiple ports with same
 		 * address, just use the first one.
@@ -401,7 +432,7 @@ static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
 		fdb_delete(br, fdb);
 	}
 
-	fdb = fdb_create(head, source, addr, 0);
+	fdb = fdb_create(head, source, addr, vid);
 	if (!fdb)
 		return -ENOMEM;
 
@@ -412,12 +443,12 @@ static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
 
 /* Add entry for local address of interface */
 int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
-		  const unsigned char *addr)
+		  const unsigned char *addr, u16 vid)
 {
 	int ret;
 
 	spin_lock_bh(&br->hash_lock);
-	ret = fdb_insert(br, source, addr);
+	ret = fdb_insert(br, source, addr, vid);
 	spin_unlock_bh(&br->hash_lock);
 	return ret;
 }
@@ -713,8 +744,8 @@ out:
 	return err;
 }
 
-static int fdb_delete_by_addr(struct net_bridge *br, const u8 *addr,
-			      u16 vlan)
+int fdb_delete_by_addr(struct net_bridge *br, const u8 *addr,
+		       u16 vlan)
 {
 	struct hlist_head *head = &br->hash[br_mac_hash(addr, vlan)];
 	struct net_bridge_fdb_entry *fdb;
net/bridge/br_if.c +1 -1
index 335c60c..ef1b914 100644
@@ -397,7 +397,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)
 
 	dev_set_mtu(br->dev, br_min_mtu(br));
 
-	if (br_fdb_insert(br, p, dev->dev_addr))
+	if (br_fdb_insert(br, p, dev->dev_addr, 0))
 		netdev_err(dev, "failed insert local address bridge forwarding table\n");
 
 	kobject_uevent(&p->kobj, KOBJ_ADD);
net/bridge/br_private.h +9 -1
index 0bdf138..f4e6cab 100644
@@ -380,11 +380,13 @@ extern int br_fdb_fillbuf(struct net_bridge *br, void *buf,
 			  unsigned long count, unsigned long off);
 extern int br_fdb_insert(struct net_bridge *br,
 			 struct net_bridge_port *source,
-			 const unsigned char *addr);
+			 const unsigned char *addr,
+			 u16 vid);
 extern void br_fdb_update(struct net_bridge *br,
 			  struct net_bridge_port *source,
 			  const unsigned char *addr,
 			  u16 vid);
+extern int fdb_delete_by_addr(struct net_bridge *br, const u8 *addr, u16 vid);
 
 extern int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
 			 struct net_device *dev,
@@ -571,6 +573,7 @@ extern int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val);
 extern int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags);
 extern int nbp_vlan_delete(struct net_bridge_port *port, u16 vid);
 extern void nbp_vlan_flush(struct net_bridge_port *port);
+extern bool nbp_vlan_find(struct net_bridge_port *port, u16 vid);
 
 static inline struct net_port_vlans *br_get_vlan_info(
 						const struct net_bridge *br)
@@ -659,6 +662,11 @@ static inline struct net_port_vlans *nbp_get_vlan_info(
 	return NULL;
 }
 
+static inline bool nbp_vlan_find(struct net_bridge_port *port, u16 vid)
+{
+	return false;
+}
+
 static inline u16 br_vlan_get_tag(const struct sk_buff *skb, u16 *tag)
 {
 	return 0;
net/bridge/br_vlan.c +69 -9

116 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#21 lore raw

PATCH v9 11/12 bridge: Dump vlan information from a bridge port

In reply to Vlad Yasevich

Using the RTM_GETLINK dump the vlan filter list of a given bridge port. The information depends on setting the filter flag similar to how nic VF info is dumped.

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |    3 +-
 include/linux/netdevice.h                     |    3 +-
 include/uapi/linux/rtnetlink.h                |    1 +
 net/bridge/br_netlink.c                       |   97 ++++++++++++++++++++++---
 net/bridge/br_private.h                       |    3 +-
 net/bridge/br_vlan.c                          |    4 +-
 net/core/rtnetlink.c                          |   16 +++-
 7 files changed, 107 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +2 -1
index 23fc510..b5e9df5 100644
@@ -7078,7 +7078,8 @@ static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
 }
 
 static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
-				    struct net_device *dev)
+				    struct net_device *dev,
+				    u32 filter_mask)
 {
 	struct ixgbe_adapter *adapter = netdev_priv(dev);
 	u16 mode;
include/linux/netdevice.h +2 -1
index 2dec09e..6eb70eb 100644
@@ -1020,7 +1020,8 @@ struct net_device_ops {
 						      struct nlmsghdr *nlh);
 	int			(*ndo_bridge_getlink)(struct sk_buff *skb,
 						      u32 pid, u32 seq,
-						      struct net_device *dev);
+						      struct net_device *dev,
+						      u32 filter_mask);
 	int			(*ndo_bridge_dellink)(struct net_device *dev,
 						      struct nlmsghdr *nlh);
 	int			(*ndo_change_carrier)(struct net_device *dev,
include/uapi/linux/rtnetlink.h +1 -0
index 7a5eb19..7a2144e 100644
@@ -630,6 +630,7 @@ struct tcamsg {
 
 /* New extended info filters for IFLA_EXT_MASK */
 #define RTEXT_FILTER_VF		(1 << 0)
+#define RTEXT_FILTER_BRVLAN	(1 << 1)
 
 /* End of information exported to user level */
 
net/bridge/br_netlink.c +86 -11

159 lines not on this page · raw message

net/bridge/br_private.h +2 -1
index f4e6cab..1fcbc9f 100644
@@ -73,6 +73,7 @@ struct net_port_vlans {
 	void				*parent;
 	struct rcu_head			rcu;
 	unsigned long			vlan_bitmap[BR_VLAN_BITMAP_LEN];
+	u16				num_vlans;
 };
 
 struct net_bridge_fdb_entry
@@ -735,7 +736,7 @@ extern void br_ifinfo_notify(int event, struct net_bridge_port *port);
 extern int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg);
 extern int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg);
 extern int br_getlink(struct sk_buff *skb, u32 pid, u32 seq,
-		      struct net_device *dev);
+		      struct net_device *dev, u32 filter_mask);
 
 #ifdef CONFIG_SYSFS
 /* br_sysfs_if.c */
net/bridge/br_vlan.c +2 -2
index 9c4eda6..fec139c 100644
@@ -70,6 +70,7 @@ static int __vlan_add(struct net_port_vlans *v, u16 vid, u16 flags)
 	}
 
 	set_bit(vid, v->vlan_bitmap);
+	v->num_vlans++;
 	if (flags & BRIDGE_VLAN_INFO_PVID)
 		__vlan_add_pvid(v, vid);
 
@@ -107,6 +108,7 @@ static int __vlan_del(struct net_port_vlans *v, u16 vid)
 	}
 
 	clear_bit(vid, v->vlan_bitmap);
+	v->num_vlans--;
 	if (first_bit == last_bit) {
 		if (v->port_idx) {
 			struct net_bridge_port *p =
@@ -369,8 +371,6 @@ int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags)
 	pv->parent = port;
 	pv->pvid = BR_INVALID_VID;
 	err = __vlan_add(pv, vid, flags);
-	if (err)
-		goto clean_up;
 
 	rcu_assign_pointer(port->vlan_info, pv);
 	return 0;
net/core/rtnetlink.c +12 -4
index 87b07d8..257b73e 100644
@@ -2326,6 +2326,13 @@ static int rtnl_bridge_getlink(struct sk_buff *skb, struct netlink_callback *cb)
 	int idx = 0;
 	u32 portid = NETLINK_CB(cb->skb).portid;
 	u32 seq = cb->nlh->nlmsg_seq;
+	struct nlattr *extfilt;
+	u32 filter_mask = 0;
+
+	extfilt = nlmsg_find_attr(cb->nlh, sizeof(struct rtgenmsg),
+				  IFLA_EXT_MASK);
+	if (extfilt)
+		filter_mask = nla_get_u32(extfilt);
 
 	rcu_read_lock();
 	for_each_netdev_rcu(net, dev) {
@@ -2335,14 +2342,15 @@ static int rtnl_bridge_getlink(struct sk_buff *skb, struct netlink_callback *cb)
 		if (br_dev && br_dev->netdev_ops->ndo_bridge_getlink) {
 			if (idx >= cb->args[0] &&
 			    br_dev->netdev_ops->ndo_bridge_getlink(
-				    skb, portid, seq, dev) < 0)
+				    skb, portid, seq, dev, filter_mask) < 0)
 				break;
 			idx++;
 		}
 
 		if (ops->ndo_bridge_getlink) {
 			if (idx >= cb->args[0] &&
-			    ops->ndo_bridge_getlink(skb, portid, seq, dev) < 0)
+			    ops->ndo_bridge_getlink(skb, portid, seq, dev,
+						    filter_mask) < 0)
 				break;
 			idx++;
 		}
@@ -2383,14 +2391,14 @@ static int rtnl_bridge_notify(struct net_device *dev, u16 flags)
 
 	if ((!flags || (flags & BRIDGE_FLAGS_MASTER)) &&
 	    br_dev && br_dev->netdev_ops->ndo_bridge_getlink) {
-		err = br_dev->netdev_ops->ndo_bridge_getlink(skb, 0, 0, dev);
+		err = br_dev->netdev_ops->ndo_bridge_getlink(skb, 0, 0, dev, 0);
 		if (err < 0)
 			goto errout;
 	}
 
 	if ((flags & BRIDGE_FLAGS_SELF) &&
 	    dev->netdev_ops->ndo_bridge_getlink) {
-		err = dev->netdev_ops->ndo_bridge_getlink(skb, 0, 0, dev);
+		err = dev->netdev_ops->ndo_bridge_getlink(skb, 0, 0, dev, 0);
 		if (err < 0)
 			goto errout;
 	}
Signature · 1 line
1.7.7.6
#22 lore raw

PATCH v9 12/12 bridge: Separate egress policy bitmap

In reply to Vlad Yasevich

Add an ability to configure a separate "untagged" egress policy to the VLAN information of the bridge. This superseeds PVID policy and makes PVID ingress-only. The policy is configured with a new flag and is represented as a port bitmap per vlan. Egress frames with a VLAN id in "untagged" policy bitmap would egress the port without VLAN header.

---
 include/uapi/linux/if_bridge.h |    1 +
 net/bridge/br_netlink.c        |    2 ++
 net/bridge/br_private.h        |    1 +
 net/bridge/br_vlan.c           |   20 ++++++++++++++------
 4 files changed, 18 insertions(+), 6 deletions(-)
include/uapi/linux/if_bridge.h +1 -0
index 875c9e2..8e1fc51 100644
@@ -121,6 +121,7 @@ enum {
 
 #define BRIDGE_VLAN_INFO_MASTER	(1<<0)	/* Operate on Bridge device as well */
 #define BRIDGE_VLAN_INFO_PVID	(1<<1)	/* VLAN is PVID, ingress untagged */
+#define BRIDGE_VLAN_INFO_UNTAGGED	(1<<2)	/* VLAN egresses untagged */
 
 struct bridge_vlan_info {
 	u16 flags;
net/bridge/br_netlink.c +2 -0
index ddbb2c7..b71d1c5 100644
@@ -141,6 +141,8 @@ static int br_fill_ifinfo(struct sk_buff *skb,
 			vinfo.flags = 0;
 			if (vid == pv->pvid)
 				vinfo.flags |= BRIDGE_VLAN_INFO_PVID;
+			if (test_bit(vid, pv->untagged_bitmap))
+				vinfo.flags |= BRIDGE_VLAN_INFO_UNTAGGED;
 
 			if (nla_put(skb, IFLA_BRIDGE_VLAN_INFO,
 				    sizeof(vinfo), &vinfo))
net/bridge/br_private.h +1 -0
index 1fcbc9f..c0395f7 100644
@@ -73,6 +73,7 @@ struct net_port_vlans {
 	void				*parent;
 	struct rcu_head			rcu;
 	unsigned long			vlan_bitmap[BR_VLAN_BITMAP_LEN];
+	unsigned long			untagged_bitmap[BR_VLAN_BITMAP_LEN];
 	u16				num_vlans;
 };
 
net/bridge/br_vlan.c +14 -6
index fec139c..a8e29e3 100644
@@ -25,6 +25,15 @@ static void __vlan_delete_pvid(struct net_port_vlans *v, u16 vid)
 	v->pvid = BR_INVALID_VID;
 }
 
+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);
+
+	if (flags & BRIDGE_VLAN_INFO_UNTAGGED)
+		set_bit(vid, v->untagged_bitmap);
+}
+
 static int __vlan_add(struct net_port_vlans *v, u16 vid, u16 flags)
 {
 	struct net_bridge_port *p = NULL;
@@ -33,8 +42,7 @@ static int __vlan_add(struct net_port_vlans *v, u16 vid, u16 flags)
 	int err;
 
 	if (test_bit(vid, v->vlan_bitmap)) {
-		if (flags & BRIDGE_VLAN_INFO_PVID)
-			__vlan_add_pvid(v, vid);
+		__vlan_add_flags(v, vid, flags);
 		return 0;
 	}
 
@@ -71,8 +79,7 @@ static int __vlan_add(struct net_port_vlans *v, u16 vid, u16 flags)
 
 	set_bit(vid, v->vlan_bitmap);
 	v->num_vlans++;
-	if (flags & BRIDGE_VLAN_INFO_PVID)
-		__vlan_add_pvid(v, vid);
+	__vlan_add_flags(v, vid, flags);
 
 	return 0;
 
@@ -91,6 +98,7 @@ static int __vlan_del(struct net_port_vlans *v, u16 vid)
 		return -EINVAL;
 
 	__vlan_delete_pvid(v, vid);
+	clear_bit(vid, v->untagged_bitmap);
 
 	/* Check to see if any other vlans are in this table.  If this
 	 * is the last vlan, delete the whole structure.  If this is not the
@@ -173,11 +181,11 @@ struct sk_buff *br_handle_vlan(struct net_bridge *br,
 		goto out;
 
 	/* At this point, we know that the frame was filtered and contains
-	 * a valid vlan id.  If the vlan id matches the pvid of current port
+	 * a valid vlan id.  If the vlan id is set in the untagged bitmap,
 	 * send untagged; otherwise, send taged.
 	 */
 	br_vlan_get_tag(skb, &vid);
-	if (vid == br_get_pvid(pv))
+	if (test_bit(vid, pv->untagged_bitmap))
 		skb = br_vlan_untag(skb);
 	else {
 		/* Egress policy says "send tagged".  If output device
Signature · 1 line
1.7.7.6
#23 lore raw
In reply to Vlad Yasevich

One thing I am not clear about is whether is supposed to be just a simple filter of VLAN traffic, or a full VLAN aware bridge.

The change to make FDB entries per-VLAN seems to be the biggest tipping point into a full VLAN bridge. I am concerned that might break existing API's and Spanning Tree (internal and external).

#24 lore raw
Quoted 2 lines · Stephen Hemminger

One thing I am not clear about is whether is supposed to be just a simple filter of VLAN traffic, or a full VLAN aware bridge.

I started with the concept of basic VLAN filtering, but it has been morphing into more of a VLAN away bridge.

Quoted 5 lines

The change to make FDB entries per-VLAN seems to be the biggest tipping point into a full VLAN bridge. I am concerned that might break existing API's and Spanning Tree (internal and external).

I debated for a while about whether per-VLAN FDB entries were needed. The typing point was that without it, you may end up with flopping FDB and possible packet drops or vlan leaks, if say 2 different VMs used the same MAC but different VLANs. Without it, there is an exploitable gap.

I've also tried to separate FDB code changes as much as possible. If you really thing this is a big risk and a barrier to entry, then we can drop them. I am just concerned about the hole I described above, but I guess it is not much different then what's there now.

Thanks
-vlad

#25 lore raw
Quoted 18 lines · Vlad Yasevich
Quoted 2 lines · Stephen Hemminger

One thing I am not clear about is whether is supposed to be just a simple filter of VLAN traffic, or a full VLAN aware bridge.

I started with the concept of basic VLAN filtering, but it has been morphing into more of a VLAN away bridge.

Quoted 5 lines

The change to make FDB entries per-VLAN seems to be the biggest tipping point into a full VLAN bridge. I am concerned that might break existing API's and Spanning Tree (internal and external).

I debated for a while about whether per-VLAN FDB entries were needed. The typing point was that without it, you may end up with flopping FDB and possible packet drops or vlan leaks, if say 2 different VMs used the same MAC but different VLANs. Without it, there is an exploitable gap.

Quoted 5 lines

I've also tried to separate FDB code changes as much as possible. If you really thing this is a big risk and a barrier to entry, then we can drop them. I am just concerned about the hole I described above, but I guess it is not much different then what's there now.

So I played with STP for quite a bit and found the FDB changes have absolutely no effect on operation of STP.
Since all the vlan filtering code is mostly in forwarding path, STP works just fine.
Looking at STP code (the one in the kernel), I don't see any dependencies on FDB. The only userspace code I can find is from here
git://git.kernel.org/pub/scm/linux/kernel/git/shemminger/rstp.git. That only seems to ask for RTM_GETLINK, and there you will not get any vlan information if you don't set the filter flags.

So, I don't see any API impact as far as STP is concerned.

-vlad

#26 lore raw
Quoted 35 lines · On Thu, 07 Feb 2013 17:48:00 -0500 Vlad Yasevich <[email protected]> wrote:
Quoted 18 lines · Vlad Yasevich
Quoted 2 lines · Stephen Hemminger

One thing I am not clear about is whether is supposed to be just a simple filter of VLAN traffic, or a full VLAN aware bridge.

I started with the concept of basic VLAN filtering, but it has been morphing into more of a VLAN away bridge.

Quoted 5 lines

The change to make FDB entries per-VLAN seems to be the biggest tipping point into a full VLAN bridge. I am concerned that might break existing API's and Spanning Tree (internal and external).

I debated for a while about whether per-VLAN FDB entries were needed. The typing point was that without it, you may end up with flopping FDB and possible packet drops or vlan leaks, if say 2 different VMs used the same MAC but different VLANs. Without it, there is an exploitable gap.

Quoted 5 lines

I've also tried to separate FDB code changes as much as possible. If you really thing this is a big risk and a barrier to entry, then we can drop them. I am just concerned about the hole I described above, but I guess it is not much different then what's there now.

So I played with STP for quite a bit and found the FDB changes have absolutely no effect on operation of STP.
Since all the vlan filtering code is mostly in forwarding path, STP works just fine.
Looking at STP code (the one in the kernel), I don't see any dependencies on FDB. The only userspace code I can find is from here
git://git.kernel.org/pub/scm/linux/kernel/git/shemminger/rstp.git. That only seems to ask for RTM_GETLINK, and there you will not get any vlan information if you don't set the filter flags.

Quoted 1 line

So, I don't see any API impact as far as STP is concerned.

Good, does bridge command (in newer iproute2) still work?

#27 lore raw
Quoted 38 lines · Stephen Hemminger
Quoted 35 lines · On Thu, 07 Feb 2013 17:48:00 -0500 Vlad Yasevich <[email protected]> wrote:
Quoted 18 lines · Vlad Yasevich
Quoted 2 lines · Stephen Hemminger

One thing I am not clear about is whether is supposed to be just a simple filter of VLAN traffic, or a full VLAN aware bridge.

I started with the concept of basic VLAN filtering, but it has been morphing into more of a VLAN away bridge.

Quoted 5 lines

The change to make FDB entries per-VLAN seems to be the biggest tipping point into a full VLAN bridge. I am concerned that might break existing API's and Spanning Tree (internal and external).

I debated for a while about whether per-VLAN FDB entries were needed. The typing point was that without it, you may end up with flopping FDB and possible packet drops or vlan leaks, if say 2 different VMs used the same MAC but different VLANs. Without it, there is an exploitable gap.

Quoted 5 lines

I've also tried to separate FDB code changes as much as possible. If you really thing this is a big risk and a barrier to entry, then we can drop them. I am just concerned about the hole I described above, but I guess it is not much different then what's there now.

So I played with STP for quite a bit and found the FDB changes have absolutely no effect on operation of STP.
Since all the vlan filtering code is mostly in forwarding path, STP works just fine.
Looking at STP code (the one in the kernel), I don't see any dependencies on FDB. The only userspace code I can find is from here
git://git.kernel.org/pub/scm/linux/kernel/git/shemminger/rstp.git. That only seems to ask for RTM_GETLINK, and there you will not get any vlan information if you don't set the filter flags.

Quoted 4 lines
Quoted 1 line

So, I don't see any API impact as far as STP is concerned.

Good, does bridge command (in newer iproute2) still work?

Yes. I have patches to it enable the vlan functionality, but I haven't posted them since I wanted the kernel pieces including the API to get accepted.

-vlad