Merge pull request #2500 from fnack/nhdp_optimize_rx
sys/nhdp: Remove temp address lists to optimize hello processing
This commit is contained in:
commit
087b51e10b
@ -40,23 +40,17 @@ static iib_base_entry_t *iib_base_entry_head = NULL;
|
|||||||
|
|
||||||
/* Internal function prototypes */
|
/* Internal function prototypes */
|
||||||
static void rem_link_set_entry(iib_base_entry_t *base_entry, iib_link_set_entry_t *ls_entry);
|
static void rem_link_set_entry(iib_base_entry_t *base_entry, iib_link_set_entry_t *ls_entry);
|
||||||
static void cleanup_link_sets(nhdp_addr_entry_t *rem_list);
|
static void cleanup_link_sets(void);
|
||||||
static iib_link_set_entry_t *add_default_link_set_entry(iib_base_entry_t *base_entry, timex_t *now,
|
static iib_link_set_entry_t *add_default_link_set_entry(iib_base_entry_t *base_entry, timex_t *now,
|
||||||
uint64_t val_time);
|
uint64_t val_time);
|
||||||
static void reset_link_set_entry(iib_link_set_entry_t *ls_entry, timex_t *now, uint64_t val_time);
|
static void reset_link_set_entry(iib_link_set_entry_t *ls_entry, timex_t *now, uint64_t val_time);
|
||||||
static iib_link_set_entry_t *update_link_set(iib_base_entry_t *base_entry, nib_entry_t *nb_elt,
|
static iib_link_set_entry_t *update_link_set(iib_base_entry_t *base_entry, nib_entry_t *nb_elt,
|
||||||
nhdp_addr_entry_t *send_list, timex_t *now,
|
timex_t *now, uint64_t val_time,
|
||||||
uint64_t val_time, uint8_t sym, uint8_t lost);
|
uint8_t sym, uint8_t lost);
|
||||||
static void release_link_tuple_addresses(iib_link_set_entry_t *ls_entry);
|
static void release_link_tuple_addresses(iib_link_set_entry_t *ls_entry);
|
||||||
|
|
||||||
static int update_two_hop_set(iib_base_entry_t *base_entry, iib_link_set_entry_t *ls_entry,
|
static int update_two_hop_set(iib_base_entry_t *base_entry, iib_link_set_entry_t *ls_entry,
|
||||||
nhdp_addr_entry_t *th_sym_list, nhdp_addr_entry_t *th_rem_list,
|
|
||||||
timex_t *now, uint64_t val_time);
|
timex_t *now, uint64_t val_time);
|
||||||
static uint8_t rem_exst_th_entries(iib_base_entry_t *base_entry, iib_two_hop_set_entry_t *ts_elt,
|
|
||||||
nhdp_addr_entry_t *th_sym_list);
|
|
||||||
static uint8_t rem_non_sym_th_entries(iib_base_entry_t *base_entry,
|
|
||||||
iib_two_hop_set_entry_t *ts_elt,
|
|
||||||
nhdp_addr_entry_t *th_rem_list);
|
|
||||||
static int add_two_hop_entry(iib_base_entry_t *base_entry, iib_link_set_entry_t *ls_entry,
|
static int add_two_hop_entry(iib_base_entry_t *base_entry, iib_link_set_entry_t *ls_entry,
|
||||||
nhdp_addr_t *th_addr, timex_t *now, uint64_t val_time);
|
nhdp_addr_t *th_addr, timex_t *now, uint64_t val_time);
|
||||||
static void rem_two_hop_entry(iib_base_entry_t *base_entry, iib_two_hop_set_entry_t *th_entry);
|
static void rem_two_hop_entry(iib_base_entry_t *base_entry, iib_two_hop_set_entry_t *th_entry);
|
||||||
@ -92,10 +86,8 @@ int iib_register_if(kernel_pid_t pid)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int iib_process_hello(kernel_pid_t if_pid, nib_entry_t *nb_elt, nhdp_addr_entry_t *send_list,
|
int iib_process_hello(kernel_pid_t if_pid, nib_entry_t *nb_elt,
|
||||||
nhdp_addr_entry_t *th_sym_list, nhdp_addr_entry_t *th_rem_list,
|
uint64_t validity_time, uint8_t is_sym_nb, uint8_t is_lost)
|
||||||
nhdp_addr_entry_t *rem_list, uint64_t validity_time, uint8_t is_sym_nb,
|
|
||||||
uint8_t is_lost)
|
|
||||||
{
|
{
|
||||||
iib_base_entry_t *base_elt;
|
iib_base_entry_t *base_elt;
|
||||||
timex_t now;
|
timex_t now;
|
||||||
@ -103,7 +95,7 @@ int iib_process_hello(kernel_pid_t if_pid, nib_entry_t *nb_elt, nhdp_addr_entry_
|
|||||||
mutex_lock(&mtx_iib_access);
|
mutex_lock(&mtx_iib_access);
|
||||||
|
|
||||||
/* Remove link tuple addresses that are included in the Removed Addr List */
|
/* Remove link tuple addresses that are included in the Removed Addr List */
|
||||||
cleanup_link_sets(rem_list);
|
cleanup_link_sets();
|
||||||
|
|
||||||
LL_FOREACH(iib_base_entry_head, base_elt) {
|
LL_FOREACH(iib_base_entry_head, base_elt) {
|
||||||
/* Find the link set and two hop set for the interface */
|
/* Find the link set and two hop set for the interface */
|
||||||
@ -116,12 +108,12 @@ int iib_process_hello(kernel_pid_t if_pid, nib_entry_t *nb_elt, nhdp_addr_entry_
|
|||||||
vtimer_now(&now);
|
vtimer_now(&now);
|
||||||
|
|
||||||
/* Create a new link tuple for the neighbor that originated the hello */
|
/* Create a new link tuple for the neighbor that originated the hello */
|
||||||
iib_link_set_entry_t *ls_entry = update_link_set(base_elt, nb_elt, send_list,
|
iib_link_set_entry_t *ls_entry = update_link_set(base_elt, nb_elt, &now,
|
||||||
&now, validity_time, is_sym_nb, is_lost);
|
validity_time, is_sym_nb, is_lost);
|
||||||
|
|
||||||
/* Create new two hop tuples for signaled symmetric neighbors */
|
/* Create new two hop tuples for signaled symmetric neighbors */
|
||||||
if (ls_entry) {
|
if (ls_entry) {
|
||||||
update_two_hop_set(base_elt, ls_entry, th_sym_list, th_rem_list, &now, validity_time);
|
update_two_hop_set(base_elt, ls_entry, &now, validity_time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,32 +224,22 @@ void iib_propagate_nb_entry_change(nib_entry_t *old_entry, nib_entry_t *new_entr
|
|||||||
/**
|
/**
|
||||||
* Remove addresses included in the Removed Address List from all existing Link Tuples
|
* Remove addresses included in the Removed Address List from all existing Link Tuples
|
||||||
*/
|
*/
|
||||||
static void cleanup_link_sets(nhdp_addr_entry_t *rem_list)
|
static void cleanup_link_sets(void)
|
||||||
{
|
{
|
||||||
/* Check whether the Removed Address List is not empty */
|
iib_base_entry_t *base_elt;
|
||||||
if (!rem_list) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Loop through all link sets */
|
/* Loop through all link sets */
|
||||||
iib_base_entry_t *base_elt;
|
|
||||||
LL_FOREACH(iib_base_entry_head, base_elt) {
|
LL_FOREACH(iib_base_entry_head, base_elt) {
|
||||||
/* Loop through all link tuples of the link set */
|
/* Loop through all link tuples of the link set */
|
||||||
iib_link_set_entry_t *ls_elt, *ls_tmp;
|
iib_link_set_entry_t *ls_elt, *ls_tmp;
|
||||||
LL_FOREACH_SAFE(base_elt->link_set_head, ls_elt, ls_tmp) {
|
LL_FOREACH_SAFE(base_elt->link_set_head, ls_elt, ls_tmp) {
|
||||||
/* Loop through all addresses of the link tuples */
|
/* Loop through all addresses of the link tuples */
|
||||||
nhdp_addr_entry_t *lt_elt;
|
nhdp_addr_entry_t *lt_elt, *lt_tmp;
|
||||||
LL_FOREACH(ls_elt->address_list_head, lt_elt) {
|
LL_FOREACH_SAFE(ls_elt->address_list_head, lt_elt, lt_tmp) {
|
||||||
/* Loop through all addresses of the Removed Addr List */
|
if (NHDP_ADDR_TMP_IN_REM_LIST(lt_elt->address)) {
|
||||||
nhdp_addr_entry_t *rem_elt;
|
|
||||||
LL_FOREACH(rem_list, rem_elt) {
|
|
||||||
/* Remove link tuple address if included in the Removed Addr List */
|
/* Remove link tuple address if included in the Removed Addr List */
|
||||||
if (lt_elt->address == rem_elt->address) {
|
LL_DELETE(ls_elt->address_list_head, lt_elt);
|
||||||
/* Addresses are equal (same NHDP address db entry) */
|
nhdp_free_addr_entry(lt_elt);
|
||||||
LL_DELETE(ls_elt->address_list_head, lt_elt);
|
|
||||||
nhdp_free_addr_entry(lt_elt);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,12 +265,12 @@ static void cleanup_link_sets(nhdp_addr_entry_t *rem_list)
|
|||||||
* Update the Link Set for the receiving interface during HELLO message processing
|
* Update the Link Set for the receiving interface during HELLO message processing
|
||||||
*/
|
*/
|
||||||
static iib_link_set_entry_t *update_link_set(iib_base_entry_t *base_entry, nib_entry_t *nb_elt,
|
static iib_link_set_entry_t *update_link_set(iib_base_entry_t *base_entry, nib_entry_t *nb_elt,
|
||||||
nhdp_addr_entry_t *send_list, timex_t *now,
|
timex_t *now, uint64_t val_time,
|
||||||
uint64_t val_time, uint8_t sym, uint8_t lost)
|
uint8_t sym, uint8_t lost)
|
||||||
{
|
{
|
||||||
iib_link_set_entry_t *ls_elt, *ls_tmp;
|
iib_link_set_entry_t *ls_elt, *ls_tmp;
|
||||||
iib_link_set_entry_t *matching_lt = NULL;
|
iib_link_set_entry_t *matching_lt = NULL;
|
||||||
nhdp_addr_entry_t *lt_elt, *send_elt;
|
nhdp_addr_entry_t *lt_elt;
|
||||||
timex_t v_time, l_hold;
|
timex_t v_time, l_hold;
|
||||||
uint8_t matches = 0;
|
uint8_t matches = 0;
|
||||||
|
|
||||||
@ -296,30 +278,21 @@ static iib_link_set_entry_t *update_link_set(iib_base_entry_t *base_entry, nib_e
|
|||||||
LL_FOREACH_SAFE(base_entry->link_set_head, ls_elt, ls_tmp) {
|
LL_FOREACH_SAFE(base_entry->link_set_head, ls_elt, ls_tmp) {
|
||||||
/* Loop through all addresses of the link tuple */
|
/* Loop through all addresses of the link tuple */
|
||||||
LL_FOREACH(ls_elt->address_list_head, lt_elt) {
|
LL_FOREACH(ls_elt->address_list_head, lt_elt) {
|
||||||
/* Loop through all addresses of the Sending Addr List */
|
if (NHDP_ADDR_TMP_IN_SEND_LIST(lt_elt->address)) {
|
||||||
LL_FOREACH(send_list, send_elt) {
|
|
||||||
/* If link tuple address matches a sending addr we found a fitting tuple */
|
/* If link tuple address matches a sending addr we found a fitting tuple */
|
||||||
if (lt_elt->address == send_elt->address) {
|
matches++;
|
||||||
/* Addresses are equal (same NHDP address db entry) */
|
|
||||||
matches++;
|
|
||||||
|
|
||||||
if (matches > 1) {
|
if (matches > 1) {
|
||||||
/* Multiple matching link tuples, delete the previous one */
|
/* Multiple matching link tuples, delete the previous one */
|
||||||
if (matching_lt->last_status == IIB_LT_STATUS_SYM) {
|
if (matching_lt->last_status == IIB_LT_STATUS_SYM) {
|
||||||
update_nb_tuple_symmetry(base_entry, matching_lt, now);
|
update_nb_tuple_symmetry(base_entry, matching_lt, now);
|
||||||
}
|
|
||||||
|
|
||||||
rem_link_set_entry(base_entry, matching_lt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
matching_lt = ls_elt;
|
rem_link_set_entry(base_entry, matching_lt);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matching_lt == ls_elt) {
|
matching_lt = ls_elt;
|
||||||
/* This link tuple is already detected as matching */
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -350,7 +323,7 @@ static iib_link_set_entry_t *update_link_set(iib_base_entry_t *base_entry, nib_e
|
|||||||
l_hold = timex_from_uint64(((uint64_t)NHDP_L_HOLD_TIME_MS) * MS_IN_USEC);
|
l_hold = timex_from_uint64(((uint64_t)NHDP_L_HOLD_TIME_MS) * MS_IN_USEC);
|
||||||
|
|
||||||
/* Set Sending Address List as this tuples address list */
|
/* Set Sending Address List as this tuples address list */
|
||||||
matching_lt->address_list_head = nhdp_generate_new_addr_list(send_list);
|
matching_lt->address_list_head = nhdp_generate_addr_list_from_tmp(NHDP_ADDR_TMP_SEND_LIST);
|
||||||
|
|
||||||
if (!matching_lt->address_list_head) {
|
if (!matching_lt->address_list_head) {
|
||||||
/* Insufficient memory */
|
/* Insufficient memory */
|
||||||
@ -520,7 +493,6 @@ static void release_link_tuple_addresses(iib_link_set_entry_t *ls_entry)
|
|||||||
* Update the 2-Hop Set during HELLO message processing
|
* Update the 2-Hop Set during HELLO message processing
|
||||||
*/
|
*/
|
||||||
static int update_two_hop_set(iib_base_entry_t *base_entry, iib_link_set_entry_t *ls_entry,
|
static int update_two_hop_set(iib_base_entry_t *base_entry, iib_link_set_entry_t *ls_entry,
|
||||||
nhdp_addr_entry_t *th_sym_list, nhdp_addr_entry_t *th_rem_list,
|
|
||||||
timex_t *now, uint64_t val_time)
|
timex_t *now, uint64_t val_time)
|
||||||
{
|
{
|
||||||
/* Check whether a corresponding link tuple was created */
|
/* Check whether a corresponding link tuple was created */
|
||||||
@ -531,7 +503,7 @@ static int update_two_hop_set(iib_base_entry_t *base_entry, iib_link_set_entry_t
|
|||||||
/* If the link to the neighbor is still symmetric */
|
/* If the link to the neighbor is still symmetric */
|
||||||
if (get_tuple_status(ls_entry, now) == IIB_LT_STATUS_SYM) {
|
if (get_tuple_status(ls_entry, now) == IIB_LT_STATUS_SYM) {
|
||||||
iib_two_hop_set_entry_t *ths_elt, *ths_tmp;
|
iib_two_hop_set_entry_t *ths_elt, *ths_tmp;
|
||||||
nhdp_addr_entry_t *sym_elt;
|
nhdp_addr_t *addr_elt;
|
||||||
|
|
||||||
/* Loop through all the two hop tuples of the two hop set */
|
/* Loop through all the two hop tuples of the two hop set */
|
||||||
LL_FOREACH_SAFE(base_entry->two_hop_set_head, ths_elt, ths_tmp) {
|
LL_FOREACH_SAFE(base_entry->two_hop_set_head, ths_elt, ths_tmp) {
|
||||||
@ -540,17 +512,20 @@ static int update_two_hop_set(iib_base_entry_t *base_entry, iib_link_set_entry_t
|
|||||||
rem_two_hop_entry(base_entry, ths_elt);
|
rem_two_hop_entry(base_entry, ths_elt);
|
||||||
}
|
}
|
||||||
else if (ths_elt->ls_elt == ls_entry) {
|
else if (ths_elt->ls_elt == ls_entry) {
|
||||||
if (!rem_non_sym_th_entries(base_entry, ths_elt, th_rem_list)) {
|
if (ths_elt->th_nb_addr->in_tmp_table &
|
||||||
rem_exst_th_entries(base_entry, ths_elt, th_sym_list);
|
(NHDP_ADDR_TMP_TH_REM_LIST | NHDP_ADDR_TMP_TH_SYM_LIST)) {
|
||||||
|
rem_two_hop_entry(base_entry, ths_elt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add a new entry for every signaled symmetric neighbor address */
|
/* Add a new entry for every signaled symmetric neighbor address */
|
||||||
LL_FOREACH(th_sym_list, sym_elt) {
|
LL_FOREACH(nhdp_get_addr_db_head(), addr_elt) {
|
||||||
if (add_two_hop_entry(base_entry, ls_entry, sym_elt->address, now, val_time)) {
|
if (NHDP_ADDR_TMP_IN_TH_SYM_LIST(addr_elt)) {
|
||||||
/* No more memory available, return error */
|
if (add_two_hop_entry(base_entry, ls_entry, addr_elt, now, val_time)) {
|
||||||
return -1;
|
/* No more memory available, return error */
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -558,46 +533,6 @@ static int update_two_hop_set(iib_base_entry_t *base_entry, iib_link_set_entry_t
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove an existing 2-Hop Tuple if its address was signalled as lost in the received HELLO
|
|
||||||
*/
|
|
||||||
static uint8_t rem_non_sym_th_entries(iib_base_entry_t *base_entry,
|
|
||||||
iib_two_hop_set_entry_t *ts_elt,
|
|
||||||
nhdp_addr_entry_t *th_rem_list)
|
|
||||||
{
|
|
||||||
nhdp_addr_entry_t *rem_elt;
|
|
||||||
|
|
||||||
/* Remove the given two hop entry if it was signaled as lost */
|
|
||||||
LL_FOREACH(th_rem_list, rem_elt) {
|
|
||||||
if (ts_elt->th_nb_addr == rem_elt->address) {
|
|
||||||
/* Addresses are equal (same NHDP address db entry) */
|
|
||||||
rem_two_hop_entry(base_entry, ts_elt);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove an existing 2-Hop Tuple if it is present in the 2-Hop symmetric address
|
|
||||||
* list of the received HELLO
|
|
||||||
*/
|
|
||||||
static uint8_t rem_exst_th_entries(iib_base_entry_t *base_entry,
|
|
||||||
iib_two_hop_set_entry_t *ts_elt, nhdp_addr_entry_t *th_sym_list)
|
|
||||||
{
|
|
||||||
nhdp_addr_entry_t *sym_elt;
|
|
||||||
|
|
||||||
/* Remove the given two hop entry if it was signaled as symmetric (new one is added) */
|
|
||||||
LL_FOREACH(th_sym_list, sym_elt) {
|
|
||||||
if (ts_elt->th_nb_addr == sym_elt->address) {
|
|
||||||
/* Addresses are equal (same NHDP address db entry) */
|
|
||||||
rem_two_hop_entry(base_entry, ts_elt);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a 2-Hop Tuple for a given address
|
* Add a 2-Hop Tuple for a given address
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -96,20 +96,14 @@ int iib_register_if(kernel_pid_t pid);
|
|||||||
*
|
*
|
||||||
* @param[in] if_pid PID of the interface the message was received on
|
* @param[in] if_pid PID of the interface the message was received on
|
||||||
* @param[in] nb_elt Pointer to the Neighbor Tuple for the message originator
|
* @param[in] nb_elt Pointer to the Neighbor Tuple for the message originator
|
||||||
* @param[in] send_list Pointer to the Sending Address List from the received HELLO
|
|
||||||
* @param[in] th_sym_list Pointer to the Addr List of the originator's symmetric 2-Hop neighbors
|
|
||||||
* @param[in] th_rem_list Pointer to the Addr List of the originator's lost 2-Hop neighbors
|
|
||||||
* @param[in] rem_list Pointer to the Removed Address List
|
|
||||||
* @param[in] validity_time Validity time in milliseconds for the originator's information
|
* @param[in] validity_time Validity time in milliseconds for the originator's information
|
||||||
* @param[in] is_sym_nb Flag whether the link to the originator is symmetric
|
* @param[in] is_sym_nb Flag whether the link to the originator is symmetric
|
||||||
* @param[in] is_lost Flag whether the originator marked this link as lost
|
* @param[in] is_lost Flag whether the originator marked this link as lost
|
||||||
*
|
*
|
||||||
* @return 0 on success
|
* @return 0 on success
|
||||||
*/
|
*/
|
||||||
int iib_process_hello(kernel_pid_t if_pid, nib_entry_t *nb_elt, nhdp_addr_entry_t *send_list,
|
int iib_process_hello(kernel_pid_t if_pid, nib_entry_t *nb_elt,
|
||||||
nhdp_addr_entry_t *th_sym_list, nhdp_addr_entry_t *th_rem_list,
|
uint64_t validity_time, uint8_t is_sym_nb, uint8_t is_lost);
|
||||||
nhdp_addr_entry_t *rem_list, uint64_t validity_time, uint8_t is_sym_nb,
|
|
||||||
uint8_t is_lost);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add addresses to the currently constructed HELLO message
|
* @brief Add addresses to the currently constructed HELLO message
|
||||||
|
|||||||
@ -115,34 +115,47 @@ void nhdp_free_addr_entry(nhdp_addr_entry_t *addr_entry)
|
|||||||
free(addr_entry);
|
free(addr_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
nhdp_addr_entry_t *nhdp_generate_new_addr_list(nhdp_addr_entry_t *orig_list)
|
nhdp_addr_entry_t *nhdp_generate_addr_list_from_tmp(uint8_t tmp_type)
|
||||||
{
|
{
|
||||||
nhdp_addr_entry_t *new_list_head, *addr_elt;
|
nhdp_addr_entry_t *new_list_head;
|
||||||
|
nhdp_addr_t *addr_elt;
|
||||||
|
|
||||||
new_list_head = NULL;
|
new_list_head = NULL;
|
||||||
LL_FOREACH(orig_list, addr_elt) {
|
LL_FOREACH(nhdp_addr_db_head, addr_elt) {
|
||||||
nhdp_addr_entry_t *new_entry = (nhdp_addr_entry_t *) malloc(sizeof(nhdp_addr_entry_t));
|
if (addr_elt->in_tmp_table & tmp_type) {
|
||||||
|
nhdp_addr_entry_t *new_entry = (nhdp_addr_entry_t *) malloc(sizeof(nhdp_addr_entry_t));
|
||||||
|
|
||||||
if (!new_entry) {
|
if (!new_entry) {
|
||||||
/* Insufficient memory, free all previously allocated memory */
|
/* Insufficient memory, free all previously allocated memory */
|
||||||
nhdp_free_addr_list(new_list_head);
|
nhdp_free_addr_list(new_list_head);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
new_entry->address = addr_elt;
|
||||||
|
/* Increment usage counter of address in central NHDP address storage */
|
||||||
|
addr_elt->usg_count++;
|
||||||
|
LL_PREPEND(new_list_head, new_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
new_entry->address = addr_elt->address;
|
|
||||||
/* Increment usage counter of address in central NHDP address storage */
|
|
||||||
addr_elt->address->usg_count++;
|
|
||||||
LL_PREPEND(new_list_head, new_entry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new_list_head;
|
return new_list_head;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nhdp_reset_addresses_tmp_usg(void)
|
void nhdp_reset_addresses_tmp_usg(uint8_t decr_usg)
|
||||||
{
|
{
|
||||||
nhdp_addr_t *addr_elt;
|
nhdp_addr_t *addr_elt, *addr_tmp;
|
||||||
|
|
||||||
LL_FOREACH(nhdp_addr_db_head, addr_elt) {
|
LL_FOREACH_SAFE(nhdp_addr_db_head, addr_elt, addr_tmp) {
|
||||||
addr_elt->in_tmp_table = NHDP_ADDR_TMP_NONE;
|
if (addr_elt->in_tmp_table) {
|
||||||
|
addr_elt->in_tmp_table = NHDP_ADDR_TMP_NONE;
|
||||||
|
if (decr_usg) {
|
||||||
|
nhdp_decrement_addr_usage(addr_elt);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nhdp_addr_t *nhdp_get_addr_db_head(void)
|
||||||
|
{
|
||||||
|
return nhdp_addr_db_head;
|
||||||
|
}
|
||||||
|
|||||||
@ -51,9 +51,19 @@ typedef struct nhdp_addr_entry_t {
|
|||||||
#define NHDP_ADDR_TMP_NONE (0x00)
|
#define NHDP_ADDR_TMP_NONE (0x00)
|
||||||
#define NHDP_ADDR_TMP_ANY (0x01)
|
#define NHDP_ADDR_TMP_ANY (0x01)
|
||||||
#define NHDP_ADDR_TMP_SYM (0x03)
|
#define NHDP_ADDR_TMP_SYM (0x03)
|
||||||
|
#define NHDP_ADDR_TMP_REM_LIST (0x04)
|
||||||
|
#define NHDP_ADDR_TMP_TH_REM_LIST (0x08)
|
||||||
|
#define NHDP_ADDR_TMP_TH_SYM_LIST (0x10)
|
||||||
|
#define NHDP_ADDR_TMP_NB_LIST (0x20)
|
||||||
|
#define NHDP_ADDR_TMP_SEND_LIST (0x60)
|
||||||
|
|
||||||
#define NHDP_ADDR_TMP_IN_SYM(addr) ((addr->in_tmp_table & 0x02) >> 1)
|
#define NHDP_ADDR_TMP_IN_ANY(addr) ((addr->in_tmp_table & 0x01))
|
||||||
#define NHDP_ADDR_TMP_IN_ANY(addr) ((addr->in_tmp_table & 0x01))
|
#define NHDP_ADDR_TMP_IN_SYM(addr) ((addr->in_tmp_table & 0x02) >> 1)
|
||||||
|
#define NHDP_ADDR_TMP_IN_REM_LIST(addr) ((addr->in_tmp_table & 0x04) >> 2)
|
||||||
|
#define NHDP_ADDR_TMP_IN_TH_REM_LIST(addr) ((addr->in_tmp_table & 0x08) >> 3)
|
||||||
|
#define NHDP_ADDR_TMP_IN_TH_SYM_LIST(addr) ((addr->in_tmp_table & 0x10) >> 4)
|
||||||
|
#define NHDP_ADDR_TMP_IN_NB_LIST(addr) ((addr->in_tmp_table & 0x20) >> 5)
|
||||||
|
#define NHDP_ADDR_TMP_IN_SEND_LIST(addr) ((addr->in_tmp_table & 0x40) >> 6)
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,22 +107,31 @@ void nhdp_free_addr_list(nhdp_addr_entry_t *list_head);
|
|||||||
void nhdp_free_addr_entry(nhdp_addr_entry_t *addr_entry);
|
void nhdp_free_addr_entry(nhdp_addr_entry_t *addr_entry);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Construct an address list containing the addresses of the given list
|
* @brief Construct an addr list containing all addresses with
|
||||||
*
|
* the given tmp_type
|
||||||
* @param[in] orig_list Pointer to the head of the address list to 'clone'
|
|
||||||
*
|
*
|
||||||
* @return Pointer to the head of the newly created address list
|
* @return Pointer to the head of the newly created address list
|
||||||
* @return NULL on error
|
* @return NULL on error
|
||||||
*/
|
*/
|
||||||
nhdp_addr_entry_t *nhdp_generate_new_addr_list(nhdp_addr_entry_t *orig_list);
|
nhdp_addr_entry_t *nhdp_generate_addr_list_from_tmp(uint8_t tmp_type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Reset in_tmp_table flag of all NHDP addresses
|
* @brief Reset in_tmp_table flag of all NHDP addresses
|
||||||
*
|
*
|
||||||
* @note
|
* @note
|
||||||
* Must not be called from outside the NHDP writer's message creation process.
|
* Must not be called from outside the NHDP writer's or reader's message creation process.
|
||||||
|
*
|
||||||
|
* @param[in] decr_usg Flag whether the usage counter of a resetted addr has to be decremented
|
||||||
*/
|
*/
|
||||||
void nhdp_reset_addresses_tmp_usg(void);
|
void nhdp_reset_addresses_tmp_usg(uint8_t decr_usg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get a pointer to the head of the address storage list
|
||||||
|
*
|
||||||
|
* @return Pointer to the head of the central storage address list
|
||||||
|
* @return NULL if no addresses are registered
|
||||||
|
*/
|
||||||
|
nhdp_addr_t *nhdp_get_addr_db_head(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,12 +36,6 @@
|
|||||||
struct rfc5444_reader reader;
|
struct rfc5444_reader reader;
|
||||||
static mutex_t mtx_packet_handler = MUTEX_INIT;
|
static mutex_t mtx_packet_handler = MUTEX_INIT;
|
||||||
|
|
||||||
static nhdp_addr_entry_t *send_addr_list_head;
|
|
||||||
static nhdp_addr_entry_t *nb_addr_list_head;
|
|
||||||
static nhdp_addr_entry_t *th_sym_addr_list_head;
|
|
||||||
static nhdp_addr_entry_t *th_rem_addr_list_head;
|
|
||||||
static nhdp_addr_entry_t *rem_addr_list_head;
|
|
||||||
|
|
||||||
static kernel_pid_t if_pid;
|
static kernel_pid_t if_pid;
|
||||||
static uint64_t val_time;
|
static uint64_t val_time;
|
||||||
static uint64_t int_time;
|
static uint64_t int_time;
|
||||||
@ -57,7 +51,6 @@ static enum rfc5444_result check_msg_validity(struct rfc5444_reader_tlvblock_con
|
|||||||
static enum rfc5444_result check_addr_validity(nhdp_addr_t *addr);
|
static enum rfc5444_result check_addr_validity(nhdp_addr_t *addr);
|
||||||
static nhdp_addr_t *get_nhdp_db_addr(uint8_t *addr, uint8_t prefix);
|
static nhdp_addr_t *get_nhdp_db_addr(uint8_t *addr, uint8_t prefix);
|
||||||
static void process_temp_tables(void);
|
static void process_temp_tables(void);
|
||||||
static void cleanup_temp_addr_lists(void);
|
|
||||||
|
|
||||||
/* Array containing the processable message TLVs for HELLO messages */
|
/* Array containing the processable message TLVs for HELLO messages */
|
||||||
static struct rfc5444_reader_tlvblock_consumer_entry _nhdp_msg_tlvs[] = {
|
static struct rfc5444_reader_tlvblock_consumer_entry _nhdp_msg_tlvs[] = {
|
||||||
@ -93,13 +86,6 @@ static struct rfc5444_reader_tlvblock_consumer _nhdp_address_consumer = {
|
|||||||
|
|
||||||
void nhdp_reader_init(void)
|
void nhdp_reader_init(void)
|
||||||
{
|
{
|
||||||
/* Reset locally created address lists */
|
|
||||||
send_addr_list_head = NULL;
|
|
||||||
nb_addr_list_head = NULL;
|
|
||||||
th_sym_addr_list_head = NULL;
|
|
||||||
th_rem_addr_list_head = NULL;
|
|
||||||
rem_addr_list_head = NULL;
|
|
||||||
|
|
||||||
/* Initialize reader */
|
/* Initialize reader */
|
||||||
rfc5444_reader_init(&reader);
|
rfc5444_reader_init(&reader);
|
||||||
|
|
||||||
@ -128,7 +114,6 @@ int nhdp_reader_handle_packet(kernel_pid_t rcvg_if_pid, void *buffer, size_t len
|
|||||||
|
|
||||||
void nhdp_reader_cleanup(void)
|
void nhdp_reader_cleanup(void)
|
||||||
{
|
{
|
||||||
cleanup_temp_addr_lists();
|
|
||||||
rfc5444_reader_cleanup(&reader);
|
rfc5444_reader_cleanup(&reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,26 +130,18 @@ static enum rfc5444_result
|
|||||||
_nhdp_blocktlv_address_cb(struct rfc5444_reader_tlvblock_context *cont)
|
_nhdp_blocktlv_address_cb(struct rfc5444_reader_tlvblock_context *cont)
|
||||||
{
|
{
|
||||||
uint8_t tmp_result;
|
uint8_t tmp_result;
|
||||||
/* Create address list entry to add it later to one of the temp address lists */
|
|
||||||
nhdp_addr_entry_t *current_addr = (nhdp_addr_entry_t *) malloc(sizeof(nhdp_addr_entry_t));
|
/* Get NHDP address for the current netaddr */
|
||||||
|
nhdp_addr_t *current_addr = get_nhdp_db_addr(&cont->addr._addr[0], cont->addr._prefix_len);
|
||||||
|
|
||||||
if (!current_addr) {
|
if (!current_addr) {
|
||||||
/* Insufficient memory */
|
/* Insufficient memory */
|
||||||
return RFC5444_DROP_MESSAGE;
|
return RFC5444_DROP_MESSAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get NHDP address for the current netaddr */
|
|
||||||
current_addr->address = get_nhdp_db_addr(&cont->addr._addr[0], cont->addr._prefix_len);
|
|
||||||
|
|
||||||
if (!current_addr->address) {
|
|
||||||
/* Insufficient memory */
|
|
||||||
free(current_addr);
|
|
||||||
return RFC5444_DROP_MESSAGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check validity of address tlvs */
|
/* Check validity of address tlvs */
|
||||||
if (check_addr_validity(current_addr->address) != RFC5444_OKAY) {
|
if (check_addr_validity(current_addr) != RFC5444_OKAY) {
|
||||||
nhdp_free_addr_entry(current_addr);
|
nhdp_decrement_addr_usage(current_addr);
|
||||||
return RFC5444_DROP_MESSAGE;
|
return RFC5444_DROP_MESSAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,32 +149,20 @@ _nhdp_blocktlv_address_cb(struct rfc5444_reader_tlvblock_context *cont)
|
|||||||
if (_nhdp_addr_tlvs[RFC5444_ADDRTLV_LOCAL_IF].tlv) {
|
if (_nhdp_addr_tlvs[RFC5444_ADDRTLV_LOCAL_IF].tlv) {
|
||||||
switch (*_nhdp_addr_tlvs[RFC5444_ADDRTLV_LOCAL_IF].tlv->single_value) {
|
switch (*_nhdp_addr_tlvs[RFC5444_ADDRTLV_LOCAL_IF].tlv->single_value) {
|
||||||
case RFC5444_LOCALIF_THIS_IF:
|
case RFC5444_LOCALIF_THIS_IF:
|
||||||
LL_PREPEND(send_addr_list_head, current_addr);
|
current_addr->in_tmp_table = NHDP_ADDR_TMP_SEND_LIST;
|
||||||
/* Local IF marked addresses have to be added to two temp lists */
|
|
||||||
nhdp_addr_entry_t *sec_container =
|
|
||||||
(nhdp_addr_entry_t *) malloc(sizeof(nhdp_addr_entry_t));
|
|
||||||
|
|
||||||
if (!sec_container) {
|
|
||||||
return RFC5444_DROP_MESSAGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Increment usage counter of address in central NHDP address storage */
|
|
||||||
current_addr->address->usg_count++;
|
|
||||||
sec_container->address = current_addr->address;
|
|
||||||
LL_PREPEND(nb_addr_list_head, sec_container);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RFC5444_LOCALIF_OTHER_IF:
|
case RFC5444_LOCALIF_OTHER_IF:
|
||||||
LL_PREPEND(nb_addr_list_head, current_addr);
|
current_addr->in_tmp_table = NHDP_ADDR_TMP_NB_LIST;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Wrong value, drop message */
|
/* Wrong value, drop message */
|
||||||
nhdp_free_addr_entry(current_addr);
|
nhdp_decrement_addr_usage(current_addr);
|
||||||
return RFC5444_DROP_MESSAGE;
|
return RFC5444_DROP_MESSAGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((tmp_result = lib_is_reg_addr(if_pid, current_addr->address))) {
|
else if ((tmp_result = lib_is_reg_addr(if_pid, current_addr))) {
|
||||||
/* The address is one of our local addresses (do not add it for processing) */
|
/* The address is one of our local addresses (do not add it for processing) */
|
||||||
if ((!sym) && (tmp_result == 1) && _nhdp_addr_tlvs[RFC5444_ADDRTLV_LINK_STATUS].tlv) {
|
if ((!sym) && (tmp_result == 1) && _nhdp_addr_tlvs[RFC5444_ADDRTLV_LINK_STATUS].tlv) {
|
||||||
/* If address is a local address of the receiving interface, check */
|
/* If address is a local address of the receiving interface, check */
|
||||||
@ -216,18 +181,18 @@ _nhdp_blocktlv_address_cb(struct rfc5444_reader_tlvblock_context *cont)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
/* Wrong value, drop message */
|
/* Wrong value, drop message */
|
||||||
nhdp_free_addr_entry(current_addr);
|
nhdp_decrement_addr_usage(current_addr);
|
||||||
return RFC5444_DROP_MESSAGE;
|
return RFC5444_DROP_MESSAGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Address is one of our own addresses, ignore it */
|
/* Address is one of our own addresses, ignore it */
|
||||||
nhdp_free_addr_entry(current_addr);
|
nhdp_decrement_addr_usage(current_addr);
|
||||||
}
|
}
|
||||||
else if (_nhdp_addr_tlvs[RFC5444_ADDRTLV_LINK_STATUS].tlv) {
|
else if (_nhdp_addr_tlvs[RFC5444_ADDRTLV_LINK_STATUS].tlv) {
|
||||||
switch (*_nhdp_addr_tlvs[RFC5444_ADDRTLV_LINK_STATUS].tlv->single_value) {
|
switch (*_nhdp_addr_tlvs[RFC5444_ADDRTLV_LINK_STATUS].tlv->single_value) {
|
||||||
case RFC5444_LINKSTATUS_SYMMETRIC:
|
case RFC5444_LINKSTATUS_SYMMETRIC:
|
||||||
LL_PREPEND(th_sym_addr_list_head, current_addr);
|
current_addr->in_tmp_table = NHDP_ADDR_TMP_TH_SYM_LIST;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RFC5444_LINKSTATUS_HEARD:
|
case RFC5444_LINKSTATUS_HEARD:
|
||||||
@ -238,39 +203,39 @@ _nhdp_blocktlv_address_cb(struct rfc5444_reader_tlvblock_context *cont)
|
|||||||
&& *_nhdp_addr_tlvs[RFC5444_ADDRTLV_OTHER_NEIGHB].tlv->single_value
|
&& *_nhdp_addr_tlvs[RFC5444_ADDRTLV_OTHER_NEIGHB].tlv->single_value
|
||||||
== RFC5444_OTHERNEIGHB_SYMMETRIC) {
|
== RFC5444_OTHERNEIGHB_SYMMETRIC) {
|
||||||
/* Symmetric has higher priority */
|
/* Symmetric has higher priority */
|
||||||
LL_PREPEND(th_sym_addr_list_head, current_addr);
|
current_addr->in_tmp_table = NHDP_ADDR_TMP_TH_SYM_LIST;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LL_PREPEND(th_rem_addr_list_head, current_addr);
|
current_addr->in_tmp_table = NHDP_ADDR_TMP_TH_REM_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Wrong value, drop message */
|
/* Wrong value, drop message */
|
||||||
nhdp_free_addr_entry(current_addr);
|
nhdp_decrement_addr_usage(current_addr);
|
||||||
return RFC5444_DROP_MESSAGE;
|
return RFC5444_DROP_MESSAGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (_nhdp_addr_tlvs[RFC5444_ADDRTLV_OTHER_NEIGHB].tlv) {
|
else if (_nhdp_addr_tlvs[RFC5444_ADDRTLV_OTHER_NEIGHB].tlv) {
|
||||||
switch (*_nhdp_addr_tlvs[RFC5444_ADDRTLV_OTHER_NEIGHB].tlv->single_value) {
|
switch (*_nhdp_addr_tlvs[RFC5444_ADDRTLV_OTHER_NEIGHB].tlv->single_value) {
|
||||||
case RFC5444_OTHERNEIGHB_SYMMETRIC:
|
case RFC5444_OTHERNEIGHB_SYMMETRIC:
|
||||||
LL_PREPEND(th_sym_addr_list_head, current_addr);
|
current_addr->in_tmp_table = NHDP_ADDR_TMP_TH_SYM_LIST;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RFC5444_OTHERNEIGHB_LOST:
|
case RFC5444_OTHERNEIGHB_LOST:
|
||||||
LL_PREPEND(th_rem_addr_list_head, current_addr);
|
current_addr->in_tmp_table = NHDP_ADDR_TMP_TH_REM_LIST;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Wrong value, drop message */
|
/* Wrong value, drop message */
|
||||||
nhdp_free_addr_entry(current_addr);
|
nhdp_decrement_addr_usage(current_addr);
|
||||||
return RFC5444_DROP_MESSAGE;
|
return RFC5444_DROP_MESSAGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Addresses without expected TLV are ignored */
|
/* Addresses without expected TLV are ignored */
|
||||||
nhdp_free_addr_entry(current_addr);
|
nhdp_decrement_addr_usage(current_addr);
|
||||||
return RFC5444_DROP_ADDRESS;
|
return RFC5444_DROP_ADDRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,7 +285,7 @@ _nhdp_msg_end_cb(struct rfc5444_reader_tlvblock_context *cont __attribute__((unu
|
|||||||
int_time = 0ULL;
|
int_time = 0ULL;
|
||||||
sym = 0;
|
sym = 0;
|
||||||
lost = 0;
|
lost = 0;
|
||||||
cleanup_temp_addr_lists();
|
nhdp_reset_addresses_tmp_usg(1);
|
||||||
|
|
||||||
if (dropped) {
|
if (dropped) {
|
||||||
return RFC5444_DROP_MESSAGE;
|
return RFC5444_DROP_MESSAGE;
|
||||||
@ -430,27 +395,9 @@ static void process_temp_tables(void)
|
|||||||
vtimer_now(&now);
|
vtimer_now(&now);
|
||||||
iib_update_lt_status(&now);
|
iib_update_lt_status(&now);
|
||||||
|
|
||||||
nib_elt = nib_process_hello(nb_addr_list_head, &rem_addr_list_head);
|
nib_elt = nib_process_hello();
|
||||||
|
|
||||||
if (nib_elt) {
|
if (nib_elt) {
|
||||||
iib_process_hello(if_pid, nib_elt, send_addr_list_head, th_sym_addr_list_head,
|
iib_process_hello(if_pid, nib_elt, val_time, sym, lost);
|
||||||
th_rem_addr_list_head, rem_addr_list_head, val_time, sym, lost);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Free all allocated space for the temporary address lists
|
|
||||||
*/
|
|
||||||
static void cleanup_temp_addr_lists(void)
|
|
||||||
{
|
|
||||||
nhdp_free_addr_list(send_addr_list_head);
|
|
||||||
nhdp_free_addr_list(nb_addr_list_head);
|
|
||||||
nhdp_free_addr_list(th_sym_addr_list_head);
|
|
||||||
nhdp_free_addr_list(th_rem_addr_list_head);
|
|
||||||
nhdp_free_addr_list(rem_addr_list_head);
|
|
||||||
send_addr_list_head = NULL;
|
|
||||||
nb_addr_list_head = NULL;
|
|
||||||
th_sym_addr_list_head = NULL;
|
|
||||||
th_rem_addr_list_head = NULL;
|
|
||||||
rem_addr_list_head = NULL;
|
|
||||||
}
|
|
||||||
|
|||||||
@ -213,7 +213,7 @@ static void _nhdp_add_addresses_cb(struct rfc5444_writer *wr)
|
|||||||
lib_fill_wr_addresses(nhdp_wr_curr_if_entry->if_pid, wr);
|
lib_fill_wr_addresses(nhdp_wr_curr_if_entry->if_pid, wr);
|
||||||
iib_fill_wr_addresses(nhdp_wr_curr_if_entry->if_pid, wr);
|
iib_fill_wr_addresses(nhdp_wr_curr_if_entry->if_pid, wr);
|
||||||
nib_fill_wr_addresses(wr);
|
nib_fill_wr_addresses(wr);
|
||||||
nhdp_reset_addresses_tmp_usg();
|
nhdp_reset_addresses_tmp_usg(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -37,11 +37,9 @@ static nib_entry_t *nib_entry_head = NULL;
|
|||||||
static nib_lost_address_entry_t *nib_lost_address_entry_head = NULL;
|
static nib_lost_address_entry_t *nib_lost_address_entry_head = NULL;
|
||||||
|
|
||||||
/* Internal function prototypes */
|
/* Internal function prototypes */
|
||||||
static nib_entry_t *add_nib_entry(nhdp_addr_entry_t *nb_list);
|
static nib_entry_t *add_nib_entry_for_nb_addr_list(void);
|
||||||
static void rem_nib_entry(nib_entry_t *nib_entry, nhdp_addr_entry_t *nb_list,
|
static void rem_nib_entry(nib_entry_t *nib_entry, timex_t *now);
|
||||||
nhdp_addr_entry_t **out_list, timex_t *now);
|
static void clear_nb_addresses(nib_entry_t *nib_entry, timex_t *now);
|
||||||
static void clear_nb_addresses(nib_entry_t *nib_entry, nhdp_addr_entry_t *nb_list,
|
|
||||||
nhdp_addr_entry_t **out_list, timex_t *now);
|
|
||||||
static int add_lost_neighbor_address(nhdp_addr_t *lost_addr, timex_t *now);
|
static int add_lost_neighbor_address(nhdp_addr_t *lost_addr, timex_t *now);
|
||||||
static void rem_ln_entry(nib_lost_address_entry_t *ln_entry);
|
static void rem_ln_entry(nib_lost_address_entry_t *ln_entry);
|
||||||
|
|
||||||
@ -50,68 +48,57 @@ static void rem_ln_entry(nib_lost_address_entry_t *ln_entry);
|
|||||||
* Neighbor Information Base API *
|
* Neighbor Information Base API *
|
||||||
*---------------------------------------------------------------------------*/
|
*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
nib_entry_t *nib_process_hello(nhdp_addr_entry_t *nb_list, nhdp_addr_entry_t **out_list)
|
nib_entry_t *nib_process_hello(void)
|
||||||
{
|
{
|
||||||
nib_entry_t *nb_match = NULL;
|
nib_entry_t *nb_match = NULL;
|
||||||
|
nib_entry_t *nib_elt, *nib_tmp;
|
||||||
timex_t now;
|
timex_t now;
|
||||||
|
uint8_t matches = 0;
|
||||||
|
|
||||||
mutex_lock(&mtx_nib_access);
|
mutex_lock(&mtx_nib_access);
|
||||||
|
|
||||||
if (nb_list) {
|
vtimer_now(&now);
|
||||||
nib_entry_t *nib_elt, *nib_tmp;
|
|
||||||
uint8_t matches = 0;
|
|
||||||
|
|
||||||
vtimer_now(&now);
|
LL_FOREACH_SAFE(nib_entry_head, nib_elt, nib_tmp) {
|
||||||
|
nhdp_addr_entry_t *list_elt;
|
||||||
|
LL_FOREACH(nib_elt->address_list_head, list_elt) {
|
||||||
|
if (NHDP_ADDR_TMP_IN_NB_LIST(list_elt->address)) {
|
||||||
|
/* Matching neighbor tuple */
|
||||||
|
matches++;
|
||||||
|
|
||||||
LL_FOREACH_SAFE(nib_entry_head, nib_elt, nib_tmp) {
|
if (matches > 1) {
|
||||||
nhdp_addr_entry_t *list_elt;
|
/* Multiple matching nb tuples, delete the previous one */
|
||||||
LL_FOREACH(nib_elt->address_list_head, list_elt) {
|
iib_propagate_nb_entry_change(nb_match, nib_elt);
|
||||||
nhdp_addr_entry_t *list_elt2;
|
rem_nib_entry(nb_match, &now);
|
||||||
LL_FOREACH(nb_list, list_elt2) {
|
|
||||||
if (list_elt->address == list_elt2->address) {
|
|
||||||
/* Addresses are equal (same NHDP address db entry) */
|
|
||||||
matches++;
|
|
||||||
|
|
||||||
if (matches > 1) {
|
|
||||||
/* Multiple matching nb tuples, delete the previous one */
|
|
||||||
iib_propagate_nb_entry_change(nb_match, nib_elt);
|
|
||||||
rem_nib_entry(nb_match, nb_list, out_list, &now);
|
|
||||||
}
|
|
||||||
|
|
||||||
nb_match = nib_elt;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nb_match == nib_elt) {
|
nb_match = nib_elt;
|
||||||
/* This nb tuple is already detected as matching */
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Add or update nb tuple */
|
/* Add or update nb tuple */
|
||||||
if (matches > 0) {
|
if (matches > 0) {
|
||||||
/* We found matching nb tuples, reuse the last one */
|
/* We found matching nb tuples, reuse the last one */
|
||||||
clear_nb_addresses(nb_match, nb_list, out_list, &now);
|
clear_nb_addresses(nb_match, &now);
|
||||||
|
|
||||||
if (matches > 1) {
|
if (matches > 1) {
|
||||||
nb_match->symmetric = 0;
|
nb_match->symmetric = 0;
|
||||||
}
|
|
||||||
|
|
||||||
nb_match->address_list_head = nhdp_generate_new_addr_list(nb_list);
|
|
||||||
|
|
||||||
if (!nb_match->address_list_head) {
|
|
||||||
/* Insufficient memory */
|
|
||||||
LL_DELETE(nib_entry_head, nb_match);
|
|
||||||
free(nb_match);
|
|
||||||
nb_match = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
nb_match = add_nib_entry(nb_list);
|
nb_match->address_list_head = nhdp_generate_addr_list_from_tmp(NHDP_ADDR_TMP_NB_LIST);
|
||||||
|
|
||||||
|
if (!nb_match->address_list_head) {
|
||||||
|
/* Insufficient memory */
|
||||||
|
LL_DELETE(nib_entry_head, nb_match);
|
||||||
|
free(nb_match);
|
||||||
|
nb_match = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
nb_match = add_nib_entry_for_nb_addr_list();
|
||||||
|
}
|
||||||
|
|
||||||
mutex_unlock(&mtx_nib_access);
|
mutex_unlock(&mtx_nib_access);
|
||||||
return nb_match;
|
return nb_match;
|
||||||
@ -205,9 +192,9 @@ void nib_reset_nb_entry_sym(nib_entry_t *nib_entry, timex_t *now)
|
|||||||
/*------------------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a Neighbor Tuple with the given address list
|
* Add a Neighbor Tuple for the neighbor address list
|
||||||
*/
|
*/
|
||||||
static nib_entry_t *add_nib_entry(nhdp_addr_entry_t *nb_list)
|
static nib_entry_t *add_nib_entry_for_nb_addr_list(void)
|
||||||
{
|
{
|
||||||
nib_entry_t *new_elem;
|
nib_entry_t *new_elem;
|
||||||
|
|
||||||
@ -218,8 +205,8 @@ static nib_entry_t *add_nib_entry(nhdp_addr_entry_t *nb_list)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy address list to new neighbor tuple */
|
/* Copy neighbor address list to new neighbor tuple */
|
||||||
new_elem->address_list_head = nhdp_generate_new_addr_list(nb_list);
|
new_elem->address_list_head = nhdp_generate_addr_list_from_tmp(NHDP_ADDR_TMP_NB_LIST);
|
||||||
|
|
||||||
if (!new_elem->address_list_head) {
|
if (!new_elem->address_list_head) {
|
||||||
/* Insufficient memory */
|
/* Insufficient memory */
|
||||||
@ -236,10 +223,9 @@ static nib_entry_t *add_nib_entry(nhdp_addr_entry_t *nb_list)
|
|||||||
/**
|
/**
|
||||||
* Remove a given Neighbor Tuple
|
* Remove a given Neighbor Tuple
|
||||||
*/
|
*/
|
||||||
static void rem_nib_entry(nib_entry_t *nib_entry, nhdp_addr_entry_t *nb_list,
|
static void rem_nib_entry(nib_entry_t *nib_entry, timex_t *now)
|
||||||
nhdp_addr_entry_t **out_list, timex_t *now)
|
|
||||||
{
|
{
|
||||||
clear_nb_addresses(nib_entry, nb_list, out_list, now);
|
clear_nb_addresses(nib_entry, now);
|
||||||
LL_DELETE(nib_entry_head, nib_entry);
|
LL_DELETE(nib_entry_head, nib_entry);
|
||||||
free(nib_entry);
|
free(nib_entry);
|
||||||
}
|
}
|
||||||
@ -248,34 +234,27 @@ static void rem_nib_entry(nib_entry_t *nib_entry, nhdp_addr_entry_t *nb_list,
|
|||||||
* Clear address list of a Neighbor Tuple and add Lost Neighbor Tuple for addresses
|
* Clear address list of a Neighbor Tuple and add Lost Neighbor Tuple for addresses
|
||||||
* no longer used by this neighbor
|
* no longer used by this neighbor
|
||||||
*/
|
*/
|
||||||
static void clear_nb_addresses(nib_entry_t *nib_entry, nhdp_addr_entry_t *nb_list,
|
static void clear_nb_addresses(nib_entry_t *nib_entry, timex_t *now)
|
||||||
nhdp_addr_entry_t **out_list, timex_t *now)
|
|
||||||
{
|
{
|
||||||
nhdp_addr_entry_t *elt, *nib_elt, *nib_tmp;
|
nhdp_addr_entry_t *nib_elt, *nib_tmp;
|
||||||
|
|
||||||
LL_FOREACH_SAFE(nib_entry->address_list_head, nib_elt, nib_tmp) {
|
LL_FOREACH_SAFE(nib_entry->address_list_head, nib_elt, nib_tmp) {
|
||||||
uint8_t found = 0;
|
/* Check whether address is still present in the new neighbor address list */
|
||||||
|
if (!NHDP_ADDR_TMP_IN_NB_LIST(nib_elt->address)) {
|
||||||
LL_FOREACH(nb_list, elt) {
|
|
||||||
/* Check whether address is still present in the new neighbor address list */
|
|
||||||
if (nib_elt->address == elt->address) {
|
|
||||||
/* Simply free the address entry */
|
|
||||||
nhdp_free_addr_entry(nib_elt);
|
|
||||||
found = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
/* Address is not in the newly received address list of the neighbor */
|
/* Address is not in the newly received address list of the neighbor */
|
||||||
/* Add it to the Removed Address List (out_list) */
|
/* Add it to the Removed Address List */
|
||||||
LL_PREPEND(*out_list, nib_elt);
|
nib_elt->address->in_tmp_table |= NHDP_ADDR_TMP_REM_LIST;
|
||||||
|
/* Increment usage counter of address in central NHDP address storage */
|
||||||
|
nib_elt->address->usg_count++;
|
||||||
|
|
||||||
if (nib_entry->symmetric) {
|
if (nib_entry->symmetric) {
|
||||||
/* Additionally create a Lost Neighbor Tuple for symmetric neighbors */
|
/* Additionally create a Lost Neighbor Tuple for symmetric neighbors */
|
||||||
add_lost_neighbor_address(nib_elt->address, now);
|
add_lost_neighbor_address(nib_elt->address, now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Free the address entry */
|
||||||
|
nhdp_free_addr_entry(nib_elt);
|
||||||
}
|
}
|
||||||
nib_entry->address_list_head = NULL;
|
nib_entry->address_list_head = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,13 +53,10 @@ typedef struct nib_lost_address_entry_t {
|
|||||||
* @note
|
* @note
|
||||||
* Must not be called from outside the NHDP reader's message processing.
|
* Must not be called from outside the NHDP reader's message processing.
|
||||||
*
|
*
|
||||||
* @param[in] nb_list Pointer to the Neighbor Address List from the received HELLO
|
|
||||||
* @param[out] out_list Pointer to the created Removed Address List
|
|
||||||
*
|
|
||||||
* @return Pointer to the new Neighbor Tuple
|
* @return Pointer to the new Neighbor Tuple
|
||||||
* @return NULL on error
|
* @return NULL on error
|
||||||
*/
|
*/
|
||||||
nib_entry_t *nib_process_hello(nhdp_addr_entry_t *nb_list, nhdp_addr_entry_t **out_list);
|
nib_entry_t *nib_process_hello(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add addresses to the currently constructed HELLO message
|
* @brief Add addresses to the currently constructed HELLO message
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user