datapath: use eth_hw_addr_random() and reset addr_assign_type
authorDanny Kukawka <danny.kukawka@bisect.de>
Wed, 15 Feb 2012 23:13:19 +0000 (15:13 -0800)
committerJesse Gross <jesse@nicira.com>
Wed, 15 Feb 2012 23:16:36 +0000 (15:16 -0800)
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 <danny.kukawka@bisect.de>
[jesse: add backporting to older kernels]
Signed-off-by: Jesse Gross <jesse@nicira.com>
AUTHORS
datapath/linux/Modules.mk
datapath/linux/compat/include/linux/etherdevice.h [new file with mode: 0644]
datapath/vport-internal_dev.c

diff --git a/AUTHORS b/AUTHORS
index 58f7eccd32615f58d95db3abb86394bc26e6fd82..84908a9a97a4d7a201f6b9cee2dbec8a0fafac7e 100644 (file)
--- 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
index 7f54bde434b1241bdc2e87f86833f9cd09489775..97d977b72e19f3422e8a6749c409fc784ffafa51 100644 (file)
@@ -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 (file)
index 0000000..7a8178e
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef __LINUX_ETHERDEVICE_WRAPPER_H
+#define __LINUX_ETHERDEVICE_WRAPPER_H 1
+
+#include_next <linux/etherdevice.h>
+#include <linux/version.h>
+
+#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
index 46b78d226d20d5729b05b7a3bb1fda91c2f26d4d..9647a617c9f57d1f7ee20e973dffb60c82511f86 100644 (file)
@@ -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)