From c33e40cce15c6cb3ea1892e678fa3acb3e808107 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Wed, 4 Aug 2021 12:36:10 +0200 Subject: [PATCH] gnrc_ipv6_nib: provide functions to get offset of public timestamps --- sys/include/net/gnrc/ipv6/nib/abr.h | 21 +++++++++++++++ sys/include/net/gnrc/ipv6/nib/pl.h | 42 +++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/sys/include/net/gnrc/ipv6/nib/abr.h b/sys/include/net/gnrc/ipv6/nib/abr.h index dd9dbd4e3b..3514912eb5 100644 --- a/sys/include/net/gnrc/ipv6/nib/abr.h +++ b/sys/include/net/gnrc/ipv6/nib/abr.h @@ -23,6 +23,11 @@ #include +/* prevent cascading include error to xtimer if it is not compiled in or not + * supported by board */ +#if IS_USED(MODULE_EVTIMER) +#include "evtimer.h" +#endif #include "net/ipv6/addr.h" #include "net/gnrc/ipv6/nib/conf.h" @@ -99,6 +104,22 @@ void gnrc_ipv6_nib_abr_del(const ipv6_addr_t *addr); */ bool gnrc_ipv6_nib_abr_iter(void **state, gnrc_ipv6_nib_abr_t *abr); +#if IS_USED(MODULE_EVTIMER) || defined(DOXYGEN) +/** + * @brief Provides the time in minutes for which the authoritative border + * router entry is valid + * + * @param[in] abr An authoritative border router entry. + * + * @return The time in minutes for which the authoritative border router entry + * is valid. + */ +static inline uint32_t gnrc_ipv6_nib_abr_valid_offset(const gnrc_ipv6_nib_abr_t *abr) +{ + return abr->valid_until - evtimer_now_min(); +} +#endif + /** * @brief Prints an authoritative border router list entry * diff --git a/sys/include/net/gnrc/ipv6/nib/pl.h b/sys/include/net/gnrc/ipv6/nib/pl.h index b18ba6fc55..aebc798d4f 100644 --- a/sys/include/net/gnrc/ipv6/nib/pl.h +++ b/sys/include/net/gnrc/ipv6/nib/pl.h @@ -22,6 +22,9 @@ #include +#if IS_USED(MODULE_EVTIMER) +#include "evtimer.h" +#endif #include "net/ipv6/addr.h" #ifdef __cplusplus @@ -122,6 +125,45 @@ void gnrc_ipv6_nib_pl_del(unsigned iface, bool gnrc_ipv6_nib_pl_iter(unsigned iface, void **state, gnrc_ipv6_nib_pl_t *ple); +#if IS_USED(MODULE_EVTIMER) || defined(DOXYGEN) +/** + * @brief Provides the time in milliseconds for which the prefix list + * entry is valid + * + * @param[in] ple A prefix list entry. + * + * @return The time in milliseconds for which the prefix list entry is valid. + * UINT32_MAX if it is valid forever. + */ +static inline uint32_t gnrc_ipv6_nib_pl_valid_offset(const gnrc_ipv6_nib_pl_t *ple) +{ + + return (ple->valid_until == UINT32_MAX) + ? UINT32_MAX + : (ple->valid_until - evtimer_now_msec()); +} + +/** + * @brief Provides the time in milliseconds for which the prefix list + * entry is preferred + * + * A prefix for which the preference expired is deprecated (see [RFC 4862] + * (https://tools.ietf.org/html/rfc4862)) + * + * @param[in] ple A prefix list entry. + * + * @return The time in milliseconds for which the prefix list entry is + * preferred. UINT32_MAX if it is preferred forever. + */ +static inline uint32_t gnrc_ipv6_nib_pl_pref_offset(const gnrc_ipv6_nib_pl_t *ple) +{ + + return (ple->pref_until == UINT32_MAX) + ? UINT32_MAX + : (ple->pref_until - evtimer_now_msec()); +} +#endif + /** * @brief Prints a prefix list entry *