Skip to content

Commit

Permalink
ng_ndp/ng_sixlowpan: import 6LoWPAN-ND host behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed May 31, 2015
1 parent 2f218c0 commit 5841e25
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 28 deletions.
8 changes: 8 additions & 0 deletions sys/include/net/ng_sixlowpan/nd.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
extern "C" {
#endif

/**
* @brief Interval in seconds between initial router solicitation
* transmissions
*
* @see @ref NG_NDP_MAX_RTR_SOL_INT
*/
#define NG_SIXLOWPAN_ND_MAX_RTR_SOL_INT (10U)

/**
* @{
* @name New option types
Expand Down
23 changes: 21 additions & 2 deletions sys/net/network_layer/ng_ipv6/netif/ng_ipv6_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ static ng_ipv6_addr_t *_add_addr_to_entry(ng_ipv6_netif_t *entry, const ng_ipv6_
tmp_addr->flags |= NG_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST;
}
else {
ng_ipv6_addr_t sol_node;

if (!ng_ipv6_addr_is_link_local(addr)) {
/* add also corresponding link-local address */
ng_ipv6_addr_t ll_addr;
Expand All @@ -93,8 +91,21 @@ static ng_ipv6_addr_t *_add_addr_to_entry(ng_ipv6_netif_t *entry, const ng_ipv6_
tmp_addr->flags |= NG_IPV6_NETIF_ADDR_FLAGS_NDP_ON_LINK;
}

#ifdef MODULE_NG_SIXLOWPAN_ND
/* https://tools.ietf.org/html/rfc6775#section-5.2 states a join to
* the solicited nodes address is not necessary for 6LoWPAN */
if (!(entry->flags & NG_IPV6_NETIF_FLAGS_SIXLOWPAN)) {
ng_ipv6_addr_t sol_node;

ng_ipv6_addr_set_solicited_nodes(&sol_node, addr);
_add_addr_to_entry(entry, &sol_node, NG_IPV6_ADDR_BIT_LEN, 0);
}
#else
ng_ipv6_addr_t sol_node;

ng_ipv6_addr_set_solicited_nodes(&sol_node, addr);
_add_addr_to_entry(entry, &sol_node, NG_IPV6_ADDR_BIT_LEN, 0);
#endif
}

return &(tmp_addr->addr);
Expand Down Expand Up @@ -535,6 +546,14 @@ void ng_ipv6_netif_init_by_dev(void)
ipv6_ifs->flags |= NG_IPV6_NETIF_FLAGS_SIXLOWPAN;
}

hwaddr_len = 8;

#ifdef MODULE_NG_SIXLOWPAN_ND
/* https://tools.ietf.org/html/rfc6775#section-5.2 states that the
* link-local addresses are formed by the EUI-64 */
ng_netapi_set(ifs[i], NETCONF_OPT_SRC_LEN, 0, &hwaddr_len,
sizeof(hwaddr_len));
#endif
#endif

