diff options
| author | Sebastien Bacher <seb128@ubuntu.com> | 2020-02-26 16:32:44 +0100 |
|---|---|---|
| committer | Sebastien Bacher <seb128@ubuntu.com> | 2020-02-26 16:32:44 +0100 |
| commit | 447eb1ee6c50e2cac4009e66add3c1d449822589 (patch) | |
| tree | 7bc7db8f5d7e12137e758ea03ebe5c1eb8b07a23 /shared/n-dhcp4/src | |
| parent | 0b818c504ebbb9454b501c532be8603bf383e37a (diff) | |
| parent | 3cbb3d6ecfef1076fc757632ee8327935250afee (diff) | |
Merge remote-tracking branch 'salsa/debian/master' into ubuntu/master
Diffstat (limited to 'shared/n-dhcp4/src')
| -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 | 24 | ||||
| -rw-r--r-- | shared/n-dhcp4/src/n-dhcp4-incoming.c | 8 | ||||
| -rw-r--r-- | shared/n-dhcp4/src/n-dhcp4-outgoing.c | 5 | ||||
| -rw-r--r-- | shared/n-dhcp4/src/n-dhcp4-private.h | 3 |
5 files changed, 29 insertions, 22 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 5bed15b8..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,11 +844,11 @@ static int n_dhcp4_client_probe_transition_lifetime(NDhcp4ClientProbe *probe) { return r; c_assert(probe->client->current_probe == probe); - probe->client->current_probe = NULL; - n_dhcp4_c_connection_close(&probe->connection); + probe->current_lease = n_dhcp4_client_lease_unref(probe->current_lease); - probe->state = N_DHCP4_CLIENT_PROBE_STATE_EXPIRED; + probe->state = N_DHCP4_CLIENT_PROBE_STATE_INIT; + probe->ns_deferred = n_dhcp4_gettime(CLOCK_BOOTTIME) + UINT64_C(1); break; @@ -946,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; @@ -1005,9 +1009,9 @@ static int n_dhcp4_client_probe_transition_nak(NDhcp4ClientProbe *probe) { probe->state = N_DHCP4_CLIENT_PROBE_STATE_INIT; probe->ns_deferred = n_dhcp4_gettime(CLOCK_BOOTTIME) + probe->ns_nak_restart_delay; - probe->ns_nak_restart_delay = C_CLAMP(probe->ns_nak_restart_delay * 2, - UINT64_C(1000000000 * 2), - UINT64_C(1000000000 * 300)); + probe->ns_nak_restart_delay = C_CLAMP(probe->ns_nak_restart_delay * 2u, + UINT64_C(2) * UINT64_C(1000000000), + UINT64_C(300) * UINT64_C(1000000000)); break; case N_DHCP4_CLIENT_PROBE_STATE_SELECTING: case N_DHCP4_CLIENT_PROBE_STATE_INIT_REBOOT: diff --git a/shared/n-dhcp4/src/n-dhcp4-incoming.c b/shared/n-dhcp4/src/n-dhcp4-incoming.c index e7234c0a..f739413b 100644 --- a/shared/n-dhcp4/src/n-dhcp4-incoming.c +++ b/shared/n-dhcp4/src/n-dhcp4-incoming.c @@ -326,7 +326,7 @@ static int n_dhcp4_incoming_query_u8(NDhcp4Incoming *message, uint8_t option, ui r = n_dhcp4_incoming_query(message, option, &data, &n_data); if (r) return r; - else if (n_data != sizeof(*data)) + else if (n_data < sizeof(*data)) return N_DHCP4_E_MALFORMED; *u8p = *data; @@ -342,7 +342,7 @@ static int n_dhcp4_incoming_query_u16(NDhcp4Incoming *message, uint8_t option, u r = n_dhcp4_incoming_query(message, option, &data, &n_data); if (r) return r; - else if (n_data != sizeof(be16)) + else if (n_data < sizeof(be16)) return N_DHCP4_E_MALFORMED; memcpy(&be16, data, sizeof(be16)); @@ -360,7 +360,7 @@ static int n_dhcp4_incoming_query_u32(NDhcp4Incoming *message, uint8_t option, u r = n_dhcp4_incoming_query(message, option, &data, &n_data); if (r) return r; - else if (n_data != sizeof(be32)) + else if (n_data < sizeof(be32)) return N_DHCP4_E_MALFORMED; memcpy(&be32, data, sizeof(be32)); @@ -378,7 +378,7 @@ static int n_dhcp4_incoming_query_in_addr(NDhcp4Incoming *message, uint8_t optio r = n_dhcp4_incoming_query(message, option, &data, &n_data); if (r) return r; - else if (n_data != sizeof(be32)) + else if (n_data < sizeof(be32)) return N_DHCP4_E_MALFORMED; memcpy(&be32, data, sizeof(be32)); 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); |