]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/netdev/vxcan.c
core/namespace: rework the return semantics of clone_device_node yet again
[thirdparty/systemd.git] / src / network / netdev / vxcan.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2017 Susant Sahani
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #include "netdev/vxcan.h"
21 #include "missing.h"
22
23 static int netdev_vxcan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
24 VxCan *v;
25 int r;
26
27 assert(netdev);
28 assert(!link);
29 assert(m);
30
31 v = VXCAN(netdev);
32
33 assert(v);
34
35 r = sd_netlink_message_open_container(m, VXCAN_INFO_PEER);
36 if (r < 0)
37 return log_netdev_error_errno(netdev, r, "Could not append VXCAN_INFO_PEER attribute: %m");
38
39 if (v->ifname_peer) {
40 r = sd_netlink_message_append_string(m, IFLA_IFNAME, v->ifname_peer);
41 if (r < 0)
42 return log_error_errno(r, "Failed to add vxcan netlink interface peer name: %m");
43 }
44
45 r = sd_netlink_message_close_container(m);
46 if (r < 0)
47 return log_netdev_error_errno(netdev, r, "Could not append VXCAN_INFO_PEER attribute: %m");
48
49 return r;
50 }
51
52 static int netdev_vxcan_verify(NetDev *netdev, const char *filename) {
53 VxCan *v;
54
55 assert(netdev);
56 assert(filename);
57
58 v = VXCAN(netdev);
59
60 assert(v);
61
62 if (!v->ifname_peer) {
63 log_warning("VxCan NetDev without peer name configured in %s. Ignoring", filename);
64 return -EINVAL;
65 }
66
67 return 0;
68 }
69
70 static void vxcan_done(NetDev *n) {
71 VxCan *v;
72
73 assert(n);
74
75 v = VXCAN(n);
76
77 assert(v);
78
79 free(v->ifname_peer);
80 }
81
82 const NetDevVTable vxcan_vtable = {
83 .object_size = sizeof(VxCan),
84 .sections = "Match\0NetDev\0VXCAN\0",
85 .done = vxcan_done,
86 .fill_message_create = netdev_vxcan_fill_message_create,
87 .create_type = NETDEV_CREATE_INDEPENDENT,
88 .config_verify = netdev_vxcan_verify,
89 };