mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-12 06:50:19 +01:00
n-dhcp4: fix initialization of the 'secs' DHCP header field
Due to wrong type conversions, the value was always zero.
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/341
(cherry picked from commit df6129d93a)
This commit is contained in:
parent
68fa338e34
commit
ff7545704e
3 changed files with 6 additions and 6 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue