From patchwork Thu Jun 5 12:01:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ding Tianhong X-Patchwork-Id: 31415 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f72.google.com (mail-qa0-f72.google.com [209.85.216.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 887E8203AC for ; Thu, 5 Jun 2014 12:01:39 +0000 (UTC) Received: by mail-qa0-f72.google.com with SMTP id hw13sf3737241qab.3 for ; Thu, 05 Jun 2014 05:01:39 -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=lP3za8dffgH4URmlda5/dAA/6XvSQXenqljOnxmnnRN9xINL4UhOwZAxLg1jwERKKj FyBjqyUFct74KQlMkKpqwBwj+PiPz0Q4Q1QCgID6ipk/GaXe3gN5aT5F7h/8dlzPxfeA nSJdARzmsEqODFXK1/HBHH9T4nDiH1Zyepv5OBQit6qt+V63527qsYLlzS8twSQYSqN8 fX/Gu4rvBaN1YgBFLQ7jyu3e3MzXEWXq7NYeS8H3IkTou9LYBXOR9xPL1Pa64DmghzR5 pAtfj0WhNtR2IoZyi+SCYUT/Ia17XyRFK7WulK75Pw7U7B+VE7eRDjm9QIeOD+kFk0su FAkA== X-Gm-Message-State: ALoCoQkgYqvu+7EkCpiGY5EDXi4EHk5aXxyQN8lI/y4TxX627yRIsdVydot2EuAS39VkknJTR4gY X-Received: by 10.236.172.168 with SMTP id t28mr2980781yhl.45.1401969699213; Thu, 05 Jun 2014 05:01:39 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.97.200 with SMTP id m66ls118632qge.83.gmail; Thu, 05 Jun 2014 05:01:39 -0700 (PDT) X-Received: by 10.58.82.106 with SMTP id h10mr946230vey.60.1401969699104; Thu, 05 Jun 2014 05:01:39 -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 hf4si3538684vdb.99.2014.06.05.05.01.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 05 Jun 2014 05:01:39 -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 sa20so1042881veb.9 for ; Thu, 05 Jun 2014 05:01:39 -0700 (PDT) X-Received: by 10.53.10.234 with SMTP id ed10mr6766779vdd.86.1401969699011; Thu, 05 Jun 2014 05:01:39 -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 vs6csp10840vcb; Thu, 5 Jun 2014 05:01:38 -0700 (PDT) X-Received: by 10.68.226.197 with SMTP id ru5mr76597121pbc.77.1401969698165; Thu, 05 Jun 2014 05:01:38 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id nw8si12398477pbb.72.2014.06.05.05.01.37; Thu, 05 Jun 2014 05:01:37 -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 S1751383AbaFEMBc (ORCPT + 3 others); Thu, 5 Jun 2014 08:01:32 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:30565 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750944AbaFEMB2 (ORCPT ); Thu, 5 Jun 2014 08:01:28 -0400 Received: from 172.24.2.119 (EHLO szxeml210-edg.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BUS78921; Thu, 05 Jun 2014 20:01:12 +0800 (CST) Received: from SZXEML418-HUB.china.huawei.com (10.82.67.157) by szxeml210-edg.china.huawei.com (172.24.2.183) with Microsoft SMTP Server (TLS) id 14.3.158.1; Thu, 5 Jun 2014 20:01:08 +0800 Received: from localhost (10.177.22.246) by szxeml418-hub.china.huawei.com (10.82.67.157) with Microsoft SMTP Server id 14.3.158.1; Thu, 5 Jun 2014 20:01:06 +0800 From: Ding Tianhong To: , , , , CC: Subject: [PATCH net-next v2 2/3] net: dev: revert the mac address when notifier failed Date: Thu, 5 Jun 2014 20:01:02 +0800 Message-ID: <1401969663-4464-3-git-send-email-dingtianhong@huawei.com> X-Mailer: git-send-email 1.8.5.2.msysgit.0 In-Reply-To: <1401969663-4464-1-git-send-email-dingtianhong@huawei.com> References: <1401969663-4464-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 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);