Blame SOURCES/iproute2-3.10.0-Add-IPv6-support-to-VXLAN.patch

7787e2
From 885f6dfe74abec4f29fe48433b5ad9f899f2defd Mon Sep 17 00:00:00 2001
7787e2
From: =?UTF-8?q?Petr=20=C5=A0abata?= <contyk@redhat.com>
7787e2
Date: Tue, 25 Feb 2014 16:36:10 +0100
7787e2
Subject: [PATCH 2/2] Add IPv6 support to VXLAN
7787e2
MIME-Version: 1.0
7787e2
Content-Type: text/plain; charset=UTF-8
7787e2
Content-Transfer-Encoding: 8bit
7787e2
7787e2
Signed-off-by: Petr Ĺ abata <contyk@redhat.com>
7787e2
---
7787e2
 include/utils.h   |  1 +
7787e2
 ip/iplink_vxlan.c | 59 +++++++++++++++++++++++++++++++++++++++++++++----------
7787e2
 lib/utils.c       |  8 ++++++++
7787e2
 3 files changed, 58 insertions(+), 10 deletions(-)
7787e2
7787e2
diff --git a/include/utils.h b/include/utils.h
7787e2
index 24ff19f..a3e310e 100644
7787e2
--- a/include/utils.h
7787e2
+++ b/include/utils.h
7787e2
@@ -151,6 +151,7 @@ int print_timestamp(FILE *fp);
7787e2
 extern int cmdlineno;
7787e2
 extern ssize_t getcmdline(char **line, size_t *len, FILE *in);
7787e2
 extern int makeargs(char *line, char *argv[], int maxargs);
7787e2
+extern int inet_get_addr(const char *src, __u32 *dst, struct in6_addr *dst6);
7787e2
 
7787e2
 struct iplink_req;
7787e2
 int iplink_parse(int argc, char **argv, struct iplink_req *req,
7787e2
diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c
7787e2
index fdae6b1..81b8706 100644
7787e2
--- a/ip/iplink_vxlan.c
7787e2
+++ b/ip/iplink_vxlan.c
7787e2
@@ -43,6 +43,9 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
7787e2
 	__u32 saddr = 0;
7787e2
 	__u32 gaddr = 0;
7787e2
 	__u32 daddr = 0;
7787e2
+	struct in6_addr saddr6 = IN6ADDR_ANY_INIT;
7787e2
+	struct in6_addr gaddr6 = IN6ADDR_ANY_INIT;
7787e2
+	struct in6_addr daddr6 = IN6ADDR_ANY_INIT;
7787e2
 	unsigned link = 0;
7787e2
 	__u8 tos = 0;
7787e2
 	__u8 ttl = 0;
7787e2
@@ -68,21 +71,30 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
7787e2
 			vni_set = 1;
7787e2
 		} else if (!matches(*argv, "group")) {
7787e2
 			NEXT_ARG();
7787e2
-			gaddr = get_addr32(*argv);
7787e2
-
7787e2
-			if (!IN_MULTICAST(ntohl(gaddr)))
7787e2
+			if (!inet_get_addr(*argv, &gaddr, &gaddr6)) {
7787e2
+				fprintf(stderr, "Invalid address \"%s\"\n", *argv);
7787e2
+				return -1;
7787e2
+			}
7787e2
+			if (!IN6_IS_ADDR_MULTICAST(&gaddr6) && !IN_MULTICAST(ntohl(gaddr)))
7787e2
 				invarg("invalid group address", *argv);
7787e2
 		} else if (!matches(*argv, "remote")) {
7787e2
 			NEXT_ARG();
7787e2
-			daddr = get_addr32(*argv);
7787e2
-
7787e2
-			if (IN_MULTICAST(ntohl(daddr)))
7787e2
+			if (!inet_get_addr(*argv, &daddr, &daddr6)) {
7787e2
+				fprintf(stderr, "Invalid address \"%s\"\n", *argv);
7787e2
+				return -1;
7787e2
+			}
7787e2
+			if (IN6_IS_ADDR_MULTICAST(&daddr6) || IN_MULTICAST(ntohl(daddr)))
7787e2
 				invarg("invalid remote address", *argv);
7787e2
 		} else if (!matches(*argv, "local")) {
7787e2
 			NEXT_ARG();
7787e2
-			if (strcmp(*argv, "any"))
7787e2
-				saddr = get_addr32(*argv);
7787e2
-			if (IN_MULTICAST(ntohl(saddr)))
7787e2
+			if (strcmp(*argv, "any")) {
7787e2
+				if (!inet_get_addr(*argv, &saddr, &saddr6)) {
7787e2
+					fprintf(stderr, "Invalid address \"%s\"\n", *argv);
7787e2
+					return -1;
7787e2
+				}
7787e2
+			}
7787e2
+
7787e2
+			if (IN_MULTICAST(ntohl(saddr)) || IN6_IS_ADDR_MULTICAST(&saddr6))
7787e2
 				invarg("invalid local address", *argv);
7787e2
 		} else if (!matches(*argv, "dev")) {
7787e2
 			NEXT_ARG();
7787e2
@@ -183,7 +195,9 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
7787e2
 			"Use 'dstport 4789' to get the IANA assigned value\n"
7787e2
 			"Use 'dstport 0' to get default and quiet this message\n");
