naccyde / rpms / iproute

Forked from rpms/iproute 8 months ago
Clone

Blame SOURCES/0012-tc-act_tunnel_key-Enable-setup-of-tos-and-ttl.patch

7e752c
From b24c686f3e5bb0acbebf40c3e7f5a16f0582fd64 Mon Sep 17 00:00:00 2001
7e752c
From: Phil Sutter <psutter@redhat.com>
7e752c
Date: Thu, 13 Sep 2018 20:55:45 +0200
7e752c
Subject: [PATCH] tc/act_tunnel_key: Enable setup of tos and ttl
7e752c
7e752c
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1615915
7e752c
Upstream Status: iproute2.git commit 9f89b0cc0eda2
7e752c
Conflicts: Context change due to missing Geneve support.
7e752c
7e752c
commit 9f89b0cc0eda2ef52d8850b0610f3e2e09fd7c1c
7e752c
Author: Or Gerlitz <ogerlitz@mellanox.com>
7e752c
Date:   Thu Jul 19 14:02:14 2018 +0300
7e752c
7e752c
    tc/act_tunnel_key: Enable setup of tos and ttl
7e752c
7e752c
    Allow to set tos and ttl for the tunnel.
7e752c
7e752c
    For example, here's encap rule that sets tos to the tunnel:
7e752c
7e752c
    tc filter add dev eth0_0 protocol ip parent ffff: prio 10 flower \
7e752c
       src_mac e4:11:22:33:44:50 dst_mac e4:11:22:33:44:70 \
7e752c
       action tunnel_key set src_ip 192.168.10.1 dst_ip 192.168.10.2 id 100 dst_port 4789 tos 0x30 \
7e752c
       action mirred egress redirect dev vxlan_sys_4789
7e752c
7e752c
    Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
7e752c
    Reviewed-by: Roi Dayan <roid@mellanox.com>
7e752c
    Acked-by: Jiri Pirko <jiri@mellanox.com>
7e752c
    Signed-off-by: David Ahern <dsahern@gmail.com>
7e752c
---
7e752c
 man/man8/tc-tunnel_key.8 |  8 ++++++++
7e752c
 tc/m_tunnel_key.c        | 53 ++++++++++++++++++++++++++++++++++++++++++++++++
7e752c
 2 files changed, 61 insertions(+)
7e752c
7e752c
diff --git a/man/man8/tc-tunnel_key.8 b/man/man8/tc-tunnel_key.8
7e752c
index e979a74..71cee5b 100644
7e752c
--- a/man/man8/tc-tunnel_key.8
7e752c
+++ b/man/man8/tc-tunnel_key.8
7e752c
@@ -16,6 +16,8 @@ tunnel_key - Tunnel metadata manipulation
7e752c
 .IR ADDRESS
7e752c
 .BI id " KEY_ID"
7e752c
 .BI dst_port " UDP_PORT"
7e752c
+.BI tos " TOS"
7e752c
+.BI ttl " TTL"
7e752c
 .RB "[ " csum " | " nocsum " ]"
7e752c
 
7e752c
 .SH DESCRIPTION
7e752c
@@ -79,6 +81,12 @@ Outer header destination IP address (IPv4 or IPv6)
7e752c
 .B dst_port
7e752c
 Outer header destination UDP port
7e752c
 .TP
7e752c
+.B tos
7e752c
+Outer header TOS
7e752c
+.TP
7e752c
+.B ttl
7e752c
+Outer header TTL
7e752c
+.TP
7e752c
 .RB [ no ] csum
7e752c
 Controlls outer UDP checksum. When set to
7e752c
 .B csum
7e752c
diff --git a/tc/m_tunnel_key.c b/tc/m_tunnel_key.c
7e752c
index 0fa4615..8d0a8d1 100644
7e752c
--- a/tc/m_tunnel_key.c
7e752c
+++ b/tc/m_tunnel_key.c
7e752c
@@ -81,6 +81,22 @@ static int tunnel_key_parse_dst_port(char *str, int type, struct nlmsghdr *n)
7e752c
 	return 0;
7e752c
 }
7e752c
 
