All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ding Tianhong <dingtianhong@huawei.com>
To: <kaber@trash.net>, <davem@davemloft.net>, <edumazet@google.com>,
	<vyasevic@redhat.com>
Cc: <netdev@vger.kernel.org>
Subject: [PATCH net-next 3/4] net: dev: revert the mac address when notifier failed
Date: Thu, 5 Jun 2014 14:50:27 +0800	[thread overview]
Message-ID: <1401951028-9800-4-git-send-email-dingtianhong@huawei.com> (raw)
In-Reply-To: <1401951028-9800-1-git-send-email-dingtianhong@huawei.com>

When set a new mac address to a netdev, the dev should propagate
to the upperdev or lowerdev and make sure the new mac address could
work well with other devs, otherwise the new mac address shouldn't
be set and revert the old mac address.

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

diff --git a/net/core/dev.c b/net/core/dev.c
index 4008a51..fc07b8f 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5562,6 +5562,7 @@ EXPORT_SYMBOL(dev_set_group);
 int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
 {
 	const struct net_device_ops *ops = dev->netdev_ops;
+	struct sockaddr old_sa;
 	int err;
 
 	if (!ops->ndo_set_mac_address)
@@ -5572,13 +5573,27 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
 		return -ENODEV;
 	if (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);
+
 	err = ops->ndo_set_mac_address(dev, sa);
 	if (err)
 		return err;
-	dev->addr_assign_type = NET_ADDR_SET;
-	call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
-	add_device_randomness(dev->dev_addr, dev->addr_len);
-	return 0;
+
+	err = call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
+	err = notifier_to_errno(err);
+	if (err) {
+		/* setting mac address back and notify everyone again,
+		 *  so that they have a chance to revert changes.
+		 */
+		ops->ndo_set_mac_address(dev, &old_sa);
+		call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
+	} else {
+		dev->addr_assign_type = NET_ADDR_SET;
+		add_device_randomness(dev->dev_addr, dev->addr_len);
+	}
+	return err;
 }
 EXPORT_SYMBOL(dev_set_mac_address);
 
-- 
1.8.0

  parent reply	other threads:[~2014-06-05  6:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-05  6:50 [PATCH net-next 0/4] macvlan: fix some problem if mac address changes Ding Tianhong
2014-06-05  6:50 ` [PATCH net-next 1/4] macvlan: don't update the uc and vlan list for L2 forwarding offload Ding Tianhong
2014-06-05 13:52   ` Vlad Yasevich
2014-06-05 14:12     ` John Fastabend
2014-06-05  6:50 ` [PATCH net-next 2/4] net: dev: don't set the same mac address for netdev Ding Tianhong
2014-06-05  9:09   ` Toshiaki Makita
2014-06-05  9:50     ` Ding Tianhong
2014-06-05 10:51       ` Toshiaki Makita
2014-06-05 11:42         ` Ding Tianhong
2014-06-05 14:06       ` Vlad Yasevich
2014-06-06  3:54         ` Ding Tianhong
2014-06-06 14:09           ` Vlad Yasevich
2014-06-07  5:53             ` Ding Tianhong
2014-06-05  6:50 ` Ding Tianhong [this message]
2014-06-05  6:50 ` [PATCH net-next 4/4] macvlan: don't set the same mac address for non-passthru mode Ding Tianhong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1401951028-9800-4-git-send-email-dingtianhong@huawei.com \
    --to=dingtianhong@huawei.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kaber@trash.net \
    --cc=netdev@vger.kernel.org \
    --cc=vyasevic@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.