From patchwork Wed Apr 2 07:00:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?TWFoZXNoIEJhbmRld2FyICjgpK7gpLngpYfgpLYg4KSs4KSC4KSh4KWH4KS14KS+4KSwKQ==?= X-Patchwork-Id: 336258 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 243B8140311 for ; Wed, 2 Apr 2014 18:05:39 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932094AbaDBHFb (ORCPT ); Wed, 2 Apr 2014 03:05:31 -0400 Received: from mail-ob0-f202.google.com ([209.85.214.202]:35305 "EHLO mail-ob0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932088AbaDBHF3 (ORCPT ); Wed, 2 Apr 2014 03:05:29 -0400 Received: by mail-ob0-f202.google.com with SMTP id wo20so2207534obc.3 for ; Wed, 02 Apr 2014 00:05:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=uXeczbpfos242B5D1iwyiU1J77zH0lxDLAqIkkAb5YI=; b=Mxr+4DcR2AK8kJKe971CedteiIvGYanjWqyKEnh+12QwE881aKSxBK1TbSEV8N1DYA JUaP+/2WhZcfrizuzYYsI1ALdZZavsdMq8jxC+RD07r/hArDN5e9twSs6bo31nu4bnqP AAWFzk4t2VEvls1EFMh8Yuga+tfVJ1y4KpdTcr2II/KX2aMYjUZshjRCf78Ty7ChHAQy yguQqx1w9YpeSKbSU5wty0J5FTpY0fPgZ1RnBN3QCvSaWmYnnz0CXx1fifaLGy8dV5Wi UtT86FOpdOUPNJ86fKF+j066xHl7leXOxTzW5QSj46zA2WQT3L2ereUqI4UYxuIyKJGg 64ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=uXeczbpfos242B5D1iwyiU1J77zH0lxDLAqIkkAb5YI=; b=CprFw27ob1LQxvqEg8UyVAJJk/z2f3uX8plH57N80rAuF4s9Z9/JvSoLVQaxRhMwmO S0wXw6rumLHWGKRY44BEVVHeCe21BEFYYX12QbFTz++w89DLOzgAjrUKwlmACjGV+xTL nK1WyYAWfIeSA7pAW7d8DftsfBUvjq9sd6R2aamKLnFZpuKflgGLmFZqMHupeUNgepxU c3JhnAcsPctQghCLfBQCJjIfnjcAMv+/x073tkly2IKTtNJJ/vpvXh72RfkkGKPfVadk wcJorrkwDW2uy2Dpgi2YDpm6LlQJogTelr6X7UcwmIlemRzZdXL10u/NECBhQycbPZ1y Dsdw== X-Gm-Message-State: ALoCoQmgDTRp8TlS6jBzLzxNkF/rxMWrn5sJ3JWixx1j6K+aFIA8d2mv+Tw/aTSQsuDZdiG/8BxpQ6BFqZKicS9cdzuVu9Fswcgn9FwPAm0yBymHSM3UW7bpyiccqAnykNKMz7HO5/8F8n1+LuyMbgxGhNlDQvFbslMI/hxxq3J0iA4Ly6kqWYR0VB4yS9lXoKICWGnZZuyPQfl3QxTGyFo1Yb9At1i7PA== X-Received: by 10.43.135.4 with SMTP id ie4mr13602511icc.1.1396422012978; Wed, 02 Apr 2014 00:00:12 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id s65si182898yhc.2.2014.04.02.00.00.12 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 Apr 2014 00:00:12 -0700 (PDT) Received: from coldfire.mtv.corp.google.com (coldfire.mtv.corp.google.com [172.17.131.114]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id B97B731C1DD; Wed, 2 Apr 2014 00:00:12 -0700 (PDT) Received: by coldfire.mtv.corp.google.com (Postfix, from userid 109155) id 656F2140E63; Wed, 2 Apr 2014 00:00:12 -0700 (PDT) From: Mahesh Bandewar To: Jay Vosburgh , Veaceslav Falico , Andy Gospodarek , David Miller Cc: netdev , Mahesh Bandewar , Eric Dumazet , Maciej Zenczykowski Subject: [PATCH v3 2/5] bonding: Reorg bond_alb_xmit code Date: Wed, 2 Apr 2014 00:00:10 -0700 Message-Id: <1396422010-31981-1-git-send-email-maheshb@google.com> X-Mailer: git-send-email 1.9.1.423.g4596e3a Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Separating the actual xmit part from the function in a separate function that can be used in the tlb_xmit in the next patch. Also there is no reason do_tx_balance to be an int so changing it to bool type. Change-Id: I9c48ff30487810f68587e621a191db616f49bd3b Signed-off-by: Mahesh Bandewar Acked-by: Eric Dumazet --- v2: Rebase v3: Rebase drivers/net/bonding/bond_alb.c | 79 +++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c index 9f69e818b000..5cd36016c393 100644 --- a/drivers/net/bonding/bond_alb.c +++ b/drivers/net/bonding/bond_alb.c @@ -1347,6 +1347,40 @@ void bond_alb_deinitialize(struct bonding *bond) rlb_deinitialize(bond); } +static int bond_do_alb_xmit(struct sk_buff *skb, struct bonding *bond, + struct slave *tx_slave) +{ + struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); + struct ethhdr *eth_data = eth_hdr(skb); + + if (!tx_slave) { + /* unbalanced or unassigned, send through primary */ + tx_slave = rcu_dereference(bond->curr_active_slave); + bond_info->unbalanced_load += skb->len; + } + + if (tx_slave && SLAVE_IS_OK(tx_slave)) { + if (tx_slave != rcu_dereference(bond->curr_active_slave)) { + ether_addr_copy(eth_data->h_source, + tx_slave->dev->dev_addr); + } + + bond_dev_queue_xmit(bond, skb, tx_slave->dev); + goto out; + } + + if (tx_slave) { + _lock_tx_hashtbl(bond); + __tlb_clear_slave(bond, tx_slave, 0); + _unlock_tx_hashtbl(bond); + } + + /* no suitable interface, frame not sent */ + dev_kfree_skb_any(skb); +out: + return NETDEV_TX_OK; +} + int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev) { struct bonding *bond = netdev_priv(bond_dev); @@ -1355,7 +1389,7 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev) struct slave *tx_slave = NULL; static const __be32 ip_bcast = htonl(0xffffffff); int hash_size = 0; - int do_tx_balance = 1; + bool do_tx_balance = true; u32 hash_index = 0; const u8 *hash_start = NULL; struct ipv6hdr *ip6hdr; @@ -1370,7 +1404,7 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev) if (ether_addr_equal_64bits(eth_data->h_dest, mac_bcast) || (iph->daddr == ip_bcast) || (iph->protocol == IPPROTO_IGMP)) { - do_tx_balance = 0; + do_tx_balance = false; break; } hash_start = (char *)&(iph->daddr); @@ -1382,7 +1416,7 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev) * that here just in case. */ if (ether_addr_equal_64bits(eth_data->h_dest, mac_bcast)) { - do_tx_balance = 0; + do_tx_balance = false; break; } @@ -1390,7 +1424,7 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev) * broadcasts in IPv4. */ if (ether_addr_equal_64bits(eth_data->h_dest, mac_v6_allmcast)) { - do_tx_balance = 0; + do_tx_balance = false; break; } @@ -1400,7 +1434,7 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev) */ ip6hdr = ipv6_hdr(skb); if (ipv6_addr_any(&ip6hdr->saddr)) { - do_tx_balance = 0; + do_tx_balance = false; break; } @@ -1410,7 +1444,7 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev) case ETH_P_IPX: if (ipx_hdr(skb)->ipx_checksum != IPX_NO_CHECKSUM) { /* something is wrong with this packet */ - do_tx_balance = 0; + do_tx_balance = false; break; } @@ -1419,7 +1453,7 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev) * this family since it has an "ARP" like * mechanism */ - do_tx_balance = 0; + do_tx_balance = false; break; } @@ -1427,12 +1461,12 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev) hash_size = ETH_ALEN; break; case ETH_P_ARP: - do_tx_balance = 0; + do_tx_balance = false; if (bond_info->rlb_enabled) tx_slave = rlb_arp_xmit(skb, bond); break; default: - do_tx_balance = 0; + do_tx_balance = false; break; } @@ -1441,32 +1475,7 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev) tx_slave = tlb_choose_channel(bond, hash_index, skb->len); } - if (!tx_slave) { - /* unbalanced or unassigned, send through primary */ - tx_slave = rcu_dereference(bond->curr_active_slave); - bond_info->unbalanced_load += skb->len; - } - - if (tx_slave && SLAVE_IS_OK(tx_slave)) { - if (tx_slave != rcu_dereference(bond->curr_active_slave)) { - ether_addr_copy(eth_data->h_source, - tx_slave->dev->dev_addr); - } - - bond_dev_queue_xmit(bond, skb, tx_slave->dev); - goto out; - } - - if (tx_slave) { - _lock_tx_hashtbl(bond); - __tlb_clear_slave(bond, tx_slave, 0); - _unlock_tx_hashtbl(bond); - } - - /* no suitable interface, frame not sent */ - dev_kfree_skb_any(skb); -out: - return NETDEV_TX_OK; + return bond_do_alb_xmit(skb, bond, tx_slave); } void bond_alb_monitor(struct work_struct *work)