From patchwork Mon Oct 21 20:09:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 1180842 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="Ddua8wSz"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46xnpm3sHQz9s7T for ; Tue, 22 Oct 2019 07:11:44 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730338AbfJUULn (ORCPT ); Mon, 21 Oct 2019 16:11:43 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:44329 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730052AbfJUULn (ORCPT ); Mon, 21 Oct 2019 16:11:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571688701; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fKQgbWuikOflsblq1Eqq9EME7qTpUP9bfFsTutkuQ7M=; b=Ddua8wSz2zhvRY8DDn8fHFNIlAjkhH43UwJOXZljSZmn3yfFNAPMEx9J+HLVVgPVFpQ748 Do8w77pAHe3j8tUqZo1Ao84he/AwxapLziFoOmPMn6YPJxdK1xarTWhT8p6kxnmJETnCUe X4drbnroJdxM3Xd1grMW5QCHnxYhXiQ= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-200-HCRPstR-N1qIecd6Pa9tKw-1; Mon, 21 Oct 2019 16:11:38 -0400 Received: by mail-wr1-f71.google.com with SMTP id x9so1558865wrq.5 for ; Mon, 21 Oct 2019 13:11:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=51LIoCpMIxhBzrnm/L7yqZ4c2j05Lx5qfysNEUKia7M=; b=kEmDxaYdsdY8+QIb5hLTBa6fDHy0qNp8UApv44ruODtf9g4ihFG9k9miSfcJj/meBe Legs9MvnOqm5OpaUbsZ7zabqbtX+QBbRGlp6yNDWBcjNBnfEZAkh0WsLC2KzbS2su/m5 M3iZBw2EobCe1hrFTuW7jpNiLvoN7ankGlGTNoTQfj2gP5RuGyCQRAgSVGsujY9ji/dt 3e8SiqsH1AF1tNrzin/B09c8mYXl+qw4sn0ldNxtUYcB1Cyn+DMqz3esP+47nVCBkBrV gk0HpotFMZ3KuxM1MkGs7fEO722SLir0CbEdx2wmKFPhIYxmuC1Cg+EUzXH7wXqH3hHj bt0A== X-Gm-Message-State: APjAAAXB1CfmzjHOfocrPRdztD61BqJ3YsPbQkB7GVbbWbwMMWHV7l/5 IEmFVN+IIF7uq4WefkLIfq4JnKX9Gw+IGyIVToH9PX5tFQIT+o9lNptlXUm+CAoLwTYessJnlyU bBg6EbVXrzjMX1n+G X-Received: by 2002:a1c:7c13:: with SMTP id x19mr20545142wmc.80.1571688697035; Mon, 21 Oct 2019 13:11:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4eoHxAWTQ+LvXncS6zBXjbLAyI3z6egZ5xoXP+n9ihgqP+iqXdVTfi0xJTu60J9hIc740cg== X-Received: by 2002:a1c:7c13:: with SMTP id x19mr20545124wmc.80.1571688696804; Mon, 21 Oct 2019 13:11:36 -0700 (PDT) Received: from turbo.teknoraver.net (net-109-115-41-234.cust.vodafonedsl.it. [109.115.41.234]) by smtp.gmail.com with ESMTPSA id l18sm20701933wrn.48.2019.10.21.13.11.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 13:11:36 -0700 (PDT) From: Matteo Croce To: netdev@vger.kernel.org Cc: Jay Vosburgh , Veaceslav Falico , Andy Gospodarek , "David S . Miller " , Stanislav Fomichev , Daniel Borkmann , Song Liu , Alexei Starovoitov , Paul Blakey , linux-kernel@vger.kernel.org Subject: [PATCH net-next 4/4] bonding: balance ICMP echoes in layer3+4 mode Date: Mon, 21 Oct 2019 22:09:48 +0200 Message-Id: <20191021200948.23775-5-mcroce@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191021200948.23775-1-mcroce@redhat.com> References: <20191021200948.23775-1-mcroce@redhat.com> MIME-Version: 1.0 X-MC-Unique: HCRPstR-N1qIecd6Pa9tKw-1 X-Mimecast-Spam-Score: 0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The bonding uses the L4 ports to balance flows between slaves. As the ICMP protocol has no ports, those packets are sent all to the same device: # tcpdump -qltnni veth0 ip |sed 's/^/0: /' & # tcpdump -qltnni veth1 ip |sed 's/^/1: /' & # ping -qc1 192.168.0.2 1: IP 192.168.0.1 > 192.168.0.2: ICMP echo request, id 315, seq 1, length 64 1: IP 192.168.0.2 > 192.168.0.1: ICMP echo reply, id 315, seq 1, length 64 # ping -qc1 192.168.0.2 1: IP 192.168.0.1 > 192.168.0.2: ICMP echo request, id 316, seq 1, length 64 1: IP 192.168.0.2 > 192.168.0.1: ICMP echo reply, id 316, seq 1, length 64 # ping -qc1 192.168.0.2 1: IP 192.168.0.1 > 192.168.0.2: ICMP echo request, id 317, seq 1, length 64 1: IP 192.168.0.2 > 192.168.0.1: ICMP echo reply, id 317, seq 1, length 64 But some ICMP packets have an Identifier field which is used to match packets within sessions, let's use this value in the hash function to balance these packets between bond slaves: # ping -qc1 192.168.0.2 0: IP 192.168.0.1 > 192.168.0.2: ICMP echo request, id 303, seq 1, length 64 0: IP 192.168.0.2 > 192.168.0.1: ICMP echo reply, id 303, seq 1, length 64 # ping -qc1 192.168.0.2 1: IP 192.168.0.1 > 192.168.0.2: ICMP echo request, id 304, seq 1, length 64 1: IP 192.168.0.2 > 192.168.0.1: ICMP echo reply, id 304, seq 1, length 64 Signed-off-by: Matteo Croce --- drivers/net/bonding/bond_main.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 21d8fcc83c9c..83afb03f4d07 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -3267,6 +3267,8 @@ static bool bond_flow_dissect(struct bonding *bond, struct sk_buff *skb, return skb_flow_dissect_flow_keys(skb, fk, 0); fk->ports.ports = 0; + fk->icmp.icmp = 0; + fk->icmp.id = 0; noff = skb_network_offset(skb); if (skb->protocol == htons(ETH_P_IP)) { if (unlikely(!pskb_may_pull(skb, noff + sizeof(*iph)))) @@ -3286,8 +3288,14 @@ static bool bond_flow_dissect(struct bonding *bond, struct sk_buff *skb, } else { return false; } - if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34 && proto >= 0) - fk->ports.ports = skb_flow_get_ports(skb, noff, proto); + if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34 && proto >= 0) { + if (proto == IPPROTO_ICMP || proto == IPPROTO_ICMPV6) + skb_flow_get_icmp_tci(skb, &fk->icmp, skb->data, + skb_transport_offset(skb), + skb_headlen(skb)); + else + fk->ports.ports = skb_flow_get_ports(skb, noff, proto); + } return true; } @@ -3314,10 +3322,14 @@ u32 bond_xmit_hash(struct bonding *bond, struct sk_buff *skb) return bond_eth_hash(skb); if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER23 || - bond->params.xmit_policy == BOND_XMIT_POLICY_ENCAP23) + bond->params.xmit_policy == BOND_XMIT_POLICY_ENCAP23) { hash = bond_eth_hash(skb); - else - hash = (__force u32)flow.ports.ports; + } else { + if (flow.icmp.id) + memcpy(&hash, &flow.icmp, sizeof(hash)); + else + memcpy(&hash, &flow.ports.ports, sizeof(hash)); + } hash ^= (__force u32)flow_get_u32_dst(&flow) ^ (__force u32)flow_get_u32_src(&flow); hash ^= (hash >> 16);