diff options
-rw-r--r-- | src/network/networkd-dhcp4.c | 12 | ||||
-rw-r--r-- | src/network/networkd-dhcp4.h | 1 | ||||
-rw-r--r-- | src/network/networkd-dhcp6.c | 25 | ||||
-rw-r--r-- | src/network/networkd-ipv4ll.c | 5 | ||||
-rw-r--r-- | src/network/networkd-link.c | 69 | ||||
-rw-r--r-- | src/network/networkd-lldp-rx.c | 21 | ||||
-rw-r--r-- | src/network/networkd-lldp-rx.h | 3 | ||||
-rw-r--r-- | src/network/networkd-lldp-tx.c | 2 | ||||
-rw-r--r-- | src/network/networkd-ndisc.c | 17 |
9 files changed, 74 insertions, 81 deletions
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index c8f4f4bf61..a20f06d6c3 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -1157,12 +1157,10 @@ static bool promote_secondaries_enabled(const char *ifname) { * the primary one expires it relies on the kernel to promote the * secondary IP. See also https://github.com/systemd/systemd/issues/7163 */ -int dhcp4_set_promote_secondaries(Link *link) { +static int dhcp4_set_promote_secondaries(Link *link) { int r; assert(link); - assert(link->network); - assert(link->network->dhcp & ADDRESS_FAMILY_IPV4); /* check if the kernel has promote_secondaries enabled for our * interface. If it is not globally enabled or enabled for the @@ -1267,7 +1265,13 @@ int dhcp4_configure(Link *link) { assert(link); assert(link->network); - assert(link->network->dhcp & ADDRESS_FAMILY_IPV4); + + if (!link_dhcp4_enabled(link)) + return 0; + + r = dhcp4_set_promote_secondaries(link); + if (r < 0) + return r; r = dhcp4_init(link); if (r < 0) diff --git a/src/network/networkd-dhcp4.h b/src/network/networkd-dhcp4.h index ee3b4f1288..8aa6ac9453 100644 --- a/src/network/networkd-dhcp4.h +++ b/src/network/networkd-dhcp4.h @@ -19,7 +19,6 @@ typedef enum DHCPClientIdentifier { int dhcp4_configure(Link *link); int dhcp4_update_mac(Link *link); -int dhcp4_set_promote_secondaries(Link *link); int link_deserialize_dhcp4(Link *link, const char *dhcp4_address); diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c index 5724d083fc..ce9f6ac300 100644 --- a/src/network/networkd-dhcp6.c +++ b/src/network/networkd-dhcp6.c @@ -25,6 +25,15 @@ #include "radv-internal.h" #include "web-util.h" +bool link_dhcp6_pd_is_enabled(Link *link) { + assert(link); + + if (!link->network) + return false; + + return link->network->router_prefix_delegation & RADV_PREFIX_DELEGATION_DHCP6; +} + static bool dhcp6_lease_has_pd_prefix(sd_dhcp6_lease *lease) { uint32_t lifetime_preferred, lifetime_valid; union in_addr_union pd_prefix; @@ -181,6 +190,9 @@ int dhcp6_pd_remove(Link *link) { assert(link); assert(link->manager); + if (!link_dhcp6_pd_is_enabled(link)) + return 0; + link->dhcp6_pd_address_configured = false; link->dhcp6_pd_route_configured = false; @@ -426,13 +438,6 @@ static int dhcp6_pd_assign_prefix(Link *link, const union in_addr_union *prefix, return 0; } -bool link_dhcp6_pd_is_enabled(Link *link) { - if (!link->network) - return false; - - return link->network->router_prefix_delegation & RADV_PREFIX_DELEGATION_DHCP6; -} - static bool link_has_preferred_subnet_id(Link *link) { if (!link->network) return false; @@ -644,9 +649,6 @@ static void dhcp6_pd_prefix_lost(Link *dhcp6_link) { if (link == dhcp6_link) continue; - if (!link_dhcp6_pd_is_enabled(link)) - continue; - r = dhcp6_pd_remove(link); if (r < 0) link_enter_failed(link); @@ -1386,6 +1388,9 @@ int dhcp6_configure(Link *link) { assert(link); assert(link->network); + if (!link_dhcp6_enabled(link) && !link_ipv6_accept_ra_enabled(link)) + return 0; + if (link->dhcp6_client) return 0; diff --git a/src/network/networkd-ipv4ll.c b/src/network/networkd-ipv4ll.c index 706393b2f2..b0e0a97ad8 100644 --- a/src/network/networkd-ipv4ll.c +++ b/src/network/networkd-ipv4ll.c @@ -166,8 +166,9 @@ int ipv4ll_configure(Link *link) { int r; assert(link); - assert(link->network); - assert(link->network->link_local & (ADDRESS_FAMILY_IPV4 | ADDRESS_FAMILY_FALLBACK_IPV4)); + + if (!link_ipv4ll_enabled(link, ADDRESS_FAMILY_IPV4 | ADDRESS_FAMILY_FALLBACK_IPV4)) + return 0; r = ipv4ll_init(link); if (r < 0) diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 53242d8e0f..b8145ea651 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -638,11 +638,9 @@ int link_stop_clients(Link *link, bool may_keep_dhcp) { r = log_link_warning_errno(link, k, "Could not stop DHCPv6 client: %m"); } - if (link_dhcp6_pd_is_enabled(link)) { - k = dhcp6_pd_remove(link); - if (k < 0) - r = log_link_warning_errno(link, k, "Could not remove DHCPv6 PD addresses and routes: %m"); - } + k = dhcp6_pd_remove(link); + if (k < 0) + r = log_link_warning_errno(link, k, "Could not remove DHCPv6 PD addresses and routes: %m"); if (link->ndisc) { k = sd_ndisc_stop(link->ndisc); @@ -1072,9 +1070,7 @@ static int link_acquire_ipv6_conf(Link *link) { assert(link); - if (link_ipv6_accept_ra_enabled(link)) { - assert(link->ndisc); - + if (link->ndisc) { log_link_debug(link, "Discovering IPv6 routers"); r = sd_ndisc_start(link->ndisc); @@ -1134,9 +1130,7 @@ static int link_acquire_ipv4_conf(Link *link) { return log_link_warning_errno(link, r, "Could not acquire IPv4 link-local address: %m"); } - if (link_dhcp4_enabled(link)) { - assert(link->dhcp_client); - + if (link->dhcp_client) { log_link_debug(link, "Acquiring DHCPv4 lease"); r = sd_dhcp_client_start(link->dhcp_client); @@ -1162,11 +1156,9 @@ static int link_acquire_conf(Link *link) { return r; } - if (link_lldp_emit_enabled(link)) { - r = link_lldp_emit_start(link); - if (r < 0) - return log_link_warning_errno(link, r, "Failed to start LLDP transmission: %m"); - } + r = link_lldp_emit_start(link); + if (r < 0) + return log_link_warning_errno(link, r, "Failed to start LLDP transmission: %m"); return 0; } @@ -1974,44 +1966,29 @@ int link_configure(Link *link) { if (r < 0) return r; - if (link_ipv4ll_enabled(link, ADDRESS_FAMILY_IPV4 | ADDRESS_FAMILY_FALLBACK_IPV4)) { - r = ipv4ll_configure(link); - if (r < 0) - return r; - } - - if (link_dhcp4_enabled(link)) { - r = dhcp4_set_promote_secondaries(link); - if (r < 0) - return r; + r = ipv4ll_configure(link); + if (r < 0) + return r; - r = dhcp4_configure(link); - if (r < 0) - return r; - } + r = dhcp4_configure(link); + if (r < 0) + return r; - if (link_dhcp6_enabled(link) || - link_ipv6_accept_ra_enabled(link)) { - r = dhcp6_configure(link); - if (r < 0) - return r; - } + r = dhcp6_configure(link); + if (r < 0) + return r; - if (link_ipv6_accept_ra_enabled(link)) { - r = ndisc_configure(link); - if (r < 0) - return r; - } + r = ndisc_configure(link); + if (r < 0) + return r; r = radv_configure(link); if (r < 0) return r; - if (link_lldp_rx_enabled(link)) { - r = link_lldp_rx_configure(link); - if (r < 0) - return r; - } + r = link_lldp_rx_configure(link); + if (r < 0) + return r; r = link_configure_mtu(link); if (r < 0) diff --git a/src/network/networkd-lldp-rx.c b/src/network/networkd-lldp-rx.c index fe88777977..a97bdeda19 100644 --- a/src/network/networkd-lldp-rx.c +++ b/src/network/networkd-lldp-rx.c @@ -25,7 +25,7 @@ static const char* const lldp_mode_table[_LLDP_MODE_MAX] = { DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(lldp_mode, LLDPMode, LLDP_MODE_YES); -bool link_lldp_rx_enabled(Link *link) { +static bool link_lldp_rx_enabled(Link *link) { assert(link); if (link->flags & IFF_LOOPBACK) @@ -68,9 +68,18 @@ static void lldp_handler(sd_lldp *lldp, sd_lldp_event event, sd_lldp_neighbor *n int link_lldp_rx_configure(Link *link) { int r; - r = sd_lldp_new(&link->lldp); - if (r < 0) - return r; + if (!link_lldp_rx_enabled(link)) + return 0; + + if (!link->lldp) { + r = sd_lldp_new(&link->lldp); + if (r < 0) + return r; + + r = sd_lldp_attach_event(link->lldp, NULL, 0); + if (r < 0) + return r; + } r = sd_lldp_set_ifindex(link->lldp, link->ifindex); if (r < 0) @@ -87,10 +96,6 @@ int link_lldp_rx_configure(Link *link) { if (r < 0) return r; - r = sd_lldp_attach_event(link->lldp, NULL, 0); - if (r < 0) - return r; - r = sd_lldp_set_callback(link->lldp, lldp_handler, link); if (r < 0) return r; diff --git a/src/network/networkd-lldp-rx.h b/src/network/networkd-lldp-rx.h index 12f512f628..8e1a6a0b62 100644 --- a/src/network/networkd-lldp-rx.h +++ b/src/network/networkd-lldp-rx.h @@ -1,8 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once -#include <stdbool.h> - #include "conf-parser.h" typedef struct Link Link; @@ -15,7 +13,6 @@ typedef enum LLDPMode { _LLDP_MODE_INVALID = -1, } LLDPMode; -bool link_lldp_rx_enabled(Link *link); int link_lldp_rx_configure(Link *link); int link_update_lldp(Link *link); int link_lldp_save(Link *link); diff --git a/src/network/networkd-lldp-tx.c b/src/network/networkd-lldp-tx.c index 2be7c27e18..c8e56a5fec 100644 --- a/src/network/networkd-lldp-tx.c +++ b/src/network/networkd-lldp-tx.c @@ -367,7 +367,7 @@ int link_lldp_emit_start(Link *link) { assert(link); - if (!link->network || link->network->lldp_emit == LLDP_EMIT_NO) { + if (!link_lldp_emit_enabled(link)) { link_lldp_emit_stop(link); return 0; } diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c index 0e42e768da..a60c42528b 100644 --- a/src/network/networkd-ndisc.c +++ b/src/network/networkd-ndisc.c @@ -1226,13 +1226,18 @@ int ndisc_configure(Link *link) { assert(link); - r = sd_ndisc_new(&link->ndisc); - if (r < 0) - return r; + if (!link_ipv6_accept_ra_enabled(link)) + return 0; - r = sd_ndisc_attach_event(link->ndisc, NULL, 0); - if (r < 0) - return r; + if (!link->ndisc) { + r = sd_ndisc_new(&link->ndisc); + if (r < 0) + return r; + + r = sd_ndisc_attach_event(link->ndisc, NULL, 0); + if (r < 0) + return r; + } r = sd_ndisc_set_mac(link->ndisc, &link->mac); if (r < 0) |