]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/netdev/veth.c
network: warn about unknown sections when parsing .netdev files
[thirdparty/systemd.git] / src / network / netdev / veth.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <errno.h>
4 #include <net/if.h>
5 #include <linux/veth.h>
6
7 #include "veth.h"
8
9 static int netdev_veth_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
10 Veth *v;
11 int r;
12
13 assert(netdev);
14 assert(!link);
15 assert(m);
16
17 v = VETH(netdev);
18
19 assert(v);
20
21 r = sd_netlink_message_open_container(m, VETH_INFO_PEER);
22 if (r < 0)
23 return log_netdev_error_errno(netdev, r, "Could not append VETH_INFO_PEER attribute: %m");
24
25 if (v->ifname_peer) {
26 r = sd_netlink_message_append_string(m, IFLA_IFNAME, v->ifname_peer);
27 if (r < 0)
28 return log_error_errno(r, "Failed to add netlink interface name: %m");
29 }
30
31 if (v->mac_peer) {
32 r = sd_netlink_message_append_ether_addr(m, IFLA_ADDRESS, v->mac_peer);
33 if (r < 0)
34 return log_netdev_error_errno(netdev, r, "Could not append IFLA_ADDRESS attribute: %m");
35 }
36
37 r = sd_netlink_message_close_container(m);
38 if (r < 0)
39 return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m");
40
41 return r;
42 }
43
44 static int netdev_veth_verify(NetDev *netdev, const char *filename) {
45 Veth *v;
46 int r;
47
48 assert(netdev);
49 assert(filename);
50
51 v = VETH(netdev);
52
53 assert(v);
54
55 if (!v->ifname_peer) {
56 log_warning("Veth NetDev without peer name configured in %s. Ignoring",
57 filename);
58 return -EINVAL;
59 }
60
61 if (!v->mac_peer) {
62 r = netdev_get_mac(v->ifname_peer, &v->mac_peer);
63 if (r < 0) {
64 log_warning("Failed to generate predictable MAC address for %s. Ignoring",
65 v->ifname_peer);
66 return -EINVAL;
67 }
68 }
69
70 return 0;
71 }
72
73 static void veth_done(NetDev *n) {
74 Veth *v;
75
76 assert(n);
77
78 v = VETH(n);
79
80 assert(v);
81
82 free(v->ifname_peer);
83 free(v->mac_peer);
84 }
85
86 const NetDevVTable veth_vtable = {
87 .object_size = sizeof(Veth),
88 .sections = NETDEV_COMMON_SECTIONS "Peer\0",
89 .done = veth_done,
90 .fill_message_create = netdev_veth_fill_message_create,
91 .create_type = NETDEV_CREATE_INDEPENDENT,
92 .config_verify = netdev_veth_verify,
93 .generate_mac = true,
94 };