Microchip® Advanced Software Framework

nd6.h File Reference

Neighbor discovery and stateless address autoconfiguration for IPv6.

Aims to be compliant with RFC 4861 (Neighbor discovery) and RFC 4862 (Address autoconfiguration).

#include "lwip/opt.h"
#include "lwip/pbuf.h"
#include "lwip/ip6.h"
#include "lwip/ip6_addr.h"
#include "lwip/netif.h"

Data Structures

struct  lladdr_option
 
struct  mtu_option
 
struct  na_header
 Neighbor advertisement message header. More...
 
struct  nd6_destination_cache_entry
 
struct  nd6_neighbor_cache_entry
 
struct  nd6_prefix_list_entry
 
struct  nd6_q_entry
 struct for queueing outgoing packets for unknown address defined here to be accessed by memp.h More...
 
struct  nd6_router_list_entry
 
struct  ns_header
 Neighbor solicitation message header. More...
 
struct  prefix_option
 
struct  ra_header
 
struct  redirect_header
 Redirect message header. More...
 
struct  redirected_header_option
 
struct  route_option
 
struct  rs_header
 Router solicitation message header. More...
 

Macros

#define ND6_FLAG_OVERRIDE   (0x20)
 
#define ND6_FLAG_ROUTER   (0x80)
 
#define ND6_FLAG_SOLICITED   (0x40)
 
#define nd6_init()   /* TODO should we init tables? */
 
#define ND6_OPTION_TYPE_MTU   (0x05)
 MTU option. More...
 
#define ND6_OPTION_TYPE_PREFIX_INFO   (0x03)
 Prefix information option. More...
 
#define ND6_OPTION_TYPE_REDIR_HDR   (0x04)
 Redirected header option. More...
 
#define ND6_OPTION_TYPE_ROUTE_INFO   (24)
 Route information option. More...
 
#define ND6_OPTION_TYPE_SOURCE_LLADDR   (0x01)
 Link-layer address option. More...
 
#define ND6_OPTION_TYPE_TARGET_LLADDR   (0x02)
 
#define ND6_PREFIX_AUTOCONFIG_ADDRESS_DUPLICATE   0x04
 
#define ND6_PREFIX_AUTOCONFIG_ADDRESS_GENERATED   0x02
 
#define ND6_PREFIX_AUTOCONFIG_AUTONOMOUS   0x01
 
#define ND6_PREFIX_FLAG_AUTONOMOUS   (0x40)
 
#define ND6_PREFIX_FLAG_ON_LINK   (0x80)
 
#define ND6_PREFIX_FLAG_ROUTER_ADDRESS   (0x20)
 
#define ND6_PREFIX_FLAG_SITE_PREFIX   (0x10)
 
#define ND6_RA_FLAG_HOME_AGENT   (0x20)
 
#define ND6_RA_FLAG_MANAGED_ADDR_CONFIG   (0x80)
 Router advertisement message header. More...
 
#define ND6_RA_FLAG_OTHER_STATEFUL_CONFIG   (0x40)
 
#define ND6_RA_PREFERENCE_DISABLED   (0x10)
 
#define ND6_RA_PREFERENCE_HIGH   (0x08)
 
#define ND6_RA_PREFERENCE_LOW   (0x18)
 
#define ND6_RA_PREFERENCE_MASK   (0x18)
 
#define ND6_RA_PREFERENCE_MEDIUM   (0x00)
 
#define ND6_TMR_INTERVAL   1000
 1 second period More...
 

Enumerations

enum  nd6_neighbor_cache_entry_state {
  ND6_NO_ENTRY = 0,
  ND6_INCOMPLETE,
  ND6_REACHABLE,
  ND6_STALE,
  ND6_DELAY,
  ND6_PROBE
}
 

Functions

u16_t nd6_get_destination_mtu (ip6_addr_t *ip6addr, struct netif *netif)
 Get the Path MTU for a destination. More...
 
s8_t nd6_get_next_hop_entry (ip6_addr_t *ip6addr, struct netif *netif)
 Determine the next hop for a destination. More...
 
void nd6_input (struct pbuf *p, struct netif *inp)
 Process an incoming neighbor discovery message. More...
 
err_t nd6_queue_packet (s8_t neighbor_index, struct pbuf *p)
 Queue a packet for a neighbor. More...
 
