Skip to contentSkip to conversation

Add basic VLAN support to bridges

PATCH Superseded Vlad Yasevich 7 participants 34 messages Jan 16, 2013 – Jan 22, 2013 2 messages not in the archive

Subsystems (4)

v6 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v6 cover Add basic VLAN support to bridges

This series of patches provides an ability to add VLANs to the bridge ports. This is similar to what can be found in most switches. The bridge port may have any number of VLANs added to it including vlan 0 priority tagged traffic. When vlans are added to the port, only traffic tagged with particular vlan will forwarded over this port. Additionally, vlan ids are added to FDB entries and become part of the lookup. This way we correctly identify the FDB entry.

A single vlan per port may also be designated as a PVID. Any untagged traffic recieved by the port will be assigned to this vlan and all further processing will be done with this vlan in mind.

Any number for vlans per port may also be designated as untagged. This defines their egress policy such that any frame exiting the port with a VID matching the untagged vlan will exit untagged (the bridge will strip the vlan header).

Bridge device is trated as just another port for the purposes of vlan configuration so, users have to configure which vlans are allowed to enter and exit the bridge master device.

The default behavior of the bridge is unchanged if no vlans have been configured. Default behavior of each port is also unchanged if no vlans are configured on that port (i.e there are no ingress/egress checks or vlan header manipulation).

Vlan filtering can now be optionally compiled in or left out.

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 (14):
vlan: wrap hw-acceleration calls in separate functions.
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: Cache vlan in the cb for faster egress lookup.
bridge: Add netlink interface to configure vlans on bridge ports
bridge: Add the ability to configure pvid
bridge: Implement vlan ingress/egress policy
bridge: API to configure 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

Vlad Yasevich (14):
vlan: wrap hw-acceleration calls in separate functions.
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: Cache vlan in the cb for faster egress lookup.
bridge: Add netlink interface to configure vlans on bridge ports
bridge: Add the ability to configure pvid
bridge: Implement vlan ingress/egress policy
bridge: API to configure 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

 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |    5 +-
 drivers/net/macvlan.c                         |    2 +-
 drivers/net/vxlan.c                           |    3 +-
 include/linux/if_vlan.h                       |   21 +
 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.c                              |    4 +-
 net/8021q/vlan_core.c                         |   82 ++++-
 net/bridge/Kconfig                            |   14 +
 net/bridge/Makefile                           |    2 +
 net/bridge/br_device.c                        |   13 +-
 net/bridge/br_fdb.c                           |  254 +++++++++++---
 net/bridge/br_forward.c                       |    9 +
 net/bridge/br_if.c                            |    7 +-
 net/bridge/br_input.c                         |   29 ++-
 net/bridge/br_multicast.c                     |   69 +++-
 net/bridge/br_netlink.c                       |  245 +++++++++++--
 net/bridge/br_private.h                       |  163 ++++++++-
 net/bridge/br_vlan.c                          |  484 +++++++++++++++++++++++++
 net/core/rtnetlink.c                          |  111 +++++-
 22 files changed, 1390 insertions(+), 148 deletions(-)
 create mode 100644 net/bridge/br_vlan.c
Signature · 1 line
1.7.7.6
#1 lore raw

PATCH v6 1/14 vlan: wrap hw-acceleration calls in separate functions.

Wrap VLAN hardware acceleration calls into separate functions. This way other code can re-use it.

---
 include/linux/if_vlan.h |   21 ++++++++++++
 net/8021q/vlan.c        |    4 +--
 net/8021q/vlan_core.c   |   81 +++++++++++++++++++++++++++++++++++++---------
 3 files changed, 87 insertions(+), 19 deletions(-)
include/linux/if_vlan.h +21 -0
index d06cc5c..b658eda 100644
@@ -93,6 +93,10 @@ extern u16 vlan_dev_vlan_id(const struct net_device *dev);
 extern bool vlan_do_receive(struct sk_buff **skb);
 extern struct sk_buff *vlan_untag(struct sk_buff *skb);
 
+extern bool vlan_hw_buggy(const struct net_device *dev);
+extern int vlan_vid_add_hw(struct net_device *dev, unsigned short vid);
+extern int vlan_vid_del_hw(struct net_device *dev, unsigned short vid);
+
 extern int vlan_vid_add(struct net_device *dev, unsigned short vid);
 extern void vlan_vid_del(struct net_device *dev, unsigned short vid);
 
@@ -155,6 +159,23 @@ static inline bool vlan_uses_dev(const struct net_device *dev)
 {
 	return false;
 }
