Skip to content

Commit

Permalink
[SQUASH ME] finish router discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Apr 4, 2015
1 parent f76eaf1 commit 0279330
Show file tree
Hide file tree
Showing 6 changed files with 589 additions and 204 deletions.
16 changes: 5 additions & 11 deletions sys/include/net/ng_ipv6/nc.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
#ifndef NG_IPV6_NC_H_
#define NG_IPV6_NC_H_

#include <stdbool.h>
#include <stdint.h>

#include "kernel_types.h"
#include "net/ng_ipv6/addr.h"
#include "net/ng_netif.h"
#include "net/ng_pktqueue.h"
#include "timex.h"
#include "vtimer.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -123,14 +124,7 @@ typedef struct {
uint8_t l2_addr_len; /**< Length of ng_ipv6_nc_t::l2_addr */
uint8_t flags; /**< Flags as defined above */
kernel_pid_t iface; /**< PID to the interface where the neighbor is */
/**
* @{
* @name Variables for the neighbor discovery.
*/
/**
* @brief Lifetime in seconds if entry is router. 0 (default) if no router.
*/
uint16_t rtr_ltime;
vtimer_t rtr_timeout; /**< timeout timer for router flag */
uint8_t unanswered_probes; /**< number of unanswered probes */
/**
* @}
Expand Down Expand Up @@ -209,9 +203,9 @@ ng_ipv6_nc_t *ng_ipv6_nc_get_next_router(ng_ipv6_nc_t *prev);
* @return true, if you can send packets to @p entry
* @return false, if you can't send packets to @p entry
*/
ng_ipv6_nc_t *ng_ipv6_nc_is_reachable(const ng_ipv6_nc_t *entry)
bool ng_ipv6_nc_is_reachable(const ng_ipv6_nc_t *entry)
{
switch ((entry->flags & NG_IPV6_NC_STATE_MASK) >> NG_IPV6_NC_STATE_POS) {
switch ((entry->flags & NG_IPV6_NC_STATE_MASK)) {
case NG_IPV6_NC_STATE_UNREACHABLE:
case NG_IPV6_NC_STATE_INCOMPLETE:
case NG_IPV6_NC_STATE_STALE:
Expand Down
113 changes: 23 additions & 90 deletions sys/include/net/ng_ipv6/netif.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "kernel_types.h"
#include "mutex.h"
#include "net/ng_ipv6/addr.h"
#include "timex.h"
#include "vtimer.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -118,17 +117,20 @@ typedef struct {
* </a>
*/
/**
* @brief The length of time this address is valid. If timex_t::seconds
* is UINT32_MAX the lifetime is infinite.
* @brief The length of time this address is valid. If it is UINT32_MAX
* the lifetime is infinite.
*/
timex_t valid;

uint32_t valid;
/**
* @brief The length of time that this address remains preferred.
* If timex_t::seconds is UINT32_MAX the lifetime is infinite.
* If it is UINT32_MAX the lifetime is infinite.
* It **must** be < ng_ipv6_netif_addr_t::valid.
*/
timex_t preferred;
uint32_t preferred;
/**
* @brief Validity timeout timer.
*/
vtimer_t valid_timeout;
/**
* @}
*/
Expand All @@ -142,8 +144,9 @@ typedef struct {
* to the interface */
mutex_t mutex; /**< mutex for the interface */
kernel_pid_t pid; /**< PID of the interface */
uint16_t mtu; /**< Maximum Transmission Unit (MTU) of the interface */
uint32_t mtu; /**< Maximum Transmission Unit (MTU) of the interface */
uint8_t cur_hl; /**< current hop limit for the interface */
uint16_t flags; /**< flags as defined in @ref net_ng_ndp and above. */
/**
* @{
* @name Neighbor discovery variables
Expand All @@ -154,8 +157,6 @@ typedef struct {
* RFC 4861, section 6.3.2
* </a>
*/
uint16_t flags; /**< flags for neighbor discovery as defined in
* @ref net_ng_ndp and above. */
/**
* @brief Base value in microseconds for computing random
* ng_ipv6_netif_t::reach_time.
Expand Down Expand Up @@ -264,19 +265,17 @@ ng_ipv6_netif_t *ng_ipv6_netif_get(kernel_pid_t pid);
* RFC 4291, section 2.6
* </a>
*
* @return 0, on success.
* @return -EINVAL, if @p addr is NULL or unspecified address or if
* @p prefix length was < 1 or > 128.
* @return -ENOENT, if @p pid is no interface.
* @return -ENOMEM, if there is no space left to store @p addr.
* @return The address on the interface, on success.
* @return NULL, on failure
*/
int ng_ipv6_netif_add_addr(kernel_pid_t pid, const ng_ipv6_addr_t *addr,
uint8_t prefix_len, uint8_t flags);
ng_ipv6_addr_t *ng_ipv6_netif_add_addr(kernel_pid_t pid, const ng_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.
* @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 ng_ipv6_netif_remove_addr(kernel_pid_t pid, ng_ipv6_addr_t *addr);
Expand Down Expand Up @@ -355,12 +354,18 @@ ng_ipv6_addr_t *ng_ipv6_netif_match_prefix(kernel_pid_t pid,
*/
ng_ipv6_addr_t *ng_ipv6_netif_find_best_src_addr(kernel_pid_t pid, const ng_ipv6_addr_t *dest);

static inline ng_ipv6_netif_addr_t *ng_ipv6_netif_addr_get(const ng_ipv6_addr_t *addr)
{
return container_of(addr, ng_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:
*
* * ng_ipv6_netif_add_addr()
* * ng_ipv6_find_addr()
* * ng_ipv6_find_addr_local()
* * ng_ipv6_find_prefix_match()
Expand All @@ -381,78 +386,6 @@ static inline bool ng_ipv6_netif_addr_is_non_unicast(const ng_ipv6_addr_t *addr)

}

/**
* @brief Checks if an address is on-link.
*
* @details This only works with addresses you retrieved via the following
* functions:
*
* * ng_ipv6_find_addr()
* * ng_ipv6_find_addr_local()
* * ng_ipv6_find_prefix_match()
* * ng_ipv6_find_prefix_match_local()
* * ng_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 on-link.
* @return false, if address is off-link.
*/
static inline bool ng_ipv6_netif_addr_on_link(const ng_ipv6_addr_t *addr)
{
return (bool)(container_of(addr, ng_ipv6_netif_addr_t, addr)->flags &
NG_IPV6_NETIF_FLAGS_NDP_ON_LINK);

}

/**
* @brief Sets the valid lifetime of an address/prefix.
*
* @details This only works with addresses you retrieved via the following
* functions:
*
* * ng_ipv6_find_addr()
* * ng_ipv6_find_addr_local()
* * ng_ipv6_find_prefix_match()
* * ng_ipv6_find_prefix_match_local()
* * ng_ipv6_find_best_src_address()
*
* The behaviour for other addresses is undefined.
*
* @param[in] addr The address/prefix you want to set the valid lifetime for.
* @param[in] valid The valid lifetime in seconds
*/
static inline void ng_ipv6_netif_addr_set_valid(const ng_ipv6_addr_t *addr,
uint32_t valid)
{
container_of(addr, ng_ipv6_netif_addr_t, addr)->valid = timex_set(valid, 0);
}

/**
* @brief Sets the preferred lifetime of an address/prefix.
*
* @details This only works with addresses you retrieved via the following
* functions:
*
* * ng_ipv6_find_addr()
* * ng_ipv6_find_addr_local()
* * ng_ipv6_find_prefix_match()
* * ng_ipv6_find_prefix_match_local()
* * ng_ipv6_find_best_src_address()
*
* The behaviour for other addresses is undefined.
*
* @param[in] addr The address/prefix you want to set the preferred
* lifetime for.
* @param[in] prefered The preferred lifetime in seconds
*/
static inline void ng_ipv6_netif_addr_set_preferred(const ng_ipv6_addr_t *addr,
uint32_t preferred)
{
container_of(addr, ng_ipv6_netif_addr_t, addr)->preferred = timex_set(preferred, 0);
}
#ifdef __cplusplus
}
#endif
Expand Down
33 changes: 19 additions & 14 deletions sys/include/net/ng_ndp.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ extern "C" {

#define NG_NDP_MSG_RTR_ADV (0x0210) /**< Message type for periodic
* Router advertisements */
#define NG_NDP_MSG_RTR_TIMEOUT (0x0211) /**< Message type for router timeouts */
#define NG_NDP_MSG_ADDR_TIMEOUT (0x0212) /**< Message type for address timeouts */

/**
* @{
Expand All @@ -47,8 +49,9 @@ extern "C" {
* RFC 4861, section 4.2
* </a>
*/
#define NG_NDP_RTR_ADV_FLAGS_M (0x80) /**< managed address configuration */
#define NG_NDP_RTR_ADV_FLAGS_O (0x40) /**< other configuration */
#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 */
/**
* @}
*/
Expand All @@ -60,9 +63,10 @@ extern "C" {
* RFC 4861, section 4.2
* </a>
*/
#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 */
#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 */
/**
* @}
*/
Expand All @@ -74,11 +78,11 @@ extern "C" {
* 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 */
#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 */
/**
* @}
*/
Expand All @@ -87,8 +91,9 @@ extern "C" {
* @{
* @name Flags for prefix information option
*/
#define NG_NDP_OPT_PI_FLAGS_L (0x80) /**< on-link */
#define NG_NDP_OPT_PI_FLAGS_A (0x40) /**< autonomous address configuration */
#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 */
/**
* @}
*/
Expand All @@ -98,8 +103,8 @@ extern "C" {
* @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)
#define NG_NDP_OPT_PI_LEN (4U)
#define NG_NDP_OPT_MTU_LEN (1U)
/*
* @}
*/
Expand Down
Loading

0 comments on commit 0279330

Please sign in to comment.