void nd6_reachability_hint (ip6_addr_t *ip6addr)
 Provide the Neighbor discovery process with a hint that a destination is reachable. More...
 
s8_t nd6_select_router (ip6_addr_t *ip6addr, struct netif *netif)
 Select a default router for a destination. More...
 
void nd6_tmr (void)
 Periodic timer for Neighbor discovery functions: More...
 

Variables

struct nd6_router_list_entry default_router_list []
 
struct nd6_destination_cache_entry destination_cache []
 
struct nd6_neighbor_cache_entry neighbor_cache []
 
PACK_STRUCT_BEGIN struct ns_header PACK_STRUCT_STRUCT
 
struct nd6_prefix_list_entry prefix_list []
 
u32_t reachable_time
 
u32_t retrans_timer
 

#define ND6_FLAG_OVERRIDE   (0x20)

Referenced by nd6_input().

#define ND6_FLAG_ROUTER   (0x80)
#define ND6_FLAG_SOLICITED   (0x40)

Referenced by nd6_input().

#define nd6_init ( )    /* TODO should we init tables? */

Referenced by lwip_init().

#define ND6_OPTION_TYPE_MTU   (0x05)

MTU option.

Referenced by nd6_input().

#define ND6_OPTION_TYPE_PREFIX_INFO   (0x03)

Prefix information option.

Referenced by nd6_input().

#define ND6_OPTION_TYPE_REDIR_HDR   (0x04)

Redirected header option.

#define ND6_OPTION_TYPE_ROUTE_INFO   (24)

Route information option.

Referenced by nd6_input().

#define ND6_OPTION_TYPE_SOURCE_LLADDR   (0x01)

Link-layer address option.

Referenced by nd6_input(), nd6_send_ns(), and nd6_send_rs().

#define ND6_OPTION_TYPE_TARGET_LLADDR   (0x02)

Referenced by nd6_input(), and nd6_send_na().

#define ND6_PREFIX_AUTOCONFIG_ADDRESS_DUPLICATE   0x04

Referenced by nd6_input().

#define ND6_PREFIX_AUTOCONFIG_ADDRESS_GENERATED   0x02

Referenced by nd6_tmr().

#define ND6_PREFIX_AUTOCONFIG_AUTONOMOUS   0x01

Referenced by nd6_input(), and nd6_tmr().

#define ND6_PREFIX_FLAG_AUTONOMOUS   (0x40)

Referenced by nd6_input().

#define ND6_PREFIX_FLAG_ON_LINK   (0x80)

Referenced by nd6_input().

#define ND6_PREFIX_FLAG_ROUTER_ADDRESS   (0x20)
#define ND6_PREFIX_FLAG_SITE_PREFIX   (0x10)
#define ND6_RA_FLAG_HOME_AGENT   (0x20)
#define ND6_RA_FLAG_MANAGED_ADDR_CONFIG   (0x80)

Router advertisement message header.

#define ND6_RA_FLAG_OTHER_STATEFUL_CONFIG   (0x40)
#define ND6_RA_PREFERENCE_DISABLED   (0x10)
#define ND6_RA_PREFERENCE_HIGH   (0x08)
#define ND6_RA_PREFERENCE_LOW   (0x18)
#define ND6_RA_PREFERENCE_MASK   (0x18)
#define ND6_RA_PREFERENCE_MEDIUM   (0x00)
#define ND6_TMR_INTERVAL   1000

1 second period

Referenced by nd6_timer(), nd6_tmr(), and sys_timeouts_init().

Enumerator
ND6_NO_ENTRY 
ND6_INCOMPLETE 
ND6_REACHABLE 
ND6_STALE 
ND6_DELAY 
ND6_PROBE 

u16_t nd6_get_destination_mtu ( ip6_addr_t ip6addr,
struct netif netif 
)

Get the Path MTU for a destination.

Parameters
ip6addrthe destination address
netifthe netif on which the packet will be sent
Returns
the Path MTU, if known, or the netif default MTU

References destination_cache, netif::mtu, nd6_find_destination_cache_entry(), NULL, and nd6_destination_cache_entry::pmtu.

Referenced by ip6_output_if_src(), and tcp_eff_send_mss_impl().

s8_t nd6_get_next_hop_entry ( ip6_addr_t ip6addr,
struct netif netif 
)

Determine the next hop for a destination.

Will determine if the destination is on-link, else a suitable on-link router is selected.

