Commit f9329cca authored by Vitaliy Gusev's avatar Vitaliy Gusev Committed by Stephen Hemminger

veth device link management

Signed-off-by: default avatarVitaliy Gusev <vgusev@openvz.org>
Signed-off-by: default avatarStephen Hemminger <shemminger@linux-foundation.org>
parent 909dfe2c
...@@ -10,78 +10,52 @@ ...@@ -10,78 +10,52 @@
* *
*/ */
#include <stdio.h>
#include <string.h> #include <string.h>
#include "utils.h" #include "utils.h"
#include "ip_common.h" #include "ip_common.h"
#include "veth.h" #include "veth.h"
#define ETH_ALEN 6 #define IFNAMSIZ 16
static void usage(void) static void usage(void)
{ {
printf("Usage: ip link add ... type veth " printf("Usage: ip link <options> type veth "
"[peer <peer-name>] [mac <mac>] [peer_mac <mac>]\n"); "[peer <options>]\nTo get <options> type "
"'ip link add help'\n");
} }
static int veth_parse_opt(struct link_util *lu, int argc, char **argv, static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *hdr) struct nlmsghdr *hdr)
{ {
__u8 mac[ETH_ALEN]; char *name, *type, *link, *dev;
int err, len;
struct rtattr * data;
for (; argc != 0; argv++, argc--) { if (strcmp(argv[0], "peer") != 0) {
if (strcmp(*argv, "peer") == 0) {
argv++;
argc--;
if (argc == 0) {
usage(); usage();
return -1; return -1;
} }
addattr_l(hdr, 1024, VETH_INFO_PEER, data = NLMSG_TAIL(hdr);
*argv, strlen(*argv)); addattr_l(hdr, 1024, VETH_INFO_PEER, NULL, 0);
continue; hdr->nlmsg_len += sizeof(struct ifinfomsg);
}
if (strcmp(*argv, "mac") == 0) {
argv++;
argc--;
if (argc == 0) {
usage();
return -1;
}
if (hexstring_a2n(*argv, mac, sizeof(mac)) == NULL)
return -1;
addattr_l(hdr, 1024, VETH_INFO_MAC,
mac, ETH_ALEN);
continue;
}
if (strcmp(*argv, "peer_mac") == 0) { err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)hdr,
argv++; &name, &type, &link, &dev);
argc--; if (err < 0)
if (argc == 0) { return err;
usage();
return -1;
}
if (hexstring_a2n(*argv, mac, sizeof(mac)) == NULL)
return -1;
addattr_l(hdr, 1024, VETH_INFO_PEER_MAC, if (name) {
mac, ETH_ALEN); len = strlen(name) + 1;
continue; if (len > IFNAMSIZ)
} invarg("\"name\" too long\n", *argv);
addattr_l(hdr, 1024, IFLA_IFNAME, name, len);
usage();
return -1;
} }
return 0; data->rta_len = (void *)NLMSG_TAIL(hdr) - (void *)data;
return argc - 1 - err;
} }
struct link_util veth_link_util = { struct link_util veth_link_util = {
......
...@@ -3,9 +3,7 @@ ...@@ -3,9 +3,7 @@
enum { enum {
VETH_INFO_UNSPEC, VETH_INFO_UNSPEC,
VETH_INFO_MAC,
VETH_INFO_PEER, VETH_INFO_PEER,
VETH_INFO_PEER_MAC,
__VETH_INFO_MAX __VETH_INFO_MAX
#define VETH_INFO_MAX (__VETH_INFO_MAX - 1) #define VETH_INFO_MAX (__VETH_INFO_MAX - 1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment