]> git.proxmox.com Git - mirror_iproute2.git/blame - ip/link_veth.c
snapshot target
[mirror_iproute2.git] / ip / link_veth.c
CommitLineData
2da55b1b
PE
1/*
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
13#include <string.h>
c595fda5
SH
14#include <net/if.h>
15#include <net/veth.h>
2da55b1b
PE
16
17#include "utils.h"
18#include "ip_common.h"
2da55b1b
PE
19
20static void usage(void)
21{
f9329cca 22 printf("Usage: ip link <options> type veth "
c595fda5
SH
23 "[peer <options>]\nTo get <options> type "
24 "'ip link add help'\n");
2da55b1b
PE
25}
26
27static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
c595fda5 28 struct nlmsghdr *hdr)
2da55b1b 29{
f9329cca
VG
30 char *name, *type, *link, *dev;
31 int err, len;
32 struct rtattr * data;
2da55b1b 33
f9329cca
VG
34 if (strcmp(argv[0], "peer") != 0) {
35 usage();
36 return -1;
37 }
2da55b1b 38
f9329cca
VG
39 data = NLMSG_TAIL(hdr);
40 addattr_l(hdr, 1024, VETH_INFO_PEER, NULL, 0);
2da55b1b 41
f9329cca 42 hdr->nlmsg_len += sizeof(struct ifinfomsg);
2da55b1b 43
f9329cca 44 err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)hdr,
c595fda5 45 &name, &type, &link, &dev);
f9329cca
VG
46 if (err < 0)
47 return err;
2da55b1b 48
f9329cca
VG
49 if (name) {
50 len = strlen(name) + 1;
51 if (len > IFNAMSIZ)
52 invarg("\"name\" too long\n", *argv);
53 addattr_l(hdr, 1024, IFLA_IFNAME, name, len);
2da55b1b
PE
54 }
55
f9329cca
VG
56 data->rta_len = (void *)NLMSG_TAIL(hdr) - (void *)data;
57 return argc - 1 - err;
2da55b1b
PE
58}
59
60struct link_util veth_link_util = {
61 .id = "veth",
62 .parse_opt = veth_parse_opt,
63};