IPv6 Neighbor discovery

GNRC's IPv6 Neighbor Discovery implementation. More...

Detailed Description

Modules

 Host-specific part of router discovery.
 Host-specific part for the router discovery in IPv6 neighbor discovery.
 
 Internal functions for neighbor discovery.
 Internal functions for neighbor discovery.
 
 Neighbor discovery for pure IPv6 nodes
 Used for pure IPv6 nodes (without 6LoWPAN).
 
 Router-specific part of router discovery.
 Router-specific part for the router discovery in IPv6 neighbor discovery.
 

Files

file  gnrc/ndp.h
 Definitions for GNRC's IPv6 Neighbor Discovery.
 

Macros

#define GNRC_NDP_MSG_RTR_TIMEOUT   (0x0210)
 Message type for router timeouts.
 
#define GNRC_NDP_MSG_ADDR_TIMEOUT   (0x0211)
 Message type for address timeouts.
 
#define GNRC_NDP_MSG_NBR_SOL_RETRANS   (0x0212)
 Message type for multicast neighbor solicitation retransmissions.
 
#define GNRC_NDP_MSG_RTR_ADV_RETRANS   (0x0213)
 Message type for periodic router advertisements.
 
#define GNRC_NDP_MSG_RTR_ADV_DELAY   (0x0214)
 Message type for delayed router advertisements.
 
#define GNRC_NDP_MSG_RTR_ADV_SIXLOWPAN_DELAY   (0x0215)
 Message type for delayed router advertisements in a 6LoWPAN 6LoWPAN needs a special handling, because router advertisements are only sent after a short randomized delay, but not periodically. More...
 
#define GNRC_NDP_MSG_RTR_SOL_RETRANS   (0x0216)
 Message type for periodic router solicitations.
 
#define GNRC_NDP_MSG_NC_STATE_TIMEOUT   (0x0217)
 Message type for neighbor cache state timeouts.
 

Functions

void gnrc_ndp_nbr_sol_handle (kernel_pid_t iface, gnrc_pktsnip_t *pkt, ipv6_hdr_t *ipv6, ndp_nbr_sol_t *nbr_sol, size_t icmpv6_size)
 Handles received neighbor solicitations. More...
 
void gnrc_ndp_nbr_adv_handle (kernel_pid_t iface, gnrc_pktsnip_t *pkt, ipv6_hdr_t *ipv6, ndp_nbr_adv_t *nbr_adv, size_t icmpv6_size)
 Handles received neighbor advertisements. More...
 
void gnrc_ndp_rtr_sol_handle (kernel_pid_t iface, gnrc_pktsnip_t *pkt, ipv6_hdr_t *ipv6, ndp_rtr_sol_t *rtr_sol, size_t icmpv6_size)
 Handles received router solicitations. More...
 
void gnrc_ndp_rtr_adv_handle (kernel_pid_t iface, gnrc_pktsnip_t *pkt, ipv6_hdr_t *ipv6, ndp_rtr_adv_t *rtr_adv, size_t icmpv6_size)
 Handles received router advertisements. More...
 
void gnrc_ndp_retrans_nbr_sol (gnrc_ipv6_nc_t *nc_entry)
 Retransmits a multicast neighbor solicitation for an incomplete or probing neighbor cache entry nc_entry, if nc_entry::probes_remaining > 0. More...
 
void gnrc_ndp_state_timeout (gnrc_ipv6_nc_t *nc_entry)
 Event handler for a neighbor cache state timeout. More...
 
void gnrc_ndp_netif_add (gnrc_ipv6_netif_t *iface)
 NDP interface initialization. More...
 
void gnrc_ndp_netif_remove (gnrc_ipv6_netif_t *iface)
 NDP interface removal. More...
 
kernel_pid_t gnrc_ndp_next_hop_l2addr (uint8_t *l2addr, uint8_t *l2addr_len, kernel_pid_t iface, ipv6_addr_t *dst, gnrc_pktsnip_t *pkt)
 Get link-layer address and interface for next hop to destination IPv6 address. More...
 
