diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2020-02-06 14:52:12 +0100 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2020-02-06 14:52:59 +0100 |
commit | 09ee928619a7f5a175b15172ac66246d11aae086 (patch) | |
tree | c7093d3afbc558bd076ba2d420fc2ab45cbfa87f | |
parent | 623a1e1f993b3166509202bc580c30e3daf9c67b (diff) | |
download | NetworkManager-bg/nettools-secs.tar.gz |
n-dhcp4: fix initialization of the 'secs' DHCP header fieldbg/nettools-secs
Due to wrong type conversions, the value was always zero.
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/341
-rw-r--r-- | shared/n-dhcp4/src/n-dhcp4-c-connection.c | 6 | ||||
-rw-r--r-- | shared/n-dhcp4/src/n-dhcp4-outgoing.c | 4 | ||||
-rw-r--r-- | shared/n-dhcp4/src/n-dhcp4-private.h | 2 |
3 files changed, 6 insertions, 6 deletions
diff --git a/shared/n-dhcp4/src/n-dhcp4-c-connection.c b/shared/n-dhcp4/src/n-dhcp4-c-connection.c index f3ae44e2d9..3dd0535678 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); } diff --git a/shared/n-dhcp4/src/n-dhcp4-outgoing.c b/shared/n-dhcp4/src/n-dhcp4-outgoing.c index f8698e6d27..bcab407f21 100644 --- a/shared/n-dhcp4/src/n-dhcp4-outgoing.c +++ b/shared/n-dhcp4/src/n-dhcp4-outgoing.c @@ -342,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); /* @@ -351,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 c092ae8fc3..b5936ddf84 100644 --- a/shared/n-dhcp4/src/n-dhcp4-private.h +++ b/shared/n-dhcp4/src/n-dhcp4-private.h @@ -477,7 +477,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); |