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