+
+static inline bool vlan_hw_buggy(const struct net_device *dev)
+{
+	return false;
+}
+
+static inline int vlan_vid_add_hw(struct net_device *dev,
+				  unsigned short vid)
+{
+	return 0;
+}
+
+static inline int vlan_vid_del_hw(struct net_device *dev,
+				  unsigned short vid)
+{
+	return 0;
+}
 #endif
 
 /**
net/8021q/vlan.c +1 -3
index babfde9..540d759 100644
@@ -117,15 +117,13 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
 int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id)
 {
 	const char *name = real_dev->name;
-	const struct net_device_ops *ops = real_dev->netdev_ops;
 
 	if (real_dev->features & NETIF_F_VLAN_CHALLENGED) {
 		pr_info("VLANs not supported on %s\n", name);
 		return -EOPNOTSUPP;
 	}
 
-	if ((real_dev->features & NETIF_F_HW_VLAN_FILTER) &&
-	    (!ops->ndo_vlan_rx_add_vid || !ops->ndo_vlan_rx_kill_vid)) {
+	if (vlan_hw_buggy(real_dev)) {
 		pr_info("Device %s has buggy VLAN hw accel\n", name);
 		return -EOPNOTSUPP;
 	}
net/8021q/vlan_core.c +65 -16

108 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#2 lore raw

Re: [PATCH net-next V6 01/14] vlan: wrap hw-acceleration calls in separate functions.

(resend with proper To:)

Quoted 2 lines

Wrap VLAN hardware acceleration calls into separate functions. This way other code can re-use it.

Maybe instead of jumping aroung bugs that are easily fixed just don't let them in? See untested patch below. Affected drivers can be either fixed or have NETIF_F_HW_VLAN_FILTER removed from advertised features.

--cut-here--

net: disallow drivers with buggy VLAN accel to register_netdevice()

---
 net/8021q/vlan.c      |    7 -------
 net/8021q/vlan_core.c |    6 ++----
 net/core/dev.c        |    9 +++++++++
 3 files changed, 11 insertions(+), 11 deletions(-)
net/8021q/vlan.c +0 -7
index babfde9..addc578 100644
@@ -117,19 +117,12 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
 int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id)
 {
 	const char *name = real_dev->name;
-	const struct net_device_ops *ops = real_dev->netdev_ops;
 
 	if (real_dev->features & NETIF_F_VLAN_CHALLENGED) {
 		pr_info("VLANs not supported on %s\n", name);
 		return -EOPNOTSUPP;
 	}
 
-	if ((real_dev->features & NETIF_F_HW_VLAN_FILTER) &&
-	    (!ops->ndo_vlan_rx_add_vid || !ops->ndo_vlan_rx_kill_vid)) {
-		pr_info("Device %s has buggy VLAN hw accel\n", name);
-		return -EOPNOTSUPP;
-	}
-
 	if (vlan_find_dev(real_dev, vlan_id) != NULL)
 		return -EEXIST;
 
net/8021q/vlan_core.c +2 -4
index 380440b..71b64fd 100644
@@ -224,8 +224,7 @@ static int __vlan_vid_add(struct vlan_info *vlan_info, unsigned short vid,
 	if (!vid_info)
 		return -ENOMEM;
 
-	if ((dev->features & NETIF_F_HW_VLAN_FILTER) &&
-	    ops->ndo_vlan_rx_add_vid) {
+	if (dev->features & NETIF_F_HW_VLAN_FILTER) {
 		err =  ops->ndo_vlan_rx_add_vid(dev, vid);
 		if (err) {
 			kfree(vid_info);
@@ -282,8 +281,7 @@ static void __vlan_vid_del(struct vlan_info *vlan_info,
 	unsigned short vid = vid_info->vid;
 	int err;
 
-	if ((dev->features & NETIF_F_HW_VLAN_FILTER) &&
-	     ops->ndo_vlan_rx_kill_vid) {
+	if (dev->features & NETIF_F_HW_VLAN_FILTER) {
 		err = ops->ndo_vlan_rx_kill_vid(dev, vid);
 		if (err) {
 			pr_warn("failed to kill vid %d for device %s\n",
net/core/dev.c +9 -0
index b6d2b32..f87cdc2 100644
@@ -6211,6 +6211,15 @@ int register_netdevice(struct net_device *dev)
 		}
 	}
 
+	if (((dev->hw_features & NETIF_F_HW_VLAN_FILTER) ||
+             (dev->features & NETIF_F_HW_VLAN_FILTER)) &&
+	    (!dev->netdev_ops->ndo_vlan_rx_add_vid ||
+	     !dev->netdev_ops->ndo_vlan_rx_kill_vid)) {
+		netdev_WARN(dev, "Buggy VLAN acceleration in driver!\n");
+		ret = -EINVAL;
+		goto err_uninit;
+	}
+
 	ret = -EBUSY;
 	if (!dev->ifindex)
 		dev->ifindex = dev_new_index(net);
Signature · 4 lines
1.7.10.4


----- End forwarded message -----
#3 lore raw

Re: [PATCH net-next V6 01/14] vlan: wrap hw-acceleration calls in separate functions.

In reply to Vlad Yasevich
Quoted 2 lines

Wrap VLAN hardware acceleration calls into separate functions. This way other code can re-use it.

Maybe instead of jumping aroung bugs that are easily fixed just don't let them in? See untested patch below. Affected drivers can be either fixed or have NETIF_F_HW_VLAN_FILTER removed from advertised features.

--cut-here--

net: disallow drivers with buggy VLAN accel to register_netdevice()

---
 net/8021q/vlan.c      |    7 -------
 net/8021q/vlan_core.c |    6 ++----
 net/core/dev.c        |    9 +++++++++
 3 files changed, 11 insertions(+), 11 deletions(-)
net/8021q/vlan.c +0 -7
index babfde9..addc578 100644
@@ -117,19 +117,12 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
 int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id)
 {
 	const char *name = real_dev->name;
-	const struct net_device_ops *ops = real_dev->netdev_ops;
 
 	if (real_dev->features & NETIF_F_VLAN_CHALLENGED) {
 		pr_info("VLANs not supported on %s\n", name);
 		return -EOPNOTSUPP;
 	}
 
-	if ((real_dev->features & NETIF_F_HW_VLAN_FILTER) &&
-	    (!ops->ndo_vlan_rx_add_vid || !ops->ndo_vlan_rx_kill_vid)) {
-		pr_info("Device %s has buggy VLAN hw accel\n", name);
-		return -EOPNOTSUPP;
-	}
-
 	if (vlan_find_dev(real_dev, vlan_id) != NULL)
 		return -EEXIST;
 
net/8021q/vlan_core.c +2 -4
index 380440b..71b64fd 100644
@@ -224,8 +224,7 @@ static int __vlan_vid_add(struct vlan_info *vlan_info, unsigned short vid,
 	if (!vid_info)
 		return -ENOMEM;
 
-	if ((dev->features & NETIF_F_HW_VLAN_FILTER) &&
-	    ops->ndo_vlan_rx_add_vid) {
+	if (dev->features & NETIF_F_HW_VLAN_FILTER) {
 		err =  ops->ndo_vlan_rx_add_vid(dev, vid);
 		if (err) {
 			kfree(vid_info);
@@ -282,8 +281,7 @@ static void __vlan_vid_del(struct vlan_info *vlan_info,
 	unsigned short vid = vid_info->vid;
 	int err;
 
-	if ((dev->features & NETIF_F_HW_VLAN_FILTER) &&
-	     ops->ndo_vlan_rx_kill_vid) {
+	if (dev->features & NETIF_F_HW_VLAN_FILTER) {
 		err = ops->ndo_vlan_rx_kill_vid(dev, vid);
 		if (err) {
 			pr_warn("failed to kill vid %d for device %s\n",
net/core/dev.c +9 -0
index b6d2b32..f87cdc2 100644
@@ -6211,6 +6211,15 @@ int register_netdevice(struct net_device *dev)
 		}
 	}
 
+	if (((dev->hw_features & NETIF_F_HW_VLAN_FILTER) ||
+             (dev->features & NETIF_F_HW_VLAN_FILTER)) &&
+	    (!dev->netdev_ops->ndo_vlan_rx_add_vid ||
+	     !dev->netdev_ops->ndo_vlan_rx_kill_vid)) {
+		netdev_WARN(dev, "Buggy VLAN acceleration in driver!\n");
+		ret = -EINVAL;
+		goto err_uninit;
+	}
+
 	ret = -EBUSY;
 	if (!dev->ifindex)
 		dev->ifindex = dev_new_index(net);
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH v6 2/14 bridge: Add vlan filtering infrastructure

In reply to Vlad Yasevich

This is an infrastructure patch. It adds 2 structures types:
net_bridge_vlan - list element of all vlans that have been configured
on the bridge.
net_port_vlan - list element of all vlans configured on a specific port.
references net_bridge_vlan.

In this implementation, bridge has a hash list of all vlans that have been added to the bridge. Each vlan element holds a vid and port_bitmap where each port sets its bit if a given vlan is added to the port.

Each port has its own list of vlans. Each element here refrences a vlan from the bridge list.

Write access to both lists is protected by RTNL, and read access is protected by RCU.

---
 net/bridge/Kconfig      |   14 +++
 net/bridge/Makefile     |    2 +
 net/bridge/br_device.c  |    5 +
 net/bridge/br_if.c      |    4 +
 net/bridge/br_private.h |   95 ++++++++++++++++++++
 net/bridge/br_vlan.c    |  223 +++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 343 insertions(+), 0 deletions(-)
 create mode 100644 net/bridge/br_vlan.c
net/bridge/Kconfig +14 -0
index 6dee7bf..c0283c1 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 y
+	---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_device.c +5 -0
index e1bc090..b64b5c8 100644
@@ -331,6 +331,7 @@ static struct device_type br_type = {
 void br_dev_setup(struct net_device *dev)
 {
 	struct net_bridge *br = netdev_priv(dev);
+	int i;
 
 	eth_hw_addr_random(dev);
 	ether_setup(dev);
@@ -353,6 +354,8 @@ void br_dev_setup(struct net_device *dev)
 	spin_lock_init(&br->lock);
 	INIT_LIST_HEAD(&br->port_list);
 	spin_lock_init(&br->hash_lock);
+	for (i = 0; i < BR_VID_HASH_SIZE; i++)
+		INIT_HLIST_HEAD(&br->vlan_hlist[i]);
 
 	br->bridge_id.prio[0] = 0x80;
 	br->bridge_id.prio[1] = 0x00;
@@ -367,6 +370,8 @@ void br_dev_setup(struct net_device *dev)
 	br->bridge_hello_time = br->hello_time = 2 * HZ;
 	br->bridge_forward_delay = br->forward_delay = 15 * HZ;
 	br->ageing_time = 300 * HZ;
+	br->vlan_info.port_idx = 0;
+	INIT_LIST_HEAD(&br->vlan_info.vlan_list);
 
 	br_netfilter_rtable_init(br);
 	br_stp_timer_init(br);
net/bridge/br_if.c +4 -0
index 2148d47..2427a21 100644
@@ -139,6 +139,7 @@ static void del_nbp(struct net_bridge_port *p)
 
 	br_ifinfo_notify(RTM_DELLINK, p);
 
+	nbp_vlan_flush(&p->vlan_info);
 	br_fdb_delete_by_port(br, p, 1);
 
 	list_del_rcu(&p->list);
@@ -170,6 +171,7 @@ void br_dev_delete(struct net_device *dev, struct list_head *head)
 		del_nbp(p);
 	}
 
+	br_vlan_flush(br);
 	del_timer_sync(&br->gc_timer);
 
 	br_sysfs_delbr(br->dev);
@@ -222,6 +224,8 @@ static struct net_bridge_port *new_nbp(struct net_bridge *br,
 	p->flags = 0;
 	br_init_port(p);
 	p->state = BR_STATE_DISABLED;
+	p->vlan_info.port_idx = index;
+	INIT_LIST_HEAD(&p->vlan_info.vlan_list);
 	br_stp_port_timer_init(p);
 	br_multicast_add_port(p);
 
net/bridge/br_private.h +95 -0

139 lines not on this page · raw message

net/bridge/br_vlan.c new file +223 -0

223 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#5 lore raw

Re: [PATCH net-next V6 02/14] bridge: Add vlan filtering infrastructure

net/bridge/Kconfig config BRIDGE_IGMP_SNOOPING · line 54

Quoted 5 lines · Vlad Yasevich
net/bridge/Kconfig +5 -0
+config BRIDGE_VLAN_FILTERING
+	bool "VLAN filtering"
+	depends on BRIDGE
+	depends on VLAN_8021Q
+	default y

This should default to n, otherwise Linus will complain.

net/bridge/Kconfig config BRIDGE_IGMP_SNOOPING · line 58

Quoted 4 lines
net/bridge/Kconfig +4 -0
+	---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.

_and_ any VLAN information...? Missed 'and'?

#6 lore raw

Re: [PATCH net-next V6 02/14] bridge: Add vlan filtering infrastructure

In reply to Vlad Yasevich

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

Quoted 2 lines
net/bridge/br_vlan.c new file +0 -0

[...]

Quoted 4 lines
net/bridge/br_vlan.c new file +4 -0
+struct net_port_vlan *nbp_vlan_find(const struct net_port_vlans *v, u16 vid)
+{
+       struct net_port_vlan *pve;
+

net/bridge/br_vlan.c line 117

Quoted 10 lines
net/bridge/br_vlan.c new file +10 -0
+       /* Must be done either in rcu critical section or with RTNL held */
+       WARN_ON_ONCE(!rcu_read_lock_held() && !rtnl_is_locked());
+
+       list_for_each_entry_rcu(pve, &v->vlan_list, list) {
+               if (pve->vid == vid)
+                       return pve;
+       }
+
+       return NULL;
+}

