Commit 7ce5d222 authored by Danny Kukawka's avatar Danny Kukawka Committed by David S. Miller

net: use eth_hw_addr_random() and reset addr_assign_type

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

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

v2: adapt to renamed eth_hw_addr_random()
Signed-off-by: default avatarDanny Kukawka <danny.kukawka@bisect.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f2cedb63
...@@ -47,6 +47,7 @@ static int dummy_set_address(struct net_device *dev, void *p) ...@@ -47,6 +47,7 @@ static int dummy_set_address(struct net_device *dev, void *p)
if (!is_valid_ether_addr(sa->sa_data)) if (!is_valid_ether_addr(sa->sa_data))
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
dev->addr_assign_type &= ~NET_ADDR_RANDOM;
memcpy(dev->dev_addr, sa->sa_data, ETH_ALEN); memcpy(dev->dev_addr, sa->sa_data, ETH_ALEN);
return 0; return 0;
} }
...@@ -135,7 +136,7 @@ static void dummy_setup(struct net_device *dev) ...@@ -135,7 +136,7 @@ static void dummy_setup(struct net_device *dev)
dev->flags &= ~IFF_MULTICAST; dev->flags &= ~IFF_MULTICAST;
dev->features |= NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO; dev->features |= NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO;
dev->features |= NETIF_F_HW_CSUM | NETIF_F_HIGHDMA | NETIF_F_LLTX; dev->features |= NETIF_F_HW_CSUM | NETIF_F_HIGHDMA | NETIF_F_LLTX;
random_ether_addr(dev->dev_addr); eth_hw_addr_random(dev);
} }
static int dummy_validate(struct nlattr *tb[], struct nlattr *data[]) static int dummy_validate(struct nlattr *tb[], struct nlattr *data[])
......
...@@ -3007,6 +3007,7 @@ int bnx2x_change_mac_addr(struct net_device *dev, void *p) ...@@ -3007,6 +3007,7 @@ int bnx2x_change_mac_addr(struct net_device *dev, void *p)
return rc; return rc;
} }
dev->addr_assign_type &= ~NET_ADDR_RANDOM;
memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
if (netif_running(dev)) if (netif_running(dev))
......
...@@ -9683,7 +9683,7 @@ static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp) ...@@ -9683,7 +9683,7 @@ static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
if (BP_NOMCP(bp)) { if (BP_NOMCP(bp)) {
BNX2X_ERROR("warning: random MAC workaround active\n"); BNX2X_ERROR("warning: random MAC workaround active\n");
random_ether_addr(bp->dev->dev_addr); eth_hw_addr_random(bp->dev);
} else if (IS_MF(bp)) { } else if (IS_MF(bp)) {
val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper); val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
val = MF_CFG_RD(bp, func_mf_config[func].mac_lower); val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
......
...@@ -1012,7 +1012,7 @@ static int xgmac_open(struct net_device *dev) ...@@ -1012,7 +1012,7 @@ static int xgmac_open(struct net_device *dev)
* address using the following linux command: * address using the following linux command:
* ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx */ * ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx */
if (!is_valid_ether_addr(dev->dev_addr)) { if (!is_valid_ether_addr(dev->dev_addr)) {
random_ether_addr(dev->dev_addr); eth_hw_addr_random(dev);
netdev_dbg(priv->dev, "generated random MAC address %pM\n", netdev_dbg(priv->dev, "generated random MAC address %pM\n",
dev->dev_addr); dev->dev_addr);
} }
...@@ -1482,6 +1482,7 @@ static int xgmac_set_mac_address(struct net_device *dev, void *p) ...@@ -1482,6 +1482,7 @@ static int xgmac_set_mac_address(struct net_device *dev, void *p)
if (!is_valid_ether_addr(addr->sa_data)) if (!is_valid_ether_addr(addr->sa_data))
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
dev->addr_assign_type &= ~NET_ADDR_RANDOM;
memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
xgmac_set_mac_addr(ioaddr, dev->dev_addr, 0); xgmac_set_mac_addr(ioaddr, dev->dev_addr, 0);
......
...@@ -629,6 +629,7 @@ static int pxa168_eth_set_mac_address(struct net_device *dev, void *addr) ...@@ -629,6 +629,7 @@ static int pxa168_eth_set_mac_address(struct net_device *dev, void *addr)
if (!is_valid_ether_addr(sa->sa_data)) if (!is_valid_ether_addr(sa->sa_data))
return -EINVAL; return -EINVAL;
memcpy(oldMac, dev->dev_addr, ETH_ALEN); memcpy(oldMac, dev->dev_addr, ETH_ALEN);
dev->addr_assign_type &= ~NET_ADDR_RANDOM;
memcpy(dev->dev_addr, sa->sa_data, ETH_ALEN); memcpy(dev->dev_addr, sa->sa_data, ETH_ALEN);
netif_addr_lock_bh(dev); netif_addr_lock_bh(dev);
update_hash_table_mac_address(pep, oldMac, dev->dev_addr); update_hash_table_mac_address(pep, oldMac, dev->dev_addr);
...@@ -1520,7 +1521,7 @@ static int pxa168_eth_probe(struct platform_device *pdev) ...@@ -1520,7 +1521,7 @@ static int pxa168_eth_probe(struct platform_device *pdev)
INIT_WORK(&pep->tx_timeout_task, pxa168_eth_tx_timeout_task); INIT_WORK(&pep->tx_timeout_task, pxa168_eth_tx_timeout_task);
printk(KERN_INFO "%s:Using random mac address\n", DRIVER_NAME); printk(KERN_INFO "%s:Using random mac address\n", DRIVER_NAME);
random_ether_addr(dev->dev_addr); eth_hw_addr_random(dev);
pep->pd = pdev->dev.platform_data; pep->pd = pdev->dev.platform_data;
pep->rx_ring_size = NUM_RX_DESCS; pep->rx_ring_size = NUM_RX_DESCS;
......
...@@ -1080,6 +1080,7 @@ static int ks8842_set_mac(struct net_device *netdev, void *p) ...@@ -1080,6 +1080,7 @@ static int ks8842_set_mac(struct net_device *netdev, void *p)
if (!is_valid_ether_addr(addr->sa_data)) if (!is_valid_ether_addr(addr->sa_data))
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
netdev->addr_assign_type &= ~NET_ADDR_RANDOM;
memcpy(netdev->dev_addr, mac, netdev->addr_len); memcpy(netdev->dev_addr, mac, netdev->addr_len);
ks8842_write_mac_addr(adapter, mac); ks8842_write_mac_addr(adapter, mac);
...@@ -1211,7 +1212,7 @@ static int __devinit ks8842_probe(struct platform_device *pdev) ...@@ -1211,7 +1212,7 @@ static int __devinit ks8842_probe(struct platform_device *pdev)
ks8842_read_mac_addr(adapter, netdev->dev_addr); ks8842_read_mac_addr(adapter, netdev->dev_addr);
if (!is_valid_ether_addr(netdev->dev_addr)) if (!is_valid_ether_addr(netdev->dev_addr))
random_ether_addr(netdev->dev_addr); eth_hw_addr_random(netdev);
} }
id = ks8842_read16(adapter, 32, REG_SW_ID_AND_ENABLE); id = ks8842_read16(adapter, 32, REG_SW_ID_AND_ENABLE);
......
...@@ -439,7 +439,7 @@ 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); dev->dev_addr);
} }
random_ether_addr(dev->dev_addr); eth_hw_addr_random(dev);
ks8851_write_mac_addr(dev); ks8851_write_mac_addr(dev);
} }
...@@ -1050,6 +1050,7 @@ static int ks8851_set_mac_address(struct net_device *dev, void *addr) ...@@ -1050,6 +1050,7 @@ static int ks8851_set_mac_address(struct net_device *dev, void *addr)
if (!is_valid_ether_addr(sa->sa_data)) if (!is_valid_ether_addr(sa->sa_data))
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
dev->addr_assign_type &= ~NET_ADDR_RANDOM;
memcpy(dev->dev_addr, sa->sa_data, ETH_ALEN); memcpy(dev->dev_addr, sa->sa_data, ETH_ALEN);
return ks8851_write_mac_addr(dev); return ks8851_write_mac_addr(dev);
} }
......
...@@ -1241,6 +1241,7 @@ static int ks_set_mac_address(struct net_device *netdev, void *paddr) ...@@ -1241,6 +1241,7 @@ static int ks_set_mac_address(struct net_device *netdev, void *paddr)
struct sockaddr *addr = paddr; struct sockaddr *addr = paddr;
u8 *da; u8 *da;
netdev->addr_assign_type &= ~NET_ADDR_RANDOM;
memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
da = (u8 *)netdev->dev_addr; da = (u8 *)netdev->dev_addr;
......
...@@ -527,6 +527,7 @@ static int enc28j60_set_mac_address(struct net_device *dev, void *addr) ...@@ -527,6 +527,7 @@ static int enc28j60_set_mac_address(struct net_device *dev, void *addr)
if (!is_valid_ether_addr(address->sa_data)) if (!is_valid_ether_addr(address->sa_data))
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
dev->addr_assign_type &= ~NET_ADDR_RANDOM;
memcpy(dev->dev_addr, address->sa_data, dev->addr_len); memcpy(dev->dev_addr, address->sa_data, dev->addr_len);
return enc28j60_set_hw_macaddr(dev); return enc28j60_set_hw_macaddr(dev);
} }
...@@ -1575,7 +1576,7 @@ static int __devinit enc28j60_probe(struct spi_device *spi) ...@@ -1575,7 +1576,7 @@ static int __devinit enc28j60_probe(struct spi_device *spi)
ret = -EIO; ret = -EIO;
goto error_irq; goto error_irq;
} }
random_ether_addr(dev->dev_addr); eth_hw_addr_random(dev);
enc28j60_set_hw_macaddr(dev); enc28j60_set_hw_macaddr(dev);
/* Board setup must set the relevant edge trigger type; /* Board setup must set the relevant edge trigger type;
......
...@@ -3022,6 +3022,7 @@ static int nv_set_mac_address(struct net_device *dev, void *addr) ...@@ -3022,6 +3022,7 @@ static int nv_set_mac_address(struct net_device *dev, void *addr)
/* synchronized against open : rtnl_lock() held by caller */ /* synchronized against open : rtnl_lock() held by caller */
memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN); memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN);
dev->addr_assign_type &= ~NET_ADDR_RANDOM;
if (netif_running(dev)) { if (netif_running(dev)) {
netif_tx_lock_bh(dev); netif_tx_lock_bh(dev);
...@@ -5741,7 +5742,7 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i ...@@ -5741,7 +5742,7 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
dev_err(&pci_dev->dev, dev_err(&pci_dev->dev,
"Invalid MAC address detected: %pM - Please complain to your hardware vendor.\n", "Invalid MAC address detected: %pM - Please complain to your hardware vendor.\n",
dev->dev_addr); dev->dev_addr);
random_ether_addr(dev->dev_addr); eth_hw_addr_random(dev);
dev_err(&pci_dev->dev, dev_err(&pci_dev->dev,
"Using random MAC address: %pM\n", dev->dev_addr); "Using random MAC address: %pM\n", dev->dev_addr);
} }
......
...@@ -1833,6 +1833,7 @@ static int smsc911x_set_mac_address(struct net_device *dev, void *p) ...@@ -1833,6 +1833,7 @@ static int smsc911x_set_mac_address(struct net_device *dev, void *p)
if (!is_valid_ether_addr(addr->sa_data)) if (!is_valid_ether_addr(addr->sa_data))
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
dev->addr_assign_type &= ~NET_ADDR_RANDOM;
memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
spin_lock_irq(&pdata->mac_lock); spin_lock_irq(&pdata->mac_lock);
...@@ -2485,7 +2486,7 @@ static int __devinit smsc911x_drv_probe(struct platform_device *pdev) ...@@ -2485,7 +2486,7 @@ static int __devinit smsc911x_drv_probe(struct platform_device *pdev)
"Mac Address is read from LAN911x EEPROM"); "Mac Address is read from LAN911x EEPROM");
} else { } else {
/* eeprom values are invalid, generate random MAC */ /* eeprom values are invalid, generate random MAC */
random_ether_addr(dev->dev_addr); eth_hw_addr_random(dev);
smsc911x_set_hw_mac_address(pdata, dev->dev_addr); smsc911x_set_hw_mac_address(pdata, dev->dev_addr);
SMSC_TRACE(pdata, probe, SMSC_TRACE(pdata, probe,
"MAC Address is set to random_ether_addr"); "MAC Address is set to random_ether_addr");
......
...@@ -2190,6 +2190,7 @@ static int tile_net_set_mac_address(struct net_device *dev, void *p) ...@@ -2190,6 +2190,7 @@ static int tile_net_set_mac_address(struct net_device *dev, void *p)
/* ISSUE: Note that "dev_addr" is now a pointer. */ /* ISSUE: Note that "dev_addr" is now a pointer. */
memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
dev->addr_assign_type &= ~NET_ADDR_RANDOM;
return 0; return 0;
} }
...@@ -2254,7 +2255,7 @@ static int tile_net_get_mac(struct net_device *dev) ...@@ -2254,7 +2255,7 @@ static int tile_net_get_mac(struct net_device *dev)
* can't get its MAC address, we are most likely running * can't get its MAC address, we are most likely running
* the simulator, so let's generate a random MAC address. * the simulator, so let's generate a random MAC address.
*/ */
random_ether_addr(dev->dev_addr); eth_hw_addr_random(dev);
} }
return 0; return 0;
......
...@@ -372,6 +372,7 @@ static int macvlan_set_mac_address(struct net_device *dev, void *p) ...@@ -372,6 +372,7 @@ static int macvlan_set_mac_address(struct net_device *dev, void *p)
if (!(dev->flags & IFF_UP)) { if (!(dev->flags & IFF_UP)) {
/* Just copy in the new address */ /* Just copy in the new address */
dev->addr_assign_type &= ~NET_ADDR_RANDOM;
memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
} else { } else {
/* Rehash and update the device filters */ /* Rehash and update the device filters */
...@@ -687,7 +688,7 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev, ...@@ -687,7 +688,7 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
return -EINVAL; return -EINVAL;
if (!tb[IFLA_ADDRESS]) if (!tb[IFLA_ADDRESS])
random_ether_addr(dev->dev_addr); eth_hw_addr_random(dev);
if (!macvlan_port_exists(lowerdev)) { if (!macvlan_port_exists(lowerdev)) {
err = macvlan_port_create(lowerdev); err = macvlan_port_create(lowerdev);
......
...@@ -868,6 +868,7 @@ static int team_set_mac_address(struct net_device *dev, void *p) ...@@ -868,6 +868,7 @@ static int team_set_mac_address(struct net_device *dev, void *p)
struct team_port *port; struct team_port *port;
struct sockaddr *addr = p; struct sockaddr *addr = p;
dev->addr_assign_type &= ~NET_ADDR_RANDOM;
memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
rcu_read_lock(); rcu_read_lock();
list_for_each_entry_rcu(port, &team->port_list, list) list_for_each_entry_rcu(port, &team->port_list, list)
...@@ -1087,7 +1088,7 @@ static int team_newlink(struct net *src_net, struct net_device *dev, ...@@ -1087,7 +1088,7 @@ static int team_newlink(struct net *src_net, struct net_device *dev,
int err; int err;
if (tb[IFLA_ADDRESS] == NULL) if (tb[IFLA_ADDRESS] == NULL)
random_ether_addr(dev->dev_addr); eth_hw_addr_random(dev);
err = register_netdevice(dev); err = register_netdevice(dev);
if (err) if (err)
......
...@@ -171,6 +171,7 @@ static int br_set_mac_address(struct net_device *dev, void *p) ...@@ -171,6 +171,7 @@ static int br_set_mac_address(struct net_device *dev, void *p)
spin_lock_bh(&br->lock); spin_lock_bh(&br->lock);
if (compare_ether_addr(dev->dev_addr, addr->sa_data)) { if (compare_ether_addr(dev->dev_addr, addr->sa_data)) {
dev->addr_assign_type &= ~NET_ADDR_RANDOM;
memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
br_fdb_change_mac_address(br, addr->sa_data); br_fdb_change_mac_address(br, addr->sa_data);
br_stp_change_bridge_id(br, addr->sa_data); br_stp_change_bridge_id(br, addr->sa_data);
...@@ -334,7 +335,7 @@ void br_dev_setup(struct net_device *dev) ...@@ -334,7 +335,7 @@ void br_dev_setup(struct net_device *dev)
{ {
struct net_bridge *br = netdev_priv(dev); struct net_bridge *br = netdev_priv(dev);
random_ether_addr(dev->dev_addr); eth_hw_addr_random(dev);
ether_setup(dev); ether_setup(dev);
dev->netdev_ops = &br_netdev_ops; dev->netdev_ops = &br_netdev_ops;
......
...@@ -66,6 +66,7 @@ static int internal_dev_mac_addr(struct net_device *dev, void *p) ...@@ -66,6 +66,7 @@ static int internal_dev_mac_addr(struct net_device *dev, void *p)
if (!is_valid_ether_addr(addr->sa_data)) if (!is_valid_ether_addr(addr->sa_data))
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
dev->addr_assign_type &= ~NET_ADDR_RANDOM;
memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
return 0; return 0;
} }
...@@ -145,7 +146,7 @@ static void do_setup(struct net_device *netdev) ...@@ -145,7 +146,7 @@ static void do_setup(struct net_device *netdev)
netdev->vlan_features = netdev->features; netdev->vlan_features = netdev->features;
netdev->features |= NETIF_F_HW_VLAN_TX; netdev->features |= NETIF_F_HW_VLAN_TX;
netdev->hw_features = netdev->features & ~NETIF_F_LLTX; netdev->hw_features = netdev->features & ~NETIF_F_LLTX;
random_ether_addr(netdev->dev_addr); eth_hw_addr_random(netdev);
} }
static struct vport *internal_dev_create(const struct vport_parms *parms) static struct vport *internal_dev_create(const struct vport_parms *parms)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment