From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.bufferbloat.net (Postfix) with ESMTPS id E21C43B29D for ; Thu, 25 Jun 2020 07:55:09 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593086109; 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=+GyCVjS8LavJYzTtjsaGAZKXMsx/0KStkzJq3dfYbt4=; b=jH+e2480V7wuyhJC/bZoAHb++MviINYUzkq/R47cu+6gSNK+/8hfLs0PKqySEeNV4M8H33 y43gOCjyNwtKktyeSGdpI2VNn0gImOohEUoGE2qiENnWg13Yguh2vrRW7sJzZfoOc1AphE NevEVpDNM3WVXnoyDpX3SCDClwkpBr8= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-319-ZOXftZCVMje6OwBwI6m3aQ-1; Thu, 25 Jun 2020 07:55:08 -0400 X-MC-Unique: ZOXftZCVMje6OwBwI6m3aQ-1 Received: by mail-wm1-f70.google.com with SMTP id g124so6617373wmg.6 for ; Thu, 25 Jun 2020 04:55:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=+GyCVjS8LavJYzTtjsaGAZKXMsx/0KStkzJq3dfYbt4=; b=KlQoURu7H3PqWgLUoxh8XsShoGd7z/tNUjO7q16GPS34+THdEJQ998n60GP0a+OPTi 1fAP8NGvz5VyzPqoxdTbj10VVks0/PAJSzmKXmwkqsttMs1mwdSSMhtI6y2Nu/wcS3Gk tFMoK4CqZae/Bb5LUEKCLrgS3tELh+z98ZiMhMzy+nXA8b6A+N8YZpaDaR4yGiboQMea vvtw8P965wM0EjSs1pTEDDOWNoiNM56N93yT/aSmBy1YXVPuyqhxg+XJuCzfWnXmID/h IiDbHXppYffu8MvWf4GTyAOMvtaxenzfrzXH3P3FoyOR/vDc/Zp22GEu6XN+NlKvr5gR f/zg== X-Gm-Message-State: AOAM530A+YWyQUyQDbNyqnDYoWKSEg7gV+uRftXRhQxWwiaUYLjkF6VC WdODZWkZMTBTc/rdvc8dL76YJmeEeOD/+tlQf8pblL5nP4QfeRzIybPLYKCh0kFQf2lW+lNgJ6G 8lbOTwHd1jiVsVOz8ecsHuQ== X-Received: by 2002:adf:de12:: with SMTP id b18mr29199206wrm.390.1593086106426; Thu, 25 Jun 2020 04:55:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzixQVDcysECuSK19xqNfgAFGxuWDWVR/lLk1obBH5HLClAUOnlT7+gODGTqff+OoDNWxACMw== X-Received: by 2002:adf:de12:: with SMTP id b18mr29199182wrm.390.1593086106142; Thu, 25 Jun 2020 04:55:06 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id d24sm11573252wmb.45.2020.06.25.04.55.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2020 04:55:05 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id F201B1814FA; Thu, 25 Jun 2020 13:55:03 +0200 (CEST) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: David Miller Cc: netdev@vger.kernel.org, cake@lists.bufferbloat.net Date: Thu, 25 Jun 2020 13:55:03 +0200 Message-ID: <159308610390.190211.17831843954243284203.stgit@toke.dk> In-Reply-To: <159308610282.190211.9431406149182757758.stgit@toke.dk> References: <159308610282.190211.9431406149182757758.stgit@toke.dk> User-Agent: StGit/0.23 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Subject: [Cake] [PATCH net-next 1/5] sch_cake: fix IP protocol handling in the presence of VLAN tags X-BeenThere: cake@lists.bufferbloat.net X-Mailman-Version: 2.1.20 Precedence: list List-Id: Cake - FQ_codel the next generation List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Jun 2020 11:55:10 -0000 From: Ilya Ponetayev CAKE was using the return value of tc_skb_protocol() and expecting it to be the IP protocol type. This can fail in the presence of QinQ VLAN tags, making CAKE unable to handle ECN marking and diffserv parsing in this case. Fix this by implementing our own version of tc_skb_protocol(), which will use skb->protocol directly, but also parse and skip over any VLAN tags and return the inner protocol number instead. Also fix CE marking by implementing a version of INET_ECN_set_ce() that uses the same parsing routine. Fixes: ea82511518f4 ("sch_cake: Add NAT awareness to packet classifier") Fixes: b2100cc56fca ("sch_cake: Use tc_skb_protocol() helper for getting packet protocol") Fixes: 046f6fd5daef ("sched: Add Common Applications Kept Enhanced (cake) qdisc") Signed-off-by: Ilya Ponetayev [ squash original two patches, rewrite commit message ] Signed-off-by: Toke Høiland-Jørgensen --- net/sched/sch_cake.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c index 60f8ae578819..0f594d88a957 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -497,6 +497,52 @@ static bool cobalt_queue_empty(struct cobalt_vars *vars, return down; } +static __be16 cake_skb_proto(const struct sk_buff *skb) +{ + unsigned int offset = skb_mac_offset(skb) + sizeof(struct ethhdr); + __be16 proto = skb->protocol; + struct vlan_hdr vhdr, *vh; + + while (proto == htons(ETH_P_8021Q) || proto == htons(ETH_P_8021AD)) { + vh = skb_header_pointer(skb, offset, sizeof(vhdr), &vhdr); + if (!vh) + break; + + proto = vh->h_vlan_encapsulated_proto; + offset += sizeof(vhdr); + } + + return proto; +} + +static int cake_set_ce(struct sk_buff *skb) +{ + int wlen = skb_network_offset(skb); + + switch (cake_skb_proto(skb)) { + case htons(ETH_P_IP): + wlen += sizeof(struct iphdr); + if (!pskb_may_pull(skb, wlen) || + skb_try_make_writable(skb, wlen)) + return 0; + + return IP_ECN_set_ce(ip_hdr(skb)); + + case htons(ETH_P_IPV6): + wlen += sizeof(struct ipv6hdr); + if (!pskb_may_pull(skb, wlen) || + skb_try_make_writable(skb, wlen)) + return 0; + + return IP6_ECN_set_ce(skb, ipv6_hdr(skb)); + + default: + return 0; + } + + return 0; +} + /* Call this with a freshly dequeued packet for possible congestion marking. * Returns true as an instruction to drop the packet, false for delivery. */ @@ -549,7 +595,7 @@ static bool cobalt_should_drop(struct cobalt_vars *vars, if (next_due && vars->dropping) { /* Use ECN mark if possible, otherwise drop */ - drop = !(vars->ecn_marked = INET_ECN_set_ce(skb)); + drop = !(vars->ecn_marked = cake_set_ce(skb)); vars->count++; if (!vars->count) @@ -592,7 +638,7 @@ static bool cake_update_flowkeys(struct flow_keys *keys, bool rev = !skb->_nfct, upd = false; __be32 ip; - if (tc_skb_protocol(skb) != htons(ETH_P_IP)) + if (cake_skb_proto(skb) != htons(ETH_P_IP)) return false; if (!nf_ct_get_tuple_skb(&tuple, skb)) @@ -1556,7 +1602,7 @@ static u8 cake_handle_diffserv(struct sk_buff *skb, u16 wash) int wlen = skb_network_offset(skb); u8 dscp; - switch (tc_skb_protocol(skb)) { + switch (cake_skb_proto(skb)) { case htons(ETH_P_IP): wlen += sizeof(struct iphdr); if (!pskb_may_pull(skb, wlen) ||