]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
02b59d57 | 2 | |
987efa17 | 3 | #include <net/if.h> |
f2000933 | 4 | #include <netinet/in.h> |
007899f4 | 5 | #include <linux/if_arp.h> |
a0b191b7 | 6 | #include <unistd.h> |
987efa17 | 7 | |
b5efdb8a | 8 | #include "alloc-util.h" |
007899f4 | 9 | #include "arphrd-util.h" |
e6980c72 | 10 | #include "bareudp.h" |
c0267a59 | 11 | #include "batadv.h" |
737f1405 YW |
12 | #include "bond.h" |
13 | #include "bridge.h" | |
02b59d57 TG |
14 | #include "conf-files.h" |
15 | #include "conf-parser.h" | |
737f1405 | 16 | #include "dummy.h" |
3ffd4af2 | 17 | #include "fd-util.h" |
737f1405 YW |
18 | #include "fou-tunnel.h" |
19 | #include "geneve.h" | |
3295a461 | 20 | #include "ifb.h" |
b90d0f83 | 21 | #include "ipoib.h" |
737f1405 YW |
22 | #include "ipvlan.h" |
23 | #include "l2tp-tunnel.h" | |
02b59d57 | 24 | #include "list.h" |
737f1405 YW |
25 | #include "macsec.h" |
26 | #include "macvlan.h" | |
27 | #include "netdev.h" | |
28 | #include "netdevsim.h" | |
007899f4 | 29 | #include "netif-util.h" |
3a56e697 | 30 | #include "netlink-util.h" |
3a56e697 | 31 | #include "networkd-manager.h" |
71a754f7 | 32 | #include "networkd-queue.h" |
9b682672 | 33 | #include "networkd-setlink.h" |
e33232d4 | 34 | #include "networkd-sriov.h" |
737f1405 | 35 | #include "nlmon.h" |
b0c82192 | 36 | #include "path-lookup.h" |
3a56e697 SS |
37 | #include "siphash24.h" |
38 | #include "stat-util.h" | |
39 | #include "string-table.h" | |
40 | #include "string-util.h" | |
41 | #include "strv.h" | |
737f1405 YW |
42 | #include "tunnel.h" |
43 | #include "tuntap.h" | |
44 | #include "vcan.h" | |
45 | #include "veth.h" | |
46 | #include "vlan.h" | |
47 | #include "vrf.h" | |
48 | #include "vxcan.h" | |
49 | #include "vxlan.h" | |
50 | #include "wireguard.h" | |
dedf2d00 | 51 | #include "wlan.h" |
737f1405 | 52 | #include "xfrm.h" |
23f53b99 | 53 | |
3be1d7e0 | 54 | const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX] = { |
bc945c2b YW |
55 | [NETDEV_KIND_BAREUDP] = &bare_udp_vtable, |
56 | [NETDEV_KIND_BATADV] = &batadv_vtable, | |
57 | [NETDEV_KIND_BOND] = &bond_vtable, | |
58 | [NETDEV_KIND_BRIDGE] = &bridge_vtable, | |
59 | [NETDEV_KIND_DUMMY] = &dummy_vtable, | |
60 | [NETDEV_KIND_ERSPAN] = &erspan_vtable, | |
61 | [NETDEV_KIND_FOU] = &foutnl_vtable, | |
62 | [NETDEV_KIND_GENEVE] = &geneve_vtable, | |
63 | [NETDEV_KIND_GRE] = &gre_vtable, | |
64 | [NETDEV_KIND_GRETAP] = &gretap_vtable, | |
65 | [NETDEV_KIND_IFB] = &ifb_vtable, | |
66 | [NETDEV_KIND_IP6GRE] = &ip6gre_vtable, | |
b16492f8 | 67 | [NETDEV_KIND_IP6GRETAP] = &ip6gretap_vtable, |
bc945c2b YW |
68 | [NETDEV_KIND_IP6TNL] = &ip6tnl_vtable, |
69 | [NETDEV_KIND_IPIP] = &ipip_vtable, | |
b90d0f83 | 70 | [NETDEV_KIND_IPOIB] = &ipoib_vtable, |
bc945c2b YW |
71 | [NETDEV_KIND_IPVLAN] = &ipvlan_vtable, |
72 | [NETDEV_KIND_IPVTAP] = &ipvtap_vtable, | |
73 | [NETDEV_KIND_L2TP] = &l2tptnl_vtable, | |
74 | [NETDEV_KIND_MACSEC] = &macsec_vtable, | |
75 | [NETDEV_KIND_MACVLAN] = &macvlan_vtable, | |
76 | [NETDEV_KIND_MACVTAP] = &macvtap_vtable, | |
56e7fb50 | 77 | [NETDEV_KIND_NETDEVSIM] = &netdevsim_vtable, |
bc945c2b YW |
78 | [NETDEV_KIND_NLMON] = &nlmon_vtable, |
79 | [NETDEV_KIND_SIT] = &sit_vtable, | |
80 | [NETDEV_KIND_TAP] = &tap_vtable, | |
81 | [NETDEV_KIND_TUN] = &tun_vtable, | |
82 | [NETDEV_KIND_VCAN] = &vcan_vtable, | |
83 | [NETDEV_KIND_VETH] = &veth_vtable, | |
84 | [NETDEV_KIND_VLAN] = &vlan_vtable, | |
85 | [NETDEV_KIND_VRF] = &vrf_vtable, | |
86 | [NETDEV_KIND_VTI6] = &vti6_vtable, | |
87 | [NETDEV_KIND_VTI] = &vti_vtable, | |
88 | [NETDEV_KIND_VXCAN] = &vxcan_vtable, | |
89 | [NETDEV_KIND_VXLAN] = &vxlan_vtable, | |
90 | [NETDEV_KIND_WIREGUARD] = &wireguard_vtable, | |
dedf2d00 | 91 | [NETDEV_KIND_WLAN] = &wlan_vtable, |
bc945c2b | 92 | [NETDEV_KIND_XFRM] = &xfrm_vtable, |
3be1d7e0 TG |
93 | }; |
94 | ||
2c5859af | 95 | static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = { |
bc945c2b YW |
96 | [NETDEV_KIND_BAREUDP] = "bareudp", |
97 | [NETDEV_KIND_BATADV] = "batadv", | |
98 | [NETDEV_KIND_BOND] = "bond", | |
99 | [NETDEV_KIND_BRIDGE] = "bridge", | |
100 | [NETDEV_KIND_DUMMY] = "dummy", | |
101 | [NETDEV_KIND_ERSPAN] = "erspan", | |
102 | [NETDEV_KIND_FOU] = "fou", | |
103 | [NETDEV_KIND_GENEVE] = "geneve", | |
104 | [NETDEV_KIND_GRE] = "gre", | |
105 | [NETDEV_KIND_GRETAP] = "gretap", | |
106 | [NETDEV_KIND_IFB] = "ifb", | |
107 | [NETDEV_KIND_IP6GRE] = "ip6gre", | |
b16492f8 | 108 | [NETDEV_KIND_IP6GRETAP] = "ip6gretap", |
bc945c2b YW |
109 | [NETDEV_KIND_IP6TNL] = "ip6tnl", |
110 | [NETDEV_KIND_IPIP] = "ipip", | |
b90d0f83 | 111 | [NETDEV_KIND_IPOIB] = "ipoib", |
bc945c2b YW |
112 | [NETDEV_KIND_IPVLAN] = "ipvlan", |
113 | [NETDEV_KIND_IPVTAP] = "ipvtap", | |
114 | [NETDEV_KIND_L2TP] = "l2tp", | |
115 | [NETDEV_KIND_MACSEC] = "macsec", | |
116 | [NETDEV_KIND_MACVLAN] = "macvlan", | |
117 | [NETDEV_KIND_MACVTAP] = "macvtap", | |
56e7fb50 | 118 | [NETDEV_KIND_NETDEVSIM] = "netdevsim", |
bc945c2b YW |
119 | [NETDEV_KIND_NLMON] = "nlmon", |
120 | [NETDEV_KIND_SIT] = "sit", | |
121 | [NETDEV_KIND_TAP] = "tap", | |
122 | [NETDEV_KIND_TUN] = "tun", | |
123 | [NETDEV_KIND_VCAN] = "vcan", | |
124 | [NETDEV_KIND_VETH] = "veth", | |
125 | [NETDEV_KIND_VLAN] = "vlan", | |
126 | [NETDEV_KIND_VRF] = "vrf", | |
127 | [NETDEV_KIND_VTI6] = "vti6", | |
128 | [NETDEV_KIND_VTI] = "vti", | |
129 | [NETDEV_KIND_VXCAN] = "vxcan", | |
130 | [NETDEV_KIND_VXLAN] = "vxlan", | |
131 | [NETDEV_KIND_WIREGUARD] = "wireguard", | |
ec4954d9 | 132 | [NETDEV_KIND_WLAN] = "wlan", |
bc945c2b | 133 | [NETDEV_KIND_XFRM] = "xfrm", |
52433f6b | 134 | }; |
02b59d57 | 135 | |
1a436809 | 136 | DEFINE_STRING_TABLE_LOOKUP(netdev_kind, NetDevKind); |
62facba1 | 137 | |
9e2bbf99 YW |
138 | bool netdev_is_managed(NetDev *netdev) { |
139 | if (!netdev || !netdev->manager || !netdev->ifname) | |
140 | return false; | |
141 | ||
142 | return hashmap_get(netdev->manager->netdevs, netdev->ifname) == netdev; | |
143 | } | |
144 | ||
798e5dc8 YW |
145 | static bool netdev_is_stacked_and_independent(NetDev *netdev) { |
146 | assert(netdev); | |
147 | ||
3d24b0dd | 148 | if (netdev_get_create_type(netdev) != NETDEV_CREATE_STACKED) |
798e5dc8 YW |
149 | return false; |
150 | ||
151 | switch (netdev->kind) { | |
152 | case NETDEV_KIND_ERSPAN: | |
153 | return ERSPAN(netdev)->independent; | |
154 | case NETDEV_KIND_GRE: | |
155 | return GRE(netdev)->independent; | |
156 | case NETDEV_KIND_GRETAP: | |
157 | return GRETAP(netdev)->independent; | |
158 | case NETDEV_KIND_IP6GRE: | |
159 | return IP6GRE(netdev)->independent; | |
160 | case NETDEV_KIND_IP6GRETAP: | |
161 | return IP6GRETAP(netdev)->independent; | |
162 | case NETDEV_KIND_IP6TNL: | |
163 | return IP6TNL(netdev)->independent; | |
164 | case NETDEV_KIND_IPIP: | |
165 | return IPIP(netdev)->independent; | |
166 | case NETDEV_KIND_SIT: | |
167 | return SIT(netdev)->independent; | |
168 | case NETDEV_KIND_VTI: | |
169 | return VTI(netdev)->independent; | |
170 | case NETDEV_KIND_VTI6: | |
171 | return VTI6(netdev)->independent; | |
172 | case NETDEV_KIND_VXLAN: | |
173 | return VXLAN(netdev)->independent; | |
174 | case NETDEV_KIND_XFRM: | |
175 | return XFRM(netdev)->independent; | |
176 | default: | |
177 | return false; | |
178 | } | |
179 | } | |
180 | ||
2f117922 YW |
181 | static bool netdev_is_stacked(NetDev *netdev) { |
182 | assert(netdev); | |
183 | ||
3d24b0dd | 184 | if (netdev_get_create_type(netdev) != NETDEV_CREATE_STACKED) |
2f117922 YW |
185 | return false; |
186 | ||
187 | if (netdev_is_stacked_and_independent(netdev)) | |
188 | return false; | |
189 | ||
190 | return true; | |
191 | } | |
192 | ||
c4397d94 YW |
193 | static void netdev_detach_from_manager(NetDev *netdev) { |
194 | if (netdev->ifname && netdev->manager) | |
195 | hashmap_remove(netdev->manager->netdevs, netdev->ifname); | |
c4397d94 YW |
196 | } |
197 | ||
8301aa0b YW |
198 | static NetDev *netdev_free(NetDev *netdev) { |
199 | assert(netdev); | |
59cb64e6 | 200 | |
c4397d94 | 201 | netdev_detach_from_manager(netdev); |
02b59d57 | 202 | |
52433f6b | 203 | free(netdev->filename); |
02b59d57 | 204 | |
52433f6b | 205 | free(netdev->description); |
af4e9e2c | 206 | free(netdev->ifname); |
c4f58dea | 207 | condition_free_list(netdev->conditions); |
79e16ce3 | 208 | |
f3c33b23 LP |
209 | /* Invoke the per-kind done() destructor, but only if the state field is initialized. We conditionalize that |
210 | * because we parse .netdev files twice: once to determine the kind (with a short, minimal NetDev structure | |
211 | * allocation, with no room for per-kind fields), and once to read the kind's properties (with a full, | |
212 | * comprehensive NetDev structure allocation with enough space for whatever the specific kind needs). Now, in | |
213 | * the first case we shouldn't try to destruct the per-kind NetDev fields on destruction, in the second case we | |
214 | * should. We use the state field to discern the two cases: it's _NETDEV_STATE_INVALID on the first "raw" | |
215 | * call. */ | |
216 | if (netdev->state != _NETDEV_STATE_INVALID && | |
217 | NETDEV_VTABLE(netdev) && | |
aa9f1140 TG |
218 | NETDEV_VTABLE(netdev)->done) |
219 | NETDEV_VTABLE(netdev)->done(netdev); | |
220 | ||
8301aa0b | 221 | return mfree(netdev); |
14b746f7 TG |
222 | } |
223 | ||
8301aa0b | 224 | DEFINE_TRIVIAL_REF_UNREF_FUNC(NetDev, netdev, netdev_free); |
14b746f7 | 225 | |
2cc7e981 | 226 | void netdev_drop(NetDev *netdev) { |
2f117922 | 227 | if (!netdev) |
2cc7e981 TG |
228 | return; |
229 | ||
2f117922 YW |
230 | if (netdev_is_stacked(netdev)) { |
231 | /* The netdev may be removed due to the underlying device removal, and the device may | |
232 | * be re-added later. */ | |
233 | netdev->state = NETDEV_STATE_LOADING; | |
234 | netdev->ifindex = 0; | |
235 | ||
236 | log_netdev_debug(netdev, "netdev removed"); | |
237 | return; | |
238 | } | |
239 | ||
af7a86b8 YW |
240 | if (NETDEV_VTABLE(netdev) && NETDEV_VTABLE(netdev)->drop) |
241 | NETDEV_VTABLE(netdev)->drop(netdev); | |
242 | ||
2cc7e981 TG |
243 | netdev->state = NETDEV_STATE_LINGER; |
244 | ||
79008bdd | 245 | log_netdev_debug(netdev, "netdev removed"); |
370e9930 | 246 | |
c4397d94 | 247 | netdev_detach_from_manager(netdev); |
2cc7e981 | 248 | netdev_unref(netdev); |
2cc7e981 TG |
249 | return; |
250 | } | |
251 | ||
1a436809 TG |
252 | int netdev_get(Manager *manager, const char *name, NetDev **ret) { |
253 | NetDev *netdev; | |
02b59d57 TG |
254 | |
255 | assert(manager); | |
256 | assert(name); | |
257 | assert(ret); | |
258 | ||
52433f6b | 259 | netdev = hashmap_get(manager->netdevs, name); |
fef805b9 | 260 | if (!netdev) |
02b59d57 | 261 | return -ENOENT; |
02b59d57 | 262 | |
52433f6b | 263 | *ret = netdev; |
02b59d57 TG |
264 | |
265 | return 0; | |
266 | } | |
267 | ||
8f65304c | 268 | void netdev_enter_failed(NetDev *netdev) { |
52433f6b | 269 | netdev->state = NETDEV_STATE_FAILED; |
02b59d57 TG |
270 | } |
271 | ||
1a436809 | 272 | static int netdev_enter_ready(NetDev *netdev) { |
52433f6b | 273 | assert(netdev); |
af4e9e2c | 274 | assert(netdev->ifname); |
924fe430 | 275 | |
ba5596ec TG |
276 | if (netdev->state != NETDEV_STATE_CREATING) |
277 | return 0; | |
278 | ||
52433f6b | 279 | netdev->state = NETDEV_STATE_READY; |
02b59d57 | 280 | |
98b32556 | 281 | log_netdev_info(netdev, "netdev ready"); |
02b59d57 | 282 | |
540eb5f0 | 283 | if (NETDEV_VTABLE(netdev)->post_create) |
c2b19b8f | 284 | NETDEV_VTABLE(netdev)->post_create(netdev, NULL); |
540eb5f0 | 285 | |
02b59d57 TG |
286 | return 0; |
287 | } | |
8469c1d3 | 288 | |
d5b3d845 | 289 | /* callback for netdev's created without a backing Link */ |
302a796f | 290 | static int netdev_create_handler(sd_netlink *rtnl, sd_netlink_message *m, NetDev *netdev) { |
172f6635 | 291 | int r; |
02b59d57 | 292 | |
1046bf9b | 293 | assert(netdev); |
52433f6b | 294 | assert(netdev->state != _NETDEV_STATE_INVALID); |
02b59d57 | 295 | |
1c4baffc | 296 | r = sd_netlink_message_get_errno(m); |
e09826dc | 297 | if (r == -EEXIST) |
98b32556 | 298 | log_netdev_info(netdev, "netdev exists, using existing without changing its parameters"); |
505f8da7 | 299 | else if (r < 0) { |
6a7a4e4d | 300 | log_netdev_warning_errno(netdev, r, "netdev could not be created: %m"); |
8f65304c | 301 | netdev_enter_failed(netdev); |
dd3efc09 TG |
302 | |
303 | return 1; | |
02b59d57 TG |
304 | } |
305 | ||
6a7a4e4d | 306 | log_netdev_debug(netdev, "Created"); |
aa9f1140 | 307 | |
dd3efc09 | 308 | return 1; |
02b59d57 TG |
309 | } |
310 | ||
1c4baffc | 311 | int netdev_set_ifindex(NetDev *netdev, sd_netlink_message *message) { |
c3ebdce3 | 312 | uint16_t type; |
d39edfc7 | 313 | const char *kind; |
ca4e095a LP |
314 | const char *received_kind; |
315 | const char *received_name; | |
d39edfc7 TG |
316 | int r, ifindex; |
317 | ||
50add290 | 318 | assert(netdev); |
c3ebdce3 | 319 | assert(message); |
02b59d57 | 320 | |
1c4baffc | 321 | r = sd_netlink_message_get_type(message, &type); |
6a7a4e4d LP |
322 | if (r < 0) |
323 | return log_netdev_error_errno(netdev, r, "Could not get rtnl message type: %m"); | |
c3ebdce3 | 324 | |
5a9494be YW |
325 | if (type != RTM_NEWLINK) |
326 | return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL), "Cannot set ifindex from unexpected rtnl message type."); | |
d39edfc7 | 327 | |
a21df104 TG |
328 | r = sd_rtnl_message_link_get_ifindex(message, &ifindex); |
329 | if (r < 0) { | |
6a7a4e4d | 330 | log_netdev_error_errno(netdev, r, "Could not get ifindex: %m"); |
a21df104 TG |
331 | netdev_enter_failed(netdev); |
332 | return r; | |
333 | } else if (ifindex <= 0) { | |
79008bdd | 334 | log_netdev_error(netdev, "Got invalid ifindex: %d", ifindex); |
a21df104 | 335 | netdev_enter_failed(netdev); |
6a7a4e4d | 336 | return -EINVAL; |
a21df104 TG |
337 | } |
338 | ||
a21df104 TG |
339 | if (netdev->ifindex > 0) { |
340 | if (netdev->ifindex != ifindex) { | |
79008bdd | 341 | log_netdev_error(netdev, "Could not set ifindex to %d, already set to %d", |
a21df104 TG |
342 | ifindex, netdev->ifindex); |
343 | netdev_enter_failed(netdev); | |
344 | return -EEXIST; | |
345 | } else | |
346 | /* ifindex already set to the same for this netdev */ | |
347 | return 0; | |
348 | } | |
349 | ||
1c4baffc | 350 | r = sd_netlink_message_read_string(message, IFLA_IFNAME, &received_name); |
6a7a4e4d LP |
351 | if (r < 0) |
352 | return log_netdev_error_errno(netdev, r, "Could not get IFNAME: %m"); | |
c6315a7a | 353 | |
af4e9e2c | 354 | if (!streq(netdev->ifname, received_name)) { |
6a7a4e4d | 355 | log_netdev_error(netdev, "Received newlink with wrong IFNAME %s", received_name); |
c6315a7a | 356 | netdev_enter_failed(netdev); |
72f09281 | 357 | return -EINVAL; |
c6315a7a TG |
358 | } |
359 | ||
1d4312d5 YW |
360 | if (!NETDEV_VTABLE(netdev)->skip_netdev_kind_check) { |
361 | ||
362 | r = sd_netlink_message_enter_container(message, IFLA_LINKINFO); | |
363 | if (r < 0) | |
364 | return log_netdev_error_errno(netdev, r, "Could not get LINKINFO: %m"); | |
365 | ||
366 | r = sd_netlink_message_read_string(message, IFLA_INFO_KIND, &received_kind); | |
367 | if (r < 0) | |
368 | return log_netdev_error_errno(netdev, r, "Could not get KIND: %m"); | |
369 | ||
370 | r = sd_netlink_message_exit_container(message); | |
371 | if (r < 0) | |
372 | return log_netdev_error_errno(netdev, r, "Could not exit container: %m"); | |
373 | ||
374 | if (netdev->kind == NETDEV_KIND_TAP) | |
375 | /* the kernel does not distinguish between tun and tap */ | |
376 | kind = "tun"; | |
377 | else { | |
378 | kind = netdev_kind_to_string(netdev->kind); | |
379 | if (!kind) { | |
380 | log_netdev_error(netdev, "Could not get kind"); | |
381 | netdev_enter_failed(netdev); | |
382 | return -EINVAL; | |
383 | } | |
384 | } | |
d39edfc7 | 385 | |
1d4312d5 YW |
386 | if (!streq(kind, received_kind)) { |
387 | log_netdev_error(netdev, "Received newlink with wrong KIND %s, expected %s", | |
388 | received_kind, kind); | |
30ae9dfd SS |
389 | netdev_enter_failed(netdev); |
390 | return -EINVAL; | |
391 | } | |
c3ebdce3 TG |
392 | } |
393 | ||
50add290 | 394 | netdev->ifindex = ifindex; |
52433f6b | 395 | |
79008bdd | 396 | log_netdev_debug(netdev, "netdev has index %d", netdev->ifindex); |
5261692f | 397 | |
52433f6b | 398 | netdev_enter_ready(netdev); |
02b59d57 TG |
399 | |
400 | return 0; | |
401 | } | |
402 | ||
5c8f858d TG |
403 | #define HASH_KEY SD_ID128_MAKE(52,e1,45,bd,00,6f,29,96,21,c6,30,6d,83,71,04,48) |
404 | ||
a8ee2b8e YW |
405 | int netdev_generate_hw_addr( |
406 | NetDev *netdev, | |
b90d0f83 | 407 | Link *parent, |
a8ee2b8e YW |
408 | const char *name, |
409 | const struct hw_addr_data *hw_addr, | |
410 | struct hw_addr_data *ret) { | |
411 | ||
412 | struct hw_addr_data a = HW_ADDR_NULL; | |
45aa0e84 | 413 | bool is_static = false; |
5c8f858d TG |
414 | int r; |
415 | ||
007899f4 YW |
416 | assert(netdev); |
417 | assert(name); | |
418 | assert(hw_addr); | |
a8ee2b8e | 419 | assert(ret); |
5c8f858d | 420 | |
a8ee2b8e YW |
421 | if (hw_addr_equal(hw_addr, &HW_ADDR_NONE)) { |
422 | *ret = HW_ADDR_NULL; | |
aaa5ca57 | 423 | return 0; |
a8ee2b8e | 424 | } |
aaa5ca57 | 425 | |
007899f4 YW |
426 | if (hw_addr->length == 0) { |
427 | uint64_t result; | |
5c8f858d | 428 | |
007899f4 | 429 | /* HardwareAddress= is not specified. */ |
5c8f858d | 430 | |
007899f4 | 431 | if (!NETDEV_VTABLE(netdev)->generate_mac) |
a8ee2b8e | 432 | goto finalize; |
5c8f858d | 433 | |
b90d0f83 | 434 | if (!IN_SET(NETDEV_VTABLE(netdev)->iftype, ARPHRD_ETHER, ARPHRD_INFINIBAND)) |
a8ee2b8e | 435 | goto finalize; |
5c8f858d | 436 | |
007899f4 YW |
437 | r = net_get_unique_predictable_data_from_name(name, &HASH_KEY, &result); |
438 | if (r < 0) { | |
439 | log_netdev_warning_errno(netdev, r, | |
440 | "Failed to generate persistent MAC address, ignoring: %m"); | |
a8ee2b8e | 441 | goto finalize; |
007899f4 | 442 | } |
5c8f858d | 443 | |
007899f4 | 444 | a.length = arphrd_to_hw_addr_len(NETDEV_VTABLE(netdev)->iftype); |
5c8f858d | 445 | |
b90d0f83 YW |
446 | switch (NETDEV_VTABLE(netdev)->iftype) { |
447 | case ARPHRD_ETHER: | |
448 | assert(a.length <= sizeof(result)); | |
449 | memcpy(a.bytes, &result, a.length); | |
450 | ||
451 | if (ether_addr_is_null(&a.ether) || ether_addr_is_broadcast(&a.ether)) { | |
452 | log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL), | |
453 | "Failed to generate persistent MAC address, ignoring: %m"); | |
454 | a = HW_ADDR_NULL; | |
455 | goto finalize; | |
456 | } | |
457 | ||
458 | break; | |
459 | case ARPHRD_INFINIBAND: | |
460 | if (result == 0) { | |
461 | log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL), | |
462 | "Failed to generate persistent MAC address: %m"); | |
463 | goto finalize; | |
464 | } | |
465 | ||
466 | assert(a.length >= sizeof(result)); | |
467 | memzero(a.bytes, a.length - sizeof(result)); | |
468 | memcpy(a.bytes + a.length - sizeof(result), &result, sizeof(result)); | |
469 | break; | |
470 | default: | |
471 | assert_not_reached(); | |
007899f4 | 472 | } |
b90d0f83 | 473 | |
007899f4 YW |
474 | } else { |
475 | a = *hw_addr; | |
45aa0e84 | 476 | is_static = true; |
007899f4 YW |
477 | } |
478 | ||
45aa0e84 | 479 | r = net_verify_hardware_address(name, is_static, NETDEV_VTABLE(netdev)->iftype, |
b90d0f83 | 480 | parent ? &parent->hw_addr : NULL, &a); |
007899f4 YW |
481 | if (r < 0) |
482 | return r; | |
483 | ||
a8ee2b8e YW |
484 | finalize: |
485 | *ret = a; | |
5c8f858d TG |
486 | return 0; |
487 | } | |
488 | ||
0c50cb50 | 489 | static int netdev_create_message(NetDev *netdev, Link *link, sd_netlink_message *m) { |
aa9f1140 TG |
490 | int r; |
491 | ||
28a8cc0a YW |
492 | r = sd_netlink_message_append_string(m, IFLA_IFNAME, netdev->ifname); |
493 | if (r < 0) | |
0c50cb50 | 494 | return r; |
aa9f1140 | 495 | |
0c50cb50 | 496 | struct hw_addr_data hw_addr; |
b90d0f83 | 497 | r = netdev_generate_hw_addr(netdev, link, netdev->ifname, &netdev->hw_addr, &hw_addr); |
a8ee2b8e YW |
498 | if (r < 0) |
499 | return r; | |
500 | ||
501 | if (hw_addr.length > 0) { | |
502 | log_netdev_debug(netdev, "Using MAC address: %s", HW_ADDR_TO_STR(&hw_addr)); | |
503 | r = netlink_message_append_hw_addr(m, IFLA_ADDRESS, &hw_addr); | |
6a7a4e4d | 504 | if (r < 0) |
0c50cb50 | 505 | return r; |
28a8cc0a | 506 | } |
aa9f1140 | 507 | |
28a8cc0a YW |
508 | if (netdev->mtu != 0) { |
509 | r = sd_netlink_message_append_u32(m, IFLA_MTU, netdev->mtu); | |
6a7a4e4d | 510 | if (r < 0) |
0c50cb50 | 511 | return r; |
28a8cc0a | 512 | } |
aa9f1140 | 513 | |
28a8cc0a YW |
514 | if (link) { |
515 | r = sd_netlink_message_append_u32(m, IFLA_LINK, link->ifindex); | |
516 | if (r < 0) | |
0c50cb50 | 517 | return r; |
28a8cc0a | 518 | } |
aa9f1140 | 519 | |
28a8cc0a YW |
520 | r = sd_netlink_message_open_container(m, IFLA_LINKINFO); |
521 | if (r < 0) | |
0c50cb50 | 522 | return r; |
aa9f1140 | 523 | |
28a8cc0a YW |
524 | if (NETDEV_VTABLE(netdev)->fill_message_create) { |
525 | r = sd_netlink_message_open_container_union(m, IFLA_INFO_DATA, netdev_kind_to_string(netdev->kind)); | |
526 | if (r < 0) | |
0c50cb50 | 527 | return r; |
aa9f1140 | 528 | |
28a8cc0a | 529 | r = NETDEV_VTABLE(netdev)->fill_message_create(netdev, link, m); |
6a7a4e4d | 530 | if (r < 0) |
0c50cb50 | 531 | return r; |
aa9f1140 | 532 | |
1c4baffc | 533 | r = sd_netlink_message_close_container(m); |
6a7a4e4d | 534 | if (r < 0) |
0c50cb50 | 535 | return r; |
28a8cc0a YW |
536 | } else { |
537 | r = sd_netlink_message_append_string(m, IFLA_INFO_KIND, netdev_kind_to_string(netdev->kind)); | |
538 | if (r < 0) | |
0c50cb50 | 539 | return r; |
28a8cc0a | 540 | } |
aa9f1140 | 541 | |
28a8cc0a YW |
542 | r = sd_netlink_message_close_container(m); |
543 | if (r < 0) | |
0c50cb50 ZJS |
544 | return r; |
545 | ||
546 | return 0; | |
547 | } | |
548 | ||
b4d6ae63 | 549 | static int independent_netdev_create(NetDev *netdev) { |
0c50cb50 ZJS |
550 | _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL; |
551 | int r; | |
552 | ||
553 | assert(netdev); | |
0c50cb50 ZJS |
554 | |
555 | /* create netdev */ | |
556 | if (NETDEV_VTABLE(netdev)->create) { | |
0c50cb50 ZJS |
557 | r = NETDEV_VTABLE(netdev)->create(netdev); |
558 | if (r < 0) | |
559 | return r; | |
560 | ||
561 | log_netdev_debug(netdev, "Created"); | |
562 | return 0; | |
563 | } | |
564 | ||
565 | r = sd_rtnl_message_new_link(netdev->manager->rtnl, &m, RTM_NEWLINK, 0); | |
566 | if (r < 0) | |
b4d6ae63 | 567 | return r; |
0c50cb50 | 568 | |
b4d6ae63 | 569 | r = netdev_create_message(netdev, NULL, m); |
0c50cb50 | 570 | if (r < 0) |
b4d6ae63 | 571 | return r; |
aa9f1140 | 572 | |
b4d6ae63 YW |
573 | r = netlink_call_async(netdev->manager->rtnl, NULL, m, netdev_create_handler, |
574 | netdev_destroy_callback, netdev); | |
575 | if (r < 0) | |
576 | return r; | |
28a8cc0a | 577 | |
b4d6ae63 | 578 | netdev_ref(netdev); |
aa9f1140 | 579 | |
28a8cc0a | 580 | netdev->state = NETDEV_STATE_CREATING; |
28a8cc0a | 581 | log_netdev_debug(netdev, "Creating"); |
aa9f1140 TG |
582 | return 0; |
583 | } | |
584 | ||
54ff39f7 | 585 | static int stacked_netdev_create(NetDev *netdev, Link *link, Request *req) { |
b4d6ae63 | 586 | _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL; |
aa9f1140 TG |
587 | int r; |
588 | ||
589 | assert(netdev); | |
590 | assert(netdev->manager); | |
b4d6ae63 | 591 | assert(link); |
54ff39f7 | 592 | assert(req); |
aa9f1140 | 593 | |
b4d6ae63 YW |
594 | r = sd_rtnl_message_new_link(netdev->manager->rtnl, &m, RTM_NEWLINK, 0); |
595 | if (r < 0) | |
596 | return r; | |
aa9f1140 | 597 | |
b4d6ae63 YW |
598 | r = netdev_create_message(netdev, link, m); |
599 | if (r < 0) | |
600 | return r; | |
601 | ||
80d62d4f | 602 | r = request_call_netlink_async(netdev->manager->rtnl, m, req); |
b4d6ae63 YW |
603 | if (r < 0) |
604 | return r; | |
605 | ||
b4d6ae63 YW |
606 | netdev->state = NETDEV_STATE_CREATING; |
607 | log_netdev_debug(netdev, "Creating"); | |
aa9f1140 TG |
608 | return 0; |
609 | } | |
610 | ||
e33232d4 | 611 | static bool link_is_ready_to_create_stacked_netdev_one(Link *link, bool allow_unmanaged) { |
00117f88 YW |
612 | assert(link); |
613 | ||
e33232d4 | 614 | if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED, LINK_STATE_UNMANAGED)) |
00117f88 YW |
615 | return false; |
616 | ||
e33232d4 YW |
617 | if (!link->network) |
618 | return allow_unmanaged; | |
619 | ||
00117f88 YW |
620 | if (link->set_link_messages > 0) |
621 | return false; | |
622 | ||
623 | /* If stacked netdevs are created before the underlying interface being activated, then | |
624 | * the activation policy for the netdevs are ignored. See issue #22593. */ | |
625 | if (!link->activated) | |
626 | return false; | |
627 | ||
628 | return true; | |
629 | } | |
630 | ||
e33232d4 YW |
631 | static bool link_is_ready_to_create_stacked_netdev(Link *link) { |
632 | return check_ready_for_all_sr_iov_ports(link, /* allow_unmanaged = */ false, | |
633 | link_is_ready_to_create_stacked_netdev_one); | |
634 | } | |
635 | ||
d708bc6e | 636 | static int netdev_is_ready_to_create(NetDev *netdev, Link *link) { |
71a754f7 | 637 | assert(netdev); |
71a754f7 YW |
638 | |
639 | if (netdev->state != NETDEV_STATE_LOADING) | |
640 | return false; | |
543240f5 | 641 | |
00117f88 YW |
642 | if (link && !link_is_ready_to_create_stacked_netdev(link)) |
643 | return false; | |
71a754f7 | 644 | |
562729d7 YW |
645 | if (NETDEV_VTABLE(netdev)->is_ready_to_create) |
646 | return NETDEV_VTABLE(netdev)->is_ready_to_create(netdev, link); | |
647 | ||
71a754f7 YW |
648 | return true; |
649 | } | |
650 | ||
09d09207 | 651 | static int stacked_netdev_process_request(Request *req, Link *link, void *userdata) { |
ff51134c | 652 | NetDev *netdev = ASSERT_PTR(userdata); |
71a754f7 YW |
653 | int r; |
654 | ||
655 | assert(req); | |
ff51134c | 656 | assert(link); |
b4d6ae63 YW |
657 | |
658 | r = netdev_is_ready_to_create(netdev, link); | |
d708bc6e YW |
659 | if (r <= 0) |
660 | return r; | |
71a754f7 | 661 | |
54ff39f7 | 662 | r = stacked_netdev_create(netdev, link, req); |
71a754f7 | 663 | if (r < 0) |
b4d6ae63 | 664 | return log_netdev_warning_errno(netdev, r, "Failed to create netdev: %m"); |
71a754f7 YW |
665 | |
666 | return 1; | |
667 | } | |
668 | ||
80d62d4f | 669 | static int create_stacked_netdev_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link, void *userdata) { |
71a754f7 YW |
670 | int r; |
671 | ||
672 | assert(m); | |
673 | assert(link); | |
71a754f7 YW |
674 | |
675 | r = sd_netlink_message_get_errno(m); | |
676 | if (r < 0 && r != -EEXIST) { | |
677 | log_link_message_warning_errno(link, m, r, "Could not create stacked netdev"); | |
678 | link_enter_failed(link); | |
679 | return 0; | |
680 | } | |
681 | ||
71a754f7 YW |
682 | if (link->create_stacked_netdev_messages == 0) { |
683 | link->stacked_netdevs_created = true; | |
684 | log_link_debug(link, "Stacked netdevs created."); | |
bb916f35 | 685 | link_check_ready(link); |
71a754f7 YW |
686 | } |
687 | ||
688 | return 0; | |
689 | } | |
690 | ||
b14686ff | 691 | int link_request_stacked_netdev(Link *link, NetDev *netdev) { |
71a754f7 YW |
692 | int r; |
693 | ||
694 | assert(link); | |
695 | assert(netdev); | |
696 | ||
2f117922 | 697 | if (!netdev_is_stacked(netdev)) |
71a754f7 YW |
698 | return -EINVAL; |
699 | ||
2f117922 YW |
700 | if (!IN_SET(netdev->state, NETDEV_STATE_LOADING, NETDEV_STATE_FAILED) || netdev->ifindex > 0) |
701 | return 0; /* Already created. */ | |
71a754f7 | 702 | |
3d24b0dd | 703 | link->stacked_netdevs_created = false; |
09d09207 YW |
704 | r = link_queue_request_full(link, REQUEST_TYPE_NETDEV_STACKED, |
705 | netdev_ref(netdev), (mfree_func_t) netdev_unref, | |
706 | trivial_hash_func, trivial_compare_func, | |
707 | stacked_netdev_process_request, | |
708 | &link->create_stacked_netdev_messages, | |
709 | create_stacked_netdev_handler, NULL); | |
71a754f7 | 710 | if (r < 0) |
b14686ff | 711 | return log_link_error_errno(link, r, "Failed to request stacked netdev '%s': %m", |
71a754f7 YW |
712 | netdev->ifname); |
713 | ||
b14686ff | 714 | log_link_debug(link, "Requested stacked netdev '%s'", netdev->ifname); |
71a754f7 YW |
715 | return 0; |
716 | } | |
717 | ||
09d09207 | 718 | static int independent_netdev_process_request(Request *req, Link *link, void *userdata) { |
ff51134c | 719 | NetDev *netdev = ASSERT_PTR(userdata); |
5d4a925a YW |
720 | int r; |
721 | ||
ff51134c | 722 | assert(!link); |
b4d6ae63 YW |
723 | |
724 | r = netdev_is_ready_to_create(netdev, NULL); | |
5d4a925a YW |
725 | if (r <= 0) |
726 | return r; | |
727 | ||
b4d6ae63 | 728 | r = independent_netdev_create(netdev); |
5d4a925a | 729 | if (r < 0) |
b4d6ae63 | 730 | return log_netdev_warning_errno(netdev, r, "Failed to create netdev: %m"); |
5d4a925a YW |
731 | |
732 | return 1; | |
733 | } | |
734 | ||
b4d6ae63 | 735 | static int netdev_request_to_create(NetDev *netdev) { |
5d4a925a YW |
736 | int r; |
737 | ||
738 | assert(netdev); | |
739 | ||
eae0d010 | 740 | if (netdev_is_stacked(netdev)) |
5d4a925a YW |
741 | return 0; |
742 | ||
743 | r = netdev_is_ready_to_create(netdev, NULL); | |
744 | if (r < 0) | |
745 | return r; | |
b4d6ae63 | 746 | if (r > 0) { |
5d4a925a | 747 | /* If the netdev has no dependency, then create it now. */ |
b4d6ae63 YW |
748 | r = independent_netdev_create(netdev); |
749 | if (r < 0) | |
750 | return log_netdev_warning_errno(netdev, r, "Failed to create netdev: %m"); | |
751 | ||
752 | } else { | |
753 | /* Otherwise, wait for the dependencies being resolved. */ | |
09d09207 | 754 | r = netdev_queue_request(netdev, independent_netdev_process_request, NULL); |
b4d6ae63 | 755 | if (r < 0) |
09d09207 | 756 | return log_netdev_warning_errno(netdev, r, "Failed to request to create netdev: %m"); |
b4d6ae63 | 757 | } |
5d4a925a | 758 | |
b4d6ae63 | 759 | return 0; |
5d4a925a YW |
760 | } |
761 | ||
e27aac11 | 762 | int netdev_load_one(Manager *manager, const char *filename) { |
8e766630 | 763 | _cleanup_(netdev_unrefp) NetDev *netdev_raw = NULL, *netdev = NULL; |
2cc34d5b | 764 | const char *dropin_dirname; |
02b59d57 TG |
765 | int r; |
766 | ||
bf1bc670 TA |
767 | assert(manager); |
768 | assert(filename); | |
769 | ||
4e54a17d | 770 | r = null_or_empty_path(filename); |
4e54a17d | 771 | if (r < 0) |
61ec7bea | 772 | return log_warning_errno(r, "Failed to check if \"%s\" is empty: %m", filename); |
4e54a17d | 773 | if (r > 0) { |
ed88bcfb ZJS |
774 | log_debug("Skipping empty file: %s", filename); |
775 | return 0; | |
776 | } | |
777 | ||
17f9c355 | 778 | netdev_raw = new(NetDev, 1); |
aa9f1140 | 779 | if (!netdev_raw) |
02b59d57 TG |
780 | return log_oom(); |
781 | ||
17f9c355 YW |
782 | *netdev_raw = (NetDev) { |
783 | .n_ref = 1, | |
784 | .kind = _NETDEV_KIND_INVALID, | |
785 | .state = _NETDEV_STATE_INVALID, /* an invalid state means done() of the implementation won't be called on destruction */ | |
786 | }; | |
02b59d57 | 787 | |
281bb5c1 | 788 | dropin_dirname = strjoina(basename(filename), ".d"); |
4f9ff96a | 789 | r = config_parse_many( |
8b8024f1 | 790 | STRV_MAKE_CONST(filename), NETWORK_DIRS, dropin_dirname, |
4f9ff96a LP |
791 | NETDEV_COMMON_SECTIONS NETDEV_OTHER_SECTIONS, |
792 | config_item_perf_lookup, network_netdev_gperf_lookup, | |
793 | CONFIG_PARSE_WARN, | |
794 | netdev_raw, | |
ead3a3fc | 795 | NULL, |
4f9ff96a | 796 | NULL); |
36f822c4 | 797 | if (r < 0) |
61ec7bea | 798 | return r; /* config_parse_many() logs internally. */ |
02b59d57 | 799 | |
2023dc8a | 800 | /* skip out early if configuration does not match the environment */ |
a0b191b7 | 801 | if (!condition_test_list(netdev_raw->conditions, environ, NULL, NULL, NULL)) { |
a6779fec | 802 | log_debug("%s: Conditions in the file do not match the system environment, skipping.", filename); |
2023dc8a | 803 | return 0; |
a6779fec | 804 | } |
2023dc8a | 805 | |
61ec7bea YW |
806 | if (netdev_raw->kind == _NETDEV_KIND_INVALID) |
807 | return log_warning_errno(SYNTHETIC_ERRNO(EINVAL), "NetDev has no Kind= configured in \"%s\", ignoring.", filename); | |
2023dc8a | 808 | |
61ec7bea YW |
809 | if (!netdev_raw->ifname) |
810 | return log_warning_errno(SYNTHETIC_ERRNO(EINVAL), "NetDev without Name= configured in \"%s\", ignoring.", filename); | |
326cb406 | 811 | |
aa9f1140 TG |
812 | netdev = malloc0(NETDEV_VTABLE(netdev_raw)->object_size); |
813 | if (!netdev) | |
814 | return log_oom(); | |
fe6b2d55 | 815 | |
aa9f1140 TG |
816 | netdev->n_ref = 1; |
817 | netdev->manager = manager; | |
aa9f1140 | 818 | netdev->kind = netdev_raw->kind; |
c6e77d7b YW |
819 | netdev->state = NETDEV_STATE_LOADING; /* we initialize the state here for the first time, |
820 | so that done() will be called on destruction */ | |
326cb406 | 821 | |
aa9f1140 TG |
822 | if (NETDEV_VTABLE(netdev)->init) |
823 | NETDEV_VTABLE(netdev)->init(netdev); | |
824 | ||
4f9ff96a | 825 | r = config_parse_many( |
8b8024f1 | 826 | STRV_MAKE_CONST(filename), NETWORK_DIRS, dropin_dirname, |
4f9ff96a LP |
827 | NETDEV_VTABLE(netdev)->sections, |
828 | config_item_perf_lookup, network_netdev_gperf_lookup, | |
829 | CONFIG_PARSE_WARN, | |
ead3a3fc | 830 | netdev, NULL, NULL); |
aa9f1140 | 831 | if (r < 0) |
61ec7bea | 832 | return r; /* config_parse_many() logs internally. */ |
aa9f1140 TG |
833 | |
834 | /* verify configuration */ | |
835 | if (NETDEV_VTABLE(netdev)->config_verify) { | |
836 | r = NETDEV_VTABLE(netdev)->config_verify(netdev, filename); | |
837 | if (r < 0) | |
61ec7bea | 838 | return r; /* config_verify() logs internally. */ |
fe6b2d55 TG |
839 | } |
840 | ||
52433f6b TG |
841 | netdev->filename = strdup(filename); |
842 | if (!netdev->filename) | |
02b59d57 TG |
843 | return log_oom(); |
844 | ||
c26f9a9d SS |
845 | r = hashmap_ensure_put(&netdev->manager->netdevs, &string_hash_ops, netdev->ifname, netdev); |
846 | if (r == -ENOMEM) | |
847 | return log_oom(); | |
b519908c YW |
848 | if (r == -EEXIST) { |
849 | NetDev *n = hashmap_get(netdev->manager->netdevs, netdev->ifname); | |
850 | ||
851 | assert(n); | |
e272b621 YW |
852 | if (!streq(netdev->filename, n->filename)) |
853 | log_netdev_warning_errno(netdev, r, | |
61ec7bea | 854 | "Device was already configured by \"%s\", ignoring %s.", |
74bd6ad0 | 855 | n->filename, netdev->filename); |
b519908c YW |
856 | |
857 | /* Clear ifname before netdev_free() is called. Otherwise, the NetDev object 'n' is | |
858 | * removed from the hashmap 'manager->netdevs'. */ | |
859 | netdev->ifname = mfree(netdev->ifname); | |
61ec7bea | 860 | return -EEXIST; |
b519908c | 861 | } |
61ec7bea | 862 | assert(r > 0); |
02b59d57 | 863 | |
61ec7bea | 864 | log_netdev_debug(netdev, "loaded \"%s\"", netdev_kind_to_string(netdev->kind)); |
3be1d7e0 | 865 | |
b4d6ae63 | 866 | r = netdev_request_to_create(netdev); |
5d4a925a | 867 | if (r < 0) |
61ec7bea | 868 | return r; /* netdev_request_to_create() logs internally. */ |
02b59d57 | 869 | |
5d4a925a | 870 | TAKE_PTR(netdev); |
02b59d57 TG |
871 | return 0; |
872 | } | |
873 | ||
e272b621 | 874 | int netdev_load(Manager *manager, bool reload) { |
6a7a4e4d | 875 | _cleanup_strv_free_ char **files = NULL; |
02b59d57 TG |
876 | int r; |
877 | ||
878 | assert(manager); | |
879 | ||
e272b621 YW |
880 | if (!reload) |
881 | hashmap_clear_with_destructor(manager->netdevs, netdev_unref); | |
02b59d57 | 882 | |
dc0d4078 | 883 | r = conf_files_list_strv(&files, ".netdev", NULL, 0, NETWORK_DIRS); |
f647962d MS |
884 | if (r < 0) |
885 | return log_error_errno(r, "Failed to enumerate netdev files: %m"); | |
02b59d57 | 886 | |
61ec7bea YW |
887 | STRV_FOREACH(f, files) |
888 | (void) netdev_load_one(manager, *f); | |
02b59d57 | 889 | |
02b59d57 TG |
890 | return 0; |
891 | } | |
5dcc5b1a YW |
892 | |
893 | int config_parse_netdev_kind( | |
894 | const char *unit, | |
895 | const char *filename, | |
896 | unsigned line, | |
897 | const char *section, | |
898 | unsigned section_line, | |
899 | const char *lvalue, | |
900 | int ltype, | |
901 | const char *rvalue, | |
902 | void *data, | |
903 | void *userdata) { | |
904 | ||
99534007 | 905 | NetDevKind k, *kind = ASSERT_PTR(data); |
5dcc5b1a YW |
906 | |
907 | assert(filename); | |
908 | assert(rvalue); | |
5dcc5b1a YW |
909 | |
910 | k = netdev_kind_from_string(rvalue); | |
911 | if (k < 0) { | |
912 | log_syntax(unit, LOG_WARNING, filename, line, k, "Failed to parse netdev kind, ignoring assignment: %s", rvalue); | |
913 | return 0; | |
914 | } | |
915 | ||
916 | if (*kind != _NETDEV_KIND_INVALID && *kind != k) { | |
917 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
918 | "Specified netdev kind is different from the previous value '%s', ignoring assignment: %s", | |
919 | netdev_kind_to_string(*kind), rvalue); | |
920 | return 0; | |
921 | } | |
922 | ||
923 | *kind = k; | |
924 | ||
925 | return 0; | |
926 | } | |
aaa5ca57 YW |
927 | |
928 | int config_parse_netdev_hw_addr( | |
929 | const char *unit, | |
930 | const char *filename, | |
931 | unsigned line, | |
932 | const char *section, | |
933 | unsigned section_line, | |
934 | const char *lvalue, | |
935 | int ltype, | |
936 | const char *rvalue, | |
937 | void *data, | |
938 | void *userdata) { | |
939 | ||
99534007 | 940 | struct hw_addr_data *hw_addr = ASSERT_PTR(data); |
aaa5ca57 YW |
941 | |
942 | assert(rvalue); | |
aaa5ca57 YW |
943 | |
944 | if (streq(rvalue, "none")) { | |
945 | *hw_addr = HW_ADDR_NONE; | |
946 | return 0; | |
947 | } | |
948 | ||
949 | return config_parse_hw_addr(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata); | |
950 | } |