From patchwork Tue Apr 26 09:14:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12826746 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 16A0EC433EF for ; Tue, 26 Apr 2022 09:53:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348161AbiDZJ5D (ORCPT ); Tue, 26 Apr 2022 05:57:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345113AbiDZJ4z (ORCPT ); Tue, 26 Apr 2022 05:56:55 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0A9E36161 for ; Tue, 26 Apr 2022 02:14:55 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id p12so5707951pfn.0 for ; Tue, 26 Apr 2022 02:14:55 -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=kBx8KTV4cCQ5F5Vp4zg+QAENCViNYF/iEP8UvSG/FiU=; b=T2ZF+FtRI3el4HdOltD6A47sbXQ7CP/WA1yvqRZzzx0iu2BX+PNMPFHBmujEXKyxYO oM/1YihKtvYfdhQHwkfjR6ovlNXIkPEY/SYS7aoFd7MQWfjWpFdzvbofg0sW4RFjjqUa jE5G7P1QsY7NpTmIzGTagFMtcK1uqOuu7az+4= 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=kBx8KTV4cCQ5F5Vp4zg+QAENCViNYF/iEP8UvSG/FiU=; b=8LOCdp6t2n2S4tCjM4v5T96dN5LqfbYWv1qslf7qddK4x7ZBhovsFYHmNtiqUg1mQR +x3cBiw+U3KDrfyd2hvTowDIn8lHip151Of7+4Tkt6N89brt2yVkGKolCZvUIB2e+Ksr eUnWjLBOUi+uc39702yt/PeklWabFlXk2pDKj3+K+kgXf04REMoVjK0QbOw6HK3vyeQM tKIR/FOAAoik/MiXoWCVWsV8nMYfhlp/BoEER+CGmdFbo+frL93qwdFEU5a43YIDy6kz eWU89RCcKdUaLAkKt+EhvWUF8SaN4XcyIvtMZpQm1QZY+E47m2PiF9abCLum0Kl4g19k 5tHg== X-Gm-Message-State: AOAM531K3CASzyqIOyk67frrsdYqRm1kb7fZGEE8sI4P4SwnFQiesz0F lw9iBYbh2a2LbrQNm/naRo5zOr/QrrNi3f0oG4akhrPCl2pOF15wFNPfx4jqv2d1NUkeeqR8qPO ACmraHHuvykCoVPRWtiLSjrOM2KbEqPnuO/WTjoP8f9PPzYbVBmkVJ1AhzXq52f7/kXFomi7NXM KSuRnZ X-Google-Smtp-Source: ABdhPJyqsBejtjqWJfonGEdcHzxTEbNFn+5bjEijuMX+gIaJfGQb7HpsjboX722MZcl3qqQ5NNpkUg== X-Received: by 2002:a63:8b41:0:b0:3ab:6c5:79ba with SMTP id j62-20020a638b41000000b003ab06c579bamr11530417pge.382.1650964494931; Tue, 26 Apr 2022 02:14:54 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id z10-20020a62d10a000000b0050d3c3668bcsm7593829pfg.137.2022.04.26.02.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 02:14:54 -0700 (PDT) From: Boris Sukholitko To: netdev@vger.kernel.org, David Ahern Cc: Ilya Lifshits , Boris Sukholitko Subject: [PATCH iproute2-next v3 1/2] f_flower: Add num of vlans parameter Date: Tue, 26 Apr 2022 12:14:16 +0300 Message-Id: <20220426091417.7153-2-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220426091417.7153-1-boris.sukholitko@broadcom.com> References: <20220426091417.7153-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 --- tc/f_flower.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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 26 09:14:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12826747 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 23E09C4332F for ; Tue, 26 Apr 2022 09:54:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348177AbiDZJ5E (ORCPT ); Tue, 26 Apr 2022 05:57:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347918AbiDZJ44 (ORCPT ); Tue, 26 Apr 2022 05:56:56 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4408936B42 for ; Tue, 26 Apr 2022 02:14:59 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id t13so3766570pfg.2 for ; Tue, 26 Apr 2022 02:14:59 -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=ZBiMD4tEBeedkhTRdDHEgPGHqhk4eSsoe9CIMP5yimc=; b=HL6T/nzIgmoJIRdMkM63HEVcQsIZXzeQB9BFBd5b1LG5vT5AeompwzEptCXZNOBzmQ /EuelSIZ459MOQZQlXXos9mHEgl6lX5HAFw967ze3AYotNuQxv7k90NMjUiKpYsS7p8X nOcllKsdqnuBeBJIc/TC6lWM61mGCyqwJEts0= 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=ZBiMD4tEBeedkhTRdDHEgPGHqhk4eSsoe9CIMP5yimc=; b=bD+1vnLdC5iGmnyen0LB3O6DnGm0f47X6FE6elOxmNbLpPy0BajeVllcHwO9INZg3O vLJH3VintClhpQrVTUI0/kJd6nbiOyijmPjKxW2U2B3tTW4NouS/TuzKMYsul4XqRFD8 0rLvXzd+Ir1yFGYsQzuZJhjdSznbKK5VBLAZBBndnXaSZ6HyRR/UzGpB+cwM/wbG8VVq QItIR99oXBaOmd1GBSrJYvqwo/QYeZn5T5MpryQKpQUBaZdOmMrUTCv1m1fwWUfAkBsx zK+NYn+vvvtaKfkILJR1btVgQ8wD89hC5ooC0ml1jxNH9UO7KsCAtZxLdXJwV0r/wIgC pxSg== X-Gm-Message-State: AOAM530t9NPUObiXZoLpWgnGfnHwtAvxEoOyr+tKp4iZdWi0nSYVHLVj aTC/6+sbRnEc2PXzGVCVkRdSMmDjc1u4BcltL+QE+aaHI0ZovnjvXfBjK2GZ+fXLW4fzMv+LUXm TEX2S/Ql9WCHote5flwx7pMGgYv8eEHgVIIvFbw4EEhOoFAPQ9+Lu5vmjlQ8WZ+kqmJBI9Pu8DY vgwJ+r X-Google-Smtp-Source: ABdhPJxK2nHFACzlOaqNdMzWpl/rgIpAdqhoUwuYeOvEOf9G/ZkVLrbttb2sXXzO1r0mAUvEy59xmA== X-Received: by 2002:a63:8ac7:0:b0:3aa:fa62:5a28 with SMTP id y190-20020a638ac7000000b003aafa625a28mr13137938pgd.400.1650964497939; Tue, 26 Apr 2022 02:14:57 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id z10-20020a62d10a000000b0050d3c3668bcsm7593829pfg.137.2022.04.26.02.14.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 02:14:57 -0700 (PDT) From: Boris Sukholitko To: netdev@vger.kernel.org, David Ahern Cc: Ilya Lifshits , Boris Sukholitko Subject: [PATCH iproute2-next v3 2/2] f_flower: Check args with num_of_vlans Date: Tue, 26 Apr 2022 12:14:17 +0300 Message-Id: <20220426091417.7153-3-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220426091417.7153-1-boris.sukholitko@broadcom.com> References: <20220426091417.7153-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) {