7e752c
+static int tunnel_key_parse_tos_ttl(char *str, int type, struct nlmsghdr *n)
7e752c
+{
7e752c
+	int ret;
7e752c
+	__u8 val;
7e752c
+
7e752c
+	ret = get_u8(&val, str, 10);
7e752c
+	if (ret)
7e752c
+		ret = get_u8(&val, str, 16);
7e752c
+	if (ret)
7e752c
+		return -1;
7e752c
+
7e752c
+	addattr8(n, MAX_MSG, type, val);
7e752c
+
7e752c
+	return 0;
7e752c
+}
7e752c
+
7e752c
 static int parse_tunnel_key(struct action_util *a, int *argc_p, char ***argv_p,
7e752c
 			    int tca_id, struct nlmsghdr *n)
7e752c
 {
7e752c
@@ -157,6 +173,22 @@ static int parse_tunnel_key(struct action_util *a, int *argc_p, char ***argv_p,
7e752c
 				fprintf(stderr, "Illegal \"dst port\"\n");
7e752c
 				return -1;
7e752c
 			}
7e752c
+		} else if (matches(*argv, "tos") == 0) {
7e752c
+			NEXT_ARG();
7e752c
+			ret = tunnel_key_parse_tos_ttl(*argv,
7e752c
+							TCA_TUNNEL_KEY_ENC_TOS, n);
7e752c
+			if (ret < 0) {
7e752c
+				fprintf(stderr, "Illegal \"tos\"\n");
7e752c
+				return -1;
7e752c
+			}
7e752c
+		} else if (matches(*argv, "ttl") == 0) {
7e752c
+			NEXT_ARG();
7e752c
+			ret = tunnel_key_parse_tos_ttl(*argv,
7e752c
+							TCA_TUNNEL_KEY_ENC_TTL, n);
7e752c
+			if (ret < 0) {
7e752c
+				fprintf(stderr, "Illegal \"ttl\"\n");
7e752c
+				return -1;
7e752c
+			}
7e752c
 		} else if (matches(*argv, "csum") == 0) {
7e752c
 			csum = 1;
7e752c
 		} else if (matches(*argv, "nocsum") == 0) {
7e752c
@@ -260,6 +292,23 @@ static void tunnel_key_print_flag(FILE *f, const char *name_on,
7e752c
 		     rta_getattr_u8(attr) ? name_on : name_off);
7e752c
 }
7e752c
 
7e752c
+static void tunnel_key_print_tos_ttl(FILE *f, char *name,
7e752c
+				     struct rtattr *attr)
7e752c
+{
7e752c
+	if (!attr)
7e752c
+		return;
7e752c
+
7e752c
+	if (matches(name, "tos") == 0 && rta_getattr_u8(attr) != 0) {
7e752c
+		print_string(PRINT_FP, NULL, "%s", _SL_);
7e752c
+		print_uint(PRINT_ANY, "tos", "\ttos 0x%x",
7e752c
+			   rta_getattr_u8(attr));
7e752c
+	} else if (matches(name, "ttl") == 0 && rta_getattr_u8(attr) != 0) {
7e752c
+		print_string(PRINT_FP, NULL, "%s", _SL_);
7e752c
+		print_uint(PRINT_ANY, "ttl", "\tttl %u",
7e752c
+			   rta_getattr_u8(attr));
7e752c
+	}
7e752c
+}
7e752c
+
7e752c
 static int print_tunnel_key(struct action_util *au, FILE *f, struct rtattr *arg)
7e752c
 {
7e752c
 	struct rtattr *tb[TCA_TUNNEL_KEY_MAX + 1];
7e752c
@@ -299,6 +348,10 @@ static int print_tunnel_key(struct action_util *au, FILE *f, struct rtattr *arg)
7e752c
 					  tb[TCA_TUNNEL_KEY_ENC_DST_PORT]);
7e752c
 		tunnel_key_print_flag(f, "nocsum", "csum",
7e752c
 				      tb[TCA_TUNNEL_KEY_NO_CSUM]);
7e752c
+		tunnel_key_print_tos_ttl(f, "tos",
7e752c
+					  tb[TCA_TUNNEL_KEY_ENC_TOS]);
7e752c
+		tunnel_key_print_tos_ttl(f, "ttl",
7e752c
+					  tb[TCA_TUNNEL_KEY_ENC_TTL]);
7e752c
 		break;
7e752c
 	}
7e752c
 	print_action_control(f, " ", parm->action, "");
7e752c
-- 
7e752c
1.8.3.1
7e752c