From patchwork Wed Apr 21 08:44:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12215691 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70DD4C433ED for ; Wed, 21 Apr 2021 08:44:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4588E6143E for ; Wed, 21 Apr 2021 08:44:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237242AbhDUIou (ORCPT ); Wed, 21 Apr 2021 04:44:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235083AbhDUIot (ORCPT ); Wed, 21 Apr 2021 04:44:49 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABC87C06174A for ; Wed, 21 Apr 2021 01:44:16 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id 20so17294405pll.7 for ; Wed, 21 Apr 2021 01:44:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=date:from:to:cc:subject:message-id:mime-version; bh=7JzpPj+zPGXdKHdMicaBlqvPcqZwTfnr/huEEEpyx+U=; b=YFZhmZeB+BUGd2LpE16uUmSmj5pmRsJxmyMILPdK2Z5rV7Qppj9giDaC3ZjDI0MX2a 7lHnhUNKMac/mpjvk1nTQqBIn38t36n8OtWJt7jUnUnAMWWy74uZF2EGicGY+ujaICJw OmoxiKDtEntWOQ9Lw6V0toNCi+c8Qn8T+MPJo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version; bh=7JzpPj+zPGXdKHdMicaBlqvPcqZwTfnr/huEEEpyx+U=; b=qTgKpau/Dp4t3A5o5EZfbgofvJClIWzcwD49bT0jOXjshUyoG3ue/196V1XlXndF6z IkooYiocB+x35Z9bVyRD+ockLKISnePUC7xiABMt9tQE8vfVgmjGzsDRCLzMmuyE47qB frdFIAV9qhfx6+TAeUI2iWIlXGxzeg9HVSMTI37K1KednjAdi1LiWm7AU7j4HbmJ7b0z LOMC8BB+lWBKdk9GZuqSnsUV/nR6h5gLVkKxX+tzwjeNeLfbJpsf4UPf0h4RkWsyqUic SFP6ZdJWBptwKG6OuYcNYxPRRHllGRD4cqut05yzgxDZ9BWe7AxB6N17FTcNGA0iFgme Am7g== X-Gm-Message-State: AOAM533f8UVv1thYktl7KOdszGFR4Bmb1a3/LQviV/s+1DzJKgjO6PDi b1X7vBBL8OwbmoozlTMa2Dzin0I2iIvLyLynxGUsoue9lVNh1RWcUAHu5yj7hNSsgMF36BlVQj6 54rzCwZlIMWgqUZ4ahtaofNmHMSG+C09in1OSb8LkTNoH64xv4pvmUy6r50F+PSAMxg+gl4hxcu Agejx6cPg= X-Google-Smtp-Source: ABdhPJwAASMIIQrVI4189rJVcBXnT+wrYv+J9YFCCccLq9Eq6dpaKScPgOXA2Idm7Y7ygm9sn/B4Pw== X-Received: by 2002:a17:902:e98a:b029:eb:65ee:ddc9 with SMTP id f10-20020a170902e98ab02900eb65eeddc9mr32463001plb.73.1618994655710; Wed, 21 Apr 2021 01:44:15 -0700 (PDT) Received: from noodle ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id p10sm1130812pfo.210.2021.04.21.01.44.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Apr 2021 01:44:15 -0700 (PDT) Date: Wed, 21 Apr 2021 11:44:04 +0300 From: Boris Sukholitko To: netdev@vger.kernel.org, Jamal Hadi Salim , Jiri Pirko , Cong Wang Cc: Ilya Lifshits , Shmulik Ladkani Subject: [PATCH net-next] net/sched: act_vlan: Fix vlan modify to allow zero priority Message-ID: <20210421084404.GA7262@noodle> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Currently vlan modification action checks existance of vlan priority by comparing it to 0. Therefore it is impossible to modify existing vlan tag to have priority 0. For example, the following tc command will change the vlan id but will not affect vlan priority: tc filter add dev eth1 ingress matchall action vlan modify id 300 \ priority 0 pipe mirred egress redirect dev eth2 The incoming packet on eth1: ethertype 802.1Q (0x8100), vlan 200, p 4, ethertype IPv4 will be changed to: ethertype 802.1Q (0x8100), vlan 300, p 4, ethertype IPv4 although the user has intended to have p == 0. The fix is to add tcfv_push_prio_exists flag to struct tcf_vlan_params and rely on it when deciding to set the priority. Fixes: 45a497f2d149a4a8061c (net/sched: act_vlan: Introduce TCA_VLAN_ACT_MODIFY vlan action) Signed-off-by: Boris Sukholitko --- include/net/tc_act/tc_vlan.h | 1 + net/sched/act_vlan.c | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/net/tc_act/tc_vlan.h b/include/net/tc_act/tc_vlan.h index f051046ba034..f94b8bc26f9e 100644 --- a/include/net/tc_act/tc_vlan.h +++ b/include/net/tc_act/tc_vlan.h @@ -16,6 +16,7 @@ struct tcf_vlan_params { u16 tcfv_push_vid; __be16 tcfv_push_proto; u8 tcfv_push_prio; + bool tcfv_push_prio_exists; struct rcu_head rcu; }; diff --git a/net/sched/act_vlan.c b/net/sched/act_vlan.c index 1cac3c6fbb49..cca10b5e99c9 100644 --- a/net/sched/act_vlan.c +++ b/net/sched/act_vlan.c @@ -70,7 +70,7 @@ static int tcf_vlan_act(struct sk_buff *skb, const struct tc_action *a, /* replace the vid */ tci = (tci & ~VLAN_VID_MASK) | p->tcfv_push_vid; /* replace prio bits, if tcfv_push_prio specified */ - if (p->tcfv_push_prio) { + if (p->tcfv_push_prio_exists) { tci &= ~VLAN_PRIO_MASK; tci |= p->tcfv_push_prio << VLAN_PRIO_SHIFT; } @@ -121,6 +121,7 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla, struct tc_action_net *tn = net_generic(net, vlan_net_id); struct nlattr *tb[TCA_VLAN_MAX + 1]; struct tcf_chain *goto_ch = NULL; + bool push_prio_exists = false; struct tcf_vlan_params *p; struct tc_vlan *parm; struct tcf_vlan *v; @@ -189,7 +190,8 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla, push_proto = htons(ETH_P_8021Q); } - if (tb[TCA_VLAN_PUSH_VLAN_PRIORITY]) + push_prio_exists = !!tb[TCA_VLAN_PUSH_VLAN_PRIORITY]; + if (push_prio_exists) push_prio = nla_get_u8(tb[TCA_VLAN_PUSH_VLAN_PRIORITY]); break; case TCA_VLAN_ACT_POP_ETH: @@ -241,6 +243,7 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla, p->tcfv_action = action; p->tcfv_push_vid = push_vid; p->tcfv_push_prio = push_prio; + p->tcfv_push_prio_exists = push_prio_exists; p->tcfv_push_proto = push_proto; if (action == TCA_VLAN_ACT_PUSH_ETH) {