From patchwork Thu Jun 5 06:50:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ding Tianhong X-Patchwork-Id: 31400 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f69.google.com (mail-qa0-f69.google.com [209.85.216.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6B14D20BF9 for ; Thu, 5 Jun 2014 06:52:20 +0000 (UTC) Received: by mail-qa0-f69.google.com with SMTP id j5sf2569237qaq.8 for ; Wed, 04 Jun 2014 23:52:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=rQFHsiqfGIjthS+C6Ku+aSe6Ve/zatKhHKQzdegAoCg=; b=ME7DLKz9+2YL2RwLnkuLOSlUlIvmCNn26p7w8eJsQVdfN9Ztnt+rARrEiEPtH+nZTj l8VGL21uWaMSVRa1P/vJ4nfm+TGp37p89yBlBgsdf6tH+lugelrYiTE6LFr1WbYJHOxN U0p8nHqHEQha+jvjPf2AtvoOK4PfUwJ8qN06caU1xa3r0WgaxUn7EOewWWQbfM8lbf8D VBeTc6n95Z8zIdDyN8vbvWBSZsWxKhA2W+K781NCKUsIShOuJjXQskqa++k2FNkxDnk+ 6uSkzhUdq3UwKxONYX25BW3HSKTQipFCKic1tWQZbB2s/SMzRBZOwuy7pUvyiVhdwmes I/0A== X-Gm-Message-State: ALoCoQnSEVJmhvCDx+t2Wgu7uwDWhsqWd/XC22p+mVCOTRWW9uJYIk2aA/ybRqm6RSzEb3isQmOx X-Received: by 10.58.238.7 with SMTP id vg7mr24900583vec.22.1401951140128; Wed, 04 Jun 2014 23:52:20 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.29.225 with SMTP id b88ls11771qgb.32.gmail; Wed, 04 Jun 2014 23:52:20 -0700 (PDT) X-Received: by 10.58.201.5 with SMTP id jw5mr48049661vec.6.1401951140028; Wed, 04 Jun 2014 23:52:20 -0700 (PDT) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by mx.google.com with ESMTPS id js7si3270348vec.86.2014.06.04.23.52.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Jun 2014 23:52:19 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.178 as permitted sender) client-ip=209.85.128.178; Received: by mail-ve0-f178.google.com with SMTP id sa20so687721veb.9 for ; Wed, 04 Jun 2014 23:52:19 -0700 (PDT) X-Received: by 10.52.25.130 with SMTP id c2mr36493823vdg.27.1401951139930; Wed, 04 Jun 2014 23:52:19 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.54.6 with SMTP id vs6csp103005vcb; Wed, 4 Jun 2014 23:52:19 -0700 (PDT) X-Received: by 10.68.240.5 with SMTP id vw5mr72497066pbc.113.1401951139228; Wed, 04 Jun 2014 23:52:19 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id zk3si10955523pbb.155.2014.06.04.23.52.18; Wed, 04 Jun 2014 23:52:18 -0700 (PDT) Received-SPF: none (google.com: netdev-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751175AbaFEGv0 (ORCPT + 3 others); Thu, 5 Jun 2014 02:51:26 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:25961 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751065AbaFEGvZ (ORCPT ); Thu, 5 Jun 2014 02:51:25 -0400 Received: from 172.24.2.119 (EHLO szxeml214-edg.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BUS39422; Thu, 05 Jun 2014 14:50:44 +0800 (CST) Received: from SZXEML423-HUB.china.huawei.com (10.82.67.162) by szxeml214-edg.china.huawei.com (172.24.2.29) with Microsoft SMTP Server (TLS) id 14.3.158.1; Thu, 5 Jun 2014 14:50:39 +0800 Received: from localhost (10.177.22.246) by szxeml423-hub.china.huawei.com (10.82.67.162) with Microsoft SMTP Server id 14.3.158.1; Thu, 5 Jun 2014 14:50:32 +0800 From: Ding Tianhong To: , , , CC: Subject: [PATCH net-next 3/4] net: dev: revert the mac address when notifier failed Date: Thu, 5 Jun 2014 14:50:27 +0800 Message-ID: <1401951028-9800-4-git-send-email-dingtianhong@huawei.com> X-Mailer: git-send-email 1.8.5.2.msysgit.0 In-Reply-To: <1401951028-9800-1-git-send-email-dingtianhong@huawei.com> References: <1401951028-9800-1-git-send-email-dingtianhong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.22.246] X-CFilter-Loop: Reflected Sender: netdev-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: netdev@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: dingtianhong@huawei.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.178 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- 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);