gnrc_pktsnip_tgnrc_ndp_nbr_sol_build (ipv6_addr_t *tgt, gnrc_pktsnip_t *options)
 Builds a neighbor solicitation message for sending. More...
 
gnrc_pktsnip_tgnrc_ndp_nbr_adv_build (uint8_t flags, ipv6_addr_t *tgt, gnrc_pktsnip_t *options)
 Builds a neighbor advertisement message for sending. More...
 
gnrc_pktsnip_tgnrc_ndp_rtr_sol_build (gnrc_pktsnip_t *options)
 Builds a router solicitation message for sending. More...
 
gnrc_pktsnip_tgnrc_ndp_rtr_adv_build (uint8_t cur_hl, uint8_t flags, uint16_t ltime, uint32_t reach_time, uint32_t retrans_timer, gnrc_pktsnip_t *options)
 Builds a router advertisement message for sending. More...
 
gnrc_pktsnip_tgnrc_ndp_opt_build (uint8_t type, size_t size, gnrc_pktsnip_t *next)
 Builds a generic NDP option. More...
 
gnrc_pktsnip_tgnrc_ndp_opt_sl2a_build (const uint8_t *l2addr, uint8_t l2addr_len, gnrc_pktsnip_t *next)
 Builds the source link-layer address option. More...
 
gnrc_pktsnip_tgnrc_ndp_opt_tl2a_build (const uint8_t *l2addr, uint8_t l2addr_len, gnrc_pktsnip_t *next)
 Builds the target link-layer address option. More...
 
gnrc_pktsnip_tgnrc_ndp_opt_pi_build (uint8_t prefix_len, uint8_t flags, uint32_t valid_ltime, uint32_t pref_ltime, ipv6_addr_t *prefix, gnrc_pktsnip_t *next)
 Builds the prefix information option. More...
 
gnrc_pktsnip_tgnrc_ndp_opt_mtu_build (uint32_t mtu, gnrc_pktsnip_t *next)
 Builds the MTU option. More...
 

Host constants

See also
RFC 4861, section 10
#define GNRC_NDP_MAX_RTR_SOL_DELAY   (1U)
 Upper bound for randomised delay in seconds for initial router solicitation transmissions.
 
#define GNRC_NDP_MAX_RTR_SOL_INT   (4U)
 Interval in seconds between initial router solicitation transmissions.
 
#define GNRC_NDP_MAX_RTR_SOL_NUMOF   (3U)
 Maximum number of initial router solicitation transmissions.
 

Node constants

See also
RFC 4861, section 10
#define GNRC_NDP_MAX_MC_NBR_SOL_NUMOF   (3U)
 Maximum number of unanswered multicast neighbor solicitations before address resolution is considered failed.
 
#define GNRC_NDP_MAX_UC_NBR_SOL_NUMOF   (3U)
 Maximum number of unanswered unicast neighbor solicitations before an address is considered unreachable.
 
#define GNRC_NDP_MAX_AC_TGT_DELAY   (1U)
 Upper bound of randomized delay in seconds for a solicited neighbor advertisement transmission for an anycast target.
 
#define GNRC_NDP_MAX_NBR_ADV_NUMOF   (3U)
 Maximum number of unsolicited neighbor advertisements before on link-layer address change.
 
#define GNRC_NDP_REACH_TIME   (30U * US_PER_SEC)
 Base value in mircoseconds for computing randomised reachable time.
 
#define GNRC_NDP_RETRANS_TIMER   (1U * US_PER_SEC)
 Time in mircoseconds between retransmissions of neighbor solicitations to a neighbor.
 
#define GNRC_NDP_FIRST_PROBE_DELAY   (5U)
 Delay in seconds for neighbor cache entry between entering DELAY state and entering PROBE state if no reachability confirmation has been received.
 
#define GNRC_NDP_MIN_RAND   (5U)
 Lower bound for randomised reachable time calculation.
 
#define GNRC_NDP_MAX_RAND   (15U)
 Upper bound for randomised reachable time calculation.
 

Router constants

