Neighbor cache definitions. More...

Detailed Description

Neighbor cache definitions.

Author
Martine Lenders mlend.nosp@m.ers@.nosp@m.inf.f.nosp@m.u-be.nosp@m.rlin..nosp@m.de

Definition in file nc.h.

#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "kernel_types.h"
#include "net/eui64.h"
#include "net/ipv6/addr.h"
#include "net/gnrc/netif.h"
#include "net/gnrc/pktqueue.h"
#include "xtimer.h"
+ Include dependency graph for nc.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  gnrc_ipv6_nc_t
 Neighbor cache entry as defined in RFC 4861, section 5.1 . More...
 

Macros

#define GNRC_IPV6_NC_SIZE   (GNRC_NETIF_NUMOF * 8)
 The size of the neighbor cache.
 
#define GNRC_IPV6_NC_L2_ADDR_MAX   (8)
 The maximum size of a link layer address.
 
#define GNRC_IPV6_NC_IS_ROUTER   (0x08)
 The neighbor is a router.
 
#define GNRC_IPV6_NC_TYPE_MASK   (0x30)
 Mask for neighbor cache state.
 
Flag definitions for gnrc_ipv6_nc_t
#define GNRC_IPV6_NC_STATE_MASK   (0x07)
 States of a neighbor cache entry. More...
 
#define GNRC_IPV6_NC_STATE_POS   (0)
 Shift of neighbor cache state.
 
#define GNRC_IPV6_NC_STATE_UNMANAGED   (0x00)
 The entry is not manage by NDP.
 
#define GNRC_IPV6_NC_STATE_UNREACHABLE   (0x01)
 The entry is unreachable. More...
 
#define GNRC_IPV6_NC_STATE_INCOMPLETE   (0x02)
 Address resolution is performed.
 
#define GNRC_IPV6_NC_STATE_STALE   (0x03)
 The entry is stale.
 
#define GNRC_IPV6_NC_STATE_DELAY   (0x04)
 The entry was stale but packet was sent out.
 
#define GNRC_IPV6_NC_STATE_PROBE   (0x05)
 Periodic reachabality confirmation.
 
#define GNRC_IPV6_NC_STATE_REACHABLE   (0x07)
 The entry is reachable.
 
#define GNRC_IPV6_NC_TYPE_NONE   (0x00)
 States of a neighbor cache entry. More...
 
#define GNRC_IPV6_NC_TYPE_GC   (0x10)
 The entry is marked for removal.
 
#define GNRC_IPV6_NC_TYPE_TENTATIVE   (0x20)
 The entry is temporary.
 
#define GNRC_IPV6_NC_TYPE_REGISTERED   (0x30)
 The entry is registered.
 

Functions

void gnrc_ipv6_nc_init (void)
 Initializes neighbor cache.
 
gnrc_ipv6_nc_tgnrc_ipv6_nc_add (kernel_pid_t iface, const ipv6_addr_t *ipv6_addr, const void *l2_addr, size_t l2_addr_len, uint8_t flags)
 Adds a neighbor to the neighbor cache. More...
 
void gnrc_ipv6_nc_remove (kernel_pid_t iface, const ipv6_addr_t *ipv6_addr)
 Removes a neighbor from the neighbor cache. More...
 
gnrc_ipv6_nc_tgnrc_ipv6_nc_get (kernel_pid_t iface, const ipv6_addr_t *ipv6_addr)
 Searches for any neighbor cache entry fitting the ipv6_addr. More...
 
gnrc_ipv6_nc_tgnrc_ipv6_nc_get_next (gnrc_ipv6_nc_t *prev)
 Gets next entry in neighbor cache after prev. More...
 
gnrc_ipv6_nc_tgnrc_ipv6_nc_get_next_router (gnrc_ipv6_nc_t *prev)
 Gets next reachable router entry in neighbor cache after prev. More...
 
static uint8_t gnrc_ipv6_nc_get_state (const gnrc_ipv6_nc_t *entry)
 Returns the state of a neighbor cache entry. More...
 
static uint8_t gnrc_ipv6_nc_get_type (const gnrc_ipv6_nc_t *entry)
 Returns the type of a neighbor cache entry. More...
 
static bool gnrc_ipv6_nc_is_reachable (const gnrc_ipv6_nc_t *entry)
 Checks if an entry is reachable (do not confuse with GNRC_IPV6_NC_STATE_REACHABLE). More...
 
gnrc_ipv6_nc_tgnrc_ipv6_nc_still_reachable (const ipv6_addr_t *ipv6_addr)
 Marks an entry as still reachable, if one with a fitting ipv6_addr can be found. More...
 
kernel_pid_t gnrc_ipv6_nc_get_l2_addr (uint8_t *l2_addr, uint8_t *l2_addr_len, const gnrc_ipv6_nc_t *entry)
 Gets link-layer address from neighbor cache entry if neighbor is reachable. More...
 

Function Documentation

◆ gnrc_ipv6_nc_add()

