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 
21 #ifndef NET_GNRC_NETIF_INTERNAL_H
22 #define NET_GNRC_NETIF_INTERNAL_H
23 
24 #include "net/gnrc/netif.h"
25 #include "net/l2util.h"
26 #include "net/netopt.h"
27 
28 #ifdef MODULE_GNRC_IPV6_NIB
29 #include "net/gnrc/ipv6/nib/conf.h"
30 #endif
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
39 #define NETDEV_MSG_TYPE_EVENT (0x1234)
40 
48 void gnrc_netif_acquire(gnrc_netif_t *netif);
49 
57 void gnrc_netif_release(gnrc_netif_t *netif);
58 
59 #if defined(MODULE_GNRC_IPV6) || DOXYGEN
60 
95 int gnrc_netif_ipv6_addr_add_internal(gnrc_netif_t *netif,
96  const ipv6_addr_t *addr,
97  unsigned pfx_len, uint8_t flags);
98 
109 void gnrc_netif_ipv6_addr_remove_internal(gnrc_netif_t *netif,
110  const ipv6_addr_t *addr);
111 
112 
129 int gnrc_netif_ipv6_addr_idx(gnrc_netif_t *netif,
130  const ipv6_addr_t *addr);
131 
140 static inline uint8_t gnrc_netif_ipv6_addr_get_state(const gnrc_netif_t *netif,
141  int idx)
142 {
144 }
145 
156 static inline uint8_t gnrc_netif_ipv6_addr_dad_trans(const gnrc_netif_t *netif,
157  int idx)
158 {
160 }
161 
180 int gnrc_netif_ipv6_addr_match(gnrc_netif_t *netif,
181  const ipv6_addr_t *addr);
182 
209 ipv6_addr_t *gnrc_netif_ipv6_addr_best_src(gnrc_netif_t *netif,
210  const ipv6_addr_t *dst,
211  bool ll_only);
212 
224 gnrc_netif_t *gnrc_netif_get_by_ipv6_addr(const ipv6_addr_t *addr);
225 
235 gnrc_netif_t *gnrc_netif_get_by_prefix(const ipv6_addr_t *prefix);
236 
251 int gnrc_netif_ipv6_group_join_internal(gnrc_netif_t *netif,
252  const ipv6_addr_t *addr);
253 
264 void gnrc_netif_ipv6_group_leave_internal(gnrc_netif_t *netif,
265  const ipv6_addr_t *addr);
266 
283 int gnrc_netif_ipv6_group_idx(gnrc_netif_t *netif,
284  const ipv6_addr_t *addr);
285 #endif /* MODULE_GNRC_IPV6 */
286 
301 #if defined(MODULE_GNRC_IPV6_ROUTER) || defined(DOXYGEN)
302 static inline bool gnrc_netif_is_rtr(const gnrc_netif_t *netif)
303 {
304  return (netif->flags & GNRC_NETIF_FLAGS_IPV6_FORWARDING);
305 }
306 #else
307 #define gnrc_netif_is_rtr(netif) (false)
308 #endif
309 
323 #if defined(MODULE_GNRC_IPV6_ROUTER) || defined(DOXYGEN)
324 static inline bool gnrc_netif_is_rtr_adv(const gnrc_netif_t *netif)
325 {
326  return (netif->flags & GNRC_NETIF_FLAGS_IPV6_RTR_ADV);
327 }
328 #else
329 #define gnrc_netif_is_rtr_adv(netif) (false)
330 #endif
331 
349 #if ((GNRC_NETIF_NUMOF > 1) && defined(MODULE_GNRC_SIXLOWPAN)) || \
350  defined(MODULE_GNRC_SIXLOENC) || defined(DOXYGEN)
351 bool gnrc_netif_is_6lo(const gnrc_netif_t *netif);
352 #elif (GNRC_NETIF_NUMOF == 1) && defined(MODULE_GNRC_SIXLOWPAN)
353 #define gnrc_netif_is_6lo(netif) (true)
354 #else
355 #define gnrc_netif_is_6lo(netif) (false)
356 #endif
357 
372 #if GNRC_IPV6_NIB_CONF_6LN || defined(DOXYGEN)
373 static inline bool gnrc_netif_is_6ln(const gnrc_netif_t *netif)
374 {
375  return (netif->flags & GNRC_NETIF_FLAGS_6LN);
376 }
377 #else
378 #define gnrc_netif_is_6ln(netif) (false)
379 #endif
380 
395 #if (GNRC_IPV6_NIB_CONF_6LR && \
396  /* if flag checkers even evaluate, otherwise just assume their result */ \
397  (defined(MODULE_GNRC_IPV6_ROUTER) || \
398  (GNRC_NETIF_NUMOF > 1) || !defined(MODULE_GNRC_SIXLOWPAN))) || \
399  defined(DOXYGEN)
400 static inline bool gnrc_netif_is_6lr(const gnrc_netif_t *netif)
401 {
402  return gnrc_netif_is_rtr(netif) && gnrc_netif_is_6ln(netif);
403 }
404 #else
405 #define gnrc_netif_is_6lr(netif) (false)
406 #endif
407 
422 #if GNRC_IPV6_NIB_CONF_6LBR
423 static inline bool gnrc_netif_is_6lbr(const gnrc_netif_t *netif)
424 {
425  return (netif->flags & GNRC_NETIF_FLAGS_6LO_ABR) &&
426  gnrc_netif_is_6lr(netif);
427 }
428 #else
429 #define gnrc_netif_is_6lbr(netif) (false)
430 #endif
431 
452 netopt_t gnrc_netif_get_l2addr_opt(const gnrc_netif_t *netif);
453 
474 int gnrc_netif_eui64_from_addr(const gnrc_netif_t *netif,
475  const uint8_t *addr, size_t addr_len,
476  eui64_t *eui64);
477 
493 static inline int gnrc_netif_get_eui64(gnrc_netif_t *netif, eui64_t *eui64)
494 {
495 #if GNRC_NETIF_L2ADDR_MAXLEN > 0
496  if (netif->flags & GNRC_NETIF_FLAGS_HAS_L2ADDR) {
497  return gnrc_netif_eui64_from_addr(netif,
498  netif->l2addr, netif->l2addr_len,
499  eui64);
500  }
501 #endif /* GNRC_NETIF_L2ADDR_MAXLEN > 0 */
502  (void)netif;
503  (void)eui64;
504  return -ENOTSUP;
505 }
506 
513 void gnrc_netif_init_6ln(gnrc_netif_t *netif);
514 
515 #if defined(MODULE_GNRC_IPV6) || defined(DOXYGEN)
516 
522 void gnrc_netif_ipv6_init_mtu(gnrc_netif_t *netif);
523 
547 int gnrc_netif_ipv6_iid_from_addr(const gnrc_netif_t *netif,
548  const uint8_t *addr, size_t addr_len,
549  eui64_t *iid);
550 
575 static inline int gnrc_netif_ipv6_iid_to_addr(const gnrc_netif_t *netif,
576  const eui64_t *iid, uint8_t *addr)
577 {
579  return l2util_ipv6_iid_to_addr(netif->device_type, iid, addr);
580 }
581 
601 static inline int gnrc_netif_ipv6_get_iid(gnrc_netif_t *netif, eui64_t *iid)
602 {
603 #if GNRC_NETIF_L2ADDR_MAXLEN > 0
604  if (netif->flags & GNRC_NETIF_FLAGS_HAS_L2ADDR) {
605  return gnrc_netif_ipv6_iid_from_addr(netif,
606  netif->l2addr, netif->l2addr_len,
607  iid);
608  }
609 #endif /* GNRC_NETIF_L2ADDR_MAXLEN > 0 */
610  (void)netif;
611  (void)iid;
612  return -ENOTSUP;
613 }
614 
642 static inline int gnrc_netif_ndp_addr_len_from_l2ao(gnrc_netif_t *netif,
643  const ndp_opt_t *opt)
644 {
646  return l2util_ndp_addr_len_from_l2ao(netif->device_type, opt);
647 }
648 #else /* defined(MODULE_GNRC_IPV6) || defined(DOXYGEN) */
649 #define gnrc_netif_ipv6_init_mtu(netif) (void)netif
650 #define gnrc_netif_ipv6_iid_from_addr(netif, addr, addr_len, iid) (-ENOTSUP)
651 #define gnrc_netif_ipv6_iid_to_addr(netif, iid, addr) (-ENOTSUP)
652 #define gnrc_netif_ndp_addr_len_from_l2ao(netif, opt) (-ENOTSUP)
653 #define gnrc_netif_ipv6_get_iid(netif, iid) (-ENOTSUP)
654 #endif /* defined(MODULE_GNRC_IPV6) || defined(DOXYGEN) */
655 
657 #ifdef __cplusplus
658 }
659 #endif
660 
661 #endif /* NET_GNRC_NETIF_INTERNAL_H */
662 
#define GNRC_NETIF_IPV6_ADDRS_FLAGS_STATE_TENTATIVE
Tentative states (with encoded DAD retransmissions)
Definition: ipv6.h:55
uint8_t l2addr[GNRC_NETIF_L2ADDR_MAXLEN]
The link-layer address currently used as the source address on this interface.
Definition: netif.h:104
uint32_t flags
Flags for the interface.
Definition: netif.h:96
#define GNRC_NETIF_FLAGS_6LO_ABR
This interface acts as a 6Lo border router to the LLN.
Definition: flags.h:103
#define GNRC_NETIF_FLAGS_6LN
This interface represents a 6Lo node (6LN) according to RFC 6775.
Definition: flags.h:126
General NDP option format.
Definition: ndp.h:286
uint8_t device_type
Device type.
Definition: netif.h:125
#define GNRC_NETIF_FLAGS_IPV6_RTR_ADV
Network interface advertises itself as an IPv6 router (implies GNRC_NETIF_FLAGS_IPV6_FORWARDING to be...
Definition: flags.h:58
Link-layer helper function definitions.
uint8_t l2addr_len
Length in bytes of gnrc_netif_t::l2addr.
Definition: netif.h:111
netopt_t
Global list of configuration options available throughout the network stack, e.g. ...
Definition: netopt.h:59
#define ENOTSUP
Not supported (may be the same value as [EOPNOTSUPP]).
Definition: errno.h:130
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:104
Configuration macro definitions for neighbor information base.
int l2util_ipv6_iid_to_addr(int dev_type, const eui64_t *iid, uint8_t *addr)
Converts an IPv6 IID to a hardware address.
gnrc_netif_ipv6_t ipv6
IPv6 component.
Definition: netif.h:86
#define GNRC_NETIF_FLAGS_IPV6_FORWARDING
Network interface is enabled for IPv6 forwarding.
Definition: flags.h:52
Representation of a network interface.
Definition: netif.h:74
#define GNRC_NETIF_IPV6_ADDRS_FLAGS_STATE_MASK
Mask for the address' state.
Definition: ipv6.h:46
Definition of global configuration options.
Definition for GNRC's network interfaces.
Data type to represent an IPv6 address.
Definition: addr.h:74
Data type to represent an EUI-64.
Definition: eui64.h:55
uint8_t addrs_flags[CONFIG_GNRC_NETIF_IPV6_ADDRS_NUMOF]
Flags for gnrc_netif_t::ipv6_addrs.
Definition: ipv6.h:86
int l2util_ndp_addr_len_from_l2ao(int dev_type, const ndp_opt_t *opt)
Derives the length of the link-layer address in an NDP link-layer address option from that option's l...
#define GNRC_NETIF_FLAGS_HAS_L2ADDR
Network interface has link-layer address.
Definition: flags.h:47