summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-09-04 20:11:53 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-09-20 20:59:00 +0200
commitfb70992d3973cf09f421260780c4ac96b99467e7 (patch)
treede3a04cdd04fd65b59d58d9f817e77bb531be742 /src
parenttreewide: split commandline into command line (diff)
downloadsystemd-fb70992d3973cf09f421260780c4ac96b99467e7.tar.xz
systemd-fb70992d3973cf09f421260780c4ac96b99467e7.zip
sd-dhcp6-client: introduce sd_dhcp6_lease_has_pd_prefix() and friend
No functional change, just refactoring.
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd-network/sd-dhcp6-lease.c8
-rw-r--r--src/libsystemd-network/test-dhcp6-client.c3
-rw-r--r--src/network/networkd-dhcp-prefix-delegation.c18
-rw-r--r--src/network/networkd-dhcp-prefix-delegation.h1
-rw-r--r--src/network/networkd-dhcp6.c6
-rw-r--r--src/network/networkd-json.c3
-rw-r--r--src/network/networkd-link.c2
-rw-r--r--src/systemd/sd-dhcp6-lease.h2
8 files changed, 20 insertions, 23 deletions
diff --git a/src/libsystemd-network/sd-dhcp6-lease.c b/src/libsystemd-network/sd-dhcp6-lease.c
index 6dcc25888d..9d1c69ed3f 100644
--- a/src/libsystemd-network/sd-dhcp6-lease.c
+++ b/src/libsystemd-network/sd-dhcp6-lease.c
@@ -243,6 +243,10 @@ void sd_dhcp6_lease_reset_address_iter(sd_dhcp6_lease *lease) {
lease->addr_iter = lease->ia_na ? lease->ia_na->addresses : NULL;
}
+int sd_dhcp6_lease_has_address(sd_dhcp6_lease *lease) {
+ return lease && lease->ia_na;
+}
+
int sd_dhcp6_lease_get_pd(
sd_dhcp6_lease *lease,
struct in6_addr *ret_prefix,
@@ -273,6 +277,10 @@ void sd_dhcp6_lease_reset_pd_prefix_iter(sd_dhcp6_lease *lease) {
lease->prefix_iter = lease->ia_pd ? lease->ia_pd->addresses : NULL;
}
+int sd_dhcp6_lease_has_pd_prefix(sd_dhcp6_lease *lease) {
+ return lease && lease->ia_pd;
+}
+
int dhcp6_lease_add_dns(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen) {
assert(lease);
assert(optval || optlen == 0);
diff --git a/src/libsystemd-network/test-dhcp6-client.c b/src/libsystemd-network/test-dhcp6-client.c
index ccf9208d43..a954bfb666 100644
--- a/src/libsystemd-network/test-dhcp6-client.c
+++ b/src/libsystemd-network/test-dhcp6-client.c
@@ -902,6 +902,9 @@ static void test_lease_managed(sd_dhcp6_client *client) {
assert_se(dhcp6_lease_get_serverid(lease, &id, &len) >= 0);
assert_se(memcmp_nn(id, len, server_id, sizeof(server_id)) == 0);
+ assert_se(sd_dhcp6_lease_has_address(lease));
+ assert_se(sd_dhcp6_lease_has_pd_prefix(lease));
+
sd_dhcp6_lease_reset_address_iter(lease);
assert_se(sd_dhcp6_lease_get_address(lease, &addr, &lt_pref, &lt_valid) >= 0);
assert_se(in6_addr_equal(&addr, &ia_na_address1));
diff --git a/src/network/networkd-dhcp-prefix-delegation.c b/src/network/networkd-dhcp-prefix-delegation.c
index c6e6857aa4..0051a7ee44 100644
--- a/src/network/networkd-dhcp-prefix-delegation.c
+++ b/src/network/networkd-dhcp-prefix-delegation.c
@@ -51,19 +51,6 @@ bool dhcp_pd_is_uplink(Link *link, Link *target, bool accept_auto) {
return accept_auto;
}
-bool dhcp6_lease_has_pd_prefix(sd_dhcp6_lease *lease) {
- uint32_t lifetime_preferred_sec, lifetime_valid_sec;
- struct in6_addr pd_prefix;
- uint8_t pd_prefix_len;
-
- if (!lease)
- return false;
-
- sd_dhcp6_lease_reset_pd_prefix_iter(lease);
-
- return sd_dhcp6_lease_get_pd(lease, &pd_prefix, &pd_prefix_len, &lifetime_preferred_sec, &lifetime_valid_sec) >= 0;
-}
-
static void link_remove_dhcp_pd_subnet_prefix(Link *link, const struct in6_addr *prefix) {
void *key;
@@ -1154,10 +1141,7 @@ static bool dhcp6_pd_uplink_is_ready(Link *link) {
if (sd_dhcp6_client_is_running(link->dhcp6_client) <= 0)
return false;
- if (!link->dhcp6_lease)
- return false;
-
- return dhcp6_lease_has_pd_prefix(link->dhcp6_lease);
+ return sd_dhcp6_lease_has_pd_prefix(link->dhcp6_lease);
}
int dhcp_pd_find_uplink(Link *link, Link **ret) {
diff --git a/src/network/networkd-dhcp-prefix-delegation.h b/src/network/networkd-dhcp-prefix-delegation.h
index b12e985bec..e591b8ae2e 100644
--- a/src/network/networkd-dhcp-prefix-delegation.h
+++ b/src/network/networkd-dhcp-prefix-delegation.h
@@ -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 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);
int dhcp4_pd_prefix_acquired(Link *uplink);
diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c
index 57e1087211..e30344fb4f 100644
--- a/src/network/networkd-dhcp6.c
+++ b/src/network/networkd-dhcp6.c
@@ -317,11 +317,11 @@ static int dhcp6_lease_ip_acquired(sd_dhcp6_client *client, Link *link) {
if (r < 0)
return r;
- if (dhcp6_lease_has_pd_prefix(lease)) {
+ if (sd_dhcp6_lease_has_pd_prefix(lease)) {
r = dhcp6_pd_prefix_acquired(link);
if (r < 0)
return r;
- } else if (dhcp6_lease_has_pd_prefix(lease_old))
+ } else if (sd_dhcp6_lease_has_pd_prefix(lease_old))
/* When we had PD prefixes but not now, we need to remove them. */
dhcp_pd_prefix_lost(link);
@@ -353,7 +353,7 @@ static int dhcp6_lease_lost(Link *link) {
log_link_info(link, "DHCPv6 lease lost");
- if (dhcp6_lease_has_pd_prefix(link->dhcp6_lease))
+ if (sd_dhcp6_lease_has_pd_prefix(link->dhcp6_lease))
dhcp_pd_prefix_lost(link);
link->dhcp6_lease = sd_dhcp6_lease_unref(link->dhcp6_lease);
diff --git a/src/network/networkd-json.c b/src/network/networkd-json.c
index 1e425fcb29..e4db7ef75d 100644
--- a/src/network/networkd-json.c
+++ b/src/network/networkd-json.c
@@ -1084,7 +1084,8 @@ static int dhcp6_client_pd_append_json(Link *link, JsonVariant **v) {
assert(link->network);
assert(v);
- if (!link->network->dhcp6_use_pd_prefix || !link->dhcp6_lease || !dhcp6_lease_has_pd_prefix(link->dhcp6_lease))
+ if (!link->network->dhcp6_use_pd_prefix ||
+ !sd_dhcp6_lease_has_pd_prefix(link->dhcp6_lease))
return 0;
sd_dhcp6_lease_reset_pd_prefix_iter(link->dhcp6_lease);
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index eea47f6c8c..a3b6762dc4 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -485,7 +485,7 @@ void link_check_ready(Link *link) {
}
if (link_dhcp6_enabled(link) && link->network->dhcp6_use_pd_prefix &&
- link->dhcp6_lease && dhcp6_lease_has_pd_prefix(link->dhcp6_lease)) {
+ sd_dhcp6_lease_has_pd_prefix(link->dhcp6_lease)) {
if (!dhcp6_ready)
return (void) log_link_debug(link, "%s(): DHCPv6 IA_PD prefix is assigned, but DHCPv6 protocol is not finished yet.", __func__);
if (!dhcp_pd_ready)
diff --git a/src/systemd/sd-dhcp6-lease.h b/src/systemd/sd-dhcp6-lease.h
index 9f52496985..dc226ebc99 100644
--- a/src/systemd/sd-dhcp6-lease.h
+++ b/src/systemd/sd-dhcp6-lease.h
@@ -37,11 +37,13 @@ int sd_dhcp6_lease_get_address(sd_dhcp6_lease *lease,
struct in6_addr *addr,
uint32_t *lifetime_preferred,
uint32_t *lifetime_valid);
+int sd_dhcp6_lease_has_address(sd_dhcp6_lease *lease);
void sd_dhcp6_lease_reset_pd_prefix_iter(sd_dhcp6_lease *lease);
int sd_dhcp6_lease_get_pd(sd_dhcp6_lease *lease, struct in6_addr *prefix,
uint8_t *prefix_len,
uint32_t *lifetime_preferred,
uint32_t *lifetime_valid);
+int sd_dhcp6_lease_has_pd_prefix(sd_dhcp6_lease *lease);
int sd_dhcp6_lease_get_dns(sd_dhcp6_lease *lease, const struct in6_addr **ret);
int sd_dhcp6_lease_get_domains(sd_dhcp6_lease *lease, char ***ret);