From 550534413c31d7c91181305962fc7fc982465ac0 Mon Sep 17 00:00:00 2001 From: Danny Kukawka Date: Wed, 15 Feb 2012 15:13:19 -0800 Subject: [PATCH] datapath: use eth_hw_addr_random() and reset addr_assign_type Use eth_hw_addr_random() instead of calling random_ether_addr() to set addr_assign_type correctly to NET_ADDR_RANDOM. Reset the state to NET_ADDR_PERM as soon as the MAC get changed via .ndo_set_mac_address. Signed-off-by: Danny Kukawka [jesse: add backporting to older kernels] Signed-off-by: Jesse Gross --- AUTHORS | 1 + datapath/linux/Modules.mk | 1 + .../linux/compat/include/linux/etherdevice.h | 19 +++++++++++++++++++ datapath/vport-internal_dev.c | 5 ++++- 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 datapath/linux/compat/include/linux/etherdevice.h diff --git a/AUTHORS b/AUTHORS index 58f7eccd..84908a9a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -14,6 +14,7 @@ Chuck Short zulcss@ubuntu.com Dan Carpenter dan.carpenter@oracle.com Dan Wendlandt dan@nicira.com Daniel Roman droman@nicira.com +Danny Kukawka danny.kukawka@bisect.de David Erickson derickso@stanford.edu Devendra Naga devendra.aaru@gmail.com Dominic Curran dominic.curran@citrix.com diff --git a/datapath/linux/Modules.mk b/datapath/linux/Modules.mk index 7f54bde4..97d977b7 100644 --- a/datapath/linux/Modules.mk +++ b/datapath/linux/Modules.mk @@ -18,6 +18,7 @@ openvswitch_headers += \ linux/compat/include/linux/cpumask.h \ linux/compat/include/linux/dmi.h \ linux/compat/include/linux/err.h \ + linux/compat/include/linux/etherdevice.h \ linux/compat/include/linux/flex_array.h \ linux/compat/include/linux/genetlink.h \ linux/compat/include/linux/icmp.h \ diff --git a/datapath/linux/compat/include/linux/etherdevice.h b/datapath/linux/compat/include/linux/etherdevice.h new file mode 100644 index 00000000..7a8178e5 --- /dev/null +++ b/datapath/linux/compat/include/linux/etherdevice.h @@ -0,0 +1,19 @@ +#ifndef __LINUX_ETHERDEVICE_WRAPPER_H +#define __LINUX_ETHERDEVICE_WRAPPER_H 1 + +#include_next +#include + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) +static inline void eth_hw_addr_random(struct net_device *dev) +{ + random_ether_addr(dev->dev_addr); +} +#elif LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) +static inline void eth_hw_addr_random(struct net_device *dev) +{ + dev_hw_addr_random(dev, dev->dev_addr); +} +#endif + +#endif diff --git a/datapath/vport-internal_dev.c b/datapath/vport-internal_dev.c index 46b78d22..9647a617 100644 --- a/datapath/vport-internal_dev.c +++ b/datapath/vport-internal_dev.c @@ -87,6 +87,9 @@ static int internal_dev_mac_addr(struct net_device *dev, void *p) if (!is_valid_ether_addr(addr->sa_data)) return -EADDRNOTAVAIL; +#ifdef NET_ADDR_RANDOM + dev->addr_assign_type &= ~NET_ADDR_RANDOM; +#endif memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); return 0; } @@ -213,7 +216,7 @@ static void do_setup(struct net_device *netdev) #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39) netdev->hw_features = netdev->features & ~NETIF_F_LLTX; #endif - random_ether_addr(netdev->dev_addr); + eth_hw_addr_random(netdev); } static struct vport *internal_dev_create(const struct vport_parms *parms) -- 2.30.2