2012-02-08 21:15:28

by Danny Kukawka

[permalink] [raw]
Subject: [RFC][PATCH 00/50] set addr_assign_type to NET_ADDR_RANDOM if a random mac address get assigned to a netdevice

The information if a device has a random MAC address is exported
to the userspace via /sys/class/net/*/addr_assign_type, which
export net_device->addr_assign_type.

Currently only a few driver really use dev_hw_addr_random() to
set addr_assign_type correctly to NET_ADDR_RANDOM.

This patch change the drivers which set random addresses to
change also addr_assign_type to NET_ADDR_RANDOM.

To reflect if the MAC was changed from userspace via SIOCSIFHWADDR,
which means it's no longer a random address set by the kernel,
this patch remove NET_ADDR_RANDOM from addr_assign_type in this
case.

With this patch tools from userspace can now detect devices with
random MAC addresses and change them to persistent addresses if
needed (as e.g. in case of smsc95xx on PandaBoard).

Maybe it makes sense to introduce a new state for addr_assign_type
to reflect the fact, that the MAC address was changed via a ioctl
from user space, e.g, with NET_ADDR_USERSPACE ?

Danny Kukawka (50):
eth: reset addr_assign_type if eth_mac_addr() called
smsc95xx: use dev_hw_addr_random() instead of random_ether_addr()
smsc75xx: se dev_hw_addr_random() instead of random_ether_addr()
adi/blackfin: set addr_assign_type correctly if random
UML net: set addr_assign_type if random_ether_addr() used
dummy: use dev_hw_addr_random() instead of random_ether_addr()
au1000_eth: use dev_hw_addr_random() instead of random_ether_addr()
bnx2x: use dev_hw_addr_random() instead of random_ether_addr()
Cadence MACB: use dev_hw_addr_random() instead of random_ether_addr()
Calxeda XGMAC: use dev_hw_addr_random() instead of
random_ether_addr()
ep93xx: use dev_hw_addr_random() instead of random_ether_addr()
dm9000: use dev_hw_addr_random() instead of random_ether_addr()
dnet: use dev_hw_addr_random() instead of random_ether_addr()
ethoc: set addr_assign_type if random_ether_addr() used
lantiq_etop: set addr_assign_type if random_ether_addr() used
pxa168_eth: use dev_hw_addr_random() instead of random_ether_addr()
enc28j60: use dev_hw_addr_random() instead of random_ether_addr()
mipsnet: use dev_hw_addr_random() instead of random_ether_addr()
macsonic: use dev_hw_addr_random() instead of random_ether_addr()
smsc911x: use dev_hw_addr_random() instead of random_ether_addr()
smsc9420: use dev_hw_addr_random() instead of random_ether_addr()
r6040: use dev_hw_addr_random() instead of random_ether_addr()
efx: use dev_hw_addr_random() instead of random_ether_addr()
sis900: use dev_hw_addr_random() instead of random_ether_addr()
via-rhine: use dev_hw_addr_random() instead of random_ether_addr()
faraday: use dev_hw_addr_random() instead of random_ether_addr()
davinci_emac: use dev_hw_addr_random() instead of random_ether_addr()
forcedeth: use dev_hw_addr_random() instead of random_ether_addr()
micrel eth: use dev_hw_addr_random() instead of random_ether_addr()
atheros eth: set addr_assign_type if random_ether_addr() used
tc35815: use dev_hw_addr_random() instead of random_ether_addr()
tile_net: use dev_hw_addr_random() instead of random_ether_addr()
stmmac: use dev_hw_addr_random() instead of random_ether_addr()
xilinx ll_temac: use dev_hw_addr_random() instead of
random_ether_addr()
ifb: use dev_hw_addr_random() instead of random_ether_addr()
igbvf: reset netdevice addr_assign_type if changed from random
usbnet: set addr_assign_type if random_ether_addr() used
g_ether: set addr_assign_type if random_ether_addr() used
veth: use dev_hw_addr_random() instead of random_ether_addr()
batman-adv: use dev_hw_addr_random() instead of random_ether_addr()
l2tp_eth: use dev_hw_addr_random() instead of random_ether_addr()
virtio_net: use dev_hw_addr_random() instead of random_ether_addr()
macvlan: use dev_hw_addr_random() instead of random_ether_addr()
team: use dev_hw_addr_random() instead of random_ether_addr()
tun: use dev_hw_addr_random() instead of random_ether_addr()
wan: use dev_hw_addr_random() instead of random_ether_addr()
bridge: use dev_hw_addr_random() instead of random_ether_addr()
ip_gre.c: use dev_hw_addr_random() instead of random_ether_addr()
openvswitch: use dev_hw_addr_random() instead of random_ether_addr()
use dev_hw_addr_random() instead of random_ether_addr()

arch/blackfin/mach-bf518/boards/ezbrd.c | 3 ++-
arch/blackfin/mach-bf518/boards/tcm-bf518.c | 3 ++-
arch/blackfin/mach-bf527/boards/ad7160eval.c | 3 ++-
arch/blackfin/mach-bf527/boards/cm_bf527.c | 3 ++-
arch/blackfin/mach-bf527/boards/ezbrd.c | 3 ++-
arch/blackfin/mach-bf527/boards/ezkit.c | 3 ++-
arch/blackfin/mach-bf527/boards/tll6527m.c | 3 ++-
arch/blackfin/mach-bf537/boards/cm_bf537e.c | 3 ++-
arch/blackfin/mach-bf537/boards/cm_bf537u.c | 3 ++-
arch/blackfin/mach-bf537/boards/dnp5370.c | 3 ++-
arch/blackfin/mach-bf537/boards/pnav10.c | 3 ++-
arch/blackfin/mach-bf537/boards/stamp.c | 3 ++-
arch/blackfin/mach-bf537/boards/tcm_bf537.c | 3 ++-
arch/um/drivers/net_kern.c | 11 ++++++++---
drivers/net/dummy.c | 4 +++-
drivers/net/ethernet/adi/bfin_mac.c | 10 +++++++---
drivers/net/ethernet/adi/bfin_mac.h | 2 +-
drivers/net/ethernet/amd/au1000_eth.c | 9 +++++----
drivers/net/ethernet/atheros/atl1c/atl1c_hw.c | 2 +-
drivers/net/ethernet/atheros/atl1c/atl1c_main.c | 11 ++++++-----
drivers/net/ethernet/atheros/atlx/atl1.c | 12 +++++++++---
drivers/net/ethernet/atheros/atlx/atlx.c | 3 +++
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 2 ++
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 2 +-
drivers/net/ethernet/cadence/macb.c | 2 +-
drivers/net/ethernet/calxeda/xgmac.c | 4 +++-
drivers/net/ethernet/cirrus/ep93xx_eth.c | 2 +-
drivers/net/ethernet/cisco/enic/enic_main.c | 13 +++++++++++--
drivers/net/ethernet/davicom/dm9000.c | 2 +-
drivers/net/ethernet/dnet.c | 2 +-
drivers/net/ethernet/ethoc.c | 11 ++++++++++-
drivers/net/ethernet/faraday/ftgmac100.c | 2 +-
drivers/net/ethernet/faraday/ftmac100.c | 2 +-
drivers/net/ethernet/intel/igbvf/netdev.c | 2 ++
drivers/net/ethernet/lantiq_etop.c | 4 ++++
drivers/net/ethernet/marvell/pxa168_eth.c | 4 +++-
drivers/net/ethernet/micrel/ks8842.c | 4 +++-
drivers/net/ethernet/micrel/ks8851.c | 7 +++++--
drivers/net/ethernet/micrel/ks8851_mll.c | 4 +++-
drivers/net/ethernet/microchip/enc28j60.c | 5 ++++-
drivers/net/ethernet/mipsnet.c | 2 +-
drivers/net/ethernet/natsemi/macsonic.c | 2 +-
drivers/net/ethernet/nvidia/forcedeth.c | 4 +++-
drivers/net/ethernet/rdc/r6040.c | 2 +-
drivers/net/ethernet/sfc/efx.c | 4 +++-
drivers/net/ethernet/sis/sis900.c | 2 +-
drivers/net/ethernet/smsc/smsc911x.c | 4 +++-
drivers/net/ethernet/smsc/smsc9420.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
drivers/net/ethernet/ti/davinci_emac.c | 4 +++-
drivers/net/ethernet/tile/tilepro.c | 4 +++-
drivers/net/ethernet/toshiba/tc35815.c | 2 +-
drivers/net/ethernet/via/via-rhine.c | 2 +-
drivers/net/ethernet/xilinx/ll_temac_main.c | 11 +++++++++--
drivers/net/ifb.c | 2 +-
drivers/net/macvlan.c | 4 +++-
drivers/net/team/team.c | 5 ++++-
drivers/net/tun.c | 2 +-
drivers/net/usb/smsc75xx.c | 2 +-
drivers/net/usb/smsc95xx.c | 2 +-
drivers/net/usb/usbnet.c | 1 +
drivers/net/veth.c | 4 ++--
drivers/net/virtio_net.c | 2 +-
drivers/net/wan/hdlc_fr.c | 2 +-
drivers/net/wan/hdlc_raw_eth.c | 2 +-
drivers/usb/gadget/u_ether.c | 4 +++-
net/batman-adv/soft-interface.c | 7 ++++---
net/bridge/br_device.c | 6 +++++-
net/ethernet/eth.c | 4 ++++
net/ipv4/ip_gre.c | 2 +-
net/l2tp/l2tp_eth.c | 2 +-
net/openvswitch/vport-internal_dev.c | 4 +++-
72 files changed, 196 insertions(+), 85 deletions(-)

--
1.7.7.3


2012-02-08 21:11:21

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 02/50] smsc95xx: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/usb/smsc95xx.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index d45520e..3a28e95 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -614,7 +614,7 @@ static void smsc95xx_init_mac_address(struct usbnet *dev)
}

/* no eeprom, or eeprom values are invalid. generate random MAC */
- random_ether_addr(dev->net->dev_addr);
+ dev_hw_addr_random(dev->net , dev->net->dev_addr);
netif_dbg(dev, ifup, dev->net, "MAC address set to random_ether_addr\n");
}

--
1.7.7.3

2012-02-08 21:11:24

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 03/50] smsc75xx: se dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/usb/smsc75xx.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
index 3b017bb..aafa6cf 100644
--- a/drivers/net/usb/smsc75xx.c
+++ b/drivers/net/usb/smsc75xx.c
@@ -615,7 +615,7 @@ static void smsc75xx_init_mac_address(struct usbnet *dev)
}

/* no eeprom, or eeprom values are invalid. generate random MAC */
- random_ether_addr(dev->net->dev_addr);
+ dev_hw_addr_random(dev->net, dev->net->dev_addr);
netif_dbg(dev, ifup, dev->net, "MAC address set to random_ether_addr");
}

--
1.7.7.3

2012-02-08 21:11:37

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 04/50] adi/blackfin: set addr_assign_type correctly if random

Set the addr_assign_type for adi driver correctly to
NET_ADDR_RANDOM if a random MAC address was generated.
Reset the state to NET_ADDR_PERM as soon as the MAC get
changed via .ndo_set_mac_address.

Signed-off-by: Danny Kukawka <[email protected]>
---
arch/blackfin/mach-bf518/boards/ezbrd.c | 3 ++-
arch/blackfin/mach-bf518/boards/tcm-bf518.c | 3 ++-
arch/blackfin/mach-bf527/boards/ad7160eval.c | 3 ++-
arch/blackfin/mach-bf527/boards/cm_bf527.c | 3 ++-
arch/blackfin/mach-bf527/boards/ezbrd.c | 3 ++-
arch/blackfin/mach-bf527/boards/ezkit.c | 3 ++-
arch/blackfin/mach-bf527/boards/tll6527m.c | 3 ++-
arch/blackfin/mach-bf537/boards/cm_bf537e.c | 3 ++-
arch/blackfin/mach-bf537/boards/cm_bf537u.c | 3 ++-
arch/blackfin/mach-bf537/boards/dnp5370.c | 3 ++-
arch/blackfin/mach-bf537/boards/pnav10.c | 3 ++-
arch/blackfin/mach-bf537/boards/stamp.c | 3 ++-
arch/blackfin/mach-bf537/boards/tcm_bf537.c | 3 ++-
drivers/net/ethernet/adi/bfin_mac.c | 10 +++++++---
drivers/net/ethernet/adi/bfin_mac.h | 2 +-
15 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/arch/blackfin/mach-bf518/boards/ezbrd.c b/arch/blackfin/mach-bf518/boards/ezbrd.c
index a2d96d3..a173957 100644
--- a/arch/blackfin/mach-bf518/boards/ezbrd.c
+++ b/arch/blackfin/mach-bf518/boards/ezbrd.c
@@ -821,7 +821,7 @@ void native_machine_restart(char *cmd)
bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS);
}

-void bfin_get_ether_addr(char *addr)
+int bfin_get_ether_addr(char *addr)
{
/* the MAC is stored in OTP memory page 0xDF */
u32 ret;
@@ -834,5 +834,6 @@ void bfin_get_ether_addr(char *addr)
for (ret = 0; ret < 6; ++ret)
addr[ret] = otp_mac_p[5 - ret];
}
+ return 0;
}
EXPORT_SYMBOL(bfin_get_ether_addr);
diff --git a/arch/blackfin/mach-bf518/boards/tcm-bf518.c b/arch/blackfin/mach-bf518/boards/tcm-bf518.c
index f271310..d3c763e 100644
--- a/arch/blackfin/mach-bf518/boards/tcm-bf518.c
+++ b/arch/blackfin/mach-bf518/boards/tcm-bf518.c
@@ -730,9 +730,10 @@ void native_machine_restart(char *cmd)
bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS);
}

-void bfin_get_ether_addr(char *addr)
+int bfin_get_ether_addr(char *addr)
{
random_ether_addr(addr);
printk(KERN_WARNING "%s:%s: Setting Ethernet MAC to a random one\n", __FILE__, __func__);
+ return 1;
}
EXPORT_SYMBOL(bfin_get_ether_addr);
diff --git a/arch/blackfin/mach-bf527/boards/ad7160eval.c b/arch/blackfin/mach-bf527/boards/ad7160eval.c
index c8d5d2b..fad7fea 100644
--- a/arch/blackfin/mach-bf527/boards/ad7160eval.c
+++ b/arch/blackfin/mach-bf527/boards/ad7160eval.c
@@ -846,7 +846,7 @@ void native_machine_restart(char *cmd)
bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS);
}

-void bfin_get_ether_addr(char *addr)
+int bfin_get_ether_addr(char *addr)
{
/* the MAC is stored in OTP memory page 0xDF */
u32 ret;
@@ -859,5 +859,6 @@ void bfin_get_ether_addr(char *addr)
for (ret = 0; ret < 6; ++ret)
addr[ret] = otp_mac_p[5 - ret];
}
+ return 0;
}
EXPORT_SYMBOL(bfin_get_ether_addr);
diff --git a/arch/blackfin/mach-bf527/boards/cm_bf527.c b/arch/blackfin/mach-bf527/boards/cm_bf527.c
index 7330607..5fb09ad 100644
--- a/arch/blackfin/mach-bf527/boards/cm_bf527.c
+++ b/arch/blackfin/mach-bf527/boards/cm_bf527.c
@@ -983,9 +983,10 @@ void native_machine_restart(char *cmd)
bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS);
}

