diff options
Diffstat (limited to 'shared/n-dhcp4')
| -rw-r--r-- | shared/n-dhcp4/src/n-dhcp4-c-connection.c | 11 | ||||
| -rw-r--r-- | shared/n-dhcp4/src/n-dhcp4-c-probe.c | 13 | ||||
| -rw-r--r-- | shared/n-dhcp4/src/n-dhcp4-outgoing.c | 5 | ||||
| -rw-r--r-- | shared/n-dhcp4/src/n-dhcp4-private.h | 3 |
4 files changed, 20 insertions, 12 deletions
diff --git a/shared/n-dhcp4/src/n-dhcp4-c-connection.c b/shared/n-dhcp4/src/n-dhcp4-c-connection.c index f3ae44e2..d4354467 100644 --- a/shared/n-dhcp4/src/n-dhcp4-c-connection.c +++ b/shared/n-dhcp4/src/n-dhcp4-c-connection.c @@ -89,7 +89,7 @@ void n_dhcp4_c_connection_deinit(NDhcp4CConnection *connection) { } static void n_dhcp4_c_connection_outgoing_set_secs(NDhcp4Outgoing *message) { - uint32_t secs; + uint64_t secs; /* * This function sets the `secs` field for outgoing messages. It @@ -125,12 +125,12 @@ static void n_dhcp4_c_connection_outgoing_set_secs(NDhcp4Outgoing *message) { * * Note: Some DHCP relays reject a `secs` value of 0 (which might look * like it is uninitialized). Hence, we always clamp the value to - * the range `[1, INF[`. + * the range `[1, 65535]`. */ secs = message->userdata.base_time - message->userdata.start_time; secs /= 1000ULL * 1000ULL * 1000ULL; /* nsecs to secs */ - secs = secs ?: 1; /* clamp to `[1, INF[` */ + secs = C_CLAMP(secs, 1, UINT16_MAX); n_dhcp4_outgoing_set_secs(message, secs); } @@ -1104,13 +1104,14 @@ int n_dhcp4_c_connection_start_request(NDhcp4CConnection *connection, if (request->userdata.start_time == 0) request->userdata.start_time = timestamp; - n_dhcp4_outgoing_free(connection->request); - connection->request = request; + connection->request = n_dhcp4_outgoing_free(connection->request); r = n_dhcp4_c_connection_send_request(connection, request, timestamp); if (r) return r; + connection->request = request; + return 0; } diff --git a/shared/n-dhcp4/src/n-dhcp4-c-probe.c b/shared/n-dhcp4/src/n-dhcp4-c-probe.c index bfead036..e4477a7c 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-outgoing.c b/shared/n-dhcp4/src/n-dhcp4-outgoing.c index 99123308..bcab407f 100644 --- a/shared/n-dhcp4/src/n-dhcp4-outgoing.c +++ b/shared/n-dhcp4/src/n-dhcp4-outgoing.c @@ -277,6 +277,7 @@ int n_dhcp4_outgoing_append(NDhcp4Outgoing *outgoing, return 0; } + overload = outgoing->overload; if (overload & N_DHCP4_OVERLOAD_SNAME) outgoing->i_message = offsetof(NDhcp4Message, sname); else @@ -341,7 +342,7 @@ int n_dhcp4_outgoing_append_requested_ip(NDhcp4Outgoing *message, struct in_addr return n_dhcp4_outgoing_append_in_addr(message, N_DHCP4_OPTION_REQUESTED_IP_ADDRESS, addr); } -void n_dhcp4_outgoing_set_secs(NDhcp4Outgoing *message, uint32_t secs) { +void n_dhcp4_outgoing_set_secs(NDhcp4Outgoing *message, uint16_t secs) { NDhcp4Header *header = n_dhcp4_outgoing_get_header(message); /* @@ -350,7 +351,7 @@ void n_dhcp4_outgoing_set_secs(NDhcp4Outgoing *message, uint32_t secs) { */ c_assert(secs); - header->secs = htonl(secs); + header->secs = htons(secs); } void n_dhcp4_outgoing_set_xid(NDhcp4Outgoing *message, uint32_t xid) { diff --git a/shared/n-dhcp4/src/n-dhcp4-private.h b/shared/n-dhcp4/src/n-dhcp4-private.h index c092ae8f..436ee806 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 */ @@ -477,7 +478,7 @@ int n_dhcp4_outgoing_append_lifetime(NDhcp4Outgoing *message, uint32_t lifetime) int n_dhcp4_outgoing_append_server_identifier(NDhcp4Outgoing *message, struct in_addr addr); int n_dhcp4_outgoing_append_requested_ip(NDhcp4Outgoing *message, struct in_addr addr); -void n_dhcp4_outgoing_set_secs(NDhcp4Outgoing *message, uint32_t secs); +void n_dhcp4_outgoing_set_secs(NDhcp4Outgoing *message, uint16_t secs); void n_dhcp4_outgoing_set_xid(NDhcp4Outgoing *message, uint32_t xid); void n_dhcp4_outgoing_set_yiaddr(NDhcp4Outgoing *message, struct in_addr yiaddr); |