]> git.proxmox.com Git - mirror_iproute2.git/blame - ip/link_veth.c
iplink: Follow documented behaviour when "index" is given
[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 14#include <net/if.h>
118c923c 15#include <linux/veth.h>
2da55b1b
PE
16
17#include "utils.h"
18#include "ip_common.h"
2da55b1b 19
561e650e 20static void print_usage(FILE *f)
2da55b1b 21{
ac3ff720
SH
22 printf("Usage: ip link <options> type veth [peer <options>]\n"
23 "To get <options> type 'ip link add help'\n");
2da55b1b
PE
24}
25
561e650e 26static void usage(void)
27{
28 print_usage(stderr);
29}
30
2da55b1b 31static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
28254695 32 struct nlmsghdr *n)
2da55b1b 33{
be2c3142
SH
34 char *dev = NULL;
35 char *name = NULL;
36 char *link = NULL;
37 char *type = NULL;
5e25cf77 38 int index = 0;
dac9ff35 39 int err;
56f5daac 40 struct rtattr *data;
db02608b 41 int group;
18917544
KK
42 struct ifinfomsg *ifm, *peer_ifm;
43 unsigned int ifi_flags, ifi_change;
2da55b1b 44
f9329cca
VG
45 if (strcmp(argv[0], "peer") != 0) {
46 usage();
47 return -1;
48 }
2da55b1b 49
28254695 50 ifm = NLMSG_DATA(n);
18917544
KK
51 ifi_flags = ifm->ifi_flags;
52 ifi_change = ifm->ifi_change;
53 ifm->ifi_flags = 0;
54 ifm->ifi_change = 0;
55
c14f9d92 56 data = addattr_nest(n, 1024, VETH_INFO_PEER);
2da55b1b 57
28254695 58 n->nlmsg_len += sizeof(struct ifinfomsg);
2da55b1b 59
28254695 60 err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)n,
5e25cf77 61 &name, &type, &link, &dev, &group, &index);
f9329cca
VG
62 if (err < 0)
63 return err;
2da55b1b 64
8c0b19d1
SP
65 if (type)
66 duparg("type", argv[err]);
67
f9329cca 68 if (name) {
28254695 69 addattr_l(n, 1024,
dac9ff35 70 IFLA_IFNAME, name, strlen(name) + 1);
2da55b1b
PE
71 }
72
18917544
KK
73 peer_ifm = RTA_DATA(data);
74 peer_ifm->ifi_index = index;
75 peer_ifm->ifi_flags = ifm->ifi_flags;
76 peer_ifm->ifi_change = ifm->ifi_change;
77 ifm->ifi_flags = ifi_flags;
78 ifm->ifi_change = ifi_change;
5e25cf77 79
e0d47aa3 80 if (group != -1)
28254695 81 addattr32(n, 1024, IFLA_GROUP, group);
e0d47aa3 82
c14f9d92 83 addattr_nest_end(n, data);
f9329cca 84 return argc - 1 - err;
2da55b1b
PE
85}
86
561e650e 87static void veth_print_help(struct link_util *lu, int argc, char **argv,
88 FILE *f)
89{
90 print_usage(f);
91}
92
2da55b1b
PE
93struct link_util veth_link_util = {
94 .id = "veth",
95 .parse_opt = veth_parse_opt,
561e650e 96 .print_help = veth_print_help,
2da55b1b 97};