From patchwork Thu May 18 02:49:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Dawson X-Patchwork-Id: 763828 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 3wSwcx6F9Tz9s3s for ; Thu, 18 May 2017 12:49:21 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="sqveFgFN"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753734AbdERCtE (ORCPT ); Wed, 17 May 2017 22:49:04 -0400 Received: from mail-yw0-f180.google.com ([209.85.161.180]:34893 "EHLO mail-yw0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753553AbdERCtD (ORCPT ); Wed, 17 May 2017 22:49:03 -0400 Received: by mail-yw0-f180.google.com with SMTP id l74so14892846ywe.2 for ; Wed, 17 May 2017 19:49:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=acj5BYDO7nfGif3HmYpna61JRnmM6V8gw5cxedJ5ETw=; b=sqveFgFNvZc6mc00P+jD8qzjmfeX3+hdhNGmNOaNHjPxMJ0QRzArWdwblmk1FX+DKE oa2IYIKVWg3gBeuIg1syRyo4SQpM39vwVb3Fhg41kAeXXLF6zZCCil9IwjOPHKU7a7ix vt22PFY4ZUlWFs8SaiiG0It+v1KOfaA3nOUCdH1KI5b3L6CGQ4VxDJuGqZ2NA6jxwEoD JSUNRnWzLBV9E5FX8Fu2r1t6vkho+/S0YI12es/RYoytT8HH4uGmk9pHIQDfR/5zDOJV qhUB7+CtmhiUvdNv7ZNs3pdddHddNQX2cyt9vgupC+ZqDFAHrNRRyTDcGR2SZ6+mmeFS HtvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=acj5BYDO7nfGif3HmYpna61JRnmM6V8gw5cxedJ5ETw=; b=gWFQdyI+tzbfaWik1tq62MVerRh15MmPbdYnnJmrJu8Hlq1kDr1bZ4XTw6y5NUfZqR zuUjRuqc3vLODNEiIapzylL47gojjq82g0pqnPc5lIWlGtkYUAyQyYB13eJtWj3awbIE Jss3/JCgJc1hek8ebQMABGeOCUnAVeznx4c2LRVIYPzk5OXRYfh8i0wMrq1CBEZxlgGb YZ5HlCpAyZwuue9MXpG2VZsWnSAPLf4qupJ/1OJ9Y1o7YJA3NDqWEU/zsiqbH62VKx+z EEqyCsRrl+8y4lWUeasJCFeg8AkgGgz/F7Me+5IIjo57MdxhgQ2e/YPyIpeSlHbvNqlx J7Mg== X-Gm-Message-State: AODbwcAPE94gSu/cHJGOXUzOY51tjzAq2GBun6Lamju5NCbBcGZNHGUp Wnyx1bDL20HsAyRf07+RLT09xCLp5g== X-Received: by 10.129.91.136 with SMTP id p130mr1537849ywb.167.1495075742216; Wed, 17 May 2017 19:49:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.129.198.9 with HTTP; Wed, 17 May 2017 19:49:01 -0700 (PDT) In-Reply-To: <579256095bc540bab2668f55a6a2c25b@XCH15-07-02.nw.nos.boeing.com> References: <5fba416f3f644db2b1f51e54724ef6ba@XCH15-07-02.nw.nos.boeing.com> <20170517181800.07788dd8@xeon-e3> <579256095bc540bab2668f55a6a2c25b@XCH15-07-02.nw.nos.boeing.com> From: Peter Dawson Date: Thu, 18 May 2017 12:49:01 +1000 Message-ID: Subject: Re: [PATCH] ip6_tunnel, ip6_gre: fix setting of DSCP on encapsulated packets To: stephen@networkplumber.org Cc: netdev@vger.kernel.org Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org >> This fix addresses two problems in the way the DSCP field is >> formulated on the encapsulating header of IPv6 tunnels. >> This fix addresses Bug 195661. >> https://bugzilla.kernel.org/show_bug.cgi?id=195661 >> >> 1) The IPv6 tunneling code was manipulating the DSCP field of the >> encapsulating packet using the 32b flowlabel. Since the flowlabel is >> only the lower 20b it was incorrect to assume that the upper 12b >> containing the DSCP and ECN fields would remain intact when >> formulating the encapsulating header. This fix handles the 'inherit' >> and 'fixed-value' DSCP cases explicitly using the extant dsfield u8 variable. >> >> 2) The use of INET_ECN_encapsulate(0, dsfield) in ip6_tnl_xmit was >> incorrect and resulted in the DSCP value always being set to 0. >> --- >> net/ipv6/ip6_gre.c | 18 ++++++++++-------- >> net/ipv6/ip6_tunnel.c | 28 +++++++++++++++++----------- >> 2 files changed, 27 insertions(+), 19 deletions(-) > > This patch looks correct, but has trivial style issues like using spaces instead of tabs and other junk. Please run checkpatch.pl, look at the results and resubmit. Thanks. I've run checkpatch.pl over this updated file with no errors. Regards Peter From f12adb265f683d53ae071725e657dab17d26ed8d Mon Sep 17 00:00:00 2001 From: Peter Dawson Date: Thu, 18 May 2017 11:52:22 +1000 Subject: [PATCH] ip6_tunnel, ip6_gre: fix setting of DSCP on encapsulated packets This fix addresses two problems in the way the DSCP field is formulated on the encapsulating header of IPv6 tunnels. This fix addresses Bug 195661. 1) The IPv6 tunneling code was manipulating the DSCP field of the encapsulating packet using the 32b flowlabel. Since the flowlabel is only the lower 20b it was incorrect to assume that the upper 12b containing the DSCP and ECN fields would remain intact when formulating the encapsulating header. This fix handles the 'inherit' and 'fixed-value' DSCP cases explicitly using the extant dsfield u8 variable. 2) The use of INET_ECN_encapsulate(0, dsfield) in ip6_tnl_xmit was incorrect and resulted in the DSCP value always being set to 0. Signed-off-by: Peter Dawson --- net/ipv6/ip6_gre.c | 13 +++++++------ net/ipv6/ip6_tunnel.c | 21 +++++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index 8d128ba..0c5b4caa 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -537,11 +537,10 @@ static inline int ip6gre_xmit_ipv4(struct sk_buff *skb, struct net_device *dev) memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6)); - dsfield = ipv4_get_dsfield(iph); - if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS) - fl6.flowlabel |= htonl((__u32)iph->tos << IPV6_TCLASS_SHIFT) - & IPV6_TCLASS_MASK; + dsfield = ipv4_get_dsfield(iph); + else + dsfield = ip6_tclass(t->parms.flowinfo); if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK) fl6.flowi6_mark = skb->mark; else @@ -598,9 +597,11 @@ static inline int ip6gre_xmit_ipv6(struct sk_buff *skb, struct net_device *dev) memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6)); - dsfield = ipv6_get_dsfield(ipv6h); if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS) - fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK); + dsfield = ipv6_get_dsfield(ipv6h); + else + dsfield = ip6_tclass(t->parms.flowinfo); + if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL) fl6.flowlabel |= ip6_flowlabel(ipv6h); if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK) diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c index 6eb2ae5..7ae6c50 100644 --- a/net/ipv6/ip6_tunnel.c +++ b/net/ipv6/ip6_tunnel.c @@ -1196,7 +1196,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield, skb_push(skb, sizeof(struct ipv6hdr)); skb_reset_network_header(skb); ipv6h = ipv6_hdr(skb); - ip6_flow_hdr(ipv6h, INET_ECN_encapsulate(0, dsfield), + ip6_flow_hdr(ipv6h, dsfield, ip6_make_flowlabel(net, skb, fl6->flowlabel, true, fl6)); ipv6h->hop_limit = hop_limit; ipv6h->nexthdr = proto; @@ -1231,8 +1231,6 @@ ip4ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev) if (tproto != IPPROTO_IPIP && tproto != 0) return -1; - dsfield = ipv4_get_dsfield(iph); - if (t->parms.collect_md) { struct ip_tunnel_info *tun_info; const struct ip_tunnel_key *key; @@ -1246,6 +1244,7 @@ ip4ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev) fl6.flowi6_proto = IPPROTO_IPIP; fl6.daddr = key->u.ipv6.dst; fl6.flowlabel = key->label; + dsfield = ip6_tclass(key->label); } else { if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT)) encap_limit = t->parms.encap_limit; @@ -1254,8 +1253,9 @@ ip4ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev) fl6.flowi6_proto = IPPROTO_IPIP; if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS) - fl6.flowlabel |= htonl((__u32)iph->tos << IPV6_TCLASS_SHIFT) - & IPV6_TCLASS_MASK; + dsfield = ipv4_get_dsfield(iph); + else + dsfield = ip6_tclass(t->parms.flowinfo); if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK) fl6.flowi6_mark = skb->mark; else @@ -1267,6 +1267,8 @@ ip4ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev) if (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP6)) return -1; + dsfield = INET_ECN_encapsulate(dsfield, ipv4_get_dsfield(iph)); + skb_set_inner_ipproto(skb, IPPROTO_IPIP); err = ip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu, @@ -1300,8 +1302,6 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev) ip6_tnl_addr_conflict(t, ipv6h)) return -1; - dsfield = ipv6_get_dsfield(ipv6h); - if (t->parms.collect_md) { struct ip_tunnel_info *tun_info; const struct ip_tunnel_key *key; @@ -1315,6 +1315,7 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev) fl6.flowi6_proto = IPPROTO_IPV6; fl6.daddr = key->u.ipv6.dst; fl6.flowlabel = key->label; + dsfield = ip6_tclass(key->label); } else { offset = ip6_tnl_parse_tlv_enc_lim(skb, skb_network_header(skb)); /* ip6_tnl_parse_tlv_enc_lim() might have reallocated skb->head */ @@ -1337,7 +1338,9 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev) fl6.flowi6_proto = IPPROTO_IPV6; if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS) - fl6.flowlabel |= (*(__be32 *)ipv6h & IPV6_TCLASS_MASK); + dsfield = ipv6_get_dsfield(ipv6h); + else + dsfield = ip6_tclass(t->parms.flowinfo); if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL) fl6.flowlabel |= ip6_flowlabel(ipv6h); if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK) @@ -1351,6 +1354,8 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev) if (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP6)) return -1; + dsfield = INET_ECN_encapsulate(dsfield, ipv6_get_dsfield(ipv6h)); + skb_set_inner_ipproto(skb, IPPROTO_IPV6); err = ip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu, -- 2.7.4