Merge pull request #10681 from miri64/gnrc_sixlowpan_frag/cleanup/unroll-recursion

gnrc_sixlowpan_frag: unroll recursion
This commit is contained in:
Cenk Gündoğan 2019-01-08 09:46:15 +01:00 committed by GitHub
commit f6f6501109
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -64,9 +64,27 @@ static bool _rbuf_update_ints(rbuf_t *entry, uint16_t offset, size_t frag_size);
static rbuf_t *_rbuf_get(const void *src, size_t src_len, static rbuf_t *_rbuf_get(const void *src, size_t src_len,
const void *dst, size_t dst_len, const void *dst, size_t dst_len,
size_t size, uint16_t tag, unsigned page); size_t size, uint16_t tag, unsigned page);
/* internal add to repeat add when fragments overlapped */
static int _rbuf_add(gnrc_netif_hdr_t *netif_hdr, gnrc_pktsnip_t *pkt,
size_t offset, unsigned page);
/* status codes for _rbuf_add() */
enum {
RBUF_ADD_SUCCESS,
RBUF_ADD_ERROR,
RBUF_ADD_REPEAT,
};
void rbuf_add(gnrc_netif_hdr_t *netif_hdr, gnrc_pktsnip_t *pkt, void rbuf_add(gnrc_netif_hdr_t *netif_hdr, gnrc_pktsnip_t *pkt,
size_t offset, unsigned page) size_t offset, unsigned page)
{
if (_rbuf_add(netif_hdr, pkt, offset, page) == RBUF_ADD_REPEAT) {
_rbuf_add(netif_hdr, pkt, offset, page);
}
}
static int _rbuf_add(gnrc_netif_hdr_t *netif_hdr, gnrc_pktsnip_t *pkt,
size_t offset, unsigned page)
{ {
rbuf_t *entry; rbuf_t *entry;
sixlowpan_frag_t *frag = pkt->data; sixlowpan_frag_t *frag = pkt->data;
@ -83,7 +101,7 @@ void rbuf_add(gnrc_netif_hdr_t *netif_hdr, gnrc_pktsnip_t *pkt,
if (entry == NULL) { if (entry == NULL) {
DEBUG("6lo rbuf: reassembly buffer full.\n"); DEBUG("6lo rbuf: reassembly buffer full.\n");
gnrc_pktbuf_release(pkt); gnrc_pktbuf_release(pkt);
return; return RBUF_ADD_ERROR;
} }
ptr = entry->ints; ptr = entry->ints;
@ -104,7 +122,7 @@ void rbuf_add(gnrc_netif_hdr_t *netif_hdr, gnrc_pktsnip_t *pkt,
DEBUG("6lo rfrag: fragment too big for resulting datagram, discarding datagram\n"); DEBUG("6lo rfrag: fragment too big for resulting datagram, discarding datagram\n");
gnrc_pktbuf_release(entry->super.pkt); gnrc_pktbuf_release(entry->super.pkt);
rbuf_rm(entry); rbuf_rm(entry);
return; return RBUF_ADD_ERROR;
} }
/* If the fragment overlaps another fragment and differs in either the size /* If the fragment overlaps another fragment and differs in either the size
@ -119,9 +137,7 @@ void rbuf_add(gnrc_netif_hdr_t *netif_hdr, gnrc_pktsnip_t *pkt,
/* "A fresh reassembly may be commenced with the most recently /* "A fresh reassembly may be commenced with the most recently
* received link fragment" * received link fragment"
* https://tools.ietf.org/html/rfc4944#section-5.3 */ * https://tools.ietf.org/html/rfc4944#section-5.3 */
rbuf_add(netif_hdr, pkt, offset, page); return RBUF_ADD_REPEAT;
return;
} }
ptr = ptr->next; ptr = ptr->next;
@ -139,10 +155,10 @@ void rbuf_add(gnrc_netif_hdr_t *netif_hdr, gnrc_pktsnip_t *pkt,
gnrc_pktbuf_release(entry->super.pkt); gnrc_pktbuf_release(entry->super.pkt);
gnrc_pktbuf_release(pkt); gnrc_pktbuf_release(pkt);
rbuf_rm(entry); rbuf_rm(entry);
return; return RBUF_ADD_ERROR;
} }
gnrc_sixlowpan_iphc_recv(pkt, &entry->super, 0); gnrc_sixlowpan_iphc_recv(pkt, &entry->super, 0);
return; return RBUF_ADD_SUCCESS;
} }
else else
#endif #endif
@ -155,6 +171,7 @@ void rbuf_add(gnrc_netif_hdr_t *netif_hdr, gnrc_pktsnip_t *pkt,
} }
gnrc_sixlowpan_frag_rbuf_dispatch_when_complete(&entry->super, netif_hdr); gnrc_sixlowpan_frag_rbuf_dispatch_when_complete(&entry->super, netif_hdr);
gnrc_pktbuf_release(pkt); gnrc_pktbuf_release(pkt);
return RBUF_ADD_SUCCESS;
} }
static inline bool _rbuf_int_overlap_partially(rbuf_int_t *i, uint16_t start, uint16_t end) static inline bool _rbuf_int_overlap_partially(rbuf_int_t *i, uint16_t start, uint16_t end)