naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

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

36cfb7
From 7521695ca299ceb723dc6b17f304b91300b3b16c Mon Sep 17 00:00:00 2001
36cfb7
From: Phil Sutter <psutter@redhat.com>
36cfb7
Date: Wed, 6 Feb 2019 14:51:57 +0100
36cfb7
Subject: [PATCH] tc/act_tunnel_key: Enable setup of tos and ttl
36cfb7
36cfb7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1641909
36cfb7
Upstream Status: iproute2.git commit 9f89b0cc0eda2
36cfb7
Conflicts:
36cfb7
* Context change due to missing commits
36cfb7
  59eb271d1d259 ("tc: m_tunnel_key: add csum/nocsum option") and
36cfb7
  6217917a38268 ("tc: m_tunnel_key: Add tunnel option support to act_tunnel_key").
36cfb7
* Adjusted tunnel_key_print_tos_ttl() to missing commit 8feb516bfcdd9
36cfb7
  ("tc: jsonify tunnel_key action").
36cfb7
36cfb7
commit 9f89b0cc0eda2ef52d8850b0610f3e2e09fd7c1c
36cfb7
Author: Or Gerlitz <ogerlitz@mellanox.com>
36cfb7
Date:   Thu Jul 19 14:02:14 2018 +0300
36cfb7
36cfb7
    tc/act_tunnel_key: Enable setup of tos and ttl
36cfb7
36cfb7
    Allow to set tos and ttl for the tunnel.
36cfb7
36cfb7
    For example, here's encap rule that sets tos to the tunnel:
36cfb7
36cfb7
    tc filter add dev eth0_0 protocol ip parent ffff: prio 10 flower \
36cfb7
       src_mac e4:11:22:33:44:50 dst_mac e4:11:22:33:44:70 \
36cfb7
       action tunnel_key set src_ip 192.168.10.1 dst_ip 192.168.10.2 id 100 dst_port 4789 tos 0x30 \
36cfb7
       action mirred egress redirect dev vxlan_sys_4789
36cfb7
36cfb7
    Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
36cfb7
    Reviewed-by: Roi Dayan <roid@mellanox.com>
36cfb7
    Acked-by: Jiri Pirko <jiri@mellanox.com>
36cfb7
    Signed-off-by: David Ahern <dsahern@gmail.com>
36cfb7
---
e138d9
 man/man8/tc-tunnel_key.8 |  8 +++++++
e138d9
 tc/m_tunnel_key.c        | 49 ++++++++++++++++++++++++++++++++++++++++
36cfb7
 2 files changed, 57 insertions(+)
36cfb7
36cfb7
diff --git a/man/man8/tc-tunnel_key.8 b/man/man8/tc-tunnel_key.8
e138d9
index 52fa585a75c8f..5e93c59d49465 100644
36cfb7
--- a/man/man8/tc-tunnel_key.8
36cfb7
+++ b/man/man8/tc-tunnel_key.8
36cfb7
@@ -16,6 +16,8 @@ tunnel_key - Tunnel metadata manipulation
36cfb7
 .IR ADDRESS
36cfb7
 .BI id " KEY_ID"
36cfb7
 .BI dst_port " UDP_PORT"
36cfb7
+.BI tos " TOS"
36cfb7
+.BI ttl " TTL"
36cfb7
 
36cfb7
 .SH DESCRIPTION
36cfb7
 The
36cfb7
@@ -77,6 +79,12 @@ Outer header destination IP address (IPv4 or IPv6)
36cfb7
 .TP
36cfb7
 .B dst_port
36cfb7
 Outer header destination UDP port
36cfb7
+.TP
36cfb7
+.B tos
36cfb7
+Outer header TOS
36cfb7
+.TP
36cfb7
+.B ttl
36cfb7
+Outer header TTL
36cfb7
 .RE
36cfb7
 .SH EXAMPLES
36cfb7
 The following example encapsulates incoming ICMP packets on eth0 into a vxlan
36cfb7
diff --git a/tc/m_tunnel_key.c b/tc/m_tunnel_key.c
e138d9
index acbcfc15cda76..60fd1c464e531 100644
36cfb7
--- a/tc/m_tunnel_key.c
36cfb7
+++ b/tc/m_tunnel_key.c
36cfb7
@@ -80,6 +80,22 @@ static int tunnel_key_parse_dst_port(char *str, int type, struct nlmsghdr *n)
36cfb7
 	return 0;
36cfb7
 }
