From 8721d0b0a28e4b4d7797448710ef866988faf09c Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Tue, 3 Jul 2018 14:01:06 +0200 Subject: [PATCH] gnrc_sixlowpan_frag: add page context to reassembly buffer While refactoring IPHC I noticed that the page actually can already be used for fragmentation: Given @cgundogan's work on [ICN LoWPAN] we can already assume, that the page context may (among other thing) determine the type of the reassembled packet. This PR provides the basis for that. [ICN LoWPAN]: https://tools.ietf.org/html/draft-gundogan-icnrg-ccnlowpan-01 --- .../sixlowpan/frag/gnrc_sixlowpan_frag.c | 6 +--- .../gnrc/network_layer/sixlowpan/frag/rbuf.c | 28 +++++++++++++------ .../gnrc/network_layer/sixlowpan/frag/rbuf.h | 4 +-- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/sys/net/gnrc/network_layer/sixlowpan/frag/gnrc_sixlowpan_frag.c b/sys/net/gnrc/network_layer/sixlowpan/frag/gnrc_sixlowpan_frag.c index 03ac3db6f4..0b2e96e36f 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/frag/gnrc_sixlowpan_frag.c +++ b/sys/net/gnrc/network_layer/sixlowpan/frag/gnrc_sixlowpan_frag.c @@ -294,18 +294,14 @@ void gnrc_sixlowpan_frag_recv(gnrc_pktsnip_t *pkt, void *ctx, unsigned page) gnrc_netif_hdr_t *hdr = pkt->next->data; sixlowpan_frag_t *frag = pkt->data; uint16_t offset = 0; - size_t frag_size; (void)ctx; - (void)page; switch (frag->disp_size.u8[0] & SIXLOWPAN_FRAG_DISP_MASK) { case SIXLOWPAN_FRAG_1_DISP: - frag_size = (pkt->size - sizeof(sixlowpan_frag_t)); break; case SIXLOWPAN_FRAG_N_DISP: offset = (((sixlowpan_frag_n_t *)frag)->offset * 8); - frag_size = (pkt->size - sizeof(sixlowpan_frag_n_t)); break; default: @@ -315,7 +311,7 @@ void gnrc_sixlowpan_frag_recv(gnrc_pktsnip_t *pkt, void *ctx, unsigned page) return; } - rbuf_add(hdr, pkt, frag_size, offset); + rbuf_add(hdr, pkt, offset, page); gnrc_pktbuf_release(pkt); } diff --git a/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c b/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c index 451edd4be0..d8f282935c 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c +++ b/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.c @@ -65,25 +65,25 @@ static bool _rbuf_update_ints(rbuf_t *entry, uint16_t offset, size_t frag_size); /* gets an entry identified by its tupel */ static rbuf_t *_rbuf_get(const void *src, size_t src_len, const void *dst, size_t dst_len, - size_t size, uint16_t tag); + size_t size, uint16_t tag, unsigned page); void rbuf_add(gnrc_netif_hdr_t *netif_hdr, gnrc_pktsnip_t *pkt, - size_t frag_size, size_t offset) + size_t offset, unsigned page) { rbuf_t *entry; /* cppcheck-suppress variableScope * (reason: cppcheck is clearly wrong here) */ unsigned int data_offset = 0; - size_t original_size = frag_size; sixlowpan_frag_t *frag = pkt->data; rbuf_int_t *ptr; uint8_t *data = ((uint8_t *)pkt->data) + sizeof(sixlowpan_frag_t); + size_t frag_size; rbuf_gc(); entry = _rbuf_get(gnrc_netif_hdr_get_src_addr(netif_hdr), netif_hdr->src_l2addr_len, gnrc_netif_hdr_get_dst_addr(netif_hdr), netif_hdr->dst_l2addr_len, byteorder_ntohs(frag->disp_size) & SIXLOWPAN_FRAG_SIZE_MASK, - byteorder_ntohs(frag->tag)); + byteorder_ntohs(frag->tag), page); if (entry == NULL) { DEBUG("6lo rbuf: reassembly buffer full.\n"); @@ -94,8 +94,8 @@ void rbuf_add(gnrc_netif_hdr_t *netif_hdr, gnrc_pktsnip_t *pkt, /* dispatches in the first fragment are ignored */ if (offset == 0) { + frag_size = pkt->size - sizeof(sixlowpan_frag_t); if (data[0] == SIXLOWPAN_UNCOMP) { - data++; /* skip 6LoWPAN dispatch */ frag_size--; } #ifdef MODULE_GNRC_SIXLOWPAN_IPHC @@ -121,6 +121,7 @@ void rbuf_add(gnrc_netif_hdr_t *netif_hdr, gnrc_pktsnip_t *pkt, #endif } else { + frag_size = pkt->size - sizeof(sixlowpan_frag_n_t); data++; /* FRAGN header is one byte longer (offset) */ } @@ -143,7 +144,7 @@ void rbuf_add(gnrc_netif_hdr_t *netif_hdr, gnrc_pktsnip_t *pkt, /* "A fresh reassembly may be commenced with the most recently * received link fragment" * https://tools.ietf.org/html/rfc4944#section-5.3 */ - rbuf_add(netif_hdr, pkt, original_size, offset); + rbuf_add(netif_hdr, pkt, offset, page); return; } @@ -279,7 +280,7 @@ static inline void _set_rbuf_timeout(void) static rbuf_t *_rbuf_get(const void *src, size_t src_len, const void *dst, size_t dst_len, - size_t size, uint16_t tag) + size_t size, uint16_t tag, unsigned page) { rbuf_t *res = NULL, *oldest = NULL; uint32_t now_usec = xtimer_now_usec(); @@ -330,7 +331,18 @@ static rbuf_t *_rbuf_get(const void *src, size_t src_len, /* now we have an empty spot */ - res->super.pkt = gnrc_pktbuf_add(NULL, NULL, size, GNRC_NETTYPE_IPV6); + gnrc_nettype_t reass_type; + switch (page) { + /* use switch(page) to be extendable */ +#ifdef MODULE_GNRC_IPV6 + case 0U: + reass_type = GNRC_NETTYPE_IPV6; + break; +#endif + default: + reass_type = GNRC_NETTYPE_UNDEF; + } + res->super.pkt = gnrc_pktbuf_add(NULL, NULL, size, reass_type); if (res->super.pkt == NULL) { DEBUG("6lo rfrag: can not allocate reassembly buffer space.\n"); return NULL; diff --git a/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.h b/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.h index 810ad2fcdb..a07ce71ba4 100644 --- a/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.h +++ b/sys/net/gnrc/network_layer/sixlowpan/frag/rbuf.h @@ -76,13 +76,13 @@ typedef struct { * gnrc_netif_hdr_t::if_pid and its source and * destination address set. * @param[in] frag The fragment to add. - * @param[in] frag_size The fragment's size. * @param[in] offset The fragment's offset. + * @param[in] page Current 6Lo dispatch parsing page. * * @internal */ void rbuf_add(gnrc_netif_hdr_t *netif_hdr, gnrc_pktsnip_t *frag, - size_t frag_size, size_t offset); + size_t offset, unsigned page); /** * @brief Checks timeouts and removes entries if necessary