1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #9482 from miri64/gnrc_sixlowpan_frag/enh/pages

gnrc_sixlowpan_frag: add page context to reassembly buffer
This commit is contained in:
Cenk Gündoğan 2018-07-24 18:16:39 +02:00 committed by GitHub
commit 0dc02d9a97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 15 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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