naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

Blame SOURCES/0112-tc-flower-Support-matching-on-SCTP-ports.patch

4aca6e
From 9c00f1da75c407be7638e5dc84ce02448f3832cd Mon Sep 17 00:00:00 2001
4aca6e
From: Phil Sutter <psutter@redhat.com>
4aca6e
Date: Fri, 17 Mar 2017 13:23:10 +0100
4aca6e
Subject: [PATCH] tc: flower: Support matching on SCTP ports
4aca6e
4aca6e
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1422629
4aca6e
Upstream Status: iproute2.git commit a1fb0d484237b
4aca6e
4aca6e
commit a1fb0d484237b41f92ee17634880be80a0dcf51a
4aca6e
Author: Simon Horman <simon.horman@netronome.com>
4aca6e
Date:   Thu Nov 3 13:26:41 2016 +0100
4aca6e
4aca6e
    tc: flower: Support matching on SCTP ports
4aca6e
4aca6e
    Support matching on SCTP ports in the same way that matching
4aca6e
    on TCP and UDP ports is already supported.
4aca6e
4aca6e
    Example usage:
4aca6e
4aca6e
    tc qdisc add dev eth0 ingress
4aca6e
4aca6e
    tc filter add dev eth0 protocol ip parent ffff: \
4aca6e
            flower indev eth0 ip_proto sctp dst_port 80 \
4aca6e
            action drop
4aca6e
4aca6e
    Signed-off-by: Simon Horman <simon.horman@netronome.com>
4aca6e
---
4aca6e
 tc/f_flower.c | 65 ++++++++++++++++++++++++++++-------------------------------
4aca6e
 1 file changed, 31 insertions(+), 34 deletions(-)
