From patchwork Tue Apr 12 10:03:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12810515 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 4BEF5C4332F for ; Tue, 12 Apr 2022 11:17:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345897AbiDLLTT (ORCPT ); Tue, 12 Apr 2022 07:19:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353728AbiDLLSp (ORCPT ); Tue, 12 Apr 2022 07:18:45 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96D17270F for ; Tue, 12 Apr 2022 03:04:03 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id w7so17018976pfu.11 for ; Tue, 12 Apr 2022 03:04:03 -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=Su5g0cBvl9sY0aYek3V0UtXX6OK7gdGZs1KvKvdoxx4=; b=JRDhmRj0Dvc3mNu5gqwT/E+HxqWXPLS8qE6ivqT1mYZ5yQVzEWA5R3zOlal1x5qHob 8OpHq8PtWLskUn8kchmWn6rMqMfrizJW8vcT6MNSBvAfvlEz4R5TiC4RVv7J+hlivL9l ZK4IUXGKpGjxDJc5WsrLeJYl323+rSVvZdg8c= 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=Su5g0cBvl9sY0aYek3V0UtXX6OK7gdGZs1KvKvdoxx4=; b=f9PQUfGnt6gu7k+XG1bm26j/AEiJd8J41Ombjo+QWrKHILivKoNQg6HVe3CJQ1bv4D +rFdmo7DCvDWQ0HJBaYxKqD//j6e54TyPGF7Hz2mORxcq3LujOpc0e3bkfqOKq946rnQ cXh6Q2iEuB5z9gh/qsbN8EtitunLbC+phOS8iz2yqfcRhDqY7Q5U0rkmlaSFD06gZMIz ht3uc06uks0ooj4Qlk3pgT4zMoZz4kODscBXChPahCxZuHkUR4LaSgKHy37RhbGlEGXF yq8Ch18DmeMshuo+KVpg2JwQmVDCDoYnKVTk/UUUrshs4WLlyg44NahvMqkmBDLAACfD afKg== X-Gm-Message-State: AOAM532xxIO73Tm2lhZWO7DJu1oB7fUC/dQEuVTVT79dyE7hCgmguw9O C68TrEg3gkrrG91xRLyP2ruf+1uOUiiUXCmTGjKnlFN6ooelewBEy8cHGrqW+fnXeJWyKAHdr6V 0JtcQuGC6S8sZkxbKwAgV0tWfucJ29hGRZQSE45VYu100nfJ+CDa7u1nVHSNdtjTwAAPrzvbIym fniTziNuFY+g== X-Google-Smtp-Source: ABdhPJwRikj4gacRtvBjJ22X3h+gKCJPqoWJiJNXkGbMmwdGO5t/+lXYtIjBhqttX16dJxtDQj8TGQ== X-Received: by 2002:a63:f24c:0:b0:383:c279:e662 with SMTP id d12-20020a63f24c000000b00383c279e662mr30137507pgk.303.1649757842504; Tue, 12 Apr 2022 03:04:02 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id n24-20020aa79058000000b00505686a982asm17357087pfo.125.2022.04.12.03.03.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 03:04:02 -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 v2 1/2] f_flower: Add num of vlans parameter Date: Tue, 12 Apr 2022 13:03:42 +0300 Message-Id: <20220412100343.27387-2-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220412100343.27387-1-boris.sukholitko@broadcom.com> References: <20220412100343.27387-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 404f97fb..c3d3b5f0 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 686cf121..25ffd295 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" @@ -1525,6 +1526,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; @@ -2694,6 +2706,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]; From patchwork Tue Apr 12 10:03:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12810518 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 7FB6FC433F5 for ; Tue, 12 Apr 2022 11:17:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234524AbiDLLUG (ORCPT ); Tue, 12 Apr 2022 07:20:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353659AbiDLLSo (ORCPT ); Tue, 12 Apr 2022 07:18:44 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35D85B1EE for ; Tue, 12 Apr 2022 03:04:08 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id s8so17028530pfk.12 for ; Tue, 12 Apr 2022 03:04:08 -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=WYWdI8SnkW+7JcG0y6OXmOYBsZ4qC0Suz1521b7t3yA=; b=c1JRDcQ9rOUHYLPBmmyyzwz6Sl+qiUmgU9+qnS1h6ixreXFWG69WcDeZIhSlhzT+v8 lhMk4vi68uijceqf6zp/KG6aDQ7TXsyUqbbNQ8qsZ0SmLOzvx4aqE2X3dx64H5+3eW7g 6cjo5gNbiRGZkEIluEOoGo3bM8JwA0rzIhFDQ= 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=WYWdI8SnkW+7JcG0y6OXmOYBsZ4qC0Suz1521b7t3yA=; b=ZF1PUBFxqCASIGc9n0GwDLUW+x3ZIkLSXPgRf+G2NyshBLmerb3lS/GH6bln2Ay2t3 bRabQD9L6fwY7nuasHKuEMwdlgqNk0xAXIBOJXIiBZvYj7sXAtOPuOWS11Bv9AB/eGx1 H/RcppTv5vVp7qpDi82X7/LuAshd32wVCGk18T+zXR+PY+euAczYcqIqR/Y/bRlom168 52SUUDpYmrNoMwfIEVK2LqkRIxW6j8u/jrRKRnq+eL+dH7n0Os5ATm/+8fdlFtz1KTm2 8FDVyyDeGkw8IZ8H0J2QusQynoR3pMvMUaPED1hVO8DvAm3n1AXtvpKNbBlKA/IbIL/S zOUA== X-Gm-Message-State: AOAM532JKqxtGlecR5GLx39pZkIlCiVTJEXhtzgKwI9+R29RiWGzzW/8 p9PiGl6CsAarP0kGlB7YW8qf9XASMVjULTgnxQGZ7zZPulOgVIMrAfq7e2IqR1V7PasNXWPgC6w A0oWgBVvbEzU+RZ6s4bI2DnK4OMnXCYN9ny/qtyk1kYGOhyFIGJBpgusPhF9n+/LWZ+pJdF/tbn 0+uKcMtuqZUw== X-Google-Smtp-Source: ABdhPJyVEQGZDAIS9xPw4B8cLm3gcL4CW9ZbPjXXFwUAKql8bOB7nGUtu9MnVTfO5ADlbxdJR7guaA== X-Received: by 2002:a05:6a00:e05:b0:505:952c:eb04 with SMTP id bq5-20020a056a000e0500b00505952ceb04mr17553907pfb.48.1649757846903; Tue, 12 Apr 2022 03:04:06 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id n24-20020aa79058000000b00505686a982asm17357087pfo.125.2022.04.12.03.04.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 03:04:06 -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 v2 2/2] f_flower: Check args with num_of_vlans Date: Tue, 12 Apr 2022 13:03:43 +0300 Message-Id: <20220412100343.27387-3-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220412100343.27387-1-boris.sukholitko@broadcom.com> References: <20220412100343.27387-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 Having more than one vlan allows matching on the vlan tag parameters. This patch changes vlan key validation to take number of vlan tags into account. Signed-off-by: Boris Sukholitko --- tc/f_flower.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/tc/f_flower.c b/tc/f_flower.c index 25ffd295..fbb7042f 100644 --- a/tc/f_flower.c +++ b/tc/f_flower.c @@ -160,21 +160,23 @@ err: return err; } -static bool eth_type_vlan(__be16 ethertype) +static bool eth_type_vlan(__be16 ethertype, bool good_num_of_vlans) { return ethertype == htons(ETH_P_8021Q) || - ethertype == htons(ETH_P_8021AD); + ethertype == htons(ETH_P_8021AD) || + good_num_of_vlans; } static int flower_parse_vlan_eth_type(char *str, __be16 eth_type, int type, __be16 *p_vlan_eth_type, - struct nlmsghdr *n) + struct nlmsghdr *n, bool good_num_of_vlans) { __be16 vlan_eth_type; - if (!eth_type_vlan(eth_type)) { - fprintf(stderr, "Can't set \"%s\" if ethertype isn't 802.1Q or 802.1AD\n", - type == TCA_FLOWER_KEY_VLAN_ETH_TYPE ? "vlan_ethtype" : "cvlan_ethtype"); + if (!eth_type_vlan(eth_type, good_num_of_vlans)) { + fprintf(stderr, "Can't set \"%s\" if ethertype isn't 802.1Q or 802.1AD and num_of_vlans %s\n", + type == TCA_FLOWER_KEY_VLAN_ETH_TYPE ? "vlan_ethtype" : "cvlan_ethtype", + type == TCA_FLOWER_KEY_VLAN_ETH_TYPE ? "is 0" : "less than 2"); return -1; } @@ -1425,6 +1427,7 @@ static int flower_parse_opt(struct filter_util *qu, char *handle, __be16 tc_proto = TC_H_MIN(t->tcm_info); __be16 eth_type = tc_proto; __be16 vlan_ethtype = 0; + __u8 num_of_vlans = 0; __u8 ip_proto = 0xff; __u32 flags = 0; __u32 mtf = 0; @@ -1527,8 +1530,6 @@ static int flower_parse_opt(struct filter_util *qu, char *handle, 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) { @@ -1541,8 +1542,9 @@ static int flower_parse_opt(struct filter_util *qu, char *handle, __u16 vid; NEXT_ARG(); - if (!eth_type_vlan(tc_proto)) { - fprintf(stderr, "Can't set \"vlan_id\" if ethertype isn't 802.1Q or 802.1AD\n"); + if (!eth_type_vlan(tc_proto, num_of_vlans > 0)) { + fprintf(stderr, "Can't set \"vlan_id\" if ethertype isn't 802.1Q or 802.1AD" + " and num_of_vlans is 0\n"); return -1; } ret = get_u16(&vid, *argv, 10); @@ -1555,8 +1557,9 @@ static int flower_parse_opt(struct filter_util *qu, char *handle, __u8 vlan_prio; NEXT_ARG(); - if (!eth_type_vlan(tc_proto)) { - fprintf(stderr, "Can't set \"vlan_prio\" if ethertype isn't 802.1Q or 802.1AD\n"); + if (!eth_type_vlan(tc_proto, num_of_vlans > 0)) { + fprintf(stderr, "Can't set \"vlan_prio\" if ethertype isn't 802.1Q or 802.1AD" + " and num_of_vlans is 0\n"); return -1; } ret = get_u8(&vlan_prio, *argv, 10); @@ -1570,7 +1573,7 @@ static int flower_parse_opt(struct filter_util *qu, char *handle, NEXT_ARG(); ret = flower_parse_vlan_eth_type(*argv, eth_type, TCA_FLOWER_KEY_VLAN_ETH_TYPE, - &vlan_ethtype, n); + &vlan_ethtype, n, num_of_vlans > 0); if (ret < 0) return -1; /* get new ethtype for later parsing */ @@ -1579,8 +1582,9 @@ static int flower_parse_opt(struct filter_util *qu, char *handle, __u16 vid; NEXT_ARG(); - if (!eth_type_vlan(vlan_ethtype)) { - fprintf(stderr, "Can't set \"cvlan_id\" if inner vlan ethertype isn't 802.1Q or 802.1AD\n"); + if (!eth_type_vlan(vlan_ethtype, num_of_vlans > 1)) { + fprintf(stderr, "Can't set \"cvlan_id\" if inner vlan ethertype isn't 802.1Q or 802.1AD" + " and num_of_vlans is less than 2\n"); return -1; } ret = get_u16(&vid, *argv, 10); @@ -1593,8 +1597,9 @@ static int flower_parse_opt(struct filter_util *qu, char *handle, __u8 cvlan_prio; NEXT_ARG(); - if (!eth_type_vlan(vlan_ethtype)) { - fprintf(stderr, "Can't set \"cvlan_prio\" if inner vlan ethertype isn't 802.1Q or 802.1AD\n"); + if (!eth_type_vlan(vlan_ethtype, num_of_vlans > 1)) { + fprintf(stderr, "Can't set \"cvlan_prio\" if inner vlan ethertype isn't 802.1Q or 802.1AD" + " and num_of_vlans is less than 2\n"); return -1; } ret = get_u8(&cvlan_prio, *argv, 10); @@ -1609,7 +1614,7 @@ static int flower_parse_opt(struct filter_util *qu, char *handle, /* get new ethtype for later parsing */ ret = flower_parse_vlan_eth_type(*argv, vlan_ethtype, TCA_FLOWER_KEY_CVLAN_ETH_TYPE, - ð_type, n); + ð_type, n, num_of_vlans > 1); if (ret < 0) return -1; } else if (matches(*argv, "mpls") == 0) {