nc.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser General
5  * Public License v2.1. See the file LICENSE in the top level directory for
6  * more details.
7  */
8 
21 #ifndef GNRC_IPV6_NC_H
22 #define GNRC_IPV6_NC_H
23 
24 #include <assert.h>
25 #include <stdbool.h>
26 #include <stdint.h>
27 #include <string.h>
28 
29 #include "kernel_types.h"
30 #include "net/eui64.h"
31 #include "net/ipv6/addr.h"
32 #include "net/gnrc/netif.h"
33 #include "net/gnrc/pktqueue.h"
34 #include "xtimer.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #ifndef GNRC_IPV6_NC_SIZE
41 
44 #define GNRC_IPV6_NC_SIZE (GNRC_NETIF_NUMOF * 8)
45 #endif
46 
47 #ifndef GNRC_IPV6_NC_L2_ADDR_MAX
48 
51 #define GNRC_IPV6_NC_L2_ADDR_MAX (8)
52 #endif
53 
66 #define GNRC_IPV6_NC_STATE_MASK (0x07)
67 #define GNRC_IPV6_NC_STATE_POS (0)
69 #define GNRC_IPV6_NC_STATE_UNMANAGED (0x00)
78 #define GNRC_IPV6_NC_STATE_UNREACHABLE (0x01)
79 #define GNRC_IPV6_NC_STATE_INCOMPLETE (0x02)
80 #define GNRC_IPV6_NC_STATE_STALE (0x03)
81 #define GNRC_IPV6_NC_STATE_DELAY (0x04)
82 #define GNRC_IPV6_NC_STATE_PROBE (0x05)
83 #define GNRC_IPV6_NC_STATE_REACHABLE (0x07)
88 #define GNRC_IPV6_NC_IS_ROUTER (0x08)
90 #define GNRC_IPV6_NC_TYPE_MASK (0x30)
105 #define GNRC_IPV6_NC_TYPE_NONE (0x00)
106 #define GNRC_IPV6_NC_TYPE_GC (0x10)
107 #define GNRC_IPV6_NC_TYPE_TENTATIVE (0x20)
108 #define GNRC_IPV6_NC_TYPE_REGISTERED (0x30)
122 typedef struct {
123 #ifdef MODULE_GNRC_NDP_NODE
124  gnrc_pktqueue_t *pkts;
125 #endif
127  uint8_t l2_addr[GNRC_IPV6_NC_L2_ADDR_MAX];
128  uint8_t l2_addr_len;
129  uint8_t flags;
153 #if defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER)
156 #endif
157 
158 #ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER
163 #endif
164 
170 
174 void gnrc_ipv6_nc_init(void);
175 
190  const void *l2_addr, size_t l2_addr_len, uint8_t flags);
191 
200 void gnrc_ipv6_nc_remove(kernel_pid_t iface, const ipv6_addr_t *ipv6_addr);
201 
213 gnrc_ipv6_nc_t *gnrc_ipv6_nc_get(kernel_pid_t iface, const ipv6_addr_t *ipv6_addr);
214 
223 
232 
240 static inline uint8_t gnrc_ipv6_nc_get_state(const gnrc_ipv6_nc_t *entry)
241 {
242  return (entry->flags & GNRC_IPV6_NC_STATE_MASK);
243 }
244 
252 static inline uint8_t gnrc_ipv6_nc_get_type(const gnrc_ipv6_nc_t *entry)
253 {
254  return (entry->flags & GNRC_IPV6_NC_TYPE_MASK);
255 }
256 
266 static inline bool gnrc_ipv6_nc_is_reachable(const gnrc_ipv6_nc_t *entry)
267 {
268  switch (gnrc_ipv6_nc_get_state(entry)) {
271  return false;
272 
273  default:
274  return true;
275  }
276 }
277 
296 
309 kernel_pid_t gnrc_ipv6_nc_get_l2_addr(uint8_t *l2_addr, uint8_t *l2_addr_len,
310  const gnrc_ipv6_nc_t *entry);
311 
312 #ifdef __cplusplus
313 }
314 #endif
315 
316 #endif /* GNRC_IPV6_NC_H */
317 
Types used by the kernel.
EUI-64 data type definition.
msg_t type_timeout_msg
msg_t for gnrc_ipv6_nc_t::type_timeout
Definition: nc.h:160
Definitions for IPv6 addresses.
uint8_t l2_addr_len
Length of gnrc_ipv6_nc_t::l2_addr.
Definition: nc.h:128
ipv6_addr_t ipv6_addr
IPv6 address of the neighbor.
Definition: nc.h:126
int16_t kernel_pid_t
Unique process identifier.
Definition: kernel_types.h:83
eui64_t eui64
the unique EUI-64 of the neighbor (might be different from L2 address, if l2_addr_len == 2) ...
Definition: nc.h:161
xtimer_t rtr_timeout
timeout timer for router flag
Definition: nc.h:131
msg_t rtr_timeout_msg
msg_t for gnrc_ipv6_nc_t::rtr_timeout
Definition: nc.h:132
xtimer_t type_timeout
Timer for type transmissions.
Definition: nc.h:159
#define GNRC_IPV6_NC_L2_ADDR_MAX
The maximum size of a link layer address.
Definition: nc.h:51
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.
static uint8_t gnrc_ipv6_nc_get_state(const gnrc_ipv6_nc_t *entry)
Returns the state of a neighbor cache entry.
Definition: nc.h:240
#define GNRC_IPV6_NC_STATE_MASK
States of a neighbor cache entry.
Definition: nc.h:66
msg_t nbr_sol_msg
msg_t for gnrc_ipv6_nc_t::nbr_sol_timer
Definition: nc.h:139
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.
void gnrc_ipv6_nc_remove(kernel_pid_t iface, const ipv6_addr_t *ipv6_addr)
Removes a neighbor from the neighbor cache.
POSIX.1-2008 compliant version of the assert macro.
Definitions for GNRC's network interfaces.
#define GNRC_IPV6_NC_STATE_UNREACHABLE
The entry is unreachable.
Definition: nc.h:78
data type for packet queue nodes
Definition: pktqueue.h:37
xtimer_t nbr_adv_timer
Delay timer for neighbor advertisements of this entry.
Definition: nc.h:150
xtimer interface definitions
Describes a message object which can be sent between threads.
Definition: msg.h:184
static uint8_t gnrc_ipv6_nc_get_type(const gnrc_ipv6_nc_t *entry)
Returns the type of a neighbor cache entry.
Definition: nc.h:252
uint8_t flags
Flags as defined above.
Definition: nc.h:129
kernel_pid_t iface
PID to the interface where the neighbor is.
Definition: nc.h:130
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.
void gnrc_ipv6_nc_init(void)
Initializes neighbor cache.
msg_t nbr_adv_msg
msg_t for gnrc_ipv6_nc_t::nbr_adv_timer
Definition: nc.h:151
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).
Definition: nc.h:266
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.
Data type to represent an IPv6 address.
Definition: ipv6/addr.h:74
#define GNRC_IPV6_NC_STATE_INCOMPLETE
Address resolution is performed.
Definition: nc.h:79
xtimer timer structure
Definition: xtimer.h:70
Data type to represent an EUI-64.
Definition: eui64.h:37
Packet queue definitions.
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.
Neighbor cache entry as defined in RFC 4861, section 5.1 .
Definition: nc.h:122
xtimer_t nbr_sol_timer
(Re)Transmission timer for neighbor solicitations of this entry and timeout for states.
Definition: nc.h:138
msg_t rtr_adv_msg
msg_t for gnrc_ipv6_nc_t::rtr_adv_timer
Definition: nc.h:155
xtimer_t rtr_adv_timer
Timer for periodic router advertisements.
Definition: nc.h:154
gnrc_ipv6_nc_t * gnrc_ipv6_nc_get_next(gnrc_ipv6_nc_t *prev)
Gets next entry in neighbor cache after prev.
#define GNRC_IPV6_NC_TYPE_MASK
Mask for neighbor cache state.
Definition: nc.h:90
uint8_t probes_remaining
remaining number of unanswered probes
Definition: nc.h:165