From patchwork Mon Apr 11 13:32:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12809110 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 7C746C433F5 for ; Mon, 11 Apr 2022 13:32:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346515AbiDKNel (ORCPT ); Mon, 11 Apr 2022 09:34:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344766AbiDKNee (ORCPT ); Mon, 11 Apr 2022 09:34:34 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C483D3BA78 for ; Mon, 11 Apr 2022 06:32:20 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id md4so7005172pjb.4 for ; Mon, 11 Apr 2022 06:32:20 -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=FR4SpZ9TdPBWFRM2d2PCRNVXh3HmS7NIyYotcUyr+Lo=; b=NDXVPiSfg4mus+QQx0LeiuNTTIy7UJyK1WFida75V5qB+KS8EXodAFGAPy/+/OOwOS 1bYYUk1gblTLVaZampbojLZUHakg6hGd9j2O/58grB857DxUN0SNRIzdHAI3PPu0i27U sH/0hUCXdY6P2Ng+HyMGTn8klQ1c8fnRrScSA= 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=FR4SpZ9TdPBWFRM2d2PCRNVXh3HmS7NIyYotcUyr+Lo=; b=WOQReXZels3bsxI+U2aMSw0aejjDdYfs/a6WooWqQF5qTrIXjlMMt7KfkYQK4Z9jD8 Nsg0JxKAdYBDFv1p9d/8Q3GY5SR5sEbRP3LsZjNdQUTwVMKxpXmrFk7WBMeEHzHyO+DW XdRNmcEg7rzhdQzg6MW25Y8oKrJoHq0fy38fpH1BrNxbfibw2xL0cWd9xRUpqPgmRba2 IFPKmft6VDVlIpilyEBsPQDRp9uP8DfGalm7h6LMuNwErJ7PBUkhAHu8ioYbYbx9PQL7 pVVeJRdTcWm+aHmGZ8y5DJf82AOnykP1BS3cFIRyWXUAgpN2sTqvoVbodhZMdj57Xtjp FaRA== X-Gm-Message-State: AOAM530xytU1L/0G5PuWnbUgrkkQA/OOAuuIgkCYdt23d0Vy3CWnkoQh 5U0a8bySgvFYkGDzGUCdTwD/9qfKISmoybFxPhmiW1em7wd28FlHHHRUsQSFSJYFbgi3Kfe06Ku 5T+PAAFmkKMkGb0R2eYIZSaC/HNmeV4Nszxhdp8nAGhAMOkc1HLi0Cm7ZraxNwDy9zQZarzTROX BqouoZmOxDyg== X-Google-Smtp-Source: ABdhPJyK1YBU7YuX4Z2jpB+Q3WlzpaROhX6ErZOtmhF+wf5FiadKdipVdHzFY0pVBDYYDuoQWMNYmA== X-Received: by 2002:a17:90b:4c44:b0:1c7:109c:b419 with SMTP id np4-20020a17090b4c4400b001c7109cb419mr36810433pjb.113.1649683939714; Mon, 11 Apr 2022 06:32:19 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id v4-20020a17090a00c400b001cb4f242c92sm10232730pjd.26.2022.04.11.06.32.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 06:32:19 -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: Mon, 11 Apr 2022 16:32:01 +0300 Message-Id: <20220411133202.18278-2-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220411133202.18278-1-boris.sukholitko@broadcom.com> References: <20220411133202.18278-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]; From patchwork Mon Apr 11 13:32:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12809111 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 5C10EC433EF for ; Mon, 11 Apr 2022 13:32:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346520AbiDKNem (ORCPT ); Mon, 11 Apr 2022 09:34:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346513AbiDKNej (ORCPT ); Mon, 11 Apr 2022 09:34:39 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 578F83BBC2 for ; Mon, 11 Apr 2022 06:32:25 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id w7so14563364pfu.11 for ; Mon, 11 Apr 2022 06:32:25 -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=OHX0dl9AmtffQB/6l5CyS0UXxgnNzwfTEMkXvaYH1GY=; b=M5Ba/1Q6akqRTRjeiw4HJr0Xjby6kH3CfdjZxJKQP79wTbZoAlacsWsboZguOwJZBk rxa/krE7eH0l9JE0YTWT3fZ06OAh1TzgoqZ1RNqo6buPUEjmImMiuCAeQ/NluuSdwPHU hq+o3fB8jGJ4yVpdq0gWHFOTcmQFr3ej7vrQc= 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=OHX0dl9AmtffQB/6l5CyS0UXxgnNzwfTEMkXvaYH1GY=; b=WL4lRb26r8SnZ4Rux0/LL7OUOg9i4rYmX+pemYDTBsgkZUS/fHiAjBxShJaJtVofXH M3RzyGh6018fCEBhf5f7luXV+ReL2q90mKw5agyIHE+FR3wGRfczpeGmercT0MUUJgOi GRVIuW6En5lU8cM74Hjz9ovb5QPUegp05/G88PyFBYv5p4ixlJqgbFgNwMAvENPntFn1 L3TO0VNS6UjEqnaPSFHr6Grqii/6nXt9kAYxL15MxKRP42tH6rrQefZm0CcR+bet/uwS xsvPnj0fvoyq2lmIbUOsv6LlBwYk4EqwULyAI2bS/8JCgcN1m/EoY17cbPtScE9fUvtM e5Cw== X-Gm-Message-State: AOAM533iW51WW/mwdNVLf6wtT3rVAKiCgQCRLcXwxK+/uRGflDVDa39Y qAwqIvzi3KBeFG81RpG3V2qEC1Ln4VrDivUtltQ4jdf+yRwfDInoJlgUuoFlf1xodmX48wW30Zp p6JRNcZfmTOpqmK3xPrAPmBb30zCp/1NMU865WgC8AG/cIwdtSo/iEzx/LTYCjkSvbwzSXy0qnu UMIorGS8ENQQ== X-Google-Smtp-Source: ABdhPJwiy+euyuMajH/1HgeZb9c8/hjtNloFH+aez+xBC7kcUoWCTSFXd6egelgfAe/2sjJtTFfuPA== X-Received: by 2002:a62:7b12:0:b0:505:bf6f:46b9 with SMTP id w18-20020a627b12000000b00505bf6f46b9mr5439104pfc.22.1649683944319; Mon, 11 Apr 2022 06:32:24 -0700 (PDT) Received: from localhost.localdomain ([192.19.250.250]) by smtp.gmail.com with ESMTPSA id v4-20020a17090a00c400b001cb4f242c92sm10232730pjd.26.2022.04.11.06.32.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 06:32:23 -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 2/2] Check args with num_of_vlans Date: Mon, 11 Apr 2022 16:32:02 +0300 Message-Id: <20220411133202.18278-3-boris.sukholitko@broadcom.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220411133202.18278-1-boris.sukholitko@broadcom.com> References: <20220411133202.18278-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 68f7dbe3..968a2bb4 100644 --- a/tc/f_flower.c +++ b/tc/f_flower.c @@ -146,21 +146,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; } @@ -1330,6 +1332,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; @@ -1432,8 +1435,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) { @@ -1446,8 +1447,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); @@ -1460,8 +1462,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); @@ -1475,7 +1478,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 */ @@ -1484,8 +1487,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); @@ -1498,8 +1502,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); @@ -1514,7 +1519,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) {