Skip to content

Commit f671a87

Browse files
committed
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.
1 parent 02a7bc2 commit f671a87

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

sys/net/gnrc/network_layer/ipv6/ext/gnrc_ipv6_ext.c

+9-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
* Copyright (C) 2015 Martine Lenders <[email protected]>
2+
* Copyright (C) 2015 Cenk Gündoğan <[email protected]>
3+
* Copyright (C) 2018 Freie Universität Berlin
34
*
45
* This file is subject to the terms and conditions of the GNU Lesser
56
* General Public License v2.1. See the file LICENSE in the top level
@@ -10,6 +11,8 @@
1011
* @{
1112
*
1213
* @file
14+
* @author Cenk Gündoğan <[email protected]>
15+
* @author Martine Lenders <[email protected]>
1316
*/
1417

1518
#include <errno.h>
@@ -63,38 +66,17 @@ static void _forward_pkt(gnrc_pktsnip_t *pkt, ipv6_hdr_t *hdr)
6366
static int _handle_rh(gnrc_pktsnip_t *pkt)
6467
{
6568
gnrc_pktsnip_t *ipv6;
66-
gnrc_pktsnip_t *current = pkt;
67-
ipv6_ext_t *ext = (ipv6_ext_t *) current->data;
68-
size_t current_offset;
69+
ipv6_ext_t *ext = (ipv6_ext_t *)pkt->data;
6970
ipv6_hdr_t *hdr;
7071
int res;
7172

72-
/* check seg_left early to avoid duplicating the packet */
73+
/* check seg_left early to to exit quickly */
7374
if (((ipv6_ext_rh_t *)ext)->seg_left == 0) {
7475
return GNRC_IPV6_EXT_RH_AT_DST;
7576
}
76-
77-
/* We cannot use `gnrc_pktbuf_start_write` since it duplicates only
78-
the head. `ipv6_ext_rh_process` modifies the IPv6 header as well as
79-
the extension header */
80-
81-
current_offset = gnrc_pkt_len_upto(current->next, GNRC_NETTYPE_IPV6);
82-
83-
if (pkt->users != 1) {
84-
if ((ipv6 = gnrc_pktbuf_duplicate_upto(pkt, GNRC_NETTYPE_IPV6)) == NULL) {
85-
DEBUG("ipv6: could not get a copy of pkt\n");
86-
gnrc_pktbuf_release(pkt);
87-
return GNRC_IPV6_EXT_RH_ERROR;
88-
}
89-
pkt = ipv6;
90-
hdr = ipv6->data;
91-
ext = (ipv6_ext_t *)(((uint8_t *)ipv6->data) + current_offset);
92-
}
93-
else {
94-
ipv6 = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_IPV6);
95-
hdr = ipv6->data;
96-
}
97-
77+
ipv6 = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_IPV6);
78+
assert(ipv6 != NULL);
79+
hdr = ipv6->data;
9880
switch ((res = gnrc_ipv6_ext_rh_process(hdr, (ipv6_ext_rh_t *)ext))) {
9981
case GNRC_IPV6_EXT_RH_ERROR:
10082
/* TODO: send ICMPv6 error codes */

0 commit comments

Comments
 (0)