]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * iplink_vxcan.c vxcan device support (Virtual CAN Tunnel) | |
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 | * Author: Oliver Hartkopp <socketcan@hartkopp.net> | |
10 | * Based on: link_veth.c from Pavel Emelianov <xemul@openvz.org> | |
11 | */ | |
12 | ||
13 | #include <stdio.h> | |
14 | #include <stdlib.h> | |
15 | #include <string.h> | |
16 | #include <net/if.h> | |
17 | #include <linux/can/vxcan.h> | |
18 | ||
19 | #include "utils.h" | |
20 | #include "ip_common.h" | |
21 | ||
22 | static void print_usage(FILE *f) | |
23 | { | |
24 | printf("Usage: ip link <options> type vxcan [peer <options>]\n" | |
25 | "To get <options> type 'ip link add help'\n"); | |
26 | } | |
27 | ||
28 | static void usage(void) | |
29 | { | |
30 | print_usage(stderr); | |
31 | } | |
32 | ||
33 | static int vxcan_parse_opt(struct link_util *lu, int argc, char **argv, | |
34 | struct nlmsghdr *n) | |
35 | { | |
36 | char *type = NULL; | |
37 | int err; | |
38 | struct rtattr *data; | |
39 | struct ifinfomsg *ifm, *peer_ifm; | |
40 | unsigned int ifi_flags, ifi_change, ifi_index; | |
41 | ||
42 | if (strcmp(argv[0], "peer") != 0) { | |
43 | usage(); | |
44 | return -1; | |
45 | } | |
46 | ||
47 | ifm = NLMSG_DATA(n); | |
48 | ifi_flags = ifm->ifi_flags; | |
49 | ifi_change = ifm->ifi_change; | |
50 | ifi_index = ifm->ifi_index; | |
51 | ifm->ifi_flags = 0; | |
52 | ifm->ifi_change = 0; | |
53 | ifm->ifi_index = 0; | |
54 | ||
55 | data = addattr_nest(n, 1024, VXCAN_INFO_PEER); | |
56 | ||
57 | n->nlmsg_len += sizeof(struct ifinfomsg); | |
58 | ||
59 | err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)n, &type); | |
60 | if (err < 0) | |
61 | return err; | |
62 | ||
63 | if (type) | |
64 | duparg("type", argv[err]); | |
65 | ||
66 | peer_ifm = RTA_DATA(data); | |
67 | peer_ifm->ifi_index = ifm->ifi_index; | |
68 | peer_ifm->ifi_flags = ifm->ifi_flags; | |
69 | peer_ifm->ifi_change = ifm->ifi_change; | |
70 | ifm->ifi_flags = ifi_flags; | |
71 | ifm->ifi_change = ifi_change; | |
72 | ifm->ifi_index = ifi_index; | |
73 | ||
74 | addattr_nest_end(n, data); | |
75 | return argc - 1 - err; | |
76 | } | |
77 | ||
78 | static void vxcan_print_help(struct link_util *lu, int argc, char **argv, | |
79 | FILE *f) | |
80 | { | |
81 | print_usage(f); | |
82 | } | |
83 | ||
84 | struct link_util vxcan_link_util = { | |
85 | .id = "vxcan", | |
86 | .parse_opt = vxcan_parse_opt, | |
87 | .print_help = vxcan_print_help, | |
88 | }; |