net 00/06: add GARP/GVRP support
Subsystems (3)
These patches add an implementation of the GARP (Generic Attribute Registration Protocol) applicant-only participant, which can be used to dynamically register VLANs and multicast addresses with switches. Applicant-only means it can only be used as a client, not on a bridge. Also included is a GVRP (GARP VLAN Registration Protocol) application on top.
I asked on opinions whether this should be merged a couple of weeks ago, and Pekka Savola informed me that GARP was considered obsolete by the IEEE. However, especially GVRP is supported by a huge number of switches, even very cheap ones, so I think this is still useful to support.
GARP uses the LLC_SAP_BSPAN LLC, which is also used by STP. Different multicast addresses are used to distinguish the protocols. Since the LLC code doesn't allow multiple registrations for the same SAP, a small mac based demux layer is added that is used by both bridging and GARP.
GVRP is not enabled by default yet. Since the applicant-only participant should not be used on a bridge, we first need a reliable way to get notified when a VLAN device becomes a bridge member. So currently, the user needs to manually enable it using iproute. I plan to change this soon.
include/linux/if_vlan.h | 1 + include/linux/netdevice.h | 2 + include/net/garp.h | 128 +++++++++ include/net/stp.h | 14 + net/802/Kconfig | 7 + net/802/Makefile | 2 + net/802/garp.c | 633 +++++++++++++++++++++++++++++++++++++++++++++ net/802/stp.c | 102 ++++++++ net/8021q/Kconfig | 10 + net/8021q/Makefile | 9 +- net/8021q/vlan.c | 33 ++- net/8021q/vlan.h | 19 ++- net/8021q/vlan_dev.c | 32 ++- net/8021q/vlan_gvrp.c | 66 +++++ net/8021q/vlan_netlink.c | 7 +- net/Kconfig | 1 + net/bridge/Kconfig | 1 + net/bridge/br.c | 16 +- net/bridge/br_private.h | 5 +- net/bridge/br_stp_bpdu.c | 12 +- 20 files changed, 1051 insertions(+), 49 deletions(-) create mode 100644 include/net/garp.h create mode 100644 include/net/stp.h create mode 100644 net/802/Kconfig create mode 100644 net/802/garp.c create mode 100644 net/802/stp.c create mode 100644 net/8021q/vlan_gvrp.c
Patrick McHardy (6):
net: Add STP demux layer
bridge: Use STP demux
net: Add GARP applicant-only participant
vlan: Change vlan_dev_set_vlan_flag() to handle multiple flags at once
vlan: Move device unregistration before lower dev cleanup
vlan: Add GVRP support
net 01/06: Add STP demux layer
net: Add STP demux layer
Add small STP demux layer for demuxing STP PDUs based on MAC address. This is needed to run both GARP and STP in parallel (or even load the modules) since both use LLC_SAP_BSPAN.
---
commit 6c0be0e52a154f1991c221a6f60c6b9be71a10c8
tree 6dcdf3d929edeae8463c6957e688f1e91ca6cfe5
parent 44d28ab19c64d095314ac66f765d0c747519f4ed
author Patrick McHardy <[email protected]> Thu, 03 Jul 2008 18:05:56 +0200 committer Patrick McHardy <[email protected]> Thu, 03 Jul 2008 18:05:56 +0200
include/net/stp.h | 14 +++++++ net/802/Kconfig | 3 ++ net/802/Makefile | 1 + net/802/stp.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/Kconfig | 1 + 5 files changed, 121 insertions(+), 0 deletions(-)
include/net/stp.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef _NET_STP_H +#define _NET_STP_H + +struct stp_proto { +unsigned char group_address[ETH_ALEN ]; +void (*rcv)(const struct stp_proto *,struct sk_buff *, +struct net_device *); +void *data; +}; + +extern int stp_proto_register (const struct stp_proto *proto); +extern void stp_proto_unregister (const struct stp_proto *proto); + +#endif /* _NET_STP_H */
net/802/Kconfig new file +3 -0
@@ -0,0 +1,3 @@ +config STP + tristate + select LLC
net/802/Makefile +1 -0
@@ -10,3 +10,4 @@ obj-$(CONFIG_FDDI) += fddi.o obj-$(CONFIG_HIPPI) += hippi.o obj-$(CONFIG_IPX) += p8022.o psnap.o p8023.o obj-$(CONFIG_ATALK) += p8022.o psnap.o +obj-$(CONFIG_STP) += stp.o
net/802/stp.c new file +102 -0
102 lines not on this page · raw message
net/Kconfig +1 -0
@@ -181,6 +181,7 @@ source "net/dccp/Kconfig" source "net/sctp/Kconfig" source "net/tipc/Kconfig" source "net/atm/Kconfig" +source "net/802/Kconfig" source "net/bridge/Kconfig" source "net/8021q/Kconfig" source "net/decnet/Kconfig"
Re: net 01/06: Add STP demux layer
Quoted 173 lines · On Thu, 3 Jul 2008 19:04:42 +0200 (MEST) Patrick McHardy <[email protected]>…
net: Add STP demux layer
Add small STP demux layer for demuxing STP PDUs based on MAC address. This is needed to run both GARP and STP in parallel (or even load the modules) since both use
LLC_SAP_BSPAN.Signed-off-by Patrick McHardy <[email protected]>---
commit6c0be0e52a154f1991c221a6f60c6b9be71a10c8
tree6dcdf3d929edeae8463c6957e688f1e91ca6cfe5
parent44d28ab19c64d095314ac66f765d0c747519f4ed
author Patrick McHardy <[email protected]> Thu, 03 Jul 2008 18:05:56 +0200 committer Patrick McHardy <[email protected]> Thu, 03 Jul 2008 18:05:56 +0200include/net/stp.h | 14 +++++++ net/802/Kconfig | 3 ++ net/802/Makefile | 1 + net/802/stp.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/Kconfig | 1 + 5 files changed, 121 insertions(+), 0 deletions(-)include/net/stp.h new file +14
-0@@ -0,0 +1,14 @@ +#ifndef _NET_STP_H +#define _NET_STP_H + +struct stp_proto { +unsigned char group_address[ETH_ALEN ]; +void (*rcv)(const struct stp_proto *,struct sk_buff *, +struct net_device *); +void *data; +}; + +extern int stp_proto_register (const struct stp_proto *proto); +extern void stp_proto_unregister (const struct stp_proto *proto); + +#endif /* _NET_STP_H */ net/802/Kconfig new file +3
-0@@ -0,0 +1,3 @@ +config STP + tristate + select LLCnet/802/Makefile +1
-0@@ -10,3 +10,4 @@ obj-$(CONFIG_FDDI) += fddi.o obj-$(CONFIG_HIPPI) += hippi.o obj-$(CONFIG_IPX) += p8022.o psnap.o p8023.o obj-$(CONFIG_ATALK) += p8022.o psnap.o +obj-$(CONFIG_STP) += stp.onet/802/stp.c new file +102
-0@@ -0,0 +1,102 @@ +/* +* STP SAP demux +* +* Copyright (c) 2008 Patrick McHardy <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +*/ +#include <linux/mutex.h> +#include <linux/skbuff.h> +#include <linux/etherdevice.h> +#include <linux/llc.h> +#include <net/llc.h> +#include <net/llc_pdu.h> +#include <net/stp.h> + +/* 01:80:c2:00:00:20 - 01:80:c2:00:00:2F */ +#define GARP_ADDR_MIN 0x20 +#define GARP_ADDR_MAX 0x2F +#define GARP_ADDR_RANGE (GARP_ADDR_MAX - GARP_ADDR_MIN) + +static const struct stp_proto *garp_protos[GARP_ADDR_RANGE +1 ]__read_mostly ; +static const struct stp_proto *stp_proto__read_mostly ; + +static struct llc_sap *sap__read_mostly ; +static unsigned int sap_registered; +static DEFINE_MUTEX (stp_proto_mutex); + +/* Called under rcu_read_lock from LLC */ +static int stp_pdu_rcv (struct sk_buff *skb,struct net_device *dev, +struct packet_type *pt,struct net_device *orig_dev) +{ +const struct ethhdr *eh =eth_hdr (skb); +const struct llc_pdu_un *pdu =llc_pdu_un_hdr (skb); +const struct stp_proto *proto; + +if (pdu->ssap !=LLC_SAP_BSPAN || + pdu->dsap !=LLC_SAP_BSPAN || + pdu->ctrl_1 !=LLC_PDU_TYPE_U ) + goto err; + +if (eh->h_dest[5 ] >=GARP_ADDR_MIN && eh->h_dest[5 ] <=GARP_ADDR_MAX ) { + proto =rcu_dereference (garp_protos[eh->h_dest[5 ] - +GARP_ADDR_MIN ]); +if (proto && +compare_ether_addr (eh->h_dest, proto->group_address)) + goto err; + }else + proto =rcu_dereference (stp_proto); + +if (!proto) + goto err; + + proto->rcv (proto, skb, dev); +return 0 ; + +err: +kfree_skb (skb); +return 0 ; +} + +int stp_proto_register (const struct stp_proto *proto) +{ +int err =0 ; + +mutex_lock (&stp_proto_mutex); +if (sap_registered++ ==0 ) { + sap =llc_sap_open (LLC_SAP_BSPAN , stp_pdu_rcv); +if (!sap) { + err = -ENOMEM ; + goto out; + } + } +if (is_zero_ether_addr (proto->group_address)) +rcu_assign_pointer (stp_proto, proto); +else +rcu_assign_pointer (garp_protos[proto->group_address[5 ] - +GARP_ADDR_MIN ], proto); +out: +mutex_unlock (&stp_proto_mutex); +return err; +} +EXPORT_SYMBOL_GPL (stp_proto_register); + +void stp_proto_unregister (const struct stp_proto *proto) +{ +mutex_lock (&stp_proto_mutex); +if (is_zero_ether_addr (proto->group_address)) +rcu_assign_pointer (stp_proto,NULL ); +else +rcu_assign_pointer (garp_protos[proto->group_address[5 ] - +GARP_ADDR_MIN ],NULL ); +synchronize_rcu (); + +if (--sap_registered ==0 ) +llc_sap_put (sap); +mutex_unlock (&stp_proto_mutex); +} +EXPORT_SYMBOL_GPL (stp_proto_unregister); + +MODULE_LICENSE ("GPL" );net/Kconfig +0
-0
net/Kconfig source "net/dccp/Kconfig" · line 187
Quoted 7 lines
net/Kconfig +1
-0@@ -181,6 +181,7 @@ source "net/dccp/Kconfig" source "net/sctp/Kconfig" source "net/tipc/Kconfig" source "net/atm/Kconfig" +source "net/802/Kconfig" source "net/bridge/Kconfig" source "net/8021q/Kconfig" source "net/decnet/Kconfig"
Why not just have LLC handle multiple registrations for same SAP?
Re: net 01/06: Add STP demux layer
Quoted 11 lines · Stephen Hemminger
Quoted 7 lines · On Thu, 3 Jul 2008 19:04:42 +0200 (MEST) Patrick McHardy <[email protected]>…
net: Add STP demux layer
Add small STP demux layer for demuxing STP PDUs based on MAC address. This is needed to run both GARP and STP in parallel (or even load the modules) since both use
LLC_SAP_BSPAN.Why not just have LLC handle multiple registrations for same SAP?
I considered that, but it looks like a lot more work without a clear advantage - nothing else seems to need it.
bridge 02/06: Use STP demux
In reply to Patrick McHardybridge: Use STP demux
Use the STP demux layer for receiving STP PDUs instead of directly registering with LLC.
---
commit 85ecc2934a05203a4f6372cd8f0b132c2d1f2f97
tree 331543d774aa6897e5902576b337515cfe70eb9c
parent 6c0be0e52a154f1991c221a6f60c6b9be71a10c8
author Patrick McHardy <[email protected]> Thu, 03 Jul 2008 18:06:07 +0200 committer Patrick McHardy <[email protected]> Thu, 03 Jul 2008 18:06:07 +0200
net/bridge/Kconfig | 1 + net/bridge/br.c | 16 +++++++++------- net/bridge/br_private.h | 5 +++-- net/bridge/br_stp_bpdu.c | 12 +++--------- 4 files changed, 16 insertions(+), 18 deletions(-)
net/bridge/Kconfig +1 -0
@@ -5,6 +5,7 @@ config BRIDGE tristate "802.1d Ethernet Bridging" select LLC + select STP ---help--- If you say Y here, then your Linux box will be able to act as an Ethernet bridge, which means that the different Ethernet segments it
net/bridge/br.c +9 -7
@@ -18,21 +18,24 @@#include <linux/init.h> #include <linux/llc.h> #include <net/llc.h> +#include <net/stp.h> #include "br_private.h" int (*br_should_route_hook)(struct sk_buff *skb); -static struct llc_sap *br_stp_sap; +static const struct stp_proto br_stp_proto = { + .rcv = br_stp_rcv, +};static int __init br_init (void ) {int err; - br_stp_sap =llc_sap_open (LLC_SAP_BSPAN , br_stp_rcv); -if (!br_stp_sap) { + err =stp_proto_register (&br_stp_proto); +if (err <0 ) {printk (KERN_ERR "bridge: can't register sap for STP\n" ); -return -EADDRINUSE ; +return err; } err =br_fdb_init ();
@@ -65,13 +68,13 @@ err_out2: err_out1:br_fdb_fini (); err_out: -llc_sap_put (br_stp_sap); +stp_proto_unregister (&br_stp_proto);return err; } static void __exit br_deinit(void) { -rcu_assign_pointer (br_stp_sap->rcv_func,NULL ); +stp_proto_unregister (&br_stp_proto);br_netlink_fini ();unregister_netdevice_notifier (&br_device_notifier);
@@ -82,7 +85,6 @@ static void __exit br_deinit(void)synchronize_net ();br_netfilter_fini (); -llc_sap_put (br_stp_sap); br_fdb_get_hook =NULL ; br_fdb_put_hook =NULL ;
net/bridge/br_private.h +3 -2
@@ -226,8 +226,9 @@ extern void br_stp_set_path_cost(struct net_bridge_port *p,extern ssize_t br_show_bridge_id (char *buf,const struct bridge_id *id);/* br_stp_bpdu.c */ -extern int br_stp_rcv (struct sk_buff *skb,struct net_device *dev, -struct packet_type *pt,struct net_device *orig_dev); +struct stp_proto ; +extern void br_stp_rcv (const struct stp_proto *proto,struct sk_buff *skb, +struct net_device *dev);/* br_stp_timer.c */ extern void br_stp_timer_init (struct net_bridge *br);
net/bridge/br_stp_bpdu.c +3 -9
@@ -18,6 +18,7 @@#include <net/net_namespace.h> #include <net/llc.h> #include <net/llc_pdu.h> +#include <net/stp.h> #include <asm/unaligned.h> #include "br_private.h"
@@ -131,10 +132,9 @@ void br_send_tcn_bpdu(struct net_bridge_port *p)* * NO locks, but rcu_read_lock (preempt_disabled) */ -int br_stp_rcv (struct sk_buff *skb,struct net_device *dev, -struct packet_type *pt,struct net_device *orig_dev) +void br_stp_rcv (const struct stp_proto *proto,struct sk_buff *skb, +struct net_device *dev) { -const struct llc_pdu_un *pdu =llc_pdu_un_hdr (skb);const unsigned char *dest =eth_hdr (skb)->h_dest;struct net_bridge_port *p =rcu_dereference (dev->br_port);struct net_bridge *br;
@@ -146,11 +146,6 @@ int br_stp_rcv(struct sk_buff *skb, struct net_device *dev,if (!p) goto err; -if (pdu->ssap !=LLC_SAP_BSPAN - || pdu->dsap !=LLC_SAP_BSPAN - || pdu->ctrl_1 !=LLC_PDU_TYPE_U ) - goto err; -if (!pskb_may_pull (skb,4 )) goto err;
@@ -224,5 +219,4 @@ int br_stp_rcv(struct sk_buff *skb, struct net_device *dev,spin_unlock (&br->lock); err:kfree_skb (skb); -return 0 ; }
net 03/06: Add GARP applicant-only participant
In reply to Patrick McHardynet: Add GARP applicant-only participant
Add an implementation of the GARP (Generic Attribute Registration Protocol) applicant-only participant. This will be used by the following patch to add GVRP support to the VLAN code.
---
commit 4c8767ab0402e70217e9ec118d940e56255a8221
tree 5559fa726cb8ac236f69ccd2ead03adb26304e2b
parent 85ecc2934a05203a4f6372cd8f0b132c2d1f2f97
author Patrick McHardy <[email protected]> Thu, 03 Jul 2008 18:11:18 +0200 committer Patrick McHardy <[email protected]> Thu, 03 Jul 2008 18:11:18 +0200
include/linux/netdevice.h | 2 include/net/garp.h | 127 +++++++++ net/802/Kconfig | 4 net/802/Makefile | 1 net/802/garp.c | 633 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 767 insertions(+), 0 deletions(-)
include/linux/netdevice.h +2 -0
@@ -740,6 +740,8 @@ struct net_devicestruct net_bridge_port *br_port;/* macvlan */ struct macvlan_port *macvlan_port; +/* GARP */ +struct garp_port *garp_port;/* class/net/name entry */ struct device dev;
include/net/garp.h new file +127 -0
127 lines not on this page · raw message
net/802/Kconfig +4 -0
@@ -1,3 +1,7 @@ config STP tristate select LLC + +config GARP + tristate + select STP
net/802/Makefile +1 -0
@@ -11,3 +11,4 @@ obj-$(CONFIG_HIPPI) += hippi.o obj-$(CONFIG_IPX) += p8022.o psnap.o p8023.o obj-$(CONFIG_ATALK) += p8022.o psnap.o obj-$(CONFIG_STP) += stp.o +obj-$(CONFIG_GARP) += garp.o
net/802/garp.c new file +633 -0
633 lines not on this page · raw message
vlan 04/06: Change vlan_dev_set_vlan_flag() to handle multiple flags at once
In reply to Patrick McHardyvlan: Change vlan_dev_set_vlan_flag() to handle multiple flags at once
Change vlan_dev_set_vlan_flag() to handle multiple flags at once and rename to vlan_dev_change_flags(). This allows to to use it from the netlink interface, which in turn allows to handle necessary adjustments when changing flags centrally.
---
commit 12ad21b911562368e08dc7166109370130c156c7
tree 1002d0cb3c6b1158a25fdd3494e81904c1931d17
parent 4c8767ab0402e70217e9ec118d940e56255a8221
author Patrick McHardy <[email protected]> Thu, 03 Jul 2008 18:11:18 +0200 committer Patrick McHardy <[email protected]> Thu, 03 Jul 2008 18:11:18 +0200
net/8021q/vlan.c | 6 +++--- net/8021q/vlan.h | 3 +-- net/8021q/vlan_dev.c | 20 +++++++++----------- net/8021q/vlan_netlink.c | 4 +--- 4 files changed, 14 insertions(+), 19 deletions(-)
net/8021q/vlan.c +3 -3
@@ -591,9 +591,9 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg) err = -EPERM ;if (!capable (CAP_NET_ADMIN ))break ; - err =vlan_dev_set_vlan_flag (dev, - args.u.flag, - args.vlan_qos); + err =vlan_dev_change_flags (dev, + args.vlan_qos ? args.u.flag :0 , + args.u.flag);break ;case SET_VLAN_NAME_TYPE_CMD :
net/8021q/vlan.h +1 -2
@@ -28,8 +28,7 @@ void vlan_dev_set_ingress_priority(const struct net_device *dev, u32 skb_prio, short vlan_prio);int vlan_dev_set_egress_priority (const struct net_device *dev,u32 skb_prio,short vlan_prio); -int vlan_dev_set_vlan_flag (const struct net_device *dev, -u32 flag,short flag_val); +int vlan_dev_change_flags (const struct net_device *dev,u32 flag,u32 mask);void vlan_dev_get_realdev_name (const struct net_device *dev,char *result);void vlan_dev_get_vid (const struct net_device *dev,unsigned short *result);
net/8021q/vlan_dev.c +9 -11
@@ -507,18 +507,16 @@ int vlan_dev_set_egress_priority(const struct net_device *dev, }/* Flags are defined in the vlan_flags enum in include/linux/if_vlan.h file. */ -int vlan_dev_set_vlan_flag (const struct net_device *dev, -u32 flag,short flag_val) +int vlan_dev_change_flags (const struct net_device *dev,u32 flags,u32 mask) { -/* verify flag is supported */ -if (flag ==VLAN_FLAG_REORDER_HDR ) { -if (flag_val) -vlan_dev_info (dev)->flags |=VLAN_FLAG_REORDER_HDR ; -else -vlan_dev_info (dev)->flags &= ~VLAN_FLAG_REORDER_HDR ; -return 0 ; - } -return -EINVAL ; +struct vlan_dev_info *vlan =vlan_dev_info (dev); +u32 old_flags = vlan->flags; + +if (mask & ~VLAN_FLAG_REORDER_HDR ) +return -EINVAL ; + + vlan->flags = (old_flags & ~mask) | (flags & mask); +return 0 ; }void vlan_dev_get_realdev_name (const struct net_device *dev,char *result)
net/8021q/vlan_netlink.c +1 -3
@@ -75,7 +75,6 @@ static int vlan_validate(struct nlattr *tb[], struct nlattr *data[])static int vlan_changelink (struct net_device *dev,struct nlattr *tb[],struct nlattr *data[]) { -struct vlan_dev_info *vlan =vlan_dev_info (dev);struct ifla_vlan_flags *flags;struct ifla_vlan_qos_mapping *m;struct nlattr *attr;
@@ -83,8 +82,7 @@ static int vlan_changelink(struct net_device *dev,if (data[IFLA_VLAN_FLAGS ]) { flags =nla_data (data[IFLA_VLAN_FLAGS ]); - vlan->flags = (vlan->flags & ~flags->mask) | - (flags->flags & flags->mask); +vlan_dev_change_flags (dev, flags->flags, flags->mask); }if (data[IFLA_VLAN_INGRESS_QOS ]) {nla_for_each_nested (attr, data[IFLA_VLAN_INGRESS_QOS ], rem) {
vlan 05/06: Move device unregistration before lower dev cleanup
In reply to Patrick McHardyvlan: Move device unregistration before lower dev cleanup
Move the unregister_netdevice() call for the VLAN device before cleanup for the lower device. This is needed by GVRP so it can send a leave message before the applicant on the lower device is cleaned up.
---
commit 8f8f9dfb07f7c96492d58488d1aaf670329cc91a
tree 7748d32b10dc9342fe36e5f8259d259494c17641
parent 12ad21b911562368e08dc7166109370130c156c7
author Patrick McHardy <[email protected]> Thu, 03 Jul 2008 18:11:19 +0200 committer Patrick McHardy <[email protected]> Thu, 03 Jul 2008 18:11:19 +0200
net/8021q/vlan.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
net/8021q/vlan.c +2 -2
@@ -165,6 +165,8 @@ void unregister_vlan_dev(struct net_device *dev)synchronize_net (); +unregister_netdevice (dev); +/* If the group is now empty, kill off the group. */ if (grp->nr_vlans ==0 ) {if (real_dev->features &NETIF_F_HW_VLAN_RX )
@@ -178,8 +180,6 @@ void unregister_vlan_dev(struct net_device *dev)/* Get rid of the vlan's reference to real_dev */ dev_put (real_dev); - -unregister_netdevice (dev); } static void vlan_transfer_operstate(const struct net_device *dev,
vlan 06/06: Add GVRP support
In reply to Patrick McHardyvlan: Add GVRP support
Add GVRP support for dynamically registering VLANs with switches.
By default GVRP is disabled because we only support the applicant-only participant model, which means it should not be enabled on vlans that are members of a bridge. Since there is currently no way to cleanly determine that, the user is responsible for enabling it.
The code is pretty small and low impact, its wrapped in a config option though because it depends on the GARP implementation and the STP core.
---
commit 48425f9bd27acfbc92688ac133dac7a536879082
tree f9794528a4352d8f48623495b0e53306f8cc33a7
parent 8f8f9dfb07f7c96492d58488d1aaf670329cc91a
author Patrick McHardy <[email protected]> Thu, 03 Jul 2008 18:11:19 +0200 committer Patrick McHardy <[email protected]> Thu, 03 Jul 2008 18:11:19 +0200
include/linux/if_vlan.h | 1 + include/net/garp.h | 1 + net/8021q/Kconfig | 10 +++++++ net/8021q/Makefile | 9 ++---- net/8021q/vlan.c | 23 +++++++++++++--- net/8021q/vlan.h | 16 +++++++++++ net/8021q/vlan_dev.c | 18 +++++++++++-- net/8021q/vlan_gvrp.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++ net/8021q/vlan_netlink.c | 3 +- 9 files changed, 134 insertions(+), 13 deletions(-)
include/linux/if_vlan.h +1 -0
@@ -402,6 +402,7 @@ enum vlan_ioctl_cmds {enum vlan_flags {VLAN_FLAG_REORDER_HDR =0x1 , +VLAN_FLAG_GVRP =0x2 , };enum vlan_name_types {
include/net/garp.h +1 -0
@@ -84,6 +84,7 @@ struct garp_attr { };enum garp_applications { +GARP_APPLICATION_GVRP , __GARP_APPLICATION_MAX };#define GARP_APPLICATION_MAX (__GARP_APPLICATION_MAX - 1)
net/8021q/Kconfig +10 -0
@@ -17,3 +17,13 @@ config VLAN_8021Q will be called 8021q. If unsure, say N. + +config VLAN_8021Q_GVRP + bool "GVRP (GARP VLAN Registration Protocol) support" + depends on VLAN_8021Q + select GARP + help + Select this to enable GVRP end-system support. GVRP is used for + automatic propagation of registered VLANs to switches. + + If unsure, say N.
net/8021q/Makefile +3 -6
@@ -4,9 +4,6 @@ obj-$(CONFIG_VLAN_8021Q) += 8021q.o -8021q-objs := vlan.o vlan_dev.o vlan_netlink.o - -ifeq ($(CONFIG_PROC_FS),y) -8021q-objs += vlanproc.o -endif - +8021q-y := vlan.o vlan_dev.o vlan_netlink.o +8021q-$(CONFIG_VLAN_8021Q_GVRP) += vlan_gvrp.o +8021q-$(CONFIG_PROC_FS) += vlanproc.o
net/8021q/vlan.c +19 -4
@@ -169,6 +169,8 @@ void unregister_vlan_dev(struct net_device *dev)/* If the group is now empty, kill off the group. */ if (grp->nr_vlans ==0 ) { +vlan_gvrp_uninit_applicant (real_dev); +if (real_dev->features &NETIF_F_HW_VLAN_RX ) real_dev->vlan_rx_register (real_dev,NULL );
@@ -249,15 +251,18 @@ int register_vlan_dev(struct net_device *dev) ngrp = grp =vlan_group_alloc (real_dev);if (!grp)return -ENOBUFS ; + err =vlan_gvrp_init_applicant (real_dev); +if (err <0 ) + goto out_free_group; } err =vlan_group_prealloc_vid (grp, vlan_id);if (err <0 ) - goto out_free_group; + goto out_uninit_applicant; err =register_netdevice (dev);if (err <0 ) - goto out_free_group; + goto out_uninit_applicant;/* Account for reference in struct vlan_dev_info */ dev_hold (real_dev);
@@ -278,6 +283,9 @@ int register_vlan_dev(struct net_device *dev)return 0 ; +out_uninit_applicant: +if (ngrp) +vlan_gvrp_uninit_applicant (real_dev); out_free_group:if (ngrp)vlan_group_free (ngrp);
@@ -713,14 +721,20 @@ static int __init vlan_proto_init(void)if (err <0 ) goto err2; - err =vlan_netlink_init (); + err =vlan_gvrp_init ();if (err <0 ) goto err3; + err =vlan_netlink_init (); +if (err <0 ) + goto err4; +dev_add_pack (&vlan_packet_type);vlan_ioctl_set (vlan_ioctl_handler);return 0 ; +err4: +vlan_gvrp_uninit (); err3:unregister_netdevice_notifier (&vlan_notifier_block); err2:
@@ -745,8 +759,9 @@ static void __exit vlan_cleanup_module(void)BUG_ON (!hlist_empty (&vlan_group_hash[i]));unregister_pernet_gen_device (vlan_net_id, &vlan_net_ops); -synchronize_net (); + +vlan_gvrp_uninit (); }module_init (vlan_proto_init);
net/8021q/vlan.h +16 -0
@@ -37,6 +37,22 @@ void vlan_setup(struct net_device *dev);int register_vlan_dev (struct net_device *dev);void unregister_vlan_dev (struct net_device *dev); +#ifdef CONFIG_VLAN_8021Q_GVRP +extern int vlan_gvrp_request_join (const struct net_device *dev); +extern void vlan_gvrp_request_leave (const struct net_device *dev); +extern int vlan_gvrp_init_applicant (struct net_device *dev); +extern void vlan_gvrp_uninit_applicant (struct net_device *dev); +extern int vlan_gvrp_init (void ); +extern void vlan_gvrp_uninit (void ); +#else +static inline int vlan_gvrp_request_join (const struct net_device *dev) {return 0 ; } +static inline void vlan_gvrp_request_leave (const struct net_device *dev) {} +static inline int vlan_gvrp_init_applicant (struct net_device *dev) {return 0 ; } +static inline void vlan_gvrp_uninit_applicant (struct net_device *dev) {} +static inline int vlan_gvrp_init (void ) {return 0 ; } +static inline void vlan_gvrp_uninit (void ) {} +#endif +int vlan_netlink_init (void );void vlan_netlink_fini (void );
net/8021q/vlan_dev.c +16 -2
@@ -512,10 +512,17 @@ int vlan_dev_change_flags(const struct net_device *dev, u32 flags, u32 mask)struct vlan_dev_info *vlan =vlan_dev_info (dev);u32 old_flags = vlan->flags; -if (mask & ~VLAN_FLAG_REORDER_HDR ) +if (mask & ~(VLAN_FLAG_REORDER_HDR |VLAN_FLAG_GVRP ))return -EINVAL ; vlan->flags = (old_flags & ~mask) | (flags & mask); + +if (netif_running (dev) && (vlan->flags ^ old_flags) &VLAN_FLAG_GVRP ) { +if (vlan->flags &VLAN_FLAG_GVRP ) +vlan_gvrp_request_join (dev); +else +vlan_gvrp_request_leave (dev); + }return 0 ; }
@@ -550,12 +557,19 @@ static int vlan_dev_open(struct net_device *dev)if (dev->flags &IFF_PROMISC )dev_set_promiscuity (real_dev,1 ); +if (vlan->flags &VLAN_FLAG_GVRP ) +vlan_gvrp_request_join (dev); +return 0 ; }static int vlan_dev_stop (struct net_device *dev) { -struct net_device *real_dev =vlan_dev_info (dev)->real_dev; +struct vlan_dev_info *vlan =vlan_dev_info (dev); +struct net_device *real_dev = vlan->real_dev; + +if (vlan->flags &VLAN_FLAG_GVRP ) +vlan_gvrp_request_leave (dev);dev_mc_unsync (real_dev, dev);dev_unicast_unsync (real_dev, dev);
net/8021q/vlan_gvrp.c new file +66 -0
66 lines not on this page · raw message
net/8021q/vlan_netlink.c +2 -1
@@ -59,7 +59,8 @@ static int vlan_validate(struct nlattr *tb[], struct nlattr *data[]) }if (data[IFLA_VLAN_FLAGS ]) { flags =nla_data (data[IFLA_VLAN_FLAGS ]); -if ((flags->flags & flags->mask) & ~VLAN_FLAG_REORDER_HDR ) +if ((flags->flags & flags->mask) & + ~(VLAN_FLAG_REORDER_HDR |VLAN_FLAG_GVRP ))return -EINVAL ; }
David Miller
maintainerFrom: Patrick McHardy <[email protected]>
Date: Thu, 3 Jul 2008 19:04:41 +0200 (MEST)
Quoted 6 lines
These patches add an implementation of the GARP (Generic Attribute Registration Protocol) applicant-only participant, which can be used to dynamically register VLANs and multicast addresses with switches. Applicant-only means it can only be used as a client, not on a bridge. Also included is a GVRP (GARP VLAN Registration Protocol) application on top.
These look good, applied and pushed out to net-next-2.6, thanks!