-void bfin_get_ether_addr(char *addr)
+int bfin_get_ether_addr(char *addr)
{
random_ether_addr(addr);
printk(KERN_WARNING "%s:%s: Setting Ethernet MAC to a random one\n", __FILE__, __func__);
+ return 1;
}
EXPORT_SYMBOL(bfin_get_ether_addr);
diff --git a/arch/blackfin/mach-bf527/boards/ezbrd.c b/arch/blackfin/mach-bf527/boards/ezbrd.c
index db3ecfc..17c6a24 100644
--- a/arch/blackfin/mach-bf527/boards/ezbrd.c
+++ b/arch/blackfin/mach-bf527/boards/ezbrd.c
@@ -870,7 +870,7 @@ void native_machine_restart(char *cmd)
bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS);
}

-void bfin_get_ether_addr(char *addr)
+int bfin_get_ether_addr(char *addr)
{
/* the MAC is stored in OTP memory page 0xDF */
u32 ret;
@@ -883,5 +883,6 @@ void bfin_get_ether_addr(char *addr)
for (ret = 0; ret < 6; ++ret)
addr[ret] = otp_mac_p[5 - ret];
}
+ return 0;
}
EXPORT_SYMBOL(bfin_get_ether_addr);
diff --git a/arch/blackfin/mach-bf527/boards/ezkit.c b/arch/blackfin/mach-bf527/boards/ezkit.c
index dfdd8e6..89b0f6c 100644
--- a/arch/blackfin/mach-bf527/boards/ezkit.c
+++ b/arch/blackfin/mach-bf527/boards/ezkit.c
@@ -1311,7 +1311,7 @@ void native_machine_restart(char *cmd)
bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS);
}

-void bfin_get_ether_addr(char *addr)
+int bfin_get_ether_addr(char *addr)
{
/* the MAC is stored in OTP memory page 0xDF */
u32 ret;
@@ -1324,5 +1324,6 @@ void bfin_get_ether_addr(char *addr)
for (ret = 0; ret < 6; ++ret)
addr[ret] = otp_mac_p[5 - ret];
}
+ return 0;
}
EXPORT_SYMBOL(bfin_get_ether_addr);
diff --git a/arch/blackfin/mach-bf527/boards/tll6527m.c b/arch/blackfin/mach-bf527/boards/tll6527m.c
index 360e97f..d192c0a 100644
--- a/arch/blackfin/mach-bf527/boards/tll6527m.c
+++ b/arch/blackfin/mach-bf527/boards/tll6527m.c
@@ -931,7 +931,7 @@ void native_machine_restart(char *cmd)
bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS);
}

-void bfin_get_ether_addr(char *addr)
+int bfin_get_ether_addr(char *addr)
{
/* the MAC is stored in OTP memory page 0xDF */
u32 ret;
@@ -945,5 +945,6 @@ void bfin_get_ether_addr(char *addr)
for (ret = 0; ret < 6; ++ret)
addr[ret] = otp_mac_p[5 - ret];
}
+ return 0;
}
EXPORT_SYMBOL(bfin_get_ether_addr);
diff --git a/arch/blackfin/mach-bf537/boards/cm_bf537e.c b/arch/blackfin/mach-bf537/boards/cm_bf537e.c
index 0d4a2f6..618fd7d 100644
--- a/arch/blackfin/mach-bf537/boards/cm_bf537e.c
+++ b/arch/blackfin/mach-bf537/boards/cm_bf537e.c
@@ -813,9 +813,10 @@ void __init native_machine_early_platform_add_devices(void)
ARRAY_SIZE(cm_bf537e_early_devices));
}

-void bfin_get_ether_addr(char *addr)
+int bfin_get_ether_addr(char *addr)
{
random_ether_addr(addr);
printk(KERN_WARNING "%s:%s: Setting Ethernet MAC to a random one\n", __FILE__, __func__);
+ return 1;
}
EXPORT_SYMBOL(bfin_get_ether_addr);
diff --git a/arch/blackfin/mach-bf537/boards/cm_bf537u.c b/arch/blackfin/mach-bf537/boards/cm_bf537u.c
index f553698..48a7a23 100644
--- a/arch/blackfin/mach-bf537/boards/cm_bf537u.c
+++ b/arch/blackfin/mach-bf537/boards/cm_bf537u.c
@@ -790,9 +790,10 @@ void __init native_machine_early_platform_add_devices(void)
ARRAY_SIZE(cm_bf537u_early_devices));
}

-void bfin_get_ether_addr(char *addr)
+int bfin_get_ether_addr(char *addr)
{
random_ether_addr(addr);
printk(KERN_WARNING "%s:%s: Setting Ethernet MAC to a random one\n", __FILE__, __func__);
+ return 1;
}
EXPORT_SYMBOL(bfin_get_ether_addr);
diff --git a/arch/blackfin/mach-bf537/boards/dnp5370.c b/arch/blackfin/mach-bf537/boards/dnp5370.c
index 11dadeb..6f77bf7 100644
--- a/arch/blackfin/mach-bf537/boards/dnp5370.c
+++ b/arch/blackfin/mach-bf537/boards/dnp5370.c
@@ -399,9 +399,10 @@ arch_initcall(dnp5370_init);
/*
* Currently the MAC address is saved in Flash by U-Boot
*/
-void bfin_get_ether_addr(char *addr)
+int bfin_get_ether_addr(char *addr)
{
*(u32 *)(&(addr[0])) = bfin_read32(FLASH_MAC);
*(u16 *)(&(addr[4])) = bfin_read16(FLASH_MAC + 4);
+ return 0;
}
EXPORT_SYMBOL(bfin_get_ether_addr);
diff --git a/arch/blackfin/mach-bf537/boards/pnav10.c b/arch/blackfin/mach-bf537/boards/pnav10.c
index 6fd8470..2a9cd61 100644
--- a/arch/blackfin/mach-bf537/boards/pnav10.c
+++ b/arch/blackfin/mach-bf537/boards/pnav10.c
@@ -535,9 +535,10 @@ void __init native_machine_early_platform_add_devices(void)
ARRAY_SIZE(stamp_early_devices));
}

-void bfin_get_ether_addr(char *addr)
+int bfin_get_ether_addr(char *addr)
{
random_ether_addr(addr);
printk(KERN_WARNING "%s:%s: Setting Ethernet MAC to a random one\n", __FILE__, __func__);
+ return 1;
}
EXPORT_SYMBOL(bfin_get_ether_addr);
diff --git a/arch/blackfin/mach-bf537/boards/stamp.c b/arch/blackfin/mach-bf537/boards/stamp.c
index 2221173..0b80725 100644
--- a/arch/blackfin/mach-bf537/boards/stamp.c
+++ b/arch/blackfin/mach-bf537/boards/stamp.c
@@ -2993,9 +2993,10 @@ void native_machine_restart(char *cmd)
* Currently the MAC address is saved in Flash by U-Boot
*/
#define FLASH_MAC 0x203f0000
-void bfin_get_ether_addr(char *addr)
+int bfin_get_ether_addr(char *addr)
{
*(u32 *)(&(addr[0])) = bfin_read32(FLASH_MAC);
*(u16 *)(&(addr[4])) = bfin_read16(FLASH_MAC + 4);
+ return 0;
}
EXPORT_SYMBOL(bfin_get_ether_addr);
diff --git a/arch/blackfin/mach-bf537/boards/tcm_bf537.c b/arch/blackfin/mach-bf537/boards/tcm_bf537.c
index 9885176..02eb9d0 100644
--- a/arch/blackfin/mach-bf537/boards/tcm_bf537.c
+++ b/arch/blackfin/mach-bf537/boards/tcm_bf537.c
@@ -780,9 +780,10 @@ void __init native_machine_early_platform_add_devices(void)
ARRAY_SIZE(cm_bf537_early_devices));
}

-void bfin_get_ether_addr(char *addr)
+int bfin_get_ether_addr(char *addr)
{
random_ether_addr(addr);
printk(KERN_WARNING "%s:%s: Setting Ethernet MAC to a random one\n", __FILE__, __func__);
+ return 1;
}
EXPORT_SYMBOL(bfin_get_ether_addr);
diff --git a/drivers/net/ethernet/adi/bfin_mac.c b/drivers/net/ethernet/adi/bfin_mac.c
index d812a10..064a3a6 100644
--- a/drivers/net/ethernet/adi/bfin_mac.c
+++ b/drivers/net/ethernet/adi/bfin_mac.c
@@ -621,6 +621,8 @@ static int bfin_mac_set_mac_address(struct net_device *dev, void *p)
if (netif_running(dev))
return -EBUSY;
memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
+ if (dev->addr_assign_type & NET_ADDR_RANDOM)
+ dev->addr_assign_type ^= NET_ADDR_RANDOM;
setup_mac_addr(dev->dev_addr);
return 0;
}
@@ -1496,12 +1498,14 @@ static int __devinit bfin_mac_probe(struct platform_device *pdev)
* Grab the MAC from the board somehow
* this is done in the arch/blackfin/mach-bfxxx/boards/eth_mac.c
*/
- if (!is_valid_ether_addr(ndev->dev_addr))
- bfin_get_ether_addr(ndev->dev_addr);
+ if (!is_valid_ether_addr(ndev->dev_addr)) {
+ if (bfin_get_ether_addr(ndev->dev_addr))
+ ndev->addr_assign_type |= NET_ADDR_RANDOM;
+ }

/* If still not valid, get a random one */
if (!is_valid_ether_addr(ndev->dev_addr))
- random_ether_addr(ndev->dev_addr);
+ dev_hw_addr_random(ndev, ndev->dev_addr);

setup_mac_addr(ndev->dev_addr);

diff --git a/drivers/net/ethernet/adi/bfin_mac.h b/drivers/net/ethernet/adi/bfin_mac.h
index f8559ac..960905c 100644
--- a/drivers/net/ethernet/adi/bfin_mac.h
+++ b/drivers/net/ethernet/adi/bfin_mac.h
@@ -101,6 +101,6 @@ struct bfin_mac_local {
#endif
};

-extern void bfin_get_ether_addr(char *addr);
+extern int bfin_get_ether_addr(char *addr);

#endif
--
1.7.7.3

2012-02-08 21:11:22

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 06/50] dummy: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_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 <[email protected]>
---
drivers/net/dummy.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
index 087648e..a766598 100644
--- a/drivers/net/dummy.c
+++ b/drivers/net/dummy.c
@@ -48,6 +48,8 @@ static int dummy_set_address(struct net_device *dev, void *p)
return -EADDRNOTAVAIL;

memcpy(dev->dev_addr, sa->sa_data, ETH_ALEN);
+ if (dev->addr_assign_type & NET_ADDR_RANDOM)
+ dev->addr_assign_type ^= NET_ADDR_RANDOM;
return 0;
}

@@ -135,7 +137,7 @@ static void dummy_setup(struct net_device *dev)
dev->flags &= ~IFF_MULTICAST;
dev->features |= NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO;
dev->features |= NETIF_F_HW_CSUM | NETIF_F_HIGHDMA | NETIF_F_LLTX;
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);
}

static int dummy_validate(struct nlattr *tb[], struct nlattr *data[])
--
1.7.7.3

2012-02-08 21:11:52

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 05/50] UML net: set addr_assign_type if random_ether_addr() used

Set addr_assign_type correctly to NET_ADDR_RANDOM in case
a random MAC address was generated and assigned to the netdevice.

Signed-off-by: Danny Kukawka <[email protected]>
---
arch/um/drivers/net_kern.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/um/drivers/net_kern.c b/arch/um/drivers/net_kern.c
index a492e59..5f274f0 100644
--- a/arch/um/drivers/net_kern.c
+++ b/arch/um/drivers/net_kern.c
@@ -293,7 +293,7 @@ static void uml_net_user_timer_expire(unsigned long _conn)
#endif
}

-static void setup_etheraddr(char *str, unsigned char *addr, char *name)
+static int setup_etheraddr(char *str, unsigned char *addr, char *name)
{
char *end;
int i;
@@ -334,12 +334,13 @@ static void setup_etheraddr(char *str, unsigned char *addr, char *name)
addr[0] | 0x02, addr[1], addr[2], addr[3], addr[4],
addr[5]);
}
- return;
+ return 0;

random:
printk(KERN_INFO
"Choosing a random ethernet address for device %s\n", name);
random_ether_addr(addr);
+ return 1;
}

static DEFINE_SPINLOCK(devices_lock);
@@ -391,6 +392,7 @@ static void eth_configure(int n, void *init, char *mac,
struct net_device *dev;
struct uml_net_private *lp;
int err, size;
+ int is_random;

size = transport->private_size + sizeof(struct uml_net_private);

@@ -417,7 +419,7 @@ static void eth_configure(int n, void *init, char *mac,
*/
snprintf(dev->name, sizeof(dev->name), "eth%d", n);

- setup_etheraddr(mac, device->mac, dev->name);
+ is_random = setup_etheraddr(mac, device->mac, dev->name);

printk(KERN_INFO "Netdevice %d (%pM) : ", n, device->mac);

@@ -474,6 +476,9 @@ static void eth_configure(int n, void *init, char *mac,

/* don't use eth_mac_addr, it will not work here */
memcpy(dev->dev_addr, device->mac, ETH_ALEN);
+ if (is_random)
+ dev->addr_assign_type |= NET_ADDR_RANDOM;
+
dev->mtu = transport->user->mtu;
dev->netdev_ops = &uml_netdev_ops;
dev->ethtool_ops = &uml_net_ethtool_ops;
--
1.7.7.3

2012-02-08 21:12:39

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 32/50] tile_net: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_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 <[email protected]>
---
drivers/net/ethernet/tile/tilepro.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/tile/tilepro.c b/drivers/net/ethernet/tile/tilepro.c
index d9951af..f007df4 100644
--- a/drivers/net/ethernet/tile/tilepro.c
+++ b/drivers/net/ethernet/tile/tilepro.c
@@ -2190,6 +2190,8 @@ static int tile_net_set_mac_address(struct net_device *dev, void *p)

/* ISSUE: Note that "dev_addr" is now a pointer. */
memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
+ if (dev->addr_assign_type & NET_ADDR_RANDOM)
+ dev->addr_assign_type ^= NET_ADDR_RANDOM;

return 0;
}
@@ -2254,7 +2256,7 @@ static int tile_net_get_mac(struct net_device *dev)
* can't get its MAC address, we are most likely running
* the simulator, so let's generate a random MAC address.
*/
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);
}

return 0;
--
1.7.7.3

2012-02-08 21:12:51

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 31/50] tc35815: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ethernet/toshiba/tc35815.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/toshiba/tc35815.c b/drivers/net/ethernet/toshiba/tc35815.c
index 71b785c..b5bb9ed 100644
--- a/drivers/net/ethernet/toshiba/tc35815.c
+++ b/drivers/net/ethernet/toshiba/tc35815.c
@@ -850,7 +850,7 @@ static int __devinit tc35815_init_one(struct pci_dev *pdev,
/* Retrieve the ethernet address. */
if (tc35815_init_dev_addr(dev)) {
dev_warn(&pdev->dev, "not valid ether addr\n");
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);
}

rc = register_netdev(dev);
--
1.7.7.3

2012-02-08 21:13:13

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 30/50] atheros eth: set addr_assign_type if random_ether_addr() used

Set addr_assign_type correctly to NET_ADDR_RANDOM in case
a random MAC address was generated and assigned to the netdevice.

Reset the state to NET_ADDR_PERM as soon as the MAC get
changed via .ndo_set_mac_address.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ethernet/atheros/atl1c/atl1c_hw.c | 2 +-
drivers/net/ethernet/atheros/atl1c/atl1c_main.c | 11 ++++++-----
drivers/net/ethernet/atheros/atlx/atl1.c | 12 +++++++++---
drivers/net/ethernet/atheros/atlx/atlx.c | 3 +++
4 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/atheros/atl1c/atl1c_hw.c b/drivers/net/ethernet/atheros/atl1c/atl1c_hw.c
index 23f2ab0..bd1667c 100644
--- a/drivers/net/ethernet/atheros/atl1c/atl1c_hw.c
+++ b/drivers/net/ethernet/atheros/atl1c/atl1c_hw.c
@@ -224,7 +224,7 @@ int atl1c_read_mac_addr(struct atl1c_hw *hw)
random_ether_addr(hw->perm_mac_addr);

