From patchwork Sat Jun 7 07:45:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ding Tianhong X-Patchwork-Id: 31510 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f199.google.com (mail-vc0-f199.google.com [209.85.220.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5A2E72100A for ; Sat, 7 Jun 2014 07:46:41 +0000 (UTC) Received: by mail-vc0-f199.google.com with SMTP id ij19sf783347vcb.10 for ; Sat, 07 Jun 2014 00:46:41 -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=buA7nKyyF6G/Q22+lmHefNEL5mvgPqZuaQUQMdEc1aI=; b=H054pU2zvuEjBeDKHq7VcfY9dEvl3kRy+bNP3A3gwp/2BG2KzMbGwesGoK8NJBBqUq KunTAcvLyveOAy2DnnxmlKNHARsJrknfBPrTSo1QIvnzDWB7ZO8yuGQrqjbUQxTcIdzq M5QKQWwVqaRkg30pJVneJ4KcelpeXks3h/2upUf5dNz2WXwkDxSgD8yHs5oeSvUkHbHL 1/njExI/2d9swbK892mQOi1FYVIocviqI6QKBesCakgwRSJKhk6bTw/nsWYhb3se3hCb vWDHtKCpute9TEdrCc1efr7fV0PzVvTFl0rlzbcpGAPqwm6Gmu8eC4Z0q9ReHqrUTUgM XIOw== X-Gm-Message-State: ALoCoQl7JFezRtez3r96zd8BCNGmnT954ZgkjBPbGrMlMTeP8tTfZ9Z2IzMhy+a7XehDTvZfnZzX X-Received: by 10.52.170.145 with SMTP id am17mr5449321vdc.2.1402127201181; Sat, 07 Jun 2014 00:46:41 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.83.50 with SMTP id i47ls978130qgd.38.gmail; Sat, 07 Jun 2014 00:46:41 -0700 (PDT) X-Received: by 10.52.75.40 with SMTP id z8mr8705904vdv.90.1402127201081; Sat, 07 Jun 2014 00:46:41 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id ky16si8366218vdb.106.2014.06.07.00.46.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 07 Jun 2014 00:46:41 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id lf12so4275465vcb.17 for ; Sat, 07 Jun 2014 00:46:41 -0700 (PDT) X-Received: by 10.221.20.199 with SMTP id qp7mr11499947vcb.24.1402127200968; Sat, 07 Jun 2014 00:46:40 -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 vs6csp6584vcb; Sat, 7 Jun 2014 00:46:40 -0700 (PDT) X-Received: by 10.69.25.105 with SMTP id ip9mr318310pbd.145.1402127200220; Sat, 07 Jun 2014 00:46:40 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id az1si24063901pbd.0.2014.06.07.00.46.39; Sat, 07 Jun 2014 00:46:39 -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 S1752818AbaFGHq3 (ORCPT + 3 others); Sat, 7 Jun 2014 03:46:29 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:48739 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752760AbaFGHq2 (ORCPT ); Sat, 7 Jun 2014 03:46:28 -0400 Received: from 172.24.2.119 (EHLO szxeml212-edg.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BUV13313; Sat, 07 Jun 2014 15:45:50 +0800 (CST) Received: from SZXEML424-HUB.china.huawei.com (10.82.67.163) by szxeml212-edg.china.huawei.com (172.24.2.181) with Microsoft SMTP Server (TLS) id 14.3.158.1; Sat, 7 Jun 2014 15:45:44 +0800 Received: from localhost (10.177.22.246) by szxeml424-hub.china.huawei.com (10.82.67.163) with Microsoft SMTP Server id 14.3.158.1; Sat, 7 Jun 2014 15:45:47 +0800 From: Ding Tianhong To: , , , , CC: Subject: [PATCH net-next v2 RESEND 2/4] net: dev: revert the mac address when notifier failed Date: Sat, 7 Jun 2014 15:45:41 +0800 Message-ID: <1402127143-6456-3-git-send-email-dingtianhong@huawei.com> X-Mailer: git-send-email 1.8.5.2.msysgit.0 In-Reply-To: <1402127143-6456-1-git-send-email-dingtianhong@huawei.com> References: <1402127143-6456-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.220.172 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 5367bfb..b0fb3dd 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) @@ -5570,13 +5571,27 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa) return -EINVAL; if (!netif_device_present(dev)) return -ENODEV; + + 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);