]> git.proxmox.com Git - mirror_iproute2.git/blob - ip/link_veth.c
rdma: Properly mark RDMAtool license
[mirror_iproute2.git] / ip / link_veth.c
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 #include <net/if.h>
15 #include <linux/veth.h>
16
17 #include "utils.h"
18 #include "ip_common.h"
19
20 static void print_usage(FILE *f)
21 {
22 printf("Usage: ip link <options> type veth [peer <options>]\n"
23 "To get <options> type 'ip link add help'\n");
24 }
25
26 static void usage(void)
27 {
28 print_usage(stderr);
29 }
30
31 static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
32 struct nlmsghdr *n)
33 {
34 char *type = NULL;
35 int err;
36 struct rtattr *data;
37 struct ifinfomsg *ifm, *peer_ifm;
38 unsigned int ifi_flags, ifi_change, ifi_index;
39
40 if (strcmp(argv[0], "peer") != 0) {
41 usage();
42 return -1;
43 }
44
45 ifm = NLMSG_DATA(n);
46 ifi_flags = ifm->ifi_flags;
47 ifi_change = ifm->ifi_change;
48 ifi_index = ifm->ifi_index;
49 ifm->ifi_flags = 0;
50 ifm->ifi_change = 0;
51 ifm->ifi_index = 0;
52
53 data = addattr_nest(n, 1024, VETH_INFO_PEER);
54
55 n->nlmsg_len += sizeof(struct ifinfomsg);
56
57 err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)n, &type);
58 if (err < 0)
59 return err;
60
61 if (type)
62 duparg("type", argv[err]);
63
64 peer_ifm = RTA_DATA(data);
65 peer_ifm->ifi_index = ifm->ifi_index;
66 peer_ifm->ifi_flags = ifm->ifi_flags;
67 peer_ifm->ifi_change = ifm->ifi_change;
68 ifm->ifi_flags = ifi_flags;
69 ifm->ifi_change = ifi_change;
70 ifm->ifi_index = ifi_index;
71
72 addattr_nest_end(n, data);
73 return argc - 1 - err;
74 }
75
76 static void veth_print_help(struct link_util *lu, int argc, char **argv,
77 FILE *f)
78 {
79 print_usage(f);
80 }
81
82 struct link_util veth_link_util = {
83 .id = "veth",
84 .parse_opt = veth_parse_opt,
85 .print_help = veth_print_help,
86 };