See also
RFC 4861, section 10
#define GNRC_NDP_MAX_INIT_RTR_ADV_INT   (16U)
 Initial router advertisement interval in seconds.
 
#define GNRC_NDP_MAX_INIT_RTR_ADV_NUMOF   (3U)
 Maximum number of initial router advertisement transmissions.
 
#define GNRC_NDP_MAX_FIN_RTR_ADV_NUMOF   (3U)
 Maximum number of final router advertisement transmissions.
 
#define GNRC_NDP_MIN_RTR_ADV_DELAY   (3U)
 Minimum delay in seconds between router advertisement transmissions.
 
#define GNRC_NDP_MAX_RTR_ADV_DELAY   (500U * US_PER_MS)
 Upper bound for randomised delay in microseconds between router solicitation reception and responding router advertisement transmission.
 

Macro Definition Documentation

◆ GNRC_NDP_MSG_RTR_ADV_SIXLOWPAN_DELAY

#define GNRC_NDP_MSG_RTR_ADV_SIXLOWPAN_DELAY   (0x0215)

Definition at line 57 of file gnrc/ndp.h.

Function Documentation

◆ gnrc_ndp_nbr_adv_build()

gnrc_pktsnip_t* gnrc_ndp_nbr_adv_build ( uint8_t  flags,
ipv6_addr_t tgt,
gnrc_pktsnip_t options 
)
See also
RFC 4861, section 4.4
Parameters
[in]flagsNeighbor advertisement flags: NDP_NBR_ADV_FLAGS_R == 1 indicates, that the sender is a router, NDP_NBR_ADV_FLAGS_S == 1 indicates that the advertisement was sent in response to a neighbor solicitation, NDP_NBR_ADV_FLAGS_O == 1 indicates that the advertisement should override an existing cache entry and update the cached link-layer address.
[in]tgtFor solicited advertisements, the Target Address field in the neighbor solicitaton. For and unsolicited advertisement, the address whose link-layer address has changed. MUST NOT be multicast.
[in]optionsOptions to append to the neighbor advertisement.
Returns
The resulting ICMPv6 packet on success.
NULL, on failure.

◆ gnrc_ndp_nbr_adv_handle()

void gnrc_ndp_nbr_adv_handle ( kernel_pid_t  iface,
gnrc_pktsnip_t pkt,
ipv6_hdr_t ipv6,
ndp_nbr_adv_t nbr_adv,
size_t  icmpv6_size 
)
Parameters
[in]ifaceThe receiving interface.
[in]pktThe received packet.
[in]ipv6The IPv6 header in pkt.
[in]nbr_advThe neighbor advertisement in pkt.
[in]icmpv6_sizeThe overall size of the neighbor advertisement.

◆ gnrc_ndp_nbr_sol_build()

gnrc_pktsnip_t* gnrc_ndp_nbr_sol_build ( ipv6_addr_t tgt,
gnrc_pktsnip_t options 
)
See also
RFC 4861, section 4.3
Parameters
[in]tgtThe target address.
[in]optionsOptions to append to the router solicitation.
Returns
The resulting ICMPv6 packet on success.
NULL, on failure.

◆ gnrc_ndp_nbr_sol_handle()

void gnrc_ndp_nbr_sol_handle ( kernel_pid_t  iface,
gnrc_pktsnip_t pkt,
ipv6_hdr_t ipv6,
ndp_nbr_sol_t nbr_sol,
size_t  icmpv6_size 
)
Parameters
[in]ifaceThe receiving interface.
[in]pktThe received packet.
[in]ipv6The IPv6 header in pkt.
[in]nbr_solThe neighbor solicitation in pkt.
[in]icmpv6_sizeThe overall size of the neighbor solicitation.

◆ gnrc_ndp_netif_add()

void gnrc_ndp_netif_add ( gnrc_ipv6_netif_t iface)
Parameters
[in]ifaceAn IPv6 interface descriptor. Must not be NULL.

◆ gnrc_ndp_netif_remove()

