]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
f_flower: Treat port 0 as valid
authorIdo Schimmel <idosch@nvidia.com>
Tue, 11 Jul 2023 06:59:03 +0000 (09:59 +0300)
committerStephen Hemminger <stephen@networkplumber.org>
Thu, 13 Jul 2023 22:47:17 +0000 (15:47 -0700)
It is not currently possible to add a filter matching on port 0 despite
it being a valid port number. This is caused by cited commit which
treats a value of 0 as an indication that the port was not specified.

Instead of inferring that a port range was specified by checking that both
the minimum and the maximum ports are non-zero, simply add a boolean
argument to parse_range() and set it after parsing a port range.

Before:

 # tc filter add dev swp1 ingress pref 1 proto ip flower ip_proto udp src_port 0 action pass
 Illegal "src_port"

 # tc filter add dev swp1 ingress pref 2 proto ip flower ip_proto udp dst_port 0 action pass
 Illegal "dst_port"

 # tc filter add dev swp1 ingress pref 3 proto ip flower ip_proto udp src_port 0-100 action pass
 Illegal "src_port"

 # tc filter add dev swp1 ingress pref 4 proto ip flower ip_proto udp dst_port 0-100 action pass
 Illegal "dst_port"

After:

 # tc filter add dev swp1 ingress pref 1 proto ip flower ip_proto udp src_port 0 action pass

 # tc filter add dev swp1 ingress pref 2 proto ip flower ip_proto udp dst_port 0 action pass

 # tc filter add dev swp1 ingress pref 3 proto ip flower ip_proto udp src_port 0-100 action pass

 # tc filter add dev swp1 ingress pref 4 proto ip flower ip_proto udp dst_port 0-100 action pass

 # tc filter show dev swp1 ingress | grep _port
   src_port 0
   dst_port 0
   src_port 0-100
   dst_port 0-100

Fixes: 767b6fd620dd ("tc: flower: fix port value truncation")
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
tc/f_flower.c

index c71394f753a62027352c5e8ebc8616f98dccac02..737df199acf81e4ebf144450ab8b8cb01581d7fb 100644 (file)
@@ -735,7 +735,7 @@ static int flower_port_range_attr_type(__u8 ip_proto, enum flower_endpoint type,
 }
 
 /* parse range args in format 10-20 */
-static int parse_range(char *str, __be16 *min, __be16 *max)
+static int parse_range(char *str, __be16 *min, __be16 *max, bool *p_is_range)
 {
        char *sep;
 
@@ -748,6 +748,8 @@ static int parse_range(char *str, __be16 *min, __be16 *max)
 
                if (get_be16(max, sep + 1, 10))
                        return -1;
+
+               *p_is_range = true;
        } else {
                if (get_be16(min, str, 10))
                        return -1;
@@ -759,19 +761,20 @@ static int flower_parse_port(char *str, __u8 ip_proto,
                             enum flower_endpoint endpoint,
                             struct nlmsghdr *n)
 {
+       bool is_range = false;
        char *slash = NULL;
        __be16 min = 0;
        __be16 max = 0;
        int ret;
 
-       ret = parse_range(str, &min, &max);
+       ret = parse_range(str, &min, &max, &is_range);
        if (ret) {
                slash = strchr(str, '/');
                if (!slash)
                        return -1;
        }
 
-       if (min && max) {
+       if (is_range) {
                __be16 min_port_type, max_port_type;
 
                if (ntohs(max) <= ntohs(min)) {
@@ -784,7 +787,7 @@ static int flower_parse_port(char *str, __u8 ip_proto,
 
                addattr16(n, MAX_MSG, min_port_type, min);
                addattr16(n, MAX_MSG, max_port_type, max);
-       } else if (slash || (min && !max)) {
+       } else {
                int type;
 
                type = flower_port_attr_type(ip_proto, endpoint);
@@ -802,8 +805,6 @@ static int flower_parse_port(char *str, __u8 ip_proto,
                                return -1;
                        return flower_parse_u16(str, type, mask_type, n, true);
                }
-       } else {
-               return -1;
        }
        return 0;
 }