Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4712862ybg; Mon, 21 Oct 2019 13:14:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqxEs+j1C8iTmdxtxibTRjCWmUuOkeYffg0LOU2XcwoBFnkChhMtKs6rtrbfrQuzDJukUpU/ X-Received: by 2002:aa7:c612:: with SMTP id h18mr27237558edq.245.1571688898257; Mon, 21 Oct 2019 13:14:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571688898; cv=none; d=google.com; s=arc-20160816; b=kAoyzLrdRf8I9F0g3rtpU3FEdw+T5fw9BJAj6EXCYNaU7WKbccku8pCwf5cI4ZCGMH M/E5KNyWVEhNd0iPeXsV9UMy1gc3mHPnZR62zrG2XA3dujJBDFukV/HIGanMHU+LY2KX DrX4sJcVtxBFw2dncmzhbQe5Oo3ocmCAV+MTIqurnJ91IWcKMA3cYaX8uwnoOmfqyfAK ubXmfQAdHuTdmrvA4u8yEED+wAV2vjL/eJaWM63MEew6mpo0Sal7s49JUkqzRj7S1Z+J TbOzUJvQkZZ7EmCh2GG2IXe/kcuXc9/H88TaLloSsv2VADOBXVqRuNodP1814j3guym9 W5GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fKQgbWuikOflsblq1Eqq9EME7qTpUP9bfFsTutkuQ7M=; b=eESn6dNvEvRQ+vDERkZ5+lNum6lnisGWEvJMbkDHFrVlMkGUDuxO7FrDKaBWBmXoJ7 hqjJ7XmwVv1QmrMPoyFtMwTbS9/9G/Axx0XFAwWZWHRe6EQ5bpuvi27rCrUVO8tTOtil U4Dz0OE8RWene+vfqjOakm+BN6ab+mRy/YH9qBTmu9CHEvkcRcnDr0MxWL59eQFCc2pd WVqhC8VWQI13X80BJJqVs6V6/x+BHu6o6SSMEgzjeVNnXoa1oicQ4oDgSZejk/m147E4 MppxI3F6eoKNB/cT9O6vKBxWPOKJ8jDUV4OzpgLiehnYplQ017PcDbGik0iiDCLW5D4I kLKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=b5rT68h0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q17si4504314edc.6.2019.10.21.13.14.34; Mon, 21 Oct 2019 13:14:58 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=b5rT68h0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730345AbfJUULn (ORCPT + 99 others); Mon, 21 Oct 2019 16:11:43 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:29874 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730065AbfJUULn (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=1571688702; 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=b5rT68h0d8fFbdZrLv0rG8XyCKgFjqe9koChbVNxZFIfJaQbLJuiF6vGZJWtTihaWRfZgc mq+mSjidNe1b6r0OWmslDkRlWdijiQVC7VJj4db7ytZwpJud4DKPOW8ztTAJOtf8MOLpl6 wprdhpQY8sBlqeBa57OGmBBBHPPNloQ= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-79-c0HCnvEUP7efnzr8eLAeDw-1; Mon, 21 Oct 2019 16:11:38 -0400 Received: by mail-wr1-f70.google.com with SMTP id f4so7880756wrj.12 for ; Mon, 21 Oct 2019 13:11:37 -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=i+A4l2pIhkvPAoDX2ZDVniao0Tto7FL80LWy3tE8fwpN9SpEZPAYlsxeKx+cZ6yyq/ c/O4X02Wx8s+jCM/QPRzM8rG32p8L0AMutkcQAx1ttZXHE8Ti+pt2Diu+lFGJH6+40hR Skhyt8NRfAVRcsDCTiZH6VhCAb0iUlJtIj1/B9iANVL/41WL1ppwpsDl+o/wcO9HWWNe lWJjAS8XygV0pzk94jHEiyVlTsI1RbKV1AVKB00JkvV20WUhqzpnyCqbhp4i5xyN7xXM 68J76vsjjiEpujl2FVMZnnlsunxEXVrzUuiAhPn9gDqHFlXFmvfke2I0Gd4xsgkqtIwl bHbQ== X-Gm-Message-State: APjAAAXrkpg4yueh1iswNh733J+E7sI514DTvHtNEAfPhDk0FSTYCUTI 9UpLaYOfqlJtplTUxDU+BmVlEFoIzxfI9BXMAjfyyGLHO9rAXKlmQka5vvKI6TViMJpr+QjZ7za ONRVO19exRE9KLPJsPxrKTlae X-Received: by 2002:a1c:7c13:: with SMTP id x19mr20545149wmc.80.1571688697036; Mon, 21 Oct 2019 13:11:37 -0700 (PDT) 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: c0HCnvEUP7efnzr8eLAeDw-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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, leng= th 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, leng= th 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, leng= th 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, leng= th 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, leng= th 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_mai= n.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, s= truct sk_buff *skb, =09=09return skb_flow_dissect_flow_keys(skb, fk, 0); =20 =09fk->ports.ports =3D 0; +=09fk->icmp.icmp =3D 0; +=09fk->icmp.id =3D 0; =09noff =3D skb_network_offset(skb); =09if (skb->protocol =3D=3D htons(ETH_P_IP)) { =09=09if (unlikely(!pskb_may_pull(skb, noff + sizeof(*iph)))) @@ -3286,8 +3288,14 @@ static bool bond_flow_dissect(struct bonding *bond, = struct sk_buff *skb, =09} else { =09=09return false; =09} -=09if (bond->params.xmit_policy =3D=3D BOND_XMIT_POLICY_LAYER34 && proto >= =3D 0) -=09=09fk->ports.ports =3D skb_flow_get_ports(skb, noff, proto); +=09if (bond->params.xmit_policy =3D=3D BOND_XMIT_POLICY_LAYER34 && proto >= =3D 0) { +=09=09if (proto =3D=3D IPPROTO_ICMP || proto =3D=3D IPPROTO_ICMPV6) +=09=09=09skb_flow_get_icmp_tci(skb, &fk->icmp, skb->data, +=09=09=09=09=09 skb_transport_offset(skb), +=09=09=09=09=09 skb_headlen(skb)); +=09=09else +=09=09=09fk->ports.ports =3D skb_flow_get_ports(skb, noff, proto); +=09} =20 =09return true; } @@ -3314,10 +3322,14 @@ u32 bond_xmit_hash(struct bonding *bond, struct sk_= buff *skb) =09=09return bond_eth_hash(skb); =20 =09if (bond->params.xmit_policy =3D=3D BOND_XMIT_POLICY_LAYER23 || -=09 bond->params.xmit_policy =3D=3D BOND_XMIT_POLICY_ENCAP23) +=09 bond->params.xmit_policy =3D=3D BOND_XMIT_POLICY_ENCAP23) { =09=09hash =3D bond_eth_hash(skb); -=09else -=09=09hash =3D (__force u32)flow.ports.ports; +=09} else { +=09=09if (flow.icmp.id) +=09=09=09memcpy(&hash, &flow.icmp, sizeof(hash)); +=09=09else +=09=09=09memcpy(&hash, &flow.ports.ports, sizeof(hash)); +=09} =09hash ^=3D (__force u32)flow_get_u32_dst(&flow) ^ =09=09(__force u32)flow_get_u32_src(&flow); =09hash ^=3D (hash >> 16); --=20 2.21.0