]> git.proxmox.com Git - mirror_iproute2.git/blame - ip/link_veth.c
ip: iptuntap: Convert to use print_on_off()
[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 34 char *type = NULL;
dac9ff35 35 int err;
56f5daac 36 struct rtattr *data;
18917544 37 struct ifinfomsg *ifm, *peer_ifm;
c58213f6 38 unsigned int ifi_flags, ifi_change, ifi_index;
2da55b1b 39
f9329cca
VG
40 if (strcmp(argv[0], "peer") != 0) {
41 usage();
42 return -1;
43 }
2da55b1b 44
28254695 45 ifm = NLMSG_DATA(n);
18917544
KK
46 ifi_flags = ifm->ifi_flags;
47 ifi_change = ifm->ifi_change;
c58213f6 48 ifi_index = ifm->ifi_index;
18917544
KK
49 ifm->ifi_flags = 0;
50 ifm->ifi_change = 0;
c58213f6 51 ifm->ifi_index = 0;
18917544 52
c14f9d92 53 data = addattr_nest(n, 1024, VETH_INFO_PEER);
2da55b1b 54
28254695 55 n->nlmsg_len += sizeof(struct ifinfomsg);
2da55b1b 56
c58213f6 57 err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)n, &type);
f9329cca
VG
58 if (err < 0)
59 return err;
2da55b1b 60
8c0b19d1
SP
61 if (type)
62 duparg("type", argv[err]);
63
18917544 64 peer_ifm = RTA_DATA(data);
c58213f6 65 peer_ifm->ifi_index = ifm->ifi_index;
18917544
KK
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;
c58213f6 70 ifm->ifi_index = ifi_index;
e0d47aa3 71
c14f9d92 72 addattr_nest_end(n, data);
f9329cca 73 return argc - 1 - err;
2da55b1b
PE
74}
75
561e650e 76static void veth_print_help(struct link_util *lu, int argc, char **argv,
77 FILE *f)
78{
79 print_usage(f);
80}
81
2da55b1b
PE
82struct link_util veth_link_util = {
83 .id = "veth",
84 .parse_opt = veth_parse_opt,
561e650e 85 .print_help = veth_print_help,
2da55b1b 86};