From 71a7dbf91856dc221a5615e29587c6b8309b08d2 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 16 Nov 2017 17:00:40 +0100 Subject: [PATCH] gnrc: remove legacy network interface structures --- examples/gnrc_minimal/Makefile | 3 +- sys/auto_init/auto_init.c | 4 - sys/include/net/gnrc/ipv6/nc.h | 1 - sys/include/net/gnrc/ipv6/netif.h | 622 -------- sys/include/net/gnrc/ndp.h | 15 - sys/include/net/gnrc/ndp/host.h | 21 - sys/include/net/gnrc/ndp/router.h | 39 - sys/include/net/gnrc/netif.h | 146 -- sys/include/net/gnrc/rpl/structs.h | 1 - sys/include/net/gnrc/sixlowpan.h | 9 +- sys/include/net/gnrc/sixlowpan/nd/router.h | 3 - sys/include/net/gnrc/sixlowpan/netif.h | 77 - sys/net/gnrc/Makefile | 9 - sys/net/gnrc/netif/Makefile | 3 - sys/net/gnrc/netif/gnrc_netif.c | 110 -- sys/net/gnrc/netif/gnrc_netif_addr_from_str.c | 90 -- sys/net/gnrc/netif/gnrc_netif_addr_to_str.c | 48 - sys/net/gnrc/nettest/gnrc_nettest.c | 5 - .../icmpv6/error/gnrc_icmpv6_error.c | 1 - sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c | 2 +- .../gnrc/network_layer/ipv6/netif/Makefile | 3 - .../ipv6/netif/gnrc_ipv6_netif.c | 924 ------------ .../gnrc/network_layer/sixlowpan/frag/rbuf.c | 4 +- .../sixlowpan/nd/gnrc_sixlowpan_nd.c | 1 - .../network_layer/sixlowpan/netif/Makefile | 3 - .../sixlowpan/netif/gnrc_sixlowpan_netif.c | 79 - sys/net/gnrc/sock/gnrc_sock.c | 1 - sys/net/routing/nhdp/nhdp.c | 1 - sys/shell/commands/Makefile | 8 +- sys/shell/commands/sc_gnrc_6ctx.c | 10 +- sys/shell/commands/sc_gnrc_ipv6_nib.c | 2 +- sys/shell/commands/sc_ipv6_nc.c | 14 - sys/shell/commands/sc_netif.c | 1339 ----------------- tests/driver_kw2xrf/main.c | 1 - tests/driver_xbee/Makefile | 1 - tests/gnrc_ipv6_ext/main.c | 1 - tests/gnrc_sock_dns/Makefile | 3 +- .../tests-gnrc_ipv6_nib-internal.c | 1 - tests/unittests/tests-gnrc_netif/Makefile | 1 - .../tests-gnrc_netif/Makefile.include | 3 - .../tests-gnrc_netif/tests-gnrc_netif.c | 324 ---- .../tests-gnrc_netif/tests-gnrc_netif.h | 37 - 42 files changed, 15 insertions(+), 3955 deletions(-) delete mode 100644 sys/include/net/gnrc/ipv6/netif.h delete mode 100644 sys/include/net/gnrc/netif.h delete mode 100644 sys/include/net/gnrc/sixlowpan/netif.h delete mode 100644 sys/net/gnrc/netif/Makefile delete mode 100644 sys/net/gnrc/netif/gnrc_netif.c delete mode 100644 sys/net/gnrc/netif/gnrc_netif_addr_from_str.c delete mode 100644 sys/net/gnrc/netif/gnrc_netif_addr_to_str.c delete mode 100644 sys/net/gnrc/network_layer/ipv6/netif/Makefile delete mode 100644 sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c delete mode 100644 sys/net/gnrc/network_layer/sixlowpan/netif/Makefile delete mode 100644 sys/net/gnrc/network_layer/sixlowpan/netif/gnrc_sixlowpan_netif.c delete mode 100644 sys/shell/commands/sc_netif.c delete mode 100644 tests/unittests/tests-gnrc_netif/Makefile delete mode 100644 tests/unittests/tests-gnrc_netif/Makefile.include delete mode 100644 tests/unittests/tests-gnrc_netif/tests-gnrc_netif.c delete mode 100644 tests/unittests/tests-gnrc_netif/tests-gnrc_netif.h diff --git a/examples/gnrc_minimal/Makefile b/examples/gnrc_minimal/Makefile index 63abb60752..69a5b7c396 100644 --- a/examples/gnrc_minimal/Makefile +++ b/examples/gnrc_minimal/Makefile @@ -26,7 +26,8 @@ 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 450916b27f..42abc69ed6 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/ipv6/nc.h b/sys/include/net/gnrc/ipv6/nc.h index c233d90b94..9672c90373 100644 --- a/sys/include/net/gnrc/ipv6/nc.h +++ b/sys/include/net/gnrc/ipv6/nc.h @@ -29,7 +29,6 @@ #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" diff --git a/sys/include/net/gnrc/ipv6/netif.h b/sys/include/net/gnrc/ipv6/netif.h deleted file mode 100644 index 11f4271ef8..0000000000 --- a/sys/include/net/gnrc/ipv6/netif.h +++ /dev/null @@ -1,622 +0,0 @@ -/* - * Copyright (C) 2014 Martine Lenders - * - * 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 - */ - -#ifndef NET_GNRC_IPV6_NETIF_H -#define NET_GNRC_IPV6_NETIF_H - -#include -#include -#include - -#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 - * RFC 4861, section 6.3.2 - * - * @see - * IANA, IP TIME TO LIVE PARAMETER - * - */ -#define GNRC_IPV6_NETIF_DEFAULT_HL (64) - -/** - * @name Default values for router configuration - * @{ - * @see - * RFC 4861, section 6.2.1 - * - */ -/** - * @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 - * RFC 4291, section 2.6 - * - */ -#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 - * RFC 4861, section 6.2.1 - * - */ -#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 - * RFC 4861, section 6.2.1 - * - */ -#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 RFC4861, - * section 4.2, RFC6275, - * section 7.1, RFC4191, - * section 2.2, and RFC4389, - * section 4.1.3.3. - */ -/** - * @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 - * RFC 4861, section 6.2.1 - * - */ - /** - * @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 - * RFC 4291, section 2.6 - * - * - * @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 index df745947ff..3397437627 100644 --- a/sys/include/net/gnrc/ndp.h +++ b/sys/include/net/gnrc/ndp.h @@ -30,7 +30,6 @@ #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" @@ -271,20 +270,6 @@ void gnrc_ndp_retrans_nbr_sol(gnrc_ipv6_nc_t *nc_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. diff --git a/sys/include/net/gnrc/ndp/host.h b/sys/include/net/gnrc/ndp/host.h index deebb6a302..c67090a3d3 100644 --- a/sys/include/net/gnrc/ndp/host.h +++ b/sys/include/net/gnrc/ndp/host.h @@ -21,31 +21,10 @@ #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 diff --git a/sys/include/net/gnrc/ndp/router.h b/sys/include/net/gnrc/ndp/router.h index 21e78e9709..86a2a73921 100644 --- a/sys/include/net/gnrc/ndp/router.h +++ b/sys/include/net/gnrc/ndp/router.h @@ -33,45 +33,6 @@ 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 - * RFC 4861, section 6.2.2 - * - * @see - * RFC 4861, section 6.2.5 - * - * - * @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. diff --git a/sys/include/net/gnrc/netif.h b/sys/include/net/gnrc/netif.h deleted file mode 100644 index c92f33bbdc..0000000000 --- a/sys/include/net/gnrc/netif.h +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders - * - * 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 - * @author Oliver Hahm - */ -#ifndef NET_GNRC_NETIF_H -#define NET_GNRC_NETIF_H - -#include -#include -#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 753d4645d0..b192163c2a 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 1f9b4a9e25..219bfc422c 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 * RFC 6282. 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 RFC 4944 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 index 302a858f90..3c11d6acce 100644 --- a/sys/include/net/gnrc/sixlowpan/nd/router.h +++ b/sys/include/net/gnrc/sixlowpan/nd/router.h @@ -24,7 +24,6 @@ #include "bitfield.h" #include "net/gnrc/sixlowpan/ctx.h" -#include "net/gnrc/ipv6/netif.h" #ifdef __cplusplus extern "C" { @@ -56,8 +55,6 @@ extern "C" { */ 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; /** diff --git a/sys/include/net/gnrc/sixlowpan/netif.h b/sys/include/net/gnrc/sixlowpan/netif.h deleted file mode 100644 index c6a7a28510..0000000000 --- a/sys/include/net/gnrc/sixlowpan/netif.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders - * - * 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 - */ -#ifndef NET_GNRC_SIXLOWPAN_NETIF_H -#define NET_GNRC_SIXLOWPAN_NETIF_H - -#include - -#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 1d01eaa27e..a26ecff645 100644 --- a/sys/net/gnrc/Makefile +++ b/sys/net/gnrc/Makefile @@ -19,9 +19,6 @@ 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 @@ -55,9 +52,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 @@ -115,9 +109,6 @@ 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 84295e48c1..0000000000 --- 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 d9df5786fc..0000000000 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders - * 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 -#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 0915488bbc..0000000000 --- a/sys/net/gnrc/netif/gnrc_netif_addr_from_str.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders - * Copyright (C) 2015 René Kijewski - * - * 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 41d0453f1c..0000000000 --- a/sys/net/gnrc/netif/gnrc_netif_addr_to_str.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders - * - * 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 6838b81139..bce9c20ad2 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 80a6773bdd..4313414c45 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/ipv6/gnrc_ipv6.c b/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c index 7fd41fb085..664eb2682c 100644 --- a/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c +++ b/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c @@ -414,7 +414,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/netif/Makefile b/sys/net/gnrc/network_layer/ipv6/netif/Makefile deleted file mode 100644 index 5913859c40..0000000000 --- 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 b9bf3934d4..0000000000 --- a/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c +++ /dev/null @@ -1,924 +0,0 @@ -/* - * Copyright (C) 2014 Martin Lenders - * Copyright (C) 2015 Oliver Hahm - * - * 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 - * @author Oliver Hahm - */ - -#include -#include - -#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 -#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 - * RFC6724, section 4 - * - * @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 - * RFC6724, section 5 - * - * - * @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/sixlowpan/frag/rbuf.c b/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c index 5d8331c0c2..cb99b6a3d2 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 #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 7b3526051a..a2a3449484 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 758ba59edb..0000000000 --- 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 6046d9b425..0000000000 --- a/sys/net/gnrc/network_layer/sixlowpan/netif/gnrc_sixlowpan_netif.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders - * - * 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 65c88876cf..0f66aeea79 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 4665f7746f..0897c81272 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 fc7d1e199d..09d4280498 100644 --- a/sys/shell/commands/Makefile +++ b/sys/shell/commands/Makefile @@ -23,9 +23,6 @@ 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 @@ -44,12 +41,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 1af9b80974..32232e2188 100644 --- a/sys/shell/commands/sc_gnrc_6ctx.c +++ b/sys/shell/commands/sc_gnrc_6ctx.c @@ -60,15 +60,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 83f6c5c698..544f360e32 100644 --- a/sys/shell/commands/sc_gnrc_ipv6_nib.c +++ b/sys/shell/commands/sc_gnrc_ipv6_nib.c @@ -16,7 +16,7 @@ #include #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_ipv6_nc.c b/sys/shell/commands/sc_ipv6_nc.c index ae4d9cac27..88f16e768f 100644 --- a/sys/shell/commands/sc_ipv6_nc.c +++ b/sys/shell/commands/sc_ipv6_nc.c @@ -21,7 +21,6 @@ #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 */ @@ -87,20 +86,7 @@ static void _print_nc_type(gnrc_ipv6_nc_t *entry) 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) diff --git a/sys/shell/commands/sc_netif.c b/sys/shell/commands/sc_netif.c deleted file mode 100644 index 5b8af6c190..0000000000 --- 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 - * @author Martine Lenders - * @author Oliver Hahm - */ - -#include -#include -#include -#include -#include -#include - -#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 set \n", cmd_name); - puts(" Sets an hardware specific specific value\n" - " 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 mtu \n", cmd_name); -} - -#ifdef MODULE_GNRC_IPV6_NETIF -static void _hl_usage(char *cmd_name) -{ - printf("usage: %s hl \n", cmd_name); -} -#endif - -static void _flag_usage(char *cmd_name) -{ - printf("usage: %s [-]{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 add [anycast|multicast|unicast] " - "[/prefix_len]\n", cmd_name); -} - -static void _del_usage(char *cmd_name) -{ - printf("usage: %s del \n", - cmd_name); -} - -#ifdef MODULE_NETSTATS -static void _stats_usage(char *cmd_name) -{ - printf("usage: %s 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 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 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 l2filter {add|del} \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 [|bcast] \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 []\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/tests/driver_kw2xrf/main.c b/tests/driver_kw2xrf/main.c index 8da60025a1..aba18b1b86 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 c2487dfb18..2882e3ec64 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 3c39331f3b..861147451a 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 b6a0c0b46c..8ff2c111d1 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 72ebd5334a..bccaf5c3bd 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 48422e909a..0000000000 --- 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 fe1714ad67..0000000000 --- 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 09dad43669..0000000000 --- a/tests/unittests/tests-gnrc_netif/tests-gnrc_netif.c +++ /dev/null @@ -1,324 +0,0 @@ -/* - * Copyright (C) 2015 Martine Lenders - * - * 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 -#include -#include - -#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 3b6bbbf3fa..0000000000 --- a/tests/unittests/tests-gnrc_netif/tests-gnrc_netif.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2014 Martine Lenders - * - * 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 - */ -#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 */ -/** @} */