1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 02:21:44 +03:00

network: check feature is enabled in xxx_configure()

This commit is contained in:
Yu Watanabe 2020-10-04 07:37:22 +09:00
parent 51f5dfd8ba
commit 2ffd6d73f9
9 changed files with 74 additions and 81 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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;

View File

@ -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)

View File

@ -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");
}
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");
}
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 = 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;
}
if (link_ipv6_accept_ra_enabled(link)) {
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_configure_mtu(link);
if (r < 0)

View File

@ -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,10 +68,19 @@ static void lldp_handler(sd_lldp *lldp, sd_lldp_event event, sd_lldp_neighbor *n
int link_lldp_rx_configure(Link *link) {
int 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)
return r;
@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -1226,6 +1226,10 @@ int ndisc_configure(Link *link) {
assert(link);
if (!link_ipv6_accept_ra_enabled(link))
return 0;
if (!link->ndisc) {
r = sd_ndisc_new(&link->ndisc);
if (r < 0)
return r;
@ -1233,6 +1237,7 @@ int ndisc_configure(Link *link) {
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)