]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
10142d75 SS |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2014 Susant Sahani <susant@redhat.com> | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU Lesser General Public License as published by | |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public License | |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ***/ | |
20 | ||
dccca82b | 21 | #include <errno.h> |
10142d75 | 22 | #include <linux/veth.h> |
dccca82b | 23 | #include <net/if.h> |
10142d75 | 24 | |
1c4baffc | 25 | #include "sd-netlink.h" |
cf0fbc49 | 26 | |
441e9ae4 | 27 | #include "netdev/veth.h" |
10142d75 | 28 | |
1c4baffc | 29 | static int netdev_veth_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { |
cd946b9c | 30 | Veth *v; |
10142d75 SS |
31 | int r; |
32 | ||
33 | assert(netdev); | |
aa9f1140 | 34 | assert(!link); |
10142d75 SS |
35 | assert(m); |
36 | ||
cd946b9c SS |
37 | v = VETH(netdev); |
38 | ||
39 | assert(v); | |
40 | ||
1c4baffc | 41 | r = sd_netlink_message_open_container(m, VETH_INFO_PEER); |
7676666c SS |
42 | if (r < 0) |
43 | return log_netdev_error_errno(netdev, r, "Could not append VETH_INFO_PEER attribute: %m"); | |
10142d75 | 44 | |
aa9f1140 | 45 | if (v->ifname_peer) { |
1c4baffc | 46 | r = sd_netlink_message_append_string(m, IFLA_IFNAME, v->ifname_peer); |
f647962d MS |
47 | if (r < 0) |
48 | return log_error_errno(r, "Failed to add netlink interface name: %m"); | |
10142d75 SS |
49 | } |
50 | ||
aa9f1140 | 51 | if (v->mac_peer) { |
1c4baffc | 52 | r = sd_netlink_message_append_ether_addr(m, IFLA_ADDRESS, v->mac_peer); |
7676666c SS |
53 | if (r < 0) |
54 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_ADDRESS attribute: %m"); | |
96c90742 TG |
55 | } |
56 | ||
1c4baffc | 57 | r = sd_netlink_message_close_container(m); |
7676666c SS |
58 | if (r < 0) |
59 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m"); | |
10142d75 | 60 | |
10142d75 SS |
61 | return r; |
62 | } | |
63 | ||
3be1d7e0 | 64 | static int netdev_veth_verify(NetDev *netdev, const char *filename) { |
cd946b9c | 65 | Veth *v; |
10142d75 SS |
66 | int r; |
67 | ||
68 | assert(netdev); | |
3be1d7e0 | 69 | assert(filename); |
10142d75 | 70 | |
cd946b9c SS |
71 | v = VETH(netdev); |
72 | ||
73 | assert(v); | |
74 | ||
aa9f1140 | 75 | if (!v->ifname_peer) { |
3be1d7e0 TG |
76 | log_warning("Veth NetDev without peer name configured in %s. Ignoring", |
77 | filename); | |
78 | return -EINVAL; | |
10142d75 SS |
79 | } |
80 | ||
aa9f1140 TG |
81 | if (!v->mac_peer) { |
82 | r = netdev_get_mac(v->ifname_peer, &v->mac_peer); | |
3be1d7e0 TG |
83 | if (r < 0) { |
84 | log_warning("Failed to generate predictable MAC address for %s. Ignoring", | |
aa9f1140 | 85 | v->ifname_peer); |
3be1d7e0 TG |
86 | return -EINVAL; |
87 | } | |
10142d75 SS |
88 | } |
89 | ||
10142d75 SS |
90 | return 0; |
91 | } | |
3be1d7e0 | 92 | |
aa9f1140 | 93 | static void veth_done(NetDev *n) { |
cd946b9c | 94 | Veth *v; |
aa9f1140 TG |
95 | |
96 | assert(n); | |
cd946b9c SS |
97 | |
98 | v = VETH(n); | |
99 | ||
aa9f1140 TG |
100 | assert(v); |
101 | ||
102 | free(v->ifname_peer); | |
103 | free(v->mac_peer); | |
104 | } | |
105 | ||
3be1d7e0 | 106 | const NetDevVTable veth_vtable = { |
aa9f1140 TG |
107 | .object_size = sizeof(Veth), |
108 | .sections = "Match\0NetDev\0Peer\0", | |
109 | .done = veth_done, | |
3be1d7e0 | 110 | .fill_message_create = netdev_veth_fill_message_create, |
aa9f1140 | 111 | .create_type = NETDEV_CREATE_INDEPENDENT, |
3be1d7e0 TG |
112 | .config_verify = netdev_veth_verify, |
113 | }; |