aboutsummaryrefslogtreecommitdiffstats
path: root/ip/link_veth.c
diff options
context:
space:
mode:
authorVitaliy Gusev <vgusev@openvz.org>2007-12-18 15:15:38 +0300
committerStephen Hemminger <shemminger@linux-foundation.org>2007-12-21 09:24:12 -0800
commitf9329ccaf933a9dee5760de6979c7be6f17e253f (patch)
tree94e86ddb645a5ecad8ea760126417300f4f8e283 /ip/link_veth.c
parent909dfe2c7ebcfe853b2fe4f995be1c4681d5a2a5 (diff)
downloadplatform_external_iproute2-f9329ccaf933a9dee5760de6979c7be6f17e253f.tar.gz
platform_external_iproute2-f9329ccaf933a9dee5760de6979c7be6f17e253f.tar.bz2
platform_external_iproute2-f9329ccaf933a9dee5760de6979c7be6f17e253f.zip
veth device link management
Signed-off-by: Vitaliy Gusev <vgusev@openvz.org> Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Diffstat (limited to 'ip/link_veth.c')
-rw-r--r--ip/link_veth.c76
1 files changed, 25 insertions, 51 deletions
diff --git a/ip/link_veth.c b/ip/link_veth.c
index a4764f2e..226b4ef4 100644
--- a/ip/link_veth.c
+++ b/ip/link_veth.c
@@ -10,78 +10,52 @@
*
*/
-#include <stdio.h>
#include <string.h>
#include "utils.h"
#include "ip_common.h"
#include "veth.h"
-#define ETH_ALEN 6
+#define IFNAMSIZ 16
static void usage(void)
{
- printf("Usage: ip link add ... type veth "
- "[peer <peer-name>] [mac <mac>] [peer_mac <mac>]\n");
+ printf("Usage: ip link <options> type veth "
+ "[peer <options>]\nTo get <options> type "
+ "'ip link add help'\n");
}
static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
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, "peer") == 0) {
- argv++;
- argc--;
- if (argc == 0) {
- usage();
- return -1;
- }
-
- addattr_l(hdr, 1024, VETH_INFO_PEER,
- *argv, strlen(*argv));
-
- continue;
- }
-
- 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[0], "peer") != 0) {
+ usage();
+ return -1;
+ }
- if (strcmp(*argv, "peer_mac") == 0) {
- argv++;
- argc--;
- if (argc == 0) {
- usage();
- return -1;
- }
+ data = NLMSG_TAIL(hdr);
+ addattr_l(hdr, 1024, VETH_INFO_PEER, NULL, 0);
- if (hexstring_a2n(*argv, mac, sizeof(mac)) == NULL)
- return -1;
+ hdr->nlmsg_len += sizeof(struct ifinfomsg);
- addattr_l(hdr, 1024, VETH_INFO_PEER_MAC,
- mac, ETH_ALEN);
- continue;
- }
+ err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)hdr,
+ &name, &type, &link, &dev);
+ if (err < 0)
+ return err;
- usage();
- return -1;
+ if (name) {
+ len = strlen(name) + 1;
+ if (len > IFNAMSIZ)
+ invarg("\"name\" too long\n", *argv);
+ addattr_l(hdr, 1024, IFLA_IFNAME, name, len);
}
- return 0;
+ data->rta_len = (void *)NLMSG_TAIL(hdr) - (void *)data;
+ return argc - 1 - err;
}
struct link_util veth_link_util = {