1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #include "alloc-util.h"
6 #include "conf-files.h"
7 #include "conf-parser.h"
10 #include "netlink-util.h"
11 #include "network-internal.h"
12 #include "netdev/netdev.h"
13 #include "networkd-manager.h"
14 #include "networkd-link.h"
15 #include "siphash24.h"
16 #include "stat-util.h"
17 #include "string-table.h"
18 #include "string-util.h"
21 #include "netdev/bridge.h"
22 #include "netdev/bond.h"
23 #include "netdev/geneve.h"
24 #include "netdev/vlan.h"
25 #include "netdev/macvlan.h"
26 #include "netdev/ipvlan.h"
27 #include "netdev/vxlan.h"
28 #include "netdev/tunnel.h"
29 #include "netdev/tuntap.h"
30 #include "netdev/veth.h"
31 #include "netdev/dummy.h"
32 #include "netdev/vrf.h"
33 #include "netdev/vcan.h"
34 #include "netdev/vxcan.h"
35 #include "netdev/wireguard.h"
36 #include "netdev/netdevsim.h"
37 #include "netdev/fou-tunnel.h"
39 const NetDevVTable
* const netdev_vtable
[_NETDEV_KIND_MAX
] = {
40 [NETDEV_KIND_BRIDGE
] = &bridge_vtable
,
41 [NETDEV_KIND_BOND
] = &bond_vtable
,
42 [NETDEV_KIND_VLAN
] = &vlan_vtable
,
43 [NETDEV_KIND_MACVLAN
] = &macvlan_vtable
,
44 [NETDEV_KIND_MACVTAP
] = &macvtap_vtable
,
45 [NETDEV_KIND_IPVLAN
] = &ipvlan_vtable
,
46 [NETDEV_KIND_VXLAN
] = &vxlan_vtable
,
47 [NETDEV_KIND_IPIP
] = &ipip_vtable
,
48 [NETDEV_KIND_GRE
] = &gre_vtable
,
49 [NETDEV_KIND_GRETAP
] = &gretap_vtable
,
50 [NETDEV_KIND_IP6GRE
] = &ip6gre_vtable
,
51 [NETDEV_KIND_IP6GRETAP
] = &ip6gretap_vtable
,
52 [NETDEV_KIND_SIT
] = &sit_vtable
,
53 [NETDEV_KIND_VTI
] = &vti_vtable
,
54 [NETDEV_KIND_VTI6
] = &vti6_vtable
,
55 [NETDEV_KIND_VETH
] = &veth_vtable
,
56 [NETDEV_KIND_DUMMY
] = &dummy_vtable
,
57 [NETDEV_KIND_TUN
] = &tun_vtable
,
58 [NETDEV_KIND_TAP
] = &tap_vtable
,
59 [NETDEV_KIND_IP6TNL
] = &ip6tnl_vtable
,
60 [NETDEV_KIND_VRF
] = &vrf_vtable
,
61 [NETDEV_KIND_VCAN
] = &vcan_vtable
,
62 [NETDEV_KIND_GENEVE
] = &geneve_vtable
,
63 [NETDEV_KIND_VXCAN
] = &vxcan_vtable
,
64 [NETDEV_KIND_WIREGUARD
] = &wireguard_vtable
,
65 [NETDEV_KIND_NETDEVSIM
] = &netdevsim_vtable
,
66 [NETDEV_KIND_FOU
] = &foutnl_vtable
,
67 [NETDEV_KIND_ERSPAN
] = &erspan_vtable
,
70 static const char* const netdev_kind_table
[_NETDEV_KIND_MAX
] = {
71 [NETDEV_KIND_BRIDGE
] = "bridge",
72 [NETDEV_KIND_BOND
] = "bond",
73 [NETDEV_KIND_VLAN
] = "vlan",
74 [NETDEV_KIND_MACVLAN
] = "macvlan",
75 [NETDEV_KIND_MACVTAP
] = "macvtap",
76 [NETDEV_KIND_IPVLAN
] = "ipvlan",
77 [NETDEV_KIND_VXLAN
] = "vxlan",
78 [NETDEV_KIND_IPIP
] = "ipip",
79 [NETDEV_KIND_GRE
] = "gre",
80 [NETDEV_KIND_GRETAP
] = "gretap",
81 [NETDEV_KIND_IP6GRE
] = "ip6gre",
82 [NETDEV_KIND_IP6GRETAP
] = "ip6gretap",
83 [NETDEV_KIND_SIT
] = "sit",
84 [NETDEV_KIND_VETH
] = "veth",
85 [NETDEV_KIND_VTI
] = "vti",
86 [NETDEV_KIND_VTI6
] = "vti6",
87 [NETDEV_KIND_DUMMY
] = "dummy",
88 [NETDEV_KIND_TUN
] = "tun",
89 [NETDEV_KIND_TAP
] = "tap",
90 [NETDEV_KIND_IP6TNL
] = "ip6tnl",
91 [NETDEV_KIND_VRF
] = "vrf",
92 [NETDEV_KIND_VCAN
] = "vcan",
93 [NETDEV_KIND_GENEVE
] = "geneve",
94 [NETDEV_KIND_VXCAN
] = "vxcan",
95 [NETDEV_KIND_WIREGUARD
] = "wireguard",
96 [NETDEV_KIND_NETDEVSIM
] = "netdevsim",
97 [NETDEV_KIND_FOU
] = "fou",
98 [NETDEV_KIND_ERSPAN
] = "erspan",
101 DEFINE_STRING_TABLE_LOOKUP(netdev_kind
, NetDevKind
);
103 int config_parse_netdev_kind(
105 const char *filename
,
108 unsigned section_line
,
115 NetDevKind k
, *kind
= data
;
120 k
= netdev_kind_from_string(rvalue
);
122 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse netdev kind, ignoring assignment: %s", rvalue
);
126 if (*kind
!= _NETDEV_KIND_INVALID
&& *kind
!= k
) {
127 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
128 "Specified netdev kind is different from the previous value '%s', ignoring assignment: %s",
129 netdev_kind_to_string(*kind
), rvalue
);
138 static void netdev_callbacks_clear(NetDev
*netdev
) {
139 netdev_join_callback
*callback
;
144 while ((callback
= netdev
->callbacks
)) {
145 LIST_REMOVE(callbacks
, netdev
->callbacks
, callback
);
146 link_unref(callback
->link
);
151 static void netdev_detach_from_manager(NetDev
*netdev
) {
152 if (netdev
->ifname
&& netdev
->manager
)
153 hashmap_remove(netdev
->manager
->netdevs
, netdev
->ifname
);
155 netdev
->manager
= NULL
;
158 static NetDev
*netdev_free(NetDev
*netdev
) {
161 netdev_callbacks_clear(netdev
);
163 netdev_detach_from_manager(netdev
);
165 free(netdev
->filename
);
167 free(netdev
->description
);
168 free(netdev
->ifname
);
171 condition_free_list(netdev
->match_host
);
172 condition_free_list(netdev
->match_virt
);
173 condition_free_list(netdev
->match_kernel_cmdline
);
174 condition_free_list(netdev
->match_kernel_version
);
175 condition_free_list(netdev
->match_arch
);
177 /* Invoke the per-kind done() destructor, but only if the state field is initialized. We conditionalize that
178 * because we parse .netdev files twice: once to determine the kind (with a short, minimal NetDev structure
179 * allocation, with no room for per-kind fields), and once to read the kind's properties (with a full,
180 * comprehensive NetDev structure allocation with enough space for whatever the specific kind needs). Now, in
181 * the first case we shouldn't try to destruct the per-kind NetDev fields on destruction, in the second case we
182 * should. We use the state field to discern the two cases: it's _NETDEV_STATE_INVALID on the first "raw"
184 if (netdev
->state
!= _NETDEV_STATE_INVALID
&&
185 NETDEV_VTABLE(netdev
) &&
186 NETDEV_VTABLE(netdev
)->done
)
187 NETDEV_VTABLE(netdev
)->done(netdev
);
189 return mfree(netdev
);
192 DEFINE_TRIVIAL_REF_UNREF_FUNC(NetDev
, netdev
, netdev_free
);
194 void netdev_drop(NetDev
*netdev
) {
195 if (!netdev
|| netdev
->state
== NETDEV_STATE_LINGER
)
198 netdev
->state
= NETDEV_STATE_LINGER
;
200 log_netdev_debug(netdev
, "netdev removed");
202 netdev_callbacks_clear(netdev
);
204 netdev_detach_from_manager(netdev
);
206 netdev_unref(netdev
);
211 int netdev_get(Manager
*manager
, const char *name
, NetDev
**ret
) {
218 netdev
= hashmap_get(manager
->netdevs
, name
);
229 static int netdev_enter_failed(NetDev
*netdev
) {
230 netdev
->state
= NETDEV_STATE_FAILED
;
232 netdev_callbacks_clear(netdev
);
237 static int netdev_enslave_ready(NetDev
*netdev
, Link
* link
, link_netlink_message_handler_t callback
) {
238 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
242 assert(netdev
->state
== NETDEV_STATE_READY
);
243 assert(netdev
->manager
);
244 assert(netdev
->manager
->rtnl
);
245 assert(IN_SET(netdev
->kind
, NETDEV_KIND_BRIDGE
, NETDEV_KIND_BOND
, NETDEV_KIND_VRF
));
249 if (link
->flags
& IFF_UP
&& netdev
->kind
== NETDEV_KIND_BOND
) {
250 log_netdev_debug(netdev
, "Link '%s' was up when attempting to enslave it. Bringing link down.", link
->ifname
);
253 return log_netdev_error_errno(netdev
, r
, "Could not bring link down: %m");
256 r
= sd_rtnl_message_new_link(netdev
->manager
->rtnl
, &req
, RTM_SETLINK
, link
->ifindex
);
258 return log_netdev_error_errno(netdev
, r
, "Could not allocate RTM_SETLINK message: %m");
260 r
= sd_netlink_message_append_u32(req
, IFLA_MASTER
, netdev
->ifindex
);
262 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_MASTER attribute: %m");
264 r
= netlink_call_async(netdev
->manager
->rtnl
, NULL
, req
, callback
,
265 link_netlink_destroy_callback
, link
);
267 return log_netdev_error_errno(netdev
, r
, "Could not send rtnetlink message: %m");
271 log_netdev_debug(netdev
, "Enslaving link '%s'", link
->ifname
);
276 static int netdev_enter_ready(NetDev
*netdev
) {
277 netdev_join_callback
*callback
, *callback_next
;
281 assert(netdev
->ifname
);
283 if (netdev
->state
!= NETDEV_STATE_CREATING
)
286 netdev
->state
= NETDEV_STATE_READY
;
288 log_netdev_info(netdev
, "netdev ready");
290 LIST_FOREACH_SAFE(callbacks
, callback
, callback_next
, netdev
->callbacks
) {
291 /* enslave the links that were attempted to be enslaved before the
293 r
= netdev_enslave_ready(netdev
, callback
->link
, callback
->callback
);
297 LIST_REMOVE(callbacks
, netdev
->callbacks
, callback
);
298 link_unref(callback
->link
);
302 if (NETDEV_VTABLE(netdev
)->post_create
)
303 NETDEV_VTABLE(netdev
)->post_create(netdev
, NULL
, NULL
);
308 /* callback for netdev's created without a backing Link */
309 static int netdev_create_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, NetDev
*netdev
) {
313 assert(netdev
->state
!= _NETDEV_STATE_INVALID
);
315 r
= sd_netlink_message_get_errno(m
);
317 log_netdev_info(netdev
, "netdev exists, using existing without changing its parameters");
319 log_netdev_warning_errno(netdev
, r
, "netdev could not be created: %m");
325 log_netdev_debug(netdev
, "Created");
330 static int netdev_enslave(NetDev
*netdev
, Link
*link
, link_netlink_message_handler_t callback
) {
334 assert(netdev
->manager
);
335 assert(netdev
->manager
->rtnl
);
336 assert(IN_SET(netdev
->kind
, NETDEV_KIND_BRIDGE
, NETDEV_KIND_BOND
, NETDEV_KIND_VRF
));
338 if (netdev
->state
== NETDEV_STATE_READY
) {
339 r
= netdev_enslave_ready(netdev
, link
, callback
);
342 } else if (IN_SET(netdev
->state
, NETDEV_STATE_LINGER
, NETDEV_STATE_FAILED
)) {
343 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*m
= NULL
;
345 r
= rtnl_message_new_synthetic_error(netdev
->manager
->rtnl
, -ENODEV
, 0, &m
);
347 callback(netdev
->manager
->rtnl
, m
, link
);
349 /* the netdev is not yet read, save this request for when it is */
350 netdev_join_callback
*cb
;
352 cb
= new(netdev_join_callback
, 1);
356 *cb
= (netdev_join_callback
) {
357 .callback
= callback
,
358 .link
= link_ref(link
),
361 LIST_PREPEND(callbacks
, netdev
->callbacks
, cb
);
363 log_netdev_debug(netdev
, "Will enslave '%s', when ready", link
->ifname
);
369 int netdev_set_ifindex(NetDev
*netdev
, sd_netlink_message
*message
) {
372 const char *received_kind
;
373 const char *received_name
;
379 r
= sd_netlink_message_get_type(message
, &type
);
381 return log_netdev_error_errno(netdev
, r
, "Could not get rtnl message type: %m");
383 if (type
!= RTM_NEWLINK
) {
384 log_netdev_error(netdev
, "Cannot set ifindex from unexpected rtnl message type.");
388 r
= sd_rtnl_message_link_get_ifindex(message
, &ifindex
);
390 log_netdev_error_errno(netdev
, r
, "Could not get ifindex: %m");
391 netdev_enter_failed(netdev
);
393 } else if (ifindex
<= 0) {
394 log_netdev_error(netdev
, "Got invalid ifindex: %d", ifindex
);
395 netdev_enter_failed(netdev
);
399 if (netdev
->ifindex
> 0) {
400 if (netdev
->ifindex
!= ifindex
) {
401 log_netdev_error(netdev
, "Could not set ifindex to %d, already set to %d",
402 ifindex
, netdev
->ifindex
);
403 netdev_enter_failed(netdev
);
406 /* ifindex already set to the same for this netdev */
410 r
= sd_netlink_message_read_string(message
, IFLA_IFNAME
, &received_name
);
412 return log_netdev_error_errno(netdev
, r
, "Could not get IFNAME: %m");
414 if (!streq(netdev
->ifname
, received_name
)) {
415 log_netdev_error(netdev
, "Received newlink with wrong IFNAME %s", received_name
);
416 netdev_enter_failed(netdev
);
420 r
= sd_netlink_message_enter_container(message
, IFLA_LINKINFO
);
422 return log_netdev_error_errno(netdev
, r
, "Could not get LINKINFO: %m");
424 r
= sd_netlink_message_read_string(message
, IFLA_INFO_KIND
, &received_kind
);
426 return log_netdev_error_errno(netdev
, r
, "Could not get KIND: %m");
428 r
= sd_netlink_message_exit_container(message
);
430 return log_netdev_error_errno(netdev
, r
, "Could not exit container: %m");
432 if (netdev
->kind
== NETDEV_KIND_TAP
)
433 /* the kernel does not distinguish between tun and tap */
436 kind
= netdev_kind_to_string(netdev
->kind
);
438 log_netdev_error(netdev
, "Could not get kind");
439 netdev_enter_failed(netdev
);
444 if (!streq(kind
, received_kind
)) {
445 log_netdev_error(netdev
,
446 "Received newlink with wrong KIND %s, "
447 "expected %s", received_kind
, kind
);
448 netdev_enter_failed(netdev
);
452 netdev
->ifindex
= ifindex
;
454 log_netdev_debug(netdev
, "netdev has index %d", netdev
->ifindex
);
456 netdev_enter_ready(netdev
);
461 #define HASH_KEY SD_ID128_MAKE(52,e1,45,bd,00,6f,29,96,21,c6,30,6d,83,71,04,48)
463 int netdev_get_mac(const char *ifname
, struct ether_addr
**ret
) {
464 _cleanup_free_
struct ether_addr
*mac
= NULL
;
473 mac
= new0(struct ether_addr
, 1);
478 sz
= sizeof(sd_id128_t
) + l
;
481 /* fetch some persistent data unique to the machine */
482 r
= sd_id128_get_machine((sd_id128_t
*) v
);
486 /* combine with some data unique (on this machine) to this
488 memcpy(v
+ sizeof(sd_id128_t
), ifname
, l
);
490 /* Let's hash the host machine ID plus the container name. We
491 * use a fixed, but originally randomly created hash key here. */
492 result
= siphash24(v
, sz
, HASH_KEY
.bytes
);
494 assert_cc(ETH_ALEN
<= sizeof(result
));
495 memcpy(mac
->ether_addr_octet
, &result
, ETH_ALEN
);
497 /* see eth_random_addr in the kernel */
498 mac
->ether_addr_octet
[0] &= 0xfe; /* clear multicast bit */
499 mac
->ether_addr_octet
[0] |= 0x02; /* set local assignment bit (IEEE802) */
501 *ret
= TAKE_PTR(mac
);
506 static int netdev_create(NetDev
*netdev
, Link
*link
, link_netlink_message_handler_t callback
) {
510 assert(!link
|| callback
);
513 if (NETDEV_VTABLE(netdev
)->create
) {
516 r
= NETDEV_VTABLE(netdev
)->create(netdev
);
520 log_netdev_debug(netdev
, "Created");
522 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*m
= NULL
;
524 r
= sd_rtnl_message_new_link(netdev
->manager
->rtnl
, &m
, RTM_NEWLINK
, 0);
526 return log_netdev_error_errno(netdev
, r
, "Could not allocate RTM_NEWLINK message: %m");
528 r
= sd_netlink_message_append_string(m
, IFLA_IFNAME
, netdev
->ifname
);
530 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_IFNAME, attribute: %m");
533 r
= sd_netlink_message_append_ether_addr(m
, IFLA_ADDRESS
, netdev
->mac
);
535 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_ADDRESS attribute: %m");
539 r
= sd_netlink_message_append_u32(m
, IFLA_MTU
, netdev
->mtu
);
541 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_MTU attribute: %m");
545 r
= sd_netlink_message_append_u32(m
, IFLA_LINK
, link
->ifindex
);
547 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_LINK attribute: %m");
550 r
= sd_netlink_message_open_container(m
, IFLA_LINKINFO
);
552 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_LINKINFO attribute: %m");
554 r
= sd_netlink_message_open_container_union(m
, IFLA_INFO_DATA
, netdev_kind_to_string(netdev
->kind
));
556 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_INFO_DATA attribute: %m");
558 if (NETDEV_VTABLE(netdev
)->fill_message_create
) {
559 r
= NETDEV_VTABLE(netdev
)->fill_message_create(netdev
, link
, m
);
564 r
= sd_netlink_message_close_container(m
);
566 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_INFO_DATA attribute: %m");
568 r
= sd_netlink_message_close_container(m
);
570 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_LINKINFO attribute: %m");
573 r
= netlink_call_async(netdev
->manager
->rtnl
, NULL
, m
, callback
,
574 link_netlink_destroy_callback
, link
);
576 return log_netdev_error_errno(netdev
, r
, "Could not send rtnetlink message: %m");
580 r
= netlink_call_async(netdev
->manager
->rtnl
, NULL
, m
, netdev_create_handler
,
581 netdev_destroy_callback
, netdev
);
583 return log_netdev_error_errno(netdev
, r
, "Could not send rtnetlink message: %m");
588 netdev
->state
= NETDEV_STATE_CREATING
;
590 log_netdev_debug(netdev
, "Creating");
596 /* the callback must be called, possibly after a timeout, as otherwise the Link will hang */
597 int netdev_join(NetDev
*netdev
, Link
*link
, link_netlink_message_handler_t callback
) {
601 assert(netdev
->manager
);
602 assert(netdev
->manager
->rtnl
);
603 assert(NETDEV_VTABLE(netdev
));
605 switch (NETDEV_VTABLE(netdev
)->create_type
) {
606 case NETDEV_CREATE_MASTER
:
607 r
= netdev_enslave(netdev
, link
, callback
);
612 case NETDEV_CREATE_STACKED
:
613 r
= netdev_create(netdev
, link
, callback
);
619 assert_not_reached("Can not join independent netdev");
625 int netdev_load_one(Manager
*manager
, const char *filename
) {
626 _cleanup_(netdev_unrefp
) NetDev
*netdev_raw
= NULL
, *netdev
= NULL
;
627 _cleanup_fclose_
FILE *file
= NULL
;
628 const char *dropin_dirname
;
629 bool independent
= false;
635 file
= fopen(filename
, "re");
643 if (null_or_empty_fd(fileno(file
))) {
644 log_debug("Skipping empty file: %s", filename
);
648 netdev_raw
= new(NetDev
, 1);
652 *netdev_raw
= (NetDev
) {
654 .kind
= _NETDEV_KIND_INVALID
,
655 .state
= _NETDEV_STATE_INVALID
, /* an invalid state means done() of the implementation won't be called on destruction */
658 dropin_dirname
= strjoina(basename(filename
), ".d");
659 r
= config_parse_many(filename
, network_dirs
, dropin_dirname
,
661 config_item_perf_lookup
, network_netdev_gperf_lookup
,
662 CONFIG_PARSE_WARN
|CONFIG_PARSE_RELAXED
, netdev_raw
);
666 /* skip out early if configuration does not match the environment */
667 if (net_match_config(NULL
, NULL
, NULL
, NULL
, NULL
,
668 netdev_raw
->match_host
, netdev_raw
->match_virt
,
669 netdev_raw
->match_kernel_cmdline
, netdev_raw
->match_kernel_version
,
670 netdev_raw
->match_arch
,
671 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
) <= 0)
674 if (netdev_raw
->kind
== _NETDEV_KIND_INVALID
) {
675 log_warning("NetDev has no Kind configured in %s. Ignoring", filename
);
679 if (!netdev_raw
->ifname
) {
680 log_warning("NetDev without Name configured in %s. Ignoring", filename
);
684 r
= fseek(file
, 0, SEEK_SET
);
688 netdev
= malloc0(NETDEV_VTABLE(netdev_raw
)->object_size
);
693 netdev
->manager
= manager
;
694 netdev
->kind
= netdev_raw
->kind
;
695 netdev
->state
= NETDEV_STATE_LOADING
; /* we initialize the state here for the first time, so that done() will be called on destruction */
697 if (NETDEV_VTABLE(netdev
)->init
)
698 NETDEV_VTABLE(netdev
)->init(netdev
);
700 r
= config_parse_many(filename
, network_dirs
, dropin_dirname
,
701 NETDEV_VTABLE(netdev
)->sections
,
702 config_item_perf_lookup
, network_netdev_gperf_lookup
,
703 CONFIG_PARSE_WARN
, netdev
);
707 /* verify configuration */
708 if (NETDEV_VTABLE(netdev
)->config_verify
) {
709 r
= NETDEV_VTABLE(netdev
)->config_verify(netdev
, filename
);
714 netdev
->filename
= strdup(filename
);
715 if (!netdev
->filename
)
718 if (!netdev
->mac
&& netdev
->kind
!= NETDEV_KIND_VLAN
) {
719 r
= netdev_get_mac(netdev
->ifname
, &netdev
->mac
);
721 return log_error_errno(r
, "Failed to generate predictable MAC address for %s: %m", netdev
->ifname
);
724 r
= hashmap_ensure_allocated(&netdev
->manager
->netdevs
, &string_hash_ops
);
728 r
= hashmap_put(netdev
->manager
->netdevs
, netdev
->ifname
, netdev
);
732 LIST_HEAD_INIT(netdev
->callbacks
);
734 log_netdev_debug(netdev
, "loaded %s", netdev_kind_to_string(netdev
->kind
));
736 switch (NETDEV_VTABLE(netdev
)->create_type
) {
737 case NETDEV_CREATE_MASTER
:
738 case NETDEV_CREATE_INDEPENDENT
:
739 r
= netdev_create(netdev
, NULL
, NULL
);
748 switch (netdev
->kind
) {
749 case NETDEV_KIND_IPIP
:
750 independent
= IPIP(netdev
)->independent
;
752 case NETDEV_KIND_GRE
:
753 independent
= GRE(netdev
)->independent
;
755 case NETDEV_KIND_GRETAP
:
756 independent
= GRETAP(netdev
)->independent
;
758 case NETDEV_KIND_IP6GRE
:
759 independent
= IP6GRE(netdev
)->independent
;
761 case NETDEV_KIND_IP6GRETAP
:
762 independent
= IP6GRETAP(netdev
)->independent
;
764 case NETDEV_KIND_SIT
:
765 independent
= SIT(netdev
)->independent
;
767 case NETDEV_KIND_VTI
:
768 independent
= VTI(netdev
)->independent
;
770 case NETDEV_KIND_VTI6
:
771 independent
= VTI6(netdev
)->independent
;
773 case NETDEV_KIND_IP6TNL
:
774 independent
= IP6TNL(netdev
)->independent
;
781 r
= netdev_create(netdev
, NULL
, NULL
);
791 int netdev_load(Manager
*manager
) {
792 _cleanup_strv_free_
char **files
= NULL
;
798 hashmap_clear_with_destructor(manager
->netdevs
, netdev_unref
);
800 r
= conf_files_list_strv(&files
, ".netdev", NULL
, 0, network_dirs
);
802 return log_error_errno(r
, "Failed to enumerate netdev files: %m");
804 STRV_FOREACH_BACKWARDS(f
, files
) {
805 r
= netdev_load_one(manager
, *f
);