Skip to content

Commit

Permalink
gnrc_ipv6_nib: implement behavior for router discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Aug 17, 2017
1 parent 11a3f2e commit 4e36e23
Show file tree
Hide file tree
Showing 19 changed files with 1,328 additions and 157 deletions.
32 changes: 11 additions & 21 deletions sys/include/net/gnrc/ipv6/nib.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,6 @@ extern "C" {
*/
#define GNRC_IPV6_NIB_SEARCH_RTR (0x4fc3U)

/**
* @brief Reconfirm router event.
*
* This message type is for the event the reconfirmation of a router (which
* implies sending a unicast Router Solicitation). The expected message context
* is a pointer to a valid on-link entry representing the router that is to be
* confirmed.
*/
#define GNRC_IPV6_NIB_RECONFIRM_RTR (0x4fc4U)

/**
* @brief Reply Router Solicitation event.
*
Expand Down Expand Up @@ -150,17 +140,6 @@ extern "C" {
*/
#define GNRC_IPV6_NIB_ADDR_REG_TIMEOUT (0x4fc9U)

/**
* @brief 6LoWPAN context timeout event.
*
* This message type is for the event of a 6LoWPAN compression context timeout.
* The expected message context is the compression context's numerical
* identifier.
*
* @note Only handled with @ref GNRC_IPV6_NIB_CONF_6LN != 0
*/
#define GNRC_IPV6_NIB_6LO_CTX_TIMEOUT (0x4fcaU)

/**
* @brief Authoritative border router timeout event.
*
Expand Down Expand Up @@ -198,6 +177,17 @@ extern "C" {
* @note Only handled with @ref GNRC_IPV6_NIB_CONF_ARSM != 0
*/
#define GNRC_IPV6_NIB_RECALC_REACH_TIME (0x4fceU)

/**
* @brief Reregister address.
*
* This message type is for the event of reregistering an IPv6 address to the
* upstream router. The expected message context is an IPv6 address assigned to
* one of the nodes interfaces.
*
* @note Only handled with @ref GNRC_IPV6_NIB_CONF_6LN != 0
*/
#define GNRC_IPV6_NIB_REREG_ADDRESS (0x4fcfU)
/** @} */

/**
Expand Down
23 changes: 19 additions & 4 deletions sys/include/net/gnrc/netif2/flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,31 +81,46 @@ enum {
*/
#define GNRC_NETIF2_FLAGS_IPV6_ADV_RETRANS_TIMER (0x00000040U)

/**
* @brief If gnrc_netif2_t::ipv6::aac_mode == GNRC_NETIF2_AAC_DHCP then this
* flag indicates that other configuration information is available via
* DHCPv6 (e.g. DNS-related information)
*
* @see [RFC 4861, section 4.2](https://tools.ietf.org/html/rfc4861#section-4.2)
*/
#define GNRC_NETIF2_FLAGS_IPV6_ADV_O_FLAG (0x00000080U)

/**
* @brief This interface uses 6Lo header compression
*
* @see [RFC 6282](https://tools.ietf.org/html/rfc6282)
*/
#define GNRC_NETIF2_FLAGS_6LO_HC (0x00000080U)
#define GNRC_NETIF2_FLAGS_6LO_HC (0x00000100U)

/**
* @brief This interface acts as a 6Lo border router to the LLN
*/
#define GNRC_NETIF2_FLAGS_6LO_ABR (0x00000100U)
#define GNRC_NETIF2_FLAGS_6LO_ABR (0x00000200U)

/**
* @brief This interface acts as a mesh-under node (route-over topology when
* unset)
*/
#define GNRC_NETIF2_FLAGS_6LO_MESH (0x00000200U)
#define GNRC_NETIF2_FLAGS_6LO_MESH (0x00000400U)

/**
* @brief Interface supports 6LoWPAN general header compression
*
* @attention GHC not implemented yet
* @see [RFC 7400, section 3.3](https://tools.ietf.org/html/rfc7400#section-3.3)
*/
#define GNRC_NETIF2_FLAGS_6LO_BACKBONE (0x00000400U)
#define GNRC_NETIF2_FLAGS_6LO_BACKBONE (0x00000800U)

/**
* @brief Marks if the addresses of the interface were already registered
* to an interface or not
*/
#define GNRC_NETIF2_FLAGS_6LO_ADDRS_REG (0x00001000U)

/**
* @brief Mask for @ref gnrc_mac_tx_feedback_t
Expand Down
19 changes: 17 additions & 2 deletions sys/include/net/gnrc/netif2/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ typedef struct {
* and @ref net_gnrc_ipv6_nib "NIB"
*/
evtimer_msg_event_t search_rtr;
#if GNRC_IPV6_NIB_CONF_6LN || DOXYGEN
/**
* @brief Timers for address re-registration
*
* @note Only available with module @ref net_gnrc_ipv6 "gnrc_ipv6" and
* @ref net_gnrc_ipv6_nib "NIB" and if
* @ref GNRC_IPV6_NIB_CONF_6LN != 0
* @note Might also be usable in the later default SLAAC implementation
* for NS retransmission timers.
*/
evtimer_msg_event_t addrs_timers[GNRC_NETIF2_IPV6_ADDRS_NUMOF];
#endif

#if GNRC_IPV6_NIB_CONF_ROUTER || DOXYGEN
/**
Expand Down Expand Up @@ -203,21 +215,24 @@ typedef struct {
*/
uint8_t ra_sent;
#endif
#if GNRC_IPV6_NIB_CONF_6LN || DOXYGEN
/**
* @brief number of unsolicited router solicitations scheduled
*
* @note Only available with module @ref net_gnrc_ipv6 "gnrc_ipv6" and
* @ref net_gnrc_ipv6_nib "NIB"
* @ref net_gnrc_ipv6_nib "NIB" and if
* @ref GNRC_IPV6_NIB_CONF_6LN != 0
*/
uint8_t rs_sent;
#endif
/**
* @brief number of unsolicited neighbor advertisements scheduled
*
* @note Only available with module @ref net_gnrc_ipv6 "gnrc_ipv6" and
* @ref net_gnrc_ipv6_nib "NIB"
*/
uint8_t na_sent;
#endif
#endif /* MODULE_GNRC_IPV6_NIB */

/**
* @brief IPv6 auto-address configuration mode
Expand Down
4 changes: 4 additions & 0 deletions sys/include/net/ndp.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,17 @@ extern "C" {
/**
* @{
* @name Router constants
* @see [RFC 4861, section 6.2.1](https://tools.ietf.org/html/rfc4861#section-6.2.1)
* @see [RFC 4861, section 10](https://tools.ietf.org/html/rfc4861#section-10)
*/
#define NDP_MAX_INIT_RA_INTERVAL (16000U) /**< MAX_INITIAL_RTR_ADVERT_INTERVAL (in ms) */
#define NDP_MAX_INIT_RA_NUMOF (3U) /**< MAX_INITIAL_RTR_ADVERTISEMENT */
#define NDP_MAX_FIN_RA_NUMOF (3U) /**< MAX_FINAL_RTR_ADVERTISEMENT */
#define NDP_MIN_MS_DELAY_BETWEEN_RAS (3000U) /**< MIN_DELAY_BETWEEN_RAS (in ms) */
#define NDP_MAX_RA_DELAY (500U) /**< MAX_RA_DELAY_TIME (in ms) */
#define NDP_MAX_RA_INTERVAL_MS (600000U) /**< default of MaxRtrAdvInterval (in ms) */
#define NDP_MIN_RA_INTERVAL_MS (198000U) /**< default of MinRtrAdvInterval (in ms) */
#define NDP_RTR_LTIME_SEC (1800U) /**< default of AdvDefaultLifetime (in sec) */
/** @} */

/**
Expand Down
2 changes: 2 additions & 0 deletions sys/include/net/sixlowpan/nd.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ extern "C" {
* @name Lengths for fixed length options
* @note Options don't use bytes as their length unit, but 8 bytes.
*/
#define SIXLOWPAN_ND_OPT_6CTX_LEN_MIN (2U)
#define SIXLOWPAN_ND_OPT_6CTX_LEN_MAX (3U)
#define SIXLOWPAN_ND_OPT_AR_LEN (2U)
#define SIXLOWPAN_ND_OPT_ABR_LEN (3U)
/**
Expand Down
26 changes: 21 additions & 5 deletions sys/net/gnrc/netif2/gnrc_netif2.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,16 @@ int gnrc_netif2_ipv6_addr_add(gnrc_netif2_t *netif, const ipv6_addr_t *addr,
}
netif->ipv6.addrs_flags[idx] = flags;
memcpy(&netif->ipv6.addrs[idx], addr, sizeof(netif->ipv6.addrs[idx]));
/* TODO:
* - update prefix list, if flags == VALID
* - with SLAAC, send out NS otherwise for DAD probing */
#ifdef MODULE_GNRC_IPV6_NIB
if (_get_state(netif, idx) == GNRC_NETIF2_IPV6_ADDRS_FLAGS_STATE_VALID) {
gnrc_ipv6_nib_pl_set(netif->pid, addr, pfx_len, UINT32_MAX, UINT32_MAX);
}
#if GNRC_IPV6_NIB_CONF_SLAAC
else {
/* TODO: send out NS to solicited nodes for DAD probing */
}
#endif
#endif
(void)pfx_len;
gnrc_netif2_release(netif);
return idx;
Expand All @@ -549,8 +556,17 @@ void gnrc_netif2_ipv6_addr_remove(gnrc_netif2_t *netif,
if (idx >= 0) {
netif->ipv6.addrs_flags[idx] = 0;
ipv6_addr_set_unspecified(&netif->ipv6.addrs[idx]);
/* TODO:
* - update prefix list, if necessary */
#ifdef MODULE_GNRC_IPV6_NIB
gnrc_ipv6_nib_pl_t ple;
void *state = NULL;

while (gnrc_ipv6_nib_pl_iter(netif->pid, &state, &ple)) {
if (ipv6_addr_match_prefix(addr, &ple.pfx) >= ple.pfx_len) {
gnrc_ipv6_nib_pl_del(ple.iface, &ple.pfx, ple.pfx_len);
break;
}
}
#endif
}
gnrc_netif2_release(netif);
}
Expand Down
6 changes: 3 additions & 3 deletions sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,17 +375,16 @@ static void *_event_loop(void *args)
case GNRC_IPV6_NIB_SND_MC_NS:
case GNRC_IPV6_NIB_SND_NA:
case GNRC_IPV6_NIB_SEARCH_RTR:
case GNRC_IPV6_NIB_RECONFIRM_RTR:
case GNRC_IPV6_NIB_REPLY_RS:
case GNRC_IPV6_NIB_SND_MC_RA:
case GNRC_IPV6_NIB_REACH_TIMEOUT:
case GNRC_IPV6_NIB_DELAY_TIMEOUT:
case GNRC_IPV6_NIB_ADDR_REG_TIMEOUT:
case GNRC_IPV6_NIB_6LO_CTX_TIMEOUT:
case GNRC_IPV6_NIB_ABR_TIMEOUT:
case GNRC_IPV6_NIB_PFX_TIMEOUT:
case GNRC_IPV6_NIB_RTR_TIMEOUT:
case GNRC_IPV6_NIB_RECALC_REACH_TIME:
case GNRC_IPV6_NIB_REREG_ADDRESS:
DEBUG("ipv6: NIB timer event received\n");
gnrc_ipv6_nib_handle_timer_event(msg.content.ptr, msg.type);
break;
Expand Down Expand Up @@ -896,7 +895,8 @@ static void _send(gnrc_pktsnip_t *pkt, bool prep_hdr)
}

if (prep_hdr) {
if (_fill_ipv6_hdr(iface, ipv6, payload) < 0) {
if (_fill_ipv6_hdr(gnrc_ipv6_nib_nc_get_iface(&nce), ipv6,
payload) < 0) {
/* error on filling up header */
gnrc_pktbuf_release(pkt);
return;
Expand Down
Loading

0 comments on commit 4e36e23

Please sign in to comment.