[PATCH V8 net-next 11/11] net: add ndo_validate_addr check in dev_set_mac_address
From: Jijie Shao
Date: Sun Sep 08 2024 - 22:40:48 EST
If driver implements ndo_validate_addr,
core should check the mac address before ndo_set_mac_address.
Signed-off-by: Jijie Shao <shaojijie@xxxxxxxxxx>
Reviewed-by: Andrew Lunn <andrew@xxxxxxx>
---
ChangeLog:
v2 -> v3:
- Use ndo_validate_addr() instead of is_valid_ether_addr()
in dev_set_mac_address(), suggested by Jakub and Andrew.
v2: https://lore.kernel.org/all/20240820140154.137876-1-shaojijie@xxxxxxxxxx/
---
net/core/dev.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/core/dev.c b/net/core/dev.c
index 98bb5f890b88..d6ec91ea8043 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -9089,6 +9089,11 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa,
return -EOPNOTSUPP;
if (sa->sa_family != dev->type)
return -EINVAL;
+ if (ops->ndo_validate_addr) {
+ err = ops->ndo_validate_addr(dev);
+ if (err)
+ return err;
+ }
if (!netif_device_present(dev))
return -ENODEV;
err = dev_pre_changeaddr_notify(dev, sa->sa_data, extack);
--
2.33.0