diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-07-14 02:52:48 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-07-14 20:56:41 +0900 |
commit | 5235d739605f0f3f91abef9d5e7d8764ae57430c (patch) | |
tree | bcc21822a4052ddd9a87ac4ae483888ea621195b /src/network/networkd-util.h | |
parent | def4741bd74b947cfbbc1929abd81b68acbeadd0 (diff) | |
download | systemd-5235d739605f0f3f91abef9d5e7d8764ae57430c.tar.gz |
network: fix infinite lifetime handling
Diffstat (limited to 'src/network/networkd-util.h')
-rw-r--r-- | src/network/networkd-util.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/network/networkd-util.h b/src/network/networkd-util.h index 0a627588aa..373184a3ed 100644 --- a/src/network/networkd-util.h +++ b/src/network/networkd-util.h @@ -37,6 +37,18 @@ typedef enum NetworkConfigState { NETWORK_CONFIG_STATE_REMOVING = 1 << 5, /* 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 == UINT32_MAX ? USEC_INFINITY : usec_add(timestamp_usec, sec * USEC_PER_SEC); +} + +static inline uint32_t usec_to_sec(usec_t usec, usec_t now_usec) { + return MIN(DIV_ROUND_UP(usec_sub_unsigned(usec, now_usec), USEC_PER_SEC), UINT32_MAX); +} + CONFIG_PARSER_PROTOTYPE(config_parse_link_local_address_family); CONFIG_PARSER_PROTOTYPE(config_parse_address_family_with_kernel); CONFIG_PARSER_PROTOTYPE(config_parse_ip_masquerade); |