From patchwork Tue Aug 25 16:02:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ahmed Abdelsalam X-Patchwork-Id: 1351155 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=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=gHlYvvBK; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BbYfz4nBdz9sTX for ; Wed, 26 Aug 2020 02:02:51 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727019AbgHYQCr (ORCPT ); Tue, 25 Aug 2020 12:02:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726351AbgHYQCq (ORCPT ); Tue, 25 Aug 2020 12:02:46 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 003AFC061574; Tue, 25 Aug 2020 09:02:45 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id q14so2136727wrn.9; Tue, 25 Aug 2020 09:02:45 -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; bh=GBdGSIj6c6kMmn2l3br70BmRSgCoyvpbeosCzLwhaiQ=; b=gHlYvvBKVBB9MbiHpJ5W2+mubNzZz9fccqFaVNiF6i65de6l84KBY2YNo/CcZBWTtU Hb03r9OSnU1blTHS5k2PPlxQLTuoN6jFn0wGPaLEFir468xZHzCR62Mn2QI3unQk3Rm7 Y2mvP7GsmCKu/SKmT31Ymuy3dOw78ZpsR29AHkWlxL0tEQU/3pEvx1DErT+zPikjyOd7 +SL1LMNDRQMwBD2hQgzVwbWL5aKOO5VVO5OEe5E1ULbsHMyP6O5ytdR5+7DuHqchJB2Q t+FuovH+xtHDfjx9ufsJWScZl8VhOYV1ozNHgWkDPCILhMh0rV3tXebuPVkqoeBtcfMn epTw== 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; bh=GBdGSIj6c6kMmn2l3br70BmRSgCoyvpbeosCzLwhaiQ=; b=lyMc9kuZA2JncwBDaSXGt47FfvAdk+PU7LA5/CpPNv5jlwhL5y3e7Mi8GegMi9Rhb7 kmabMZTEGcT/JIt9Juw/EtHULpgCo4sudBQHnLftpnigPYQVVZzHiuOxQ8ZM89GpbVsg gWlhmfC/f3twXYZLiBr5uz6FtovzxtaD4G1XpS4byhBZ46zgxLJcN/q6TKdHmnysgY0Z jmwYo+RQQkRA+ZWYqBiBPNiiZ2RbhBCfJm66rTEESRxcpsrBupO3douWjmb1bJnwIHEb IxH2MiswfF7+VTdYYt+PZ0wqCPRfuNC/ganPUH2MS55HmzYWEKOtC1E96iZiGzXhXhGc qfOA== X-Gm-Message-State: AOAM5307rNe4Wrr0SyMHqBtQccONBS9yoUoSuJMCspIOlzdxK+osFmTa Gd4zcK4u8xxrXknx6lArQFk= X-Google-Smtp-Source: ABdhPJwg1w6hC0wPfzTvlgDP5wtZeHxsrtuxW2x99xq/v63Bl0Alz7BDYKNzUJgFqZ2t6A3L2A42yQ== X-Received: by 2002:adf:fecc:: with SMTP id q12mr11701025wrs.374.1598371364695; Tue, 25 Aug 2020 09:02:44 -0700 (PDT) Received: from ubuntu18_1.cisco.com ([173.38.220.45]) by smtp.gmail.com with ESMTPSA id o2sm30070711wrj.21.2020.08.25.09.02.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2020 09:02:44 -0700 (PDT) From: Ahmed Abdelsalam To: "David S. Miller" , Jakub Kicinski , Alexey Kuznetsov , Hideaki YOSHIFUJI , Ahmed Abdelsalam , David Ahern , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: andrea.mayer@uniroma2.it Subject: [net-next v5 1/2] seg6: inherit DSCP of inner IPv4 packets Date: Tue, 25 Aug 2020 16:02:33 +0000 Message-Id: <20200825160236.1123-1-ahabdels@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch allows SRv6 encapsulation to inherit the DSCP value of the inner IPv4 packet. This allows forwarding packet across the SRv6 fabric based on their original traffic class. The option is controlled through a sysctl (seg6_inherit_inner_ipv4_dscp). The sysctl has to be set to 1 to enable this feature. Signed-off-by: Ahmed Abdelsalam --- include/net/netns/ipv6.h | 1 + net/ipv6/seg6_iptunnel.c | 37 ++++++++++++++++++++----------------- net/ipv6/sysctl_net_ipv6.c | 9 +++++++++ 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h index 5ec054473d81..6ed73951f479 100644 --- a/include/net/netns/ipv6.h +++ b/include/net/netns/ipv6.h @@ -50,6 +50,7 @@ struct netns_sysctl_ipv6 { int max_dst_opts_len; int max_hbh_opts_len; int seg6_flowlabel; + bool seg6_inherit_inner_ipv4_dscp; bool skip_notify_on_dev_down; }; diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c index 897fa59c47de..9cc168462e11 100644 --- a/net/ipv6/seg6_iptunnel.c +++ b/net/ipv6/seg6_iptunnel.c @@ -104,8 +104,7 @@ static void set_tun_src(struct net *net, struct net_device *dev, } /* Compute flowlabel for outer IPv6 header */ -static __be32 seg6_make_flowlabel(struct net *net, struct sk_buff *skb, - struct ipv6hdr *inner_hdr) +static __be32 seg6_make_flowlabel(struct net *net, struct sk_buff *skb) { int do_flowlabel = net->ipv6.sysctl.seg6_flowlabel; __be32 flowlabel = 0; @@ -116,7 +115,7 @@ static __be32 seg6_make_flowlabel(struct net *net, struct sk_buff *skb, hash = 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); + flowlabel = ip6_flowlabel(ipv6_hdr(skb)); } return flowlabel; } @@ -129,6 +128,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; + u8 tos = 0, hop_limit; __be32 flowlabel; hdrlen = (osrh->hdrlen + 1) << 3; @@ -138,30 +138,33 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto) if (unlikely(err)) return err; - inner_hdr = ipv6_hdr(skb); - flowlabel = seg6_make_flowlabel(net, skb, inner_hdr); - - skb_push(skb, tot_len); - skb_reset_network_header(skb); - skb_mac_header_rebuild(skb); - hdr = ipv6_hdr(skb); - /* inherit tc, flowlabel and hlim * hlim will be decremented in ip6_forward() afterwards and * decapsulation will overwrite inner hlim with outer hlim */ + flowlabel = seg6_make_flowlabel(net, skb); + hop_limit = ip6_dst_hoplimit(skb_dst(skb)); + if (skb->protocol == htons(ETH_P_IPV6)) { - ip6_flow_hdr(hdr, ip6_tclass(ip6_flowinfo(inner_hdr)), - flowlabel); - hdr->hop_limit = inner_hdr->hop_limit; + inner_hdr = ipv6_hdr(skb); + hop_limit = inner_hdr->hop_limit; + tos = ip6_tclass(ip6_flowinfo(inner_hdr)); + } else if (skb->protocol == htons(ETH_P_IP)) { + if (net->ipv6.sysctl.seg6_inherit_inner_ipv4_dscp) + tos = ip_hdr(skb)->tos; + memset(IP6CB(skb), 0, sizeof(*IP6CB(skb))); } else { - ip6_flow_hdr(hdr, 0, flowlabel); - hdr->hop_limit = ip6_dst_hoplimit(skb_dst(skb)); - memset(IP6CB(skb), 0, sizeof(*IP6CB(skb))); } + skb_push(skb, tot_len); + skb_reset_network_header(skb); + skb_mac_header_rebuild(skb); + + hdr = ipv6_hdr(skb); + ip6_flow_hdr(hdr, tos, flowlabel); + hdr->hop_limit = hop_limit; hdr->nexthdr = NEXTHDR_ROUTING; isrh = (void *)hdr + sizeof(*hdr); diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c index fac2135aa47b..4b2cf8764524 100644 --- a/net/ipv6/sysctl_net_ipv6.c +++ b/net/ipv6/sysctl_net_ipv6.c @@ -159,6 +159,15 @@ static struct ctl_table ipv6_table_template[] = { .mode = 0644, .proc_handler = proc_dointvec }, + { + .procname = "seg6_inherit_inner_ipv4_dscp", + .data = &init_net.ipv6.sysctl.seg6_inherit_inner_ipv4_dscp, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, { } }; From patchwork Tue Aug 25 15:58:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ahmed Abdelsalam X-Patchwork-Id: 1351154 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=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=VGI3XJus; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BbYZd4wdJz9sTN for ; Wed, 26 Aug 2020 01:59:05 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726843AbgHYP7A (ORCPT ); Tue, 25 Aug 2020 11:59:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726466AbgHYP67 (ORCPT ); Tue, 25 Aug 2020 11:58:59 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAEC3C061574; Tue, 25 Aug 2020 08:58:58 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id b17so12461294wru.2; Tue, 25 Aug 2020 08:58:58 -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; bh=uc+i0gWQ7QGFfIc1FEZg9eNWGBKxWPtFWURbOx3qDRs=; b=VGI3XJusG7DtDltydX+p+GzQ5RPWGMc1T1ToEdnMnFchvPZQ3hNqQJyzZXejriIevw hK/hOEsqvPo9CqNq5xjLXmUF/Lq+FYVV8cCkZNDTXXjsiuep9u07mK1dbVu64ZCl4i/y hU7vcT/ErbkDhi8L+hWUu8Krk2xRoktNjGH2j/1ew87GNEk/l2I3mBETh0I7uMoYHRfA 0ICvCAZLnd/b9Ztb31msjaxO5SwIKNejh3SL18kQZhDeiG8IMcYexqxsLs9WPnMIYZd4 C5Uzkj/Wi++Jk9wGeEAN0HZVT+yGQQaM9PTfj+CRPgrkB7/bFOpALaSUcIsNdNGxRyS0 gIvg== 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; bh=uc+i0gWQ7QGFfIc1FEZg9eNWGBKxWPtFWURbOx3qDRs=; b=X/B49lI4Rf6YfR0OfY/AHfIiZIE5NNoEy+GPjkIxIeOsujridcCV/p1sGHMCJfDSiW 7RxgjgMgKmJTBK+mylVKGaOGKdbFwOveyDW3yUx8ldgMFReLYCjd1oulJ9/OIIiiHvop o7S0kCYdkVwiXCbB4B07GELjkCq7wsMWZIzvwjj8znw56oycfMvS9QbpZT4nDSBIfbd5 0AWVLOzRVEzEg5eT+VvebQe/VQpVAT4TdZBSYwF5VI8Djn/lXcE1Y433grmzYyIA6OxO Xfr1opVJxVDdoJoyKQX/IZHhnbC1S50iskCtRnc6haaSmC9ZZ7BPvHC2zVufFlhAUn0P kM5w== X-Gm-Message-State: AOAM531Sup77c/vtO0yqEVAiTtXQO/wPmIVSqHnIPNJouHJERT/XJueI txVbxe/zi5xCFD20PEL5gYlkxlKQlsDae1QT X-Google-Smtp-Source: ABdhPJy5CtEGeRW1UBmrR30rISXoR9TcOxm8quyf9iUBq3d4PfZjDJ8RF7ddO2JxnjDRZy14uWvLDQ== X-Received: by 2002:a5d:4850:: with SMTP id n16mr8439374wrs.92.1598371136604; Tue, 25 Aug 2020 08:58:56 -0700 (PDT) Received: from ubuntu18_1.cisco.com ([173.38.220.45]) by smtp.gmail.com with ESMTPSA id r3sm28198987wro.1.2020.08.25.08.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2020 08:58:55 -0700 (PDT) From: Ahmed Abdelsalam To: "David S. Miller" , Jakub Kicinski , Jonathan Corbet , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ahabdels@gmail.com, andrea.mayer@uniroma2.it Subject: [net-next v5 2/2] seg6: Add documentation for seg6_inherit_inner_ipv4_dscp sysctl Date: Tue, 25 Aug 2020 15:58:40 +0000 Message-Id: <20200825155840.1070-1-ahabdels@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch adds a documentation for seg6_inherit_inner_ipv4_dscp sysctl into Documentation/networking/ip-sysctl.rst Signed-off-by: Ahmed Abdelsalam --- Documentation/networking/ip-sysctl.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst index 837d51f9e1fa..9dacdebeafc5 100644 --- a/Documentation/networking/ip-sysctl.rst +++ b/Documentation/networking/ip-sysctl.rst @@ -1799,6 +1799,11 @@ seg6_flowlabel - INTEGER Default is 0. +seg6_inherit_inner_ipv4_dscp - BOOLEAN + Enable the SRv6 encapsulation to inherit the DSCP value of the inner IPv4 packet. + + Default: FALSE (Do not inherit DSCP) + ``conf/default/*``: Change the interface-specific default settings.