From patchwork Thu Jan 24 20:01:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 215494 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id B687C2C0084 for ; Fri, 25 Jan 2013 07:01:35 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753852Ab3AXUBd (ORCPT ); Thu, 24 Jan 2013 15:01:33 -0500 Received: from mail-we0-f171.google.com ([74.125.82.171]:50731 "EHLO mail-we0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752677Ab3AXUBb (ORCPT ); Thu, 24 Jan 2013 15:01:31 -0500 Received: by mail-we0-f171.google.com with SMTP id u3so3059574wey.2 for ; Thu, 24 Jan 2013 12:01:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:mime-version :content-type:content-transfer-encoding:x-gm-message-state; bh=RQrVhb445VdT9hBaYhF3g4BTfPsnz8UEFSpuh+keuXI=; b=jtjpq7r+Z7wT9pdg2f8W/RFncRBXUJcYWthJfbGxMWJjD6SnNAoYH8vwb0CUS/K9VZ ph6ycNGkOj7CcmzCo/Z1pVr+0KJph4HdmrG8RDr6GzhkvMqrO/4O5g23eI0GuobIcs/h 1Gp99o0V0CfJMkMq3QNGmSuIzueLdBtNSZxA5Fn5id8/RgAV7R6oBib54DxS0tZseSEo HgwdxbkVyi54DhToZfqNrGvwhaGy+9C3v0K0eegSFasLtvIMOY/PW99AhN4ojYt3LpAU KBP/UhKXqRB/sHVEgqOzd7cfAWvdEBvFhrdMRGW40EU38A/6hROb8jrKYuEukA7teft7 FiIQ== X-Received: by 10.180.109.195 with SMTP id hu3mr5047484wib.31.1359057689749; Thu, 24 Jan 2013 12:01:29 -0800 (PST) Received: from localhost (ip-94-112-98-141.net.upcbroadband.cz. [94.112.98.141]) by mx.google.com with ESMTPS id hg17sm3848285wib.1.2013.01.24.12.01.27 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 24 Jan 2013 12:01:28 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, fubar@us.ibm.com, andy@greyhouse.net, stephen@networkplumber.org, psimerda@redhat.com, dcbw@redhat.com Subject: [patch net-next V2] bond: have random dev address by default instead of zeroes Date: Thu, 24 Jan 2013 21:01:24 +0100 Message-Id: <1359057684-6732-1-git-send-email-jiri@resnulli.us> X-Mailer: git-send-email 1.8.1 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQl0NG7DUQ1XgoqMEH6390Lq1jfRMR0FExp+56LJD8PS3sFasyaSf8B82K4U5H9rPICTpNcr Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Makes more sense to have randomly generated address by default than to have all zeroes. It also allows user to for example put the bond into bridge without need to have any slaves in it. Also note that this changes only behaviour of bonds with no slaves. Once the first slave device is enslaved, its address will be used (no change here). Also, fix dev_assign_type values on the way. Reported-by: Pavel Šimerda Signed-off-by: Jiri Pirko --- v1->v2: - fixed assign value of bond_dev->addr_assign_type in bond_set_dev_addr() - added note to patch description drivers/net/bonding/bond_main.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 564cf42..1d56ac9 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -1320,14 +1320,14 @@ static void bond_netpoll_cleanup(struct net_device *bond_dev) /*---------------------------------- IOCTL ----------------------------------*/ -static int bond_sethwaddr(struct net_device *bond_dev, - struct net_device *slave_dev) +static void bond_set_dev_addr(struct net_device *bond_dev, + struct net_device *slave_dev) { pr_debug("bond_dev=%p\n", bond_dev); pr_debug("slave_dev=%p\n", slave_dev); pr_debug("slave_dev->addr_len=%d\n", slave_dev->addr_len); memcpy(bond_dev->dev_addr, slave_dev->dev_addr, slave_dev->addr_len); - return 0; + bond_dev->addr_assign_type = NET_ADDR_SET; } static netdev_features_t bond_fix_features(struct net_device *dev, @@ -1628,10 +1628,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) /* If this is the first slave, then we need to set the master's hardware * address to be the same as the slave's. */ - if (is_zero_ether_addr(bond->dev->dev_addr)) - memcpy(bond->dev->dev_addr, slave_dev->dev_addr, - slave_dev->addr_len); - + if (bond->dev->addr_assign_type != NET_ADDR_SET) + bond_set_dev_addr(bond->dev, slave_dev); new_slave = kzalloc(sizeof(struct slave), GFP_KERNEL); if (!new_slave) { @@ -2049,11 +2047,11 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev) if (bond->slave_cnt == 0) { bond_set_carrier(bond); - /* if the last slave was removed, zero the mac address - * of the master so it will be set by the application - * to the mac address of the first slave + /* If the last slave was removed, set random mac address + * of the master so it will be set by bond_enslave() + * to the mac address of the first slave. */ - memset(bond_dev->dev_addr, 0, bond_dev->addr_len); + eth_hw_addr_random(bond_dev); if (bond_vlan_used(bond)) { pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n", @@ -3708,7 +3706,8 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd break; case BOND_SETHWADDR_OLD: case SIOCBONDSETHWADDR: - res = bond_sethwaddr(bond_dev, slave_dev); + bond_set_dev_addr(bond_dev, slave_dev); + res = 0; break; case BOND_CHANGE_ACTIVE_OLD: case SIOCBONDCHANGEACTIVE: @@ -4858,6 +4857,11 @@ static int bond_init(struct net_device *bond_dev) bond_debug_register(bond); + /* Ensure valid dev_addr */ + if (is_zero_ether_addr(bond_dev->dev_addr) && + bond_dev->addr_assign_type == NET_ADDR_PERM) + eth_hw_addr_random(bond_dev); + __hw_addr_init(&bond->mc_list); return 0; }