diff --git a/sys/include/net/gnrc/sixlowpan/config.h b/sys/include/net/gnrc/sixlowpan/config.h index 8cfebbcf67..0e5d52ad59 100644 --- a/sys/include/net/gnrc/sixlowpan/config.h +++ b/sys/include/net/gnrc/sixlowpan/config.h @@ -68,6 +68,22 @@ extern "C" { #define GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS (3U * US_PER_SEC) #endif +/** + * @brief Aggressively override reassembly buffer when full + * + * @note Only applicable with + * [gnrc_sixlowpan_frag](@ref net_gnrc_sixlowpan_frag) module + * + * When set to a non-zero value this will cause the reassembly buffer to + * override the oldest entry no matter what. When set to zero only the oldest + * entry that is older than @ref GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS will be + * overwritten (they will still timeout normally if reassembly buffer is not + * full). + */ +#ifndef GNRC_SIXLOWPAN_FRAG_RBUF_AGGRESSIVE_OVERRIDE +#define GNRC_SIXLOWPAN_FRAG_RBUF_AGGRESSIVE_OVERRIDE (1) +#endif + /** * @brief Registration lifetime in minutes for the address registration option * diff --git a/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c b/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c index fc2d16bacc..ea35516dfe 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c +++ b/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c @@ -322,10 +322,17 @@ static rbuf_t *_rbuf_get(const void *src, size_t src_len, /* if oldest is not empty, res must not be NULL (because otherwise * oldest could have been picked as res) */ assert(!rbuf_entry_empty(oldest)); - DEBUG("6lo rfrag: reassembly buffer full, remove oldest entry\n"); - gnrc_pktbuf_release(oldest->super.pkt); - rbuf_rm(oldest); - res = oldest; + if (GNRC_SIXLOWPAN_FRAG_RBUF_AGGRESSIVE_OVERRIDE || + ((now_usec - oldest->arrival) > + GNRC_SIXLOWPAN_FRAG_RBUF_TIMEOUT_MS)) { + DEBUG("6lo rfrag: reassembly buffer full, remove oldest entry\n"); + gnrc_pktbuf_release(oldest->super.pkt); + rbuf_rm(oldest); + res = oldest; + } + else { + return NULL; + } } /* now we have an empty spot */