7787e2
 	}
7787e2
-	if (gaddr && daddr) {
7787e2
+	if ((gaddr && daddr) ||
7787e2
+		(memcmp(&gaddr6, &in6addr_any, sizeof(gaddr6)) &&
7787e2
+		 memcmp(&daddr6, &in6addr_any, sizeof(daddr6)))) {
7787e2
 		fprintf(stderr, "vxlan: both group and remote cannot be specified\n");
7787e2
 		return -1;
7787e2
 	}
7787e2
@@ -192,8 +206,16 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
7787e2
 		addattr_l(n, 1024, IFLA_VXLAN_GROUP, &gaddr, 4);
7787e2
 	else if (daddr)
7787e2
 		addattr_l(n, 1024, IFLA_VXLAN_GROUP, &daddr, 4);
7787e2
+	if (memcmp(&gaddr6, &in6addr_any, sizeof(gaddr6)) != 0)
7787e2
+		addattr_l(n, 1024, IFLA_VXLAN_GROUP6, &gaddr6, sizeof(struct in6_addr));
7787e2
+	else if (memcmp(&daddr6, &in6addr_any, sizeof(daddr6)) != 0)
7787e2
+		addattr_l(n, 1024, IFLA_VXLAN_GROUP6, &daddr6, sizeof(struct in6_addr));
7787e2
+
7787e2
 	if (saddr)
7787e2
 		addattr_l(n, 1024, IFLA_VXLAN_LOCAL, &saddr, 4);
7787e2
+	else if (memcmp(&saddr6, &in6addr_any, sizeof(saddr6)) != 0)
7787e2
+		addattr_l(n, 1024, IFLA_VXLAN_LOCAL6, &saddr6, sizeof(struct in6_addr));
7787e2
+
7787e2
 	if (link)
7787e2
 		addattr32(n, 1024, IFLA_VXLAN_LINK, link);
7787e2
 	addattr8(n, 1024, IFLA_VXLAN_TTL, ttl);
7787e2
@@ -248,6 +270,17 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
7787e2
 				fprintf(f, "remote %s ",
7787e2
 					format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
7787e2
 		}
7787e2
+	} else if (tb[IFLA_VXLAN_GROUP6]) {
7787e2
+		struct in6_addr addr;
7787e2
+		memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_GROUP6]), sizeof(struct in6_addr));
7787e2
+		if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) {
7787e2
+			if (IN6_IS_ADDR_MULTICAST(&addr))
7787e2
+				fprintf(f, "group %s ",
7787e2
+					format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1)));
7787e2
+			else
7787e2
+				fprintf(f, "remote %s ",
7787e2
+					format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1)));
7787e2
+		}
7787e2
 	}
7787e2
 
7787e2
 	if (tb[IFLA_VXLAN_LOCAL]) {
7787e2
@@ -255,6 +288,12 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
7787e2
 		if (addr)
7787e2
 			fprintf(f, "local %s ",
7787e2
 				format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
7787e2
+	} else if (tb[IFLA_VXLAN_LOCAL6]) {
7787e2
+		struct in6_addr addr;
7787e2
+		memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_LOCAL6]), sizeof(struct in6_addr));
7787e2
+		if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0)
7787e2
+			fprintf(f, "local %s ",
7787e2
+				format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1)));
7787e2
 	}
7787e2
 
7787e2
 	if (tb[IFLA_VXLAN_LINK] &&
7787e2
diff --git a/lib/utils.c b/lib/utils.c
7787e2
index 55fea18..1e12f85 100644
7787e2
--- a/lib/utils.c
7787e2
+++ b/lib/utils.c
7787e2
@@ -864,3 +864,11 @@ int makeargs(char *line, char *argv[], int maxargs)
7787e2
 
7787e2
 	return argc;
7787e2
 }
7787e2
+
7787e2
+int inet_get_addr(const char *src, __u32 *dst, struct in6_addr *dst6)
7787e2
+{
7787e2
+	if (strchr(src, ':'))
7787e2
+		return inet_pton(AF_INET6, src, dst6);
7787e2
+	else
7787e2
+		return inet_pton(AF_INET, src, dst);
7787e2
+}
7787e2
-- 
7787e2
1.8.5.3
7787e2
7787e2
diff --git a/include/linux/if_link.h b/include/linux/if_link.h
7787e2
index 965dc9f..b352b73 100644
7787e2
--- a/include/linux/if_link.h
7787e2
+++ b/include/linux/if_link.h
7787e2
@@ -309,6 +309,8 @@ enum {
7787e2
 	IFLA_VXLAN_L2MISS,
7787e2
 	IFLA_VXLAN_L3MISS,
7787e2
 	IFLA_VXLAN_PORT,	/* destination port */
7787e2
+	IFLA_VXLAN_GROUP6,
7787e2
+	IFLA_VXLAN_LOCAL6,
7787e2
 	__IFLA_VXLAN_MAX
7787e2
 };
7787e2
 #define IFLA_VXLAN_MAX	(__IFLA_VXLAN_MAX - 1)