From patchwork Wed Mar 23 10:58:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12789679 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B387BC433FE for ; Wed, 23 Mar 2022 10:58:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243678AbiCWK76 (ORCPT ); Wed, 23 Mar 2022 06:59:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232688AbiCWK74 (ORCPT ); Wed, 23 Mar 2022 06:59:56 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7179E1172 for ; Wed, 23 Mar 2022 03:58:27 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id u22so1222524pfg.6 for ; Wed, 23 Mar 2022 03:58:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version; bh=fDPJDSlzrmhxhmXvprMkoAWld1toldk3H8GDE66busU=; b=VVpGjUSa+7eKwc0/eKAFxqAfYoUAmR/VfWia8a3ewiHuofPdMkQN0G3CJGU593LrC8 XJTDIE/C8iW+j5//fdAL0jPbIEL68N9pb3f7Hb5yJBqFbbB8ehxk/Cg7ULdlJTncGnXX FUAEz7fy1sJB+c6pFRmBRWj/zInhimHIpXdek= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version; bh=fDPJDSlzrmhxhmXvprMkoAWld1toldk3H8GDE66busU=; b=jfdUM1hmU6mrhRgzT1CTZgxc95/ea2I10z5OyBnfJekQl35BFqnMffRtbslXJASX/S R9ldiJIrk7wB/DRg+S5d4nIhrAytGbcP33izsncyN8UY98o7FTV2sOEGq8XLBmbOkFwe v/FgUsv2T1YOmsVqXEkAZZccc17SQe8B64PUGC1rZEZYdlssgUrQZjXLE5oj9wc4b/hP Kev/xXSchXT/AkNAfTx4Uaf6fNMoWUC7vsWlKdCXIcY4iYLJDUCZjk/NTcSJt2Prv1gT YmRYQBGkI/papkXfVRznkYE/raMf4HQWKVSy7h7JzJHFmw5TX0KiwSYSPukYScQZmGQn RcnA== X-Gm-Message-State: AOAM532E7EFEEQKSvgcy7ZwNHQS0TWvw0iWqGDsOS35nm28ib0w0tQWq w0hA8/5aqlaBEOeAst62Dac2fXOJujWDYEFMNIK9md/NhhYj3A5K22FwOhXp1Bk/7+TC8Gm51LB a1pJSKi29QalyJsrT+Y/Yf8Hm/oBXXCKMWYxhlKrieJVpepctaJv2VNHAeI0VkraYtdCW/wMzox vM9e51KY+SSQ== X-Google-Smtp-Source: ABdhPJxR2UzPjcKLmStVNM1flBoERfPPNbjdtnqIUBgPxyAOcU0UXaYNoZOflaotpJQ18K9LWiXJxA== X-Received: by 2002:a63:dc42:0:b0:382:6aff:3f17 with SMTP id f2-20020a63dc42000000b003826aff3f17mr13401746pgj.5.1648033106513; Wed, 23 Mar 2022 03:58:26 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id p125-20020a622983000000b004f6c5d58225sm26092027pfp.90.2022.03.23.03.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 03:58:26 -0700 (PDT) From: Boris Sukholitko To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Jamal Hadi Salim , Cong Wang , Jiri Pirko , "Gustavo A . R . Silva" , Vladimir Oltean , Eric Dumazet , zhang kai , Yoshiki Komachi Cc: Ilya Lifshits , Boris Sukholitko Subject: [PATCH iproute2-next 1/2] Add num of vlans parameter Date: Wed, 23 Mar 2022 12:58:07 +0200 Message-Id: <20220323105808.30298-2-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220323105808.30298-1-boris.sukholitko@broadcom.com> References: <20220323105808.30298-1-boris.sukholitko@broadcom.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Our customers in the fiber telecom world have network configurations where they would like to control their traffic according to the number of tags appearing in the packet. For example, TR247 GPON conformance test suite specification mostly talks about untagged, single, double tagged packets and gives lax guidelines on the vlan protocol vs. number of vlan tags. This is different from the common IT networks where 802.1Q and 802.1ad protocols are usually describe single and double tagged packet. GPON configurations that we work with have arbitrary mix the above protocols and number of vlan tags in the packet. This patch adds num_of_vlans flower key and associated print and parse routines. The following command becomes possible: tc filter add dev eth1 ingress flower num_of_vlans 1 action drop Signed-off-by: Boris Sukholitko --- include/uapi/linux/pkt_cls.h | 2 ++ tc/f_flower.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h index ee38b35c..658f71db 100644 --- a/include/uapi/linux/pkt_cls.h +++ b/include/uapi/linux/pkt_cls.h @@ -587,6 +587,8 @@ enum { TCA_FLOWER_KEY_HASH, /* u32 */ TCA_FLOWER_KEY_HASH_MASK, /* u32 */ + TCA_FLOWER_KEY_NUM_OF_VLANS, /* u8 */ + __TCA_FLOWER_MAX, }; diff --git a/tc/f_flower.c b/tc/f_flower.c index 728b280c..68f7dbe3 100644 --- a/tc/f_flower.c +++ b/tc/f_flower.c @@ -48,6 +48,7 @@ static void explain(void) "\n" "Where: MATCH-LIST := [ MATCH-LIST ] MATCH\n" " MATCH := { indev DEV-NAME |\n" + " num_of_vlans VLANS_COUNT |\n" " vlan_id VID |\n" " vlan_prio PRIORITY |\n" " vlan_ethtype [ ipv4 | ipv6 | ETH-TYPE ] |\n" @@ -1430,6 +1431,17 @@ static int flower_parse_opt(struct filter_util *qu, char *handle, if (check_ifname(*argv)) invarg("\"indev\" not a valid ifname", *argv); addattrstrz(n, MAX_MSG, TCA_FLOWER_INDEV, *argv); + } else if (matches(*argv, "num_of_vlans") == 0) { + __u8 num_of_vlans; + + NEXT_ARG(); + ret = get_u8(&num_of_vlans, *argv, 10); + if (ret < 0) { + fprintf(stderr, "Illegal \"num_of_vlans\"\n"); + return -1; + } + addattr8(n, MAX_MSG, + TCA_FLOWER_KEY_NUM_OF_VLANS, num_of_vlans); } else if (matches(*argv, "vlan_id") == 0) { __u16 vid; @@ -2581,6 +2593,14 @@ static int flower_print_opt(struct filter_util *qu, FILE *f, open_json_object("keys"); + if (tb[TCA_FLOWER_KEY_NUM_OF_VLANS]) { + struct rtattr *attr = tb[TCA_FLOWER_KEY_NUM_OF_VLANS]; + + print_nl(); + print_uint(PRINT_ANY, "num_of_vlans", " num_of_vlans %d", + rta_getattr_u8(attr)); + } + if (tb[TCA_FLOWER_KEY_VLAN_ID]) { struct rtattr *attr = tb[TCA_FLOWER_KEY_VLAN_ID];