memcpy(hw->mac_addr, hw->perm_mac_addr, sizeof(hw->perm_mac_addr));
- return 0;
+ return err;
}

/*
diff --git a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c
index b859124..edc0442 100644
--- a/drivers/net/ethernet/atheros/atl1c/atl1c_main.c
+++ b/drivers/net/ethernet/atheros/atl1c/atl1c_main.c
@@ -467,6 +467,9 @@ static int atl1c_set_mac_addr(struct net_device *netdev, void *p)
return -EBUSY;

memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
+ /* reset to NET_ADDR_PERM if was random */
+ if (netdev->addr_assign_type & NET_ADDR_RANDOM)
+ netdev->addr_assign_type ^= NET_ADDR_RANDOM;
memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);

atl1c_hw_set_mac_addr(&adapter->hw);
@@ -2746,10 +2749,9 @@ static int __devinit atl1c_probe(struct pci_dev *pdev,
err = -EIO;
goto err_reset;
}
- if (atl1c_read_mac_addr(&adapter->hw) != 0) {
- err = -EIO;
- dev_err(&pdev->dev, "get mac address failed\n");
- goto err_eeprom;
+ if (atl1c_read_mac_addr(&adapter->hw)) {
+ /* got a random MAC address, set NET_ADDR_RANDOM to netdev */
+ netdev->addr_assign_type |= NET_ADDR_RANDOM;
}
memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
@@ -2774,7 +2776,6 @@ static int __devinit atl1c_probe(struct pci_dev *pdev,
err_reset:
err_register:
err_sw_init:
-err_eeprom:
iounmap(adapter->hw.hw_addr);
err_init_netdev:
err_ioremap:
diff --git a/drivers/net/ethernet/atheros/atlx/atl1.c b/drivers/net/ethernet/atheros/atlx/atl1.c
index 9bd2049..40ac414 100644
--- a/drivers/net/ethernet/atheros/atlx/atl1.c
+++ b/drivers/net/ethernet/atheros/atlx/atl1.c
@@ -534,14 +534,17 @@ static int atl1_get_permanent_address(struct atl1_hw *hw)
*/
static s32 atl1_read_mac_addr(struct atl1_hw *hw)
{
+ s32 ret = 0;
u16 i;

- if (atl1_get_permanent_address(hw))
+ if (atl1_get_permanent_address(hw)) {
random_ether_addr(hw->perm_mac_addr);
+ ret = 1;
+ }

for (i = 0; i < ETH_ALEN; i++)
hw->mac_addr[i] = hw->perm_mac_addr[i];
- return 0;
+ return ret;
}

/*
@@ -3007,7 +3010,10 @@ static int __devinit atl1_probe(struct pci_dev *pdev,
}

/* copy the MAC address out of the EEPROM */
- atl1_read_mac_addr(&adapter->hw);
+ if (atl1_read_mac_addr(&adapter->hw)) {
+ /* mark random mac */
+ netdev->addr_assign_type |= NET_ADDR_RANDOM;
+ }
memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);

if (!is_valid_ether_addr(netdev->dev_addr)) {
diff --git a/drivers/net/ethernet/atheros/atlx/atlx.c b/drivers/net/ethernet/atheros/atlx/atlx.c
index 8ff7411..77d2925 100644
--- a/drivers/net/ethernet/atheros/atlx/atlx.c
+++ b/drivers/net/ethernet/atheros/atlx/atlx.c
@@ -83,6 +83,9 @@ static int atlx_set_mac(struct net_device *netdev, void *p)
return -EADDRNOTAVAIL;

memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
+ /* reset to NET_ADDR_PERM if was random */
+ if (netdev->addr_assign_type & NET_ADDR_RANDOM)
+ netdev->addr_assign_type ^= NET_ADDR_RANDOM;
memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);

atlx_set_mac_addr(&adapter->hw);
--
1.7.7.3

2012-02-08 21:13:20

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 29/50] micrel eth: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_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 <[email protected]>
---
drivers/net/ethernet/micrel/ks8842.c | 4 +++-
drivers/net/ethernet/micrel/ks8851.c | 7 +++++--
drivers/net/ethernet/micrel/ks8851_mll.c | 4 +++-
3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/micrel/ks8842.c b/drivers/net/ethernet/micrel/ks8842.c
index 0a85690..5bba69a 100644
--- a/drivers/net/ethernet/micrel/ks8842.c
+++ b/drivers/net/ethernet/micrel/ks8842.c
@@ -1081,6 +1081,8 @@ static int ks8842_set_mac(struct net_device *netdev, void *p)
return -EADDRNOTAVAIL;

memcpy(netdev->dev_addr, mac, netdev->addr_len);
+ if (netdev->addr_assign_type & NET_ADDR_RANDOM)
+ netdev->addr_assign_type ^= NET_ADDR_RANDOM;

ks8842_write_mac_addr(adapter, mac);
return 0;
@@ -1211,7 +1213,7 @@ static int __devinit ks8842_probe(struct platform_device *pdev)
ks8842_read_mac_addr(adapter, netdev->dev_addr);

if (!is_valid_ether_addr(netdev->dev_addr))
- random_ether_addr(netdev->dev_addr);
+ dev_hw_addr_random(netdev, netdev->dev_addr);
}

id = ks8842_read16(adapter, 32, REG_SW_ID_AND_ENABLE);
diff --git a/drivers/net/ethernet/micrel/ks8851.c b/drivers/net/ethernet/micrel/ks8851.c
index 6b35e7d..49537d4 100644
--- a/drivers/net/ethernet/micrel/ks8851.c
+++ b/drivers/net/ethernet/micrel/ks8851.c
@@ -422,7 +422,7 @@ static void ks8851_read_mac_addr(struct net_device *dev)
*
* Get or create the initial mac address for the device and then set that
* into the station address register. If there is an EEPROM present, then
- * we try that. If no valid mac address is found we use random_ether_addr()
+ * we try that. If no valid mac address is found we use dev_hw_addr_random()
* to create a new one.
*/
static void ks8851_init_mac(struct ks8851_net *ks)
@@ -439,7 +439,7 @@ static void ks8851_init_mac(struct ks8851_net *ks)
dev->dev_addr);
}

- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);
ks8851_write_mac_addr(dev);
}

@@ -1051,6 +1051,9 @@ static int ks8851_set_mac_address(struct net_device *dev, void *addr)
return -EADDRNOTAVAIL;

memcpy(dev->dev_addr, sa->sa_data, ETH_ALEN);
+ if (dev->addr_assign_type & NET_ADDR_RANDOM)
+ dev->addr_assign_type ^= NET_ADDR_RANDOM;
+
return ks8851_write_mac_addr(dev);
}

diff --git a/drivers/net/ethernet/micrel/ks8851_mll.c b/drivers/net/ethernet/micrel/ks8851_mll.c
index e58e78e..1fa93b6 100644
--- a/drivers/net/ethernet/micrel/ks8851_mll.c
+++ b/drivers/net/ethernet/micrel/ks8851_mll.c
@@ -1242,6 +1242,8 @@ static int ks_set_mac_address(struct net_device *netdev, void *paddr)
u8 *da;

memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
+ if (netdev->addr_assign_type & NET_ADDR_RANDOM)
+ netdev->addr_assign_type ^= NET_ADDR_RANDOM;

da = (u8 *)netdev->dev_addr;

@@ -1609,7 +1611,7 @@ static int __devinit ks8851_probe(struct platform_device *pdev)
* comment out the 2 functions below.
*/

- random_ether_addr(netdev->dev_addr);
+ dev_hw_addr_random(netdev, netdev->dev_addr);
ks_set_mac(ks, netdev->dev_addr);

id = ks_rdreg16(ks, KS_CIDER);
--
1.7.7.3

2012-02-08 21:13:42

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 27/50] davinci_emac: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_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 <[email protected]>
---
drivers/net/ethernet/ti/davinci_emac.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c
index 794ac30..fba3f74 100644
--- a/drivers/net/ethernet/ti/davinci_emac.c
+++ b/drivers/net/ethernet/ti/davinci_emac.c
@@ -1260,6 +1260,8 @@ static int emac_dev_setmac_addr(struct net_device *ndev, void *addr)
/* Store mac addr in priv and rx channel and set it in EMAC hw */
memcpy(priv->mac_addr, sa->sa_data, ndev->addr_len);
memcpy(ndev->dev_addr, sa->sa_data, ndev->addr_len);
+ if (ndev->addr_assign_type & NET_ADDR_RANDOM)
+ ndev->addr_assign_type ^= NET_ADDR_RANDOM;

/* MAC address is configured only after the interface is enabled. */
if (netif_running(ndev)) {
@@ -1897,7 +1899,7 @@ static int __devinit davinci_emac_probe(struct platform_device *pdev)

if (!is_valid_ether_addr(priv->mac_addr)) {
/* Use random MAC if none passed */
- random_ether_addr(priv->mac_addr);
+ dev_hw_addr_random(ndev, priv->mac_addr);
dev_warn(&pdev->dev, "using random MAC addr: %pM\n",
priv->mac_addr);
}
--
1.7.7.3

2012-02-08 21:11:20

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 01/50] eth: reset addr_assign_type if eth_mac_addr() called

If eth_mac_addr() get called, usually if SIOCSIFHWADDR was
used to change the MAC of a ethernet device, reset the
addr_assign_type to NET_ADDR_PERM if the state was
NET_ADDR_RANDOM before. Reset the state since the MAC is
no longer random at least not from the kernel side.

Signed-off-by: Danny Kukawka <[email protected]>
---
net/ethernet/eth.c | 4 ++++
1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index a246836..9d68142 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -288,6 +288,10 @@ int eth_mac_addr(struct net_device *dev, void *p)
if (!is_valid_ether_addr(addr->sa_data))
return -EADDRNOTAVAIL;
memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
+ /* if device marked as NET_ADDR_RANDOM, reset it */
+ if (dev->addr_assign_type & NET_ADDR_RANDOM)
+ dev->addr_assign_type ^= NET_ADDR_RANDOM;
+
return 0;
}
EXPORT_SYMBOL(eth_mac_addr);
--
1.7.7.3

2012-02-08 21:11:18

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 09/50] Cadence MACB: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ethernet/cadence/macb.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index 2320068..3ee8d79 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -87,7 +87,7 @@ static void __init macb_get_hwaddr(struct macb *bp)
memcpy(bp->dev->dev_addr, addr, sizeof(addr));
} else {
netdev_info(bp->dev, "invalid hw address, using random\n");
- random_ether_addr(bp->dev->dev_addr);
+ dev_hw_addr_random(bp->dev, bp->dev->dev_addr);
}
}

--
1.7.7.3

2012-02-08 21:11:17

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 08/50] bnx2x: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_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 <[email protected]>
---
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 2 ++
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 2 +-
2 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index 03f3935..c21acf3 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -3009,6 +3009,8 @@ int bnx2x_change_mac_addr(struct net_device *dev, void *p)
}

memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
+ if (dev->addr_assign_type & NET_ADDR_RANDOM)
+ dev->addr_assign_type ^= NET_ADDR_RANDOM;

if (netif_running(dev))
rc = bnx2x_set_eth_mac(bp, true);
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 1e3f978..ff82dc9 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -9605,7 +9605,7 @@ static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)

if (BP_NOMCP(bp)) {
BNX2X_ERROR("warning: random MAC workaround active\n");
- random_ether_addr(bp->dev->dev_addr);
+ dev_hw_addr_random(bp->dev, bp->dev->dev_addr);
} else if (IS_MF(bp)) {
val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
--
1.7.7.3

2012-02-08 21:15:26

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 07/50] au1000_eth: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ethernet/amd/au1000_eth.c | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/amd/au1000_eth.c b/drivers/net/ethernet/amd/au1000_eth.c
index 8b95dd3..5683c06 100644
--- a/drivers/net/ethernet/amd/au1000_eth.c
+++ b/drivers/net/ethernet/amd/au1000_eth.c
@@ -1130,9 +1130,6 @@ static int __devinit au1000_probe(struct platform_device *pdev)

au1000_setup_hw_rings(aup, aup->macdma);

- /* set a random MAC now in case platform_data doesn't provide one */
- random_ether_addr(dev->dev_addr);
-
writel(0, aup->enable);
aup->mac_enabled = 0;

@@ -1142,8 +1139,12 @@ static int __devinit au1000_probe(struct platform_device *pdev)
" PHY search on MAC0\n");
aup->phy1_search_mac0 = 1;
} else {
- if (is_valid_ether_addr(pd->mac))
+ if (is_valid_ether_addr(pd->mac)) {
memcpy(dev->dev_addr, pd->mac, 6);
+ } else {
+ /*set a random MAC if not provided by platform_data*/
+ dev_hw_addr_random(dev, dev->dev_addr);
+ }

aup->phy_static_config = pd->phy_static_config;
aup->phy_search_highest_addr = pd->phy_search_highest_addr;
--
1.7.7.3

2012-02-08 21:17:07

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 28/50] forcedeth: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_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 <[email protected]>
---
drivers/net/ethernet/nvidia/forcedeth.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/nvidia/forcedeth.c b/drivers/net/ethernet/nvidia/forcedeth.c
index 4c4e7f4..60176ad 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -3022,6 +3022,8 @@ static int nv_set_mac_address(struct net_device *dev, void *addr)

/* synchronized against open : rtnl_lock() held by caller */
memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN);
+ if (dev->addr_assign_type & NET_ADDR_RANDOM)
+ dev->addr_assign_type ^= NET_ADDR_RANDOM;

if (netif_running(dev)) {
netif_tx_lock_bh(dev);
@@ -5741,7 +5743,7 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
dev_err(&pci_dev->dev,
"Invalid MAC address detected: %pM - Please complain to your hardware vendor.\n",
dev->dev_addr);
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);
dev_err(&pci_dev->dev,
"Using random MAC address: %pM\n", dev->dev_addr);
}
--
1.7.7.3

2012-02-08 21:17:13

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 16/50] pxa168_eth: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_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 <[email protected]>
---
drivers/net/ethernet/marvell/pxa168_eth.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/marvell/pxa168_eth.c b/drivers/net/ethernet/marvell/pxa168_eth.c
index 953ba58..76a5189 100644
--- a/drivers/net/ethernet/marvell/pxa168_eth.c
+++ b/drivers/net/ethernet/marvell/pxa168_eth.c
@@ -630,6 +630,8 @@ static int pxa168_eth_set_mac_address(struct net_device *dev, void *addr)
return -EINVAL;
memcpy(oldMac, dev->dev_addr, ETH_ALEN);
memcpy(dev->dev_addr, sa->sa_data, ETH_ALEN);
+ if (dev->addr_assign_type & NET_ADDR_RANDOM)
+ dev->addr_assign_type ^= NET_ADDR_RANDOM;
netif_addr_lock_bh(dev);
update_hash_table_mac_address(pep, oldMac, dev->dev_addr);
netif_addr_unlock_bh(dev);
@@ -1522,7 +1524,7 @@ static int pxa168_eth_probe(struct platform_device *pdev)
INIT_WORK(&pep->tx_timeout_task, pxa168_eth_tx_timeout_task);

printk(KERN_INFO "%s:Using random mac address\n", DRIVER_NAME);
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);

pep->pd = pdev->dev.platform_data;
pep->rx_ring_size = NUM_RX_DESCS;
--
1.7.7.3