This looks expensive - it's O(n) with n = number of configured VLANs on a port. And this is called for every packet. The bridge already has a hash of VLAN structures found by br_vlan_find(). You could add a second bitmap there (eg. ingres_ports[]) and check port's bit instead of walking the list. You would use a bit more memory (64 bytes minus the removed list-head) per configured VLAN but save some cycles in hot path.

Best Regards,
Michał Mirosław

#7 lore raw

Re: [PATCH net-next V6 02/14] bridge: Add vlan filtering infrastructure

Quoted 18 lines · Michał Mirosław

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

Quoted 2 lines
net/bridge/br_vlan.c new file +0 -0

[...]

Quoted 13 lines
net/bridge/br_vlan.c new file +13 -0
+struct net_port_vlan *nbp_vlan_find(const struct net_port_vlans *v, u16 vid)
+{
+       struct net_port_vlan *pve;
+
+       /* Must be done either in rcu critical section or with RTNL held */
+       WARN_ON_ONCE(!rcu_read_lock_held() && !rtnl_is_locked());
+
+       list_for_each_entry_rcu(pve, &v->vlan_list, list) {
+               if (pve->vid == vid)
+                       return pve;
+       }
+
+       return NULL;
Quoted 9 lines
Quoted 1 line

+}

This looks expensive - it's O(n) with n = number of configured VLANs on a port. And this is called for every packet. The bridge already has a hash of VLAN structures found by br_vlan_find(). You could add a second bitmap there (eg. ingres_ports[]) and check port's bit instead of walking the list. You would use a bit more memory (64 bytes minus the removed list-head) per configured VLAN but save some cycles in hot path.

Technically wouldn't even need another bitmap as an existing membership bitmap would cover this case. I did some profiling and the list is faster for 3 vlans per port. Hash is faster for more then 3 vlans.

I can easily switch to hash if that is what others think.

-vlad

Quoted 3 lines

Best Regards,
Michał Mirosław

#8 lore raw

Re: [PATCH net-next V6 02/14] bridge: Add vlan filtering infrastructure

Quoted 29 lines · On Sun, 20 Jan 2013 12:59:22 -0500 Vlad Yasevich <[email protected]> wrote:
Quoted 18 lines · Michał Mirosław

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

Quoted 2 lines
net/bridge/br_vlan.c new file +0 -0

[...]

Quoted 13 lines
net/bridge/br_vlan.c new file +13 -0
+struct net_port_vlan *nbp_vlan_find(const struct net_port_vlans *v, u16 vid)
+{
+       struct net_port_vlan *pve;
+
+       /* Must be done either in rcu critical section or with RTNL held */
+       WARN_ON_ONCE(!rcu_read_lock_held() && !rtnl_is_locked());
+
+       list_for_each_entry_rcu(pve, &v->vlan_list, list) {
+               if (pve->vid == vid)
+                       return pve;
+       }
+
+       return NULL;
Quoted 9 lines
Quoted 1 line

+}

This looks expensive - it's O(n) with n = number of configured VLANs on a port. And this is called for every packet. The bridge already has a hash of VLAN structures found by br_vlan_find(). You could add a second bitmap there (eg. ingres_ports[]) and check port's bit instead of walking the list. You would use a bit more memory (64 bytes minus the removed list-head) per configured VLAN but save some cycles in hot path.

Quoted 7 lines

Technically wouldn't even need another bitmap as an existing membership bitmap would cover this case. I did some profiling and the list is faster for 3 vlans per port. Hash is faster for more then 3 vlans.

I can easily switch to hash if that is what others think.

-vlad

Let's assume the people that really want this feature are using a lot of vlan's. i.e n = 1000 or so. A bitmap is O(1). Any hash list would incur a just a big memory penalty for the list head. In other words a full bitmap is 4096 bits = 512 bytes. If you use hash list, then the equivalent memory size would be only 64 list heads, therefore a bitmap is a better choice than a hlist.

#9 lore raw

Re: [PATCH net-next V6 02/14] bridge: Add vlan filtering infrastructure

Quoted 38 lines · Stephen Hemminger
Quoted 35 lines · On Sun, 20 Jan 2013 12:59:22 -0500 Vlad Yasevich <[email protected]> wrote:
Quoted 18 lines · Michał Mirosław

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

Quoted 2 lines
net/bridge/br_vlan.c new file +0 -0

[...]

Quoted 13 lines
net/bridge/br_vlan.c new file +13 -0
+struct net_port_vlan *nbp_vlan_find(const struct net_port_vlans *v, u16 vid)
+{
+       struct net_port_vlan *pve;
+
+       /* Must be done either in rcu critical section or with RTNL held */
+       WARN_ON_ONCE(!rcu_read_lock_held() && !rtnl_is_locked());
+
+       list_for_each_entry_rcu(pve, &v->vlan_list, list) {
+               if (pve->vid == vid)
+                       return pve;
+       }
+
+       return NULL;
Quoted 9 lines
Quoted 1 line

+}

This looks expensive - it's O(n) with n = number of configured VLANs on a port. And this is called for every packet. The bridge already has a hash of VLAN structures found by br_vlan_find(). You could add a second bitmap there (eg. ingres_ports[]) and check port's bit instead of walking the list. You would use a bit more memory (64 bytes minus the removed list-head) per configured VLAN but save some cycles in hot path.

Technically wouldn't even need another bitmap as an existing membership bitmap would cover this case. I did some profiling and the list is faster for 3 vlans per port. Hash is faster for more then 3 vlans.

I can easily switch to hash if that is what others think.

Quoted 10 lines
Quoted 1 line

-vlad

Let's assume the people that really want this feature are using a lot of vlan's. i.e n = 1000 or so. A bitmap is O(1). Any hash list would incur a just a big memory penalty for the list head. In other words a full bitmap is 4096 bits = 512 bytes. If you use hash list, then the equivalent memory size would be only 64 list heads, therefore a bitmap is a better choice than a hlist.

This was the approach taken in the RFC v1 of this series. What I found was that while it worked very well as far as speed goes, it was a bit cumbersome to extend it to support pvids and it would completely fall on its face for egress policy that Shmulik is suggesting. So any kinds of extensions to it were tough to do.

This is why I went with the list. Interestingly enough, VLAN implementation in the kernel is a list and noone is complaining that it is really slow on the fast path.

-vlad

#10 lore raw

Re: [PATCH net-next V6 02/14] bridge: Add vlan filtering infrastructure

Hi Vlad,

Quoted 9 lines · On Sun, 20 Jan 2013 20:50:59 -0500 Vlad Yasevich <[email protected]> wrote:
Quoted 7 lines · Stephen Hemminger

Let's assume the people that really want this feature are using a lot of vlan's. i.e n = 1000 or so. A bitmap is O(1). Any hash list would incur a just a big memory penalty for the list head. In other words a full bitmap is 4096 bits = 512 bytes. If you use hash list, then the equivalent memory size would be only 64 list heads, therefore a bitmap is a better choice than a hlist.

Quoted 5 lines

This was the approach taken in the RFC v1 of this series. What I found was that while it worked very well as far as speed goes, it was a bit cumbersome to extend it to support pvids and it would completely fall on its face for egress policy that Shmulik is suggesting. So any kinds of extensions to it were tough to do.

I don't see why this is the case.

How about (sketch only, names questionable...):

struct net_bridge {
+ unsigned long vlan_port_membership_bitmap[VLAN_N_VID][PORT_BITMAP_LEN];
+ unsigned long vlan_port_egress_policy_bitmap[VLAN_N_VID][PORT_BITMAP_LEN];
}

