Commit 61c8106e authored by David S. Miller's avatar David S. Miller

Merge branch 'addr_assign_type'

Bjørn Mork says:

====================
net: set addr_assign_type when inheriting a dev_addr

Copying the dev_addr from a parent device is an operation
common to a number of drivers. The addr_assign_type should
be updated accordingly, either by reusing the value from
the source device or explicitly indicating that the address
is stolen by setting addr_assign_type to NET_ADDR_STOLEN.

This patch set adds a helper copying both the dev_addr and
the addr_assign_type, and use this helper in drivers which
don't currently set the addr_assign_type. Using NET_ADDR_STOLEN
might be more appropriate in some of these cases.  Please
let me know, and I'll update the patch accordingly.

Changes in v2:
 - assuming addr_len == ETH_ALEN to allow optimized memcpy
 - dropped the vt6656 patch due to addr_len being unset in that driver
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 5a17a390 314cb11b
...@@ -823,7 +823,7 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev, ...@@ -823,7 +823,7 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
if (port->count) if (port->count)
return -EINVAL; return -EINVAL;
port->passthru = true; port->passthru = true;
memcpy(dev->dev_addr, lowerdev->dev_addr, ETH_ALEN); eth_hw_addr_inherit(dev, lowerdev);
} }
err = netdev_upper_dev_link(lowerdev, dev); err = netdev_upper_dev_link(lowerdev, dev);
......
...@@ -1974,7 +1974,7 @@ static void team_setup_by_port(struct net_device *dev, ...@@ -1974,7 +1974,7 @@ static void team_setup_by_port(struct net_device *dev,
dev->addr_len = port_dev->addr_len; dev->addr_len = port_dev->addr_len;
dev->mtu = port_dev->mtu; dev->mtu = port_dev->mtu;
memcpy(dev->broadcast, port_dev->broadcast, port_dev->addr_len); memcpy(dev->broadcast, port_dev->broadcast, port_dev->addr_len);
memcpy(dev->dev_addr, port_dev->dev_addr, port_dev->addr_len); eth_hw_addr_inherit(dev, port_dev);
} }
static int team_dev_type_check_change(struct net_device *dev, static int team_dev_type_check_change(struct net_device *dev,
......
...@@ -2693,7 +2693,7 @@ static struct net_device *init_wifidev(struct airo_info *ai, ...@@ -2693,7 +2693,7 @@ static struct net_device *init_wifidev(struct airo_info *ai,
dev->base_addr = ethdev->base_addr; dev->base_addr = ethdev->base_addr;
dev->wireless_data = ethdev->wireless_data; dev->wireless_data = ethdev->wireless_data;
SET_NETDEV_DEV(dev, ethdev->dev.parent); SET_NETDEV_DEV(dev, ethdev->dev.parent);
memcpy(dev->dev_addr, ethdev->dev_addr, dev->addr_len); eth_hw_addr_inherit(dev, ethdev);
err = register_netdev(dev); err = register_netdev(dev);
if (err<0) { if (err<0) {
free_netdev(dev); free_netdev(dev);
......
...@@ -1425,7 +1425,7 @@ static int prism2_hw_init2(struct net_device *dev, int initial) ...@@ -1425,7 +1425,7 @@ static int prism2_hw_init2(struct net_device *dev, int initial)
} }
list_for_each(ptr, &local->hostap_interfaces) { list_for_each(ptr, &local->hostap_interfaces) {
iface = list_entry(ptr, struct hostap_interface, list); iface = list_entry(ptr, struct hostap_interface, list);
memcpy(iface->dev->dev_addr, dev->dev_addr, ETH_ALEN); eth_hw_addr_inherit(iface->dev, dev);
} }
} else if (local->fw_ap) } else if (local->fw_ap)
prism2_check_sta_fw_version(local); prism2_check_sta_fw_version(local);
......
...@@ -66,7 +66,7 @@ struct net_device * hostap_add_interface(struct local_info *local, ...@@ -66,7 +66,7 @@ struct net_device * hostap_add_interface(struct local_info *local,
list_add(&iface->list, &local->hostap_interfaces); list_add(&iface->list, &local->hostap_interfaces);
mdev = local->dev; mdev = local->dev;
memcpy(dev->dev_addr, mdev->dev_addr, ETH_ALEN); eth_hw_addr_inherit(dev, mdev);
dev->base_addr = mdev->base_addr; dev->base_addr = mdev->base_addr;
dev->irq = mdev->irq; dev->irq = mdev->irq;
dev->mem_start = mdev->mem_start; dev->mem_start = mdev->mem_start;
......
...@@ -1017,7 +1017,7 @@ static int lbs_add_mesh(struct lbs_private *priv) ...@@ -1017,7 +1017,7 @@ static int lbs_add_mesh(struct lbs_private *priv)
mesh_dev->netdev_ops = &mesh_netdev_ops; mesh_dev->netdev_ops = &mesh_netdev_ops;
mesh_dev->ethtool_ops = &lbs_ethtool_ops; mesh_dev->ethtool_ops = &lbs_ethtool_ops;
memcpy(mesh_dev->dev_addr, priv->dev->dev_addr, ETH_ALEN); eth_hw_addr_inherit(mesh_dev, priv->dev);
SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent); SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
......
...@@ -86,7 +86,7 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked) ...@@ -86,7 +86,7 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
apdev_priv = netdev_priv(pDevice->apdev); apdev_priv = netdev_priv(pDevice->apdev);
*apdev_priv = *pDevice; *apdev_priv = *pDevice;
memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN); eth_hw_addr_inherit(pDevice->apdev, dev);
pDevice->apdev->netdev_ops = &apdev_netdev_ops; pDevice->apdev->netdev_ops = &apdev_netdev_ops;
......
...@@ -460,7 +460,7 @@ int private_ioctl(PSDevice pDevice, struct ifreq *rq) ...@@ -460,7 +460,7 @@ int private_ioctl(PSDevice pDevice, struct ifreq *rq)
} }
if (sValue.dwValue == 1) { if (sValue.dwValue == 1) {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "up wpadev\n"); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "up wpadev\n");
memcpy(pDevice->wpadev->dev_addr, pDevice->dev->dev_addr, ETH_ALEN); eth_hw_addr_inherit(pDevice->wpadev, pDevice->dev);
pDevice->bWPADEVUp = true; pDevice->bWPADEVUp = true;
} else { } else {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "close wpadev\n"); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "close wpadev\n");
......
...@@ -96,7 +96,7 @@ static int wpa_init_wpadev(PSDevice pDevice) ...@@ -96,7 +96,7 @@ static int wpa_init_wpadev(PSDevice pDevice)
wpadev_priv = netdev_priv(pDevice->wpadev); wpadev_priv = netdev_priv(pDevice->wpadev);
*wpadev_priv = *pDevice; *wpadev_priv = *pDevice;
memcpy(pDevice->wpadev->dev_addr, dev->dev_addr, ETH_ALEN); eth_hw_addr_inherit(pDevice->wpadev, dev);
pDevice->wpadev->base_addr = dev->base_addr; pDevice->wpadev->base_addr = dev->base_addr;
pDevice->wpadev->irq = dev->irq; pDevice->wpadev->irq = dev->irq;
pDevice->wpadev->mem_start = dev->mem_start; pDevice->wpadev->mem_start = dev->mem_start;
......
...@@ -198,6 +198,21 @@ static inline void eth_hw_addr_random(struct net_device *dev) ...@@ -198,6 +198,21 @@ static inline void eth_hw_addr_random(struct net_device *dev)
eth_random_addr(dev->dev_addr); eth_random_addr(dev->dev_addr);
} }
/**
* eth_hw_addr_inherit - Copy dev_addr from another net_device
* @dst: pointer to net_device to copy dev_addr to
* @src: pointer to net_device to copy dev_addr from
*
* Copy the Ethernet address from one net_device to another along with
* the address attributes (addr_assign_type).
*/
static inline void eth_hw_addr_inherit(struct net_device *dst,
struct net_device *src)
{
dst->addr_assign_type = src->addr_assign_type;
memcpy(dst->dev_addr, src->dev_addr, ETH_ALEN);
}
/** /**
* compare_ether_addr - Compare two Ethernet addresses * compare_ether_addr - Compare two Ethernet addresses
* @addr1: Pointer to a six-byte array containing the Ethernet address * @addr1: Pointer to a six-byte array containing the Ethernet address
......
...@@ -582,7 +582,7 @@ static int vlan_dev_init(struct net_device *dev) ...@@ -582,7 +582,7 @@ static int vlan_dev_init(struct net_device *dev)
dev->dev_id = real_dev->dev_id; dev->dev_id = real_dev->dev_id;
if (is_zero_ether_addr(dev->dev_addr)) if (is_zero_ether_addr(dev->dev_addr))
memcpy(dev->dev_addr, real_dev->dev_addr, dev->addr_len); eth_hw_addr_inherit(dev, real_dev);
if (is_zero_ether_addr(dev->broadcast)) if (is_zero_ether_addr(dev->broadcast))
memcpy(dev->broadcast, real_dev->broadcast, dev->addr_len); memcpy(dev->broadcast, real_dev->broadcast, dev->addr_len);
......
...@@ -347,7 +347,7 @@ dsa_slave_create(struct dsa_switch *ds, struct device *parent, ...@@ -347,7 +347,7 @@ dsa_slave_create(struct dsa_switch *ds, struct device *parent,
slave_dev->features = master->vlan_features; slave_dev->features = master->vlan_features;
SET_ETHTOOL_OPS(slave_dev, &dsa_slave_ethtool_ops); SET_ETHTOOL_OPS(slave_dev, &dsa_slave_ethtool_ops);
memcpy(slave_dev->dev_addr, master->dev_addr, ETH_ALEN); eth_hw_addr_inherit(slave_dev, master);
slave_dev->tx_queue_len = 0; slave_dev->tx_queue_len = 0;
switch (ds->dst->tag_protocol) { switch (ds->dst->tag_protocol) {
......
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