From: Yu Watanabe Date: Mon, 3 Oct 2022 03:42:40 +0000 (+0900) Subject: network: make sec_to_usec() map 0sec -> 0usec X-Git-Tag: v252-rc1~16^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0cf1fe88885bd5ae1944c331ee1a5ec80b0ddfbc;p=thirdparty%2Fsystemd.git network: make sec_to_usec() map 0sec -> 0usec Zero lifetime in RA is special, and we should not assign possibly very short lifetime addresses or friends. This should not change anything at least now, preparation for later commits. Note, DHCPv4 and v6 code also uses it, but sd-dhcp-client and sd-dhcp6-client already filtered messages with zero lifetime. Hence, the change should not affect DHCP code. --- diff --git a/src/network/networkd-util.h b/src/network/networkd-util.h index 84fdc99958f..e8c390196e1 100644 --- a/src/network/networkd-util.h +++ b/src/network/networkd-util.h @@ -36,12 +36,15 @@ typedef enum NetworkConfigState { NETWORK_CONFIG_STATE_REMOVING = 1 << 4, /* e.g. address_remove() is called, but no response is received yet */ } NetworkConfigState; -static inline usec_t sec16_to_usec(uint16_t sec, usec_t timestamp_usec) { - return sec == UINT16_MAX ? USEC_INFINITY : usec_add(timestamp_usec, sec * USEC_PER_SEC); +static inline usec_t sec_to_usec(uint32_t sec, usec_t timestamp_usec) { + return + sec == 0 ? 0 : + sec == UINT32_MAX ? USEC_INFINITY : + usec_add(timestamp_usec, sec * USEC_PER_SEC); } -static inline usec_t sec_to_usec(uint32_t sec, usec_t timestamp_usec) { - return sec == UINT32_MAX ? USEC_INFINITY : usec_add(timestamp_usec, sec * USEC_PER_SEC); +static inline usec_t sec16_to_usec(uint16_t sec, usec_t timestamp_usec) { + return sec_to_usec(sec == UINT16_MAX ? UINT32_MAX : (uint32_t) sec, timestamp_usec); } static inline uint32_t usec_to_sec(usec_t usec, usec_t now_usec) {