gnrc_ipv6_nc_t* gnrc_ipv6_nc_add ( kernel_pid_t  iface,
const ipv6_addr_t ipv6_addr,
const void *  l2_addr,
size_t  l2_addr_len,
uint8_t  flags 
)

Adds a neighbor to the neighbor cache.

Parameters
[in]ifacePID to the interface where the neighbor is.
[in]ipv6_addrIPv6 address of the neighbor. Must not be NULL.
[in]l2_addrLink layer address of the neighbor. NULL if unknown.
[in]l2_addr_lenLength of l2_addr, must be lesser than or equal to GNRC_IPV6_L2_ADDR_MAX. 0 if unknown.
[in]flagsFlags for the entry
Returns
Pointer to new neighbor cache entry on success
NULL, on failure

◆ gnrc_ipv6_nc_get()

gnrc_ipv6_nc_t* gnrc_ipv6_nc_get ( kernel_pid_t  iface,
const ipv6_addr_t ipv6_addr 
)

Searches for any neighbor cache entry fitting the ipv6_addr.

Parameters
[in]ifacePID to the interface where the neighbor is. If it is KERNEL_PID_UNDEF it will be searched on all interfaces.
[in]ipv6_addrAn IPv6 address
Returns
The neighbor cache entry, if one is found.
NULL, if none is found.

◆ gnrc_ipv6_nc_get_l2_addr()

kernel_pid_t gnrc_ipv6_nc_get_l2_addr ( uint8_t *  l2_addr,
uint8_t *  l2_addr_len,
const gnrc_ipv6_nc_t entry 
)

Gets link-layer address from neighbor cache entry if neighbor is reachable.

Precondition
(l2_addr != NULL) && (l2_addr_len != NULL)
Parameters
[out]l2_addrThe link layer address of entry. Must not be NULL.
[out]l2_addr_lenLength of l2_addr. Must not be NULL.
[in]entryA neighbor cache entry
Returns
PID to the interface where the neighbor is.
KERNEL_PID_UNDEF, if entry == NULL or the neighbor is not reachable.

◆ gnrc_ipv6_nc_get_next()

gnrc_ipv6_nc_t* gnrc_ipv6_nc_get_next ( gnrc_ipv6_nc_t prev)

Gets next entry in neighbor cache after prev.

Parameters
[in]prevPrevious entry. NULL to start iteration.
Returns
The next entry in neighbor cache.

◆ gnrc_ipv6_nc_get_next_router()

gnrc_ipv6_nc_t* gnrc_ipv6_nc_get_next_router ( gnrc_ipv6_nc_t prev)

Gets next reachable router entry in neighbor cache after prev.

Parameters
[in]prevPrevious router entry. NULL to start iteration.
Returns
The next reachable router entry in neighbor cache.

◆ gnrc_ipv6_nc_get_state()

static uint8_t gnrc_ipv6_nc_get_state ( const gnrc_ipv6_nc_t entry)
inlinestatic

Returns the state of a neighbor cache entry.

Parameters
[in]entryA neighbor cache entry
Returns
The state of the neighbor cache entry as defined by its flags.

Definition at line 240 of file nc.h.

◆ gnrc_ipv6_nc_get_type()

static uint8_t gnrc_ipv6_nc_get_type ( const gnrc_ipv6_nc_t entry)
inlinestatic

Returns the type of a neighbor cache entry.

Parameters
[in]entryA neighbor cache entry
Returns
The type of the neighbor cache entry as defined by its flags.

Definition at line 252 of file nc.h.

◆ gnrc_ipv6_nc_is_reachable()

static bool gnrc_ipv6_nc_is_reachable ( const gnrc_ipv6_nc_t entry)
inlinestatic

Checks if an entry is reachable (do not confuse with GNRC_IPV6_NC_STATE_REACHABLE).

Parameters
[in]entryA neighbor cache entry
Returns
true, if you can send packets to entry
false, if you can't send packets to entry

Definition at line 266 of file nc.h.

◆ gnrc_ipv6_nc_remove()

void gnrc_ipv6_nc_remove ( kernel_pid_t  iface,
const ipv6_addr_t ipv6_addr 
)

Removes a neighbor from the neighbor cache.

Parameters
[in]ifacePID to the interface where the neighbor is. If it is KERNEL_PID_UNDEF it will be removed for all interfaces.
[in]ipv6_addrIPv6 address of the neighbor

◆ gnrc_ipv6_nc_still_reachable()

gnrc_ipv6_nc_t* gnrc_ipv6_nc_still_reachable ( const ipv6_addr_t ipv6_addr)

Marks an entry as still reachable, if one with a fitting ipv6_addr can be found.

This function can be used by upper layer protocols for neighbor discovery optimization to confirm that there was a reachability confirmation (e. g. an ACK in TCP) from the neighbor.

See also
RFC 4861, section 7.3.1
Parameters
[in]ipv6_addrAn IPv6 address
Returns
The neighbor cache entry, if one is found.
NULL, if none is found.