From dbda759b40bcdda4e02ab363af5cb6716b6675e6 Mon Sep 17 00:00:00 2001 From: Martine Lenders <mail@martine-lenders.eu> Date: Thu, 22 Feb 2018 20:30:03 +0100 Subject: [PATCH] Revert "gnrc/netreg: remove usages of gnrc_netreg_num" This reverts commit c2b403f4ad0fda2e196be248406f2c04d626cf26. --- .../gnrc/application_layer/tftp/gnrc_tftp.c | 2 +- sys/net/gnrc/netapi/gnrc_netapi.c | 76 ++++++++++--------- sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c | 2 +- 3 files changed, 41 insertions(+), 39 deletions(-) diff --git a/sys/net/gnrc/application_layer/tftp/gnrc_tftp.c b/sys/net/gnrc/application_layer/tftp/gnrc_tftp.c index 0c952e73fe..6cf78233db 100644 --- a/sys/net/gnrc/application_layer/tftp/gnrc_tftp.c +++ b/sys/net/gnrc/application_layer/tftp/gnrc_tftp.c @@ -367,7 +367,7 @@ int _tftp_init_ctxt(ipv6_addr_t *addr, const char *file_name, /* generate a random source UDP source port */ do { ctxt->src_port = (random_uint32() & 0xff) + GNRC_TFTP_DEFAULT_SRC_PORT; - } while (gnrc_netreg_lookup(GNRC_NETTYPE_UDP, ctxt->src_port)); + } while (gnrc_netreg_num(GNRC_NETTYPE_UDP, ctxt->src_port)); return TS_FINISHED; } diff --git a/sys/net/gnrc/netapi/gnrc_netapi.c b/sys/net/gnrc/netapi/gnrc_netapi.c index afe5998813..9d7fbee96e 100644 --- a/sys/net/gnrc/netapi/gnrc_netapi.c +++ b/sys/net/gnrc/netapi/gnrc_netapi.c @@ -94,52 +94,54 @@ static inline int _snd_rcv_mbox(mbox_t *mbox, uint16_t type, gnrc_pktsnip_t *pkt int gnrc_netapi_dispatch(gnrc_nettype_t type, uint32_t demux_ctx, uint16_t cmd, gnrc_pktsnip_t *pkt) { - int numof = 0; - gnrc_netreg_entry_t *sendto = gnrc_netreg_lookup(type, demux_ctx); + int numof = gnrc_netreg_num(type, demux_ctx); - while (sendto) { - if (numof != 0) { - gnrc_pktbuf_hold(pkt, 1); - } + if (numof != 0) { + gnrc_netreg_entry_t *sendto = gnrc_netreg_lookup(type, demux_ctx); + + gnrc_pktbuf_hold(pkt, numof - 1); + + while (sendto) { #if defined(MODULE_GNRC_NETAPI_MBOX) || defined(MODULE_GNRC_NETAPI_CALLBACKS) - int release = 0; - switch (sendto->type) { - case GNRC_NETREG_TYPE_DEFAULT: - if (_snd_rcv(sendto->target.pid, cmd, pkt) < 1) { - /* unable to dispatch packet */ - release = 1; - } - break; + int release = 0; + switch (sendto->type) { + case GNRC_NETREG_TYPE_DEFAULT: + if (_snd_rcv(sendto->target.pid, cmd, pkt) < 1) { + /* unable to dispatch packet */ + release = 1; + } + break; #ifdef MODULE_GNRC_NETAPI_MBOX - case GNRC_NETREG_TYPE_MBOX: - if (_snd_rcv_mbox(sendto->target.mbox, cmd, pkt) < 1) { - /* unable to dispatch packet */ - release = 1; - } - break; + case GNRC_NETREG_TYPE_MBOX: + if (_snd_rcv_mbox(sendto->target.mbox, cmd, pkt) < 1) { + /* unable to dispatch packet */ + release = 1; + } + break; #endif #ifdef MODULE_GNRC_NETAPI_CALLBACKS - case GNRC_NETREG_TYPE_CB: - sendto->target.cbd->cb(cmd, pkt, sendto->target.cbd->ctx); - break; + case GNRC_NETREG_TYPE_CB: + sendto->target.cbd->cb(cmd, pkt, sendto->target.cbd->ctx); + break; #endif - default: - /* unknown dispatch type */ - release = 1; - break; - } - if (release) { - gnrc_pktbuf_release(pkt); - } + default: + /* unknown dispatch type */ + release = 1; + break; + } + if (release) { + gnrc_pktbuf_release(pkt); + } #else - if (_snd_rcv(sendto->target.pid, cmd, pkt) < 1) { - /* unable to dispatch packet */ - gnrc_pktbuf_release(pkt); - } + if (_snd_rcv(sendto->target.pid, cmd, pkt) < 1) { + /* unable to dispatch packet */ + gnrc_pktbuf_release(pkt); + } #endif - numof++; - sendto = gnrc_netreg_getnext(sendto); + sendto = gnrc_netreg_getnext(sendto); + } } + return numof; } diff --git a/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c b/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c index fa6cf2097c..ee9619f4ea 100644 --- a/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c +++ b/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c @@ -219,7 +219,7 @@ static void _dispatch_next_header(gnrc_pktsnip_t *current, gnrc_pktsnip_t *pkt, /* dispatch IPv6 extension header only once */ if (should_dispatch_current_type) { - bool should_release = (!gnrc_netreg_lookup(GNRC_NETTYPE_IPV6, nh)) && + bool should_release = (gnrc_netreg_num(GNRC_NETTYPE_IPV6, nh) == 0) && (!interested); if (!should_release) { -- GitLab