[net-next,v2,RESEND,4/4] net: dev: don't set the same mac address for netdev

Message ID 1402127143-6456-5-git-send-email-dingtianhong@huawei.com
State New
Headers show

Commit Message

Ding Tianhong June 7, 2014, 7:45 a.m.
Most of netdev just link bond, team, vlan will set the mac address
and propagate to the upperdev or lowerdev regardless the mac address
is same or not, setting a same mac address make no sense for most of
the netdev, but some netdev need a flag to see whether the ndo_set_mac_address()
is called and decide what to do next, so don't do anything if the address
has already been set by user and it is the same as before, otherwise set
the same address to the netdev.

Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>
---
 net/core/dev.c | 7 +++++++
 1 file changed, 7 insertions(+)

Patch

diff --git a/net/core/dev.c b/net/core/dev.c
index b0fb3dd..201d88b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5572,6 +5572,13 @@  int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
 	if (!netif_device_present(dev))
 		return -ENODEV;
 
+	/* If the address has already been set by user and it
+	 * is the same as before, don't do anything.
+	 */
+	if (dev->addr_assign_type == NET_ADDR_SET &&
+	    ether_addr_equal_64bits(dev->dev_addr, sa->sa_data))
+		return 0;
+
 	old_sa.sa_family = dev->type;
 	ether_addr_copy(old_sa.sa_data, dev->dev_addr);