2012-02-08 21:17:44

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 49/50] openvswitch: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_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 <[email protected]>
---
net/openvswitch/vport-internal_dev.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c
index 322b8d2..c71baf0 100644
--- a/net/openvswitch/vport-internal_dev.c
+++ b/net/openvswitch/vport-internal_dev.c
@@ -67,6 +67,8 @@ static int internal_dev_mac_addr(struct net_device *dev, void *p)
if (!is_valid_ether_addr(addr->sa_data))
return -EADDRNOTAVAIL;
memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
+ if (dev->addr_assign_type & NET_ADDR_RANDOM)
+ dev->addr_assign_type ^= NET_ADDR_RANDOM;
return 0;
}

@@ -145,7 +147,7 @@ static void do_setup(struct net_device *netdev)
netdev->vlan_features = netdev->features;
netdev->features |= NETIF_F_HW_VLAN_TX;
netdev->hw_features = netdev->features & ~NETIF_F_LLTX;
- random_ether_addr(netdev->dev_addr);
+ dev_hw_addr_random(netdev, netdev->dev_addr);
}

static struct vport *internal_dev_create(const struct vport_parms *parms)
--
1.7.7.3

2012-02-08 21:17:48

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 47/50] bridge: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_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 <[email protected]>
---
net/bridge/br_device.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
index 71773b0..a25ed22 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -172,6 +172,10 @@ static int br_set_mac_address(struct net_device *dev, void *p)
spin_lock_bh(&br->lock);
if (compare_ether_addr(dev->dev_addr, addr->sa_data)) {
memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
+ if (dev->addr_assign_type & NET_ADDR_RANDOM) {
+ /* set back to NET_ADDR_PERM */
+ dev->addr_assign_type ^= NET_ADDR_RANDOM;
+ }
br_fdb_change_mac_address(br, addr->sa_data);
br_stp_change_bridge_id(br, addr->sa_data);
}
@@ -334,7 +338,7 @@ void br_dev_setup(struct net_device *dev)
{
struct net_bridge *br = netdev_priv(dev);

- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);
ether_setup(dev);

dev->netdev_ops = &br_netdev_ops;
--
1.7.7.3

2012-02-08 21:17:52

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 48/50] ip_gre.c: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
net/ipv4/ip_gre.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 6b3ca5b..33371a9 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -1529,7 +1529,7 @@ static int ipgre_newlink(struct net *src_net, struct net_device *dev, struct nla
return -EEXIST;

if (dev->type == ARPHRD_ETHER && !tb[IFLA_ADDRESS])
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);

mtu = ipgre_tunnel_bind_dev(dev);
if (!tb[IFLA_MTU])
--
1.7.7.3

2012-02-08 21:18:29

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 14/50] ethoc: set addr_assign_type if random_ether_addr() used

Set addr_assign_type correctly to NET_ADDR_RANDOM in case
a random MAC address was generated and assigned to the netdevice.

Reset the state to NET_ADDR_PERM as soon as the MAC get
changed via .ndo_set_mac_address.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ethernet/ethoc.c | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/ethoc.c b/drivers/net/ethernet/ethoc.c
index 60f0e78..4f21471 100644
--- a/drivers/net/ethernet/ethoc.c
+++ b/drivers/net/ethernet/ethoc.c
@@ -780,6 +780,10 @@ static int ethoc_set_mac_address(struct net_device *dev, void *addr)
(mac[4] << 8) | (mac[5] << 0));
ethoc_write(priv, MAC_ADDR1, (mac[0] << 8) | (mac[1] << 0));

+ /* if device marked as NET_ADDR_RANDOM, reset it to NET_ADDR_PERM */
+ if (dev->addr_assign_type & NET_ADDR_RANDOM)
+ dev->addr_assign_type ^= NET_ADDR_RANDOM;
+
return 0;
}

@@ -909,6 +913,7 @@ static int __devinit ethoc_probe(struct platform_device *pdev)
unsigned int phy;
int num_bd;
int ret = 0;
+ bool random_mac = false;

/* allocate networking device */
netdev = alloc_etherdev(sizeof(struct ethoc));
@@ -1050,10 +1055,14 @@ static int __devinit ethoc_probe(struct platform_device *pdev)

/* Check the MAC again for validity, if it still isn't choose and
* program a random one. */
- if (!is_valid_ether_addr(netdev->dev_addr))
+ if (!is_valid_ether_addr(netdev->dev_addr)) {
random_ether_addr(netdev->dev_addr);
+ random_mac = true;
+ }

ethoc_set_mac_address(netdev, netdev->dev_addr);
+ if (random_mac)
+ netdev->addr_assign_type |= NET_ADDR_RANDOM;

/* register MII bus */
priv->mdio = mdiobus_alloc();
--
1.7.7.3

2012-02-08 21:18:21

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 17/50] enc28j60: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_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 <[email protected]>
---
drivers/net/ethernet/microchip/enc28j60.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/microchip/enc28j60.c b/drivers/net/ethernet/microchip/enc28j60.c
index 50055e0..2abf71d 100644
--- a/drivers/net/ethernet/microchip/enc28j60.c
+++ b/drivers/net/ethernet/microchip/enc28j60.c
@@ -528,6 +528,9 @@ static int enc28j60_set_mac_address(struct net_device *dev, void *addr)
return -EADDRNOTAVAIL;

memcpy(dev->dev_addr, address->sa_data, dev->addr_len);
+ if (dev->addr_assign_type & NET_ADDR_RANDOM)
+ dev->addr_assign_type ^= NET_ADDR_RANDOM;
+
return enc28j60_set_hw_macaddr(dev);
}

@@ -1579,7 +1582,7 @@ static int __devinit enc28j60_probe(struct spi_device *spi)
ret = -EIO;
goto error_irq;
}
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);
enc28j60_set_hw_macaddr(dev);

/* Board setup must set the relevant edge trigger type;
--
1.7.7.3

2012-02-08 21:20:23

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 13/50] dnet: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ethernet/dnet.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/dnet.c b/drivers/net/ethernet/dnet.c
index 925c9ba..9f88165 100644
--- a/drivers/net/ethernet/dnet.c
+++ b/drivers/net/ethernet/dnet.c
@@ -897,7 +897,7 @@ static int __devinit dnet_probe(struct platform_device *pdev)

if (!is_valid_ether_addr(dev->dev_addr)) {
/* choose a random ethernet address */
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);
__dnet_set_hwaddr(bp);
}

--
1.7.7.3

2012-02-08 21:20:30

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 10/50] Calxeda XGMAC: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_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 <[email protected]>
---
drivers/net/ethernet/calxeda/xgmac.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/calxeda/xgmac.c b/drivers/net/ethernet/calxeda/xgmac.c
index 1fce186..dedaaf0 100644
--- a/drivers/net/ethernet/calxeda/xgmac.c
+++ b/drivers/net/ethernet/calxeda/xgmac.c
@@ -1012,7 +1012,7 @@ static int xgmac_open(struct net_device *dev)
* address using the following linux command:
* ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx */
if (!is_valid_ether_addr(dev->dev_addr)) {
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);
netdev_dbg(priv->dev, "generated random MAC address %pM\n",
dev->dev_addr);
}
@@ -1483,6 +1483,8 @@ static int xgmac_set_mac_address(struct net_device *dev, void *p)
return -EADDRNOTAVAIL;

memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
+ if (dev->addr_assign_type & NET_ADDR_RANDOM)
+ dev->addr_assign_type ^= NET_ADDR_RANDOM;

xgmac_set_mac_addr(ioaddr, dev->dev_addr, 0);

--
1.7.7.3

2012-02-08 21:20:36

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 12/50] dm9000: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ethernet/davicom/dm9000.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/davicom/dm9000.c b/drivers/net/ethernet/davicom/dm9000.c
index f801754..8e04cab 100644
--- a/drivers/net/ethernet/davicom/dm9000.c
+++ b/drivers/net/ethernet/davicom/dm9000.c
@@ -1587,7 +1587,7 @@ dm9000_probe(struct platform_device *pdev)
dev_warn(db->dev, "%s: Invalid ethernet MAC address. Please "
"set using ifconfig\n", ndev->name);

- random_ether_addr(ndev->dev_addr);
+ dev_hw_addr_random(ndev, ndev->dev_addr);
mac_src = "random";
}

--
1.7.7.3

2012-02-08 21:20:48

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 15/50] lantiq_etop: set addr_assign_type if random_ether_addr() used

Set addr_assign_type correctly to NET_ADDR_RANDOM in case
a random MAC address was generated and assigned to the netdevice.

Reset the state to NET_ADDR_PERM as soon as the MAC get
changed via .ndo_set_mac_address.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ethernet/lantiq_etop.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/net/ethernet/lantiq_etop.c b/drivers/net/ethernet/lantiq_etop.c
index 85e2c6c..b4f5108 100644
--- a/drivers/net/ethernet/lantiq_etop.c
+++ b/drivers/net/ethernet/lantiq_etop.c
@@ -634,6 +634,7 @@ ltq_etop_init(struct net_device *dev)
struct ltq_etop_priv *priv = netdev_priv(dev);
struct sockaddr mac;
int err;
+ bool random = false;

ether_setup(dev);
dev->watchdog_timeo = 10 * HZ;
@@ -646,9 +647,12 @@ ltq_etop_init(struct net_device *dev)
if (!is_valid_ether_addr(mac.sa_data)) {
pr_warn("etop: invalid MAC, using random\n");
random_ether_addr(mac.sa_data);
+ random = true;
}

err = ltq_etop_set_mac_address(dev, &mac);
+ if (random)
+ dev->addr_assign_type |= NET_ADDR_RANDOM;
if (err)
goto err_netdev;
ltq_etop_set_multicast_list(dev);
--
1.7.7.3

2012-02-08 21:20:58

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 21/50] smsc9420: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ethernet/smsc/smsc9420.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/smsc/smsc9420.c b/drivers/net/ethernet/smsc/smsc9420.c
index a9efbdf..51013df 100644
--- a/drivers/net/ethernet/smsc/smsc9420.c
+++ b/drivers/net/ethernet/smsc/smsc9420.c
@@ -509,7 +509,7 @@ static void smsc9420_check_mac_address(struct net_device *dev)
smsc_dbg(PROBE, "Mac Address is read from EEPROM");
} else {
/* eeprom values are invalid, generate random MAC */
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);
smsc9420_set_mac_address(dev);
smsc_dbg(PROBE,
"MAC Address is set to random_ether_addr");
--
1.7.7.3

2012-02-08 21:21:04

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 19/50] macsonic: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ethernet/natsemi/macsonic.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/natsemi/macsonic.c b/drivers/net/ethernet/natsemi/macsonic.c
index f1b8556..c3819dc 100644
--- a/drivers/net/ethernet/natsemi/macsonic.c
+++ b/drivers/net/ethernet/natsemi/macsonic.c
@@ -307,7 +307,7 @@ static void __devinit mac_onboard_sonic_ethernet_addr(struct net_device *dev)

printk(KERN_WARNING "macsonic: MAC address in CAM entry 15 "
"seems invalid, will use a random MAC\n");
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);
}

static int __devinit mac_onboard_sonic_probe(struct net_device *dev)
--
1.7.7.3

2012-02-08 21:21:01

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 18/50] mipsnet: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ethernet/mipsnet.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/mipsnet.c b/drivers/net/ethernet/mipsnet.c
index d05b0c9..ebdd56c 100644
--- a/drivers/net/ethernet/mipsnet.c
+++ b/drivers/net/ethernet/mipsnet.c
@@ -281,7 +281,7 @@ static int __devinit mipsnet_probe(struct platform_device *dev)
* Lacking any better mechanism to allocate a MAC address we use a
* random one ...
*/
- random_ether_addr(netdev->dev_addr);
+ dev_hw_addr_random(netdev, netdev->dev_addr);

err = register_netdev(netdev);
if (err) {
--
1.7.7.3

2012-02-08 21:21:21

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 45/50] tun: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/tun.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 93c5d72..ace3f9c 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -531,7 +531,7 @@ static void tun_net_init(struct net_device *dev)
ether_setup(dev);
dev->priv_flags &= ~IFF_TX_SKB_SHARING;

- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);

dev->tx_queue_len = TUN_READQ_SIZE; /* We prefer our own queue length */
break;
--
1.7.7.3

2012-02-08 21:21:10

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 23/50] efx: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_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 <[email protected]>
---
drivers/net/ethernet/sfc/efx.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c
index e43702f..cce339a 100644
--- a/drivers/net/ethernet/sfc/efx.c
+++ b/drivers/net/ethernet/sfc/efx.c
@@ -940,7 +940,7 @@ static int efx_probe_port(struct efx_nic *efx)
rc = -EINVAL;
goto err;
}
- random_ether_addr(efx->net_dev->dev_addr);
+ dev_hw_addr_random(efx->net_dev, efx->net_dev->dev_addr);
netif_info(efx, probe, efx->net_dev,
"using locally-generated MAC %pM\n",
efx->net_dev->dev_addr);
@@ -1858,6 +1858,8 @@ static int efx_set_mac_address(struct net_device *net_dev, void *data)
}

memcpy(net_dev->dev_addr, new_addr, net_dev->addr_len);
+ if (net_dev->addr_assign_type & NET_ADDR_RANDOM)
+ net_dev->addr_assign_type ^= NET_ADDR_RANDOM;

/* Reconfigure the MAC */
mutex_lock(&efx->mac_lock);
--
1.7.7.3

2012-02-08 21:21:36

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 44/50] team: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_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 <[email protected]>
---
drivers/net/team/team.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
index 6b678f3..b67ebc4 100644
--- a/drivers/net/team/team.c
+++ b/drivers/net/team/team.c
@@ -869,6 +869,9 @@ static int team_set_mac_address(struct net_device *dev, void *p)
struct sockaddr *addr = p;

memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
+ if (dev->addr_assign_type & NET_ADDR_RANDOM)
+ dev->addr_assign_type ^= NET_ADDR_RANDOM;
+
rcu_read_lock();
list_for_each_entry_rcu(port, &team->port_list, list)
if (team->ops.port_change_mac)
@@ -1087,7 +1090,7 @@ static int team_newlink(struct net *src_net, struct net_device *dev,
int err;

if (tb[IFLA_ADDRESS] == NULL)
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);

err = register_netdevice(dev);
if (err)
--
1.7.7.3

2012-02-08 21:21:47

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 38/50] g_ether: set addr_assign_type if random_ether_addr() used

Set addr_assign_type correctly to NET_ADDR_RANDOM in case
a random MAC address was generated and assigned to the netdevice.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/usb/gadget/u_ether.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index 29c854b..984a1be 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -782,9 +782,11 @@ int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN])
dev->net = net;
strcpy(net->name, "usb%d");

- if (get_ether_addr(dev_addr, net->dev_addr))
+ if (get_ether_addr(dev_addr, net->dev_addr)) {
+ net->addr_assign_type |= NET_ADDR_RANDOM;
dev_warn(&g->dev,
"using random %s ethernet address\n", "self");
+ }
if (get_ether_addr(host_addr, dev->host_mac))
dev_warn(&g->dev,
"using random %s ethernet address\n", "host");
--
1.7.7.3

2012-02-08 21:21:39

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 43/50] macvlan: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_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 <[email protected]>
---
drivers/net/macvlan.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 9ea9921..bc4614e 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -373,6 +373,8 @@ static int macvlan_set_mac_address(struct net_device *dev, void *p)
if (!(dev->flags & IFF_UP)) {
/* Just copy in the new address */
memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
+ if (dev->addr_assign_type & NET_ADDR_RANDOM)
+ dev->addr_assign_type ^= NET_ADDR_RANDOM;
} else {
/* Rehash and update the device filters */
if (macvlan_addr_busy(vlan->port, addr->sa_data))
@@ -687,7 +689,7 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
return -EINVAL;

if (!tb[IFLA_ADDRESS])
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);

