From f671a87fe2c539c3aecd595ae03fa4f6f209d042 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Wed, 24 Oct 2018 00:17:38 +0200 Subject: [PATCH] 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. --- .../network_layer/ipv6/ext/gnrc_ipv6_ext.c | 36 +++++-------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/sys/net/gnrc/network_layer/ipv6/ext/gnrc_ipv6_ext.c b/sys/net/gnrc/network_layer/ipv6/ext/gnrc_ipv6_ext.c index a4a1e2035a..53accf24a7 100644 --- a/sys/net/gnrc/network_layer/ipv6/ext/gnrc_ipv6_ext.c +++ b/sys/net/gnrc/network_layer/ipv6/ext/gnrc_ipv6_ext.c @@ -1,5 +1,6 @@ /* - * Copyright (C) 2015 Martine Lenders + * Copyright (C) 2015 Cenk Gündoğan + * 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 + * @author Martine Lenders */ #include @@ -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 */