void gnrc_ndp_netif_remove ( gnrc_ipv6_netif_t iface)
Parameters
[in]ifaceAn IPv6 interface descriptor. Must not be NULL.

◆ gnrc_ndp_next_hop_l2addr()

kernel_pid_t gnrc_ndp_next_hop_l2addr ( uint8_t *  l2addr,
uint8_t *  l2addr_len,
kernel_pid_t  iface,
ipv6_addr_t dst,
gnrc_pktsnip_t pkt 
)
Parameters
[out]l2addrThe link-layer for the next hop to dst.
[out]l2addr_lenLength of l2addr.
[in]ifaceThe interface to search the next hop on. May be KERNEL_PID_UNDEF if not specified.
[in]dstAn IPv6 address to search the next hop for.
[in]pktPacket to send to dst. Leave NULL if you just want to get the addresses.
Returns
The PID of the interface, on success.
-EHOSTUNREACH, if dst is not reachable.
-ENOBUFS, if l2addr_len was smaller than the resulting l2addr would be long.

◆ gnrc_ndp_opt_build()

gnrc_pktsnip_t* gnrc_ndp_opt_build ( uint8_t  type,
size_t  size,
gnrc_pktsnip_t next 
)
Parameters
[in]typeType of the option.
[in]sizeSize in byte of the option (will be rounded up to the next multiple of 8).
[in]nextMore options in the packet. NULL, if there are none.
Returns
The packet snip list of options, on success
NULL, if packet buffer is full

◆ gnrc_ndp_opt_mtu_build()

gnrc_pktsnip_t* gnrc_ndp_opt_mtu_build ( uint32_t  mtu,
gnrc_pktsnip_t next 
)
See also
RFC 4861, section 4.6.4
Note
Must only be used with router advertisemnents. This is not checked however, since nodes should silently ignore it in other NDP messages.
Parameters
[in]mtuThe recommended MTU for the link.
[in]nextMore options in the packet. NULL, if there are none.
Returns
The packet snip list of options, on success
NULL, if packet buffer is full

◆ gnrc_ndp_opt_pi_build()

gnrc_pktsnip_t* gnrc_ndp_opt_pi_build ( uint8_t  prefix_len,
uint8_t  flags,
uint32_t  valid_ltime,
uint32_t  pref_ltime,
ipv6_addr_t prefix,
gnrc_pktsnip_t next 
)
See also
RFC 4861, section 4.6.2
Note
Must only be used with router advertisemnents. This is not checked however, since nodes should silently ignore it in other NDP messages.
Parameters
[in]prefix_lenThe length of prefix in bits. Must be between 0 and 128.
[in]flagsFlags as defined above. NDP_OPT_PI_FLAGS_L == 1 indicates, that prefix can be used for on-link determination, NDP_OPT_PI_FLAGS_A == 1 indicates, that prefix can be used for stateless address configuration.
[in]valid_ltimeLength of time in seconds that prefix is valid. UINT32_MAX represents infinity.
[in]pref_ltimeLength of time in seconds that addresses using prefix remain prefered. UINT32_MAX represents infinity.
[in]prefixAn IPv6 address or a prefix of an IPv6 address.
[in]nextMore options in the packet. NULL, if there are none.
Returns
The packet snip list of options, on success
NULL, if packet buffer is full

◆ gnrc_ndp_opt_sl2a_build()

gnrc_pktsnip_t* gnrc_ndp_opt_sl2a_build ( const uint8_t *  l2addr,
uint8_t  l2addr_len,
gnrc_pktsnip_t next 
)
See also
RFC 4861, section 4.6.1
Note
Must only be used with neighbor solicitations, router solicitations, and router advertisements. This is not checked however, since hosts should silently ignore it in other NDP messages.
Parameters
[in]l2addrA link-layer address of variable length.
[in]l2addr_lenLength of l2addr.
[in]nextMore options in the packet. NULL, if there are none.
Returns
The packet snip list of options, on success
NULL, if packet buffer is full

◆ gnrc_ndp_opt_tl2a_build()