if (!macvlan_port_exists(lowerdev)) {
err = macvlan_port_create(lowerdev);
--
1.7.7.3

2012-02-08 21:21:42

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 40/50] batman-adv: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_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 <[email protected]>
---
net/batman-adv/soft-interface.c | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index 987c75a..865a485 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -541,6 +541,9 @@ static int interface_set_mac_addr(struct net_device *dev, void *p)
}

memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
+ if (dev->addr_assign_type & NET_ADDR_RANDOM)
+ dev->addr_assign_type ^= NET_ADDR_RANDOM;
+
return 0;
}

@@ -783,7 +786,6 @@ static const struct net_device_ops bat_netdev_ops = {
static void interface_setup(struct net_device *dev)
{
struct bat_priv *priv = netdev_priv(dev);
- char dev_addr[ETH_ALEN];

ether_setup(dev);

@@ -800,8 +802,7 @@ static void interface_setup(struct net_device *dev)
dev->hard_header_len = BAT_HEADER_LEN;

/* generate random address */
- random_ether_addr(dev_addr);
- memcpy(dev->dev_addr, dev_addr, ETH_ALEN);
+ dev_hw_addr_random(dev, dev->dev_addr);

SET_ETHTOOL_OPS(dev, &bat_ethtool_ops);

--
1.7.7.3

2012-02-08 21:21:53

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 35/50] ifb: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ifb.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
index e05b645..9ec2a86 100644
--- a/drivers/net/ifb.c
+++ b/drivers/net/ifb.c
@@ -184,7 +184,7 @@ static void ifb_setup(struct net_device *dev)
dev->flags |= IFF_NOARP;
dev->flags &= ~IFF_MULTICAST;
dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_TX_SKB_SHARING);
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);
}

static netdev_tx_t ifb_xmit(struct sk_buff *skb, struct net_device *dev)
--
1.7.7.3

2012-02-08 21:21:58

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 34/50] xilinx ll_temac: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_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 <[email protected]>
---
drivers/net/ethernet/xilinx/ll_temac_main.c | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/xilinx/ll_temac_main.c b/drivers/net/ethernet/xilinx/ll_temac_main.c
index f21addb..d687620 100644
--- a/drivers/net/ethernet/xilinx/ll_temac_main.c
+++ b/drivers/net/ethernet/xilinx/ll_temac_main.c
@@ -322,12 +322,19 @@ out:
static int temac_set_mac_address(struct net_device *ndev, void *address)
{
struct temac_local *lp = netdev_priv(ndev);
+ bool set_random = false;

if (address)
memcpy(ndev->dev_addr, address, ETH_ALEN);

- if (!is_valid_ether_addr(ndev->dev_addr))
- random_ether_addr(ndev->dev_addr);
+ if (!is_valid_ether_addr(ndev->dev_addr)) {
+ dev_hw_addr_random(ndev, ndev->dev_addr);
+ set_random = true;
+ }
+ if (!set_random) {
+ if (ndev->addr_assign_type & NET_ADDR_RANDOM)
+ ndev->addr_assign_type ^= NET_ADDR_RANDOM;
+ }

/* set up unicast MAC address filter set its mac address */
mutex_lock(&lp->indirect_mutex);
--
1.7.7.3

2012-02-08 21:22:14

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 42/50] virtio_net: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/virtio_net.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 4880aa8..69d36e1 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1061,7 +1061,7 @@ static int virtnet_probe(struct virtio_device *vdev)
if (virtio_config_val_len(vdev, VIRTIO_NET_F_MAC,
offsetof(struct virtio_net_config, mac),
dev->dev_addr, dev->addr_len) < 0)
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);

/* Set up our device-specific information */
vi = netdev_priv(dev);
--
1.7.7.3

2012-02-08 21:22:06

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 41/50] l2tp_eth: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
net/l2tp/l2tp_eth.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
index d2726a7..fa91e4e 100644
--- a/net/l2tp/l2tp_eth.c
+++ b/net/l2tp/l2tp_eth.c
@@ -64,7 +64,7 @@ static int l2tp_eth_dev_init(struct net_device *dev)
struct l2tp_eth *priv = netdev_priv(dev);

priv->dev = dev;
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);
memset(&dev->broadcast[0], 0xff, 6);

return 0;
--
1.7.7.3

2012-02-08 21:22:30

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 46/50] wan: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/wan/hdlc_fr.c | 2 +-
drivers/net/wan/hdlc_raw_eth.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c
index eb20281..579664c 100644
--- a/drivers/net/wan/hdlc_fr.c
+++ b/drivers/net/wan/hdlc_fr.c
@@ -1087,7 +1087,7 @@ static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type)
}

if (type == ARPHRD_ETHER)
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);
else {
*(__be16*)dev->dev_addr = htons(dlci);
dlci_to_q922(dev->broadcast, dlci);
diff --git a/drivers/net/wan/hdlc_raw_eth.c b/drivers/net/wan/hdlc_raw_eth.c
index 05c9b0b..0962a42 100644
--- a/drivers/net/wan/hdlc_raw_eth.c
+++ b/drivers/net/wan/hdlc_raw_eth.c
@@ -101,7 +101,7 @@ static int raw_eth_ioctl(struct net_device *dev, struct ifreq *ifr)
old_qlen = dev->tx_queue_len;
ether_setup(dev);
dev->tx_queue_len = old_qlen;
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);
netif_dormant_off(dev);
return 0;
}
--
1.7.7.3

2012-02-08 21:22:26

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 33/50] stmmac: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 96fa2da..e84bdb2 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -910,7 +910,7 @@ static void stmmac_check_ether_addr(struct stmmac_priv *priv)
priv->dev->base_addr,
priv->dev->dev_addr, 0);
if (!is_valid_ether_addr(priv->dev->dev_addr))
- random_ether_addr(priv->dev->dev_addr);
+ dev_hw_addr_random(priv->dev, priv->dev->dev_addr);
}
pr_warning("%s: device MAC address %pM\n", priv->dev->name,
priv->dev->dev_addr);
--
1.7.7.3

2012-02-08 21:22:23

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 36/50] igbvf: reset netdevice addr_assign_type if changed from random

Reset the state of addr_assign_type to NET_ADDR_PERM as soon as
the MAC get changed via .ndo_set_mac_address.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ethernet/intel/igbvf/netdev.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/net/ethernet/intel/igbvf/netdev.c b/drivers/net/ethernet/intel/igbvf/netdev.c
index a4b20c8..af652bf 100644
--- a/drivers/net/ethernet/intel/igbvf/netdev.c
+++ b/drivers/net/ethernet/intel/igbvf/netdev.c
@@ -1695,6 +1695,8 @@ static int igbvf_set_mac(struct net_device *netdev, void *p)
return -EADDRNOTAVAIL;

memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
+ if (netdev->addr_assign_type & NET_ADDR_RANDOM)
+ netdev->addr_assign_type ^= NET_ADDR_RANDOM;

return 0;
}
--
1.7.7.3

2012-02-08 21:24:14

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 39/50] veth: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/veth.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 49f4667..1dd466a 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -346,7 +346,7 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,
}

if (tbp[IFLA_ADDRESS] == NULL)
- random_ether_addr(peer->dev_addr);
+ dev_hw_addr_random(peer, peer->dev_addr);

err = register_netdevice(peer);
put_net(net);
@@ -368,7 +368,7 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,
*/

if (tb[IFLA_ADDRESS] == NULL)
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);

if (tb[IFLA_IFNAME])
nla_strlcpy(dev->name, tb[IFLA_IFNAME], IFNAMSIZ);
--
1.7.7.3

2012-02-08 21:24:49

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 37/50] usbnet: set addr_assign_type if random_ether_addr() used

Set addr_assign_type correctly to NET_ADDR_RANDOM in case
a random MAC address was generated and assigned to the netdevice.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/usb/usbnet.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index fae0fbd..7bd07d7 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -1365,6 +1365,7 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
dev->net = net;
strcpy (net->name, "usb%d");
memcpy (net->dev_addr, node_id, sizeof node_id);
+ net->addr_assign_type |= NET_ADDR_RANDOM;

/* rx and tx sides can use different message sizes;
* bind() should set rx_urb_size in that case.
--
1.7.7.3

2012-02-08 21:21:08

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 22/50] r6040: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ethernet/rdc/r6040.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/rdc/r6040.c b/drivers/net/ethernet/rdc/r6040.c
index cb0eca8..dba0a6a 100644
--- a/drivers/net/ethernet/rdc/r6040.c
+++ b/drivers/net/ethernet/rdc/r6040.c
@@ -1152,7 +1152,7 @@ static int __devinit r6040_init_one(struct pci_dev *pdev,
if (!(adrp[0] || adrp[1] || adrp[2])) {
netdev_warn(dev, "MAC address not initialized, "
"generating random\n");
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);
}

/* Link new device into r6040_root_dev */
--
1.7.7.3

2012-02-08 21:27:03

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 20/50] smsc911x: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_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 <[email protected]>
---
drivers/net/ethernet/smsc/smsc911x.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/smsc/smsc911x.c b/drivers/net/ethernet/smsc/smsc911x.c
index 24d2df0..92ab844 100644
--- a/drivers/net/ethernet/smsc/smsc911x.c
+++ b/drivers/net/ethernet/smsc/smsc911x.c
@@ -1834,6 +1834,8 @@ static int smsc911x_set_mac_address(struct net_device *dev, void *p)
return -EADDRNOTAVAIL;

memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
+ if (dev->addr_assign_type & NET_ADDR_RANDOM)
+ dev->addr_assign_type ^= NET_ADDR_RANDOM;

spin_lock_irq(&pdata->mac_lock);
smsc911x_set_hw_mac_address(pdata, dev->dev_addr);
@@ -2486,7 +2488,7 @@ static int __devinit smsc911x_drv_probe(struct platform_device *pdev)
"Mac Address is read from LAN911x EEPROM");
} else {
/* eeprom values are invalid, generate random MAC */
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);
smsc911x_set_hw_mac_address(pdata, dev->dev_addr);
SMSC_TRACE(pdata, probe,
"MAC Address is set to random_ether_addr");
--
1.7.7.3

2012-02-08 21:20:56

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 24/50] sis900: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ethernet/sis/sis900.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/sis/sis900.c b/drivers/net/ethernet/sis/sis900.c
index c8efc70..cbd0343 100644
--- a/drivers/net/ethernet/sis/sis900.c
+++ b/drivers/net/ethernet/sis/sis900.c
@@ -527,7 +527,7 @@ static int __devinit sis900_probe(struct pci_dev *pci_dev,
ret = sis900_get_mac_addr(pci_dev, net_dev);

if (!ret || !is_valid_ether_addr(net_dev->dev_addr)) {
- random_ether_addr(net_dev->dev_addr);
+ dev_hw_addr_random(net_dev, net_dev->dev_addr);
printk(KERN_WARNING "%s: Unreadable or invalid MAC address,"
"using random generated one\n", dev_name);
}
--
1.7.7.3

2012-02-08 21:20:54

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 25/50] via-rhine: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ethernet/via/via-rhine.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c
index 10b18eb..eda0711 100644
--- a/drivers/net/ethernet/via/via-rhine.c
+++ b/drivers/net/ethernet/via/via-rhine.c
@@ -984,7 +984,7 @@ static int __devinit rhine_init_one(struct pci_dev *pdev,
if (!is_valid_ether_addr(dev->dev_addr)) {
/* Report it and use a random ethernet address instead */
netdev_err(dev, "Invalid MAC address: %pM\n", dev->dev_addr);
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);
netdev_info(dev, "Using random MAC address: %pM\n",
dev->dev_addr);
}
--
1.7.7.3

2012-02-08 21:28:01

by Oliver Neukum

[permalink] [raw]
Subject: Re: [PATCH 37/50] usbnet: set addr_assign_type if random_ether_addr() used

Am Mittwoch, 8. Februar 2012, 22:10:44 schrieb Danny Kukawka:
> Set addr_assign_type correctly to NET_ADDR_RANDOM in case
> a random MAC address was generated and assigned to the netdevice.
>
> Signed-off-by: Danny Kukawka <[email protected]>
> ---
> drivers/net/usb/usbnet.c | 1 +
> 1 files changed, 1 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
> index fae0fbd..7bd07d7 100644
> --- a/drivers/net/usb/usbnet.c
> +++ b/drivers/net/usb/usbnet.c
> @@ -1365,6 +1365,7 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
> dev->net = net;
> strcpy (net->name, "usb%d");
> memcpy (net->dev_addr, node_id, sizeof node_id);
> + net->addr_assign_type |= NET_ADDR_RANDOM;
>
> /* rx and tx sides can use different message sizes;
> * bind() should set rx_urb_size in that case.

Don't you set the flag too early here? By that time we don't know
whether the device provides a real MAC, do we?

Regards
Oliver

2012-02-08 21:29:01

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 11/50] ep93xx: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ethernet/cirrus/ep93xx_eth.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/cirrus/ep93xx_eth.c b/drivers/net/ethernet/cirrus/ep93xx_eth.c
index 4317af8..4b46270 100644
--- a/drivers/net/ethernet/cirrus/ep93xx_eth.c
+++ b/drivers/net/ethernet/cirrus/ep93xx_eth.c
@@ -859,7 +859,7 @@ static int ep93xx_eth_probe(struct platform_device *pdev)
ep->mdc_divisor = 40; /* Max HCLK 100 MHz, min MDIO clk 2.5 MHz. */

if (is_zero_ether_addr(dev->dev_addr))
- random_ether_addr(dev->dev_addr);
+ dev_hw_addr_random(dev, dev->dev_addr);

err = register_netdev(dev);
if (err) {
--
1.7.7.3

2012-02-08 21:29:46

by Ben Hutchings

[permalink] [raw]
Subject: Re: [PATCH 23/50] efx: use dev_hw_addr_random() instead of random_ether_addr()

On Wed, 2012-02-08 at 22:10 +0100, Danny Kukawka wrote:
> Use dev_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 <[email protected]>
> ---
> drivers/net/ethernet/sfc/efx.c | 4 +++-
> 1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c
> index e43702f..cce339a 100644
> --- a/drivers/net/ethernet/sfc/efx.c
> +++ b/drivers/net/ethernet/sfc/efx.c
> @@ -940,7 +940,7 @@ static int efx_probe_port(struct efx_nic *efx)
> rc = -EINVAL;
> goto err;
> }
> - random_ether_addr(efx->net_dev->dev_addr);
> + dev_hw_addr_random(efx->net_dev, efx->net_dev->dev_addr);
> netif_info(efx, probe, efx->net_dev,
> "using locally-generated MAC %pM\n",
> efx->net_dev->dev_addr);
[...]

This code no longer exists in net-next.

Ben.

--
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.

2012-02-08 21:30:41

by Hartley Sweeten

[permalink] [raw]
Subject: RE: [PATCH 11/50] ep93xx: use dev_hw_addr_random() instead of random_ether_addr()

