mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
gnrc: remove legacy network interface structures
This commit is contained in:
parent
7ecafb7909
commit
71a7dbf918
@ -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
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
||||
|
@ -1,622 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser General
|
||||
* Public License v2.1. See the file LICENSE in the top level directory for
|
||||
* more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup net_gnrc_ipv6_netif IPv6 network interfaces
|
||||
* @ingroup net_gnrc_ipv6
|
||||
* @brief IPv6 specific information on @ref net_gnrc_netif.
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Definitions for IPv6 specific information of network interfaces.
|
||||
*
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
|
||||
#ifndef NET_GNRC_IPV6_NETIF_H
|
||||
#define NET_GNRC_IPV6_NETIF_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "kernel_defines.h"
|
||||
#include "kernel_types.h"
|
||||
#include "mutex.h"
|
||||
#include "net/ipv6.h"
|
||||
#include "net/ipv6/addr.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
#ifdef MODULE_NETSTATS_IPV6
|
||||
#include "net/netstats.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @cond INTERNAL
|
||||
*/
|
||||
#ifdef MODULE_GNRC_RPL
|
||||
/* RPL needs all-RPL-nodes multicast address */
|
||||
# define GNRC_IPV6_NETIF_RPL_ADDR (1)
|
||||
#else
|
||||
# define GNRC_IPV6_NETIF_RPL_ADDR (0)
|
||||
#endif
|
||||
#ifdef MODULE_GNRC_IPV6_ROUTER
|
||||
/* routers need all-routers multicast address */
|
||||
# define GNRC_IPV6_NETIF_RTR_ADDR (1)
|
||||
#else
|
||||
# define GNRC_IPV6_NETIF_RTR_ADDR (0)
|
||||
#endif
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
/**
|
||||
* @brief Number of IPv6 addresses per interface.
|
||||
*/
|
||||
#ifndef GNRC_IPV6_NETIF_ADDR_NUMOF
|
||||
#define GNRC_IPV6_NETIF_ADDR_NUMOF (6 + GNRC_IPV6_NETIF_RPL_ADDR + GNRC_IPV6_NETIF_RTR_ADDR)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Default MTU
|
||||
*
|
||||
* An interface will choose this MTU if the link-layer's maximum packet size
|
||||
* (see @ref NETOPT_MAX_PACKET_SIZE) is lesser than the @ref IPV6_MIN_MTU or if it just not
|
||||
* provide it. For RFC-compatible communication it must be at least @ref IPV6_MIN_MTU.
|
||||
*
|
||||
* @note If the scenario the node is used in allows for it and the packet size is predictable,
|
||||
* a user might choose to set @ref GNRC_IPV6_NETIF_DEFAULT_MTU to a lesser value than
|
||||
* @ref IPV6_MIN_MTU to optimize for code size (e.g. because it is then possible to omit
|
||||
* @ref net_gnrc_sixlowpan_frag) and memory usage (e.g. because @ref GNRC_PKTBUF_SIZE
|
||||
* can be much smaller).
|
||||
*/
|
||||
#ifndef GNRC_IPV6_NETIF_DEFAULT_MTU
|
||||
#define GNRC_IPV6_NETIF_DEFAULT_MTU (IPV6_MIN_MTU)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Default hop limit
|
||||
*
|
||||
* @see <a href="https://tools.ietf.org/html/rfc4861#section-6.3.2">
|
||||
* RFC 4861, section 6.3.2
|
||||
* </a>
|
||||
* @see <a href="http://www.iana.org/assignments/ip-parameters/ip-parameters.xhtml#ip-parameters-2">
|
||||
* IANA, IP TIME TO LIVE PARAMETER
|
||||
* </a>
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_DEFAULT_HL (64)
|
||||
|
||||
/**
|
||||
* @name Default values for router configuration
|
||||
* @{
|
||||
* @see <a href="https://tools.ietf.org/html/rfc4861#section-6.2.1">
|
||||
* RFC 4861, section 6.2.1
|
||||
* </a>
|
||||
*/
|
||||
/**
|
||||
* @brief Maximum time in seconds between sending unsolicited multicast router advertisements.
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_DEFAULT_MAX_ADV_INT (600U)
|
||||
|
||||
/**
|
||||
* @brief Minimum time in seconds between sending unsolicited multicast router advertisements.
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_DEFAULT_MIN_ADV_INT (200U)
|
||||
|
||||
/**
|
||||
* @brief The router lifetime to propagate in router advertisements.
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_DEFAULT_ROUTER_LTIME (1800U)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @{
|
||||
* @name Flags for a registered IPv6 address.
|
||||
* @brief Needed primarily to identify addresses as either anycast or unicast.
|
||||
*
|
||||
* @see <a href="https://tools.ietf.org/html/rfc4291#section-2.6">
|
||||
* RFC 4291, section 2.6
|
||||
* </a>
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST (0x00) /**< unicast address */
|
||||
#define GNRC_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST (0x01) /**< non-unicast address */
|
||||
|
||||
/**
|
||||
* @brief A prefix information option that propagates the prefix of this
|
||||
* address should set the autonomous flag.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc4861#section-6.2.1">
|
||||
* RFC 4861, section 6.2.1
|
||||
* </a>
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_ADDR_FLAGS_NDP_AUTO (0x40)
|
||||
|
||||
/**
|
||||
* @brief A prefix information option that propagates the prefix of this
|
||||
* address should set the on-link flag.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc4861#section-6.2.1">
|
||||
* RFC 4861, section 6.2.1
|
||||
* </a>
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_ADDR_FLAGS_NDP_ON_LINK (0x80)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @{
|
||||
* @name Flags for the interfaces
|
||||
*
|
||||
* @note The most-significant byte of these flags is identical to the flags in
|
||||
* IPv6 router advertisements. See <a
|
||||
* href="https://tools.ietf.org/html/rfc4861#section-4.2">RFC4861,
|
||||
* section 4.2</a>, <a
|
||||
* href="https://tools.ietf.org/html/rfc6275#section-7.1">RFC6275,
|
||||
* section 7.1</a>, <a
|
||||
* href="https://tools.ietf.org/html/rfc4191#section-2.2">RFC4191,
|
||||
* section 2.2</a>, and <a
|
||||
* href="https://tools.ietf.org/html/rfc4389#section-4.1.3.3">RFC4389,
|
||||
* section 4.1.3.3</a>.
|
||||
*/
|
||||
/**
|
||||
* @brief Interface is 6LoWPAN interface.
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN (0x0001)
|
||||
|
||||
/**
|
||||
* @brief Flag to indicate that routing is enabled on the interface.
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_FLAGS_ROUTER (0x0002)
|
||||
|
||||
/**
|
||||
* @brief Flag to indicate that the interface sends periodic router
|
||||
* advertisements and in response to router solicitations.
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_FLAGS_RTR_ADV (0x0004)
|
||||
|
||||
/**
|
||||
* @brief Flag to indicate that gnrc_ipv6_netif_t::mtu shall be propagated
|
||||
* with the MTU options in router advertisements.
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_FLAGS_ADV_MTU (0x0008)
|
||||
|
||||
/**
|
||||
* @brief Flag to indicate that gnrc_ipv6_netif_t::cur_hl shall be propagated
|
||||
* in router advertisements.
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_FLAGS_ADV_CUR_HL (0x0010)
|
||||
|
||||
/**
|
||||
* @brief Flag to indicate that gnrc_ipv6_netif_t::reach_time shall be propagated
|
||||
* in router advertisements.
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_FLAGS_ADV_REACH_TIME (0x0020)
|
||||
|
||||
/**
|
||||
* @brief Flag to indicate that gnrc_ipv6_netif_t::retrans_timer shall be propagated
|
||||
* in router advertisements.
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_FLAGS_ADV_RETRANS_TIMER (0x0040)
|
||||
|
||||
/**
|
||||
* @brief Flag to indicate if the interface is operating over a wired link
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_FLAGS_IS_WIRED (0x0080)
|
||||
|
||||
/**
|
||||
* @brief Offset of the router advertisement flags compared to the position in router
|
||||
* advertisements.
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_FLAGS_RTR_ADV_POS (8U)
|
||||
|
||||
/**
|
||||
* @brief Mask for flags intended for router advertisements.
|
||||
* @note Please expand if more router advertisement flags are introduced.
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_FLAGS_RTR_ADV_MASK (0xc000)
|
||||
|
||||
/**
|
||||
* @brief Flag to indicate that the interface has other address
|
||||
* configuration.
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_FLAGS_OTHER_CONF (0x4000)
|
||||
|
||||
/**
|
||||
* @brief Flag to indicate that the interface has managed address
|
||||
* configuration (e.g. via DHCPv6).
|
||||
*/
|
||||
#define GNRC_IPV6_NETIF_FLAGS_MANAGED (0x8000)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Type to represent an IPv6 address registered to an interface.
|
||||
*/
|
||||
typedef struct {
|
||||
ipv6_addr_t addr; /**< The address data */
|
||||
uint8_t flags; /**< flags */
|
||||
uint8_t prefix_len; /**< length of the prefix of the address */
|
||||
/**
|
||||
* @{
|
||||
* @name Neigbour discovery variables for prefixes
|
||||
* @see <a href="https://tools.ietf.org/html/rfc4861#section-6.2.1">
|
||||
* RFC 4861, section 6.2.1
|
||||
* </a>
|
||||
*/
|
||||
/**
|
||||
* @brief The time in seconds this address is valid. If it is UINT32_MAX
|
||||
* the lifetime is infinite.
|
||||
*/
|
||||
uint32_t valid;
|
||||
|
||||
/**
|
||||
* @brief The length of time that this address remains preferred.
|
||||
* If it is UINT32_MAX the lifetime is infinite.
|
||||
* It **must** be < gnrc_ipv6_netif_addr_t::valid.
|
||||
*/
|
||||
uint32_t preferred;
|
||||
/**
|
||||
* @brief Validity timeout timer.
|
||||
*/
|
||||
xtimer_t valid_timeout;
|
||||
msg_t valid_timeout_msg; /**< msg_t for gnrc_ipv6_netif_addr_t::valid_timeout */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
} gnrc_ipv6_netif_addr_t;
|
||||
|
||||
/**
|
||||
* @brief Definition of IPv6 interface type.
|
||||
*/
|
||||
typedef struct {
|
||||
/**
|
||||
* @brief addresses registered to the interface
|
||||
*/
|
||||
gnrc_ipv6_netif_addr_t addrs[GNRC_IPV6_NETIF_ADDR_NUMOF];
|
||||
mutex_t mutex; /**< mutex for the interface */
|
||||
kernel_pid_t pid; /**< PID of the interface */
|
||||
uint16_t flags; /**< flags for 6LoWPAN and Neighbor Discovery */
|
||||
uint16_t mtu; /**< Maximum Transmission Unit (MTU) of the interface */
|
||||
uint8_t cur_hl; /**< current hop limit for the interface */
|
||||
#if defined(MODULE_GNRC_NDP_HOST) || defined(MODULE_GNRC_SIXLOWPAN_ND)
|
||||
/**
|
||||
* @brief Counter for send router solicitations.
|
||||
*/
|
||||
uint8_t rtr_sol_count;
|
||||
#endif
|
||||
#ifdef MODULE_GNRC_NDP_ROUTER
|
||||
/**
|
||||
* @brief Counter for initial router advertisements.
|
||||
*/
|
||||
uint8_t rtr_adv_count;
|
||||
|
||||
/**
|
||||
* @brief Maximum time in seconds between sending unsolicited multicast
|
||||
* router advertisements. Must be between 4 and 1800 seconds.
|
||||
* The default value is @ref GNRC_IPV6_NETIF_DEFAULT_MAX_ADV_INT.
|
||||
*/
|
||||
uint16_t max_adv_int;
|
||||
|
||||
/**
|
||||
* @brief Minimum time in seconds between sending unsolicited multicast
|
||||
* router advertisements. Must be between 3 and
|
||||
* 3/4 * gnrc_ipv6_netif_t::max_adv_int seconds.
|
||||
* The default value is @ref GNRC_IPV6_NETIF_DEFAULT_MIN_ADV_INT.
|
||||
*/
|
||||
uint16_t min_adv_int;
|
||||
|
||||
#endif
|
||||
#if defined (MODULE_GNRC_NDP_ROUTER) || defined (MODULE_GNRC_SIXLOWPAN_ND_ROUTER)
|
||||
/**
|
||||
* @brief The router lifetime to propagate in router advertisements.
|
||||
* Must be either 0 or between gnrc_ipv6_netif_t::max_adv_int and
|
||||
* 9000 seconds. 0 means this router is not to be used as a default
|
||||
* router. The default value is @ref GNRC_IPV6_NETIF_DEFAULT_ROUTER_LTIME.
|
||||
*/
|
||||
uint16_t adv_ltime;
|
||||
#endif
|
||||
/**
|
||||
* @brief Base value in microseconds for computing random
|
||||
* gnrc_ipv6_netif_t::reach_time.
|
||||
* The default value is @ref GNRC_NDP_REACH_TIME.
|
||||
*/
|
||||
uint32_t reach_time_base;
|
||||
|
||||
/**
|
||||
* @brief The time a neighbor is considered reachable after receiving
|
||||
* a reachability confirmation.
|
||||
* Should be uniformly distributed between @ref GNRC_NDP_MIN_RAND
|
||||
* and GNRC_NDP_MAX_RAND multiplied with
|
||||
* gnrc_ipv6_netif_t::reach_time_base microseconds devided by 10.
|
||||
* Can't be greater than 1 hour.
|
||||
*/
|
||||
uint32_t reach_time;
|
||||
|
||||
/**
|
||||
* @brief Time between retransmissions of neighbor solicitations to a
|
||||
* neighbor.
|
||||
* The default value is @ref GNRC_NDP_RETRANS_TIMER.
|
||||
*/
|
||||
uint32_t retrans_timer;
|
||||
xtimer_t rtr_sol_timer; /**< Timer for periodic router solicitations */
|
||||
msg_t rtr_sol_msg; /**< msg_t for gnrc_ipv6_netif_t::rtr_sol_timer */
|
||||
#if defined (MODULE_GNRC_NDP_ROUTER) || defined (MODULE_GNRC_SIXLOWPAN_ND_ROUTER)
|
||||
xtimer_t rtr_adv_timer; /**< Timer for periodic router advertisements */
|
||||
msg_t rtr_adv_msg; /**< msg_t for gnrc_ipv6_netif_t::rtr_adv_timer */
|
||||
#endif
|
||||
#ifdef MODULE_NETSTATS_IPV6
|
||||
netstats_t stats; /**< transceiver's statistics */
|
||||
#endif
|
||||
} gnrc_ipv6_netif_t;
|
||||
|
||||
/**
|
||||
* @brief Initializes the module.
|
||||
*/
|
||||
void gnrc_ipv6_netif_init(void);
|
||||
|
||||
/**
|
||||
* @brief Add interface to IPv6.
|
||||
*
|
||||
* @details This function will be called by @ref gnrc_netif_add().
|
||||
*
|
||||
* @param[in] pid The PID to the interface.
|
||||
*/
|
||||
void gnrc_ipv6_netif_add(kernel_pid_t pid);
|
||||
|
||||
/**
|
||||
* @brief Remove interface from IPv6.
|
||||
*
|
||||
* @details This function will be called by @ref gnrc_netif_remove().
|
||||
*
|
||||
* @param[in] pid The PID to the interface.
|
||||
*/
|
||||
void gnrc_ipv6_netif_remove(kernel_pid_t pid);
|
||||
|
||||
/**
|
||||
* @brief Get interface.
|
||||
*
|
||||
* @param[in] pid The PID to the interface.
|
||||
*
|
||||
* @return The interface describing structure, on success.
|
||||
* @return NULL, if there is no interface with PID @p pid.
|
||||
*/
|
||||
gnrc_ipv6_netif_t *gnrc_ipv6_netif_get(kernel_pid_t pid);
|
||||
|
||||
#if (defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER))
|
||||
/**
|
||||
* @brief Set interface to router mode.
|
||||
*
|
||||
* @details This sets/unsets the GNRC_IPV6_NETIF_FLAGS_ROUTER and initializes
|
||||
* or ceases router behavior for neighbor discovery.
|
||||
*
|
||||
* @param[in] netif The interface.
|
||||
* @param[in] enable Status for the GNRC_IPV6_NETIF_FLAGS_ROUTER flag.
|
||||
*/
|
||||
void gnrc_ipv6_netif_set_router(gnrc_ipv6_netif_t *netif, bool enable);
|
||||
|
||||
/**
|
||||
* @brief Set interface to router advertisement mode.
|
||||
*
|
||||
* @details If GNRC_IPV6_NETIF_FLAGS_ROUTER is set this sets/unsets the
|
||||
* GNRC_IPV6_NETIF_FLAGS_RTR_ADV and initializes or ceases router
|
||||
* advertising behavior for neighbor discovery.
|
||||
*
|
||||
* @param[in] netif The interface.
|
||||
* @param[in] enable Status for the GNRC_IPV6_NETIF_FLAGS_RTR flag.
|
||||
*/
|
||||
void gnrc_ipv6_netif_set_rtr_adv(gnrc_ipv6_netif_t *netif, bool enable);
|
||||
#else
|
||||
/* dummy macros to be able to "call" these functions when none of the relevant modules
|
||||
* is implemented */
|
||||
#define gnrc_ipv6_netif_set_router(netif, enable)
|
||||
#define gnrc_ipv6_netif_set_rtr_adv(netif, enable)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Adds an address to an interface.
|
||||
*
|
||||
* @param[in] pid The PID to the interface.
|
||||
* @param[in] addr An address you want to add to the interface.
|
||||
* @param[in] prefix_len Length of the prefix of the address.
|
||||
* Must be between 1 and 128.
|
||||
* @param[in] flags Flags for the address entry
|
||||
* If @p addr should be an anycast address, @p flags
|
||||
* must have @ref GNRC_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST
|
||||
* set. Otherwise leave it unset.
|
||||
* If @p addr is a multicast address, the status of
|
||||
* @ref GNRC_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST will be
|
||||
* ignored and set in either case.
|
||||
*
|
||||
* @see <a href="https://tools.ietf.org/html/rfc4291#section-2.6">
|
||||
* RFC 4291, section 2.6
|
||||
* </a>
|
||||
*
|
||||
* @return The address on the interface, on success.
|
||||
* @return NULL, on failure
|
||||
*/
|
||||
ipv6_addr_t *gnrc_ipv6_netif_add_addr(kernel_pid_t pid, const ipv6_addr_t *addr, uint8_t prefix_len,
|
||||
uint8_t flags);
|
||||
|
||||
/**
|
||||
* @brief Remove an address from the interface.
|
||||
*
|
||||
* @param[in] pid The PID to the interface. If @p pid is KERNEL_PID_UNDEF
|
||||
* it will be removed from all interfaces.
|
||||
* @param[in] addr An address you want to remove from interface.
|
||||
*/
|
||||
void gnrc_ipv6_netif_remove_addr(kernel_pid_t pid, ipv6_addr_t *addr);
|
||||
|
||||
/**
|
||||
* @brief Removes all addresses from the interface.
|
||||
*
|
||||
* @param[in] pid The PID to the interface.
|
||||
*/
|
||||
void gnrc_ipv6_netif_reset_addr(kernel_pid_t pid);
|
||||
|
||||
/**
|
||||
* @brief Searches for an address on all interfaces.
|
||||
*
|
||||
* @param[out] out The reference to the address on the interface.
|
||||
* @param[in] addr The address you want to search for.
|
||||
*
|
||||
* @return The PID to the interface the address is registered to.
|
||||
* @return KERNEL_PID_UNDEF, if the address can not be found on any interface.
|
||||
*/
|
||||
kernel_pid_t gnrc_ipv6_netif_find_by_addr(ipv6_addr_t **out, const ipv6_addr_t *addr);
|
||||
|
||||
/**
|
||||
* @brief Searches for an address on an interface.
|
||||
*
|
||||
* @param[in] pid The PID to the interface.
|
||||
* @param[in] addr The address you want to search for.
|
||||
*
|
||||
* @return The reference to the address on the interface.
|
||||
* @return NULL, if the address can not be found on the interface.
|
||||
* @return NULL, if @p pid is no interface.
|
||||
*/
|
||||
ipv6_addr_t *gnrc_ipv6_netif_find_addr(kernel_pid_t pid, const ipv6_addr_t *addr);
|
||||
|
||||
/**
|
||||
* @brief Searches for the first address matching a prefix best on all
|
||||
* interfaces.
|
||||
*
|
||||
* @param[out] out The reference to the found address on the interface.
|
||||
* Must be a pointer to NULL on calling and may stay
|
||||
* unchanged if no match can be found.
|
||||
*
|
||||
* @param[in] prefix The prefix you want to search for.
|
||||
*
|
||||
* @pre @p out must not be NULL.
|
||||
*
|
||||
* @return The PID to the interface the address is registered to.
|
||||
* @return KERNEL_PID_UNDEF, if no matching address can not be found on any
|
||||
* interface.
|
||||
*/
|
||||
kernel_pid_t gnrc_ipv6_netif_find_by_prefix(ipv6_addr_t **out, const ipv6_addr_t *prefix);
|
||||
|
||||
/**
|
||||
* @brief Searches for the first address matching a prefix best on an
|
||||
* interface.
|
||||
*
|
||||
* @param[in] pid The PID to the interface.
|
||||
* @param[in] prefix The prefix you want to search for.
|
||||
*
|
||||
* @return The reference to the found address on the interface.
|
||||
* @return NULL, if no matching address can be found on the interface.
|
||||
* @return NULL, if @p pid is no interface.
|
||||
*/
|
||||
ipv6_addr_t *gnrc_ipv6_netif_match_prefix(kernel_pid_t pid, const ipv6_addr_t *prefix);
|
||||
|
||||
/**
|
||||
* @brief Searches for the best address on an interface usable as a
|
||||
* source address for a given destination address.
|
||||
*
|
||||
* @param[in] pid The PID to the interface.
|
||||
* @param[in] dest The destination address you want to find a destination
|
||||
* address for.
|
||||
* @param[in] ll_only If only link local addresses qualify
|
||||
*
|
||||
* @todo Rule 4 from RFC 6724 is currently not implemented. Has to updated as
|
||||
* soon as gnrc supports Mobile IP.
|
||||
*
|
||||
* @todo Rule 6 from RFC 6724 is currently not implemented. Has to updated as
|
||||
* soon as gnrc supports flow labels.
|
||||
*
|
||||
* @todo Rule 7 from RFC 6724 is currently not implemented. Has to updated as
|
||||
* soon as gnrc supports temporary addresses.
|
||||
*
|
||||
* @return The reference to the found address on the interface.
|
||||
* @return NULL, if no matching address can be found on the interface.
|
||||
* @return NULL, if @p pid is no interface.
|
||||
*/
|
||||
ipv6_addr_t *gnrc_ipv6_netif_find_best_src_addr(kernel_pid_t pid, const ipv6_addr_t *dest, bool ll_only);
|
||||
|
||||
/**
|
||||
* @brief Get interface specific meta-information on an address
|
||||
*
|
||||
* @details This only works with addresses you retrieved via the following
|
||||
* functions:
|
||||
*
|
||||
* * gnrc_ipv6_netif_add_addr()
|
||||
* * gnrc_ipv6_find_addr()
|
||||
* * gnrc_ipv6_find_addr_local()
|
||||
* * gnrc_ipv6_find_prefix_match()
|
||||
* * gnrc_ipv6_find_prefix_match_local()
|
||||
* * gnrc_ipv6_find_best_src_address()
|
||||
*
|
||||
* The behaviour for other addresses is undefined.
|
||||
*
|
||||
* @param[in] addr The address you want to get the meta-information for.
|
||||
*
|
||||
* @return Interface specific meta-information on @p addr
|
||||
*/
|
||||
static inline gnrc_ipv6_netif_addr_t *gnrc_ipv6_netif_addr_get(const ipv6_addr_t *addr)
|
||||
{
|
||||
return container_of(addr, gnrc_ipv6_netif_addr_t, addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if an address is non-unicast.
|
||||
*
|
||||
* @details This only works with addresses you retrieved via the following
|
||||
* functions:
|
||||
*
|
||||
* * gnrc_ipv6_netif_add_addr()
|
||||
* * gnrc_ipv6_find_addr()
|
||||
* * gnrc_ipv6_find_addr_local()
|
||||
* * gnrc_ipv6_find_prefix_match()
|
||||
* * gnrc_ipv6_find_prefix_match_local()
|
||||
* * gnrc_ipv6_find_best_src_address()
|
||||
*
|
||||
* The behaviour for other addresses is undefined.
|
||||
*
|
||||
* @param[in] addr The address you want to check.
|
||||
*
|
||||
* @return true, if address is anycast or multicast.
|
||||
* @return false, if address is unicast.
|
||||
*/
|
||||
static inline bool gnrc_ipv6_netif_addr_is_non_unicast(const ipv6_addr_t *addr)
|
||||
{
|
||||
return (bool)(container_of(addr, gnrc_ipv6_netif_addr_t, addr)->flags &
|
||||
GNRC_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes an interface with device-dependent values.
|
||||
*
|
||||
* @note Must be called after all interfaces were initialized and must not
|
||||
* be called in an interface's thread (will otherwise hang up).
|
||||
*/
|
||||
void gnrc_ipv6_netif_init_by_dev(void);
|
||||
|
||||
/**
|
||||
* @brief Get sent and received statistics about IPv6 traffic on this interface.
|
||||
*
|
||||
* @note This function is only available if compiled with module `netstats_ipv6`.
|
||||
*
|
||||
* @param[in] pid The PID to the interface.
|
||||
*
|
||||
* @return A @ref netstats_t pointer to the statistics.
|
||||
* @return NULL if no statistics are available.
|
||||
*/
|
||||
#if defined(MODULE_NETSTATS_IPV6) || DOXYGEN
|
||||
netstats_t *gnrc_ipv6_netif_get_stats(kernel_pid_t pid);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NET_GNRC_IPV6_NETIF_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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 <a href="https://tools.ietf.org/html/rfc4861#section-6.2.2">
|
||||
* RFC 4861, section 6.2.2
|
||||
* </a>
|
||||
* @see <a href="https://tools.ietf.org/html/rfc4861#section-6.2.5">
|
||||
* RFC 4861, section 6.2.5
|
||||
* </a>
|
||||
*
|
||||
* @details GNRC_IPV6_NETIF_FLAGS_RTR_ADV and initializes or ceases
|
||||
* periodic router advertising behavior for neighbor discovery.
|
||||
*
|
||||
* @param[in] iface An IPv6 interface. Must not be NULL.
|
||||
* @param[in] enable Status for the GNRC_IPV6_NETIF_FLAGS_RTR_ADV flags.
|
||||
*/
|
||||
void gnrc_ndp_router_set_rtr_adv(gnrc_ipv6_netif_t *iface, bool enable);
|
||||
|
||||
/**
|
||||
* @brief Send an unsolicited router advertisement over @p iface
|
||||
* and reset the timer for the next one if necessary.
|
||||
*
|
||||
* @param[in] iface An IPv6 interface.
|
||||
*/
|
||||
void gnrc_ndp_router_retrans_rtr_adv(gnrc_ipv6_netif_t *iface);
|
||||
|
||||
/**
|
||||
* @brief Send an solicited router advertisement to IPv6 address of
|
||||
* @p neighbor.
|
||||
|
@ -1,146 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup net_gnrc_netif Network interfaces
|
||||
* @ingroup net_gnrc
|
||||
* @brief Abstraction layer for GNRC's network interfaces
|
||||
*
|
||||
* Network interfaces in the context of GNRC are threads for protocols that are
|
||||
* below the network layer.
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Definitions for GNRC's network interfaces
|
||||
*
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
||||
*/
|
||||
#ifndef NET_GNRC_NETIF_H
|
||||
#define NET_GNRC_NETIF_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include "kernel_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Maximum number of network interfaces
|
||||
*/
|
||||
#ifndef GNRC_NETIF_NUMOF
|
||||
#define GNRC_NETIF_NUMOF (1)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief The add/remove operation to set network layer protocol
|
||||
* specific options for an interface.
|
||||
*
|
||||
* @param[in] pid The PID to the new interface.
|
||||
*/
|
||||
typedef void (*gnrc_netif_op_t)(kernel_pid_t pid);
|
||||
|
||||
/**
|
||||
* @brief The add and remove handlers to set network layer protocol
|
||||
* specific options for an interface.
|
||||
*
|
||||
* @details If you implement a pair, please add it to the list in gnrc_netif.c
|
||||
* statically.
|
||||
*/
|
||||
typedef struct {
|
||||
gnrc_netif_op_t add; /**< The add operation */
|
||||
gnrc_netif_op_t remove; /**< The remove operation */
|
||||
} gnrc_netif_handler_t;
|
||||
|
||||
/**
|
||||
* @brief Initializes module.
|
||||
*/
|
||||
void gnrc_netif_init(void);
|
||||
|
||||
/**
|
||||
* @brief Adds a thread as interface.
|
||||
*
|
||||
* @param[in] pid PID of the added thread.
|
||||
*
|
||||
* @return 0, on success,
|
||||
* @return -ENOMEM, if maximum number of interfaces has been exceeded.
|
||||
*/
|
||||
int gnrc_netif_add(kernel_pid_t pid);
|
||||
|
||||
/**
|
||||
* @brief Removes a thread as interface.
|
||||
*
|
||||
* @param[in] pid PID of the removed thread.
|
||||
*/
|
||||
void gnrc_netif_remove(kernel_pid_t pid);
|
||||
|
||||
/**
|
||||
* @brief Get all active interfaces.
|
||||
*
|
||||
* @param[out] netifs List of all active interfaces. There is no order ensured.
|
||||
* It must at least fit @ref GNRC_NETIF_NUMOF elements.
|
||||
*
|
||||
* @return The number of active interfaces.
|
||||
*/
|
||||
size_t gnrc_netif_get(kernel_pid_t *netifs);
|
||||
|
||||
/**
|
||||
* @brief Check if an interface exist.
|
||||
*
|
||||
* @param[in] pid The PID to be checked.
|
||||
*
|
||||
* @return True, if an interface @p pid exists.
|
||||
* @return False, otherwise
|
||||
*/
|
||||
bool gnrc_netif_exist(kernel_pid_t pid);
|
||||
|
||||
/**
|
||||
* @brief Converts a hardware address to a human readable string.
|
||||
*
|
||||
* @details The format will be like `xx:xx:xx:xx` where `xx` are the bytes
|
||||
* of @p addr in hexadecimal representation.
|
||||
*
|
||||
* @pre @p out_len >= 3 * @p addr_len
|
||||
*
|
||||
* @param[out] out A string to store the output in.
|
||||
* @param[out] out_len Length of @p out. Must be at least
|
||||
* 3 * @p addr_len long.
|
||||
* @param[in] addr A hardware address.
|
||||
* @param[in] addr_len Length of @p addr.
|
||||
*
|
||||
* @return Copy of @p out on success.
|
||||
* @return NULL, if @p out_len < 3 * @p addr_len.
|
||||
*/
|
||||
char *gnrc_netif_addr_to_str(char *out, size_t out_len, const uint8_t *addr,
|
||||
size_t addr_len);
|
||||
|
||||
/**
|
||||
* @brief Parses a string of colon-separated hexadecimals to a hardware
|
||||
* address.
|
||||
*
|
||||
* @details The input format must be like `xx:xx:xx:xx` where `xx` will be the
|
||||
* bytes of @p addr in hexadecimal representation.
|
||||
*
|
||||
* @param[out] out The resulting hardware address.
|
||||
* @param[out] out_len Length of @p out.
|
||||
* @param[in] str A string of colon-separated hexadecimals.
|
||||
*
|
||||
* @return Actual length of @p out on success.
|
||||
* @return 0, on failure.
|
||||
*/
|
||||
size_t gnrc_netif_addr_from_str(uint8_t *out, size_t out_len, const char *str);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NET_GNRC_NETIF_H */
|
||||
/** @} */
|
@ -27,7 +27,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "net/gnrc/ipv6/netif.h"
|
||||
#include "net/ipv6/addr.h"
|
||||
#include "xtimer.h"
|
||||
#include "trickle.h"
|
||||
|
@ -65,18 +65,17 @@
|
||||
* packet will be silently discarded.
|
||||
*
|
||||
* The @ref GNRC_NETTYPE_SIXLOWPAN header must at least have the gnrc_netif_hdr_t::if_pid field
|
||||
* set to a legal, 6LoWPAN compatible interface (a @ref gnrc_sixlowpan_netif_t entry referred to as
|
||||
* `iface` in the following must exist) referred to as "the interface thread" in the following,
|
||||
* otherwise the packet will be discarded.
|
||||
* set to a legal, 6LoWPAN compatible interface referred to as `netif` in the
|
||||
* following, otherwise the packet will be discarded.
|
||||
*
|
||||
* If @ref net_gnrc_sixlowpan_iphc is included and gnrc_sixlowpan_netif_t::iphc_enable of `iface`
|
||||
* If @ref net_gnrc_sixlowpan_iphc is included and gnrc_sixlowpan_netif_t::iphc_enable of `netif`
|
||||
* is true the @ref GNRC_NETTYPE_IPV6 header will be compressed according to
|
||||
* <a href="https://tools.ietf.org/html/rfc6282">RFC 6282</a>. If it is false the
|
||||
* @ref SIXLOWPAN_UNCOMP dispatch will be appended as a new @ref gnrc_pktsnip_t to the packet.
|
||||
* The false case also applies if @ref net_gnrc_sixlowpan_iphc is not included.
|
||||
*
|
||||
* If the packet without @ref GNRC_NETTYPE_NETIF header is shorter than
|
||||
* gnrc_sixlowpan_netif_t::max_frag_size of `iface` the packet will be send to the interface
|
||||
* gnrc_netif2_t::sixlo::max_frag_size of `netif` the packet will be send to the `netif`'s
|
||||
* thread. Otherwise if @ref net_gnrc_sixlowpan_frag is included the packet will be fragmented
|
||||
* according to <a href="https://tools.ietf.org/html/rfc4944">RFC 4944</a> if the packet is without
|
||||
* @ref GNRC_NETTYPE_NETIF header shorter than @ref SIXLOWPAN_FRAG_MAX_LEN. If none of these cases
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup net_gnrc_sixlowpan_netif 6LoWPAN network interfaces
|
||||
* @ingroup net_gnrc_sixlowpan
|
||||
* @brief 6LoWPAN specific information on @ref net_gnrc_netif
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Definitions for 6LoWPAN specific information of network interfaces.
|
||||
*
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
#ifndef NET_GNRC_SIXLOWPAN_NETIF_H
|
||||
#define NET_GNRC_SIXLOWPAN_NETIF_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "kernel_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Definition of 6LoWPAN interface type.
|
||||
*/
|
||||
typedef struct {
|
||||
kernel_pid_t pid; /**< PID of the interface */
|
||||
uint16_t max_frag_size; /**< Maximum fragment size for this interface */
|
||||
#ifdef MODULE_GNRC_SIXLOWPAN_IPHC
|
||||
bool iphc_enabled; /**< enable or disable IPHC */
|
||||
#endif
|
||||
} gnrc_sixlowpan_netif_t;
|
||||
|
||||
/**
|
||||
* @brief Initializes the module
|
||||
*/
|
||||
void gnrc_sixlowpan_netif_init(void);
|
||||
|
||||
/**
|
||||
* @brief Add interface to 6LoWPAN.
|
||||
*
|
||||
* @param[in] pid The PID to the interface.
|
||||
* @param[in] max_frag_size The maximum fragment size for this interface.
|
||||
*/
|
||||
void gnrc_sixlowpan_netif_add(kernel_pid_t pid, uint16_t max_frag_size);
|
||||
|
||||
/**
|
||||
* @brief Remove interface from 6LoWPAN.
|
||||
*
|
||||
* @param[in] pid The PID to the interface.
|
||||
*/
|
||||
void gnrc_sixlowpan_netif_remove(kernel_pid_t pid);
|
||||
|
||||
/**
|
||||
* @brief Get interface.
|
||||
*
|
||||
* @param[in] pid The PID to the interface
|
||||
*
|
||||
* @return The interface describing structure, on success.
|
||||
* @return NULL, if there is no interface with PID @p pid.
|
||||
*/
|
||||
gnrc_sixlowpan_netif_t *gnrc_sixlowpan_netif_get(kernel_pid_t pid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NET_GNRC_SIXLOWPAN_NETIF_H */
|
||||
/** @} */
|
@ -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
|
||||
|
@ -1,3 +0,0 @@
|
||||
MODULE = gnrc_netif
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -1,110 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
* Copyright (C) 2015 INRIA
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include "kernel_types.h"
|
||||
#include "net/gnrc/netif.h"
|
||||
|
||||
#ifdef MODULE_GNRC_IPV6_NETIF
|
||||
#include "net/gnrc/ipv6/netif.h"
|
||||
#endif
|
||||
|
||||
static gnrc_netif_handler_t if_handler[] = {
|
||||
#ifdef MODULE_GNRC_IPV6_NETIF
|
||||
{ gnrc_ipv6_netif_add, gnrc_ipv6_netif_remove },
|
||||
#endif
|
||||
/* #ifdef MODULE_GNRC_IPV4_NETIF
|
||||
* { ipv4_netif_add, ipv4_netif_remove },
|
||||
* #endif ... you get the idea
|
||||
*/
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static kernel_pid_t ifs[GNRC_NETIF_NUMOF];
|
||||
|
||||
void gnrc_netif_init(void)
|
||||
{
|
||||
for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
|
||||
ifs[i] = KERNEL_PID_UNDEF;
|
||||
}
|
||||
}
|
||||
|
||||
int gnrc_netif_add(kernel_pid_t pid)
|
||||
{
|
||||
kernel_pid_t *free_entry = NULL;
|
||||
|
||||
for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
|
||||
if (ifs[i] == pid) {
|
||||
return 0;
|
||||
}
|
||||
else if (ifs[i] == KERNEL_PID_UNDEF && !free_entry) {
|
||||
free_entry = &ifs[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (!free_entry) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
*free_entry = pid;
|
||||
|
||||
for (int j = 0; if_handler[j].add != NULL; j++) {
|
||||
if_handler[j].add(pid);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void gnrc_netif_remove(kernel_pid_t pid)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < GNRC_NETIF_NUMOF; i++) {
|
||||
if (ifs[i] == pid) {
|
||||
ifs[i] = KERNEL_PID_UNDEF;
|
||||
|
||||
for (int j = 0; if_handler[j].remove != NULL; j++) {
|
||||
if_handler[j].remove(pid);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t gnrc_netif_get(kernel_pid_t *netifs)
|
||||
{
|
||||
size_t size = 0;
|
||||
|
||||
for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
|
||||
if (ifs[i] != KERNEL_PID_UNDEF) {
|
||||
netifs[size++] = ifs[i];
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
bool gnrc_netif_exist(kernel_pid_t pid)
|
||||
{
|
||||
for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
|
||||
if (ifs[i] == pid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @} */
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
* Copyright (C) 2015 René Kijewski <rene.kijewski@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include "net/gnrc/netif.h"
|
||||
|
||||
static inline int _dehex(char c, int default_)
|
||||
{
|
||||
if ('0' <= c && c <= '9') {
|
||||
return c - '0';
|
||||
}
|
||||
else if ('A' <= c && c <= 'F') {
|
||||
return c - 'A' + 10;
|
||||
}
|
||||
else if ('a' <= c && c <= 'f') {
|
||||
return c - 'a' + 10;
|
||||
}
|
||||
else {
|
||||
return default_;
|
||||
}
|
||||
}
|
||||
|
||||
size_t gnrc_netif_addr_from_str(uint8_t *out, size_t out_len, const char *str)
|
||||
{
|
||||
/* Walk over str from the end. */
|
||||
/* Take two chars a time as one hex value (%hhx). */
|
||||
/* Leading zeros can be omitted. */
|
||||
/* Every non-hexadimal character is a delimiter. */
|
||||
/* Leading, tailing and adjacent delimiters are forbidden. */
|
||||
|
||||
const char *end_str = str;
|
||||
uint8_t *out_end = out;
|
||||
size_t count = 0;
|
||||
int assert_cell = 1;
|
||||
|
||||
if (!str || !*str) {
|
||||
return 0;
|
||||
}
|
||||
while (end_str[1]) {
|
||||
++end_str;
|
||||
}
|
||||
|
||||
while (end_str >= str) {
|
||||
int a = 0, b = _dehex(*end_str--, -1);
|
||||
if (b < 0) {
|
||||
if (assert_cell) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
assert_cell = 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
assert_cell = 0;
|
||||
|
||||
if (end_str >= str) {
|
||||
a = _dehex(*end_str--, 0);
|
||||
}
|
||||
|
||||
if (++count > out_len) {
|
||||
return 0;
|
||||
}
|
||||
*out_end++ = (a << 4) | b;
|
||||
}
|
||||
if (assert_cell) {
|
||||
return 0;
|
||||
}
|
||||
/* out is reversed */
|
||||
|
||||
while (out < --out_end) {
|
||||
uint8_t tmp = *out_end;
|
||||
*out_end = *out;
|
||||
*out++ = tmp;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/** @} */
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include "net/gnrc/netif.h"
|
||||
|
||||
static inline char _half_byte_to_char(uint8_t half_byte)
|
||||
{
|
||||
return (half_byte < 10) ? ('0' + half_byte) : ('a' + (half_byte - 10));
|
||||
}
|
||||
|
||||
char *gnrc_netif_addr_to_str(char *out, size_t out_len, const uint8_t *addr,
|
||||
size_t addr_len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (out_len < (3 * addr_len)) { /* 2 for every byte, 1 for ':' or '\0' */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
out[0] = '\0';
|
||||
|
||||
for (i = 0; i < addr_len; i++) {
|
||||
out[(3 * i)] = _half_byte_to_char(addr[i] >> 4);
|
||||
out[(3 * i) + 1] = _half_byte_to_char(addr[i] & 0xf);
|
||||
|
||||
if (i != (addr_len - 1)) {
|
||||
out[(3 * i) + 2] = ':';
|
||||
}
|
||||
else {
|
||||
out[(3 * i) + 2] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/** @} */
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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;
|
||||
|
@ -1,3 +0,0 @@
|
||||
MODULE = gnrc_ipv6_netif
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -1,924 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Martin Lenders <mlenders@inf.fu-berlin.de>
|
||||
* Copyright (C) 2015 Oliver Hahm <oliver.hahm@inria.fr>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser General
|
||||
* Public License v2.1. See the file LICENSE in the top level directory for
|
||||
* more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
*
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "kernel_types.h"
|
||||
#include "mutex.h"
|
||||
#include "bitfield.h"
|
||||
|
||||
#include "net/eui64.h"
|
||||
#include "net/ipv6/addr.h"
|
||||
#include "net/gnrc/ndp.h"
|
||||
#include "net/gnrc/netapi.h"
|
||||
#include "net/gnrc/netif.h"
|
||||
#include "net/gnrc/netif/hdr.h"
|
||||
#include "net/gnrc/sixlowpan/nd.h"
|
||||
#include "net/gnrc/sixlowpan/netif.h"
|
||||
|
||||
#include "net/gnrc/ipv6/netif.h"
|
||||
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
#if ENABLE_DEBUG
|
||||
/* For PRIu16 etc. */
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
/* number of "points" assigned to an source address candidate with equal scope
|
||||
* than destination address */
|
||||
#define RULE_2A_PTS (4)
|
||||
/* number of "points" assigned to an source address candidate with smaller scope
|
||||
* than destination address */
|
||||
#define RULE_2B_PTS (2)
|
||||
/* number of "points" assigned to an source address candidate in preferred state */
|
||||
#define RULE_3_PTS (1)
|
||||
|
||||
static gnrc_ipv6_netif_t ipv6_ifs[GNRC_NETIF_NUMOF];
|
||||
|
||||
#if ENABLE_DEBUG
|
||||
static char addr_str[IPV6_ADDR_MAX_STR_LEN];
|
||||
#endif
|
||||
|
||||
static ipv6_addr_t *_add_addr_to_entry(gnrc_ipv6_netif_t *entry, const ipv6_addr_t *addr,
|
||||
uint8_t prefix_len, uint8_t flags)
|
||||
{
|
||||
gnrc_ipv6_netif_addr_t *tmp_addr = NULL;
|
||||
|
||||
for (int i = 0; i < GNRC_IPV6_NETIF_ADDR_NUMOF; i++) {
|
||||
if (ipv6_addr_equal(&(entry->addrs[i].addr), addr)) {
|
||||
return &(entry->addrs[i].addr);
|
||||
}
|
||||
|
||||
if (ipv6_addr_is_unspecified(&(entry->addrs[i].addr)) && !tmp_addr) {
|
||||
tmp_addr = &(entry->addrs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!tmp_addr) {
|
||||
DEBUG("ipv6 netif: couldn't add %s/%" PRIu8 " to interface %" PRIkernel_pid "\n: No space left.\n",
|
||||
ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)),
|
||||
prefix_len, entry->pid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(&(tmp_addr->addr), addr, sizeof(ipv6_addr_t));
|
||||
DEBUG("ipv6 netif: Added %s/%" PRIu8 " to interface %" PRIkernel_pid "\n",
|
||||
ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)),
|
||||
prefix_len, entry->pid);
|
||||
|
||||
tmp_addr->prefix_len = prefix_len;
|
||||
tmp_addr->flags = flags;
|
||||
|
||||
#ifdef MODULE_GNRC_SIXLOWPAN_ND
|
||||
if (!ipv6_addr_is_multicast(&(tmp_addr->addr)) &&
|
||||
(entry->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN)) {
|
||||
ipv6_addr_t *router = gnrc_ndp_internal_default_router();
|
||||
if (router != NULL) {
|
||||
mutex_unlock(&entry->mutex); /* function below relocks mutex */
|
||||
gnrc_ndp_internal_send_nbr_sol(entry->pid, &tmp_addr->addr, router, router);
|
||||
mutex_lock(&entry->mutex); /* relock mutex */
|
||||
}
|
||||
/* otherwise there is no default router to register to */
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ipv6_addr_is_multicast(addr)) {
|
||||
tmp_addr->flags |= GNRC_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST;
|
||||
}
|
||||
else {
|
||||
if (!ipv6_addr_is_link_local(addr)) {
|
||||
#ifdef MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER
|
||||
tmp_addr->valid = UINT32_MAX;
|
||||
tmp_addr->preferred = UINT32_MAX;
|
||||
gnrc_sixlowpan_nd_router_abr_t *abr = gnrc_sixlowpan_nd_router_abr_get();
|
||||
mutex_unlock(&entry->mutex);
|
||||
gnrc_ipv6_netif_set_rtr_adv(entry, true);
|
||||
mutex_lock(&entry->mutex);
|
||||
if (gnrc_sixlowpan_nd_router_abr_add_prf(abr, entry, tmp_addr) < 0) {
|
||||
DEBUG("ipv6_netif: error adding prefix to 6LoWPAN-ND management\n");
|
||||
}
|
||||
#endif
|
||||
#if defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER)
|
||||
if ((entry->flags & GNRC_IPV6_NETIF_FLAGS_ROUTER) &&
|
||||
(entry->flags & GNRC_IPV6_NETIF_FLAGS_RTR_ADV)) {
|
||||
mutex_unlock(&entry->mutex); /* function below relocks mutex */
|
||||
#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER
|
||||
if (entry->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) {
|
||||
gnrc_ndp_internal_send_rtr_adv(entry->pid, NULL, NULL, false);
|
||||
}
|
||||
#endif
|
||||
#ifdef MODULE_GNRC_NDP_ROUTER
|
||||
/* New prefixes MAY allow the router to retransmit up to
|
||||
* GNRC_NDP_MAX_INIT_RTR_ADV_NUMOF unsolicited RA
|
||||
* (see https://tools.ietf.org/html/rfc4861#section-6.2.4) */
|
||||
if (!(entry->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN)) {
|
||||
entry->rtr_adv_count = GNRC_NDP_MAX_INIT_RTR_ADV_NUMOF;
|
||||
gnrc_ndp_router_retrans_rtr_adv(entry);
|
||||
}
|
||||
#endif
|
||||
mutex_lock(&entry->mutex); /* relock mutex */
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
tmp_addr->flags |= GNRC_IPV6_NETIF_ADDR_FLAGS_NDP_ON_LINK;
|
||||
}
|
||||
#if defined(MODULE_GNRC_NDP_NODE) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER)
|
||||
/* add solicited-nodes multicast address for new address if interface is not a
|
||||
* 6LoWPAN host interface (see: https://tools.ietf.org/html/rfc6775#section-5.2) */
|
||||
if (!(entry->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) ||
|
||||
(entry->flags & GNRC_IPV6_NETIF_FLAGS_ROUTER)) {
|
||||
ipv6_addr_t sol_node;
|
||||
ipv6_addr_set_solicited_nodes(&sol_node, addr);
|
||||
_add_addr_to_entry(entry, &sol_node, IPV6_ADDR_BIT_LEN, 0);
|
||||
}
|
||||
#endif
|
||||
/* TODO: send NS with ARO on 6LoWPAN interfaces, but not so many and only for the new
|
||||
* source address. */
|
||||
}
|
||||
|
||||
tmp_addr->valid_timeout_msg.type = GNRC_NDP_MSG_ADDR_TIMEOUT;
|
||||
tmp_addr->valid_timeout_msg.content.ptr = &tmp_addr->addr;
|
||||
|
||||
return &(tmp_addr->addr);
|
||||
}
|
||||
|
||||
static void _reset_addr_from_entry(gnrc_ipv6_netif_t *entry)
|
||||
{
|
||||
DEBUG("ipv6 netif: Reset IPv6 addresses on interface %" PRIkernel_pid "\n", entry->pid);
|
||||
memset(entry->addrs, 0, sizeof(entry->addrs));
|
||||
}
|
||||
|
||||
static void _ipv6_netif_remove(gnrc_ipv6_netif_t *entry)
|
||||
{
|
||||
if (entry == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef MODULE_GNRC_NDP
|
||||
gnrc_ndp_netif_remove(entry);
|
||||
#endif
|
||||
|
||||
mutex_lock(&entry->mutex);
|
||||
xtimer_remove(&entry->rtr_sol_timer);
|
||||
#ifdef MODULE_GNRC_NDP_ROUTER
|
||||
xtimer_remove(&entry->rtr_adv_timer);
|
||||
#endif
|
||||
_reset_addr_from_entry(entry);
|
||||
DEBUG("ipv6 netif: Remove IPv6 interface %" PRIkernel_pid "\n", entry->pid);
|
||||
entry->pid = KERNEL_PID_UNDEF;
|
||||
entry->flags = 0;
|
||||
|
||||
mutex_unlock(&entry->mutex);
|
||||
}
|
||||
|
||||
void gnrc_ipv6_netif_init(void)
|
||||
{
|
||||
for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
|
||||
mutex_init(&(ipv6_ifs[i].mutex));
|
||||
_ipv6_netif_remove(&ipv6_ifs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void gnrc_ipv6_netif_add(kernel_pid_t pid)
|
||||
{
|
||||
gnrc_ipv6_netif_t *free_entry = NULL;
|
||||
|
||||
for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
|
||||
if (ipv6_ifs[i].pid == pid) {
|
||||
/* pid has already been added */
|
||||
return;
|
||||
}
|
||||
|
||||
else if ((ipv6_ifs[i].pid == KERNEL_PID_UNDEF) && !free_entry) {
|
||||
/* found the first free entry */
|
||||
free_entry = &ipv6_ifs[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (!free_entry) {
|
||||
DEBUG("ipv6 netif: Could not add %" PRIkernel_pid " to IPv6: No space left.\n", pid);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Otherwise, fill the free entry */
|
||||
|
||||
mutex_lock(&free_entry->mutex);
|
||||
|
||||
DEBUG("ipv6 netif: Add IPv6 interface %" PRIkernel_pid " (i = %d)\n", pid,
|
||||
free_entry - ipv6_ifs);
|
||||
free_entry->pid = pid;
|
||||
free_entry->mtu = GNRC_IPV6_NETIF_DEFAULT_MTU;
|
||||
free_entry->cur_hl = GNRC_IPV6_NETIF_DEFAULT_HL;
|
||||
free_entry->flags = 0;
|
||||
|
||||
_add_addr_to_entry(free_entry, &ipv6_addr_all_nodes_link_local,
|
||||
IPV6_ADDR_BIT_LEN, 0);
|
||||
|
||||
mutex_unlock(&free_entry->mutex);
|
||||
|
||||
#ifdef MODULE_GNRC_NDP
|
||||
gnrc_ndp_netif_add(free_entry);
|
||||
#endif
|
||||
|
||||
DEBUG(" * pid = %" PRIkernel_pid " ", free_entry->pid);
|
||||
DEBUG("cur_hl = %d ", free_entry->cur_hl);
|
||||
DEBUG("mtu = %d ", free_entry->mtu);
|
||||
DEBUG("flags = %04" PRIx16 "\n", free_entry->flags);
|
||||
}
|
||||
|
||||
void gnrc_ipv6_netif_remove(kernel_pid_t pid)
|
||||
{
|
||||
gnrc_ipv6_netif_t *entry = gnrc_ipv6_netif_get(pid);
|
||||
_ipv6_netif_remove(entry);
|
||||
}
|
||||
|
||||
gnrc_ipv6_netif_t *gnrc_ipv6_netif_get(kernel_pid_t pid)
|
||||
{
|
||||
for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
|
||||
if (ipv6_ifs[i].pid == pid) {
|
||||
DEBUG("ipv6 netif: Get IPv6 interface %" PRIkernel_pid " (%p, i = %d)\n", pid,
|
||||
(void *)(&(ipv6_ifs[i])), i);
|
||||
return &(ipv6_ifs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER)
|
||||
void gnrc_ipv6_netif_set_router(gnrc_ipv6_netif_t *netif, bool enable)
|
||||
{
|
||||
#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER
|
||||
if (netif->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) {
|
||||
gnrc_sixlowpan_nd_router_set_router(netif, enable);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef MODULE_GNRC_NDP_ROUTER
|
||||
gnrc_ndp_router_set_router(netif, enable);
|
||||
#endif
|
||||
}
|
||||
|
||||
void gnrc_ipv6_netif_set_rtr_adv(gnrc_ipv6_netif_t *netif, bool enable)
|
||||
{
|
||||
#if defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER)
|
||||
if (netif->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) {
|
||||
gnrc_sixlowpan_nd_router_set_rtr_adv(netif, enable);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef MODULE_GNRC_NDP_ROUTER
|
||||
gnrc_ndp_router_set_rtr_adv(netif, enable);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
ipv6_addr_t *gnrc_ipv6_netif_add_addr(kernel_pid_t pid, const ipv6_addr_t *addr,
|
||||
uint8_t prefix_len, uint8_t flags)
|
||||
{
|
||||
gnrc_ipv6_netif_t *entry = gnrc_ipv6_netif_get(pid);
|
||||
ipv6_addr_t *res;
|
||||
|
||||
if ((entry == NULL) || (addr == NULL) || (ipv6_addr_is_unspecified(addr)) ||
|
||||
((prefix_len - 1) > 127)) { /* prefix_len < 1 || prefix_len > 128 */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mutex_lock(&entry->mutex);
|
||||
|
||||
res = _add_addr_to_entry(entry, addr, prefix_len, flags);
|
||||
|
||||
mutex_unlock(&entry->mutex);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static void _remove_addr_from_entry(gnrc_ipv6_netif_t *entry, ipv6_addr_t *addr)
|
||||
{
|
||||
mutex_lock(&entry->mutex);
|
||||
|
||||
for (int i = 0; i < GNRC_IPV6_NETIF_ADDR_NUMOF; i++) {
|
||||
if (ipv6_addr_equal(&(entry->addrs[i].addr), addr)) {
|
||||
DEBUG("ipv6 netif: Remove %s to interface %" PRIkernel_pid "\n",
|
||||
ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)), entry->pid);
|
||||
ipv6_addr_set_unspecified(&(entry->addrs[i].addr));
|
||||
entry->addrs[i].flags = 0;
|
||||
#ifdef MODULE_GNRC_NDP_ROUTER
|
||||
/* Removal of prefixes MAY allow the router to retransmit up to
|
||||
* GNRC_NDP_MAX_INIT_RTR_ADV_NUMOF unsolicited RA
|
||||
* (see https://tools.ietf.org/html/rfc4861#section-6.2.4) */
|
||||
if ((entry->flags & GNRC_IPV6_NETIF_FLAGS_ROUTER) &&
|
||||
(entry->flags & GNRC_IPV6_NETIF_FLAGS_RTR_ADV) &&
|
||||
(!ipv6_addr_is_multicast(addr) &&
|
||||
!ipv6_addr_is_link_local(addr))) {
|
||||
entry->rtr_adv_count = GNRC_NDP_MAX_INIT_RTR_ADV_NUMOF;
|
||||
mutex_unlock(&entry->mutex); /* function below relocks the mutex */
|
||||
gnrc_ndp_router_retrans_rtr_adv(entry);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER
|
||||
gnrc_sixlowpan_nd_router_abr_t *abr = gnrc_sixlowpan_nd_router_abr_get();
|
||||
gnrc_sixlowpan_nd_router_abr_rem_prf(abr, entry, &entry->addrs[i]);
|
||||
#endif
|
||||
|
||||
mutex_unlock(&entry->mutex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mutex_unlock(&entry->mutex);
|
||||
}
|
||||
|
||||
void gnrc_ipv6_netif_remove_addr(kernel_pid_t pid, ipv6_addr_t *addr)
|
||||
{
|
||||
if (pid == KERNEL_PID_UNDEF) {
|
||||
for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
|
||||
if (ipv6_ifs[i].pid == KERNEL_PID_UNDEF) {
|
||||
continue;
|
||||
}
|
||||
|
||||
_remove_addr_from_entry(ipv6_ifs + i, addr);
|
||||
}
|
||||
}
|
||||
else {
|
||||
gnrc_ipv6_netif_t *entry = gnrc_ipv6_netif_get(pid);
|
||||
|
||||
_remove_addr_from_entry(entry, addr);
|
||||
}
|
||||
}
|
||||
|
||||
void gnrc_ipv6_netif_reset_addr(kernel_pid_t pid)
|
||||
{
|
||||
gnrc_ipv6_netif_t *entry = gnrc_ipv6_netif_get(pid);
|
||||
|
||||
if (entry == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
mutex_lock(&entry->mutex);
|
||||
|
||||
_reset_addr_from_entry(entry);
|
||||
|
||||
mutex_unlock(&entry->mutex);
|
||||
}
|
||||
|
||||
kernel_pid_t gnrc_ipv6_netif_find_by_addr(ipv6_addr_t **out, const ipv6_addr_t *addr)
|
||||
{
|
||||
for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
|
||||
if (out != NULL) {
|
||||
*out = gnrc_ipv6_netif_find_addr(ipv6_ifs[i].pid, addr);
|
||||
|
||||
if (*out != NULL) {
|
||||
DEBUG("ipv6 netif: Found %s on interface %" PRIkernel_pid "\n",
|
||||
ipv6_addr_to_str(addr_str, *out, sizeof(addr_str)),
|
||||
ipv6_ifs[i].pid);
|
||||
return ipv6_ifs[i].pid;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (gnrc_ipv6_netif_find_addr(ipv6_ifs[i].pid, addr) != NULL) {
|
||||
DEBUG("ipv6 netif: Found :: on interface %" PRIkernel_pid "\n",
|
||||
ipv6_ifs[i].pid);
|
||||
return ipv6_ifs[i].pid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (out != NULL) {
|
||||
*out = NULL;
|
||||
}
|
||||
|
||||
return KERNEL_PID_UNDEF;
|
||||
}
|
||||
|
||||
ipv6_addr_t *gnrc_ipv6_netif_find_addr(kernel_pid_t pid, const ipv6_addr_t *addr)
|
||||
{
|
||||
gnrc_ipv6_netif_t *entry = gnrc_ipv6_netif_get(pid);
|
||||
|
||||
if (entry == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mutex_lock(&entry->mutex);
|
||||
|
||||
for (int i = 0; i < GNRC_IPV6_NETIF_ADDR_NUMOF; i++) {
|
||||
if (ipv6_addr_equal(&(entry->addrs[i].addr), addr)) {
|
||||
mutex_unlock(&entry->mutex);
|
||||
DEBUG("ipv6 netif: Found %s on interface %" PRIkernel_pid "\n",
|
||||
ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)),
|
||||
pid);
|
||||
return &(entry->addrs[i].addr);
|
||||
}
|
||||
}
|
||||
|
||||
mutex_unlock(&entry->mutex);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static uint8_t _find_by_prefix_unsafe(ipv6_addr_t **res, gnrc_ipv6_netif_t *iface,
|
||||
const ipv6_addr_t *addr, uint8_t *only)
|
||||
{
|
||||
uint8_t best_match = 0;
|
||||
|
||||
for (int i = 0; i < GNRC_IPV6_NETIF_ADDR_NUMOF; i++) {
|
||||
uint8_t match;
|
||||
|
||||
if ((only != NULL) && !(bf_isset(only, i))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (((only != NULL) &&
|
||||
gnrc_ipv6_netif_addr_is_non_unicast(&(iface->addrs[i].addr))) ||
|
||||
ipv6_addr_is_unspecified(&(iface->addrs[i].addr))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
match = ipv6_addr_match_prefix(&(iface->addrs[i].addr), addr);
|
||||
|
||||
if ((only == NULL) && !ipv6_addr_is_multicast(addr) &&
|
||||
(match < iface->addrs[i].prefix_len)) {
|
||||
/* match but not of same subnet */
|
||||
continue;
|
||||
}
|
||||
|
||||
if (match > best_match) {
|
||||
if (res != NULL) {
|
||||
*res = &(iface->addrs[i].addr);
|
||||
}
|
||||
|
||||
best_match = match;
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_DEBUG
|
||||
if (*res != NULL) {
|
||||
DEBUG("ipv6 netif: Found %s on interface %" PRIkernel_pid " matching ",
|
||||
ipv6_addr_to_str(addr_str, *res, sizeof(addr_str)),
|
||||
iface->pid);
|
||||
DEBUG("%s by %" PRIu8 " bits (used as source address = %s)\n",
|
||||
ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)),
|
||||
best_match,
|
||||
(only != NULL) ? "true" : "false");
|
||||
}
|
||||
else {
|
||||
DEBUG("ipv6 netif: Did not found any address on interface %" PRIkernel_pid
|
||||
" matching %s (used as source address = %s)\n",
|
||||
iface->pid,
|
||||
ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)),
|
||||
(only != NULL) ? "true" : "false");
|
||||
}
|
||||
#endif
|
||||
|
||||
return best_match;
|
||||
}
|
||||
|
||||
kernel_pid_t gnrc_ipv6_netif_find_by_prefix(ipv6_addr_t **out, const ipv6_addr_t *prefix)
|
||||
{
|
||||
uint8_t best_match = 0;
|
||||
ipv6_addr_t *tmp_res = NULL;
|
||||
kernel_pid_t res = KERNEL_PID_UNDEF;
|
||||
|
||||
for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
|
||||
uint8_t match;
|
||||
|
||||
mutex_lock(&(ipv6_ifs[i].mutex));
|
||||
|
||||
match = _find_by_prefix_unsafe(&tmp_res, ipv6_ifs + i, prefix, NULL);
|
||||
|
||||
if (match > best_match) {
|
||||
*out = tmp_res;
|
||||
res = ipv6_ifs[i].pid;
|
||||
best_match = match;
|
||||
}
|
||||
|
||||
mutex_unlock(&(ipv6_ifs[i].mutex));
|
||||
}
|
||||
|
||||
#if ENABLE_DEBUG
|
||||
if (res != KERNEL_PID_UNDEF) {
|
||||
DEBUG("ipv6 netif: Found %s on interface %" PRIkernel_pid " globally matching ",
|
||||
ipv6_addr_to_str(addr_str, *out, sizeof(addr_str)),
|
||||
res);
|
||||
DEBUG("%s by %" PRIu8 " bits\n",
|
||||
ipv6_addr_to_str(addr_str, prefix, sizeof(addr_str)),
|
||||
best_match);
|
||||
}
|
||||
else {
|
||||
DEBUG("ipv6 netif: Did not found any address globally matching %s\n",
|
||||
ipv6_addr_to_str(addr_str, prefix, sizeof(addr_str)));
|
||||
}
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief selects potential source address candidates
|
||||
* @see <a href="http://tools.ietf.org/html/rfc6724#section-4">
|
||||
* RFC6724, section 4
|
||||
* </a>
|
||||
* @param[in] iface the interface used for sending
|
||||
* @param[in] dst the destination address
|
||||
* @param[out] candidate_set a bitfield representing all addresses
|
||||
* configured to @p iface, potential candidates
|
||||
* will be marked as 1
|
||||
*
|
||||
* @return false if no candidates were found
|
||||
* @return true otherwise
|
||||
*
|
||||
* @pre the interface entry and its set of addresses must not be changed during
|
||||
* runtime of this function
|
||||
*/
|
||||
static int _create_candidate_set(gnrc_ipv6_netif_t *iface, const ipv6_addr_t *dst,
|
||||
uint8_t *candidate_set, bool link_local_only)
|
||||
{
|
||||
int res = -1;
|
||||
|
||||
DEBUG("gathering candidates\n");
|
||||
|
||||
/* currently this implementation supports only addresses as source address
|
||||
* candidates assigned to this interface. Thus we assume all addresses to be
|
||||
* on interface @p iface */
|
||||
(void) dst;
|
||||
|
||||
for (int i = 0; i < GNRC_IPV6_NETIF_ADDR_NUMOF; i++) {
|
||||
gnrc_ipv6_netif_addr_t *iter = &(iface->addrs[i]);
|
||||
|
||||
DEBUG("Checking address: %s\n",
|
||||
ipv6_addr_to_str(addr_str, &(iter->addr), sizeof(addr_str)));
|
||||
|
||||
/* "In any case, multicast addresses and the unspecified address MUST NOT
|
||||
* be included in a candidate set."
|
||||
*/
|
||||
if (ipv6_addr_is_multicast(&(iter->addr)) ||
|
||||
ipv6_addr_is_unspecified(&(iter->addr))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Check if we only want link local addresses */
|
||||
if (link_local_only && !ipv6_addr_is_link_local(&(iter->addr))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* "For all multicast and link-local destination addresses, the set of
|
||||
* candidate source addresses MUST only include addresses assigned to
|
||||
* interfaces belonging to the same link as the outgoing interface."
|
||||
*
|
||||
* "For site-local unicast destination addresses, the set of candidate
|
||||
* source addresses MUST only include addresses assigned to interfaces
|
||||
* belonging to the same site as the outgoing interface."
|
||||
* -> we should also be fine, since we're only iterating addresses of
|
||||
* the sending interface
|
||||
*/
|
||||
|
||||
/* put all other addresses into the candidate set */
|
||||
DEBUG("add to candidate set\n");
|
||||
bf_set(candidate_set, i);
|
||||
res = i;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
ipv6_addr_t *gnrc_ipv6_netif_match_prefix(kernel_pid_t pid, const ipv6_addr_t *prefix)
|
||||
{
|
||||
ipv6_addr_t *res = NULL;
|
||||
gnrc_ipv6_netif_t *iface = gnrc_ipv6_netif_get(pid);
|
||||
|
||||
mutex_lock(&(iface->mutex));
|
||||
|
||||
if (_find_by_prefix_unsafe(&res, iface, prefix, NULL) > 0) {
|
||||
mutex_unlock(&(iface->mutex));
|
||||
return res;
|
||||
}
|
||||
|
||||
mutex_unlock(&(iface->mutex));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Determines the scope of the given address.
|
||||
*
|
||||
* @param[in] addr The IPv6 address to check.
|
||||
* @param[in] maybe_multicast False if @p addr is definitely no multicast
|
||||
* address, true otherwise.
|
||||
*
|
||||
* @return The scope of the address.
|
||||
*
|
||||
* @pre address is not loopback or unspecified.
|
||||
* see http://tools.ietf.org/html/rfc6724#section-4
|
||||
*/
|
||||
static uint8_t _get_scope(const ipv6_addr_t *addr, const bool maybe_multicast)
|
||||
{
|
||||
if (maybe_multicast && ipv6_addr_is_multicast(addr)) {
|
||||
return (addr->u8[1] & 0x0f);
|
||||
}
|
||||
else if (ipv6_addr_is_link_local(addr)) {
|
||||
return IPV6_ADDR_MCAST_SCP_LINK_LOCAL;
|
||||
}
|
||||
else if (ipv6_addr_is_site_local(addr)) {
|
||||
return IPV6_ADDR_MCAST_SCP_SITE_LOCAL;
|
||||
}
|
||||
else {
|
||||
return IPV6_ADDR_MCAST_SCP_GLOBAL;
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief Find the best candidate among the configured addresses
|
||||
* for a certain destination address according to the 8 rules
|
||||
* specified in RFC 6734, section 5.
|
||||
* @see <a href="http://tools.ietf.org/html/rfc6724#section-5">
|
||||
* RFC6724, section 5
|
||||
* </a>
|
||||
*
|
||||
* @param[in] iface The interface for sending.
|
||||
* @param[in] dst The destination IPv6 address.
|
||||
* @param[in, out] candidate_set The preselected set of candidate addresses as
|
||||
* a bitfield.
|
||||
*
|
||||
* @pre @p dst is not unspecified.
|
||||
*
|
||||
* @return The best matching candidate found on @p iface, may be NULL if none
|
||||
* is found.
|
||||
*/
|
||||
static ipv6_addr_t *_source_address_selection(gnrc_ipv6_netif_t *iface, const ipv6_addr_t *dst,
|
||||
uint8_t *candidate_set)
|
||||
{
|
||||
/* create temporary set for assigning "points" to candidates wining in the
|
||||
* corresponding rules.
|
||||
*/
|
||||
uint8_t winner_set[GNRC_IPV6_NETIF_ADDR_NUMOF];
|
||||
memset(winner_set, 0, GNRC_IPV6_NETIF_ADDR_NUMOF);
|
||||
|
||||
uint8_t max_pts = 0;
|
||||
|
||||
/* _create_candidate_set() assures that `dest` is not unspecified and if
|
||||
* `dst` is loopback rule 1 will fire anyway. */
|
||||
uint8_t dst_scope = _get_scope(dst, true);
|
||||
DEBUG("finding the best match within the source address candidates\n");
|
||||
|
||||
for (int i = 0; i < GNRC_IPV6_NETIF_ADDR_NUMOF; i++) {
|
||||
gnrc_ipv6_netif_addr_t *iter = &(iface->addrs[i]);
|
||||
DEBUG("Checking address: %s\n",
|
||||
ipv6_addr_to_str(addr_str, &(iter->addr), sizeof(addr_str)));
|
||||
/* entries which are not part of the candidate set can be ignored */
|
||||
if (!(bf_isset(candidate_set, i))) {
|
||||
DEBUG("Not part of the candidate set - skipping\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Rule 1: if we have an address configured that equals the destination
|
||||
* use this one as source */
|
||||
if (ipv6_addr_equal(&(iter->addr), dst)) {
|
||||
DEBUG("Ease one - rule 1\n");
|
||||
return &(iter->addr);
|
||||
}
|
||||
|
||||
/* Rule 2: Prefer appropriate scope. */
|
||||
/* both link local */
|
||||
uint8_t candidate_scope = _get_scope(&(iter->addr), false);
|
||||
if (candidate_scope == dst_scope) {
|
||||
DEBUG("winner for rule 2 (same scope) found\n");
|
||||
winner_set[i] += RULE_2A_PTS;
|
||||
if (winner_set[i] > max_pts) {
|
||||
max_pts = RULE_2A_PTS;
|
||||
}
|
||||
}
|
||||
else if (candidate_scope < dst_scope) {
|
||||
DEBUG("winner for rule 2 (smaller scope) found\n");
|
||||
winner_set[i] += RULE_2B_PTS;
|
||||
if (winner_set[i] > max_pts) {
|
||||
max_pts = winner_set[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* Rule 3: Avoid deprecated addresses. */
|
||||
if (iter->preferred > 0) {
|
||||
DEBUG("winner for rule 3 found\n");
|
||||
winner_set[i] += RULE_3_PTS;
|
||||
if (winner_set[i] > max_pts) {
|
||||
max_pts = winner_set[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* Rule 4: Prefer home addresses.
|
||||
* Does not apply, gnrc does not support Mobile IP.
|
||||
* TODO: update as soon as gnrc supports Mobile IP
|
||||
*/
|
||||
|
||||
/* Rule 5: Prefer outgoing interface.
|
||||
* RFC 6724 says:
|
||||
* "It is RECOMMENDED that the candidate source addresses be the set of
|
||||
* unicast addresses assigned to the interface that will be used to
|
||||
* send to the destination (the "outgoing" interface). On routers,
|
||||
* the candidate set MAY include unicast addresses assigned to any
|
||||
* interface that forwards packets, subject to the restrictions
|
||||
* described below."
|
||||
* Currently this implementation uses ALWAYS source addresses assigned
|
||||
* to the outgoing interface. Hence, Rule 5 is always fulfilled.
|
||||
*/
|
||||
|
||||
/* Rule 6: Prefer matching label.
|
||||
* Flow labels are currently not supported by gnrc.
|
||||
* TODO: update as soon as gnrc supports flow labels
|
||||
*/
|
||||
|
||||
/* Rule 7: Prefer temporary addresses.
|
||||
* Temporary addresses are currently not supported by gnrc.
|
||||
* TODO: update as soon as gnrc supports temporary addresses
|
||||
*/
|
||||
}
|
||||
|
||||
/* reset candidate set to mark winners */
|
||||
memset(candidate_set, 0, (GNRC_IPV6_NETIF_ADDR_NUMOF + 7) / 8);
|
||||
/* check if we have a clear winner */
|
||||
/* collect candidates with maximum points */
|
||||
for (int i = 0; i < GNRC_IPV6_NETIF_ADDR_NUMOF; i++) {
|
||||
if (winner_set[i] == max_pts) {
|
||||
bf_set(candidate_set, i);
|
||||
}
|
||||
}
|
||||
|
||||
/* otherwise apply rule 8: Use longest matching prefix. */
|
||||
ipv6_addr_t *res = NULL;
|
||||
_find_by_prefix_unsafe(&res, iface, dst, candidate_set);
|
||||
return res;
|
||||
}
|
||||
|
||||
ipv6_addr_t *gnrc_ipv6_netif_find_best_src_addr(kernel_pid_t pid, const ipv6_addr_t *dst, bool ll_only)
|
||||
{
|
||||
gnrc_ipv6_netif_t *iface = gnrc_ipv6_netif_get(pid);
|
||||
ipv6_addr_t *best_src = NULL;
|
||||
mutex_lock(&(iface->mutex));
|
||||
BITFIELD(candidate_set, GNRC_IPV6_NETIF_ADDR_NUMOF);
|
||||
memset(candidate_set, 0, sizeof(candidate_set));
|
||||
|
||||
int first_candidate = _create_candidate_set(iface, dst, candidate_set, ll_only);
|
||||
if (first_candidate >= 0) {
|
||||
best_src = _source_address_selection(iface, dst, candidate_set);
|
||||
if (best_src == NULL) {
|
||||
best_src = &(iface->addrs[first_candidate].addr);
|
||||
}
|
||||
}
|
||||
mutex_unlock(&(iface->mutex));
|
||||
|
||||
return best_src;
|
||||
}
|
||||
|
||||
void gnrc_ipv6_netif_init_by_dev(void)
|
||||
{
|
||||
kernel_pid_t ifs[GNRC_NETIF_NUMOF];
|
||||
size_t ifnum = gnrc_netif_get(ifs);
|
||||
#ifdef MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER
|
||||
/* cppcheck-suppress unreadVariable
|
||||
* (reason: cppcheck bug. abr_init is read in if below) */
|
||||
bool abr_init = false;
|
||||
#endif
|
||||
|
||||
for (size_t i = 0; i < ifnum; i++) {
|
||||
ipv6_addr_t addr;
|
||||
eui64_t iid;
|
||||
uint16_t tmp;
|
||||
gnrc_ipv6_netif_t *ipv6_if = gnrc_ipv6_netif_get(ifs[i]);
|
||||
|
||||
if (ipv6_if == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
mutex_lock(&ipv6_if->mutex);
|
||||
|
||||
#ifdef MODULE_GNRC_SIXLOWPAN
|
||||
gnrc_nettype_t if_type = GNRC_NETTYPE_UNDEF;
|
||||
|
||||
if ((gnrc_netapi_get(ifs[i], NETOPT_PROTO, 0, &if_type,
|
||||
sizeof(if_type)) != -ENOTSUP) &&
|
||||
(if_type == GNRC_NETTYPE_SIXLOWPAN)) {
|
||||
uint16_t src_len = 8;
|
||||
uint16_t max_frag_size = UINT16_MAX;
|
||||
|
||||
DEBUG("ipv6 netif: Set 6LoWPAN flag\n");
|
||||
ipv6_ifs[i].flags |= GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN;
|
||||
|
||||
/* the router flag must be set early here, because otherwise
|
||||
* _add_addr_to_entry() wouldn't set the solicited node address.
|
||||
* However, addresses have to be configured before calling
|
||||
* gnrc_ipv6_netif_set_router().
|
||||
*/
|
||||
#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER
|
||||
DEBUG("ipv6 netif: Set router flag\n");
|
||||
ipv6_ifs[i].flags |= GNRC_IPV6_NETIF_FLAGS_ROUTER;
|
||||
#endif
|
||||
/* use EUI-64 (8-byte address) for IID generation and for sending
|
||||
* packets */
|
||||
gnrc_netapi_set(ifs[i], NETOPT_SRC_LEN, 0, &src_len,
|
||||
sizeof(src_len)); /* don't care for result */
|
||||
|
||||
if (gnrc_netapi_get(ifs[i], NETOPT_MAX_PACKET_SIZE,
|
||||
0, &max_frag_size, sizeof(max_frag_size)) < 0) {
|
||||
/* if error we assume it works */
|
||||
DEBUG("ipv6 netif: Can not get max packet size from interface %"
|
||||
PRIkernel_pid "\n", ifs[i]);
|
||||
}
|
||||
|
||||
gnrc_sixlowpan_netif_add(ifs[i], max_frag_size);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* set link-local address */
|
||||
if (gnrc_netapi_get(ifs[i], NETOPT_IPV6_IID, 0, &iid,
|
||||
sizeof(eui64_t)) >= 0) {
|
||||
ipv6_addr_set_aiid(&addr, iid.uint8);
|
||||
ipv6_addr_set_link_local_prefix(&addr);
|
||||
_add_addr_to_entry(ipv6_if, &addr, 64, 0);
|
||||
|
||||
}
|
||||
#ifdef GNRC_IPV6_STATIC_LLADDR
|
||||
/* parse addr from string and explicitely set a link lokal prefix
|
||||
* if ifnum > 1 each interface will get its own link local address
|
||||
* with GNRC_IPV6_STATIC_LLADDR + i
|
||||
*/
|
||||
char lladdr_str[] = GNRC_IPV6_STATIC_LLADDR;
|
||||
ipv6_addr_t lladdr;
|
||||
if(ipv6_addr_from_str(&lladdr, lladdr_str) != NULL) {
|
||||
lladdr.u8[15] += i;
|
||||
assert(ipv6_addr_is_link_local(&lladdr));
|
||||
_add_addr_to_entry(ipv6_if, &lladdr, 64, 0);
|
||||
}
|
||||
#endif
|
||||
/* set link MTU */
|
||||
if ((gnrc_netapi_get(ifs[i], NETOPT_MAX_PACKET_SIZE, 0, &tmp,
|
||||
sizeof(uint16_t)) >= 0)) {
|
||||
if (tmp >= IPV6_MIN_MTU) {
|
||||
ipv6_if->mtu = tmp;
|
||||
}
|
||||
/* otherwise leave at GNRC_IPV6_NETIF_DEFAULT_MTU as initialized in
|
||||
* gnrc_ipv6_netif_add() */
|
||||
}
|
||||
|
||||
if (gnrc_netapi_get(ifs[i], NETOPT_IS_WIRED, 0, NULL, 0) > 0) {
|
||||
ipv6_if->flags |= GNRC_IPV6_NETIF_FLAGS_IS_WIRED;
|
||||
}
|
||||
else {
|
||||
ipv6_if->flags &= ~GNRC_IPV6_NETIF_FLAGS_IS_WIRED;
|
||||
}
|
||||
|
||||
mutex_unlock(&ipv6_if->mutex);
|
||||
#if (defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER))
|
||||
gnrc_ipv6_netif_set_router(ipv6_if, true);
|
||||
#endif
|
||||
#ifdef MODULE_GNRC_SIXLOWPAN_ND
|
||||
if (ipv6_if->flags & GNRC_IPV6_NETIF_FLAGS_SIXLOWPAN) {
|
||||
#ifdef MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER
|
||||
/* first interface wins */
|
||||
if (!abr_init) {
|
||||
gnrc_sixlowpan_nd_router_abr_create(&addr, 0);
|
||||
/* XXX should be set to true if there ever is an hard-coded
|
||||
* prefix set */
|
||||
gnrc_ipv6_netif_set_rtr_adv(ipv6_if, false);
|
||||
abr_init = true;
|
||||
}
|
||||
#endif
|
||||
gnrc_sixlowpan_nd_init(ipv6_if);
|
||||
continue; /* skip gnrc_ndp_host_init() */
|
||||
}
|
||||
#endif
|
||||
#ifdef MODULE_GNRC_NDP_HOST
|
||||
/* start periodic router solicitations */
|
||||
gnrc_ndp_host_init(ipv6_if);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MODULE_NETSTATS_IPV6
|
||||
netstats_t *gnrc_ipv6_netif_get_stats(kernel_pid_t pid)
|
||||
{
|
||||
gnrc_ipv6_netif_t *iface = gnrc_ipv6_netif_get(pid);
|
||||
return &(iface->stats);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
@ -16,9 +16,9 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "rbuf.h"
|
||||
#include "net/ipv6.h"
|
||||
#include "net/ipv6/hdr.h"
|
||||
#include "net/gnrc.h"
|
||||
#include "net/gnrc/ipv6/netif.h"
|
||||
#include "net/gnrc/sixlowpan.h"
|
||||
#include "net/gnrc/sixlowpan/frag.h"
|
||||
#include "net/sixlowpan.h"
|
||||
@ -39,7 +39,7 @@
|
||||
#ifndef RBUF_INT_SIZE
|
||||
/* same as ((int) ceil((double) N / D)) */
|
||||
#define DIV_CEIL(N, D) (((N) + (D) - 1) / (D))
|
||||
#define RBUF_INT_SIZE (DIV_CEIL(GNRC_IPV6_NETIF_DEFAULT_MTU, GNRC_SIXLOWPAN_FRAG_SIZE) * RBUF_SIZE)
|
||||
#define RBUF_INT_SIZE (DIV_CEIL(IPV6_MIN_MTU, GNRC_SIXLOWPAN_FRAG_SIZE) * RBUF_SIZE)
|
||||
#endif
|
||||
|
||||
static rbuf_int_t rbuf_int[RBUF_INT_SIZE];
|
||||
|
@ -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"
|
||||
|
@ -1,3 +0,0 @@
|
||||
MODULE = gnrc_sixlowpan_netif
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include "kernel_types.h"
|
||||
|
||||
#include "net/gnrc/netif.h"
|
||||
#include "net/gnrc/sixlowpan/netif.h"
|
||||
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
static gnrc_sixlowpan_netif_t sixlow_ifs[GNRC_NETIF_NUMOF];
|
||||
|
||||
void gnrc_sixlowpan_netif_init(void)
|
||||
{
|
||||
for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
|
||||
sixlow_ifs[i].pid = KERNEL_PID_UNDEF;
|
||||
sixlow_ifs[i].max_frag_size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void gnrc_sixlowpan_netif_add(kernel_pid_t pid, uint16_t max_frag_size)
|
||||
{
|
||||
gnrc_sixlowpan_netif_t *free_entry = NULL;
|
||||
|
||||
for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
|
||||
if (sixlow_ifs[i].pid == pid) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((sixlow_ifs[i].pid == KERNEL_PID_UNDEF) && !free_entry) {
|
||||
/* found the first free entry */
|
||||
free_entry = &sixlow_ifs[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (!free_entry) {
|
||||
DEBUG("gnrc_sixlowpan_netif_add: couldn't add interface with PID %d: No space left.\n", pid);
|
||||
return;
|
||||
}
|
||||
|
||||
free_entry->pid = pid;
|
||||
free_entry->max_frag_size = max_frag_size;
|
||||
#ifdef MODULE_GNRC_SIXLOWPAN_IPHC
|
||||
free_entry->iphc_enabled = true;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
void gnrc_sixlowpan_netif_remove(kernel_pid_t pid)
|
||||
{
|
||||
gnrc_sixlowpan_netif_t *entry = gnrc_sixlowpan_netif_get(pid);
|
||||
|
||||
entry->pid = KERNEL_PID_UNDEF;
|
||||
}
|
||||
|
||||
gnrc_sixlowpan_netif_t *gnrc_sixlowpan_netif_get(kernel_pid_t pid)
|
||||
{
|
||||
for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
|
||||
if (sixlow_ifs[i].pid == pid) {
|
||||
return sixlow_ifs + i;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** @} */
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "net/gnrc/ipv6/nib.h"
|
||||
#include "net/gnrc/netif.h"
|
||||
#include "net/gnrc/netif2.h"
|
||||
#include "net/ipv6/addr.h"
|
||||
|
||||
static void _usage(char **argv);
|
||||
|
@ -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)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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"
|
||||
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -1,3 +0,0 @@
|
||||
USEMODULE += gnrc_netif
|
||||
|
||||
CFLAGS += -DGNRC_NETIF_NUMOF=3
|
@ -1,324 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "embUnit/embUnit.h"
|
||||
#include "kernel_types.h"
|
||||
#include "net/gnrc/netif.h"
|
||||
|
||||
#include "unittests-constants.h"
|
||||
#include "tests-gnrc_netif.h"
|
||||
|
||||
static void set_up(void)
|
||||
{
|
||||
gnrc_netif_init();
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_add__KERNEL_PID_UNDEF(void)
|
||||
{
|
||||
kernel_pid_t ifs[GNRC_NETIF_NUMOF];
|
||||
size_t size;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(KERNEL_PID_UNDEF));
|
||||
size = gnrc_netif_get(ifs);
|
||||
TEST_ASSERT_EQUAL_INT(0, size);
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_add__memfull(void)
|
||||
{
|
||||
for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(TEST_UINT8 + i));
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(-ENOMEM, gnrc_netif_add(TEST_UINT8 - 1));
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_add__success(void)
|
||||
{
|
||||
kernel_pid_t ifs[GNRC_NETIF_NUMOF];
|
||||
size_t size;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(TEST_UINT8));
|
||||
|
||||
size = gnrc_netif_get(ifs);
|
||||
TEST_ASSERT_EQUAL_INT(1, size);
|
||||
TEST_ASSERT_EQUAL_INT(TEST_UINT8, ifs[0]);
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_add__duplicate_entry(void)
|
||||
{
|
||||
kernel_pid_t ifs[GNRC_NETIF_NUMOF];
|
||||
size_t size;
|
||||
|
||||
for (int i = 0; i < GNRC_NETIF_NUMOF + 4; i++) {
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(TEST_UINT8));
|
||||
}
|
||||
|
||||
size = gnrc_netif_get(ifs);
|
||||
TEST_ASSERT_EQUAL_INT(1, size);
|
||||
TEST_ASSERT_EQUAL_INT(TEST_UINT8, ifs[0]);
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_remove__KERNEL_PID_UNDEF(void)
|
||||
{
|
||||
kernel_pid_t ifs[GNRC_NETIF_NUMOF];
|
||||
size_t size;
|
||||
|
||||
test_gnrc_netif_add__success();
|
||||
|
||||
gnrc_netif_remove(KERNEL_PID_UNDEF);
|
||||
|
||||
size = gnrc_netif_get(ifs);
|
||||
TEST_ASSERT_EQUAL_INT(1, size);
|
||||
TEST_ASSERT_EQUAL_INT(TEST_UINT8, ifs[0]);
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_remove__not_an_if(void)
|
||||
{
|
||||
kernel_pid_t ifs[GNRC_NETIF_NUMOF];
|
||||
size_t size;
|
||||
|
||||
test_gnrc_netif_add__success();
|
||||
|
||||
gnrc_netif_remove(TEST_UINT8 + 1);
|
||||
|
||||
size = gnrc_netif_get(ifs);
|
||||
TEST_ASSERT_EQUAL_INT(1, size);
|
||||
TEST_ASSERT_EQUAL_INT(TEST_UINT8, ifs[0]);
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_remove__success(void)
|
||||
{
|
||||
kernel_pid_t ifs[GNRC_NETIF_NUMOF];
|
||||
size_t size;
|
||||
|
||||
test_gnrc_netif_add__success();
|
||||
|
||||
gnrc_netif_remove(TEST_UINT8);
|
||||
|
||||
size = gnrc_netif_get(ifs);
|
||||
TEST_ASSERT_EQUAL_INT(0, size);
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_get__empty(void)
|
||||
{
|
||||
kernel_pid_t ifs[GNRC_NETIF_NUMOF];
|
||||
size_t size = gnrc_netif_get(ifs);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, size);
|
||||
}
|
||||
|
||||
/* takes one out of the middle of the gnrc_netif list and checks if all interfaces
|
||||
* are gotten regardless */
|
||||
static void test_gnrc_netif_get__success_3_minus_one(void)
|
||||
{
|
||||
kernel_pid_t ifs[GNRC_NETIF_NUMOF];
|
||||
size_t size;
|
||||
int count = 0;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(TEST_UINT8 + i));
|
||||
}
|
||||
|
||||
gnrc_netif_remove(TEST_UINT8 + 1);
|
||||
|
||||
size = gnrc_netif_get(ifs);
|
||||
TEST_ASSERT_EQUAL_INT(2, size);
|
||||
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
if ((ifs[i] == TEST_UINT8) || ifs[i] == (TEST_UINT8 + 2)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(size, count);
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_get__full(void)
|
||||
{
|
||||
kernel_pid_t ifs[GNRC_NETIF_NUMOF];
|
||||
size_t size;
|
||||
|
||||
for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(TEST_UINT8 + i));
|
||||
}
|
||||
|
||||
size = gnrc_netif_get(ifs);
|
||||
TEST_ASSERT_EQUAL_INT(GNRC_NETIF_NUMOF, size);
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_exist(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(0));
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(1));
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_add(TEST_UINT8));
|
||||
|
||||
for (int i = 0; i < UINT8_MAX; i++) {
|
||||
if ((i == 0) || (i == 1) || (i == TEST_UINT8)) {
|
||||
TEST_ASSERT(gnrc_netif_exist(i));
|
||||
}
|
||||
else {
|
||||
TEST_ASSERT(!gnrc_netif_exist(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_addr_to_str__out_too_short(void)
|
||||
{
|
||||
static const uint8_t addr[] = { 0x05, 0xcd };
|
||||
char out[2];
|
||||
|
||||
TEST_ASSERT_NULL(gnrc_netif_addr_to_str(out, sizeof(out), addr, sizeof(addr)));
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_addr_to_str__success(void)
|
||||
{
|
||||
static const uint8_t addr[] = { 0x05, 0xcd };
|
||||
char out[3 * sizeof(addr)];
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING("05:cd", gnrc_netif_addr_to_str(out, sizeof(out),
|
||||
addr, sizeof(addr)));
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_addr_from_str__out_too_short(void)
|
||||
{
|
||||
static const char str[] = "05:cd";
|
||||
uint8_t out[1];
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_addr_from_str(out, sizeof(out), str));
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_addr_from_str__omitted_delimitter(void)
|
||||
{
|
||||
static const char str[] = "4567:cd";
|
||||
uint8_t out[3];
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(3, gnrc_netif_addr_from_str(out, sizeof(out), str));
|
||||
TEST_ASSERT_EQUAL_INT(0x45, out[0]);
|
||||
TEST_ASSERT_EQUAL_INT(0x67, out[1]);
|
||||
TEST_ASSERT_EQUAL_INT(0xcd, out[2]);
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_addr_from_str__ill_formated2(void)
|
||||
{
|
||||
static const char str[] = TEST_STRING8;
|
||||
uint8_t out[sizeof(str)];
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_addr_from_str(out, sizeof(out), str));
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_addr_from_str__dash_delimitter(void)
|
||||
{
|
||||
static const char str[] = "05-cd";
|
||||
uint8_t out[2];
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(2, gnrc_netif_addr_from_str(out, sizeof(out), str));
|
||||
TEST_ASSERT_EQUAL_INT(0x05, out[0]);
|
||||
TEST_ASSERT_EQUAL_INT(0xcd, out[1]);
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_addr_from_str__zero_omitted_back(void)
|
||||
{
|
||||
static const char str[] = "05:c";
|
||||
uint8_t out[2];
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(2, gnrc_netif_addr_from_str(out, sizeof(out), str));
|
||||
TEST_ASSERT_EQUAL_INT(0x05, out[0]);
|
||||
TEST_ASSERT_EQUAL_INT(0x0c, out[1]);
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_addr_from_str__zero_omitted_front(void)
|
||||
{
|
||||
static const char str[] = "5:cd";
|
||||
uint8_t out[2];
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(2, gnrc_netif_addr_from_str(out, sizeof(out), str));
|
||||
TEST_ASSERT_EQUAL_INT(0x05, out[0]);
|
||||
TEST_ASSERT_EQUAL_INT(0xcd, out[1]);
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_addr_from_str__ill_trailing_delimitter(void)
|
||||
{
|
||||
static const char str[] = "05:cd:";
|
||||
uint8_t out[sizeof(str)];
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_addr_from_str(out, sizeof(out), str));
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_addr_from_str__ill_leading_delimitter(void)
|
||||
{
|
||||
static const char str[] = ":05:cd";
|
||||
uint8_t out[sizeof(str)];
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_addr_from_str(out, sizeof(out), str));
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_addr_from_str__ill_extra_delimitter(void)
|
||||
{
|
||||
static const char str[] = "05::cd";
|
||||
uint8_t out[sizeof(str)];
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, gnrc_netif_addr_from_str(out, sizeof(out), str));
|
||||
}
|
||||
|
||||
static void test_gnrc_netif_addr_from_str__success(void)
|
||||
{
|
||||
static const char str[] = "05:cd";
|
||||
uint8_t out[2];
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(2, gnrc_netif_addr_from_str(out, sizeof(out), str));
|
||||
TEST_ASSERT_EQUAL_INT(0x05, out[0]);
|
||||
TEST_ASSERT_EQUAL_INT(0xcd, out[1]);
|
||||
}
|
||||
|
||||
Test *tests_gnrc_netif_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
new_TestFixture(test_gnrc_netif_add__KERNEL_PID_UNDEF),
|
||||
new_TestFixture(test_gnrc_netif_add__memfull),
|
||||
new_TestFixture(test_gnrc_netif_add__success),
|
||||
new_TestFixture(test_gnrc_netif_add__duplicate_entry),
|
||||
new_TestFixture(test_gnrc_netif_remove__KERNEL_PID_UNDEF),
|
||||
new_TestFixture(test_gnrc_netif_remove__not_an_if),
|
||||
new_TestFixture(test_gnrc_netif_remove__success),
|
||||
new_TestFixture(test_gnrc_netif_get__empty),
|
||||
new_TestFixture(test_gnrc_netif_get__success_3_minus_one),
|
||||
new_TestFixture(test_gnrc_netif_get__full),
|
||||
new_TestFixture(test_gnrc_netif_exist),
|
||||
new_TestFixture(test_gnrc_netif_addr_to_str__out_too_short),
|
||||
new_TestFixture(test_gnrc_netif_addr_to_str__success),
|
||||
new_TestFixture(test_gnrc_netif_addr_from_str__out_too_short),
|
||||
new_TestFixture(test_gnrc_netif_addr_from_str__omitted_delimitter),
|
||||
new_TestFixture(test_gnrc_netif_addr_from_str__ill_formated2),
|
||||
new_TestFixture(test_gnrc_netif_addr_from_str__dash_delimitter),
|
||||
new_TestFixture(test_gnrc_netif_addr_from_str__zero_omitted_back),
|
||||
new_TestFixture(test_gnrc_netif_addr_from_str__zero_omitted_front),
|
||||
new_TestFixture(test_gnrc_netif_addr_from_str__ill_trailing_delimitter),
|
||||
new_TestFixture(test_gnrc_netif_addr_from_str__ill_leading_delimitter),
|
||||
new_TestFixture(test_gnrc_netif_addr_from_str__ill_extra_delimitter),
|
||||
new_TestFixture(test_gnrc_netif_addr_from_str__success),
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(gnrc_netif_tests, set_up, NULL, fixtures);
|
||||
|
||||
return (Test *)&gnrc_netif_tests;
|
||||
}
|
||||
|
||||
void tests_gnrc_netif(void)
|
||||
{
|
||||
TESTS_RUN(tests_gnrc_netif_tests());
|
||||
}
|
||||
/** @} */
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup unittests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Unittests for the ``gnrc_netif`` module
|
||||
*
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
#ifndef TESTS_GNRC_NETIF_H
|
||||
#define TESTS_GNRC_NETIF_H
|
||||
|
||||
#include "embUnit.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief The entry point of this test suite.
|
||||
*/
|
||||
void tests_gnrc_netif(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TESTS_GNRC_NETIF_H */
|
||||
/** @} */
|
Loading…
Reference in New Issue
Block a user