Skip to content

Commit

Permalink
gnrc_pktbuf: remove gnrc_pktbuf_duplicate_upto
Browse files Browse the repository at this point in the history
The removal of this function was already announced for the 2019.04
release. So it is safe to remove it.
  • Loading branch information
miri64 committed Jul 3, 2019
1 parent e8650f5 commit b83430a
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 156 deletions.
55 changes: 0 additions & 55 deletions sys/include/net/gnrc/pktbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,61 +229,6 @@ gnrc_pktsnip_t *gnrc_pktbuf_replace_snip(gnrc_pktsnip_t *pkt, gnrc_pktsnip_t *ol
*/
gnrc_pktsnip_t *gnrc_pktbuf_reverse_snips(gnrc_pktsnip_t *pkt);

/**
* @brief Duplicates pktsnip chain upto (including) a snip with the given type
* as a continuous snip.
*
* Example:
* Input:
* buffer
* +---------------------------+ +------+
* | size = 8 | data +-------->| |
* | type = NETTYPE_IPV6_EXT |------------+ +------+
* +---------------------------+ . .
* | next . .
* v . .
* +---------------------------+ +------+
* | size = 40 | data +----------->| |
* | type = NETTYPE_IPV6 |---------+ +------+
* +---------------------------+ . .
* | next . .
* v
* +---------------------------+ +------+
* | size = 14 | data +-------------->| |
* | type = NETTYPE_NETIF |------+ +------+
* +---------------------------+ . .
*
*
* Output:
* buffer
* +---------------------------+ +------+
* | size = 48 | data +-------->| |
* | type = NETTYPE_IPV6 |------------+ | |
* +---------------------------+ | |
* | +------+
* | . .
* | next . .
* v
* +---------------------------+ +------+
* | size = 14 | data +-------------->| |
* | type = NETTYPE_NETIF |------+ +------+
* +---------------------------+ . .
*
* The original snip is keeped as is except `users` decremented.
*
* @deprecated This function breaks the abstraction of `gnrc_pktbuf` and its
* only user within the RIOT code base `gnrc_ipv6_ext` was reworked
* so it isn't needed anymore.
* It will be removed after the 2019.04 release.
*
* @param[in,out] pkt The snip to duplicate.
* @param[in] type The type of snip to stop duplication.
*
* @return The duplicated snip, if succeeded.
* @return NULL, if no space is left in the packet buffer.
*/
gnrc_pktsnip_t *gnrc_pktbuf_duplicate_upto(gnrc_pktsnip_t *pkt, gnrc_nettype_t type);

/**
* @brief Merge pktsnip chain to single pktsnip.
*
Expand Down
50 changes: 0 additions & 50 deletions sys/net/gnrc/pktbuf_malloc/gnrc_pktbuf_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,54 +295,4 @@ static gnrc_pktsnip_t *_create_snip(gnrc_pktsnip_t *next, const void *data, size
return pkt;
}

gnrc_pktsnip_t *gnrc_pktbuf_duplicate_upto(gnrc_pktsnip_t *pkt, gnrc_nettype_t type)
{
mutex_lock(&_mutex);

bool is_shared = pkt->users > 1;
size_t size = gnrc_pkt_len_upto(pkt, type);

DEBUG("ipv6_ext: duplicating %d octets\n", (int) size);

gnrc_pktsnip_t *tmp;
gnrc_pktsnip_t *target = gnrc_pktsnip_search_type(pkt, type);
gnrc_pktsnip_t *next = (target == NULL) ? NULL : target->next;
gnrc_pktsnip_t *new = _create_snip(next, NULL, size, type);

if (new == NULL) {
mutex_unlock(&_mutex);

return NULL;
}

/* copy payloads */
for (tmp = pkt; tmp != NULL; tmp = tmp->next) {
uint8_t *dest = ((uint8_t *)new->data) + (size - tmp->size);

memcpy(dest, tmp->data, tmp->size);

size -= tmp->size;

if (tmp->type == type) {
break;
}
}

/* decrements reference counters */

if (target != NULL) {
target->next = NULL;
}

_release_error_locked(pkt, GNRC_NETERR_SUCCESS);

if (is_shared && (target != NULL)) {
target->next = next;
}

mutex_unlock(&_mutex);

return new;
}

/** @} */
51 changes: 0 additions & 51 deletions sys/net/gnrc/pktbuf_static/gnrc_pktbuf_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,55 +485,4 @@ static void _pktbuf_free(void *data, size_t size)
}
}


gnrc_pktsnip_t *gnrc_pktbuf_duplicate_upto(gnrc_pktsnip_t *pkt, gnrc_nettype_t type)
{
mutex_lock(&_mutex);

bool is_shared = pkt->users > 1;
size_t size = gnrc_pkt_len_upto(pkt, type);

DEBUG("ipv6_ext: duplicating %d octets\n", (int) size);

gnrc_pktsnip_t *tmp;
gnrc_pktsnip_t *target = gnrc_pktsnip_search_type(pkt, type);
gnrc_pktsnip_t *next = (target == NULL) ? NULL : target->next;
gnrc_pktsnip_t *new = _create_snip(next, NULL, size, type);

if (new == NULL) {
mutex_unlock(&_mutex);

return NULL;
}

/* copy payloads */
for (tmp = pkt; tmp != NULL; tmp = tmp->next) {
uint8_t *dest = ((uint8_t *)new->data) + (size - tmp->size);

memcpy(dest, tmp->data, tmp->size);

size -= tmp->size;

if (tmp->type == type) {
break;
}
}

/* decrements reference counters */

if (target != NULL) {
target->next = NULL;
}

_release_error_locked(pkt, GNRC_NETERR_SUCCESS);

if (is_shared && (target != NULL)) {
target->next = next;
}

mutex_unlock(&_mutex);

return new;
}

/** @} */

0 comments on commit b83430a

Please sign in to comment.