On Wednesday, February 08, 2012 2:10 PM, Danny Kukawka wrote:
>
> Use dev_hw_addr_random() instead of calling random_ether_addr()
> to set addr_assign_type correctly to NET_ADDR_RANDOM
>
> Signed-off-by: Danny Kukawka <[email protected]>
> ---
> drivers/net/ethernet/cirrus/ep93xx_eth.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/net/ethernet/cirrus/ep93xx_eth.c b/drivers/net/ethernet/cirrus/ep93xx_eth.c
> index 4317af8..4b46270 100644
> --- a/drivers/net/ethernet/cirrus/ep93xx_eth.c
> +++ b/drivers/net/ethernet/cirrus/ep93xx_eth.c
> @@ -859,7 +859,7 @@ static int ep93xx_eth_probe(struct platform_device *pdev)
> ep->mdc_divisor = 40; /* Max HCLK 100 MHz, min MDIO clk 2.5 MHz. */
>
> if (is_zero_ether_addr(dev->dev_addr))
> - random_ether_addr(dev->dev_addr);
> + dev_hw_addr_random(dev, dev->dev_addr);
>
> err = register_netdev(dev);
> if (err) {

Acked-by: H Hartley Sweeten <[email protected]>

2012-02-08 21:17:42

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 50/50] use dev_hw_addr_random() instead of random_ether_addr()

Use dev_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 <[email protected]>
---
drivers/net/ethernet/cisco/enic/enic_main.c | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
index ab3f67f..3e7cb54 100644
--- a/drivers/net/ethernet/cisco/enic/enic_main.c
+++ b/drivers/net/ethernet/cisco/enic/enic_main.c
@@ -865,6 +865,8 @@ static int enic_set_mac_addr(struct net_device *netdev, char *addr)
}

memcpy(netdev->dev_addr, addr, netdev->addr_len);
+ if (netdev->addr_assign_type & NET_ADDR_RANDOM)
+ netdev->addr_assign_type ^= NET_ADDR_RANDOM;

return 0;
}
@@ -1119,7 +1121,7 @@ static int enic_set_vf_port(struct net_device *netdev, int vf,
memcpy(pp->mac_addr, prev_pp.vf_mac, ETH_ALEN);

if (vf == PORT_SELF_VF && is_zero_ether_addr(netdev->dev_addr))
- random_ether_addr(netdev->dev_addr);
+ dev_hw_addr_random(netdev, netdev->dev_addr);

err = enic_process_set_pp_request(enic, vf, &prev_pp, &restore_pp);
if (err) {
@@ -2272,6 +2274,7 @@ static int __devinit enic_probe(struct pci_dev *pdev,
int err;
#ifdef CONFIG_PCI_IOV
int pos = 0;
+ bool random_mac = false;
#endif
int num_pps = 1;

@@ -2467,11 +2470,17 @@ static int __devinit enic_probe(struct pci_dev *pdev,
(void)enic_change_mtu(netdev, enic->port_mtu);

#ifdef CONFIG_PCI_IOV
- if (enic_is_sriov_vf(enic) && is_zero_ether_addr(enic->mac_addr))
+ if (enic_is_sriov_vf(enic) && is_zero_ether_addr(enic->mac_addr)) {
random_ether_addr(enic->mac_addr);
+ random_mac = true;
+ }
#endif

err = enic_set_mac_addr(netdev, enic->mac_addr);
+#ifdef CONFIG_PCI_IOV
+ if (random_mac)
+ netdev->addr_assign_type |= NET_ADDR_RANDOM;
+#endif
if (err) {
dev_err(dev, "Invalid MAC address, aborting\n");
goto err_out_dev_deinit;
--
1.7.7.3

2012-02-08 21:17:03

by Danny Kukawka

[permalink] [raw]
Subject: [PATCH 26/50] faraday: use dev_hw_addr_random() instead of random_ether_addr()

Use dev_hw_addr_random() instead of calling random_ether_addr()
to set addr_assign_type correctly to NET_ADDR_RANDOM.

Signed-off-by: Danny Kukawka <[email protected]>
---
drivers/net/ethernet/faraday/ftgmac100.c | 2 +-
drivers/net/ethernet/faraday/ftmac100.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
index 47f85c3..4842659 100644
--- a/drivers/net/ethernet/faraday/ftgmac100.c
+++ b/drivers/net/ethernet/faraday/ftgmac100.c
@@ -1289,7 +1289,7 @@ static int ftgmac100_probe(struct platform_device *pdev)
netdev_info(netdev, "irq %d, mapped at %p\n", priv->irq, priv->base);

if (!is_valid_ether_addr(netdev->dev_addr)) {
- random_ether_addr(netdev->dev_addr);
+ dev_hw_addr_random(netdev, netdev->dev_addr);
netdev_info(netdev, "generated random MAC address %pM\n",
netdev->dev_addr);
}
diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
index bb336a0..1561010 100644
--- a/drivers/net/ethernet/faraday/ftmac100.c
+++ b/drivers/net/ethernet/faraday/ftmac100.c
@@ -1133,7 +1133,7 @@ static int ftmac100_probe(struct platform_device *pdev)
netdev_info(netdev, "irq %d, mapped at %p\n", priv->irq, priv->base);

if (!is_valid_ether_addr(netdev->dev_addr)) {
- random_ether_addr(netdev->dev_addr);
+ dev_hw_addr_random(netdev, netdev->dev_addr);
netdev_info(netdev, "generated random MAC address %pM\n",
netdev->dev_addr);
}
--
1.7.7.3

2012-02-08 21:42:36

by Danny Kukawka

[permalink] [raw]
Subject: Re: [PATCH 37/50] usbnet: set addr_assign_type if random_ether_addr() used

On Mittwoch, 8. Februar 2012, Oliver Neukum wrote:
> Am Mittwoch, 8. Februar 2012, 22:10:44 schrieb Danny Kukawka:
> > Set addr_assign_type correctly to NET_ADDR_RANDOM in case
> > a random MAC address was generated and assigned to the netdevice.
> >
> > Signed-off-by: Danny Kukawka <[email protected]>
> > ---
> > drivers/net/usb/usbnet.c | 1 +
> > 1 files changed, 1 insertions(+), 0 deletions(-)
> >
> > diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
> > index fae0fbd..7bd07d7 100644
> > --- a/drivers/net/usb/usbnet.c
> > +++ b/drivers/net/usb/usbnet.c
> > @@ -1365,6 +1365,7 @@ usbnet_probe (struct usb_interface *udev, const
> > struct usb_device_id *prod) dev->net = net;
> > strcpy (net->name, "usb%d");
> > memcpy (net->dev_addr, node_id, sizeof node_id);
> > + net->addr_assign_type |= NET_ADDR_RANDOM;
> >
> > /* rx and tx sides can use different message sizes;
> > * bind() should set rx_urb_size in that case.
>
> Don't you set the flag too early here? By that time we don't know
> whether the device provides a real MAC, do we?

You're right. Maybe it's the wrong place. Better the drivers take care of
setting the correct addr_assign_type.

Danny

2012-02-08 22:50:09

by Stephen Hemminger

[permalink] [raw]
Subject: Re: [PATCH 01/50] eth: reset addr_assign_type if eth_mac_addr() called

On Wed, 8 Feb 2012 22:10:08 +0100
Danny Kukawka <[email protected]> wrote:

> + if (dev->addr_assign_type & NET_ADDR_RANDOM)
> + dev->addr_assign_type ^= NET_ADDR_RANDOM;

Why not just avoid the conditional, or better yet use bitops?

dev->addr_assign_type &= ~NET_ADDR_RANDOM;

2012-02-08 22:52:45

by Stephen Hemminger

[permalink] [raw]
Subject: Re: [PATCH 47/50] bridge: use dev_hw_addr_random() instead of random_ether_addr()

On Wed, 8 Feb 2012 22:10:54 +0100
Danny Kukawka <[email protected]> wrote:

> Use dev_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 <[email protected]>
> ---
> net/bridge/br_device.c | 6 +++++-
> 1 files changed, 5 insertions(+), 1 deletions(-)
>
> diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
> index 71773b0..a25ed22 100644
> --- a/net/bridge/br_device.c
> +++ b/net/bridge/br_device.c
> @@ -172,6 +172,10 @@ static int br_set_mac_address(struct net_device *dev, void *p)
> spin_lock_bh(&br->lock);
> if (compare_ether_addr(dev->dev_addr, addr->sa_data)) {
> memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
> + if (dev->addr_assign_type & NET_ADDR_RANDOM) {
> + /* set back to NET_ADDR_PERM */
> + dev->addr_assign_type ^= NET_ADDR_RANDOM;
> + }
> br_fdb_change_mac_address(br, addr->sa_data);
> br_stp_change_bridge_id(br, addr->sa_data);
> }
> @@ -334,7 +338,7 @@ void br_dev_setup(struct net_device *dev)
> {
> struct net_bridge *br = netdev_priv(dev);
>
> - random_ether_addr(dev->dev_addr);
> + dev_hw_addr_random(dev, dev->dev_addr);
> ether_setup(dev);
>
> dev->netdev_ops = &br_netdev_ops;


You should do more than just mechanical change here.
Go ahead and eliminate the private (BR_SET_MAC_ADDR) flag as well,
since it would be redundant.


2012-02-08 22:58:25

by Danny Kukawka

[permalink] [raw]
Subject: Re: [PATCH 01/50] eth: reset addr_assign_type if eth_mac_addr() called

On Mittwoch, 8. Februar 2012, Stephen Hemminger wrote:
> On Wed, 8 Feb 2012 22:10:08 +0100
>
> Danny Kukawka <[email protected]> wrote:
> > + if (dev->addr_assign_type & NET_ADDR_RANDOM)
> > + dev->addr_assign_type ^= NET_ADDR_RANDOM;
>
> Why not just avoid the conditional, or better yet use bitops?
>
> dev->addr_assign_type &= ~NET_ADDR_RANDOM;

Okay, If I have comments on the other patches back, I will send new versions
which avoid the if. Thanks for the hint.

Danny

2012-02-08 22:58:29

by Stephen Hemminger

[permalink] [raw]
Subject: Re: [RFC][PATCH 00/50] set addr_assign_type to NET_ADDR_RANDOM if a random mac address get assigned to a netdevice

On Wed, 8 Feb 2012 22:10:07 +0100
Danny Kukawka <[email protected]> wrote:

> The information if a device has a random MAC address is exported
> to the userspace via /sys/class/net/*/addr_assign_type, which
> export net_device->addr_assign_type.
>
> Currently only a few driver really use dev_hw_addr_random() to
> set addr_assign_type correctly to NET_ADDR_RANDOM.
>
> This patch change the drivers which set random addresses to
> change also addr_assign_type to NET_ADDR_RANDOM.
>
> To reflect if the MAC was changed from userspace via SIOCSIFHWADDR,
> which means it's no longer a random address set by the kernel,
> this patch remove NET_ADDR_RANDOM from addr_assign_type in this
> case.
>
> With this patch tools from userspace can now detect devices with
> random MAC addresses and change them to persistent addresses if
> needed (as e.g. in case of smsc95xx on PandaBoard).
>
> Maybe it makes sense to introduce a new state for addr_assign_type
> to reflect the fact, that the MAC address was changed via a ioctl
> from user space, e.g, with NET_ADDR_USERSPACE ?
>


This reminds me that passing dev->dev_addr to dev_hw_addr_rrandom is redundant
for all the instances you showed, so why is it ia parameter.

Also it should BUG() if address length is not 6 (ETH_ALEN).

2012-02-08 23:29:53

by David Miller

[permalink] [raw]
Subject: Re: [RFC][PATCH 00/50] set addr_assign_type to NET_ADDR_RANDOM if a random mac address get assigned to a netdevice


50 patches is way too many patches to submit and expect people
to review at one time.

You must do one of two things:

1) Condense the series down to a smaller number of more managable
patches. Perhaps combine all the completely trivial conversion
cases into one single patch, and post the non-trivial cases
seperately.

2) Only submit a few of these changes at a time, not all at once.

It's your choice, but what you did here is unacceptable.

2012-02-09 03:28:04

by Bob Liu

[permalink] [raw]
Subject: Re: [PATCH 04/50] adi/blackfin: set addr_assign_type correctly if random

Hi Danny,

On Thu, Feb 9, 2012 at 5:10 AM, Danny Kukawka <[email protected]> wrote:
> Set the addr_assign_type for adi driver correctly to
> NET_ADDR_RANDOM if a random MAC address was generated.
> Reset the state to NET_ADDR_PERM as soon as the MAC get
> changed via .ndo_set_mac_address.
>
> Signed-off-by: Danny Kukawka <[email protected]>
> ---
>  arch/blackfin/mach-bf518/boards/ezbrd.c      |    3 ++-
>  arch/blackfin/mach-bf518/boards/tcm-bf518.c  |    3 ++-
>  arch/blackfin/mach-bf527/boards/ad7160eval.c |    3 ++-
>  arch/blackfin/mach-bf527/boards/cm_bf527.c   |    3 ++-
>  arch/blackfin/mach-bf527/boards/ezbrd.c      |    3 ++-
>  arch/blackfin/mach-bf527/boards/ezkit.c      |    3 ++-
>  arch/blackfin/mach-bf527/boards/tll6527m.c   |    3 ++-
>  arch/blackfin/mach-bf537/boards/cm_bf537e.c  |    3 ++-
>  arch/blackfin/mach-bf537/boards/cm_bf537u.c  |    3 ++-
>  arch/blackfin/mach-bf537/boards/dnp5370.c    |    3 ++-
>  arch/blackfin/mach-bf537/boards/pnav10.c     |    3 ++-
>  arch/blackfin/mach-bf537/boards/stamp.c      |    3 ++-
>  arch/blackfin/mach-bf537/boards/tcm_bf537.c  |    3 ++-
>  drivers/net/ethernet/adi/bfin_mac.c          |   10 +++++++---
>  drivers/net/ethernet/adi/bfin_mac.h          |    2 +-

Would you please split this into two patches, one for arch/blackfin
and the other
for drivers/net.
This can make our maintain simpler and clearer.

>  15 files changed, 34 insertions(+), 17 deletions(-)
>
> diff --git a/arch/blackfin/mach-bf518/boards/ezbrd.c b/arch/blackfin/mach-bf518/boards/ezbrd.c
> index a2d96d3..a173957 100644
> --- a/arch/blackfin/mach-bf518/boards/ezbrd.c
> +++ b/arch/blackfin/mach-bf518/boards/ezbrd.c
> @@ -821,7 +821,7 @@ void native_machine_restart(char *cmd)
>                bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS);
>  }
>
> -void bfin_get_ether_addr(char *addr)
> +int bfin_get_ether_addr(char *addr)
>  {
>        /* the MAC is stored in OTP memory page 0xDF */
>        u32 ret;
> @@ -834,5 +834,6 @@ void bfin_get_ether_addr(char *addr)
>                for (ret = 0; ret < 6; ++ret)
>                        addr[ret] = otp_mac_p[5 - ret];
>        }
> +       return 0;
>  }
>  EXPORT_SYMBOL(bfin_get_ether_addr);
> diff --git a/arch/blackfin/mach-bf518/boards/tcm-bf518.c b/arch/blackfin/mach-bf518/boards/tcm-bf518.c
> index f271310..d3c763e 100644
> --- a/arch/blackfin/mach-bf518/boards/tcm-bf518.c
> +++ b/arch/blackfin/mach-bf518/boards/tcm-bf518.c
> @@ -730,9 +730,10 @@ void native_machine_restart(char *cmd)
>                bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS);
>  }
>
> -void bfin_get_ether_addr(char *addr)
> +int bfin_get_ether_addr(char *addr)
>  {
>        random_ether_addr(addr);
>        printk(KERN_WARNING "%s:%s: Setting Ethernet MAC to a random one\n", __FILE__, __func__);
> +       return 1;
>  }
>  EXPORT_SYMBOL(bfin_get_ether_addr);
> diff --git a/arch/blackfin/mach-bf527/boards/ad7160eval.c b/arch/blackfin/mach-bf527/boards/ad7160eval.c
> index c8d5d2b..fad7fea 100644
> --- a/arch/blackfin/mach-bf527/boards/ad7160eval.c
> +++ b/arch/blackfin/mach-bf527/boards/ad7160eval.c
> @@ -846,7 +846,7 @@ void native_machine_restart(char *cmd)
>                bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS);
>  }
>
> -void bfin_get_ether_addr(char *addr)
> +int bfin_get_ether_addr(char *addr)
>  {
>        /* the MAC is stored in OTP memory page 0xDF */
>        u32 ret;
> @@ -859,5 +859,6 @@ void bfin_get_ether_addr(char *addr)
>                for (ret = 0; ret < 6; ++ret)
>                        addr[ret] = otp_mac_p[5 - ret];
>        }
> +       return 0;
>  }
>  EXPORT_SYMBOL(bfin_get_ether_addr);
> diff --git a/arch/blackfin/mach-bf527/boards/cm_bf527.c b/arch/blackfin/mach-bf527/boards/cm_bf527.c
> index 7330607..5fb09ad 100644
> --- a/arch/blackfin/mach-bf527/boards/cm_bf527.c
> +++ b/arch/blackfin/mach-bf527/boards/cm_bf527.c
> @@ -983,9 +983,10 @@ void native_machine_restart(char *cmd)
>                bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS);
>  }
>
> -void bfin_get_ether_addr(char *addr)
> +int bfin_get_ether_addr(char *addr)
>  {
>        random_ether_addr(addr);
>        printk(KERN_WARNING "%s:%s: Setting Ethernet MAC to a random one\n", __FILE__, __func__);
> +       return 1;
>  }
>  EXPORT_SYMBOL(bfin_get_ether_addr);
> diff --git a/arch/blackfin/mach-bf527/boards/ezbrd.c b/arch/blackfin/mach-bf527/boards/ezbrd.c
> index db3ecfc..17c6a24 100644
> --- a/arch/blackfin/mach-bf527/boards/ezbrd.c
> +++ b/arch/blackfin/mach-bf527/boards/ezbrd.c
> @@ -870,7 +870,7 @@ void native_machine_restart(char *cmd)
>                bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS);
>  }
>
> -void bfin_get_ether_addr(char *addr)
> +int bfin_get_ether_addr(char *addr)
>  {
>        /* the MAC is stored in OTP memory page 0xDF */
>        u32 ret;
> @@ -883,5 +883,6 @@ void bfin_get_ether_addr(char *addr)
>                for (ret = 0; ret < 6; ++ret)
>                        addr[ret] = otp_mac_p[5 - ret];
>        }
> +       return 0;
>  }
>  EXPORT_SYMBOL(bfin_get_ether_addr);
> diff --git a/arch/blackfin/mach-bf527/boards/ezkit.c b/arch/blackfin/mach-bf527/boards/ezkit.c
> index dfdd8e6..89b0f6c 100644
> --- a/arch/blackfin/mach-bf527/boards/ezkit.c
> +++ b/arch/blackfin/mach-bf527/boards/ezkit.c
> @@ -1311,7 +1311,7 @@ void native_machine_restart(char *cmd)
>                bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS);
>  }
>
> -void bfin_get_ether_addr(char *addr)
> +int bfin_get_ether_addr(char *addr)
>  {
>        /* the MAC is stored in OTP memory page 0xDF */
>        u32 ret;
> @@ -1324,5 +1324,6 @@ void bfin_get_ether_addr(char *addr)
>                for (ret = 0; ret < 6; ++ret)
>                        addr[ret] = otp_mac_p[5 - ret];
>        }
> +       return 0;
>  }
>  EXPORT_SYMBOL(bfin_get_ether_addr);
> diff --git a/arch/blackfin/mach-bf527/boards/tll6527m.c b/arch/blackfin/mach-bf527/boards/tll6527m.c
> index 360e97f..d192c0a 100644
> --- a/arch/blackfin/mach-bf527/boards/tll6527m.c
> +++ b/arch/blackfin/mach-bf527/boards/tll6527m.c
> @@ -931,7 +931,7 @@ void native_machine_restart(char *cmd)
>                bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS);
>  }
>
> -void bfin_get_ether_addr(char *addr)
> +int bfin_get_ether_addr(char *addr)
>  {
>        /* the MAC is stored in OTP memory page 0xDF */
>        u32 ret;
> @@ -945,5 +945,6 @@ void bfin_get_ether_addr(char *addr)
>                for (ret = 0; ret < 6; ++ret)
>                        addr[ret] = otp_mac_p[5 - ret];
>        }
> +       return 0;
>  }
>  EXPORT_SYMBOL(bfin_get_ether_addr);
> diff --git a/arch/blackfin/mach-bf537/boards/cm_bf537e.c b/arch/blackfin/mach-bf537/boards/cm_bf537e.c
> index 0d4a2f6..618fd7d 100644
> --- a/arch/blackfin/mach-bf537/boards/cm_bf537e.c
> +++ b/arch/blackfin/mach-bf537/boards/cm_bf537e.c
> @@ -813,9 +813,10 @@ void __init native_machine_early_platform_add_devices(void)
>                ARRAY_SIZE(cm_bf537e_early_devices));
>  }
>
> -void bfin_get_ether_addr(char *addr)
> +int bfin_get_ether_addr(char *addr)
>  {
>        random_ether_addr(addr);
>        printk(KERN_WARNING "%s:%s: Setting Ethernet MAC to a random one\n", __FILE__, __func__);
> +       return 1;
>  }
>  EXPORT_SYMBOL(bfin_get_ether_addr);
> diff --git a/arch/blackfin/mach-bf537/boards/cm_bf537u.c b/arch/blackfin/mach-bf537/boards/cm_bf537u.c
> index f553698..48a7a23 100644
> --- a/arch/blackfin/mach-bf537/boards/cm_bf537u.c
> +++ b/arch/blackfin/mach-bf537/boards/cm_bf537u.c
> @@ -790,9 +790,10 @@ void __init native_machine_early_platform_add_devices(void)
>                ARRAY_SIZE(cm_bf537u_early_devices));
>  }
>
> -void bfin_get_ether_addr(char *addr)
> +int bfin_get_ether_addr(char *addr)
>  {
>        random_ether_addr(addr);
>        printk(KERN_WARNING "%s:%s: Setting Ethernet MAC to a random one\n", __FILE__, __func__);
> +       return 1;
>  }
>  EXPORT_SYMBOL(bfin_get_ether_addr);
> diff --git a/arch/blackfin/mach-bf537/boards/dnp5370.c b/arch/blackfin/mach-bf537/boards/dnp5370.c
> index 11dadeb..6f77bf7 100644
> --- a/arch/blackfin/mach-bf537/boards/dnp5370.c
> +++ b/arch/blackfin/mach-bf537/boards/dnp5370.c
> @@ -399,9 +399,10 @@ arch_initcall(dnp5370_init);
>  /*
>  * Currently the MAC address is saved in Flash by U-Boot
>  */
> -void bfin_get_ether_addr(char *addr)
> +int bfin_get_ether_addr(char *addr)
>  {
>        *(u32 *)(&(addr[0])) = bfin_read32(FLASH_MAC);
>        *(u16 *)(&(addr[4])) = bfin_read16(FLASH_MAC + 4);
> +       return 0;
>  }
>  EXPORT_SYMBOL(bfin_get_ether_addr);
> diff --git a/arch/blackfin/mach-bf537/boards/pnav10.c b/arch/blackfin/mach-bf537/boards/pnav10.c
> index 6fd8470..2a9cd61 100644
> --- a/arch/blackfin/mach-bf537/boards/pnav10.c
> +++ b/arch/blackfin/mach-bf537/boards/pnav10.c
> @@ -535,9 +535,10 @@ void __init native_machine_early_platform_add_devices(void)
>                ARRAY_SIZE(stamp_early_devices));
>  }
>
> -void bfin_get_ether_addr(char *addr)
> +int bfin_get_ether_addr(char *addr)
>  {
>        random_ether_addr(addr);
>        printk(KERN_WARNING "%s:%s: Setting Ethernet MAC to a random one\n", __FILE__, __func__);
> +       return 1;
>  }
>  EXPORT_SYMBOL(bfin_get_ether_addr);
> diff --git a/arch/blackfin/mach-bf537/boards/stamp.c b/arch/blackfin/mach-bf537/boards/stamp.c
> index 2221173..0b80725 100644
> --- a/arch/blackfin/mach-bf537/boards/stamp.c
> +++ b/arch/blackfin/mach-bf537/boards/stamp.c
> @@ -2993,9 +2993,10 @@ void native_machine_restart(char *cmd)
>  * Currently the MAC address is saved in Flash by U-Boot
>  */
>  #define FLASH_MAC      0x203f0000
> -void bfin_get_ether_addr(char *addr)
> +int bfin_get_ether_addr(char *addr)
>  {
>        *(u32 *)(&(addr[0])) = bfin_read32(FLASH_MAC);
>        *(u16 *)(&(addr[4])) = bfin_read16(FLASH_MAC + 4);
> +       return 0;
>  }
>  EXPORT_SYMBOL(bfin_get_ether_addr);
> diff --git a/arch/blackfin/mach-bf537/boards/tcm_bf537.c b/arch/blackfin/mach-bf537/boards/tcm_bf537.c
> index 9885176..02eb9d0 100644
> --- a/arch/blackfin/mach-bf537/boards/tcm_bf537.c
> +++ b/arch/blackfin/mach-bf537/boards/tcm_bf537.c
> @@ -780,9 +780,10 @@ void __init native_machine_early_platform_add_devices(void)
>                ARRAY_SIZE(cm_bf537_early_devices));
>  }
>
> -void bfin_get_ether_addr(char *addr)
> +int bfin_get_ether_addr(char *addr)
>  {
>        random_ether_addr(addr);
>        printk(KERN_WARNING "%s:%s: Setting Ethernet MAC to a random one\n", __FILE__, __func__);
> +       return 1;
>  }
>  EXPORT_SYMBOL(bfin_get_ether_addr);
> diff --git a/drivers/net/ethernet/adi/bfin_mac.c b/drivers/net/ethernet/adi/bfin_mac.c
> index d812a10..064a3a6 100644
> --- a/drivers/net/ethernet/adi/bfin_mac.c
> +++ b/drivers/net/ethernet/adi/bfin_mac.c
> @@ -621,6 +621,8 @@ static int bfin_mac_set_mac_address(struct net_device *dev, void *p)
>        if (netif_running(dev))
>                return -EBUSY;
>        memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
> +       if (dev->addr_assign_type & NET_ADDR_RANDOM)
> +               dev->addr_assign_type ^= NET_ADDR_RANDOM;
>        setup_mac_addr(dev->dev_addr);
>        return 0;
>  }
> @@ -1496,12 +1498,14 @@ static int __devinit bfin_mac_probe(struct platform_device *pdev)
>         * Grab the MAC from the board somehow
>         * this is done in the arch/blackfin/mach-bfxxx/boards/eth_mac.c
>         */
> -       if (!is_valid_ether_addr(ndev->dev_addr))
> -               bfin_get_ether_addr(ndev->dev_addr);
> +       if (!is_valid_ether_addr(ndev->dev_addr)) {
> +               if (bfin_get_ether_addr(ndev->dev_addr))
> +                       ndev->addr_assign_type |= NET_ADDR_RANDOM;
> +       }
>
>        /* If still not valid, get a random one */
>        if (!is_valid_ether_addr(ndev->dev_addr))
> -               random_ether_addr(ndev->dev_addr);
> +               dev_hw_addr_random(ndev, ndev->dev_addr);
>
>        setup_mac_addr(ndev->dev_addr);
>
> diff --git a/drivers/net/ethernet/adi/bfin_mac.h b/drivers/net/ethernet/adi/bfin_mac.h
> index f8559ac..960905c 100644
> --- a/drivers/net/ethernet/adi/bfin_mac.h
> +++ b/drivers/net/ethernet/adi/bfin_mac.h
> @@ -101,6 +101,6 @@ struct bfin_mac_local {
>  #endif
>  };
>
> -extern void bfin_get_ether_addr(char *addr);
> +extern int bfin_get_ether_addr(char *addr);
>
>  #endif
> --
> 1.7.7.3
>

