summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/sd-dhcp6-client.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-09-24 00:59:15 +0200
committerTom Gundersen <teg@jklm.no>2015-09-24 00:59:15 +0200
commit56c581598389739ba2a97baf896ea9277c278a1d (patch)
tree1e0651f405787d6624fad7bcc88c08f16e9235c7 /src/libsystemd-network/sd-dhcp6-client.c
parent5fecc33e32161008a14ede1061982805dbe57cec (diff)
parentf89087272b5561c9a3fc9d6a4e2a09f75f688fa7 (diff)
Merge pull request #1332 from thom311/master
sd-dhcp6: ensure canceling lease timers and refactor setting lease
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 1ab3640c6b..acb31a16c2 100644
--- a/src/libsystemd-network/sd-dhcp6-client.c
+++ b/src/libsystemd-network/sd-dhcp6-client.c
@@ -274,13 +274,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);
@@ -834,12 +839,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;
@@ -868,8 +868,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;
}
@@ -1244,7 +1243,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);