diff mbox

[iproute2,v3] vxlan: Allow setting destination to unicast address.

Message ID 87fvywm7ya.wl%atzm@stratosphere.co.jp
State Awaiting Upstream, archived
Delegated to: stephen hemminger
Headers show

Commit Message

Atzm Watanabe April 12, 2013, 9:09 a.m. UTC
This patch allows setting VXLAN destination to unicast address.
It allows that VXLAN can be used as peer-to-peer tunnel without
multicast.

v3: move a new attribute REMOTE into the last of an enum list
    based by Stephen Hemminger's comments.
    fix the usage to show explicitly that both "remote" and "group"
    cannot be specified, based by Ben Hutchings's comments.

v2: use a new argument "remote" instead of "group" based by
    Stephen Hemminger's comments.

Signed-off-by: Atzm Watanabe <atzm@stratosphere.co.jp>
---
 include/linux/if_link.h |  1 +
 ip/iplink_vxlan.c       | 25 +++++++++++++++++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/include/linux/if_link.h b/include/linux/if_link.h
index 40167af..3a7f7b9 100644
--- a/include/linux/if_link.h
+++ b/include/linux/if_link.h
@@ -306,6 +306,7 @@  enum {
 	IFLA_VXLAN_RSC,
 	IFLA_VXLAN_L2MISS,
 	IFLA_VXLAN_L3MISS,
+	IFLA_VXLAN_REMOTE,
 	__IFLA_VXLAN_MAX
 };
 #define IFLA_VXLAN_MAX	(__IFLA_VXLAN_MAX - 1)
diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c
index 1025326..52a2c6b 100644
--- a/ip/iplink_vxlan.c
+++ b/ip/iplink_vxlan.c
@@ -23,7 +23,8 @@ 
 
 static void explain(void)
 {
-	fprintf(stderr, "Usage: ... vxlan id VNI [ group ADDR ] [ local ADDR ]\n");
+	fprintf(stderr, "Usage: ... vxlan id VNI [ { group | remote } ADDR ]\n");
+	fprintf(stderr, "                 [ local ADDR ]\n");
 	fprintf(stderr, "                 [ ttl TTL ] [ tos TOS ] [ dev PHYS_DEV ]\n");
 	fprintf(stderr, "                 [ port MIN MAX ] [ [no]learning ]\n");
 	fprintf(stderr, "                 [ [no]proxy ] [ [no]rsc ]\n");
@@ -41,6 +42,7 @@  static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
 	__u32 vni = 0;
 	int vni_set = 0;
 	__u32 saddr = 0;
+	__u32 daddr = 0;
 	__u32 gaddr = 0;
 	unsigned link = 0;
 	__u8 tos = 0;
@@ -68,7 +70,13 @@  static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
 			gaddr = get_addr32(*argv);
 
 			if (!IN_MULTICAST(ntohl(gaddr)))
-				invarg("invald group address", *argv);
+				invarg("invalid group address", *argv);
+		} else if (!matches(*argv, "remote")) {
+			NEXT_ARG();
+			daddr = get_addr32(*argv);
+
+			if (IN_MULTICAST(ntohl(daddr)))
+				invarg("invalid remote address", *argv);
 		} else if (!matches(*argv, "local")) {
 			NEXT_ARG();
 			if (strcmp(*argv, "any"))
@@ -160,9 +168,15 @@  static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
 		fprintf(stderr, "vxlan: missing virtual network identifier\n");
 		return -1;
 	}
+	if (gaddr && daddr) {
+		fprintf(stderr, "vxlan: both group and remote cannot be specified\n");
+		return -1;
+	}
 	addattr32(n, 1024, IFLA_VXLAN_ID, vni);
 	if (gaddr)
 		addattr_l(n, 1024, IFLA_VXLAN_GROUP, &gaddr, 4);
+	else if (daddr)
+		addattr_l(n, 1024, IFLA_VXLAN_REMOTE, &daddr, 4);
 	if (saddr)
 		addattr_l(n, 1024, IFLA_VXLAN_LOCAL, &saddr, 4);
 	if (link)
@@ -213,6 +227,13 @@  static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 				format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
 	}
 
+	if (tb[IFLA_VXLAN_REMOTE]) {
+		__be32 addr = rta_getattr_u32(tb[IFLA_VXLAN_REMOTE]);
+		if (addr)
+			fprintf(f, "remote %s ",
+				format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
+	}
+
 	if (tb[IFLA_VXLAN_LOCAL]) {
 		__be32 addr = rta_getattr_u32(tb[IFLA_VXLAN_LOCAL]);
 		if (addr)