--
Thanks,
--Bob

2012-02-09 04:05:16

by Mike Frysinger

[permalink] [raw]
Subject: Re: [PATCH 04/50] adi/blackfin: set addr_assign_type correctly if random

On Wednesday 08 February 2012 16:10:11 Danny Kukawka wrote:
> --- a/arch/blackfin/mach-bf537/boards/cm_bf537e.c
> +++ b/arch/blackfin/mach-bf537/boards/cm_bf537e.c
>
> -void bfin_get_ether_addr(char *addr)
> +int bfin_get_ether_addr(char *addr)
> {
> random_ether_addr(addr);
> printk(KERN_WARNING "%s:%s: Setting Ethernet MAC to a random one\n",
> __FILE__, __func__);
> + return 1;
> }

these boards that just call random_ether_addr() should be changed to only
return 1 ...

> --- a/drivers/net/ethernet/adi/bfin_mac.c
> +++ b/drivers/net/ethernet/adi/bfin_mac.c
> @@ -621,6 +621,8 @@
>
> memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
> + if (dev->addr_assign_type & NET_ADDR_RANDOM)
> + dev->addr_assign_type ^= NET_ADDR_RANDOM;
> setup_mac_addr(dev->dev_addr);
> return 0;
> }
> @@ -1496,12 +1498,14 @@
>
> - if (!is_valid_ether_addr(ndev->dev_addr))
> - bfin_get_ether_addr(ndev->dev_addr);
> + if (!is_valid_ether_addr(ndev->dev_addr)) {
> + if (bfin_get_ether_addr(ndev->dev_addr))
> + ndev->addr_assign_type |= NET_ADDR_RANDOM;
> + }

if it returned non-zero, then the mac addr is still invalid, so down below ...

> /* If still not valid, get a random one */
> if (!is_valid_ether_addr(ndev->dev_addr))
> - random_ether_addr(ndev->dev_addr);
> + dev_hw_addr_random(ndev, ndev->dev_addr);

... we call dev_hw_addr_random(), so explicitly setting NET_ADDR_RANDOM
ourselves is unnecessary