4aca6e
4aca6e
diff --git a/tc/f_flower.c b/tc/f_flower.c
4aca6e
index 6c9bea6..805e841 100644
4aca6e
--- a/tc/f_flower.c
4aca6e
+++ b/tc/f_flower.c
4aca6e
@@ -98,6 +98,8 @@ static int flower_parse_ip_proto(char *str, __be16 eth_type, int type,
4aca6e
 		ip_proto = IPPROTO_TCP;
4aca6e
 	} else if (matches(str, "udp") == 0) {
4aca6e
 		ip_proto = IPPROTO_UDP;
4aca6e
+	} else if (matches(str, "sctp") == 0) {
4aca6e
+		ip_proto = IPPROTO_SCTP;
4aca6e
 	} else {
4aca6e
 		ret = get_u8(&ip_proto, str, 16);
4aca6e
 		if (ret)
4aca6e
@@ -158,21 +160,33 @@ static int flower_parse_ip_addr(char *str, __be16 eth_type,
4aca6e
 	return 0;
4aca6e
 }
4aca6e
 
4aca6e
-static int flower_parse_port(char *str, __u8 ip_port,
4aca6e
-			     int tcp_type, int udp_type, struct nlmsghdr *n)
4aca6e
+static int flower_port_attr_type(__u8 ip_port, bool is_src)
4aca6e
 {
4aca6e
-	int ret;
4aca6e
-	int type;
4aca6e
-	__be16 port;
4aca6e
-
4aca6e
 	if (ip_port == IPPROTO_TCP) {
4aca6e
-		type = tcp_type;
4aca6e
+		return is_src ? TCA_FLOWER_KEY_TCP_SRC :
4aca6e
+			TCA_FLOWER_KEY_TCP_DST;
4aca6e
 	} else if (ip_port == IPPROTO_UDP) {
4aca6e
-		type = udp_type;
4aca6e
+		return is_src ? TCA_FLOWER_KEY_UDP_SRC :
4aca6e
+			TCA_FLOWER_KEY_UDP_DST;
4aca6e
+	} else if (ip_port == IPPROTO_SCTP) {
4aca6e
+		return is_src ? TCA_FLOWER_KEY_SCTP_SRC :
4aca6e
+			TCA_FLOWER_KEY_SCTP_DST;
4aca6e
 	} else {
4aca6e
 		fprintf(stderr, "Illegal \"ip_proto\" for port\n");
4aca6e
 		return -1;
4aca6e
 	}
4aca6e
+}
4aca6e
+
4aca6e
+static int flower_parse_port(char *str, __u8 ip_port, bool is_src,
4aca6e
+			     struct nlmsghdr *n)
4aca6e
+{
4aca6e
+	int ret;
4aca6e
+	int type;
4aca6e
+	__be16 port;
4aca6e
+
4aca6e
+	type = flower_port_attr_type(ip_port, is_src);
4aca6e
+	if (type < 0)
4aca6e
+		return -1;
4aca6e
 
4aca6e
 	ret = get_be16(&port, str, 10);
4aca6e
 	if (ret)
4aca6e
@@ -329,18 +343,14 @@ 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,
4aca6e
-						TCA_FLOWER_KEY_TCP_DST,
4aca6e
-						TCA_FLOWER_KEY_UDP_DST, n);
4aca6e
+			ret = flower_parse_port(*argv, ip_proto, false, 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,
4aca6e
-						TCA_FLOWER_KEY_TCP_SRC,
4aca6e
-						TCA_FLOWER_KEY_UDP_SRC, n);
4aca6e
+			ret = flower_parse_port(*argv, ip_proto, true, n);
4aca6e
 			if (ret < 0) {
4aca6e
 				fprintf(stderr, "Illegal \"src_port\"\n");
4aca6e
 				return -1;
4aca6e
@@ -456,6 +466,8 @@ static void flower_print_ip_proto(FILE *f, __u8 *p_ip_proto,
4aca6e
 		fprintf(f, "tcp");
4aca6e
 	else if (ip_proto == IPPROTO_UDP)
4aca6e
 		fprintf(f, "udp");
4aca6e
+	else if (ip_proto == IPPROTO_SCTP)
4aca6e
+		fprintf(f, "sctp");
4aca6e
 	else
4aca6e
 		fprintf(f, "%02x", ip_proto);
4aca6e
 	*p_ip_proto = ip_proto;
4aca6e
@@ -498,20 +510,8 @@ static void flower_print_ip_addr(FILE *f, char *name, __be16 eth_type,
4aca6e
 		fprintf(f, "/%d", bits);
4aca6e
 }
4aca6e
 
4aca6e
-static void flower_print_port(FILE *f, char *name, __u8 ip_proto,
4aca6e
-			      struct rtattr *tcp_attr,
4aca6e
-			      struct rtattr *udp_attr)
4aca6e
+static void flower_print_port(FILE *f, char *name, struct rtattr *attr)
4aca6e
 {
4aca6e
-	struct rtattr *attr;
4aca6e
-
4aca6e
-	if (ip_proto == IPPROTO_TCP)
4aca6e
-		attr = tcp_attr;
4aca6e
-	else if (ip_proto == IPPROTO_UDP)
4aca6e
-		attr = udp_attr;
4aca6e
-	else
4aca6e
-		return;
4aca6e
-	if (!attr)
4aca6e
-		return;
4aca6e
 	fprintf(f, "\n  %s %d", name, ntohs(rta_getattr_u16(attr)));
4aca6e
 }
4aca6e
 
4aca6e
@@ -575,13 +575,10 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
4aca6e
 			     tb[TCA_FLOWER_KEY_IPV6_SRC],
4aca6e
 			     tb[TCA_FLOWER_KEY_IPV6_SRC_MASK]);
4aca6e
 
4aca6e
-	flower_print_port(f, "dst_port", ip_proto,
4aca6e
-			  tb[TCA_FLOWER_KEY_TCP_DST],
4aca6e
-			  tb[TCA_FLOWER_KEY_UDP_DST]);
4aca6e
-
4aca6e
-	flower_print_port(f, "src_port", ip_proto,
4aca6e
-			  tb[TCA_FLOWER_KEY_TCP_SRC],
4aca6e
-			  tb[TCA_FLOWER_KEY_UDP_SRC]);
4aca6e
+	flower_print_port(f, "dst_port",
4aca6e
+			  tb[flower_port_attr_type(ip_proto, false)]);
4aca6e
+	flower_print_port(f, "src_port",
4aca6e
+			  tb[flower_port_attr_type(ip_proto, true)]);
4aca6e
 
4aca6e
 	if (tb[TCA_FLOWER_FLAGS]) {
4aca6e
 		__u32 flags = rta_getattr_u32(tb[TCA_FLOWER_FLAGS]);
4aca6e
-- 
4aca6e
1.8.3.1
4aca6e