From 0580fa5852cee45738d81e2cee958c9c641f808a Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Wed, 24 Oct 2018 18:03:39 +0200 Subject: [PATCH] gnrc_ipv6: dispatch ext. headers to external interested parties This way e.g. a raw socket listening for an extension headers protocol number also get's it. --- sys/include/net/gnrc/ipv6/ext.h | 3 +++ .../network_layer/ipv6/ext/gnrc_ipv6_ext.c | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/sys/include/net/gnrc/ipv6/ext.h b/sys/include/net/gnrc/ipv6/ext.h index 2c61e4e39b..b03d9c7843 100644 --- a/sys/include/net/gnrc/ipv6/ext.h +++ b/sys/include/net/gnrc/ipv6/ext.h @@ -41,6 +41,9 @@ extern "C" { /** * @brief Demultiplex an extension header according to @p nh. * + * This includes dispatching it to interested parties in the + * @ref net_gnrc_netreg. + * * @param[in] pkt A packet with the first snip pointing to the extension * header to process. * @param[in] nh Protocol number of @p pkt. 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 74bd79b569..0130414fb9 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 @@ -19,6 +19,7 @@ #include "utlist.h" #include "net/gnrc/netif.h" +#include "net/gnrc/netreg.h" #include "net/gnrc/pktbuf.h" #include "net/gnrc/icmpv6/error.h" #include "net/gnrc/ipv6.h" @@ -258,6 +259,24 @@ gnrc_pktsnip_t *gnrc_ipv6_ext_demux(gnrc_pktsnip_t *pkt, unsigned nh) gnrc_pktbuf_release(pkt); return NULL; } + if (gnrc_netreg_num(GNRC_NETTYPE_IPV6, nh) > 0) { + gnrc_pktsnip_t *sub_pkt; + + /* enforce duplication so we can dispatch packet to subscriber(s) and + * handle the packet */ + gnrc_pktbuf_hold(pkt, 1); + sub_pkt = gnrc_pktbuf_start_write(pkt); + if (sub_pkt != NULL) { + /* check in case subscriber unregistered in the meantime */ + if (gnrc_netapi_dispatch_receive(GNRC_NETTYPE_IPV6, nh, sub_pkt) == 0) { + gnrc_pktbuf_release(sub_pkt); + }; + } + else { + gnrc_pktbuf_release(pkt); + /* try to keep handling, the sockets aren't *that* important anyway :-P */ + } + } switch (nh) { case PROTNUM_IPV6_EXT_RH: #ifdef MODULE_GNRC_RPL_SRH