diff --git a/Makefile.dep b/Makefile.dep index d7b244c58a9216d16ec691e18d11af836b9d601e..4d7f2b4d0107059c5159f5627e2de53d41d1d49f 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -193,20 +193,6 @@ ifneq (,$(filter gnrc_ipv6_router_default,$(USEMODULE))) USEMODULE += gnrc_icmpv6 endif -ifneq (,$(filter gnrc_ndp_router,$(USEMODULE))) - USEMODULE += gnrc_ndp_node - USEMODULE += random - USEMODULE += xtimer -endif - -ifneq (,$(filter gnrc_ndp_node,$(USEMODULE))) - USEMODULE += gnrc_ndp_internal -endif - -ifneq (,$(filter gnrc_ndp_%,$(USEMODULE))) - USEMODULE += gnrc_ndp -endif - ifneq (,$(filter gnrc_ndp2,$(USEMODULE))) USEMODULE += gnrc_icmpv6 USEMODULE += gnrc_netif2 @@ -273,10 +259,6 @@ ifneq (,$(filter ipv6_hdr,$(USEMODULE))) USEMODULE += ipv6_addr endif -ifneq (,$(filter gnrc_ipv6_nc,$(USEMODULE))) - USEMODULE += ipv6_addr -endif - ifneq (,$(filter gnrc_ipv6_nib_6lbr,$(USEMODULE))) USEMODULE += gnrc_ipv6_nib_6lr endif diff --git a/examples/gnrc_minimal/Makefile b/examples/gnrc_minimal/Makefile index 63abb6075201276e9b56393ffb292f052daffbd6..09200a6ec65094f0080a8b17c05f11e2eb76e2fc 100644 --- a/examples/gnrc_minimal/Makefile +++ b/examples/gnrc_minimal/Makefile @@ -20,13 +20,13 @@ USEMODULE += gnrc_netdev_default USEMODULE += auto_init_gnrc_netif # Specify the minimum networking modules for IPv6 USEMODULE += gnrc_ipv6 -USEMODULE += gnrc_ndp # Additional networking modules that can be dropped if not needed USEMODULE += gnrc_icmpv6_echo # Use minimal standard PRNG USEMODULE += prng_minstd -CFLAGS += -DGNRC_PKTBUF_SIZE=512 -DGNRC_IPV6_NETIF_ADDR_NUMOF=4 -DGNRC_IPV6_NC_SIZE=1 +CFLAGS += -DGNRC_PKTBUF_SIZE=512 -DGNRC_NETIF2_IPV6_ADDRS_NUMOF=2 \ + -DGNRC_NETIF2_IPV6_GROUPS_NUMOF=2 -DGNRC_IPV6_NC_SIZE=1 # Change this to 0 show compiler invocation lines by default: QUIET ?= 1 diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index 450916b27f8d036a7cacbd258f1f8af88f66ed77..42abc69ed65c9f6084218badfd7803e44855abda 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -44,10 +44,6 @@ #include "net/gnrc/ipv6.h" #endif -#ifdef MODULE_GNRC_IPV6_NETIF -#include "net/gnrc/ipv6/netif.h" -#endif - #ifdef MODULE_L2_PING #include "l2_ping.h" #endif diff --git a/sys/include/net/gnrc.h b/sys/include/net/gnrc.h index 313bdbb7bfef9c0b36a79f7ce2baba531831b76b..75bb0e67ba2cc952ff988f3efd7b48b6ce1238a1 100644 --- a/sys/include/net/gnrc.h +++ b/sys/include/net/gnrc.h @@ -241,11 +241,10 @@ * USEMODULE += gnrc_ipv6_router * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * respectively. Those modules provide the bare minimum of IPv6 - * functionalities (no @ref net_gnrc_icmpv6, no @ref net_gnrc_ndp). Because - * of that, the @ref net_gnrc_ipv6_nc needs to be configured manually. If an - * IEEE 802.15.4 device is present @ref net_gnrc_sixlowpan will be included - * automatically, but no fragmentation or header compression support will be - * provided. + * functionalities (no @ref net_gnrc_icmpv6). Because of that, the + * @ref net_gnrc_ipv6_nib needs to be configured manually. If an IEEE 802.15.4 + * device is present @ref net_gnrc_sixlowpan will be included automatically, + * but no fragmentation or header compression support will be provided. * * - For @ref net_gnrc_icmpv6_echo "ICMPv6 echo request/reply (ping)" * functionality: diff --git a/sys/include/net/gnrc/ipv6/nc.h b/sys/include/net/gnrc/ipv6/nc.h deleted file mode 100644 index c233d90b948529a284a4088c579778c96661df4c..0000000000000000000000000000000000000000 --- a/sys/include/net/gnrc/ipv6/nc.h +++ /dev/null @@ -1,319 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser General - * Public License v2.1. See the file LICENSE in the top level directory for - * more details. - */ - -/** - * @defgroup net_gnrc_ipv6_nc IPv6 neighbor cache - * @ingroup net_gnrc_ipv6 - * @brief Translates IPv6 addresses to link layer addresses. - * @{ - * - * @file - * @brief Neighbor cache definitions. - * - * @author Martine Lenders <mlenders@inf.fu-berlin.de> - */ - -#ifndef NET_GNRC_IPV6_NC_H -#define NET_GNRC_IPV6_NC_H - -#include <assert.h> -#include <stdbool.h> -#include <stdint.h> -#include <string.h> - -#include "kernel_types.h" -#include "net/eui64.h" -#include "net/ipv6/addr.h" -#include "net/gnrc/netif.h" -#include "net/gnrc/pktqueue.h" -#include "xtimer.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef GNRC_IPV6_NC_SIZE -/** - * @brief The size of the neighbor cache - */ -#define GNRC_IPV6_NC_SIZE (GNRC_NETIF_NUMOF * 8) -#endif - -#ifndef GNRC_IPV6_NC_L2_ADDR_MAX -/** - * @brief The maximum size of a link layer address - */ -#define GNRC_IPV6_NC_L2_ADDR_MAX (8) -#endif - -/** - * @{ - * @name Flag definitions for gnrc_ipv6_nc_t - */ -/** - * @{ - * @brief States of a neighbor cache entry. - * - * @see <a href="http://tools.ietf.org/html/rfc4861#section-7.3.2"> - * RFC 4861, section 7.3.2 - * </a> - */ -#define GNRC_IPV6_NC_STATE_MASK (0x07) /**< Mask for neighbor cache state */ -#define GNRC_IPV6_NC_STATE_POS (0) /**< Shift of neighbor cache state */ - -#define GNRC_IPV6_NC_STATE_UNMANAGED (0x00) /**< The entry is not manage by NDP */ - -/** - * @brief The entry is unreachable - * - * @see <a href="http://tools.ietf.org/html/rfc7048#section-3"> - * RFC 7048, section 3 - * </a> - */ -#define GNRC_IPV6_NC_STATE_UNREACHABLE (0x01) -#define GNRC_IPV6_NC_STATE_INCOMPLETE (0x02) /**< Address resolution is performed */ -#define GNRC_IPV6_NC_STATE_STALE (0x03) /**< The entry is stale */ -#define GNRC_IPV6_NC_STATE_DELAY (0x04) /**< The entry was stale but packet was sent out */ -#define GNRC_IPV6_NC_STATE_PROBE (0x05) /**< Periodic reachabality confirmation */ -#define GNRC_IPV6_NC_STATE_REACHABLE (0x07) /**< The entry is reachable */ -/** - * @} - */ - -#define GNRC_IPV6_NC_IS_ROUTER (0x08) /**< The neighbor is a router */ - -#define GNRC_IPV6_NC_TYPE_MASK (0x30) /**< Mask for neighbor cache state */ - -/** - * @{ - * @brief States of a neighbor cache entry. - * - * @see <a href="http://tools.ietf.org/html/rfc6775#section-3.5"> - * RFC 6775, section 3.5 - * </a> - */ -/** - * @brief The entry has no type - * - * @details The node sents multicast Neighbor Solicitations for hosts. - */ -#define GNRC_IPV6_NC_TYPE_NONE (0x00) -#define GNRC_IPV6_NC_TYPE_GC (0x10) /**< The entry is marked for removal */ -#define GNRC_IPV6_NC_TYPE_TENTATIVE (0x20) /**< The entry is temporary */ -#define GNRC_IPV6_NC_TYPE_REGISTERED (0x30) /**< The entry is registered */ -/** - * @} - */ -/** - * @} - */ - -/** - * @brief Neighbor cache entry as defined in - * <a href="http://tools.ietf.org/html/rfc4861#section-5.1"> - * RFC 4861, section 5.1 - * </a>. - */ -typedef struct { -#ifdef MODULE_GNRC_NDP_NODE - gnrc_pktqueue_t *pkts; /**< Packets waiting for address resolution */ -#endif - ipv6_addr_t ipv6_addr; /**< IPv6 address of the neighbor */ - uint8_t l2_addr[GNRC_IPV6_NC_L2_ADDR_MAX]; /**< Link layer address of the neighbor */ - uint8_t l2_addr_len; /**< Length of gnrc_ipv6_nc_t::l2_addr */ - uint8_t flags; /**< Flags as defined above */ - kernel_pid_t iface; /**< PID to the interface where the neighbor is */ - xtimer_t rtr_timeout; /**< timeout timer for router flag */ - msg_t rtr_timeout_msg; /**< msg_t for gnrc_ipv6_nc_t::rtr_timeout */ - - /** - * @brief (Re)Transmission timer for neighbor solicitations of this entry and - * timeout for states. - */ - xtimer_t nbr_sol_timer; - msg_t nbr_sol_msg; /**< msg_t for gnrc_ipv6_nc_t::nbr_sol_timer */ - - /** - * @brief Delay timer for neighbor advertisements of this entry. - * - * @note Only needed for delayed anycast neighbor advertisements - * - * @see <a href="https://tools.ietf.org/html/rfc4861#section-7.2.7"> - * RFC 4861, section 7.2.7 - * </a> - */ - xtimer_t nbr_adv_timer; - msg_t nbr_adv_msg; /**< msg_t for gnrc_ipv6_nc_t::nbr_adv_timer */ - -#if defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER) - xtimer_t rtr_adv_timer; /**< Timer for periodic router advertisements */ - msg_t rtr_adv_msg; /**< msg_t for gnrc_ipv6_nc_t::rtr_adv_timer */ -#endif - -#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER - xtimer_t type_timeout; /**< Timer for type transmissions */ - msg_t type_timeout_msg; /**< msg_t for gnrc_ipv6_nc_t::type_timeout */ - eui64_t eui64; /**< the unique EUI-64 of the neighbor (might be - * different from L2 address, if l2_addr_len == 2) */ -#endif - - uint8_t probes_remaining; /**< remaining number of unanswered probes */ - /** - * @} - */ -} gnrc_ipv6_nc_t; - -/** - * @brief Initializes neighbor cache - */ -void gnrc_ipv6_nc_init(void); - -/** - * @brief Adds a neighbor to the neighbor cache - * - * @param[in] iface PID to the interface where the neighbor is. - * @param[in] ipv6_addr IPv6 address of the neighbor. Must not be NULL. - * @param[in] l2_addr Link layer address of the neighbor. NULL if unknown. - * @param[in] l2_addr_len Length of @p l2_addr, must be lesser than or equal - * to GNRC_IPV6_L2_ADDR_MAX. 0 if unknown. - * @param[in] flags Flags for the entry - * - * @return Pointer to new neighbor cache entry on success - * @return NULL, on failure - */ -gnrc_ipv6_nc_t *gnrc_ipv6_nc_add(kernel_pid_t iface, const ipv6_addr_t *ipv6_addr, - const void *l2_addr, size_t l2_addr_len, uint8_t flags); - -/** - * @brief Removes a neighbor from the neighbor cache - * - * @param[in] iface PID to the interface where the neighbor is. If it - * is KERNEL_PID_UNDEF it will be removed for all - * interfaces. - * @param[in] ipv6_addr IPv6 address of the neighbor - */ -void gnrc_ipv6_nc_remove(kernel_pid_t iface, const ipv6_addr_t *ipv6_addr); - -/** - * @brief Searches for any neighbor cache entry fitting the @p ipv6_addr. - * - * @param[in] iface PID to the interface where the neighbor is. If it - * is KERNEL_PID_UNDEF it will be searched on all - * interfaces. - * @param[in] ipv6_addr An IPv6 address - * - * @return The neighbor cache entry, if one is found. - * @return NULL, if none is found. - */ -gnrc_ipv6_nc_t *gnrc_ipv6_nc_get(kernel_pid_t iface, const ipv6_addr_t *ipv6_addr); - -/** - * @brief Gets next entry in neighbor cache after @p prev. - * - * @param[in] prev Previous entry. NULL to start iteration. - * - * @return The next entry in neighbor cache. - */ -gnrc_ipv6_nc_t *gnrc_ipv6_nc_get_next(gnrc_ipv6_nc_t *prev); - -/** - * @brief Gets next reachable router entry in neighbor cache after @p prev. - * - * @param[in] prev Previous router entry. NULL to start iteration. - * - * @return The next reachable router entry in neighbor cache. - */ -gnrc_ipv6_nc_t *gnrc_ipv6_nc_get_next_router(gnrc_ipv6_nc_t *prev); - -/** - * @brief Returns the state of a neighbor cache entry. - * - * @param[in] entry A neighbor cache entry - * - * @return The state of the neighbor cache entry as defined by its flags. - */ -static inline uint8_t gnrc_ipv6_nc_get_state(const gnrc_ipv6_nc_t *entry) -{ - return (entry->flags & GNRC_IPV6_NC_STATE_MASK); -} - -/** - * @brief Returns the type of a neighbor cache entry. - * - * @param[in] entry A neighbor cache entry - * - * @return The type of the neighbor cache entry as defined by its flags. - */ -static inline uint8_t gnrc_ipv6_nc_get_type(const gnrc_ipv6_nc_t *entry) -{ - return (entry->flags & GNRC_IPV6_NC_TYPE_MASK); -} - -/** - * @brief Checks if an entry is reachable (do not confuse with - * @ref GNRC_IPV6_NC_STATE_REACHABLE). - * - * @param[in] entry A neighbor cache entry - * - * @return true, if you can send packets to @p entry - * @return false, if you can't send packets to @p entry - */ -static inline bool gnrc_ipv6_nc_is_reachable(const gnrc_ipv6_nc_t *entry) -{ - switch (gnrc_ipv6_nc_get_state(entry)) { - case GNRC_IPV6_NC_STATE_UNREACHABLE: - case GNRC_IPV6_NC_STATE_INCOMPLETE: - return false; - - default: - return true; - } -} - -/** - * @brief Marks an entry as still reachable, if one with a fitting @p ipv6_addr - * can be found. - * - * @details This function can be used by upper layer protocols for neighbor - * discovery optimization to confirm that there was a reachability - * confirmation (e. g. an ACK in TCP) from the neighbor. - * - * @see <a href="http://tools.ietf.org/html/rfc4861#section-7.3.1"> - * RFC 4861, section 7.3.1 - * </a> - * - * @param[in] ipv6_addr An IPv6 address - * - * @return The neighbor cache entry, if one is found. - * @return NULL, if none is found. - */ -gnrc_ipv6_nc_t *gnrc_ipv6_nc_still_reachable(const ipv6_addr_t *ipv6_addr); - -/** - * @brief Gets link-layer address from neighbor cache entry if neighbor is reachable. - * - * @pre (l2_addr != NULL) && (l2_addr_len != NULL) - * - * @param[out] l2_addr The link layer address of @p entry. Must not be NULL. - * @param[out] l2_addr_len Length of @p l2_addr. Must not be NULL. - * @param[in] entry A neighbor cache entry - * - * @return PID to the interface where the neighbor is. - * @return KERNEL_PID_UNDEF, if @p entry == NULL or the neighbor is not reachable. - */ -kernel_pid_t gnrc_ipv6_nc_get_l2_addr(uint8_t *l2_addr, uint8_t *l2_addr_len, - const gnrc_ipv6_nc_t *entry); - -#ifdef __cplusplus -} -#endif - -#endif /* NET_GNRC_IPV6_NC_H */ -/** - * @} - */ diff --git a/sys/include/net/gnrc/ipv6/netif.h b/sys/include/net/gnrc/ipv6/netif.h deleted file mode 100644 index 11f4271ef84c04be092e84982fbe52b2d05402b8..0000000000000000000000000000000000000000 --- a/sys/include/net/gnrc/ipv6/netif.h +++ /dev/null @@ -1,622 +0,0 @@ -/* - * Copyright (C) 2014 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser General - * Public License v2.1. See the file LICENSE in the top level directory for - * more details. - */ - -/** - * @defgroup net_gnrc_ipv6_netif IPv6 network interfaces - * @ingroup net_gnrc_ipv6 - * @brief IPv6 specific information on @ref net_gnrc_netif. - * @{ - * - * @file - * @brief Definitions for IPv6 specific information of network interfaces. - * - * @author Martine Lenders <mlenders@inf.fu-berlin.de> - */ - -#ifndef NET_GNRC_IPV6_NETIF_H -#define NET_GNRC_IPV6_NETIF_H - -#include <stdbool.h> -#include <stdint.h> -#include <stdlib.h> - -#include "kernel_defines.h" -#include "kernel_types.h" -#include "mutex.h" -#include "net/ipv6.h" -#include "net/ipv6/addr.h" -#include "xtimer.h" - -#ifdef MODULE_NETSTATS_IPV6 -#include "net/netstats.h" -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @cond INTERNAL - */ -#ifdef MODULE_GNRC_RPL -/* RPL needs all-RPL-nodes multicast address */ -# define GNRC_IPV6_NETIF_RPL_ADDR (1) -#else -# define GNRC_IPV6_NETIF_RPL_ADDR (0) -#endif -#ifdef MODULE_GNRC_IPV6_ROUTER -/* routers need all-routers multicast address */ -# define GNRC_IPV6_NETIF_RTR_ADDR (1) -#else -# define GNRC_IPV6_NETIF_RTR_ADDR (0) -#endif -/** - * @endcond - */ -/** - * @brief Number of IPv6 addresses per interface. - */ -#ifndef GNRC_IPV6_NETIF_ADDR_NUMOF -#define GNRC_IPV6_NETIF_ADDR_NUMOF (6 + GNRC_IPV6_NETIF_RPL_ADDR + GNRC_IPV6_NETIF_RTR_ADDR) -#endif - -/** - * @brief Default MTU - * - * An interface will choose this MTU if the link-layer's maximum packet size - * (see @ref NETOPT_MAX_PACKET_SIZE) is lesser than the @ref IPV6_MIN_MTU or if it just not - * provide it. For RFC-compatible communication it must be at least @ref IPV6_MIN_MTU. - * - * @note If the scenario the node is used in allows for it and the packet size is predictable, - * a user might choose to set @ref GNRC_IPV6_NETIF_DEFAULT_MTU to a lesser value than - * @ref IPV6_MIN_MTU to optimize for code size (e.g. because it is then possible to omit - * @ref net_gnrc_sixlowpan_frag) and memory usage (e.g. because @ref GNRC_PKTBUF_SIZE - * can be much smaller). - */ -#ifndef GNRC_IPV6_NETIF_DEFAULT_MTU -#define GNRC_IPV6_NETIF_DEFAULT_MTU (IPV6_MIN_MTU) -#endif - -/** - * @brief Default hop limit - * - * @see <a href="https://tools.ietf.org/html/rfc4861#section-6.3.2"> - * RFC 4861, section 6.3.2 - * </a> - * @see <a href="http://www.iana.org/assignments/ip-parameters/ip-parameters.xhtml#ip-parameters-2"> - * IANA, IP TIME TO LIVE PARAMETER - * </a> - */ -#define GNRC_IPV6_NETIF_DEFAULT_HL (64) - -/** - * @name Default values for router configuration - * @{ - * @see <a href="https://tools.ietf.org/html/rfc4861#section-6.2.1"> - * RFC 4861, section 6.2.1 - * </a> - */ -/** - * @brief Maximum time in seconds between sending unsolicited multicast router advertisements. - */ -#define GNRC_IPV6_NETIF_DEFAULT_MAX_ADV_INT (600U) - -/** - * @brief Minimum time in seconds between sending unsolicited multicast router advertisements. - */ -#define GNRC_IPV6_NETIF_DEFAULT_MIN_ADV_INT (200U) - -/** - * @brief The router lifetime to propagate in router advertisements. - */ -#define GNRC_IPV6_NETIF_DEFAULT_ROUTER_LTIME (1800U) -/** @} */ - -/** - * @{ - * @name Flags for a registered IPv6 address. - * @brief Needed primarily to identify addresses as either anycast or unicast. - * - * @see <a href="https://tools.ietf.org/html/rfc4291#section-2.6"> - * RFC 4291, section 2.6 - * </a> - */ -#define GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST (0x00) /**< unicast address */ -#define GNRC_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST (0x01) /**< non-unicast address */ - -/** - * @brief A prefix information option that propagates the prefix of this - * address should set the autonomous flag. - * @see <a href="https://tools.ietf.org/html/rfc4861#section-6.2.1"> - * RFC 4861, section 6.2.1 - * </a> - */ -#define GNRC_IPV6_NETIF_ADDR_FLAGS_NDP_AUTO (0x40) - -/** - * @brief A prefix information option that propagates the prefix of this - * address should set the on-link flag. - * @see <a href="https://tools.ietf.org/html/rfc4861#section-6.2.1"> - * RFC 4861, section 6.2.1 - * </a> - */ -#define GNRC_IPV6_NETIF_ADDR_FLAGS_NDP_ON_LINK (0x80) -/** - * @} - */ - -/** - * @{ - * @name Flags for the interfaces - * - * @note The most-significant byte of these flags is identical to the flags in - * IPv6 router advertisements. See <a - * href="https://tools.ietf.org/html/rfc4861#section-4.2">RFC4861, - * section 4.2</a>, <a - * href="https://tools.ietf.org/html/rfc6275#section-7.1">RFC6275, - * section 7.1</a>, <a - * href="https://tools.ietf.org/html/rfc4191#section-2.2">RFC4191, - * section 2.2</a>, and <a - * href="https://tools.ietf.org/html/rfc4389#section-4.1.3.3">RFC4389, - * section 4.1.3.3</a>. - */ -/** - * @brief Interface is 6LoWPAN interface. - */ -#define GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN (0x0001) - -/** - * @brief Flag to indicate that routing is enabled on the interface. - */ -#define GNRC_IPV6_NETIF_FLAGS_ROUTER (0x0002) - -/** - * @brief Flag to indicate that the interface sends periodic router - * advertisements and in response to router solicitations. - */ -#define GNRC_IPV6_NETIF_FLAGS_RTR_ADV (0x0004) - -/** - * @brief Flag to indicate that gnrc_ipv6_netif_t::mtu shall be propagated - * with the MTU options in router advertisements. - */ -#define GNRC_IPV6_NETIF_FLAGS_ADV_MTU (0x0008) - -/** - * @brief Flag to indicate that gnrc_ipv6_netif_t::cur_hl shall be propagated - * in router advertisements. - */ -#define GNRC_IPV6_NETIF_FLAGS_ADV_CUR_HL (0x0010) - -/** - * @brief Flag to indicate that gnrc_ipv6_netif_t::reach_time shall be propagated - * in router advertisements. - */ -#define GNRC_IPV6_NETIF_FLAGS_ADV_REACH_TIME (0x0020) - -/** - * @brief Flag to indicate that gnrc_ipv6_netif_t::retrans_timer shall be propagated - * in router advertisements. - */ -#define GNRC_IPV6_NETIF_FLAGS_ADV_RETRANS_TIMER (0x0040) - -/** - * @brief Flag to indicate if the interface is operating over a wired link - */ -#define GNRC_IPV6_NETIF_FLAGS_IS_WIRED (0x0080) - -/** - * @brief Offset of the router advertisement flags compared to the position in router - * advertisements. - */ -#define GNRC_IPV6_NETIF_FLAGS_RTR_ADV_POS (8U) - -/** - * @brief Mask for flags intended for router advertisements. - * @note Please expand if more router advertisement flags are introduced. - */ -#define GNRC_IPV6_NETIF_FLAGS_RTR_ADV_MASK (0xc000) - -/** - * @brief Flag to indicate that the interface has other address - * configuration. - */ -#define GNRC_IPV6_NETIF_FLAGS_OTHER_CONF (0x4000) - -/** - * @brief Flag to indicate that the interface has managed address - * configuration (e.g. via DHCPv6). - */ -#define GNRC_IPV6_NETIF_FLAGS_MANAGED (0x8000) -/** - * @} - */ - -/** - * @brief Type to represent an IPv6 address registered to an interface. - */ -typedef struct { - ipv6_addr_t addr; /**< The address data */ - uint8_t flags; /**< flags */ - uint8_t prefix_len; /**< length of the prefix of the address */ - /** - * @{ - * @name Neigbour discovery variables for prefixes - * @see <a href="https://tools.ietf.org/html/rfc4861#section-6.2.1"> - * RFC 4861, section 6.2.1 - * </a> - */ - /** - * @brief The time in seconds this address is valid. If it is UINT32_MAX - * the lifetime is infinite. - */ - uint32_t valid; - - /** - * @brief The length of time that this address remains preferred. - * If it is UINT32_MAX the lifetime is infinite. - * It **must** be < gnrc_ipv6_netif_addr_t::valid. - */ - uint32_t preferred; - /** - * @brief Validity timeout timer. - */ - xtimer_t valid_timeout; - msg_t valid_timeout_msg; /**< msg_t for gnrc_ipv6_netif_addr_t::valid_timeout */ - /** - * @} - */ -} gnrc_ipv6_netif_addr_t; - -/** - * @brief Definition of IPv6 interface type. - */ -typedef struct { - /** - * @brief addresses registered to the interface - */ - gnrc_ipv6_netif_addr_t addrs[GNRC_IPV6_NETIF_ADDR_NUMOF]; - mutex_t mutex; /**< mutex for the interface */ - kernel_pid_t pid; /**< PID of the interface */ - uint16_t flags; /**< flags for 6LoWPAN and Neighbor Discovery */ - uint16_t mtu; /**< Maximum Transmission Unit (MTU) of the interface */ - uint8_t cur_hl; /**< current hop limit for the interface */ -#if defined(MODULE_GNRC_NDP_HOST) || defined(MODULE_GNRC_SIXLOWPAN_ND) - /** - * @brief Counter for send router solicitations. - */ - uint8_t rtr_sol_count; -#endif -#ifdef MODULE_GNRC_NDP_ROUTER - /** - * @brief Counter for initial router advertisements. - */ - uint8_t rtr_adv_count; - - /** - * @brief Maximum time in seconds between sending unsolicited multicast - * router advertisements. Must be between 4 and 1800 seconds. - * The default value is @ref GNRC_IPV6_NETIF_DEFAULT_MAX_ADV_INT. - */ - uint16_t max_adv_int; - - /** - * @brief Minimum time in seconds between sending unsolicited multicast - * router advertisements. Must be between 3 and - * 3/4 * gnrc_ipv6_netif_t::max_adv_int seconds. - * The default value is @ref GNRC_IPV6_NETIF_DEFAULT_MIN_ADV_INT. - */ - uint16_t min_adv_int; - -#endif -#if defined (MODULE_GNRC_NDP_ROUTER) || defined (MODULE_GNRC_SIXLOWPAN_ND_ROUTER) - /** - * @brief The router lifetime to propagate in router advertisements. - * Must be either 0 or between gnrc_ipv6_netif_t::max_adv_int and - * 9000 seconds. 0 means this router is not to be used as a default - * router. The default value is @ref GNRC_IPV6_NETIF_DEFAULT_ROUTER_LTIME. - */ - uint16_t adv_ltime; -#endif - /** - * @brief Base value in microseconds for computing random - * gnrc_ipv6_netif_t::reach_time. - * The default value is @ref GNRC_NDP_REACH_TIME. - */ - uint32_t reach_time_base; - - /** - * @brief The time a neighbor is considered reachable after receiving - * a reachability confirmation. - * Should be uniformly distributed between @ref GNRC_NDP_MIN_RAND - * and GNRC_NDP_MAX_RAND multiplied with - * gnrc_ipv6_netif_t::reach_time_base microseconds devided by 10. - * Can't be greater than 1 hour. - */ - uint32_t reach_time; - - /** - * @brief Time between retransmissions of neighbor solicitations to a - * neighbor. - * The default value is @ref GNRC_NDP_RETRANS_TIMER. - */ - uint32_t retrans_timer; - xtimer_t rtr_sol_timer; /**< Timer for periodic router solicitations */ - msg_t rtr_sol_msg; /**< msg_t for gnrc_ipv6_netif_t::rtr_sol_timer */ -#if defined (MODULE_GNRC_NDP_ROUTER) || defined (MODULE_GNRC_SIXLOWPAN_ND_ROUTER) - xtimer_t rtr_adv_timer; /**< Timer for periodic router advertisements */ - msg_t rtr_adv_msg; /**< msg_t for gnrc_ipv6_netif_t::rtr_adv_timer */ -#endif -#ifdef MODULE_NETSTATS_IPV6 - netstats_t stats; /**< transceiver's statistics */ -#endif -} gnrc_ipv6_netif_t; - -/** - * @brief Initializes the module. - */ -void gnrc_ipv6_netif_init(void); - -/** - * @brief Add interface to IPv6. - * - * @details This function will be called by @ref gnrc_netif_add(). - * - * @param[in] pid The PID to the interface. - */ -void gnrc_ipv6_netif_add(kernel_pid_t pid); - -/** - * @brief Remove interface from IPv6. - * - * @details This function will be called by @ref gnrc_netif_remove(). - * - * @param[in] pid The PID to the interface. - */ -void gnrc_ipv6_netif_remove(kernel_pid_t pid); - -/** - * @brief Get interface. - * - * @param[in] pid The PID to the interface. - * - * @return The interface describing structure, on success. - * @return NULL, if there is no interface with PID @p pid. - */ -gnrc_ipv6_netif_t *gnrc_ipv6_netif_get(kernel_pid_t pid); - -#if (defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER)) -/** - * @brief Set interface to router mode. - * - * @details This sets/unsets the GNRC_IPV6_NETIF_FLAGS_ROUTER and initializes - * or ceases router behavior for neighbor discovery. - * - * @param[in] netif The interface. - * @param[in] enable Status for the GNRC_IPV6_NETIF_FLAGS_ROUTER flag. - */ -void gnrc_ipv6_netif_set_router(gnrc_ipv6_netif_t *netif, bool enable); - -/** - * @brief Set interface to router advertisement mode. - * - * @details If GNRC_IPV6_NETIF_FLAGS_ROUTER is set this sets/unsets the - * GNRC_IPV6_NETIF_FLAGS_RTR_ADV and initializes or ceases router - * advertising behavior for neighbor discovery. - * - * @param[in] netif The interface. - * @param[in] enable Status for the GNRC_IPV6_NETIF_FLAGS_RTR flag. - */ -void gnrc_ipv6_netif_set_rtr_adv(gnrc_ipv6_netif_t *netif, bool enable); -#else -/* dummy macros to be able to "call" these functions when none of the relevant modules - * is implemented */ -#define gnrc_ipv6_netif_set_router(netif, enable) -#define gnrc_ipv6_netif_set_rtr_adv(netif, enable) -#endif - -/** - * @brief Adds an address to an interface. - * - * @param[in] pid The PID to the interface. - * @param[in] addr An address you want to add to the interface. - * @param[in] prefix_len Length of the prefix of the address. - * Must be between 1 and 128. - * @param[in] flags Flags for the address entry - * If @p addr should be an anycast address, @p flags - * must have @ref GNRC_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST - * set. Otherwise leave it unset. - * If @p addr is a multicast address, the status of - * @ref GNRC_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST will be - * ignored and set in either case. - * - * @see <a href="https://tools.ietf.org/html/rfc4291#section-2.6"> - * RFC 4291, section 2.6 - * </a> - * - * @return The address on the interface, on success. - * @return NULL, on failure - */ -ipv6_addr_t *gnrc_ipv6_netif_add_addr(kernel_pid_t pid, const ipv6_addr_t *addr, uint8_t prefix_len, - uint8_t flags); - -/** - * @brief Remove an address from the interface. - * - * @param[in] pid The PID to the interface. If @p pid is KERNEL_PID_UNDEF - * it will be removed from all interfaces. - * @param[in] addr An address you want to remove from interface. - */ -void gnrc_ipv6_netif_remove_addr(kernel_pid_t pid, ipv6_addr_t *addr); - -/** - * @brief Removes all addresses from the interface. - * - * @param[in] pid The PID to the interface. - */ -void gnrc_ipv6_netif_reset_addr(kernel_pid_t pid); - -/** - * @brief Searches for an address on all interfaces. - * - * @param[out] out The reference to the address on the interface. - * @param[in] addr The address you want to search for. - * - * @return The PID to the interface the address is registered to. - * @return KERNEL_PID_UNDEF, if the address can not be found on any interface. - */ -kernel_pid_t gnrc_ipv6_netif_find_by_addr(ipv6_addr_t **out, const ipv6_addr_t *addr); - -/** - * @brief Searches for an address on an interface. - * - * @param[in] pid The PID to the interface. - * @param[in] addr The address you want to search for. - * - * @return The reference to the address on the interface. - * @return NULL, if the address can not be found on the interface. - * @return NULL, if @p pid is no interface. - */ -ipv6_addr_t *gnrc_ipv6_netif_find_addr(kernel_pid_t pid, const ipv6_addr_t *addr); - -/** - * @brief Searches for the first address matching a prefix best on all - * interfaces. - * - * @param[out] out The reference to the found address on the interface. - * Must be a pointer to NULL on calling and may stay - * unchanged if no match can be found. - * - * @param[in] prefix The prefix you want to search for. - * - * @pre @p out must not be NULL. - * - * @return The PID to the interface the address is registered to. - * @return KERNEL_PID_UNDEF, if no matching address can not be found on any - * interface. - */ -kernel_pid_t gnrc_ipv6_netif_find_by_prefix(ipv6_addr_t **out, const ipv6_addr_t *prefix); - -/** - * @brief Searches for the first address matching a prefix best on an - * interface. - * - * @param[in] pid The PID to the interface. - * @param[in] prefix The prefix you want to search for. - * - * @return The reference to the found address on the interface. - * @return NULL, if no matching address can be found on the interface. - * @return NULL, if @p pid is no interface. - */ -ipv6_addr_t *gnrc_ipv6_netif_match_prefix(kernel_pid_t pid, const ipv6_addr_t *prefix); - -/** - * @brief Searches for the best address on an interface usable as a - * source address for a given destination address. - * - * @param[in] pid The PID to the interface. - * @param[in] dest The destination address you want to find a destination - * address for. - * @param[in] ll_only If only link local addresses qualify - * - * @todo Rule 4 from RFC 6724 is currently not implemented. Has to updated as - * soon as gnrc supports Mobile IP. - * - * @todo Rule 6 from RFC 6724 is currently not implemented. Has to updated as - * soon as gnrc supports flow labels. - * - * @todo Rule 7 from RFC 6724 is currently not implemented. Has to updated as - * soon as gnrc supports temporary addresses. - * - * @return The reference to the found address on the interface. - * @return NULL, if no matching address can be found on the interface. - * @return NULL, if @p pid is no interface. - */ -ipv6_addr_t *gnrc_ipv6_netif_find_best_src_addr(kernel_pid_t pid, const ipv6_addr_t *dest, bool ll_only); - -/** - * @brief Get interface specific meta-information on an address - * - * @details This only works with addresses you retrieved via the following - * functions: - * - * * gnrc_ipv6_netif_add_addr() - * * gnrc_ipv6_find_addr() - * * gnrc_ipv6_find_addr_local() - * * gnrc_ipv6_find_prefix_match() - * * gnrc_ipv6_find_prefix_match_local() - * * gnrc_ipv6_find_best_src_address() - * - * The behaviour for other addresses is undefined. - * - * @param[in] addr The address you want to get the meta-information for. - * - * @return Interface specific meta-information on @p addr - */ -static inline gnrc_ipv6_netif_addr_t *gnrc_ipv6_netif_addr_get(const ipv6_addr_t *addr) -{ - return container_of(addr, gnrc_ipv6_netif_addr_t, addr); -} - -/** - * @brief Checks if an address is non-unicast. - * - * @details This only works with addresses you retrieved via the following - * functions: - * - * * gnrc_ipv6_netif_add_addr() - * * gnrc_ipv6_find_addr() - * * gnrc_ipv6_find_addr_local() - * * gnrc_ipv6_find_prefix_match() - * * gnrc_ipv6_find_prefix_match_local() - * * gnrc_ipv6_find_best_src_address() - * - * The behaviour for other addresses is undefined. - * - * @param[in] addr The address you want to check. - * - * @return true, if address is anycast or multicast. - * @return false, if address is unicast. - */ -static inline bool gnrc_ipv6_netif_addr_is_non_unicast(const ipv6_addr_t *addr) -{ - return (bool)(container_of(addr, gnrc_ipv6_netif_addr_t, addr)->flags & - GNRC_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST); - -} - -/** - * @brief Initializes an interface with device-dependent values. - * - * @note Must be called after all interfaces were initialized and must not - * be called in an interface's thread (will otherwise hang up). - */ -void gnrc_ipv6_netif_init_by_dev(void); - -/** - * @brief Get sent and received statistics about IPv6 traffic on this interface. - * - * @note This function is only available if compiled with module `netstats_ipv6`. - * - * @param[in] pid The PID to the interface. - * - * @return A @ref netstats_t pointer to the statistics. - * @return NULL if no statistics are available. - */ -#if defined(MODULE_NETSTATS_IPV6) || DOXYGEN -netstats_t *gnrc_ipv6_netif_get_stats(kernel_pid_t pid); -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* NET_GNRC_IPV6_NETIF_H */ -/** - * @} - */ diff --git a/sys/include/net/gnrc/ndp.h b/sys/include/net/gnrc/ndp.h deleted file mode 100644 index df745947ff6573d63f35b8ba1e402e3df6b9dfab..0000000000000000000000000000000000000000 --- a/sys/include/net/gnrc/ndp.h +++ /dev/null @@ -1,563 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser General - * Public License v2.1. See the file LICENSE in the top level directory for - * more details. - */ - -/** - * @defgroup net_gnrc_ndp IPv6 Neighbor discovery - * @ingroup net_gnrc_icmpv6 - * @brief GNRC's IPv6 Neighbor Discovery implementation - * @{ - * - * @file - * @brief Definitions for GNRC's IPv6 Neighbor Discovery - * - * @author Martine Lenders <mlenders@inf.fu-berlin.de> - */ - -#ifndef NET_GNRC_NDP_H -#define NET_GNRC_NDP_H - -#include <inttypes.h> -#include <stdlib.h> - -#include "byteorder.h" -#include "net/ndp.h" -#include "net/gnrc/pkt.h" -#include "net/gnrc/icmpv6.h" -#include "net/ipv6/addr.h" -#include "net/gnrc/ipv6/nc.h" -#include "net/gnrc/ipv6/netif.h" - -#include "net/gnrc/ndp/host.h" -#include "net/gnrc/ndp/internal.h" -#include "net/gnrc/ndp/router.h" -#include "net/gnrc/ndp/node.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** Message type for router timeouts */ -#define GNRC_NDP_MSG_RTR_TIMEOUT (0x0210) -/** Message type for address timeouts */ -#define GNRC_NDP_MSG_ADDR_TIMEOUT (0x0211) -/** Message type for multicast neighbor solicitation retransmissions */ -#define GNRC_NDP_MSG_NBR_SOL_RETRANS (0x0212) -/** Message type for periodic router advertisements */ -#define GNRC_NDP_MSG_RTR_ADV_RETRANS (0x0213) -/** Message type for delayed router advertisements */ -#define GNRC_NDP_MSG_RTR_ADV_DELAY (0x0214) -/** Message type for delayed router advertisements in a 6LoWPAN - * 6LoWPAN needs a special handling, because router advertisements are only - * sent after a short randomized delay, but not periodically. */ -#define GNRC_NDP_MSG_RTR_ADV_SIXLOWPAN_DELAY (0x0215) -/** Message type for periodic router solicitations */ -#define GNRC_NDP_MSG_RTR_SOL_RETRANS (0x0216) -/** Message type for neighbor cache state timeouts */ -#define GNRC_NDP_MSG_NC_STATE_TIMEOUT (0x0217) - -/** - * @name Host constants - * @{ - * @see <a href="https://tools.ietf.org/html/rfc4861#section-10"> - * RFC 4861, section 10 - * </a> - */ -/** - * @brief Upper bound for randomised delay in seconds for initial - * router solicitation transmissions - */ -#define GNRC_NDP_MAX_RTR_SOL_DELAY (1U) - -/** - * @brief Interval in seconds between initial router solicitation - * transmissions - */ -#define GNRC_NDP_MAX_RTR_SOL_INT (4U) - -/** - * @brief Maximum number of initial router solicitation transmissions - */ -#define GNRC_NDP_MAX_RTR_SOL_NUMOF (3U) -/** @} */ - -/** - * @name Node constants - * @{ - * @see <a href="https://tools.ietf.org/html/rfc4861#section-10"> - * RFC 4861, section 10 - * </a> - */ -/** - * @brief Maximum number of unanswered multicast neighbor solicitations - * before address resolution is considered failed. - */ -#define GNRC_NDP_MAX_MC_NBR_SOL_NUMOF (3U) - -/** - * @brief Maximum number of unanswered unicast neighbor solicitations before - * an address is considered unreachable. - */ -#define GNRC_NDP_MAX_UC_NBR_SOL_NUMOF (3U) - -/** - * @brief Upper bound of randomized delay in seconds for a solicited - * neighbor advertisement transmission for an anycast target. - */ -#define GNRC_NDP_MAX_AC_TGT_DELAY (1U) - -/** - * @brief Maximum number of unsolicited neighbor advertisements before on - * link-layer address change. - */ -#define GNRC_NDP_MAX_NBR_ADV_NUMOF (3U) - -/** - * @brief Base value in mircoseconds for computing randomised - * reachable time. - */ -#define GNRC_NDP_REACH_TIME (30U * US_PER_SEC) - -/** - * @brief Time in mircoseconds between retransmissions of neighbor - * solicitations to a neighbor. - */ -#define GNRC_NDP_RETRANS_TIMER (1U * US_PER_SEC) - -/** - * @brief Delay in seconds for neighbor cache entry between entering - * DELAY state and entering PROBE state if no reachability - * confirmation has been received. - */ -#define GNRC_NDP_FIRST_PROBE_DELAY (5U) - -/** - * @brief Lower bound for randomised reachable time calculation. - */ -#define GNRC_NDP_MIN_RAND (5U) - -/** - * @brief Upper bound for randomised reachable time calculation. - */ -#define GNRC_NDP_MAX_RAND (15U) -/** @} */ - -/** - * @name Router constants - * @{ - * @see <a href="https://tools.ietf.org/html/rfc4861#section-10"> - * RFC 4861, section 10 - * </a> - */ -/** - * @brief Initial router advertisement interval in seconds - */ -#define GNRC_NDP_MAX_INIT_RTR_ADV_INT (16U) - -/** - * @brief Maximum number of initial router advertisement transmissions - */ -#define GNRC_NDP_MAX_INIT_RTR_ADV_NUMOF (3U) - -/** - * @brief Maximum number of final router advertisement transmissions - */ -#define GNRC_NDP_MAX_FIN_RTR_ADV_NUMOF (3U) - -/** - * @brief Minimum delay in seconds between router advertisement - * transmissions - */ -#define GNRC_NDP_MIN_RTR_ADV_DELAY (3U) - -/** - * @brief Upper bound for randomised delay in microseconds between router - * solicitation reception and responding router advertisement - * transmission. - */ -#define GNRC_NDP_MAX_RTR_ADV_DELAY (500U * US_PER_MS) -/** @} */ - -/** - * @brief Handles received neighbor solicitations. - * - * @param[in] iface The receiving interface. - * @param[in] pkt The received packet. - * @param[in] ipv6 The IPv6 header in @p pkt. - * @param[in] nbr_sol The neighbor solicitation in @p pkt. - * @param[in] icmpv6_size The overall size of the neighbor solicitation. - */ -void gnrc_ndp_nbr_sol_handle(kernel_pid_t iface, gnrc_pktsnip_t *pkt, - ipv6_hdr_t *ipv6, ndp_nbr_sol_t *nbr_sol, - size_t icmpv6_size); - -/** - * @brief Handles received neighbor advertisements. - * - * @param[in] iface The receiving interface. - * @param[in] pkt The received packet. - * @param[in] ipv6 The IPv6 header in @p pkt. - * @param[in] nbr_adv The neighbor advertisement in @p pkt. - * @param[in] icmpv6_size The overall size of the neighbor advertisement. - */ -void gnrc_ndp_nbr_adv_handle(kernel_pid_t iface, gnrc_pktsnip_t *pkt, - ipv6_hdr_t *ipv6, ndp_nbr_adv_t *nbr_adv, - size_t icmpv6_size); - -#if (defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER)) -/** - * @brief Handles received router solicitations. - * - * @param[in] iface The receiving interface. - * @param[in] pkt The received packet. - * @param[in] ipv6 The IPv6 header in @p pkt. - * @param[in] rtr_sol The router solicitation in @p pkt. - * @param[in] icmpv6_size The overall size of the router solicitation. - */ -void gnrc_ndp_rtr_sol_handle(kernel_pid_t iface, gnrc_pktsnip_t *pkt, - ipv6_hdr_t *ipv6, ndp_rtr_sol_t *rtr_sol, - size_t icmpv6_size); -#else -/** - * @brief A host *must* silently discard all received router solicitations. - * @see <a href="https://tools.ietf.org/html/rfc4861#section-6.2.6"> - * RFC 4861, section 6.2.6 - * </a> - * - * This macro is primarily an optimization to not go into the function defined - * above. - */ -#define gnrc_ndp_rtr_sol_handle(iface, pkt, ipv6, rtr_sol, size) -#endif - -/** - * @brief Handles received router advertisements - * - * @todo As router check consistency as described in RFC 4861, section 6.2.3 - * - * @param[in] iface The receiving interface. - * @param[in] pkt The received packet. - * @param[in] ipv6 The IPv6 header in @p pkt. - * @param[in] rtr_adv The router advertisement in @p pkt. - * @param[in] icmpv6_size The overall size of the router advertisement. - */ -void gnrc_ndp_rtr_adv_handle(kernel_pid_t iface, gnrc_pktsnip_t *pkt, - ipv6_hdr_t *ipv6, ndp_rtr_adv_t *rtr_adv, - size_t icmpv6_size); - -/** - * @brief Retransmits a multicast neighbor solicitation for an incomplete or - * probing neighbor cache entry @p nc_entry, - * if nc_entry::probes_remaining > 0. - * - * @details If nc_entry::probes_remaining > 0 it will be decremented. If it - * reaches 0 it the entry @p nc_entry will be removed from the - * neighbor cache. - * - * @param[in] nc_entry A neighbor cache entry. Will be ignored if its state - * is not @ref GNRC_IPV6_NC_STATE_INCOMPLETE or - * @ref GNRC_IPV6_NC_STATE_PROBE. - */ -void gnrc_ndp_retrans_nbr_sol(gnrc_ipv6_nc_t *nc_entry); - -/** - * @brief Event handler for a neighbor cache state timeout. - * - * @param[in] nc_entry A neighbor cache entry. - */ -void gnrc_ndp_state_timeout(gnrc_ipv6_nc_t *nc_entry); - -/** - * @brief NDP interface initialization. - * - * @param[in] iface An IPv6 interface descriptor. Must not be NULL. - */ -void gnrc_ndp_netif_add(gnrc_ipv6_netif_t *iface); - -/** - * @brief NDP interface removal. - * - * @param[in] iface An IPv6 interface descriptor. Must not be NULL. - */ -void gnrc_ndp_netif_remove(gnrc_ipv6_netif_t *iface); - -/** - * @brief Get link-layer address and interface for next hop to destination - * IPv6 address. - * - * @param[out] l2addr The link-layer for the next hop to @p dst. - * @param[out] l2addr_len Length of @p l2addr. - * @param[in] iface The interface to search the next hop on. - * May be @ref KERNEL_PID_UNDEF if not specified. - * @param[in] dst An IPv6 address to search the next hop for. - * @param[in] pkt Packet to send to @p dst. Leave NULL if you - * just want to get the addresses. - * - * @return The PID of the interface, on success. - * @return -EHOSTUNREACH, if @p dst is not reachable. - * @return -ENOBUFS, if @p l2addr_len was smaller than the resulting @p l2addr - * would be long. - */ -kernel_pid_t gnrc_ndp_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_len, - kernel_pid_t iface, ipv6_addr_t *dst, - gnrc_pktsnip_t *pkt); - -/** - * @brief Builds a neighbor solicitation message for sending. - * - * @see <a href="https://tools.ietf.org/html/rfc4861#section-4.3"> - * RFC 4861, section 4.3 - * </a> - * - * @param[in] tgt The target address. - * @param[in] options Options to append to the router solicitation. - * - * @return The resulting ICMPv6 packet on success. - * @return NULL, on failure. - */ -gnrc_pktsnip_t *gnrc_ndp_nbr_sol_build(ipv6_addr_t *tgt, gnrc_pktsnip_t *options); - -/** - * @brief Builds a neighbor advertisement message for sending. - * - * @see <a href="https://tools.ietf.org/html/rfc4861#section-4.4"> - * RFC 4861, section 4.4 - * </a> - * - * @param[in] flags Neighbor advertisement flags: - * @ref NDP_NBR_ADV_FLAGS_R == 1 indicates, that the - * sender is a router, - * @ref NDP_NBR_ADV_FLAGS_S == 1 indicates that the - * advertisement was sent in response to a neighbor - * solicitation, - * @ref NDP_NBR_ADV_FLAGS_O == 1 indicates that the - * advertisement should override an existing cache entry - * and update the cached link-layer address. - * @param[in] tgt For solicited advertisements, the Target Address field - * in the neighbor solicitaton. - * For and unsolicited advertisement, the address whose - * link-layer address has changed. - * MUST NOT be multicast. - * @param[in] options Options to append to the neighbor advertisement. - * - * @return The resulting ICMPv6 packet on success. - * @return NULL, on failure. - */ -gnrc_pktsnip_t *gnrc_ndp_nbr_adv_build(uint8_t flags, ipv6_addr_t *tgt, - gnrc_pktsnip_t *options); - -/** - * @brief Builds a router solicitation message for sending. - * - * @see <a href="https://tools.ietf.org/html/rfc4861#section-4.1"> - * RFC 4861, section 4.1 - * </a> - * - * @param[in] options Options to append to the router solicitation. - * - * @return The resulting ICMPv6 packet on success. - * @return NULL, on failure. - */ -gnrc_pktsnip_t *gnrc_ndp_rtr_sol_build(gnrc_pktsnip_t *options); - -/** - * @brief Builds a router solicitation message for sending. - * - * @see <a href="https://tools.ietf.org/html/rfc4861#section-4.1"> - * RFC 4861, section 4.1 - * </a> - * - * @param[in] options Options to append to the router solicitation. - * - * @return The resulting ICMPv6 packet on success. - * @return NULL, on failure. - */ -gnrc_pktsnip_t *gnrc_ndp_rtr_sol_build(gnrc_pktsnip_t *options); - -#if (defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER)) -/** - * @brief Builds a router advertisement message for sending. - * - * @see <a href="https://tools.ietf.org/html/rfc4861#section-4.2"> - * RFC 4861, section 4.2 - * </a> - * - * @note The source address for the packet MUST be the link-local address - * of the interface. - * - * @param[in] cur_hl Default hop limit for outgoing IP packets, 0 if - * unspecified by this router. - * @param[in] flags Flags as defined above. - * @ref NDP_RTR_ADV_FLAGS_M == 1 indicates, that the - * addresses are managed by DHCPv6, - * @ref NDP_RTR_ADV_FLAGS_O == 1 indicates that other - * configuration information is available via DHCPv6. - * @param[in] ltime Lifetime of the default router in seconds. - * @param[in] reach_time Time in milliseconds a node should assume a neighbor - * reachable. 0 means unspecified by the router. - * @param[in] retrans_timer Time in milliseconds between retransmitted - * neighbor solicitations. 0 means unspecified by - * the router. - * @param[in] options Options to append to the router advertisement. - * - * @return The resulting ICMPv6 packet on success. - * @return NULL, on failure. - */ -gnrc_pktsnip_t *gnrc_ndp_rtr_adv_build(uint8_t cur_hl, uint8_t flags, uint16_t ltime, - uint32_t reach_time, uint32_t retrans_timer, - gnrc_pktsnip_t *options); -#else -/** - * @brief A host *must not* send router advertisements at any time (so why build them?) - * @see <a href="https://tools.ietf.org/html/rfc4861#section-6.3.4"> - * RFC 4861, section 6.3.4 - * </a> - * - * This macro is primarily an optimization to not go into the function defined - * above. - */ -#define gnrc_ndp_rtr_adv_build(cur_hl, flags, ltime, reach_time, retrans_timer, options) (NULL) -#endif - -/** - * @brief Builds a generic NDP option. - * - * @param[in] type Type of the option. - * @param[in] size Size in byte of the option (will be rounded up to the next - * multiple of 8). - * @param[in] next More options in the packet. NULL, if there are none. - * - * @return The packet snip list of options, on success - * @return NULL, if packet buffer is full - */ -gnrc_pktsnip_t *gnrc_ndp_opt_build(uint8_t type, size_t size, gnrc_pktsnip_t *next); - -/** - * @brief Builds the source link-layer address option. - * - * @see <a href="https://tools.ietf.org/html/rfc4861#section-4.6.1"> - * RFC 4861, section 4.6.1 - * </a> - * - * @note Must only be used with neighbor solicitations, router solicitations, - * and router advertisements. This is not checked however, since - * hosts should silently ignore it in other NDP messages. - * - * @param[in] l2addr A link-layer address of variable length. - * @param[in] l2addr_len Length of @p l2addr. - * @param[in] next More options in the packet. NULL, if there are none. - * - * @return The packet snip list of options, on success - * @return NULL, if packet buffer is full - */ -gnrc_pktsnip_t *gnrc_ndp_opt_sl2a_build(const uint8_t *l2addr, uint8_t l2addr_len, - gnrc_pktsnip_t *next); - -/** - * @brief Builds the target link-layer address option. - * - * @see <a href="https://tools.ietf.org/html/rfc4861#section-4.6.1"> - * RFC 4861, section 4.6.1 - * </a> - * - * @note Must only be used with neighbor advertisemnents and redirect packets. - * This is not checked however, since hosts should silently ignore it - * in other NDP messages. - * - * @param[in] l2addr A link-layer address of variable length. - * @param[in] l2addr_len Length of @p l2addr. - * @param[in] next More options in the packet. NULL, if there are none. - * - * @return The pkt snip list of options, on success - * @return NULL, if packet buffer is full - */ -gnrc_pktsnip_t *gnrc_ndp_opt_tl2a_build(const uint8_t *l2addr, uint8_t l2addr_len, - gnrc_pktsnip_t *next); - -#if (defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER)) -/** - * @brief Builds the prefix information option. - * - * @see <a href="https://tools.ietf.org/html/rfc4861#section-4.6.2"> - * RFC 4861, section 4.6.2 - * </a> - * - * @note Must only be used with router advertisemnents. This is not checked - * however, since nodes should silently ignore it in other NDP messages. - * - * @param[in] prefix_len The length of @p prefix in bits. Must be between - * 0 and 128. - * @param[in] flags Flags as defined above. - * @ref NDP_OPT_PI_FLAGS_L == 1 indicates, that - * @p prefix can be used for on-link determination, - * @ref NDP_OPT_PI_FLAGS_A == 1 indicates, that - * @p prefix can be used for stateless address - * configuration. - * @param[in] valid_ltime Length of time in seconds that @p prefix is valid. - * UINT32_MAX represents infinity. - * @param[in] pref_ltime Length of time in seconds that addresses using - * @p prefix remain prefered. UINT32_MAX represents - * infinity. - * @param[in] prefix An IPv6 address or a prefix of an IPv6 address. - * @param[in] next More options in the packet. NULL, if there are none. - * - * @return The packet snip list of options, on success - * @return NULL, if packet buffer is full - */ -gnrc_pktsnip_t *gnrc_ndp_opt_pi_build(uint8_t prefix_len, uint8_t flags, - uint32_t valid_ltime, uint32_t pref_ltime, - ipv6_addr_t *prefix, gnrc_pktsnip_t *next); - -/** - * @brief Builds the MTU option. - * - * @see <a href="https://tools.ietf.org/html/rfc4861#section-4.6.4"> - * RFC 4861, section 4.6.4 - * </a> - * - * @note Must only be used with router advertisemnents. This is not checked - * however, since nodes should silently ignore it in other NDP messages. - * - * @param[in] mtu The recommended MTU for the link. - * @param[in] next More options in the packet. NULL, if there are none. - * - * @return The packet snip list of options, on success - * @return NULL, if packet buffer is full - */ -gnrc_pktsnip_t *gnrc_ndp_opt_mtu_build(uint32_t mtu, gnrc_pktsnip_t *next); -#else -/** - * @brief A host *must not* send router advertisements at any time (so why build their options?) - * @see <a href="https://tools.ietf.org/html/rfc4861#section-6.3.4"> - * RFC 4861, section 6.3.4 - * </a> - * - * This macro is primarily an optimization to not go into the function defined - * above. - */ -#define gnrc_ndp_opt_pi_build(prefix_len, flags, valid_ltime, pref_ltime, prefix, next) (NULL) - -/** - * @brief A host *must not* send router advertisements at any time (so why build their options?) - * @see <a href="https://tools.ietf.org/html/rfc4861#section-6.3.4"> - * RFC 4861, section 6.3.4 - * </a> - * - * This macro is primarily an optimization to not go into the function defined - * above. - */ -#define gnrc_ndp_opt_mtu_build(mtu, next) (NULL) -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* NET_GNRC_NDP_H */ -/** - * @} - */ diff --git a/sys/include/net/gnrc/ndp/host.h b/sys/include/net/gnrc/ndp/host.h deleted file mode 100644 index deebb6a3022cc2a631590ac2d0ea54571e815275..0000000000000000000000000000000000000000 --- a/sys/include/net/gnrc/ndp/host.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup net_gnrc_ndp_host Host-specific part of router discovery. - * @ingroup net_gnrc_ndp - * @brief Host-specific part for the router discovery in IPv6 - * neighbor discovery. - * @{ - * - * @file - * @brief Host-specific router discovery definitions - * - * @author Martine Lenders <mlenders@inf.fu-berlin.de> - */ -#ifndef NET_GNRC_NDP_HOST_H -#define NET_GNRC_NDP_HOST_H - -#include "net/gnrc/ipv6/netif.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Initializes interface @p iface as host. - * - * @pre iface != NULL - * - * @param[in] iface An IPv6 interface - */ -void gnrc_ndp_host_init(gnrc_ipv6_netif_t *iface); - -/** - * @brief Sends a router solicitation over interface @p iface - * and reset the timer for the next one. - * - * @pre iface != NULL - * - * @param[in] iface An IPv6 interface - */ -void gnrc_ndp_host_retrans_rtr_sol(gnrc_ipv6_netif_t *iface); - -#ifdef __cplusplus -} -#endif - -#endif /* NET_GNRC_NDP_HOST_H */ -/** @} */ diff --git a/sys/include/net/gnrc/ndp/internal.h b/sys/include/net/gnrc/ndp/internal.h deleted file mode 100644 index 13fd68e357487e78177583a64e3c32851d2dd4f9..0000000000000000000000000000000000000000 --- a/sys/include/net/gnrc/ndp/internal.h +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup net_gnrc_ndp_internal Internal functions for neighbor discovery. - * @ingroup net_gnrc_ndp - * @brief Internal functions for neighbor discovery. - * @internal - * @note Only for use with a neighbor discovery implementations. - * @{ - * - * @file - * @brief Internal neighbor discovery functions for neighbor discovery. - * - * @author Martine Lenders <mlenders@inf.fu-berlin.de> - */ -#ifndef NET_GNRC_NDP_INTERNAL_H -#define NET_GNRC_NDP_INTERNAL_H - -#include "kernel_types.h" -#include "net/gnrc/ipv6/nc.h" -#include "net/ipv6/addr.h" -#include "net/ipv6/hdr.h" -#include "net/ndp.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Get best match from default router list. - * - * @internal - * - * @see <a href="https://tools.ietf.org/html/rfc4861#section-6.3.6"> - * RFC 4861, section 6.3.6 - * </a> - * - * @return Address to a default router. - * @return NULL, if the default router list is empty. - */ -ipv6_addr_t *gnrc_ndp_internal_default_router(void); - -/** - * @brief Sets state of a neighbor cache entry and triggers required actions. - * - * @internal - * - * @param[in] nc_entry A neighbor cache entry. - * @param[in] state The new state for the neighbor cache entry. - */ -void gnrc_ndp_internal_set_state(gnrc_ipv6_nc_t *nc_entry, uint8_t state); - -/** - * @brief Send precompiled neighbor solicitation. - * - * @internal - * - * @param[in] iface Interface to send over. May not be KERNEL_PID_UNDEF. - * @param[in] src Source address for the neighbor solicitation. Will be chosen from the - * interface according to @p dst, if NULL. - * @param[in] tgt Target address for the neighbor solicitation. May not be - * NULL. - * @param[in] dst Destination address for neighbor solicitation. May not be - * NULL. - */ -void gnrc_ndp_internal_send_nbr_sol(kernel_pid_t iface, ipv6_addr_t *src, ipv6_addr_t *tgt, - ipv6_addr_t *dst); - -/** - * @brief Send precompiled neighbor advertisement. - * - * @internal - * - * @param[in] iface Interface to send over. May not be KERNEL_PID_UNDEF. - * @param[in] tgt Target address for the neighbor solicitation. May - * not be NULL. - * @param[in] dst Destination address for neighbor solicitation. May - * not be NULL. - * @param[in] supply_tl2a Add target link-layer address option to neighbor - * advertisement if link-layer has addresses. - * @param[in] ext_opts External options for the neighbor advertisement. Leave NULL for none. - * **Warning:** these are not tested if they are suitable for a - * neighbor advertisement so be sure to check that. - * **Will be released** in an error case. - */ -void gnrc_ndp_internal_send_nbr_adv(kernel_pid_t iface, ipv6_addr_t *tgt, ipv6_addr_t *dst, - bool supply_tl2a, gnrc_pktsnip_t *ext_opts); - -/** - * @brief Send precompiled router solicitation to @p dst. - * - * @internal - * - * @param[in] iface Interface to send over. May not be KERNEL_PID_UNDEF. - * @param[in] dst Destination for the router solicitation. ff02::2 if NULL. - */ -void gnrc_ndp_internal_send_rtr_sol(kernel_pid_t iface, ipv6_addr_t *dst); - -#if (defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER)) -/** - * @brief Handles received router solicitations. - * - * @param[in] iface Interface to send over. May not be KERNEL_PID_UNDEF. - * @param[in] src Source address for the router advertisement. May be NULL to be determined - * by source address selection (:: if no @p iface has no address). - * @param[in] dst Destination address for router advertisement. - * @ref IPV6_ADDR_ALL_NODES_LINK_LOCAL if NULL. - * @param[in] fin This is part of the router's final batch of router advertisements - * before ceising to be a router (set's router lifetime field to 0). - */ -void gnrc_ndp_internal_send_rtr_adv(kernel_pid_t iface, ipv6_addr_t *src, - ipv6_addr_t *dst, bool fin); -#else -/** - * @brief A host *must not* send router advertisements at any time. - * - * This macro is primarily an optimization to not go into the function defined - * above. - */ -#define gnrc_ndp_internal_send_rtr_adv(iface, src, dst, fin) -#endif - -/** - * @brief Handles a SL2A option. - * - * @param[in] pkt Packet the option was received in. - * @param[in] ipv6 IPv6 header of @p pkt - * @param[in] icmpv6_type ICMPv6 type of the message carrying the option. - * @param[in] tl2a_opt The TL2A option. - * @param[out] l2addr The L2 address carried in the SL2A option. - * - * @return length of the L2 address, on success. - * @return -EINVAL, if SL2A was not valid. - * @return -ENOTSUP, if node should silently ignore the option. - */ -int gnrc_ndp_internal_sl2a_opt_handle(gnrc_pktsnip_t *pkt, ipv6_hdr_t *ipv6, uint8_t icmpv6_type, - ndp_opt_t *sl2a_opt, uint8_t *l2addr); - -/** - * @brief Handles a TL2A option. - * - * @param[in] pkt Packet the option was received in. - * @param[in] ipv6 IPv6 header of @p pkt - * @param[in] icmpv6_type ICMPv6 type of the message carrying the option. - * @param[in] tl2a_opt The TL2A option. - * @param[out] l2addr The L2 address carried in the TL2A option. - * - * @return length of the L2 address, on success. - * @return -EINVAL, if TL2A was not valid. - * @return -ENOTSUP, if node should silently ignore the option. - */ -int gnrc_ndp_internal_tl2a_opt_handle(gnrc_pktsnip_t *pkt, ipv6_hdr_t *ipv6, - uint8_t icmpv6_type, ndp_opt_t *tl2a_opt, - uint8_t *l2addr); - -/** - * @brief Handles a MTU option. - * - * @internal - * - * @param[in] iface Interface the MTU option was received on. - * @param[in] icmpv6_type ICMPv6 type of the message carrying the option. - * @param[in] mtu_opt A MTU option. - * - * @return true, on success (or if the node should silently ignore the option). - * @return false, if MTU option was not valid. - */ -bool gnrc_ndp_internal_mtu_opt_handle(kernel_pid_t iface, uint8_t icmpv6_type, - ndp_opt_mtu_t *mtu_opt); - -/** - * @brief Handles a PI option. - * - * @internal - * - * @param[in] iface Interface the PI option was received on. - * @param[in] icmpv6_type ICMPv6 type of the message carrying the option. - * @param[in] pi_opt A PI option. - * - * @return true, on success (or if the node should silently ignore the option). - * @return false, if PIO was not valid. - */ -bool gnrc_ndp_internal_pi_opt_handle(kernel_pid_t iface, uint8_t icmpv6_type, - ndp_opt_pi_t *pi_opt); - -/** - * @brief Resets the gnrc_ipv6_nc_t::nbr_sol_timer. - * - * @internal - * - * @param[in] nc_entry A neighbor cache entry. - * @param[in] delay The delay when the timer should fire. - * @param[in] type The msg_t::type for the timer. - * @param[in] pid The pid of the receiver thread of the msg_t - */ -static inline void gnrc_ndp_internal_reset_nbr_sol_timer(gnrc_ipv6_nc_t *nc_entry, uint32_t delay, - uint16_t type, kernel_pid_t pid) -{ - xtimer_remove(&nc_entry->nbr_sol_timer); - nc_entry->nbr_sol_msg.type = type; - xtimer_set_msg(&nc_entry->nbr_sol_timer, delay, &nc_entry->nbr_sol_msg, pid); -} - -#ifdef __cplusplus -} -#endif - -#endif /* NET_GNRC_NDP_INTERNAL_H */ -/** @} */ diff --git a/sys/include/net/gnrc/ndp/node.h b/sys/include/net/gnrc/ndp/node.h deleted file mode 100644 index 61ef12e14f0f99f7a48f5f996ebca423fe3a35e1..0000000000000000000000000000000000000000 --- a/sys/include/net/gnrc/ndp/node.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup net_gnrc_ndp_node Neighbor discovery for pure IPv6 nodes - * @ingroup net_gnrc_ndp - * @brief Used for pure IPv6 nodes (without 6LoWPAN). - * @{ - * - * @file - * @brief IPv6-node neighbor discovery definitions - * - * @author Martine Lenders <mlenders@inf.fu-berlin.de> - */ -#ifndef NET_GNRC_NDP_NODE_H -#define NET_GNRC_NDP_NODE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Get link-layer address and interface for next hop to destination - * IPv6 address. - * - * @param[out] l2addr The link-layer for the next hop to @p dst. - * @param[out] l2addr_len Length of @p l2addr. - * @param[in] iface The interface to search the next hop on. - * May be @ref KERNEL_PID_UNDEF if not specified. - * @param[in] dst An IPv6 address to search the next hop for. - * @param[in] pkt Packet to send to @p dst. Leave NULL if you - * just want to get the addresses. - * - * @return The PID of the interface, on success. - * @return -EHOSTUNREACH, if @p dst is not reachable. - * @return -ENOBUFS, if @p l2addr_len was smaller than the resulting @p l2addr - * would be long. - */ -kernel_pid_t gnrc_ndp_node_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_len, - kernel_pid_t iface, ipv6_addr_t *dst, - gnrc_pktsnip_t *pkt); - -#ifdef __cplusplus -} -#endif - -#endif /* NET_GNRC_NDP_NODE_H */ -/** @} */ diff --git a/sys/include/net/gnrc/ndp/router.h b/sys/include/net/gnrc/ndp/router.h deleted file mode 100644 index 21e78e9709aef6670e9c9dcb074d43c9b6c6572c..0000000000000000000000000000000000000000 --- a/sys/include/net/gnrc/ndp/router.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup net_gnrc_ndp_router Router-specific part of router discovery. - * @ingroup net_gnrc_ndp - * @brief Router-specific part for the router discovery in IPv6 - * neighbor discovery. - * @{ - * - * @file - * @brief Router-specific router discovery definitions - * - * @author Martine Lenders <mlenders@inf.fu-berlin.de> - */ -#ifndef NET_GNRC_NDP_ROUTER_H -#define NET_GNRC_NDP_ROUTER_H - -#include <stdbool.h> - -#include "kernel_types.h" -#include "net/ipv6/hdr.h" -#include "net/ndp.h" -#include "net/gnrc/ipv6/nc.h" -#include "timex.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Set @p iface to router mode. - * - * @details This sets/unsets the GNRC_IPV6_NETIF_FLAGS_ROUTER and - * GNRC_IPV6_NETIF_FLAGS_RTR_ADV and initializes or ceases router - * behavior for neighbor discovery. - * - * @param[in] iface An IPv6 interface. Must not be NULL. - * @param[in] enable Status for the GNRC_IPV6_NETIF_FLAGS_ROUTER and - * GNRC_IPV6_NETIF_FLAGS_RTR_ADV flags. - */ -void gnrc_ndp_router_set_router(gnrc_ipv6_netif_t *iface, bool enable); - -/** - * @brief Set/Unset GNRC_IPV6_NETIF_FLAGS_RTR_ADV flag for @p iface. - * - * @see <a href="https://tools.ietf.org/html/rfc4861#section-6.2.2"> - * RFC 4861, section 6.2.2 - * </a> - * @see <a href="https://tools.ietf.org/html/rfc4861#section-6.2.5"> - * RFC 4861, section 6.2.5 - * </a> - * - * @details GNRC_IPV6_NETIF_FLAGS_RTR_ADV and initializes or ceases - * periodic router advertising behavior for neighbor discovery. - * - * @param[in] iface An IPv6 interface. Must not be NULL. - * @param[in] enable Status for the GNRC_IPV6_NETIF_FLAGS_RTR_ADV flags. - */ -void gnrc_ndp_router_set_rtr_adv(gnrc_ipv6_netif_t *iface, bool enable); - -/** - * @brief Send an unsolicited router advertisement over @p iface - * and reset the timer for the next one if necessary. - * - * @param[in] iface An IPv6 interface. - */ -void gnrc_ndp_router_retrans_rtr_adv(gnrc_ipv6_netif_t *iface); - -/** - * @brief Send an solicited router advertisement to IPv6 address of - * @p neighbor. - * - * @param[in] neighbor A neighbor cache entry. - */ -void gnrc_ndp_router_send_rtr_adv(gnrc_ipv6_nc_t *neighbor); - -#ifdef __cplusplus -} -#endif - -#endif /* NET_GNRC_NDP_ROUTER_H */ -/** @} */ diff --git a/sys/include/net/gnrc/netif.h b/sys/include/net/gnrc/netif.h deleted file mode 100644 index c92f33bbdce915baefe1b3b92c1b36fbf08dd2ab..0000000000000000000000000000000000000000 --- a/sys/include/net/gnrc/netif.h +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup net_gnrc_netif Network interfaces - * @ingroup net_gnrc - * @brief Abstraction layer for GNRC's network interfaces - * - * Network interfaces in the context of GNRC are threads for protocols that are - * below the network layer. - * - * @{ - * - * @file - * @brief Definitions for GNRC's network interfaces - * - * @author Martine Lenders <mlenders@inf.fu-berlin.de> - * @author Oliver Hahm <oliver.hahm@inria.fr> - */ -#ifndef NET_GNRC_NETIF_H -#define NET_GNRC_NETIF_H - -#include <stdlib.h> -#include <stdbool.h> -#include "kernel_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Maximum number of network interfaces - */ -#ifndef GNRC_NETIF_NUMOF -#define GNRC_NETIF_NUMOF (1) -#endif - -/** - * @brief The add/remove operation to set network layer protocol - * specific options for an interface. - * - * @param[in] pid The PID to the new interface. - */ -typedef void (*gnrc_netif_op_t)(kernel_pid_t pid); - -/** - * @brief The add and remove handlers to set network layer protocol - * specific options for an interface. - * - * @details If you implement a pair, please add it to the list in gnrc_netif.c - * statically. - */ -typedef struct { - gnrc_netif_op_t add; /**< The add operation */ - gnrc_netif_op_t remove; /**< The remove operation */ -} gnrc_netif_handler_t; - -/** - * @brief Initializes module. - */ -void gnrc_netif_init(void); - -/** - * @brief Adds a thread as interface. - * - * @param[in] pid PID of the added thread. - * - * @return 0, on success, - * @return -ENOMEM, if maximum number of interfaces has been exceeded. - */ -int gnrc_netif_add(kernel_pid_t pid); - -/** - * @brief Removes a thread as interface. - * - * @param[in] pid PID of the removed thread. - */ -void gnrc_netif_remove(kernel_pid_t pid); - -/** - * @brief Get all active interfaces. - * - * @param[out] netifs List of all active interfaces. There is no order ensured. - * It must at least fit @ref GNRC_NETIF_NUMOF elements. - * - * @return The number of active interfaces. - */ -size_t gnrc_netif_get(kernel_pid_t *netifs); - -/** - * @brief Check if an interface exist. - * - * @param[in] pid The PID to be checked. - * - * @return True, if an interface @p pid exists. - * @return False, otherwise - */ -bool gnrc_netif_exist(kernel_pid_t pid); - -/** - * @brief Converts a hardware address to a human readable string. - * - * @details The format will be like `xx:xx:xx:xx` where `xx` are the bytes - * of @p addr in hexadecimal representation. - * - * @pre @p out_len >= 3 * @p addr_len - * - * @param[out] out A string to store the output in. - * @param[out] out_len Length of @p out. Must be at least - * 3 * @p addr_len long. - * @param[in] addr A hardware address. - * @param[in] addr_len Length of @p addr. - * - * @return Copy of @p out on success. - * @return NULL, if @p out_len < 3 * @p addr_len. - */ -char *gnrc_netif_addr_to_str(char *out, size_t out_len, const uint8_t *addr, - size_t addr_len); - -/** - * @brief Parses a string of colon-separated hexadecimals to a hardware - * address. - * - * @details The input format must be like `xx:xx:xx:xx` where `xx` will be the - * bytes of @p addr in hexadecimal representation. - * - * @param[out] out The resulting hardware address. - * @param[out] out_len Length of @p out. - * @param[in] str A string of colon-separated hexadecimals. - * - * @return Actual length of @p out on success. - * @return 0, on failure. - */ -size_t gnrc_netif_addr_from_str(uint8_t *out, size_t out_len, const char *str); - -#ifdef __cplusplus -} -#endif - -#endif /* NET_GNRC_NETIF_H */ -/** @} */ diff --git a/sys/include/net/gnrc/rpl/structs.h b/sys/include/net/gnrc/rpl/structs.h index 753d4645d097ae02a13c6f3fbb70750aecaa3213..b192163c2aa123314a439394bfe2c06ecfaddb02 100644 --- a/sys/include/net/gnrc/rpl/structs.h +++ b/sys/include/net/gnrc/rpl/structs.h @@ -27,7 +27,6 @@ extern "C" { #endif -#include "net/gnrc/ipv6/netif.h" #include "net/ipv6/addr.h" #include "xtimer.h" #include "trickle.h" diff --git a/sys/include/net/gnrc/sixlowpan.h b/sys/include/net/gnrc/sixlowpan.h index 1f9b4a9e254acc9cd7b06fa9b91b2b4d6f8661bd..219bfc422c0fdc6a1b2ef68cfe0025eb6bea17bd 100644 --- a/sys/include/net/gnrc/sixlowpan.h +++ b/sys/include/net/gnrc/sixlowpan.h @@ -65,18 +65,17 @@ * packet will be silently discarded. * * The @ref GNRC_NETTYPE_SIXLOWPAN header must at least have the gnrc_netif_hdr_t::if_pid field - * set to a legal, 6LoWPAN compatible interface (a @ref gnrc_sixlowpan_netif_t entry referred to as - * `iface` in the following must exist) referred to as "the interface thread" in the following, - * otherwise the packet will be discarded. + * set to a legal, 6LoWPAN compatible interface referred to as `netif` in the + * following, otherwise the packet will be discarded. * - * If @ref net_gnrc_sixlowpan_iphc is included and gnrc_sixlowpan_netif_t::iphc_enable of `iface` + * If @ref net_gnrc_sixlowpan_iphc is included and gnrc_sixlowpan_netif_t::iphc_enable of `netif` * is true the @ref GNRC_NETTYPE_IPV6 header will be compressed according to * <a href="https://tools.ietf.org/html/rfc6282">RFC 6282</a>. If it is false the * @ref SIXLOWPAN_UNCOMP dispatch will be appended as a new @ref gnrc_pktsnip_t to the packet. * The false case also applies if @ref net_gnrc_sixlowpan_iphc is not included. * * If the packet without @ref GNRC_NETTYPE_NETIF header is shorter than - * gnrc_sixlowpan_netif_t::max_frag_size of `iface` the packet will be send to the interface + * gnrc_netif2_t::sixlo::max_frag_size of `netif` the packet will be send to the `netif`'s * thread. Otherwise if @ref net_gnrc_sixlowpan_frag is included the packet will be fragmented * according to <a href="https://tools.ietf.org/html/rfc4944">RFC 4944</a> if the packet is without * @ref GNRC_NETTYPE_NETIF header shorter than @ref SIXLOWPAN_FRAG_MAX_LEN. If none of these cases diff --git a/sys/include/net/gnrc/sixlowpan/nd/router.h b/sys/include/net/gnrc/sixlowpan/nd/router.h deleted file mode 100644 index 302a858f90b5649c116ba330f41314b433b91203..0000000000000000000000000000000000000000 --- a/sys/include/net/gnrc/sixlowpan/nd/router.h +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup net_gnrc_sixlowpan_nd_router Router-part of 6LoWPAN-ND - * @ingroup net_gnrc_sixlowpan_nd - * @brief Router-part of 6LoWPAN-ND - * @{ - * - * @file - * @brief Router-definitions for 6LoWPAN-ND. - * - * @author Martine Lenders <mlenders@inf.fu-berlin.de> - */ -#ifndef NET_GNRC_SIXLOWPAN_ND_ROUTER_H -#define NET_GNRC_SIXLOWPAN_ND_ROUTER_H - -#include <stdbool.h> - -#include "bitfield.h" -#include "net/gnrc/sixlowpan/ctx.h" -#include "net/gnrc/ipv6/netif.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Number of registerable border routers - * - * @note More than one border routers require some way of synchronization - * of the context information (see - * [RFC 6775, section 8.1](https://tools.ietf.org/html/rfc6775#section-8.1)) - */ -#ifndef GNRC_SIXLOWPAN_ND_ROUTER_ABR_NUMOF -#define GNRC_SIXLOWPAN_ND_ROUTER_ABR_NUMOF (1) -#endif - -/** - * @brief The number of non-link-local prefixes associated with border routers - * at maximum. - */ -#ifndef GNRC_SIXLOWPAN_ND_ROUTER_ABR_PRF_NUMOF -/* One prefix per interface */ -#define GNRC_SIXLOWPAN_ND_ROUTER_ABR_PRF_NUMOF \ - (GNRC_SIXLOWPAN_ND_ROUTER_ABR_NUMOF * GNRC_NETIF_NUMOF) -#endif - -/** - * @brief Representation for prefixes coming from a router - */ -typedef struct gnrc_sixlowpan_nd_router_prf { - struct gnrc_sixlowpan_nd_router_prf *next; /**< next prefix */ - gnrc_ipv6_netif_t *iface; /**< interface the prefix is registered too */ - gnrc_ipv6_netif_addr_t *prefix; /**< prefix on the interface/in the prefix list */ -} gnrc_sixlowpan_nd_router_prf_t; - -/** - * @brief Abstract representation of a border router on all (border) routers. - */ -typedef struct { - ipv6_addr_t addr; /**< the IPv6 address of the border router (BR) */ - uint32_t version; /**< version of the information dissiminated by the - * BR */ - uint16_t ltime; /**< the time in minutes until deletion */ -#ifdef MODULE_GNRC_SIXLOWPAN_CTX - BITFIELD(ctxs, GNRC_SIXLOWPAN_CTX_SIZE);/**< contexts associated with BR */ -#endif - gnrc_sixlowpan_nd_router_prf_t *prfs; /**< prefixes associated with BR */ - xtimer_t ltimer; /**< timer for deletion */ - msg_t ltimer_msg; /**< msg_t for gnrc_sixlowpan_nd_router_abr_t::ltimer */ -} gnrc_sixlowpan_nd_router_abr_t; - -/** - * @brief Removes tentetative neighbor cache entries or sets registered ones to - * garbage-collectible. - * - * @param[in] nc_entry A neighbor cache entry. - */ -static inline void gnrc_sixlowpan_nd_router_gc_nc(gnrc_ipv6_nc_t *nc_entry) -{ - switch (gnrc_ipv6_nc_get_type(nc_entry)) { - case GNRC_IPV6_NC_TYPE_TENTATIVE: - case GNRC_IPV6_NC_TYPE_REGISTERED: - gnrc_ipv6_nc_remove(nc_entry->iface, &nc_entry->ipv6_addr); - break; - default: - break; - } - -} - -/** - * @brief Set @p netif to router mode. - * - * @details This sets/unsets the GNRC_IPV6_NETIF_FLAGS_ROUTER and initializes or ceases router - * behavior for 6LoWPAN neighbor discovery. - * - * @param[in] netif An IPv6 interface. Must not be NULL. - * @param[in] enable Status for the GNRC_IPV6_NETIF_FLAGS_ROUTER flag. - */ -static inline void gnrc_sixlowpan_nd_router_set_router(gnrc_ipv6_netif_t *netif, bool enable) -{ - if (enable) { - netif->flags |= GNRC_IPV6_NETIF_FLAGS_ROUTER; - } - else { - netif->flags &= ~GNRC_IPV6_NETIF_FLAGS_ROUTER; - } -} - -/** - * @brief Set/Unset GNRC_IPV6_NETIF_FLAGS_RTR_ADV flag for @p netif. - * - * @details GNRC_IPV6_NETIF_FLAGS_RTR_ADV and initializes or ceases - * periodic router advertising behavior for neighbor discovery. - * - * @param[in] netif An IPv6 interface. Must not be NULL. - * @param[in] enable Status for the GNRC_IPV6_NETIF_FLAGS_RTR_ADV flag. - */ -void gnrc_sixlowpan_nd_router_set_rtr_adv(gnrc_ipv6_netif_t *netif, bool enable); - -/** - * @brief Get's the border router for this router. - * - * @return The border router, if one is specified. - * @return NULL, otherwise. - */ -gnrc_sixlowpan_nd_router_abr_t *gnrc_sixlowpan_nd_router_abr_get(void); - -/** - * @brief Checks if the version data @p abr_opt is older than the version of the currently - * registered border router. - * - * @param[in] abr_opt An authoritative border router option containing potentially new - * information on the currently registered border router. - * - * @return true, if the information in @p abr_opt is newer. - * @return false, if the information in @p abr_opt is older. - */ -bool gnrc_sixlowpan_nd_router_abr_older(sixlowpan_nd_opt_abr_t *abr_opt); - -/** - * @brief Removes the border router and all the prefixes and contexts it disseminated through - * the network for this node. - * - * @param[in] abr The border router. - */ -void gnrc_sixlowpan_nd_router_abr_remove(gnrc_sixlowpan_nd_router_abr_t *abr); - -#ifdef MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER -/** - * @brief Makes this node a new border router. - * - * @pre addr != NULL - * - * @param[in] addr The local address to use in the ABROs - * @param[in] ltime The lifetime to advertise in the ABROs. 0 assumes a default value of - * @ref GNRC_SIXLOWPAN_ND_BORDER_ROUTER_DEFAULT_LTIME - * - * @return The new border router object. - * @return NULL, on error. - */ -gnrc_sixlowpan_nd_router_abr_t *gnrc_sixlowpan_nd_router_abr_create(ipv6_addr_t *addr, - unsigned int ltime); - -/** - * @brief Adds a prefix for this border router to manage. - * - * @pre iface != NULL && prefix != NULL - * - * @param[in] abr The local border router. - * @param[in] iface The IPv6 interface the prefix was added to. - * @param[in] prefix The prefix. - * - * @return 0, on success - * @return -ENOMEM, if no space for the new prefix is available. - * @return -ENOENT, if @p abr is not registered. - */ -int gnrc_sixlowpan_nd_router_abr_add_prf(gnrc_sixlowpan_nd_router_abr_t* abr, - gnrc_ipv6_netif_t *iface, gnrc_ipv6_netif_addr_t *prefix); - -/** - * @brief Removes a prefix from this border router. - * - * @param[in] abr The local border router. - * @param[in] iface The IPv6 interface the prefix was added to. - * @param[in] prefix The prefix. - */ -void gnrc_sixlowpan_nd_router_abr_rem_prf(gnrc_sixlowpan_nd_router_abr_t *abr, - gnrc_ipv6_netif_t *iface, gnrc_ipv6_netif_addr_t *prefix); - -/** - * @brief Adds a context for this border router to manage. - * - * @param[in] abr The local border router - * @param[in] cid The context to be add. - * - * @return 0, on success - * @return -EINVAL, if @p ctx is greater than 15. - * @return -ENOENT, if @p abr is not registered. - */ -int gnrc_sixlowpan_nd_router_abr_add_ctx(gnrc_sixlowpan_nd_router_abr_t *abr, uint8_t cid); - -/** - * @brief Removes a context from this border router. - * - * @param[in] abr The local border router. - * @param[in] cid The context to be remove. - */ -void gnrc_sixlowpan_nd_router_abr_rem_ctx(gnrc_sixlowpan_nd_router_abr_t *abr, uint8_t cid); -#else -#define gnrc_sixlowpan_nd_router_abr_create(addr, ltime) (NULL) -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* NET_GNRC_SIXLOWPAN_ND_ROUTER_H */ -/** @} */ diff --git a/sys/include/net/gnrc/sixlowpan/netif.h b/sys/include/net/gnrc/sixlowpan/netif.h deleted file mode 100644 index c6a7a28510144de10a8f422ca8c6929b1f770e4f..0000000000000000000000000000000000000000 --- a/sys/include/net/gnrc/sixlowpan/netif.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup net_gnrc_sixlowpan_netif 6LoWPAN network interfaces - * @ingroup net_gnrc_sixlowpan - * @brief 6LoWPAN specific information on @ref net_gnrc_netif - * @{ - * - * @file - * @brief Definitions for 6LoWPAN specific information of network interfaces. - * - * @author Martine Lenders <mlenders@inf.fu-berlin.de> - */ -#ifndef NET_GNRC_SIXLOWPAN_NETIF_H -#define NET_GNRC_SIXLOWPAN_NETIF_H - -#include <stdbool.h> - -#include "kernel_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Definition of 6LoWPAN interface type. - */ -typedef struct { - kernel_pid_t pid; /**< PID of the interface */ - uint16_t max_frag_size; /**< Maximum fragment size for this interface */ -#ifdef MODULE_GNRC_SIXLOWPAN_IPHC - bool iphc_enabled; /**< enable or disable IPHC */ -#endif -} gnrc_sixlowpan_netif_t; - -/** - * @brief Initializes the module - */ -void gnrc_sixlowpan_netif_init(void); - -/** - * @brief Add interface to 6LoWPAN. - * - * @param[in] pid The PID to the interface. - * @param[in] max_frag_size The maximum fragment size for this interface. - */ -void gnrc_sixlowpan_netif_add(kernel_pid_t pid, uint16_t max_frag_size); - -/** - * @brief Remove interface from 6LoWPAN. - * - * @param[in] pid The PID to the interface. - */ -void gnrc_sixlowpan_netif_remove(kernel_pid_t pid); - -/** - * @brief Get interface. - * - * @param[in] pid The PID to the interface - * - * @return The interface describing structure, on success. - * @return NULL, if there is no interface with PID @p pid. - */ -gnrc_sixlowpan_netif_t *gnrc_sixlowpan_netif_get(kernel_pid_t pid); - -#ifdef __cplusplus -} -#endif - -#endif /* NET_GNRC_SIXLOWPAN_NETIF_H */ -/** @} */ diff --git a/sys/net/gnrc/Makefile b/sys/net/gnrc/Makefile index 1d01eaa27ec9dbe2bf35cd0286edcf9f284fb961..61d132a635fdeb6239bc74d797b5e1ce338e748e 100644 --- a/sys/net/gnrc/Makefile +++ b/sys/net/gnrc/Makefile @@ -16,12 +16,6 @@ endif ifneq (,$(filter gnrc_ipv6_hdr,$(USEMODULE))) DIRS += network_layer/ipv6/hdr endif -ifneq (,$(filter gnrc_ipv6_nc,$(USEMODULE))) - DIRS += network_layer/ipv6/nc -endif -ifneq (,$(filter gnrc_ipv6_netif,$(USEMODULE))) - DIRS += network_layer/ipv6/netif -endif ifneq (,$(filter gnrc_ipv6_nib,$(USEMODULE))) DIRS += network_layer/ipv6/nib endif @@ -31,21 +25,6 @@ endif ifneq (,$(filter gnrc_ipv6_blacklist,$(USEMODULE))) DIRS += network_layer/ipv6/blacklist endif -ifneq (,$(filter gnrc_ndp,$(USEMODULE))) - DIRS += network_layer/ndp -endif -ifneq (,$(filter gnrc_ndp_internal,$(USEMODULE))) - DIRS += network_layer/ndp/internal -endif -ifneq (,$(filter gnrc_ndp_host,$(USEMODULE))) - DIRS += network_layer/ndp/host -endif -ifneq (,$(filter gnrc_ndp_node,$(USEMODULE))) - DIRS += network_layer/ndp/node -endif -ifneq (,$(filter gnrc_ndp_router,$(USEMODULE))) - DIRS += network_layer/ndp/router -endif ifneq (,$(filter gnrc_ndp2,$(USEMODULE))) DIRS += network_layer/ndp2 endif @@ -55,9 +34,6 @@ endif ifneq (,$(filter gnrc_netif2,$(USEMODULE))) DIRS += netif2 endif -ifneq (,$(filter gnrc_netif,$(USEMODULE))) - DIRS += netif -endif ifneq (,$(filter gnrc_netif_hdr,$(USEMODULE))) DIRS += netif/hdr endif @@ -112,12 +88,6 @@ endif ifneq (,$(filter gnrc_sixlowpan_nd,$(USEMODULE))) DIRS += network_layer/sixlowpan/nd endif -ifneq (,$(filter gnrc_sixlowpan_nd_router,$(USEMODULE))) - DIRS += network_layer/sixlowpan/nd/router -endif -ifneq (,$(filter gnrc_sixlowpan_netif,$(USEMODULE))) - DIRS += network_layer/sixlowpan/netif -endif ifneq (,$(filter gnrc_sock,$(USEMODULE))) DIRS += sock endif diff --git a/sys/net/gnrc/netif/Makefile b/sys/net/gnrc/netif/Makefile deleted file mode 100644 index 84295e48c1b71b053ac93eafc43f7981a3d6f135..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/netif/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -MODULE = gnrc_netif - -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c deleted file mode 100644 index d9df5786fcf5cd18d2c82b5931398a853e0ded4a..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * Copyright (C) 2015 INRIA - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @{ - * - * @file - */ - -#include <errno.h> -#include "kernel_types.h" -#include "net/gnrc/netif.h" - -#ifdef MODULE_GNRC_IPV6_NETIF -#include "net/gnrc/ipv6/netif.h" -#endif - -static gnrc_netif_handler_t if_handler[] = { -#ifdef MODULE_GNRC_IPV6_NETIF - { gnrc_ipv6_netif_add, gnrc_ipv6_netif_remove }, -#endif - /* #ifdef MODULE_GNRC_IPV4_NETIF - * { ipv4_netif_add, ipv4_netif_remove }, - * #endif ... you get the idea - */ - { NULL, NULL } -}; - -static kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - -void gnrc_netif_init(void) -{ - for (int i = 0; i < GNRC_NETIF_NUMOF; i++) { - ifs[i] = KERNEL_PID_UNDEF; - } -} - -int gnrc_netif_add(kernel_pid_t pid) -{ - kernel_pid_t *free_entry = NULL; - - for (int i = 0; i < GNRC_NETIF_NUMOF; i++) { - if (ifs[i] == pid) { - return 0; - } - else if (ifs[i] == KERNEL_PID_UNDEF && !free_entry) { - free_entry = &ifs[i]; - } - } - - if (!free_entry) { - return -ENOMEM; - } - - *free_entry = pid; - - for (int j = 0; if_handler[j].add != NULL; j++) { - if_handler[j].add(pid); - } - - return 0; -} - -void gnrc_netif_remove(kernel_pid_t pid) -{ - int i; - - for (i = 0; i < GNRC_NETIF_NUMOF; i++) { - if (ifs[i] == pid) { - ifs[i] = KERNEL_PID_UNDEF; - - for (int j = 0; if_handler[j].remove != NULL; j++) { - if_handler[j].remove(pid); - } - - return; - } - } -} - -size_t gnrc_netif_get(kernel_pid_t *netifs) -{ - size_t size = 0; - - for (int i = 0; i < GNRC_NETIF_NUMOF; i++) { - if (ifs[i] != KERNEL_PID_UNDEF) { - netifs[size++] = ifs[i]; - } - } - - return size; -} - -bool gnrc_netif_exist(kernel_pid_t pid) -{ - for (int i = 0; i < GNRC_NETIF_NUMOF; i++) { - if (ifs[i] == pid) { - return true; - } - } - return false; -} - -/** @} */ diff --git a/sys/net/gnrc/netif/gnrc_netif_addr_from_str.c b/sys/net/gnrc/netif/gnrc_netif_addr_from_str.c deleted file mode 100644 index 0915488bbc6b5d6ad380da7d17d7101de80b616b..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/netif/gnrc_netif_addr_from_str.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * Copyright (C) 2015 René Kijewski <rene.kijewski@fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @{ - * - * @file - */ - -#include "net/gnrc/netif.h" - -static inline int _dehex(char c, int default_) -{ - if ('0' <= c && c <= '9') { - return c - '0'; - } - else if ('A' <= c && c <= 'F') { - return c - 'A' + 10; - } - else if ('a' <= c && c <= 'f') { - return c - 'a' + 10; - } - else { - return default_; - } -} - -size_t gnrc_netif_addr_from_str(uint8_t *out, size_t out_len, const char *str) -{ - /* Walk over str from the end. */ - /* Take two chars a time as one hex value (%hhx). */ - /* Leading zeros can be omitted. */ - /* Every non-hexadimal character is a delimiter. */ - /* Leading, tailing and adjacent delimiters are forbidden. */ - - const char *end_str = str; - uint8_t *out_end = out; - size_t count = 0; - int assert_cell = 1; - - if (!str || !*str) { - return 0; - } - while (end_str[1]) { - ++end_str; - } - - while (end_str >= str) { - int a = 0, b = _dehex(*end_str--, -1); - if (b < 0) { - if (assert_cell) { - return 0; - } - else { - assert_cell = 1; - continue; - } - } - assert_cell = 0; - - if (end_str >= str) { - a = _dehex(*end_str--, 0); - } - - if (++count > out_len) { - return 0; - } - *out_end++ = (a << 4) | b; - } - if (assert_cell) { - return 0; - } - /* out is reversed */ - - while (out < --out_end) { - uint8_t tmp = *out_end; - *out_end = *out; - *out++ = tmp; - } - - return count; -} - -/** @} */ diff --git a/sys/net/gnrc/netif/gnrc_netif_addr_to_str.c b/sys/net/gnrc/netif/gnrc_netif_addr_to_str.c deleted file mode 100644 index 41d0453f1cb7975a4821fc6f67efa1f47c384b67..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/netif/gnrc_netif_addr_to_str.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @{ - * - * @file - */ - -#include "net/gnrc/netif.h" - -static inline char _half_byte_to_char(uint8_t half_byte) -{ - return (half_byte < 10) ? ('0' + half_byte) : ('a' + (half_byte - 10)); -} - -char *gnrc_netif_addr_to_str(char *out, size_t out_len, const uint8_t *addr, - size_t addr_len) -{ - size_t i; - - if (out_len < (3 * addr_len)) { /* 2 for every byte, 1 for ':' or '\0' */ - return NULL; - } - - out[0] = '\0'; - - for (i = 0; i < addr_len; i++) { - out[(3 * i)] = _half_byte_to_char(addr[i] >> 4); - out[(3 * i) + 1] = _half_byte_to_char(addr[i] & 0xf); - - if (i != (addr_len - 1)) { - out[(3 * i) + 2] = ':'; - } - else { - out[(3 * i) + 2] = '\0'; - } - } - - return out; -} - -/** @} */ diff --git a/sys/net/gnrc/nettest/gnrc_nettest.c b/sys/net/gnrc/nettest/gnrc_nettest.c index 6838b811391d69bc90374664635e86114e9628b3..bce9c20ad298a013859744797355092771d23669 100644 --- a/sys/net/gnrc/nettest/gnrc_nettest.c +++ b/sys/net/gnrc/nettest/gnrc_nettest.c @@ -18,7 +18,6 @@ #include "msg.h" #include "mutex.h" #include "net/gnrc/netapi.h" -#include "net/gnrc/netif.h" #include "net/netopt.h" #include "net/gnrc/netreg.h" #include "net/gnrc/pktbuf.h" @@ -132,13 +131,9 @@ gnrc_nettest_res_t gnrc_nettest_send_iface(kernel_pid_t pid, gnrc_pktsnip_t *in, { gnrc_nettest_res_t res; - gnrc_netif_add(thread_getpid()); - res = _pkt_test(GNRC_NETAPI_MSG_TYPE_SND, pid, in, exp_pkts, exp_senders, exp_out); - gnrc_netif_remove(thread_getpid()); - return res; } diff --git a/sys/net/gnrc/network_layer/icmpv6/error/gnrc_icmpv6_error.c b/sys/net/gnrc/network_layer/icmpv6/error/gnrc_icmpv6_error.c index 80a6773bdd524e9b756fb0c6654e83baba90e9c2..4313414c45e583b2d92adf22f15f9fd6513e6682 100644 --- a/sys/net/gnrc/network_layer/icmpv6/error/gnrc_icmpv6_error.c +++ b/sys/net/gnrc/network_layer/icmpv6/error/gnrc_icmpv6_error.c @@ -15,7 +15,6 @@ #include "net/gnrc/pktbuf.h" #include "net/ipv6.h" -#include "net/gnrc/ipv6/netif.h" #include "net/gnrc/icmpv6/error.h" #include "net/gnrc/icmpv6.h" diff --git a/sys/net/gnrc/network_layer/icmpv6/gnrc_icmpv6.c b/sys/net/gnrc/network_layer/icmpv6/gnrc_icmpv6.c index 9184a29b88149a2f2a9ba125cdec4e34c5dbf94a..b7ab3a3ae5477eba974f8f0c25469d1f86b72a5e 100644 --- a/sys/net/gnrc/network_layer/icmpv6/gnrc_icmpv6.c +++ b/sys/net/gnrc/network_layer/icmpv6/gnrc_icmpv6.c @@ -73,8 +73,7 @@ void gnrc_icmpv6_demux(kernel_pid_t iface, gnrc_pktsnip_t *pkt) return; } - /* Note: size will be checked again in gnrc_icmpv6_echo_req_handle, - gnrc_ndp_rtr_sol_handle, and others */ + /* Note: size will be checked again in packet handlers */ hdr = (icmpv6_hdr_t *)icmpv6->data; diff --git a/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c b/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c index 7fd41fb0859fc928c056a948d04ff464da6d5d77..c612768753c7eec59e7821d8bf85dede2ba10742 100644 --- a/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c +++ b/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c @@ -21,10 +21,8 @@ #include "kernel_types.h" #include "net/gnrc.h" #include "net/gnrc/icmpv6.h" -#include "net/gnrc/ndp.h" #include "net/gnrc/sixlowpan/ctx.h" #include "net/gnrc/sixlowpan/nd.h" -#include "net/gnrc/sixlowpan/nd/router.h" #include "net/protnum.h" #include "thread.h" #include "utlist.h" @@ -414,7 +412,7 @@ static int _fill_ipv6_hdr(gnrc_netif2_t *netif, gnrc_pktsnip_t *ipv6, if (hdr->hl == 0) { if (netif == NULL) { - hdr->hl = GNRC_IPV6_NETIF_DEFAULT_HL; + hdr->hl = GNRC_NETIF2_DEFAULT_HL; } else { hdr->hl = netif->cur_hl; diff --git a/sys/net/gnrc/network_layer/ipv6/nc/Makefile b/sys/net/gnrc/network_layer/ipv6/nc/Makefile deleted file mode 100644 index d0c37ac776a08334721646aa0814e98e063e0829..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/network_layer/ipv6/nc/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -MODULE = gnrc_ipv6_nc - -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/gnrc/network_layer/ipv6/nc/gnrc_ipv6_nc.c b/sys/net/gnrc/network_layer/ipv6/nc/gnrc_ipv6_nc.c deleted file mode 100644 index 417a442b160663ab362e5a425d637ec26396e3b3..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/network_layer/ipv6/nc/gnrc_ipv6_nc.c +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @{ - * - * @file - */ - -#include <errno.h> -#include <string.h> - -#include "net/gnrc/ipv6.h" -#include "net/ipv6/addr.h" -#include "net/gnrc/ipv6/nc.h" -#include "net/gnrc/ipv6/netif.h" -#include "net/gnrc/ndp.h" -#include "net/gnrc/pktbuf.h" -#include "net/gnrc/sixlowpan/nd.h" -#include "thread.h" -#include "xtimer.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#if ENABLE_DEBUG -/* For PRIu8 etc. */ -#include <inttypes.h> - -static char addr_str[IPV6_ADDR_MAX_STR_LEN]; -#endif - -static gnrc_ipv6_nc_t ncache[GNRC_IPV6_NC_SIZE]; - -static void _nc_remove(kernel_pid_t iface, gnrc_ipv6_nc_t *entry) -{ - (void) iface; - if (entry == NULL) { - return; - } - - DEBUG("ipv6_nc: Remove %s for interface %" PRIkernel_pid "\n", - ipv6_addr_to_str(addr_str, &(entry->ipv6_addr), sizeof(addr_str)), - iface); - -#ifdef MODULE_GNRC_NDP_NODE - while (entry->pkts != NULL) { - gnrc_pktbuf_release(entry->pkts->pkt); - entry->pkts->pkt = NULL; - gnrc_pktqueue_remove_head(&entry->pkts); - } -#endif -#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER - xtimer_remove(&entry->type_timeout); - - gnrc_ipv6_netif_t *if_entry = gnrc_ipv6_netif_get(iface); - - if ((if_entry != NULL) && (if_entry->rtr_adv_msg.content.ptr == entry)) { - /* cancel timer set by gnrc_ndp_rtr_sol_handle */ - xtimer_remove(&if_entry->rtr_adv_timer); - } -#endif -#if defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER) - xtimer_remove(&entry->rtr_adv_timer); -#endif - - xtimer_remove(&entry->rtr_timeout); - xtimer_remove(&entry->nbr_sol_timer); - xtimer_remove(&entry->nbr_adv_timer); - - ipv6_addr_set_unspecified(&(entry->ipv6_addr)); - entry->iface = KERNEL_PID_UNDEF; - entry->flags = 0; -} - -void gnrc_ipv6_nc_init(void) -{ - gnrc_ipv6_nc_t *entry; - - for (entry = ncache; entry < (ncache + GNRC_IPV6_NC_SIZE); entry++) { - _nc_remove(entry->iface, entry); - } - memset(ncache, 0, sizeof(ncache)); -} - -gnrc_ipv6_nc_t *_find_free_entry(void) -{ - for (int i = 0; i < GNRC_IPV6_NC_SIZE; i++) { - if (ipv6_addr_is_unspecified(&(ncache[i].ipv6_addr))) { - return ncache + i; - } - } - - return NULL; -} - -gnrc_ipv6_nc_t *gnrc_ipv6_nc_add(kernel_pid_t iface, const ipv6_addr_t *ipv6_addr, - const void *l2_addr, size_t l2_addr_len, uint8_t flags) -{ - gnrc_ipv6_nc_t *free_entry = NULL; - - if (ipv6_addr == NULL) { - DEBUG("ipv6_nc: address was NULL\n"); - return NULL; - } - - if ((l2_addr_len > GNRC_IPV6_NC_L2_ADDR_MAX) || ipv6_addr_is_unspecified(ipv6_addr)) { - DEBUG("ipv6_nc: invalid parameters\n"); - return NULL; - } - - for (int i = 0; i < GNRC_IPV6_NC_SIZE; i++) { - if (ipv6_addr_equal(&(ncache[i].ipv6_addr), ipv6_addr)) { - DEBUG("ipv6_nc: Address %s already registered.\n", - ipv6_addr_to_str(addr_str, ipv6_addr, sizeof(addr_str))); - - if ((l2_addr != NULL) && (l2_addr_len > 0)) { - DEBUG("ipv6_nc: Update to L2 address %s", - gnrc_netif_addr_to_str(addr_str, sizeof(addr_str), - l2_addr, l2_addr_len)); - - memcpy(&(ncache[i].l2_addr), l2_addr, l2_addr_len); - ncache[i].l2_addr_len = l2_addr_len; - ncache[i].flags = flags; - DEBUG(" with flags = 0x%0x\n", flags); - - } - return &ncache[i]; - } - - if (ipv6_addr_is_unspecified(&(ncache[i].ipv6_addr)) && !free_entry) { - /* found the first free entry */ - free_entry = &ncache[i]; - } - } - - if (!free_entry) { - /* reached end of NC without finding updateable or free entry */ - DEBUG("ipv6_nc: neighbor cache full.\n"); - return NULL; - } - - /* Otherwise, fill free entry with your fresh information */ - free_entry->iface = iface; - -#ifdef MODULE_GNRC_NDP_NODE - free_entry->pkts = NULL; -#endif - memcpy(&(free_entry->ipv6_addr), ipv6_addr, sizeof(ipv6_addr_t)); - DEBUG("ipv6_nc: Register %s for interface %" PRIkernel_pid, - ipv6_addr_to_str(addr_str, ipv6_addr, sizeof(addr_str)), - iface); - - if ((l2_addr != NULL) && (l2_addr_len > 0)) { - DEBUG(" to L2 address %s", - gnrc_netif_addr_to_str(addr_str, sizeof(addr_str), - l2_addr, l2_addr_len)); - memcpy(&(free_entry->l2_addr), l2_addr, l2_addr_len); - free_entry->l2_addr_len = l2_addr_len; - } - - free_entry->flags = flags; - - DEBUG(" with flags = 0x%0x\n", flags); - - if (gnrc_ipv6_nc_get_state(free_entry) == GNRC_IPV6_NC_STATE_INCOMPLETE) { - DEBUG("ipv6_nc: Set remaining probes to %" PRIu8 "\n", (uint8_t) GNRC_NDP_MAX_MC_NBR_SOL_NUMOF); - free_entry->probes_remaining = GNRC_NDP_MAX_MC_NBR_SOL_NUMOF; - } - -#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER - free_entry->type_timeout_msg.type = GNRC_SIXLOWPAN_ND_MSG_AR_TIMEOUT; - free_entry->type_timeout_msg.content.ptr = free_entry; -#endif - - free_entry->rtr_timeout_msg.type = GNRC_NDP_MSG_RTR_TIMEOUT; - free_entry->rtr_timeout_msg.content.ptr = free_entry; - -#if defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER) - free_entry->rtr_adv_msg.type = GNRC_NDP_MSG_RTR_ADV_DELAY; - free_entry->rtr_adv_msg.content.ptr = free_entry; -#endif - - free_entry->nbr_sol_msg.content.ptr = free_entry; - - return free_entry; -} - -void gnrc_ipv6_nc_remove(kernel_pid_t iface, const ipv6_addr_t *ipv6_addr) -{ - gnrc_ipv6_nc_t *entry = gnrc_ipv6_nc_get(iface, ipv6_addr); - _nc_remove(iface, entry); -} - -gnrc_ipv6_nc_t *gnrc_ipv6_nc_get(kernel_pid_t iface, const ipv6_addr_t *ipv6_addr) -{ - if ((ipv6_addr == NULL) || (ipv6_addr_is_unspecified(ipv6_addr))) { - DEBUG("ipv6_nc: address was NULL or ::\n"); - return NULL; - } - - for (int i = 0; i < GNRC_IPV6_NC_SIZE; i++) { - if (((ncache[i].iface == KERNEL_PID_UNDEF) || (iface == KERNEL_PID_UNDEF) || - (iface == ncache[i].iface)) && - ipv6_addr_equal(&(ncache[i].ipv6_addr), ipv6_addr)) { - DEBUG("ipv6_nc: Found entry for %s on interface %" PRIkernel_pid - " (0 = all interfaces) [%p]\n", - ipv6_addr_to_str(addr_str, ipv6_addr, sizeof(addr_str)), - iface, (void *)(ncache + i)); - - return ncache + i; - } - } - - return NULL; -} - -gnrc_ipv6_nc_t *gnrc_ipv6_nc_get_next(gnrc_ipv6_nc_t *prev) -{ - if (prev == NULL) { - prev = ncache; - } - else { - prev++; /* get next entry */ - } - - while (prev < (ncache + GNRC_IPV6_NC_SIZE)) { /* while not reached end */ - if (!ipv6_addr_is_unspecified(&(prev->ipv6_addr))) { - return prev; - } - - prev++; - } - - return NULL; -} - -gnrc_ipv6_nc_t *gnrc_ipv6_nc_get_next_router(gnrc_ipv6_nc_t *prev) -{ - for (gnrc_ipv6_nc_t *router = gnrc_ipv6_nc_get_next(prev); router != NULL; - router = gnrc_ipv6_nc_get_next(router)) { - if (router->flags & GNRC_IPV6_NC_IS_ROUTER) { - return router; - } - } - - return NULL; -} - -gnrc_ipv6_nc_t *gnrc_ipv6_nc_still_reachable(const ipv6_addr_t *ipv6_addr) -{ - gnrc_ipv6_nc_t *entry = gnrc_ipv6_nc_get(KERNEL_PID_UNDEF, ipv6_addr); - - if (entry == NULL) { - DEBUG("ipv6_nc: No entry found for %s\n", - ipv6_addr_to_str(addr_str, ipv6_addr, sizeof(addr_str))); - return NULL; - } - - if ((gnrc_ipv6_nc_get_state(entry) != GNRC_IPV6_NC_STATE_INCOMPLETE) && - (gnrc_ipv6_nc_get_state(entry) != GNRC_IPV6_NC_STATE_UNMANAGED)) { -#if defined(MODULE_GNRC_IPV6_NETIF) && defined(MODULE_XTIMER) && defined(MODULE_GNRC_IPV6) - gnrc_ipv6_netif_t *iface = gnrc_ipv6_netif_get(entry->iface); - - gnrc_ndp_internal_reset_nbr_sol_timer(entry, iface->reach_time, - GNRC_NDP_MSG_NC_STATE_TIMEOUT, gnrc_ipv6_pid); -#endif - - DEBUG("ipv6_nc: Marking entry %s as reachable\n", - ipv6_addr_to_str(addr_str, ipv6_addr, sizeof(addr_str))); - entry->flags &= ~(GNRC_IPV6_NC_STATE_MASK >> GNRC_IPV6_NC_STATE_POS); - entry->flags |= (GNRC_IPV6_NC_STATE_REACHABLE >> GNRC_IPV6_NC_STATE_POS); - } - - return entry; -} - -kernel_pid_t gnrc_ipv6_nc_get_l2_addr(uint8_t *l2_addr, uint8_t *l2_addr_len, - const gnrc_ipv6_nc_t *entry) -{ - assert((l2_addr != NULL) && (l2_addr_len != NULL)); - if ((entry == NULL) || !gnrc_ipv6_nc_is_reachable(entry)) { - return KERNEL_PID_UNDEF; - } - *l2_addr_len = entry->l2_addr_len; - memcpy(l2_addr, entry->l2_addr, entry->l2_addr_len); - return entry->iface; -} - -/** @} */ diff --git a/sys/net/gnrc/network_layer/ipv6/netif/Makefile b/sys/net/gnrc/network_layer/ipv6/netif/Makefile deleted file mode 100644 index 5913859c40871984485641db554568d0d1a3adc4..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/network_layer/ipv6/netif/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -MODULE = gnrc_ipv6_netif - -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c b/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c deleted file mode 100644 index b9bf3934d451b7abbc3c0eda6fe550be930fbbef..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c +++ /dev/null @@ -1,924 +0,0 @@ -/* - * Copyright (C) 2014 Martin Lenders <mlenders@inf.fu-berlin.de> - * Copyright (C) 2015 Oliver Hahm <oliver.hahm@inria.fr> - * - * This file is subject to the terms and conditions of the GNU Lesser General - * Public License v2.1. See the file LICENSE in the top level directory for - * more details. - */ - -/** - * @{ - * - * @file - * - * @author Martine Lenders <mlenders@inf.fu-berlin.de> - * @author Oliver Hahm <oliver.hahm@inria.fr> - */ - -#include <errno.h> -#include <string.h> - -#include "kernel_types.h" -#include "mutex.h" -#include "bitfield.h" - -#include "net/eui64.h" -#include "net/ipv6/addr.h" -#include "net/gnrc/ndp.h" -#include "net/gnrc/netapi.h" -#include "net/gnrc/netif.h" -#include "net/gnrc/netif/hdr.h" -#include "net/gnrc/sixlowpan/nd.h" -#include "net/gnrc/sixlowpan/netif.h" - -#include "net/gnrc/ipv6/netif.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#if ENABLE_DEBUG -/* For PRIu16 etc. */ -#include <inttypes.h> -#endif - -/* number of "points" assigned to an source address candidate with equal scope - * than destination address */ -#define RULE_2A_PTS (4) -/* number of "points" assigned to an source address candidate with smaller scope - * than destination address */ -#define RULE_2B_PTS (2) -/* number of "points" assigned to an source address candidate in preferred state */ -#define RULE_3_PTS (1) - -static gnrc_ipv6_netif_t ipv6_ifs[GNRC_NETIF_NUMOF]; - -#if ENABLE_DEBUG -static char addr_str[IPV6_ADDR_MAX_STR_LEN]; -#endif - -static ipv6_addr_t *_add_addr_to_entry(gnrc_ipv6_netif_t *entry, const ipv6_addr_t *addr, - uint8_t prefix_len, uint8_t flags) -{ - gnrc_ipv6_netif_addr_t *tmp_addr = NULL; - - for (int i = 0; i < GNRC_IPV6_NETIF_ADDR_NUMOF; i++) { - if (ipv6_addr_equal(&(entry->addrs[i].addr), addr)) { - return &(entry->addrs[i].addr); - } - - if (ipv6_addr_is_unspecified(&(entry->addrs[i].addr)) && !tmp_addr) { - tmp_addr = &(entry->addrs[i]); - } - } - - if (!tmp_addr) { - DEBUG("ipv6 netif: couldn't add %s/%" PRIu8 " to interface %" PRIkernel_pid "\n: No space left.\n", - ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)), - prefix_len, entry->pid); - return NULL; - } - - memcpy(&(tmp_addr->addr), addr, sizeof(ipv6_addr_t)); - DEBUG("ipv6 netif: Added %s/%" PRIu8 " to interface %" PRIkernel_pid "\n", - ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)), - prefix_len, entry->pid); - - tmp_addr->prefix_len = prefix_len; - tmp_addr->flags = flags; - -#ifdef MODULE_GNRC_SIXLOWPAN_ND - if (!ipv6_addr_is_multicast(&(tmp_addr->addr)) && - (entry->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN)) { - ipv6_addr_t *router = gnrc_ndp_internal_default_router(); - if (router != NULL) { - mutex_unlock(&entry->mutex); /* function below relocks mutex */ - gnrc_ndp_internal_send_nbr_sol(entry->pid, &tmp_addr->addr, router, router); - mutex_lock(&entry->mutex); /* relock mutex */ - } - /* otherwise there is no default router to register to */ - } -#endif - - if (ipv6_addr_is_multicast(addr)) { - tmp_addr->flags |= GNRC_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST; - } - else { - if (!ipv6_addr_is_link_local(addr)) { -#ifdef MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER - tmp_addr->valid = UINT32_MAX; - tmp_addr->preferred = UINT32_MAX; - gnrc_sixlowpan_nd_router_abr_t *abr = gnrc_sixlowpan_nd_router_abr_get(); - mutex_unlock(&entry->mutex); - gnrc_ipv6_netif_set_rtr_adv(entry, true); - mutex_lock(&entry->mutex); - if (gnrc_sixlowpan_nd_router_abr_add_prf(abr, entry, tmp_addr) < 0) { - DEBUG("ipv6_netif: error adding prefix to 6LoWPAN-ND management\n"); - } -#endif -#if defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER) - if ((entry->flags & GNRC_IPV6_NETIF_FLAGS_ROUTER) && - (entry->flags & GNRC_IPV6_NETIF_FLAGS_RTR_ADV)) { - mutex_unlock(&entry->mutex); /* function below relocks mutex */ -#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER - if (entry->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) { - gnrc_ndp_internal_send_rtr_adv(entry->pid, NULL, NULL, false); - } -#endif -#ifdef MODULE_GNRC_NDP_ROUTER - /* New prefixes MAY allow the router to retransmit up to - * GNRC_NDP_MAX_INIT_RTR_ADV_NUMOF unsolicited RA - * (see https://tools.ietf.org/html/rfc4861#section-6.2.4) */ - if (!(entry->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN)) { - entry->rtr_adv_count = GNRC_NDP_MAX_INIT_RTR_ADV_NUMOF; - gnrc_ndp_router_retrans_rtr_adv(entry); - } -#endif - mutex_lock(&entry->mutex); /* relock mutex */ - } -#endif - } - else { - tmp_addr->flags |= GNRC_IPV6_NETIF_ADDR_FLAGS_NDP_ON_LINK; - } -#if defined(MODULE_GNRC_NDP_NODE) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER) - /* add solicited-nodes multicast address for new address if interface is not a - * 6LoWPAN host interface (see: https://tools.ietf.org/html/rfc6775#section-5.2) */ - if (!(entry->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) || - (entry->flags & GNRC_IPV6_NETIF_FLAGS_ROUTER)) { - ipv6_addr_t sol_node; - ipv6_addr_set_solicited_nodes(&sol_node, addr); - _add_addr_to_entry(entry, &sol_node, IPV6_ADDR_BIT_LEN, 0); - } -#endif - /* TODO: send NS with ARO on 6LoWPAN interfaces, but not so many and only for the new - * source address. */ - } - - tmp_addr->valid_timeout_msg.type = GNRC_NDP_MSG_ADDR_TIMEOUT; - tmp_addr->valid_timeout_msg.content.ptr = &tmp_addr->addr; - - return &(tmp_addr->addr); -} - -static void _reset_addr_from_entry(gnrc_ipv6_netif_t *entry) -{ - DEBUG("ipv6 netif: Reset IPv6 addresses on interface %" PRIkernel_pid "\n", entry->pid); - memset(entry->addrs, 0, sizeof(entry->addrs)); -} - -static void _ipv6_netif_remove(gnrc_ipv6_netif_t *entry) -{ - if (entry == NULL) { - return; - } - -#ifdef MODULE_GNRC_NDP - gnrc_ndp_netif_remove(entry); -#endif - - mutex_lock(&entry->mutex); - xtimer_remove(&entry->rtr_sol_timer); -#ifdef MODULE_GNRC_NDP_ROUTER - xtimer_remove(&entry->rtr_adv_timer); -#endif - _reset_addr_from_entry(entry); - DEBUG("ipv6 netif: Remove IPv6 interface %" PRIkernel_pid "\n", entry->pid); - entry->pid = KERNEL_PID_UNDEF; - entry->flags = 0; - - mutex_unlock(&entry->mutex); -} - -void gnrc_ipv6_netif_init(void) -{ - for (int i = 0; i < GNRC_NETIF_NUMOF; i++) { - mutex_init(&(ipv6_ifs[i].mutex)); - _ipv6_netif_remove(&ipv6_ifs[i]); - } -} - -void gnrc_ipv6_netif_add(kernel_pid_t pid) -{ - gnrc_ipv6_netif_t *free_entry = NULL; - - for (int i = 0; i < GNRC_NETIF_NUMOF; i++) { - if (ipv6_ifs[i].pid == pid) { - /* pid has already been added */ - return; - } - - else if ((ipv6_ifs[i].pid == KERNEL_PID_UNDEF) && !free_entry) { - /* found the first free entry */ - free_entry = &ipv6_ifs[i]; - } - } - - if (!free_entry) { - DEBUG("ipv6 netif: Could not add %" PRIkernel_pid " to IPv6: No space left.\n", pid); - return; - } - - /* Otherwise, fill the free entry */ - - mutex_lock(&free_entry->mutex); - - DEBUG("ipv6 netif: Add IPv6 interface %" PRIkernel_pid " (i = %d)\n", pid, - free_entry - ipv6_ifs); - free_entry->pid = pid; - free_entry->mtu = GNRC_IPV6_NETIF_DEFAULT_MTU; - free_entry->cur_hl = GNRC_IPV6_NETIF_DEFAULT_HL; - free_entry->flags = 0; - - _add_addr_to_entry(free_entry, &ipv6_addr_all_nodes_link_local, - IPV6_ADDR_BIT_LEN, 0); - - mutex_unlock(&free_entry->mutex); - -#ifdef MODULE_GNRC_NDP - gnrc_ndp_netif_add(free_entry); -#endif - - DEBUG(" * pid = %" PRIkernel_pid " ", free_entry->pid); - DEBUG("cur_hl = %d ", free_entry->cur_hl); - DEBUG("mtu = %d ", free_entry->mtu); - DEBUG("flags = %04" PRIx16 "\n", free_entry->flags); -} - -void gnrc_ipv6_netif_remove(kernel_pid_t pid) -{ - gnrc_ipv6_netif_t *entry = gnrc_ipv6_netif_get(pid); - _ipv6_netif_remove(entry); -} - -gnrc_ipv6_netif_t *gnrc_ipv6_netif_get(kernel_pid_t pid) -{ - for (int i = 0; i < GNRC_NETIF_NUMOF; i++) { - if (ipv6_ifs[i].pid == pid) { - DEBUG("ipv6 netif: Get IPv6 interface %" PRIkernel_pid " (%p, i = %d)\n", pid, - (void *)(&(ipv6_ifs[i])), i); - return &(ipv6_ifs[i]); - } - } - - return NULL; -} - -#if defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER) -void gnrc_ipv6_netif_set_router(gnrc_ipv6_netif_t *netif, bool enable) -{ -#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER - if (netif->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) { - gnrc_sixlowpan_nd_router_set_router(netif, enable); - return; - } -#endif -#ifdef MODULE_GNRC_NDP_ROUTER - gnrc_ndp_router_set_router(netif, enable); -#endif -} - -void gnrc_ipv6_netif_set_rtr_adv(gnrc_ipv6_netif_t *netif, bool enable) -{ -#if defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER) - if (netif->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) { - gnrc_sixlowpan_nd_router_set_rtr_adv(netif, enable); - return; - } -#endif -#ifdef MODULE_GNRC_NDP_ROUTER - gnrc_ndp_router_set_rtr_adv(netif, enable); -#endif -} -#endif - -ipv6_addr_t *gnrc_ipv6_netif_add_addr(kernel_pid_t pid, const ipv6_addr_t *addr, - uint8_t prefix_len, uint8_t flags) -{ - gnrc_ipv6_netif_t *entry = gnrc_ipv6_netif_get(pid); - ipv6_addr_t *res; - - if ((entry == NULL) || (addr == NULL) || (ipv6_addr_is_unspecified(addr)) || - ((prefix_len - 1) > 127)) { /* prefix_len < 1 || prefix_len > 128 */ - return NULL; - } - - mutex_lock(&entry->mutex); - - res = _add_addr_to_entry(entry, addr, prefix_len, flags); - - mutex_unlock(&entry->mutex); - - return res; -} - -static void _remove_addr_from_entry(gnrc_ipv6_netif_t *entry, ipv6_addr_t *addr) -{ - mutex_lock(&entry->mutex); - - for (int i = 0; i < GNRC_IPV6_NETIF_ADDR_NUMOF; i++) { - if (ipv6_addr_equal(&(entry->addrs[i].addr), addr)) { - DEBUG("ipv6 netif: Remove %s to interface %" PRIkernel_pid "\n", - ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)), entry->pid); - ipv6_addr_set_unspecified(&(entry->addrs[i].addr)); - entry->addrs[i].flags = 0; -#ifdef MODULE_GNRC_NDP_ROUTER - /* Removal of prefixes MAY allow the router to retransmit up to - * GNRC_NDP_MAX_INIT_RTR_ADV_NUMOF unsolicited RA - * (see https://tools.ietf.org/html/rfc4861#section-6.2.4) */ - if ((entry->flags & GNRC_IPV6_NETIF_FLAGS_ROUTER) && - (entry->flags & GNRC_IPV6_NETIF_FLAGS_RTR_ADV) && - (!ipv6_addr_is_multicast(addr) && - !ipv6_addr_is_link_local(addr))) { - entry->rtr_adv_count = GNRC_NDP_MAX_INIT_RTR_ADV_NUMOF; - mutex_unlock(&entry->mutex); /* function below relocks the mutex */ - gnrc_ndp_router_retrans_rtr_adv(entry); - return; - } -#endif -#ifdef MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER - gnrc_sixlowpan_nd_router_abr_t *abr = gnrc_sixlowpan_nd_router_abr_get(); - gnrc_sixlowpan_nd_router_abr_rem_prf(abr, entry, &entry->addrs[i]); -#endif - - mutex_unlock(&entry->mutex); - return; - } - } - - mutex_unlock(&entry->mutex); -} - -void gnrc_ipv6_netif_remove_addr(kernel_pid_t pid, ipv6_addr_t *addr) -{ - if (pid == KERNEL_PID_UNDEF) { - for (int i = 0; i < GNRC_NETIF_NUMOF; i++) { - if (ipv6_ifs[i].pid == KERNEL_PID_UNDEF) { - continue; - } - - _remove_addr_from_entry(ipv6_ifs + i, addr); - } - } - else { - gnrc_ipv6_netif_t *entry = gnrc_ipv6_netif_get(pid); - - _remove_addr_from_entry(entry, addr); - } -} - -void gnrc_ipv6_netif_reset_addr(kernel_pid_t pid) -{ - gnrc_ipv6_netif_t *entry = gnrc_ipv6_netif_get(pid); - - if (entry == NULL) { - return; - } - - mutex_lock(&entry->mutex); - - _reset_addr_from_entry(entry); - - mutex_unlock(&entry->mutex); -} - -kernel_pid_t gnrc_ipv6_netif_find_by_addr(ipv6_addr_t **out, const ipv6_addr_t *addr) -{ - for (int i = 0; i < GNRC_NETIF_NUMOF; i++) { - if (out != NULL) { - *out = gnrc_ipv6_netif_find_addr(ipv6_ifs[i].pid, addr); - - if (*out != NULL) { - DEBUG("ipv6 netif: Found %s on interface %" PRIkernel_pid "\n", - ipv6_addr_to_str(addr_str, *out, sizeof(addr_str)), - ipv6_ifs[i].pid); - return ipv6_ifs[i].pid; - } - } - else { - if (gnrc_ipv6_netif_find_addr(ipv6_ifs[i].pid, addr) != NULL) { - DEBUG("ipv6 netif: Found :: on interface %" PRIkernel_pid "\n", - ipv6_ifs[i].pid); - return ipv6_ifs[i].pid; - } - } - } - - if (out != NULL) { - *out = NULL; - } - - return KERNEL_PID_UNDEF; -} - -ipv6_addr_t *gnrc_ipv6_netif_find_addr(kernel_pid_t pid, const ipv6_addr_t *addr) -{ - gnrc_ipv6_netif_t *entry = gnrc_ipv6_netif_get(pid); - - if (entry == NULL) { - return NULL; - } - - mutex_lock(&entry->mutex); - - for (int i = 0; i < GNRC_IPV6_NETIF_ADDR_NUMOF; i++) { - if (ipv6_addr_equal(&(entry->addrs[i].addr), addr)) { - mutex_unlock(&entry->mutex); - DEBUG("ipv6 netif: Found %s on interface %" PRIkernel_pid "\n", - ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)), - pid); - return &(entry->addrs[i].addr); - } - } - - mutex_unlock(&entry->mutex); - - return NULL; -} - -static uint8_t _find_by_prefix_unsafe(ipv6_addr_t **res, gnrc_ipv6_netif_t *iface, - const ipv6_addr_t *addr, uint8_t *only) -{ - uint8_t best_match = 0; - - for (int i = 0; i < GNRC_IPV6_NETIF_ADDR_NUMOF; i++) { - uint8_t match; - - if ((only != NULL) && !(bf_isset(only, i))) { - continue; - } - - if (((only != NULL) && - gnrc_ipv6_netif_addr_is_non_unicast(&(iface->addrs[i].addr))) || - ipv6_addr_is_unspecified(&(iface->addrs[i].addr))) { - continue; - } - - match = ipv6_addr_match_prefix(&(iface->addrs[i].addr), addr); - - if ((only == NULL) && !ipv6_addr_is_multicast(addr) && - (match < iface->addrs[i].prefix_len)) { - /* match but not of same subnet */ - continue; - } - - if (match > best_match) { - if (res != NULL) { - *res = &(iface->addrs[i].addr); - } - - best_match = match; - } - } - -#if ENABLE_DEBUG - if (*res != NULL) { - DEBUG("ipv6 netif: Found %s on interface %" PRIkernel_pid " matching ", - ipv6_addr_to_str(addr_str, *res, sizeof(addr_str)), - iface->pid); - DEBUG("%s by %" PRIu8 " bits (used as source address = %s)\n", - ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)), - best_match, - (only != NULL) ? "true" : "false"); - } - else { - DEBUG("ipv6 netif: Did not found any address on interface %" PRIkernel_pid - " matching %s (used as source address = %s)\n", - iface->pid, - ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)), - (only != NULL) ? "true" : "false"); - } -#endif - - return best_match; -} - -kernel_pid_t gnrc_ipv6_netif_find_by_prefix(ipv6_addr_t **out, const ipv6_addr_t *prefix) -{ - uint8_t best_match = 0; - ipv6_addr_t *tmp_res = NULL; - kernel_pid_t res = KERNEL_PID_UNDEF; - - for (int i = 0; i < GNRC_NETIF_NUMOF; i++) { - uint8_t match; - - mutex_lock(&(ipv6_ifs[i].mutex)); - - match = _find_by_prefix_unsafe(&tmp_res, ipv6_ifs + i, prefix, NULL); - - if (match > best_match) { - *out = tmp_res; - res = ipv6_ifs[i].pid; - best_match = match; - } - - mutex_unlock(&(ipv6_ifs[i].mutex)); - } - -#if ENABLE_DEBUG - if (res != KERNEL_PID_UNDEF) { - DEBUG("ipv6 netif: Found %s on interface %" PRIkernel_pid " globally matching ", - ipv6_addr_to_str(addr_str, *out, sizeof(addr_str)), - res); - DEBUG("%s by %" PRIu8 " bits\n", - ipv6_addr_to_str(addr_str, prefix, sizeof(addr_str)), - best_match); - } - else { - DEBUG("ipv6 netif: Did not found any address globally matching %s\n", - ipv6_addr_to_str(addr_str, prefix, sizeof(addr_str))); - } -#endif - - return res; -} - -/** - * @brief selects potential source address candidates - * @see <a href="http://tools.ietf.org/html/rfc6724#section-4"> - * RFC6724, section 4 - * </a> - * @param[in] iface the interface used for sending - * @param[in] dst the destination address - * @param[out] candidate_set a bitfield representing all addresses - * configured to @p iface, potential candidates - * will be marked as 1 - * - * @return false if no candidates were found - * @return true otherwise - * - * @pre the interface entry and its set of addresses must not be changed during - * runtime of this function - */ -static int _create_candidate_set(gnrc_ipv6_netif_t *iface, const ipv6_addr_t *dst, - uint8_t *candidate_set, bool link_local_only) -{ - int res = -1; - - DEBUG("gathering candidates\n"); - - /* currently this implementation supports only addresses as source address - * candidates assigned to this interface. Thus we assume all addresses to be - * on interface @p iface */ - (void) dst; - - for (int i = 0; i < GNRC_IPV6_NETIF_ADDR_NUMOF; i++) { - gnrc_ipv6_netif_addr_t *iter = &(iface->addrs[i]); - - DEBUG("Checking address: %s\n", - ipv6_addr_to_str(addr_str, &(iter->addr), sizeof(addr_str))); - - /* "In any case, multicast addresses and the unspecified address MUST NOT - * be included in a candidate set." - */ - if (ipv6_addr_is_multicast(&(iter->addr)) || - ipv6_addr_is_unspecified(&(iter->addr))) { - continue; - } - - /* Check if we only want link local addresses */ - if (link_local_only && !ipv6_addr_is_link_local(&(iter->addr))) { - continue; - } - - /* "For all multicast and link-local destination addresses, the set of - * candidate source addresses MUST only include addresses assigned to - * interfaces belonging to the same link as the outgoing interface." - * - * "For site-local unicast destination addresses, the set of candidate - * source addresses MUST only include addresses assigned to interfaces - * belonging to the same site as the outgoing interface." - * -> we should also be fine, since we're only iterating addresses of - * the sending interface - */ - - /* put all other addresses into the candidate set */ - DEBUG("add to candidate set\n"); - bf_set(candidate_set, i); - res = i; - } - - return res; -} - -ipv6_addr_t *gnrc_ipv6_netif_match_prefix(kernel_pid_t pid, const ipv6_addr_t *prefix) -{ - ipv6_addr_t *res = NULL; - gnrc_ipv6_netif_t *iface = gnrc_ipv6_netif_get(pid); - - mutex_lock(&(iface->mutex)); - - if (_find_by_prefix_unsafe(&res, iface, prefix, NULL) > 0) { - mutex_unlock(&(iface->mutex)); - return res; - } - - mutex_unlock(&(iface->mutex)); - - return NULL; -} - -/** - * @brief Determines the scope of the given address. - * - * @param[in] addr The IPv6 address to check. - * @param[in] maybe_multicast False if @p addr is definitely no multicast - * address, true otherwise. - * - * @return The scope of the address. - * - * @pre address is not loopback or unspecified. - * see http://tools.ietf.org/html/rfc6724#section-4 - */ -static uint8_t _get_scope(const ipv6_addr_t *addr, const bool maybe_multicast) -{ - if (maybe_multicast && ipv6_addr_is_multicast(addr)) { - return (addr->u8[1] & 0x0f); - } - else if (ipv6_addr_is_link_local(addr)) { - return IPV6_ADDR_MCAST_SCP_LINK_LOCAL; - } - else if (ipv6_addr_is_site_local(addr)) { - return IPV6_ADDR_MCAST_SCP_SITE_LOCAL; - } - else { - return IPV6_ADDR_MCAST_SCP_GLOBAL; - } -} - -/** @brief Find the best candidate among the configured addresses - * for a certain destination address according to the 8 rules - * specified in RFC 6734, section 5. - * @see <a href="http://tools.ietf.org/html/rfc6724#section-5"> - * RFC6724, section 5 - * </a> - * - * @param[in] iface The interface for sending. - * @param[in] dst The destination IPv6 address. - * @param[in, out] candidate_set The preselected set of candidate addresses as - * a bitfield. - * - * @pre @p dst is not unspecified. - * - * @return The best matching candidate found on @p iface, may be NULL if none - * is found. - */ -static ipv6_addr_t *_source_address_selection(gnrc_ipv6_netif_t *iface, const ipv6_addr_t *dst, - uint8_t *candidate_set) -{ - /* create temporary set for assigning "points" to candidates wining in the - * corresponding rules. - */ - uint8_t winner_set[GNRC_IPV6_NETIF_ADDR_NUMOF]; - memset(winner_set, 0, GNRC_IPV6_NETIF_ADDR_NUMOF); - - uint8_t max_pts = 0; - - /* _create_candidate_set() assures that `dest` is not unspecified and if - * `dst` is loopback rule 1 will fire anyway. */ - uint8_t dst_scope = _get_scope(dst, true); - DEBUG("finding the best match within the source address candidates\n"); - - for (int i = 0; i < GNRC_IPV6_NETIF_ADDR_NUMOF; i++) { - gnrc_ipv6_netif_addr_t *iter = &(iface->addrs[i]); - DEBUG("Checking address: %s\n", - ipv6_addr_to_str(addr_str, &(iter->addr), sizeof(addr_str))); - /* entries which are not part of the candidate set can be ignored */ - if (!(bf_isset(candidate_set, i))) { - DEBUG("Not part of the candidate set - skipping\n"); - continue; - } - - /* Rule 1: if we have an address configured that equals the destination - * use this one as source */ - if (ipv6_addr_equal(&(iter->addr), dst)) { - DEBUG("Ease one - rule 1\n"); - return &(iter->addr); - } - - /* Rule 2: Prefer appropriate scope. */ - /* both link local */ - uint8_t candidate_scope = _get_scope(&(iter->addr), false); - if (candidate_scope == dst_scope) { - DEBUG("winner for rule 2 (same scope) found\n"); - winner_set[i] += RULE_2A_PTS; - if (winner_set[i] > max_pts) { - max_pts = RULE_2A_PTS; - } - } - else if (candidate_scope < dst_scope) { - DEBUG("winner for rule 2 (smaller scope) found\n"); - winner_set[i] += RULE_2B_PTS; - if (winner_set[i] > max_pts) { - max_pts = winner_set[i]; - } - } - - /* Rule 3: Avoid deprecated addresses. */ - if (iter->preferred > 0) { - DEBUG("winner for rule 3 found\n"); - winner_set[i] += RULE_3_PTS; - if (winner_set[i] > max_pts) { - max_pts = winner_set[i]; - } - } - - /* Rule 4: Prefer home addresses. - * Does not apply, gnrc does not support Mobile IP. - * TODO: update as soon as gnrc supports Mobile IP - */ - - /* Rule 5: Prefer outgoing interface. - * RFC 6724 says: - * "It is RECOMMENDED that the candidate source addresses be the set of - * unicast addresses assigned to the interface that will be used to - * send to the destination (the "outgoing" interface). On routers, - * the candidate set MAY include unicast addresses assigned to any - * interface that forwards packets, subject to the restrictions - * described below." - * Currently this implementation uses ALWAYS source addresses assigned - * to the outgoing interface. Hence, Rule 5 is always fulfilled. - */ - - /* Rule 6: Prefer matching label. - * Flow labels are currently not supported by gnrc. - * TODO: update as soon as gnrc supports flow labels - */ - - /* Rule 7: Prefer temporary addresses. - * Temporary addresses are currently not supported by gnrc. - * TODO: update as soon as gnrc supports temporary addresses - */ - } - - /* reset candidate set to mark winners */ - memset(candidate_set, 0, (GNRC_IPV6_NETIF_ADDR_NUMOF + 7) / 8); - /* check if we have a clear winner */ - /* collect candidates with maximum points */ - for (int i = 0; i < GNRC_IPV6_NETIF_ADDR_NUMOF; i++) { - if (winner_set[i] == max_pts) { - bf_set(candidate_set, i); - } - } - - /* otherwise apply rule 8: Use longest matching prefix. */ - ipv6_addr_t *res = NULL; - _find_by_prefix_unsafe(&res, iface, dst, candidate_set); - return res; -} - -ipv6_addr_t *gnrc_ipv6_netif_find_best_src_addr(kernel_pid_t pid, const ipv6_addr_t *dst, bool ll_only) -{ - gnrc_ipv6_netif_t *iface = gnrc_ipv6_netif_get(pid); - ipv6_addr_t *best_src = NULL; - mutex_lock(&(iface->mutex)); - BITFIELD(candidate_set, GNRC_IPV6_NETIF_ADDR_NUMOF); - memset(candidate_set, 0, sizeof(candidate_set)); - - int first_candidate = _create_candidate_set(iface, dst, candidate_set, ll_only); - if (first_candidate >= 0) { - best_src = _source_address_selection(iface, dst, candidate_set); - if (best_src == NULL) { - best_src = &(iface->addrs[first_candidate].addr); - } - } - mutex_unlock(&(iface->mutex)); - - return best_src; -} - -void gnrc_ipv6_netif_init_by_dev(void) -{ - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - size_t ifnum = gnrc_netif_get(ifs); -#ifdef MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER - /* cppcheck-suppress unreadVariable - * (reason: cppcheck bug. abr_init is read in if below) */ - bool abr_init = false; -#endif - - for (size_t i = 0; i < ifnum; i++) { - ipv6_addr_t addr; - eui64_t iid; - uint16_t tmp; - gnrc_ipv6_netif_t *ipv6_if = gnrc_ipv6_netif_get(ifs[i]); - - if (ipv6_if == NULL) { - continue; - } - - mutex_lock(&ipv6_if->mutex); - -#ifdef MODULE_GNRC_SIXLOWPAN - gnrc_nettype_t if_type = GNRC_NETTYPE_UNDEF; - - if ((gnrc_netapi_get(ifs[i], NETOPT_PROTO, 0, &if_type, - sizeof(if_type)) != -ENOTSUP) && - (if_type == GNRC_NETTYPE_SIXLOWPAN)) { - uint16_t src_len = 8; - uint16_t max_frag_size = UINT16_MAX; - - DEBUG("ipv6 netif: Set 6LoWPAN flag\n"); - ipv6_ifs[i].flags |= GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN; - - /* the router flag must be set early here, because otherwise - * _add_addr_to_entry() wouldn't set the solicited node address. - * However, addresses have to be configured before calling - * gnrc_ipv6_netif_set_router(). - */ -#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER - DEBUG("ipv6 netif: Set router flag\n"); - ipv6_ifs[i].flags |= GNRC_IPV6_NETIF_FLAGS_ROUTER; -#endif - /* use EUI-64 (8-byte address) for IID generation and for sending - * packets */ - gnrc_netapi_set(ifs[i], NETOPT_SRC_LEN, 0, &src_len, - sizeof(src_len)); /* don't care for result */ - - if (gnrc_netapi_get(ifs[i], NETOPT_MAX_PACKET_SIZE, - 0, &max_frag_size, sizeof(max_frag_size)) < 0) { - /* if error we assume it works */ - DEBUG("ipv6 netif: Can not get max packet size from interface %" - PRIkernel_pid "\n", ifs[i]); - } - - gnrc_sixlowpan_netif_add(ifs[i], max_frag_size); - } -#endif - - /* set link-local address */ - if (gnrc_netapi_get(ifs[i], NETOPT_IPV6_IID, 0, &iid, - sizeof(eui64_t)) >= 0) { - ipv6_addr_set_aiid(&addr, iid.uint8); - ipv6_addr_set_link_local_prefix(&addr); - _add_addr_to_entry(ipv6_if, &addr, 64, 0); - - } -#ifdef GNRC_IPV6_STATIC_LLADDR - /* parse addr from string and explicitely set a link lokal prefix - * if ifnum > 1 each interface will get its own link local address - * with GNRC_IPV6_STATIC_LLADDR + i - */ - char lladdr_str[] = GNRC_IPV6_STATIC_LLADDR; - ipv6_addr_t lladdr; - if(ipv6_addr_from_str(&lladdr, lladdr_str) != NULL) { - lladdr.u8[15] += i; - assert(ipv6_addr_is_link_local(&lladdr)); - _add_addr_to_entry(ipv6_if, &lladdr, 64, 0); - } -#endif - /* set link MTU */ - if ((gnrc_netapi_get(ifs[i], NETOPT_MAX_PACKET_SIZE, 0, &tmp, - sizeof(uint16_t)) >= 0)) { - if (tmp >= IPV6_MIN_MTU) { - ipv6_if->mtu = tmp; - } - /* otherwise leave at GNRC_IPV6_NETIF_DEFAULT_MTU as initialized in - * gnrc_ipv6_netif_add() */ - } - - if (gnrc_netapi_get(ifs[i], NETOPT_IS_WIRED, 0, NULL, 0) > 0) { - ipv6_if->flags |= GNRC_IPV6_NETIF_FLAGS_IS_WIRED; - } - else { - ipv6_if->flags &= ~GNRC_IPV6_NETIF_FLAGS_IS_WIRED; - } - - mutex_unlock(&ipv6_if->mutex); -#if (defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER)) - gnrc_ipv6_netif_set_router(ipv6_if, true); -#endif -#ifdef MODULE_GNRC_SIXLOWPAN_ND - if (ipv6_if->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) { -#ifdef MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER - /* first interface wins */ - if (!abr_init) { - gnrc_sixlowpan_nd_router_abr_create(&addr, 0); - /* XXX should be set to true if there ever is an hard-coded - * prefix set */ - gnrc_ipv6_netif_set_rtr_adv(ipv6_if, false); - abr_init = true; - } -#endif - gnrc_sixlowpan_nd_init(ipv6_if); - continue; /* skip gnrc_ndp_host_init() */ - } -#endif -#ifdef MODULE_GNRC_NDP_HOST - /* start periodic router solicitations */ - gnrc_ndp_host_init(ipv6_if); -#endif - } -} - -#ifdef MODULE_NETSTATS_IPV6 -netstats_t *gnrc_ipv6_netif_get_stats(kernel_pid_t pid) -{ - gnrc_ipv6_netif_t *iface = gnrc_ipv6_netif_get(pid); - return &(iface->stats); -} -#endif - -/** - * @} - */ diff --git a/sys/net/gnrc/network_layer/ndp/Makefile b/sys/net/gnrc/network_layer/ndp/Makefile deleted file mode 100644 index c4c1861f0b63827bf91b7bebe0b6f0ada7acfeaa..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/network_layer/ndp/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -MODULE = gnrc_ndp - -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/gnrc/network_layer/ndp/gnrc_ndp.c b/sys/net/gnrc/network_layer/ndp/gnrc_ndp.c deleted file mode 100644 index dd1845375e6777af4318eb65cf7d4da8494a92c9..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/network_layer/ndp/gnrc_ndp.c +++ /dev/null @@ -1,900 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser General - * Public License v2.1. See the file LICENSE in the top level directory for - * more details. - */ - -/** - * @ingroup net_gnrc_ndp - * @{ - * - * @file - * - * @author Martine Lenders <mlenders@inf.fu-berlin.de> - */ - -#include <errno.h> -#include <string.h> - -#include "byteorder.h" -#include "net/fib.h" -#include "net/ieee802154.h" -#include "net/ipv6/ext/rh.h" -#include "net/gnrc/icmpv6.h" -#include "net/gnrc/ipv6.h" -#include "net/gnrc/sixlowpan/nd.h" -#include "net/gnrc.h" -#include "net/sixlowpan/nd.h" -#include "random.h" -#include "utlist.h" -#include "thread.h" -#include "xtimer.h" - -#include "net/gnrc/ndp/internal.h" - -#include "net/gnrc/ndp.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#if ENABLE_DEBUG -/* For PRIu8 etc. */ -#include <inttypes.h> - -static char addr_str[IPV6_ADDR_MAX_STR_LEN]; -#endif - -/* sets an entry to stale if its l2addr differs from the given one or creates it stale if it - * does not exist */ -static void _stale_nc(kernel_pid_t iface, ipv6_addr_t *ipaddr, uint8_t *l2addr, - int l2addr_len) -{ - if (l2addr_len != -ENOTSUP) { - gnrc_ipv6_nc_t *nc_entry = gnrc_ipv6_nc_get(iface, ipaddr); - if (nc_entry == NULL) { - gnrc_ipv6_nc_add(iface, ipaddr, l2addr, (uint16_t)l2addr_len, - GNRC_IPV6_NC_STATE_STALE); - } -#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER - /* unreachable set in gnrc_ndp_retrans_nbr_sol() will just be staled */ - else if (gnrc_ipv6_nc_get_state(nc_entry) == GNRC_IPV6_NC_STATE_UNREACHABLE) { - gnrc_ndp_internal_set_state(nc_entry, GNRC_IPV6_NC_STATE_STALE); - } -#endif - else if (((uint16_t)l2addr_len != nc_entry->l2_addr_len) || - (memcmp(l2addr, nc_entry->l2_addr, l2addr_len) != 0)) { - /* if entry exists but l2 address differs: set */ - nc_entry->l2_addr_len = (uint16_t)l2addr_len; - memcpy(nc_entry->l2_addr, l2addr, l2addr_len); - gnrc_ndp_internal_set_state(nc_entry, GNRC_IPV6_NC_STATE_STALE); - } - } -} - -void gnrc_ndp_nbr_sol_handle(kernel_pid_t iface, gnrc_pktsnip_t *pkt, - ipv6_hdr_t *ipv6, ndp_nbr_sol_t *nbr_sol, - size_t icmpv6_size) -{ - uint16_t opt_offset = 0; - uint8_t l2src[GNRC_IPV6_NC_L2_ADDR_MAX]; - uint8_t *buf = ((uint8_t *)nbr_sol) + sizeof(ndp_nbr_sol_t); - ipv6_addr_t *tgt, nbr_adv_dst; - gnrc_pktsnip_t *nbr_adv_opts = NULL; -#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER - ndp_opt_t *sl2a_opt = NULL; - sixlowpan_nd_opt_ar_t *ar_opt = NULL; -#endif - int sicmpv6_size = (int)icmpv6_size, l2src_len = 0; - DEBUG("ndp: received neighbor solicitation (src: %s, ", - ipv6_addr_to_str(addr_str, &ipv6->src, sizeof(addr_str))); - DEBUG("dst: %s, ", - ipv6_addr_to_str(addr_str, &ipv6->dst, sizeof(addr_str))); - DEBUG("tgt: %s)\n", - ipv6_addr_to_str(addr_str, &nbr_sol->tgt, sizeof(addr_str))); - /* check validity */ - if ((ipv6->hl != 255) || (nbr_sol->code != 0) || - (icmpv6_size < sizeof(ndp_nbr_sol_t)) || - ipv6_addr_is_multicast(&nbr_sol->tgt) || - (ipv6_addr_is_unspecified(&ipv6->src) && - ipv6_addr_is_solicited_node(&ipv6->dst))) { - DEBUG("ndp: neighbor solicitation was invalid.\n"); - /* icmpv6 releases */ - return; - } - if ((tgt = gnrc_ipv6_netif_find_addr(iface, &nbr_sol->tgt)) == NULL) { - DEBUG("ndp: Target address is not to interface %" PRIkernel_pid "\n", - iface); - /* icmpv6 releases */ - return; - } - sicmpv6_size -= sizeof(ndp_nbr_sol_t); - while (sicmpv6_size > 0) { - ndp_opt_t *opt = (ndp_opt_t *)(buf + opt_offset); - switch (opt->type) { - case NDP_OPT_SL2A: - if ((l2src_len = gnrc_ndp_internal_sl2a_opt_handle(pkt, ipv6, nbr_sol->type, opt, - l2src)) < 0) { - /* -ENOTSUP can not happen, since the function only returns this for invalid - * message types containing the SL2A. Neighbor solicitations are not an - * invalid message type for SL2A. According to that, we don't need to watch - * out for that here, but regardless, the source link-layer address option - * is invalid. */ - return; - } -#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER - sl2a_opt = opt; - break; - case NDP_OPT_AR: - /* actually handling at the end of the function (see below) */ - ar_opt = (sixlowpan_nd_opt_ar_t *)opt; -#endif - break; - default: - /* silently discard all other options */ - break; - } - opt_offset += (opt->len * 8); - sicmpv6_size -= (opt->len * 8); - -#if ENABLE_DEBUG - if (sicmpv6_size < 0) { - DEBUG("ndp: Option parsing out of sync.\n"); - } -#endif - } -#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER - gnrc_ipv6_netif_t *ipv6_iface = gnrc_ipv6_netif_get(iface); - assert(ipv6_iface != NULL); - if ((sl2a_opt != NULL) && (ar_opt != NULL) && - (ipv6_iface->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) && - (ipv6_iface->flags & GNRC_IPV6_NETIF_FLAGS_ROUTER)) { - uint8_t status = gnrc_sixlowpan_nd_opt_ar_handle(iface, ipv6, - nbr_sol->type, - &ipv6->src, ar_opt, - l2src, l2src_len); - /* check for multihop DAD return */ - nbr_adv_opts = gnrc_sixlowpan_nd_opt_ar_build(status, GNRC_SIXLOWPAN_ND_AR_LTIME, - &ar_opt->eui64, NULL); - if (status == 0) { - memcpy(&nbr_adv_dst, &ipv6->src, sizeof(ipv6_addr_t)); - } - else { - /* see https://tools.ietf.org/html/rfc6775#section-6.5.2 */ - eui64_t iid; - ieee802154_get_iid(&iid, ar_opt->eui64.uint8, sizeof(eui64_t)); - ipv6_addr_set_aiid(&nbr_adv_dst, iid.uint8); - ipv6_addr_set_link_local_prefix(&nbr_adv_dst); - } - } - else { /* gnrc_sixlowpan_nd_opt_ar_handle updates neighbor cache */ - _stale_nc(iface, &ipv6->src, l2src, l2src_len); - memcpy(&nbr_adv_dst, &ipv6->src, sizeof(ipv6_addr_t)); - } -#else - _stale_nc(iface, &ipv6->src, l2src, l2src_len); - memcpy(&nbr_adv_dst, &ipv6->src, sizeof(ipv6_addr_t)); -#endif - gnrc_ndp_internal_send_nbr_adv(iface, tgt, &nbr_adv_dst, ipv6_addr_is_multicast(&ipv6->dst), - nbr_adv_opts); -} - -static inline bool _pkt_has_l2addr(gnrc_netif_hdr_t *netif_hdr) -{ - return (netif_hdr != NULL) && (netif_hdr->src_l2addr_len != 0) && - (netif_hdr->dst_l2addr_len != 0); -} - -void gnrc_ndp_nbr_adv_handle(kernel_pid_t iface, gnrc_pktsnip_t *pkt, - ipv6_hdr_t *ipv6, ndp_nbr_adv_t *nbr_adv, - size_t icmpv6_size) -{ - uint16_t opt_offset = 0; - uint8_t *buf = ((uint8_t *)nbr_adv) + sizeof(ndp_nbr_adv_t); - int l2tgt_len = 0; - uint8_t l2tgt[GNRC_IPV6_NC_L2_ADDR_MAX]; - int sicmpv6_size = (int)icmpv6_size; - gnrc_ipv6_nc_t *nc_entry = gnrc_ipv6_nc_get(iface, &nbr_adv->tgt); - gnrc_pktsnip_t *netif; - gnrc_netif_hdr_t *netif_hdr = NULL; - - DEBUG("ndp: received neighbor advertisement (src: %s, ", - ipv6_addr_to_str(addr_str, &ipv6->src, sizeof(addr_str))); - DEBUG("dst: %s, ", - ipv6_addr_to_str(addr_str, &ipv6->dst, sizeof(addr_str))); - DEBUG("tgt: %s)\n", - ipv6_addr_to_str(addr_str, &nbr_adv->tgt, sizeof(addr_str))); - - /* check validity */ - if ((ipv6->hl != 255) || (nbr_adv->code != 0) || - (icmpv6_size < sizeof(ndp_nbr_adv_t)) || - ipv6_addr_is_multicast(&nbr_adv->tgt)) { - DEBUG("ndp: neighbor advertisement was invalid.\n"); - /* icmpv6 releases */ - return; - } - - if (nc_entry == NULL) { - /* see https://tools.ietf.org/html/rfc4861#section-7.2.5 */ - DEBUG("ndp: no neighbor cache entry found for advertisement's target\n"); - /* icmpv6 releases */ - return; - } - - sicmpv6_size -= sizeof(ndp_nbr_adv_t); - - while (sicmpv6_size > 0) { - ndp_opt_t *opt = (ndp_opt_t *)(buf + opt_offset); - - switch (opt->type) { - case NDP_OPT_TL2A: - if ((l2tgt_len = gnrc_ndp_internal_tl2a_opt_handle(pkt, ipv6, nbr_adv->type, opt, l2tgt)) < 0) { - /* invalid target link-layer address option */ - return; - } - break; -#ifdef MODULE_GNRC_SIXLOWPAN_ND - case NDP_OPT_AR: - /* address registration option is always ignored when invalid */ - gnrc_sixlowpan_nd_opt_ar_handle(iface, ipv6, nbr_adv->type, - &nbr_adv->tgt, - (sixlowpan_nd_opt_ar_t *)opt, - NULL, 0); - break; -#endif - default: - /* silently discard all other options */ - break; - } - - opt_offset += (opt->len * 8); - sicmpv6_size -= (opt->len * 8); - -#if ENABLE_DEBUG - if (sicmpv6_size < 0) { - DEBUG("ndp: Option parsing out of sync.\n"); - } -#endif - } - - netif = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_NETIF); - - if (netif != NULL) { - netif_hdr = netif->data; - } - - if (l2tgt_len != -ENOTSUP) { -#ifdef MODULE_GNRC_SIXLOWPAN_ND - /* check if entry wasn't removed by ARO, ideally there should not be any TL2A in here */ - nc_entry = gnrc_ipv6_nc_get(iface, &nbr_adv->tgt); - if (nc_entry == NULL) { - return; - } -#endif - if (gnrc_ipv6_nc_get_state(nc_entry) == GNRC_IPV6_NC_STATE_INCOMPLETE) { - if (_pkt_has_l2addr(netif_hdr) && (l2tgt_len == 0)) { - /* link-layer has addresses, but no TLLAO supplied: discard silently - * (see https://tools.ietf.org/html/rfc4861#section-7.2.5) */ - return; - } - - nc_entry->iface = iface; - nc_entry->l2_addr_len = l2tgt_len; - memcpy(nc_entry->l2_addr, l2tgt, l2tgt_len); - - if (nbr_adv->flags & NDP_NBR_ADV_FLAGS_S) { - gnrc_ndp_internal_set_state(nc_entry, GNRC_IPV6_NC_STATE_REACHABLE); - } - else { - gnrc_ndp_internal_set_state(nc_entry, GNRC_IPV6_NC_STATE_STALE); - } - - if (nbr_adv->flags & NDP_NBR_ADV_FLAGS_R) { - nc_entry->flags |= GNRC_IPV6_NC_IS_ROUTER; - } - else { - nc_entry->flags &= ~GNRC_IPV6_NC_IS_ROUTER; - /* TODO: update state of neighbor as router in FIB? */ - } -#ifdef MODULE_GNRC_NDP_NODE - gnrc_pktqueue_t *queued_pkt; - while ((queued_pkt = gnrc_pktqueue_remove_head(&nc_entry->pkts)) != NULL) { - if (gnrc_netapi_send(gnrc_ipv6_pid, queued_pkt->pkt) < 1) { - DEBUG("ndp: unable to send queued packet\n"); - gnrc_pktbuf_release(queued_pkt->pkt); - } - queued_pkt->pkt = NULL; - } -#endif - } - else { - /* first or-term: no link-layer, but nc_entry has l2addr, - * second or-term: different l2addr cached */ - bool l2tgt_changed = false; - - if ((!_pkt_has_l2addr(netif_hdr)) && (l2tgt_len == 0)) { - /* there was previously a L2 address registered */ - l2tgt_changed = (nc_entry->l2_addr_len != 0); - } - /* link-layer has addresses and TLLAO with different address */ - else if (_pkt_has_l2addr(netif_hdr) && (l2tgt_len != 0)) { - l2tgt_changed = (!(l2tgt_len == nc_entry->l2_addr_len)) && - (memcmp(nc_entry->l2_addr, l2tgt, l2tgt_len) == 0); - } - - if ((nbr_adv->flags & NDP_NBR_ADV_FLAGS_O) || !l2tgt_changed || - (l2tgt_len == 0)) { - if (l2tgt_len != 0) { - nc_entry->iface = iface; - nc_entry->l2_addr_len = l2tgt_len; - memcpy(nc_entry->l2_addr, l2tgt, l2tgt_len); - } - - if (nbr_adv->flags & NDP_NBR_ADV_FLAGS_S) { - gnrc_ndp_internal_set_state(nc_entry, GNRC_IPV6_NC_STATE_REACHABLE); - } - else if (l2tgt_changed) { - gnrc_ndp_internal_set_state(nc_entry, GNRC_IPV6_NC_STATE_STALE); - } - - if (nbr_adv->flags & NDP_NBR_ADV_FLAGS_R) { - nc_entry->flags |= GNRC_IPV6_NC_IS_ROUTER; - } - else { - nc_entry->flags &= ~GNRC_IPV6_NC_IS_ROUTER; - /* TODO: update state of neighbor as router in FIB? */ - } - } - else if (l2tgt_changed && - gnrc_ipv6_nc_get_state(nc_entry) == GNRC_IPV6_NC_STATE_REACHABLE) { - gnrc_ndp_internal_set_state(nc_entry, GNRC_IPV6_NC_STATE_STALE); - } - } - } - - return; -} - -#if (defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER)) -void gnrc_ndp_rtr_sol_handle(kernel_pid_t iface, gnrc_pktsnip_t *pkt, - ipv6_hdr_t *ipv6, ndp_rtr_sol_t *rtr_sol, - size_t icmpv6_size) -{ - gnrc_ipv6_netif_t *if_entry = gnrc_ipv6_netif_get(iface); - - if (if_entry->flags & GNRC_IPV6_NETIF_FLAGS_ROUTER) { - gnrc_ipv6_nc_t *nc_entry; - int sicmpv6_size = (int)icmpv6_size, l2src_len = 0; - uint8_t l2src[GNRC_IPV6_NC_L2_ADDR_MAX]; - uint16_t opt_offset = 0; - uint8_t *buf = (uint8_t *)(rtr_sol + 1); - /* check validity */ - if ((ipv6->hl != 255) || (rtr_sol->code != 0) || - (icmpv6_size < sizeof(ndp_rtr_sol_t))) { - DEBUG("ndp: router solicitation was invalid\n"); - return; - } - sicmpv6_size -= sizeof(ndp_rtr_sol_t); - while (sicmpv6_size > 0) { - ndp_opt_t *opt = (ndp_opt_t *)(buf + opt_offset); - - switch (opt->type) { - case NDP_OPT_SL2A: - l2src_len = gnrc_ndp_internal_sl2a_opt_handle(pkt, ipv6, - rtr_sol->type, - opt, l2src); - if (l2src_len < 0) { - /* -ENOTSUP can not happen */ - /* invalid source link-layer address option */ - return; - } - _stale_nc(iface, &ipv6->src, l2src, l2src_len); - break; - - default: - /* silently discard all other options */ - break; - } - - opt_offset += (opt->len * 8); - sicmpv6_size -= (opt->len * 8); - -#if ENABLE_DEBUG - if (sicmpv6_size < 0) { - DEBUG("ndp: Option parsing out of sync.\n"); - } -#endif - } - - /* send delayed */ - if (if_entry->flags & GNRC_IPV6_NETIF_FLAGS_RTR_ADV) { - uint32_t delay; - uint32_t ms = GNRC_NDP_MAX_RTR_ADV_DELAY; -#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER - if (if_entry->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) { - ms = GNRC_SIXLOWPAN_ND_MAX_RTR_ADV_DELAY; - } -#endif - delay = random_uint32_range(0, ms); - xtimer_remove(&if_entry->rtr_adv_timer); -#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER - /* in case of a 6LBR we have to check if the interface is actually - * the 6lo interface */ - if (if_entry->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) { - gnrc_ipv6_nc_t *nc_entry = gnrc_ipv6_nc_get(iface, &ipv6->src); - if (nc_entry != NULL) { - if_entry->rtr_adv_msg.type = GNRC_NDP_MSG_RTR_ADV_SIXLOWPAN_DELAY; - if_entry->rtr_adv_msg.content.ptr = nc_entry; - xtimer_set_msg(&if_entry->rtr_adv_timer, delay, &if_entry->rtr_adv_msg, - gnrc_ipv6_pid); - } - } -#elif defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER) - if (ipv6_addr_is_unspecified(&ipv6->src)) { - /* either multicast, if source unspecified */ - if_entry->rtr_adv_msg.type = GNRC_NDP_MSG_RTR_ADV_RETRANS; - if_entry->rtr_adv_msg.content.ptr = if_entry; - xtimer_set_msg(&if_entry->rtr_adv_timer, delay, &if_entry->rtr_adv_msg, - gnrc_ipv6_pid); - } - else { - /* or unicast, if source is known */ - /* XXX: can't just use GNRC_NETAPI_MSG_TYPE_SND, since the next retransmission - * must also be set. */ - nc_entry = gnrc_ipv6_nc_get(iface, &ipv6->src); - if (nc_entry) { - xtimer_set_msg(&nc_entry->rtr_adv_timer, delay, &nc_entry->rtr_adv_msg, - gnrc_ipv6_pid); - } - } -#endif - } - nc_entry = gnrc_ipv6_nc_get(iface, &ipv6->src); - if (nc_entry != NULL) { - /* unset isRouter flag - * (https://tools.ietf.org/html/rfc4861#section-6.2.6) */ - nc_entry->flags &= ~GNRC_IPV6_NC_IS_ROUTER; - } - } - /* otherwise ignore silently */ -} -#endif - -static inline void _set_reach_time(gnrc_ipv6_netif_t *if_entry, uint32_t mean) -{ - uint32_t reach_time = random_uint32_range(GNRC_NDP_MIN_RAND, GNRC_NDP_MAX_RAND); - - if_entry->reach_time_base = mean; - /* to avoid floating point number computation and have higher value entropy, the - * boundaries for the random value are multiplied by 10 and we need to account for that */ - reach_time = (reach_time * if_entry->reach_time_base) / 10; - if_entry->reach_time = reach_time; -} - -void gnrc_ndp_rtr_adv_handle(kernel_pid_t iface, gnrc_pktsnip_t *pkt, ipv6_hdr_t *ipv6, - ndp_rtr_adv_t *rtr_adv, size_t icmpv6_size) -{ - uint8_t *buf = (uint8_t *)(rtr_adv + 1); - gnrc_ipv6_nc_t *nc_entry = NULL; - gnrc_ipv6_netif_t *if_entry = gnrc_ipv6_netif_get(iface); - uint8_t l2src[GNRC_IPV6_NC_L2_ADDR_MAX]; -#ifdef MODULE_GNRC_SIXLOWPAN_ND - uint32_t next_rtr_sol = 0; -#endif - int sicmpv6_size = (int)icmpv6_size, l2src_len = 0; - uint16_t opt_offset = 0; - - if (!ipv6_addr_is_link_local(&ipv6->src) || - ipv6_addr_is_multicast(&ipv6->src) || - (ipv6->hl != 255) || (rtr_adv->code != 0) || - (icmpv6_size < sizeof(ndp_rtr_adv_t))) { - DEBUG("ndp: router advertisement was invalid\n"); - /* icmpv6 releases */ - return; - } - /* get source from default router list */ - nc_entry = gnrc_ipv6_nc_get(iface, &ipv6->src); - if (nc_entry == NULL) { /* not in default router list */ - /* create default router list entry */ - nc_entry = gnrc_ipv6_nc_add(iface, &ipv6->src, NULL, 0, - GNRC_IPV6_NC_STATE_STALE | GNRC_IPV6_NC_IS_ROUTER); - if (nc_entry == NULL) { - DEBUG("ndp: error on default router list entry creation\n"); - return; - } - } - else if ((nc_entry->flags & GNRC_IPV6_NC_IS_ROUTER) && (byteorder_ntohs(rtr_adv->ltime) == 0)) { - nc_entry->flags &= ~GNRC_IPV6_NC_IS_ROUTER; - } - else { - nc_entry->flags |= GNRC_IPV6_NC_IS_ROUTER; - } - /* set router life timer */ - if (rtr_adv->ltime.u16 != 0) { - uint16_t ltime = byteorder_ntohs(rtr_adv->ltime); -#ifdef MODULE_GNRC_SIXLOWPAN_ND - next_rtr_sol = ltime; -#endif - xtimer_set_msg(&nc_entry->rtr_timeout, (ltime * US_PER_SEC), - &nc_entry->rtr_timeout_msg, thread_getpid()); - } - /* set current hop limit from message if available */ - if (rtr_adv->cur_hl != 0) { - if_entry->cur_hl = rtr_adv->cur_hl; - } - /* set flags from message */ - if_entry->flags &= ~GNRC_IPV6_NETIF_FLAGS_RTR_ADV_MASK; - if_entry->flags |= (rtr_adv->flags << GNRC_IPV6_NETIF_FLAGS_RTR_ADV_POS) & - GNRC_IPV6_NETIF_FLAGS_RTR_ADV_MASK; - /* set reachable time from message if it is not the same as the random base - * value */ - if ((rtr_adv->reach_time.u32 != 0) && - (if_entry->reach_time_base != byteorder_ntohl(rtr_adv->reach_time))) { - _set_reach_time(if_entry, byteorder_ntohl(rtr_adv->reach_time)); - } - /* set retransmission timer from message */ - if (rtr_adv->retrans_timer.u32 != 0) { - if_entry->retrans_timer = byteorder_ntohl(rtr_adv->retrans_timer); - } - mutex_unlock(&if_entry->mutex); - sicmpv6_size -= sizeof(ndp_rtr_adv_t); - /* parse options */ - while (sicmpv6_size > 0) { - ndp_opt_t *opt = (ndp_opt_t *)(buf + opt_offset); - switch (opt->type) { - case NDP_OPT_SL2A: - if ((l2src_len = gnrc_ndp_internal_sl2a_opt_handle(pkt, ipv6, rtr_adv->type, opt, - l2src)) < 0) { - /* -ENOTSUP can not happen */ - /* invalid source link-layer address option */ - return; - } - break; - case NDP_OPT_MTU: - if (!gnrc_ndp_internal_mtu_opt_handle(iface, rtr_adv->type, (ndp_opt_mtu_t *)opt)) { - /* invalid MTU option */ - return; - } - break; - case NDP_OPT_PI: - if (!gnrc_ndp_internal_pi_opt_handle(iface, rtr_adv->type, (ndp_opt_pi_t *)opt)) { - /* invalid prefix information option */ - return; - } -#ifdef MODULE_GNRC_SIXLOWPAN_ND - uint32_t valid_ltime = byteorder_ntohl(((ndp_opt_pi_t *)opt)->valid_ltime); - if ((valid_ltime != 0) && (valid_ltime < next_rtr_sol)) { - next_rtr_sol = valid_ltime; - } -#endif - break; -#ifdef MODULE_GNRC_SIXLOWPAN_ND - case NDP_OPT_6CTX: - if (!gnrc_sixlowpan_nd_opt_6ctx_handle(rtr_adv->type, - (sixlowpan_nd_opt_6ctx_t *)opt)) { - /* invalid 6LoWPAN context option */ - return; - } - uint16_t ltime = byteorder_ntohs(((sixlowpan_nd_opt_6ctx_t *)opt)->ltime); - if ((ltime != 0) && (ltime < (next_rtr_sol / 60))) { - next_rtr_sol = ltime * 60; - } - - break; -#endif -#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER - case NDP_OPT_ABR: - gnrc_sixlowpan_nd_opt_abr_handle(iface, rtr_adv, icmpv6_size, - (sixlowpan_nd_opt_abr_t *)opt); - break; -#endif - } - - opt_offset += (opt->len * 8); - sicmpv6_size -= (opt->len * 8); - -#if ENABLE_DEBUG - if (sicmpv6_size < 0) { - DEBUG("ndp: Option parsing out of sync.\n"); - } -#endif - } -#if ENABLE_DEBUG && defined(MODULE_GNRC_SIXLOWPAN_ND) - if ((if_entry->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) && (l2src_len <= 0)) { - DEBUG("ndp: Router advertisement did not contain any source address information\n"); - } -#endif - _stale_nc(iface, &ipv6->src, l2src, l2src_len); - /* stop multicast router solicitation retransmission timer */ - xtimer_remove(&if_entry->rtr_sol_timer); -#ifdef MODULE_GNRC_SIXLOWPAN_ND - if (if_entry->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) { - /* 3/4 of the time should be "well before" enough the respective timeout - * not to run out; see https://tools.ietf.org/html/rfc6775#section-5.4.3 */ - next_rtr_sol *= 3; - next_rtr_sol = (next_rtr_sol > 4) ? (next_rtr_sol >> 2) : 1; - /* according to https://tools.ietf.org/html/rfc6775#section-5.3: - * "In all cases, the RS retransmissions are terminated when an RA is - * received." - * Hence, reset router solicitation counter and reset timer. */ - if_entry->rtr_sol_count = 0; - gnrc_sixlowpan_nd_rtr_sol_reschedule(nc_entry, next_rtr_sol); - gnrc_ndp_internal_send_nbr_sol(nc_entry->iface, NULL, &nc_entry->ipv6_addr, - &nc_entry->ipv6_addr); - if (if_entry->flags & GNRC_IPV6_NETIF_FLAGS_ROUTER) { - gnrc_ipv6_netif_set_rtr_adv(if_entry, true); - } - } -#endif -} - -void gnrc_ndp_retrans_nbr_sol(gnrc_ipv6_nc_t *nc_entry) -{ - if ((gnrc_ipv6_nc_get_state(nc_entry) == GNRC_IPV6_NC_STATE_INCOMPLETE) || - (gnrc_ipv6_nc_get_state(nc_entry) == GNRC_IPV6_NC_STATE_PROBE)) { - if (nc_entry->probes_remaining > 1) { - ipv6_addr_t dst; - - DEBUG("ndp: Retransmit neighbor solicitation for %s\n", - ipv6_addr_to_str(addr_str, &nc_entry->ipv6_addr, sizeof(addr_str))); - - /* retransmit neighbor solicatation */ - if (gnrc_ipv6_nc_get_state(nc_entry) == GNRC_IPV6_NC_STATE_INCOMPLETE) { - ipv6_addr_set_solicited_nodes(&dst, &nc_entry->ipv6_addr); - } - else { - dst.u64[0] = nc_entry->ipv6_addr.u64[0]; - dst.u64[1] = nc_entry->ipv6_addr.u64[1]; - } - - nc_entry->probes_remaining--; - - if (nc_entry->iface == KERNEL_PID_UNDEF) { - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - size_t ifnum = gnrc_netif_get(ifs); - - for (size_t i = 0; i < ifnum; i++) { - gnrc_ndp_internal_send_nbr_sol(ifs[i], NULL, &nc_entry->ipv6_addr, &dst); - } - - gnrc_ndp_internal_reset_nbr_sol_timer(nc_entry, GNRC_NDP_RETRANS_TIMER, - GNRC_NDP_MSG_NBR_SOL_RETRANS, gnrc_ipv6_pid); - } - else { - gnrc_ipv6_netif_t *ipv6_iface = gnrc_ipv6_netif_get(nc_entry->iface); - - gnrc_ndp_internal_send_nbr_sol(nc_entry->iface, NULL, &nc_entry->ipv6_addr, &dst); - - mutex_lock(&ipv6_iface->mutex); - gnrc_ndp_internal_reset_nbr_sol_timer(nc_entry, ipv6_iface->retrans_timer, - GNRC_NDP_MSG_NBR_SOL_RETRANS, gnrc_ipv6_pid); - mutex_unlock(&ipv6_iface->mutex); - } - } - /* cppcheck-suppress knownConditionTrueFalse - * cppcheck bug: probes_remaining is initialized to a value > 1 */ - else if (nc_entry->probes_remaining <= 1) { - - /* For a 6LoWPAN router entries may be set to UNREACHABLE instead - * of removing them, since RFC6775, section 6 - * (https://tools.ietf.org/html/rfc6775#section-6) says: "if NUD on - * the router determines that the host is UNREACHABLE (based on the - * logic in [RFC4861]), the NCE SHOULD NOT be deleted but rather - * retained until the Registration Lifetime expires." However, this - * "SHOULD NOT" is not implemented to circumvent NCEs going into - * UNREACHABLE forever and in order to save some memory in the - * neighbor cache. */ - - DEBUG("ndp: Remove nc entry %s for interface %" PRIkernel_pid "\n", - ipv6_addr_to_str(addr_str, &nc_entry->ipv6_addr, sizeof(addr_str)), - nc_entry->iface); - - gnrc_ipv6_nc_remove(nc_entry->iface, &nc_entry->ipv6_addr); - } - } -} - -void gnrc_ndp_state_timeout(gnrc_ipv6_nc_t *nc_entry) -{ - switch (gnrc_ipv6_nc_get_state(nc_entry)) { - case GNRC_IPV6_NC_STATE_REACHABLE: - gnrc_ndp_internal_set_state(nc_entry, GNRC_IPV6_NC_STATE_STALE); - break; - - case GNRC_IPV6_NC_STATE_DELAY: - gnrc_ndp_internal_set_state(nc_entry, GNRC_IPV6_NC_STATE_PROBE); - break; - - default: - break; - } -} - -void gnrc_ndp_netif_add(gnrc_ipv6_netif_t *iface) -{ - /* set default values */ - mutex_lock(&iface->mutex); - _set_reach_time(iface, GNRC_NDP_REACH_TIME); - iface->retrans_timer = GNRC_NDP_RETRANS_TIMER; - mutex_unlock(&iface->mutex); -} - -void gnrc_ndp_netif_remove(gnrc_ipv6_netif_t *iface) -{ - /* TODO */ - (void) iface; -} - -gnrc_pktsnip_t *gnrc_ndp_nbr_sol_build(ipv6_addr_t *tgt, gnrc_pktsnip_t *options) -{ - gnrc_pktsnip_t *pkt; - - DEBUG("ndp: building neighbor solicitation message\n"); - - if (ipv6_addr_is_multicast(tgt)) { - DEBUG("ndp: tgt must not be multicast\n"); - return NULL; - } - - pkt = gnrc_icmpv6_build(options, ICMPV6_NBR_SOL, 0, sizeof(ndp_nbr_sol_t)); - - if (pkt != NULL) { - ndp_nbr_sol_t *nbr_sol = pkt->data; - nbr_sol->resv.u32 = 0; - nbr_sol->tgt.u64[0].u64 = tgt->u64[0].u64; - nbr_sol->tgt.u64[1].u64 = tgt->u64[1].u64; - } - - return pkt; -} - -gnrc_pktsnip_t *gnrc_ndp_nbr_adv_build(uint8_t flags, ipv6_addr_t *tgt, - gnrc_pktsnip_t *options) -{ - gnrc_pktsnip_t *pkt; - - DEBUG("ndp: building neighbor advertisement message\n"); - - if (ipv6_addr_is_multicast(tgt)) { - DEBUG("ndp: tgt must not be multicast\n"); - return NULL; - } - - pkt = gnrc_icmpv6_build(options, ICMPV6_NBR_ADV, 0, sizeof(ndp_nbr_adv_t)); - - if (pkt != NULL) { - ndp_nbr_adv_t *nbr_adv = pkt->data; - nbr_adv->flags = (flags & NDP_NBR_ADV_FLAGS_MASK); - nbr_adv->resv[0] = nbr_adv->resv[1] = nbr_adv->resv[2] = 0; - nbr_adv->tgt.u64[0].u64 = tgt->u64[0].u64; - nbr_adv->tgt.u64[1].u64 = tgt->u64[1].u64; - } - - return pkt; -} - -gnrc_pktsnip_t *gnrc_ndp_rtr_sol_build(gnrc_pktsnip_t *options) -{ - gnrc_pktsnip_t *pkt; - DEBUG("ndp: building router solicitation message\n"); - pkt = gnrc_icmpv6_build(options, ICMPV6_RTR_SOL, 0, sizeof(ndp_rtr_sol_t)); - if (pkt != NULL) { - ndp_rtr_sol_t *rtr_sol = pkt->data; - rtr_sol->resv.u32 = 0; - } - return pkt; -} - -static inline size_t _ceil8(uint8_t length) -{ - /* NDP options use units of 8 byte for there length field, so round up */ - return (length + 7U) & 0xf8U; -} - -gnrc_pktsnip_t *gnrc_ndp_opt_build(uint8_t type, size_t size, gnrc_pktsnip_t *next) -{ - ndp_opt_t *opt; - gnrc_pktsnip_t *pkt = gnrc_pktbuf_add(next, NULL, _ceil8(size), GNRC_NETTYPE_UNDEF); - - if (pkt == NULL) { - DEBUG("ndp: no space left in packet buffer\n"); - return NULL; - } - - opt = pkt->data; - - opt->type = type; - opt->len = (uint8_t)(pkt->size / 8); - - return pkt; -} - -static inline gnrc_pktsnip_t *_opt_l2a_build(uint8_t type, const uint8_t *l2addr, - uint8_t l2addr_len, gnrc_pktsnip_t *next) -{ - gnrc_pktsnip_t *pkt = gnrc_ndp_opt_build(type, sizeof(ndp_opt_t) + l2addr_len, next); - - if (pkt != NULL) { - ndp_opt_t *l2a_opt = pkt->data; - - memset(l2a_opt + 1, 0, pkt->size - sizeof(ndp_opt_t)); - memcpy(l2a_opt + 1, l2addr, l2addr_len); - } - - return pkt; -} - -gnrc_pktsnip_t *gnrc_ndp_opt_sl2a_build(const uint8_t *l2addr, uint8_t l2addr_len, - gnrc_pktsnip_t *next) -{ - DEBUG("ndp: building source link-layer address option (l2addr: %s)\n", - gnrc_netif_addr_to_str(addr_str, sizeof(addr_str), l2addr, l2addr_len)); - - return _opt_l2a_build(NDP_OPT_SL2A, l2addr, l2addr_len, next); -} - -gnrc_pktsnip_t *gnrc_ndp_opt_tl2a_build(const uint8_t *l2addr, uint8_t l2addr_len, - gnrc_pktsnip_t *next) -{ - DEBUG("ndp: building target link-layer address option (l2addr: %s)\n", - gnrc_netif_addr_to_str(addr_str, sizeof(addr_str), l2addr, l2addr_len)); - - return _opt_l2a_build(NDP_OPT_TL2A, l2addr, l2addr_len, next); -} - -#if (defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER)) -gnrc_pktsnip_t *gnrc_ndp_rtr_adv_build(uint8_t cur_hl, uint8_t flags, - uint16_t ltime, uint32_t reach_time, - uint32_t retrans_timer, gnrc_pktsnip_t *options) -{ - gnrc_pktsnip_t *pkt; - DEBUG("ndp rtr: building router advertisement message\n"); - pkt = gnrc_icmpv6_build(options, ICMPV6_RTR_ADV, 0, sizeof(ndp_rtr_adv_t)); - if (pkt != NULL) { - ndp_rtr_adv_t *rtr_adv = pkt->data; - rtr_adv->cur_hl = cur_hl; - rtr_adv->flags = (flags & NDP_RTR_ADV_FLAGS_MASK); - rtr_adv->ltime = byteorder_htons(ltime); - rtr_adv->reach_time = byteorder_htonl(reach_time); - rtr_adv->retrans_timer = byteorder_htonl(retrans_timer); - } - return pkt; -} - -gnrc_pktsnip_t *gnrc_ndp_opt_pi_build(uint8_t prefix_len, uint8_t flags, - uint32_t valid_ltime, uint32_t pref_ltime, - ipv6_addr_t *prefix, gnrc_pktsnip_t *next) -{ - gnrc_pktsnip_t *pkt = gnrc_ndp_opt_build(NDP_OPT_PI, sizeof(ndp_opt_pi_t), - next); - if (pkt != NULL) { - ndp_opt_pi_t *pi_opt = pkt->data; - pi_opt->prefix_len = prefix_len; - pi_opt->flags = (flags & NDP_OPT_PI_FLAGS_MASK); - pi_opt->valid_ltime = byteorder_htonl(valid_ltime); - pi_opt->pref_ltime = byteorder_htonl(pref_ltime); - pi_opt->resv.u32 = 0; - /* Bits beyond prefix_len MUST be 0 */ - ipv6_addr_set_unspecified(&pi_opt->prefix); - ipv6_addr_init_prefix(&pi_opt->prefix, prefix, prefix_len); - } - return pkt; -} - -gnrc_pktsnip_t *gnrc_ndp_opt_mtu_build(uint32_t mtu, gnrc_pktsnip_t *next) -{ - gnrc_pktsnip_t *pkt = gnrc_ndp_opt_build(NDP_OPT_MTU, sizeof(ndp_opt_mtu_t), - next); - if (pkt != NULL) { - ndp_opt_mtu_t *mtu_opt = pkt->data; - mtu_opt->resv.u16 = 0; - mtu_opt->mtu = byteorder_htonl(mtu); - } - return pkt; -} -#endif - -/** - * @} - */ diff --git a/sys/net/gnrc/network_layer/ndp/host/Makefile b/sys/net/gnrc/network_layer/ndp/host/Makefile deleted file mode 100644 index c3b51fb8dab8ddd6a05215dc421561ee4dd3d572..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/network_layer/ndp/host/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -MODULE = gnrc_ndp_host - -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/gnrc/network_layer/ndp/host/gnrc_ndp_host.c b/sys/net/gnrc/network_layer/ndp/host/gnrc_ndp_host.c deleted file mode 100644 index 433e0f58a91844cafb120e37a7f6456998e2526d..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/network_layer/ndp/host/gnrc_ndp_host.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @{ - * - * @file - */ - -#include <inttypes.h> -#include "random.h" -#include "net/gnrc/ipv6.h" -#include "net/gnrc/ndp.h" -#include "net/gnrc/ndp/internal.h" -#include "xtimer.h" - -#include "net/gnrc/ndp/host.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -static inline void _reschedule_rtr_sol(gnrc_ipv6_netif_t *iface, uint32_t delay) -{ - xtimer_remove(&iface->rtr_sol_timer); - iface->rtr_sol_msg.type = GNRC_NDP_MSG_RTR_SOL_RETRANS; - iface->rtr_sol_msg.content.ptr = iface; - xtimer_set_msg(&iface->rtr_sol_timer, delay, &iface->rtr_sol_msg, gnrc_ipv6_pid); -} - -void gnrc_ndp_host_init(gnrc_ipv6_netif_t *iface) -{ - uint32_t interval = random_uint32_range(0, GNRC_NDP_MAX_RTR_SOL_DELAY * US_PER_SEC); - mutex_lock(&iface->mutex); - iface->rtr_sol_count = GNRC_NDP_MAX_RTR_SOL_NUMOF; - DEBUG("ndp host: delayed initial router solicitation by %" PRIu32 " usec.\n", interval); - _reschedule_rtr_sol(iface, interval); - mutex_unlock(&iface->mutex); -} - -void gnrc_ndp_host_retrans_rtr_sol(gnrc_ipv6_netif_t *iface) -{ - mutex_lock(&iface->mutex); - if (iface->rtr_sol_count > 1) { /* regard off-by-one error */ - DEBUG("ndp hst: retransmit rtr sol in %d sec\n", GNRC_NDP_MAX_RTR_SOL_INT); - iface->rtr_sol_count--; - _reschedule_rtr_sol(iface, GNRC_NDP_MAX_RTR_SOL_INT * US_PER_SEC); - } - mutex_unlock(&iface->mutex); - gnrc_ndp_internal_send_rtr_sol(iface->pid, NULL); -} - -/** @} */ diff --git a/sys/net/gnrc/network_layer/ndp/internal/Makefile b/sys/net/gnrc/network_layer/ndp/internal/Makefile deleted file mode 100644 index 54bdd221c2a49bc03c1b9c5a38ebca7a4160744f..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/network_layer/ndp/internal/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -MODULE = gnrc_ndp_internal - -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/gnrc/network_layer/ndp/internal/gnrc_ndp_internal.c b/sys/net/gnrc/network_layer/ndp/internal/gnrc_ndp_internal.c deleted file mode 100644 index f46c39ca38866d074331d24ccc7c4f4fa7b3cff3..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/network_layer/ndp/internal/gnrc_ndp_internal.c +++ /dev/null @@ -1,860 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @{ - * - * @file - */ - -#include <stdlib.h> - -#include "net/eui64.h" -#include "net/gnrc/ipv6.h" -#include "net/gnrc/ndp.h" -#include "net/gnrc/sixlowpan/ctx.h" -#include "net/gnrc/sixlowpan/nd.h" -#include "random.h" -#include "xtimer.h" - -#include "net/gnrc/ndp/internal.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#if ENABLE_DEBUG -static char addr_str[IPV6_ADDR_MAX_STR_LEN]; -#endif - -static gnrc_ipv6_nc_t *_last_router = NULL; /* last router chosen as default - * router. Only used if reachability - * is suspect (i. e. incomplete or - * not at all) */ -static gnrc_pktsnip_t *_build_headers(kernel_pid_t iface, gnrc_pktsnip_t *payload, - ipv6_addr_t *dst, ipv6_addr_t *src); -static size_t _get_l2src(kernel_pid_t iface, uint8_t *l2src, size_t l2src_maxlen); - -/** - * @brief Sends @ref GNRC_NETAPI_MSG_TYPE_SND delayed. - * - * @param[in] t Timer for the delay. - * @param[in] msg Msg for the timer. - * @param[in] interval Delay interval. - * @param[in] pkt Packet to send delayed. - */ -static inline void _send_delayed(xtimer_t *t, msg_t *msg, uint32_t interval, gnrc_pktsnip_t *pkt) -{ - xtimer_remove(t); - msg->type = GNRC_NETAPI_MSG_TYPE_SND; - msg->content.ptr = pkt; - xtimer_set_msg(t, interval, msg, gnrc_ipv6_pid); -} - - -ipv6_addr_t *gnrc_ndp_internal_default_router(void) -{ - gnrc_ipv6_nc_t *router = gnrc_ipv6_nc_get_next_router(NULL); - - /* first look if there is any reachable router */ - while (router != NULL) { - if ((gnrc_ipv6_nc_get_state(router) != GNRC_IPV6_NC_STATE_INCOMPLETE) && - (gnrc_ipv6_nc_get_state(router) != GNRC_IPV6_NC_STATE_UNREACHABLE)) { - _last_router = NULL; - - return &router->ipv6_addr; - } - - router = gnrc_ipv6_nc_get_next_router(router); - } - - /* else take the first one, but keep round-robin in further selections */ - router = gnrc_ipv6_nc_get_next_router(_last_router); - - if (router == NULL) { /* end of router list or there is none => wrap around */ - router = gnrc_ipv6_nc_get_next_router(router); - - if (router == NULL) { /* still nothing found => no router in list */ - return NULL; - } - } - - _last_router = router; - - return &router->ipv6_addr; -} - -void gnrc_ndp_internal_set_state(gnrc_ipv6_nc_t *nc_entry, uint8_t state) -{ - gnrc_ipv6_netif_t *ipv6_iface; - uint32_t t = GNRC_NDP_FIRST_PROBE_DELAY * US_PER_SEC; - - nc_entry->flags &= ~GNRC_IPV6_NC_STATE_MASK; - nc_entry->flags |= state; - - DEBUG("ndp internal: set %s state to ", - ipv6_addr_to_str(addr_str, &nc_entry->ipv6_addr, sizeof(addr_str))); - - switch (state) { - case GNRC_IPV6_NC_STATE_REACHABLE: - ipv6_iface = gnrc_ipv6_netif_get(nc_entry->iface); - DEBUG("REACHABLE (reachable time = %" PRIu32 " us)\n", ipv6_iface->reach_time); - t = ipv6_iface->reach_time; - - /* Falls through. */ - /* this is intentional to set the desired timeout t */ - case GNRC_IPV6_NC_STATE_DELAY: -#if ENABLE_DEBUG - if (state == GNRC_IPV6_NC_STATE_DELAY) { - DEBUG("DELAY (probe with unicast NS in %u seconds)\n", - GNRC_NDP_FIRST_PROBE_DELAY); - } -#endif - gnrc_ndp_internal_reset_nbr_sol_timer(nc_entry, t, GNRC_NDP_MSG_NC_STATE_TIMEOUT, - gnrc_ipv6_pid); - break; - - case GNRC_IPV6_NC_STATE_PROBE: - ipv6_iface = gnrc_ipv6_netif_get(nc_entry->iface); - - nc_entry->probes_remaining = GNRC_NDP_MAX_UC_NBR_SOL_NUMOF; - DEBUG("PROBE (probe with %" PRIu8 " unicast NS every %" PRIu32 " us)\n", - nc_entry->probes_remaining, ipv6_iface->retrans_timer); - - gnrc_ndp_internal_send_nbr_sol(nc_entry->iface, NULL, &nc_entry->ipv6_addr, - &nc_entry->ipv6_addr); - - mutex_lock(&ipv6_iface->mutex); - gnrc_ndp_internal_reset_nbr_sol_timer(nc_entry, ipv6_iface->retrans_timer, - GNRC_NDP_MSG_NBR_SOL_RETRANS, gnrc_ipv6_pid); - mutex_unlock(&ipv6_iface->mutex); - break; - -#ifdef ENABLE_DEBUG - case GNRC_IPV6_NC_STATE_STALE: - DEBUG("STALE (go into DELAY on next packet)\n"); - break; -#endif - - default: - DEBUG("errorneous or unknown\n"); - break; - } -} - -void gnrc_ndp_internal_send_nbr_adv(kernel_pid_t iface, ipv6_addr_t *tgt, ipv6_addr_t *dst, - bool supply_tl2a, gnrc_pktsnip_t *ext_opts) -{ - gnrc_pktsnip_t *hdr, *pkt = ext_opts; - uint8_t adv_flags = 0; - - DEBUG("ndp internal: send neighbor advertisement (iface: %" PRIkernel_pid ", tgt: %s, ", - iface, ipv6_addr_to_str(addr_str, tgt, sizeof(addr_str))); - DEBUG("dst: %s, supply_tl2a: %d)\n", - ipv6_addr_to_str(addr_str, dst, sizeof(addr_str)), supply_tl2a); - - if ((gnrc_ipv6_netif_get(iface)->flags & GNRC_IPV6_NETIF_FLAGS_ROUTER) && - (gnrc_ipv6_netif_get(iface)->flags & GNRC_IPV6_NETIF_FLAGS_RTR_ADV)) { - adv_flags |= NDP_NBR_ADV_FLAGS_R; - } - - if (ipv6_addr_is_unspecified(dst)) { - ipv6_addr_set_all_nodes_multicast(dst, IPV6_ADDR_MCAST_SCP_LINK_LOCAL); - } - else { - adv_flags |= NDP_NBR_ADV_FLAGS_S; - } - - if (supply_tl2a) { - uint8_t l2src[8]; - size_t l2src_len; - /* we previously checked if we are the target, so we can take our L2src */ - l2src_len = _get_l2src(iface, l2src, sizeof(l2src)); - - if (l2src_len > 0) { - /* add target address link-layer address option */ - pkt = gnrc_ndp_opt_tl2a_build(l2src, l2src_len, pkt); - - if (pkt == NULL) { - DEBUG("ndp internal: error allocating Target Link-layer address option.\n"); - gnrc_pktbuf_release(ext_opts); - return; - } - } - } - - /* TODO: also check if the node provides proxy servies for tgt */ - if ((pkt != NULL) && !gnrc_ipv6_netif_addr_is_non_unicast(tgt)) { - /* TL2A is not supplied and tgt is not anycast */ - adv_flags |= NDP_NBR_ADV_FLAGS_O; - } - - hdr = gnrc_ndp_nbr_adv_build(adv_flags, tgt, pkt); - - if (hdr == NULL) { - DEBUG("ndp internal: error allocating Neighbor advertisement.\n"); - gnrc_pktbuf_release(pkt); - return; - } - pkt = hdr; - hdr = _build_headers(iface, pkt, dst, NULL); - if (hdr == NULL) { - DEBUG("ndp internal: error adding lower-layer headers.\n"); - gnrc_pktbuf_release(pkt); - return; - } - if (gnrc_ipv6_netif_addr_is_non_unicast(tgt)) { - /* avoid collision for anycast addresses - * (see https://tools.ietf.org/html/rfc4861#section-7.2.7) */ - uint32_t delay = random_uint32_range(0, GNRC_NDP_MAX_AC_TGT_DELAY * US_PER_SEC); - gnrc_ipv6_nc_t *nc_entry = gnrc_ipv6_nc_get(iface, dst); - DEBUG("ndp internal: delay neighbor advertisement for %" PRIu32 " sec.", - (delay / US_PER_SEC)); - - /* nc_entry must be set so no need to check it */ - assert(nc_entry); - - _send_delayed(&nc_entry->nbr_adv_timer, &nc_entry->nbr_adv_msg, delay, hdr); - } - else if (gnrc_netapi_send(gnrc_ipv6_pid, hdr) < 1) { - DEBUG("ndp internal: unable to send neighbor advertisement\n"); - gnrc_pktbuf_release(hdr); - } -} - -void gnrc_ndp_internal_send_nbr_sol(kernel_pid_t iface, ipv6_addr_t *src, ipv6_addr_t *tgt, - ipv6_addr_t *dst) -{ -#ifdef MODULE_GNRC_SIXLOWPAN_ND - gnrc_ipv6_netif_t *ipv6_iface = gnrc_ipv6_netif_get(iface); - assert(ipv6_iface != NULL); -#endif - gnrc_pktsnip_t *hdr, *pkt = NULL; - /* cppcheck-suppress variableScope - * (reason: they are needed in the MODULE_GNRC_SIXLOWPAN_ND branch) */ - uint8_t l2src[8]; - /* cppcheck-suppress variableScope - * (reason: they are needed in the MODULE_GNRC_SIXLOWPAN_ND branch) */ - size_t l2src_len = 0; - - DEBUG("ndp internal: send neighbor solicitation (iface: %" PRIkernel_pid ", src: %s, ", - iface, ipv6_addr_to_str(addr_str, src ? src : &ipv6_addr_unspecified, sizeof(addr_str))); - DEBUG(" tgt: %s, ", ipv6_addr_to_str(addr_str, tgt, sizeof(addr_str))); - DEBUG("dst: %s)\n", ipv6_addr_to_str(addr_str, dst, sizeof(addr_str))); - - /* check if there is a fitting source address to target */ - if (src == NULL) { - src = gnrc_ipv6_netif_find_best_src_addr(iface, tgt, false); - } - if (src != NULL) { - l2src_len = _get_l2src(iface, l2src, sizeof(l2src)); - - if (l2src_len > 0) { - /* add source address link-layer address option */ - pkt = gnrc_ndp_opt_sl2a_build(l2src, l2src_len, NULL); - - if (pkt == NULL) { - DEBUG("ndp internal: error allocating Source Link-layer address option.\n"); - gnrc_pktbuf_release(pkt); - return; - } - } - } - -#ifdef MODULE_GNRC_SIXLOWPAN_ND - if (ipv6_iface->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) { - if (l2src_len != sizeof(eui64_t)) { - l2src_len = (uint16_t)gnrc_netapi_get(iface, NETOPT_ADDRESS_LONG, 0, l2src, - sizeof(l2src)); - if (l2src_len != sizeof(eui64_t)) { - DEBUG("ndp internal: can't get EUI-64 of the interface\n"); - gnrc_pktbuf_release(pkt); - return; - } - } - hdr = gnrc_sixlowpan_nd_opt_ar_build(0, GNRC_SIXLOWPAN_ND_AR_LTIME, (eui64_t *)l2src, pkt); - if (hdr == NULL) { - DEBUG("ndp internal: error allocatin Address Registration option.\n"); - gnrc_pktbuf_release(pkt); - return; - } - pkt = hdr; - } -#endif - - hdr = gnrc_ndp_nbr_sol_build(tgt, pkt); - - if (hdr == NULL) { - DEBUG("ndp internal: error allocating Neighbor solicitation.\n"); - gnrc_pktbuf_release(pkt); - return; - } - pkt = hdr; - hdr = _build_headers(iface, pkt, dst, src); - if (hdr == NULL) { - DEBUG("ndp internal: error adding lower-layer headers.\n"); - gnrc_pktbuf_release(pkt); - return; - } - else if (gnrc_netapi_send(gnrc_ipv6_pid, hdr) < 1) { - DEBUG("ndp internal: unable to send neighbor solicitation\n"); - gnrc_pktbuf_release(hdr); - } -} - -void gnrc_ndp_internal_send_rtr_sol(kernel_pid_t iface, ipv6_addr_t *dst) -{ - gnrc_pktsnip_t *hdr, *pkt = NULL; - ipv6_addr_t *src = NULL; - DEBUG("ndp internal: send router solicitation (iface: %" PRIkernel_pid ", dst: ff02::2)\n", - iface); - if (dst == NULL) { - /* isn't changed afterwards so discarding const should be alright */ - dst = (ipv6_addr_t *)&ipv6_addr_all_routers_link_local; - } - /* check if there is a fitting source address to target */ - if ((src = gnrc_ipv6_netif_find_best_src_addr(iface, dst, false)) != NULL) { - uint8_t l2src[8]; - size_t l2src_len; - l2src_len = _get_l2src(iface, l2src, sizeof(l2src)); - if (l2src_len > 0) { - /* add source address link-layer address option */ - pkt = gnrc_ndp_opt_sl2a_build(l2src, l2src_len, NULL); - - if (pkt == NULL) { - DEBUG("ndp internal: error allocating Source Link-layer address option.\n"); - gnrc_pktbuf_release(pkt); - return; - } - } - } - hdr = gnrc_ndp_rtr_sol_build(pkt); - if (hdr == NULL) { - DEBUG("ndp internal: error allocating router solicitation.\n"); - gnrc_pktbuf_release(pkt); - return; - } - pkt = hdr; - hdr = _build_headers(iface, pkt, dst, src); - if (hdr == NULL) { - DEBUG("ndp internal: error adding lower-layer headers.\n"); - gnrc_pktbuf_release(pkt); - return; - } - else if (gnrc_netapi_send(gnrc_ipv6_pid, hdr) < 1) { - DEBUG("ndp internal: unable to send router solicitation\n"); - gnrc_pktbuf_release(hdr); - } -} - -#if (defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER)) -static bool _pio_from_iface_addr(gnrc_pktsnip_t **res, gnrc_ipv6_netif_t *iface, - gnrc_ipv6_netif_addr_t *addr, gnrc_pktsnip_t *next) -{ - assert(((uint8_t) addr->prefix_len) <= 128U); - - if (!ipv6_addr_is_unspecified(&addr->addr) && - !ipv6_addr_is_link_local(&addr->addr) && - !gnrc_ipv6_netif_addr_is_non_unicast(&addr->addr)) { - uint8_t flags = 0; - DEBUG(" - PIO for %s/%" PRIu8 "\n", ipv6_addr_to_str(addr_str, &addr->addr, - sizeof(addr_str)), - addr->prefix_len); - -#ifdef MODULE_GNRC_SIXLOWPAN_ND - if (!(iface->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN)) { - flags = GNRC_IPV6_NETIF_ADDR_FLAGS_NDP_ON_LINK; - } -#else - (void) iface; -#endif - - *res = gnrc_ndp_opt_pi_build(addr->prefix_len, addr->flags | flags, addr->valid, - addr->preferred, &addr->addr, next); - return true; - } - return false; -} - -static inline bool _check_prefixes(gnrc_ipv6_netif_addr_t *a, gnrc_ipv6_netif_addr_t *b) -{ - if ((a->prefix_len == b->prefix_len) && - (ipv6_addr_match_prefix(&a->addr, &b->addr) >= a->prefix_len)) { - return true; - } - - return false; -} - -static bool _add_pios(gnrc_pktsnip_t **res, gnrc_ipv6_netif_t *ipv6_iface, gnrc_pktsnip_t *pkt) -{ - for (int i = 0; i < GNRC_IPV6_NETIF_ADDR_NUMOF; i++) { - /* skip if prefix has been processed already */ - bool processed_before = false; - - for (int j = 0; j < i; j++) { - if ((processed_before = - _check_prefixes(&ipv6_iface->addrs[i], &ipv6_iface->addrs[j]))) { - break; - } - } - - if (processed_before) { - continue; - } - - if (_pio_from_iface_addr(res, ipv6_iface, &ipv6_iface->addrs[i], pkt)) { - if (*res != NULL) { - pkt = *res; - } - else { - DEBUG("ndp rtr: error allocating PIO\n"); - gnrc_pktbuf_release(pkt); - return false; - } - } - } - return true; -} - -void gnrc_ndp_internal_send_rtr_adv(kernel_pid_t iface, ipv6_addr_t *src, ipv6_addr_t *dst, - bool fin) -{ - gnrc_pktsnip_t *hdr = NULL, *pkt = NULL; - gnrc_ipv6_netif_t *ipv6_iface = gnrc_ipv6_netif_get(iface); - uint32_t reach_time = 0, retrans_timer = 0; - uint16_t adv_ltime = 0; - uint8_t cur_hl = 0; - - if (dst == NULL) { - /* isn't changed afterwards so discarding const should be fine */ - dst = (ipv6_addr_t *)&ipv6_addr_all_nodes_link_local; - } - DEBUG("ndp internal: send router advertisement (iface: %" PRIkernel_pid ", dst: %s%s\n", - iface, ipv6_addr_to_str(addr_str, dst, sizeof(addr_str)), fin ? ", final" : ""); - mutex_lock(&ipv6_iface->mutex); -#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER - if (!(ipv6_iface->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN)) { -#endif - if (!_add_pios(&hdr, ipv6_iface, pkt)) { - /* pkt already released in _add_pios */ - mutex_unlock(&ipv6_iface->mutex); - return; - } - pkt = hdr; -#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER - } - else { - gnrc_sixlowpan_nd_router_abr_t *abr = gnrc_sixlowpan_nd_router_abr_get(); - if (abr != NULL) { - gnrc_sixlowpan_nd_router_prf_t *prf = abr->prfs; - /* add prefixes from border router */ - while (prf) { - bool processed_before = false; - /* skip if prefix does not belong to iface */ - if (prf->iface != ipv6_iface) { - prf = prf->next; - continue; - } - /* skip if prefix has been processed already */ - for (gnrc_sixlowpan_nd_router_prf_t *tmp = abr->prfs; tmp != prf; tmp = tmp->next) { - if ((processed_before = - _check_prefixes(prf->prefix, tmp->prefix))) { - break; - } - } - - if (processed_before) { - prf = prf->next; - continue; - } - - if (_pio_from_iface_addr(&hdr, ipv6_iface, prf->prefix, pkt)) { - if (hdr != NULL) { - pkt = hdr; - } - else { - DEBUG("ndp rtr: error allocating PIO\n"); - gnrc_pktbuf_release(pkt); - mutex_unlock(&ipv6_iface->mutex); - return; - } - } - prf = prf->next; - } - for (unsigned int i = 0; i < GNRC_SIXLOWPAN_CTX_SIZE; i++) { - gnrc_sixlowpan_ctx_t *ctx; - if (!bf_isset(abr->ctxs, i)) { - continue; - } - ctx = gnrc_sixlowpan_ctx_lookup_id(i); - hdr = gnrc_sixlowpan_nd_opt_6ctx_build(ctx->prefix_len, ctx->flags_id, ctx->ltime, - &ctx->prefix, pkt); - if (hdr == NULL) { - DEBUG("ndp rtr: error allocating 6CO\n"); - mutex_unlock(&ipv6_iface->mutex); - gnrc_pktbuf_release(pkt); - return; - } - pkt = hdr; - } - hdr = gnrc_sixlowpan_nd_opt_abr_build(abr->version, abr->ltime, &abr->addr, pkt); - if (hdr == NULL) { - DEBUG("ndp internal: error allocating ABRO.\n"); - mutex_unlock(&ipv6_iface->mutex); - gnrc_pktbuf_release(pkt); - return; - } - pkt = hdr; - } - } -#endif /* MODULE_GNRC_SIXLOWPAN_ND_ROUTER */ - if (ipv6_iface->flags & GNRC_IPV6_NETIF_FLAGS_ADV_MTU) { - if ((hdr = gnrc_ndp_opt_mtu_build(ipv6_iface->mtu, pkt)) == NULL) { - DEBUG("ndp rtr: no space left in packet buffer\n"); - mutex_unlock(&ipv6_iface->mutex); - gnrc_pktbuf_release(pkt); - return; - } - pkt = hdr; - } - if (src == NULL) { - mutex_unlock(&ipv6_iface->mutex); - /* get address from source selection algorithm. - * Only link local addresses may be used (RFC 4861 section 4.1) */ - src = gnrc_ipv6_netif_find_best_src_addr(iface, dst, true); - mutex_lock(&ipv6_iface->mutex); - } - /* add SL2A for source address */ - if (src != NULL) { - DEBUG(" - SL2A\n"); - uint8_t l2src[8]; - size_t l2src_len; - /* optimization note: MAY also be omitted to facilitate in-bound load balancing over - * replicated interfaces. - * source: https://tools.ietf.org/html/rfc4861#section-6.2.3 */ - l2src_len = _get_l2src(iface, l2src, sizeof(l2src)); - if (l2src_len > 0) { - /* add source address link-layer address option */ - hdr = gnrc_ndp_opt_sl2a_build(l2src, l2src_len, pkt); - - if (hdr == NULL) { - DEBUG("ndp internal: error allocating Source Link-layer address option.\n"); - mutex_unlock(&ipv6_iface->mutex); - gnrc_pktbuf_release(pkt); - return; - } - pkt = hdr; - } - } - if (ipv6_iface->flags & GNRC_IPV6_NETIF_FLAGS_ADV_CUR_HL) { - cur_hl = ipv6_iface->cur_hl; - } - if (ipv6_iface->flags & GNRC_IPV6_NETIF_FLAGS_ADV_REACH_TIME) { - - if (ipv6_iface->reach_time > (3600 * US_PER_SEC)) { /* reach_time > 1 hour */ - reach_time = (3600 * MS_PER_SEC); - } - else { - reach_time = ipv6_iface->reach_time / US_PER_MS; - } - } - if (ipv6_iface->flags & GNRC_IPV6_NETIF_FLAGS_ADV_RETRANS_TIMER) { - retrans_timer = ipv6_iface->retrans_timer / US_PER_MS; - } - if (!fin) { - adv_ltime = ipv6_iface->adv_ltime; - } - mutex_unlock(&ipv6_iface->mutex); - hdr = gnrc_ndp_rtr_adv_build(cur_hl, - (ipv6_iface->flags & (GNRC_IPV6_NETIF_FLAGS_OTHER_CONF | - GNRC_IPV6_NETIF_FLAGS_MANAGED)) >> 8, - adv_ltime, reach_time, retrans_timer, pkt); - if (hdr == NULL) { - DEBUG("ndp internal: error allocating router advertisement.\n"); - gnrc_pktbuf_release(pkt); - return; - } - pkt = hdr; - hdr = _build_headers(iface, pkt, dst, src); - if (hdr == NULL) { - DEBUG("ndp internal: error adding lower-layer headers.\n"); - gnrc_pktbuf_release(pkt); - return; - } - else if (gnrc_netapi_send(gnrc_ipv6_pid, hdr) < 1) { - DEBUG("ndp internal: unable to send router advertisement\n"); - gnrc_pktbuf_release(hdr); - } -} -#endif - -int gnrc_ndp_internal_sl2a_opt_handle(gnrc_pktsnip_t *pkt, ipv6_hdr_t *ipv6, uint8_t icmpv6_type, - ndp_opt_t *sl2a_opt, uint8_t *l2src) -{ - int sl2a_len = 0; - uint8_t *sl2a = (uint8_t *)(sl2a_opt + 1); - - if ((sl2a_opt->len == 0) || ipv6_addr_is_unspecified(&ipv6->src)) { - DEBUG("ndp: invalid source link-layer address option received\n"); - return -EINVAL; - } - - while (pkt) { - if (pkt->type == GNRC_NETTYPE_NETIF) { - gnrc_netif_hdr_t *hdr = pkt->data; - sl2a_len = hdr->src_l2addr_len; - break; - } - pkt = pkt->next; - } - -#ifdef MODULE_GNRC_SIXLOWPAN_ND - if ((sl2a_len == 2) || (sl2a_len == 8)) { - /* The link-layer seems to be IEEE 802.15.4. - * Determining address length from the option length: - * https://tools.ietf.org/html/rfc4944#section-8 */ - if (sl2a_opt->len == 1) { - sl2a_len = 2; - } - else if (sl2a_opt->len == 2) { - sl2a_len = 8; - } - else { - DEBUG("ndp: invalid source link-layer address option received\n"); - return -EINVAL; - } - } -#endif - - DEBUG("ndp: received SL2A (link-layer address: %s)\n", - gnrc_netif_addr_to_str(addr_str, sizeof(addr_str), sl2a, sl2a_len)); - - switch (icmpv6_type) { - case ICMPV6_RTR_SOL: - case ICMPV6_RTR_ADV: - case ICMPV6_NBR_SOL: - if (sl2a_len == 0) { /* in case there was no source address in l2 */ - sl2a_len = (sl2a_opt->len * 8) - sizeof(ndp_opt_t); - - /* ignore all zeroes at the end for length */ - for (; sl2a[sl2a_len - 1] == 0x00; sl2a_len--); - } - - memcpy(l2src, sl2a, sl2a_len); - return sl2a_len; - - default: /* wrong encapsulating message: silently discard */ - DEBUG("ndp: silently discard sl2a_opt for ICMPv6 message type %" - PRIu8 "\n", icmpv6_type); - return -ENOTSUP; - } -} - -int gnrc_ndp_internal_tl2a_opt_handle(gnrc_pktsnip_t *pkt, ipv6_hdr_t *ipv6, - uint8_t icmpv6_type, ndp_opt_t *tl2a_opt, - uint8_t *l2addr) -{ - uint8_t tl2a_len = 0; - uint8_t *tl2a = (uint8_t *)(tl2a_opt + 1); - - if ((tl2a_opt->len == 0) || ipv6_addr_is_unspecified(&ipv6->src)) { - DEBUG("ndp: invalid target link-layer address option received\n"); - return -EINVAL; - } - - switch (icmpv6_type) { - case ICMPV6_NBR_ADV: - while (pkt) { - if (pkt->type == GNRC_NETTYPE_NETIF) { - gnrc_netif_hdr_t *hdr = pkt->data; - tl2a_len = hdr->src_l2addr_len; - break; - } - pkt = pkt->next; - } -#ifdef MODULE_GNRC_SIXLOWPAN_ND - if ((tl2a_len == 2) || (tl2a_len == 8)) { - /* The link-layer seems to be IEEE 802.15.4. - * Determining address length from the option length: - * https://tools.ietf.org/html/rfc4944#section-8 */ - if (tl2a_opt->len == 1) { - tl2a_len = 2; - } - else if (tl2a_opt->len == 2) { - tl2a_len = 8; - } - else { - DEBUG("ndp: invalid target link-layer address option received\n"); - return -EINVAL; - } - } -#endif - - if (tl2a_len == 0) { /* in case there was no source address in l2 */ - tl2a_len = (tl2a_opt->len / 8) - sizeof(ndp_opt_t); - - /* ignore all zeroes at the end for length */ - for (; tl2a[tl2a_len - 1] == 0x00; tl2a_len--); - } - - DEBUG("ndp: received TL2A (link-layer address: %s)\n", - gnrc_netif_addr_to_str(addr_str, sizeof(addr_str), tl2a, tl2a_len)); - - memcpy(l2addr, tl2a, tl2a_len); - - return (int)tl2a_len; - - default: /* wrong encapsulating message: silently discard */ - DEBUG("ndp: silently discard tl2a_opt for ICMPv6 message type %" - PRIu8 "\n", icmpv6_type); - return 0; - } -} - -bool gnrc_ndp_internal_mtu_opt_handle(kernel_pid_t iface, uint8_t icmpv6_type, - ndp_opt_mtu_t *mtu_opt) -{ - gnrc_ipv6_netif_t *if_entry = gnrc_ipv6_netif_get(iface); - - if ((mtu_opt->len != NDP_OPT_MTU_LEN)) { - DEBUG("ndp: invalid MTU option received\n"); - return false; - } - if (icmpv6_type != ICMPV6_RTR_ADV) { - /* else discard silently */ - return true; - } - mutex_lock(&if_entry->mutex); - if_entry->mtu = byteorder_ntohl(mtu_opt->mtu); - mutex_unlock(&if_entry->mutex); - return true; -} - -bool gnrc_ndp_internal_pi_opt_handle(kernel_pid_t iface, uint8_t icmpv6_type, - ndp_opt_pi_t *pi_opt) -{ - ipv6_addr_t *prefix; - gnrc_ipv6_netif_addr_t *netif_addr; - - if ((pi_opt->len != NDP_OPT_PI_LEN)) { - DEBUG("ndp: invalid PI option received\n"); - return false; - } - if (icmpv6_type != ICMPV6_RTR_ADV || ipv6_addr_is_link_local(&pi_opt->prefix)) { - /* else discard silently */ - return true; - } -#ifdef MODULE_GNRC_SIXLOWPAN_ND - if ((gnrc_ipv6_netif_get(iface)->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) && - (pi_opt->flags & NDP_OPT_PI_FLAGS_L)) { - /* ignore: see https://tools.ietf.org/html/rfc6775#section-5.4 */ - return true; - } -#endif - prefix = gnrc_ipv6_netif_find_addr(iface, &pi_opt->prefix); - if (((prefix == NULL) || - (gnrc_ipv6_netif_addr_get(prefix)->prefix_len != pi_opt->prefix_len)) && - (pi_opt->valid_ltime.u32 != 0)) { - ipv6_addr_t pref_addr = IPV6_ADDR_UNSPECIFIED; - - if (pi_opt->flags & NDP_OPT_PI_FLAGS_A) { - if ((gnrc_netapi_get(iface, NETOPT_IPV6_IID, 0, &pref_addr.u64[1], - sizeof(eui64_t)) < 0)) { - DEBUG("ndp: could not get IID from interface %d\n", iface); - return false; - } - } - - ipv6_addr_init_prefix(&pref_addr, &pi_opt->prefix, pi_opt->prefix_len); - prefix = gnrc_ipv6_netif_add_addr(iface, &pref_addr, - pi_opt->prefix_len, - pi_opt->flags & NDP_OPT_PI_FLAGS_MASK); - if (prefix == NULL) { - DEBUG("ndp: could not add prefix to interface %d\n", iface); - return false; - } -#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER - gnrc_sixlowpan_nd_router_set_rtr_adv(gnrc_ipv6_netif_get(iface), true); -#endif - } - netif_addr = gnrc_ipv6_netif_addr_get(prefix); - if (pi_opt->valid_ltime.u32 == 0) { - if (prefix != NULL) { - gnrc_ipv6_netif_remove_addr(iface, &netif_addr->addr); - } - - return true; - } - netif_addr->valid = byteorder_ntohl(pi_opt->valid_ltime); - netif_addr->preferred = byteorder_ntohl(pi_opt->pref_ltime); - if (netif_addr->valid != UINT32_MAX) { - xtimer_set_msg(&netif_addr->valid_timeout, - (byteorder_ntohl(pi_opt->valid_ltime) * US_PER_SEC), - &netif_addr->valid_timeout_msg, thread_getpid()); - } - /* TODO: preferred lifetime for address auto configuration */ - /* on-link flag MUST stay set if it was */ - netif_addr->flags &= NDP_OPT_PI_FLAGS_L; - netif_addr->flags |= (pi_opt->flags & NDP_OPT_PI_FLAGS_MASK); - return true; -} - -static size_t _get_l2src(kernel_pid_t iface, uint8_t *l2src, size_t l2src_maxlen) -{ - bool try_long = false; - int res; - uint16_t l2src_len; - /* maximum address length that fits into a minimum length (8) S/TL2A option */ - const uint16_t max_short_len = 6; - - /* try getting source address */ - if ((gnrc_netapi_get(iface, NETOPT_SRC_LEN, 0, &l2src_len, - sizeof(l2src_len)) >= 0) && - (l2src_len > max_short_len)) { - try_long = true; - } - - if (try_long && ((res = gnrc_netapi_get(iface, NETOPT_ADDRESS_LONG, 0, - l2src, l2src_maxlen)) > max_short_len)) { - l2src_len = (uint16_t)res; - } - else if ((res = gnrc_netapi_get(iface, NETOPT_ADDRESS, 0, l2src, - l2src_maxlen)) >= 0) { - l2src_len = (uint16_t)res; - } - else { - DEBUG("ndp internal: no link-layer address found.\n"); - l2src_len = 0; - } - - return l2src_len; -} - -static gnrc_pktsnip_t *_build_headers(kernel_pid_t iface, gnrc_pktsnip_t *payload, - ipv6_addr_t *dst, ipv6_addr_t *src) -{ - gnrc_pktsnip_t *l2hdr; - gnrc_pktsnip_t *iphdr = gnrc_ipv6_hdr_build(payload, src, dst); - if (iphdr == NULL) { - DEBUG("ndp internal: error allocating IPv6 header.\n"); - return NULL; - } - ((ipv6_hdr_t *)iphdr->data)->hl = 255; - /* add netif header for send interface specification */ - l2hdr = gnrc_netif_hdr_build(NULL, 0, NULL, 0); - if (l2hdr == NULL) { - DEBUG("ndp internal: error allocating netif header.\n"); - gnrc_pktbuf_remove_snip(iphdr, iphdr); - return NULL; - } - ((gnrc_netif_hdr_t *)l2hdr->data)->if_pid = iface; - LL_PREPEND(iphdr, l2hdr); - return l2hdr; -} - -/** @} */ diff --git a/sys/net/gnrc/network_layer/ndp/node/Makefile b/sys/net/gnrc/network_layer/ndp/node/Makefile deleted file mode 100644 index 127a91910935d743e56ffe82d31b22f07d2ea6aa..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/network_layer/ndp/node/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -MODULE = gnrc_ndp_node - -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/gnrc/network_layer/ndp/node/gnrc_ndp_node.c b/sys/net/gnrc/network_layer/ndp/node/gnrc_ndp_node.c deleted file mode 100644 index 402d344d209231df370218cbba6be2ac663e4d92..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/network_layer/ndp/node/gnrc_ndp_node.c +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @{ - * - * @file - */ - -#include <stdint.h> -#include <stdlib.h> - -#include "kernel_types.h" -#include "net/fib.h" -#include "net/gnrc/ipv6.h" -#include "net/gnrc/ndp.h" -#include "net/gnrc/pkt.h" -#include "net/gnrc/pktqueue.h" - -#include "net/gnrc/ndp/internal.h" - -#include "net/gnrc/ndp/node.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -#if ENABLE_DEBUG -static char addr_str[IPV6_ADDR_MAX_STR_LEN]; -#endif - -static gnrc_pktqueue_t _pkt_nodes[GNRC_IPV6_NC_SIZE * 2]; - -/** - * @brief Allocates a node for the packet queue. - * - * @param[in] pkt Packet to add to the packet queue. - * - * @return A packet queue node. - */ -static gnrc_pktqueue_t *_alloc_pkt_node(gnrc_pktsnip_t *pkt) -{ - for (size_t i = 0; i < sizeof(_pkt_nodes) / sizeof(gnrc_pktqueue_t); i++) { - if ((_pkt_nodes[i].pkt == NULL) && (_pkt_nodes[i].next == NULL)) { - _pkt_nodes[i].pkt = pkt; - - return &(_pkt_nodes[i]); - } - } - - return NULL; -} - -kernel_pid_t gnrc_ndp_node_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_len, - kernel_pid_t iface, ipv6_addr_t *dst, - gnrc_pktsnip_t *pkt) -{ - gnrc_ipv6_nc_t *nc_entry; - ipv6_addr_t *next_hop_ip = NULL, *prefix = NULL; - bool dst_link_local = ipv6_addr_is_link_local(dst); - -#ifdef MODULE_FIB - ipv6_addr_t next_hop_actual; /* FIB copies address into this variable */ - /* don't look-up link local addresses in FIB */ - if (!dst_link_local) { - size_t next_hop_size = sizeof(ipv6_addr_t); - uint32_t next_hop_flags = 0; - - if ((next_hop_ip == NULL) && - (fib_get_next_hop(&gnrc_ipv6_fib_table, &iface, next_hop_actual.u8, - &next_hop_size, &next_hop_flags, (uint8_t *)dst, - sizeof(ipv6_addr_t), 0) >= 0) && - (next_hop_size == sizeof(ipv6_addr_t))) { - next_hop_ip = &next_hop_actual; - } - } -#endif - - /* cppcheck-suppress knownConditionTrueFalse - * cppcheck bug: next_hop_ip might be initialized if a FIB is available */ - if (next_hop_ip == NULL) { /* no route to host */ - if (!dst_link_local) { - if (iface == KERNEL_PID_UNDEF) { - /* gnrc_ipv6_netif_t doubles as prefix list */ - iface = gnrc_ipv6_netif_find_by_prefix(&prefix, dst); - } - else { - /* gnrc_ipv6_netif_t doubles as prefix list */ - prefix = gnrc_ipv6_netif_match_prefix(iface, dst); - } - } - - if (dst_link_local || ((prefix != NULL) && - (gnrc_ipv6_netif_addr_get(prefix)->flags & /* prefix is on-link */ - GNRC_IPV6_NETIF_ADDR_FLAGS_NDP_ON_LINK))) { - next_hop_ip = dst; - } - } - - /* dst has not an on-link prefix */ - if (next_hop_ip == NULL) { - next_hop_ip = gnrc_ndp_internal_default_router(); - } - - if (next_hop_ip == NULL) { - next_hop_ip = dst; /* Just look if it's in the neighbor cache - * (aka on-link but not registered in prefix list as such) */ - } - - /* start address resolution */ - nc_entry = gnrc_ipv6_nc_get(iface, next_hop_ip); - - if ((nc_entry != NULL) && gnrc_ipv6_nc_is_reachable(nc_entry)) { - DEBUG("ndp node: found reachable neighbor (%s => ", - ipv6_addr_to_str(addr_str, &nc_entry->ipv6_addr, sizeof(addr_str))); - DEBUG("%s)\n", - gnrc_netif_addr_to_str(addr_str, sizeof(addr_str), - nc_entry->l2_addr, nc_entry->l2_addr_len)); - - if (gnrc_ipv6_nc_get_state(nc_entry) == GNRC_IPV6_NC_STATE_STALE) { - gnrc_ndp_internal_set_state(nc_entry, GNRC_IPV6_NC_STATE_DELAY); - } - return gnrc_ipv6_nc_get_l2_addr(l2addr, l2addr_len, nc_entry); - } - else if (nc_entry == NULL) { - gnrc_pktqueue_t *pkt_node; - ipv6_addr_t dst_sol; - - nc_entry = gnrc_ipv6_nc_add(iface, next_hop_ip, NULL, 0, - GNRC_IPV6_NC_STATE_INCOMPLETE << GNRC_IPV6_NC_STATE_POS); - - if (nc_entry == NULL) { - DEBUG("ndp node: could not create neighbor cache entry\n"); - return KERNEL_PID_UNDEF; - } - - pkt_node = _alloc_pkt_node(pkt); - - if (pkt_node == NULL) { - DEBUG("ndp node: could not add packet to packet queue\n"); - } - else { - /* prevent packet from being released by IPv6 */ - gnrc_pktbuf_hold(pkt_node->pkt, 1); - gnrc_pktqueue_add(&nc_entry->pkts, pkt_node); - } - - /* address resolution */ - ipv6_addr_set_solicited_nodes(&dst_sol, next_hop_ip); - - if (iface == KERNEL_PID_UNDEF) { - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - size_t ifnum = gnrc_netif_get(ifs); - - for (size_t i = 0; i < ifnum; i++) { - gnrc_ndp_internal_send_nbr_sol(ifs[i], NULL, next_hop_ip, &dst_sol); - } - - gnrc_ndp_internal_reset_nbr_sol_timer(nc_entry, GNRC_NDP_RETRANS_TIMER, - GNRC_NDP_MSG_NBR_SOL_RETRANS, gnrc_ipv6_pid); - } - else { - gnrc_ipv6_netif_t *ipv6_iface = gnrc_ipv6_netif_get(iface); - - gnrc_ndp_internal_send_nbr_sol(iface, NULL, next_hop_ip, &dst_sol); - - mutex_lock(&ipv6_iface->mutex); - gnrc_ndp_internal_reset_nbr_sol_timer(nc_entry, ipv6_iface->retrans_timer, - GNRC_NDP_MSG_NBR_SOL_RETRANS, gnrc_ipv6_pid); - mutex_unlock(&ipv6_iface->mutex); - } - } - - return KERNEL_PID_UNDEF; -} - - -/** @} */ diff --git a/sys/net/gnrc/network_layer/ndp/router/Makefile b/sys/net/gnrc/network_layer/ndp/router/Makefile deleted file mode 100644 index 541dc343692c18477294358051880d8477ec554d..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/network_layer/ndp/router/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -MODULE = gnrc_ndp_router - -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/gnrc/network_layer/ndp/router/gnrc_ndp_router.c b/sys/net/gnrc/network_layer/ndp/router/gnrc_ndp_router.c deleted file mode 100644 index 07fd1109742eb1fadee752ced22c2ed256f51d88..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/network_layer/ndp/router/gnrc_ndp_router.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @{ - * - * @file - */ - -#include "net/gnrc/ipv6.h" -#include "net/gnrc/ndp.h" -#include "net/gnrc/ndp/internal.h" -#include "random.h" -#include "xtimer.h" - -#include "net/gnrc/ndp/router.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -static void _send_rtr_adv(gnrc_ipv6_netif_t *iface, ipv6_addr_t *dst); - -void gnrc_ndp_router_set_router(gnrc_ipv6_netif_t *iface, bool enable) -{ - if (enable && !(iface->flags & GNRC_IPV6_NETIF_FLAGS_ROUTER)) { - gnrc_ipv6_netif_add_addr(iface->pid, &ipv6_addr_all_routers_link_local, - 128, GNRC_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST); - mutex_lock(&iface->mutex); - iface->flags |= GNRC_IPV6_NETIF_FLAGS_ROUTER; - iface->max_adv_int = GNRC_IPV6_NETIF_DEFAULT_MAX_ADV_INT; - iface->min_adv_int = GNRC_IPV6_NETIF_DEFAULT_MIN_ADV_INT; - iface->adv_ltime = GNRC_IPV6_NETIF_DEFAULT_ROUTER_LTIME; - mutex_unlock(&iface->mutex); - gnrc_ndp_router_set_rtr_adv(iface, enable); - } - else if (!enable && (iface->flags & GNRC_IPV6_NETIF_FLAGS_ROUTER)) { - gnrc_ipv6_netif_remove_addr(iface->pid, (ipv6_addr_t *)&ipv6_addr_all_routers_link_local); - gnrc_ndp_router_set_rtr_adv(iface, enable); - } -} - -void gnrc_ndp_router_set_rtr_adv(gnrc_ipv6_netif_t *iface, bool enable) -{ - if (enable && !(iface->flags & GNRC_IPV6_NETIF_FLAGS_RTR_ADV)) { - mutex_lock(&iface->mutex); - iface->flags |= GNRC_IPV6_NETIF_FLAGS_RTR_ADV; - iface->rtr_adv_count = GNRC_NDP_MAX_INIT_RTR_ADV_NUMOF; - mutex_unlock(&iface->mutex); - _send_rtr_adv(iface, NULL); - } - else if (!enable && (iface->flags & GNRC_IPV6_NETIF_FLAGS_RTR_ADV)) { - mutex_lock(&iface->mutex); - iface->rtr_adv_count = GNRC_NDP_MAX_FIN_RTR_ADV_NUMOF; - iface->flags &= ~GNRC_IPV6_NETIF_FLAGS_RTR_ADV; - iface->adv_ltime = 0; -#ifdef MODULE_GNRC_NDP_HOST - iface->rtr_sol_count = GNRC_NDP_MAX_RTR_SOL_NUMOF; -#endif - mutex_unlock(&iface->mutex); - _send_rtr_adv(iface, NULL); -#ifdef MODULE_GNRC_NDP_HOST - gnrc_ndp_host_retrans_rtr_sol(iface); -#endif - } -} - -void gnrc_ndp_router_retrans_rtr_adv(gnrc_ipv6_netif_t *iface) -{ - _send_rtr_adv(iface, NULL); -} - -void gnrc_ndp_router_send_rtr_adv(gnrc_ipv6_nc_t *neighbor) -{ - gnrc_ipv6_netif_t *iface = gnrc_ipv6_netif_get(neighbor->iface); - /* TODO: send one router advertisement per ABR: https://tools.ietf.org/html/rfc6775#section-6.3 */ - _send_rtr_adv(iface, &neighbor->ipv6_addr); -} - -static void _send_rtr_adv(gnrc_ipv6_netif_t *iface, ipv6_addr_t *dst) -{ - bool fin; - uint32_t interval; - - mutex_lock(&iface->mutex); - fin = (iface->adv_ltime == 0); - assert((iface->min_adv_int != 0) && (iface->max_adv_int != 0)); - interval = random_uint32_range(iface->min_adv_int, iface->max_adv_int); - if (!fin && !((iface->flags | GNRC_IPV6_NETIF_FLAGS_ROUTER) && - (iface->flags | GNRC_IPV6_NETIF_FLAGS_RTR_ADV))) { - DEBUG("ndp rtr: interface %" PRIkernel_pid " is not an advertising interface\n", - iface->pid); - return; - } - if (iface->rtr_adv_count > 1) { /* regard for off-by-one error */ - iface->rtr_adv_count--; - if (!fin && (interval > GNRC_NDP_MAX_INIT_RTR_ADV_INT)) { - interval = GNRC_NDP_MAX_INIT_RTR_ADV_INT; - } - } - if (!fin || (iface->rtr_adv_count > 1)) { /* regard for off-by-one-error */ - /* reset timer for next router advertisement */ - xtimer_remove(&iface->rtr_adv_timer); - iface->rtr_adv_msg.type = GNRC_NDP_MSG_RTR_ADV_RETRANS; - iface->rtr_adv_msg.content.ptr = iface; - xtimer_set_msg(&iface->rtr_adv_timer, interval * US_PER_SEC, &iface->rtr_adv_msg, - gnrc_ipv6_pid); - } - mutex_unlock(&iface->mutex); - for (int i = 0; i < GNRC_IPV6_NETIF_ADDR_NUMOF; i++) { - ipv6_addr_t *src = &iface->addrs[i].addr; - - if (!ipv6_addr_is_unspecified(src) && ipv6_addr_is_link_local(src) && - !gnrc_ipv6_netif_addr_is_non_unicast(src)) { - /* send one for every link local address (ideally there is only one) */ - gnrc_ndp_internal_send_rtr_adv(iface->pid, src, dst, fin); - } - } -} - -/** @} */ diff --git a/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c b/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c index 5d8331c0c2c328789bb89bd80e09826736140590..cb99b6a3d2b18f3248e8c9051ad74c225a4cefdd 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c +++ b/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c @@ -16,9 +16,9 @@ #include <stdbool.h> #include "rbuf.h" +#include "net/ipv6.h" #include "net/ipv6/hdr.h" #include "net/gnrc.h" -#include "net/gnrc/ipv6/netif.h" #include "net/gnrc/sixlowpan.h" #include "net/gnrc/sixlowpan/frag.h" #include "net/sixlowpan.h" @@ -39,7 +39,7 @@ #ifndef RBUF_INT_SIZE /* same as ((int) ceil((double) N / D)) */ #define DIV_CEIL(N, D) (((N) + (D) - 1) / (D)) -#define RBUF_INT_SIZE (DIV_CEIL(GNRC_IPV6_NETIF_DEFAULT_MTU, GNRC_SIXLOWPAN_FRAG_SIZE) * RBUF_SIZE) +#define RBUF_INT_SIZE (DIV_CEIL(IPV6_MIN_MTU, GNRC_SIXLOWPAN_FRAG_SIZE) * RBUF_SIZE) #endif static rbuf_int_t rbuf_int[RBUF_INT_SIZE]; diff --git a/sys/net/gnrc/network_layer/sixlowpan/nd/gnrc_sixlowpan_nd.c b/sys/net/gnrc/network_layer/sixlowpan/nd/gnrc_sixlowpan_nd.c index 7b3526051afbc7abd8f81ab1aaf0ee6fb4821e49..a2a34494846a0e1ae84304b17eb76ac52654be9c 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/nd/gnrc_sixlowpan_nd.c +++ b/sys/net/gnrc/network_layer/sixlowpan/nd/gnrc_sixlowpan_nd.c @@ -16,7 +16,6 @@ #include "net/icmpv6.h" #include "net/gnrc/ipv6.h" #include "net/gnrc/ndp2.h" -#include "net/gnrc/netif.h" #include "net/gnrc/sixlowpan.h" #include "net/gnrc/sixlowpan/ctx.h" #include "random.h" diff --git a/sys/net/gnrc/network_layer/sixlowpan/netif/Makefile b/sys/net/gnrc/network_layer/sixlowpan/netif/Makefile deleted file mode 100644 index 758ba59edbccc27bc50f2b2ab732741d050b1d45..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/network_layer/sixlowpan/netif/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -MODULE = gnrc_sixlowpan_netif - -include $(RIOTBASE)/Makefile.base diff --git a/sys/net/gnrc/network_layer/sixlowpan/netif/gnrc_sixlowpan_netif.c b/sys/net/gnrc/network_layer/sixlowpan/netif/gnrc_sixlowpan_netif.c deleted file mode 100644 index 6046d9b4258d3e0bad74366562d7d31d2ca8828a..0000000000000000000000000000000000000000 --- a/sys/net/gnrc/network_layer/sixlowpan/netif/gnrc_sixlowpan_netif.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @{ - * - * @file - */ - -#include "kernel_types.h" - -#include "net/gnrc/netif.h" -#include "net/gnrc/sixlowpan/netif.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -static gnrc_sixlowpan_netif_t sixlow_ifs[GNRC_NETIF_NUMOF]; - -void gnrc_sixlowpan_netif_init(void) -{ - for (int i = 0; i < GNRC_NETIF_NUMOF; i++) { - sixlow_ifs[i].pid = KERNEL_PID_UNDEF; - sixlow_ifs[i].max_frag_size = 0; - } -} - -void gnrc_sixlowpan_netif_add(kernel_pid_t pid, uint16_t max_frag_size) -{ - gnrc_sixlowpan_netif_t *free_entry = NULL; - - for (int i = 0; i < GNRC_NETIF_NUMOF; i++) { - if (sixlow_ifs[i].pid == pid) { - return; - } - - if ((sixlow_ifs[i].pid == KERNEL_PID_UNDEF) && !free_entry) { - /* found the first free entry */ - free_entry = &sixlow_ifs[i]; - } - } - - if (!free_entry) { - DEBUG("gnrc_sixlowpan_netif_add: couldn't add interface with PID %d: No space left.\n", pid); - return; - } - - free_entry->pid = pid; - free_entry->max_frag_size = max_frag_size; -#ifdef MODULE_GNRC_SIXLOWPAN_IPHC - free_entry->iphc_enabled = true; -#endif - return; -} - -void gnrc_sixlowpan_netif_remove(kernel_pid_t pid) -{ - gnrc_sixlowpan_netif_t *entry = gnrc_sixlowpan_netif_get(pid); - - entry->pid = KERNEL_PID_UNDEF; -} - -gnrc_sixlowpan_netif_t *gnrc_sixlowpan_netif_get(kernel_pid_t pid) -{ - for (int i = 0; i < GNRC_NETIF_NUMOF; i++) { - if (sixlow_ifs[i].pid == pid) { - return sixlow_ifs + i; - } - } - - return NULL; -} - -/** @} */ diff --git a/sys/net/gnrc/sock/gnrc_sock.c b/sys/net/gnrc/sock/gnrc_sock.c index 65c88876cfee52ce51b2eab766d47866bcb0629e..0f66aeea795580093b6d53ee18ed80571e2ff3d4 100644 --- a/sys/net/gnrc/sock/gnrc_sock.c +++ b/sys/net/gnrc/sock/gnrc_sock.c @@ -18,7 +18,6 @@ #include "net/af.h" #include "net/ipv6/hdr.h" #include "net/gnrc/ipv6/hdr.h" -#include "net/gnrc/ipv6/netif.h" #include "net/gnrc/netreg.h" #include "net/udp.h" #include "utlist.h" diff --git a/sys/net/routing/nhdp/nhdp.c b/sys/net/routing/nhdp/nhdp.c index 4665f7746f686336594d24babf54128514aa1936..0897c812723dc41c76720e0452369565c7eb5021 100644 --- a/sys/net/routing/nhdp/nhdp.c +++ b/sys/net/routing/nhdp/nhdp.c @@ -21,7 +21,6 @@ #include "net/sock/udp.h" #include "msg.h" #include "net/gnrc/netapi.h" -#include "net/gnrc/netif.h" #include "thread.h" #include "utlist.h" #include "mutex.h" diff --git a/sys/shell/commands/Makefile b/sys/shell/commands/Makefile index fc7d1e199dc3b1a987ca31b66465032361b9f33a..2c8da3187382eee948975c16f07b1df6aa3194d9 100644 --- a/sys/shell/commands/Makefile +++ b/sys/shell/commands/Makefile @@ -23,18 +23,12 @@ endif ifneq (,$(filter at30tse75x,$(USEMODULE))) SRC += sc_at30tse75x.c endif -ifneq (,$(filter gnrc_netif,$(USEMODULE))) - SRC += sc_netif.c -endif ifneq (,$(filter gnrc_netif2,$(USEMODULE))) SRC += sc_gnrc_netif2.c endif ifneq (,$(filter fib,$(USEMODULE))) SRC += sc_fib.c endif -ifneq (,$(filter gnrc_ipv6_nc,$(USEMODULE))) - SRC += sc_ipv6_nc.c -endif ifneq (,$(filter gnrc_ipv6_nib,$(USEMODULE))) SRC += sc_gnrc_ipv6_nib.c endif @@ -44,12 +38,11 @@ endif ifneq (,$(filter gnrc_ipv6_blacklist,$(USEMODULE))) SRC += sc_blacklist.c endif -# The ping command in sc_icmpv6_echo requires xtimer, too. However, this is -# implicitly pulled in by gnrc_ipv6_netif (which is a dependency of gnrc_ipv6) -# already. ifneq (,$(filter gnrc_icmpv6_echo,$(USEMODULE))) +ifneq (,$(filter xtimer,$(USEMODULE))) SRC += sc_icmpv6_echo.c endif +endif ifneq (,$(filter gnrc_rpl,$(USEMODULE))) SRC += sc_gnrc_rpl.c endif diff --git a/sys/shell/commands/sc_gnrc_6ctx.c b/sys/shell/commands/sc_gnrc_6ctx.c index 1af9b809741a9bccb890c9ab853f010dd3a84ed0..ab457e444c4af0b1c6feee8ce5226debe9ccbd9b 100644 --- a/sys/shell/commands/sc_gnrc_6ctx.c +++ b/sys/shell/commands/sc_gnrc_6ctx.c @@ -20,7 +20,6 @@ #include <string.h> #include "net/ipv6/addr.h" -#include "net/gnrc/ndp/internal.h" #include "net/gnrc/sixlowpan/ctx.h" #include "net/gnrc/sixlowpan/nd.h" #include "timex.h" @@ -60,15 +59,7 @@ int _gnrc_6ctx_list(void) static void _adv_ctx(void) { - /* TODO: update NIB */ - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - size_t ifnum = gnrc_netif_get(ifs); - for (size_t i = 0; i < ifnum; i++) { - gnrc_ipv6_netif_t *iface = gnrc_ipv6_netif_get(ifs[i]); - if ((iface != NULL) && (iface->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN)) { - gnrc_ndp_internal_send_rtr_adv(ifs[i], NULL, NULL, false); - } - } + /* TODO: update NIB, send router advertisement */ } int _gnrc_6ctx_add(char *cmd_str, char *ctx_str, char *prefix_str, char *ltime_str) diff --git a/sys/shell/commands/sc_gnrc_ipv6_nib.c b/sys/shell/commands/sc_gnrc_ipv6_nib.c index 83f6c5c698bb0f4fd797ff5d649578afb5f7d502..544f360e3256b62ca407e881b521e11079e0938d 100644 --- a/sys/shell/commands/sc_gnrc_ipv6_nib.c +++ b/sys/shell/commands/sc_gnrc_ipv6_nib.c @@ -16,7 +16,7 @@ #include <stdio.h> #include "net/gnrc/ipv6/nib.h" -#include "net/gnrc/netif.h" +#include "net/gnrc/netif2.h" #include "net/ipv6/addr.h" static void _usage(char **argv); diff --git a/sys/shell/commands/sc_icmpv6_echo.c b/sys/shell/commands/sc_icmpv6_echo.c index 2d6710946ca49420c931fa51634410611dfd5bb0..5ac65923b4abcdef3cad064de45bf46e58f82b35 100644 --- a/sys/shell/commands/sc_icmpv6_echo.c +++ b/sys/shell/commands/sc_icmpv6_echo.c @@ -24,7 +24,9 @@ #include "byteorder.h" #include "net/gnrc/icmpv6.h" #include "net/ipv6/addr.h" -#include "net/gnrc/ipv6/nc.h" +#ifdef MODULE_GNRC_IPV6_NIB +#include "net/gnrc/ipv6/nib/nc.h" +#endif #include "net/gnrc/ipv6/hdr.h" #include "net/gnrc/netif2.h" #include "net/gnrc.h" @@ -109,8 +111,8 @@ int _handle_reply(gnrc_pktsnip_t *pkt, uint32_t time) ipv6_addr_to_str(ipv6_str, &(ipv6_hdr->src), sizeof(ipv6_str)), byteorder_ntohs(icmpv6_hdr->id), seq, (unsigned)ipv6_hdr->hl, time / US_PER_MS, time % US_PER_MS); -#ifdef MODULE_GNRC_IPV6_NC - gnrc_ipv6_nc_still_reachable(&ipv6_hdr->src); +#ifdef MODULE_GNRC_IPV6_NIB + gnrc_ipv6_nib_nc_mark_reachable(&ipv6_hdr->src); #endif } else { diff --git a/sys/shell/commands/sc_ipv6_nc.c b/sys/shell/commands/sc_ipv6_nc.c deleted file mode 100644 index ae4d9cac276fda34ace65c94c6a9e73e657c5cbb..0000000000000000000000000000000000000000 --- a/sys/shell/commands/sc_ipv6_nc.c +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser General - * Public License v2.1. See the file LICENSE in the top level directory for - * more details. - */ - -/** - * @ingroup sys_shell_commands.h - * @{ - * - * @file - * - * @author Martine Lenders <mlenders@inf.fu-berlin.de> - */ - -#include <stdio.h> -#include <string.h> - -#include "kernel_types.h" -#include "net/ipv6/addr.h" -#include "net/gnrc/ipv6/nc.h" -#include "net/gnrc/netif.h" -#include "thread.h" - -/* maximum length of L2 address */ -#define MAX_L2_ADDR_LEN (8U) - -static void _print_nc_state(gnrc_ipv6_nc_t *entry) -{ - switch (entry->flags & GNRC_IPV6_NC_STATE_MASK) { - case GNRC_IPV6_NC_STATE_UNMANAGED: - printf("UNMANAGED "); - break; - - case GNRC_IPV6_NC_STATE_UNREACHABLE: - printf("UNREACHABLE "); - break; - - case GNRC_IPV6_NC_STATE_INCOMPLETE: - printf("INCOMPLETE "); - break; - - case GNRC_IPV6_NC_STATE_STALE: - printf("STALE "); - break; - - case GNRC_IPV6_NC_STATE_DELAY: - printf("DELAY "); - break; - - case GNRC_IPV6_NC_STATE_PROBE: - printf("PROBE "); - break; - - case GNRC_IPV6_NC_STATE_REACHABLE: - printf("REACHABLE "); - break; - - default: - printf("UNKNOWN "); - break; - } -} - -static void _print_nc_type(gnrc_ipv6_nc_t *entry) -{ - switch (entry->flags & GNRC_IPV6_NC_TYPE_MASK) { - case GNRC_IPV6_NC_TYPE_GC: - printf("GC"); - break; - - case GNRC_IPV6_NC_TYPE_TENTATIVE: - printf("TENT"); - break; - - case GNRC_IPV6_NC_TYPE_REGISTERED: - printf("REG"); - break; - - default: - printf("-"); - break; - } -} - -static bool _is_iface(kernel_pid_t iface) -{ -#ifdef MODULE_GNRC_NETIF - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - size_t numof = gnrc_netif_get(ifs); - - for (size_t i = 0; i < numof && i < GNRC_NETIF_NUMOF; i++) { - if (ifs[i] == iface) { - return true; - } - } - - return false; -#else - return (thread_get(iface) != NULL); -#endif -} - -static int _ipv6_nc_list(void) -{ - char ipv6_str[IPV6_ADDR_MAX_STR_LEN]; - char l2addr_str[3 * MAX_L2_ADDR_LEN]; - - puts("IPv6 address if L2 address state type"); - puts("------------------------------------------------------------------------------"); - - for (gnrc_ipv6_nc_t *entry = gnrc_ipv6_nc_get_next(NULL); - entry != NULL; - entry = gnrc_ipv6_nc_get_next(entry)) { - printf("%-30s %2" PRIkernel_pid " %-24s ", - ipv6_addr_to_str(ipv6_str, &entry->ipv6_addr, sizeof(ipv6_str)), - entry->iface, - gnrc_netif_addr_to_str(l2addr_str, sizeof(l2addr_str), - entry->l2_addr, entry->l2_addr_len)); - _print_nc_state(entry); - _print_nc_type(entry); - puts(""); - } - - return 0; -} - -static inline kernel_pid_t _get_iface(void) -{ - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - size_t ifnum = gnrc_netif_get(ifs); - return (ifnum > 1) ? KERNEL_PID_UNDEF : ifs[0]; -} - -static int _ipv6_nc_add(int argc, char **argv) -{ - char *ipv6_addr_str; - char *l2_addr_str = NULL; - kernel_pid_t iface = KERNEL_PID_UNDEF; - ipv6_addr_t ipv6_addr; - uint8_t l2_addr[MAX_L2_ADDR_LEN]; - size_t l2_addr_len = 0; - - switch (argc) { - case 1: - iface = _get_iface(); - ipv6_addr_str = argv[0]; /* store for output */ - l2_addr_len = 0; - break; - case 2: - ipv6_addr_str = argv[0]; /* store for output */ - if (ipv6_addr_from_str(&ipv6_addr, ipv6_addr_str) == NULL) { - iface = atoi(argv[0]); - ipv6_addr_str = argv[1]; - l2_addr_len = 0; - } - else { - iface = _get_iface(); - l2_addr_str = argv[1]; - } - break; - default: - iface = atoi(argv[0]); - ipv6_addr_str = argv[1]; - l2_addr_str = argv[2]; - break; - } - - if (!_is_iface(iface)) { - puts("error: invalid interface given."); - return 1; - } - - if (ipv6_addr_from_str(&ipv6_addr, ipv6_addr_str) == NULL) { - puts("error: unable to parse IPv6 address."); - return 1; - } - - if ((l2_addr_str != NULL) && (l2_addr_len = gnrc_netif_addr_from_str(l2_addr, sizeof(l2_addr), - l2_addr_str)) == 0) { - puts("error: unable to parse link-layer address."); - return 1; - } - - if (gnrc_ipv6_nc_add(iface, &ipv6_addr, l2_addr, l2_addr_len, 0) == NULL) { - puts("error: unable to add address to neighbor cache."); - return 1; - } - - printf("success: added IPv6 address %s to neighbor cache\n", ipv6_addr_str); - return 0; -} - -static int _ipv6_nc_del(char *ipv6_addr_str) -{ - ipv6_addr_t ipv6_addr; - - if (ipv6_addr_from_str(&ipv6_addr, ipv6_addr_str) == NULL) { - puts("error: unable to parse IPv6 address."); - return 1; - } - - gnrc_ipv6_nc_remove(KERNEL_PID_UNDEF, &ipv6_addr); - printf("success: removed %s from neighbor cache\n", ipv6_addr_str); - - return 0; -} - -static int _ipv6_nc_reset(void) -{ - gnrc_ipv6_nc_t *tmp = NULL; - - for (gnrc_ipv6_nc_t *entry = gnrc_ipv6_nc_get_next(NULL); - entry != NULL; - tmp = entry, entry = gnrc_ipv6_nc_get_next(entry)) { - if (tmp) { - gnrc_ipv6_nc_remove(tmp->iface, &tmp->ipv6_addr); - } - } - - /* remove last entry */ - if (tmp) { - gnrc_ipv6_nc_remove(tmp->iface, &tmp->ipv6_addr); - } - - printf("success: reset neighbor cache\n"); - - return 0; -} - -int _ipv6_nc_manage(int argc, char **argv) -{ - if ((argc == 1) || (strcmp("list", argv[1]) == 0)) { - return _ipv6_nc_list(); - } - - if (argc > 1) { - if ((argc > 2) && (strcmp("add", argv[1]) == 0)) { - return _ipv6_nc_add(argc - 2, &argv[2]); - } - if ((argc > 2) && (strcmp("del", argv[1]) == 0)) { - return _ipv6_nc_del(argv[2]); - } - if (strcmp("reset", argv[1]) == 0) { - return _ipv6_nc_reset(); - } - } - - printf("usage: %s [list]\n" - " or: %s add [<iface pid>] <ipv6_addr> <l2_addr>\n" - " * <iface pid> is optional if only one interface exists.\n" - " or: %s del <ipv6_addr>\n" - " or: %s reset\n", argv[0], argv[0], argv[0], argv[0]); - return 1; -} - -int _ipv6_nc_routers(int argc, char **argv) -{ - kernel_pid_t iface = KERNEL_PID_UNDEF; - char ipv6_str[IPV6_ADDR_MAX_STR_LEN]; - - if (argc > 1) { - iface = atoi(argv[1]); - - if (!_is_iface(iface)) { - printf("usage: %s [<iface pid>]\n", argv[0]); - return 1; - } - } - - puts("if Router state type"); - puts("---------------------------------------------------"); - - for (gnrc_ipv6_nc_t *entry = gnrc_ipv6_nc_get_next_router(NULL); - entry != NULL; - entry = gnrc_ipv6_nc_get_next_router(entry)) { - if ((iface != KERNEL_PID_UNDEF) && (iface != entry->iface)) { - continue; - } - - printf("%2" PRIkernel_pid " %-30s ", entry->iface, - ipv6_addr_to_str(ipv6_str, &entry->ipv6_addr, sizeof(ipv6_str))); - _print_nc_state(entry); - _print_nc_type(entry); - puts(""); - } - - return 0; -} - -/** - * @} - */ diff --git a/sys/shell/commands/sc_netif.c b/sys/shell/commands/sc_netif.c deleted file mode 100644 index 5b8af6c19083e4961852d862ae20ece4c8d9025d..0000000000000000000000000000000000000000 --- a/sys/shell/commands/sc_netif.c +++ /dev/null @@ -1,1339 +0,0 @@ -/* - * Copyright (C) 2015 Freie Universität Berlin - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup sys_shell_commands - * @{ - * - * @file - * @brief Shell commands for interacting with network devices - * - * @author Hauke Petersen <hauke.petersen@fu-berlin.de> - * @author Martine Lenders <mlenders@inf.fu-berlin.de> - * @author Oliver Hahm <oliver.hahm@inria.fr> - */ - -#include <stdbool.h> -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <inttypes.h> - -#include "thread.h" -#include "net/ipv6/addr.h" -#include "net/gnrc/ipv6/netif.h" -#include "net/gnrc/netif.h" -#include "net/gnrc/netapi.h" -#include "net/netopt.h" -#include "net/gnrc/pkt.h" -#include "net/gnrc/pktbuf.h" -#include "net/gnrc/netif/hdr.h" -#include "net/gnrc/sixlowpan/netif.h" - -#ifdef MODULE_NETSTATS -#include "net/netstats.h" -#endif -#ifdef MODULE_L2FILTER -#include "net/l2filter.h" -#endif - -/** - * @brief The maximal expected link layer address length in byte - */ -#define MAX_ADDR_LEN (8U) - -/** - * @brief The default IPv6 prefix length if not specified. - */ -#define SC_NETIF_IPV6_DEFAULT_PREFIX_LEN (64) - -/* utility functions */ -static bool _is_number(char *str) -{ - for (; *str; str++) { - if (*str < '0' || *str > '9') { - return false; - } - } - - return true; -} - -static bool _is_iface(kernel_pid_t dev) -{ - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - size_t numof = gnrc_netif_get(ifs); - - for (size_t i = 0; i < numof && i < GNRC_NETIF_NUMOF; i++) { - if (ifs[i] == dev) { - return true; - } - } - - return false; -} - -#ifdef MODULE_NETSTATS -const char *_netstats_module_to_str(uint8_t module) -{ - switch (module) { - case NETSTATS_LAYER2: - return "Layer 2"; - case NETSTATS_IPV6: - return "IPv6"; - case NETSTATS_ALL: - return "all"; - default: - return "Unknown"; - } -} - -static int _netif_stats(kernel_pid_t dev, unsigned module, bool reset) -{ - netstats_t *stats; - int res = -ENOTSUP; - - if (module == NETSTATS_LAYER2) { - res = gnrc_netapi_get(dev, NETOPT_STATS, 0, &stats, sizeof(&stats)); - } -#ifdef MODULE_NETSTATS_IPV6 - else if (module == NETSTATS_IPV6) { - stats = gnrc_ipv6_netif_get_stats(dev); - if (stats != NULL) { - res = 1; - } - } -#endif - - if (res < 0) { - puts(" Protocol or device doesn't provide statistics."); - } - else if (reset) { - memset(stats, 0, sizeof(netstats_t)); - printf("Reset statistics for module %s!\n", _netstats_module_to_str(module)); - } - else { - printf(" Statistics for %s\n" - " RX packets %u bytes %u\n" - " TX packets %u (Multicast: %u) bytes %u\n" - " TX succeeded %u errors %u\n", - _netstats_module_to_str(module), - (unsigned) stats->rx_count, - (unsigned) stats->rx_bytes, - (unsigned) (stats->tx_unicast_count + stats->tx_mcast_count), - (unsigned) stats->tx_mcast_count, - (unsigned) stats->tx_bytes, - (unsigned) stats->tx_success, - (unsigned) stats->tx_failed); - res = 0; - } - return res; -} -#endif // MODULE_NETSTATS - -static void _set_usage(char *cmd_name) -{ - printf("usage: %s <if_id> set <key> <value>\n", cmd_name); - puts(" Sets an hardware specific specific value\n" - " <key> may be one of the following\n" - " * \"addr\" - sets (short) address\n" - " * \"addr_long\" - sets long address\n" - " * \"addr_short\" - alias for \"addr\"\n" - " * \"channel\" - sets the frequency channel\n" - " * \"chan\" - alias for \"channel\"\n" - " * \"csma_retries\" - set max. number of channel access attempts\n" - " * \"cca_threshold\" - set ED threshold during CCA in dBm\n" - " * \"nid\" - sets the network identifier (or the PAN ID)\n" - " * \"page\" - set the channel page (IEEE 802.15.4)\n" - " * \"pan\" - alias for \"nid\"\n" - " * \"pan_id\" - alias for \"nid\"\n" - " * \"power\" - TX power in dBm\n" - " * \"retrans\" - max. number of retransmissions\n" - " * \"src_len\" - sets the source address length in byte\n" - " * \"state\" - set the device state\n" - " * \"encrypt\" - set the encryption on-off\n" - " * \"key\" - set the encryption key in hexadecimal format\n"); -} - -static void _mtu_usage(char *cmd_name) -{ - printf("usage: %s <if_id> mtu <n>\n", cmd_name); -} - -#ifdef MODULE_GNRC_IPV6_NETIF -static void _hl_usage(char *cmd_name) -{ - printf("usage: %s <if_id> hl <n>\n", cmd_name); -} -#endif - -static void _flag_usage(char *cmd_name) -{ - printf("usage: %s <if_id> [-]{promisc|autoack|ack_req|csma|autocca|cca_threshold|preload|mac_no_sleep|iphc|rtr_adv}\n", cmd_name); -} - -static void _add_usage(char *cmd_name) -{ - printf("usage: %s <if_id> add [anycast|multicast|unicast] " - "<ipv6_addr>[/prefix_len]\n", cmd_name); -} - -static void _del_usage(char *cmd_name) -{ - printf("usage: %s <if_id> del <ipv6_addr>\n", - cmd_name); -} - -#ifdef MODULE_NETSTATS -static void _stats_usage(char *cmd_name) -{ - printf("usage: %s <if_id> stats [l2|ipv6] [reset]\n", cmd_name); - puts(" reset can be only used if the module is specified."); -} -#endif - -static void _print_netopt(netopt_t opt) -{ - switch (opt) { - case NETOPT_ADDRESS: - printf("(short) address"); - break; - - case NETOPT_ADDRESS_LONG: - printf("long address"); - break; - - case NETOPT_SRC_LEN: - printf("source address length"); - break; - - case NETOPT_CHANNEL: - printf("channel"); - break; - - case NETOPT_CHANNEL_PAGE: - printf("page"); - break; - - case NETOPT_NID: - printf("network identifier"); - break; - - case NETOPT_TX_POWER: - printf("TX power [in dBm]"); - break; - - case NETOPT_RETRANS: - printf("max. retransmissions"); - break; - - case NETOPT_CSMA_RETRIES: - printf("CSMA retries"); - break; - - case NETOPT_CCA_THRESHOLD: - printf("CCA threshold [in dBm]"); - break; - - case NETOPT_ENCRYPTION: - printf("encryption"); - break; - - case NETOPT_ENCRYPTION_KEY: - printf("encryption key"); - break; - - default: - /* we don't serve these options here */ - break; - } -} - -static void _print_netopt_state(netopt_state_t state) -{ - switch (state) { - case NETOPT_STATE_OFF: - printf("OFF"); - break; - case NETOPT_STATE_SLEEP: - printf("SLEEP"); - break; - case NETOPT_STATE_STANDBY: - printf("STANDBY"); - break; - case NETOPT_STATE_IDLE: - printf("IDLE"); - break; - case NETOPT_STATE_RX: - printf("RX"); - break; - case NETOPT_STATE_TX: - printf("TX"); - break; - case NETOPT_STATE_RESET: - printf("RESET"); - break; - default: - printf("%08x", (unsigned int)state); - /* nothing to do then */ - break; - } -} - -static void _netif_list(kernel_pid_t dev) -{ - uint8_t hwaddr[MAX_ADDR_LEN]; - uint16_t u16; - int16_t i16; - uint8_t u8; - int res; - netopt_state_t state; - netopt_enable_t enable = NETOPT_DISABLE; - bool linebreak = false; - -#ifdef MODULE_GNRC_IPV6_NETIF - gnrc_ipv6_netif_t *entry = gnrc_ipv6_netif_get(dev); - char ipv6_addr[IPV6_ADDR_MAX_STR_LEN]; -#endif - - - printf("Iface %2d ", dev); - - res = gnrc_netapi_get(dev, NETOPT_ADDRESS, 0, hwaddr, sizeof(hwaddr)); - - if (res >= 0) { - char hwaddr_str[res * 3]; - printf(" HWaddr: "); - printf("%s", gnrc_netif_addr_to_str(hwaddr_str, sizeof(hwaddr_str), - hwaddr, res)); - printf(" "); - } - - res = gnrc_netapi_get(dev, NETOPT_CHANNEL, 0, &u16, sizeof(u16)); - - if (res >= 0) { - printf(" Channel: %" PRIu16 " ", u16); - } - - res = gnrc_netapi_get(dev, NETOPT_CHANNEL_PAGE, 0, &u16, sizeof(u16)); - - if (res >= 0) { - printf(" Page: %" PRIu16 " ", u16); - } - - res = gnrc_netapi_get(dev, NETOPT_NID, 0, &u16, sizeof(u16)); - - if (res >= 0) { - printf(" NID: 0x%" PRIx16, u16); - } - - printf("\n "); - - res = gnrc_netapi_get(dev, NETOPT_ADDRESS_LONG, 0, hwaddr, sizeof(hwaddr)); - - if (res >= 0) { - char hwaddr_str[res * 3]; - printf("Long HWaddr: "); - printf("%s ", gnrc_netif_addr_to_str(hwaddr_str, sizeof(hwaddr_str), - hwaddr, res)); - linebreak = true; - } - - if (linebreak) { - printf("\n "); - } - - res = gnrc_netapi_get(dev, NETOPT_TX_POWER, 0, &i16, sizeof(i16)); - - if (res >= 0) { - printf(" TX-Power: %" PRIi16 "dBm ", i16); - } - - res = gnrc_netapi_get(dev, NETOPT_STATE, 0, &state, sizeof(state)); - - if (res >= 0) { - printf(" State: "); - _print_netopt_state(state); - printf(" "); - } - - res = gnrc_netapi_get(dev, NETOPT_RETRANS, 0, &u8, sizeof(u8)); - - if (res >= 0) { - printf(" max. Retrans.: %u ", (unsigned)u8); - } - - res = gnrc_netapi_get(dev, NETOPT_CSMA_RETRIES, 0, &u8, sizeof(u8)); - - if (res >= 0) { - res = gnrc_netapi_get(dev, NETOPT_CSMA, 0, &enable, sizeof(enable)); - if ((res >= 0) && (enable == NETOPT_ENABLE)) { - printf(" CSMA Retries: %u ", (unsigned)u8); - } - } - - printf("\n "); - - res = gnrc_netapi_get(dev, NETOPT_PROMISCUOUSMODE, 0, &enable, sizeof(enable)); - - if ((res >= 0) && (enable == NETOPT_ENABLE)) { - printf("PROMISC "); - linebreak = true; - } - - res = gnrc_netapi_get(dev, NETOPT_AUTOACK, 0, &enable, sizeof(enable)); - - if ((res >= 0) && (enable == NETOPT_ENABLE)) { - printf("AUTOACK "); - linebreak = true; - } - - res = gnrc_netapi_get(dev, NETOPT_ACK_REQ, 0, &enable, sizeof(enable)); - - if ((res >= 0) && (enable == NETOPT_ENABLE)) { - printf("ACK_REQ "); - linebreak = true; - } - - res = gnrc_netapi_get(dev, NETOPT_PRELOADING, 0, &enable, sizeof(enable)); - - if ((res >= 0) && (enable == NETOPT_ENABLE)) { - printf("PRELOAD "); - linebreak = true; - } - - res = gnrc_netapi_get(dev, NETOPT_RAWMODE, 0, &enable, sizeof(enable)); - - if ((res >= 0) && (enable == NETOPT_ENABLE)) { - printf("RAWMODE "); - linebreak = true; - } - - res = gnrc_netapi_get(dev, NETOPT_CSMA, 0, &enable, sizeof(enable)); - - if ((res >= 0) && (enable == NETOPT_ENABLE)) { - printf("CSMA "); - linebreak = true; - } - - res = gnrc_netapi_get(dev, NETOPT_AUTOCCA, 0, &enable, sizeof(enable)); - - if ((res >= 0) && (enable == NETOPT_ENABLE)) { - printf("AUTOCCA "); - linebreak = true; - } - - res = gnrc_netapi_get(dev, NETOPT_MAC_NO_SLEEP, 0, &enable, sizeof(enable)); - - if ((res >= 0) && (enable == NETOPT_ENABLE)) { - printf("MAC_NO_SLEEP "); - linebreak = true; - } - -#ifdef MODULE_GNRC_IPV6_NETIF - if (entry != NULL) { - printf("MTU:%" PRIu16 " ", entry->mtu); - printf("HL:%u ", (unsigned)entry->cur_hl); - if (entry->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) { - printf("6LO "); - } - if (entry->flags & GNRC_IPV6_NETIF_FLAGS_ROUTER) { - printf("RTR "); - } - if (entry->flags & GNRC_IPV6_NETIF_FLAGS_RTR_ADV) { - printf("RTR_ADV "); - } - linebreak = true; - - } -#endif - -#if defined(MODULE_GNRC_SIXLOWPAN_NETIF) && defined(MODULE_GNRC_SIXLOWPAN_IPHC) - gnrc_sixlowpan_netif_t *sixlo_entry = gnrc_sixlowpan_netif_get(dev); - - if ((sixlo_entry != NULL) && (sixlo_entry->iphc_enabled)) { - printf("IPHC "); - linebreak = true; - } -#endif - - if (linebreak) { - printf("\n "); - } - - res = gnrc_netapi_get(dev, NETOPT_SRC_LEN, 0, &u16, sizeof(u16)); - - if (res >= 0) { - printf("Source address length: %" PRIu16 "\n ", u16); - } - -#ifdef MODULE_GNRC_IPV6_NETIF - if (entry == NULL) { - puts(""); - return; - } - - printf("Link type: %s", (entry->flags & GNRC_IPV6_NETIF_FLAGS_IS_WIRED) ? - "wired" : "wireless"); - printf("\n "); - - for (int i = 0; i < GNRC_IPV6_NETIF_ADDR_NUMOF; i++) { - if (!ipv6_addr_is_unspecified(&entry->addrs[i].addr)) { - printf("inet6 addr: "); - - if (ipv6_addr_to_str(ipv6_addr, &entry->addrs[i].addr, - IPV6_ADDR_MAX_STR_LEN)) { - printf("%s/%u scope: ", ipv6_addr, (unsigned)entry->addrs[i].prefix_len); - - if ((ipv6_addr_is_link_local(&entry->addrs[i].addr))) { - printf("local"); - } - else { - printf("global"); - } - - if (entry->addrs[i].flags & GNRC_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST) { - if (ipv6_addr_is_multicast(&entry->addrs[i].addr)) { - printf(" [multicast]"); - } - else { - printf(" [anycast]"); - } - } - } - else { - printf("error in conversion"); - } - - printf("\n "); - } - } -#endif - -#ifdef MODULE_L2FILTER - l2filter_t *filter = NULL; - res = gnrc_netapi_get(dev, NETOPT_L2FILTER, 0, &filter, sizeof(filter)); - if (res > 0) { -#ifdef MODULE_L2FILTER_WHITELIST - puts("\n White-listed link layer addresses:"); -#else - puts("\n Black-listed link layer addresses:"); -#endif - int count = 0; - for (unsigned i = 0; i < L2FILTER_LISTSIZE; i++) { - if (filter[i].addr_len > 0) { - char hwaddr_str[filter[i].addr_len * 3]; - gnrc_netif_addr_to_str(hwaddr_str, sizeof(hwaddr_str), - filter[i].addr, filter[i].addr_len); - printf(" %2i: %s\n", count++, hwaddr_str); - } - } - if (count == 0) { - puts(" --- none ---"); - } - } -#endif - -#ifdef MODULE_NETSTATS_L2 - puts(""); - _netif_stats(dev, NETSTATS_LAYER2, false); -#endif -#ifdef MODULE_NETSTATS_IPV6 - _netif_stats(dev, NETSTATS_IPV6, false); -#endif - puts(""); -} - -static int _netif_set_u16(kernel_pid_t dev, netopt_t opt, char *u16_str) -{ - unsigned int res; - bool hex = false; - - if (_is_number(u16_str)) { - if ((res = strtoul(u16_str, NULL, 10)) == ULONG_MAX) { - puts("error: unable to parse value.\n" - "Must be a 16-bit unsigned integer (dec or hex)\n"); - return 1; - } - } - else { - if ((res = strtoul(u16_str, NULL, 16)) == ULONG_MAX) { - puts("error: unable to parse value.\n" - "Must be a 16-bit unsigned integer (dec or hex)\n"); - return 1; - } - - hex = true; - } - - if (res > 0xffff) { - puts("error: unable to parse value.\n" - "Must be a 16-bit unsigned integer (dec or hex)\n"); - return 1; - } - - if (gnrc_netapi_set(dev, opt, 0, (uint16_t *)&res, sizeof(uint16_t)) < 0) { - printf("error: unable to set "); - _print_netopt(opt); - puts(""); - return 1; - } - - printf("success: set "); - _print_netopt(opt); - printf(" on interface %" PRIkernel_pid " to ", dev); - - if (hex) { - printf("0x%04x\n", res); - } - else { - printf("%u\n", res); - } - - return 0; -} - -static int _netif_set_i16(kernel_pid_t dev, netopt_t opt, char *i16_str) -{ - int16_t val = atoi(i16_str); - - if (gnrc_netapi_set(dev, opt, 0, (int16_t *)&val, sizeof(int16_t)) < 0) { - printf("error: unable to set "); - _print_netopt(opt); - puts(""); - return 1; - } - - printf("success: set "); - _print_netopt(opt); - printf(" on interface %" PRIkernel_pid " to %i\n", dev, val); - - return 0; -} - -static int _netif_set_u8(kernel_pid_t dev, netopt_t opt, char *u8_str) -{ - uint8_t val = atoi(u8_str); - - if (gnrc_netapi_set(dev, opt, 0, (uint8_t *)&val, sizeof(uint8_t)) < 0) { - printf("error: unable to set "); - _print_netopt(opt); - puts(""); - return 1; - } - - printf("success: set "); - _print_netopt(opt); - printf(" on interface %" PRIkernel_pid " to %i\n", dev, val); - - return 0; -} - -static int _netif_set_flag(kernel_pid_t dev, netopt_t opt, - netopt_enable_t set) -{ - if (gnrc_netapi_set(dev, opt, 0, &set, sizeof(netopt_enable_t)) < 0) { - puts("error: unable to set option"); - return 1; - } - printf("success: %sset option\n", (set) ? "" : "un"); - return 0; -} - -static int _netif_set_addr(kernel_pid_t dev, netopt_t opt, char *addr_str) -{ - uint8_t addr[MAX_ADDR_LEN]; - size_t addr_len = gnrc_netif_addr_from_str(addr, sizeof(addr), addr_str); - - if (addr_len == 0) { - puts("error: unable to parse address.\n" - "Must be of format [0-9a-fA-F]{2}(:[0-9a-fA-F]{2})*\n" - "(hex pairs delimited by colons)"); - return 1; - } - - if (gnrc_netapi_set(dev, opt, 0, addr, addr_len) < 0) { - printf("error: unable to set "); - _print_netopt(opt); - puts(""); - return 1; - } - - printf("success: set "); - _print_netopt(opt); - printf(" on interface %" PRIkernel_pid " to %s\n", dev, addr_str); - - return 0; -} - -static int _netif_set_state(kernel_pid_t dev, char *state_str) -{ - netopt_state_t state; - - if ((strcmp("off", state_str) == 0) || (strcmp("OFF", state_str) == 0)) { - state = NETOPT_STATE_OFF; - } - else if ((strcmp("sleep", state_str) == 0) || - (strcmp("SLEEP", state_str) == 0)) { - state = NETOPT_STATE_SLEEP; - } - else if ((strcmp("idle", state_str) == 0) || - (strcmp("IDLE", state_str) == 0)) { - state = NETOPT_STATE_IDLE; - } - else if ((strcmp("reset", state_str) == 0) || - (strcmp("RESET", state_str) == 0)) { - state = NETOPT_STATE_RESET; - } - else if ((strcmp("standby", state_str) == 0) || - (strcmp("STANDBY", state_str) == 0)) { - state = NETOPT_STATE_STANDBY; - } - else { - puts("usage: ifconfig <if_id> set state [off|sleep|idle|reset|standby]"); - return 1; - } - if (gnrc_netapi_set(dev, NETOPT_STATE, 0, - &state, sizeof(netopt_state_t)) < 0) { - printf("error: unable to set state to "); - _print_netopt_state(state); - puts(""); - return 1; - } - printf("success: set state of interface %" PRIkernel_pid " to ", dev); - _print_netopt_state(state); - puts(""); - - return 0; -} - -static int _netif_set_encrypt(kernel_pid_t dev, netopt_t opt, char *encrypt_str) -{ - netopt_enable_t set; - size_t size = 1; - if ((strcmp("on", encrypt_str) == 0) || (strcmp("ON", encrypt_str) == 0)) { - set = NETOPT_ENABLE; - } - else if ((strcmp("off", encrypt_str) == 0) || (strcmp("OFF", encrypt_str) == 0)) { - set = NETOPT_DISABLE; - } - else { - puts("usage: ifconfig <if_id> set encryption [on|off]"); - return 1; - } - - if (gnrc_netapi_set(dev, opt, 0, &set, size) < 0) { - printf("error: unable to set "); - _print_netopt(opt); - puts(""); - return 1; - } - - printf("success: set "); - _print_netopt(opt); - printf(" on interface %" PRIkernel_pid " to %s\n", dev, encrypt_str); - - return 0; -} - -static int _hex_to_int(char c) { - if ('0' <= c && c <= '9') { - return c - '0'; - } - else if ('a' <= c && c <= 'f') { - return c - 'a'; - } - else if ('A' <= c && c <= 'F') { - return c - 'A'; - } - else { - return -1; - } -} - -static int _netif_set_encrypt_key(kernel_pid_t dev, netopt_t opt, char *key_str) -{ - size_t str_len = strlen(key_str); - size_t key_len = str_len / 2; - uint8_t key[key_len]; - - if (str_len == 14U) { - printf("\nNotice: setting 56 bit key."); - } - else if (str_len == 16U) { - printf("\nNotice: setting 64 bit key."); - } - else if (str_len == 32U) { - printf("\nNotice: setting 128 bit key."); - } - else if (str_len == 48U) { - printf("\nNotice: setting 192 bit key."); - } - else if (str_len == 64U) { - printf("\nNotice: setting 256 bit key."); - } - else if (str_len == 128U) { - printf("\nNotice: setting 512 bit key."); - } - else { - printf("error: invalid key size.\n"); - return 1; - } - /* Convert any char from ASCII table in hex format */ - for (size_t i = 0; i < str_len; i += 2) { - int i1 = _hex_to_int(key_str[i]); - int i2 = _hex_to_int(key_str[i + 1]); - - if (i1 == -1 || i2 == -1) { - puts("error: unable to parse key"); - return 1; - } - - key[i / 2] = (uint8_t)((i1 << 4) + i2); - } - - if (gnrc_netapi_set(dev, opt, 0, key, key_len) < 0) { - printf("error: unable to set "); - _print_netopt(opt); - puts(""); - return 1; - } - - printf("success: set "); - _print_netopt(opt); - printf(" on interface %" PRIkernel_pid " to \n", dev); - for (size_t i = 0; i < key_len; i++) { - /* print the hex value of the key */ - printf("%02x", key[i]); - } - puts(""); - return 0; -} - -#ifdef MODULE_L2FILTER -static int _netif_addrm_l2filter(kernel_pid_t dev, char *val, bool add) -{ - uint8_t addr[MAX_ADDR_LEN]; - size_t addr_len = gnrc_netif_addr_from_str(addr, sizeof(addr), val); - - if ((addr_len == 0) || (addr_len > L2FILTER_ADDR_MAXLEN)) { - puts("error: given address is invalid"); - return 1; - } - - if (add) { - if (gnrc_netapi_set(dev, NETOPT_L2FILTER, 0, addr, addr_len) < 0) { - puts("unable to add link layer address to filter"); - return 1; - } - puts("successfully added address to filter"); - } - else { - if (gnrc_netapi_set(dev, NETOPT_L2FILTER_RM, 0, addr, addr_len) < 0) { - puts("unable to remove link layer address from filter"); - return 1; - } - puts("successfully removed address to filter"); - } - return 0; -} - -static void _l2filter_usage(const char *cmd) -{ - printf("usage: %s <if_id> l2filter {add|del} <addr>\n", cmd); -} -#endif - -static int _netif_set(char *cmd_name, kernel_pid_t dev, char *key, char *value) -{ - if ((strcmp("addr", key) == 0) || (strcmp("addr_short", key) == 0)) { - return _netif_set_addr(dev, NETOPT_ADDRESS, value); - } - else if (strcmp("addr_long", key) == 0) { - return _netif_set_addr(dev, NETOPT_ADDRESS_LONG, value); - } - else if ((strcmp("channel", key) == 0) || (strcmp("chan", key) == 0)) { - return _netif_set_u16(dev, NETOPT_CHANNEL, value); - } - else if (strcmp("page", key) == 0) { - return _netif_set_u16(dev, NETOPT_CHANNEL_PAGE, value); - } - else if ((strcmp("nid", key) == 0) || (strcmp("pan", key) == 0) || - (strcmp("pan_id", key) == 0)) { - return _netif_set_u16(dev, NETOPT_NID, value); - } - else if (strcmp("power", key) == 0) { - return _netif_set_i16(dev, NETOPT_TX_POWER, value); - } - else if (strcmp("src_len", key) == 0) { - return _netif_set_u16(dev, NETOPT_SRC_LEN, value); - } - else if (strcmp("state", key) == 0) { - return _netif_set_state(dev, value); - } - else if (strcmp("retrans", key) == 0) { - return _netif_set_u8(dev, NETOPT_RETRANS, value); - } - else if (strcmp("csma_retries", key) == 0) { - return _netif_set_u8(dev, NETOPT_CSMA_RETRIES, value); - } - else if (strcmp("cca_threshold", key) == 0) { - return _netif_set_u8(dev, NETOPT_CCA_THRESHOLD, value); - } - else if (strcmp("encrypt", key) == 0) { - return _netif_set_encrypt(dev, NETOPT_ENCRYPTION, value); - } - else if (strcmp("key", key) == 0) { - return _netif_set_encrypt_key(dev, NETOPT_ENCRYPTION_KEY, value); - } - - _set_usage(cmd_name); - return 1; -} - -static int _netif_flag(char *cmd, kernel_pid_t dev, char *flag) -{ - netopt_enable_t set = NETOPT_ENABLE; - - if (flag[0] == '-') { - set = NETOPT_DISABLE; - flag++; - } - - if (strcmp(flag, "promisc") == 0) { - return _netif_set_flag(dev, NETOPT_PROMISCUOUSMODE, set); - } - else if (strcmp(flag, "preload") == 0) { - return _netif_set_flag(dev, NETOPT_PRELOADING, set); - } - else if (strcmp(flag, "autoack") == 0) { - return _netif_set_flag(dev, NETOPT_AUTOACK, set); - } - else if (strcmp(flag, "ack_req") == 0) { - return _netif_set_flag(dev, NETOPT_ACK_REQ, set); - } - else if (strcmp(flag, "raw") == 0) { - return _netif_set_flag(dev, NETOPT_RAWMODE, set); - } - else if (strcmp(flag, "csma") == 0) { - return _netif_set_flag(dev, NETOPT_CSMA, set); - } - else if (strcmp(flag, "autocca") == 0) { - return _netif_set_flag(dev, NETOPT_AUTOCCA, set); - } - else if (strcmp(flag, "mac_no_sleep") == 0) { - return _netif_set_flag(dev, NETOPT_MAC_NO_SLEEP, set); - } - else if (strcmp(flag, "iphc") == 0) { -#if defined(MODULE_GNRC_SIXLOWPAN_NETIF) && defined(MODULE_GNRC_SIXLOWPAN_IPHC) - gnrc_sixlowpan_netif_t *entry = gnrc_sixlowpan_netif_get(dev); - - if (entry == NULL) { - puts("error: unable to (un)set IPHC"); - return 1; - } - - if (set) { - entry->iphc_enabled = true; - printf("success: enable IPHC on interface %" PRIkernel_pid "\n", dev); - } - else { - entry->iphc_enabled = false; - printf("success: disable IPHC on interface %" PRIkernel_pid "\n", dev); - } - return 0; -#else - puts("error: unable to (un)set IPHC."); - return 1; -#endif - } - else if (strcmp(flag, "rtr_adv") == 0) { -#if defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER) - gnrc_ipv6_netif_t *entry = gnrc_ipv6_netif_get(dev); - - if (entry == NULL) { - puts("error: unable to (un)set router advertisement flag."); - return 1; - } - - if (set) { - gnrc_ipv6_netif_set_rtr_adv(entry, true); - printf("success: enable router advertisements on interface %" PRIkernel_pid "\n", dev); - } - else { - gnrc_ipv6_netif_set_rtr_adv(entry, false); - printf("success: disable router advertisements on interface %" PRIkernel_pid "\n", - dev); - } - return 0; -#else - puts("error: unable to (un)set router advertisement flag."); - return 1; -#endif - } - - _flag_usage(cmd); - return 1; -} - -#ifdef MODULE_GNRC_IPV6_NETIF -static uint8_t _get_prefix_len(char *addr) -{ - int prefix_len = ipv6_addr_split(addr, '/', SC_NETIF_IPV6_DEFAULT_PREFIX_LEN); - - if ((prefix_len < 1) || (prefix_len > IPV6_ADDR_BIT_LEN)) { - prefix_len = SC_NETIF_IPV6_DEFAULT_PREFIX_LEN; - } - - return prefix_len; -} -#endif - -static int _netif_add(char *cmd_name, kernel_pid_t dev, int argc, char **argv) -{ -#ifdef MODULE_GNRC_IPV6_NETIF - enum { - _UNICAST = 0, - _MULTICAST, /* multicast value just to check if given addr is mc */ - _ANYCAST - } type = _UNICAST; - char *addr_str = argv[0]; - ipv6_addr_t addr; - ipv6_addr_t *ifaddr; - uint8_t prefix_len, flags = 0; - - if (argc > 1) { - if (strcmp(argv[0], "anycast") == 0) { - type = _ANYCAST; - addr_str = argv[1]; - } - else if (strcmp(argv[0], "multicast") == 0) { - type = _MULTICAST; - addr_str = argv[1]; - } - else if (strcmp(argv[0], "unicast") == 0) { - /* type already set to unicast */ - addr_str = argv[1]; - } - else { - _add_usage(cmd_name); - return 1; - } - } - - prefix_len = _get_prefix_len(addr_str); - - if (ipv6_addr_from_str(&addr, addr_str) == NULL) { - puts("error: unable to parse IPv6 address."); - return 1; - } - - if ((argc > 1) && (ipv6_addr_is_multicast(&addr)) && (type != _MULTICAST)) { - puts("error: address was not a multicast address."); - return 1; - } - - flags = GNRC_IPV6_NETIF_ADDR_FLAGS_NDP_AUTO; - if (type == _ANYCAST) { - flags |= GNRC_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST; - } - else { - flags |= GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST; - } - - if ((ifaddr = gnrc_ipv6_netif_add_addr(dev, &addr, prefix_len, flags)) == NULL) { - printf("error: unable to add IPv6 address\n"); - return 1; - } - - /* Address shall be valid infinitely */ - gnrc_ipv6_netif_addr_get(ifaddr)->valid = UINT32_MAX; - /* Address shall be preferred infinitely */ - gnrc_ipv6_netif_addr_get(ifaddr)->preferred = UINT32_MAX; - - printf("success: added %s/%d to interface %" PRIkernel_pid "\n", addr_str, - prefix_len, dev); - - return 0; -#else - (void)cmd_name; - (void)dev; - (void)argc; - (void)argv; - puts("error: unable to add IPv6 address."); - - return 1; -#endif -} - -static int _netif_del(kernel_pid_t dev, char *addr_str) -{ -#ifdef MODULE_GNRC_IPV6_NETIF - ipv6_addr_t addr; - - if (ipv6_addr_from_str(&addr, addr_str) == NULL) { - puts("error: unable to parse IPv6 address."); - return 1; - } - - gnrc_ipv6_netif_remove_addr(dev, &addr); - - printf("success: removed %s to interface %" PRIkernel_pid "\n", addr_str, - dev); - - return 0; -#else - (void)dev; - (void)addr_str; - puts("error: unable to delete IPv6 address."); - return 1; -#endif -} - -static int _netif_mtu(kernel_pid_t dev, char *mtu_str) -{ -#ifdef MODULE_GNRC_IPV6_NETIF - int mtu; - gnrc_ipv6_netif_t *entry; - if (((mtu = atoi(mtu_str)) < IPV6_MIN_MTU) || (mtu > UINT16_MAX)) { - printf("error: MTU must be between %" PRIu16 " and %" PRIu16 "\n", - (uint16_t)IPV6_MIN_MTU, (uint16_t)UINT16_MAX); - return 1; - } - if ((entry = gnrc_ipv6_netif_get(dev)) == NULL) { - puts("error: unable to set MTU."); - return 1; - } - entry->mtu = mtu; - printf("success: set MTU %u interface %" PRIkernel_pid "\n", mtu, - dev); - return 0; -#else - (void)dev; - (void)mtu_str; - puts("error: unable to set MTU."); - return 1; -#endif -} - -/* shell commands */ -int _netif_send(int argc, char **argv) -{ - kernel_pid_t dev; - uint8_t addr[MAX_ADDR_LEN]; - size_t addr_len; - gnrc_pktsnip_t *pkt, *hdr; - gnrc_netif_hdr_t *nethdr; - uint8_t flags = 0x00; - - if (argc < 4) { - printf("usage: %s <if> [<L2 addr>|bcast] <data>\n", argv[0]); - return 1; - } - - /* parse interface */ - dev = atoi(argv[1]); - - if (!_is_iface(dev)) { - puts("error: invalid interface given"); - return 1; - } - - /* parse address */ - addr_len = gnrc_netif_addr_from_str(addr, sizeof(addr), argv[2]); - - if (addr_len == 0) { - if (strcmp(argv[2], "bcast") == 0) { - flags |= GNRC_NETIF_HDR_FLAGS_BROADCAST; - } - else { - puts("error: invalid address given"); - return 1; - } - } - - /* put packet together */ - pkt = gnrc_pktbuf_add(NULL, argv[3], strlen(argv[3]), GNRC_NETTYPE_UNDEF); - if (pkt == NULL) { - puts("error: packet buffer full"); - return 1; - } - hdr = gnrc_netif_hdr_build(NULL, 0, addr, addr_len); - if (hdr == NULL) { - puts("error: packet buffer full"); - gnrc_pktbuf_release(pkt); - return 1; - } - LL_PREPEND(pkt, hdr); - nethdr = (gnrc_netif_hdr_t *)hdr->data; - nethdr->flags = flags; - /* and send it */ - if (gnrc_netapi_send(dev, pkt) < 1) { - puts("error: unable to send"); - gnrc_pktbuf_release(pkt); - return 1; - } - - return 0; -} - -int _netif_config(int argc, char **argv) -{ - if (argc < 2) { - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - size_t numof = gnrc_netif_get(ifs); - - for (size_t i = 0; i < numof && i < GNRC_NETIF_NUMOF; i++) { - _netif_list(ifs[i]); - } - - return 0; - } - else if (_is_number(argv[1])) { - kernel_pid_t dev = atoi(argv[1]); - - if (_is_iface(dev)) { - if (argc < 3) { - _netif_list(dev); - return 0; - } - else if (strcmp(argv[2], "set") == 0) { - if (argc < 5) { - _set_usage(argv[0]); - return 1; - } - - return _netif_set(argv[0], dev, argv[3], argv[4]); - } - else if (strcmp(argv[2], "add") == 0) { - if (argc < 4) { - _add_usage(argv[0]); - return 1; - } - - return _netif_add(argv[0], (kernel_pid_t)dev, argc - 3, argv + 3); - } - else if (strcmp(argv[2], "del") == 0) { - if (argc < 4) { - _del_usage(argv[0]); - return 1; - } - - return _netif_del((kernel_pid_t)dev, argv[3]); - } - else if (strcmp(argv[2], "mtu") == 0) { - if (argc < 4) { - _mtu_usage(argv[0]); - return 1; - } - - return _netif_mtu((kernel_pid_t)dev, argv[3]); - } -#ifdef MODULE_L2FILTER - else if (strcmp(argv[2], "l2filter") == 0) { - if (argc < 5) { - _l2filter_usage(argv[2]); - } - else if (strcmp(argv[3], "add") == 0) { - return _netif_addrm_l2filter(dev, argv[4], true); - } - else if (strcmp(argv[3], "del") == 0) { - return _netif_addrm_l2filter(dev, argv[4], false); - } - else { - _l2filter_usage(argv[2]); - } - return 1; - } -#endif -#ifdef MODULE_NETSTATS - else if (strcmp(argv[2], "stats") == 0) { - uint8_t module; - bool reset = false; - - /* check for requested module */ - if ((argc == 3) || (strcmp(argv[3], "all") == 0)) { - module = NETSTATS_ALL; - } - else if (strcmp(argv[3], "l2") == 0) { - module = NETSTATS_LAYER2; - } - else if (strcmp(argv[3], "ipv6") == 0) { - module = NETSTATS_IPV6; - } - else { - printf("Module %s doesn't exist or does not provide statistics.\n", argv[3]); - - return 0; - } - - /* check if reset flag was given */ - if ((argc > 4) && (strncmp(argv[4], "reset", 5) == 0)) { - reset = true; - } - if (module & NETSTATS_LAYER2) { - _netif_stats((kernel_pid_t) dev, NETSTATS_LAYER2, reset); - } - if (module & NETSTATS_IPV6) { - _netif_stats((kernel_pid_t) dev, NETSTATS_IPV6, reset); - } - - return 1; - } -#endif -#ifdef MODULE_GNRC_IPV6_NETIF - else if (strcmp(argv[2], "hl") == 0) { - if (argc < 4) { - _hl_usage(argv[0]); - return 1; - } - int hl; - gnrc_ipv6_netif_t *entry; - if (((hl = atoi(argv[3])) < 0) || (hl > UINT8_MAX)) { - printf("error: Hop limit must be between %" PRIu16 " and %" PRIu16 "\n", - (uint16_t)0, (uint16_t)UINT16_MAX); - return 1; - } - if ((entry = gnrc_ipv6_netif_get(dev)) == NULL) { - puts("error: unable to set hop limit."); - return 1; - } - entry->cur_hl = hl; - printf("success: set hop limit %u interface %" PRIkernel_pid "\n", hl, dev); - - return 0; - } -#endif - else { - return _netif_flag(argv[0], dev, argv[2]); - } - } - else { - puts("error: invalid interface given"); - return 1; - } - } - - printf("usage: %s [<if_id>]\n", argv[0]); - _set_usage(argv[0]); - _mtu_usage(argv[0]); -#ifdef MODULE_GNRC_IPV6_NETIF - _hl_usage(argv[0]); -#endif - _flag_usage(argv[0]); - _add_usage(argv[0]); - _del_usage(argv[0]); -#ifdef MODULE_L2FILTER - _l2filter_usage(argv[0]); -#endif -#ifdef MODULE_NETSTATS - _stats_usage(argv[0]); -#endif - return 1; -} diff --git a/sys/shell/commands/shell_commands.c b/sys/shell/commands/shell_commands.c index fc7fc22796852b9dfe1306aa8dae4c70b4fa15db..e61b9e2552dd814299fa4bb7b8482d4fa39a17d5 100644 --- a/sys/shell/commands/shell_commands.c +++ b/sys/shell/commands/shell_commands.c @@ -200,10 +200,6 @@ const shell_command_t _shell_command_list[] = { #ifdef MODULE_FIB {"fibroute", "Manipulate the FIB (info: 'fibroute [add|del]')", _fib_route_handler}, #endif -#ifdef MODULE_GNRC_IPV6_NC - {"ncache", "manage neighbor cache by hand", _ipv6_nc_manage }, - {"routers", "IPv6 default router list", _ipv6_nc_routers }, -#endif #ifdef MODULE_GNRC_IPV6_WHITELIST {"whitelist", "whitelists an address for receival ('whitelist [add|del|help]')", _whitelist }, #endif diff --git a/tests/driver_kw2xrf/main.c b/tests/driver_kw2xrf/main.c index 8da60025a1c8fc987fff908a60909ff088e5f5d5..aba18b1b86d3a486a453b3b5f1ecb1f259316c9f 100644 --- a/tests/driver_kw2xrf/main.c +++ b/tests/driver_kw2xrf/main.c @@ -23,7 +23,6 @@ #include "kw2xrf.h" #include "shell_commands.h" #include "net/gnrc.h" -#include "net/gnrc/netif.h" #include "net/gnrc/netapi.h" #include "net/netopt.h" diff --git a/tests/driver_xbee/Makefile b/tests/driver_xbee/Makefile index c2487dfb1859ba7990dad510606dfe8234a7a447..2882e3ec64b7c291016bc8c47098a08b007850aa 100644 --- a/tests/driver_xbee/Makefile +++ b/tests/driver_xbee/Makefile @@ -7,7 +7,6 @@ BOARD_INSUFFICIENT_MEMORY := nucleo32-f031 nucleo32-f042 nucleo-f030 nucleo-f334 stm32f0discovery USEMODULE += xbee -USEMODULE += gnrc_netif USEMODULE += gnrc_txtsnd USEMODULE += auto_init_gnrc_netif USEMODULE += gnrc_pktdump diff --git a/tests/gnrc_ipv6_ext/main.c b/tests/gnrc_ipv6_ext/main.c index 3c39331f3b0e5d7896119bb4099e213894dd939e..861147451aebf55a912e19e04067e89526000666 100644 --- a/tests/gnrc_ipv6_ext/main.c +++ b/tests/gnrc_ipv6_ext/main.c @@ -24,7 +24,6 @@ #include "shell.h" #include "msg.h" #include "net/ipv6/addr.h" -#include "net/gnrc/ipv6/netif.h" #include "net/gnrc/pkt.h" #include "net/gnrc/pktbuf.h" #include "net/gnrc/netreg.h" diff --git a/tests/gnrc_sock_dns/Makefile b/tests/gnrc_sock_dns/Makefile index b6a0c0b46cd4abc09fb6b6a345911355f1db5e97..8ff2c111d103d6a69f08f159c020054755e38cd9 100644 --- a/tests/gnrc_sock_dns/Makefile +++ b/tests/gnrc_sock_dns/Makefile @@ -22,7 +22,8 @@ CFLAGS += -DDEVELHELP LOW_MEMORY_BOARDS := nucleo-f334 msb-430 msb-430h ifeq ($(BOARD),$(filter $(BOARD),$(LOW_MEMORY_BOARDS))) - CFLAGS += -DGNRC_PKTBUF_SIZE=512 -DGNRC_IPV6_NETIF_ADDR_NUMOF=4 -DGNRC_IPV6_NC_SIZE=1 + CFLAGS += -DGNRC_PKTBUF_SIZE=512 -DGNRC_NETIF2_IPV6_ADDRS_NUMOF=2 \ + -DGNRC_NETIF2_IPV6_GROUPS_NUMOF=2 -DGNRC_IPV6_NC_SIZE=1 endif include $(RIOTBASE)/Makefile.include diff --git a/tests/unittests/tests-gnrc_ipv6_nib/tests-gnrc_ipv6_nib-internal.c b/tests/unittests/tests-gnrc_ipv6_nib/tests-gnrc_ipv6_nib-internal.c index 72ebd5334a6ac952dd3ed7336b0cc1c067dc6f7e..bccaf5c3bd0fedc0e9e50ea3c3fcb833e43203b1 100644 --- a/tests/unittests/tests-gnrc_ipv6_nib/tests-gnrc_ipv6_nib-internal.c +++ b/tests/unittests/tests-gnrc_ipv6_nib/tests-gnrc_ipv6_nib-internal.c @@ -19,7 +19,6 @@ #include "net/ndp.h" #include "net/gnrc/ipv6/nib/conf.h" #include "net/gnrc/ipv6/nib.h" -#include "net/gnrc/netif.h" #include "_nib-internal.h" diff --git a/tests/unittests/tests-gnrc_netif/Makefile b/tests/unittests/tests-gnrc_netif/Makefile deleted file mode 100644 index 48422e909a47d7cd428d10fa73825060ccc8d8c2..0000000000000000000000000000000000000000 --- a/tests/unittests/tests-gnrc_netif/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(RIOTBASE)/Makefile.base diff --git a/tests/unittests/tests-gnrc_netif/Makefile.include b/tests/unittests/tests-gnrc_netif/Makefile.include deleted file mode 100644 index fe1714ad67e36553f374c757f42356e34bbe7d57..0000000000000000000000000000000000000000 --- a/tests/unittests/tests-gnrc_netif/Makefile.include +++ /dev/null @@ -1,3 +0,0 @@ -USEMODULE += gnrc_netif - -CFLAGS += -DGNRC_NETIF_NUMOF=3 diff --git a/tests/unittests/tests-gnrc_netif/tests-gnrc_netif.c b/tests/unittests/tests-gnrc_netif/tests-gnrc_netif.c deleted file mode 100644 index 09dad436694f4f8220e63776317add41d5e44346..0000000000000000000000000000000000000000 --- a/tests/unittests/tests-gnrc_netif/tests-gnrc_netif.c +++ /dev/null @@ -1,324 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @{ - * - * @file - */ -#include <errno.h> -#include <stdint.h> -#include <stdlib.h> - -#include "embUnit/embUnit.h" -#include "kernel_types.h" -#include "net/gnrc/netif.h" - -#include "unittests-constants.h" -#include "tests-gnrc_netif.h" - -static void set_up(void) -{ - gnrc_netif_init(); -} - -static void test_gnrc_netif_add__KERNEL_PID_UNDEF(void) -{ - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - size_t size; - - TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(KERNEL_PID_UNDEF)); - size = gnrc_netif_get(ifs); - TEST_ASSERT_EQUAL_INT(0, size); -} - -static void test_gnrc_netif_add__memfull(void) -{ - for (int i = 0; i < GNRC_NETIF_NUMOF; i++) { - TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(TEST_UINT8 + i)); - } - - TEST_ASSERT_EQUAL_INT(-ENOMEM, gnrc_netif_add(TEST_UINT8 - 1)); -} - -static void test_gnrc_netif_add__success(void) -{ - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - size_t size; - - TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(TEST_UINT8)); - - size = gnrc_netif_get(ifs); - TEST_ASSERT_EQUAL_INT(1, size); - TEST_ASSERT_EQUAL_INT(TEST_UINT8, ifs[0]); -} - -static void test_gnrc_netif_add__duplicate_entry(void) -{ - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - size_t size; - - for (int i = 0; i < GNRC_NETIF_NUMOF + 4; i++) { - TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(TEST_UINT8)); - } - - size = gnrc_netif_get(ifs); - TEST_ASSERT_EQUAL_INT(1, size); - TEST_ASSERT_EQUAL_INT(TEST_UINT8, ifs[0]); -} - -static void test_gnrc_netif_remove__KERNEL_PID_UNDEF(void) -{ - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - size_t size; - - test_gnrc_netif_add__success(); - - gnrc_netif_remove(KERNEL_PID_UNDEF); - - size = gnrc_netif_get(ifs); - TEST_ASSERT_EQUAL_INT(1, size); - TEST_ASSERT_EQUAL_INT(TEST_UINT8, ifs[0]); -} - -static void test_gnrc_netif_remove__not_an_if(void) -{ - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - size_t size; - - test_gnrc_netif_add__success(); - - gnrc_netif_remove(TEST_UINT8 + 1); - - size = gnrc_netif_get(ifs); - TEST_ASSERT_EQUAL_INT(1, size); - TEST_ASSERT_EQUAL_INT(TEST_UINT8, ifs[0]); -} - -static void test_gnrc_netif_remove__success(void) -{ - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - size_t size; - - test_gnrc_netif_add__success(); - - gnrc_netif_remove(TEST_UINT8); - - size = gnrc_netif_get(ifs); - TEST_ASSERT_EQUAL_INT(0, size); -} - -static void test_gnrc_netif_get__empty(void) -{ - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - size_t size = gnrc_netif_get(ifs); - - TEST_ASSERT_EQUAL_INT(0, size); -} - -/* takes one out of the middle of the gnrc_netif list and checks if all interfaces - * are gotten regardless */ -static void test_gnrc_netif_get__success_3_minus_one(void) -{ - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - size_t size; - int count = 0; - - for (int i = 0; i < 3; i++) { - TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(TEST_UINT8 + i)); - } - - gnrc_netif_remove(TEST_UINT8 + 1); - - size = gnrc_netif_get(ifs); - TEST_ASSERT_EQUAL_INT(2, size); - - for (size_t i = 0; i < size; i++) { - if ((ifs[i] == TEST_UINT8) || ifs[i] == (TEST_UINT8 + 2)) { - count++; - } - } - - TEST_ASSERT_EQUAL_INT(size, count); -} - -static void test_gnrc_netif_get__full(void) -{ - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - size_t size; - - for (int i = 0; i < GNRC_NETIF_NUMOF; i++) { - TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(TEST_UINT8 + i)); - } - - size = gnrc_netif_get(ifs); - TEST_ASSERT_EQUAL_INT(GNRC_NETIF_NUMOF, size); -} - -static void test_gnrc_netif_exist(void) -{ - TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(0)); - TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(1)); - TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(TEST_UINT8)); - - for (int i = 0; i < UINT8_MAX; i++) { - if ((i == 0) || (i == 1) || (i == TEST_UINT8)) { - TEST_ASSERT(gnrc_netif_exist(i)); - } - else { - TEST_ASSERT(!gnrc_netif_exist(i)); - } - } -} - -static void test_gnrc_netif_addr_to_str__out_too_short(void) -{ - static const uint8_t addr[] = { 0x05, 0xcd }; - char out[2]; - - TEST_ASSERT_NULL(gnrc_netif_addr_to_str(out, sizeof(out), addr, sizeof(addr))); -} - -static void test_gnrc_netif_addr_to_str__success(void) -{ - static const uint8_t addr[] = { 0x05, 0xcd }; - char out[3 * sizeof(addr)]; - - TEST_ASSERT_EQUAL_STRING("05:cd", gnrc_netif_addr_to_str(out, sizeof(out), - addr, sizeof(addr))); -} - -static void test_gnrc_netif_addr_from_str__out_too_short(void) -{ - static const char str[] = "05:cd"; - uint8_t out[1]; - - TEST_ASSERT_EQUAL_INT(0, gnrc_netif_addr_from_str(out, sizeof(out), str)); -} - -static void test_gnrc_netif_addr_from_str__omitted_delimitter(void) -{ - static const char str[] = "4567:cd"; - uint8_t out[3]; - - TEST_ASSERT_EQUAL_INT(3, gnrc_netif_addr_from_str(out, sizeof(out), str)); - TEST_ASSERT_EQUAL_INT(0x45, out[0]); - TEST_ASSERT_EQUAL_INT(0x67, out[1]); - TEST_ASSERT_EQUAL_INT(0xcd, out[2]); -} - -static void test_gnrc_netif_addr_from_str__ill_formated2(void) -{ - static const char str[] = TEST_STRING8; - uint8_t out[sizeof(str)]; - - TEST_ASSERT_EQUAL_INT(0, gnrc_netif_addr_from_str(out, sizeof(out), str)); -} - -static void test_gnrc_netif_addr_from_str__dash_delimitter(void) -{ - static const char str[] = "05-cd"; - uint8_t out[2]; - - TEST_ASSERT_EQUAL_INT(2, gnrc_netif_addr_from_str(out, sizeof(out), str)); - TEST_ASSERT_EQUAL_INT(0x05, out[0]); - TEST_ASSERT_EQUAL_INT(0xcd, out[1]); -} - -static void test_gnrc_netif_addr_from_str__zero_omitted_back(void) -{ - static const char str[] = "05:c"; - uint8_t out[2]; - - TEST_ASSERT_EQUAL_INT(2, gnrc_netif_addr_from_str(out, sizeof(out), str)); - TEST_ASSERT_EQUAL_INT(0x05, out[0]); - TEST_ASSERT_EQUAL_INT(0x0c, out[1]); -} - -static void test_gnrc_netif_addr_from_str__zero_omitted_front(void) -{ - static const char str[] = "5:cd"; - uint8_t out[2]; - - TEST_ASSERT_EQUAL_INT(2, gnrc_netif_addr_from_str(out, sizeof(out), str)); - TEST_ASSERT_EQUAL_INT(0x05, out[0]); - TEST_ASSERT_EQUAL_INT(0xcd, out[1]); -} - -static void test_gnrc_netif_addr_from_str__ill_trailing_delimitter(void) -{ - static const char str[] = "05:cd:"; - uint8_t out[sizeof(str)]; - - TEST_ASSERT_EQUAL_INT(0, gnrc_netif_addr_from_str(out, sizeof(out), str)); -} - -static void test_gnrc_netif_addr_from_str__ill_leading_delimitter(void) -{ - static const char str[] = ":05:cd"; - uint8_t out[sizeof(str)]; - - TEST_ASSERT_EQUAL_INT(0, gnrc_netif_addr_from_str(out, sizeof(out), str)); -} - -static void test_gnrc_netif_addr_from_str__ill_extra_delimitter(void) -{ - static const char str[] = "05::cd"; - uint8_t out[sizeof(str)]; - - TEST_ASSERT_EQUAL_INT(0, gnrc_netif_addr_from_str(out, sizeof(out), str)); -} - -static void test_gnrc_netif_addr_from_str__success(void) -{ - static const char str[] = "05:cd"; - uint8_t out[2]; - - TEST_ASSERT_EQUAL_INT(2, gnrc_netif_addr_from_str(out, sizeof(out), str)); - TEST_ASSERT_EQUAL_INT(0x05, out[0]); - TEST_ASSERT_EQUAL_INT(0xcd, out[1]); -} - -Test *tests_gnrc_netif_tests(void) -{ - EMB_UNIT_TESTFIXTURES(fixtures) { - new_TestFixture(test_gnrc_netif_add__KERNEL_PID_UNDEF), - new_TestFixture(test_gnrc_netif_add__memfull), - new_TestFixture(test_gnrc_netif_add__success), - new_TestFixture(test_gnrc_netif_add__duplicate_entry), - new_TestFixture(test_gnrc_netif_remove__KERNEL_PID_UNDEF), - new_TestFixture(test_gnrc_netif_remove__not_an_if), - new_TestFixture(test_gnrc_netif_remove__success), - new_TestFixture(test_gnrc_netif_get__empty), - new_TestFixture(test_gnrc_netif_get__success_3_minus_one), - new_TestFixture(test_gnrc_netif_get__full), - new_TestFixture(test_gnrc_netif_exist), - new_TestFixture(test_gnrc_netif_addr_to_str__out_too_short), - new_TestFixture(test_gnrc_netif_addr_to_str__success), - new_TestFixture(test_gnrc_netif_addr_from_str__out_too_short), - new_TestFixture(test_gnrc_netif_addr_from_str__omitted_delimitter), - new_TestFixture(test_gnrc_netif_addr_from_str__ill_formated2), - new_TestFixture(test_gnrc_netif_addr_from_str__dash_delimitter), - new_TestFixture(test_gnrc_netif_addr_from_str__zero_omitted_back), - new_TestFixture(test_gnrc_netif_addr_from_str__zero_omitted_front), - new_TestFixture(test_gnrc_netif_addr_from_str__ill_trailing_delimitter), - new_TestFixture(test_gnrc_netif_addr_from_str__ill_leading_delimitter), - new_TestFixture(test_gnrc_netif_addr_from_str__ill_extra_delimitter), - new_TestFixture(test_gnrc_netif_addr_from_str__success), - }; - - EMB_UNIT_TESTCALLER(gnrc_netif_tests, set_up, NULL, fixtures); - - return (Test *)&gnrc_netif_tests; -} - -void tests_gnrc_netif(void) -{ - TESTS_RUN(tests_gnrc_netif_tests()); -} -/** @} */ diff --git a/tests/unittests/tests-gnrc_netif/tests-gnrc_netif.h b/tests/unittests/tests-gnrc_netif/tests-gnrc_netif.h deleted file mode 100644 index 3b6bbbf3fa23dee16df1f68472ab127228c9dc81..0000000000000000000000000000000000000000 --- a/tests/unittests/tests-gnrc_netif/tests-gnrc_netif.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2014 Martine Lenders <mlenders@inf.fu-berlin.de> - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @addtogroup unittests - * @{ - * - * @file - * @brief Unittests for the ``gnrc_netif`` module - * - * @author Martine Lenders <mlenders@inf.fu-berlin.de> - */ -#ifndef TESTS_GNRC_NETIF_H -#define TESTS_GNRC_NETIF_H - -#include "embUnit.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief The entry point of this test suite. - */ -void tests_gnrc_netif(void); - -#ifdef __cplusplus -} -#endif - -#endif /* TESTS_GNRC_NETIF_H */ -/** @} */