mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-23 01:29:33 +00:00
Merge branch 'master' of ssh://contiki.git.sourceforge.net/gitroot/contiki/contiki
This commit is contained in:
commit
a47e75486c
@ -46,9 +46,7 @@
|
|||||||
#define ETX_LIMIT 15
|
#define ETX_LIMIT 15
|
||||||
#define ETX_SCALE 100
|
#define ETX_SCALE 100
|
||||||
#define ETX_ALPHA 90
|
#define ETX_ALPHA 90
|
||||||
#define ETX_FIRST_GUESS 5
|
#define ETX_NOACK_PENALTY ETX_LIMIT
|
||||||
|
|
||||||
#define NOACK_PACKET_ETX 8
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
NEIGHBOR_ATTRIBUTE(uint8_t, etx, NULL);
|
NEIGHBOR_ATTRIBUTE(uint8_t, etx, NULL);
|
||||||
|
|
||||||
@ -61,16 +59,17 @@ update_etx(const rimeaddr_t *dest, int packet_etx)
|
|||||||
uint8_t recorded_etx, new_etx;
|
uint8_t recorded_etx, new_etx;
|
||||||
|
|
||||||
etxp = (uint8_t *)neighbor_attr_get_data(&etx, dest);
|
etxp = (uint8_t *)neighbor_attr_get_data(&etx, dest);
|
||||||
|
packet_etx = NEIGHBOR_INFO_ETX2FIX(packet_etx);
|
||||||
if(etxp == NULL || *etxp == 0) {
|
if(etxp == NULL || *etxp == 0) {
|
||||||
recorded_etx = NEIGHBOR_INFO_ETX2FIX(ETX_FIRST_GUESS);
|
recorded_etx = NEIGHBOR_INFO_ETX2FIX(ETX_LIMIT);
|
||||||
|
new_etx = packet_etx;
|
||||||
} else {
|
} else {
|
||||||
recorded_etx = *etxp;
|
recorded_etx = *etxp;
|
||||||
|
/* Update the EWMA of the ETX for the neighbor. */
|
||||||
|
new_etx = ((uint16_t)recorded_etx * ETX_ALPHA +
|
||||||
|
(uint16_t)packet_etx * (ETX_SCALE - ETX_ALPHA)) / ETX_SCALE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update the EWMA of the ETX for the neighbor. */
|
|
||||||
packet_etx = NEIGHBOR_INFO_ETX2FIX(packet_etx);
|
|
||||||
new_etx = ((uint16_t)recorded_etx * ETX_ALPHA +
|
|
||||||
(uint16_t)packet_etx * (ETX_SCALE - ETX_ALPHA)) / ETX_SCALE;
|
|
||||||
PRINTF("neighbor-info: ETX changed from %d to %d (packet ETX = %d) %d\n",
|
PRINTF("neighbor-info: ETX changed from %d to %d (packet ETX = %d) %d\n",
|
||||||
NEIGHBOR_INFO_FIX2ETX(recorded_etx),
|
NEIGHBOR_INFO_FIX2ETX(recorded_etx),
|
||||||
NEIGHBOR_INFO_FIX2ETX(new_etx),
|
NEIGHBOR_INFO_FIX2ETX(new_etx),
|
||||||
@ -96,9 +95,6 @@ add_neighbor(const rimeaddr_t *addr)
|
|||||||
PRINTF("neighbor-info: The neighbor is already known\n");
|
PRINTF("neighbor-info: The neighbor is already known\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if(subscriber_callback != NULL) {
|
|
||||||
subscriber_callback(addr, 1, NEIGHBOR_INFO_ETX2FIX(ETX_FIRST_GUESS));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,18 +123,15 @@ neighbor_info_packet_sent(int status, int numtx)
|
|||||||
packet_etx = numtx;
|
packet_etx = numtx;
|
||||||
break;
|
break;
|
||||||
case MAC_TX_NOACK:
|
case MAC_TX_NOACK:
|
||||||
packet_etx = NOACK_PACKET_ETX;
|
packet_etx = ETX_NOACK_PENALTY;
|
||||||
/* error and collissions will not cause high hits ??? */
|
|
||||||
break;
|
break;
|
||||||
case MAC_TX_ERR:
|
|
||||||
default:
|
default:
|
||||||
packet_etx = 0;
|
/* Do not penalize the ETX when collisions or transmission
|
||||||
break;
|
errors occur. */
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(packet_etx > 0) {
|
update_etx(dest, packet_etx);
|
||||||
update_etx(dest, packet_etx);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
@ -175,6 +168,6 @@ neighbor_info_get_etx(const rimeaddr_t *addr)
|
|||||||
uint8_t *etxp;
|
uint8_t *etxp;
|
||||||
|
|
||||||
etxp = (uint8_t *)neighbor_attr_get_data(&etx, addr);
|
etxp = (uint8_t *)neighbor_attr_get_data(&etx, addr);
|
||||||
return etxp == NULL ? 0 : *etxp;
|
return etxp == NULL ? ETX_LIMIT : *etxp;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
@ -94,8 +94,6 @@ static rpl_of_t * const objective_functions[] = {&RPL_OF};
|
|||||||
#define RPL_DIO_INTERVAL_DOUBLINGS RPL_CONF_DIO_INTERVAL_DOUBLINGS
|
#define RPL_DIO_INTERVAL_DOUBLINGS RPL_CONF_DIO_INTERVAL_DOUBLINGS
|
||||||
#endif /* !RPL_CONF_DIO_INTERVAL_DOUBLINGS */
|
#endif /* !RPL_CONF_DIO_INTERVAL_DOUBLINGS */
|
||||||
|
|
||||||
#define INITIAL_ETX NEIGHBOR_INFO_ETX_DIVISOR * 5
|
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/* Allocate parents from the same static MEMB chunk to reduce memory waste. */
|
/* Allocate parents from the same static MEMB chunk to reduce memory waste. */
|
||||||
MEMB(parent_memb, struct rpl_parent, RPL_MAX_PARENTS);
|
MEMB(parent_memb, struct rpl_parent, RPL_MAX_PARENTS);
|
||||||
@ -309,7 +307,7 @@ rpl_add_parent(rpl_dag_t *dag, rpl_dio_t *dio, uip_ipaddr_t *addr)
|
|||||||
memcpy(&p->addr, addr, sizeof(p->addr));
|
memcpy(&p->addr, addr, sizeof(p->addr));
|
||||||
p->dag = dag;
|
p->dag = dag;
|
||||||
p->rank = dio->rank;
|
p->rank = dio->rank;
|
||||||
p->etx = INITIAL_ETX;
|
p->link_metric = INITIAL_LINK_METRIC;
|
||||||
p->dtsn = 0;
|
p->dtsn = 0;
|
||||||
|
|
||||||
memcpy(&p->mc, &dio->mc, sizeof(p->mc));
|
memcpy(&p->mc, &dio->mc, sizeof(p->mc));
|
||||||
@ -459,8 +457,6 @@ join_dag(uip_ipaddr_t *from, rpl_dio_t *dio)
|
|||||||
}
|
}
|
||||||
PRINTF("succeeded\n");
|
PRINTF("succeeded\n");
|
||||||
|
|
||||||
p->etx = INITIAL_ETX; /* The lowest confidence for new parents. */
|
|
||||||
|
|
||||||
/* Determine the objective function by using the
|
/* Determine the objective function by using the
|
||||||
objective code point of the DIO. */
|
objective code point of the DIO. */
|
||||||
of = rpl_find_of(dio->ocp);
|
of = rpl_find_of(dio->ocp);
|
||||||
@ -733,7 +729,7 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
|
|||||||
PRINTF(")\n");
|
PRINTF(")\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRINTF("RPL: New candidate parent with rank %u: ", (unsigned)p->rank);
|
PRINTF("RPL: New candidate parent with rank %u: ", (unsigned)p->rank);
|
||||||
PRINT6ADDR(from);
|
PRINT6ADDR(from);
|
||||||
PRINTF("\n");
|
PRINTF("\n");
|
||||||
@ -743,7 +739,8 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* We have allocated a candidate parent; process the DIO further. */
|
/* We have allocated a candidate parent; process the DIO further. */
|
||||||
|
|
||||||
|
memcpy(&p->mc, &dio->mc, sizeof(p->mc));
|
||||||
p->rank = dio->rank;
|
p->rank = dio->rank;
|
||||||
if(rpl_process_parent_event(dag, p) == 0) {
|
if(rpl_process_parent_event(dag, p) == 0) {
|
||||||
/* The candidate parent no longer exists. */
|
/* The candidate parent no longer exists. */
|
||||||
|
@ -66,7 +66,7 @@ rpl_of_t rpl_of_etx = {
|
|||||||
|
|
||||||
#define NI_ETX_TO_RPL_ETX(etx) \
|
#define NI_ETX_TO_RPL_ETX(etx) \
|
||||||
((etx) * (RPL_DAG_MC_ETX_DIVISOR / NEIGHBOR_INFO_ETX_DIVISOR))
|
((etx) * (RPL_DAG_MC_ETX_DIVISOR / NEIGHBOR_INFO_ETX_DIVISOR))
|
||||||
#define rpl_path_metric_tO_NI_ETX(etx) \
|
#define RPL_ETX_TO_NI_ETX(etx) \
|
||||||
((etx) / (RPL_DAG_MC_ETX_DIVISOR / NEIGHBOR_INFO_ETX_DIVISOR))
|
((etx) / (RPL_DAG_MC_ETX_DIVISOR / NEIGHBOR_INFO_ETX_DIVISOR))
|
||||||
|
|
||||||
/* Reject parents that have a higher link metric than the following. */
|
/* Reject parents that have a higher link metric than the following. */
|
||||||
@ -75,9 +75,6 @@ rpl_of_t rpl_of_etx = {
|
|||||||
/* Reject parents that have a higher path cost than the following. */
|
/* Reject parents that have a higher path cost than the following. */
|
||||||
#define MAX_PATH_COST 100
|
#define MAX_PATH_COST 100
|
||||||
|
|
||||||
/* An initial guess of the link metric. */
|
|
||||||
#define INITIAL_LINK_METRIC 3
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The rank must differ more than 1/PARENT_SWITCH_THRESHOLD_DIV in order
|
* The rank must differ more than 1/PARENT_SWITCH_THRESHOLD_DIV in order
|
||||||
* to switch preferred parent.
|
* to switch preferred parent.
|
||||||
@ -89,7 +86,10 @@ typedef uint16_t rpl_path_metric_t;
|
|||||||
static uint16_t
|
static uint16_t
|
||||||
calculate_path_metric(rpl_parent_t *p)
|
calculate_path_metric(rpl_parent_t *p)
|
||||||
{
|
{
|
||||||
return p->mc.obj.etx + NI_ETX_TO_RPL_ETX(p->etx);
|
if(p->mc.obj.etx == 0 && p->rank > ROOT_RANK(p->dag)) {
|
||||||
|
return MAX_PATH_COST * RPL_DAG_MC_ETX_DIVISOR;
|
||||||
|
}
|
||||||
|
return p->mc.obj.etx + NI_ETX_TO_RPL_ETX(p->link_metric);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -112,12 +112,9 @@ calculate_rank(rpl_parent_t *p, rpl_rank_t base_rank)
|
|||||||
if(base_rank == 0) {
|
if(base_rank == 0) {
|
||||||
return INFINITE_RANK;
|
return INFINITE_RANK;
|
||||||
}
|
}
|
||||||
rank_increase = INITIAL_LINK_METRIC * DEFAULT_MIN_HOPRANKINC;
|
rank_increase = NEIGHBOR_INFO_FIX2ETX(INITIAL_LINK_METRIC) * DEFAULT_MIN_HOPRANKINC;
|
||||||
} else {
|
} else {
|
||||||
if(p->etx == 0) {
|
rank_increase = NEIGHBOR_INFO_FIX2ETX(p->link_metric) * p->dag->min_hoprankinc;
|
||||||
p->etx = INITIAL_LINK_METRIC * NEIGHBOR_INFO_ETX_DIVISOR;
|
|
||||||
}
|
|
||||||
rank_increase = (p->etx * p->dag->min_hoprankinc) / NEIGHBOR_INFO_ETX_DIVISOR;
|
|
||||||
if(base_rank == 0) {
|
if(base_rank == 0) {
|
||||||
base_rank = p->rank;
|
base_rank = p->rank;
|
||||||
}
|
}
|
||||||
@ -180,6 +177,10 @@ update_metric_container(rpl_dag_t *dag)
|
|||||||
} else {
|
} else {
|
||||||
dag->mc.obj.etx = calculate_path_metric(dag->preferred_parent);
|
dag->mc.obj.etx = calculate_path_metric(dag->preferred_parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PRINTF("RPL: My path ETX to the root is %u.%u\n",
|
||||||
|
dag->mc.obj.etx / RPL_DAG_MC_ETX_DIVISOR,
|
||||||
|
(dag->mc.obj.etx % RPL_DAG_MC_ETX_DIVISOR * 100) / RPL_DAG_MC_ETX_DIVISOR);
|
||||||
#elif RPL_DAG_MC == RPL_DAG_MC_ENERGY
|
#elif RPL_DAG_MC == RPL_DAG_MC_ENERGY
|
||||||
dag->mc.type = RPL_DAG_MC_ENERGY;
|
dag->mc.type = RPL_DAG_MC_ENERGY;
|
||||||
dag->mc.flags = RPL_DAG_MC_FLAG_P;
|
dag->mc.flags = RPL_DAG_MC_FLAG_P;
|
||||||
@ -195,8 +196,4 @@ update_metric_container(rpl_dag_t *dag)
|
|||||||
#else
|
#else
|
||||||
#error "Unsupported RPL_DAG_MC configured. See rpl.h."
|
#error "Unsupported RPL_DAG_MC configured. See rpl.h."
|
||||||
#endif /* RPL_DAG_MC */
|
#endif /* RPL_DAG_MC */
|
||||||
|
|
||||||
PRINTF("RPL: My path ETX to the root is %u.%u\n",
|
|
||||||
dag->mc.obj.etx / RPL_DAG_MC_ETX_DIVISOR,
|
|
||||||
(dag->mc.obj.etx % RPL_DAG_MC_ETX_DIVISOR * 100) / RPL_DAG_MC_ETX_DIVISOR);
|
|
||||||
}
|
}
|
||||||
|
@ -127,6 +127,8 @@
|
|||||||
|
|
||||||
#define INFINITE_RANK 0xffff
|
#define INFINITE_RANK 0xffff
|
||||||
|
|
||||||
|
#define INITIAL_LINK_METRIC NEIGHBOR_INFO_ETX2FIX(5)
|
||||||
|
|
||||||
/* Represents 2^n ms. */
|
/* Represents 2^n ms. */
|
||||||
/* Default value according to the specification is 3 which
|
/* Default value according to the specification is 3 which
|
||||||
means 8 milliseconds, but that is an unreasonable value if
|
means 8 milliseconds, but that is an unreasonable value if
|
||||||
|
@ -148,11 +148,10 @@ rpl_link_neighbor_callback(const rimeaddr_t *addr, int known, int etx)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(etx != parent->etx) {
|
/* Trigger DAG rank recalculation. */
|
||||||
/* Trigger DAG rank recalculation. */
|
parent->updated = 1;
|
||||||
parent->updated = 1;
|
|
||||||
}
|
parent->link_metric = etx;
|
||||||
parent->etx = etx;
|
|
||||||
|
|
||||||
if(dag->of->parent_state_callback != NULL) {
|
if(dag->of->parent_state_callback != NULL) {
|
||||||
dag->of->parent_state_callback(parent, known, etx);
|
dag->of->parent_state_callback(parent, known, etx);
|
||||||
@ -163,7 +162,6 @@ rpl_link_neighbor_callback(const rimeaddr_t *addr, int known, int etx)
|
|||||||
PRINT6ADDR(&parent->addr);
|
PRINT6ADDR(&parent->addr);
|
||||||
PRINTF(" because of bad connectivity (ETX %d)\n", etx);
|
PRINTF(" because of bad connectivity (ETX %d)\n", etx);
|
||||||
parent->rank = INFINITE_RANK;
|
parent->rank = INFINITE_RANK;
|
||||||
parent->updated = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
@ -147,7 +147,7 @@ struct rpl_parent {
|
|||||||
rpl_metric_container_t mc;
|
rpl_metric_container_t mc;
|
||||||
uip_ipaddr_t addr;
|
uip_ipaddr_t addr;
|
||||||
rpl_rank_t rank;
|
rpl_rank_t rank;
|
||||||
uint8_t etx;
|
uint8_t link_metric;
|
||||||
uint8_t dtsn;
|
uint8_t dtsn;
|
||||||
uint8_t updated;
|
uint8_t updated;
|
||||||
};
|
};
|
||||||
|
@ -174,60 +174,60 @@ uip_ds6_periodic(void)
|
|||||||
#if !UIP_CONF_ROUTER
|
#if !UIP_CONF_ROUTER
|
||||||
/* Periodic processing on prefixes */
|
/* Periodic processing on prefixes */
|
||||||
for(locprefix = uip_ds6_prefix_list;
|
for(locprefix = uip_ds6_prefix_list;
|
||||||
locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB; locprefix++) {
|
locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB;
|
||||||
if((locprefix->isused) && (!locprefix->isinfinite)
|
locprefix++) {
|
||||||
&& (stimer_expired(&(locprefix->vlifetime)))) {
|
if(locprefix->isused && !locprefix->isinfinite
|
||||||
|
&& stimer_expired(&(locprefix->vlifetime))) {
|
||||||
uip_ds6_prefix_rm(locprefix);
|
uip_ds6_prefix_rm(locprefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* !UIP_CONF_ROUTER */
|
#endif /* !UIP_CONF_ROUTER */
|
||||||
|
|
||||||
/* Periodic processing on neighbors */
|
/* Periodic processing on neighbors */
|
||||||
for(locnbr = uip_ds6_nbr_cache; locnbr < uip_ds6_nbr_cache + UIP_DS6_NBR_NB;
|
for(locnbr = uip_ds6_nbr_cache;
|
||||||
|
locnbr < uip_ds6_nbr_cache + UIP_DS6_NBR_NB;
|
||||||
locnbr++) {
|
locnbr++) {
|
||||||
if(locnbr->isused) {
|
if(locnbr->isused) {
|
||||||
switch (locnbr->state) {
|
switch(locnbr->state) {
|
||||||
case NBR_INCOMPLETE:
|
case NBR_INCOMPLETE:
|
||||||
if(locnbr->nscount >= UIP_ND6_MAX_MULTICAST_SOLICIT) {
|
if(locnbr->nscount >= UIP_ND6_MAX_MULTICAST_SOLICIT) {
|
||||||
uip_ds6_nbr_rm(locnbr);
|
uip_ds6_nbr_rm(locnbr);
|
||||||
} else if(stimer_expired(&(locnbr->sendns))) {
|
} else if(stimer_expired(&locnbr->sendns)) {
|
||||||
locnbr->nscount++;
|
locnbr->nscount++;
|
||||||
PRINTF("NBR_INCOMPLETE: NS %u\n", locnbr->nscount);
|
PRINTF("NBR_INCOMPLETE: NS %u\n", locnbr->nscount);
|
||||||
uip_nd6_ns_output(NULL, NULL, &locnbr->ipaddr);
|
uip_nd6_ns_output(NULL, NULL, &locnbr->ipaddr);
|
||||||
stimer_set(&(locnbr->sendns), uip_ds6_if.retrans_timer / 1000);
|
stimer_set(&locnbr->sendns, uip_ds6_if.retrans_timer / 1000);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NBR_REACHABLE:
|
case NBR_REACHABLE:
|
||||||
if(stimer_expired(&(locnbr->reachable))) {
|
if(stimer_expired(&locnbr->reachable)) {
|
||||||
PRINTF("REACHABLE: moving to STALE (");
|
PRINTF("REACHABLE: moving to STALE (");
|
||||||
PRINT6ADDR(&locnbr->ipaddr);
|
PRINT6ADDR(&locnbr->ipaddr);
|
||||||
PRINTF(")\n");
|
PRINTF(")\n");
|
||||||
locnbr->state = NBR_STALE;
|
locnbr->state = NBR_STALE;
|
||||||
/* NEIGHBOR_STATE_CHANGED(locnbr); */
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NBR_DELAY:
|
case NBR_DELAY:
|
||||||
if(stimer_expired(&(locnbr->reachable))) {
|
if(stimer_expired(&locnbr->reachable)) {
|
||||||
locnbr->state = NBR_PROBE;
|
locnbr->state = NBR_PROBE;
|
||||||
locnbr->nscount = 1;
|
locnbr->nscount = 1;
|
||||||
/* NEIGHBOR_STATE_CHANGED(locnbr); */
|
|
||||||
PRINTF("DELAY: moving to PROBE + NS %u\n", locnbr->nscount);
|
PRINTF("DELAY: moving to PROBE + NS %u\n", locnbr->nscount);
|
||||||
uip_nd6_ns_output(NULL, &locnbr->ipaddr, &locnbr->ipaddr);
|
uip_nd6_ns_output(NULL, &locnbr->ipaddr, &locnbr->ipaddr);
|
||||||
stimer_set(&(locnbr->sendns), uip_ds6_if.retrans_timer / 1000);
|
stimer_set(&locnbr->sendns, uip_ds6_if.retrans_timer / 1000);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NBR_PROBE:
|
case NBR_PROBE:
|
||||||
if(locnbr->nscount >= UIP_ND6_MAX_UNICAST_SOLICIT) {
|
if(locnbr->nscount >= UIP_ND6_MAX_UNICAST_SOLICIT) {
|
||||||
PRINTF("PROBE END \n");
|
PRINTF("PROBE END\n");
|
||||||
if((locdefrt = uip_ds6_defrt_lookup(&locnbr->ipaddr)) != NULL) {
|
if((locdefrt = uip_ds6_defrt_lookup(&locnbr->ipaddr)) != NULL) {
|
||||||
uip_ds6_defrt_rm(locdefrt);
|
uip_ds6_defrt_rm(locdefrt);
|
||||||
}
|
}
|
||||||
uip_ds6_nbr_rm(locnbr);
|
uip_ds6_nbr_rm(locnbr);
|
||||||
} else if(stimer_expired(&(locnbr->sendns))) {
|
} else if(stimer_expired(&locnbr->sendns)) {
|
||||||
locnbr->nscount++;
|
locnbr->nscount++;
|
||||||
PRINTF("PROBE: NS %u\n", locnbr->nscount);
|
PRINTF("PROBE: NS %u\n", locnbr->nscount);
|
||||||
uip_nd6_ns_output(NULL, &locnbr->ipaddr, &locnbr->ipaddr);
|
uip_nd6_ns_output(NULL, &locnbr->ipaddr, &locnbr->ipaddr);
|
||||||
stimer_set(&(locnbr->sendns), uip_ds6_if.retrans_timer / 1000);
|
stimer_set(&locnbr->sendns, uip_ds6_if.retrans_timer / 1000);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -248,9 +248,9 @@ uip_ds6_periodic(void)
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
uint8_t
|
uint8_t
|
||||||
uip_ds6_list_loop(uip_ds6_element_t * list, uint8_t size,
|
uip_ds6_list_loop(uip_ds6_element_t *list, uint8_t size,
|
||||||
uint16_t elementsize, uip_ipaddr_t * ipaddr,
|
uint16_t elementsize, uip_ipaddr_t *ipaddr,
|
||||||
uint8_t ipaddrlen, uip_ds6_element_t ** out_element)
|
uint8_t ipaddrlen, uip_ds6_element_t **out_element)
|
||||||
{
|
{
|
||||||
uip_ds6_element_t *element;
|
uip_ds6_element_t *element;
|
||||||
|
|
||||||
@ -258,11 +258,10 @@ uip_ds6_list_loop(uip_ds6_element_t * list, uint8_t size,
|
|||||||
|
|
||||||
for(element = list;
|
for(element = list;
|
||||||
element <
|
element <
|
||||||
(uip_ds6_element_t *) ((uint8_t *) list + (size * elementsize));
|
(uip_ds6_element_t *)((uint8_t *)list + (size * elementsize));
|
||||||
element = (uip_ds6_element_t *) ((uint8_t *) element + elementsize)) {
|
element = (uip_ds6_element_t *)((uint8_t *)element + elementsize)) {
|
||||||
// printf("+ %p %d\n", &element->isused, element->isused);
|
|
||||||
if(element->isused) {
|
if(element->isused) {
|
||||||
if(uip_ipaddr_prefixcmp(&(element->ipaddr), ipaddr, ipaddrlen)) {
|
if(uip_ipaddr_prefixcmp(&element->ipaddr, ipaddr, ipaddrlen)) {
|
||||||
*out_element = element;
|
*out_element = element;
|
||||||
return FOUND;
|
return FOUND;
|
||||||
}
|
}
|
||||||
@ -271,33 +270,28 @@ uip_ds6_list_loop(uip_ds6_element_t * list, uint8_t size,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(*out_element != NULL) {
|
return *out_element != NULL ? FREESPACE : NOSPACE;
|
||||||
return FREESPACE;
|
|
||||||
} else {
|
|
||||||
return NOSPACE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
uip_ds6_nbr_t *
|
uip_ds6_nbr_t *
|
||||||
uip_ds6_nbr_add(uip_ipaddr_t * ipaddr, uip_lladdr_t * lladdr,
|
uip_ds6_nbr_add(uip_ipaddr_t *ipaddr, uip_lladdr_t * lladdr,
|
||||||
uint8_t isrouter, uint8_t state)
|
uint8_t isrouter, uint8_t state)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = uip_ds6_list_loop
|
r = uip_ds6_list_loop
|
||||||
((uip_ds6_element_t *) uip_ds6_nbr_cache, UIP_DS6_NBR_NB,
|
((uip_ds6_element_t *)uip_ds6_nbr_cache, UIP_DS6_NBR_NB,
|
||||||
sizeof(uip_ds6_nbr_t), ipaddr, 128,
|
sizeof(uip_ds6_nbr_t), ipaddr, 128,
|
||||||
(uip_ds6_element_t **) &locnbr);
|
(uip_ds6_element_t **)&locnbr);
|
||||||
// printf("r %d\n", r);
|
|
||||||
|
|
||||||
if(r == FREESPACE) {
|
if(r == FREESPACE) {
|
||||||
locnbr->isused = 1;
|
locnbr->isused = 1;
|
||||||
uip_ipaddr_copy(&(locnbr->ipaddr), ipaddr);
|
uip_ipaddr_copy(&locnbr->ipaddr, ipaddr);
|
||||||
if(lladdr != NULL) {
|
if(lladdr != NULL) {
|
||||||
memcpy(&(locnbr->lladdr), lladdr, UIP_LLADDR_LEN);
|
memcpy(&locnbr->lladdr, lladdr, UIP_LLADDR_LEN);
|
||||||
} else {
|
} else {
|
||||||
memset(&(locnbr->lladdr), 0, UIP_LLADDR_LEN);
|
memset(&locnbr->lladdr, 0, UIP_LLADDR_LEN);
|
||||||
}
|
}
|
||||||
locnbr->isrouter = isrouter;
|
locnbr->isrouter = isrouter;
|
||||||
locnbr->state = state;
|
locnbr->state = state;
|
||||||
@ -305,18 +299,17 @@ uip_ds6_nbr_add(uip_ipaddr_t * ipaddr, uip_lladdr_t * lladdr,
|
|||||||
uip_packetqueue_new(&locnbr->packethandle);
|
uip_packetqueue_new(&locnbr->packethandle);
|
||||||
#endif /* UIP_CONF_IPV6_QUEUE_PKT */
|
#endif /* UIP_CONF_IPV6_QUEUE_PKT */
|
||||||
/* timers are set separately, for now we put them in expired state */
|
/* timers are set separately, for now we put them in expired state */
|
||||||
stimer_set(&(locnbr->reachable), 0);
|
stimer_set(&locnbr->reachable, 0);
|
||||||
stimer_set(&(locnbr->sendns), 0);
|
stimer_set(&locnbr->sendns, 0);
|
||||||
locnbr->nscount = 0;
|
locnbr->nscount = 0;
|
||||||
PRINTF("Adding neighbor with ip addr");
|
PRINTF("Adding neighbor with ip addr ");
|
||||||
PRINT6ADDR(ipaddr);
|
PRINT6ADDR(ipaddr);
|
||||||
PRINTF("link addr");
|
PRINTF("link addr ");
|
||||||
PRINTLLADDR((&(locnbr->lladdr)));
|
PRINTLLADDR((&(locnbr->lladdr)));
|
||||||
PRINTF("state %u\n", state);
|
PRINTF("state %u\n", state);
|
||||||
NEIGHBOR_STATE_CHANGED(locnbr);
|
NEIGHBOR_STATE_CHANGED(locnbr);
|
||||||
|
|
||||||
locnbr->last_lookup = clock_time();
|
locnbr->last_lookup = clock_time();
|
||||||
// printf("add %p\n", locnbr);
|
|
||||||
return locnbr;
|
return locnbr;
|
||||||
} else if(r == NOSPACE) {
|
} else if(r == NOSPACE) {
|
||||||
/* We did not find any empty slot on the neighbor list, so we need
|
/* We did not find any empty slot on the neighbor list, so we need
|
||||||
@ -338,7 +331,6 @@ uip_ds6_nbr_add(uip_ipaddr_t * ipaddr, uip_lladdr_t * lladdr,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(oldest != NULL) {
|
if(oldest != NULL) {
|
||||||
// printf("rm3\n");
|
|
||||||
uip_ds6_nbr_rm(oldest);
|
uip_ds6_nbr_rm(oldest);
|
||||||
return uip_ds6_nbr_add(ipaddr, lladdr, isrouter, state);
|
return uip_ds6_nbr_add(ipaddr, lladdr, isrouter, state);
|
||||||
}
|
}
|
||||||
@ -354,7 +346,6 @@ uip_ds6_nbr_rm(uip_ds6_nbr_t *nbr)
|
|||||||
if(nbr != NULL) {
|
if(nbr != NULL) {
|
||||||
nbr->isused = 0;
|
nbr->isused = 0;
|
||||||
#if UIP_CONF_IPV6_QUEUE_PKT
|
#if UIP_CONF_IPV6_QUEUE_PKT
|
||||||
// printf("rm %p\n", &nbr->isused);
|
|
||||||
uip_packetqueue_free(&nbr->packethandle);
|
uip_packetqueue_free(&nbr->packethandle);
|
||||||
#endif /* UIP_CONF_IPV6_QUEUE_PKT */
|
#endif /* UIP_CONF_IPV6_QUEUE_PKT */
|
||||||
NEIGHBOR_STATE_CHANGED(nbr);
|
NEIGHBOR_STATE_CHANGED(nbr);
|
||||||
@ -367,9 +358,9 @@ uip_ds6_nbr_t *
|
|||||||
uip_ds6_nbr_lookup(uip_ipaddr_t *ipaddr)
|
uip_ds6_nbr_lookup(uip_ipaddr_t *ipaddr)
|
||||||
{
|
{
|
||||||
if(uip_ds6_list_loop
|
if(uip_ds6_list_loop
|
||||||
((uip_ds6_element_t *) uip_ds6_nbr_cache, UIP_DS6_NBR_NB,
|
((uip_ds6_element_t *)uip_ds6_nbr_cache, UIP_DS6_NBR_NB,
|
||||||
sizeof(uip_ds6_nbr_t), ipaddr, 128,
|
sizeof(uip_ds6_nbr_t), ipaddr, 128,
|
||||||
(uip_ds6_element_t **) & locnbr) == FOUND) {
|
(uip_ds6_element_t **)&locnbr) == FOUND) {
|
||||||
return locnbr;
|
return locnbr;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -380,19 +371,19 @@ uip_ds6_defrt_t *
|
|||||||
uip_ds6_defrt_add(uip_ipaddr_t *ipaddr, unsigned long interval)
|
uip_ds6_defrt_add(uip_ipaddr_t *ipaddr, unsigned long interval)
|
||||||
{
|
{
|
||||||
if(uip_ds6_list_loop
|
if(uip_ds6_list_loop
|
||||||
((uip_ds6_element_t *) uip_ds6_defrt_list, UIP_DS6_DEFRT_NB,
|
((uip_ds6_element_t *)uip_ds6_defrt_list, UIP_DS6_DEFRT_NB,
|
||||||
sizeof(uip_ds6_defrt_t), ipaddr, 128,
|
sizeof(uip_ds6_defrt_t), ipaddr, 128,
|
||||||
(uip_ds6_element_t **) & locdefrt) == FREESPACE) {
|
(uip_ds6_element_t **)&locdefrt) == FREESPACE) {
|
||||||
locdefrt->isused = 1;
|
locdefrt->isused = 1;
|
||||||
uip_ipaddr_copy(&(locdefrt->ipaddr), ipaddr);
|
uip_ipaddr_copy(&locdefrt->ipaddr, ipaddr);
|
||||||
if(interval != 0) {
|
if(interval != 0) {
|
||||||
stimer_set(&(locdefrt->lifetime), interval);
|
stimer_set(&locdefrt->lifetime, interval);
|
||||||
locdefrt->isinfinite = 0;
|
locdefrt->isinfinite = 0;
|
||||||
} else {
|
} else {
|
||||||
locdefrt->isinfinite = 1;
|
locdefrt->isinfinite = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRINTF("Adding defrouter with ip addr");
|
PRINTF("Adding defrouter with ip addr ");
|
||||||
PRINT6ADDR(&locdefrt->ipaddr);
|
PRINT6ADDR(&locdefrt->ipaddr);
|
||||||
PRINTF("\n");
|
PRINTF("\n");
|
||||||
|
|
||||||
@ -405,7 +396,7 @@ uip_ds6_defrt_add(uip_ipaddr_t *ipaddr, unsigned long interval)
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
uip_ds6_defrt_rm(uip_ds6_defrt_t * defrt)
|
uip_ds6_defrt_rm(uip_ds6_defrt_t *defrt)
|
||||||
{
|
{
|
||||||
if(defrt != NULL) {
|
if(defrt != NULL) {
|
||||||
defrt->isused = 0;
|
defrt->isused = 0;
|
||||||
@ -416,11 +407,11 @@ uip_ds6_defrt_rm(uip_ds6_defrt_t * defrt)
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
uip_ds6_defrt_t *
|
uip_ds6_defrt_t *
|
||||||
uip_ds6_defrt_lookup(uip_ipaddr_t * ipaddr)
|
uip_ds6_defrt_lookup(uip_ipaddr_t *ipaddr)
|
||||||
{
|
{
|
||||||
if(uip_ds6_list_loop((uip_ds6_element_t *) uip_ds6_defrt_list,
|
if(uip_ds6_list_loop((uip_ds6_element_t *)uip_ds6_defrt_list,
|
||||||
UIP_DS6_DEFRT_NB, sizeof(uip_ds6_defrt_t), ipaddr, 128,
|
UIP_DS6_DEFRT_NB, sizeof(uip_ds6_defrt_t), ipaddr, 128,
|
||||||
(uip_ds6_element_t **) & locdefrt) == FOUND) {
|
(uip_ds6_element_t **)&locdefrt) == FOUND) {
|
||||||
return locdefrt;
|
return locdefrt;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -440,7 +431,7 @@ uip_ds6_defrt_choose(void)
|
|||||||
PRINT6ADDR(&locdefrt->ipaddr);
|
PRINT6ADDR(&locdefrt->ipaddr);
|
||||||
PRINTF("\n");
|
PRINTF("\n");
|
||||||
bestnbr = uip_ds6_nbr_lookup(&locdefrt->ipaddr);
|
bestnbr = uip_ds6_nbr_lookup(&locdefrt->ipaddr);
|
||||||
if((bestnbr != NULL) && (bestnbr->state != NBR_INCOMPLETE)) {
|
if(bestnbr != NULL && bestnbr->state != NBR_INCOMPLETE) {
|
||||||
PRINTF("Defrt found, IP address ");
|
PRINTF("Defrt found, IP address ");
|
||||||
PRINT6ADDR(&locdefrt->ipaddr);
|
PRINT6ADDR(&locdefrt->ipaddr);
|
||||||
PRINTF("\n");
|
PRINTF("\n");
|
||||||
@ -459,16 +450,16 @@ uip_ds6_defrt_choose(void)
|
|||||||
#if UIP_CONF_ROUTER
|
#if UIP_CONF_ROUTER
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
uip_ds6_prefix_t *
|
uip_ds6_prefix_t *
|
||||||
uip_ds6_prefix_add(uip_ipaddr_t * ipaddr, uint8_t ipaddrlen,
|
uip_ds6_prefix_add(uip_ipaddr_t *ipaddr, uint8_t ipaddrlen,
|
||||||
uint8_t advertise, uint8_t flags, unsigned long vtime,
|
uint8_t advertise, uint8_t flags, unsigned long vtime,
|
||||||
unsigned long ptime)
|
unsigned long ptime)
|
||||||
{
|
{
|
||||||
if(uip_ds6_list_loop
|
if(uip_ds6_list_loop
|
||||||
((uip_ds6_element_t *) uip_ds6_prefix_list, UIP_DS6_PREFIX_NB,
|
((uip_ds6_element_t *)uip_ds6_prefix_list, UIP_DS6_PREFIX_NB,
|
||||||
sizeof(uip_ds6_prefix_t), ipaddr, ipaddrlen,
|
sizeof(uip_ds6_prefix_t), ipaddr, ipaddrlen,
|
||||||
(uip_ds6_element_t **) & locprefix) == FREESPACE) {
|
(uip_ds6_element_t **)&locprefix) == FREESPACE) {
|
||||||
locprefix->isused = 1;
|
locprefix->isused = 1;
|
||||||
uip_ipaddr_copy(&(locprefix->ipaddr), ipaddr);
|
uip_ipaddr_copy(&locprefix->ipaddr, ipaddr);
|
||||||
locprefix->length = ipaddrlen;
|
locprefix->length = ipaddrlen;
|
||||||
locprefix->advertise = advertise;
|
locprefix->advertise = advertise;
|
||||||
locprefix->l_a_reserved = flags;
|
locprefix->l_a_reserved = flags;
|
||||||
@ -488,15 +479,15 @@ uip_ds6_prefix_add(uip_ipaddr_t * ipaddr, uint8_t ipaddrlen,
|
|||||||
|
|
||||||
#else /* UIP_CONF_ROUTER */
|
#else /* UIP_CONF_ROUTER */
|
||||||
uip_ds6_prefix_t *
|
uip_ds6_prefix_t *
|
||||||
uip_ds6_prefix_add(uip_ipaddr_t * ipaddr, uint8_t ipaddrlen,
|
uip_ds6_prefix_add(uip_ipaddr_t *ipaddr, uint8_t ipaddrlen,
|
||||||
unsigned long interval)
|
unsigned long interval)
|
||||||
{
|
{
|
||||||
if(uip_ds6_list_loop
|
if(uip_ds6_list_loop
|
||||||
((uip_ds6_element_t *) uip_ds6_prefix_list, UIP_DS6_PREFIX_NB,
|
((uip_ds6_element_t *)uip_ds6_prefix_list, UIP_DS6_PREFIX_NB,
|
||||||
sizeof(uip_ds6_prefix_t), ipaddr, ipaddrlen,
|
sizeof(uip_ds6_prefix_t), ipaddr, ipaddrlen,
|
||||||
(uip_ds6_element_t **) & locprefix) == FREESPACE) {
|
(uip_ds6_element_t **)&locprefix) == FREESPACE) {
|
||||||
locprefix->isused = 1;
|
locprefix->isused = 1;
|
||||||
uip_ipaddr_copy(&(locprefix->ipaddr), ipaddr);
|
uip_ipaddr_copy(&locprefix->ipaddr, ipaddr);
|
||||||
locprefix->length = ipaddrlen;
|
locprefix->length = ipaddrlen;
|
||||||
if(interval != 0) {
|
if(interval != 0) {
|
||||||
stimer_set(&(locprefix->vlifetime), interval);
|
stimer_set(&(locprefix->vlifetime), interval);
|
||||||
@ -523,7 +514,7 @@ uip_ds6_prefix_rm(uip_ds6_prefix_t * prefix)
|
|||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
uip_ds6_prefix_t *
|
uip_ds6_prefix_t *
|
||||||
uip_ds6_prefix_lookup(uip_ipaddr_t * ipaddr, uint8_t ipaddrlen)
|
uip_ds6_prefix_lookup(uip_ipaddr_t *ipaddr, uint8_t ipaddrlen)
|
||||||
{
|
{
|
||||||
if(uip_ds6_list_loop((uip_ds6_element_t *)uip_ds6_prefix_list,
|
if(uip_ds6_list_loop((uip_ds6_element_t *)uip_ds6_prefix_list,
|
||||||
UIP_DS6_PREFIX_NB, sizeof(uip_ds6_prefix_t),
|
UIP_DS6_PREFIX_NB, sizeof(uip_ds6_prefix_t),
|
||||||
@ -536,7 +527,7 @@ uip_ds6_prefix_lookup(uip_ipaddr_t * ipaddr, uint8_t ipaddrlen)
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
uint8_t
|
uint8_t
|
||||||
uip_ds6_is_addr_onlink(uip_ipaddr_t * ipaddr)
|
uip_ds6_is_addr_onlink(uip_ipaddr_t *ipaddr)
|
||||||
{
|
{
|
||||||
for(locprefix = uip_ds6_prefix_list;
|
for(locprefix = uip_ds6_prefix_list;
|
||||||
locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB; locprefix++) {
|
locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB; locprefix++) {
|
||||||
@ -550,12 +541,12 @@ uip_ds6_is_addr_onlink(uip_ipaddr_t * ipaddr)
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
uip_ds6_addr_t *
|
uip_ds6_addr_t *
|
||||||
uip_ds6_addr_add(uip_ipaddr_t * ipaddr, unsigned long vlifetime, uint8_t type)
|
uip_ds6_addr_add(uip_ipaddr_t *ipaddr, unsigned long vlifetime, uint8_t type)
|
||||||
{
|
{
|
||||||
if(uip_ds6_list_loop
|
if(uip_ds6_list_loop
|
||||||
((uip_ds6_element_t *) uip_ds6_if.addr_list, UIP_DS6_ADDR_NB,
|
((uip_ds6_element_t *)uip_ds6_if.addr_list, UIP_DS6_ADDR_NB,
|
||||||
sizeof(uip_ds6_addr_t), ipaddr, 128,
|
sizeof(uip_ds6_addr_t), ipaddr, 128,
|
||||||
(uip_ds6_element_t **) & locaddr) == FREESPACE) {
|
(uip_ds6_element_t **)&locaddr) == FREESPACE) {
|
||||||
locaddr->isused = 1;
|
locaddr->isused = 1;
|
||||||
uip_ipaddr_copy(&locaddr->ipaddr, ipaddr);
|
uip_ipaddr_copy(&locaddr->ipaddr, ipaddr);
|
||||||
locaddr->state = ADDR_TENTATIVE;
|
locaddr->state = ADDR_TENTATIVE;
|
||||||
@ -579,7 +570,7 @@ uip_ds6_addr_add(uip_ipaddr_t * ipaddr, unsigned long vlifetime, uint8_t type)
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
uip_ds6_addr_rm(uip_ds6_addr_t * addr)
|
uip_ds6_addr_rm(uip_ds6_addr_t *addr)
|
||||||
{
|
{
|
||||||
if(addr != NULL) {
|
if(addr != NULL) {
|
||||||
uip_create_solicited_node(&addr->ipaddr, &loc_fipaddr);
|
uip_create_solicited_node(&addr->ipaddr, &loc_fipaddr);
|
||||||
@ -593,12 +584,12 @@ uip_ds6_addr_rm(uip_ds6_addr_t * addr)
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
uip_ds6_addr_t *
|
uip_ds6_addr_t *
|
||||||
uip_ds6_addr_lookup(uip_ipaddr_t * ipaddr)
|
uip_ds6_addr_lookup(uip_ipaddr_t *ipaddr)
|
||||||
{
|
{
|
||||||
if(uip_ds6_list_loop
|
if(uip_ds6_list_loop
|
||||||
((uip_ds6_element_t *) uip_ds6_if.addr_list, UIP_DS6_ADDR_NB,
|
((uip_ds6_element_t *)uip_ds6_if.addr_list, UIP_DS6_ADDR_NB,
|
||||||
sizeof(uip_ds6_addr_t), ipaddr, 128,
|
sizeof(uip_ds6_addr_t), ipaddr, 128,
|
||||||
(uip_ds6_element_t **) & locaddr) == FOUND) {
|
(uip_ds6_element_t **)&locaddr) == FOUND) {
|
||||||
return locaddr;
|
return locaddr;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -615,7 +606,7 @@ uip_ds6_get_link_local(int8_t state)
|
|||||||
{
|
{
|
||||||
for(locaddr = uip_ds6_if.addr_list;
|
for(locaddr = uip_ds6_if.addr_list;
|
||||||
locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
|
locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
|
||||||
if((locaddr->isused) && (state == -1 || locaddr->state == state)
|
if(locaddr->isused && (state == -1 || locaddr->state == state)
|
||||||
&& (uip_is_addr_link_local(&locaddr->ipaddr))) {
|
&& (uip_is_addr_link_local(&locaddr->ipaddr))) {
|
||||||
return locaddr;
|
return locaddr;
|
||||||
}
|
}
|
||||||
@ -634,7 +625,7 @@ uip_ds6_get_global(int8_t state)
|
|||||||
{
|
{
|
||||||
for(locaddr = uip_ds6_if.addr_list;
|
for(locaddr = uip_ds6_if.addr_list;
|
||||||
locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
|
locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
|
||||||
if((locaddr->isused) && (state == -1 || locaddr->state == state)
|
if(locaddr->isused && (state == -1 || locaddr->state == state)
|
||||||
&& !(uip_is_addr_link_local(&locaddr->ipaddr))) {
|
&& !(uip_is_addr_link_local(&locaddr->ipaddr))) {
|
||||||
return locaddr;
|
return locaddr;
|
||||||
}
|
}
|
||||||
@ -644,12 +635,12 @@ uip_ds6_get_global(int8_t state)
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
uip_ds6_maddr_t *
|
uip_ds6_maddr_t *
|
||||||
uip_ds6_maddr_add(uip_ipaddr_t * ipaddr)
|
uip_ds6_maddr_add(uip_ipaddr_t *ipaddr)
|
||||||
{
|
{
|
||||||
if(uip_ds6_list_loop
|
if(uip_ds6_list_loop
|
||||||
((uip_ds6_element_t *) uip_ds6_if.maddr_list, UIP_DS6_MADDR_NB,
|
((uip_ds6_element_t *)uip_ds6_if.maddr_list, UIP_DS6_MADDR_NB,
|
||||||
sizeof(uip_ds6_maddr_t), ipaddr, 128,
|
sizeof(uip_ds6_maddr_t), ipaddr, 128,
|
||||||
(uip_ds6_element_t **) & locmaddr) == FREESPACE) {
|
(uip_ds6_element_t **)&locmaddr) == FREESPACE) {
|
||||||
locmaddr->isused = 1;
|
locmaddr->isused = 1;
|
||||||
uip_ipaddr_copy(&locmaddr->ipaddr, ipaddr);
|
uip_ipaddr_copy(&locmaddr->ipaddr, ipaddr);
|
||||||
return locmaddr;
|
return locmaddr;
|
||||||
@ -669,12 +660,12 @@ uip_ds6_maddr_rm(uip_ds6_maddr_t * maddr)
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
uip_ds6_maddr_t *
|
uip_ds6_maddr_t *
|
||||||
uip_ds6_maddr_lookup(uip_ipaddr_t * ipaddr)
|
uip_ds6_maddr_lookup(uip_ipaddr_t *ipaddr)
|
||||||
{
|
{
|
||||||
if(uip_ds6_list_loop
|
if(uip_ds6_list_loop
|
||||||
((uip_ds6_element_t *) uip_ds6_if.maddr_list, UIP_DS6_MADDR_NB,
|
((uip_ds6_element_t *)uip_ds6_if.maddr_list, UIP_DS6_MADDR_NB,
|
||||||
sizeof(uip_ds6_maddr_t), ipaddr, 128,
|
sizeof(uip_ds6_maddr_t), ipaddr, 128,
|
||||||
(uip_ds6_element_t **) & locmaddr) == FOUND) {
|
(uip_ds6_element_t **)&locmaddr) == FOUND) {
|
||||||
return locmaddr;
|
return locmaddr;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -683,12 +674,12 @@ uip_ds6_maddr_lookup(uip_ipaddr_t * ipaddr)
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
uip_ds6_aaddr_t *
|
uip_ds6_aaddr_t *
|
||||||
uip_ds6_aaddr_add(uip_ipaddr_t * ipaddr)
|
uip_ds6_aaddr_add(uip_ipaddr_t *ipaddr)
|
||||||
{
|
{
|
||||||
if(uip_ds6_list_loop
|
if(uip_ds6_list_loop
|
||||||
((uip_ds6_element_t *) uip_ds6_if.aaddr_list, UIP_DS6_AADDR_NB,
|
((uip_ds6_element_t *)uip_ds6_if.aaddr_list, UIP_DS6_AADDR_NB,
|
||||||
sizeof(uip_ds6_aaddr_t), ipaddr, 128,
|
sizeof(uip_ds6_aaddr_t), ipaddr, 128,
|
||||||
(uip_ds6_element_t **) & locaaddr) == FREESPACE) {
|
(uip_ds6_element_t **)&locaaddr) == FREESPACE) {
|
||||||
locaaddr->isused = 1;
|
locaaddr->isused = 1;
|
||||||
uip_ipaddr_copy(&locaaddr->ipaddr, ipaddr);
|
uip_ipaddr_copy(&locaaddr->ipaddr, ipaddr);
|
||||||
return locaaddr;
|
return locaaddr;
|
||||||
@ -708,9 +699,9 @@ uip_ds6_aaddr_rm(uip_ds6_aaddr_t * aaddr)
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
uip_ds6_aaddr_t *
|
uip_ds6_aaddr_t *
|
||||||
uip_ds6_aaddr_lookup(uip_ipaddr_t * ipaddr)
|
uip_ds6_aaddr_lookup(uip_ipaddr_t *ipaddr)
|
||||||
{
|
{
|
||||||
if(uip_ds6_list_loop((uip_ds6_element_t *) uip_ds6_if.aaddr_list,
|
if(uip_ds6_list_loop((uip_ds6_element_t *)uip_ds6_if.aaddr_list,
|
||||||
UIP_DS6_AADDR_NB, sizeof(uip_ds6_aaddr_t), ipaddr, 128,
|
UIP_DS6_AADDR_NB, sizeof(uip_ds6_aaddr_t), ipaddr, 128,
|
||||||
(uip_ds6_element_t **)&locaaddr) == FOUND) {
|
(uip_ds6_element_t **)&locaaddr) == FOUND) {
|
||||||
return locaaddr;
|
return locaaddr;
|
||||||
@ -720,12 +711,12 @@ uip_ds6_aaddr_lookup(uip_ipaddr_t * ipaddr)
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
uip_ds6_route_t *
|
uip_ds6_route_t *
|
||||||
uip_ds6_route_lookup(uip_ipaddr_t * destipaddr)
|
uip_ds6_route_lookup(uip_ipaddr_t *destipaddr)
|
||||||
{
|
{
|
||||||
uip_ds6_route_t *locrt = NULL;
|
uip_ds6_route_t *locrt = NULL;
|
||||||
uint8_t longestmatch = 0;
|
uint8_t longestmatch = 0;
|
||||||
|
|
||||||
PRINTF("DS6: Looking up route for");
|
PRINTF("DS6: Looking up route for ");
|
||||||
PRINT6ADDR(destipaddr);
|
PRINT6ADDR(destipaddr);
|
||||||
PRINTF("\n");
|
PRINTF("\n");
|
||||||
|
|
||||||
@ -747,7 +738,7 @@ uip_ds6_route_lookup(uip_ipaddr_t * destipaddr)
|
|||||||
PRINT6ADDR(&locrt->nexthop);
|
PRINT6ADDR(&locrt->nexthop);
|
||||||
PRINTF("\n");
|
PRINTF("\n");
|
||||||
} else {
|
} else {
|
||||||
PRINTF("DS6: No route found ...\n");
|
PRINTF("DS6: No route found\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return locrt;
|
return locrt;
|
||||||
@ -755,27 +746,25 @@ uip_ds6_route_lookup(uip_ipaddr_t * destipaddr)
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
uip_ds6_route_t *
|
uip_ds6_route_t *
|
||||||
uip_ds6_route_add(uip_ipaddr_t * ipaddr, u8_t length, uip_ipaddr_t * nexthop,
|
uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length, uip_ipaddr_t *nexthop,
|
||||||
u8_t metric)
|
uint8_t metric)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(uip_ds6_list_loop
|
if(uip_ds6_list_loop
|
||||||
((uip_ds6_element_t *) uip_ds6_routing_table, UIP_DS6_ROUTE_NB,
|
((uip_ds6_element_t *)uip_ds6_routing_table, UIP_DS6_ROUTE_NB,
|
||||||
sizeof(uip_ds6_route_t), ipaddr, length,
|
sizeof(uip_ds6_route_t), ipaddr, length,
|
||||||
(uip_ds6_element_t **) & locroute) == FREESPACE) {
|
(uip_ds6_element_t **)&locroute) == FREESPACE) {
|
||||||
locroute->isused = 1;
|
locroute->isused = 1;
|
||||||
uip_ipaddr_copy(&(locroute->ipaddr), ipaddr);
|
uip_ipaddr_copy(&(locroute->ipaddr), ipaddr);
|
||||||
locroute->length = length;
|
locroute->length = length;
|
||||||
uip_ipaddr_copy(&(locroute->nexthop), nexthop);
|
uip_ipaddr_copy(&(locroute->nexthop), nexthop);
|
||||||
locroute->metric = metric;
|
locroute->metric = metric;
|
||||||
|
|
||||||
PRINTF("DS6: adding route:");
|
PRINTF("DS6: adding route: ");
|
||||||
PRINT6ADDR(ipaddr);
|
PRINT6ADDR(ipaddr);
|
||||||
PRINTF(" via ");
|
PRINTF(" via ");
|
||||||
PRINT6ADDR(nexthop);
|
PRINT6ADDR(nexthop);
|
||||||
PRINTF("\n");
|
PRINTF("\n");
|
||||||
ANNOTATE("#L %u 1;blue\n",nexthop->u8[sizeof(uip_ipaddr_t) - 1]);
|
ANNOTATE("#L %u 1;blue\n", nexthop->u8[sizeof(uip_ipaddr_t) - 1]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return locroute;
|
return locroute;
|
||||||
@ -790,9 +779,10 @@ uip_ds6_route_rm(uip_ds6_route_t *route)
|
|||||||
/* we need to check if this was the last route towards "nexthop" */
|
/* we need to check if this was the last route towards "nexthop" */
|
||||||
/* if so - remove that link (annotation) */
|
/* if so - remove that link (annotation) */
|
||||||
for(locroute = uip_ds6_routing_table;
|
for(locroute = uip_ds6_routing_table;
|
||||||
locroute < uip_ds6_routing_table + UIP_DS6_ROUTE_NB; locroute++) {
|
locroute < uip_ds6_routing_table + UIP_DS6_ROUTE_NB;
|
||||||
if((locroute->isused) && uip_ipaddr_cmp(&locroute->nexthop, &route->nexthop)) {
|
locroute++) {
|
||||||
/* we did find another link using the specific nexthop, so keep the #L */
|
if(locroute->isused && uip_ipaddr_cmp(&locroute->nexthop, &route->nexthop)) {
|
||||||
|
/* we found another link using the specific nexthop, so keep the #L */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -804,8 +794,9 @@ void
|
|||||||
uip_ds6_route_rm_by_nexthop(uip_ipaddr_t *nexthop)
|
uip_ds6_route_rm_by_nexthop(uip_ipaddr_t *nexthop)
|
||||||
{
|
{
|
||||||
for(locroute = uip_ds6_routing_table;
|
for(locroute = uip_ds6_routing_table;
|
||||||
locroute < uip_ds6_routing_table + UIP_DS6_ROUTE_NB; locroute++) {
|
locroute < uip_ds6_routing_table + UIP_DS6_ROUTE_NB;
|
||||||
if((locroute->isused) && uip_ipaddr_cmp(&locroute->nexthop, nexthop)) {
|
locroute++) {
|
||||||
|
if(locroute->isused && uip_ipaddr_cmp(&locroute->nexthop, nexthop)) {
|
||||||
locroute->isused = 0;
|
locroute->isused = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -825,9 +816,9 @@ uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst)
|
|||||||
for(locaddr = uip_ds6_if.addr_list;
|
for(locaddr = uip_ds6_if.addr_list;
|
||||||
locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
|
locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
|
||||||
/* Only preferred global (not link-local) addresses */
|
/* Only preferred global (not link-local) addresses */
|
||||||
if((locaddr->isused) && (locaddr->state == ADDR_PREFERRED) &&
|
if(locaddr->isused && locaddr->state == ADDR_PREFERRED &&
|
||||||
(!uip_is_addr_link_local(&locaddr->ipaddr))) {
|
!uip_is_addr_link_local(&locaddr->ipaddr)) {
|
||||||
n = get_match_length(dst, &(locaddr->ipaddr));
|
n = get_match_length(dst, &locaddr->ipaddr);
|
||||||
if(n >= best) {
|
if(n >= best) {
|
||||||
best = n;
|
best = n;
|
||||||
matchaddr = locaddr;
|
matchaddr = locaddr;
|
||||||
@ -848,7 +839,7 @@ uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst)
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
uip_ds6_set_addr_iid(uip_ipaddr_t * ipaddr, uip_lladdr_t * lladdr)
|
uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t * lladdr)
|
||||||
{
|
{
|
||||||
/* We consider only links with IEEE EUI-64 identifier or
|
/* We consider only links with IEEE EUI-64 identifier or
|
||||||
* IEEE 48-bit MAC addresses */
|
* IEEE 48-bit MAC addresses */
|
||||||
@ -859,7 +850,7 @@ uip_ds6_set_addr_iid(uip_ipaddr_t * ipaddr, uip_lladdr_t * lladdr)
|
|||||||
memcpy(ipaddr->u8 + 8, lladdr, 3);
|
memcpy(ipaddr->u8 + 8, lladdr, 3);
|
||||||
ipaddr->u8[11] = 0xff;
|
ipaddr->u8[11] = 0xff;
|
||||||
ipaddr->u8[12] = 0xfe;
|
ipaddr->u8[12] = 0xfe;
|
||||||
memcpy(ipaddr->u8 + 13, (uint8_t *) lladdr + 3, 3);
|
memcpy(ipaddr->u8 + 13, (uint8_t *)lladdr + 3, 3);
|
||||||
ipaddr->u8[8] ^= 0x02;
|
ipaddr->u8[8] ^= 0x02;
|
||||||
#else
|
#else
|
||||||
#error uip-ds6.c cannot build interface address when UIP_LLADDR_LEN is not 6 or 8
|
#error uip-ds6.c cannot build interface address when UIP_LLADDR_LEN is not 6 or 8
|
||||||
@ -868,7 +859,7 @@ uip_ds6_set_addr_iid(uip_ipaddr_t * ipaddr, uip_lladdr_t * lladdr)
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
uint8_t
|
uint8_t
|
||||||
get_match_length(uip_ipaddr_t * src, uip_ipaddr_t * dst)
|
get_match_length(uip_ipaddr_t *src, uip_ipaddr_t *dst)
|
||||||
{
|
{
|
||||||
uint8_t j, k, x_or;
|
uint8_t j, k, x_or;
|
||||||
uint8_t len = 0;
|
uint8_t len = 0;
|
||||||
@ -894,7 +885,7 @@ get_match_length(uip_ipaddr_t * src, uip_ipaddr_t * dst)
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
uip_ds6_dad(uip_ds6_addr_t * addr)
|
uip_ds6_dad(uip_ds6_addr_t *addr)
|
||||||
{
|
{
|
||||||
/* send maxdadns NS for DAD */
|
/* send maxdadns NS for DAD */
|
||||||
if(addr->dadnscount < uip_ds6_if.maxdadns) {
|
if(addr->dadnscount < uip_ds6_if.maxdadns) {
|
||||||
|
@ -373,7 +373,7 @@ uip_ds6_aaddr_t *uip_ds6_aaddr_lookup(uip_ipaddr_t *ipaddr);
|
|||||||
/** @{ */
|
/** @{ */
|
||||||
uip_ds6_route_t *uip_ds6_route_lookup(uip_ipaddr_t *destipaddr);
|
uip_ds6_route_t *uip_ds6_route_lookup(uip_ipaddr_t *destipaddr);
|
||||||
uip_ds6_route_t *uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
|
uip_ds6_route_t *uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
|
||||||
uip_ipaddr_t *next_hop, u8_t metric);
|
uip_ipaddr_t *next_hop, uint8_t metric);
|
||||||
void uip_ds6_route_rm(uip_ds6_route_t *route);
|
void uip_ds6_route_rm(uip_ds6_route_t *route);
|
||||||
void uip_ds6_route_rm_by_nexthop(uip_ipaddr_t *nexthop);
|
void uip_ds6_route_rm_by_nexthop(uip_ipaddr_t *nexthop);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user