ipvlan: Initial check-in of the IPVLAN driver.
Subsystems (3)
PATCH v4 1/1 ipvlan: Initial check-in of the IPVLAN driver.
This driver is very similar to the macvlan driver except that it uses L3 on the frame to determine the logical interface while functioning as packet dispatcher. It inherits L2 of the master device hence the packets on wire will have the same L2 for all the packets originating from all virtual devices off of the same master device.
This driver was developed keeping the namespace use-case in mind. Hence most of the examples given here take that as the base setup where main-device belongs to the default-ns and virtual devices are assigned to the additional namespaces.
The device operates in two different modes and the difference in these two modes in primarily in the TX side.
(a) L2 mode : In this mode, the device behaves as a L2 device. TX processing upto L2 happens on the stack of the virtual device associated with (namespace). Packets are switched after that into the main device (default-ns) and queued for xmit.
RX processing is simple and all multicast, broadcast (if applicable), and unicast belonging to the address(es) are delivered to the virtual devices.
(b) L3 mode : In this mode, the device behaves like a L3 device. TX processing upto L3 happens on the stack of the virtual device associated with (namespace). Packets are switched to the main-device (default-ns) for the L2 processing. Hence the routing table of the default-ns will be used in this mode.
RX processins is somewhat similar to the L2 mode except that in this mode only Unicast packets are delivered to the virtual device while main-dev will handle all other packets.
The devices can be added using the "ip" command from the iproute2 package -
ip link add link <master> <virtual> type ipvlan mode [ l2 | l3 ]
--- Documentation/networking/ipvlan.txt | 108 +++++ drivers/net/Kconfig | 18 + drivers/net/Makefile | 1 + drivers/net/ipvlan/Makefile | 7 + drivers/net/ipvlan/ipvlan.h | 130 ++++++ drivers/net/ipvlan/ipvlan_core.c | 607 +++++++++++++++++++++++++++ drivers/net/ipvlan/ipvlan_main.c | 789 ++++++++++++++++++++++++++++++++++++ include/linux/netdevice.h | 4 + include/uapi/linux/if_link.h | 15 + 9 files changed, 1679 insertions(+) create mode 100644 Documentation/networking/ipvlan.txt create mode 100644 drivers/net/ipvlan/Makefile create mode 100644 drivers/net/ipvlan/ipvlan.h create mode 100644 drivers/net/ipvlan/ipvlan_core.c create mode 100644 drivers/net/ipvlan/ipvlan_main.c
Documentation/networking/ipvlan.txt new file +108 -0
@@ -0,0 +1,108 @@ + + IPVLAN Driver HOWTO + +Initial Release: + Mahesh Bandewar <maheshb AT google.com> + +1. Introduction: + This is conceptually very similar to the macvlan driver with one major +exception of using L3 for mux-ing /demux-ing among slaves. This property makes +the master device share the L2 with it's slave devices. I have developed this +driver in conjuntion with network namespaces and not sure if there is use case +outside of it. + + +2. Building and Installation: + In order to build the driver, please select the config item CONFIG_IPVLAN. +The driver can be built into the kernel (CONFIG_IPVLAN=y) or as a module +(CONFIG_IPVLAN=m). + + +3. Configuration: + There are no module parameters for this driver and it can be configured +using IProute2/ip utility. + + ip link add link <master-dev> <slave-dev> type ipvlan mode { l2 | L3 } + + e.g. ip link add link ipvl0 eth0 type ipvlan mode l2 + + +4. Operating modes: + IPvlan has two modes of operation - L2 and L3. For a given master device, +you can select one of these two modes and all slaves on that master will +operate in the same (selected) mode. The RX mode is almost identical except +that in L3 mode the slaves wont receive any multicast / broadcast traffic. +L3 mode is more restrictive since routing is controlled from the other (mostly) +default namespace. + +4.1 L2 mode: + In this mode TX processing happens on the stack instance attached to the +slave device and packets are switched and queued to the master device to send +out. In this mode the slaves will RX/TX multicast and broadcast (if applicable) +as well. + +4.2 L3 mode: + In this mode TX processing upto L3 happens on the stack instance attached +to the slave device and packets are switched to the stack instance of the +master device for the L2 processing and routing from that instance will be +used before packets are queued on the outbound device. In this mode the slaves +will not receive nor can send multicast / broadcast traffic. + + +5. What to choose (macvlan vs. ipvlan)? + These two devices are very similar in many regards and the specific use +case could very well define which device to choose. if one of the following +situations defines your use case then you can choose to use ipvlan - + (a) The Linux host that is connected to the external switch / router has +policy configured that allows only one mac per port. + (b) No of virtual devices created on a master exceed the mac capacity and +puts the NIC in promiscous mode and degraded performance is a concern. + (c) If the slave device is to be put into the hostile / untrusted network +namespace where L2 on the slave could be changed / misused. + + +6. Example configuration: + + +=============================================================+ + | Host: host1 | + | | + | +----------------------+ +----------------------+ | + | | NS:ns0 | | NS:ns1 | | + | | | | | | + | | | | | | + | | ipvl0 | | ipvl1 | | + | +----------#-----------+ +-----------#----------+ | + | # # | + | ################################ | + | # eth0 | + +==============================#==============================+ + + + (a) Create two network namespaces - ns0, ns1 + ip netns add ns0 + ip netns add ns1 + + (b) Create two ipvlan slaves on eth0 (master device) + ip link add link eth0 ipvl0 type ipvlan mode l2 + ip link add link eth0 ipvl1 type ipvlan mode l2 + + (c) Assign slaves to the respective network namespaces + ip link set dev ipvl0 netns ns0 + ip link set dev ipvl1 netns ns1 + + (d) Now switch to the namespace (ns0 or ns1) to configure the slave devices + - For ns0 + (1) ip netns exec ns0 bash + (2) ip link set dev ipvl0 up + (3) ip link set dev lo up + (4) ip -4 addr add 127.0.0.1 dev lo + (5) ip -4 addr add $IPADDR dev ipvl0 + (6) ip -4 route add default via $ROUTER dev ipvl0 + - For ns1 + (1) ip netns exec ns1 bash + (2) ip link set dev ipvl1 up + (3) ip link set dev lo up + (4) ip -4 addr add 127.0.0.1 dev lo + (5) ip -4 addr add $IPADDR dev ipvl1 + (6) ip -4 route add default via $ROUTER dev ipvl1 +
drivers/net/Kconfig +18 -0
@@ -145,6 +145,24 @@ config MACVTAP To compile this driver as a module, choose M here: the module will be called macvtap. + +config IPVLAN + tristate "IP-VLAN support" + ---help--- + This allows one to create virtual devices off of a main interface + and packets will be delivered based on the dest L3 (IPv6/IPv4 addr) + on packets. All interfaces (including the main interface) share L2 + making it transparent to the connected L2 switch. + + Ipvlan devices can be added using the "ip" command from the + iproute2 package starting with the iproute2-X.Y.ZZ release: + + "ip link add link <main-dev> [ NAME ] type ipvlan" + + To compile this driver as a module, choose M here: the module + will be called ipvlan. + + config VXLAN tristate "Virtual eXtensible Local Area Network (VXLAN)" depends on INET
drivers/net/Makefile +1 -0
@@ -6,6 +6,7 @@ # Networking Core Drivers # obj-$(CONFIG_BONDING) += bonding/ +obj-$(CONFIG_IPVLAN) += ipvlan/ obj-$(CONFIG_DUMMY) += dummy.o obj-$(CONFIG_EQUALIZER) += eql.o obj-$(CONFIG_IFB) += ifb.o
drivers/net/ipvlan/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile for the Ethernet Ipvlan driver +# + +obj-$(CONFIG_IPVLAN) += ipvlan.o + +ipvlan-objs := ipvlan_core.o ipvlan_main.o
drivers/net/ipvlan/ipvlan.h new file +130 -0
130 lines not on this page · raw message
drivers/net/ipvlan/ipvlan_core.c new file +607 -0
607 lines not on this page · raw message
drivers/net/ipvlan/ipvlan_main.c new file +789 -0
789 lines not on this page · raw message
include/linux/netdevice.h +4 -0
@@ -1230,6 +1230,8 @@ enum netdev_priv_flags {IFF_LIVE_ADDR_CHANGE =1 <<20 ,IFF_MACVLAN =1 <<21 ,IFF_XMIT_DST_RELEASE_PERM =1 <<22 , +IFF_IPVLAN_MASTER =1 <<23 , + IFF_IPVLAN_SLAVE = 1<<24, };#define IFF_802_1Q_VLAN IFF_802_1Q_VLAN
@@ -1255,6 +1257,8 @@ enum netdev_priv_flags {#define IFF_LIVE_ADDR_CHANGE IFF_LIVE_ADDR_CHANGE#define IFF_MACVLAN IFF_MACVLAN#define IFF_XMIT_DST_RELEASE_PERM IFF_XMIT_DST_RELEASE_PERM +#define IFF_IPVLAN_MASTER IFF_IPVLAN_MASTER +#define IFF_IPVLAN_SLAVE IFF_IPVLAN_SLAVE/** * struct net_device - The DEVICE structure.
include/uapi/linux/if_link.h +15 -0
@@ -330,6 +330,21 @@ enum macvlan_macaddr_mode {#define MACVLAN_FLAG_NOPROMISC 1 +/* IPVLAN section */ +enum { +IFLA_IPVLAN_UNSPEC , +IFLA_IPVLAN_MODE , + __IFLA_IPVLAN_MAX +}; + +#define IFLA_IPVLAN_MAX (__IFLA_IPVLAN_MAX - 1) + +enum ipvlan_mode { +IPVLAN_MODE_L2 =0 , +IPVLAN_MODE_L3 , +IPVLAN_MODE_MAX +}; +/* VXLAN section */ enum {IFLA_VXLAN_UNSPEC ,
Signature · 1 line
2.1.0.rc2.206.gedb03e5
From: Mahesh Bandewar <[email protected]>
Date: Sun, 23 Nov 2014 23:07:46 -0800
Quoted 11 lines
This driver is very similar to the macvlan driver except that it uses L3 on the frame to determine the logical interface while functioning as packet dispatcher. It inherits L2 of the master device hence the packets on wire will have the same L2 for all the packets originating from all virtual devices off of the same master device.
This driver was developed keeping the namespace use-case in mind. Hence most of the examples given here take that as the base setup where main-device belongs to the default-ns and virtual devices are assigned to the additional namespaces.
...
Quoted 1 line
Signed-off-by Mahesh Bandewar <[email protected]>
Applied, thanks.
Hi Mahesh,
I found that deleting the last ipvlan device triggers WARN_ON() in rtmsg_ifinfo().ipvlan_nl_fillinfo() seems to return -EINVAL in that case.
Quoted 9 lines
drivers/net/ipvlan/ipvlan_main.c new file +9
-0+static int ipvlan_nl_fillinfo (struct sk_buff *skb, +const struct net_device *dev) +{ +struct ipvl_dev *ipvlan =netdev_priv (dev); +struct ipvl_port *port =ipvlan_port_get_rtnl (ipvlan->phy_dev); +int ret = -EINVAL ; + +if (!port) + goto err;
drivers/net/ipvlan/ipvlan_main.c line 426
Quoted 10 lines
drivers/net/ipvlan/ipvlan_main.c new file +10
-0+ + ret = -EMSGSIZE ; +if (nla_put_u16 (skb,IFLA_IPVLAN_MODE , port->mode)) + goto err; + +return 0 ; + +err: +return ret; +}
rollback_registered_many() calls rtmsg_ifinfo() after calling ndo_uninit(). ndo_uninit() (ipvlan_uninit() -> ipvlan_port_destroy() -> netdev_rx_handler_unregister()) sets rx_handler_data into NULL. So, we cannot dereference "port" in ipvlan_nl_fillinfo().
Maybe "mode" should belong to struct ipvl_dev?
Thanks,
Toshiaki Makita
Quoted 22 lines · Toshiaki Makita
Hi Mahesh,
I found that deleting the last ipvlan device triggers
WARN_ON()inrtmsg_ifinfo().ipvlan_nl_fillinfo()seems to return-EINVALin that case.Quoted 16 lines
drivers/net/ipvlan/ipvlan_main.c new file +16
-0+static int ipvlan_nl_fillinfo (struct sk_buff *skb, +const struct net_device *dev) +{ +struct ipvl_dev *ipvlan =netdev_priv (dev); +struct ipvl_port *port =ipvlan_port_get_rtnl (ipvlan->phy_dev); +int ret = -EINVAL ; + +if (!port) + goto err; + + ret = -EMSGSIZE ; +if (nla_put_u16 (skb,IFLA_IPVLAN_MODE , port->mode)) + goto err; + +return 0 ; +
Quoted 9 lines
drivers/net/ipvlan/ipvlan_core.c line 361
Quoted 3 lines
drivers/net/ipvlan/ipvlan_core.c new file +3
-0+err: +return ret; +}
rollback_registered_many()callsrtmsg_ifinfo()after callingndo_uninit().ndo_uninit()(ipvlan_uninit()->ipvlan_port_destroy()->netdev_rx_handler_unregister()) setsrx_handler_datainto NULL. So, we cannot dereference "port" inipvlan_nl_fillinfo().
Calling fillinfo() after calling uninit() seems pointless on any device. But how are you hitting this case? Can you share the command sequence with me?
Thanks,
--mahesh..
Quoted 5 lines
Maybe "mode" should belong to struct
ipvl_dev?Thanks,
Toshiaki Makita
Quoted 33 lines · Mahesh Bandewar
Quoted 22 lines · Toshiaki Makita
Hi Mahesh,
I found that deleting the last ipvlan device triggers
WARN_ON()inrtmsg_ifinfo().ipvlan_nl_fillinfo()seems to return-EINVALin that case.Quoted 16 lines
drivers/net/ipvlan/ipvlan_main.c new file +16
-0+static int ipvlan_nl_fillinfo (struct sk_buff *skb, +const struct net_device *dev) +{ +struct ipvl_dev *ipvlan =netdev_priv (dev); +struct ipvl_port *port =ipvlan_port_get_rtnl (ipvlan->phy_dev); +int ret = -EINVAL ; + +if (!port) + goto err; + + ret = -EMSGSIZE ; +if (nla_put_u16 (skb,IFLA_IPVLAN_MODE , port->mode)) + goto err; + +return 0 ; +Quoted 9 lines
drivers/net/ipvlan/ipvlan_core.c line 361
Quoted 3 lines
drivers/net/ipvlan/ipvlan_core.c new file +3
-0+err: +return ret; +}
rollback_registered_many()callsrtmsg_ifinfo()after callingndo_uninit().ndo_uninit()(ipvlan_uninit()->ipvlan_port_destroy()->netdev_rx_handler_unregister()) setsrx_handler_datainto NULL. So, we cannot dereference "port" inipvlan_nl_fillinfo().
Quoted 2 lines
Calling
fillinfo()after callinguninit()seems pointless on any device.
bonding needs calling rtmsg_ifinfo() after calling ndo_uninit(). 56bfa7ee7c88 ("unregister_netdevice : move RTM_DELLINK to until after ndo_uninit")
Quoted 2 lines
But how are you hitting this case? Can you share the command sequence with me?
# ip link add link eth0 name ipvl0 type ipvlan # ip link del ipvl0
Thanks,
Toshiaki Makita
Quoted 8 lines
Thanks,
--mahesh..Quoted 4 lines
Maybe "mode" should belong to struct
ipvl_dev?Thanks,
Toshiaki Makita
Quoted 34 lines · Toshiaki Makita
Quoted 33 lines · Mahesh Bandewar
Quoted 31 lines · Toshiaki Makita
Hi Mahesh,
I found that deleting the last ipvlan device triggers
WARN_ON()inrtmsg_ifinfo().ipvlan_nl_fillinfo()seems to return-EINVALin that case.Quoted 9 lines
drivers/net/ipvlan/ipvlan_main.c new file +9
-0+static int ipvlan_nl_fillinfo (struct sk_buff *skb, +const struct net_device *dev) +{ +struct ipvl_dev *ipvlan =netdev_priv (dev); +struct ipvl_port *port =ipvlan_port_get_rtnl (ipvlan->phy_dev); +int ret = -EINVAL ; + +if (!port) + goto err;drivers/net/ipvlan/ipvlan_main.c line 426
Quoted 10 lines
drivers/net/ipvlan/ipvlan_main.c new file +10
-0+ + ret = -EMSGSIZE ; +if (nla_put_u16 (skb,IFLA_IPVLAN_MODE , port->mode)) + goto err; + +return 0 ; + +err: +return ret; +}
rollback_registered_many()callsrtmsg_ifinfo()after callingndo_uninit().ndo_uninit()(ipvlan_uninit()->ipvlan_port_destroy()->netdev_rx_handler_unregister()) setsrx_handler_datainto NULL. So, we cannot dereference "port" inipvlan_nl_fillinfo().
Quoted 7 lines
Quoted 2 lines
Calling
fillinfo()after callinguninit()seems pointless on any device.bonding needs calling
rtmsg_ifinfo()after callingndo_uninit().56bfa7ee7c88("unregister_netdevice: moveRTM_DELLINKto until afterndo_uninit")
Thanks I'll take a look.
Quoted 6 lines
Quoted 2 lines
But how are you hitting this case? Can you share the command sequence with me?
# ip link add link eth0 name ipvl0 type ipvlan # ip link del ipvl0
Yes, I could reproduce the issue when the master device is a bond.
Quoted 12 lines
Thanks,
Toshiaki MakitaQuoted 8 lines
Thanks,
--mahesh..Quoted 4 lines
Maybe "mode" should belong to struct
ipvl_dev?Thanks,
Toshiaki Makita