Commit d59cdf94 authored by Petr Machata's avatar Petr Machata Committed by David S. Miller

net: dev: Issue NETDEV_PRE_CHANGEADDR

When a device address is about to be changed, or an address added to the
list of device HW addresses, it is necessary to ensure that all
interested parties can support the address. Therefore, send the
NETDEV_PRE_CHANGEADDR notification, and if anyone bails on it, do not
change the address.
Signed-off-by: default avatarPetr Machata <petrm@mellanox.com>
Acked-by: default avatarJiri Pirko <jiri@mellanox.com>
Reviewed-by: default avatarIdo Schimmel <idosch@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1570415f
...@@ -3634,6 +3634,8 @@ int dev_set_mtu_ext(struct net_device *dev, int mtu, ...@@ -3634,6 +3634,8 @@ int dev_set_mtu_ext(struct net_device *dev, int mtu,
int dev_set_mtu(struct net_device *, int); int dev_set_mtu(struct net_device *, int);
int dev_change_tx_queue_len(struct net_device *, unsigned long); int dev_change_tx_queue_len(struct net_device *, unsigned long);
void dev_set_group(struct net_device *, int); void dev_set_group(struct net_device *, int);
int dev_pre_changeaddr_notify(struct net_device *dev, const char *addr,
struct netlink_ext_ack *extack);
int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa, int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa,
struct netlink_ext_ack *extack); struct netlink_ext_ack *extack);
int dev_change_carrier(struct net_device *, bool new_carrier); int dev_change_carrier(struct net_device *, bool new_carrier);
......
...@@ -7756,6 +7756,27 @@ void dev_set_group(struct net_device *dev, int new_group) ...@@ -7756,6 +7756,27 @@ void dev_set_group(struct net_device *dev, int new_group)
} }
EXPORT_SYMBOL(dev_set_group); EXPORT_SYMBOL(dev_set_group);
/**
* dev_pre_changeaddr_notify - Call NETDEV_PRE_CHANGEADDR.
* @dev: device
* @addr: new address
* @extack: netlink extended ack
*/
int dev_pre_changeaddr_notify(struct net_device *dev, const char *addr,
struct netlink_ext_ack *extack)
{
struct netdev_notifier_pre_changeaddr_info info = {
.info.dev = dev,
.info.extack = extack,
.dev_addr = addr,
};
int rc;
rc = call_netdevice_notifiers_info(NETDEV_PRE_CHANGEADDR, &info.info);
return notifier_to_errno(rc);
}
EXPORT_SYMBOL(dev_pre_changeaddr_notify);
/** /**
* dev_set_mac_address - Change Media Access Control Address * dev_set_mac_address - Change Media Access Control Address
* @dev: device * @dev: device
...@@ -7776,6 +7797,9 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa, ...@@ -7776,6 +7797,9 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa,
return -EINVAL; return -EINVAL;
if (!netif_device_present(dev)) if (!netif_device_present(dev))
return -ENODEV; return -ENODEV;
err = dev_pre_changeaddr_notify(dev, sa->sa_data, extack);
if (err)
return err;
err = ops->ndo_set_mac_address(dev, sa); err = ops->ndo_set_mac_address(dev, sa);
if (err) if (err)
return err; return err;
......
...@@ -498,6 +498,9 @@ int dev_addr_add(struct net_device *dev, const unsigned char *addr, ...@@ -498,6 +498,9 @@ int dev_addr_add(struct net_device *dev, const unsigned char *addr,
ASSERT_RTNL(); ASSERT_RTNL();
err = dev_pre_changeaddr_notify(dev, addr, NULL);
if (err)
return err;
err = __hw_addr_add(&dev->dev_addrs, addr, dev->addr_len, addr_type); err = __hw_addr_add(&dev->dev_addrs, addr, dev->addr_len, addr_type);
if (!err) if (!err)
call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
......
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