(can be alloc'ed instead of the arrays being part of the struct)

struct net_bridge_port {
+ u16 pvid;
};

Allows O(1) to the query "is port P member of vlan V".
Allows O(1) to the query "should vlan V egress tagged/untagged on port P".

I guess this might simplify the data structures involved, avoiding the refcounts, etc...

The penaties are:
- memory
- aesthetics (?)
- inefficient if query is "give me the entire list of VLANs port P is member of". But do we have such a query in bridge's code?

You say it went cumbersome. Am I missing something?

BTW, altenatively, you may:

struct net_bridge_port {
+ unsigned long vlan_membership_bitmap[BITS_TO_LONGS(VLAN_N_VID)];
+ unsigned long vlan_egress_policy_bitmap[BITS_TO_LONGS(VLAN_N_VID)];
+ u16 pvid;
};

Which also allows O(1) to "is port 'nbp' member of vlan V".

Difference:
- For the membership structure:
former (within net_bridge) uses 4096 * BR_MAX_PORTS bits, latter (within net_bridge_port) uses NumOfNBPs * 4096 bits
- better aesthetics (?)

Regards,
Shmulik

#11 lore raw

Re: [PATCH net-next V6 02/14] bridge: Add vlan filtering infrastructure

Quoted 36 lines · Shmulik Ladkani

Hi Vlad,

Quoted 9 lines · On Sun, 20 Jan 2013 20:50:59 -0500 Vlad Yasevich <[email protected]> wrote:
Quoted 7 lines · Stephen Hemminger

Let's assume the people that really want this feature are using a lot of vlan's. i.e n = 1000 or so. A bitmap is O(1). Any hash list would incur a just a big memory penalty for the list head. In other words a full bitmap is 4096 bits = 512 bytes. If you use hash list, then the equivalent memory size would be only 64 list heads, therefore a bitmap is a better choice than a hlist.

Quoted 5 lines

This was the approach taken in the RFC v1 of this series. What I found was that while it worked very well as far as speed goes, it was a bit cumbersome to extend it to support pvids and it would completely fall on its face for egress policy that Shmulik is suggesting. So any kinds of extensions to it were tough to do.

I don't see why this is the case.

How about (sketch only, names questionable...):

struct net_bridge {

(quoted diff) +2 -0
+	unsigned long vlan_port_membership_bitmap[VLAN_N_VID][PORT_BITMAP_LEN];
+	unsigned long vlan_port_egress_policy_bitmap[VLAN_N_VID][PORT_BITMAP_LEN];

}

(can be alloc'ed instead of the arrays being part of the struct)

struct net_bridge_port {

(quoted diff) +1 -0
+	u16 pvid;

};

Allows O(1) to the query "is port P member of vlan V".
Allows O(1) to the query "should vlan V egress tagged/untagged on port P".

Quoted 8 lines

I guess this might simplify the data structures involved, avoiding the refcounts, etc...

The penaties are:
- memory
- aesthetics (?)
- inefficient if query is "give me the entire list of VLANs port P is member of". But do we have such a query in bridge's code?

Yes. When a mac address is added to a port without an explicit vlan tag we try to add it for every vlan available on the port.

Also, in the API, the user may request vlans configured on a port.

Quoted 11 lines

You say it went cumbersome. Am I missing something?

BTW, altenatively, you may:

struct net_bridge_port {

(quoted diff) +3 -0
+	unsigned long vlan_membership_bitmap[BITS_TO_LONGS(VLAN_N_VID)];
+	unsigned long vlan_egress_policy_bitmap[BITS_TO_LONGS(VLAN_N_VID)];
+	u16 pvid;

};

Quoted 2 lines

Which also allows O(1) to "is port 'nbp' member of vlan V".

This is what the earlier RFC patches did. You are paying a large memory penalty and carrying a mostly empty bitmap when only a small number of vlans is used.

If someone decides that they'd like priority support, you'd need another array or list to hold priority values.

-vlad

Quoted 9 lines

Difference:
- For the membership structure:
former (within net_bridge) uses 4096 * BR_MAX_PORTS bits, latter (within net_bridge_port) uses NumOfNBPs * 4096 bits
- better aesthetics (?)

Regards,
Shmulik

#12 lore raw

Re: [PATCH net-next V6 02/14] bridge: Add vlan filtering infrastructure

Thanks Vlad,

Quoted 11 lines · On Tue, 22 Jan 2013 09:31:43 -0500 Vlad Yasevich <[email protected]> wrote:
Quoted 8 lines

I guess this might simplify the data structures involved, avoiding the refcounts, etc...

The penaties are:
- memory
- aesthetics (?)
- inefficient if query is "give me the entire list of VLANs port P is member of". But do we have such a query in bridge's code?

Yes. When a mac address is added to a port without an explicit vlan tag we try to add it for every vlan available on the port.

I see.
Can't this be bypassed by adding a _single_ FDB entry whose VID value denotes "member of ANY vlan" (value outside the valid 0-4095 range)?

Quoted 1 line

Also, in the API, the user may request vlans configured on a port.

Personally I'd pay the penalty implementing this specific user request in an inefficeint way, to acheive overall simplicity in core bridge code.
But that's just my humble opinion, maybe others might spot drawbacks taking this approach.

BTW, went through the ML, couldn't find the reason why dropped the per-port vlan bitmap and replaced with a vlan list (after your RFC v2 patches). Care to explain what was your motivation?

Regards,
Shmulik

#13 lore raw

Re: [PATCH net-next V6 02/14] bridge: Add vlan filtering infrastructure

Quoted 27 lines · Shmulik Ladkani

Thanks Vlad,

Quoted 11 lines · On Tue, 22 Jan 2013 09:31:43 -0500 Vlad Yasevich <[email protected]> wrote:
Quoted 8 lines

I guess this might simplify the data structures involved, avoiding the refcounts, etc...

The penaties are:
- memory
- aesthetics (?)
- inefficient if query is "give me the entire list of VLANs port P is member of". But do we have such a query in bridge's code?

Yes. When a mac address is added to a port without an explicit vlan tag we try to add it for every vlan available on the port.

I see.
Can't this be bypassed by adding a _single_ FDB entry whose VID value denotes "member of ANY vlan" (value outside the valid 0-4095 range)?

Quoted 1 line

Also, in the API, the user may request vlans configured on a port.

Personally I'd pay the penalty implementing this specific user request in an inefficeint way, to acheive overall simplicity in core bridge code.
But that's just my humble opinion, maybe others might spot drawbacks taking this approach.

Quoted 3 lines

BTW, went through the ML, couldn't find the reason why dropped the per-port vlan bitmap and replaced with a vlan list (after your RFC v2 patches). Care to explain what was your motivation?

I wanted to reduce the memory footprint and make it a bit more extensible so if priority was ever added, it would be very simple to do. I also had to play some ugly memory barrier games to make it less racy.
I thought that the list/hash code was cleaner.

-vlad

Quoted 4 lines

Regards,
Shmulik

A message that is not in the archive (sent off-list or not yet received): CB4696DA7737D0409230B481D0363B1414F0E6029D@HQ1-EXCH03.corp.brocade.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

#16 lore raw

Re: [PATCH net-next V6 02/14] bridge: Add vlan filtering infrastructure

Quoted 5 lines · Stephen Hemminger

I appreciate all the work on this. And at this point it may seem like it will never get in mainline. As far as I am concerned these are the key features:

1. VLAN filtering on both ingress and egress using same table

Can you elaborate a bit more what you mean by this?

Quoted 5 lines

2. O(1) based bit map table
3. netlink based configuration and dump (per port). Okay to just provide the bitmap
4. kernel feature should be optional
5. default behavior has to be to allow all VLAN's for backwards compatibility.

I think with the exception of 2, all of the above requirements are met by the current code. As for #2, a hash approach provides most of the performance gain and allows for extensibility. I am currently removing the list from all the hot paths, and we could make the hash wider if you want to make each hlist shorter.

Quoted 4 lines

Extra credit for:
* cleaning up kernel VLAN API's. Eliminate vlan_buggy() and any/all cases where error is not detected until first packet

I don't think we can truly do that since non-vlans frames should work on vlan_buggy interfaces.

I could also remove all the HW filtering calls out of the code since they are not truly needed now due to running in promisc mode.

-vlad

Quoted 8 lines

I don't care about:
* sysfs API's - sysfs is not good for binary (like bitmap), and doing a list
* split ingress/egress
* future extensibility ideas - do it right now, then do the next step; don't get ahead of yourself.

#17 lore raw

Re: [PATCH net-next V6 02/14] bridge: Add vlan filtering infrastructure

In reply to Vlad Yasevich

Hi Vlad,

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

Quoted 5 lines · On Wed, 16 Jan 2013 13:17:57 -0500 Vlad Yasevich <[email protected]> wrote:
net/bridge/br_private.h +1 -0
@@ -156,6 +183,7 @@ struct net_bridge_port
 #ifdef CONFIG_NET_POLL_CONTROLLER
 	struct netpoll			*np;
 #endif
+	struct net_port_vlans		vlan_info;

(here and at 'struct net_bridge' as well)

Not sure what the policy is; Isn't it preferred to enclose the new fields under CONFIG_BRIDGE_VLAN_FILTERING?

net/bridge/br_private.h struct net_bridge · line 315

Quoted 11 lines
net/bridge/br_private.h +11 -0
+static inline struct net_bridge *vlans_to_bridge(struct net_port_vlans *vlans)
+{
+	struct net_bridge *br;
+
+	if (!vlans->port_idx)
+		br = container_of((vlans), struct net_bridge, vlan_info);
+	else
+		br = vlans_to_port(vlans)->br;
+
+	return br;
+}

Guess it would simplify things if the bridge "master port" had an 'nbp' representation of its own ;-)

Quoted 1 line

+extern struct net_bridge_vlan *br_vlan_find(struct net_bridge *br, u16 vid);

Seems 'br_vlan_find' can be declared static within br_vlan.c.

Quoted 1 line

+extern void br_vlan_flush(struct net_bridge *br);

According to your preference, consider s/br_vlan_flush/br_vlans_flush/ since it better suggest acting on all bridge's vlans.

Quoted 1 line

+extern void nbp_vlan_flush(struct net_port_vlans *vlans);

According to your preference, consider s/nbp_vlan_flush/nbp_vlans_flush/ since it better suggest acting on all port's vlans.

net/bridge/br_vlan.c line 95

Quoted 12 lines
net/bridge/br_vlan.c new file +12 -0
+void br_vlan_flush(struct net_bridge *br)
+{
+	struct net_bridge_vlan *vlan;
+	struct hlist_node *node;
+	struct hlist_node *tmp;
+	int i;
+
+	nbp_vlan_flush(&br->vlan_info);
+
+	/* Make sure that there are no vlans left in the bridge after
+	* all the ports have been removed.
+	*/

Improper indent.

net/bridge/br_vlan.c line 99

Quoted 4 lines
net/bridge/br_vlan.c new file +4 -0
+	for (i = 0; i < BR_VID_HASH_SIZE; i++) {
+		hlist_for_each_entry_safe(vlan, node, tmp,
+					  &br->vlan_hlist[i], hlist) {
+			br_vlan_del(vlan);

Can there be any vlans left at that point? Shouldn't del_nbp() on all ports take care of that?
Also, if there _were_ any vlans left (whose bitmap isn't cleared), 'br_vlan_del' won't do a thing.
Am I missing something?

Regards,
Shmulik

#18 lore raw

Re: [PATCH net-next V6 02/14] bridge: Add vlan filtering infrastructure

Quoted 11 lines · Shmulik Ladkani

Hi Vlad,

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

Quoted 5 lines · On Wed, 16 Jan 2013 13:17:57 -0500 Vlad Yasevich <[email protected]> wrote:
net/bridge/br_private.h +1 -0
@@ -156,6 +183,7 @@ struct net_bridge_port
  #ifdef CONFIG_NET_POLL_CONTROLLER
  	struct netpoll			*np;
  #endif
+	struct net_port_vlans		vlan_info;

(here and at 'struct net_bridge' as well)

Quoted 2 lines

Not sure what the policy is; Isn't it preferred to enclose the new fields under CONFIG_BRIDGE_VLAN_FILTERING?

Good catch. Missed this one.

Quoted 15 lines

net/bridge/br_private.h struct net_bridge · line 315

Quoted 12 lines
net/bridge/br_private.h +11 -0
+static inline struct net_bridge *vlans_to_bridge(struct net_port_vlans *vlans)
+{
+	struct net_bridge *br;
+
+	if (!vlans->port_idx)
+		br = container_of((vlans), struct net_bridge, vlan_info);
+	else
+		br = vlans_to_port(vlans)->br;
+
+	return br;
+}

Guess it would simplify things if the bridge "master port" had an 'nbp' representation of its own ;-)

Yes that would simplify things for this case, but it will also add a lot of state that's not necessary. I considered doing this, but the master device doesn't really act as port in on things, just some.

Quoted 4 lines
Quoted 2 lines

+extern struct net_bridge_vlan *br_vlan_find(struct net_bridge *br, u16 vid);

Seems 'br_vlan_find' can be declared static within br_vlan.c.

Will check.

Quoted 11 lines
Quoted 2 lines

+extern void br_vlan_flush(struct net_bridge *br);

According to your preference, consider s/br_vlan_flush/br_vlans_flush/ since it better suggest acting on all bridge's vlans.

Quoted 1 line

+extern void nbp_vlan_flush(struct net_port_vlans *vlans);

According to your preference, consider s/nbp_vlan_flush/nbp_vlans_flush/ since it better suggest acting on all port's vlans.

Quoted 14 lines

net/bridge/br_vlan.c line 95

Quoted 12 lines
net/bridge/br_vlan.c new file +12 -0
+void br_vlan_flush(struct net_bridge *br)
+{
+	struct net_bridge_vlan *vlan;
+	struct hlist_node *node;
+	struct hlist_node *tmp;
+	int i;
+
+	nbp_vlan_flush(&br->vlan_info);
+
+	/* Make sure that there are no vlans left in the bridge after
+	* all the ports have been removed.
+	*/

Improper indent.

will fix

Quoted 8 lines

net/bridge/br_vlan.c line 99

Quoted 5 lines
net/bridge/br_vlan.c new file +4 -0
+	for (i = 0; i < BR_VID_HASH_SIZE; i++) {
+		hlist_for_each_entry_safe(vlan, node, tmp,
+					  &br->vlan_hlist[i], hlist) {
+			br_vlan_del(vlan);

Can there be any vlans left at that point? Shouldn't del_nbp() on all ports take care of that?

I think this function might have been a leftover from prior series when
bridge didn't have its vlan list. With the new series, I don't this it is needed. I'll double-check.

Thanks
-vlad

Quoted 7 lines

Also, if there _were_ any vlans left (whose bitmap isn't cleared), 'br_vlan_del' won't do a thing.
Am I missing something?

Regards,
Shmulik

#19 lore raw

PATCH v6 3/14 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 |   25 +++++++++++++++++++++++++
 net/bridge/br_vlan.c    |   20 ++++++++++++++++++++
 4 files changed, 52 insertions(+), 0 deletions(-)
net/bridge/br_device.c +3 -0
index b64b5c8..6b8f816 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->vlan_info, skb))
+		goto out;
+
 	BR_INPUT_SKB_CB(skb)->brdev = dev;
 
 	skb_reset_mac_header(skb);
net/bridge/br_input.c +4 -0
index 4b34207..cc959fa 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->vlan_info, 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 +25 -0
index 615f10c..7018546 100644
@@ -582,6 +582,7 @@ static inline bool br_multicast_is_router(struct net_bridge *br)
 
 /* br_vlan.c */
 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
+extern bool br_allowed_ingress(struct net_port_vlans *v, struct sk_buff *skb);
 extern struct net_bridge_vlan *br_vlan_find(struct net_bridge *br, u16 vid);
 extern void br_vlan_flush(struct net_bridge *br);
 extern int nbp_vlan_add(struct net_port_vlans *v, u16 vid);
@@ -589,7 +590,27 @@ extern int nbp_vlan_delete(struct net_port_vlans *v, u16 vid);
 extern struct net_port_vlan *nbp_vlan_find(const struct net_port_vlans *v,
 					   u16 vid);
 extern void nbp_vlan_flush(struct net_port_vlans *vlans);
+
+static inline u16 br_get_vlan(const struct sk_buff *skb)
+{
+	u16 tag;
+
+	if (vlan_tx_tag_present(skb))
+		return vlan_tx_tag_get(skb) & VLAN_VID_MASK;
+
+	if (vlan_get_tag(skb, &tag))
+		return 0;
+
+	return tag & VLAN_VID_MASK;
+}
+
 #else
+static inline bool br_allowed_ingress(struct net_port_vlans *v,
+				      struct sk_buff *skb)
+{
+	return true;
+}
+
 static inline struct net_bridge_vlan *br_vlan_find(struct net_bridge *br,
 						   u16 vid)
 {
@@ -621,6 +642,10 @@ static inline void nbp_vlan_flush(struct net_port_vlans *vlans)
 {
 }
 
+static inline u16 br_get_vlan(const struct sk_buff *skb)
+{
+	return 0;
+}
 #endif
 
 /* br_netfilter.c */
net/bridge/br_vlan.c +20 -0
index 816e85e..72b4892 100644
@@ -5,6 +5,26 @@
 
 #include "br_private.h"
 
+/* Called under RCU */
+bool br_allowed_ingress(struct net_port_vlans *v, struct sk_buff *skb)
+{
+	struct net_port_vlan *pve;
+	u16 vid;
+
+	/* If there are no vlan in the permitted list, all packets are
+	 * permitted.
+	 */
+	if (list_empty(&v->vlan_list))
+		return true;
+
+	vid = br_get_vlan(skb);
+	pve = nbp_vlan_find(v, vid);
+	if (pve)
+		return true;
+
+	return false;
+}
+
 static void br_vlan_destroy(struct net_bridge_vlan *vlan)
 {
 	if (!bitmap_empty(vlan->port_bitmap, PORT_BITMAP_LEN)) {
Signature · 1 line
1.7.7.6
#20 lore raw

Re: [PATCH net-next V6 03/14] bridge: Validate that vlan is permitted on ingress

Hi Vlad,

net/bridge/br_device.c netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev) · line 50

Quoted 7 lines · On Wed, 16 Jan 2013 13:17:58 -0500 Vlad Yasevich <[email protected]> wrote:
net/bridge/br_device.c +3 -0
@@ -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->vlan_info, skb))
+		goto out;
+

Shouldn't you consume the 'skb' in case "not allowed"? the 'out' label doesn't take care of that.

net/bridge/br_vlan.c line 18

Quoted 10 lines
net/bridge/br_vlan.c +10 -0
+bool br_allowed_ingress(struct net_port_vlans *v, struct sk_buff *skb)
+{
+	struct net_port_vlan *pve;
+	u16 vid;
+
+	/* If there are no vlan in the permitted list, all packets are
+	 * permitted.
+	 */
+	if (list_empty(&v->vlan_list))
+		return true;

Rethinking this, after discussed at [1].
The above means the port having no vlans is actually a member of every possible vlan.
IMO it might not be what users expect, and may complicate things.

Maybe we should adapt a simpler approach:
If the bridge is a vlan enabled bridge, and the port is not a member of the given vid, drop.
If the bridge is "vlan disabled", then all packets are permitted.

Regards,
Shmulik

[1]
http://marc.info/?l=linux-netdev&m=135602065425514&w=2

#21 lore raw

Re: [PATCH net-next V6 03/14] bridge: Validate that vlan is permitted on ingress

Quoted 30 lines · Shmulik Ladkani

Hi Vlad,

net/bridge/br_device.c netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev) · line 50

Quoted 7 lines · On Wed, 16 Jan 2013 13:17:58 -0500 Vlad Yasevich <[email protected]> wrote:
net/bridge/br_device.c +3 -0
@@ -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->vlan_info, skb))
+		goto out;
+

Shouldn't you consume the 'skb' in case "not allowed"? the 'out' label doesn't take care of that.

net/bridge/br_vlan.c line 18

Quoted 10 lines
net/bridge/br_vlan.c +10 -0
+bool br_allowed_ingress(struct net_port_vlans *v, struct sk_buff *skb)
+{
+	struct net_port_vlan *pve;
+	u16 vid;
+
+	/* If there are no vlan in the permitted list, all packets are
+	 * permitted.
+	 */
+	if (list_empty(&v->vlan_list))
+		return true;

Rethinking this, after discussed at [1].
The above means the port having no vlans is actually a member of every possible vlan.
IMO it might not be what users expect, and may complicate things.

Quoted 5 lines

Maybe we should adapt a simpler approach:
If the bridge is a vlan enabled bridge, and the port is not a member of the given vid, drop.
If the bridge is "vlan disabled", then all packets are permitted.

this is hybrid configuration where some ports have vlan filtering enabled while others do not.

Currently the default is to act as a non-vlan bridge when there is no configuration. I'll consider adding a configuration nob to switch the behavior so that strict filtering can be enforced.

-vlad

Quoted 6 lines

Regards,
Shmulik

[1]
http://marc.info/?l=linux-netdev&m=135602065425514&w=2

#22 lore raw

PATCH v6 4/14 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 |    9 +++++++++
 net/bridge/br_vlan.c    |   18 ++++++++++++++++++
 4 files changed, 38 insertions(+), 0 deletions(-)
net/bridge/br_forward.c +1 -0
index 02015a5..d740b52 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->vlan_info, skb) &&
 		p->state == BR_STATE_FORWARDING);
 }
 
net/bridge/br_input.c +10 -0
index cc959fa..9a1c4e3 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->vlan_info, skb)) {
+		kfree_skb(skb);
+		return NET_RX_DROP;
+	}
+
 	indev = skb->dev;
 	skb->dev = brdev;
 
