]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
f_flower: Check args with num_of_vlans
authorBoris Sukholitko <boris.sukholitko@broadcom.com>
Tue, 26 Apr 2022 09:14:17 +0000 (12:14 +0300)
committerDavid Ahern <dsahern@kernel.org>
Thu, 28 Apr 2022 02:18:12 +0000 (20:18 -0600)
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 <boris.sukholitko@broadcom.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
tc/f_flower.c

index 9e7404144d8bca82bd2521e638d87d581483a6df..805ca6718fa7cf7afd115a953baa82b06e277adf 100644 (file)
@@ -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 (strcmp(*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,
-                                                &eth_type, n);
+                                                &eth_type, n, num_of_vlans > 1);
                        if (ret < 0)
                                return -1;
                } else if (matches(*argv, "mpls") == 0) {