1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/net/gnrc
Martine S. Lenders ea449f3f9e gnrc_ipv6: remove obsolete and harmful reception code
When reworking the reception of IPv6 packets I reset a previously set
`ipv6` snip as follows  when the IPv6 extension handler returns a
packet (see first hunk of this commit):

```C
ipv6 = pkt->next->next
```

With `gnrc_ipv6_ext` this makes *somewhat* sense, `pkt->next` was
previously equal to `ipv6` and after the function call `pkt->next`
is the marked extension header, while `pkt->next->next` is the IPv6
header. However, since `ipv6` is already write-protected i.e.
`ipv6->users == 1` (see ll. 665-675), any additional call of
`gnrc_pktbuf_start_write()` [won't][start-write-doc] duplicate the
packet. In fact, the only `gnrc_pktbuf_start_write()` in
`gnrc_ipv6_ext` is used to send the *result* to the subscribers of that
extension header type, leaving the original packet unchanged for the
caller. As such `ipv6` remains the pointer to the IPv6 header whether
we set it in the line above or not. So we actually don't need that
line.

However, the extension header handling also returns a packet when
`gnrc_ipv6_ext` is not compiled in. In that case it is just a dummy
define that returns the packet you give provide it which means that
this still holds true: `pkt->next == ipv6`.
So setting `ipv6` in this case is actually harmful, as `ipv6` now
points to the NETIF header [following the IPv6 header][pkt-structure]
in the packet and this causes the `user` counter of that NETIF header
`hdr` to be decremented if `hdr->users > 1` in the write-protection I
removed in hunk 2 of this commit:

```C
/* pkt might not be writable yet, if header was given above */
ipv6 = gnrc_pktbuf_start_write(ipv6);
if (ipv6 == NULL) {
    DEBUG("ipv6: unable to get write access to packet: dropping it\n");
    gnrc_pktbuf_release(pkt);
    return;
}
```

But as we already established, `ipv6->users` is already 1, so we don't
actually need the write protection here either.

Since the packet stays unchanged after the `ipv6` snip, we also don't
need to re-search for `netif_hdr` after the other two lines are
removed.

[start-write-doc]: https://doc.riot-os.org/group__net__gnrc__pktbuf.html#ga640418467294ae3d408c109ab27bd617
[pkt-structure]: https://doc.riot-os.org/group__net__gnrc__pkt.html#ga278e783e56a5ee6f1bd7b81077ed82a7
2019-07-03 14:44:03 +02:00
..
application_layer sys/net: NETOPT_MAX_{PACKET_SIZE -> PDU_SIZE} 2019-02-18 20:15:08 +01:00
link_layer gnrc_mac: rename directory in line with other modules 2019-05-09 14:46:35 +02:00
netapi gnrc_netapi: use static inline for high-level wrapper functions 2018-12-11 16:15:51 +01:00
netif gnrc_netif_ieee802154: check if mhr_len is lesser than nread 2019-04-15 16:36:31 +02:00
netreg gnrc_netreg: use thread_has_msg_queue() for msg queue check 2018-12-19 15:39:50 +01:00
nettest gnrc: remove legacy network interface structures 2017-11-17 09:20:29 +01:00
network_layer gnrc_ipv6: remove obsolete and harmful reception code 2019-07-03 14:44:03 +02:00
pkt gnrc: cleanup and corrections in gnrc_pkt 2017-04-22 20:56:54 +02:00
pktbuf net/gnrc_pktbuf: rm deprecated _pktbuf_get_iovec() 2019-03-15 10:21:22 +01:00
pktbuf_malloc gnrc_pktbuf_malloc: allow write-protect of size 0 snips 2019-03-12 14:35:58 +01:00
pktbuf_static gnrc_pktbuf_static: allow write-protect of size 0 snips 2019-03-12 14:34:49 +01:00
pktdump gnrc_pktdump: add GNRC_NETTYPE_IPV6_EXT output 2018-12-14 01:37:53 +01:00
priority_pktqueue gnrc_priority_queue: updated coding style. 2017-06-22 11:36:55 +02:00
routing/rpl gnrc_rpl_dodag: remove new_best assignment at initialization 2019-06-20 16:18:23 +02:00
sock gnrc_sock_[udp|ip]: store return value before release 2018-11-12 14:58:26 +01:00
transport_layer gnrc_tcp: Fix packet-flood while probing 2019-03-26 21:05:53 +01:00
Makefile gnrc_mac: rename directory in line with other modules 2019-05-09 14:46:35 +02:00