Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng_ndp: initial import of address resolution #2910

Merged
merged 2 commits into from
May 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)))
Expand Down
3 changes: 3 additions & 0 deletions sys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions sys/include/net/ng_ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion sys/include/net/ng_ipv6/nc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
/**
* @}
*/
Expand Down
23 changes: 23 additions & 0 deletions sys/include/net/ng_ipv6/netif.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
297 changes: 297 additions & 0 deletions sys/include/net/ng_ndp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,297 @@
/*
* Copyright (C) 2015 Martine Lenders <[email protected]>
*
* 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 <[email protected]>
*/

#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_ */
/**
* @}
*/
Loading