net/bridge/br_private.h +9 -0
index 7018546..39e70af 100644
@@ -583,6 +583,8 @@ static inline bool br_multicast_is_router(struct net_bridge *br)
 /* br_vlan.c */
 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
 extern bool br_allowed_ingress(struct net_port_vlans *v, struct sk_buff *skb);
+extern bool br_allowed_egress(const struct net_port_vlans *v,
+			      const struct sk_buff *skb);
 extern struct net_bridge_vlan *br_vlan_find(struct net_bridge *br, u16 vid);
 extern void br_vlan_flush(struct net_bridge *br);
 extern int nbp_vlan_add(struct net_port_vlans *v, u16 vid);
@@ -598,6 +600,7 @@ static inline u16 br_get_vlan(const struct sk_buff *skb)
 	if (vlan_tx_tag_present(skb))
 		return vlan_tx_tag_get(skb) & VLAN_VID_MASK;
 
+	/* Untagged and VLAN 0 traffic is handled the same way */
 	if (vlan_get_tag(skb, &tag))
 		return 0;
 
@@ -611,6 +614,12 @@ static inline bool br_allowed_ingress(struct net_port_vlans *v,
 	return true;
 }
 
+static inline bool br_allowed_egress(const struct net_port_vlans *v,
+				     const struct sk_buff *skb)
+{
+	return true;
+}
+
 static inline struct net_bridge_vlan *br_vlan_find(struct net_bridge *br,
 						   u16 vid)
 {
net/bridge/br_vlan.c +18 -0
index 72b4892..a4f7c15 100644
@@ -25,6 +25,24 @@ bool br_allowed_ingress(struct net_port_vlans *v, struct sk_buff *skb)
 	return false;
 }
 
