naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

Blame SOURCES/0119-tc-flower-introduce-enum-flower_endpoint.patch

4aca6e
From 404b627b261aa76de7718fb481e6bbdacbd6d869 Mon Sep 17 00:00:00 2001
4aca6e
From: Phil Sutter <psutter@redhat.com>
4aca6e
Date: Fri, 17 Mar 2017 13:23:33 +0100
4aca6e
Subject: [PATCH] tc: flower: introduce enum flower_endpoint
4aca6e
4aca6e
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1422629
4aca6e
Upstream Status: iproute2.git commit 6910d65661a37
4aca6e
4aca6e
commit 6910d65661a3718ef4b944251a0dec170027f3d5
4aca6e
Author: Simon Horman <simon.horman@netronome.com>
4aca6e
Date:   Wed Dec 7 14:54:02 2016 +0100
4aca6e
4aca6e
    tc: flower: introduce enum flower_endpoint
4aca6e
4aca6e
    Introduce enum flower_endpoint and use it instead of a bool
4aca6e
    as the type for paramatising source and destination.
4aca6e
4aca6e
    This is intended to improve read-ability and provide some type
4aca6e
    checking of endpoint parameters.
4aca6e
4aca6e
    Signed-off-by: Simon Horman <simon.horman@netronome.com>
4aca6e
---
4aca6e
 tc/f_flower.c | 27 +++++++++++++++++++--------
4aca6e
 1 file changed, 19 insertions(+), 8 deletions(-)
4aca6e
4aca6e
diff --git a/tc/f_flower.c b/tc/f_flower.c
4aca6e
index 3f0190f..523b82b 100644
4aca6e
--- a/tc/f_flower.c
4aca6e
+++ b/tc/f_flower.c
4aca6e
@@ -23,6 +23,11 @@
4aca6e
 #include "tc_util.h"
4aca6e
 #include "rt_names.h"
4aca6e
 
4aca6e
+enum flower_endpoint {
4aca6e
+	FLOWER_ENDPOINT_SRC,
4aca6e
+	FLOWER_ENDPOINT_DST
4aca6e
+};
4aca6e
+
4aca6e
 static void explain(void)
4aca6e
 {
4aca6e
 	fprintf(stderr,
4aca6e
@@ -166,29 +171,33 @@ static int flower_parse_ip_addr(char *str, __be16 eth_type,
4aca6e
 	return 0;
4aca6e
 }
4aca6e
 
4aca6e
-static int flower_port_attr_type(__u8 ip_proto, bool is_src)
4aca6e
+static int flower_port_attr_type(__u8 ip_proto, enum flower_endpoint endpoint)
4aca6e
 {
4aca6e
 	if (ip_proto == IPPROTO_TCP)
4aca6e
-		return is_src ? TCA_FLOWER_KEY_TCP_SRC :
4aca6e
+		return endpoint == FLOWER_ENDPOINT_SRC ?
4aca6e
+			TCA_FLOWER_KEY_TCP_SRC :
4aca6e
 			TCA_FLOWER_KEY_TCP_DST;
4aca6e
 	else if (ip_proto == IPPROTO_UDP)
4aca6e
-		return is_src ? TCA_FLOWER_KEY_UDP_SRC :
4aca6e
+		return endpoint == FLOWER_ENDPOINT_SRC ?
4aca6e
+			TCA_FLOWER_KEY_UDP_SRC :
4aca6e
 			TCA_FLOWER_KEY_UDP_DST;
4aca6e
 	else if (ip_proto == IPPROTO_SCTP)
4aca6e
-		return is_src ? TCA_FLOWER_KEY_SCTP_SRC :
4aca6e
+		return endpoint == FLOWER_ENDPOINT_SRC ?
4aca6e
+			TCA_FLOWER_KEY_SCTP_SRC :
4aca6e
 			TCA_FLOWER_KEY_SCTP_DST;
4aca6e
 	else
4aca6e
 		return -1;
4aca6e
 }
4aca6e
 
4aca6e
-static int flower_parse_port(char *str, __u8 ip_proto, bool is_src,
4aca6e
+static int flower_parse_port(char *str, __u8 ip_proto,
4aca6e
+			     enum flower_endpoint endpoint,
4aca6e
 			     struct nlmsghdr *n)
4aca6e
 {
4aca6e
 	int ret;
4aca6e
 	int type;
4aca6e
 	__be16 port;
4aca6e
 
4aca6e
-	type = flower_port_attr_type(ip_proto, is_src);
4aca6e
+	type = flower_port_attr_type(ip_proto, endpoint);
4aca6e
 	if (type < 0)
4aca6e
 		return -1;
4aca6e
 
4aca6e
@@ -359,14 +368,16 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
4aca6e
 			}
4aca6e
 		} else if (matches(*argv, "dst_port") == 0) {
4aca6e
 			NEXT_ARG();
4aca6e
-			ret = flower_parse_port(*argv, ip_proto, false, n);
4aca6e
+			ret = flower_parse_port(*argv, ip_proto,
4aca6e
+						FLOWER_ENDPOINT_DST, n);
4aca6e
 			if (ret < 0) {
4aca6e
 				fprintf(stderr, "Illegal \"dst_port\"\n");
4aca6e
 				return -1;
4aca6e
 			}
4aca6e
 		} else if (matches(*argv, "src_port") == 0) {
4aca6e
 			NEXT_ARG();
4aca6e
-			ret = flower_parse_port(*argv, ip_proto, true, n);
4aca6e
+			ret = flower_parse_port(*argv, ip_proto,
4aca6e
+						FLOWER_ENDPOINT_SRC, n);
4aca6e
 			if (ret < 0) {
4aca6e
 				fprintf(stderr, "Illegal \"src_port\"\n");
4aca6e
 				return -1;
4aca6e
-- 
4aca6e
1.8.3.1
4aca6e