]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: make sec_to_usec() map 0sec -> 0usec
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 3 Oct 2022 03:42:40 +0000 (12:42 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 3 Oct 2022 15:25:14 +0000 (00:25 +0900)
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.

src/network/networkd-util.h

index 84fdc99958ffc0fa501483dbb19c77f93c63fcae..e8c390196e1a329412a86ad2075d45836b557152 100644 (file)
@@ -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) {