blob: 3d19b01fd9116029b2efb01d1f90183935778a18 [file] [log] [blame]
Pavel Emelianov2da55b12007-07-11 13:33:55 +04001/*
2 * link_veth.c veth driver module
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Pavel Emelianov <xemul@openvz.org>
10 *
11 */
12
Pavel Emelianov2da55b12007-07-11 13:33:55 +040013#include <string.h>
Stephen Hemmingerc595fda2007-12-21 09:37:30 -080014#include <net/if.h>
Stephen Hemminger118c9232007-12-25 12:38:08 -080015#include <linux/veth.h>
Pavel Emelianov2da55b12007-07-11 13:33:55 +040016
17#include "utils.h"
18#include "ip_common.h"
Pavel Emelianov2da55b12007-07-11 13:33:55 +040019
20static void usage(void)
21{
Vitaliy Gusevf9329cc2007-12-18 15:15:38 +030022 printf("Usage: ip link <options> type veth "
Stephen Hemmingerc595fda2007-12-21 09:37:30 -080023 "[peer <options>]\nTo get <options> type "
24 "'ip link add help'\n");
Pavel Emelianov2da55b12007-07-11 13:33:55 +040025}
26
27static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
Stephen Hemmingerc595fda2007-12-21 09:37:30 -080028 struct nlmsghdr *hdr)
Pavel Emelianov2da55b12007-07-11 13:33:55 +040029{
Vitaliy Gusevf9329cc2007-12-18 15:15:38 +030030 char *name, *type, *link, *dev;
31 int err, len;
32 struct rtattr * data;
Vlad Dogarudb026082011-02-02 20:23:41 +020033 int group;
Pavel Emelianov2da55b12007-07-11 13:33:55 +040034
Vitaliy Gusevf9329cc2007-12-18 15:15:38 +030035 if (strcmp(argv[0], "peer") != 0) {
Pavel Emelianov2da55b12007-07-11 13:33:55 +040036 usage();
37 return -1;
38 }
39
Vitaliy Gusevf9329cc2007-12-18 15:15:38 +030040 data = NLMSG_TAIL(hdr);
41 addattr_l(hdr, 1024, VETH_INFO_PEER, NULL, 0);
42
43 hdr->nlmsg_len += sizeof(struct ifinfomsg);
44
45 err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)hdr,
Vlad Dogarudb026082011-02-02 20:23:41 +020046 &name, &type, &link, &dev, &group);
Vitaliy Gusevf9329cc2007-12-18 15:15:38 +030047 if (err < 0)
48 return err;
49
50 if (name) {
51 len = strlen(name) + 1;
52 if (len > IFNAMSIZ)
53 invarg("\"name\" too long\n", *argv);
54 addattr_l(hdr, 1024, IFLA_IFNAME, name, len);
55 }
56
57 data->rta_len = (void *)NLMSG_TAIL(hdr) - (void *)data;
58 return argc - 1 - err;
Pavel Emelianov2da55b12007-07-11 13:33:55 +040059}
60
61struct link_util veth_link_util = {
62 .id = "veth",
63 .parse_opt = veth_parse_opt,
64};