mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-12-08 05:39:44 +00:00
vxlan: add ipv6 support
The kernel already supports it, so add the support to iproute2 as well. Cc: Stephen Hemminger <stephen@networkplumber.org> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
This commit is contained in:
parent
03ddbbd5ad
commit
aa574cd60e
@ -151,6 +151,7 @@ int print_timestamp(FILE *fp);
|
|||||||
extern int cmdlineno;
|
extern int cmdlineno;
|
||||||
extern ssize_t getcmdline(char **line, size_t *len, FILE *in);
|
extern ssize_t getcmdline(char **line, size_t *len, FILE *in);
|
||||||
extern int makeargs(char *line, char *argv[], int maxargs);
|
extern int makeargs(char *line, char *argv[], int maxargs);
|
||||||
|
extern int inet_get_addr(const char *src, __u32 *dst, struct in6_addr *dst6);
|
||||||
|
|
||||||
struct iplink_req;
|
struct iplink_req;
|
||||||
int iplink_parse(int argc, char **argv, struct iplink_req *req,
|
int iplink_parse(int argc, char **argv, struct iplink_req *req,
|
||||||
|
|||||||
@ -43,6 +43,9 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
|
|||||||
__u32 saddr = 0;
|
__u32 saddr = 0;
|
||||||
__u32 gaddr = 0;
|
__u32 gaddr = 0;
|
||||||
__u32 daddr = 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;
|
unsigned link = 0;
|
||||||
__u8 tos = 0;
|
__u8 tos = 0;
|
||||||
__u8 ttl = 0;
|
__u8 ttl = 0;
|
||||||
@ -66,21 +69,30 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
|
|||||||
vni_set = 1;
|
vni_set = 1;
|
||||||
} else if (!matches(*argv, "group")) {
|
} else if (!matches(*argv, "group")) {
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
gaddr = get_addr32(*argv);
|
if (!inet_get_addr(*argv, &gaddr, &gaddr6)) {
|
||||||
|
fprintf(stderr, "Invalid address \"%s\"\n", *argv);
|
||||||
if (!IN_MULTICAST(ntohl(gaddr)))
|
return -1;
|
||||||
|
}
|
||||||
|
if (!IN6_IS_ADDR_MULTICAST(&gaddr6) && !IN_MULTICAST(ntohl(gaddr)))
|
||||||
invarg("invalid group address", *argv);
|
invarg("invalid group address", *argv);
|
||||||
} else if (!matches(*argv, "remote")) {
|
} else if (!matches(*argv, "remote")) {
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
daddr = get_addr32(*argv);
|
if (!inet_get_addr(*argv, &daddr, &daddr6)) {
|
||||||
|
fprintf(stderr, "Invalid address \"%s\"\n", *argv);
|
||||||
if (IN_MULTICAST(ntohl(daddr)))
|
return -1;
|
||||||
|
}
|
||||||
|
if (IN6_IS_ADDR_MULTICAST(&daddr6) || IN_MULTICAST(ntohl(daddr)))
|
||||||
invarg("invalid remote address", *argv);
|
invarg("invalid remote address", *argv);
|
||||||
} else if (!matches(*argv, "local")) {
|
} else if (!matches(*argv, "local")) {
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
if (strcmp(*argv, "any"))
|
if (strcmp(*argv, "any")) {
|
||||||
saddr = get_addr32(*argv);
|
if (!inet_get_addr(*argv, &saddr, &saddr6)) {
|
||||||
if (IN_MULTICAST(ntohl(saddr)))
|
fprintf(stderr, "Invalid address \"%s\"\n", *argv);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IN_MULTICAST(ntohl(saddr)) || IN6_IS_ADDR_MULTICAST(&saddr6))
|
||||||
invarg("invalid local address", *argv);
|
invarg("invalid local address", *argv);
|
||||||
} else if (!matches(*argv, "dev")) {
|
} else if (!matches(*argv, "dev")) {
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
@ -167,7 +179,9 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
|
|||||||
fprintf(stderr, "vxlan: missing virtual network identifier\n");
|
fprintf(stderr, "vxlan: missing virtual network identifier\n");
|
||||||
return -1;
|
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");
|
fprintf(stderr, "vxlan: both group and remote cannot be specified\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -176,8 +190,16 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
|
|||||||
addattr_l(n, 1024, IFLA_VXLAN_GROUP, &gaddr, 4);
|
addattr_l(n, 1024, IFLA_VXLAN_GROUP, &gaddr, 4);
|
||||||
else if (daddr)
|
else if (daddr)
|
||||||
addattr_l(n, 1024, IFLA_VXLAN_GROUP, &daddr, 4);
|
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)
|
if (saddr)
|
||||||
addattr_l(n, 1024, IFLA_VXLAN_LOCAL, &saddr, 4);
|
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)
|
if (link)
|
||||||
addattr32(n, 1024, IFLA_VXLAN_LINK, link);
|
addattr32(n, 1024, IFLA_VXLAN_LINK, link);
|
||||||
addattr8(n, 1024, IFLA_VXLAN_TTL, ttl);
|
addattr8(n, 1024, IFLA_VXLAN_TTL, ttl);
|
||||||
@ -229,6 +251,17 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
|||||||
fprintf(f, "remote %s ",
|
fprintf(f, "remote %s ",
|
||||||
format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
|
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]) {
|
if (tb[IFLA_VXLAN_LOCAL]) {
|
||||||
@ -236,6 +269,12 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
|||||||
if (addr)
|
if (addr)
|
||||||
fprintf(f, "local %s ",
|
fprintf(f, "local %s ",
|
||||||
format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
|
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] &&
|
if (tb[IFLA_VXLAN_LINK] &&
|
||||||
|
|||||||
@ -868,3 +868,11 @@ int makeargs(char *line, char *argv[], int maxargs)
|
|||||||
|
|
||||||
return argc;
|
return argc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int inet_get_addr(const char *src, __u32 *dst, struct in6_addr *dst6)
|
||||||
|
{
|
||||||
|
if (strchr(src, ':'))
|
||||||
|
return inet_pton(AF_INET6, src, dst6);
|
||||||
|
else
|
||||||
|
return inet_pton(AF_INET, src, dst);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user