if ((ng_netapi_get(ifs[i], NETCONF_OPT_SRC_LEN, 0, &hwaddr_len,
Expand Down
13 changes: 11 additions & 2 deletions sys/net/network_layer/ng_ndp/hst/ng_ndp_hst.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "net/ng_netapi.h"
#include "net/ng_netif/hdr.h"
#include "net/ng_pktbuf.h"
#include "net/ng_sixlowpan/nd.h"
#include "vtimer.h"

#include "net/ng_ndp/hst.h"
Expand Down Expand Up @@ -45,12 +46,20 @@ void ng_ndp_hst_solicitate_router(ng_ipv6_netif_t *iface)
}

if (iface->initial_phase > 0) {
DEBUG("ndp hst: retransmit rtr sol in %d sec\n", NG_NDP_MAX_RTR_SOL_INT);
uint32_t interval = NG_NDP_MAX_RTR_SOL_INT;

#ifdef MODULE_NG_SIXLOWPAN_ND
if (iface->flags & NG_IPV6_NETIF_FLAGS_SIXLOWPAN) {
interval = NG_SIXLOWPAN_ND_MAX_RTR_SOL_INT;
}
#endif

DEBUG("ndp hst: retransmit rtr sol in %d sec\n", interval);

iface->initial_phase--;

vtimer_remove(&iface->rtr_sol_timer);
vtimer_set_msg(&iface->rtr_sol_timer, timex_set(NG_NDP_MAX_RTR_SOL_INT, 0),
vtimer_set_msg(&iface->rtr_sol_timer, timex_set(interval, 0),
ng_ipv6_pid, NG_NDP_MSG_RTR_SOL, iface);
}

Expand Down
66 changes: 42 additions & 24 deletions sys/net/network_layer/ng_ndp/ng_ndp.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,40 @@ static ng_ipv6_addr_t *_default_router(void)
return &router->ipv6_addr;
}


static void _l2_addr_resolution(uint8_t *l2addr, uint8_t *l2addr_len,
kernel_pid_t iface, ng_ipv6_addr_t *next_hop_ip,
ng_ipv6_nc_t *nc_entry)
{
ng_ipv6_addr_t dst_sol;

ng_ipv6_addr_set_solicited_nodes(&dst_sol, next_hop_ip);

if (iface == KERNEL_PID_UNDEF) {
timex_t t = { 0, NG_NDP_RETRANS_TIMER };
kernel_pid_t ifs[NG_NETIF_NUMOF];
size_t ifnum = ng_netif_get(ifs);

for (size_t i = 0; i < ifnum; i++) {
_ndp_send_nbr_sol(ifs[i], next_hop_ip, &dst_sol);
}

vtimer_set_msg(&nc_entry->nbr_sol_timer, t, ng_ipv6_pid,
NG_NDP_MSG_NBR_SOL_RETRANS, nc_entry);
}
else {
ng_ipv6_netif_t *ipv6_iface = ng_ipv6_netif_get(iface);

_ndp_send_nbr_sol(iface, next_hop_ip, &dst_sol);

mutex_lock(&ipv6_iface->mutex);
vtimer_set_msg(&nc_entry->nbr_sol_timer,
ipv6_iface->retrans_timer, ng_ipv6_pid,
NG_NDP_MSG_NBR_SOL_RETRANS, nc_entry);
mutex_unlock(&ipv6_iface->mutex);
}
}

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)
Expand Down Expand Up @@ -513,7 +547,6 @@ kernel_pid_t ng_ndp_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_len,
}
else if (nc_entry == NULL) {
ng_pktqueue_node_t *pkt_node;
ng_ipv6_addr_t dst_sol;

nc_entry = ng_ipv6_nc_add(iface, next_hop_ip, NULL, 0,
NG_IPV6_NC_STATE_INCOMPLETE << NG_IPV6_NC_STATE_POS);
Expand All @@ -535,31 +568,16 @@ kernel_pid_t ng_ndp_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_len,
}

/* address resolution */
ng_ipv6_addr_set_solicited_nodes(&dst_sol, next_hop_ip);

if (iface == KERNEL_PID_UNDEF) {
timex_t t = { 0, NG_NDP_RETRANS_TIMER };
kernel_pid_t ifs[NG_NETIF_NUMOF];
size_t ifnum = ng_netif_get(ifs);
#ifdef MODULE_NG_SIXLOWPAN_ND
ng_ipv6_netif_t iface_entry = ng_ipv6_netif_get(iface);

for (size_t i = 0; i < ifnum; i++) {
_ndp_send_nbr_sol(ifs[i], next_hop_ip, &dst_sol);
}

vtimer_set_msg(&nc_entry->nbr_sol_timer, t, ng_ipv6_pid,
NG_NDP_MSG_NBR_SOL_RETRANS, nc_entry);
}
else {
ng_ipv6_netif_t *ipv6_iface = ng_ipv6_netif_get(iface);

_ndp_send_nbr_sol(iface, next_hop_ip, &dst_sol);

mutex_lock(&ipv6_iface->mutex);
vtimer_set_msg(&nc_entry->nbr_sol_timer,
ipv6_iface->retrans_timer, ng_ipv6_pid,
NG_NDP_MSG_NBR_SOL_RETRANS, nc_entry);
mutex_unlock(&ipv6_iface->mutex);
if (!(iface_entry->flags & NG_IPV6_NETIF_FLAGS_SIXLOWPAN)) {
_l2_addr_resolution(l2addr, l2addr_len, iface, next_hop_ip,
nc_entry);
}
#else
_l2_addr_resolution(l2addr, l2addr_len, iface, next_hop_ip, nc_entry);
#endif
}
}

Expand Down

0 comments on commit 5841e25

Please sign in to comment.