Add basic VLAN support to bridges
Subsystems (4)
v2 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 may also be designated as untagged. Any untagged traffic recieved by the port will be assigned to this vlan. Any traffic exiting the port with a VID matching the untagged vlan will exit untagged (the bridge will strip the vlan header). This is similar to "Native Vlan" support available in most switches.
The default behavior ofthe bridge is unchanged if no vlans have been configured.
Changes since v1:
- Fixed some forwarding bugs.
- Add vlan to local fdb entries. New local entries are created per vlan to facilite correct forwarding to bridge interface.
- Allow configuration of vlans directly on the bridge master device in addition to ports.
Changes since rfc v2:
- Per-port vlan bitmap is gone and is replaced with a vlan list.
- Added bridge vlan list, which is referenced by each port. Entries in the birdge vlan list have port bitmap that shows which port are parts of which vlan.
- Netlink API changes.
- Dropped sysfs support for now. If people think this is really usefull, can add it back.
- Support for native/untagged vlans.
Changes since rfc v1:
- Comments addressed regarding formatting and RCU usage
- iocts have been removed and changed over the netlink interface.
- Added support of user added ndb entries.
- changed sysfs interface to export a bitmap. Also added a write interface. I am not sure how much I like it, but it made my testing easier/faster. I might change the write interface to take text instead of binary.
Vlad Yasevich (12):
bridge: Add vlan filtering infrastructure
bridge: Validate that vlan is permitted on ingress
bridge: Verify that a vlan is allowed to egress on give port
bridge: Cache vlan in the cb for faster egress lookup.
bridge: Add vlan to unicast fdb entries
bridge: Add vlan id to multicast groups
bridge: Add netlink interface to configure vlans on bridge ports
bridge: Add vlan support to static neighbors
bridge: Add the ability to configure untagged vlans
bridge: Implement untagged vlan handling
bridge: Dump vlan information from a bridge port
bridge: Add vlan support for local fdb entries
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 5 +- drivers/net/macvlan.c | 2 +- drivers/net/vxlan.c | 3 +- include/linux/netdevice.h | 4 +- include/uapi/linux/if_bridge.h | 23 ++- include/uapi/linux/neighbour.h | 1 + include/uapi/linux/rtnetlink.h | 1 + net/bridge/br_device.c | 34 ++- net/bridge/br_fdb.c | 253 ++++++++++++--- net/bridge/br_forward.c | 160 ++++++++++ net/bridge/br_if.c | 404 ++++++++++++++++++++++++- net/bridge/br_input.c | 65 ++++- net/bridge/br_multicast.c | 71 +++-- net/bridge/br_netlink.c | 178 ++++++++++-- net/bridge/br_private.h | 71 ++++- net/core/rtnetlink.c | 40 ++- 16 files changed, 1190 insertions(+), 125 deletions(-)
Signature · 1 line
1.7.7.6
PATCH v2 1/12 bridge: Add vlan filtering infrastructure
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/br_device.c | 3 + net/bridge/br_if.c | 251 +++++++++++++++++++++++++++++++++++++++++++++++ net/bridge/br_private.h | 33 ++++++ 3 files changed, 287 insertions(+), 0 deletions(-)
net/bridge/br_device.c +3 -0
@@ -332,6 +332,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);
@@ -354,6 +355,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 ;
net/bridge/br_if.c +251 -0
275 lines not on this page · raw message
net/bridge/br_private.h +33 -0
@@ -18,6 +18,7 @@#include <linux/netpoll.h> #include <linux/u64_stats_sync.h> #include <net/route.h> +#include <linux/if_vlan.h> #define BR_HASH_BITS 8#define BR_HASH_SIZE (1 << BR_HASH_BITS)
@@ -26,6 +27,7 @@#define BR_PORT_BITS 10#define BR_MAX_PORTS (1<<BR_PORT_BITS) +#define PORT_BITMAP_LEN BITS_TO_LONGS(BR_MAX_PORTS)#define BR_VERSION "2.3"
@@ -63,6 +65,27 @@ struct br_ip__be16 proto; }; +#define BR_INVALID_VID (1<<15) +#define BR_UNTAGGED_VID (1<<14) + +#define BR_VID_HASH_SIZE (1<<6) +#define br_vlan_hash (vid) ((vid) % (BR_VID_HASH_SIZE - 1)) + +struct net_bridge_vlan { +struct hlist_node hlist; +atomic_t refcnt; +struct rcu_head rcu; +u16 vid; +unsigned long port_bitmap[PORT_BITMAP_LEN ]; +}; + +struct net_port_vlan { +struct list_head list; +struct net_bridge_vlan *vlan; +struct rcu_head rcu; +u16 vid; +}; +struct net_bridge_fdb_entry {struct hlist_node hlist;
@@ -155,6 +178,7 @@ struct net_bridge_port#ifdef CONFIG_NET_POLL_CONTROLLER struct netpoll *np;#endif +struct list_head vlan_list; };#define br_port_exists (dev) (dev->priv_flags & IFF_BRIDGE_PORT)
@@ -259,6 +283,7 @@ struct net_bridgestruct timer_list topology_change_timer;struct timer_list gc_timer;struct kobject *ifobj; +struct hlist_head vlan_hlist[BR_VID_HASH_SIZE ]; };struct br_input_skb_cb {
@@ -400,6 +425,14 @@ extern int br_del_if(struct net_bridge *br,extern int br_min_mtu (const struct net_bridge *br);extern netdev_features_t br_features_recompute (struct net_bridge *br,netdev_features_t features); +extern struct net_bridge_vlan *br_vlan_add (struct net_bridge *br,u16 vid, +u16 flags); +extern int br_vlan_delete (struct net_bridge *br,u16 vid,u16 flags); +extern struct net_bridge_vlan *br_vlan_find (struct net_bridge *br,u16 vid); +extern int nbp_vlan_add (struct net_bridge_port *p,u16 vid,u16 flags); +extern int nbp_vlan_delete (struct net_bridge_port *p,u16 vid,u16 flags); +extern struct net_port_vlan *nbp_vlan_find (const struct net_bridge_port *p, +u16 vid);/* br_input.c */ extern int br_handle_frame_finish (struct sk_buff *skb);
Signature · 1 line
1.7.7.6
Re: [PATCH V2 01/12] bridge: Add vlan filtering infrastructure
net/bridge/br_if.c void br_port_carrier_check(struct net_bridge_port *p) · line 97
Quoted 12 lines · Vlad Yasevich
net/bridge/br_if.c +12
-0+static void br_vlan_destroy (struct net_bridge_vlan *vlan) +{ +if (!bitmap_empty (vlan->port_bitmap,PORT_BITMAP_LEN )) { +pr_err ("Attempt to delete a VLAN %d from the bridge with " +"non-empty port bitmap (%p)\n" , vlan->vid, vlan); +BUG (); + } + +hlist_del_rcu (&vlan->hlist); +synchronize_net (); +kfree_rcu (vlan, rcu); +}
Not clear why you both use synchronize_net() and kfree_rcu()
Re: [PATCH V2 01/12] bridge: Add vlan filtering infrastructure
Quoted 17 lines · Eric Dumazet
net/bridge/br_if.c void br_port_carrier_check(struct net_bridge_port *p) · line 97
Quoted 12 lines · Vlad Yasevich
net/bridge/br_if.c +12
-0+static void br_vlan_destroy (struct net_bridge_vlan *vlan) +{ +if (!bitmap_empty (vlan->port_bitmap,PORT_BITMAP_LEN )) { +pr_err ("Attempt to delete a VLAN %d from the bridge with " +"non-empty port bitmap (%p)\n" , vlan->vid, vlan); +BUG (); + } + +hlist_del_rcu (&vlan->hlist); +synchronize_net (); +kfree_rcu (vlan, rcu); +}Not clear why you both use
synchronize_net()andkfree_rcu()
I think this was a left-over from old code. I think this was originally here to mimic del_nbp behavior, but I don't think it's really needed as kfree_rcu should wait until all current rcu section have completed.
-vlad
PATCH v2 2/12 bridge: Validate that vlan is permitted on ingress
In reply to Vlad YasevichWhen a frame arrives on a port, if we have VLANs configured, validate that a given VLAN is allowed to ingress on a given port.
--- net/bridge/br_input.c | 23 +++++++++++++++++++++++ net/bridge/br_private.h | 15 +++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-)
net/bridge/br_input.c +23 -0
@@ -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 */
@@ -41,6 +42,25 @@ static int br_pass_frame_up(struct sk_buff *skb) netif_receive_skb); } +static bool br_allowed_ingress (struct net_bridge_port *p,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 (&p->vlan_list)) +return true; + + vid =br_get_vlan (skb); + pve =nbp_vlan_find (p, vid); +if (pve) +return true; + +return false; +} +/* note: already called with rcu_read_lock */ int br_handle_frame_finish (struct sk_buff *skb) {
@@ -54,6 +74,9 @@ int br_handle_frame_finish(struct sk_buff *skb)if (!p || p->state ==BR_STATE_DISABLED ) goto drop; +if (!br_allowed_ingress (p, skb)) + goto drop; +/* insert into forwarding database after filtering to avoid spoofing */ br = p->br;br_fdb_update (br, p,eth_hdr (skb)->h_source);
net/bridge/br_private.h +13 -2
@@ -66,8 +66,6 @@ struct br_ip };#define BR_INVALID_VID (1<<15) -#define BR_UNTAGGED_VID (1<<14) -#define BR_VID_HASH_SIZE (1<<6)#define br_vlan_hash (vid) ((vid) % (BR_VID_HASH_SIZE - 1))
@@ -197,6 +195,19 @@ static inline struct net_bridge_port *br_port_get_rtnl(struct net_device *dev) rtnl_dereference(dev->rx_handler_data) : NULL; } +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 ; +} +struct br_cpu_netstats {u64 rx_packets;u64 rx_bytes;
Signature · 1 line
1.7.7.6
PATCH v2 3/12 bridge: Verify that a vlan is allowed to egress on give port
In reply to Vlad YasevichWhen bridge forwards a frame, make sure that a frame is allowed to egress on that port.
--- net/bridge/br_forward.c | 18 ++++++++++++++++++ net/bridge/br_private.h | 1 + 2 files changed, 19 insertions(+), 0 deletions(-)
net/bridge/br_forward.c +18 -0
@@ -26,11 +26,29 @@ static int deliver_clone(const struct net_bridge_port *prev,void (*__packet_hook)(const struct net_bridge_port *p, struct sk_buff *skb)); +static inline bool br_allowed_egress (const struct net_bridge_port *p, +const struct sk_buff *skb) +{ +struct net_port_vlan *pve; +u16 vid; + +if (list_empty (&p->vlan_list)) +return true; + + vid =br_get_vlan (skb); + pve =nbp_vlan_find (p, vid); +if (pve) +return true; + +return false; +} +/* Don't forward packets to originating port or forwarding diasabled */ 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, skb) && p->state ==BR_STATE_FORWARDING ); }
net/bridge/br_private.h +1 -0
@@ -202,6 +202,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 ;
Signature · 1 line
1.7.7.6
PATCH v2 4/12 bridge: Cache vlan in the cb for faster egress lookup.
In reply to Vlad YasevichOn 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_device.c | 8 ++++++++ net/bridge/br_forward.c | 14 ++++++++++++++ net/bridge/br_input.c | 6 +++++- net/bridge/br_private.h | 1 + 4 files changed, 28 insertions(+), 1 deletions(-)
net/bridge/br_device.c +8 -0
@@ -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); +struct net_bridge_vlan *vlan;rcu_read_lock ();#ifdef CONFIG_BRIDGE_NETFILTER
@@ -47,6 +48,13 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)BR_INPUT_SKB_CB (skb)->brdev = dev; +/* Any vlan transmitted by the bridge itself is permitted. +* Try to cache the vlan in the CB to speed up forwarding. +*/ + vlan =br_vlan_find (br,br_get_vlan (skb)); +if (vlan) +BR_INPUT_SKB_CB (skb)->vlan = vlan; +skb_reset_mac_header (skb);skb_pull (skb,ETH_HLEN );
net/bridge/br_forward.c +14 -0
@@ -30,11 +30,25 @@ static inline bool br_allowed_egress(const struct net_bridge_port *p, const struct sk_buff *skb) {struct net_port_vlan *pve; +struct net_bridge_vlan *vlan =NULL ;u16 vid;if (list_empty (&p->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 (p->port_no, 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 (p, vid);if (pve)
net/bridge/br_input.c +5 -1
@@ -47,6 +47,8 @@ static bool br_allowed_ingress(struct net_bridge_port *p, 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. */
@@ -55,8 +57,10 @@ static bool br_allowed_ingress(struct net_bridge_port *p, struct sk_buff *skb) vid =br_get_vlan (skb); pve =nbp_vlan_find (p, vid); -if (pve) +if (pve) { +BR_INPUT_SKB_CB (skb)->vlan = pve->vlan;return true; + }return false; }
net/bridge/br_private.h +1 -0
@@ -300,6 +300,7 @@ struct net_bridgestruct br_input_skb_cb {struct net_device *brdev; +struct net_bridge_vlan *vlan;#ifdef CONFIG_BRIDGE_IGMP_SNOOPING int igmp;int mrouters_only;
Signature · 1 line
1.7.7.6
PATCH v2 5/12 bridge: Add vlan to unicast fdb entries
In reply to Vlad YasevichThis 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 | 6 ++- net/bridge/br_fdb.c | 70 +++++++++++++++++++++++---------------- net/bridge/br_input.c | 16 +++++---- net/bridge/br_private.h | 7 +++- 5 files changed, 60 insertions(+), 41 deletions(-)
include/uapi/linux/if_bridge.h +1 -1
@@ -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 +4 -2
@@ -31,6 +31,7 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)struct net_bridge_mdb_entry *mdst;struct br_cpu_netstats *brstats =this_cpu_ptr (br->stats);struct net_bridge_vlan *vlan; +u16 vid;rcu_read_lock ();#ifdef CONFIG_BRIDGE_NETFILTER
@@ -51,7 +52,8 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)/* Any vlan transmitted by the bridge itself is permitted. * Try to cache the vlan in the CB to speed up forwarding. */ - vlan =br_vlan_find (br,br_get_vlan (skb)); + vid =br_get_vlan (skb); + vlan =br_vlan_find (br, vid);if (vlan)BR_INPUT_SKB_CB (skb)->vlan = vlan;
@@ -75,7 +77,7 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)br_multicast_deliver (mdst, skb); elsebr_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 +9 -7
@@ -42,10 +42,10 @@ static int br_pass_frame_up(struct sk_buff *skb) netif_receive_skb); } -static bool br_allowed_ingress (struct net_bridge_port *p,struct sk_buff *skb) +static bool br_allowed_ingress (struct net_bridge_port *p,struct sk_buff *skb, +u16 vid) {struct net_port_vlan *pve; -u16 vid;BR_INPUT_SKB_CB (skb)->vlan =NULL ;
@@ -55,7 +55,6 @@ static bool br_allowed_ingress(struct net_bridge_port *p, struct sk_buff *skb)if (list_empty (&p->vlan_list))return true; - vid =br_get_vlan (skb); pve =nbp_vlan_find (p, vid);if (pve) {BR_INPUT_SKB_CB (skb)->vlan = pve->vlan;
@@ -74,16 +73,18 @@ 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;if (!p || p->state ==BR_STATE_DISABLED ) goto drop; -if (!br_allowed_ingress (p, skb)) + vid =br_get_vlan (skb); +if (!br_allowed_ingress (p, skb, vid)) goto drop;/* 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))
@@ -118,7 +119,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 ;
@@ -147,7 +149,7 @@ static int br_handle_local_finish(struct sk_buff *skb) {struct net_bridge_port *p =br_port_get_rcu (skb->dev); -br_fdb_update (p->br, p,eth_hdr (skb)->h_source); +br_fdb_update (p->br, p,eth_hdr (skb)->h_source,br_get_vlan (skb));return 0 ;/* process further */ }
net/bridge/br_private.h +5 -2
@@ -95,6 +95,7 @@ struct net_bridge_fdb_entrymac_addr addr;unsigned char is_local;unsigned char is_static; +__u16 vlan_id; };struct net_bridge_port_group {
@@ -392,7 +393,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);
@@ -401,7 +403,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
PATCH v2 6/12 bridge: Add vlan id to multicast groups
In reply to Vlad YasevichAdd 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 | 64 +++++++++++++++++++++++++++++++-------------- net/bridge/br_private.h | 1 + 2 files changed, 45 insertions(+), 20 deletions(-)
net/bridge/br_multicast.c +44 -20
@@ -51,6 +51,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;
@@ -62,16 +64,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
@@ -80,10 +85,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 ;
@@ -113,24 +118,27 @@ static struct net_bridge_mdb_entry *br_mdb_ip_get( }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); }
@@ -692,7 +700,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;
@@ -701,6 +710,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); }
@@ -708,7 +718,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;
@@ -717,6 +728,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); }
@@ -928,7 +940,8 @@ 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, +br_get_vlan (skb));if (err)break ; }
@@ -988,7 +1001,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, +br_get_vlan (skb));if (!err)break ; }
@@ -1106,7 +1120,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); + mp =br_mdb_ip4_get (mlock_dereference (br->mdb, br), group, +br_get_vlan (skb));if (!mp) goto out;
@@ -1178,7 +1193,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); + mp =br_mdb_ip6_get (mlock_dereference (br->mdb, br), group, +br_get_vlan (skb));if (!mp) goto out;
@@ -1283,7 +1299,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;
@@ -1292,6 +1309,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); }
@@ -1299,7 +1317,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;
@@ -1308,6 +1327,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); }
@@ -1390,7 +1410,8 @@ 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, +br_get_vlan (skb2));break ;case IGMPV3_HOST_MEMBERSHIP_REPORT : err =br_ip4_multicast_igmp3_report (br, port, skb2);
@@ -1399,7 +1420,8 @@ 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, +br_get_vlan (skb2));break ; }
@@ -1519,7 +1541,8 @@ 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, +br_get_vlan (skb2));break ; }case ICMPV6_MLD2_REPORT :
@@ -1536,7 +1559,8 @@ 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, +br_get_vlan (skb2)); } }
net/bridge/br_private.h +1 -0
@@ -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
PATCH v2 7/12 bridge: Add netlink interface to configure vlans on bridge ports
In reply to Vlad YasevichAdd 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/uapi/linux/if_bridge.h | 17 ++++++ net/bridge/br_if.c | 1 + net/bridge/br_netlink.c | 107 +++++++++++++++++++++++++++++++++------ 3 files changed, 108 insertions(+), 17 deletions(-)
include/uapi/linux/if_bridge.h +17 -0
@@ -108,15 +108,32 @@ 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) +/* Bridge VLAN info +* [IFLA_BRIDGE_VLAN_INFO] +*/ +enum { +BR_VLAN_ADD , +BR_VLAN_DEL , +}; + +struct bridge_vlan_info { +u16 op_code; +u16 flags; +u16 vid; +u16 unused; +}; +/* Bridge multicast database attributes * [MDBA_MDB] = { * [MDBA_MDB_ENTRY] = {
net/bridge/br_if.c +1 -0
@@ -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 +90 -17
149 lines not on this page · raw message
Signature · 1 line
1.7.7.6
PATCH v2 8/12 bridge: Add vlan support to static neighbors
In reply to Vlad YasevichWhen 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 | 139 ++++++++++++++++++++++--- net/bridge/br_private.h | 2 +- net/core/rtnetlink.c | 24 +++-- 8 files changed, 146 insertions(+), 28 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +1 -1
@@ -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
@@ -565,7 +565,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
@@ -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
@@ -996,6 +996,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
@@ -20,6 +20,7 @@ enum {NDA_LLADDR ,NDA_CACHEINFO ,NDA_PROBES , +NDA_VLAN , __NDA_MAX };
net/bridge/br_fdb.c +124 -15
204 lines not on this page · raw message
net/bridge/br_private.h +1 -1
@@ -407,7 +407,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 +15 -9
@@ -2125,7 +2125,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;
@@ -2133,8 +2133,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 ) {
@@ -2148,13 +2149,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 */
@@ -2163,7 +2168,8 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)struct net_device *master = dev->master;if (master->netdev_ops->ndo_fdb_del) - err = master->netdev_ops->ndo_fdb_del (ndm, dev, addr); + err = master->netdev_ops->ndo_fdb_del (ndm, tb, + dev, addr);if (err) goto out;
@@ -2173,7 +2179,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
PATCH v2 9/12 bridge: Add the ability to configure untagged vlans
In reply to Vlad YasevichA user may designate a certain vlan as untagged. This means that any ingress frame is assigned to this vlan and any forwarding decisions are made with this vlan in mind. On egress, any frames tagged/labeled with untagged vlan have the vlan tag removed and are send as regular ethernet frames.
--- include/uapi/linux/if_bridge.h | 3 + net/bridge/br_if.c | 146 +++++++++++++++++++++++++++++++++++++--- net/bridge/br_netlink.c | 6 +- net/bridge/br_private.h | 2 + 4 files changed, 144 insertions(+), 13 deletions(-)
include/uapi/linux/if_bridge.h +3 -0
@@ -127,6 +127,9 @@ enum { BR_VLAN_DEL, }; +#define BRIDGE_VLAN_INFO_MASTER 1 +#define BRIDGE_VLAN_INFO_UNTAGGED 2 +struct bridge_vlan_info {u16 op_code;u16 flags;
net/bridge/br_if.c +135 -11
238 lines not on this page · raw message
net/bridge/br_netlink.c +4 -2
@@ -199,7 +199,8 @@ static int br_afspec(struct net_bridge *br, struct net_bridge_port *p,if (p) err =nbp_vlan_add (p, vinfo->vid, vinfo->flags);else { -u16 flags = vinfo->flags |BRIDGE_FLAGS_SELF ; +u16 flags = vinfo->flags | +BRIDGE_VLAN_INFO_MASTER ;if (!br_vlan_add (br, vinfo->vid, flags)) err = -ENOMEM ; }
@@ -210,7 +211,8 @@ static int br_afspec(struct net_bridge *br, struct net_bridge_port *p, err =nbp_vlan_delete (p, vinfo->vid, vinfo->flags); else { -u16 flags = vinfo->flags |BRIDGE_FLAGS_SELF ; +u16 flags = vinfo->flags | +BRIDGE_VLAN_INFO_MASTER ; err =br_vlan_delete (br, vinfo->vid, flags); }break ;
net/bridge/br_private.h +2 -0
@@ -179,6 +179,7 @@ struct net_bridge_portstruct netpoll *np;#endif struct list_head vlan_list; +struct net_bridge_vlan __rcu *untagged; };#define br_port_exists (dev) (dev->priv_flags & IFF_BRIDGE_PORT)
@@ -298,6 +299,7 @@ struct net_bridgestruct timer_list gc_timer;struct kobject *ifobj;struct hlist_head vlan_hlist[BR_VID_HASH_SIZE ]; +struct net_bridge_vlan __rcu *untagged; };struct br_input_skb_cb {
Signature · 1 line
1.7.7.6
Re: [PATCH V2 09/12] bridge: Add the ability to configure untagged vlans
Quoted 41 lines · Vlad Yasevich
A user may designate a certain vlan as untagged. This means that any ingress frame is assigned to this vlan and any forwarding decisions are made with this vlan in mind. On egress, any frames tagged/labeled with untagged vlan have the vlan tag removed and are send as regular ethernet frames.
Signed-off-by Vlad Yasevich <[email protected]>--- include/uapi/linux/if_bridge.h | 3 + net/bridge/br_if.c | 146 +++++++++++++++++++++++++++++++++++++--- net/bridge/br_netlink.c | 6 +- net/bridge/br_private.h | 2 + 4 files changed, 144 insertions(+), 13 deletions(-)include/uapi/linux/if_bridge.h +3
-0@@ -127,6 +127,9 @@ enum { BR_VLAN_DEL, }; +#define BRIDGE_VLAN_INFO_MASTER 1 +#define BRIDGE_VLAN_INFO_UNTAGGED 2 +struct bridge_vlan_info {u16 op_code;u16 flags;net/bridge/br_if.c +5
-0@@ -108,6 +108,34 @@ static void br_vlan_put(struct net_bridge_vlan *vlan)br_vlan_destroy (vlan); } +/* Must be protected by RTNL */ +static void br_vlan_add_untagged (struct net_bridge *br, +struct net_bridge_vlan *vlan) +{ +ASSERT_RTNL ();
net/bridge/br_if.c static void br_vlan_put(struct net_bridge_vlan *vlan) · line 125
Quoted 10 lines
net/bridge/br_if.c +10
-0+if (br->untagged == vlan) +return ; +else if (br->untagged) { +/* Untagged vlan is already set on the master, +* so drop the ref since we'll be replacing it. +*/ +br_vlan_put (br->untagged); + } +br_vlan_hold (vlan); +rcu_assign_pointer (br->untagged, vlan);
Is there a reason for rcu here but not else where? If all users are under rtnl you can just assign in a simple way.
If not then rcu_dereference_protected would be more appropriate.
Quoted 278 lines
net/bridge/br_if.c +120
-11+} + +/* Must be protected by RTNL */ +static void br_vlan_del_untagged (struct net_bridge *br, +struct net_bridge_vlan *vlan) +{ +ASSERT_RTNL (); +if (br->untagged == vlan) { +br_vlan_put (vlan); +rcu_assign_pointer (br->untagged,NULL ); + } +} +struct net_bridge_vlan *br_vlan_find (struct net_bridge *br,u16 vid) {struct net_bridge_vlan *vlan;@@ -132,7 +160,7 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid, vlan =br_vlan_find (br, vid);if (vlan) -return vlan; + goto untagged; vlan =kzalloc (sizeof (struct net_bridge_vlan ),GFP_KERNEL );if (!vlan)@@ -141,7 +169,7 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid, vlan->vid = vid;atomic_set (&vlan->refcnt,1 ); -if (flags &BRIDGE_FLAGS_SELF ) { +if (flags &BRIDGE_VLAN_INFO_MASTER ) {/* Set bit 0 that is associated with the bridge master * device. Port numbers start with 1. */ @@ -149,15 +177,24 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid, }hlist_add_head_rcu (&vlan->hlist, &br->vlan_hlist[br_vlan_hash (vid)]); + +untagged: +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) +br_vlan_add_untagged (br, vlan); +return vlan; }/* Must be protected by RTNL */ -static void br_vlan_del (struct net_bridge_vlan *vlan,u16 flags) +static void br_vlan_del (struct net_bridge *br,struct net_bridge_vlan *vlan, +u16 flags) {ASSERT_RTNL (); -if (flags &BRIDGE_FLAGS_SELF ) { +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) +br_vlan_del_untagged (br, vlan); + +if (flags &BRIDGE_VLAN_INFO_MASTER ) {/* Clear bit 0 that is associated with the bridge master * device. */ @@ -172,6 +209,14 @@ static void br_vlan_del(struct net_bridge_vlan *vlan, u16 flags) vlan->vid =BR_INVALID_VID ; +/* If, for whatever reason, bridge still has a ref on this vlan +* through the @untagged pointer, drop that ref and clear untagged. +*/ +if (br->untagged == vlan) { +br_vlan_put (vlan); +rcu_assign_pointer (br->untagged,NULL ); + } +/* Drop the self-ref to trigger descrution. */ br_vlan_put (vlan); }@@ -187,7 +232,7 @@ int br_vlan_delete(struct net_bridge *br, u16 vid, u16 flags)if (!vlan)return -ENOENT ; -br_vlan_del (vlan, flags); +br_vlan_del (br, vlan, flags);return 0 ; }@@ -204,7 +249,9 @@ static void br_vlan_flush(struct net_bridge *br)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,BRIDGE_FLAGS_SELF ); +br_vlan_del (br, vlan, + (BRIDGE_VLAN_INFO_MASTER | +BRIDGE_VLAN_INFO_UNTAGGED )); } } }@@ -224,10 +271,70 @@ struct net_port_vlan *nbp_vlan_find(const struct net_bridge_port *p, u16 vid)return NULL ; } +static int nbp_vlan_add_untagged (struct net_bridge_port *p, +struct net_bridge_vlan *vlan, +u16 flags) +{ +struct net_device *dev = p->dev; + +if (p->untagged) { +/* Port already has untagged vlan set. Drop the ref +* to the old one since we'll be replace it. +*/ +br_vlan_put (p->untagged); + }else { +int err; + +/* Add vid 0 to filter if filter is available. */ +if ((dev->features &NETIF_F_HW_VLAN_FILTER ) && + dev->netdev_ops->ndo_vlan_rx_add_vid && + dev->netdev_ops->ndo_vlan_rx_kill_vid) { + err = dev->netdev_ops->ndo_vlan_rx_add_vid (dev,0 ); +if (err) +return err; + } + } + +/* This VLAN is handled as untagged/native. Save an +* additional ref. +*/ +br_vlan_hold (vlan); +rcu_assign_pointer (p->untagged, vlan); + +return 0 ; +} + +static void nbp_vlan_delete_untagged (struct net_bridge_port *p, +struct net_bridge_vlan *vlan) +{ +if (p->untagged != vlan) +return ; + +/* Remove VLAN from the device filter if it is supported. */ +if ((p->dev->features &NETIF_F_HW_VLAN_FILTER ) && + p->dev->netdev_ops->ndo_vlan_rx_kill_vid) { +int err; + + err = p->dev->netdev_ops->ndo_vlan_rx_kill_vid (p->dev,0 ); +if (err) { +pr_warn ("failed to kill vid %d for device %s\n" , + vlan->vid, p->dev->name); + } + } + +/* If this VLAN is currently functioning as untagged, clear it. +* It's safe to drop the refcount, since the vlan is still held +* by the port. +*/ +br_vlan_put (vlan); +rcu_assign_pointer (p->untagged,NULL ); + +} +/* Must be protected by RTNL */ int nbp_vlan_add (struct net_bridge_port *p,u16 vid,u16 flags) { -struct net_port_vlan *pve; +struct net_port_vlan *pve =NULL ;struct net_bridge_vlan *vlan;struct net_device *dev = p->dev;int err;@@ -275,11 +382,21 @@ int nbp_vlan_add(struct net_bridge_port *p, u16 vid, u16 flags)set_bit (p->port_no, vlan->port_bitmap);list_add_tail_rcu (&pve->list, &p->vlan_list); + +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) { + err =nbp_vlan_add_untagged (p, vlan, flags); +if (err) + goto del_vlan; + } +return 0 ; clean_up:kfree (pve); -br_vlan_del (vlan, flags); +br_vlan_del (p->br, vlan, flags); +return err; +del_vlan: +nbp_vlan_delete (p, vid, flags);return err; }@@ -296,6 +413,9 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)if (!pve)return -ENOENT ; +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) +nbp_vlan_delete_untagged (p, pve->vlan); +/* Remove VLAN from the device filter if it is supported. */ if ((dev->features &NETIF_F_HW_VLAN_FILTER ) && dev->netdev_ops->ndo_vlan_rx_kill_vid) {@@ -306,6 +426,7 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)pr_warn ("failed to kill vid %d for device %s\n" , vid, dev->name); } + pve->vid =BR_INVALID_VID ; vlan = pve->vlan;@@ -316,7 +437,7 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)list_del_rcu (&pve->list);kfree_rcu (pve, rcu); -br_vlan_del (vlan, flags); +br_vlan_del (p->br, vlan, flags);return 0 ; }@@ -328,8 +449,11 @@ static void nbp_vlan_flush(struct net_bridge_port *p)ASSERT_RTNL (); -list_for_each_entry_safe (pve, tmp, &p->vlan_list, list) -nbp_vlan_delete (p, pve->vid,BRIDGE_FLAGS_SELF ); +list_for_each_entry_safe (pve, tmp, &p->vlan_list, list) { +nbp_vlan_delete (p, pve->vid, + (BRIDGE_VLAN_INFO_MASTER | +BRIDGE_VLAN_INFO_UNTAGGED )); + } }static void release_nbp (struct kobject *kobj)net/bridge/br_netlink.c +4
-2@@ -199,7 +199,8 @@ static int br_afspec(struct net_bridge *br, struct net_bridge_port *p,if (p) err =nbp_vlan_add (p, vinfo->vid, vinfo->flags);else { -u16 flags = vinfo->flags |BRIDGE_FLAGS_SELF ; +u16 flags = vinfo->flags | +BRIDGE_VLAN_INFO_MASTER ;if (!br_vlan_add (br, vinfo->vid, flags)) err = -ENOMEM ; }@@ -210,7 +211,8 @@ static int br_afspec(struct net_bridge *br, struct net_bridge_port *p, err =nbp_vlan_delete (p, vinfo->vid, vinfo->flags); else { -u16 flags = vinfo->flags |BRIDGE_FLAGS_SELF ; +u16 flags = vinfo->flags | +BRIDGE_VLAN_INFO_MASTER ; err =br_vlan_delete (br, vinfo->vid, flags); }break ;net/bridge/br_private.h +2
-0@@ -179,6 +179,7 @@ struct net_bridge_portstruct netpoll *np;#endif struct list_head vlan_list; +struct net_bridge_vlan __rcu *untagged; };#define br_port_exists (dev) (dev->priv_flags & IFF_BRIDGE_PORT)@@ -298,6 +299,7 @@ struct net_bridgestruct timer_list gc_timer;struct kobject *ifobj;struct hlist_head vlan_hlist[BR_VID_HASH_SIZE ]; +struct net_bridge_vlan __rcu *untagged; };struct br_input_skb_cb {Signature · 1 line
1.7.7.6
Re: [PATCH V2 09/12] bridge: Add the ability to configure untagged vlans
Quoted 48 lines · Michael S. Tsirkin
Quoted 47 lines · Vlad Yasevich
A user may designate a certain vlan as untagged. This means that any ingress frame is assigned to this vlan and any forwarding decisions are made with this vlan in mind. On egress, any frames tagged/labeled with untagged vlan have the vlan tag removed and are send as regular ethernet frames.
Signed-off-by Vlad Yasevich <[email protected]>--- include/uapi/linux/if_bridge.h | 3 + net/bridge/br_if.c | 146 +++++++++++++++++++++++++++++++++++++--- net/bridge/br_netlink.c | 6 +- net/bridge/br_private.h | 2 + 4 files changed, 144 insertions(+), 13 deletions(-)include/uapi/linux/if_bridge.h +3
-0@@ -127,6 +127,9 @@ enum { BR_VLAN_DEL, }; +#define BRIDGE_VLAN_INFO_MASTER 1 +#define BRIDGE_VLAN_INFO_UNTAGGED 2 +struct bridge_vlan_info {u16 op_code;u16 flags;net/bridge/br_if.c +11
-0@@ -108,6 +108,34 @@ static void br_vlan_put(struct net_bridge_vlan *vlan)br_vlan_destroy (vlan); } +/* Must be protected by RTNL */ +static void br_vlan_add_untagged (struct net_bridge *br, +struct net_bridge_vlan *vlan) +{ +ASSERT_RTNL (); +if (br->untagged == vlan) +return ; +else if (br->untagged) { +/* Untagged vlan is already set on the master, +* so drop the ref since we'll be replacing it. +*/
Quoted 8 lines
net/bridge/br_if.c static void br_vlan_put(struct net_bridge_vlan *vlan) · line 125
Quoted 4 lines
net/bridge/br_if.c +4
-0+br_vlan_put (br->untagged); + } +br_vlan_hold (vlan); +rcu_assign_pointer (br->untagged, vlan);Is there a reason for rcu here but not else where? If all users are under rtnl you can just assign in a simple way.
If not thenrcu_dereference_protectedwould be more appropriate.
Everywhere that the pointer changes rcu_assign_pointer is used.
Now, if we hold an RTNL, we can technically read the pointer with rcu since it's guaranteed not to change since it only changes under RTNL. I'll check that this is consistent.
If I access the pointer without rtnl, it's always inside rcu critical section and with rcu_dereference().
I thought those were the basic rules of rcu. Did that change?
-vlad
Quoted 279 lines
Quoted 279 lines
net/bridge/br_if.c +120
-11+} + +/* Must be protected by RTNL */ +static void br_vlan_del_untagged (struct net_bridge *br, +struct net_bridge_vlan *vlan) +{ +ASSERT_RTNL (); +if (br->untagged == vlan) { +br_vlan_put (vlan); +rcu_assign_pointer (br->untagged,NULL ); + } +} +struct net_bridge_vlan *br_vlan_find (struct net_bridge *br,u16 vid) {struct net_bridge_vlan *vlan;@@ -132,7 +160,7 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid, vlan =br_vlan_find (br, vid);if (vlan) -return vlan; + goto untagged; vlan =kzalloc (sizeof (struct net_bridge_vlan ),GFP_KERNEL );if (!vlan)@@ -141,7 +169,7 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid, vlan->vid = vid;atomic_set (&vlan->refcnt,1 ); -if (flags &BRIDGE_FLAGS_SELF ) { +if (flags &BRIDGE_VLAN_INFO_MASTER ) {/* Set bit 0 that is associated with the bridge master * device. Port numbers start with 1. */ @@ -149,15 +177,24 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid, }hlist_add_head_rcu (&vlan->hlist, &br->vlan_hlist[br_vlan_hash (vid)]); + +untagged: +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) +br_vlan_add_untagged (br, vlan); +return vlan; }/* Must be protected by RTNL */ -static void br_vlan_del (struct net_bridge_vlan *vlan,u16 flags) +static void br_vlan_del (struct net_bridge *br,struct net_bridge_vlan *vlan, +u16 flags) {ASSERT_RTNL (); -if (flags &BRIDGE_FLAGS_SELF ) { +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) +br_vlan_del_untagged (br, vlan); + +if (flags &BRIDGE_VLAN_INFO_MASTER ) {/* Clear bit 0 that is associated with the bridge master * device. */ @@ -172,6 +209,14 @@ static void br_vlan_del(struct net_bridge_vlan *vlan, u16 flags) vlan->vid =BR_INVALID_VID ; +/* If, for whatever reason, bridge still has a ref on this vlan +* through the @untagged pointer, drop that ref and clear untagged. +*/ +if (br->untagged == vlan) { +br_vlan_put (vlan); +rcu_assign_pointer (br->untagged,NULL ); + } +/* Drop the self-ref to trigger descrution. */ br_vlan_put (vlan); }@@ -187,7 +232,7 @@ int br_vlan_delete(struct net_bridge *br, u16 vid, u16 flags)if (!vlan)return -ENOENT ; -br_vlan_del (vlan, flags); +br_vlan_del (br, vlan, flags);return 0 ; }@@ -204,7 +249,9 @@ static void br_vlan_flush(struct net_bridge *br)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,BRIDGE_FLAGS_SELF ); +br_vlan_del (br, vlan, + (BRIDGE_VLAN_INFO_MASTER | +BRIDGE_VLAN_INFO_UNTAGGED )); } } }@@ -224,10 +271,70 @@ struct net_port_vlan *nbp_vlan_find(const struct net_bridge_port *p, u16 vid)return NULL ; } +static int nbp_vlan_add_untagged (struct net_bridge_port *p, +struct net_bridge_vlan *vlan, +u16 flags) +{ +struct net_device *dev = p->dev; + +if (p->untagged) { +/* Port already has untagged vlan set. Drop the ref +* to the old one since we'll be replace it. +*/ +br_vlan_put (p->untagged); + }else { +int err; + +/* Add vid 0 to filter if filter is available. */ +if ((dev->features &NETIF_F_HW_VLAN_FILTER ) && + dev->netdev_ops->ndo_vlan_rx_add_vid && + dev->netdev_ops->ndo_vlan_rx_kill_vid) { + err = dev->netdev_ops->ndo_vlan_rx_add_vid (dev,0 ); +if (err) +return err; + } + } + +/* This VLAN is handled as untagged/native. Save an +* additional ref. +*/ +br_vlan_hold (vlan); +rcu_assign_pointer (p->untagged, vlan); + +return 0 ; +} + +static void nbp_vlan_delete_untagged (struct net_bridge_port *p, +struct net_bridge_vlan *vlan) +{ +if (p->untagged != vlan) +return ; + +/* Remove VLAN from the device filter if it is supported. */ +if ((p->dev->features &NETIF_F_HW_VLAN_FILTER ) && + p->dev->netdev_ops->ndo_vlan_rx_kill_vid) { +int err; + + err = p->dev->netdev_ops->ndo_vlan_rx_kill_vid (p->dev,0 ); +if (err) { +pr_warn ("failed to kill vid %d for device %s\n" , + vlan->vid, p->dev->name); + } + } + +/* If this VLAN is currently functioning as untagged, clear it. +* It's safe to drop the refcount, since the vlan is still held +* by the port. +*/ +br_vlan_put (vlan); +rcu_assign_pointer (p->untagged,NULL ); + +} +/* Must be protected by RTNL */ int nbp_vlan_add (struct net_bridge_port *p,u16 vid,u16 flags) { -struct net_port_vlan *pve; +struct net_port_vlan *pve =NULL ;struct net_bridge_vlan *vlan;struct net_device *dev = p->dev;int err;@@ -275,11 +382,21 @@ int nbp_vlan_add(struct net_bridge_port *p, u16 vid, u16 flags)set_bit (p->port_no, vlan->port_bitmap);list_add_tail_rcu (&pve->list, &p->vlan_list); + +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) { + err =nbp_vlan_add_untagged (p, vlan, flags); +if (err) + goto del_vlan; + } +return 0 ; clean_up:kfree (pve); -br_vlan_del (vlan, flags); +br_vlan_del (p->br, vlan, flags); +return err; +del_vlan: +nbp_vlan_delete (p, vid, flags);return err; }@@ -296,6 +413,9 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)if (!pve)return -ENOENT ; +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) +nbp_vlan_delete_untagged (p, pve->vlan); +/* Remove VLAN from the device filter if it is supported. */ if ((dev->features &NETIF_F_HW_VLAN_FILTER ) && dev->netdev_ops->ndo_vlan_rx_kill_vid) {@@ -306,6 +426,7 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)pr_warn ("failed to kill vid %d for device %s\n" , vid, dev->name); } + pve->vid =BR_INVALID_VID ; vlan = pve->vlan;@@ -316,7 +437,7 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)list_del_rcu (&pve->list);kfree_rcu (pve, rcu); -br_vlan_del (vlan, flags); +br_vlan_del (p->br, vlan, flags);return 0 ; }@@ -328,8 +449,11 @@ static void nbp_vlan_flush(struct net_bridge_port *p)ASSERT_RTNL (); -list_for_each_entry_safe (pve, tmp, &p->vlan_list, list) -nbp_vlan_delete (p, pve->vid,BRIDGE_FLAGS_SELF ); +list_for_each_entry_safe (pve, tmp, &p->vlan_list, list) { +nbp_vlan_delete (p, pve->vid, + (BRIDGE_VLAN_INFO_MASTER | +BRIDGE_VLAN_INFO_UNTAGGED )); + } }static void release_nbp (struct kobject *kobj)net/bridge/br_netlink.c +4
-2@@ -199,7 +199,8 @@ static int br_afspec(struct net_bridge *br, struct net_bridge_port *p,if (p) err =nbp_vlan_add (p, vinfo->vid, vinfo->flags);else { -u16 flags = vinfo->flags |BRIDGE_FLAGS_SELF ; +u16 flags = vinfo->flags | +BRIDGE_VLAN_INFO_MASTER ;if (!br_vlan_add (br, vinfo->vid, flags)) err = -ENOMEM ; }@@ -210,7 +211,8 @@ static int br_afspec(struct net_bridge *br, struct net_bridge_port *p, err =nbp_vlan_delete (p, vinfo->vid, vinfo->flags); else { -u16 flags = vinfo->flags |BRIDGE_FLAGS_SELF ; +u16 flags = vinfo->flags | +BRIDGE_VLAN_INFO_MASTER ; err =br_vlan_delete (br, vinfo->vid, flags); }break ;net/bridge/br_private.h +2
-1@@ -179,6 +179,7 @@ struct net_bridge_portstruct netpoll *np;#endif struct list_head vlan_list; +struct net_bridge_vlan __rcu *untagged; };#define br_port_exists (dev) (dev->priv_flags & IFF_BRIDGE_PORT)@@ -298,6 +299,7 @@ struct net_bridgestruct timer_list gc_timer;struct kobject *ifobj;struct hlist_head vlan_hlist[BR_VID_HASH_SIZE ]; +struct net_bridge_vlan __rcu *untagged; };struct br_input_skb_cb { --1.7.7.6
Re: [PATCH V2 09/12] bridge: Add the ability to configure untagged vlans
Quoted 58 lines · Vlad Yasevich
Quoted 48 lines · Michael S. Tsirkin
Quoted 47 lines · Vlad Yasevich
A user may designate a certain vlan as untagged. This means that any ingress frame is assigned to this vlan and any forwarding decisions are made with this vlan in mind. On egress, any frames tagged/labeled with untagged vlan have the vlan tag removed and are send as regular ethernet frames.
Signed-off-by Vlad Yasevich <[email protected]>--- include/uapi/linux/if_bridge.h | 3 + net/bridge/br_if.c | 146 +++++++++++++++++++++++++++++++++++++--- net/bridge/br_netlink.c | 6 +- net/bridge/br_private.h | 2 + 4 files changed, 144 insertions(+), 13 deletions(-)include/uapi/linux/if_bridge.h +3
-0@@ -127,6 +127,9 @@ enum { BR_VLAN_DEL, }; +#define BRIDGE_VLAN_INFO_MASTER 1 +#define BRIDGE_VLAN_INFO_UNTAGGED 2 +struct bridge_vlan_info {u16 op_code;u16 flags;net/bridge/br_if.c +11
-0@@ -108,6 +108,34 @@ static void br_vlan_put(struct net_bridge_vlan *vlan)br_vlan_destroy (vlan); } +/* Must be protected by RTNL */ +static void br_vlan_add_untagged (struct net_bridge *br, +struct net_bridge_vlan *vlan) +{ +ASSERT_RTNL (); +if (br->untagged == vlan) +return ; +else if (br->untagged) { +/* Untagged vlan is already set on the master, +* so drop the ref since we'll be replacing it. +*/ Quoted 8 lines
net/bridge/br_if.c static void br_vlan_put(struct net_bridge_vlan *vlan) · line 125
Quoted 4 lines
net/bridge/br_if.c +4
-0+br_vlan_put (br->untagged); + } +br_vlan_hold (vlan); +rcu_assign_pointer (br->untagged, vlan);Is there a reason for rcu here but not else where? If all users are under rtnl you can just assign in a simple way.
If not thenrcu_dereference_protectedwould be more appropriate.
Quoted 6 lines
Everywhere that the pointer changes
rcu_assign_pointeris used.Now, if we hold an RTNL, we can technically read the pointer with rcu since it's guaranteed not to change since it only changes under RTNL.
I'll check that this is consistent.
Check what rcu_dereference_protected does. It's really just an explicit way to say "this is accessed without rcu because I have this lock".
Quoted 288 lines
If I access the pointer without rtnl, it's always inside rcu critical section and with
rcu_dereference().I thought those were the basic rules of rcu. Did that change?
-vlad
Quoted 279 lines
Quoted 279 lines
net/bridge/br_if.c +120
-11+} + +/* Must be protected by RTNL */ +static void br_vlan_del_untagged (struct net_bridge *br, +struct net_bridge_vlan *vlan) +{ +ASSERT_RTNL (); +if (br->untagged == vlan) { +br_vlan_put (vlan); +rcu_assign_pointer (br->untagged,NULL ); + } +} +struct net_bridge_vlan *br_vlan_find (struct net_bridge *br,u16 vid) {struct net_bridge_vlan *vlan;@@ -132,7 +160,7 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid, vlan =br_vlan_find (br, vid);if (vlan) -return vlan; + goto untagged; vlan =kzalloc (sizeof (struct net_bridge_vlan ),GFP_KERNEL );if (!vlan)@@ -141,7 +169,7 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid, vlan->vid = vid;atomic_set (&vlan->refcnt,1 ); -if (flags &BRIDGE_FLAGS_SELF ) { +if (flags &BRIDGE_VLAN_INFO_MASTER ) {/* Set bit 0 that is associated with the bridge master * device. Port numbers start with 1. */ @@ -149,15 +177,24 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid, }hlist_add_head_rcu (&vlan->hlist, &br->vlan_hlist[br_vlan_hash (vid)]); + +untagged: +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) +br_vlan_add_untagged (br, vlan); +return vlan; }/* Must be protected by RTNL */ -static void br_vlan_del (struct net_bridge_vlan *vlan,u16 flags) +static void br_vlan_del (struct net_bridge *br,struct net_bridge_vlan *vlan, +u16 flags) {ASSERT_RTNL (); -if (flags &BRIDGE_FLAGS_SELF ) { +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) +br_vlan_del_untagged (br, vlan); + +if (flags &BRIDGE_VLAN_INFO_MASTER ) {/* Clear bit 0 that is associated with the bridge master * device. */ @@ -172,6 +209,14 @@ static void br_vlan_del(struct net_bridge_vlan *vlan, u16 flags) vlan->vid =BR_INVALID_VID ; +/* If, for whatever reason, bridge still has a ref on this vlan +* through the @untagged pointer, drop that ref and clear untagged. +*/ +if (br->untagged == vlan) { +br_vlan_put (vlan); +rcu_assign_pointer (br->untagged,NULL ); + } +/* Drop the self-ref to trigger descrution. */ br_vlan_put (vlan); }@@ -187,7 +232,7 @@ int br_vlan_delete(struct net_bridge *br, u16 vid, u16 flags)if (!vlan)return -ENOENT ; -br_vlan_del (vlan, flags); +br_vlan_del (br, vlan, flags);return 0 ; }@@ -204,7 +249,9 @@ static void br_vlan_flush(struct net_bridge *br)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,BRIDGE_FLAGS_SELF ); +br_vlan_del (br, vlan, + (BRIDGE_VLAN_INFO_MASTER | +BRIDGE_VLAN_INFO_UNTAGGED )); } } }@@ -224,10 +271,70 @@ struct net_port_vlan *nbp_vlan_find(const struct net_bridge_port *p, u16 vid)return NULL ; } +static int nbp_vlan_add_untagged (struct net_bridge_port *p, +struct net_bridge_vlan *vlan, +u16 flags) +{ +struct net_device *dev = p->dev; + +if (p->untagged) { +/* Port already has untagged vlan set. Drop the ref +* to the old one since we'll be replace it. +*/ +br_vlan_put (p->untagged); + }else { +int err; + +/* Add vid 0 to filter if filter is available. */ +if ((dev->features &NETIF_F_HW_VLAN_FILTER ) && + dev->netdev_ops->ndo_vlan_rx_add_vid && + dev->netdev_ops->ndo_vlan_rx_kill_vid) { + err = dev->netdev_ops->ndo_vlan_rx_add_vid (dev,0 ); +if (err) +return err; + } + } + +/* This VLAN is handled as untagged/native. Save an +* additional ref. +*/ +br_vlan_hold (vlan); +rcu_assign_pointer (p->untagged, vlan); + +return 0 ; +} + +static void nbp_vlan_delete_untagged (struct net_bridge_port *p, +struct net_bridge_vlan *vlan) +{ +if (p->untagged != vlan) +return ; + +/* Remove VLAN from the device filter if it is supported. */ +if ((p->dev->features &NETIF_F_HW_VLAN_FILTER ) && + p->dev->netdev_ops->ndo_vlan_rx_kill_vid) { +int err; + + err = p->dev->netdev_ops->ndo_vlan_rx_kill_vid (p->dev,0 ); +if (err) { +pr_warn ("failed to kill vid %d for device %s\n" , + vlan->vid, p->dev->name); + } + } + +/* If this VLAN is currently functioning as untagged, clear it. +* It's safe to drop the refcount, since the vlan is still held +* by the port. +*/ +br_vlan_put (vlan); +rcu_assign_pointer (p->untagged,NULL ); + +} +/* Must be protected by RTNL */ int nbp_vlan_add (struct net_bridge_port *p,u16 vid,u16 flags) { -struct net_port_vlan *pve; +struct net_port_vlan *pve =NULL ;struct net_bridge_vlan *vlan;struct net_device *dev = p->dev;int err;@@ -275,11 +382,21 @@ int nbp_vlan_add(struct net_bridge_port *p, u16 vid, u16 flags)set_bit (p->port_no, vlan->port_bitmap);list_add_tail_rcu (&pve->list, &p->vlan_list); + +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) { + err =nbp_vlan_add_untagged (p, vlan, flags); +if (err) + goto del_vlan; + } +return 0 ; clean_up:kfree (pve); -br_vlan_del (vlan, flags); +br_vlan_del (p->br, vlan, flags); +return err; +del_vlan: +nbp_vlan_delete (p, vid, flags);return err; }@@ -296,6 +413,9 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)if (!pve)return -ENOENT ; +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) +nbp_vlan_delete_untagged (p, pve->vlan); +/* Remove VLAN from the device filter if it is supported. */ if ((dev->features &NETIF_F_HW_VLAN_FILTER ) && dev->netdev_ops->ndo_vlan_rx_kill_vid) {@@ -306,6 +426,7 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)pr_warn ("failed to kill vid %d for device %s\n" , vid, dev->name); } + pve->vid =BR_INVALID_VID ; vlan = pve->vlan;@@ -316,7 +437,7 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)list_del_rcu (&pve->list);kfree_rcu (pve, rcu); -br_vlan_del (vlan, flags); +br_vlan_del (p->br, vlan, flags);return 0 ; }@@ -328,8 +449,11 @@ static void nbp_vlan_flush(struct net_bridge_port *p)ASSERT_RTNL (); -list_for_each_entry_safe (pve, tmp, &p->vlan_list, list) -nbp_vlan_delete (p, pve->vid,BRIDGE_FLAGS_SELF ); +list_for_each_entry_safe (pve, tmp, &p->vlan_list, list) { +nbp_vlan_delete (p, pve->vid, + (BRIDGE_VLAN_INFO_MASTER | +BRIDGE_VLAN_INFO_UNTAGGED )); + } }static void release_nbp (struct kobject *kobj)net/bridge/br_netlink.c +4
-2@@ -199,7 +199,8 @@ static int br_afspec(struct net_bridge *br, struct net_bridge_port *p,if (p) err =nbp_vlan_add (p, vinfo->vid, vinfo->flags);else { -u16 flags = vinfo->flags |BRIDGE_FLAGS_SELF ; +u16 flags = vinfo->flags | +BRIDGE_VLAN_INFO_MASTER ;if (!br_vlan_add (br, vinfo->vid, flags)) err = -ENOMEM ; }@@ -210,7 +211,8 @@ static int br_afspec(struct net_bridge *br, struct net_bridge_port *p, err =nbp_vlan_delete (p, vinfo->vid, vinfo->flags); else { -u16 flags = vinfo->flags |BRIDGE_FLAGS_SELF ; +u16 flags = vinfo->flags | +BRIDGE_VLAN_INFO_MASTER ; err =br_vlan_delete (br, vinfo->vid, flags); }break ;net/bridge/br_private.h +2
-1@@ -179,6 +179,7 @@ struct net_bridge_portstruct netpoll *np;#endif struct list_head vlan_list; +struct net_bridge_vlan __rcu *untagged; };#define br_port_exists (dev) (dev->priv_flags & IFF_BRIDGE_PORT)@@ -298,6 +299,7 @@ struct net_bridgestruct timer_list gc_timer;struct kobject *ifobj;struct hlist_head vlan_hlist[BR_VID_HASH_SIZE ]; +struct net_bridge_vlan __rcu *untagged; };struct br_input_skb_cb { --1.7.7.6
Re: [PATCH V2 09/12] bridge: Add the ability to configure untagged vlans
Quoted 61 lines · Michael S. Tsirkin
Quoted 60 lines · Vlad Yasevich
Quoted 48 lines · Michael S. Tsirkin
Quoted 47 lines · Vlad Yasevich
A user may designate a certain vlan as untagged. This means that any ingress frame is assigned to this vlan and any forwarding decisions are made with this vlan in mind. On egress, any frames tagged/labeled with untagged vlan have the vlan tag removed and are send as regular ethernet frames.
Signed-off-by Vlad Yasevich <[email protected]>--- include/uapi/linux/if_bridge.h | 3 + net/bridge/br_if.c | 146 +++++++++++++++++++++++++++++++++++++--- net/bridge/br_netlink.c | 6 +- net/bridge/br_private.h | 2 + 4 files changed, 144 insertions(+), 13 deletions(-)include/uapi/linux/if_bridge.h +3
-0@@ -127,6 +127,9 @@ enum { BR_VLAN_DEL, }; +#define BRIDGE_VLAN_INFO_MASTER 1 +#define BRIDGE_VLAN_INFO_UNTAGGED 2 +struct bridge_vlan_info {u16 op_code;u16 flags;net/bridge/br_if.c +11
-0@@ -108,6 +108,34 @@ static void br_vlan_put(struct net_bridge_vlan *vlan)br_vlan_destroy (vlan); } +/* Must be protected by RTNL */ +static void br_vlan_add_untagged (struct net_bridge *br, +struct net_bridge_vlan *vlan) +{ +ASSERT_RTNL (); +if (br->untagged == vlan) +return ; +else if (br->untagged) { +/* Untagged vlan is already set on the master, +* so drop the ref since we'll be replacing it. +*/ Quoted 8 lines
net/bridge/br_if.c static void br_vlan_put(struct net_bridge_vlan *vlan) · line 125
Quoted 4 lines
net/bridge/br_if.c +4
-0+br_vlan_put (br->untagged); + } +br_vlan_hold (vlan); +rcu_assign_pointer (br->untagged, vlan);Is there a reason for rcu here but not else where? If all users are under rtnl you can just assign in a simple way.
If not thenrcu_dereference_protectedwould be more appropriate.Everywhere that the pointer changes
rcu_assign_pointeris used.
Quoted 8 lines
Quoted 4 lines
Now, if we hold an RTNL, we can technically read the pointer with rcu since it's guaranteed not to change since it only changes under RTNL.
I'll check that this is consistent.Check what
rcu_dereference_protecteddoes. It's really just an explicit way to say "this is accessed without rcu because I have this lock".
Looks like the helper rtnl_dereference() already does what I need. I'll use that.
Thanks
-vlad
Quoted 289 lines
Quoted 289 lines
If I access the pointer without rtnl, it's always inside rcu critical section and with
rcu_dereference().I thought those were the basic rules of rcu. Did that change?
-vlad
Quoted 279 lines
Quoted 279 lines
net/bridge/br_if.c +120
-11+} + +/* Must be protected by RTNL */ +static void br_vlan_del_untagged (struct net_bridge *br, +struct net_bridge_vlan *vlan) +{ +ASSERT_RTNL (); +if (br->untagged == vlan) { +br_vlan_put (vlan); +rcu_assign_pointer (br->untagged,NULL ); + } +} +struct net_bridge_vlan *br_vlan_find (struct net_bridge *br,u16 vid) {struct net_bridge_vlan *vlan;@@ -132,7 +160,7 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid, vlan =br_vlan_find (br, vid);if (vlan) -return vlan; + goto untagged; vlan =kzalloc (sizeof (struct net_bridge_vlan ),GFP_KERNEL );if (!vlan)@@ -141,7 +169,7 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid, vlan->vid = vid;atomic_set (&vlan->refcnt,1 ); -if (flags &BRIDGE_FLAGS_SELF ) { +if (flags &BRIDGE_VLAN_INFO_MASTER ) {/* Set bit 0 that is associated with the bridge master * device. Port numbers start with 1. */ @@ -149,15 +177,24 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid, }hlist_add_head_rcu (&vlan->hlist, &br->vlan_hlist[br_vlan_hash (vid)]); + +untagged: +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) +br_vlan_add_untagged (br, vlan); +return vlan; }/* Must be protected by RTNL */ -static void br_vlan_del (struct net_bridge_vlan *vlan,u16 flags) +static void br_vlan_del (struct net_bridge *br,struct net_bridge_vlan *vlan, +u16 flags) {ASSERT_RTNL (); -if (flags &BRIDGE_FLAGS_SELF ) { +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) +br_vlan_del_untagged (br, vlan); + +if (flags &BRIDGE_VLAN_INFO_MASTER ) {/* Clear bit 0 that is associated with the bridge master * device. */ @@ -172,6 +209,14 @@ static void br_vlan_del(struct net_bridge_vlan *vlan, u16 flags) vlan->vid =BR_INVALID_VID ; +/* If, for whatever reason, bridge still has a ref on this vlan +* through the @untagged pointer, drop that ref and clear untagged. +*/ +if (br->untagged == vlan) { +br_vlan_put (vlan); +rcu_assign_pointer (br->untagged,NULL ); + } +/* Drop the self-ref to trigger descrution. */ br_vlan_put (vlan); }@@ -187,7 +232,7 @@ int br_vlan_delete(struct net_bridge *br, u16 vid, u16 flags)if (!vlan)return -ENOENT ; -br_vlan_del (vlan, flags); +br_vlan_del (br, vlan, flags);return 0 ; }@@ -204,7 +249,9 @@ static void br_vlan_flush(struct net_bridge *br)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,BRIDGE_FLAGS_SELF ); +br_vlan_del (br, vlan, + (BRIDGE_VLAN_INFO_MASTER | +BRIDGE_VLAN_INFO_UNTAGGED )); } } }@@ -224,10 +271,70 @@ struct net_port_vlan *nbp_vlan_find(const struct net_bridge_port *p, u16 vid)return NULL ; } +static int nbp_vlan_add_untagged (struct net_bridge_port *p, +struct net_bridge_vlan *vlan, +u16 flags) +{ +struct net_device *dev = p->dev; + +if (p->untagged) { +/* Port already has untagged vlan set. Drop the ref +* to the old one since we'll be replace it. +*/ +br_vlan_put (p->untagged); + }else { +int err; + +/* Add vid 0 to filter if filter is available. */ +if ((dev->features &NETIF_F_HW_VLAN_FILTER ) && + dev->netdev_ops->ndo_vlan_rx_add_vid && + dev->netdev_ops->ndo_vlan_rx_kill_vid) { + err = dev->netdev_ops->ndo_vlan_rx_add_vid (dev,0 ); +if (err) +return err; + } + } + +/* This VLAN is handled as untagged/native. Save an +* additional ref. +*/ +br_vlan_hold (vlan); +rcu_assign_pointer (p->untagged, vlan); + +return 0 ; +} + +static void nbp_vlan_delete_untagged (struct net_bridge_port *p, +struct net_bridge_vlan *vlan) +{ +if (p->untagged != vlan) +return ; + +/* Remove VLAN from the device filter if it is supported. */ +if ((p->dev->features &NETIF_F_HW_VLAN_FILTER ) && + p->dev->netdev_ops->ndo_vlan_rx_kill_vid) { +int err; + + err = p->dev->netdev_ops->ndo_vlan_rx_kill_vid (p->dev,0 ); +if (err) { +pr_warn ("failed to kill vid %d for device %s\n" , + vlan->vid, p->dev->name); + } + } + +/* If this VLAN is currently functioning as untagged, clear it. +* It's safe to drop the refcount, since the vlan is still held +* by the port. +*/ +br_vlan_put (vlan); +rcu_assign_pointer (p->untagged,NULL ); + +} +/* Must be protected by RTNL */ int nbp_vlan_add (struct net_bridge_port *p,u16 vid,u16 flags) { -struct net_port_vlan *pve; +struct net_port_vlan *pve =NULL ;struct net_bridge_vlan *vlan;struct net_device *dev = p->dev;int err;@@ -275,11 +382,21 @@ int nbp_vlan_add(struct net_bridge_port *p, u16 vid, u16 flags)set_bit (p->port_no, vlan->port_bitmap);list_add_tail_rcu (&pve->list, &p->vlan_list); + +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) { + err =nbp_vlan_add_untagged (p, vlan, flags); +if (err) + goto del_vlan; + } +return 0 ; clean_up:kfree (pve); -br_vlan_del (vlan, flags); +br_vlan_del (p->br, vlan, flags); +return err; +del_vlan: +nbp_vlan_delete (p, vid, flags);return err; }@@ -296,6 +413,9 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)if (!pve)return -ENOENT ; +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) +nbp_vlan_delete_untagged (p, pve->vlan); +/* Remove VLAN from the device filter if it is supported. */ if ((dev->features &NETIF_F_HW_VLAN_FILTER ) && dev->netdev_ops->ndo_vlan_rx_kill_vid) {@@ -306,6 +426,7 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)pr_warn ("failed to kill vid %d for device %s\n" , vid, dev->name); } + pve->vid =BR_INVALID_VID ; vlan = pve->vlan;@@ -316,7 +437,7 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)list_del_rcu (&pve->list);kfree_rcu (pve, rcu); -br_vlan_del (vlan, flags); +br_vlan_del (p->br, vlan, flags);return 0 ; }@@ -328,8 +449,11 @@ static void nbp_vlan_flush(struct net_bridge_port *p)ASSERT_RTNL (); -list_for_each_entry_safe (pve, tmp, &p->vlan_list, list) -nbp_vlan_delete (p, pve->vid,BRIDGE_FLAGS_SELF ); +list_for_each_entry_safe (pve, tmp, &p->vlan_list, list) { +nbp_vlan_delete (p, pve->vid, + (BRIDGE_VLAN_INFO_MASTER | +BRIDGE_VLAN_INFO_UNTAGGED )); + } }static void release_nbp (struct kobject *kobj)net/bridge/br_netlink.c +4
-2@@ -199,7 +199,8 @@ static int br_afspec(struct net_bridge *br, struct net_bridge_port *p,if (p) err =nbp_vlan_add (p, vinfo->vid, vinfo->flags);else { -u16 flags = vinfo->flags |BRIDGE_FLAGS_SELF ; +u16 flags = vinfo->flags | +BRIDGE_VLAN_INFO_MASTER ;if (!br_vlan_add (br, vinfo->vid, flags)) err = -ENOMEM ; }@@ -210,7 +211,8 @@ static int br_afspec(struct net_bridge *br, struct net_bridge_port *p, err =nbp_vlan_delete (p, vinfo->vid, vinfo->flags); else { -u16 flags = vinfo->flags |BRIDGE_FLAGS_SELF ; +u16 flags = vinfo->flags | +BRIDGE_VLAN_INFO_MASTER ; err =br_vlan_delete (br, vinfo->vid, flags); }break ;net/bridge/br_private.h +2
-1@@ -179,6 +179,7 @@ struct net_bridge_portstruct netpoll *np;#endif struct list_head vlan_list; +struct net_bridge_vlan __rcu *untagged; };#define br_port_exists (dev) (dev->priv_flags & IFF_BRIDGE_PORT)@@ -298,6 +299,7 @@ struct net_bridgestruct timer_list gc_timer;struct kobject *ifobj;struct hlist_head vlan_hlist[BR_VID_HASH_SIZE ]; +struct net_bridge_vlan __rcu *untagged; };struct br_input_skb_cb { --1.7.7.6
Re: [PATCH V2 09/12] bridge: Add the ability to configure untagged vlans
In reply to Vlad YasevichQuoted 113 lines · Vlad Yasevich
A user may designate a certain vlan as untagged. This means that any ingress frame is assigned to this vlan and any forwarding decisions are made with this vlan in mind. On egress, any frames tagged/labeled with untagged vlan have the vlan tag removed and are send as regular ethernet frames.
Signed-off-by Vlad Yasevich <[email protected]>--- include/uapi/linux/if_bridge.h | 3 + net/bridge/br_if.c | 146 +++++++++++++++++++++++++++++++++++++--- net/bridge/br_netlink.c | 6 +- net/bridge/br_private.h | 2 + 4 files changed, 144 insertions(+), 13 deletions(-)include/uapi/linux/if_bridge.h +3
-0@@ -127,6 +127,9 @@ enum { BR_VLAN_DEL, }; +#define BRIDGE_VLAN_INFO_MASTER 1 +#define BRIDGE_VLAN_INFO_UNTAGGED 2 +struct bridge_vlan_info {u16 op_code;u16 flags;net/bridge/br_if.c +41
-4@@ -108,6 +108,34 @@ static void br_vlan_put(struct net_bridge_vlan *vlan)br_vlan_destroy (vlan); } +/* Must be protected by RTNL */ +static void br_vlan_add_untagged (struct net_bridge *br, +struct net_bridge_vlan *vlan) +{ +ASSERT_RTNL (); +if (br->untagged == vlan) +return ; +else if (br->untagged) { +/* Untagged vlan is already set on the master, +* so drop the ref since we'll be replacing it. +*/ +br_vlan_put (br->untagged); + } +br_vlan_hold (vlan); +rcu_assign_pointer (br->untagged, vlan); +} + +/* Must be protected by RTNL */ +static void br_vlan_del_untagged (struct net_bridge *br, +struct net_bridge_vlan *vlan) +{ +ASSERT_RTNL (); +if (br->untagged == vlan) { +br_vlan_put (vlan); +rcu_assign_pointer (br->untagged,NULL ); + } +} +struct net_bridge_vlan *br_vlan_find (struct net_bridge *br,u16 vid) {struct net_bridge_vlan *vlan;@@ -132,7 +160,7 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid, vlan =br_vlan_find (br, vid);if (vlan) -return vlan; + goto untagged; vlan =kzalloc (sizeof (struct net_bridge_vlan ),GFP_KERNEL );if (!vlan)@@ -141,7 +169,7 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid, vlan->vid = vid;atomic_set (&vlan->refcnt,1 ); -if (flags &BRIDGE_FLAGS_SELF ) { +if (flags &BRIDGE_VLAN_INFO_MASTER ) {/* Set bit 0 that is associated with the bridge master * device. Port numbers start with 1. */ @@ -149,15 +177,24 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid, }hlist_add_head_rcu (&vlan->hlist, &br->vlan_hlist[br_vlan_hash (vid)]); + +untagged: +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) +br_vlan_add_untagged (br, vlan); +return vlan; }/* Must be protected by RTNL */ -static void br_vlan_del (struct net_bridge_vlan *vlan,u16 flags) +static void br_vlan_del (struct net_bridge *br,struct net_bridge_vlan *vlan, +u16 flags) {ASSERT_RTNL (); -if (flags &BRIDGE_FLAGS_SELF ) { +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) +br_vlan_del_untagged (br, vlan); + +if (flags &BRIDGE_VLAN_INFO_MASTER ) {/* Clear bit 0 that is associated with the bridge master * device. */
net/bridge/br_if.c static void br_vlan_del(struct net_bridge_vlan *vlan, u16 flags) · line 217
Quoted 9 lines
net/bridge/br_if.c +6
-0@@ -172,6 +209,14 @@ static void br_vlan_del(struct net_bridge_vlan *vlan, u16 flags) vlan->vid =BR_INVALID_VID ; +/* If, for whatever reason, bridge still has a ref on this vlan +* through the @untagged pointer, drop that ref and clear untagged. +*/ +if (br->untagged == vlan) { +br_vlan_put (vlan); +rcu_assign_pointer (br->untagged,NULL );
Is something doing an rcu sync after this point?
If yes maybe add a comment saying where it is, if not - some rcu read side could still be using it through this pointer.
Quoted 207 lines
net/bridge/br_if.c +88
-7+ } +/* Drop the self-ref to trigger descrution. */ br_vlan_put (vlan); }@@ -187,7 +232,7 @@ int br_vlan_delete(struct net_bridge *br, u16 vid, u16 flags)if (!vlan)return -ENOENT ; -br_vlan_del (vlan, flags); +br_vlan_del (br, vlan, flags);return 0 ; }@@ -204,7 +249,9 @@ static void br_vlan_flush(struct net_bridge *br)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,BRIDGE_FLAGS_SELF ); +br_vlan_del (br, vlan, + (BRIDGE_VLAN_INFO_MASTER | +BRIDGE_VLAN_INFO_UNTAGGED )); } } }@@ -224,10 +271,70 @@ struct net_port_vlan *nbp_vlan_find(const struct net_bridge_port *p, u16 vid)return NULL ; } +static int nbp_vlan_add_untagged (struct net_bridge_port *p, +struct net_bridge_vlan *vlan, +u16 flags) +{ +struct net_device *dev = p->dev; + +if (p->untagged) { +/* Port already has untagged vlan set. Drop the ref +* to the old one since we'll be replace it. +*/ +br_vlan_put (p->untagged); + }else { +int err; + +/* Add vid 0 to filter if filter is available. */ +if ((dev->features &NETIF_F_HW_VLAN_FILTER ) && + dev->netdev_ops->ndo_vlan_rx_add_vid && + dev->netdev_ops->ndo_vlan_rx_kill_vid) { + err = dev->netdev_ops->ndo_vlan_rx_add_vid (dev,0 ); +if (err) +return err; + } + } + +/* This VLAN is handled as untagged/native. Save an +* additional ref. +*/ +br_vlan_hold (vlan); +rcu_assign_pointer (p->untagged, vlan); + +return 0 ; +} + +static void nbp_vlan_delete_untagged (struct net_bridge_port *p, +struct net_bridge_vlan *vlan) +{ +if (p->untagged != vlan) +return ; + +/* Remove VLAN from the device filter if it is supported. */ +if ((p->dev->features &NETIF_F_HW_VLAN_FILTER ) && + p->dev->netdev_ops->ndo_vlan_rx_kill_vid) { +int err; + + err = p->dev->netdev_ops->ndo_vlan_rx_kill_vid (p->dev,0 ); +if (err) { +pr_warn ("failed to kill vid %d for device %s\n" , + vlan->vid, p->dev->name); + } + } + +/* If this VLAN is currently functioning as untagged, clear it. +* It's safe to drop the refcount, since the vlan is still held +* by the port. +*/ +br_vlan_put (vlan); +rcu_assign_pointer (p->untagged,NULL ); + +} +/* Must be protected by RTNL */ int nbp_vlan_add (struct net_bridge_port *p,u16 vid,u16 flags) { -struct net_port_vlan *pve; +struct net_port_vlan *pve =NULL ;struct net_bridge_vlan *vlan;struct net_device *dev = p->dev;int err;@@ -275,11 +382,21 @@ int nbp_vlan_add(struct net_bridge_port *p, u16 vid, u16 flags)set_bit (p->port_no, vlan->port_bitmap);list_add_tail_rcu (&pve->list, &p->vlan_list); + +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) { + err =nbp_vlan_add_untagged (p, vlan, flags); +if (err) + goto del_vlan; + } +return 0 ; clean_up:kfree (pve); -br_vlan_del (vlan, flags); +br_vlan_del (p->br, vlan, flags); +return err; +del_vlan: +nbp_vlan_delete (p, vid, flags);return err; }@@ -296,6 +413,9 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)if (!pve)return -ENOENT ; +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) +nbp_vlan_delete_untagged (p, pve->vlan); +/* Remove VLAN from the device filter if it is supported. */ if ((dev->features &NETIF_F_HW_VLAN_FILTER ) && dev->netdev_ops->ndo_vlan_rx_kill_vid) {@@ -306,6 +426,7 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)pr_warn ("failed to kill vid %d for device %s\n" , vid, dev->name); } + pve->vid =BR_INVALID_VID ; vlan = pve->vlan;@@ -316,7 +437,7 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)list_del_rcu (&pve->list);kfree_rcu (pve, rcu); -br_vlan_del (vlan, flags); +br_vlan_del (p->br, vlan, flags);return 0 ; }@@ -328,8 +449,11 @@ static void nbp_vlan_flush(struct net_bridge_port *p)ASSERT_RTNL (); -list_for_each_entry_safe (pve, tmp, &p->vlan_list, list) -nbp_vlan_delete (p, pve->vid,BRIDGE_FLAGS_SELF ); +list_for_each_entry_safe (pve, tmp, &p->vlan_list, list) { +nbp_vlan_delete (p, pve->vid, + (BRIDGE_VLAN_INFO_MASTER | +BRIDGE_VLAN_INFO_UNTAGGED )); + } }static void release_nbp (struct kobject *kobj)net/bridge/br_netlink.c +4
-2@@ -199,7 +199,8 @@ static int br_afspec(struct net_bridge *br, struct net_bridge_port *p,if (p) err =nbp_vlan_add (p, vinfo->vid, vinfo->flags);else { -u16 flags = vinfo->flags |BRIDGE_FLAGS_SELF ; +u16 flags = vinfo->flags | +BRIDGE_VLAN_INFO_MASTER ;if (!br_vlan_add (br, vinfo->vid, flags)) err = -ENOMEM ; }@@ -210,7 +211,8 @@ static int br_afspec(struct net_bridge *br, struct net_bridge_port *p, err =nbp_vlan_delete (p, vinfo->vid, vinfo->flags); else { -u16 flags = vinfo->flags |BRIDGE_FLAGS_SELF ; +u16 flags = vinfo->flags | +BRIDGE_VLAN_INFO_MASTER ; err =br_vlan_delete (br, vinfo->vid, flags); }break ;net/bridge/br_private.h +2
-0@@ -179,6 +179,7 @@ struct net_bridge_portstruct netpoll *np;#endif struct list_head vlan_list; +struct net_bridge_vlan __rcu *untagged; };#define br_port_exists (dev) (dev->priv_flags & IFF_BRIDGE_PORT)@@ -298,6 +299,7 @@ struct net_bridgestruct timer_list gc_timer;struct kobject *ifobj;struct hlist_head vlan_hlist[BR_VID_HASH_SIZE ]; +struct net_bridge_vlan __rcu *untagged; };struct br_input_skb_cb {Signature · 1 line
1.7.7.6
Re: [PATCH V2 09/12] bridge: Add the ability to configure untagged vlans
Quoted 117 lines · Michael S. Tsirkin
Quoted 116 lines · Vlad Yasevich
A user may designate a certain vlan as untagged. This means that any ingress frame is assigned to this vlan and any forwarding decisions are made with this vlan in mind. On egress, any frames tagged/labeled with untagged vlan have the vlan tag removed and are send as regular ethernet frames.
Signed-off-by Vlad Yasevich <[email protected]>--- include/uapi/linux/if_bridge.h | 3 + net/bridge/br_if.c | 146 +++++++++++++++++++++++++++++++++++++--- net/bridge/br_netlink.c | 6 +- net/bridge/br_private.h | 2 + 4 files changed, 144 insertions(+), 13 deletions(-)include/uapi/linux/if_bridge.h +3
-0@@ -127,6 +127,9 @@ enum { BR_VLAN_DEL, }; +#define BRIDGE_VLAN_INFO_MASTER 1 +#define BRIDGE_VLAN_INFO_UNTAGGED 2 +struct bridge_vlan_info {u16 op_code;u16 flags;net/bridge/br_if.c +41
-4@@ -108,6 +108,34 @@ static void br_vlan_put(struct net_bridge_vlan *vlan)br_vlan_destroy (vlan); } +/* Must be protected by RTNL */ +static void br_vlan_add_untagged (struct net_bridge *br, +struct net_bridge_vlan *vlan) +{ +ASSERT_RTNL (); +if (br->untagged == vlan) +return ; +else if (br->untagged) { +/* Untagged vlan is already set on the master, +* so drop the ref since we'll be replacing it. +*/ +br_vlan_put (br->untagged); + } +br_vlan_hold (vlan); +rcu_assign_pointer (br->untagged, vlan); +} + +/* Must be protected by RTNL */ +static void br_vlan_del_untagged (struct net_bridge *br, +struct net_bridge_vlan *vlan) +{ +ASSERT_RTNL (); +if (br->untagged == vlan) { +br_vlan_put (vlan); +rcu_assign_pointer (br->untagged,NULL ); + } +} +struct net_bridge_vlan *br_vlan_find (struct net_bridge *br,u16 vid) {struct net_bridge_vlan *vlan;@@ -132,7 +160,7 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid, vlan =br_vlan_find (br, vid);if (vlan) -return vlan; + goto untagged; vlan =kzalloc (sizeof (struct net_bridge_vlan ),GFP_KERNEL );if (!vlan)@@ -141,7 +169,7 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid, vlan->vid = vid;atomic_set (&vlan->refcnt,1 ); -if (flags &BRIDGE_FLAGS_SELF ) { +if (flags &BRIDGE_VLAN_INFO_MASTER ) {/* Set bit 0 that is associated with the bridge master * device. Port numbers start with 1. */ @@ -149,15 +177,24 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid, }hlist_add_head_rcu (&vlan->hlist, &br->vlan_hlist[br_vlan_hash (vid)]); + +untagged: +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) +br_vlan_add_untagged (br, vlan); +return vlan; }/* Must be protected by RTNL */ -static void br_vlan_del (struct net_bridge_vlan *vlan,u16 flags) +static void br_vlan_del (struct net_bridge *br,struct net_bridge_vlan *vlan, +u16 flags) {ASSERT_RTNL (); -if (flags &BRIDGE_FLAGS_SELF ) { +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) +br_vlan_del_untagged (br, vlan); + +if (flags &BRIDGE_VLAN_INFO_MASTER ) {/* Clear bit 0 that is associated with the bridge master * device. */ @@ -172,6 +209,14 @@ static void br_vlan_del(struct net_bridge_vlan *vlan, u16 flags) vlan->vid =BR_INVALID_VID ;
Quoted 10 lines
net/bridge/br_if.c static void br_vlan_del(struct net_bridge_vlan *vlan, u16 flags) · line 217
Quoted 6 lines
net/bridge/br_if.c +6
-0+/* If, for whatever reason, bridge still has a ref on this vlan +* through the @untagged pointer, drop that ref and clear untagged. +*/ +if (br->untagged == vlan) { +br_vlan_put (vlan); +rcu_assign_pointer (br->untagged,NULL );Is something doing an rcu sync after this point?
If yes maybe add a comment saying where it is, if not - some rcu read side could still be using it through this pointer.
yes, at this point, all references from the ports have been dropped and we are trying to destroy the element. The put below will trigger the destruction path which will do kfree_rcu(). Thus there is a grace period...
-vlad
Quoted 213 lines
Quoted 207 lines
net/bridge/br_if.c +88
-7+ } +/* Drop the self-ref to trigger descrution. */ br_vlan_put (vlan); }@@ -187,7 +232,7 @@ int br_vlan_delete(struct net_bridge *br, u16 vid, u16 flags)if (!vlan)return -ENOENT ; -br_vlan_del (vlan, flags); +br_vlan_del (br, vlan, flags);return 0 ; }@@ -204,7 +249,9 @@ static void br_vlan_flush(struct net_bridge *br)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,BRIDGE_FLAGS_SELF ); +br_vlan_del (br, vlan, + (BRIDGE_VLAN_INFO_MASTER | +BRIDGE_VLAN_INFO_UNTAGGED )); } } }@@ -224,10 +271,70 @@ struct net_port_vlan *nbp_vlan_find(const struct net_bridge_port *p, u16 vid)return NULL ; } +static int nbp_vlan_add_untagged (struct net_bridge_port *p, +struct net_bridge_vlan *vlan, +u16 flags) +{ +struct net_device *dev = p->dev; + +if (p->untagged) { +/* Port already has untagged vlan set. Drop the ref +* to the old one since we'll be replace it. +*/ +br_vlan_put (p->untagged); + }else { +int err; + +/* Add vid 0 to filter if filter is available. */ +if ((dev->features &NETIF_F_HW_VLAN_FILTER ) && + dev->netdev_ops->ndo_vlan_rx_add_vid && + dev->netdev_ops->ndo_vlan_rx_kill_vid) { + err = dev->netdev_ops->ndo_vlan_rx_add_vid (dev,0 ); +if (err) +return err; + } + } + +/* This VLAN is handled as untagged/native. Save an +* additional ref. +*/ +br_vlan_hold (vlan); +rcu_assign_pointer (p->untagged, vlan); + +return 0 ; +} + +static void nbp_vlan_delete_untagged (struct net_bridge_port *p, +struct net_bridge_vlan *vlan) +{ +if (p->untagged != vlan) +return ; + +/* Remove VLAN from the device filter if it is supported. */ +if ((p->dev->features &NETIF_F_HW_VLAN_FILTER ) && + p->dev->netdev_ops->ndo_vlan_rx_kill_vid) { +int err; + + err = p->dev->netdev_ops->ndo_vlan_rx_kill_vid (p->dev,0 ); +if (err) { +pr_warn ("failed to kill vid %d for device %s\n" , + vlan->vid, p->dev->name); + } + } + +/* If this VLAN is currently functioning as untagged, clear it. +* It's safe to drop the refcount, since the vlan is still held +* by the port. +*/ +br_vlan_put (vlan); +rcu_assign_pointer (p->untagged,NULL ); + +} +/* Must be protected by RTNL */ int nbp_vlan_add (struct net_bridge_port *p,u16 vid,u16 flags) { -struct net_port_vlan *pve; +struct net_port_vlan *pve =NULL ;struct net_bridge_vlan *vlan;struct net_device *dev = p->dev;int err;@@ -275,11 +382,21 @@ int nbp_vlan_add(struct net_bridge_port *p, u16 vid, u16 flags)set_bit (p->port_no, vlan->port_bitmap);list_add_tail_rcu (&pve->list, &p->vlan_list); + +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) { + err =nbp_vlan_add_untagged (p, vlan, flags); +if (err) + goto del_vlan; + } +return 0 ; clean_up:kfree (pve); -br_vlan_del (vlan, flags); +br_vlan_del (p->br, vlan, flags); +return err; +del_vlan: +nbp_vlan_delete (p, vid, flags);return err; }@@ -296,6 +413,9 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)if (!pve)return -ENOENT ; +if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) +nbp_vlan_delete_untagged (p, pve->vlan); +/* Remove VLAN from the device filter if it is supported. */ if ((dev->features &NETIF_F_HW_VLAN_FILTER ) && dev->netdev_ops->ndo_vlan_rx_kill_vid) {@@ -306,6 +426,7 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)pr_warn ("failed to kill vid %d for device %s\n" , vid, dev->name); } + pve->vid =BR_INVALID_VID ; vlan = pve->vlan;@@ -316,7 +437,7 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)list_del_rcu (&pve->list);kfree_rcu (pve, rcu); -br_vlan_del (vlan, flags); +br_vlan_del (p->br, vlan, flags);return 0 ; }@@ -328,8 +449,11 @@ static void nbp_vlan_flush(struct net_bridge_port *p)ASSERT_RTNL (); -list_for_each_entry_safe (pve, tmp, &p->vlan_list, list) -nbp_vlan_delete (p, pve->vid,BRIDGE_FLAGS_SELF ); +list_for_each_entry_safe (pve, tmp, &p->vlan_list, list) { +nbp_vlan_delete (p, pve->vid, + (BRIDGE_VLAN_INFO_MASTER | +BRIDGE_VLAN_INFO_UNTAGGED )); + } }static void release_nbp (struct kobject *kobj)net/bridge/br_netlink.c +4
-2@@ -199,7 +199,8 @@ static int br_afspec(struct net_bridge *br, struct net_bridge_port *p,if (p) err =nbp_vlan_add (p, vinfo->vid, vinfo->flags);else { -u16 flags = vinfo->flags |BRIDGE_FLAGS_SELF ; +u16 flags = vinfo->flags | +BRIDGE_VLAN_INFO_MASTER ;if (!br_vlan_add (br, vinfo->vid, flags)) err = -ENOMEM ; }@@ -210,7 +211,8 @@ static int br_afspec(struct net_bridge *br, struct net_bridge_port *p, err =nbp_vlan_delete (p, vinfo->vid, vinfo->flags); else { -u16 flags = vinfo->flags |BRIDGE_FLAGS_SELF ; +u16 flags = vinfo->flags | +BRIDGE_VLAN_INFO_MASTER ; err =br_vlan_delete (br, vinfo->vid, flags); }break ;net/bridge/br_private.h +2
-1@@ -179,6 +179,7 @@ struct net_bridge_portstruct netpoll *np;#endif struct list_head vlan_list; +struct net_bridge_vlan __rcu *untagged; };#define br_port_exists (dev) (dev->priv_flags & IFF_BRIDGE_PORT)@@ -298,6 +299,7 @@ struct net_bridgestruct timer_list gc_timer;struct kobject *ifobj;struct hlist_head vlan_hlist[BR_VID_HASH_SIZE ]; +struct net_bridge_vlan __rcu *untagged; };struct br_input_skb_cb { --Quoted 1 line
1.7.7.6
--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 10/12 bridge: Implement untagged vlan handling
In reply to Vlad YasevichWhen an untagged frame arrives on a port that has untagged vlan set, the frame is assigned to the untagged VLAN. It will then procede through the forwarding/egress process with the VLAN id set to the untagged VLAN.
At egress, a frame with a VLAN id matching untagged vid will have its vlan header stripped off.
--- net/bridge/br_device.c | 25 +++++++- net/bridge/br_forward.c | 134 ++++++++++++++++++++++++++++++++++++++++++++- net/bridge/br_input.c | 46 ++++++++++++--- net/bridge/br_multicast.c | 37 +++++++----- net/bridge/br_private.h | 20 ++++-- 5 files changed, 224 insertions(+), 38 deletions(-)
net/bridge/br_device.c +21 -4
@@ -31,7 +31,8 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)struct net_bridge_mdb_entry *mdst;struct br_cpu_netstats *brstats =this_cpu_ptr (br->stats);struct net_bridge_vlan *vlan; -u16 vid; +struct br_input_skb_cb *brcb; +u16 vid =0 ;rcu_read_lock ();#ifdef CONFIG_BRIDGE_NETFILTER
@@ -47,15 +48,31 @@ 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); -BR_INPUT_SKB_CB (skb)->brdev = dev; + brcb =BR_INPUT_SKB_CB (skb); +memset (brcb,0 ,sizeof (struct br_input_skb_cb )); + brcb->brdev = dev; + +if (br_get_vlan (skb, &vid)) { +u16 untagged_vid; + +/* Untagged frame. See if there is an untagged VLAN +* configured. +*/ +if ((vlan =rcu_dereference (br->untagged)) !=NULL && + (untagged_vid = vlan->vid) !=BR_INVALID_VID ) { +__vlan_hwaccel_put_tag (skb, untagged_vid); + brcb->untagged =1 ; + goto skip_lookup; + } + }/* Any vlan transmitted by the bridge itself is permitted. * Try to cache the vlan in the CB to speed up forwarding. */ - vid =br_get_vlan (skb); vlan =br_vlan_find (br, vid); +skip_lookup:if (vlan) -BR_INPUT_SKB_CB (skb)->vlan = vlan; + brcb->vlan = vlan;skb_reset_mac_header (skb);skb_pull (skb,ETH_HLEN );
net/bridge/br_forward.c +131 -3
164 lines not on this page · raw message
net/bridge/br_input.c +37 -9
89 lines not on this page · raw message
net/bridge/br_multicast.c +22 -15
@@ -905,6 +905,7 @@ 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 ;
@@ -940,8 +941,8 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br,continue ; } - err =br_ip4_multicast_add_group (br, port, group, -br_get_vlan (skb)); +br_get_vlan (skb, &vid); + err =br_ip4_multicast_add_group (br, port, group, vid);if (err)break ; }
@@ -960,6 +961,7 @@ 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 ;
@@ -1001,8 +1003,9 @@ static int br_ip6_multicast_mld2_report(struct net_bridge *br,continue ; } +br_get_vlan (skb, &vid); err =br_ip6_multicast_add_group (br, port, &grec->grec_mca, -br_get_vlan (skb)); + vid);if (!err)break ; }
@@ -1086,6 +1089,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) ||
@@ -1120,8 +1124,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)); +br_get_vlan (skb, &vid); + mp =br_mdb_ip4_get (mlock_dereference (br->mdb, br), group, vid);if (!mp) goto out;
@@ -1162,6 +1166,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) ||
@@ -1193,8 +1198,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)); +br_get_vlan (skb, &vid); + mp =br_mdb_ip6_get (mlock_dereference (br->mdb, br), group, vid);if (!mp) goto out;
@@ -1343,6 +1348,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)))
@@ -1410,8 +1416,8 @@ 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, -br_get_vlan (skb2)); + vid =br_get_vlan (skb2, &vid); + 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);
@@ -1420,8 +1426,8 @@ 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_get_vlan (skb2)); + vid =br_get_vlan (skb2, &vid); +br_ip4_multicast_leave_group (br, port, ih->group, vid);break ; }
@@ -1446,6 +1452,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 ;
@@ -1541,8 +1548,8 @@ 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, -br_get_vlan (skb2)); +br_get_vlan (skb2, &vid); + err =br_ip6_multicast_add_group (br, port, &mld->mld_mca, vid);break ; }case ICMPV6_MLD2_REPORT :
@@ -1559,8 +1566,8 @@ 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_get_vlan (skb2)); +br_get_vlan (skb2, &vid); +br_ip6_multicast_leave_group (br, port, &mld->mld_mca, vid); } }
net/bridge/br_private.h +13 -7
@@ -198,18 +198,20 @@ static inline struct net_bridge_port *br_port_get_rtnl(struct net_device *dev) rtnl_dereference(dev->rx_handler_data) : NULL; } -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; }struct br_cpu_netstats {
@@ -305,6 +307,7 @@ struct net_bridgestruct 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;
@@ -431,6 +434,9 @@ extern int br_forward_finish(struct sk_buff *skb);extern void br_flood_deliver (struct net_bridge *br,struct sk_buff *skb);extern void br_flood_forward (struct net_bridge *br,struct sk_buff *skb,struct sk_buff *skb2); +extern struct sk_buff *br_handle_vlan (const struct net_bridge *br, +const struct net_bridge_port *p, +struct sk_buff *skb);/* br_if.c */ extern void br_port_carrier_check (struct net_bridge_port *p);
Signature · 1 line
1.7.7.6
PATCH v2 11/12 bridge: Dump vlan information from a bridge port
In reply to Vlad YasevichUsing 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/if_bridge.h | 1 + include/uapi/linux/rtnetlink.h | 1 + net/bridge/br_if.c | 2 + net/bridge/br_netlink.c | 69 ++++++++++++++++++++++-- net/bridge/br_private.h | 3 +- net/core/rtnetlink.c | 16 ++++-- 8 files changed, 85 insertions(+), 13 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +2 -1
@@ -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
@@ -1008,7 +1008,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); };/*
include/uapi/linux/if_bridge.h +1 -0
@@ -115,6 +115,7 @@ enum {IFLA_BRIDGE_FLAGS ,IFLA_BRIDGE_MODE ,IFLA_BRIDGE_VLAN_INFO , +IFLA_BRIDGE_VLAN , __IFLA_BRIDGE_MAX, };#define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)
include/uapi/linux/rtnetlink.h +1 -0
@@ -624,6 +624,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_if.c +2 -0
@@ -382,6 +382,7 @@ int nbp_vlan_add(struct net_bridge_port *p, u16 vid, u16 flags)set_bit (p->port_no, vlan->port_bitmap);list_add_tail_rcu (&pve->list, &p->vlan_list); + p->num_vlans++;if (flags &BRIDGE_VLAN_INFO_UNTAGGED ) { err =nbp_vlan_add_untagged (p, vlan, flags);
@@ -435,6 +436,7 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags)br_vlan_put (vlan);list_del_rcu (&pve->list); + p->num_vlans--;kfree_rcu (pve, rcu);br_vlan_del (p->br, vlan, flags);
net/bridge/br_netlink.c +63 -6
115 lines not on this page · raw message
net/bridge/br_private.h +2 -1
@@ -178,6 +178,7 @@ struct net_bridge_port#ifdef CONFIG_NET_POLL_CONTROLLER struct netpoll *np;#endif +u16 num_vlans;struct list_head vlan_list;struct net_bridge_vlan __rcu *untagged; };
@@ -618,7 +619,7 @@ 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_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/core/rtnetlink.c +12 -4
@@ -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 (master && master->netdev_ops->ndo_bridge_getlink) {if (idx >= cb->args[0 ] && master->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 )) && master && master->netdev_ops->ndo_bridge_getlink) { - err = master->netdev_ops->ndo_bridge_getlink (skb,0 ,0 , dev); + err = master->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
PATCH v2 12/12 bridge: Add vlan support for local fdb entries
In reply to Vlad YasevichWhen 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 | 66 ++++++++++++++++++++++++++++++++++------------- net/bridge/br_if.c | 28 +++++++++++++++++++- net/bridge/br_private.h | 4 ++- 3 files changed, 78 insertions(+), 20 deletions(-)
net/bridge/br_fdb.c +48 -18
@@ -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_list);int i;spin_lock_bh (&br->hash_lock);
@@ -106,10 +107,12 @@ void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr)if (f->dst == p && f->is_local) {/* maybe another port has same hw addr? */ struct net_bridge_port *op; +u16 vid = f->vlan_id;list_for_each_entry (op, &br->port_list, list) {if (op != p &ðer_addr_equal (op->dev->dev_addr, - f->addr.addr)) { + f->addr.addr) && +nbp_vlan_find (op, vid)) { f->dst = op; goto insert; }
@@ -117,27 +120,55 @@ void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr)/* delete old one */ fdb_delete (br, f); - goto insert; +insert: +/* insert new address, may fail if invalid +* address or dup. +*/ +fdb_insert (br, p, newaddr, vid); + +/* if this port has no vlan information +* configured, we can safely be done at +* this point. +*/ +if (no_vlan) + goto done; } } } - insert: -/* insert new address, may fail if invalid address or dup. */ -fdb_insert (br, p, newaddr); +done:spin_unlock_bh (&br->hash_lock); }void br_fdb_change_mac_address (struct net_bridge *br,const u8 *newaddr) {struct net_bridge_fdb_entry *f; +struct net_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 +411,15 @@ static struct net_bridge_fdb_entry *fdb_create(struct hlist_head *head, }static int fdb_insert (struct net_bridge *br,struct net_bridge_port *source, -const unsigned char *addr) +const unsigned char *addr,u16 vid) { -struct hlist_head *head = &br->hash[br_mac_hash (addr,0 )]; +struct hlist_head *head = &br->hash[br_mac_hash (addr, vid)];struct net_bridge_fdb_entry *fdb;if (!is_valid_ether_addr (addr))return -EINVAL ; - fdb =fdb_find (head, addr,0 ); + fdb =fdb_find (head, addr, vid);if (fdb) {/* it is okay to have multiple ports with same * address, just use the first one.
@@ -401,7 +432,7 @@ static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,fdb_delete (br, fdb); } - fdb =fdb_create (head, source, addr,0 ); + fdb =fdb_create (head, source, addr, vid);if (!fdb)return -ENOMEM ;
@@ -412,12 +443,12 @@ static int fdb_insert(struct net_bridge *br, struct net_bridge_port *source,/* Add entry for local address of interface */ int br_fdb_insert (struct net_bridge *br,struct net_bridge_port *source, -const unsigned char *addr) +const unsigned char *addr,u16 vid) {int ret;spin_lock_bh (&br->hash_lock); - ret =fdb_insert (br, source, addr); + ret =fdb_insert (br, source, addr, vid);spin_unlock_bh (&br->hash_lock);return ret; }
@@ -710,10 +741,9 @@ out:return err; } -static int fdb_delete_by_addr (struct net_bridge_port *p,const u8 *addr, -u16 vlan) +int fdb_delete_by_addr (struct net_bridge *br,const u8 *addr, +u16 vlan) { -struct net_bridge *br = p->br;struct hlist_head *head = &br->hash[br_mac_hash (addr, vlan)];struct net_bridge_fdb_entry *fdb;
@@ -721,7 +751,7 @@ static int fdb_delete_by_addr(struct net_bridge_port *p, const u8 *addr,if (!fdb)return -ENOENT ; -fdb_delete (p->br, fdb); +fdb_delete (br, fdb);return 0 ; }
@@ -731,7 +761,7 @@ static int __br_fdb_delete(struct net_bridge_port *p,int err;spin_lock_bh (&p->br->hash_lock); - err =fdb_delete_by_addr (p, addr, vid); + err =fdb_delete_by_addr (p->br, addr, vid);spin_unlock_bh (&p->br->hash_lock);return err;
net/bridge/br_if.c +27 -1
@@ -178,6 +178,11 @@ struct net_bridge_vlan *br_vlan_add(struct net_bridge *br, u16 vid,hlist_add_head_rcu (&vlan->hlist, &br->vlan_hlist[br_vlan_hash (vid)]); +if (br_fdb_insert (br,NULL , br->dev->dev_addr, vid)) { +br_err (br, +"failed insert local address bridge forwarding table\n" ); + } + untagged:if (flags &BRIDGE_VLAN_INFO_UNTAGGED )br_vlan_add_untagged (br, vlan);
@@ -207,6 +212,12 @@ static void br_vlan_del(struct net_bridge *br, struct net_bridge_vlan *vlan,if (!bitmap_empty (vlan->port_bitmap,PORT_BITMAP_LEN ))return ; +if (vlan->vid) { +spin_lock_bh (&br->hash_lock); +fdb_delete_by_addr (br, br->dev->dev_addr, vlan->vid); +spin_unlock_bh (&br->hash_lock); + } + vlan->vid =BR_INVALID_VID ;/* If, for whatever reason, bridge still has a ref on this vlan
@@ -390,6 +401,12 @@ int nbp_vlan_add(struct net_bridge_port *p, u16 vid, u16 flags) goto del_vlan; } +if (br_fdb_insert (p->br, p, dev->dev_addr, vid)) { +br_err (p->br, +"failed insert local address bridge forwarding table\n" ); + goto del_vlan; + } +return 0 ; clean_up:
@@ -428,6 +445,15 @@ int nbp_vlan_delete(struct net_bridge_port *p, u16 vid, u16 flags) 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 (&p->br->hash_lock); +fdb_delete_by_addr (p->br, p->dev->dev_addr, vid); +spin_unlock_bh (&p->br->hash_lock); + } + pve->vid =BR_INVALID_VID ; vlan = pve->vlan;
@@ -773,7 +799,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
@@ -407,11 +407,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,
Signature · 1 line
1.7.7.6
I see that this patchset replicates a lot of code which is already present in net/8021q/ or include/linux/if_vlan.h. I think it would be nice to move this code into some "common" place, wouldn't it?
Jiri
Quoted 82 lines · Tue, Dec 18, 2012 at 08:00:51PM CET, [email protected] wrote:
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 may also be designated as untagged. Any untagged traffic recieved by the port will be assigned to this vlan. Any traffic exiting the port with a VID matching the untagged vlan will exit untagged (the bridge will strip the vlan header). This is similar to "Native Vlan" support available in most switches.
The default behavior ofthe bridge is unchanged if no vlans have been configured.
Changes since v1:
- Fixed some forwarding bugs.
- Add vlan to local fdb entries. New local entries are created per vlan to facilite correct forwarding to bridge interface.
- Allow configuration of vlans directly on the bridge master device in addition to ports.Changes since rfc v2:
- Per-port vlan bitmap is gone and is replaced with a vlan list.
- Added bridge vlan list, which is referenced by each port. Entries in the birdge vlan list have port bitmap that shows which port are parts of which vlan.
- Netlink API changes.
- Dropped sysfs support for now. If people think this is really usefull, can add it back.
- Support for native/untagged vlans.Changes since rfc v1:
- Comments addressed regarding formatting and RCU usage
- iocts have been removed and changed over the netlink interface.
- Added support of user added ndb entries.
- changed sysfs interface to export a bitmap. Also added a write interface. I am not sure how much I like it, but it made my testing easier/faster. I might change the write interface to take text instead of binary.Vlad Yasevich (12):
bridge: Add vlan filtering infrastructure
bridge: Validate that vlan is permitted on ingress
bridge: Verify that a vlan is allowed to egress on give port
bridge: Cache vlan in the cb for faster egress lookup.
bridge: Add vlan to unicast fdb entries
bridge: Add vlan id to multicast groups
bridge: Add netlink interface to configure vlans on bridge ports
bridge: Add vlan support to static neighbors
bridge: Add the ability to configure untagged vlans
bridge: Implement untagged vlan handling
bridge: Dump vlan information from a bridge port
bridge: Add vlan support for local fdb entriesdrivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 5 +- drivers/net/macvlan.c | 2 +- drivers/net/vxlan.c | 3 +- include/linux/netdevice.h | 4 +- include/uapi/linux/if_bridge.h | 23 ++- include/uapi/linux/neighbour.h | 1 + include/uapi/linux/rtnetlink.h | 1 + net/bridge/br_device.c | 34 ++- net/bridge/br_fdb.c | 253 ++++++++++++--- net/bridge/br_forward.c | 160 ++++++++++ net/bridge/br_if.c | 404 ++++++++++++++++++++++++- net/bridge/br_input.c | 65 ++++- net/bridge/br_multicast.c | 71 +++-- net/bridge/br_netlink.c | 178 ++++++++++-- net/bridge/br_private.h | 71 ++++- net/core/rtnetlink.c | 40 ++- 16 files changed, 1190 insertions(+), 125 deletions(-)Signature · 6 lines
1.7.7.6 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · Jiri Pirko
I see that this patchset replicates a lot of code which is already present in
net/8021q/orinclude/linux/if_vlan.h. I think it would be nice to move this code into some "common" place, wouldn't it?
The only replication that I am aware of is in br_vlan_untag(). I thought about pulling that piece out, but I think there is a reason why it's not available when 801q support isn't turned on. I noted that
openvswitch implemented its own vlan header manipulation functions as well.
What else are you seeing that's duplicate?
-vlad
Quoted 85 lines
Jiri
Quoted 82 lines · Tue, Dec 18, 2012 at 08:00:51PM CET, [email protected] wrote:
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 may also be designated as untagged. Any untagged traffic recieved by the port will be assigned to this vlan. Any traffic exiting the port with a VID matching the untagged vlan will exit untagged (the bridge will strip the vlan header). This is similar to "Native Vlan" support available in most switches.
The default behavior ofthe bridge is unchanged if no vlans have been configured.
Changes since v1:
- Fixed some forwarding bugs.
- Add vlan to local fdb entries. New local entries are created per vlan to facilite correct forwarding to bridge interface.
- Allow configuration of vlans directly on the bridge master device in addition to ports.Changes since rfc v2:
- Per-port vlan bitmap is gone and is replaced with a vlan list.
- Added bridge vlan list, which is referenced by each port. Entries in the birdge vlan list have port bitmap that shows which port are parts of which vlan.
- Netlink API changes.
- Dropped sysfs support for now. If people think this is really usefull, can add it back.
- Support for native/untagged vlans.Changes since rfc v1:
- Comments addressed regarding formatting and RCU usage
- iocts have been removed and changed over the netlink interface.
- Added support of user added ndb entries.
- changed sysfs interface to export a bitmap. Also added a write interface. I am not sure how much I like it, but it made my testing easier/faster. I might change the write interface to take text instead of binary.Vlad Yasevich (12):
bridge: Add vlan filtering infrastructure
bridge: Validate that vlan is permitted on ingress
bridge: Verify that a vlan is allowed to egress on give port
bridge: Cache vlan in the cb for faster egress lookup.
bridge: Add vlan to unicast fdb entries
bridge: Add vlan id to multicast groups
bridge: Add netlink interface to configure vlans on bridge ports
bridge: Add vlan support to static neighbors
bridge: Add the ability to configure untagged vlans
bridge: Implement untagged vlan handling
bridge: Dump vlan information from a bridge port
bridge: Add vlan support for local fdb entriesdrivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 5 +- drivers/net/macvlan.c | 2 +- drivers/net/vxlan.c | 3 +- include/linux/netdevice.h | 4 +- include/uapi/linux/if_bridge.h | 23 ++- include/uapi/linux/neighbour.h | 1 + include/uapi/linux/rtnetlink.h | 1 + net/bridge/br_device.c | 34 ++- net/bridge/br_fdb.c | 253 ++++++++++++--- net/bridge/br_forward.c | 160 ++++++++++ net/bridge/br_if.c | 404 ++++++++++++++++++++++++- net/bridge/br_input.c | 65 ++++- net/bridge/br_multicast.c | 71 +++-- net/bridge/br_netlink.c | 178 ++++++++++-- net/bridge/br_private.h | 71 ++++- net/core/rtnetlink.c | 40 ++- 16 files changed, 1190 insertions(+), 125 deletions(-)--
1.7.7.6--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Tue, Dec 18, 2012 at 11:46:21PM CET, [email protected] wrote:
Quoted 6 lines · Jiri Pirko
I see that this patchset replicates a lot of code which is already present in
net/8021q/orinclude/linux/if_vlan.h. I think it would be nice to move this code into some "common" place, wouldn't it?
Quoted 4 lines
The only replication that I am aware of is in
br_vlan_untag(). I thought about pulling that piece out, but I think there is a reason why it's not available when 801q support isn't turned on. I noted that openvswitch implemented its own vlan header manipulation functions as well.
openvswitch should use the "common" code as well.
Quoted 2 lines
What else are you seeing that's duplicate?
For example I spotted check of ndo_vlan_rx_[add/kill]_vid and NETIF_F_HW_VLAN_FILTER and ndo_vlan_rx_[add/kill]_vid call
Quoted 89 lines
-vlad
Quoted 85 lines
Jiri
Quoted 82 lines · Tue, Dec 18, 2012 at 08:00:51PM CET, [email protected] wrote:
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 may also be designated as untagged. Any untagged traffic recieved by the port will be assigned to this vlan. Any traffic exiting the port with a VID matching the untagged vlan will exit untagged (the bridge will strip the vlan header). This is similar to "Native Vlan" support available in most switches.
The default behavior ofthe bridge is unchanged if no vlans have been configured.
Changes since v1:
- Fixed some forwarding bugs.
- Add vlan to local fdb entries. New local entries are created per vlan to facilite correct forwarding to bridge interface.
- Allow configuration of vlans directly on the bridge master device in addition to ports.Changes since rfc v2:
- Per-port vlan bitmap is gone and is replaced with a vlan list.
- Added bridge vlan list, which is referenced by each port. Entries in the birdge vlan list have port bitmap that shows which port are parts of which vlan.
- Netlink API changes.
- Dropped sysfs support for now. If people think this is really usefull, can add it back.
- Support for native/untagged vlans.Changes since rfc v1:
- Comments addressed regarding formatting and RCU usage
- iocts have been removed and changed over the netlink interface.
- Added support of user added ndb entries.
- changed sysfs interface to export a bitmap. Also added a write interface. I am not sure how much I like it, but it made my testing easier/faster. I might change the write interface to take text instead of binary.Vlad Yasevich (12):
bridge: Add vlan filtering infrastructure
bridge: Validate that vlan is permitted on ingress
bridge: Verify that a vlan is allowed to egress on give port
bridge: Cache vlan in the cb for faster egress lookup.
bridge: Add vlan to unicast fdb entries
bridge: Add vlan id to multicast groups
bridge: Add netlink interface to configure vlans on bridge ports
bridge: Add vlan support to static neighbors
bridge: Add the ability to configure untagged vlans
bridge: Implement untagged vlan handling
bridge: Dump vlan information from a bridge port
bridge: Add vlan support for local fdb entriesdrivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 5 +- drivers/net/macvlan.c | 2 +- drivers/net/vxlan.c | 3 +- include/linux/netdevice.h | 4 +- include/uapi/linux/if_bridge.h | 23 ++- include/uapi/linux/neighbour.h | 1 + include/uapi/linux/rtnetlink.h | 1 + net/bridge/br_device.c | 34 ++- net/bridge/br_fdb.c | 253 ++++++++++++--- net/bridge/br_forward.c | 160 ++++++++++ net/bridge/br_if.c | 404 ++++++++++++++++++++++++- net/bridge/br_input.c | 65 ++++- net/bridge/br_multicast.c | 71 +++-- net/bridge/br_netlink.c | 178 ++++++++++-- net/bridge/br_private.h | 71 ++++- net/core/rtnetlink.c | 40 ++- 16 files changed, 1190 insertions(+), 125 deletions(-)--
1.7.7.6--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 14 lines · Jiri Pirko
Quoted 8 lines · Tue, Dec 18, 2012 at 11:46:21PM CET, [email protected] wrote:
Quoted 6 lines · Jiri Pirko
I see that this patchset replicates a lot of code which is already present in
net/8021q/orinclude/linux/if_vlan.h. I think it would be nice to move this code into some "common" place, wouldn't it?Quoted 4 lines
The only replication that I am aware of is in
br_vlan_untag(). I thought about pulling that piece out, but I think there is a reason why it's not available when 801q support isn't turned on. I noted that openvswitch implemented its own vlan header manipulation functions as well.
Quoted 7 lines
openvswitch should use the "common" code as well.
Quoted 2 lines
What else are you seeing that's duplicate?
For example I spotted check of ndo_vlan_rx_[add/kill]_vid and
NETIF_F_HW_VLAN_FILTERand ndo_vlan_rx_[add/kill]_vid call
Ahh yes.... I can make that generic. Thanks
-vlad
Quoted 96 lines
Quoted 91 lines
-vlad
Quoted 85 lines
Jiri
Quoted 82 lines · Tue, Dec 18, 2012 at 08:00:51PM CET, [email protected] wrote:
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 may also be designated as untagged. Any untagged traffic recieved by the port will be assigned to this vlan. Any traffic exiting the port with a VID matching the untagged vlan will exit untagged (the bridge will strip the vlan header). This is similar to "Native Vlan" support available in most switches.
The default behavior ofthe bridge is unchanged if no vlans have been configured.
Changes since v1:
- Fixed some forwarding bugs.
- Add vlan to local fdb entries. New local entries are created per vlan to facilite correct forwarding to bridge interface.
- Allow configuration of vlans directly on the bridge master device in addition to ports.Changes since rfc v2:
- Per-port vlan bitmap is gone and is replaced with a vlan list.
- Added bridge vlan list, which is referenced by each port. Entries in the birdge vlan list have port bitmap that shows which port are parts of which vlan.
- Netlink API changes.
- Dropped sysfs support for now. If people think this is really usefull, can add it back.
- Support for native/untagged vlans.Changes since rfc v1:
- Comments addressed regarding formatting and RCU usage
- iocts have been removed and changed over the netlink interface.
- Added support of user added ndb entries.
- changed sysfs interface to export a bitmap. Also added a write interface. I am not sure how much I like it, but it made my testing easier/faster. I might change the write interface to take text instead of binary.Vlad Yasevich (12):
bridge: Add vlan filtering infrastructure
bridge: Validate that vlan is permitted on ingress
bridge: Verify that a vlan is allowed to egress on give port
bridge: Cache vlan in the cb for faster egress lookup.
bridge: Add vlan to unicast fdb entries
bridge: Add vlan id to multicast groups
bridge: Add netlink interface to configure vlans on bridge ports
bridge: Add vlan support to static neighbors
bridge: Add the ability to configure untagged vlans
bridge: Implement untagged vlan handling
bridge: Dump vlan information from a bridge port
bridge: Add vlan support for local fdb entriesdrivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 5 +- drivers/net/macvlan.c | 2 +- drivers/net/vxlan.c | 3 +- include/linux/netdevice.h | 4 +- include/uapi/linux/if_bridge.h | 23 ++- include/uapi/linux/neighbour.h | 1 + include/uapi/linux/rtnetlink.h | 1 + net/bridge/br_device.c | 34 ++- net/bridge/br_fdb.c | 253 ++++++++++++--- net/bridge/br_forward.c | 160 ++++++++++ net/bridge/br_if.c | 404 ++++++++++++++++++++++++- net/bridge/br_input.c | 65 ++++- net/bridge/br_multicast.c | 71 +++-- net/bridge/br_netlink.c | 178 ++++++++++-- net/bridge/br_private.h | 71 ++++- net/core/rtnetlink.c | 40 ++- 16 files changed, 1190 insertions(+), 125 deletions(-)--
1.7.7.6--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Jiri Pirko
Quoted 8 lines · Tue, Dec 18, 2012 at 11:46:21PM CET, [email protected] wrote:
Quoted 6 lines · Jiri Pirko
I see that this patchset replicates a lot of code which is already present in
net/8021q/orinclude/linux/if_vlan.h. I think it would be nice to move this code into some "common" place, wouldn't it?
Quoted 6 lines
Quoted 4 lines
The only replication that I am aware of is in
br_vlan_untag(). I thought about pulling that piece out, but I think there is a reason why it's not available when 801q support isn't turned on. I noted that openvswitch implemented its own vlan header manipulation functions as well.openvswitch should use the "common" code as well.
I was just about to mention this. This overlaps with openvswitch in functionality which I have absoluetely no objections against but code reuse should come to focus in order to avoid having to fix bugs twice.
Quoted 15 lines · Thomas Graf
Quoted 14 lines · Jiri Pirko
Quoted 12 lines · Tue, Dec 18, 2012 at 11:46:21PM CET, [email protected] wrote:
Quoted 6 lines · Jiri Pirko
I see that this patchset replicates a lot of code which is already present in
net/8021q/orinclude/linux/if_vlan.h. I think it would be nice to move this code into some "common" place, wouldn't it?The only replication that I am aware of is in
br_vlan_untag(). I thought about pulling that piece out, but I think there is a reason why it's not available when 801q support isn't turned on. I noted that openvswitch implemented its own vlan header manipulation functions as well.
Quoted 7 lines
Quoted 1 line
openvswitch should use the "common" code as well.
I was just about to mention this. This overlaps with openvswitch in functionality which I have absoluetely no objections against but code reuse should come to focus in order to avoid having to fix bugs twice.
Could we consolidate the code after this is accepted and all the parties can agree on the consolidation? I'd really like to keep this series as minimally invasive as possible.
Thanks
-vlad
Quoted 24 lines · Wed, Dec 19, 2012 at 06:11:45PM CET, [email protected] wrote:
Quoted 15 lines · Thomas Graf
Quoted 14 lines · Jiri Pirko
Quoted 12 lines · Tue, Dec 18, 2012 at 11:46:21PM CET, [email protected] wrote:
Quoted 6 lines · Jiri Pirko
I see that this patchset replicates a lot of code which is already present in
net/8021q/orinclude/linux/if_vlan.h. I think it would be nice to move this code into some "common" place, wouldn't it?The only replication that I am aware of is in
br_vlan_untag(). I thought about pulling that piece out, but I think there is a reason why it's not available when 801q support isn't turned on. I noted that openvswitch implemented its own vlan header manipulation functions as well.Quoted 7 lines
Quoted 1 line
openvswitch should use the "common" code as well.
I was just about to mention this. This overlaps with openvswitch in functionality which I have absoluetely no objections against but code reuse should come to focus in order to avoid having to fix bugs twice.
Quoted 3 lines
Could we consolidate the code after this is accepted and all the parties can agree on the consolidation? I'd really like to keep this series as minimally invasive as possible.
That sounds good to me.
Quoted 3 lines
Thanks
-vlad
Quoted 3 lines · Vlad Yasevich
Could we consolidate the code after this is accepted and all the parties can agree on the consolidation? I'd really like to keep this series as minimally invasive as possible.
Sure, this was just a general remark on general future direction :)
Thanks Vlad,
Quoted 2 lines · On Tue, 18 Dec 2012 14:00:51 -0500 Vlad Yasevich <[email protected]> wrote:
A single vlan may also be designated as untagged. Any untagged traffic recieved by the port will be assigned to this vlan.
Why the "untagged vlan" is per-bridge global?
Usually, 802.1q switches define the PVID (port's VID) which controls the value of VID, in case ingress frame is either untagged or priority-tagged (per port configuration).
This gives greater flexibility.
Quoted 4 lines
Any traffic exiting
the port with a VID matching the untagged vlan will exit untagged (the bridge will strip the vlan header). This is similar to "Native Vlan" support available in most switches.
802.1q switches usually allow conifguring per-vlan, per-port tagged/untagged egress policy: each vid has its port membership map and an accompanying port egress-policy map.
This gives great flexibility defining all sorts of configurations.
Personally, I'd prefer a fully flexible vlan bridge allowing all sorts of configurations (as available in 802.1q switches).
What's the reason limiting such configurations?
Regards,
Shmulik
Quoted 11 lines · Shmulik Ladkani
Thanks Vlad,
Quoted 2 lines · On Tue, 18 Dec 2012 14:00:51 -0500 Vlad Yasevich <[email protected]> wrote:
A single vlan may also be designated as untagged. Any untagged traffic recieved by the port will be assigned to this vlan.
Why the "untagged vlan" is per-bridge global?
Usually, 802.1q switches define the PVID (port's VID) which controls the value of VID, in case ingress frame is either untagged or priority-tagged (per port configuration).
This gives greater flexibility.
It's not. There is a per port untagged pointer where you can designate which VLAN is untagged/native on a port. The bride interface itself can also function as a port, so it gets its own untagged pointer so
it can behave similar to port.
Quoted 10 lines
Quoted 5 lines
Any traffic exiting
the port with a VID matching the untagged vlan will exit untagged (the bridge will strip the vlan header). This is similar to "Native Vlan" support available in most switches.802.1q switches usually allow conifguring per-vlan, per-port tagged/untagged egress policy: each vid has its port membership map and an accompanying port egress-policy map.
This gives great flexibility defining all sorts of configurations.
Right, and that's what's provided here.
* Each VLAN has port membership map (net_bridge_vlan.portgroup).
* Each port has a list of vlans configured as well
(net_port_vlan.vlan_list).
* Each port also has a single vlan that can be untagged
(net_bridge_port.untagged).
* The bridge also has a single untagged vlan (net_bridge.untagged)
The limitation (in switches as well) is that only a single VLAN may be untagged on any 1 port. If you have more then 1, you don't know which VLAN the untagged traffic belongs to.
Quoted 5 lines
Personally, I'd prefer a fully flexible vlan bridge allowing all sorts of configurations (as available in 802.1q switches).
What's the reason limiting such configurations?
So, what do you see that's missing?
-vlad
Quoted 8 lines
Regards,
Shmulik
--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Vlad,
Quoted 3 lines · On Wed, 19 Dec 2012 09:13:10 -0500 Vlad Yasevich <[email protected]> wrote:
Quoted 1 line
Why the "untagged vlan" is per-bridge global?
It's not. There is a per port untagged pointer where you can designate which VLAN is untagged/native on a port.
Ok (misinterpreted the text in the cover letter).
Quoted 13 lines
Quoted 4 lines
802.1q switches usually allow conifguring per-vlan, per-port tagged/untagged egress policy: each vid has its port membership map and an accompanying port egress-policy map.
This gives great flexibility defining all sorts of configurations.Right, and that's what's provided here.
* Each VLAN has port membership map (net_bridge_vlan.portgroup).
* Each port has a list of vlans configured as well
(net_port_vlan.vlan_list).
* Each port also has a single vlan that can be untagged
(net_bridge_port.untagged).
* The bridge also has a single untagged vlan (net_bridge.untagged)
Quoted 2 lines
The limitation (in switches as well) is that only a single VLAN may be untagged on any 1 port.
Switches usually allow you to configure each port's egress policy per vlan, and allow you to configure multiple vlans to _egress_ untagged on a port.
Quoted 2 lines
If you have more then 1, you don't know
which VLAN the untagged traffic belongs to.
The port's PVID uniquely determines VID to associate with the frame during _ingress_ on that port - in the case frame arrived untagged.
This is unrelated to whether a frame having a specific VID would _egress_ tagged or untagged on that port.
Quoted 6 lines
Quoted 4 lines
Personally, I'd prefer a fully flexible vlan bridge allowing all sorts of configurations (as available in 802.1q switches).
What's the reason limiting such configurations?
So, what do you see that's missing?
I suspect some configurations wouldn't be possible at current design, please let me know what do you think.
Take for example such a configuration:
+---+---+ | | | p1 p2 p3
A bridge with 3 ports: p1 p2 p3.
(the bridge interface itself is irrelevant for this discussion)
This setup expects all traffic at those ports to be untagged.
I'd like p1 to be bridged to p2, but not to p3.
I'd like p3 to be bridged to p2, but not to p1.
Set the following:
p1 - PVID is 1
member of VLANs 1(egress untagged), 2(egress untagged)
p3 - PVID is 3
member of VLANs 3(egress untagged), 2(egress untagged)
p2 - PVID is 2
member of VLANs 1,2,3 (all egress untagged)
Or putting it differently:
VLAN 1 ports membership: p1, p2
egress policy: U U
VLAN 2 ports membership: p1, p2, p3
egress policy: U U U
VLAN 3 ports membership: p2, p3
egress policy: U U
Now, untagged traffic arriving at p1 will be assigned its PVID, which is 1, an thus forced to egress via p2 (the only other member of VLAN 1). Upon egress on p2, it will egress untagged.
(similarly for ingress in p3, only egress at p2 is possible, again
untagged).
If untagged traffic arrives at p2, it will be assigned its PVID, which is 2, and thus it may egress on either p1 or p3 (they are both members of VLAN 2).
Actual port of egress is according to FDB match.
Again egress would be untagged.
This setup might sound exotic, but similar patterns may be used in reality.
Although the example is synthetic and simplistic, still it demonstrates the vast flexibility allowed by a 802.1q bridge.
The bridge constructs needed for supporting such setups are:
- per port: PVID
- per VLAN: port membership map
- per VLAN: port egress policy map
I agree, tools other than a vlan bridge may implement such setups, but using the vlan bridge would be preferred, mainly due to the simplicity.
Regards,
Shmulik
Quoted 29 lines · Shmulik Ladkani
Hi Vlad,
Quoted 3 lines · On Wed, 19 Dec 2012 09:13:10 -0500 Vlad Yasevich <[email protected]> wrote:
Quoted 1 line
Why the "untagged vlan" is per-bridge global?
It's not. There is a per port untagged pointer where you can designate which VLAN is untagged/native on a port.
Ok (misinterpreted the text in the cover letter).
Quoted 13 lines
Quoted 4 lines
802.1q switches usually allow conifguring per-vlan, per-port tagged/untagged egress policy: each vid has its port membership map and an accompanying port egress-policy map.
This gives great flexibility defining all sorts of configurations.Right, and that's what's provided here.
* Each VLAN has port membership map (net_bridge_vlan.portgroup).
* Each port has a list of vlans configured as well
(net_port_vlan.vlan_list).
* Each port also has a single vlan that can be untagged
(net_bridge_port.untagged).
* The bridge also has a single untagged vlan (net_bridge.untagged)Quoted 2 lines
The limitation (in switches as well) is that only a single VLAN may be untagged on any 1 port.
Switches usually allow you to configure each port's egress policy per vlan, and allow you to configure multiple vlans to _egress_ untagged on a port.
Quoted 9 lines
Quoted 2 lines
If you have more then 1, you don't know
which VLAN the untagged traffic belongs to.The port's PVID uniquely determines VID to associate with the frame during _ingress_ on that port - in the case frame arrived untagged.
This is unrelated to whether a frame having a specific VID would _egress_ tagged or untagged on that port.
Ahh... I see what you mean. You would like to separate ingress policy and egress policy with regard to how tags are applied... I haven't seen that type of config before.
I did say "Basic VLAN support". :)
In this set of patches ingress and egress policies are hardcoded the same...
So, consider that what I am calling "untagged" in this series is
really vlan associated with PVID. To change the egress policy, we
could add an untagged bitmap into the vlan. Then the bitmap from the vlan would determine the egress policy. If the port is in the "tagged" bitmap, frame leaves tagged. If the port is in the "untagged" bitmap,
frame leaves untagged.
The code to make this would would be simple enough. The more interesting part would be the configuration :)
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
Personally, I'd prefer a fully flexible vlan bridge allowing all sorts of configurations (as available in 802.1q switches).
What's the reason limiting such configurations?
So, what do you see that's missing?
[ snip good example ]
Quoted 5 lines
The bridge constructs needed for supporting such setups are:
- per port: PVID
- per VLAN: port membership map
- per VLAN: port egress policy map
Ok, so from above, membership map is the exiting port_bitmap. Egress
policy map could be new untagged_bitmap. We wouldn't need a tagged policy map since a port can't be "in egress policy, but not in membership map".
Membership port_bitmap is consulted on egress for basic forward/drop decision (just as it is now). Egress policy (untagged bitmap) is consulted to see how the forwarding is done.
Sounds about right? If so, I could probably work something up. Will probably leave the configuration for later as that might take a bit longer to figure out.
-vlad
Quoted 7 lines
I agree, tools other than a vlan bridge may implement such setups, but using the vlan bridge would be preferred, mainly due to the simplicity.
Regards,
Shmulik
Quoted 58 lines · Vlad Yasevich
Quoted 30 lines · Shmulik Ladkani
Hi Vlad,
Quoted 3 lines · On Wed, 19 Dec 2012 09:13:10 -0500 Vlad Yasevich <[email protected]> wrote:
Quoted 1 line
Why the "untagged vlan" is per-bridge global?
It's not. There is a per port untagged pointer where you can designate which VLAN is untagged/native on a port.
Ok (misinterpreted the text in the cover letter).
Quoted 13 lines
Quoted 4 lines
802.1q switches usually allow conifguring per-vlan, per-port tagged/untagged egress policy: each vid has its port membership map and an accompanying port egress-policy map.
This gives great flexibility defining all sorts of configurations.Right, and that's what's provided here.
* Each VLAN has port membership map (net_bridge_vlan.portgroup).
* Each port has a list of vlans configured as well
(net_port_vlan.vlan_list).
* Each port also has a single vlan that can be untagged
(net_bridge_port.untagged).
* The bridge also has a single untagged vlan (net_bridge.untagged)Quoted 2 lines
The limitation (in switches as well) is that only a single VLAN may be untagged on any 1 port.
Switches usually allow you to configure each port's egress policy per vlan, and allow you to configure multiple vlans to _egress_ untagged on a port.
Quoted 9 lines
Quoted 2 lines
If you have more then 1, you don't know
which VLAN the untagged traffic belongs to.The port's PVID uniquely determines VID to associate with the frame during _ingress_ on that port - in the case frame arrived untagged.
This is unrelated to whether a frame having a specific VID would _egress_ tagged or untagged on that port.
Ahh... I see what you mean. You would like to separate ingress policy and egress policy with regard to how tags are applied... I haven't seen that type of config before.
I did say "Basic VLAN support". :)
In this set of patches ingress and egress policies are hardcoded the same...
So, consider that what I am calling "untagged" in this series is really vlan associated with PVID. To change the egress policy, we could add an untagged bitmap into the vlan. Then the bitmap from the vlan would determine the egress policy. If the port is in the "tagged" bitmap, frame leaves tagged. If the port is in the "untagged" bitmap, frame leaves untagged.
Quoted 2 lines
The code to make this would would be simple enough. The more interesting part would be the configuration :)
Actually, this looks much simpler then I originally thought. I think I might have something half-baked tomorrow.
-vlad
Quoted 41 lines
Quoted 9 lines
Quoted 8 lines
Quoted 6 lines
Personally, I'd prefer a fully flexible vlan bridge allowing all sorts of configurations (as available in 802.1q switches).
What's the reason limiting such configurations?
So, what do you see that's missing?
[ snip good example ]
Quoted 5 lines
The bridge constructs needed for supporting such setups are:
- per port: PVID
- per VLAN: port membership map
- per VLAN: port egress policy mapOk, so from above, membership map is the exiting
port_bitmap. Egress policy map could be newuntagged_bitmap. We wouldn't need a tagged policy map since a port can't be "in egress policy, but not in membership map".Membership
port_bitmapis consulted on egress for basic forward/drop decision (just as it is now). Egress policy (untagged bitmap) is consulted to see how the forwarding is done.Sounds about right? If so, I could probably work something up. Will probably leave the configuration for later as that might take a bit longer to figure out.
-vlad
Quoted 7 lines
I agree, tools other than a vlan bridge may implement such setups, but using the vlan bridge would be preferred, mainly due to the simplicity.
Regards,
Shmulik
Hi Vlad,
Quoted 8 lines · On Wed, 19 Dec 2012 15:03:36 -0500 Vlad Yasevich <[email protected]> wrote:
Quoted 5 lines
The port's PVID uniquely determines VID to associate with the frame during _ingress_ on that port - in the case frame arrived untagged.
This is unrelated to whether a frame having a specific VID would _egress_ tagged or untagged on that port.
Ahh... I see what you mean. You would like to separate ingress policy and egress policy with regard to how tags are applied...
Exactly.
Those are two different things; sometimes their configuration collide, sometimes not.
Quoted 6 lines
Quoted 4 lines
The bridge constructs needed for supporting such setups are:
- per port: PVID
- per VLAN: port membership map
- per VLAN: port egress policy mapOk, so from above, membership map is the exiting
port_bitmap.
Ok.
Quoted 3 lines
Egress policy map could be new
untagged_bitmap. We wouldn't need a tagged policy map since a port can't be "in egress policy, but not in membership map".
Yes, that is correct.
However I wouldn't call it "untagged_bitmap".
The name might suggest that "egress untagged" is an anomaly, where "normal" behavior is egress tagged.
But as said, both are valid, its just a matter of configuration.
You basically need one more bit for each member port, stating egress tagged/untagged.
Quoted 1 line
Sounds about right? If so, I could probably work something up.
Yes, looking forward to review the code.
P.S.
Sorry for late spotting this; I don't follow net-dev regularly. I hope to take a look at the code soon, see if I have any meaningful comments.
Regards,
Shmulik