naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

Blame SOURCES/0013-tc-flower-Add-match-on-encapsulating-tos-ttl.patch

930fb9
From 23c57e53c5dfdaf113ecf1ebde8e04e8c7a10c50 Mon Sep 17 00:00:00 2001
930fb9
From: Phil Sutter <psutter@redhat.com>
930fb9
Date: Thu, 13 Sep 2018 20:56:18 +0200
930fb9
Subject: [PATCH] tc/flower: Add match on encapsulating tos/ttl
930fb9
930fb9
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1615915
930fb9
Upstream Status: iproute2.git commit 761ec9e29ff86
930fb9
930fb9
commit 761ec9e29ff867452057f59dc6ca430688b409ea
930fb9
Author: Or Gerlitz <ogerlitz@mellanox.com>
930fb9
Date:   Thu Jul 19 14:02:15 2018 +0300
930fb9
930fb9
    tc/flower: Add match on encapsulating tos/ttl
930fb9
930fb9
    Add matching on tos/ttl of the IP tunnel headers.
930fb9
930fb9
    For example, here's decap rule that matches on the tunnel tos:
930fb9
930fb9
    tc filter add dev vxlan_sys_4789 protocol ip parent ffff: prio 10 flower \
930fb9
       enc_src_ip 192.168.10.2 enc_dst_ip 192.168.10.1 enc_key_id 100 enc_dst_port 4789 enc_tos 0x30 \
930fb9
       src_mac e4:11:22:33:44:70 dst_mac e4:11:22:33:44:50  \
930fb9
       action tunnel_key unset \
930fb9
       action mirred egress redirect dev eth0_0
930fb9
930fb9
    Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
930fb9
    Reviewed-by: Roi Dayan <roid@mellanox.com>
930fb9
    Acked-by: Jiri Pirko <jiri@mellanox.com>
930fb9
    Signed-off-by: David Ahern <dsahern@gmail.com>
930fb9
---
930fb9
 man/man8/tc-flower.8 | 14 +++++++++++++-
930fb9
 tc/f_flower.c        | 27 +++++++++++++++++++++++++++
930fb9
 2 files changed, 40 insertions(+), 1 deletion(-)
930fb9
930fb9
diff --git a/man/man8/tc-flower.8 b/man/man8/tc-flower.8
930fb9
index 4f3714b..f917f24 100644
930fb9
--- a/man/man8/tc-flower.8
930fb9
+++ b/man/man8/tc-flower.8
930fb9
@@ -70,6 +70,10 @@ flower \- flow based traffic control filter
930fb9
 .IR ipv4_address " | " ipv6_address " } | "
930fb9
 .B enc_dst_port
930fb9
 .IR port_number " | "
930fb9
+.B enc_tos
930fb9
+.IR TOS " | "
930fb9
+.B enc_ttl
930fb9
+.IR TTL " | "
930fb9
 .BR ip_flags
930fb9
 .IR IP_FLAGS
930fb9
 .SH DESCRIPTION
930fb9
@@ -252,6 +256,10 @@ bits is assumed.
930fb9
 .BI enc_src_ip " PREFIX"
930fb9
 .TQ
930fb9
 .BI enc_dst_port " NUMBER"
930fb9
+.TQ
930fb9
+.BI enc_tos " NUMBER"
930fb9
+.TQ
930fb9
+.BI enc_ttl " NUMBER"
930fb9
 Match on IP tunnel metadata. Key id
930fb9
 .I NUMBER
930fb9
 is a 32 bit tunnel key id (e.g. VNI for VXLAN tunnel).
930fb9
@@ -260,7 +268,11 @@ must be a valid IPv4 or IPv6 address optionally followed by a slash and the
930fb9
 prefix length. If the prefix is missing, \fBtc\fR assumes a full-length
930fb9
 host match.  Dst port
930fb9
 .I NUMBER
