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

net: dev: Add extack argument to dev_set_mac_address()

A follow-up patch will add a notifier type NETDEV_PRE_CHANGEADDR, which
allows vetoing of MAC address changes. One prominent path to that
notification is through dev_set_mac_address(). Therefore give this
function an extack argument, so that it can be packed together with the
notification. Thus a textual reason for rejection (or a warning) can be
communicated back to the user.
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 95302c39
...@@ -1031,7 +1031,7 @@ static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[], ...@@ -1031,7 +1031,7 @@ static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[],
*/ */
memcpy(ss.__data, addr, len); memcpy(ss.__data, addr, len);
ss.ss_family = dev->type; ss.ss_family = dev->type;
if (dev_set_mac_address(dev, (struct sockaddr *)&ss)) { if (dev_set_mac_address(dev, (struct sockaddr *)&ss, NULL)) {
netdev_err(slave->bond->dev, "dev_set_mac_address of dev %s failed! ALB mode requires that the base driver support setting the hw address also when the network device's interface is open\n", netdev_err(slave->bond->dev, "dev_set_mac_address of dev %s failed! ALB mode requires that the base driver support setting the hw address also when the network device's interface is open\n",
dev->name); dev->name);
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -1250,7 +1250,7 @@ static int alb_set_mac_address(struct bonding *bond, void *addr) ...@@ -1250,7 +1250,7 @@ static int alb_set_mac_address(struct bonding *bond, void *addr)
bond_hw_addr_copy(tmp_addr, slave->dev->dev_addr, bond_hw_addr_copy(tmp_addr, slave->dev->dev_addr,
slave->dev->addr_len); slave->dev->addr_len);
res = dev_set_mac_address(slave->dev, addr); res = dev_set_mac_address(slave->dev, addr, NULL);
/* restore net_device's hw address */ /* restore net_device's hw address */
bond_hw_addr_copy(slave->dev->dev_addr, tmp_addr, bond_hw_addr_copy(slave->dev->dev_addr, tmp_addr,
...@@ -1273,7 +1273,7 @@ static int alb_set_mac_address(struct bonding *bond, void *addr) ...@@ -1273,7 +1273,7 @@ static int alb_set_mac_address(struct bonding *bond, void *addr)
bond_hw_addr_copy(tmp_addr, rollback_slave->dev->dev_addr, bond_hw_addr_copy(tmp_addr, rollback_slave->dev->dev_addr,
rollback_slave->dev->addr_len); rollback_slave->dev->addr_len);
dev_set_mac_address(rollback_slave->dev, dev_set_mac_address(rollback_slave->dev,
(struct sockaddr *)&ss); (struct sockaddr *)&ss, NULL);
bond_hw_addr_copy(rollback_slave->dev->dev_addr, tmp_addr, bond_hw_addr_copy(rollback_slave->dev->dev_addr, tmp_addr,
rollback_slave->dev->addr_len); rollback_slave->dev->addr_len);
} }
...@@ -1732,7 +1732,8 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave ...@@ -1732,7 +1732,8 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave
bond->dev->addr_len); bond->dev->addr_len);
ss.ss_family = bond->dev->type; ss.ss_family = bond->dev->type;
/* we don't care if it can't change its mac, best effort */ /* we don't care if it can't change its mac, best effort */
dev_set_mac_address(new_slave->dev, (struct sockaddr *)&ss); dev_set_mac_address(new_slave->dev, (struct sockaddr *)&ss,
NULL);
bond_hw_addr_copy(new_slave->dev->dev_addr, tmp_addr, bond_hw_addr_copy(new_slave->dev->dev_addr, tmp_addr,
new_slave->dev->addr_len); new_slave->dev->addr_len);
......
...@@ -680,7 +680,7 @@ static void bond_do_fail_over_mac(struct bonding *bond, ...@@ -680,7 +680,7 @@ static void bond_do_fail_over_mac(struct bonding *bond,
} }
rv = dev_set_mac_address(new_active->dev, rv = dev_set_mac_address(new_active->dev,
(struct sockaddr *)&ss); (struct sockaddr *)&ss, NULL);
if (rv) { if (rv) {
netdev_err(bond->dev, "Error %d setting MAC of slave %s\n", netdev_err(bond->dev, "Error %d setting MAC of slave %s\n",
-rv, new_active->dev->name); -rv, new_active->dev->name);
...@@ -695,7 +695,7 @@ static void bond_do_fail_over_mac(struct bonding *bond, ...@@ -695,7 +695,7 @@ static void bond_do_fail_over_mac(struct bonding *bond,
ss.ss_family = old_active->dev->type; ss.ss_family = old_active->dev->type;
rv = dev_set_mac_address(old_active->dev, rv = dev_set_mac_address(old_active->dev,
(struct sockaddr *)&ss); (struct sockaddr *)&ss, NULL);
if (rv) if (rv)
netdev_err(bond->dev, "Error %d setting MAC of slave %s\n", netdev_err(bond->dev, "Error %d setting MAC of slave %s\n",
-rv, new_active->dev->name); -rv, new_active->dev->name);
...@@ -1527,7 +1527,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev, ...@@ -1527,7 +1527,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
*/ */
memcpy(ss.__data, bond_dev->dev_addr, bond_dev->addr_len); memcpy(ss.__data, bond_dev->dev_addr, bond_dev->addr_len);
ss.ss_family = slave_dev->type; ss.ss_family = slave_dev->type;
res = dev_set_mac_address(slave_dev, (struct sockaddr *)&ss); res = dev_set_mac_address(slave_dev, (struct sockaddr *)&ss,
extack);
if (res) { if (res) {
netdev_dbg(bond_dev, "Error %d calling set_mac_address\n", res); netdev_dbg(bond_dev, "Error %d calling set_mac_address\n", res);
goto err_restore_mtu; goto err_restore_mtu;
...@@ -1818,7 +1819,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev, ...@@ -1818,7 +1819,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
bond_hw_addr_copy(ss.__data, new_slave->perm_hwaddr, bond_hw_addr_copy(ss.__data, new_slave->perm_hwaddr,
new_slave->dev->addr_len); new_slave->dev->addr_len);
ss.ss_family = slave_dev->type; ss.ss_family = slave_dev->type;
dev_set_mac_address(slave_dev, (struct sockaddr *)&ss); dev_set_mac_address(slave_dev, (struct sockaddr *)&ss, NULL);
} }
err_restore_mtu: err_restore_mtu:
...@@ -1999,7 +2000,7 @@ static int __bond_release_one(struct net_device *bond_dev, ...@@ -1999,7 +2000,7 @@ static int __bond_release_one(struct net_device *bond_dev,
bond_hw_addr_copy(ss.__data, slave->perm_hwaddr, bond_hw_addr_copy(ss.__data, slave->perm_hwaddr,
slave->dev->addr_len); slave->dev->addr_len);
ss.ss_family = slave_dev->type; ss.ss_family = slave_dev->type;
dev_set_mac_address(slave_dev, (struct sockaddr *)&ss); dev_set_mac_address(slave_dev, (struct sockaddr *)&ss, NULL);
} }
if (unregister) if (unregister)
...@@ -3732,7 +3733,7 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr) ...@@ -3732,7 +3733,7 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr)
bond_for_each_slave(bond, slave, iter) { bond_for_each_slave(bond, slave, iter) {
netdev_dbg(bond_dev, "slave %p %s\n", slave, slave->dev->name); netdev_dbg(bond_dev, "slave %p %s\n", slave, slave->dev->name);
res = dev_set_mac_address(slave->dev, addr); res = dev_set_mac_address(slave->dev, addr, NULL);
if (res) { if (res) {
/* TODO: consider downing the slave /* TODO: consider downing the slave
* and retry ? * and retry ?
...@@ -3761,7 +3762,7 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr) ...@@ -3761,7 +3762,7 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr)
break; break;
tmp_res = dev_set_mac_address(rollback_slave->dev, tmp_res = dev_set_mac_address(rollback_slave->dev,
(struct sockaddr *)&tmp_ss); (struct sockaddr *)&tmp_ss, NULL);
if (tmp_res) { if (tmp_res) {
netdev_dbg(bond_dev, "unwind err %d dev %s\n", netdev_dbg(bond_dev, "unwind err %d dev %s\n",
tmp_res, rollback_slave->dev->name); tmp_res, rollback_slave->dev->name);
......
...@@ -1247,7 +1247,7 @@ static int netvsc_set_mac_addr(struct net_device *ndev, void *p) ...@@ -1247,7 +1247,7 @@ static int netvsc_set_mac_addr(struct net_device *ndev, void *p)
return -ENODEV; return -ENODEV;
if (vf_netdev) { if (vf_netdev) {
err = dev_set_mac_address(vf_netdev, addr); err = dev_set_mac_address(vf_netdev, addr, NULL);
if (err) if (err)
return err; return err;
} }
...@@ -1258,7 +1258,7 @@ static int netvsc_set_mac_addr(struct net_device *ndev, void *p) ...@@ -1258,7 +1258,7 @@ static int netvsc_set_mac_addr(struct net_device *ndev, void *p)
} else if (vf_netdev) { } else if (vf_netdev) {
/* rollback change on VF */ /* rollback change on VF */
memcpy(addr->sa_data, ndev->dev_addr, ETH_ALEN); memcpy(addr->sa_data, ndev->dev_addr, ETH_ALEN);
dev_set_mac_address(vf_netdev, addr); dev_set_mac_address(vf_netdev, addr, NULL);
} }
return err; return err;
......
...@@ -744,7 +744,7 @@ static int macvlan_set_mac_address(struct net_device *dev, void *p) ...@@ -744,7 +744,7 @@ static int macvlan_set_mac_address(struct net_device *dev, void *p)
if (vlan->mode == MACVLAN_MODE_PASSTHRU) { if (vlan->mode == MACVLAN_MODE_PASSTHRU) {
macvlan_set_addr_change(vlan->port); macvlan_set_addr_change(vlan->port);
return dev_set_mac_address(vlan->lowerdev, addr); return dev_set_mac_address(vlan->lowerdev, addr, NULL);
} }
if (macvlan_addr_busy(vlan->port, addr->sa_data)) if (macvlan_addr_busy(vlan->port, addr->sa_data))
...@@ -1213,7 +1213,7 @@ static void macvlan_port_destroy(struct net_device *dev) ...@@ -1213,7 +1213,7 @@ static void macvlan_port_destroy(struct net_device *dev)
sa.sa_family = port->dev->type; sa.sa_family = port->dev->type;
memcpy(&sa.sa_data, port->perm_addr, port->dev->addr_len); memcpy(&sa.sa_data, port->perm_addr, port->dev->addr_len);
dev_set_mac_address(port->dev, &sa); dev_set_mac_address(port->dev, &sa, NULL);
} }
kfree(port); kfree(port);
......
...@@ -1113,7 +1113,7 @@ static long tap_ioctl(struct file *file, unsigned int cmd, ...@@ -1113,7 +1113,7 @@ static long tap_ioctl(struct file *file, unsigned int cmd,
rtnl_unlock(); rtnl_unlock();
return -ENOLINK; return -ENOLINK;
} }
ret = dev_set_mac_address(tap->dev, &sa); ret = dev_set_mac_address(tap->dev, &sa, NULL);
tap_put_tap_dev(tap); tap_put_tap_dev(tap);
rtnl_unlock(); rtnl_unlock();
return ret; return ret;
......
...@@ -59,7 +59,7 @@ static int __set_port_dev_addr(struct net_device *port_dev, ...@@ -59,7 +59,7 @@ static int __set_port_dev_addr(struct net_device *port_dev,
memcpy(addr.__data, dev_addr, port_dev->addr_len); memcpy(addr.__data, dev_addr, port_dev->addr_len);
addr.ss_family = port_dev->type; addr.ss_family = port_dev->type;
return dev_set_mac_address(port_dev, (struct sockaddr *)&addr); return dev_set_mac_address(port_dev, (struct sockaddr *)&addr, NULL);
} }
static int team_port_set_orig_dev_addr(struct team_port *port) static int team_port_set_orig_dev_addr(struct team_port *port)
......
...@@ -3202,7 +3202,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, ...@@ -3202,7 +3202,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
tun_debug(KERN_DEBUG, tun, "set hw address: %pM\n", tun_debug(KERN_DEBUG, tun, "set hw address: %pM\n",
ifr.ifr_hwaddr.sa_data); ifr.ifr_hwaddr.sa_data);
ret = dev_set_mac_address(tun->dev, &ifr.ifr_hwaddr); ret = dev_set_mac_address(tun->dev, &ifr.ifr_hwaddr, NULL);
break; break;
case TUNGETSNDBUF: case TUNGETSNDBUF:
......
...@@ -879,7 +879,7 @@ int gether_register_netdev(struct net_device *net) ...@@ -879,7 +879,7 @@ int gether_register_netdev(struct net_device *net)
sa.sa_family = net->type; sa.sa_family = net->type;
memcpy(sa.sa_data, dev->dev_mac, ETH_ALEN); memcpy(sa.sa_data, dev->dev_mac, ETH_ALEN);
rtnl_lock(); rtnl_lock();
status = dev_set_mac_address(net, &sa); status = dev_set_mac_address(net, &sa, NULL);
rtnl_unlock(); rtnl_unlock();
if (status) if (status)
pr_warn("cannot set self ethernet address: %d\n", status); pr_warn("cannot set self ethernet address: %d\n", status);
......
...@@ -3628,7 +3628,8 @@ int dev_set_mtu_ext(struct net_device *dev, int mtu, ...@@ -3628,7 +3628,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_set_mac_address(struct net_device *, struct sockaddr *); int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa,
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);
int dev_get_phys_port_id(struct net_device *dev, int dev_get_phys_port_id(struct net_device *dev,
struct netdev_phys_item_id *ppid); struct netdev_phys_item_id *ppid);
......
...@@ -7759,10 +7759,12 @@ EXPORT_SYMBOL(dev_set_group); ...@@ -7759,10 +7759,12 @@ EXPORT_SYMBOL(dev_set_group);
* dev_set_mac_address - Change Media Access Control Address * dev_set_mac_address - Change Media Access Control Address
* @dev: device * @dev: device
* @sa: new address * @sa: new address
* @extack: netlink extended ack
* *
* Change the hardware (MAC) address of the device * Change the hardware (MAC) address of the device
*/ */
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)
{ {
const struct net_device_ops *ops = dev->netdev_ops; const struct net_device_ops *ops = dev->netdev_ops;
int err; int err;
......
...@@ -246,7 +246,7 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd) ...@@ -246,7 +246,7 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
case SIOCSIFHWADDR: case SIOCSIFHWADDR:
if (dev->addr_len > sizeof(struct sockaddr)) if (dev->addr_len > sizeof(struct sockaddr))
return -EINVAL; return -EINVAL;
return dev_set_mac_address(dev, &ifr->ifr_hwaddr); return dev_set_mac_address(dev, &ifr->ifr_hwaddr, NULL);
case SIOCSIFHWBROADCAST: case SIOCSIFHWBROADCAST:
if (ifr->ifr_hwaddr.sa_family != dev->type) if (ifr->ifr_hwaddr.sa_family != dev->type)
......
...@@ -2444,7 +2444,7 @@ static int do_setlink(const struct sk_buff *skb, ...@@ -2444,7 +2444,7 @@ static int do_setlink(const struct sk_buff *skb,
sa->sa_family = dev->type; sa->sa_family = dev->type;
memcpy(sa->sa_data, nla_data(tb[IFLA_ADDRESS]), memcpy(sa->sa_data, nla_data(tb[IFLA_ADDRESS]),
dev->addr_len); dev->addr_len);
err = dev_set_mac_address(dev, sa); err = dev_set_mac_address(dev, sa, extack);
kfree(sa); kfree(sa);
if (err) if (err)
goto errout; goto errout;
......
...@@ -242,7 +242,7 @@ int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info) ...@@ -242,7 +242,7 @@ int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info)
* dev_set_mac_address require RTNL_LOCK * dev_set_mac_address require RTNL_LOCK
*/ */
rtnl_lock(); rtnl_lock();
rc = dev_set_mac_address(dev, &addr); rc = dev_set_mac_address(dev, &addr, NULL);
rtnl_unlock(); rtnl_unlock();
if (rc) if (rc)
goto dev_unregister; goto dev_unregister;
......
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