-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gnrc_ipv6_ext: remove unnecessary pkt write-protection
As `pkt` isn't pre-parsed the write-protection of *the whole* packet (except the netif-header) comes for free, when this was done in the receive routine of IPv6.
- Loading branch information
Showing
1 changed file
with
9 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/* | ||
* Copyright (C) 2015 Martine Lenders <[email protected]> | ||
* Copyright (C) 2015 Cenk Gündoğan <[email protected]> | ||
* Copyright (C) 2018 Freie Universität Berlin | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
|
@@ -10,6 +11,8 @@ | |
* @{ | ||
* | ||
* @file | ||
* @author Cenk Gündoğan <[email protected]> | ||
* @author Martine Lenders <[email protected]> | ||
*/ | ||
|
||
#include <errno.h> | ||
|
@@ -63,38 +66,17 @@ static void _forward_pkt(gnrc_pktsnip_t *pkt, ipv6_hdr_t *hdr) | |
static int _handle_rh(gnrc_pktsnip_t *pkt) | ||
{ | ||
gnrc_pktsnip_t *ipv6; | ||
gnrc_pktsnip_t *current = pkt; | ||
ipv6_ext_t *ext = (ipv6_ext_t *) current->data; | ||
size_t current_offset; | ||
ipv6_ext_t *ext = (ipv6_ext_t *)pkt->data; | ||
ipv6_hdr_t *hdr; | ||
int res; | ||
|
||
/* check seg_left early to avoid duplicating the packet */ | ||
/* check seg_left early to to exit quickly */ | ||
if (((ipv6_ext_rh_t *)ext)->seg_left == 0) { | ||
return GNRC_IPV6_EXT_RH_AT_DST; | ||
} | ||
|
||
/* We cannot use `gnrc_pktbuf_start_write` since it duplicates only | ||
the head. `ipv6_ext_rh_process` modifies the IPv6 header as well as | ||
the extension header */ | ||
|
||
current_offset = gnrc_pkt_len_upto(current->next, GNRC_NETTYPE_IPV6); | ||
|
||
if (pkt->users != 1) { | ||
if ((ipv6 = gnrc_pktbuf_duplicate_upto(pkt, GNRC_NETTYPE_IPV6)) == NULL) { | ||
DEBUG("ipv6: could not get a copy of pkt\n"); | ||
gnrc_pktbuf_release(pkt); | ||
return GNRC_IPV6_EXT_RH_ERROR; | ||
} | ||
pkt = ipv6; | ||
hdr = ipv6->data; | ||
ext = (ipv6_ext_t *)(((uint8_t *)ipv6->data) + current_offset); | ||
} | ||
else { | ||
ipv6 = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_IPV6); | ||
hdr = ipv6->data; | ||
} | ||
|
||
ipv6 = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_IPV6); | ||
assert(ipv6 != NULL); | ||
hdr = ipv6->data; | ||
switch ((res = gnrc_ipv6_ext_rh_process(hdr, (ipv6_ext_rh_t *)ext))) { | ||
case GNRC_IPV6_EXT_RH_ERROR: | ||
/* TODO: send ICMPv6 error codes */ | ||
|