36cfb7
 
36cfb7
+static int tunnel_key_parse_tos_ttl(char *str, int type, struct nlmsghdr *n)
36cfb7
+{
36cfb7
+	int ret;
36cfb7
+	__u8 val;
36cfb7
+
36cfb7
+	ret = get_u8(&val, str, 10);
36cfb7
+	if (ret)
36cfb7
+		ret = get_u8(&val, str, 16);
36cfb7
+	if (ret)
36cfb7
+		return -1;
36cfb7
+
36cfb7
+	addattr8(n, MAX_MSG, type, val);
36cfb7
+
36cfb7
+	return 0;
36cfb7
+}
36cfb7
+
36cfb7
 static int parse_tunnel_key(struct action_util *a, int *argc_p, char ***argv_p,
36cfb7
 			    int tca_id, struct nlmsghdr *n)
36cfb7
 {
36cfb7
@@ -154,6 +170,22 @@ static int parse_tunnel_key(struct action_util *a, int *argc_p, char ***argv_p,
36cfb7
 				fprintf(stderr, "Illegal \"dst port\"\n");
36cfb7
 				return -1;
36cfb7
 			}
36cfb7
+		} else if (matches(*argv, "tos") == 0) {
36cfb7
+			NEXT_ARG();
36cfb7
+			ret = tunnel_key_parse_tos_ttl(*argv,
36cfb7
+							TCA_TUNNEL_KEY_ENC_TOS, n);
36cfb7
+			if (ret < 0) {
36cfb7
+				fprintf(stderr, "Illegal \"tos\"\n");
36cfb7
+				return -1;
36cfb7
+			}
36cfb7
+		} else if (matches(*argv, "ttl") == 0) {
36cfb7
+			NEXT_ARG();
36cfb7
+			ret = tunnel_key_parse_tos_ttl(*argv,
36cfb7
+							TCA_TUNNEL_KEY_ENC_TTL, n);
36cfb7
+			if (ret < 0) {
36cfb7
+				fprintf(stderr, "Illegal \"ttl\"\n");
36cfb7
+				return -1;
36cfb7
+			}
36cfb7
 		} else if (matches(*argv, "help") == 0) {
36cfb7
 			usage();
36cfb7
 		} else {
36cfb7
@@ -231,6 +263,19 @@ static void tunnel_key_print_dst_port(FILE *f, char *name,
36cfb7
 	fprintf(f, "\n\t%s %d", name, rta_getattr_be16(attr));
36cfb7
 }
36cfb7
 
36cfb7
+static void tunnel_key_print_tos_ttl(FILE *f, char *name,
36cfb7
+				     struct rtattr *attr)
36cfb7
+{
36cfb7
+	if (!attr)
36cfb7
+		return;
36cfb7
+
36cfb7
+	if (matches(name, "tos") == 0 && rta_getattr_u8(attr) != 0) {
36cfb7
+		fprintf(f, "\n\t%s 0x%x", name, rta_getattr_u8(attr));
36cfb7
+	} else if (matches(name, "ttl") == 0 && rta_getattr_u8(attr) != 0) {
36cfb7
+		fprintf(f, "\n\t%s %u", name, rta_getattr_u8(attr));
36cfb7
+	}
36cfb7
+}
36cfb7
+
36cfb7
 static int print_tunnel_key(struct action_util *au, FILE *f, struct rtattr *arg)
36cfb7
 {
36cfb7
 	struct rtattr *tb[TCA_TUNNEL_KEY_MAX + 1];
36cfb7
@@ -267,6 +312,10 @@ static int print_tunnel_key(struct action_util *au, FILE *f, struct rtattr *arg)
36cfb7
 					tb[TCA_TUNNEL_KEY_ENC_KEY_ID]);
36cfb7
 		tunnel_key_print_dst_port(f, "dst_port",
36cfb7
 					  tb[TCA_TUNNEL_KEY_ENC_DST_PORT]);
36cfb7
+		tunnel_key_print_tos_ttl(f, "tos",
36cfb7
+					  tb[TCA_TUNNEL_KEY_ENC_TOS]);
36cfb7
+		tunnel_key_print_tos_ttl(f, "ttl",
36cfb7
+					  tb[TCA_TUNNEL_KEY_ENC_TTL]);
36cfb7
 		break;
36cfb7
 	}
36cfb7
 	fprintf(f, " %s", action_n2a(parm->action));
36cfb7
-- 
e138d9
2.21.0
36cfb7