+/* Called under RCU. */
+bool br_allowed_egress(const struct net_port_vlans *v,
+		       const struct sk_buff *skb)
+{
+	struct net_port_vlan *pve;
+	u16 vid;
+
+	if (list_empty(&v->vlan_list))
+		return true;
+
+	vid = br_get_vlan(skb);
+	pve = nbp_vlan_find(v, vid);
+	if (pve)
+		return true;
+
+	return false;
+}
+
 static void br_vlan_destroy(struct net_bridge_vlan *vlan)
 {
 	if (!bitmap_empty(vlan->port_bitmap, PORT_BITMAP_LEN)) {
Signature · 1 line
1.7.7.6
#23 lore raw

PATCH v6 5/14 bridge: Cache vlan in the cb for faster egress lookup.

In reply to Vlad Yasevich

On input, cache the pointer to the bridge vlan info, so that on egress, we have can simply look at the port bitmap instead of traversing a vlan list.

---
 net/bridge/br_private.h |    1 +
 net/bridge/br_vlan.c    |   20 +++++++++++++++++++-
 2 files changed, 20 insertions(+), 1 deletions(-)
net/bridge/br_private.h +1 -0
index 39e70af..7960681 100644
@@ -316,6 +316,7 @@ static inline struct net_bridge *vlans_to_bridge(struct net_port_vlans *vlans)
 
 struct br_input_skb_cb {
 	struct net_device *brdev;
+	struct net_bridge_vlan *vlan;
 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
 	int igmp;
 	int mrouters_only;
net/bridge/br_vlan.c +19 -1
index a4f7c15..01ebfbc 100644
@@ -11,6 +11,8 @@ bool br_allowed_ingress(struct net_port_vlans *v, struct sk_buff *skb)
 	struct net_port_vlan *pve;
 	u16 vid;
 
+	BR_INPUT_SKB_CB(skb)->vlan = NULL;
+
 	/* If there are no vlan in the permitted list, all packets are
 	 * permitted.
 	 */
@@ -19,8 +21,10 @@ bool br_allowed_ingress(struct net_port_vlans *v, struct sk_buff *skb)
 
 	vid = br_get_vlan(skb);
 	pve = nbp_vlan_find(v, vid);
-	if (pve)
+	if (pve) {
+		BR_INPUT_SKB_CB(skb)->vlan = rcu_dereference(pve->vlan);
 		return true;
+	}
 
 	return false;
 }
@@ -30,11 +34,25 @@ bool br_allowed_egress(const struct net_port_vlans *v,
 		       const struct sk_buff *skb)
 {
 	struct net_port_vlan *pve;
+	struct net_bridge_vlan *vlan = NULL;
 	u16 vid;
 
 	if (list_empty(&v->vlan_list))
 		return true;
 
+	vlan = BR_INPUT_SKB_CB(skb)->vlan;
+	if (vlan) {
+		/* If we have cached VLAN information, use port_bitmap
+		 * of the vlan to make the decision
+		 */
+		if (test_bit(v->port_idx, vlan->port_bitmap))
+			return true;
+		return false;
+	}
+
+	/* We don't have cached vlan information, so we need to do
+	 * it the hard way.
+	 */
 	vid = br_get_vlan(skb);
 	pve = nbp_vlan_find(v, vid);
 	if (pve)
Signature · 1 line
1.7.7.6
#24 lore raw

PATCH v6 6/14 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        |  134 ++++++++++++++++++++++++++++++++++-----
 net/bridge/br_private.h        |    1 +
 net/core/rtnetlink.c           |   72 +++++++++++++++++++++
 7 files changed, 202 insertions(+), 18 deletions(-)
include/linux/netdevice.h +2 -0
index 0209ac3..3a68563 100644
@@ -1017,6 +1017,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 6b8f816..0802f86 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 2427a21..48dcd6c 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 +116 -18

188 lines not on this page · raw message

net/bridge/br_private.h +1 -0
index 7960681..1e7a202 100644
@@ -718,6 +718,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
#25 lore raw

Re: [PATCH net-next V6 06/14] bridge: Add netlink interface to configure vlans on bridge ports

include/uapi/linux/if_bridge.h struct __fdb_entry { · line 127

Quoted 5 lines · Vlad Yasevich
include/uapi/linux/if_bridge.h +5 -0
+
+struct bridge_vlan_info {
+	u16 flags;
+	u16 vid;
+};

I think you have to use __u16 in UAPI headers.

maintainer
#26 lore raw

Re: [PATCH net-next V6 06/14] bridge: Add netlink interface to configure vlans on bridge ports

From: Cong Wang <[email protected]>
Date: Thu, 17 Jan 2013 04:54:37 +0000 (UTC)

Quoted 8 lines · Vlad Yasevich

include/uapi/linux/if_bridge.h struct __fdb_entry { · line 127

Quoted 5 lines
include/uapi/linux/if_bridge.h +5 -0
+
+struct bridge_vlan_info {
+	u16 flags;
+	u16 vid;
+};

I think you have to use __u16 in UAPI headers.

That's right.

#27 lore raw

PATCH v6 7/14 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        |    4 +-
 net/bridge/br_private.h        |    5 ++-
 net/bridge/br_vlan.c           |   70 +++++++++++++++++++++++++++++++++++++++-
 4 files changed, 75 insertions(+), 5 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 +2 -2
index 75f368c..1dbfcf3 100644
@@ -200,12 +200,12 @@ static int br_afspec(struct net_bridge *br,
 
 		switch (cmd) {
 		case RTM_SETLINK:
-			err = nbp_vlan_add(v, vinfo->vid);
+			err = nbp_vlan_add(v, vinfo->vid, vinfo->flags);
 			if (err)
 				break;
 			if (p && (vinfo->flags & BRIDGE_VLAN_INFO_MASTER)) {
 				err = nbp_vlan_add(&p->br->vlan_info,
-						   vinfo->vid);
+						   vinfo->vid, vinfo->flags);
 			}
 			break;
 
net/bridge/br_private.h +3 -2
index 1e7a202..ecf5f34 100644
@@ -88,6 +88,7 @@ struct net_port_vlan {
 struct net_port_vlans {
 	u16				port_idx;
 	struct list_head		vlan_list;
+	struct net_bridge_vlan __rcu	*pvlan;
 };
 
 struct net_bridge_fdb_entry
@@ -588,7 +589,7 @@ extern bool br_allowed_egress(const struct net_port_vlans *v,
 			      const struct sk_buff *skb);
 extern struct net_bridge_vlan *br_vlan_find(struct net_bridge *br, u16 vid);
 extern void br_vlan_flush(struct net_bridge *br);
-extern int nbp_vlan_add(struct net_port_vlans *v, u16 vid);
+extern int nbp_vlan_add(struct net_port_vlans *v, u16 vid, u16 flags);
 extern int nbp_vlan_delete(struct net_port_vlans *v, u16 vid);
 extern struct net_port_vlan *nbp_vlan_find(const struct net_port_vlans *v,
 					   u16 vid);
@@ -631,7 +632,7 @@ static inline void br_vlan_flush(struct net_bridge *br)
 {
 }
 
-static inline int nbp_vlan_add(struct net_port_vlans *v, u16 vid)
+static inline int nbp_vlan_add(struct net_port_vlans *v, u16 vid, u16 flags)
 {
 	return -EINVAL;
 }
net/bridge/br_vlan.c +69 -1

107 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#28 lore raw

PATCH v6 8/14 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. The vlan is cached in the skb.

At egress, if we haven't cached the vlan (traffic arrived on vlan unaware interface), we try to find the vlan for egress port and cache it. If the egress port is vlan unaware, packet is forwared as is.

When we do have the vlan cached, we check to see the "untagged" bitmap to see if the traffic is supposed to leave untagged. Otherwise the traffic will leave with the vlan tag set.

---
 net/8021q/vlan_core.c   |    1 +
 net/bridge/br_device.c  |    4 +-
 net/bridge/br_forward.c |    8 ++++
 net/bridge/br_input.c   |    8 +++-
 net/bridge/br_private.h |   34 +++++++++++----
 net/bridge/br_vlan.c    |  105 ++++++++++++++++++++++++++++++++++++++++++----
 6 files changed, 138 insertions(+), 22 deletions(-)
net/8021q/vlan_core.c +1 -0
index d044dd3..99dffa6 100644
@@ -144,6 +144,7 @@ err_free:
 	kfree_skb(skb);
 	return NULL;
 }
+EXPORT_SYMBOL(vlan_untag);
 
 /**
  * vlan_hw_buggy - Check to see if VLAN hw acceleration is supported.
net/bridge/br_device.c +3 -1
index 0802f86..2d5b63d 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,8 @@ 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->vlan_info, skb))
+	memset(BR_INPUT_SKB_CB(skb), 0, sizeof(struct br_input_skb_cb));
+	if (!br_allowed_ingress(&br->vlan_info, skb, &vid))
 		goto out;
 
 	BR_INPUT_SKB_CB(skb)->brdev = dev;
net/bridge/br_forward.c +8 -0
index d740b52..6dc9f39 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->vlan_info, 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->vlan_info, skb);
+	if (!skb)
+		return;
+
 	indev = skb->dev;
 	skb->dev = to->dev;
 	skb_forward_csum(skb);
net/bridge/br_input.c +7 -1
index 9a1c4e3..10f8467 100644
@@ -45,6 +45,10 @@ static int br_pass_frame_up(struct sk_buff *skb)
 		return NET_RX_DROP;
 	}
 
+	skb = br_handle_vlan(&br->vlan_info, skb);
+	if (!skb)
+		return NET_RX_DROP;
+
 	indev = skb->dev;
 	skb->dev = brdev;
 
@@ -61,11 +65,13 @@ 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->vlan_info, skb))
+	memset(BR_INPUT_SKB_CB(skb), 0, sizeof(struct br_input_skb_cb));
+	if (!br_allowed_ingress(&p->vlan_info, skb, &vid))
 		goto drop;
 
 	/* insert into forwarding database after filtering to avoid spoofing */
net/bridge/br_private.h +24 -10
index ecf5f34..573dfab 100644
@@ -76,6 +76,7 @@ struct net_bridge_vlan {
 	struct rcu_head			rcu;
 	u16				vid;
 	unsigned long			port_bitmap[PORT_BITMAP_LEN];
+	unsigned long			untagged_bitmap[PORT_BITMAP_LEN];
 };
 
 struct net_port_vlan {
@@ -318,6 +319,7 @@ static inline struct net_bridge *vlans_to_bridge(struct net_port_vlans *vlans)
 struct br_input_skb_cb {
 	struct net_device *brdev;
 	struct net_bridge_vlan *vlan;
+	int untagged;
 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
 	int igmp;
 	int mrouters_only;
@@ -584,9 +586,12 @@ static inline bool br_multicast_is_router(struct net_bridge *br)
 
 /* br_vlan.c */
 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
-extern bool br_allowed_ingress(struct net_port_vlans *v, struct sk_buff *skb);
+extern bool br_allowed_ingress(struct net_port_vlans *v, struct sk_buff *skb,
+			       u16 *vid);
 extern bool br_allowed_egress(const struct net_port_vlans *v,
 			      const struct sk_buff *skb);
+extern struct sk_buff *br_handle_vlan(const struct net_port_vlans *v,
+				      struct sk_buff *skb);
 extern struct net_bridge_vlan *br_vlan_find(struct net_bridge *br, u16 vid);
 extern void br_vlan_flush(struct net_bridge *br);
 extern int nbp_vlan_add(struct net_port_vlans *v, u16 vid, u16 flags);
@@ -595,23 +600,26 @@ extern struct net_port_vlan *nbp_vlan_find(const struct net_port_vlans *v,
 					   u16 vid);
 extern void nbp_vlan_flush(struct net_port_vlans *vlans);
 
-static inline u16 br_get_vlan(const struct sk_buff *skb)
+static inline int br_get_vlan(const struct sk_buff *skb, u16 *tag)
 {
-	u16 tag;
+	int rc = 0;
 
-	if (vlan_tx_tag_present(skb))
-		return vlan_tx_tag_get(skb) & VLAN_VID_MASK;
+	if (vlan_tx_tag_present(skb)) {
+		*tag = vlan_tx_tag_get(skb) & VLAN_VID_MASK;
+		return rc;
+	}
 
 	/* Untagged and VLAN 0 traffic is handled the same way */
-	if (vlan_get_tag(skb, &tag))
-		return 0;
+	rc = vlan_get_tag(skb, tag);
+	*tag = *tag & VLAN_VID_MASK;
 
-	return tag & VLAN_VID_MASK;
+	return rc;
 }
 
 #else
 static inline bool br_allowed_ingress(struct net_port_vlans *v,
-				      struct sk_buff *skb)
+				      struct sk_buff *skb,
+				      u16 *vid)
 {
 	return true;
 }
@@ -622,6 +630,12 @@ static inline bool br_allowed_egress(const struct net_port_vlans *v,
 	return true;
 }
 
+static inline struct sk_buff *br_handle_vlan(const struct net_port_vlans *v,
+					     struct sk_buff *skb)
+{
+	return skb;
+}
+
 static inline struct net_bridge_vlan *br_vlan_find(struct net_bridge *br,
 						   u16 vid)
 {
@@ -653,7 +667,7 @@ static inline void nbp_vlan_flush(struct net_port_vlans *vlans)
 {
 }
 
-static inline u16 br_get_vlan(const struct sk_buff *skb)
+static inline u16 br_get_vlan(const struct sk_buff *skb, u16 *tag)
 {
 	return 0;
 }
net/bridge/br_vlan.c +95 -10

138 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#29 lore raw

PATCH v6 9/14 bridge: API to configure egress policy

In reply to Vlad Yasevich

Add an ability to configure "untagged" egress policy to the VLAN information of the bridge. The policy is by a flag and is represented as a port bitmap per vlan. Frames that leave a ports in "untagged" policy bitmap would egress the port without VLAN header.

---
 include/uapi/linux/if_bridge.h |    1 +
 net/bridge/br_vlan.c           |   49 +++++++++++++++++++++++++++++++--------
 2 files changed, 40 insertions(+), 10 deletions(-)
include/uapi/linux/if_bridge.h +1 -0
index c6c30e2..f1bf8d3 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_vlan.c +39 -10

80 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#30 lore raw

PATCH v6 10/14 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 f1bf8d3..8e1fc51 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 2d5b63d..1d42695 100644
@@ -72,7 +72,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 10f8467..e138037 100644
@@ -76,7 +76,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))
@@ -111,7 +111,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;
@@ -139,8 +140,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_get_vlan(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 573dfab..8a30c03 100644
@@ -103,6 +103,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 {
@@ -411,7 +412,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);
@@ -420,7 +422,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
#31 lore raw

PATCH v6 11/14 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 5391ca4..b3e3289 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_get_vlan(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_get_vlan(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_get_vlan(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_get_vlan(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_get_vlan(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_get_vlan(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 8a30c03..908a72a 100644
@@ -63,6 +63,7 @@ struct br_ip
 #endif
 	} u;
 	__be16		proto;
+	__u16		vid;
 };
 
 #define BR_INVALID_VID	(1<<15)
Signature · 1 line
1.7.7.6
#32 lore raw

PATCH v6 12/14 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 the list is empty, 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                           |  142 ++++++++++++++++++++++---
 net/bridge/br_private.h                       |    2 +-
 net/core/rtnetlink.c                          |   23 +++--
 8 files changed, 146 insertions(+), 30 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +1 -1
index 20a5af6..ec97efe 100644
@@ -6985,7 +6985,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 1047e58..3e16d74 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 40f2cc1..c72540b 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 3a68563..eb7a45f 100644
@@ -1005,6 +1005,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 +125 -17

206 lines not on this page · raw message

net/bridge/br_private.h +1 -1
index 908a72a..287374c 100644
@@ -426,7 +426,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[],
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
#33 lore raw

Re: [PATCH net-next V6 12/14] bridge: Add vlan support to static neighbors

net/bridge/br_fdb.c static int fdb_fill_info(struct sk_buff *skb, const struct net_bridge *br, · line 511

Quoted 11 lines · Vlad Yasevich
net/bridge/br_fdb.c +3 -0
index a244efc..90d0bc9 100644
@@ -506,6 +506,10 @@ static int fdb_fill_info(struct sk_buff *skb, const struct net_bridge *br,
 	ci.ndm_refcnt	 = 0;
 	if (nla_put(skb, NDA_CACHEINFO, sizeof(ci), &ci))
 		goto nla_put_failure;
+
+	if (nla_put(skb, NDA_VLAN, sizeof(u16), &fdb->vlan_id))
+		goto nla_put_failure;

Why not just nla_put_u16()?

net/bridge/br_fdb.c int br_fdb_delete(struct ndmsg *ndm, struct net_device *dev, · line 792

Quoted 9 lines
net/bridge/br_fdb.c +9 -0
+
+		/* We have vlans configured on this port and user didn't
+		 * specify a VLAN.  To be nice, add/update entry for every
+		 * vlan on this port.
+		 */
+		err = -ENOENT;
+		list_for_each_entry_rcu(pve, &p->vlan_info.vlan_list, list) {
+			err &= __br_fdb_delete(p, addr, pve->vid);
+		}

'&=' or '|='?

#34 lore raw

PATCH v6 13/14 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     |   62 +++++++++++++++++++++++++++++++++++-----------
 net/bridge/br_if.c      |    2 +-
 net/bridge/br_private.h |    4 ++-
 net/bridge/br_vlan.c    |   25 +++++++++++++++++-
 4 files changed, 74 insertions(+), 19 deletions(-)
net/bridge/br_fdb.c +47 -15
index 90d0bc9..942fe49 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;
+	int no_vlan = list_empty(&p->vlan_info.vlan_list);
 	int i;
 
 	spin_lock_bh(&br->hash_lock);
@@ -106,10 +107,13 @@ 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->vlan_info,
+							  vid)) {
 						f->dst = op;
 						goto insert;
 					}
@@ -117,27 +121,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_bridge_vlan *vlan;
+	struct hlist_node *node;
+	int i;
 
 	/* 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.
+	 */
+	for (i = 0; i < BR_VID_HASH_SIZE; i++) {
+		hlist_for_each_entry_rcu(vlan, node,
+					 &br->vlan_hlist[i], hlist) {
+			if (vlan->vid == BR_INVALID_VID || vlan->vid == 0)
+				continue;
+
+			f = __br_fdb_get(br, br->dev->dev_addr, vlan->vid);
+			if (f && f->is_local && !f->dst)
+				fdb_delete(br, f);
+			fdb_insert(br, NULL, newaddr, vlan->vid);
+		}
+	}
 }
 
 void br_fdb_cleanup(unsigned long _data)
@@ -380,15 +412,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 +433,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 +444,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;
 }
@@ -710,8 +742,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 48dcd6c..45b4ee6 100644
@@ -400,7 +400,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 +3 -1
index 287374c..46f8bdc 100644
@@ -420,11 +420,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,
net/bridge/br_vlan.c +23 -2
index 58cfbb4..40ef79f 100644
@@ -392,6 +392,14 @@ int nbp_vlan_add(struct net_port_vlans *v, u16 vid, u16 flags)
 	if (err)
 		goto del_vlan;
 
+	err = br_fdb_insert(br, p,
+			    (p ? p->dev->dev_addr : br->dev->dev_addr), vid);
+	if (err) {
+		br_err(br,
+		       "failed insert local address bridge forwarding table\n");
+		goto del_vlan;
+	}
+
 	return 0;
 
 clean_up:
@@ -409,13 +417,17 @@ int nbp_vlan_delete(struct net_port_vlans *v, u16 vid)
 	struct net_port_vlan *pve;
 	struct net_bridge_vlan *vlan;
 	struct net_bridge *br;
+	unsigned char *addr;
 
 	ASSERT_RTNL();
 
-	if (v->port_idx)
+	if (v->port_idx) {
 		br = vlans_to_port(v)->br;
-	else
+		addr = vlans_to_port(v)->dev->dev_addr;
+	} else {
 		br = vlans_to_bridge(v);
+		addr = br->dev->dev_addr;
+	}
 
 	pve = nbp_vlan_find(v, vid);
 	if (!pve)
@@ -435,6 +447,15 @@ int nbp_vlan_delete(struct net_port_vlans *v, u16 vid)
 			pr_warn("failed to kill vid %d for device %s\n",
 				vid, dev->name);
 	}
+
+	if (vid) {
+		/* If the VID !=0 remove fdb for this vid. VID 0 is special
+		 * in that it's the default and is always there in the fdb.
+		 */
+		spin_lock_bh(&br->hash_lock);
+		fdb_delete_by_addr(br, addr, vid);
+		spin_unlock_bh(&br->hash_lock);
+	}
 	pve->vid = BR_INVALID_VID;
 
 	rcu_assign_pointer(pve->vlan, NULL);
Signature · 1 line
1.7.7.6
#35 lore raw

PATCH v6 14/14 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                       |  111 ++++++++++++++++++++++---
 net/bridge/br_private.h                       |    3 +-
 net/bridge/br_vlan.c                          |    2 +
 net/core/rtnetlink.c                          |   16 +++-
 7 files changed, 121 insertions(+), 18 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +2 -1
index ec97efe..2f2a8e0 100644
@@ -7062,7 +7062,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 eb7a45f..178d297 100644
@@ -1017,7 +1017,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 +100 -11

167 lines not on this page · raw message

net/bridge/br_private.h +2 -1
index 46f8bdc..2dd91a5 100644
@@ -89,6 +89,7 @@ struct net_port_vlan {
 
 struct net_port_vlans {
 	u16				port_idx;
+	u16				num_vlans;
 	struct list_head		vlan_list;
 	struct net_bridge_vlan __rcu	*pvlan;
 };
@@ -741,7 +742,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 -0
index 40ef79f..efb3534 100644
@@ -387,6 +387,7 @@ int nbp_vlan_add(struct net_port_vlans *v, u16 vid, u16 flags)
 	set_bit(v->port_idx, vlan->port_bitmap);
 
 	list_add_tail_rcu(&pve->list, &v->vlan_list);
+	v->num_vlans++;
 
 	err = nbp_vlan_do_flags(v, vlan, flags);
 	if (err)
@@ -463,6 +464,7 @@ int nbp_vlan_delete(struct net_port_vlans *v, u16 vid)
 	br_vlan_put(vlan);
 
 	list_del_rcu(&pve->list);
+	v->num_vlans--;
 	kfree_rcu(pve, rcu);
 
 	br_vlan_del(vlan);
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