Loading...
Searching...
No Matches
IPv6 neighbor discovery (v2)

Provides build and send functions for neighbor discovery packets. More...

Detailed Description

Provides build and send functions for neighbor discovery packets.

Files

file  ndp.h
 GNRC-specific neighbor discovery definitions.
 

Macros

#define GNRC_NETTYPE_NDP   (GNRC_NETTYPE_IPV6) /* usual configuration */
 gnrc_nettype: Protocol type to send NDP packets to
 

Functions

gnrc_pktsnip_tgnrc_ndp_nbr_sol_build (const ipv6_addr_t *tgt, gnrc_pktsnip_t *options)
 Builds a neighbor solicitation message for sending.
 
gnrc_pktsnip_tgnrc_ndp_nbr_adv_build (const ipv6_addr_t *tgt, uint8_t flags, gnrc_pktsnip_t *options)
 Builds a neighbor advertisement message for sending.
 
gnrc_pktsnip_tgnrc_ndp_rtr_sol_build (gnrc_pktsnip_t *options)
 Builds a router solicitation message for sending.
 
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.
 
gnrc_pktsnip_tgnrc_ndp_opt_build (uint8_t type, size_t size, gnrc_pktsnip_t *next)
 Builds a generic NDP option.
 
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.
 
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.
 
gnrc_pktsnip_tgnrc_ndp_opt_pi_build (const ipv6_addr_t *prefix, uint8_t prefix_len, uint32_t valid_ltime, uint32_t pref_ltime, uint8_t flags, gnrc_pktsnip_t *next)
 Builds the prefix information option.
 
gnrc_pktsnip_tgnrc_ndp_opt_ri_build (const ipv6_addr_t *prefix, uint8_t prefix_len, uint32_t route_ltime, uint8_t flags, gnrc_pktsnip_t *next)
 Builds the route information option.
 
gnrc_pktsnip_tgnrc_ndp_opt_mtu_build (uint32_t mtu, gnrc_pktsnip_t *next)
 Builds the MTU option.
 
gnrc_pktsnip_tgnrc_ndp_opt_rdnss_build (uint32_t lifetime, ipv6_addr_t *addrs, unsigned addrs_num, gnrc_pktsnip_t *next)
 Builts the recursive DNS server option.
 
void gnrc_ndp_nbr_sol_send (const ipv6_addr_t *tgt, gnrc_netif_t *netif, const ipv6_addr_t *src, const ipv6_addr_t *dst, gnrc_pktsnip_t *ext_opts)
 Send pre-compiled neighbor solicitation depending on a given network interface.
 
void gnrc_ndp_nbr_adv_send (const ipv6_addr_t *tgt, gnrc_netif_t *netif, const ipv6_addr_t *dst, bool supply_tl2a, gnrc_pktsnip_t *ext_opts)
 Send pre-compiled neighbor advertisement depending on a given network interface.
 
void gnrc_ndp_rtr_sol_send (gnrc_netif_t *netif, const ipv6_addr_t *dst)
 Send pre-compiled router solicitation depending on a given network interface.
 
void gnrc_ndp_rtr_adv_send (gnrc_netif_t *netif, const ipv6_addr_t *src, const ipv6_addr_t *dst, bool fin, gnrc_pktsnip_t *ext_opts)
 Send pre-compiled router advertisement depending on a given network interface.
 

Macro Definition Documentation

◆ GNRC_NETTYPE_NDP

#define GNRC_NETTYPE_NDP   (GNRC_NETTYPE_IPV6) /* usual configuration */

gnrc_nettype: Protocol type to send NDP packets to

Definition at line 39 of file ndp.h.

Function Documentation

◆ gnrc_ndp_nbr_adv_build()

gnrc_pktsnip_t * gnrc_ndp_nbr_adv_build ( const ipv6_addr_t tgt,
uint8_t  flags,
gnrc_pktsnip_t options 
)

Builds a neighbor advertisement message for sending.

