|
1 | 1 | /*
|
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 |
3 | 4 | *
|
4 | 5 | * This file is subject to the terms and conditions of the GNU Lesser
|
5 | 6 | * General Public License v2.1. See the file LICENSE in the top level
|
|
10 | 11 | * @{
|
11 | 12 | *
|
12 | 13 | * @file
|
| 14 | + * @author Cenk Gündoğan <[email protected]> |
| 15 | + * @author Martine Lenders <[email protected]> |
13 | 16 | */
|
14 | 17 |
|
15 | 18 | #include <errno.h>
|
@@ -63,38 +66,17 @@ static void _forward_pkt(gnrc_pktsnip_t *pkt, ipv6_hdr_t *hdr)
|
63 | 66 | static int _handle_rh(gnrc_pktsnip_t *pkt)
|
64 | 67 | {
|
65 | 68 | 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; |
69 | 70 | ipv6_hdr_t *hdr;
|
70 | 71 | int res;
|
71 | 72 |
|
72 |
| - /* check seg_left early to avoid duplicating the packet */ |
| 73 | + /* check seg_left early to to exit quickly */ |
73 | 74 | if (((ipv6_ext_rh_t *)ext)->seg_left == 0) {
|
74 | 75 | return GNRC_IPV6_EXT_RH_AT_DST;
|
75 | 76 | }
|
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; |
98 | 80 | switch ((res = gnrc_ipv6_ext_rh_process(hdr, (ipv6_ext_rh_t *)ext))) {
|
99 | 81 | case GNRC_IPV6_EXT_RH_ERROR:
|
100 | 82 | /* TODO: send ICMPv6 error codes */
|
|
0 commit comments