net: fix net device address assign type

Commit ad72c4a06a introduced optimization to return from function
quickly if the MAC address is not changing at all. It was reported
that such change causes dev->addr_assign_type to not change
to NET_ADDR_SET from _PERM or _RANDOM.
Restore the old behavior and skip only call to ndo_set_mac_address.

Fixes: ad72c4a06a ("net: add check for current MAC address in dev_set_mac_address")
Reported-by: Gal Pressman <gal@nvidia.com>
Signed-off-by: Piotr Gardocki <piotrx.gardocki@intel.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Link: https://lore.kernel.org/r/20230621132106.991342-1-piotrx.gardocki@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Piotr Gardocki 2023-06-21 15:21:06 +02:00 коммит произвёл Jakub Kicinski
Родитель 9a14f2e3da
Коммит 0ec92a8f56
1 изменённых файлов: 5 добавлений и 5 удалений

Просмотреть файл

@ -8781,14 +8781,14 @@ 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;
if (!memcmp(dev->dev_addr, sa->sa_data, dev->addr_len))
return 0;
err = dev_pre_changeaddr_notify(dev, sa->sa_data, extack); err = dev_pre_changeaddr_notify(dev, sa->sa_data, extack);
if (err) if (err)
return err; return err;
err = ops->ndo_set_mac_address(dev, sa); if (memcmp(dev->dev_addr, sa->sa_data, dev->addr_len)) {
if (err) err = ops->ndo_set_mac_address(dev, sa);
return err; if (err)
return err;
}
dev->addr_assign_type = NET_ADDR_SET; dev->addr_assign_type = NET_ADDR_SET;
call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
add_device_randomness(dev->dev_addr, dev->addr_len); add_device_randomness(dev->dev_addr, dev->addr_len);