summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2020-02-14 22:09:34 +0100
committerBeniamino Galvani <bgalvani@redhat.com>2020-02-14 22:09:34 +0100
commit98be1bfddb62ab90d5ffd2032ac7343003ba2dd9 (patch)
tree1bc230146015a49b04bfa3b5f10302b3c9af987f
parentd165787b54eb0d3577fe20be174c9e67901ed53a (diff)
downloadNetworkManager-bg/nettools-expire.tar.gz
n-dhcp4: request previous address after expirationbg/nettools-expire
If the lease expires and the client start again sending a discover, request the previous address.
-rw-r--r--shared/n-dhcp4/src/n-dhcp4-c-probe.c13
-rw-r--r--shared/n-dhcp4/src/n-dhcp4-private.h1
2 files changed, 10 insertions, 4 deletions
diff --git a/shared/n-dhcp4/src/n-dhcp4-c-probe.c b/shared/n-dhcp4/src/n-dhcp4-c-probe.c
index bfead036bd..e4477a7c74 100644
--- a/shared/n-dhcp4/src/n-dhcp4-c-probe.c
+++ b/shared/n-dhcp4/src/n-dhcp4-c-probe.c
@@ -436,7 +436,10 @@ int n_dhcp4_client_probe_new(NDhcp4ClientProbe **probep,
if (r)
return r;
- if (probe->config->init_reboot && probe->config->requested_ip.s_addr != INADDR_ANY)
+ if (probe->config->requested_ip.s_addr != INADDR_ANY)
+ probe->last_address = probe->config->requested_ip;
+
+ if (probe->config->init_reboot && probe->last_address.s_addr != INADDR_ANY)
probe->state = N_DHCP4_CLIENT_PROBE_STATE_INIT_REBOOT;
else
probe->state = N_DHCP4_CLIENT_PROBE_STATE_INIT;
@@ -648,7 +651,7 @@ static int n_dhcp4_client_probe_transition_reboot(NDhcp4ClientProbe *probe, uint
if (r)
return r;
- r = n_dhcp4_c_connection_reboot_new(&probe->connection, &request, &probe->config->requested_ip);
+ r = n_dhcp4_c_connection_reboot_new(&probe->connection, &request, &probe->last_address);
if (r)
return r;
@@ -700,8 +703,8 @@ static int n_dhcp4_client_probe_transition_deferred(NDhcp4ClientProbe *probe, ui
if (r)
return r;
- if (!probe->config->init_reboot && probe->config->requested_ip.s_addr != INADDR_ANY) {
- r = n_dhcp4_outgoing_append_requested_ip(request, probe->config->requested_ip);
+ if (probe->last_address.s_addr != INADDR_ANY) {
+ r = n_dhcp4_outgoing_append_requested_ip(request, probe->last_address);
if (r)
return r;
}
@@ -841,6 +844,7 @@ static int n_dhcp4_client_probe_transition_lifetime(NDhcp4ClientProbe *probe) {
return r;
c_assert(probe->client->current_probe == probe);
+
probe->current_lease = n_dhcp4_client_lease_unref(probe->current_lease);
probe->state = N_DHCP4_CLIENT_PROBE_STATE_INIT;
@@ -945,6 +949,7 @@ static int n_dhcp4_client_probe_transition_ack(NDhcp4ClientProbe *probe, NDhcp4I
n_dhcp4_client_lease_unref(probe->current_lease);
probe->current_lease = n_dhcp4_client_lease_ref(lease);
probe->state = N_DHCP4_CLIENT_PROBE_STATE_BOUND;
+ n_dhcp4_client_lease_get_yiaddr(lease, &probe->last_address);
probe->ns_nak_restart_delay = 0;
break;
diff --git a/shared/n-dhcp4/src/n-dhcp4-private.h b/shared/n-dhcp4/src/n-dhcp4-private.h
index b5936ddf84..436ee8065c 100644
--- a/shared/n-dhcp4/src/n-dhcp4-private.h
+++ b/shared/n-dhcp4/src/n-dhcp4-private.h
@@ -350,6 +350,7 @@ struct NDhcp4ClientProbe {
void *userdata;
unsigned int state; /* current probe state */
+ struct in_addr last_address; /* last address obtained */
uint64_t ns_deferred; /* timeout for deferred action */
uint64_t ns_reinit;
uint64_t ns_nak_restart_delay; /* restart delay after a nak */