From patchwork Wed Mar 23 10:58:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Sukholitko X-Patchwork-Id: 12789680 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 389D1C433F5 for ; Wed, 23 Mar 2022 10:58:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243671AbiCWLAF (ORCPT ); Wed, 23 Mar 2022 07:00:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243682AbiCWLAE (ORCPT ); Wed, 23 Mar 2022 07:00:04 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1D516264 for ; Wed, 23 Mar 2022 03:58:32 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id n18so1160482plg.5 for ; Wed, 23 Mar 2022 03:58:32 -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=pARK/XoDsBYF1fxSOeFx9R+JUDJJVjySYuQqsfsBH70=; b=Khdphxz0kadtGR3ayKVrL8bZjIRajYK2tHktcLC0NukbS0T+xL4Y8JL8/l7wYCor7F 6T7DbToQC0V3l0no8ty5kx7C2vn6Wh5HTG9EuMDanx3jPoXIfJ29qZSLFwzbnl8pk97n Y/DoNOAtCc4x/3iZ6MnTVmlT/UQ27LAnpAcK4= 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=pARK/XoDsBYF1fxSOeFx9R+JUDJJVjySYuQqsfsBH70=; b=VhNKXmJgw9nNt4iKFT1rO6afSVF70b+6wVGoHb+GLDIIwRAulycaw8jF3dLY2v2mat JWq967gy/fY5rYWoxbd7IhWUomF6TmfsymkQZUjNCQadXWEAu1moa7fDR+jSBNHFhwaR aGnXNcjPSfdKTLmeQNXqQAPLQU0rRpIsBWmp/ChyGQfTQRVEfD9iK8L5HRXzQ7LCRS8m JrL2O7v+lTm5q19N7zjpjN4S9vBH2V4ldnTtuOJBGCZt/YBHkcLsqbK6x+pFJSZ3enFX 91R4+9ZqW2+bC5C7JnIrUrZk5m1vfBDTwizTH1coot6xjQQHluBkhy2N/bjS6T/IYdDM 8duw== X-Gm-Message-State: AOAM532p2yg6cs6/jc83x1OA0uGtZHSLy4PAiV/very6fcc3wyfY5tO1 EJ0+vVZgehHrrNLrzYjmp9Gzpt/4ug6Djj+7prg2vAGWYLaiyB6x+REH3zkITVZp9fH2eHRdgjV jzt0JrnmBsyfgxarv0SrFI9yg9zklq7zJgr2K6EVqiYX1OmbyIMija0ok/5oZOxswSsolC8lXU7 7n39uB5nmPLQ== X-Google-Smtp-Source: ABdhPJxW6qOG78nO+4kS7NFLW0q73PufWizS+6n2bAqH5KaowC1uysil/w0ifEHo2oMdvPNFTn7eSA== X-Received: by 2002:a17:90b:4c0a:b0:1c6:90be:1e03 with SMTP id na10-20020a17090b4c0a00b001c690be1e03mr11013581pjb.7.1648033111105; Wed, 23 Mar 2022 03:58:31 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 03:58:30 -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: Wed, 23 Mar 2022 12:58:08 +0200 Message-Id: <20220323105808.30298-3-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 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) {