1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

gnrc_ipv6: clean-up unrequired stuff after demux rework

This commit is contained in:
Martine Lenders 2018-10-24 00:26:26 +02:00 committed by Martine Lenders
parent 764ed8c300
commit e6df40dbde

View File

@ -90,11 +90,10 @@ kernel_pid_t gnrc_ipv6_init(void)
return gnrc_ipv6_pid; return gnrc_ipv6_pid;
} }
static void _dispatch_next_header(gnrc_pktsnip_t *current, gnrc_pktsnip_t *pkt, static void _dispatch_next_header(gnrc_pktsnip_t *pkt, unsigned nh,
uint8_t nh, bool interested); bool interested);
static void _demux(gnrc_netif_t *netif, gnrc_pktsnip_t *current, static void _demux(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt, unsigned nh)
gnrc_pktsnip_t *pkt, uint8_t nh)
{ {
bool interested; bool interested;
@ -134,27 +133,18 @@ static void _demux(gnrc_netif_t *netif, gnrc_pktsnip_t *current,
#else /* MODULE_GNRC_ICMPV6 */ #else /* MODULE_GNRC_ICMPV6 */
interested = false; interested = false;
#endif /* MODULE_GNRC_ICMPV6 */ #endif /* MODULE_GNRC_ICMPV6 */
current->type = gnrc_nettype_from_protnum(nh); pkt->type = gnrc_nettype_from_protnum(nh);
_dispatch_next_header(pkt, nh, interested);
_dispatch_next_header(current, pkt, nh, interested);
if (!interested) {
return;
}
switch (nh) { switch (nh) {
#ifdef MODULE_GNRC_ICMPV6 #ifdef MODULE_GNRC_ICMPV6
case PROTNUM_ICMPV6: case PROTNUM_ICMPV6:
DEBUG("ipv6: handle ICMPv6 packet (nh = %u)\n", nh); DEBUG("ipv6: handle ICMPv6 packet (nh = %u)\n", nh);
gnrc_icmpv6_demux(netif, pkt); gnrc_icmpv6_demux(netif, pkt);
return; break;
#endif /* MODULE_GNRC_ICMPV6 */ #endif /* MODULE_GNRC_ICMPV6 */
default: default:
assert(false);
break; break;
} }
assert(false);
} }
ipv6_hdr_t *gnrc_ipv6_get_header(gnrc_pktsnip_t *pkt) ipv6_hdr_t *gnrc_ipv6_get_header(gnrc_pktsnip_t *pkt)
@ -172,36 +162,26 @@ ipv6_hdr_t *gnrc_ipv6_get_header(gnrc_pktsnip_t *pkt)
} }
/* internal functions */ /* internal functions */
static void _dispatch_next_header(gnrc_pktsnip_t *current, gnrc_pktsnip_t *pkt, static void _dispatch_next_header(gnrc_pktsnip_t *pkt, unsigned nh,
uint8_t nh, bool interested) bool interested)
{ {
#ifdef MODULE_GNRC_IPV6_EXT const bool should_release = (gnrc_netreg_num(GNRC_NETTYPE_IPV6, nh) == 0) &&
const bool should_dispatch_current_type = ((current->type != GNRC_NETTYPE_IPV6_EXT) || (!interested);
(current->next->type == GNRC_NETTYPE_IPV6));
#else
const bool should_dispatch_current_type = (current->next->type == GNRC_NETTYPE_IPV6);
#endif
DEBUG("ipv6: forward nh = %u to other threads\n", nh); DEBUG("ipv6: forward nh = %u to other threads\n", nh);
/* dispatch IPv6 extension header only once */ if (!should_release) {
if (should_dispatch_current_type) { gnrc_pktbuf_hold(pkt, 1); /* don't remove from packet buffer in
bool should_release = (!gnrc_netreg_lookup(GNRC_NETTYPE_IPV6, nh)) && * next dispatch */
(!interested); }
if (gnrc_netapi_dispatch_receive(pkt->type,
if (!should_release) { GNRC_NETREG_DEMUX_CTX_ALL,
gnrc_pktbuf_hold(pkt, 1); /* don't remove from packet buffer in pkt) == 0) {
* next dispatch */ gnrc_pktbuf_release(pkt);
} }
if (gnrc_netapi_dispatch_receive(current->type, if (should_release) {
GNRC_NETREG_DEMUX_CTX_ALL, /* we should exit early. pkt was already released above */
pkt) == 0) { return;
gnrc_pktbuf_release(pkt);
}
if (should_release) {
return;
}
} }
if (interested) { if (interested) {
gnrc_pktbuf_hold(pkt, 1); /* don't remove from packet buffer in gnrc_pktbuf_hold(pkt, 1); /* don't remove from packet buffer in
@ -848,7 +828,7 @@ static void _receive(gnrc_pktsnip_t *pkt)
#endif /* MODULE_GNRC_IPV6_ROUTER */ #endif /* MODULE_GNRC_IPV6_ROUTER */
} }
_demux(netif, pkt, pkt, hdr->nh); _demux(netif, pkt, hdr->nh);
} }
/** @} */ /** @} */