Skip to content
Snippets Groups Projects
Commit 4f1d7adf authored by Martine Lenders's avatar Martine Lenders
Browse files

Merge pull request #2910 from authmillenon/ng_ndp/feat/addr-res

ng_ndp: initial import of address resolution
parents c35a869a db33a104
No related branches found
No related tags found
No related merge requests found
Showing with 1619 additions and 28 deletions
......@@ -72,6 +72,13 @@ ifneq (,$(filter ng_sixlowpan_ctx,$(USEMODULE)))
USEMODULE += vtimer
endif
ifneq (,$(filter ng_ndp,$(USEMODULE)))
USEMODULE += ng_icmpv6
USEMODULE += random
USEMODULE += timex
USEMODULE += vtimer
endif
ifneq (,$(filter ng_icmpv6_echo,$(USEMODULE)))
USEMODULE += ng_icmpv6
USEMODULE += ng_netbase
......@@ -97,7 +104,11 @@ ifneq (,$(filter ng_ipv6,$(USEMODULE)))
USEMODULE += ng_ipv6_hdr
USEMODULE += ng_ipv6_nc
USEMODULE += ng_ipv6_netif
USEMODULE += ng_ndp
USEMODULE += ng_netbase
USEMODULE += random
USEMODULE += timex
USEMODULE += vtimer
endif
ifneq (,$(filter ng_ipv6_nc,$(USEMODULE)))
......
......@@ -86,6 +86,9 @@ endif
ifneq (,$(filter ng_inet_csum,$(USEMODULE)))
DIRS += net/crosslayer/ng_inet_csum
endif
ifneq (,$(filter ng_ndp,$(USEMODULE)))
DIRS += net/network_layer/ng_ndp
endif
ifneq (,$(filter ng_netapi,$(USEMODULE)))
DIRS += net/crosslayer/ng_netapi
endif
......
......@@ -62,6 +62,16 @@ extern "C" {
#define NG_IPV6_MSG_QUEUE_SIZE (8U)
#endif
/**
* @brief The PID to the IPv6 thread.
*
* @note Use @ref ng_ipv6_init() to initialize. **Do not set by hand**.
*
* @details This variable is preferred for IPv6 internal communication *only*.
* Please use @ref net_ng_netreg for external communication.
*/
extern kernel_pid_t ng_ipv6_pid;
/**
* @brief Initialization of the IPv6 thread.
*
......
......@@ -137,7 +137,7 @@ typedef struct {
*/
vtimer_t nbr_adv_timer;
uint8_t unanswered_probes; /**< number of unanswered probes */
uint8_t probes_remaining; /**< remaining number of unanswered probes */
/**
* @}
*/
......
......@@ -195,6 +195,29 @@ typedef struct {
uint16_t mtu; /**< Maximum Transmission Unit (MTU) of the interface */
uint8_t cur_hl; /**< current hop limit for the interface */
uint16_t flags; /**< flags for 6LoWPAN and Neighbor Discovery */
/**
* @brief Base value in microseconds for computing random
* ng_ipv6_netif_t::reach_time.
* The default value is @ref NG_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 NG_NDP_MIN_RAND
* and NG_NDP_MAX_RAND multiplied with
* ng_ipv6_netif_t::reach_time_base microseconds devided by 10.
* Can't be greater than 1 hour.
*/
timex_t reach_time;
/**
* @brief Time between retransmissions of neighbor solicitations to a
* neighbor.
* The default value is @ref NG_NDP_RETRANS_TIMER.
*/
timex_t retrans_timer;
} ng_ipv6_netif_t;
/**
......
/*
* 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_ng_ndp IPv6 Neighbor discovery
* @ingroup net_ng_icmpv6
* @brief IPv6 Neighbor Discovery Implementation
* @{
*
* @file
* @brief Neighbor Discovery definitions
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#include <inttypes.h>
#include "byteorder.h"
#include "net/ng_pkt.h"
#include "net/ng_icmpv6.h"
#include "net/ng_ipv6/addr.h"
#include "net/ng_ipv6/nc.h"
#include "net/ng_ipv6/netif.h"
#include "net/ng_ndp/types.h"
#ifndef NG_NDP_H_
#define NG_NDP_H_
#ifdef __cplusplus
extern "C" {
#endif
#define NG_NDP_MSG_RTR_TIMEOUT (0x0211) /**< Message type for router timeouts */
#define NG_NDP_MSG_ADDR_TIMEOUT (0x0212) /**< Message type for address timeouts */
#define NG_NDP_MSG_NBR_SOL_RETRANS (0x0213) /**< Message type for multicast
* neighbor solicitation retransmissions */
#define NG_NDP_MSG_NC_STATE_TIMEOUT (0x0214) /**< Message type for neighbor cache state timeouts */
/**
* @{
* @name Node constants
* @see <a href="https://tools.ietf.org/html/rfc4861#section-10">
* RFC 4861, section 10
* </a>
*/
/**
* @brief Maximum number of unanswered multicast neighbor solicitations
* before address resolution is considered failed.
*/
#define NG_NDP_MAX_MC_NBR_SOL_NUMOF (3U)
/**
* @brief Maximum number of unanswered unicast neighbor solicitations before
* an address is considered unreachable.
*/
#define NG_NDP_MAX_UC_NBR_SOL_NUMOF (3U)
/**
* @brief Upper bound of randomized delay in seconds for a solicited
* neighbor advertisement transmission for an anycast target.
*/
#define NG_NDP_MAX_AC_TGT_DELAY (1U)
/**
* @brief Maximum number of unsolicited neighbor advertisements before on
* link-layer address change.
*/
#define NG_NDP_MAX_NBR_ADV_NUMOF (3U)
/**
* @brief Base value in mircoseconds for computing randomised
* reachable time.
*/
#define NG_NDP_REACH_TIME (30U * SEC_IN_USEC)
/**
* @brief Time in mircoseconds between retransmissions of neighbor
* solicitations to a neighbor.
*/
#define NG_NDP_RETRANS_TIMER (1U * SEC_IN_USEC)
/**
* @brief Delay in seconds for neighbor cache entry between entering
* DELAY state and entering PROBE state if no reachability
* confirmation has been received.
*/
#define NG_NDP_FIRST_PROBE_DELAY (5U)
/**
* @brief Lower bound for randomised reachable time calculation.
*/
#define NG_NDP_MIN_RAND (5U)
/**
* @brief Upper bound for randomised reachable time calculation.
*/
#define NG_NDP_MAX_RAND (15U)
/**
* @}
*/
/**
* @brief Handles received neighbor solicitations
*
* @param[in] iface The receiving interface.
* @param[in] pkt The received packet.
* @param[in] ipv6 The IPv6 header in @p pkt.
* @param[in] nbr_sol The neighbor solicitation in @p pkt.
* @param[in] icmpv6_size The overall size of the neighbor solicitation
*/
void ng_ndp_nbr_sol_handle(kernel_pid_t iface, ng_pktsnip_t *pkt,
ng_ipv6_hdr_t *ipv6, ng_ndp_nbr_sol_t *nbr_sol,
size_t icmpv6_size);
/**
* @brief Handles received neighbor solicitations
*
* @param[in] iface The receiving interface.
* @param[in] pkt The received packet.
* @param[in] ipv6 The IPv6 header in @p pkt.
* @param[in] nbr_adv The neighbor advertisement in @p pkt.
* @param[in] icmpv6_size The overall size of the neighbor solicitation
*/
void ng_ndp_nbr_adv_handle(kernel_pid_t iface, ng_pktsnip_t *pkt,
ng_ipv6_hdr_t *ipv6, ng_ndp_nbr_adv_t *nbr_adv,
size_t icmpv6_size);
/**
* @brief Retransmits a multicast neighbor solicitation for an incomplete or
* probing neighbor cache entry @p nc_entry,
* if nc_entry::probes_remaining > 0.
*
* @details If nc_entry::probes_remaining > 0 it will be decremented. If it
* reaches 0 it the entry @p nc_entry will be removed from the
* neighbor cache.
*
* @param[in] nc_entry A neighbor cache entry. Will be ignored if its state
* is not @ref NG_IPV6_NC_STATE_INCOMPLETE or
* @ref NG_IPV6_NC_STATE_PROBE.
*/
void ng_ndp_retrans_nbr_sol(ng_ipv6_nc_t *nc_entry);
/**
* @brief Event handler for a neighbor cache state timeout.
*
* @param[in] nc_entry A neighbor cache entry.
*/
void ng_ndp_state_timeout(ng_ipv6_nc_t *nc_entry);
/**
* @brief NDP interface initialization.
*
* @param[in] iface An IPv6 interface descriptor. Must not be NULL.
*/
void ng_ndp_netif_add(ng_ipv6_netif_t *iface);
/**
* @brief NDP interface removal.
*
* @param[in] iface An IPv6 interface descriptor. Must not be NULL.
*/
void ng_ndp_netif_remove(ng_ipv6_netif_t *iface);
/**
* @brief Get link-layer address and interface for next hop to destination
* IPv6 address.
*
* @param[out] l2addr The link-layer for the next hop to @p dst.
* @param[out] l2addr_len Length of @p l2addr.
* @param[in] iface The interface to search the next hop on.
* May be @ref KERNEL_PID_UNDEF if not specified.
* @param[in] dst An IPv6 address to search the next hop for.
* @param[in] pkt Packet to send to @p dst. Leave NULL if you
* just want to get the addresses.
*
* @return The PID of the interface, on success.
* @return -EHOSTUNREACH, if @p dst is not reachable.
* @return -ENOBUFS, if @p l2addr_len was smaller than the resulting @p l2addr
* would be long.
*/
kernel_pid_t ng_ndp_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_len,
kernel_pid_t iface, ng_ipv6_addr_t *dst,
ng_pktsnip_t *pkt);
/**
* @brief Builds a neighbor solicitation message for sending.
*
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.3">
* RFC 4861, section 4.3
* </a>
*
* @param[in] tgt The target address.
* @param[in] options Options to append to the router solicitation.
*
* @return The resulting ICMPv6 packet on success.
* @return NULL, on failure.
*/
ng_pktsnip_t *ng_ndp_nbr_sol_build(ng_ipv6_addr_t *tgt, ng_pktsnip_t *options);
/**
* @brief Builds a neighbor advertisement message for sending.
*
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.4">
* RFC 4861, section 4.4
* </a>
*
* @param[in] flags Flags as defined above.
* @ref NG_NDP_NBR_ADV_FLAGS_R == 1 indicates, that the
* sender is a router,
* @ref NG_NDP_NBR_ADV_FLAGS_S == 1 indicates that the
* advertisement was sent in response to a neighbor
* solicitation,
* @ref NG_NDP_NBR_ADV_FLAGS_O == 1 indicates that the
* advertisement should override an existing cache entry
* and update the cached link-layer address.
* @param[in] tgt For solicited advertisements, the Target Address field
* in the neighbor solicitaton.
* For and unsolicited advertisement, the address whose
* link-layer addres has changed.
* MUST NOT be multicast.
* @param[in] options Options to append to the neighbor advertisement.
*
* @return The resulting ICMPv6 packet on success.
* @return NULL, on failure.
*/
ng_pktsnip_t *ng_ndp_nbr_adv_build(uint8_t flags, ng_ipv6_addr_t *tgt,
ng_pktsnip_t *options);
/**
* @brief Builds a generic NDP option.
*
* @param[in] type Type of the option.
* @param[in] size Size in byte of the option (will be rounded up to the next
* multiple of 8).
* @param[in] next More options in the packet. NULL, if there are none.
*
* @return The packet snip list of options, on success
* @return NULL, if packet buffer is full
*/
ng_pktsnip_t *ng_ndp_opt_build(uint8_t type, size_t size, ng_pktsnip_t *next);
/**
* @brief Builds the source link-layer address option.
*
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.6.1">
* RFC 4861, section 4.6.1
* </a>
*
* @note Must only be used with neighbor solicitations, router solicitations,
* and router advertisements. This is not checked however, since
* hosts should silently ignore it in other NDP messages.
*
* @param[in] l2addr A link-layer address of variable length.
* @param[in] l2addr_len Length of @p l2addr.
* @param[in] next More options in the packet. NULL, if there are none.
*
* @return The packet snip list of options, on success
* @return NULL, if packet buffer is full
*/
ng_pktsnip_t *ng_ndp_opt_sl2a_build(const uint8_t *l2addr, uint8_t l2addr_len,
ng_pktsnip_t *next);
/**
* @brief Builds the target link-layer address option.
*
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.6.1">
* RFC 4861, section 4.6.1
* </a>
*
* @note Must only be used with neighbor advertisemnents and redirect packets.
* This is not checked however, since hosts should silently ignore it
* in other NDP messages.
*
* @param[in] l2addr A link-layer address of variable length.
* @param[in] l2addr_len Length of @p l2addr.
* @param[in] next More options in the packet. NULL, if there are none.
*
* @return The pkt snip list of options, on success
* @return NULL, if packet buffer is full
*/
ng_pktsnip_t *ng_ndp_opt_tl2a_build(const uint8_t *l2addr, uint8_t l2addr_len,
ng_pktsnip_t *next);
#ifdef __cplusplus
}
#endif
#endif /* NG_NDP_H_ */
/**
* @}
*/
/*
* 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_ng_ndp_types Types for IPv6 neighbor discovery
* @ingroup net_ng_ndp
* @brief IPv6 neighbor discovery message types
* @{
*
* @file
* @brief IPv6 neighbor discovery message type definitions
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#ifndef NG_NDP_TYPES_H_
#define NG_NDP_TYPES_H_
#include <stdint.h>
#include "byteorder.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @{
* @name Flags for router advertisement messages
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.2">
* RFC 4861, section 4.2
* </a>
*/
#define NG_NDP_RTR_ADV_FLAGS_MASK (0xc0)
#define NG_NDP_RTR_ADV_FLAGS_M (0x80) /**< managed address configuration */
#define NG_NDP_RTR_ADV_FLAGS_O (0x40) /**< other configuration */
/**
* @}
*/
/**
* @{
* @name Flags for neighbor advertisement messages
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.4">
* RFC 4861, section 4.2
* </a>
*/
#define NG_NDP_NBR_ADV_FLAGS_MASK (0xe0)
#define NG_NDP_NBR_ADV_FLAGS_R (0x80) /**< router */
#define NG_NDP_NBR_ADV_FLAGS_S (0x40) /**< solicited */
#define NG_NDP_NBR_ADV_FLAGS_O (0x20) /**< override */
/**
* @}
*/
/**
* @{
* @name NDP option types
* @see <a href="http://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml#icmpv6-parameters-5">
* IANA, IPv6 Neighbor Discovery Option Formats
* </a>
*/
#define NG_NDP_OPT_SL2A (1) /**< source link-layer address option */
#define NG_NDP_OPT_TL2A (2) /**< target link-layer address option */
#define NG_NDP_OPT_PI (3) /**< prefix information option */
#define NG_NDP_OPT_RH (4) /**< redirected option */
#define NG_NDP_OPT_MTU (5) /**< MTU option */
/**
* @}
*/
/**
* @{
* @name Flags for prefix information option
*/
#define NG_NDP_OPT_PI_FLAGS_MASK (0xc0)
#define NG_NDP_OPT_PI_FLAGS_L (0x80) /**< on-link */
#define NG_NDP_OPT_PI_FLAGS_A (0x40) /**< autonomous address configuration */
/**
* @}
*/
/**
* @{
* @name Lengths for fixed length options
* @brief Options don't use bytes as their length unit, but 8 bytes.
*/
#define NG_NDP_OPT_PI_LEN (4U)
#define NG_NDP_OPT_MTU_LEN (1U)
/**
* @}
*/
/**
* @brief Router solicitation message format.
* @extends ng_icmpv6_hdr_t
*
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.1">
* RFC 4861, section 4.1
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< message type */
uint8_t code; /**< message code */
network_uint16_t csum; /**< checksum */
network_uint32_t resv; /**< reserved field */
} ng_ndp_rtr_sol_t;
/**
* @brief Router advertisement message format.
* @extends ng_icmpv6_hdr_t
*
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.2">
* RFC 4861, section 4.2
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< message type */
uint8_t code; /**< message code */
network_uint16_t csum; /**< checksum */
uint8_t cur_hl; /**< current hop limit */
uint8_t flags; /**< flags */
network_uint16_t ltime; /**< router lifetime */
network_uint32_t reach_time; /**< reachable time */
network_uint32_t retrans_timer; /**< retransmission timer */
} ng_ndp_rtr_adv_t;
/**
* @brief Neighbor solicitation message format.
* @extends ng_icmpv6_hdr_t
*
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.3">
* RFC 4861, section 4.3
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< message type */
uint8_t code; /**< message code */
network_uint16_t csum; /**< checksum */
network_uint32_t resv; /**< reserved field */
ng_ipv6_addr_t tgt; /**< target address */
} ng_ndp_nbr_sol_t;
/**
* @brief Neighbor advertisement message format.
* @extends ng_icmpv6_hdr_t
*
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.4">
* RFC 4861, section 4.4
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< message type */
uint8_t code; /**< message code */
network_uint16_t csum; /**< checksum */
uint8_t flags; /**< flags */
uint8_t resv[3]; /**< reserved fields */
ng_ipv6_addr_t tgt; /**< target address */
} ng_ndp_nbr_adv_t;
/**
* @brief Neighbor advertisement message format.
* @extends ng_icmpv6_hdr_t
*
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.5">
* RFC 4861, section 4.5
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< message type */
uint8_t code; /**< message code */
network_uint16_t csum; /**< checksum */
network_uint32_t resv; /**< reserved field */
ng_ipv6_addr_t tgt; /**< target address */
ng_ipv6_addr_t dst; /**< destination address */
} ng_ndp_redirect_t;
/**
* @brief General NDP option format
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.6">
* RFC 4861, section 4.6
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< option type */
uint8_t len; /**< length in units of 8 octets */
} ng_ndp_opt_t;
/* XXX: slla and tlla are just ng_ndp_opt_t with variable link layer address
* appended */
/**
* @brief Prefix information option format
* @extends ng_ndp_opt_t
*
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.6.2">
* RFC 4861, section 4.6.2
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< option type */
uint8_t len; /**< length in units of 8 octets */
uint8_t prefix_len; /**< prefix length */
uint8_t flags; /**< flags */
network_uint32_t valid_ltime; /**< valid lifetime */
network_uint32_t pref_ltime; /**< preferred lifetime */
network_uint32_t resv; /**< reserved field */
ng_ipv6_addr_t prefix; /**< prefix */
} ng_ndp_opt_pi_t;
/**
* @brief Redirected header option format
* @extends ng_ndp_opt_t
*
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.6.3">
* RFC 4861, section 4.6.3
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< option type */
uint8_t len; /**< length in units of 8 octets */
uint8_t resv[6]; /**< reserved field */
} ng_ndp_opt_rh_t;
/**
* @brief MTU option format
* @extends ng_ndp_opt_t
*
* @see <a href="https://tools.ietf.org/html/rfc4861#section-4.6.4">
* RFC 4861, section 4.6.4
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< option type */
uint8_t len; /**< length in units of 8 octets */
network_uint16_t resv; /**< reserved field */
network_uint32_t mtu; /**< MTU */
} ng_ndp_opt_mtu_t;
#ifdef __cplusplus
}
#endif
#endif /* NG_NDP_TYPES_H_ */
/** @} */
......@@ -24,6 +24,7 @@
#include "net/ng_netbase.h"
#include "net/ng_protnum.h"
#include "net/ng_ipv6/hdr.h"
#include "net/ng_ndp.h"
#include "od.h"
#include "utlist.h"
......@@ -83,16 +84,32 @@ void ng_icmpv6_demux(kernel_pid_t iface, ng_pktsnip_t *pkt)
break;
#endif
#ifdef MODULE_NG_NDP
case NG_ICMPV6_RTR_SOL:
DEBUG("icmpv6: router solicitation received\n");
/* TODO */
break;
case NG_ICMPV6_RTR_ADV:
DEBUG("icmpv6: router advertisement received\n");
/* TODO */
break;
case NG_ICMPV6_NBR_SOL:
DEBUG("icmpv6: neighbor solicitation received\n");
ng_ndp_nbr_sol_handle(iface, pkt, ipv6->data, (ng_ndp_nbr_sol_t *)hdr,
icmpv6->size);
break;
case NG_ICMPV6_NBR_ADV:
DEBUG("icmpv6: neighbor advertisement received\n");
ng_ndp_nbr_adv_handle(iface, pkt, ipv6->data, (ng_ndp_nbr_adv_t *)hdr,
icmpv6->size);
break;
case NG_ICMPV6_REDIRECT:
DEBUG("icmpv6: neighbor discovery message received\n");
DEBUG("icmpv6: redirect message received\n");
/* TODO */
break;
#endif
#ifdef MODULE_NG_RPL
case NG_ICMPV6_RPL_CTRL:
......
......@@ -15,8 +15,14 @@
#include <errno.h>
#include <string.h>
#include "net/ng_ipv6.h"
#include "net/ng_ipv6/addr.h"
#include "net/ng_ipv6/nc.h"
#include "net/ng_ipv6/netif.h"
#include "net/ng_ndp.h"
#include "thread.h"
#include "timex.h"
#include "vtimer.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
......@@ -110,6 +116,11 @@ ng_ipv6_nc_t *ng_ipv6_nc_add(kernel_pid_t iface, const ng_ipv6_addr_t *ipv6_addr
DEBUG(" with flags = 0x%0x\n", flags);
if (ng_ipv6_nc_get_state(free_entry) == NG_IPV6_NC_STATE_INCOMPLETE) {
DEBUG("ipv6_nc: Set remaining probes to %" PRIu8 "\n");
free_entry->probes_remaining = NG_NDP_MAX_MC_NBR_SOL_NUMOF;
}
return free_entry;
}
......@@ -192,8 +203,16 @@ ng_ipv6_nc_t *ng_ipv6_nc_still_reachable(const ng_ipv6_addr_t *ipv6_addr)
return NULL;
}
if (((entry->flags & NG_IPV6_NC_STATE_MASK) >> NG_IPV6_NC_STATE_POS) !=
NG_IPV6_NC_STATE_INCOMPLETE) {
if (ng_ipv6_nc_get_state(entry) != NG_IPV6_NC_STATE_INCOMPLETE) {
#if defined(MODULE_NG_IPV6_NETIF) && defined(MODULE_VTIMER) && defined(MODULE_NG_IPV6)
ng_ipv6_netif_t *iface = ng_ipv6_netif_get(entry->iface);
timex_t t = iface->reach_time;
vtimer_remove(&entry->nbr_sol_timer);
vtimer_set_msg(&entry->nbr_sol_timer, t, ng_ipv6_pid,
NG_NDP_MSG_NC_STATE_TIMEOUT, entry);
#endif
DEBUG("ipv6_nc: Marking entry %s as reachable\n",
ng_ipv6_addr_to_str(addr_str, ipv6_addr, sizeof(addr_str)));
entry->flags &= ~(NG_IPV6_NC_STATE_MASK >> NG_IPV6_NC_STATE_POS);
......
......@@ -21,6 +21,7 @@
#include "kernel_types.h"
#include "mutex.h"
#include "net/ng_ipv6/addr.h"
#include "net/ng_ndp.h"
#include "net/ng_netif.h"
#include "net/ng_ipv6/netif.h"
......@@ -119,6 +120,10 @@ void ng_ipv6_netif_add(kernel_pid_t pid)
mutex_unlock(&ipv6_ifs[i].mutex);
#ifdef MODULE_NG_NDP
ng_ndp_netif_add(&ipv6_ifs[i]);
#endif
DEBUG(" * pid = %" PRIkernel_pid " ", ipv6_ifs[i].pid);
DEBUG("cur_hl = %d ", ipv6_ifs[i].cur_hl);
DEBUG("mtu = %d ", ipv6_ifs[i].mtu);
......@@ -138,6 +143,10 @@ void ng_ipv6_netif_remove(kernel_pid_t pid)
return;
}
#ifdef MODULE_NG_NDP
ng_ndp_netif_remove(entry);
#endif
mutex_lock(&entry->mutex);
_reset_addr_from_entry(entry);
......
......@@ -20,6 +20,7 @@
#include "kernel_types.h"
#include "net/ng_icmpv6.h"
#include "net/ng_netbase.h"
#include "net/ng_ndp.h"
#include "net/ng_protnum.h"
#include "thread.h"
#include "utlist.h"
......@@ -35,12 +36,13 @@
#define _MAX_L2_ADDR_LEN (8U)
static char _stack[NG_IPV6_STACK_SIZE];
static kernel_pid_t _pid = KERNEL_PID_UNDEF;
#if ENABLE_DEBUG
static char addr_str[NG_IPV6_ADDR_MAX_STR_LEN];
#endif
kernel_pid_t ng_ipv6_pid = KERNEL_PID_UNDEF;
/* handles NG_NETAPI_MSG_TYPE_RCV commands */
static void _receive(ng_pktsnip_t *pkt);
/* dispatches received IPv6 packet for upper layer */
......@@ -58,12 +60,12 @@ static void _decapsulate(ng_pktsnip_t *pkt);
kernel_pid_t ng_ipv6_init(void)
{
if (_pid == KERNEL_PID_UNDEF) {
_pid = thread_create(_stack, sizeof(_stack), NG_IPV6_PRIO,
if (ng_ipv6_pid == KERNEL_PID_UNDEF) {
ng_ipv6_pid = thread_create(_stack, sizeof(_stack), NG_IPV6_PRIO,
CREATE_STACKTEST, _event_loop, NULL, "ipv6");
}
return _pid;
return ng_ipv6_pid;
}
void ng_ipv6_demux(kernel_pid_t iface, ng_pktsnip_t *pkt, uint8_t nh)
......@@ -140,6 +142,27 @@ static void *_event_loop(void *args)
msg_reply(&msg, &reply);
break;
case NG_NDP_MSG_RTR_TIMEOUT:
DEBUG("ipv6: Router timeout received\n");
((ng_ipv6_nc_t *)msg.content.ptr)->flags &= ~NG_IPV6_NC_IS_ROUTER;
break;
case NG_NDP_MSG_ADDR_TIMEOUT:
DEBUG("ipv6: Router advertisement timer event received\n");
ng_ipv6_netif_remove_addr(KERNEL_PID_UNDEF,
(ng_ipv6_addr_t *)msg.content.ptr);
break;
case NG_NDP_MSG_NBR_SOL_RETRANS:
DEBUG("ipv6: Neigbor solicitation retransmission timer event received\n");
ng_ndp_retrans_nbr_sol((ng_ipv6_nc_t *)msg.content.ptr);
break;
case NG_NDP_MSG_NC_STATE_TIMEOUT:
DEBUG("ipv6: Neigbor cace state timeout received\n");
ng_ndp_state_timeout((ng_ipv6_nc_t *)msg.content.ptr);
break;
default:
break;
}
......@@ -411,8 +434,6 @@ static void _send(ng_pktsnip_t *pkt, bool prep_hdr)
kernel_pid_t iface = KERNEL_PID_UNDEF;
ng_pktsnip_t *ipv6, *payload;
ng_ipv6_hdr_t *hdr;
ng_ipv6_nc_t *nc_entry;
/* seize payload as temporary variable */
payload = ng_pktbuf_start_write(pkt);
......@@ -442,24 +463,14 @@ static void _send(ng_pktsnip_t *pkt, bool prep_hdr)
_send_multicast(iface, pkt, ipv6, payload, prep_hdr);
}
else {
ng_ipv6_addr_t *next_hop = NULL;
uint8_t l2addr_len = NG_IPV6_NC_L2_ADDR_MAX;
uint8_t l2addr[l2addr_len];
next_hop = &hdr->dst; /* TODO: next hop determination */
if (((nc_entry = ng_ipv6_nc_get(iface, next_hop)) == NULL) ||
!ng_ipv6_nc_is_reachable(nc_entry)) {
DEBUG("ipv6: No link layer address for next_hop %s found.\n",
ng_ipv6_addr_to_str(addr_str, next_hop, sizeof(addr_str)));
ng_pktbuf_release(pkt);
return;
}
else {
iface = nc_entry->iface;
}
iface = ng_ndp_next_hop_l2addr(l2addr, &l2addr_len, iface, &hdr->dst,
pkt);
if (iface == KERNEL_PID_UNDEF) {
DEBUG("ipv6: no interface for %s registered, dropping packet\n",
ng_ipv6_addr_to_str(addr_str, next_hop, sizeof(addr_str)));
DEBUG("ipv6: error determining next hop's link layer address\n");
ng_pktbuf_release(pkt);
return;
}
......@@ -472,7 +483,7 @@ static void _send(ng_pktsnip_t *pkt, bool prep_hdr)
}
}
_send_unicast(iface, nc_entry->l2_addr, nc_entry->l2_addr_len, pkt);
_send_unicast(iface, l2addr, l2addr_len, pkt);
}
}
......
include $(RIOTBASE)/Makefile.base
This diff is collapsed.
......@@ -23,6 +23,7 @@
#include "byteorder.h"
#include "net/ng_icmpv6.h"
#include "net/ng_ipv6/addr.h"
#include "net/ng_ipv6/nc.h"
#include "net/ng_ipv6/hdr.h"
#include "net/ng_netbase.h"
#include "thread.h"
......@@ -83,6 +84,7 @@ int _handle_reply(ng_pktsnip_t *pkt, uint64_t time)
ng_ipv6_addr_to_str(ipv6_str, &(ipv6_hdr->src), sizeof(ipv6_str)),
byteorder_ntohs(icmpv6_hdr->id), byteorder_ntohs(icmpv6_hdr->seq),
ipv6_hdr->hl, time / MS_IN_USEC, time % MS_IN_USEC);
ng_ipv6_nc_still_reachable(&ipv6_hdr->src);
}
else {
puts("error: unexpected parameters");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment