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 GNRC_IPV6_NETIF_H
22 #define 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 "net/netstats.h"
34 #include "xtimer.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
43 #ifdef MODULE_GNRC_RPL
44 /* RPL needs all-RPL-nodes multicast address */
45 # define GNRC_IPV6_NETIF_RPL_ADDR (1)
46 #else
47 # define GNRC_IPV6_NETIF_RPL_ADDR (0)
48 #endif
49 #ifdef MODULE_GNRC_IPV6_ROUTER
50 /* routers need all-routers multicast address */
51 # define GNRC_IPV6_NETIF_RTR_ADDR (1)
52 #else
53 # define GNRC_IPV6_NETIF_RTR_ADDR (0)
54 #endif
55 
61 #ifndef GNRC_IPV6_NETIF_ADDR_NUMOF
62 #define GNRC_IPV6_NETIF_ADDR_NUMOF (6 + GNRC_IPV6_NETIF_RPL_ADDR + GNRC_IPV6_NETIF_RTR_ADDR)
63 #endif
64 
78 #ifndef GNRC_IPV6_NETIF_DEFAULT_MTU
79 #define GNRC_IPV6_NETIF_DEFAULT_MTU (IPV6_MIN_MTU)
80 #endif
81 
92 #define GNRC_IPV6_NETIF_DEFAULT_HL (64)
93 
104 #define GNRC_IPV6_NETIF_DEFAULT_MAX_ADV_INT (600U)
105 
109 #define GNRC_IPV6_NETIF_DEFAULT_MIN_ADV_INT (200U)
110 
114 #define GNRC_IPV6_NETIF_DEFAULT_ROUTER_LTIME (1800U)
115 
126 #define GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST (0x00)
127 #define GNRC_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST (0x01)
136 #define GNRC_IPV6_NETIF_ADDR_FLAGS_NDP_AUTO (0x40)
137 
145 #define GNRC_IPV6_NETIF_ADDR_FLAGS_NDP_ON_LINK (0x80)
146 
168 #define GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN (0x0001)
169 
173 #define GNRC_IPV6_NETIF_FLAGS_ROUTER (0x0002)
174 
179 #define GNRC_IPV6_NETIF_FLAGS_RTR_ADV (0x0004)
180 
185 #define GNRC_IPV6_NETIF_FLAGS_ADV_MTU (0x0008)
186 
191 #define GNRC_IPV6_NETIF_FLAGS_ADV_CUR_HL (0x0010)
192 
197 #define GNRC_IPV6_NETIF_FLAGS_ADV_REACH_TIME (0x0020)
198 
203 #define GNRC_IPV6_NETIF_FLAGS_ADV_RETRANS_TIMER (0x0040)
204 
208 #define GNRC_IPV6_NETIF_FLAGS_IS_WIRED (0x0080)
209 
214 #define GNRC_IPV6_NETIF_FLAGS_RTR_ADV_POS (8U)
215 
220 #define GNRC_IPV6_NETIF_FLAGS_RTR_ADV_MASK (0xc000)
221 
226 #define GNRC_IPV6_NETIF_FLAGS_OTHER_CONF (0x4000)
227 
232 #define GNRC_IPV6_NETIF_FLAGS_MANAGED (0x8000)
233 
240 typedef struct {
242  uint8_t flags;
243  uint8_t prefix_len;
255  uint32_t valid;
256 
262  uint32_t preferred;
272 
276 typedef struct {
283  uint16_t flags;
284  uint16_t mtu;
285  uint8_t cur_hl;
286 #if defined(MODULE_GNRC_NDP_HOST) || defined(MODULE_GNRC_SIXLOWPAN_ND)
287 
290  uint8_t rtr_sol_count;
291 #endif
292 #ifdef MODULE_GNRC_NDP_ROUTER
293 
296  uint8_t rtr_adv_count;
297 
303  uint16_t max_adv_int;
304 
311  uint16_t min_adv_int;
312 
313 #endif
314 #if defined (MODULE_GNRC_NDP_ROUTER) || defined (MODULE_GNRC_SIXLOWPAN_ND_ROUTER)
315 
321  uint16_t adv_ltime;
322 #endif
323 
328  uint32_t reach_time_base;
329 
338  uint32_t reach_time;
339 
345  uint32_t retrans_timer;
348 #if defined (MODULE_GNRC_NDP_ROUTER) || defined (MODULE_GNRC_SIXLOWPAN_ND_ROUTER)
351 #endif
352 #ifdef MODULE_NETSTATS_IPV6
353  netstats_t stats;
354 #endif
356 
360 void gnrc_ipv6_netif_init(void);
361 
370 
379 
389 
390 #if (defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER))
391 
400 void gnrc_ipv6_netif_set_router(gnrc_ipv6_netif_t *netif, bool enable);
401 
412 void gnrc_ipv6_netif_set_rtr_adv(gnrc_ipv6_netif_t *netif, bool enable);
413 #else
414 /* dummy macros to be able to "call" these functions when none of the relevant modules
415  * is implemented */
416 #define gnrc_ipv6_netif_set_router(netif, enable)
417 #define gnrc_ipv6_netif_set_rtr_adv(netif, enable)
418 #endif
419 
442 ipv6_addr_t *gnrc_ipv6_netif_add_addr(kernel_pid_t pid, const ipv6_addr_t *addr, uint8_t prefix_len,
443  uint8_t flags);
444 
453 
460 
471 
483 
501 
514 
538 
559 {
560  return container_of(addr, gnrc_ipv6_netif_addr_t, addr);
561 }
562 
583 static inline bool gnrc_ipv6_netif_addr_is_non_unicast(const ipv6_addr_t *addr)
584 {
585  return (bool)(container_of(addr, gnrc_ipv6_netif_addr_t, addr)->flags &
587 
588 }
589 
596 void gnrc_ipv6_netif_init_by_dev(void);
597 
609 
610 #ifdef __cplusplus
611 }
612 #endif
613 
614 #endif /* NETIF_H */
615 
uint8_t prefix_len
length of the prefix of the address
Definition: ipv6/netif.h:243
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:283
Definition of IPv6 interface type.
Definition: ipv6/netif.h:276
Definitions for IPv6 addresses.
xtimer_t rtr_adv_timer
Timer for periodic router advertisements.
Definition: ipv6/netif.h:349
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:346
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:266
uint16_t min_adv_int
Minimum time in seconds between sending unsolicited multicast router advertisements.
Definition: ipv6/netif.h:311
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:558
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:284
kernel_pid_t pid
PID of the interface.
Definition: ipv6/netif.h:282
uint32_t retrans_timer
Time between retransmissions of neighbor solicitations to a neighbor.
Definition: ipv6/netif.h:345
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:240
uint32_t valid
The time in seconds this address is valid.
Definition: ipv6/netif.h:255
#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:347
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:267
uint8_t rtr_adv_count
Counter for initial router advertisements.
Definition: ipv6/netif.h:296
uint32_t reach_time
The time a neighbor is considered reachable after receiving a reachability confirmation.
Definition: ipv6/netif.h:338
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:583
uint8_t flags
flags
Definition: ipv6/netif.h:242
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:321
msg_t rtr_adv_msg
msg_t for gnrc_ipv6_netif_t::rtr_adv_timer
Definition: ipv6/netif.h:350
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:62
Common macros and compiler attributes/pragmas configuration.
ipv6_addr_t addr
The address data.
Definition: ipv6/netif.h:241
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:262
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:127
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:303
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:328
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:281
uint8_t cur_hl
current hop limit for the interface
Definition: ipv6/netif.h:285
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.