_nib-internal.h
1 /*
2  * Copyright (C) 2017 Freie Universit√§t Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
19 #ifndef PRIV_NIB_INTERNAL_H
20 #define PRIV_NIB_INTERNAL_H
21 
22 #include <assert.h>
23 #include <stdbool.h>
24 #include <stdint.h>
25 
26 #include "bitfield.h"
27 #include "evtimer_msg.h"
28 #include "kernel_types.h"
29 #include "mutex.h"
30 #include "net/eui64.h"
31 #include "net/ipv6/addr.h"
32 #ifdef MODULE_GNRC_IPV6
33 #include "net/gnrc/ipv6.h"
34 #endif
35 #include "net/gnrc/ipv6/nib/ft.h"
36 #include "net/gnrc/ipv6/nib/nc.h"
37 #include "net/gnrc/ipv6/nib/conf.h"
38 #include "net/gnrc/pktqueue.h"
39 #include "net/gnrc/sixlowpan/ctx.h"
40 #include "net/ndp.h"
41 #include "random.h"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
52 #define _EMPTY (0x00)
53 #define _NC (0x01)
54 #define _DC (0x02)
55 #define _PL (0x04)
56 #define _DRL (0x08)
57 #define _FT (0x10)
58 #define _DAD (0x20)
59 #define _DST (0x40)
68 #define _PFX_ON_LINK (0x0001)
69 #define _PFX_SLAAC (0x0002)
70 
75 #define _NIB_IF_MASK (GNRC_IPV6_NIB_NC_INFO_IFACE_MASK)
76 
80 #define _NIB_IF_POS (GNRC_IPV6_NIB_NC_INFO_IFACE_POS)
81 
85 #define _NIB_IF_MAX (_NIB_IF_MASK >> _NIB_IF_POS)
86 
91 typedef struct _nib_onl_entry {
92  struct _nib_onl_entry *next;
93 #if GNRC_IPV6_NIB_CONF_QUEUE_PKT || defined(DOXYGEN)
94 
100 #endif
101 
105 #if GNRC_IPV6_NIB_CONF_6LR || defined(DOXYGEN)
106 
111  eui64_t eui64;
112 #endif
113 #if GNRC_IPV6_NIB_CONF_ARSM || defined(DOXYGEN)
114 
120 #endif
121 
143 #if GNRC_IPV6_NIB_CONF_ROUTER || defined(DOXYGEN)
145 #endif
146 #if GNRC_IPV6_NIB_CONF_6LR || defined(DOXYGEN)
148 #endif
149 
155  uint16_t info;
164  uint8_t mode;
165 #if GNRC_IPV6_NIB_CONF_ARSM || defined(DOXYGEN)
166 
171  uint8_t ns_sent;
178  uint8_t l2addr_len;
179 #endif
181 
185 typedef struct {
186  _nib_onl_entry_t *next_hop;
190  evtimer_msg_event_t rtr_timeout;
192 
196 typedef struct {
197  _nib_onl_entry_t *next_hop;
202  evtimer_msg_event_t pfx_timeout;
203 #ifdef GNRC_IPV6_NIB_CONF_ROUTER
204 
207  evtimer_msg_event_t route_timeout;
208 #endif
209  uint8_t mode;
211  uint8_t pfx_len;
213  uint16_t flags;
214  uint32_t valid_until;
216  uint32_t pref_until;
219 
224 typedef struct {
225  ipv6_addr_t addr;
226  uint32_t version;
228  uint32_t valid_until;
230  evtimer_msg_event_t timeout;
242 
246 extern mutex_t _nib_mutex;
247 
251 extern evtimer_msg_t _nib_evtimer;
252 
261 extern _nib_dr_entry_t *_prime_def_router;
262 
266 void _nib_init(void);
267 
275 static inline unsigned _nib_onl_get_if(const _nib_onl_entry_t *node)
276 {
277  return (node->info & _NIB_IF_MASK) >> _NIB_IF_POS;
278 }
279 
286 static inline void _nib_onl_set_if(_nib_onl_entry_t *node, unsigned iface)
287 {
288  assert(iface <= _NIB_IF_MAX);
289  node->info &= ~(_NIB_IF_MASK);
290  node->info |= ((iface << _NIB_IF_POS) & _NIB_IF_MASK);
291 }
292 
304 _nib_onl_entry_t *_nib_onl_alloc(const ipv6_addr_t *addr, unsigned iface);
305 
314 static inline bool _nib_onl_clear(_nib_onl_entry_t *node)
315 {
316  if (node->mode == _EMPTY) {
317  memset(node, 0, sizeof(_nib_onl_entry_t));
318  return true;
319  }
320  return false;
321 }
322 
330 _nib_onl_entry_t *_nib_onl_iter(const _nib_onl_entry_t *last);
331 
343 _nib_onl_entry_t *_nib_onl_get(const ipv6_addr_t *addr, unsigned iface);
344 
364 _nib_onl_entry_t *_nib_nc_add(const ipv6_addr_t *addr, unsigned iface,
365  uint16_t cstate);
366 
372 void _nib_nc_remove(_nib_onl_entry_t *node);
373 
382 void _nib_nc_get(const _nib_onl_entry_t *node, gnrc_ipv6_nib_nc_t *nce);
383 
391 void _nib_nc_set_reachable(_nib_onl_entry_t *node);
392 
403 static inline _nib_onl_entry_t *_nib_dad_add(const ipv6_addr_t *addr)
404 {
405  assert(addr != NULL);
406  _nib_onl_entry_t *node = _nib_onl_alloc(addr, 0);
407 
408  if (node != NULL) {
409  node->mode |= (_DAD);
410  }
411  return node;
412 }
413 
419 static inline void _nib_dad_remove(_nib_onl_entry_t *node)
420 {
421  node->mode &= ~(_DAD);
422  _nib_onl_clear(node);
423 }
424 
438 _nib_dr_entry_t *_nib_drl_add(const ipv6_addr_t *router_addr, unsigned iface);
439 
447 void _nib_drl_remove(_nib_dr_entry_t *nib_dr);
448 
456 _nib_dr_entry_t *_nib_drl_iter(const _nib_dr_entry_t *last);
457 
470 _nib_dr_entry_t *_nib_drl_get(const ipv6_addr_t *router_addr, unsigned iface);
471 
481 void _nib_drl_ft_get(const _nib_dr_entry_t *drl, gnrc_ipv6_nib_ft_t *fte);
482 
491 _nib_dr_entry_t *_nib_drl_get_dr(void);
492 
510 _nib_offl_entry_t *_nib_offl_alloc(const ipv6_addr_t *next_hop, unsigned iface,
511  const ipv6_addr_t *pfx, unsigned pfx_len);
512 
518 void _nib_offl_clear(_nib_offl_entry_t *dst);
519 
527 _nib_offl_entry_t *_nib_offl_iter(const _nib_offl_entry_t *last);
528 
537 bool _nib_offl_is_entry(const _nib_offl_entry_t *entry);
538 
557 static inline _nib_offl_entry_t *_nib_offl_add(const ipv6_addr_t *next_hop,
558  unsigned iface,
559  const ipv6_addr_t *pfx,
560  unsigned pfx_len, uint8_t mode)
561 {
562  _nib_offl_entry_t *nib_offl = _nib_offl_alloc(next_hop, iface, pfx, pfx_len);
563 
564  if (nib_offl != NULL) {
565  nib_offl->mode |= mode;
566  }
567  return nib_offl;
568 }
569 
575 static inline void _nib_offl_remove(_nib_offl_entry_t *nib_offl, uint8_t mode)
576 {
577  nib_offl->mode &= ~mode;
578  _nib_offl_clear(nib_offl);
579 }
580 
581 #if GNRC_IPV6_NIB_CONF_DC || DOXYGEN
582 
598 static inline _nib_offl_entry_t *_nib_dc_add(const ipv6_addr_t *next_hop,
599  unsigned iface,
600  const ipv6_addr_t *dst)
601 {
602  assert((next_hop != NULL) && (dst != NULL));
603  return _nib_offl_add(next_hop, iface, dst, IPV6_ADDR_BIT_LEN, _DC);
604 }
605 
615 static inline void _nib_dc_remove(_nib_offl_entry_t *nib_offl)
616 {
617  _nib_offl_remove(nib_offl, _DC);
618 }
619 #endif /* GNRC_IPV6_NIB_CONF_DC */
620 
642 _nib_offl_entry_t *_nib_pl_add(unsigned iface,
643  const ipv6_addr_t *pfx,
644  unsigned pfx_len,
645  uint32_t valid_ltime,
646  uint32_t pref_ltime);
647 
655 void _nib_pl_remove(_nib_offl_entry_t *nib_offl);
656 
657 #if GNRC_IPV6_NIB_CONF_ROUTER || DOXYGEN
658 
678 static inline _nib_offl_entry_t *_nib_ft_add(const ipv6_addr_t *next_hop,
679  unsigned iface,
680  const ipv6_addr_t *pfx,
681  unsigned pfx_len)
682 {
683  return _nib_offl_add(next_hop, iface, pfx, pfx_len, _FT);
684 }
685 
695 static inline void _nib_ft_remove(_nib_offl_entry_t *nib_offl)
696 {
697  _nib_offl_remove(nib_offl, _FT);
698 }
699 #endif /* GNRC_IPV6_NIB_CONF_ROUTER */
700 
701 #if GNRC_IPV6_NIB_CONF_MULTIHOP_P6C || defined(DOXYGEN)
702 
712 _nib_abr_entry_t *_nib_abr_add(const ipv6_addr_t *addr);
713 
721 void _nib_abr_remove(const ipv6_addr_t *addr);
722 
732 void _nib_abr_add_pfx(_nib_abr_entry_t *abr, const _nib_offl_entry_t *offl);
733 
746 _nib_offl_entry_t *_nib_abr_iter_pfx(const _nib_abr_entry_t *abr,
747  const _nib_offl_entry_t *last);
748 
757 _nib_abr_entry_t *_nib_abr_iter(const _nib_abr_entry_t *last);
758 #endif
759 
769 void _nib_ft_get(const _nib_offl_entry_t *dst, gnrc_ipv6_nib_ft_t *fte);
770 
785 int _nib_get_route(const ipv6_addr_t *dst, gnrc_pktsnip_t *ctx,
786  gnrc_ipv6_nib_ft_t *entry);
787 
797 uint32_t _evtimer_lookup(const void *ctx, uint16_t type);
798 
807 static inline void _evtimer_add(void *ctx, int16_t type,
808  evtimer_msg_event_t *event, uint32_t offset)
809 {
810 #ifdef MODULE_GNRC_IPV6
811  kernel_pid_t target_pid = gnrc_ipv6_pid;
812 #else
813  kernel_pid_t target_pid = KERNEL_PID_LAST; /* just for testing */
814 #endif
815  evtimer_del((evtimer_t *)(&_nib_evtimer), (evtimer_event_t *)event);
816  event->event.next = NULL;
817  event->event.offset = offset;
818  event->msg.type = type;
819  event->msg.content.ptr = ctx;
820  evtimer_add_msg(&_nib_evtimer, event, target_pid);
821 }
822 
823 #ifdef __cplusplus
824 }
825 #endif
826 
827 #endif /* PRIV_NIB_INTERNAL_H */
828 
Types used by the kernel.
EUI-64 data type definition.
#define GNRC_IPV6_NIB_L2ADDR_MAX_LEN
Maximum link-layer address length (aligned)
Definitions for IPv6 addresses.
Context buffer definitions.
int16_t kernel_pid_t
Unique process identifier.
Definition: kernel_types.h:83
Forwarding table definitions.
bitfields operations on bitfields of arbitrary length
Forwarding table entry view on NIB.
Definition: ft.h:35
void evtimer_del(evtimer_t *evtimer, evtimer_event_t *event)
Removes an event from an event timer.
#define KERNEL_PID_LAST
The last valid PID (inclusive).
Definition: kernel_types.h:73
evtimer_msg_event_t reply_rs
Event for GNRC_IPV6_NIB_REPLY_RS.
Neighbor cache entry view on NIB.
Definition: nc.h:142
event structure
Definition: event.h:127
uint16_t info
Information flags.
uint8_t ns_sent
Neighbor solicitations sent for probing.
ipv6_addr_t ipv6
Neighbors IPv6 address.
uint8_t mode
NIB entry mode.
Neighbor cache definitions.
On-link NIB entry.
Definition: _nib-internal.h:92
struct _nib_onl_entry * next
next removable entry
Definition: _nib-internal.h:93
POSIX.1-2008 compliant version of the assert macro.
uint8_t l2addr[GNRC_IPV6_NIB_L2ADDR_MAX_LEN]
Link-layer address of _nib_onl_entry_t::next_hop.
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:104
Event timer.
Definition: evtimer.h:70
evtimer_msg_event_t addr_reg_timeout
Event for GNRC_IPV6_NIB_ADDR_REG_TIMEOUT.
eui64_t eui64
The neighbors EUI-64 (used for DAD)
Configuration macro definitions for neighbor information base.
Definitions for GNRC&#39;s IPv6 implementation.
IPC-based evtimer definitions.
data type for packet queue nodes
Definition: pktqueue.h:37
evtimer_msg_event_t nud_timeout
Event for GNRC_IPV6_NIB_SND_UC_NS, GNRC_IPV6_NIB_SND_MC_NS, GNRC_IPV6_NIB_REACH_TIMEOUT and GNRC_IPV6...
#define BITFIELD(NAME, SIZE)
Declare a bitfield of a given size.
Definition: bitfield.h:42
#define IPV6_ADDR_BIT_LEN
Length of an IPv6 address in bit.
Definition: ipv6/addr.h:43
#define GNRC_SIXLOWPAN_CTX_SIZE
maximum number of entries in context buffer
Definition: ctx.h:38
gnrc_pktqueue_t * pktqueue
queue for packets currently in address resolution
RIOT synchronization API.
#define GNRC_IPV6_NIB_OFFL_NUMOF
Number of off-link entries in NIB.
evtimer_msg_event_t snd_na
Event for GNRC_IPV6_NIB_SND_NA.
Internal NIB-representation of the authoritative border router for multihop prefix and 6LoWPAN contex...
IPC-message event.
Definition: evtimer_msg.h:40
Type to represent parts (either headers or payload) of a packet, called snips.
Data type to represent an IPv6 address.
Definition: ipv6/addr.h:74
Mutex structure.
Definition: mutex.h:36
Data type to represent an EUI-64.
Definition: eui64.h:37
Packet queue definitions.
IPv6 neighbor discovery message type definitions.
Common interface to the software PRNG.
Default route NIB entry.
uint8_t l2addr_len
length in bytes of _nib_onl_entry_t::l2addr
Off-link NIB entry.
static void evtimer_add_msg(evtimer_msg_t *evtimer, evtimer_msg_event_t *event, kernel_pid_t target_pid)
Adds event to an event timer that handles events via IPC.
Definition: evtimer_msg.h:53
kernel_pid_t gnrc_ipv6_pid
The PID to the IPv6 thread.
Generic event.
Definition: evtimer.h:57
uint8_t mode
mode of the off-link entry