ipv6/netif.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 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 NET_GNRC_IPV6_NETIF_H
22 #define NET_GNRC_IPV6_NETIF_H
23 
24 #include <stdbool.h>
25 #include <stdint.h>
26 #include <stdlib.h>
27 
28 #include "kernel_defines.h"
29 #include "kernel_types.h"
30 #include "mutex.h"
31 #include "net/ipv6.h"
32 #include "net/ipv6/addr.h"
33 #include "xtimer.h"
34 
35 #ifdef MODULE_NETSTATS_IPV6
36 #include "net/netstats.h"
37 #endif
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
46 #ifdef MODULE_GNRC_RPL
47 /* RPL needs all-RPL-nodes multicast address */
48 # define GNRC_IPV6_NETIF_RPL_ADDR (1)
49 #else
50 # define GNRC_IPV6_NETIF_RPL_ADDR (0)
51 #endif
52 #ifdef MODULE_GNRC_IPV6_ROUTER
53 /* routers need all-routers multicast address */
54 # define GNRC_IPV6_NETIF_RTR_ADDR (1)
55 #else
56 # define GNRC_IPV6_NETIF_RTR_ADDR (0)
57 #endif
58 
64 #ifndef GNRC_IPV6_NETIF_ADDR_NUMOF
65 #define GNRC_IPV6_NETIF_ADDR_NUMOF (6 + GNRC_IPV6_NETIF_RPL_ADDR + GNRC_IPV6_NETIF_RTR_ADDR)
66 #endif
67 
81 #ifndef GNRC_IPV6_NETIF_DEFAULT_MTU
82 #define GNRC_IPV6_NETIF_DEFAULT_MTU (IPV6_MIN_MTU)
83 #endif
84 
95 #define GNRC_IPV6_NETIF_DEFAULT_HL (64)
96 
107 #define GNRC_IPV6_NETIF_DEFAULT_MAX_ADV_INT (600U)
108 
112 #define GNRC_IPV6_NETIF_DEFAULT_MIN_ADV_INT (200U)
113 
117 #define GNRC_IPV6_NETIF_DEFAULT_ROUTER_LTIME (1800U)
118 
129 #define GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST (0x00)
130 #define GNRC_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST (0x01)
139 #define GNRC_IPV6_NETIF_ADDR_FLAGS_NDP_AUTO (0x40)
140 
148 #define GNRC_IPV6_NETIF_ADDR_FLAGS_NDP_ON_LINK (0x80)
149 
171 #define GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN (0x0001)
172 
176 #define GNRC_IPV6_NETIF_FLAGS_ROUTER (0x0002)
177 
182 #define GNRC_IPV6_NETIF_FLAGS_RTR_ADV (0x0004)
183 
188 #define GNRC_IPV6_NETIF_FLAGS_ADV_MTU (0x0008)
189 
194 #define GNRC_IPV6_NETIF_FLAGS_ADV_CUR_HL (0x0010)
195 
200 #define GNRC_IPV6_NETIF_FLAGS_ADV_REACH_TIME (0x0020)
201 
206 #define GNRC_IPV6_NETIF_FLAGS_ADV_RETRANS_TIMER (0x0040)
207 
211 #define GNRC_IPV6_NETIF_FLAGS_IS_WIRED (0x0080)
212 
217 #define GNRC_IPV6_NETIF_FLAGS_RTR_ADV_POS (8U)
218 
223 #define GNRC_IPV6_NETIF_FLAGS_RTR_ADV_MASK (0xc000)
224 
229 #define GNRC_IPV6_NETIF_FLAGS_OTHER_CONF (0x4000)
230 
235 #define GNRC_IPV6_NETIF_FLAGS_MANAGED (0x8000)
236 
243 typedef struct {
245  uint8_t flags;
246  uint8_t prefix_len;
258  uint32_t valid;
259 
265  uint32_t preferred;
275 
279 typedef struct {
286  uint16_t flags;
287  uint16_t mtu;
288  uint8_t cur_hl;
289 #if defined(MODULE_GNRC_NDP_HOST) || defined(MODULE_GNRC_SIXLOWPAN_ND)
290 
293  uint8_t rtr_sol_count;
294 #endif
295 #ifdef MODULE_GNRC_NDP_ROUTER
296 
299  uint8_t rtr_adv_count;
300 
306  uint16_t max_adv_int;
307 
314  uint16_t min_adv_int;
315 
316 #endif
317 #if defined (MODULE_GNRC_NDP_ROUTER) || defined (MODULE_GNRC_SIXLOWPAN_ND_ROUTER)
318 
324  uint16_t adv_ltime;
325 #endif
326 
331  uint32_t reach_time_base;
332 
341  uint32_t reach_time;
342 
348  uint32_t retrans_timer;
351 #if defined (MODULE_GNRC_NDP_ROUTER) || defined (MODULE_GNRC_SIXLOWPAN_ND_ROUTER)
354 #endif
355 #ifdef MODULE_NETSTATS_IPV6
356  netstats_t stats;
357 #endif
359 
363 void gnrc_ipv6_netif_init(void);
364 
373 
382 
392 
393 #if (defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER))
394 
403 void gnrc_ipv6_netif_set_router(gnrc_ipv6_netif_t *netif, bool enable);
404 
415 void gnrc_ipv6_netif_set_rtr_adv(gnrc_ipv6_netif_t *netif, bool enable);
416 #else
417 /* dummy macros to be able to "call" these functions when none of the relevant modules
418  * is implemented */
419 #define gnrc_ipv6_netif_set_router(netif, enable)
420 #define gnrc_ipv6_netif_set_rtr_adv(netif, enable)
421 #endif
422 
445 ipv6_addr_t *gnrc_ipv6_netif_add_addr(kernel_pid_t pid, const ipv6_addr_t *addr, uint8_t prefix_len,
446  uint8_t flags);
447 
456 
463 
474 
486 
504 
517 
541 
562 {
563  return container_of(addr, gnrc_ipv6_netif_addr_t, addr);
564 }
565 
586 static inline bool gnrc_ipv6_netif_addr_is_non_unicast(const ipv6_addr_t *addr)
587 {
588  return (bool)(container_of(addr, gnrc_ipv6_netif_addr_t, addr)->flags &
590 
591 }
592 
599 void gnrc_ipv6_netif_init_by_dev(void);
600 
611 #if defined(MODULE_NETSTATS_IPV6) || DOXYGEN
613 #endif
614 
615 #ifdef __cplusplus
616 }
617 #endif
618 
619 #endif /* NET_GNRC_IPV6_NETIF_H */
620 
uint8_t prefix_len
length of the prefix of the address
Definition: ipv6/netif.h:246
gnrc_ipv6_netif_t * gnrc_ipv6_netif_get(kernel_pid_t pid)
Get interface.
Types used by the kernel.
ipv6_addr_t * gnrc_ipv6_netif_match_prefix(kernel_pid_t pid, const ipv6_addr_t *prefix)
Searches for the first address matching a prefix best on an interface.
Definition of net statistics.
uint16_t flags
flags for 6LoWPAN and Neighbor Discovery
Definition: ipv6/netif.h:286
Definition of IPv6 interface type.
Definition: ipv6/netif.h:279
Definitions for IPv6 addresses.
xtimer_t rtr_adv_timer
Timer for periodic router advertisements.
Definition: ipv6/netif.h:352
int16_t kernel_pid_t
Unique process identifier.
Definition: kernel_types.h:83
xtimer_t rtr_sol_timer
Timer for periodic router solicitations.
Definition: ipv6/netif.h:349
kernel_pid_t gnrc_ipv6_netif_find_by_addr(ipv6_addr_t **out, const ipv6_addr_t *addr)
Searches for an address on all interfaces.
xtimer_t valid_timeout
Validity timeout timer.
Definition: ipv6/netif.h:269
uint16_t min_adv_int
Minimum time in seconds between sending unsolicited multicast router advertisements.
Definition: ipv6/netif.h:314
kernel_pid_t gnrc_ipv6_netif_find_by_prefix(ipv6_addr_t **out, const ipv6_addr_t *prefix)
Searches for the first address matching a prefix best on all interfaces.
void gnrc_ipv6_netif_init_by_dev(void)
Initializes an interface with device-dependent values.
Global statistics struct.
static gnrc_ipv6_netif_addr_t * gnrc_ipv6_netif_addr_get(const ipv6_addr_t *addr)
Get interface specific meta-information on an address.
Definition: ipv6/netif.h:561
void gnrc_ipv6_netif_remove(kernel_pid_t pid)
Remove interface from IPv6.
uint16_t mtu
Maximum Transmission Unit (MTU) of the interface.
Definition: ipv6/netif.h:287
kernel_pid_t pid
PID of the interface.
Definition: ipv6/netif.h:285
uint32_t retrans_timer
Time between retransmissions of neighbor solicitations to a neighbor.
Definition: ipv6/netif.h:348
xtimer interface definitions
void gnrc_ipv6_netif_set_rtr_adv(gnrc_ipv6_netif_t *netif, bool enable)
Set interface to router advertisement mode.
Describes a message object which can be sent between threads.
Definition: msg.h:184
Type to represent an IPv6 address registered to an interface.
Definition: ipv6/netif.h:243
uint32_t valid
The time in seconds this address is valid.
Definition: ipv6/netif.h:258
#define container_of(PTR, TYPE, MEMBER)
Returns the container of a pointer to a member.
msg_t rtr_sol_msg
msg_t for gnrc_ipv6_netif_t::rtr_sol_timer
Definition: ipv6/netif.h:350
ipv6_addr_t * gnrc_ipv6_netif_find_best_src_addr(kernel_pid_t pid, const ipv6_addr_t *dest, bool ll_only)
Searches for the best address on an interface usable as a source address for a given destination addr...
IPv6 include gathering header.
RIOT synchronization API.
msg_t valid_timeout_msg
msg_t for gnrc_ipv6_netif_addr_t::valid_timeout
Definition: ipv6/netif.h:270
uint8_t rtr_adv_count
Counter for initial router advertisements.
Definition: ipv6/netif.h:299
uint32_t reach_time
The time a neighbor is considered reachable after receiving a reachability confirmation.
Definition: ipv6/netif.h:341
static bool gnrc_ipv6_netif_addr_is_non_unicast(const ipv6_addr_t *addr)
Checks if an address is non-unicast.
Definition: ipv6/netif.h:586
uint8_t flags
flags
Definition: ipv6/netif.h:245
void gnrc_ipv6_netif_init(void)
Initializes the module.
uint16_t adv_ltime
The router lifetime to propagate in router advertisements.
Definition: ipv6/netif.h:324
msg_t rtr_adv_msg
msg_t for gnrc_ipv6_netif_t::rtr_adv_timer
Definition: ipv6/netif.h:353
void gnrc_ipv6_netif_set_router(gnrc_ipv6_netif_t *netif, bool enable)
Set interface to router mode.
#define GNRC_IPV6_NETIF_ADDR_NUMOF
Number of IPv6 addresses per interface.
Definition: ipv6/netif.h:65
Common macros and compiler attributes/pragmas configuration.
ipv6_addr_t addr
The address data.
Definition: ipv6/netif.h:244
void gnrc_ipv6_netif_remove_addr(kernel_pid_t pid, ipv6_addr_t *addr)
Remove an address from the interface.
void gnrc_ipv6_netif_add(kernel_pid_t pid)
Add interface to IPv6.
uint32_t preferred
The length of time that this address remains preferred.
Definition: ipv6/netif.h:265
Data type to represent an IPv6 address.
Definition: ipv6/addr.h:74
#define GNRC_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST
non-unicast address
Definition: ipv6/netif.h:130
xtimer timer structure
Definition: xtimer.h:70
Mutex structure.
Definition: mutex.h:36
uint16_t max_adv_int
Maximum time in seconds between sending unsolicited multicast router advertisements.
Definition: ipv6/netif.h:306
stdlib.h wrapper for MSP430
uint32_t reach_time_base
Base value in microseconds for computing random gnrc_ipv6_netif_t::reach_time.
Definition: ipv6/netif.h:331
ipv6_addr_t * gnrc_ipv6_netif_find_addr(kernel_pid_t pid, const ipv6_addr_t *addr)
Searches for an address on an interface.
netstats_t * gnrc_ipv6_netif_get_stats(kernel_pid_t pid)
Get sent and received statistics about IPv6 traffic on this interface.
void gnrc_ipv6_netif_reset_addr(kernel_pid_t pid)
Removes all addresses from the interface.
mutex_t mutex
mutex for the interface
Definition: ipv6/netif.h:284
uint8_t cur_hl
current hop limit for the interface
Definition: ipv6/netif.h:288
ipv6_addr_t * gnrc_ipv6_netif_add_addr(kernel_pid_t pid, const ipv6_addr_t *addr, uint8_t prefix_len, uint8_t flags)
Adds an address to an interface.