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