From patchwork Tue Sep 15 14:22:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 53676 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by patches.linaro.org (Postfix) with ESMTPS id E392022DE5 for ; Tue, 15 Sep 2015 14:44:40 +0000 (UTC) Received: by wisv5 with SMTP id v5sf9127766wis.0 for ; Tue, 15 Sep 2015 07:44:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=JpLxhf2cBVgPVKYMeLx7ujCzbpM7Z645EbZP/y8zAHY=; b=Z9VvGAHPYJofBSA10lQswfHqqjqbPGKBnmmZvMO+mXQ0Ag3HnSacD1rIZ8se79Oy81 ZPvmXAD/aEgo8Z7ABenTLv0YxyTXEN8RhHRFrANKxFqM4oajQniI9IGlIDoLfweSzvlI jFqgtHGuNcXW9/vojMWdbd6LDHPpwdy6pBzQjr4sFjGhomQO2AlCmwvLEcbg/N6MOkMF ye2EUVozuauImkfoL545o9GPYuGuTJrnnDyhT9bBIDjUzW9BG4TZVU/BOWd6xwaGQVo6 9i5fIh3ipPT2itogF4hwrl/6myh7PDQKaXWUVdOddLBCRYkwQmrOqlPfskAgC1YCjh9G QRlw== X-Gm-Message-State: ALoCoQlGbO1Tp4NV5H+oYE6FeWjA3uNl4uDIURJpb8z2BxipX8j9DazHpz9w9enlaDclCXlhMdA+ X-Received: by 10.180.35.132 with SMTP id h4mr863059wij.5.1442328280267; Tue, 15 Sep 2015 07:44:40 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.230 with SMTP id e6ls648692lah.66.gmail; Tue, 15 Sep 2015 07:44:40 -0700 (PDT) X-Received: by 10.152.27.163 with SMTP id u3mr21706242lag.105.1442328280088; Tue, 15 Sep 2015 07:44:40 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id sk1si14083176lbb.44.2015.09.15.07.44.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Sep 2015 07:44:40 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by lagj9 with SMTP id j9so110733392lag.2 for ; Tue, 15 Sep 2015 07:44:40 -0700 (PDT) X-Received: by 10.152.170.225 with SMTP id ap1mr12636407lac.72.1442328279929; Tue, 15 Sep 2015 07:44: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.112.59.35 with SMTP id w3csp1848191lbq; Tue, 15 Sep 2015 07:44:38 -0700 (PDT) X-Received: by 10.66.236.74 with SMTP id us10mr48786088pac.64.1442328278777; Tue, 15 Sep 2015 07:44:38 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k13si32339137pbq.238.2015.09.15.07.44.34; Tue, 15 Sep 2015 07:44:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754580AbbIOOn5 (ORCPT + 29 others); Tue, 15 Sep 2015 10:43:57 -0400 Received: from mx2.suse.de ([195.135.220.15]:60469 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752839AbbIOOWq (ORCPT ); Tue, 15 Sep 2015 10:22:46 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D117CACCE; Tue, 15 Sep 2015 14:22:44 +0000 (UTC) From: Jiri Slaby To: stable@vger.kernel.org Cc: linux-kernel@vger.kernel.org, dingtianhong , "David S. Miller" , Jiri Slaby Subject: [PATCH 3.12 19/33] bonding: correct the MAC address for "follow" fail_over_mac policy Date: Tue, 15 Sep 2015 16:22:14 +0200 Message-Id: <0068a2e07e38b0dd17c3b30efb3af5089c49cef1.1442326825.git.jslaby@suse.cz> X-Mailer: git-send-email 2.5.2 In-Reply-To: <350624fa32cb152bfec51f236b0b62b8d480a05a.1442326825.git.jslaby@suse.cz> References: <350624fa32cb152bfec51f236b0b62b8d480a05a.1442326825.git.jslaby@suse.cz> In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linux-kernel-owner@vger.kernel.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) smtp.mailfrom=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: , From: dingtianhong 3.12-stable review patch. If anyone has any objections, please let me know. =============== [ Upstream commit a951bc1e6ba58f11df5ed5ddc41311e10f5fd20b ] The "follow" fail_over_mac policy is useful for multiport devices that either become confused or incur a performance penalty when multiple ports are programmed with the same MAC address, but the same MAC address still may happened by this steps for this policy: 1) echo +eth0 > /sys/class/net/bond0/bonding/slaves bond0 has the same mac address with eth0, it is MAC1. 2) echo +eth1 > /sys/class/net/bond0/bonding/slaves eth1 is backup, eth1 has MAC2. 3) ifconfig eth0 down eth1 became active slave, bond will swap MAC for eth0 and eth1, so eth1 has MAC1, and eth0 has MAC2. 4) ifconfig eth1 down there is no active slave, and eth1 still has MAC1, eth2 has MAC2. 5) ifconfig eth0 up the eth0 became active slave again, the bond set eth0 to MAC1. Something wrong here, then if you set eth1 up, the eth0 and eth1 will have the same MAC address, it will break this policy for ACTIVE_BACKUP mode. This patch will fix this problem by finding the old active slave and swap them MAC address before change active slave. Signed-off-by: Ding Tianhong Tested-by: Nikolay Aleksandrov Signed-off-by: David S. Miller Signed-off-by: Jiri Slaby --- drivers/net/bonding/bond_main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 806ada973b9f..b3892b0d2e61 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -671,6 +671,22 @@ static void bond_set_dev_addr(struct net_device *bond_dev, call_netdevice_notifiers(NETDEV_CHANGEADDR, bond_dev); } +static struct slave *bond_get_old_active(struct bonding *bond, + struct slave *new_active) +{ + struct slave *slave; + + bond_for_each_slave(bond, slave) { + if (slave == new_active) + continue; + + if (ether_addr_equal(bond->dev->dev_addr, slave->dev->dev_addr)) + return slave; + } + + return NULL; +} + /* * bond_do_fail_over_mac * @@ -712,6 +728,9 @@ static void bond_do_fail_over_mac(struct bonding *bond, write_unlock_bh(&bond->curr_slave_lock); read_unlock(&bond->lock); + if (!old_active) + old_active = bond_get_old_active(bond, new_active); + if (old_active) { memcpy(tmp_mac, new_active->dev->dev_addr, ETH_ALEN); memcpy(saddr.sa_data, old_active->dev->dev_addr,