_nib-arsm.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 
21 #ifndef PRIV_NIB_ARSM_H
22 #define PRIV_NIB_ARSM_H
23 
24 #include <kernel_defines.h>
25 #include <stdint.h>
26 
27 #include "net/gnrc/ipv6/nib/conf.h"
28 #include "net/gnrc/netif.h"
29 #include "net/ndp.h"
30 #include "net/icmpv6.h"
31 #include "net/ipv6/hdr.h"
32 
33 #include "_nib-internal.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
53 void _snd_ns(const ipv6_addr_t *tgt, gnrc_netif_t *netif,
54  const ipv6_addr_t *src, const ipv6_addr_t *dst);
55 
68 void _snd_uc_ns(_nib_onl_entry_t *nbr, bool reset);
69 
83 void _handle_sl2ao(gnrc_netif_t *netif, const ipv6_hdr_t *ipv6,
84  const icmpv6_hdr_t *icmpv6, const ndp_opt_t *sl2ao);
85 
105 static inline uint32_t _exp_backoff_retrans_timer_factor(uint8_t ns_sent,
106  uint32_t retrans_timer,
107  uint32_t factor)
108 {
109  assert(NDP_MIN_RANDOM_FACTOR <= factor);
110  assert(factor < NDP_MAX_RANDOM_FACTOR);
111  assert(ns_sent <= NDP_MAX_NS_NUMOF);
112  /* backoff according to https://tools.ietf.org/html/rfc7048 with
113  * BACKOFF_MULTIPLE == 2 */
114  uint32_t res = (uint32_t)(((uint64_t)(((uint32_t) 1) << ns_sent) *
115  retrans_timer * factor) / US_PER_MS);
116  /* random factors were statically multiplied with 1000 */
117  if (res > NDP_MAX_RETRANS_TIMER_MS) {
119  }
120  return res;
121 }
122 
123 #if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_ARSM) || defined(DOXYGEN)
130 void _handle_snd_ns(_nib_onl_entry_t *nbr);
131 
138 void _handle_state_timeout(_nib_onl_entry_t *nbr);
139 
146 void _probe_nbr(_nib_onl_entry_t *nbr, bool reset);
147 
163 void _handle_adv_l2(gnrc_netif_t *netif, _nib_onl_entry_t *nce,
164  const icmpv6_hdr_t *icmpv6, const ndp_opt_t *tl2ao);
165 
174 void _recalc_reach_time(gnrc_netif_ipv6_t *netif);
175 
183 void _set_reachable(gnrc_netif_t *netif, _nib_onl_entry_t *nce);
184 
191 void _set_unreachable(gnrc_netif_t *netif, _nib_onl_entry_t *nce);
192 
198 static inline void _init_iface_arsm(gnrc_netif_t *netif)
199 {
201  _recalc_reach_time(&netif->ipv6);
202 }
203 
209 static inline void _deinit_iface_arsm(gnrc_netif_t *netif)
210 {
211  _evtimer_del(&netif->ipv6.recalc_reach_time);
212 }
213 
221 static inline uint16_t _get_nud_state(_nib_onl_entry_t *nbr)
222 {
224 }
225 
234 void _set_nud_state(gnrc_netif_t *netif, _nib_onl_entry_t *nbr,
235  uint16_t state);
236 
247 bool _is_reachable(_nib_onl_entry_t *entry);
248 #else /* CONFIG_GNRC_IPV6_NIB_ARSM || defined(DOXYGEN) */
249 #define _handle_snd_ns(ctx) (void)ctx
250 #define _handle_state_timeout(ctx) (void)ctx
251 #define _probe_nbr(nbr, reset) (void)nbr; (void)reset
252 #define _init_iface_arsm(netif) (void)netif
253 #define _deinit_iface_arsm(netif) (void)netif
254 #define _handle_adv_l2(netif, nce, icmpv6, tl2ao) (void)netif; (void)nce; \
255  (void)icmpv6; (void)tl2ao
256 #define _recalc_reach_time(netif) (void)netif
257 #define _set_reachable(netif, nce) (void)netif; (void)nce
258 
259 #define _get_nud_state(nbr) (GNRC_IPV6_NIB_NC_INFO_NUD_STATE_UNMANAGED)
260 #define _set_nud_state(netif, nce, state) (void)netif; (void)nce; (void)state
261 #define _is_reachable(entry) (true)
262 #endif /* CONFIG_GNRC_IPV6_NIB_ARSM || defined(DOXYGEN) */
263 
264 #ifdef __cplusplus
265 }
266 #endif
267 
268 #endif /* PRIV_NIB_ARSM_H */
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:136
Definition for GNRC's network interfaces.
#define GNRC_IPV6_NIB_NC_INFO_NUD_STATE_MASK
Mask for neighbor unreachability detection (NUD) states.
Definition: nc.h:47
void _snd_ns(const ipv6_addr_t *tgt, gnrc_netif_t *netif, const ipv6_addr_t *src, const ipv6_addr_t *dst)
Sends neighbor solicitation (including ARO if required)
#define NDP_MAX_RETRANS_TIMER_MS
MAX_RETRANS_TIMER (in ms)
Definition: ndp.h:193
#define NDP_REACH_MS
REACHABLE_TIME (in ms)
Definition: ndp.h:186
#define NDP_MAX_NS_NUMOF
Maximum retransmission of neighbor solicitations when UNREACHABLE.
Definition: ndp.h:202
#define NDP_MAX_RANDOM_FACTOR
MAX_RANDOM_FACTOR (x 1000)
Definition: ndp.h:205
#define NDP_MIN_RANDOM_FACTOR
MIN_RANDOM_FACTOR (x 1000)
Definition: ndp.h:204
#define US_PER_MS
The number of microseconds per millisecond.
Definition: time_units.h:90
ICMPv6 type and function definitions.
Configuration macro definitions for neighbor information base.
Common macros and compiler attributes/pragmas configuration.
IPv6 neighbor discovery message type definitions.
IPv6 header type and helper function definitions.
On-link NIB entry .
Definition: _nib-internal.h:94
uint16_t info
Information flags.
IPv6 component for gnrc_netif_t.
Definition: ipv6.h:78
evtimer_msg_event_t recalc_reach_time
Event for GNRC_IPV6_NIB_RECALC_REACH_TIME.
Definition: ipv6.h:145
uint32_t reach_time_base
Base for random reachable time calculation and advertised reachable time in ms (if GNRC_NETIF_FLAGS_I...
Definition: ipv6.h:189
Representation of a network interface.
Definition: netif.h:135
gnrc_netif_ipv6_t ipv6
IPv6 component.
Definition: netif.h:147
General ICMPv6 message format.
Definition: icmpv6.h:138
Data type to represent an IPv6 packet header.
Definition: hdr.h:66
General NDP option format.
Definition: ndp.h:298
Data type to represent an IPv6 address.
Definition: addr.h:72