]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
10142d75 | 2 | /*** |
11a15892 | 3 | Copyright 2014 Susant Sahani <susant@redhat.com> |
10142d75 SS |
4 | ***/ |
5 | ||
dccca82b | 6 | #include <errno.h> |
10142d75 | 7 | #include <linux/veth.h> |
dccca82b | 8 | #include <net/if.h> |
10142d75 | 9 | |
1c4baffc | 10 | #include "sd-netlink.h" |
cf0fbc49 | 11 | |
441e9ae4 | 12 | #include "netdev/veth.h" |
10142d75 | 13 | |
1c4baffc | 14 | static int netdev_veth_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { |
cd946b9c | 15 | Veth *v; |
10142d75 SS |
16 | int r; |
17 | ||
18 | assert(netdev); | |
aa9f1140 | 19 | assert(!link); |
10142d75 SS |
20 | assert(m); |
21 | ||
cd946b9c SS |
22 | v = VETH(netdev); |
23 | ||
24 | assert(v); | |
25 | ||
1c4baffc | 26 | r = sd_netlink_message_open_container(m, VETH_INFO_PEER); |
7676666c SS |
27 | if (r < 0) |
28 | return log_netdev_error_errno(netdev, r, "Could not append VETH_INFO_PEER attribute: %m"); | |
10142d75 | 29 | |
aa9f1140 | 30 | if (v->ifname_peer) { |
1c4baffc | 31 | r = sd_netlink_message_append_string(m, IFLA_IFNAME, v->ifname_peer); |
f647962d MS |
32 | if (r < 0) |
33 | return log_error_errno(r, "Failed to add netlink interface name: %m"); | |
10142d75 SS |
34 | } |
35 | ||
aa9f1140 | 36 | if (v->mac_peer) { |
1c4baffc | 37 | r = sd_netlink_message_append_ether_addr(m, IFLA_ADDRESS, v->mac_peer); |
7676666c SS |
38 | if (r < 0) |
39 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_ADDRESS attribute: %m"); | |
96c90742 TG |
40 | } |
41 | ||
1c4baffc | 42 | r = sd_netlink_message_close_container(m); |
7676666c SS |
43 | if (r < 0) |
44 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m"); | |
10142d75 | 45 | |
10142d75 SS |
46 | return r; |
47 | } | |
48 | ||
3be1d7e0 | 49 | static int netdev_veth_verify(NetDev *netdev, const char *filename) { |
cd946b9c | 50 | Veth *v; |
10142d75 SS |
51 | int r; |
52 | ||
53 | assert(netdev); | |
3be1d7e0 | 54 | assert(filename); |
10142d75 | 55 | |
cd946b9c SS |
56 | v = VETH(netdev); |
57 | ||
58 | assert(v); | |
59 | ||
aa9f1140 | 60 | if (!v->ifname_peer) { |
3be1d7e0 TG |
61 | log_warning("Veth NetDev without peer name configured in %s. Ignoring", |
62 | filename); | |
63 | return -EINVAL; | |
10142d75 SS |
64 | } |
65 | ||
aa9f1140 TG |
66 | if (!v->mac_peer) { |
67 | r = netdev_get_mac(v->ifname_peer, &v->mac_peer); | |
3be1d7e0 TG |
68 | if (r < 0) { |
69 | log_warning("Failed to generate predictable MAC address for %s. Ignoring", | |
aa9f1140 | 70 | v->ifname_peer); |
3be1d7e0 TG |
71 | return -EINVAL; |
72 | } | |
10142d75 SS |
73 | } |
74 | ||
10142d75 SS |
75 | return 0; |
76 | } | |
3be1d7e0 | 77 | |
aa9f1140 | 78 | static void veth_done(NetDev *n) { |
cd946b9c | 79 | Veth *v; |
aa9f1140 TG |
80 | |
81 | assert(n); | |
cd946b9c SS |
82 | |
83 | v = VETH(n); | |
84 | ||
aa9f1140 TG |
85 | assert(v); |
86 | ||
87 | free(v->ifname_peer); | |
88 | free(v->mac_peer); | |
89 | } | |
90 | ||
3be1d7e0 | 91 | const NetDevVTable veth_vtable = { |
aa9f1140 TG |
92 | .object_size = sizeof(Veth), |
93 | .sections = "Match\0NetDev\0Peer\0", | |
94 | .done = veth_done, | |
3be1d7e0 | 95 | .fill_message_create = netdev_veth_fill_message_create, |
aa9f1140 | 96 | .create_type = NETDEV_CREATE_INDEPENDENT, |
3be1d7e0 TG |
97 | .config_verify = netdev_veth_verify, |
98 | }; |