Merge pull request #268 from cetic/fix-rpl-address-selection

Always select a global address within the DODAG
This commit is contained in:
Simon Duquennoy 2017-12-22 13:24:24 +01:00 committed by GitHub
commit 624925d5bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 6 deletions

View File

@ -141,15 +141,23 @@ get_global_addr(uip_ipaddr_t *addr)
{
int i;
int state;
uip_ipaddr_t *prefix = NULL;
uint8_t prefix_length = 0;
rpl_dag_t *dag = rpl_get_any_dag();
if(dag != NULL && dag->prefix_info.length != 0) {
prefix = &dag->prefix_info.prefix;
prefix_length = dag->prefix_info.length;
}
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
state = uip_ds6_if.addr_list[i].state;
if(uip_ds6_if.addr_list[i].isused &&
(state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
if(!uip_is_addr_linklocal(&uip_ds6_if.addr_list[i].ipaddr)) {
memcpy(addr, &uip_ds6_if.addr_list[i].ipaddr, sizeof(uip_ipaddr_t));
return 1;
}
state == ADDR_PREFERRED &&
!uip_is_addr_linklocal(&uip_ds6_if.addr_list[i].ipaddr) &&
(prefix == NULL || uip_ipaddr_prefixcmp(prefix, &uip_ds6_if.addr_list[i].ipaddr, prefix_length))) {
memcpy(addr, &uip_ds6_if.addr_list[i].ipaddr, sizeof(uip_ipaddr_t));
return 1;
}
}
return 0;

View File

@ -71,12 +71,20 @@ rpl_get_global_address(void)
int i;
uint8_t state;
uip_ipaddr_t *ipaddr = NULL;
uip_ipaddr_t *prefix = NULL;
uint8_t prefix_length = 0;
if(curr_instance.used && curr_instance.dag.prefix_info.length != 0) {
prefix = &curr_instance.dag.prefix_info.prefix;
prefix_length = curr_instance.dag.prefix_info.length;
}
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
state = uip_ds6_if.addr_list[i].state;
if(uip_ds6_if.addr_list[i].isused &&
state == ADDR_PREFERRED &&
!uip_is_addr_linklocal(&uip_ds6_if.addr_list[i].ipaddr)) {
!uip_is_addr_linklocal(&uip_ds6_if.addr_list[i].ipaddr) &&
(prefix == NULL || uip_ipaddr_prefixcmp(prefix, &uip_ds6_if.addr_list[i].ipaddr, prefix_length))) {
ipaddr = &uip_ds6_if.addr_list[i].ipaddr;
}
}