: MACVLAN driver
Subsystems (2)
cover : MACVLAN driver
These patches add a rewritten version of Ben's macvlan driver, which allows to create virtual ethernet devices. The underlying device is put in promiscous mode and packets are demuxed based on MAC address. It behaves similar to bridge devices in that packets are visible on the real device before delivery to the macvlan driver. The driver supports all features of the underlying device except VLAN acceleration, this is currently very hard to support. I might look into this in the future.
The main downside of this driver is that it adds another hook in netif_receive_skb, unfortunately that is unavoidable. When not compiled in the hook vanishes of course.
Usage is simple:
# ip link add link eth0 type macvlan
Will create a macvlan0 device with a random MAC address on top of eth0. No iproute patches are required.
Please apply, thanks.
MAINTAINERS | 6 + drivers/net/Kconfig | 10 + drivers/net/Makefile | 1 + drivers/net/macvlan.c | 468 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/if_macvlan.h | 9 + include/linux/netdevice.h | 2 + net/core/dev.c | 26 +++ net/ethernet/eth.c | 3 + 8 files changed, 525 insertions(+), 0 deletions(-) create mode 100644 drivers/net/macvlan.c create mode 100644 include/linux/if_macvlan.h
Patrick McHardy (2):
[ETHERNET]: Validate new address in eth_mac_addr [NET]: Add MACVLAN driver
PATCH 1/2 : Validate new address in eth_mac_addr
[ETHERNET]: Validate new address in eth_mac_addr
---
commit c92ac42cd3badaf120e97223ac4798abf5226424
tree 824d080a4748fcd6f025bbe7b9466feee46e3303
parent 45da27ba265dba3c740c45d47f584c30d7066f82
author Patrick McHardy <[email protected]> Mon, 18 Jun 2007 16:15:32 +0200 committer Patrick McHardy <[email protected]> Mon, 18 Jun 2007 16:15:32 +0200
net/ethernet/eth.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
net/ethernet/eth.c +3 -0
@@ -266,8 +266,11 @@ void eth_header_cache_update(struct hh_cache *hh, struct net_device *dev,static int eth_mac_addr (struct net_device *dev,void *p) {struct sockaddr *addr = p; +if (netif_running (dev))return -EBUSY ; +if (!is_valid_ether_addr (addr->sa_data)) +return -EINVAL ;memcpy (dev->dev_addr, addr->sa_data, dev->addr_len);return 0 ; }
PATCH 2/2 : Add MACVLAN driver
In reply to Patrick McHardy[NET]: Add MACVLAN driver
Add macvlan driver, which allows to create virtual ethernet devices based on MAC address.
---
commit 890e2ae4ef5599ee34f280af4882f97c2dcfcb7b
tree a41a8564a8add18a2095a18d4a3f1a2ce0c25997
parent c92ac42cd3badaf120e97223ac4798abf5226424
author Patrick McHardy <[email protected]> Tue, 19 Jun 2007 15:01:06 +0200 committer Patrick McHardy <[email protected]> Tue, 19 Jun 2007 15:01:06 +0200
MAINTAINERS | 6 + drivers/net/Kconfig | 10 + drivers/net/Makefile | 1 drivers/net/macvlan.c | 468 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/if_macvlan.h | 9 + include/linux/netdevice.h | 2 net/core/dev.c | 26 ++ 7 files changed, 522 insertions(+), 0 deletions(-)
MAINTAINERS +6 -0
@@ -2320,6 +2320,12 @@ W: http://linuxwireless.org/ T: git kernel.org:/pub/scm/linux/kernel/git/jbenc/mac80211.git S: Maintained +MACVLAN DRIVER +P: Patrick McHardy +M: [email protected] +L: [email protected] +S: Maintained + MARVELL YUKON / SYSKONNECT DRIVER P: Mirko Lindner M: [email protected]
drivers/net/Kconfig +10 -0
@@ -77,6 +77,16 @@ config BONDING To compile this driver as a module, choose M here: the module will be called bonding. +config MACVLAN + tristate "MAC-VLAN support (EXPERIMENTAL)" + depends on EXPERIMENTAL + ---help--- + This allows one to create virtual interfaces that map packets to + or from specific MAC addresses to a particular interface. + + To compile this driver as a module, choose M here: the module + will be called macvlan. + config EQUALIZER tristate "EQL (serial line load balancing) support" ---help---
drivers/net/Makefile +1 -0
@@ -125,6 +125,7 @@ obj-$(CONFIG_SLHC) += slhc.o obj-$(CONFIG_DUMMY) += dummy.o obj-$(CONFIG_IFB) += ifb.o +obj-$(CONFIG_MACVLAN) += macvlan.o obj-$(CONFIG_DE600) += de600.o obj-$(CONFIG_DE620) += de620.o obj-$(CONFIG_LANCE) += lance.o
drivers/net/macvlan.c new file +468 -0
468 lines not on this page · raw message
include/linux/if_macvlan.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef _LINUX_IF_MACVLAN_H +#define _LINUX_IF_MACVLAN_H + +#ifdef __KERNEL__ + +extern struct sk_buff *(*macvlan_handle_frame_hook)(struct sk_buff *); + +#endif /* __KERNEL__ */ +#endif /* _LINUX_IF_MACVLAN_H */
include/linux/netdevice.h +2 -0
@@ -535,6 +535,8 @@ struct net_device/* bridge stuff */ struct net_bridge_port *br_port; +/* macvlan */ +struct macvlan_port *macvlan_port;/* class/net/name entry */ struct device dev;
net/core/dev.c +26 -0
@@ -98,6 +98,7 @@#include <linux/seq_file.h> #include <linux/stat.h> #include <linux/if_bridge.h> +#include <linux/if_macvlan.h> #include <net/dst.h> #include <net/pkt_sched.h> #include <net/checksum.h>
@@ -1793,6 +1794,28 @@ static inline struct sk_buff *handle_bridge(struct sk_buff *skb,#define handle_bridge (skb, pt_prev, ret, orig_dev) (skb)#endif +#if defined(CONFIG_MACVLAN ) || defined(CONFIG_MACVLAN_MODULE ) +struct sk_buff *(*macvlan_handle_frame_hook)(struct sk_buff *skb)__read_mostly ; +EXPORT_SYMBOL_GPL (macvlan_handle_frame_hook); + +static inline struct sk_buff *handle_macvlan (struct sk_buff *skb, +struct packet_type **pt_prev, +int *ret, +struct net_device *orig_dev) +{ +if (skb->dev->macvlan_port ==NULL ) +return skb; + +if (*pt_prev) { + *ret =deliver_skb (skb, *pt_prev, orig_dev); + *pt_prev =NULL ; + } +return macvlan_handle_frame_hook (skb); +} +#else +#define handle_macvlan (skb, pt_prev, ret, orig_dev) (skb) +#endif +#ifdef CONFIG_NET_CLS_ACT /* TODO: Maybe we should just force sch_ingress to be compiled in * when CONFIG_NET_CLS_ACT is? otherwise some useless instructions
@@ -1900,6 +1923,9 @@ ncls: skb =handle_bridge (skb, &pt_prev, &ret, orig_dev);if (!skb) goto out; + skb =handle_macvlan (skb, &pt_prev, &ret, orig_dev); +if (!skb) + goto out; type = skb->protocol;list_for_each_entry_rcu (ptype, &ptype_base[ntohs (type)&15 ], list) {
Quoted 15 lines · On Tue, 19 Jun 2007 15:08:41 +0200 (MEST) Patrick McHardy <[email protected]>…
These patches add a rewritten version of Ben's macvlan driver, which allows to create virtual ethernet devices. The underlying device is put in promiscous mode and packets are demuxed based on MAC address. It behaves similar to bridge devices in that packets are visible on the real device before delivery to the macvlan driver. The driver supports all features of the underlying device except VLAN acceleration, this is currently very hard to support. I might look into this in the future.
The main downside of this driver is that it adds another hook in
netif_receive_skb, unfortunately that is unavoidable. When not compiled in the hook vanishes of course.Usage is simple:
Quoted 8 lines
# ip link add link eth0 type macvlanWill create a macvlan0 device with a random MAC address on top of eth0. No iproute patches are required.
Please apply, thanks.
Looks good. I have some changes to allow devices with multiple MAC addresses (never finished). This device could use that.
Signature · 1 line
Stephen Hemminger <[email protected]>
Quoted 2 lines · Stephen Hemminger
Looks good. I have some changes to allow devices with multiple MAC addresses (never finished). This device could use that.
Stephen,
Is this patch available somewhere? I'd be interested in taking a look at it.
- Chris
Quoted 2 lines · Stephen Hemminger
Looks good. I have some changes to allow devices with multiple MAC addresses (never finished). This device could use that.
How would the driver do that? I was thinking about using dev_add_mc, but wasn't sure if that would work with all drivers for non-multicast addresses.
Quoted 9 lines · On Tue, 19 Jun 2007 23:14:21 +0200 Patrick McHardy <[email protected]> wrote:
Quoted 2 lines · Stephen Hemminger
Looks good. I have some changes to allow devices with multiple MAC addresses (never finished). This device could use that.
How would the driver do that? I was thinking about using
dev_add_mc, but wasn't sure if that would work with all drivers for non-multicast addresses.
Basically, add a new dev_add_addr hook to netdevice.
Drivers that can do it, would add the hook. If driver didn't have hook, then core would put device into promiscuous. Most devices with multicast allow non-multicast addresses, so it could be a simple extension. Rather than doing it for all devices, wanted to go in one by one and test.
Signature · 1 line
Stephen Hemminger <[email protected]>
David Miller
maintainerFrom: Patrick McHardy <[email protected]>
Date: Tue, 19 Jun 2007 23:14:21 +0200
Quoted 8 lines
Quoted 2 lines · Stephen Hemminger
Looks good. I have some changes to allow devices with multiple MAC addresses (never finished). This device could use that.
How would the driver do that? I was thinking about using
dev_add_mc, but wasn't sure if that would work with all drivers for non-multicast addresses.
This is actually a real issue for virtualization, and many if not all current generation ethernet chips support programming several unicast ethernet addresses in the MAC.
Networking switches in domain0 on virtualization hosts use this feature to support seperate MACs per guest node, and if the chip doesn't support this the chip is put into promiscuous mode.
We don't have any clean interfaces by which to do this MAC programming, and we do need something for it soon.
Quoted 18 lines · David Miller
From: Patrick McHardy <[email protected]>
Date: Tue, 19 Jun 2007 23:14:21 +0200Quoted 9 lines
Quoted 3 lines · Stephen Hemminger
Looks good. I have some changes to allow devices with multiple MAC addresses (never finished). This device could use that.
How would the driver do that? I was thinking about using
dev_add_mc, but wasn't sure if that would work with all drivers for non-multicast addresses.This is actually a real issue for virtualization, and many if not all current generation ethernet chips support programming several unicast ethernet addresses in the MAC.
Quoted 8 lines
Networking switches in domain0 on virtualization hosts use this feature to support seperate MACs per guest node, and if the chip doesn't support this the chip is put into promiscuous mode.
We don't have any clean interfaces by which to do this MAC programming, and we do need something for it soon.
Stephen's suggestion sounds reasonable and easily implementable, I'll see if I can come up with a patch.
Quoted 11 lines · David Miller
This is actually a real issue for virtualization, and many if not all current generation ethernet chips support programming several unicast ethernet addresses in the MAC.
Networking switches in domain0 on virtualization hosts use this feature to support seperate MACs per guest node, and if the chip doesn't support this the chip is put into promiscuous mode.
We don't have any clean interfaces by which to do this MAC programming, and we do need something for it soon.
Yep, that's been on my long term wish list for a while, as well.
Overall I would like to see a more flexible way of allowing the net stack to learn each NIC's RX filter capabilities, and exploiting them. Plenty of NICs, even 100Mbps ones, support RX filter management that allows scanning for $hw_limit unicast addresses, before having to put the hardware into promisc mode.
Jeff
Quoted 16 lines · Jeff Garzik
Quoted 11 lines · David Miller
This is actually a real issue for virtualization, and many if not all current generation ethernet chips support programming several unicast ethernet addresses in the MAC.
Networking switches in domain0 on virtualization hosts use this feature to support seperate MACs per guest node, and if the chip doesn't support this the chip is put into promiscuous mode.
We don't have any clean interfaces by which to do this MAC programming, and we do need something for it soon.
Yep, that's been on my long term wish list for a while, as well.
Quoted 7 lines
Overall I would like to see a more flexible way of allowing the net stack to learn each NIC's RX filter capabilities, and exploiting them. Plenty of NICs, even 100Mbps ones, support RX filter management that allows scanning for $hw_limit unicast addresses, before having to put the hardware into promisc mode.
Jeff
So how do we manage mac address to RX queue association? Ideally we should extend ethtool to do that rather than inventing a new tool - Is that acceptable?
-Prafulla
Quoted 23 lines · Prafulla Deuskar
Quoted 22 lines · Jeff Garzik
Quoted 11 lines · David Miller
This is actually a real issue for virtualization, and many if not all current generation ethernet chips support programming several unicast ethernet addresses in the MAC.
Networking switches in domain0 on virtualization hosts use this feature to support seperate MACs per guest node, and if the chip doesn't support this the chip is put into promiscuous mode.
We don't have any clean interfaces by which to do this MAC programming, and we do need something for it soon.
Yep, that's been on my long term wish list for a while, as well.
Overall I would like to see a more flexible way of allowing the net stack to learn each NIC's RX filter capabilities, and exploiting them. Plenty of NICs, even 100Mbps ones, support RX filter management that allows scanning for $hw_limit unicast addresses, before having to put the hardware into promisc mode.
Quoted 3 lines
Quoted 1 line
Jeff
So how do we manage mac address to RX queue association?
This is not about multiple RX queues but filtering multiple unicast addresses without going to promiscous mode. The addresses are used by something outside the driver, like macvlan.