930fb9
-is a 16 bit UDP dst port.
930fb9
+is a 16 bit UDP dst port. Tos
930fb9
+.I NUMBER
930fb9
+is an 8 bit tos (dscp+ecn) value, ttl
930fb9
+.I NUMBER
930fb9
+is an 8 bit time-to-live value.
930fb9
 .TP
930fb9
 .BI ip_flags " IP_FLAGS"
930fb9
 .I IP_FLAGS
930fb9
diff --git a/tc/f_flower.c b/tc/f_flower.c
930fb9
index 1dfd57d..cd102f2 100644
930fb9
--- a/tc/f_flower.c
930fb9
+++ b/tc/f_flower.c
930fb9
@@ -74,6 +74,8 @@ static void explain(void)
930fb9
 		"                       enc_dst_ip [ IPV4-ADDR | IPV6-ADDR ] |\n"
930fb9
 		"                       enc_src_ip [ IPV4-ADDR | IPV6-ADDR ] |\n"
930fb9
 		"                       enc_key_id [ KEY-ID ] |\n"
930fb9
+		"                       enc_tos MASKED-IP_TOS |\n"
930fb9
+		"                       enc_ttl MASKED-IP_TTL |\n"
930fb9
 		"                       ip_flags IP-FLAGS | \n"
930fb9
 		"                       enc_dst_port [ port_number ] }\n"
930fb9
 		"       FILTERID := X:Y:Z\n"
930fb9
@@ -972,6 +974,26 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
930fb9
 				fprintf(stderr, "Illegal \"enc_dst_port\"\n");
930fb9
 				return -1;
930fb9
 			}
930fb9
+		} else if (matches(*argv, "enc_tos") == 0) {
930fb9
+			NEXT_ARG();
930fb9
+			ret = flower_parse_ip_tos_ttl(*argv,
930fb9
+						      TCA_FLOWER_KEY_ENC_IP_TOS,
930fb9
+						      TCA_FLOWER_KEY_ENC_IP_TOS_MASK,
930fb9
+						      n);
930fb9
+			if (ret < 0) {
930fb9
+				fprintf(stderr, "Illegal \"enc_tos\"\n");
930fb9
+				return -1;
930fb9
+			}
930fb9
+		} else if (matches(*argv, "enc_ttl") == 0) {
930fb9
+			NEXT_ARG();
930fb9
+			ret = flower_parse_ip_tos_ttl(*argv,
930fb9
+						      TCA_FLOWER_KEY_ENC_IP_TTL,
930fb9
+						      TCA_FLOWER_KEY_ENC_IP_TTL_MASK,
930fb9
+						      n);
930fb9
+			if (ret < 0) {
930fb9
+				fprintf(stderr, "Illegal \"enc_ttl\"\n");
930fb9
+				return -1;
930fb9
+			}
930fb9
 		} else if (matches(*argv, "action") == 0) {
930fb9
 			NEXT_ARG();
930fb9
 			ret = parse_action(&argc, &argv, TCA_FLOWER_ACT, n);
930fb9
@@ -1463,6 +1485,11 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
930fb9
 
930fb9
 	flower_print_port("enc_dst_port", tb[TCA_FLOWER_KEY_ENC_UDP_DST_PORT]);
930fb9
 
930fb9
+	flower_print_ip_attr("enc_tos", tb[TCA_FLOWER_KEY_ENC_IP_TOS],
930fb9
+			    tb[TCA_FLOWER_KEY_ENC_IP_TOS_MASK]);
930fb9
+	flower_print_ip_attr("enc_ttl", tb[TCA_FLOWER_KEY_ENC_IP_TTL],
930fb9
+			    tb[TCA_FLOWER_KEY_ENC_IP_TTL_MASK]);
930fb9
+
930fb9
 	flower_print_matching_flags("ip_flags", FLOWER_IP_FLAGS,
930fb9
 				    tb[TCA_FLOWER_KEY_FLAGS],
930fb9
 				    tb[TCA_FLOWER_KEY_FLAGS_MASK]);
930fb9
-- 
930fb9
1.8.3.1
930fb9