naccyde / rpms / iproute

Forked from rpms/iproute 5 months ago
Clone

Blame SOURCES/0166-geneve-add-support-for-lwt-tunnel-creation-and-dst-p.patch

049c96
From ce4a302b676ce7e47237c4c20b3c1c3b3721ed3e Mon Sep 17 00:00:00 2001
049c96
From: Phil Sutter <psutter@redhat.com>
049c96
Date: Sat, 2 Jul 2016 12:46:03 +0200
049c96
Subject: [PATCH] geneve: add support for lwt tunnel creation and dst port
049c96
 selection
049c96
049c96
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1339178
049c96
Upstream Status: iproute2.git commit 9450c5ec63b0c
049c96
049c96
commit 9450c5ec63b0cc4068b363eae7c71b024fc25121
049c96
Author: Paolo Abeni <pabeni@redhat.com>
049c96
Date:   Thu Jan 28 14:48:55 2016 +0100
049c96
049c96
    geneve: add support for lwt tunnel creation and dst port selection
049c96
049c96
    This change add the ability to create lwt/flow based/externally
049c96
    controlled geneve device and to select the udp destination port used
049c96
    by a full geneve tunnel.
049c96
049c96
    Signed-off-by: Paolo Abeni <pabeni@redhat.com>
049c96
---
049c96
 ip/iplink_geneve.c | 41 ++++++++++++++++++++++++++++++++++++-----
049c96
 1 file changed, 36 insertions(+), 5 deletions(-)
049c96
049c96
diff --git a/ip/iplink_geneve.c b/ip/iplink_geneve.c
049c96
index 1345479..30b16b9 100644
049c96
--- a/ip/iplink_geneve.c
049c96
+++ b/ip/iplink_geneve.c
049c96
@@ -19,6 +19,7 @@ static void print_explain(FILE *f)
049c96
 {
049c96
 	fprintf(f, "Usage: ... geneve id VNI remote ADDR\n");
049c96
 	fprintf(f, "                 [ ttl TTL ] [ tos TOS ]\n");
049c96
+	fprintf(f, "                 [ dstport PORT ] [ [no]external ]\n");
049c96
 	fprintf(f, "\n");
049c96
 	fprintf(f, "Where: VNI  := 0-16777215\n");
049c96
 	fprintf(f, "       ADDR := IP_ADDRESS\n");
049c96
@@ -40,6 +41,8 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
049c96
 	struct in6_addr daddr6 = IN6ADDR_ANY_INIT;
049c96
 	__u8 ttl = 0;
049c96
 	__u8 tos = 0;
049c96
+	__u16 dstport = 0;
049c96
+	bool metadata = 0;
049c96
 
049c96
 	while (argc > 0) {
049c96
 		if (!matches(*argv, "id") ||
049c96
@@ -80,6 +83,14 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
049c96
 				tos = uval;
049c96
 			} else
049c96
 				tos = 1;
049c96
+		} else if (!matches(*argv, "dstport")) {
049c96
+			NEXT_ARG();
049c96
+			if (get_u16(&dstport, *argv, 0))
049c96
+				invarg("dstport", *argv);
049c96
+		} else if (!matches(*argv, "external")) {
049c96
+			metadata = true;
049c96
+		} else if (!matches(*argv, "noexternal")) {
049c96
+			metadata = false;
049c96
 		} else if (matches(*argv, "help") == 0) {
049c96
 			explain();
049c96
 			return -1;
049c96
@@ -91,14 +102,22 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
049c96
 		argc--, argv++;
049c96
 	}
049c96
 
049c96
-	if (!vni_set) {
049c96
-		fprintf(stderr, "geneve: missing virtual network identifier\n");
049c96
+	if (metadata && vni_set) {
049c96
+		fprintf(stderr, "geneve: both 'external' and vni cannot be specified\n");
049c96
 		return -1;
049c96
 	}
049c96
 
049c96
-	if (!daddr && memcmp(&daddr6, &in6addr_any, sizeof(daddr6)) == 0) {
049c96
-		fprintf(stderr, "geneve: remote link partner not specified\n");
049c96
-		return -1;
049c96
+	if (!metadata) {
049c96
+		/* parameter checking make sense only for full geneve tunnels */
049c96
+		if (!vni_set) {
049c96
+			fprintf(stderr, "geneve: missing virtual network identifier\n");
049c96
+			return -1;
049c96
+		}
049c96
+
049c96
+		if (!daddr && memcmp(&daddr6, &in6addr_any, sizeof(daddr6)) == 0) {
049c96
+			fprintf(stderr, "geneve: remote link partner not specified\n");
049c96
+			return -1;
049c96
+		}
049c96
 	}
049c96
 
049c96
 	addattr32(n, 1024, IFLA_GENEVE_ID, vni);
049c96
@@ -108,6 +127,10 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
049c96
 		addattr_l(n, 1024, IFLA_GENEVE_REMOTE6, &daddr6, sizeof(struct in6_addr));
049c96
 	addattr8(n, 1024, IFLA_GENEVE_TTL, ttl);
049c96
 	addattr8(n, 1024, IFLA_GENEVE_TOS, tos);
049c96
+	if (dstport)
049c96
+		addattr16(n, 1024, IFLA_GENEVE_PORT, htons(dstport));
049c96
+	if (metadata)
049c96
+		addattr(n, 1024, IFLA_GENEVE_COLLECT_METADATA);
049c96
 
049c96
 	return 0;
049c96
 }
049c96
@@ -156,6 +179,14 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
049c96
 		else
049c96
 			fprintf(f, "tos %#x ", tos);
049c96
 	}
049c96
+
049c96
+	if (tb[IFLA_GENEVE_PORT])
049c96
+		fprintf(f, "dstport %u ",
049c96
+			ntohs(rta_getattr_u16(tb[IFLA_GENEVE_PORT])));
049c96
+
049c96
+	if (tb[IFLA_GENEVE_COLLECT_METADATA])
049c96
+		fputs("external ", f);
049c96
+
049c96
 }
049c96
 
049c96
 static void geneve_print_help(struct link_util *lu, int argc, char **argv,
049c96
-- 
049c96
1.8.3.1
049c96