Skip to content
Snippets Groups Projects
Commit 569d2918 authored by Joakim Nohlgård's avatar Joakim Nohlgård
Browse files

Merge pull request #2543 from cgundogan/rpl_use_global_address

rpl: use global ip addresses instead of link-local ones
parents cce3edba 5d382b4a
No related branches found
No related tags found
No related merge requests found
...@@ -96,42 +96,46 @@ void rpl_udp_init(int argc, char **argv) ...@@ -96,42 +96,46 @@ void rpl_udp_init(int argc, char **argv)
printf("Channel set to %" PRIi32 "\n", chan); printf("Channel set to %" PRIi32 "\n", chan);
/* global address */
ipv6_addr_t global_addr, global_prefix;
ipv6_addr_init(&global_prefix, 0xabcd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0);
ipv6_addr_set_by_eui64(&global_addr, 0, &global_prefix);
if (command != 'h') { if (command != 'h') {
DEBUGF("Initializing RPL for interface 0\n"); DEBUGF("Initializing RPL for interface 0\n");
uint8_t state = rpl_init(0);
if (state != SIXLOWERROR_SUCCESS) { uint8_t state;
printf("Error initializing RPL\n"); if (command == 'n') {
/*
* no global address specified, we'll use auto address config
* initiated by the root node
*/
state = rpl_init(0, NULL);
} }
else { else if (command == 'r') {
puts("6LoWPAN and RPL initialized.");
}
if (command == 'r') {
/* add global address */
ipv6_addr_t tmp;
/* initialize prefix */
ipv6_addr_init(&tmp, 0xabcd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0);
rpl_options_t rpl_opts = { rpl_options_t rpl_opts = {
.instance_id = 0, .instance_id = 0,
.prefix = tmp, .prefix = global_prefix,
.prefix_len = 64, .prefix_len = 64,
.prefix_flags = RPL_PREFIX_INFO_AUTO_ADDR_CONF, /* autonomous address-configuration */ .prefix_flags = RPL_PREFIX_INFO_AUTO_ADDR_CONF,
/* autonomous address-configuration */
}; };
tmp.uint16[7] = HTONS(id); /* use specific global address */
/* set host suffix */ state = rpl_init(0, &global_addr);
ipv6_addr_set_by_eui64(&tmp, 0, &tmp);
ipv6_net_if_add_addr(0, &tmp, NDP_ADDR_STATE_PREFERRED, 0, 0, 0);
rpl_init_root(&rpl_opts); rpl_init_root(&rpl_opts);
ipv6_iface_set_routing_provider(rpl_get_next_hop);
is_root = 1; is_root = 1;
} }
if (state != SIXLOWERROR_SUCCESS) {
puts("Error initializing RPL");
}
else { else {
ipv6_iface_set_routing_provider(rpl_get_next_hop); puts("6LoWPAN and RPL initialized.");
} }
ipv6_iface_set_routing_provider(rpl_get_next_hop);
} }
else { else {
puts("6LoWPAN initialized."); puts("6LoWPAN initialized.");
......
...@@ -73,12 +73,13 @@ void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_ ...@@ -73,12 +73,13 @@ void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_
* corresponding objective functions and sixlowpan (including own address). * corresponding objective functions and sixlowpan (including own address).
* *
* @param[in] if_id ID of the interface, which correspond to the network under RPL-control * @param[in] if_id ID of the interface, which correspond to the network under RPL-control
* @param[in] address Global IPv6 address to use
* *
* @return 1 if initialization was successful * @return 1 if initialization was successful
* @return 0 if initialization was not successful * @return 0 if initialization was not successful
* *
*/ */
uint8_t rpl_init(int if_id); uint8_t rpl_init(int if_id, ipv6_addr_t *address);
/** /**
* @brief Initialization of RPL-root. * @brief Initialization of RPL-root.
......
...@@ -73,7 +73,7 @@ ipv6_addr_t my_address; ...@@ -73,7 +73,7 @@ ipv6_addr_t my_address;
/* IPv6 message buffer */ /* IPv6 message buffer */
static ipv6_hdr_t *ipv6_buf; static ipv6_hdr_t *ipv6_buf;
uint8_t rpl_init(int if_id) uint8_t rpl_init(int if_id, ipv6_addr_t *address)
{ {
rpl_if_id = if_id; rpl_if_id = if_id;
rpl_instances_init(); rpl_instances_init();
...@@ -89,12 +89,13 @@ uint8_t rpl_init(int if_id) ...@@ -89,12 +89,13 @@ uint8_t rpl_init(int if_id)
rpl_process, NULL, "rpl_process"); rpl_process, NULL, "rpl_process");
sixlowpan_lowpan_init_interface(if_id); sixlowpan_lowpan_init_interface(if_id);
/* need link local prefix to query _our_ corresponding address */
ipv6_addr_t ll_address;
ipv6_addr_set_link_local_prefix(&ll_address);
ipv6_net_if_get_best_src_addr(&my_address, &ll_address);
ipv6_register_rpl_handler(rpl_process_pid); ipv6_register_rpl_handler(rpl_process_pid);
if (address) {
my_address = *address;
ipv6_net_if_add_addr(if_id, &my_address, NDP_ADDR_STATE_PREFERRED, 0, 0, 0);
}
/* add all-RPL-nodes address */ /* add all-RPL-nodes address */
ipv6_addr_t all_rpl_nodes; ipv6_addr_t all_rpl_nodes;
ipv6_addr_set_all_rpl_nodes_addr(&all_rpl_nodes); ipv6_addr_set_all_rpl_nodes_addr(&all_rpl_nodes);
......
...@@ -426,7 +426,14 @@ void rpl_send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifet ...@@ -426,7 +426,14 @@ void rpl_send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifet
rpl_send_opt_target_buf->length = RPL_OPT_TARGET_LEN; rpl_send_opt_target_buf->length = RPL_OPT_TARGET_LEN;
rpl_send_opt_target_buf->flags = 0x00; rpl_send_opt_target_buf->flags = 0x00;
rpl_send_opt_target_buf->prefix_length = RPL_DODAG_ID_LEN; rpl_send_opt_target_buf->prefix_length = RPL_DODAG_ID_LEN;
memcpy(&rpl_send_opt_target_buf->target, &my_address, sizeof(ipv6_addr_t)); if (!ipv6_addr_is_unspecified(&my_dodag->prefix)) {
ipv6_addr_t tmp;
ipv6_addr_set_by_eui64(&tmp, rpl_if_id, &my_dodag->prefix);
memcpy(&rpl_send_opt_target_buf->target, &tmp, sizeof(ipv6_addr_t));
}
else {
memcpy(&rpl_send_opt_target_buf->target, &my_address, sizeof(ipv6_addr_t));
}
opt_len += RPL_OPT_TARGET_LEN_WITH_OPT_LEN; opt_len += RPL_OPT_TARGET_LEN_WITH_OPT_LEN;
rpl_send_opt_transit_buf = get_rpl_send_opt_transit_buf(DAO_BASE_LEN + opt_len); rpl_send_opt_transit_buf = get_rpl_send_opt_transit_buf(DAO_BASE_LEN + opt_len);
......
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