1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #8101 from miri64/gnrc_netif2/opt/flag-checkers

gnrc_netif: assume flag settings on compile time
This commit is contained in:
Koen Zandberg 2017-12-19 12:10:25 +01:00 committed by GitHub
commit 17ac0fa3a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 0 deletions

View File

@ -23,6 +23,10 @@
#include "net/gnrc/netif.h"
#ifdef MODULE_GNRC_IPV6_NIB
#include "net/gnrc/ipv6/nib/conf.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -293,6 +297,8 @@ int gnrc_netif_ipv6_get_iid(gnrc_netif_t *netif, eui64_t *eui64);
* @brief Checks if the interface represents a router according to RFC 4861
*
* @attention Requires prior locking
* @note Assumed to be false, when `gnrc_ipv6_router` module is not
* included.
*
* @param[in] netif the network interface
*
@ -301,15 +307,21 @@ int gnrc_netif_ipv6_get_iid(gnrc_netif_t *netif, eui64_t *eui64);
* @return true, if the interface represents a router
* @return false, if the interface does not represent a router
*/
#if defined(MODULE_GNRC_IPV6_ROUTER) || defined(DOXYGEN)
static inline bool gnrc_netif_is_rtr(const gnrc_netif_t *netif)
{
return (netif->flags & GNRC_NETIF_FLAGS_IPV6_FORWARDING);
}
#else
#define gnrc_netif_is_rtr(netif) (false)
#endif
/**
* @brief Checks if the interface is allowed to send out router advertisements
*
* @attention Requires prior locking
* @note Assumed to be false, when `gnrc_ipv6_router` module is not
* included.
*
* @param[in] netif the network interface
*
@ -317,16 +329,24 @@ static inline bool gnrc_netif_is_rtr(const gnrc_netif_t *netif)
* @return false, if the interface is not allowed to send out router
* advertisements
*/
#if defined(MODULE_GNRC_IPV6_ROUTER) || defined(DOXYGEN)
static inline bool gnrc_netif_is_rtr_adv(const gnrc_netif_t *netif)
{
return (netif->flags & GNRC_NETIF_FLAGS_IPV6_RTR_ADV);
}
#else
#define gnrc_netif_is_rtr_adv(netif) (false)
#endif
/**
* @brief Checks if the interface represents a 6Lo node (6LN) according to
* RFC 6775
*
* @attention Requires prior locking
* @note Assumed to be true, when @ref GNRC_NETIF_NUMOF == 1 and
* @ref net_gnrc_sixlowpan module is included (and
* @ref GNRC_IPV6_NIB_CONF_6LN is not 0, otherwise assumed to be
* false).
*
* @param[in] netif the network interface
*
@ -335,13 +355,20 @@ static inline bool gnrc_netif_is_rtr_adv(const gnrc_netif_t *netif)
* @return true, if the interface represents a 6LN
* @return false, if the interface does not represent a 6LN
*/
#if (GNRC_NETIF_NUMOF > 1) || !defined(MODULE_GNRC_SIXLOWPAN) || defined(DOXYGEN)
bool gnrc_netif_is_6ln(const gnrc_netif_t *netif);
#elif GNRC_IPV6_NIB_CONF_6LN
#define gnrc_netif_is_6ln(netif) (true)
#else
#define gnrc_netif_is_6ln(netif) (false)
#endif
/**
* @brief Checks if the interface represents a 6Lo router (6LR) according to
* RFC 6775
*
* @attention Requires prior locking
* @note Assumed to be false, when @ref GNRC_IPV6_NIB_CONF_6LR == 0
*
* @param[in] netif the network interface
*
@ -350,16 +377,25 @@ bool gnrc_netif_is_6ln(const gnrc_netif_t *netif);
* @return true, if the interface represents a 6LR
* @return false, if the interface does not represent a 6LR
*/
#if (GNRC_IPV6_NIB_CONF_6LR && \
/* if flag checkers even evaluate, otherwise just assume their result */ \
(defined(MODULE_GNRC_IPV6_ROUTER) || \
(GNRC_NETIF_NUMOF > 1) || !defined(MODULE_GNRC_SIXLOWPAN))) || \
defined(DOXYGEN)
static inline bool gnrc_netif_is_6lr(const gnrc_netif_t *netif)
{
return gnrc_netif_is_rtr(netif) && gnrc_netif_is_6ln(netif);
}
#else
#define gnrc_netif_is_6lr(netif) (false)
#endif
/**
* @brief Checks if the interface represents a 6Lo border router (6LBR)
* according to RFC 6775
*
* @attention Requires prior locking
* @note Assumed to be false, when @ref GNRC_IPV6_NIB_CONF_6LBR == 0.
*
* @param[in] netif the network interface
*
@ -368,11 +404,15 @@ static inline bool gnrc_netif_is_6lr(const gnrc_netif_t *netif)
* @return true, if the interface represents a 6LBR
* @return false, if the interface does not represent a 6LBR
*/
#if GNRC_IPV6_NIB_CONF_6LBR
static inline bool gnrc_netif_is_6lbr(const gnrc_netif_t *netif)
{
return (netif->flags & GNRC_NETIF_FLAGS_6LO_ABR) &&
gnrc_netif_is_6lr(netif);
}
#else
#define gnrc_netif_is_6lbr(netif) (false)
#endif
#ifdef __cplusplus
}

View File

@ -1106,6 +1106,7 @@ static int _group_idx(const gnrc_netif_t *netif, const ipv6_addr_t *addr)
}
#endif /* MODULE_GNRC_IPV6 */
#if (GNRC_NETIF_NUMOF > 1) || !defined(MODULE_GNRC_SIXLOWPAN)
bool gnrc_netif_is_6ln(const gnrc_netif_t *netif)
{
switch (netif->device_type) {
@ -1117,6 +1118,7 @@ bool gnrc_netif_is_6ln(const gnrc_netif_t *netif)
return false;
}
}
#endif /* (GNRC_NETIF_NUMOF > 1) || !defined(MODULE_GNRC_SIXLOWPAN) */
static void _update_l2addr_from_dev(gnrc_netif_t *netif)
{

View File

@ -69,6 +69,7 @@ static inline void _set_ar_state(_nib_onl_entry_t *entry, uint16_t state)
static inline bool _rtr_sol_on_6lr(const gnrc_netif_t *netif,
const icmpv6_hdr_t *icmpv6)
{
(void)netif; /* gnrc_netif_is_6lr() might just evaluate to false */
return gnrc_netif_is_6lr(netif) && (icmpv6->type == ICMPV6_RTR_SOL);
}

View File

@ -291,6 +291,7 @@ void _nib_nc_get(const _nib_onl_entry_t *node, gnrc_ipv6_nib_nc_t *nce)
if (ipv6_addr_is_link_local(&nce->ipv6)) {
gnrc_netif_t *netif = gnrc_netif_get_by_pid(_nib_onl_get_if(node));
assert(netif != NULL);
(void)netif; /* flag-checkers might evaluate just to constants */
if (gnrc_netif_is_6ln(netif) && !gnrc_netif_is_rtr(netif)) {
_get_l2addr_from_ipv6(nce->l2addr, &node->ipv6);
nce->l2addr_len = sizeof(uint64_t);