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 <kernel_defines.h>
25 
26 #include "net/gnrc/netif.h"
27 #include "net/l2util.h"
28 #include "net/netopt.h"
29 
30 #ifdef MODULE_GNRC_IPV6_NIB
31 #include "net/gnrc/ipv6/nib/conf.h"
32 #endif
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
41 #define NETDEV_MSG_TYPE_EVENT (0x1234)
42 
50 void gnrc_netif_acquire(gnrc_netif_t *netif);
51 
59 void gnrc_netif_release(gnrc_netif_t *netif);
60 
61 #if IS_USED(MODULE_GNRC_NETIF_IPV6) || DOXYGEN
62 
97 int gnrc_netif_ipv6_addr_add_internal(gnrc_netif_t *netif,
98  const ipv6_addr_t *addr,
99  unsigned pfx_len, uint8_t flags);
100 
111 void gnrc_netif_ipv6_addr_remove_internal(gnrc_netif_t *netif,
112  const ipv6_addr_t *addr);
113 
114 
131 int gnrc_netif_ipv6_addr_idx(gnrc_netif_t *netif,
132  const ipv6_addr_t *addr);
133 
142 static inline uint8_t gnrc_netif_ipv6_addr_get_state(const gnrc_netif_t *netif,
143  int idx)
144 {
146 }
147 
158 static inline uint8_t gnrc_netif_ipv6_addr_dad_trans(const gnrc_netif_t *netif,
159  int idx)
160 {
162 }
163 
182 int gnrc_netif_ipv6_addr_match(gnrc_netif_t *netif,
183  const ipv6_addr_t *addr);
184 
211 ipv6_addr_t *gnrc_netif_ipv6_addr_best_src(gnrc_netif_t *netif,
212  const ipv6_addr_t *dst,
213  bool ll_only);
214 
226 gnrc_netif_t *gnrc_netif_get_by_ipv6_addr(const ipv6_addr_t *addr);
227 
237 gnrc_netif_t *gnrc_netif_get_by_prefix(const ipv6_addr_t *prefix);
238 
253 int gnrc_netif_ipv6_group_join_internal(gnrc_netif_t *netif,
254  const ipv6_addr_t *addr);
255 
266 void gnrc_netif_ipv6_group_leave_internal(gnrc_netif_t *netif,
267  const ipv6_addr_t *addr);
268 
285 int gnrc_netif_ipv6_group_idx(gnrc_netif_t *netif,
286  const ipv6_addr_t *addr);
287 
295 static inline void gnrc_netif_ipv6_bus_post(gnrc_netif_t *netif, int type,
296  const void *ctx)
297 {
298 #ifdef MODULE_GNRC_NETIF_BUS
299  msg_bus_post(&netif->bus[GNRC_NETIF_BUS_IPV6], type, ctx);
300 #else
301  (void) netif;
302  (void) type;
303  (void) ctx;
304 #endif
305 }
306 #endif /* IS_USED(MODULE_GNRC_NETIF_IPV6) || defined(DOXYGEN) */
307 
322 static inline bool gnrc_netif_is_rtr(const gnrc_netif_t *netif)
323 {
324  if (IS_USED(MODULE_GNRC_IPV6_ROUTER)) {
325  return (netif->flags & GNRC_NETIF_FLAGS_IPV6_FORWARDING);
326  }
327  else {
328  return false;
329  }
330 }
331 
345 static inline bool gnrc_netif_is_rtr_adv(const gnrc_netif_t *netif)
346 {
347  if (IS_USED(MODULE_GNRC_IPV6_ROUTER)) {
348  return (netif->flags & GNRC_NETIF_FLAGS_IPV6_RTR_ADV);
349  }
350  else {
351  return false;
352  }
353 }
354 
364 bool gnrc_netif_dev_is_6lo(const gnrc_netif_t *netif);
365 
383 static inline bool gnrc_netif_is_6lo(const gnrc_netif_t *netif)
384 {
385  if ((!gnrc_netif_highlander() &&
386  IS_USED(MODULE_GNRC_SIXLOWPAN)) || \
387  IS_USED(MODULE_GNRC_SIXLOENC)) {
388  return gnrc_netif_dev_is_6lo(netif);
389  }
390  else if (gnrc_netif_highlander() && IS_USED(MODULE_GNRC_SIXLOWPAN)) {
391  return true;
392  }
393  else {
394  return false;
395  }
396 }
397 
412 static inline bool gnrc_netif_is_6ln(const gnrc_netif_t *netif)
413 {
415  return (netif->flags & GNRC_NETIF_FLAGS_6LN);
416  }
417  else {
418  return false;
419  }
420 }
421 
436 static inline bool gnrc_netif_is_6lr(const gnrc_netif_t *netif)
437 {
438  /* if flag checkers even evaluate, otherwise just assume their result */
440  (IS_USED(MODULE_GNRC_IPV6_ROUTER) ||
441  (!gnrc_netif_highlander()) ||
442  !IS_USED(MODULE_GNRC_SIXLOWPAN))) {
443  return gnrc_netif_is_rtr(netif) && gnrc_netif_is_6ln(netif);
444  }
445  else {
446  return false;
447  }
448 }
449 
464 static inline bool gnrc_netif_is_6lbr(const gnrc_netif_t *netif)
465 {
467  return (netif->flags & GNRC_NETIF_FLAGS_6LO_ABR) &&
468  gnrc_netif_is_6lr(netif);
469  }
470  else {
471  return false;
472  }
473 }
474 
495 netopt_t gnrc_netif_get_l2addr_opt(const gnrc_netif_t *netif);
496 
517 int gnrc_netif_eui64_from_addr(const gnrc_netif_t *netif,
518  const uint8_t *addr, size_t addr_len,
519  eui64_t *eui64);
520 
536 static inline int gnrc_netif_get_eui64(gnrc_netif_t *netif, eui64_t *eui64)
537 {
538 #if GNRC_NETIF_L2ADDR_MAXLEN > 0
539  if (netif->flags & GNRC_NETIF_FLAGS_HAS_L2ADDR) {
540  return gnrc_netif_eui64_from_addr(netif,
541  netif->l2addr, netif->l2addr_len,
542  eui64);
543  }
544 #endif /* GNRC_NETIF_L2ADDR_MAXLEN > 0 */
545  (void)netif;
546  (void)eui64;
547  return -ENOTSUP;
548 }
549 
556 void gnrc_netif_init_6ln(gnrc_netif_t *netif);
557 
558 #if IS_USED(MODULE_GNRC_NETIF_IPV6) || defined(DOXYGEN)
559 
565 void gnrc_netif_ipv6_init_mtu(gnrc_netif_t *netif);
566 
590 int gnrc_netif_ipv6_iid_from_addr(const gnrc_netif_t *netif,
591  const uint8_t *addr, size_t addr_len,
592  eui64_t *iid);
593 
618 static inline int gnrc_netif_ipv6_iid_to_addr(const gnrc_netif_t *netif,
619  const eui64_t *iid, uint8_t *addr)
620 {
622  return l2util_ipv6_iid_to_addr(netif->device_type, iid, addr);
623 }
624 
644 static inline int gnrc_netif_ipv6_get_iid(gnrc_netif_t *netif, eui64_t *iid)
645 {
646 #if GNRC_NETIF_L2ADDR_MAXLEN > 0
647  if (netif->flags & GNRC_NETIF_FLAGS_HAS_L2ADDR) {
648  return gnrc_netif_ipv6_iid_from_addr(netif,
649  netif->l2addr, netif->l2addr_len,
650  iid);
651  }
652 #endif /* GNRC_NETIF_L2ADDR_MAXLEN > 0 */
653  (void)netif;
654  (void)iid;
655  return -ENOTSUP;
656 }
657 
685 static inline int gnrc_netif_ndp_addr_len_from_l2ao(gnrc_netif_t *netif,
686  const ndp_opt_t *opt)
687 {
689  return l2util_ndp_addr_len_from_l2ao(netif->device_type, opt);
690 }
691 #else /* IS_USED(MODULE_GNRC_NETIF_IPV6) || defined(DOXYGEN) */
692 #define gnrc_netif_ipv6_init_mtu(netif) (void)netif
693 #define gnrc_netif_ipv6_iid_from_addr(netif, addr, addr_len, iid) (-ENOTSUP)
694 #define gnrc_netif_ipv6_iid_to_addr(netif, iid, addr) (-ENOTSUP)
695 #define gnrc_netif_ndp_addr_len_from_l2ao(netif, opt) (-ENOTSUP)
696 #define gnrc_netif_ipv6_get_iid(netif, iid) (-ENOTSUP)
697 #endif /* IS_USED(MODULE_GNRC_NETIF_IPV6) || defined(DOXYGEN) */
698 
700 #ifdef __cplusplus
701 }
702 #endif
703 
704 #endif /* NET_GNRC_NETIF_INTERNAL_H */
705 
#define GNRC_NETIF_IPV6_ADDRS_FLAGS_STATE_TENTATIVE
Tentative states (with encoded DAD retransmissions)
Definition: ipv6.h:56
#define CONFIG_GNRC_IPV6_NIB_6LN
enable features for 6Lo node
Definition: conf.h:114
uint8_t l2addr[GNRC_NETIF_L2ADDR_MAXLEN]
The link-layer address currently used as the source address on this interface.
Definition: netif.h:150
#define CONFIG_GNRC_IPV6_NIB_6LR
enable features for 6Lo router
Definition: conf.h:103
uint32_t flags
Flags for the interface.
Definition: netif.h:132
provides gnrc_ipv6_event_t messages to subscribers
Definition: netif.h:75
#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
msg_bus_t bus[GNRC_NETIF_BUS_NUMOF]
Event Message Bus.
Definition: netif.h:125
#define IS_USED(module)
Checks whether a module is being used or not.
General NDP option format.
Definition: ndp.h:286
uint8_t device_type
Device type.
Definition: netif.h:171
#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:157
netopt_t
Global list of configuration options available throughout the network stack, e.g. ...
Definition: netopt.h:59
#define IS_ACTIVE(macro)
Allows to verify a macro definition outside the preprocessor.
static bool gnrc_netif_highlander(void)
Check if there can only be one gnrc_netif_t interface.
Definition: netif.h:331
#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:119
#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:107
#define GNRC_NETIF_IPV6_ADDRS_FLAGS_STATE_MASK
Mask for the address&#39; state.
Definition: ipv6.h:47
Definition of global configuration options.
Definition for GNRC&#39;s network interfaces.
static int msg_bus_post(msg_bus_t *bus, uint8_t type, const void *arg)
Post a message to a bus.
Definition: msg_bus.h:198
Common macros and compiler attributes/pragmas configuration.
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:87
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&#39;s l...
#define GNRC_NETIF_FLAGS_HAS_L2ADDR
Network interface has link-layer address.
Definition: flags.h:47
#define CONFIG_GNRC_IPV6_NIB_6LBR
enable features for 6Lo border router
Definition: conf.h:93