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