summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/sd-dhcp6-client.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd-network/sd-dhcp6-client.c')
-rw-r--r--src/libsystemd-network/sd-dhcp6-client.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c
index 5489c77864..59d80bc38a 100644
--- a/src/libsystemd-network/sd-dhcp6-client.c
+++ b/src/libsystemd-network/sd-dhcp6-client.c
@@ -266,13 +266,18 @@ static void client_notify(sd_dhcp6_client *client, int event) {
client->cb(client, event, client->userdata);
}
-static int client_reset(sd_dhcp6_client *client) {
- assert_return(client, -EINVAL);
-
+static void client_set_lease(sd_dhcp6_client *client, sd_dhcp6_lease *lease) {
if (client->lease) {
dhcp6_lease_clear_timers(&client->lease->ia);
- client->lease = sd_dhcp6_lease_unref(client->lease);
+ sd_dhcp6_lease_unref(client->lease);
}
+ client->lease = lease;
+}
+
+static int client_reset(sd_dhcp6_client *client) {
+ assert_return(client, -EINVAL);
+
+ client_set_lease(client, NULL);
client->receive_message =
sd_event_source_unref(client->receive_message);
@@ -826,12 +831,7 @@ static int client_receive_reply(sd_dhcp6_client *client, DHCP6Message *reply, si
return 0;
}
- if (client->lease) {
- dhcp6_lease_clear_timers(&client->lease->ia);
- client->lease = sd_dhcp6_lease_unref(client->lease);
- }
-
- client->lease = lease;
+ client_set_lease(client, lease);
lease = NULL;
return DHCP6_STATE_BOUND;
@@ -860,8 +860,7 @@ static int client_receive_advertise(sd_dhcp6_client *client, DHCP6Message *adver
r = dhcp6_lease_get_preference(client->lease, &pref_lease);
if (r < 0 || pref_advertise > pref_lease) {
- sd_dhcp6_lease_unref(client->lease);
- client->lease = lease;
+ client_set_lease(client, lease);
lease = NULL;
r = 0;
}
@@ -1233,7 +1232,6 @@ sd_dhcp6_client *sd_dhcp6_client_unref(sd_dhcp6_client *client) {
client_reset(client);
sd_dhcp6_client_detach_event(client);
- sd_dhcp6_lease_unref(client->lease);
free(client->req_opts);
free(client);