From patchwork Sat Sep 21 02:35:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amerigo Wang X-Patchwork-Id: 276833 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 582382C01A2 for ; Sat, 21 Sep 2013 12:35:39 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752132Ab3IUCfe (ORCPT ); Fri, 20 Sep 2013 22:35:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10916 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751927Ab3IUCfd (ORCPT ); Fri, 20 Sep 2013 22:35:33 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8L2ZVHT020422 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 20 Sep 2013 22:35:31 -0400 Received: from localhost.localdomain (vpn1-114-163.nay.redhat.com [10.66.114.163]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r8L2ZSdI001917; Fri, 20 Sep 2013 22:35:29 -0400 From: Cong Wang To: netdev@vger.kernel.org Cc: "David S. Miller" , Cong Wang , Stephen Hemminger Subject: [RESEND PATCH iproute2] vxlan: add ipv6 support Date: Sat, 21 Sep 2013 10:35:24 +0800 Message-Id: <1379730924-12433-1-git-send-email-amwang@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Cong Wang The kernel already supports it, so add the support to iproute2 as well. Cc: Stephen Hemminger Signed-off-by: Cong Wang --- include/linux/if_link.h | 2 + ip/iplink_vxlan.c | 69 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 59 insertions(+), 12 deletions(-) diff --git a/include/linux/if_link.h b/include/linux/if_link.h index d07aeca..0c37561 100644 --- a/include/linux/if_link.h +++ b/include/linux/if_link.h @@ -311,6 +311,8 @@ enum { IFLA_VXLAN_L2MISS, IFLA_VXLAN_L3MISS, IFLA_VXLAN_PORT, /* destination port */ + IFLA_VXLAN_GROUP6, + IFLA_VXLAN_LOCAL6, __IFLA_VXLAN_MAX }; #define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1) diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c index 4304b0d..12e1c74 100644 --- a/ip/iplink_vxlan.c +++ b/ip/iplink_vxlan.c @@ -43,6 +43,9 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, __u32 saddr = 0; __u32 gaddr = 0; __u32 daddr = 0; + struct in6_addr saddr6 = IN6ADDR_ANY_INIT; + struct in6_addr gaddr6 = IN6ADDR_ANY_INIT; + struct in6_addr daddr6 = IN6ADDR_ANY_INIT; unsigned link = 0; __u8 tos = 0; __u8 ttl = 0; @@ -66,21 +69,36 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, vni_set = 1; } else if (!matches(*argv, "group")) { NEXT_ARG(); - gaddr = get_addr32(*argv); - - if (!IN_MULTICAST(ntohl(gaddr))) - invarg("invalid group address", *argv); + if (!inet_pton(AF_INET, *argv, &gaddr)) { + if (!inet_pton(AF_INET6, *argv, &gaddr6)) { + fprintf(stderr, "Invalid address \"%s\"\n", *argv); + return -1; + } else if (!IN6_IS_ADDR_MULTICAST(&gaddr6)) + invarg("invald group address", *argv); + } else if (!IN_MULTICAST(ntohl(gaddr))) + invarg("invald group address", *argv); } else if (!matches(*argv, "remote")) { NEXT_ARG(); - daddr = get_addr32(*argv); - - if (IN_MULTICAST(ntohl(daddr))) - invarg("invalid remote address", *argv); + if (!inet_pton(AF_INET, *argv, &daddr)) { + if (!inet_pton(AF_INET6, *argv, &daddr6)) { + fprintf(stderr, "Invalid address \"%s\"\n", *argv); + return -1; + } else if (IN6_IS_ADDR_MULTICAST(&daddr6)) + invarg("invald remote address", *argv); + } else if (IN_MULTICAST(ntohl(daddr))) + invarg("invald remote address", *argv); } else if (!matches(*argv, "local")) { NEXT_ARG(); - if (strcmp(*argv, "any")) - saddr = get_addr32(*argv); - if (IN_MULTICAST(ntohl(saddr))) + if (strcmp(*argv, "any")) { + if (!inet_pton(AF_INET, *argv, &saddr)) { + if (!inet_pton(AF_INET6, *argv, &saddr6)) { + fprintf(stderr, "Invalid address \"%s\"\n", *argv); + return -1; + } + } + } + + if (IN_MULTICAST(ntohl(saddr)) || IN6_IS_ADDR_MULTICAST(&saddr6)) invarg("invalid local address", *argv); } else if (!matches(*argv, "dev")) { NEXT_ARG(); @@ -167,7 +185,9 @@ 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) { + if ((gaddr && daddr) || + (memcmp(&gaddr6, &in6addr_any, sizeof(gaddr6)) && + memcmp(&daddr6, &in6addr_any, sizeof(daddr6)))) { fprintf(stderr, "vxlan: both group and remote cannot be specified\n"); return -1; } @@ -176,8 +196,16 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, addattr_l(n, 1024, IFLA_VXLAN_GROUP, &gaddr, 4); else if (daddr) addattr_l(n, 1024, IFLA_VXLAN_GROUP, &daddr, 4); + if (memcmp(&gaddr6, &in6addr_any, sizeof(gaddr6)) != 0) + addattr_l(n, 1024, IFLA_VXLAN_GROUP6, &gaddr6, sizeof(struct in6_addr)); + else if (memcmp(&daddr6, &in6addr_any, sizeof(daddr6)) != 0) + addattr_l(n, 1024, IFLA_VXLAN_GROUP6, &daddr6, sizeof(struct in6_addr)); + if (saddr) addattr_l(n, 1024, IFLA_VXLAN_LOCAL, &saddr, 4); + else if (memcmp(&saddr6, &in6addr_any, sizeof(saddr6)) != 0) + addattr_l(n, 1024, IFLA_VXLAN_LOCAL6, &saddr6, sizeof(struct in6_addr)); + if (link) addattr32(n, 1024, IFLA_VXLAN_LINK, link); addattr8(n, 1024, IFLA_VXLAN_TTL, ttl); @@ -229,6 +257,17 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) fprintf(f, "remote %s ", format_host(AF_INET, 4, &addr, s1, sizeof(s1))); } + } else if (tb[IFLA_VXLAN_GROUP6]) { + struct in6_addr addr; + memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_GROUP6]), sizeof(struct in6_addr)); + if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) { + if (IN6_IS_ADDR_MULTICAST(&addr)) + fprintf(f, "group %s ", + format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1))); + else + fprintf(f, "remote %s ", + format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1))); + } } if (tb[IFLA_VXLAN_LOCAL]) { @@ -236,6 +275,12 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) if (addr) fprintf(f, "local %s ", format_host(AF_INET, 4, &addr, s1, sizeof(s1))); + } else if (tb[IFLA_VXLAN_LOCAL6]) { + struct in6_addr addr; + memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_LOCAL6]), sizeof(struct in6_addr)); + if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) + fprintf(f, "local %s ", + format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1))); } if (tb[IFLA_VXLAN_LINK] &&