The last entry index is cached for fast entry search.

Parameters
ip6addrthe destination address
netifthe netif on which the packet will be sent
Returns
the neighbor cache entry for the next hop, ERR_RTE if no suitable next hop was found, ERR_MEM if no cache entry could be created

References nd6_destination_cache_entry::age, nd6_neighbor_cache_entry::counter, default_router_list, destination_cache, ERR_MEM, ERR_RTE, ip6_addr_cmp, ip6_addr_copy, ip6_addr_islinklocal, ip6_addr_set, ip6_addr_set_any, nd6_neighbor_cache_entry::isrouter, netif::mtu, nd6_cached_destination_index, nd6_cached_neighbor_index, nd6_find_destination_cache_entry(), nd6_find_neighbor_cache_entry(), ND6_INCOMPLETE, nd6_is_prefix_in_netif(), nd6_new_destination_cache_entry(), nd6_new_neighbor_cache_entry(), nd6_select_router(), ND6_STATS_INC, neighbor_cache, nd6_neighbor_cache_entry::netif, NULL, nd6_destination_cache_entry::pmtu, nd6_neighbor_cache_entry::probes_sent, and nd6_neighbor_cache_entry::state.

Referenced by ethip6_output().

void nd6_input ( struct pbuf p,
struct netif inp 
)

Process an incoming neighbor discovery message.

Parameters
pthe nd packet, p->payload pointing to the icmpv6 header
inpthe netif on which this packet was received

References buffer, nd6_neighbor_cache_entry::counter, default_router_list, nd6_neighbor_cache_entry::delay_time, destination_cache, nd6_prefix_list_entry::flags, nd6_router_list_entry::flags, netif::hwaddr_len, ICMP6_TYPE_NA, ICMP6_TYPE_NS, ICMP6_TYPE_PTB, ICMP6_TYPE_RA, ICMP6_TYPE_RD, if(), nd6_prefix_list_entry::invalidation_timer, nd6_router_list_entry::invalidation_timer, ip6_addr_cmp, IP6_ADDR_INVALID, ip6_addr_isany, ip6_addr_islinklocal, ip6_addr_ismulticast, ip6_addr_istentative, ip6_addr_isvalid, ip6_addr_set, ip6_addr_set_solicitednode, ip6_current_dest_addr, ip6_current_src_addr, IP6_HLEN, pbuf::len, mld6_leavegroup(), netif::mtu, multicast_address, ND6_DELAY, nd6_find_destination_cache_entry(), nd6_find_neighbor_cache_entry(), ND6_FLAG_OVERRIDE, ND6_FLAG_SOLICITED, nd6_get_onlink_prefix(), nd6_get_router(), ND6_INCOMPLETE, nd6_new_neighbor_cache_entry(), nd6_new_onlink_prefix(), nd6_new_router(), ND6_OPTION_TYPE_MTU, ND6_OPTION_TYPE_PREFIX_INFO, ND6_OPTION_TYPE_ROUTE_INFO, ND6_OPTION_TYPE_SOURCE_LLADDR, ND6_OPTION_TYPE_TARGET_LLADDR, ND6_PREFIX_AUTOCONFIG_ADDRESS_DUPLICATE, ND6_PREFIX_AUTOCONFIG_AUTONOMOUS, ND6_PREFIX_FLAG_AUTONOMOUS, ND6_PREFIX_FLAG_ON_LINK, nd6_ra_buffer, ND6_REACHABLE, ND6_SEND_FLAG_ALLNODES_DEST, nd6_send_na(), nd6_send_q(), ND6_STATS_INC, neighbor_cache, nd6_router_list_entry::neighbor_entry, nd6_neighbor_cache_entry::netif, netif_ip6_addr, netif_ip6_addr_set_state, netif_ip6_addr_state, NULL, pbuf::payload, pbuf_copy_partial(), pbuf_free(), nd6_destination_cache_entry::pmtu, prefix_list, reachable_time, nd6_neighbor_cache_entry::reachable_time, retrans_timer, netif::rs_count, nd6_neighbor_cache_entry::state, and pbuf::tot_len.

Referenced by icmp6_input().

err_t nd6_queue_packet ( s8_t  neighbor_index,
struct pbuf q 
)

Queue a packet for a neighbor.

Parameters
neighbor_indexthe index in the neighbor cache table
qpacket to be queued
Returns
ERR_OK if succeeded, ERR_MEM if out of memory

