]>
Commit | Line | Data |
---|---|---|
d506b89c | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
d6df583c | 2 | |
9714c020 YW |
3 | #if HAVE_LINUX_CAN_VXCAN_H |
4 | #include <linux/can/vxcan.h> | |
5 | #endif | |
6 | ||
d6df583c | 7 | #include "missing.h" |
9714c020 | 8 | #include "netdev/vxcan.h" |
d6df583c SS |
9 | |
10 | static int netdev_vxcan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { | |
11 | VxCan *v; | |
12 | int r; | |
13 | ||
14 | assert(netdev); | |
15 | assert(!link); | |
16 | assert(m); | |
17 | ||
18 | v = VXCAN(netdev); | |
19 | ||
20 | assert(v); | |
21 | ||
22 | r = sd_netlink_message_open_container(m, VXCAN_INFO_PEER); | |
23 | if (r < 0) | |
24 | return log_netdev_error_errno(netdev, r, "Could not append VXCAN_INFO_PEER attribute: %m"); | |
25 | ||
26 | if (v->ifname_peer) { | |
27 | r = sd_netlink_message_append_string(m, IFLA_IFNAME, v->ifname_peer); | |
28 | if (r < 0) | |
29 | return log_error_errno(r, "Failed to add vxcan netlink interface peer name: %m"); | |
30 | } | |
31 | ||
32 | r = sd_netlink_message_close_container(m); | |
33 | if (r < 0) | |
34 | return log_netdev_error_errno(netdev, r, "Could not append VXCAN_INFO_PEER attribute: %m"); | |
35 | ||
36 | return r; | |
37 | } | |
38 | ||
39 | static int netdev_vxcan_verify(NetDev *netdev, const char *filename) { | |
40 | VxCan *v; | |
41 | ||
42 | assert(netdev); | |
43 | assert(filename); | |
44 | ||
45 | v = VXCAN(netdev); | |
46 | ||
47 | assert(v); | |
48 | ||
49 | if (!v->ifname_peer) { | |
50 | log_warning("VxCan NetDev without peer name configured in %s. Ignoring", filename); | |
51 | return -EINVAL; | |
52 | } | |
53 | ||
54 | return 0; | |
55 | } | |
56 | ||
57 | static void vxcan_done(NetDev *n) { | |
58 | VxCan *v; | |
59 | ||
60 | assert(n); | |
61 | ||
62 | v = VXCAN(n); | |
63 | ||
64 | assert(v); | |
65 | ||
66 | free(v->ifname_peer); | |
67 | } | |
68 | ||
69 | const NetDevVTable vxcan_vtable = { | |
70 | .object_size = sizeof(VxCan), | |
71 | .sections = "Match\0NetDev\0VXCAN\0", | |
72 | .done = vxcan_done, | |
73 | .fill_message_create = netdev_vxcan_fill_message_create, | |
74 | .create_type = NETDEV_CREATE_INDEPENDENT, | |
75 | .config_verify = netdev_vxcan_verify, | |
76 | }; |