Skip to content

Commit

Permalink
gnrc/ipv6/nib: make ABR run-time configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Dec 13, 2024
1 parent d708e95 commit e24e8dd
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 9 deletions.
9 changes: 8 additions & 1 deletion sys/include/net/gnrc/ipv6/nib/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,19 @@ extern "C" {
#endif

/**
* @brief activate router advertising at interface start-up
* @brief activate router advertising at interface start-up
*/
#ifndef CONFIG_GNRC_IPV6_NIB_ADV_ROUTER
#define CONFIG_GNRC_IPV6_NIB_ADV_ROUTER 0
#endif

/**
* @brief activate authoritative border router functionality at interface start-up
*/
#ifndef CONFIG_GNRC_IPV6_NIB_ABR
#define CONFIG_GNRC_IPV6_NIB_ABR CONFIG_GNRC_IPV6_NIB_6LBR
#endif

/**
* @brief Include a Route Information Option for subnets
* on other interfaces in normal Router Advertisements
Expand Down
5 changes: 5 additions & 0 deletions sys/include/net/netopt.h
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,11 @@ typedef enum {
*/
NETOPT_6LO_IPHC,

/**
* @brief
*/
NETOPT_6LO_ABR,

/**
* @brief (uint8_t) retry amount from missing ACKs of the last transmission
*
Expand Down
31 changes: 31 additions & 0 deletions sys/net/gnrc/netif/gnrc_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,15 @@ int gnrc_netif_get_from_netdev(gnrc_netif_t *netif, gnrc_netapi_opt_t *opt)
res = sizeof(netopt_enable_t);
break;
#endif /* MODULE_GNRC_SIXLOWPAN_IPHC */
#if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_6LBR)
case NETOPT_6LO_ABR:
assert(opt->data_len == sizeof(netopt_enable_t));
*((netopt_enable_t *)opt->data) = (netif->flags & GNRC_NETIF_FLAGS_6LO_ABR)
? NETOPT_ENABLE
: NETOPT_DISABLE;
res = sizeof(netopt_enable_t);
break;
#endif
default:
break;
}
Expand Down Expand Up @@ -409,6 +418,28 @@ int gnrc_netif_set_from_netdev(gnrc_netif_t *netif,
res = sizeof(netopt_enable_t);
break;
#endif /* MODULE_GNRC_SIXLOWPAN_IPHC */
#if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_6LBR)
case NETOPT_6LO_ABR:
assert(opt->data_len == sizeof(netopt_enable_t));

extern void _start_search_rtr(gnrc_netif_t *netif);
extern void _stop_search_rtr(gnrc_netif_t *netif);

if (*(((netopt_enable_t *)opt->data)) == NETOPT_ENABLE) {
netif->flags |= GNRC_NETIF_FLAGS_6LO_ABR;
if (!(netif->flags & GNRC_NETIF_FLAGS_6LO_ABR)) {
_stop_search_rtr(netif);
}
}
else {
if (netif->flags & GNRC_NETIF_FLAGS_6LO_ABR) {
_start_search_rtr(netif);
}
netif->flags &= ~GNRC_NETIF_FLAGS_6LO_ABR;
}
res = sizeof(netopt_enable_t);
break;
#endif
case NETOPT_RAWMODE:
if (*(((netopt_enable_t *)opt->data)) == NETOPT_ENABLE) {
netif->flags |= GNRC_NETIF_FLAGS_RAWMODE;
Expand Down
2 changes: 1 addition & 1 deletion sys/net/gnrc/network_layer/ipv6/nib/_nib-router.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static inline void _init_iface_router(gnrc_netif_t *netif)
netif->flags |= GNRC_NETIF_FLAGS_IPV6_RTR_ADV;
}

if (IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_6LBR)) {
if (IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_ABR)) {
netif->flags |= GNRC_NETIF_FLAGS_6LO_ABR;
}
}
Expand Down
27 changes: 20 additions & 7 deletions sys/net/gnrc/network_layer/ipv6/nib/nib.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ static inline bool _should_search_rtr(const gnrc_netif_t *netif)
/* 6LBR interface does not send RS.
A non-advertising router sends RS or a 6LN that is advertising or not
has to refetch router information */
return !gnrc_netif_is_6lbr(netif) &&
(!gnrc_netif_is_rtr_adv(netif) || gnrc_netif_is_6ln(netif));
if (gnrc_netif_is_6lbr(netif)) {
return false;
}
return !gnrc_netif_is_rtr_adv(netif) || gnrc_netif_is_6ln(netif);
}

void gnrc_ipv6_nib_init(void)
Expand Down Expand Up @@ -167,6 +169,19 @@ static void _add_static_lladdr(gnrc_netif_t *netif)
#endif
}

void _start_search_rtr(gnrc_netif_t *netif)
{
uint32_t next_rs_time = random_uint32_range(0, NDP_MAX_RS_MS_DELAY);

_evtimer_add(netif, GNRC_IPV6_NIB_SEARCH_RTR, &netif->ipv6.search_rtr,
next_rs_time);
}

void _stop_search_rtr(gnrc_netif_t *netif)
{
_evtimer_del(&netif->ipv6.search_rtr);
}

void gnrc_ipv6_nib_iface_up(gnrc_netif_t *netif)
{
assert(netif != NULL);
Expand All @@ -185,11 +200,9 @@ void gnrc_ipv6_nib_iface_up(gnrc_netif_t *netif)
}
_add_static_lladdr(netif);
_auto_configure_addr(netif, &ipv6_addr_link_local_prefix, 64U);
if (_should_search_rtr(netif)) {
uint32_t next_rs_time = random_uint32_range(0, NDP_MAX_RS_MS_DELAY);

_evtimer_add(netif, GNRC_IPV6_NIB_SEARCH_RTR, &netif->ipv6.search_rtr,
next_rs_time);
if (_should_search_rtr(netif)) {
_start_search_rtr(netif);
}
#if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_ROUTER)
else {
Expand All @@ -208,7 +221,7 @@ void gnrc_ipv6_nib_iface_down(gnrc_netif_t *netif, bool send_final_ra)

_deinit_iface_arsm(netif);
if (_should_search_rtr(netif)) {
_evtimer_del(&netif->ipv6.search_rtr);
_stop_search_rtr(netif);
}
#if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_ROUTER)
else {
Expand Down
4 changes: 4 additions & 0 deletions sys/shell/cmds/gnrc_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ static const struct {
netopt_t opt;
} flag_cmds[] = {
{ "6lo", NETOPT_6LO },
{ "abr", NETOPT_6LO_ABR },
{ "ack_req", NETOPT_ACK_REQ },
{ "gts", NETOPT_GTS_TX },
{ "pan_coord", NETOPT_PAN_COORD },
Expand Down Expand Up @@ -887,6 +888,9 @@ static void _netif_list(netif_t *iface)
#ifdef MODULE_GNRC_SIXLOWPAN
line_thresh = _netif_list_flag(iface, NETOPT_6LO, "6LO ", line_thresh);
#endif
#if CONFIG_GNRC_IPV6_NIB_6LBR
line_thresh = _netif_list_flag(iface, NETOPT_6LO_ABR, "ABR ", line_thresh);
#endif
#ifdef MODULE_GNRC_SIXLOWPAN_IPHC
line_thresh += _LINE_THRESHOLD + 1; /* enforce linebreak after this option */
line_thresh = _netif_list_flag(iface, NETOPT_6LO_IPHC, "IPHC ",
Expand Down

0 comments on commit e24e8dd

Please sign in to comment.