Skip to content

Commit

Permalink
ng_rpl: auto address configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
cgundogan committed Jul 23, 2015
1 parent dca3ba5 commit 79efaae
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
17 changes: 17 additions & 0 deletions sys/include/net/ng_rpl/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,23 @@ typedef struct __attribute__((packed)) {
uint8_t path_lifetime; /**< lifetime of routes */
} ng_rpl_opt_transit_t;

/**
* @brief Prefix Information Option
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.7.10">
* Prefix Information
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< option type */
uint8_t length; /**< option length without the first two bytes */
uint8_t prefix_len; /**< prefix length */
uint8_t LAR_flags; /**< flags and resereved */
uint32_t valid_lifetime; /**< valid lifetime */
uint32_t pref_lifetime; /**< preferred lifetime */
uint32_t reserved; /**< reserved */
ng_ipv6_addr_t prefix; /**< prefix */
} ng_rpl_opt_prefix_info_t;

typedef struct ng_rpl_dodag ng_rpl_dodag_t;
typedef struct ng_rpl_parent ng_rpl_parent_t;

Expand Down
32 changes: 32 additions & 0 deletions sys/net/routing/ng_rpl/ng_rpl_control_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
#include "net/ng_rpl.h"
#include "inet_ntop.h"
#include "net/eui64.h"

#define ENABLE_DEBUG (0)
#include "debug.h"
Expand All @@ -25,6 +26,7 @@ static char addr_str[NG_IPV6_ADDR_MAX_STR_LEN];
#define NG_RPL_GROUNDED_SHIFT (7)
#define NG_RPL_MOP_SHIFT (3)
#define NG_RPL_OPT_DODAG_CONF_LEN (14)
#define NG_RPL_OPT_PREFIX_INFO_LEN (30)
#define NG_RPL_SHIFTED_MOP_MASK (0x7)
#define NG_RPL_PRF_MASK (0x7)

Expand Down Expand Up @@ -81,11 +83,13 @@ void ng_rpl_send_DIO(ng_rpl_dodag_t *dodag, ng_ipv6_addr_t *destination)
ng_icmpv6_hdr_t *icmp;
ng_rpl_dio_t *dio;
ng_rpl_opt_dodag_conf_t *dodag_conf;
ng_rpl_opt_prefix_info_t *prefix_info;
uint8_t *pos;
int size = sizeof(ng_icmpv6_hdr_t) + sizeof(ng_rpl_dio_t);

if ((dodag->dodag_conf_counter % 3) == 0) {
size += sizeof(ng_rpl_opt_dodag_conf_t);
size += sizeof(ng_rpl_opt_prefix_info_t);
}

if ((pkt = ng_icmpv6_build(NULL, NG_ICMPV6_RPL_CTRL, NG_RPL_ICMPV6_CODE_DIO, size)) == NULL) {
Expand Down Expand Up @@ -123,6 +127,19 @@ void ng_rpl_send_DIO(ng_rpl_dodag_t *dodag, ng_ipv6_addr_t *destination)
dodag_conf->default_lifetime = dodag->default_lifetime;
dodag_conf->lifetime_unit = byteorder_htons(dodag->lifetime_unit);
pos += sizeof(*dodag_conf);

prefix_info = (ng_rpl_opt_prefix_info_t *) pos;
prefix_info->type = NG_RPL_OPT_PREFIX_INFO;
prefix_info->length = NG_RPL_OPT_PREFIX_INFO_LEN;
/* auto-address configuration */
prefix_info->LAR_flags = (1 << 6);
prefix_info->valid_lifetime = 0xFFFFFFFF;
prefix_info->pref_lifetime = 0xFFFFFFFF;
prefix_info->prefix_len = 64;
prefix_info->reserved = 0;
memset(&prefix_info->prefix, 0, sizeof(prefix_info->prefix));
memcpy(&prefix_info->prefix, &dodag->dodag_id, prefix_info->prefix_len/8);
pos += sizeof(*prefix_info);
}

dodag->dodag_conf_counter++;
Expand Down Expand Up @@ -178,6 +195,7 @@ void _parse_options(ng_rpl_dodag_t *dodag, ng_rpl_opt_t *opt, uint16_t len, ng_i
{
uint16_t l = 0;
ng_rpl_opt_target_t *first_target = NULL;
eui64_t iid;
while(l < len) {
switch(opt->type) {
case (NG_RPL_OPT_PAD1): {
Expand Down Expand Up @@ -213,6 +231,20 @@ void _parse_options(ng_rpl_dodag_t *dodag, ng_rpl_opt_t *opt, uint16_t len, ng_i
dodag->trickle.k = dodag->dio_redun;
break;
}
case (NG_RPL_OPT_PREFIX_INFO): {
DEBUG("RPL: Prefix Information DIO option parsed\n");
ng_rpl_opt_prefix_info_t *pi = (ng_rpl_opt_prefix_info_t *) opt;
kernel_pid_t if_id = ng_ipv6_netif_find_by_prefix(NULL, &dodag->dodag_id);
/* check for the auto address-configuration flag */
if ((ng_netapi_get(if_id, NETCONF_OPT_IPV6_IID, 0, &iid, sizeof(eui64_t)) < 0) &&
!(pi->LAR_flags & (1 << 6))) {

This comment has been minimized.

Copy link
@jnohlgard

jnohlgard Jul 23, 2015

Member

Replace magic number with a constant

break;
}
ng_ipv6_addr_set_aiid(&pi->prefix, iid.uint8);
ng_ipv6_netif_add_addr(if_id, &pi->prefix, pi->prefix_len, 0);

break;
}
case (NG_RPL_OPT_TARGET): {
DEBUG("RPL: RPL TARGET DAO option parsed\n");
ng_rpl_opt_target_t *target = (ng_rpl_opt_target_t *) opt;
Expand Down

0 comments on commit 79efaae

Please sign in to comment.