]> git.proxmox.com Git - mirror_iproute2.git/blame - ip/iplink_vxcan.c
Merge branch 'main' into next
[mirror_iproute2.git] / ip / iplink_vxcan.c
CommitLineData
efe459c7
OH
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
22static 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
28static void usage(void)
29{
30 print_usage(stderr);
31}
32
33static int vxcan_parse_opt(struct link_util *lu, int argc, char **argv,
28254695 34 struct nlmsghdr *n)
efe459c7 35{
efe459c7 36 char *type = NULL;
dac9ff35 37 int err;
efe459c7 38 struct rtattr *data;
efe459c7 39 struct ifinfomsg *ifm, *peer_ifm;
c58213f6 40 unsigned int ifi_flags, ifi_change, ifi_index;
efe459c7
OH
41
42 if (strcmp(argv[0], "peer") != 0) {
43 usage();
44 return -1;
45 }
46
28254695 47 ifm = NLMSG_DATA(n);
efe459c7
OH
48 ifi_flags = ifm->ifi_flags;
49 ifi_change = ifm->ifi_change;
c58213f6 50 ifi_index = ifm->ifi_index;
efe459c7
OH
51 ifm->ifi_flags = 0;
52 ifm->ifi_change = 0;
c58213f6 53 ifm->ifi_index = 0;
efe459c7 54
c14f9d92 55 data = addattr_nest(n, 1024, VXCAN_INFO_PEER);
efe459c7 56
28254695 57 n->nlmsg_len += sizeof(struct ifinfomsg);
efe459c7 58
c58213f6 59 err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)n, &type);
efe459c7
OH
60 if (err < 0)
61 return err;
62
8c0b19d1
SP
63 if (type)
64 duparg("type", argv[err]);
65
efe459c7 66 peer_ifm = RTA_DATA(data);
c58213f6 67 peer_ifm->ifi_index = ifm->ifi_index;
efe459c7
OH
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;
c58213f6 72 ifm->ifi_index = ifi_index;
efe459c7 73
c14f9d92 74 addattr_nest_end(n, data);
efe459c7
OH
75 return argc - 1 - err;
76}
77
78static void vxcan_print_help(struct link_util *lu, int argc, char **argv,
79 FILE *f)
80{
81 print_usage(f);
82}
83
84struct link_util vxcan_link_util = {
85 .id = "vxcan",
86 .parse_opt = vxcan_parse_opt,
87 .print_help = vxcan_print_help,
88};