References ERR_ARG, ERR_MEM, ERR_OK, LWIP_DBG_TRACE, LWIP_DEBUGF, memp_malloc(), nd6_free_q(), neighbor_cache, pbuf::next, nd6_q_entry::next, NULL, nd6_q_entry::p, pbuf_alloc(), pbuf_copy(), pbuf_free(), PBUF_LINK, PBUF_RAM, pbuf_ref(), PBUF_ROM, nd6_neighbor_cache_entry::q, S16_F, pbuf::tot_len, and pbuf::type.

Referenced by ethip6_output().

void nd6_reachability_hint ( ip6_addr_t ip6addr)

Provide the Neighbor discovery process with a hint that a destination is reachable.

Called by tcp_receive when ACKs are received or sent (as per RFC). This is useful to avoid sending NS messages every 30 seconds.

Parameters
ip6addrthe destination address which is know to be reachable by an upper layer protocol (TCP)

References nd6_neighbor_cache_entry::counter, destination_cache, ip6_addr_cmp, nd6_cached_destination_index, nd6_cached_neighbor_index, nd6_find_destination_cache_entry(), nd6_find_neighbor_cache_entry(), ND6_REACHABLE, ND6_STATS_INC, neighbor_cache, reachable_time, nd6_neighbor_cache_entry::reachable_time, and nd6_neighbor_cache_entry::state.

Referenced by tcp_receive().

s8_t nd6_select_router ( ip6_addr_t ip6addr,
struct netif netif 
)

Select a default router for a destination.

Parameters
ip6addrthe destination address
netifthe netif for the outgoing packet, if known
Returns
the default router entry index, or -1 if no suitable router is found

References default_router_list, ND6_REACHABLE, nd6_router_list_entry::neighbor_entry, nd6_neighbor_cache_entry::netif, NULL, nd6_neighbor_cache_entry::state, and void.

Referenced by ip6_route(), and nd6_get_next_hop_entry().

void nd6_tmr ( void  )

Periodic timer for Neighbor discovery functions:

  • Update neighbor reachability states
  • Update destination cache entries age
  • Update invalidation timers of default routers and on-link prefixes
  • Perform duplicate address detection (DAD) for our addresses
  • Send router solicitations

References nd6_destination_cache_entry::age, nd6_neighbor_cache_entry::counter, default_router_list, nd6_neighbor_cache_entry::delay_time, destination_cache, nd6_prefix_list_entry::flags, nd6_router_list_entry::flags, netif::flags, nd6_prefix_list_entry::invalidation_timer, nd6_router_list_entry::invalidation_timer, netif::ip6_addr, IP6_ADDR_INVALID, ip6_addr_istentative, IP6_ADDR_PREFERRED, ip6_addr_set_solicitednode, netif::ip6_addr_state, IP6_ADDR_TENTATIVE, netif::ip6_autoconfig_enabled, nd6_neighbor_cache_entry::isrouter, mld6_joingroup(), multicast_address, ND6_DELAY, nd6_free_neighbor_cache_entry(), ND6_INCOMPLETE, ND6_NO_ENTRY, ND6_PREFIX_AUTOCONFIG_ADDRESS_GENERATED, ND6_PREFIX_AUTOCONFIG_AUTONOMOUS, ND6_PROBE, ND6_REACHABLE, ND6_SEND_FLAG_MULTICAST_DEST, nd6_send_ns(), nd6_send_q(), nd6_send_rs(), ND6_STALE, ND6_TMR_INTERVAL, neighbor_cache, nd6_router_list_entry::neighbor_entry, nd6_prefix_list_entry::netif, NETIF_FLAG_UP, netif_ip6_addr, netif_ip6_addr_set_state, netif_ip6_addr_state, netif_list, netif::next, NULL, nd6_prefix_list_entry::prefix, prefix_list, nd6_neighbor_cache_entry::probes_sent, nd6_neighbor_cache_entry::reachable_time, netif::rs_count, nd6_neighbor_cache_entry::stale_time, nd6_neighbor_cache_entry::state, and netif::state.

Referenced by nd6_timer().

PACK_STRUCT_BEGIN struct route_option PACK_STRUCT_STRUCT
u32_t reachable_time

Referenced by nd6_input(), and nd6_reachability_hint().

u32_t retrans_timer

Referenced by nd6_input().