Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! sys/net: add netstats_neighbor
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Jul 15, 2020
1 parent 3c1f5bd commit 3087601
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions sys/include/net/netstats/neighbor.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,10 @@ void netstats_nb_half_freshness(netstats_nb_t *stats, timex_t *cur);
* @return ptr to the least fresh record
*/
static inline netstats_nb_t *netstats_nb_comp(const netstats_nb_t *a,
const netstats_nb_t *b)
const netstats_nb_t *b,
uint16_t now)
{
return (netstats_nb_t *)((a->last_updated < b->last_updated) ? a : b);
return (netstats_nb_t *)((now - a->last_updated > now - b->last_updated) ? a : b);
}

#ifdef __cplusplus
Expand Down
5 changes: 4 additions & 1 deletion sys/net/netstats/netstats_neighbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ netstats_nb_t *netstats_nb_get_or_create(netif_t *dev, const uint8_t *l2_addr, u
netstats_nb_t *matching_entry = NULL;
netstats_nb_t *stats = dev->pstats;

timex_t cur;
xtimer_now_timex(&cur);

for (int i = 0; i < NETSTATS_NB_SIZE; i++) {
/* Check if this is the matching entry */
if (l2_addr_equal(stats[i].l2_addr, stats[i].l2_addr_len, l2_addr, len)) {
Expand All @@ -71,7 +74,7 @@ netstats_nb_t *netstats_nb_get_or_create(netif_t *dev, const uint8_t *l2_addr, u
}
/* Check if current entry is older than current oldest entry */
else {
old_entry = netstats_nb_comp(old_entry, &stats[i]);
old_entry = netstats_nb_comp(old_entry, &stats[i], cur.seconds);
}
}
}
Expand Down

0 comments on commit 3087601

Please sign in to comment.