Received: by 10.192.165.148 with SMTP id m20csp3900426imm; Mon, 23 Apr 2018 14:39:24 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+ZZgWIncv+M3rUSjc5enP6LcUqNdcP8o3ajLwsPKC1dYNcVfXPcjSBeQZa1Xsk+wVwqSLT X-Received: by 10.99.110.199 with SMTP id j190mr17853807pgc.71.1524519564278; Mon, 23 Apr 2018 14:39:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524519564; cv=none; d=google.com; s=arc-20160816; b=O3BSNnnLMJR5zAkU8hO0S0SUh0L9YyG6izl/EGH98NzX9fBYTPBlxyiCL9Yj2mBB/G YlSJw0RAB96T4NRODxsX+pIP7ZvH5Vkuydi4cS95+d15/eJJa4/d0v2ZVBH+qn5mSJwW Ry31smggg8U7Q7x6zYq26yuMT/2aTI80L38NlX+o93d9AkxXSjB59kqC4r/fivafzCmD kwbcWPBKqYFv4Mwk+pAA8awsViKQ19N+DuYB/mOb3h0qa0mzUmjwHYQLgoLT5DsGYbdm L+4AFI6Xwz+OYqeaHLfb5ne2n3njGUMi3dVXw5AjEbxSHcrrB5HBg2MPXEJSZ3hLurrz FfaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=gSsK/3vUC4WFqHLNyhrsLH7fGVU88CtjVCifnTXycQg=; b=aPvM2nk5QSak4jhwOH21igfECMIPjMbPkipxpf7O85+K5Iey5r79JwAE1q1bohQBHw zo/e6/60Jl9PJRP1W5WBfbTY/OM/mAg/GNdxGKcvhW0Y/OEONP5ez0NLl5hDLcoY1Rko jPzosrPBE+nPWB1atApPJAgO6VP/bsEM2UyaVfKR+hq0tj+kfaczQkuoE3ngBcZwUWm+ P2haewICUljC3IkrfO4kluBwUaBM1XCBposLnotT/5kz1EgopIzwTPcvbH/VpAXpkOO/ rO3u8N/R3eduNdCX5QBrAwfuDZhQ6ELfiz87/mj2vO03n6zYeIu7GisJIWYr3TACgfKY gT2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=otSe+lLo; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 132si10142989pgb.470.2018.04.23.14.39.09; Mon, 23 Apr 2018 14:39:24 -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=@gmail.com header.s=20161025 header.b=otSe+lLo; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932624AbeDWVhe (ORCPT + 99 others); Mon, 23 Apr 2018 17:37:34 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:40532 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932401AbeDWVha (ORCPT ); Mon, 23 Apr 2018 17:37:30 -0400 Received: by mail-wr0-f194.google.com with SMTP id v60-v6so45127013wrc.7; Mon, 23 Apr 2018 14:37:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gSsK/3vUC4WFqHLNyhrsLH7fGVU88CtjVCifnTXycQg=; b=otSe+lLoAI/nnA3BeaQuEiEBnKwLw+blnQDf5in3Kc8GOjIS3iQHVXBRtgQZA43507 4hH989lwpHdYCsdA4Su0GLzSuDcdPab+o97VQrFggFgrrxsJ0y1jtbW0pCkE1vl2ghW+ xdEa/iK9U6FBWQo91BuQiTVSNvWrom7uG/dX7S58J991eSMAltmvDfYtrM4DX/yPVvi+ cJHZbYnRDUTbGXvwMk8Ufc/feh6iVTEX+C79/lqH4vYEp+z5u/fS98WS89rBvM+E3CdT kXTWEQtpj7MeASbJjN4LUHr/YC2hLp4VB00Jr5GgwQjAi3zqFSzUJEpwgl/0IlmmnL1A NtEw== 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; bh=gSsK/3vUC4WFqHLNyhrsLH7fGVU88CtjVCifnTXycQg=; b=aHm38OqXMZX0gn0B3X6RPTjs9ikUeXQWM8Lfb1zUFNcwAWAMWoSkc8QBXCAREQe1yo 0q18QC1WmXaq5yEPBS1MIYRl6eLdS1rH1Y4LSKGW18SCfJyKpKrb1aD5WsBJsf3IP8wH QomF7WdCL1jYlJ+jXL5Dm6lx1NnJFVlXedn4h6WrLJzQSLuguAYGHxPAh+BWa/8+7a56 4J+KBPDzfNJBwEEQbtLnebkD03sv2w5zblxOA/+/xdhvuTaSeJ+ZdKfFj2po+iBTqUgp bsgpi8X85fhrXXflh8LtC7+BljDah2CX+ugzDm595tWIs7KwCG/EHyryF/zDfqcsmSBf O2VQ== X-Gm-Message-State: ALQs6tDPfckrqvhal6AEuM2d6zr21yPlP4o1+vgajHa4S7mluTWjh+ky /Nly4GmctNLv516arIrjVlU= X-Received: by 2002:adf:b1cd:: with SMTP id r13-v6mr9659938wra.221.1524519448659; Mon, 23 Apr 2018 14:37:28 -0700 (PDT) Received: from localhost.localdomain ([192.135.27.140]) by smtp.gmail.com with ESMTPSA id a69sm8405851wma.7.2018.04.23.14.37.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Apr 2018 14:37:28 -0700 (PDT) From: Ahmed Abdelsalam To: davem@davemloft.net, dav.lebrun@gmail.com, kuznet@ms2.inr.ac.ru, yoshfuji@linux-ipv6.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ahmed Abdelsalam Subject: [net-next 2/2] ipv6: sr: Compute flowlabel of outer IPv6 header for seg6 encap mode Date: Mon, 23 Apr 2018 23:37:00 +0200 Message-Id: <1524519420-1612-2-git-send-email-amsalam20@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1524519420-1612-1-git-send-email-amsalam20@gmail.com> References: <1524519420-1612-1-git-send-email-amsalam20@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ECMP (equal-cost multipath) hashes are typically computed on the packets' 5-tuple(src IP, dst IP, src port, dst port, L4 proto). For encapsulated packets, the L4 data is not readily available and ECMP hashing will often revert to (src IP, dst IP). This will lead to traffic polarization on a single ECMP path, causing congestion and waste of network capacity. In IPv6, the 20-bit flow label field is also used as part of the ECMP hash. In the lack of L4 data, the hashing will be on (src IP, dst IP, flow label). Having a non-zero flow label is thus important for proper traffic load balancing when L4 data is unavailable (i.e., when packets are encapsulated) Currently, the seg6_do_srh_encap() function extracts the original packet's flow label and set it as the outer IPv6 flow label. There are two issues with this behaviour: a) There is no guarantee that the inner flow label will be set by the source. b) If the original packet is not IPv6, the flow label will be set to zero (e.g., IPv4 or L2 encap). This patch adds a function, named seg6_make_flowlabel(), that computes a flow label from a given skb. It supports IPv6, IPv4 and L2 payloads, and leverages the per namespace "seg6_flowlabel" sysctl value. This patch has been tested for IPv6, IPv4, and L2 traffic. Signed-off-by: Ahmed Abdelsalam --- net/ipv6/seg6_iptunnel.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c index 5fe1394..3d9cd86 100644 --- a/net/ipv6/seg6_iptunnel.c +++ b/net/ipv6/seg6_iptunnel.c @@ -91,6 +91,24 @@ static void set_tun_src(struct net *net, struct net_device *dev, rcu_read_unlock(); } +/* Compute flowlabel for outer IPv6 header */ +__be32 seg6_make_flowlabel(struct net *net, struct sk_buff *skb, + struct ipv6hdr *inner_hdr) +{ + int do_flowlabel = net->ipv6.sysctl.seg6_flowlabel; + __be32 flowlabel = 0; + u32 hash; + + if (do_flowlabel > 0) { + hash = skb_get_hash(skb); + rol32(hash, 16); + flowlabel = (__force __be32)hash & IPV6_FLOWLABEL_MASK; + } else if (!do_flowlabel && skb->protocol == htons(ETH_P_IPV6)) { + flowlabel = ip6_flowlabel(inner_hdr); + } + return flowlabel; +} + /* encapsulate an IPv6 packet within an outer IPv6 header with a given SRH */ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto) { @@ -99,6 +117,7 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto) struct ipv6hdr *hdr, *inner_hdr; struct ipv6_sr_hdr *isrh; int hdrlen, tot_len, err; + __be32 flowlabel; hdrlen = (osrh->hdrlen + 1) << 3; tot_len = hdrlen + sizeof(*hdr); @@ -119,12 +138,13 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto) * decapsulation will overwrite inner hlim with outer hlim */ + flowlabel = seg6_make_flowlabel(net, skb, inner_hdr); if (skb->protocol == htons(ETH_P_IPV6)) { ip6_flow_hdr(hdr, ip6_tclass(ip6_flowinfo(inner_hdr)), - ip6_flowlabel(inner_hdr)); + flowlabel); hdr->hop_limit = inner_hdr->hop_limit; } else { - ip6_flow_hdr(hdr, 0, 0); + ip6_flow_hdr(hdr, 0, flowlabel); hdr->hop_limit = ip6_dst_hoplimit(skb_dst(skb)); } -- 2.1.4