sd-dhcp-client: introduce sd_dhcp_lease_has_6rd() helper function

No functional change, just refactoring.
This commit is contained in:
Yu Watanabe
2023-09-06 02:02:21 +09:00
parent a93538e892
commit 0ad8d953de
7 changed files with 12 additions and 18 deletions
+4
View File
@@ -372,6 +372,10 @@ int sd_dhcp_lease_get_6rd(
return 0;
}
int sd_dhcp_lease_has_6rd(sd_dhcp_lease *lease) {
return lease && lease->sixrd_n_br_addresses > 0;
}
int sd_dhcp_lease_get_vendor_specific(sd_dhcp_lease *lease, const void **data, size_t *data_len) {
assert_return(lease, -EINVAL);
assert_return(data, -EINVAL);
+1 -11
View File
@@ -51,13 +51,6 @@ bool dhcp_pd_is_uplink(Link *link, Link *target, bool accept_auto) {
return accept_auto;
}
bool dhcp4_lease_has_pd_prefix(sd_dhcp_lease *lease) {
if (!lease)
return false;
return sd_dhcp_lease_get_6rd(lease, NULL, NULL, NULL, NULL, NULL) >= 0;
}
bool dhcp6_lease_has_pd_prefix(sd_dhcp6_lease *lease) {
uint32_t lifetime_preferred_sec, lifetime_valid_sec;
struct in6_addr pd_prefix;
@@ -1140,10 +1133,7 @@ static bool dhcp4_pd_uplink_is_ready(Link *link) {
if (sd_dhcp_client_is_running(link->dhcp_client) <= 0)
return false;
if (!link->dhcp_lease)
return false;
return dhcp4_lease_has_pd_prefix(link->dhcp_lease);
return sd_dhcp_lease_has_6rd(link->dhcp_lease);
}
static bool dhcp6_pd_uplink_is_ready(Link *link) {
@@ -13,7 +13,6 @@ typedef struct Link Link;
bool link_dhcp_pd_is_enabled(Link *link);
bool dhcp_pd_is_uplink(Link *link, Link *target, bool accept_auto);
int dhcp_pd_find_uplink(Link *link, Link **ret);
bool dhcp4_lease_has_pd_prefix(sd_dhcp_lease *lease);
bool dhcp6_lease_has_pd_prefix(sd_dhcp6_lease *lease);
int dhcp_pd_remove(Link *link, bool only_marked);
int dhcp_request_prefix_delegation(Link *link);
+4 -4
View File
@@ -839,7 +839,7 @@ int dhcp4_lease_lost(Link *link) {
link->dhcp4_configured = false;
if (link->network->dhcp_use_6rd &&
dhcp4_lease_has_pd_prefix(link->dhcp_lease))
sd_dhcp_lease_has_6rd(link->dhcp_lease))
dhcp4_pd_prefix_lost(link);
k = dhcp4_remove_address_and_routes(link, /* only_marked = */ false);
@@ -1027,11 +1027,11 @@ static int dhcp_lease_renew(sd_dhcp_client *client, Link *link) {
link_dirty(link);
if (link->network->dhcp_use_6rd) {
if (dhcp4_lease_has_pd_prefix(link->dhcp_lease)) {
if (sd_dhcp_lease_has_6rd(link->dhcp_lease)) {
r = dhcp4_pd_prefix_acquired(link);
if (r < 0)
return log_link_warning_errno(link, r, "Failed to process 6rd option: %m");
} else if (dhcp4_lease_has_pd_prefix(old_lease))
} else if (sd_dhcp_lease_has_6rd(old_lease))
dhcp4_pd_prefix_lost(link);
}
@@ -1101,7 +1101,7 @@ static int dhcp_lease_acquired(sd_dhcp_client *client, Link *link) {
}
if (link->network->dhcp_use_6rd &&
dhcp4_lease_has_pd_prefix(link->dhcp_lease)) {
sd_dhcp_lease_has_6rd(link->dhcp_lease)) {
r = dhcp4_pd_prefix_acquired(link);
if (r < 0)
return log_link_warning_errno(link, r, "Failed to process 6rd option: %m");
+1 -1
View File
@@ -1174,7 +1174,7 @@ static int dhcp_client_pd_append_json(Link *link, JsonVariant **v) {
assert(link->network);
assert(v);
if (!link->network->dhcp_use_6rd || !link->dhcp_lease || !dhcp4_lease_has_pd_prefix(link->dhcp_lease))
if (!link->network->dhcp_use_6rd || !sd_dhcp_lease_has_6rd(link->dhcp_lease))
return 0;
r = sd_dhcp_lease_get_6rd(link->dhcp_lease, &ipv4masklen, &sixrd_prefixlen, &sixrd_prefix, &br_addresses, &n_br_addresses);
+1 -1
View File
@@ -477,7 +477,7 @@ void link_check_ready(Link *link) {
/* If the uplink for PD is self, then request the corresponding DHCP protocol is also ready. */
if (dhcp_pd_is_uplink(link, link, /* accept_auto = */ false)) {
if (link_dhcp4_enabled(link) && link->network->dhcp_use_6rd &&
link->dhcp_lease && dhcp4_lease_has_pd_prefix(link->dhcp_lease)) {
sd_dhcp_lease_has_6rd(link->dhcp_lease)) {
if (!dhcp4_ready)
return (void) log_link_debug(link, "%s(): DHCPv4 6rd prefix is assigned, but DHCPv4 protocol is not finished yet.", __func__);
if (!dhcp_pd_ready)
+1
View File
@@ -85,6 +85,7 @@ int sd_dhcp_lease_get_6rd(
struct in6_addr *ret_prefix,
const struct in_addr **ret_br_addresses,
size_t *ret_n_br_addresses);
int sd_dhcp_lease_has_6rd(sd_dhcp_lease *lease);
int sd_dhcp_route_get_destination(sd_dhcp_route *route, struct in_addr *destination);
int sd_dhcp_route_get_destination_prefix_length(sd_dhcp_route *route, uint8_t *length);