diff --git a/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c b/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c index daa2beb61d..832d59acc2 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c +++ b/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c @@ -240,7 +240,7 @@ static bool _rbuf_update_ints(rbuf_t *entry, uint16_t offset, size_t frag_size) static void _rbuf_gc(void) { rbuf_t *oldest = NULL; - uint32_t now_sec = xtimer_now() / SEC_IN_USEC; + uint32_t now_usec = xtimer_now(); unsigned int i; for (i = 0; i < RBUF_SIZE; i++) { @@ -248,7 +248,7 @@ static void _rbuf_gc(void) return; } else if ((rbuf[i].pkt != NULL) && - ((now_sec - rbuf[i].arrival) > RBUF_TIMEOUT)) { + ((now_usec - rbuf[i].arrival) > RBUF_TIMEOUT)) { DEBUG("6lo rfrag: entry (%s, ", gnrc_netif_addr_to_str(l2addr_str, sizeof(l2addr_str), rbuf[i].src, rbuf[i].src_len)); DEBUG("%s, %u, %u) timed out\n", @@ -259,7 +259,7 @@ static void _rbuf_gc(void) gnrc_pktbuf_release(rbuf[i].pkt); _rbuf_rem(&(rbuf[i])); } - else if ((oldest == NULL) || (rbuf[i].arrival < oldest->arrival)) { + else if ((oldest == NULL) || ((oldest->arrival - rbuf[i].arrival) < (UINT32_MAX / 2))) { oldest = &(rbuf[i]); } } @@ -276,7 +276,7 @@ static rbuf_t *_rbuf_get(const void *src, size_t src_len, size_t size, uint16_t tag) { rbuf_t *res = NULL; - uint32_t now_sec = xtimer_now() / SEC_IN_USEC; + uint32_t now_usec = xtimer_now(); for (unsigned int i = 0; i < RBUF_SIZE; i++) { /* check first if entry already available */ @@ -292,7 +292,7 @@ static rbuf_t *_rbuf_get(const void *src, size_t src_len, gnrc_netif_addr_to_str(l2addr_str, sizeof(l2addr_str), rbuf[i].dst, rbuf[i].dst_len), (unsigned)rbuf[i].pkt->size, rbuf[i].tag); - rbuf[i].arrival = now_sec; + rbuf[i].arrival = now_usec; return &(rbuf[i]); } @@ -311,7 +311,7 @@ static rbuf_t *_rbuf_get(const void *src, size_t src_len, *((uint64_t *)res->pkt->data) = 0; /* clean first few bytes for later * look-ups */ - res->arrival = now_sec; + res->arrival = now_usec; memcpy(res->src, src, src_len); memcpy(res->dst, dst, dst_len); res->src_len = src_len; diff --git a/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.h b/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.h index d65da43960..1b69764eb1 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.h +++ b/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.h @@ -30,9 +30,9 @@ extern "C" { #endif -#define RBUF_L2ADDR_MAX_LEN (8U) /**< maximum length for link-layer addresses */ -#define RBUF_SIZE (4U) /**< size of the reassembly buffer */ -#define RBUF_TIMEOUT (3U) /**< timeout for reassembly in seconds */ +#define RBUF_L2ADDR_MAX_LEN (8U) /**< maximum length for link-layer addresses */ +#define RBUF_SIZE (4U) /**< size of the reassembly buffer */ +#define RBUF_TIMEOUT (3U * SEC_IN_USEC) /**< timeout for reassembly in microseconds */ /** * @brief Fragment intervals to identify limits of fragments. @@ -73,8 +73,8 @@ typedef struct rbuf_int { typedef struct { rbuf_int_t *ints; /**< intervals of the fragment */ gnrc_pktsnip_t *pkt; /**< the reassembled packet in packet buffer */ - uint32_t arrival; /**< time in seconds of arrival of last - * received fragment */ + uint32_t arrival; /**< time in microseconds of arrival of + * last received fragment */ uint8_t src[RBUF_L2ADDR_MAX_LEN]; /**< source address */ uint8_t dst[RBUF_L2ADDR_MAX_LEN]; /**< destination address */ uint8_t src_len; /**< length of source address */