Precondition
(tgt != NULL) && !ipv6_addr_is_multicast(tgt)
See also
[RFC 4861, section 4.4](https://tools.ietf.org/html/rfc4861#section-4.4")
Parameters
[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 NULL or a multicast address.
[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]optionsOptions to append to the neighbor advertisement. May be NULL for none.
Returns
The resulting ICMPv6 packet on success.
NULL, if packet buffer is full.

◆ gnrc_ndp_nbr_adv_send()

void gnrc_ndp_nbr_adv_send ( const ipv6_addr_t tgt,
gnrc_netif_t netif,
const ipv6_addr_t dst,
bool  supply_tl2a,
gnrc_pktsnip_t ext_opts 
)

Send pre-compiled neighbor advertisement depending on a given network interface.

Precondition
(tgt != NULL) && !ipv6_addr_is_multicast(tgt)
(netif != NULL) && (dst != NULL)

If netif is a forwarding interface and router advertisements are activated the NDP_NBR_ADV_FLAGS_R is set in the neighbor advertisement. If dst is IPV6_ADDR_UNSPECIFIED it will be replaced with IPV6_ADDR_ALL_NODES_LINK_LOCAL and* supply_tl2a is set to true implicitly. Otherwise, the NDP_NBR_ADV_FLAGS_S will be set. If tgt is an anycast address on netif the NDP_NBR_ADV_FLAGS_O flag will be set.

The source address of the IPv6 packet will be left unspecified, so the IPv6 module selects a fitting IPv6 address.

Parameters
[in]tgtTarget address for the neighbor advertisement. May not be NULL and MUST NOT be multicast.
[in]netifInterface to send over. Must not be NULL.
[in]dstDestination address for neighbor advertisement. May not be NULL. Is set to IPV6_ADDR_ALL_NODES_LINK_LOCAL when equal to IPV6_ADDR_UNSPECIFIED (to allow for simple reply mechanisms to neighbor solicitations). This also implies that supply_tl2a must be true and the parameter will be reset accordingly. If dst is not IPV6_ADDR_UNSPECIFIED, the NDP_NBR_ADV_FLAGS_S flag will be set implicitly.
[in]supply_tl2aAdd target link-layer address option to neighbor advertisement if link-layer has addresses. If dst is IPV6_ADDR_UNSPECIFIED, it will be set to true.
[in]ext_optsExternal options for the neighbor advertisement. Leave NULL for none. Warning: these are not tested if they are suitable for a neighbor advertisement so be sure to check that. Will be released in an error case.

◆ gnrc_ndp_nbr_sol_build()

gnrc_pktsnip_t * gnrc_ndp_nbr_sol_build ( const ipv6_addr_t tgt,
gnrc_pktsnip_t options 
)

Builds a neighbor solicitation message for sending.

Precondition
(tgt != NULL) && !ipv6_addr_is_multicast(tgt)
See also
RFC 4861, section 4.3
Parameters
[in]tgtThe target address of the neighbor solicitation. Must not be NULL or a multicast address.
[in]optionsOptions to append to the neighbor solicitation. May be NULL for none.
Returns
The resulting ICMPv6 packet on success.
NULL, if packet buffer is full.

◆ gnrc_ndp_nbr_sol_send()

void gnrc_ndp_nbr_sol_send ( const ipv6_addr_t tgt,
gnrc_netif_t netif,
const ipv6_addr_t src,
const ipv6_addr_t dst,
gnrc_pktsnip_t ext_opts 
)

Send pre-compiled neighbor solicitation depending on a given network interface.

Precondition
(tgt != NULL) && !ipv6_addr_is_multicast(tgt)
(netif != NULL) && (dst != NULL)
Parameters
[in]tgtThe target address of the neighbor solicitation. Must not be NULL or a multicast address.
[in]netifInterface to send over. Must not be NULL.
[in]srcSource address for the neighbor solicitation. Will be chosen from the interface according to dst, if NULL.
[in]dstDestination address for neighbor solicitation. Must not be NULL.
[in]ext_optsExternal options for the neighbor advertisement. Leave NULL for none. Warning: these are not tested if they are suitable for a neighbor solicitation so be sure to check that. Will be released in an error case.

◆ gnrc_ndp_opt_build()

gnrc_pktsnip_t * gnrc_ndp_opt_build ( uint8_t  type,
size_t  size,
gnrc_pktsnip_t next 
)

Builds a generic NDP option.

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 
)

Builds the MTU option.

See also
RFC 4861, section 4.6.4
Note
Should 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 ( const ipv6_addr_t prefix,
uint8_t  prefix_len,
uint32_t  valid_ltime,
uint32_t  pref_ltime,
uint8_t  flags,
gnrc_pktsnip_t next 
)

Builds the prefix information option.

Precondition
prefix != NULL
!ipv6_addr_is_link_local(prefix) && !ipv6_addr_is_multicast(prefix)
prefix_len <= 128
See also
RFC 4861, section 4.6.2
Note
Should only be used with router advertisemnents. This is not checked however, since nodes should silently ignore it in other NDP messages.
Parameters
[in]prefixAn IPv6 address or a prefix of an IPv6 address. Must not be NULL or be a link-local or multicast address.
[in]prefix_lenThe length of prefix in bits. Must be between 0 and 128.
[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 preferred. UINT32_MAX represents infinity.
[in]flagsFlags as defined in net/ndp.h.
  • 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]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_rdnss_build()

gnrc_pktsnip_t * gnrc_ndp_opt_rdnss_build ( uint32_t  lifetime,
ipv6_addr_t addrs,
unsigned  addrs_num,
gnrc_pktsnip_t next 
)

Builts the recursive DNS server option.

See also
RFC 8106, section 5.1
Precondition
addrs != NULL
addrs_num > 0
Note
Should only be used with router advertisemnents. This is not checked however, since nodes should silently ignore it in other NDP messages.
Parameters
[in]lifetimeThe lifetime of the recursive DNS servers
[in]addrsThe addresses of the recursive DNS servers
[in]addrs_numThe number of addresses in addrs
[in]nextMore options in the packet. NULL, if there are none.
Returns
The packet snip list of options, on success
next, if RDNSS is not supported
NULL, if packet buffer is full

◆ gnrc_ndp_opt_ri_build()

gnrc_pktsnip_t * gnrc_ndp_opt_ri_build ( const ipv6_addr_t prefix,
uint8_t  prefix_len,
uint32_t  route_ltime,
uint8_t  flags,
gnrc_pktsnip_t next 
)

Builds the route information option.

Precondition
prefix != NULL
!ipv6_addr_is_link_local(prefix) && !ipv6_addr_is_multicast(prefix)
prefix_len <= 128
See also
RFC 4191, section 2.3
Note
Should only be used with router advertisemnents. This is not checked however, since nodes should silently ignore it in other NDP messages.
Parameters
[in]prefixAn IPv6 address or a prefix of an IPv6 address. Must not be NULL or be a link-local or multicast address.
[in]prefix_lenThe length of prefix in bits. Must be between 0 and 128.
[in]route_ltimeLength of time in seconds that prefix is valid. UINT32_MAX represents infinity.
[in]flagsFlags as defined in net/ndp.h.
[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 
)

Builds the source link-layer address option.

Precondition
(l2addr != NULL) && (l2addr_len != 0)
See also
RFC 4861, section 4.6.1
Note
Should 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. Must not be NULL.
[in]l2addr_lenLength of l2addr. Must not be 0.
[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 
)

Builds the target link-layer address option.

Precondition
(l2addr != NULL) && (l2addr_len != 0)
See also
RFC 4861, section 4.6.1
Note
Should 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. Must not be NULL.
[in]l2addr_lenLength of l2addr. Must not be 0.
[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_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 
)

Builds a router advertisement message for sending.

See also
`[RFC 4861, section 4.2](https://tools.ietf.org/html/rfc4861#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 in net/ndp.h.
[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. May be NULL for none.
Returns
The resulting ICMPv6 packet on success.
NULL, if packet buffer is full.

◆ gnrc_ndp_rtr_adv_send()

void gnrc_ndp_rtr_adv_send ( gnrc_netif_t netif,
const ipv6_addr_t src,
const ipv6_addr_t dst,
bool  fin,
gnrc_pktsnip_t ext_opts 
)

Send pre-compiled router advertisement depending on a given network interface.

Precondition
(netif != NULL)

This function does not add the PIOs to the router, since they are highly dependent on external set-ups (e.g. if multihop prefix distribution is used). Provide them via ext_opts

Parameters
[in]netifInterface to send over. Must not be NULL.
[in]srcSource address for the router advertisement. May be NULL to be determined by source address selection (:: if netif has no address).
[in]dstDestination address for router advertisement. ff02::1 if NULL.
[in]finThis is part of the router's final batch of router advertisements before ceising to be a router (set's router lifetime field to 0).
[in]ext_optsExternal options for the neighbor advertisement. Leave NULL for none. Warning: these are not tested if they are suitable for a neighbor advertisement so be sure to check that. Will be released in an error case.

◆ gnrc_ndp_rtr_sol_build()

gnrc_pktsnip_t * gnrc_ndp_rtr_sol_build ( gnrc_pktsnip_t options)

Builds a router solicitation message for sending.

See also
`[RFC 4861, section 4.1](https://tools.ietf.org/html/rfc4861#section-4.1")
Parameters
[in]optionsOptions to append to the router solicitation. May be NULL for none.
Returns
The resulting ICMPv6 packet on success.
NULL, if packet buffer is full.

◆ gnrc_ndp_rtr_sol_send()

void gnrc_ndp_rtr_sol_send ( gnrc_netif_t netif,
const ipv6_addr_t dst 
)

Send pre-compiled router solicitation depending on a given network interface.

Precondition
(netif != NULL)
Parameters
[in]netifInterface to send over. Must not be NULL.
[in]dstDestination for the router solicitation. ff02::2 if NULL.