i think the logic should read:
if (!is_valid_ether_addr(ndev->dev_addr)) {
if (bfin_get_ether_addr(ndev->dev_addr))
goto random_mac;

if (!is_valid_ether_addr(ndev->dev_addr))
random_mac:
dev_hw_addr_random(ndev, ndev->dev_addr);
-mike


Attachments:
signature.asc (836.00 B)
This is a digitally signed message part.

2012-02-09 06:58:12

by Bjørn Mork

[permalink] [raw]
Subject: Re: [PATCH 37/50] usbnet: set addr_assign_type if random_ether_addr() used

Oliver Neukum <[email protected]> writes:

> Am Mittwoch, 8. Februar 2012, 22:10:44 schrieb Danny Kukawka:
>> Set addr_assign_type correctly to NET_ADDR_RANDOM in case
>> a random MAC address was generated and assigned to the netdevice.
>>
>> Signed-off-by: Danny Kukawka <[email protected]>
>> ---
>> drivers/net/usb/usbnet.c | 1 +
>> 1 files changed, 1 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
>> index fae0fbd..7bd07d7 100644
>> --- a/drivers/net/usb/usbnet.c
>> +++ b/drivers/net/usb/usbnet.c
>> @@ -1365,6 +1365,7 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
>> dev->net = net;
>> strcpy (net->name, "usb%d");
>> memcpy (net->dev_addr, node_id, sizeof node_id);
>> + net->addr_assign_type |= NET_ADDR_RANDOM;
>>
>> /* rx and tx sides can use different message sizes;
>> * bind() should set rx_urb_size in that case.
>
> Don't you set the flag too early here? By that time we don't know
> whether the device provides a real MAC, do we?

Maybe it makes sense to set it here anyway since usbnet provides this
default random address, and let the minidrivers which set a real mac
also clear the flag? But in that case the patch need to clear the flag
everywhere a minidriver currently updates the address.


Bjørn

2012-02-09 08:25:23

by Nicolas Ferre

[permalink] [raw]
Subject: Re: [PATCH 09/50] Cadence MACB: use dev_hw_addr_random() instead of random_ether_addr()

On 02/08/2012 10:10 PM, Danny Kukawka :
> Use dev_hw_addr_random() instead of calling random_ether_addr()
> to set addr_assign_type correctly to NET_ADDR_RANDOM.
>
> Signed-off-by: Danny Kukawka <[email protected]>

Danny,

You can add my "Acked-by" even if you rework this series...

Acked-by: Nicolas Ferre <[email protected]>

Thanks, best regards,

> ---
> drivers/net/ethernet/cadence/macb.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
> index 2320068..3ee8d79 100644
> --- a/drivers/net/ethernet/cadence/macb.c
> +++ b/drivers/net/ethernet/cadence/macb.c
> @@ -87,7 +87,7 @@ static void __init macb_get_hwaddr(struct macb *bp)
> memcpy(bp->dev->dev_addr, addr, sizeof(addr));
> } else {
> netdev_info(bp->dev, "invalid hw address, using random\n");
> - random_ether_addr(bp->dev->dev_addr);
> + dev_hw_addr_random(bp->dev, bp->dev->dev_addr);
> }
> }
>


--
Nicolas Ferre

2012-02-09 08:52:45

by Sven Eckelmann

[permalink] [raw]
Subject: Re: [B.A.T.M.A.N.] [PATCH 40/50] batman-adv: use dev_hw_addr_random() instead of random_ether_addr()

On Wednesday 08 February 2012 22:10:47 Danny Kukawka wrote:
> Use dev_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 <[email protected]>
> ---
> net/batman-adv/soft-interface.c | 7 ++++---
> 1 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/net/batman-adv/soft-interface.c
> b/net/batman-adv/soft-interface.c index 987c75a..865a485 100644
> --- a/net/batman-adv/soft-interface.c
> +++ b/net/batman-adv/soft-interface.c
> @@ -541,6 +541,9 @@ static int interface_set_mac_addr(struct net_device
> *dev, void *p) }
>
> memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
> + if (dev->addr_assign_type & NET_ADDR_RANDOM)
> + dev->addr_assign_type ^= NET_ADDR_RANDOM;
> +
> return 0;
> }

Why not something like

dev->addr_assign_type &= ~NET_ADDR_RANDOM;

? It is a relative common way inside the kernel to do this kind of stuff.

Thanks,
Sven

PS: For the batman-adv people. This functionality was introduced with 2.6.36.


Attachments:
signature.asc (836.00 B)
This is a digitally signed message part.

2012-02-09 09:36:14

by Michael S. Tsirkin

[permalink] [raw]
Subject: Re: [PATCH 42/50] virtio_net: use dev_hw_addr_random() instead of random_ether_addr()

On Wed, Feb 08, 2012 at 10:10:49PM +0100, Danny Kukawka wrote:
> Use dev_hw_addr_random() instead of calling random_ether_addr()
> to set addr_assign_type correctly to NET_ADDR_RANDOM.
>
> Signed-off-by: Danny Kukawka <[email protected]>

Acked-by: Michael S. Tsirkin <[email protected]>

> ---
> drivers/net/virtio_net.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 4880aa8..69d36e1 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -1061,7 +1061,7 @@ static int virtnet_probe(struct virtio_device *vdev)
> if (virtio_config_val_len(vdev, VIRTIO_NET_F_MAC,
> offsetof(struct virtio_net_config, mac),
> dev->dev_addr, dev->addr_len) < 0)
> - random_ether_addr(dev->dev_addr);
> + dev_hw_addr_random(dev, dev->dev_addr);
>
> /* Set up our device-specific information */
> vi = netdev_priv(dev);
> --
> 1.7.7.3

2012-02-09 10:00:06

by David Laight

[permalink] [raw]
Subject: RE: [PATCH 08/50] bnx2x: use dev_hw_addr_random() instead of random_ether_addr()


> + if (dev->addr_assign_type & NET_ADDR_RANDOM)
> + dev->addr_assign_type ^= NET_ADDR_RANDOM;

Why not just:
dev->addr_assign_type &= ~NET_ADDR_RANDOM;
the cache is probably dirty and it won't be a critical path.

David

2012-02-09 10:52:59

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH 02/50] smsc95xx: use dev_hw_addr_random() instead of random_ether_addr()

Hello.

On 09-02-2012 1:10, Danny Kukawka wrote:

> Use dev_hw_addr_random() instead of calling random_ether_addr()
> to set addr_assign_type correctly to NET_ADDR_RANDOM.

> Signed-off-by: Danny Kukawka<[email protected]>
> ---
> drivers/net/usb/smsc95xx.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)

> diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
> index d45520e..3a28e95 100644
> --- a/drivers/net/usb/smsc95xx.c
> +++ b/drivers/net/usb/smsc95xx.c
> @@ -614,7 +614,7 @@ static void smsc95xx_init_mac_address(struct usbnet *dev)
> }
>
> /* no eeprom, or eeprom values are invalid. generate random MAC */
> - random_ether_addr(dev->net->dev_addr);
> + dev_hw_addr_random(dev->net , dev->net->dev_addr);

Should be no space before comma.

WBR, Sergei

2012-02-09 11:28:54

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH 20/50] smsc911x: use dev_hw_addr_random() instead of random_ether_addr()

On Wed, Feb 08, 2012 at 10:10:27PM +0100, Danny Kukawka wrote:

> + if (dev->addr_assign_type & NET_ADDR_RANDOM)
> + dev->addr_assign_type ^= NET_ADDR_RANDOM;

It would be clearer to just write

dev->addr_assign_type &= ~NET_ADDR_RANDOM;

to clear the bit - the ^ takes more thinking.

2012-02-09 12:19:32

by Danny Kukawka

[permalink] [raw]
Subject: Re: [RFC][PATCH 00/50] set addr_assign_type to NET_ADDR_RANDOM if a random mac address get assigned to a netdevice

On Donnerstag, 9. Februar 2012, David Miller wrote:
> 50 patches is way too many patches to submit and expect people
> to review at one time.
>
> You must do one of two things:
>
> 1) Condense the series down to a smaller number of more managable
> patches. Perhaps combine all the completely trivial conversion
> cases into one single patch, and post the non-trivial cases
> seperately.
>
> 2) Only submit a few of these changes at a time, not all at once.
>
> It's your choice, but what you did here is unacceptable.

Could you at least comment on these points from the cover letter, before I
change/update the patches?

- Should NET_ADDR_RANDOM get reset (to NET_ADDR_PERM) if the MAC address
get changed via SIOCSIFHWADDR/.ndo_set_mac_address and was random before?
- Would it make sense to add a new state (e.g. NET_ADDR_USERSPACE)
if the net address get changed via SIOCSIFHWADDR/.ndo_set_mac_address
from userspace?

Thanks,

Danny

2012-02-09 14:13:28

by Krzysztof Halasa

[permalink] [raw]
Subject: Re: [PATCH 46/50] wan: use dev_hw_addr_random() instead of random_ether_addr()

Danny Kukawka <[email protected]> writes:

> Use dev_hw_addr_random() instead of calling random_ether_addr()
> to set addr_assign_type correctly to NET_ADDR_RANDOM.
>
> Signed-off-by: Danny Kukawka <[email protected]>
> ---
> drivers/net/wan/hdlc_fr.c | 2 +-
> drivers/net/wan/hdlc_raw_eth.c | 2 +-

Acked-by: Krzysztof Halasa <[email protected]>
--
Krzysztof Halasa

2012-02-09 14:52:54

by Oliver Neukum

[permalink] [raw]
Subject: Re: [PATCH 37/50] usbnet: set addr_assign_type if random_ether_addr() used

Am Donnerstag, 9. Februar 2012, 07:57:42 schrieb Bjørn Mork:
> > Don't you set the flag too early here? By that time we don't know
> > whether the device provides a real MAC, do we?
>
> Maybe it makes sense to set it here anyway since usbnet provides this
> default random address, and let the minidrivers which set a real mac
> also clear the flag? But in that case the patch need to clear the flag
> everywhere a minidriver currently updates the address.
>

Doable, but where is the benefit? It seems better to me to make an effort
to guess as well as possible in the common code.

Regards
Oliver

2012-02-09 15:00:03

by Danny Kukawka

[permalink] [raw]
Subject: Re: [RFC][PATCH 00/50] set addr_assign_type to NET_ADDR_RANDOM if a random mac address get assigned to a netdevice

On Mittwoch, 8. Februar 2012, Stephen Hemminger wrote:
> On Wed, 8 Feb 2012 22:10:07 +0100
>
> Danny Kukawka <[email protected]> wrote:
> > The information if a device has a random MAC address is exported
> > to the userspace via /sys/class/net/*/addr_assign_type, which
> > export net_device->addr_assign_type.
> >
> > Currently only a few driver really use dev_hw_addr_random() to
> > set addr_assign_type correctly to NET_ADDR_RANDOM.
> >
> > This patch change the drivers which set random addresses to
> > change also addr_assign_type to NET_ADDR_RANDOM.
> >
> > To reflect if the MAC was changed from userspace via SIOCSIFHWADDR,
> > which means it's no longer a random address set by the kernel,
> > this patch remove NET_ADDR_RANDOM from addr_assign_type in this
> > case.
> >
> > With this patch tools from userspace can now detect devices with
> > random MAC addresses and change them to persistent addresses if
> > needed (as e.g. in case of smsc95xx on PandaBoard).
> >
> > Maybe it makes sense to introduce a new state for addr_assign_type
> > to reflect the fact, that the MAC address was changed via a ioctl
> > from user space, e.g, with NET_ADDR_USERSPACE ?
>
> This reminds me that passing dev->dev_addr to dev_hw_addr_rrandom is
> redundant for all the instances you showed, so why is it ia parameter.

There are two places in the existing code where it's used in a different way
in ixgbevf and igbvf, but thats changeable. I will take a look at it and
change dev_hw_addr_random to take simply a net_device ands set everything
directly.

> Also it should BUG() if address length is not 6 (ETH_ALEN).

Not needed if I change it to:
static inline void dev_hw_addr_random(struct net_device *dev)

Danny

2012-02-09 16:06:44

by Stephen Hemminger

[permalink] [raw]
Subject: Re: [RFC][PATCH 00/50] set addr_assign_type to NET_ADDR_RANDOM if a random mac address get assigned to a netdevice

On Thu, 9 Feb 2012 15:59:05 +0100
Danny Kukawka <[email protected]> wrote:

> On Mittwoch, 8. Februar 2012, Stephen Hemminger wrote:
> > On Wed, 8 Feb 2012 22:10:07 +0100
> >
> > Danny Kukawka <[email protected]> wrote:
> > > The information if a device has a random MAC address is exported
> > > to the userspace via /sys/class/net/*/addr_assign_type, which
> > > export net_device->addr_assign_type.
> > >
> > > Currently only a few driver really use dev_hw_addr_random() to
> > > set addr_assign_type correctly to NET_ADDR_RANDOM.
> > >
> > > This patch change the drivers which set random addresses to
> > > change also addr_assign_type to NET_ADDR_RANDOM.
> > >
> > > To reflect if the MAC was changed from userspace via SIOCSIFHWADDR,
> > > which means it's no longer a random address set by the kernel,
> > > this patch remove NET_ADDR_RANDOM from addr_assign_type in this
> > > case.
> > >
> > > With this patch tools from userspace can now detect devices with
> > > random MAC addresses and change them to persistent addresses if
> > > needed (as e.g. in case of smsc95xx on PandaBoard).
> > >
> > > Maybe it makes sense to introduce a new state for addr_assign_type
> > > to reflect the fact, that the MAC address was changed via a ioctl
> > > from user space, e.g, with NET_ADDR_USERSPACE ?
> >
> > This reminds me that passing dev->dev_addr to dev_hw_addr_rrandom is
> > redundant for all the instances you showed, so why is it ia parameter.
>
> There are two places in the existing code where it's used in a different way
> in ixgbevf and igbvf, but thats changeable. I will take a look at it and
> change dev_hw_addr_random to take simply a net_device ands set everything
> directly.
>
> > Also it should BUG() if address length is not 6 (ETH_ALEN).
>
> Not needed if I change it to:
> static inline void dev_hw_addr_random(struct net_device *dev)
>
> Danny

It is still needed to prevent some device driver that uses
some longer address (like Infiniband) from the thinking it is
a generic routine. Maybe even renaming int eth_hw_addr_random()

2012-02-09 18:37:31

by David Miller

[permalink] [raw]
Subject: Re: [RFC][PATCH 00/50] set addr_assign_type to NET_ADDR_RANDOM if a random mac address get assigned to a netdevice

From: Danny Kukawka <[email protected]>
Date: Thu, 9 Feb 2012 13:18:35 +0100

> On Donnerstag, 9. Februar 2012, David Miller wrote:
>> 50 patches is way too many patches to submit and expect people
>> to review at one time.
>>
>> You must do one of two things:
>>
>> 1) Condense the series down to a smaller number of more managable
>> patches. Perhaps combine all the completely trivial conversion
>> cases into one single patch, and post the non-trivial cases
>> seperately.
>>
>> 2) Only submit a few of these changes at a time, not all at once.
>>
>> It's your choice, but what you did here is unacceptable.
>
> Could you at least comment on these points from the cover letter, before I
> change/update the patches?
>
> - Should NET_ADDR_RANDOM get reset (to NET_ADDR_PERM) if the MAC address
> get changed via SIOCSIFHWADDR/.ndo_set_mac_address and was random before?

Probably, yes.

> - Would it make sense to add a new state (e.g. NET_ADDR_USERSPACE)
> if the net address get changed via SIOCSIFHWADDR/.ndo_set_mac_address
> from userspace?

I suspect this is not useful.

2012-02-11 09:14:33

by Daniele Venzano

[permalink] [raw]
Subject: Re: [PATCH 24/50] sis900: use dev_hw_addr_random() instead of random_ether_addr()

Il 08.02.2012 22:10, Danny Kukawka ha scritto:

> Use dev_hw_addr_random() instead of calling random_ether_addr()
> to set addr_assign_type correctly to NET_ADDR_RANDOM.

Acked-by: Daniele Venzano <[email protected]>

> Signed-off-by: Danny Kukawka <[email protected]>
> ---
> drivers/net/ethernet/sis/sis900.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/net/ethernet/sis/sis900.c b/drivers/net/ethernet/sis/sis900.c
> index c8efc70..cbd0343 100644
> --- a/drivers/net/ethernet/sis/sis900.c
> +++ b/drivers/net/ethernet/sis/sis900.c
> @@ -527,7 +527,7 @@ static int __devinit sis900_probe(struct pci_dev *pci_dev,
> ret = sis900_get_mac_addr(pci_dev, net_dev);
>
> if (!ret || !is_valid_ether_addr(net_dev->dev_addr)) {
> - random_ether_addr(net_dev->dev_addr);
> + dev_hw_addr_random(net_dev, net_dev->dev_addr);
> printk(KERN_WARNING "%s: Unreadable or invalid MAC address,"
> "using random generated one\n", dev_name);
> }

2012-02-11 11:18:56

by Marek Lindner

[permalink] [raw]
Subject: Re: [B.A.T.M.A.N.] [PATCH 40/50] batman-adv: use dev_hw_addr_random() instead of random_ether_addr()

On Thursday, February 09, 2012 05:10:47 Danny Kukawka wrote:
> Use dev_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.

Applied (with minor modification) in revision 910ccac.

Thanks,
Marek