gnrc_pktsnip_t* gnrc_ndp_opt_tl2a_build ( const uint8_t *  l2addr,
uint8_t  l2addr_len,
gnrc_pktsnip_t next 
)
See also
RFC 4861, section 4.6.1
Note
Must only be used with neighbor advertisemnents and redirect packets. This is not checked however, since hosts should silently ignore it in other NDP messages.
Parameters
[in]l2addrA link-layer address of variable length.
[in]l2addr_lenLength of l2addr.
[in]nextMore options in the packet. NULL, if there are none.
Returns
The pkt snip list of options, on success
NULL, if packet buffer is full

◆ gnrc_ndp_retrans_nbr_sol()

void gnrc_ndp_retrans_nbr_sol ( gnrc_ipv6_nc_t nc_entry)

If nc_entry::probes_remaining > 0 it will be decremented. If it reaches 0 it the entry nc_entry will be removed from the neighbor cache.

Parameters
[in]nc_entryA neighbor cache entry. Will be ignored if its state is not GNRC_IPV6_NC_STATE_INCOMPLETE or GNRC_IPV6_NC_STATE_PROBE.

◆ gnrc_ndp_rtr_adv_build()

gnrc_pktsnip_t* gnrc_ndp_rtr_adv_build ( uint8_t  cur_hl,
uint8_t  flags,
uint16_t  ltime,
uint32_t  reach_time,
uint32_t  retrans_timer,
gnrc_pktsnip_t options 
)
See also
RFC 4861, section 4.2
Note
The source address for the packet MUST be the link-local address of the interface.
Parameters
[in]cur_hlDefault hop limit for outgoing IP packets, 0 if unspecified by this router.
[in]flagsFlags as defined above. NDP_RTR_ADV_FLAGS_M == 1 indicates, that the addresses are managed by DHCPv6, NDP_RTR_ADV_FLAGS_O == 1 indicates that other configuration information is available via DHCPv6.
[in]ltimeLifetime of the default router in seconds.
[in]reach_timeTime in milliseconds a node should assume a neighbor reachable. 0 means unspecified by the router.
[in]retrans_timerTime in milliseconds between retransmitted neighbor solicitations. 0 means unspecified by the router.
[in]optionsOptions to append to the router advertisement.
Returns
The resulting ICMPv6 packet on success.
NULL, on failure.

◆ gnrc_ndp_rtr_adv_handle()

void gnrc_ndp_rtr_adv_handle ( kernel_pid_t  iface,
gnrc_pktsnip_t pkt,
ipv6_hdr_t ipv6,
ndp_rtr_adv_t rtr_adv,
size_t  icmpv6_size 
)
Todo:
As router check consistency as described in RFC 4861, section 6.2.3
Parameters
[in]ifaceThe receiving interface.
[in]pktThe received packet.
[in]ipv6The IPv6 header in pkt.
[in]rtr_advThe router advertisement in pkt.
[in]icmpv6_sizeThe overall size of the router advertisement.

◆ gnrc_ndp_rtr_sol_build()

gnrc_pktsnip_t * gnrc_ndp_rtr_sol_build ( gnrc_pktsnip_t options)
See also
RFC 4861, section 4.1
Parameters
[in]optionsOptions to append to the router solicitation.
Returns
The resulting ICMPv6 packet on success.
NULL, on failure.

◆ gnrc_ndp_rtr_sol_handle()

void gnrc_ndp_rtr_sol_handle ( kernel_pid_t  iface,
gnrc_pktsnip_t pkt,
ipv6_hdr_t ipv6,
ndp_rtr_sol_t rtr_sol,
size_t  icmpv6_size 
)
Parameters
[in]ifaceThe receiving interface.
[in]pktThe received packet.
[in]ipv6The IPv6 header in pkt.
[in]rtr_solThe router solicitation in pkt.
[in]icmpv6_sizeThe overall size of the router solicitation.

◆ gnrc_ndp_state_timeout()

void gnrc_ndp_state_timeout ( gnrc_ipv6_nc_t nc_entry)
Parameters
[in]nc_entryA neighbor cache entry.