l2tp: add vlan pseudowire support
Subsystems (2)
cover l2tp: add vlan pseudowire support
This RFC patch series adds L2TP vlan pseudowire support by creating a vlan netdev in addition to the l2tpeth netdev when the user creates vlan pseudowires. To do so, new symbols are exported in 8021q to allow l2tp to create and destroy vlan netdevs. The existing L2TP netlink API already contains attributes for vlan pseudowires but they have been unused to date.
L2TP vlan pseudowires are similar to the existing L2TP ethernet pseudowires except that vlan pseudowires always carry only one vlan and never carry untagged frames, while ethernet pseudowires can carry any ethernet frame (tagged or untagged). It is possible to create vlan interfaces on top of l2tpeth interfaces (ethernet pseudowires) today using standard tools. But for VLAN pseudowires, there must be one and only one vlan.
The changes in this patch series create a pair of netdevs per vlan
pseudowire: a vlan netdev and an l2tpeth netdev; the l2tpeth netdev is used as the master for the vlan netdev. The master netdev must not be configured since untagged frames are not allowed in vlan pseudowires.
Some L2TP setups have thousands of L2TP pseudowires so creating two netdevs per vlan pseudowire isn't ideal when one might suffice. Should I investigate changing 8021q to allow for the case where there is no master netdev?
James Chapman (2):
vlan: export functions to register/unregister vlan devices
l2tp: add vlan pseudowire support
include/linux/if_vlan.h | 11 ++++++ net/8021q/vlan.c | 82 ++++++++++++++++++++++++++++------------------ net/l2tp/l2tp_eth.c | 73 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 132 insertions(+), 34 deletions(-)
RFC PATCH 1/2 vlan: export functions to register/unregister vlan devices
Export two new symbols to let external code register and unregister vlan devices. Allow the caller to specify the name template for the new netdev instance.
The new symbols are:vlan_register_deviceunregister_vlan_dev
--- include/linux/if_vlan.h | 11 ++++++ net/8021q/vlan.c | 82 ++++++++++++++++++++++++++++------------------ 2 files changed, 61 insertions(+), 32 deletions(-)
include/linux/if_vlan.h +11 -0
@@ -101,6 +101,8 @@ extern void vlan_vids_del_by_dev(struct net_device *dev, const struct net_device *by_dev);extern bool vlan_uses_dev (const struct net_device *dev); +extern int vlan_register_device (struct net_device *real_dev,u16 vlan_id,struct net_device **dev,char *name); +extern void unregister_vlan_dev (struct net_device *dev,struct list_head *head);#else static inline struct net_device * __vlan_find_dev_deep(struct net_device *real_dev,
@@ -155,6 +157,15 @@ static inline bool vlan_uses_dev(const struct net_device *dev) {return false; } + +static inline int vlan_register_device (struct net_device *real_dev,u16 vlan_id,struct net_device **dev,char *name) +{ +return -EPROTONOSUPPORT ; +} + +static inline void unregister_vlan_dev (struct net_device *dev,struct list_head *head) +{ +}#endif static inline bool vlan_hw_offload_capable(netdev_features_t features,
net/8021q/vlan.c +50 -32
118 lines not on this page · raw message
Signature · 1 line
1.7.0.4
RFC PATCH 2/2 l2tp: add vlan pseudowire support
In reply to James ChapmanRegister the l2tp_eth driver for netlink ops using the vlan pseudowire type. Add code to create/destroy a VLAN netdevice when the pseudowire type is VLAN. This requires new exports in the vlan code.
This results in two netdevices per vlan pseudowire:
1. a master, which should never be used
2. a vlan device, which is enslaved to the master device
The session's ifname value is set to the VLAN netdevice name such that it is the name returned in session_get netlink requests. For vlan pseudowires, this should always be the interface that userspace configures.
--- net/l2tp/l2tp_eth.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 71 insertions(+), 2 deletions(-)
net/l2tp/l2tp_eth.c +71 -2
@@ -17,6 +17,7 @@#include <linux/hash.h> #include <linux/l2tp.h> #include <linux/in.h> +#include <linux/if_vlan.h> #include <linux/etherdevice.h> #include <linux/spinlock.h> #include <net/sock.h>
@@ -53,6 +54,7 @@ struct l2tp_eth {/* via l2tp_session_priv() */ struct l2tp_eth_sess {struct net_device *dev; +struct net_device *vlan_dev; };/* per-net private data for this module */
@@ -178,6 +180,50 @@ error:kfree_skb (skb); } +static int l2tp_vlan_create (struct l2tp_session *session,u16 vlan_id) +{ +struct l2tp_eth_sess *spriv; +struct net_device *dev; +struct net_device *vlan_dev; +char name[IFNAMSIZ +1 ]; +int rc; + + spriv =l2tp_session_priv (session); + dev = spriv->dev; + +if (!vlan_id) +return -EINVAL ; + +snprintf (name,IFNAMSIZ ,"%s.%i" , dev->name, vlan_id); +rtnl_lock (); + rc =vlan_register_device (dev, vlan_id, &vlan_dev, name); +rtnl_unlock (); +if (rc <0 ) +return rc; + + spriv->vlan_dev = vlan_dev; +strlcpy (session->ifname, vlan_dev->name,IFNAMSIZ ); + +return 0 ; +} + +static int l2tp_vlan_delete (struct l2tp_session *session) +{ +struct l2tp_eth_sess *spriv; +struct net_device *dev; + + spriv =l2tp_session_priv (session); + dev = spriv->dev; + +rtnl_lock (); +unregister_vlan_dev (spriv->vlan_dev,NULL ); +rtnl_unlock (); +strlcpy (session->ifname, dev->name,IFNAMSIZ ); + spriv->vlan_dev =NULL ; + +return 0 ; +} +static void l2tp_eth_delete (struct l2tp_session *session) {struct l2tp_eth_sess *spriv;
@@ -186,6 +232,8 @@ static void l2tp_eth_delete(struct l2tp_session *session)if (session) { spriv =l2tp_session_priv (session); dev = spriv->dev; +if (spriv->vlan_dev) +l2tp_vlan_delete (session);if (dev) {unregister_netdev (dev); spriv->dev =NULL ;
@@ -277,10 +325,18 @@ static int l2tp_eth_create(struct net *net, u32 tunnel_id, u32 session_id, u32 pif (rc <0 ) goto out_del_dev; -__module_get (THIS_MODULE );/* Must be done after register_netdev() */ strlcpy (session->ifname, dev->name,IFNAMSIZ ); +if (cfg->pw_type ==L2TP_PWTYPE_ETH_VLAN ) { +/* Create VLAN interface. Replaces session->ifname */ + rc =l2tp_vlan_create (session, cfg->vlan_id); +if (rc <0 ) + goto out_unreg; + } + +__module_get (THIS_MODULE ); +dev_hold (dev); pn =l2tp_eth_pernet (dev_net (dev));spin_lock (&pn->l2tp_eth_lock);
@@ -289,6 +345,8 @@ static int l2tp_eth_create(struct net *net, u32 tunnel_id, u32 session_id, u32 preturn 0 ; +out_unreg: +unregister_netdev (dev); out_del_dev:free_netdev (dev); spriv->dev =NULL ;
@@ -328,6 +386,11 @@ static int __init l2tp_eth_init(void) err =l2tp_nl_register_ops (L2TP_PWTYPE_ETH , &l2tp_eth_nl_cmd_ops);if (err) goto out; +#if IS_ENABLED (CONFIG_VLAN_8021Q ) + err =l2tp_nl_register_ops (L2TP_PWTYPE_ETH_VLAN , &l2tp_eth_nl_cmd_ops); +if (err) + goto out; +#endif err =register_pernet_device (&l2tp_eth_net_ops);if (err)
@@ -338,6 +401,9 @@ static int __init l2tp_eth_init(void)return 0 ; out_unreg: +#if IS_ENABLED(CONFIG_VLAN_8021Q) +l2tp_nl_unregister_ops (L2TP_PWTYPE_ETH_VLAN); +#endif l2tp_nl_unregister_ops (L2TP_PWTYPE_ETH ); out:return err;
@@ -346,6 +412,9 @@ out: static void __exit l2tp_eth_exit(void) {unregister_pernet_device (&l2tp_eth_net_ops); +#if IS_ENABLED (CONFIG_VLAN_8021Q ) +l2tp_nl_unregister_ops (L2TP_PWTYPE_ETH_VLAN ); +#endif l2tp_nl_unregister_ops (L2TP_PWTYPE_ETH ); }
@@ -355,4 +424,4 @@ module_exit(l2tp_eth_exit);MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("James Chapman <[email protected]>" );MODULE_DESCRIPTION ("L2TP ethernet pseudowire driver" ); -MODULE_VERSION ("1.0" ); +MODULE_VERSION ("1.1" );
Signature · 1 line
1.7.0.4