1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

gnrc_ipv6_nib: use mutex wrapper function instead of mutex functions

This commit is contained in:
Martine S. Lenders 2019-10-11 12:17:02 +02:00
parent 1ce19e26b4
commit a14e834ad8
5 changed files with 39 additions and 39 deletions

View File

@ -87,14 +87,14 @@ void gnrc_ipv6_nib_init(void)
{
evtimer_event_t *tmp;
mutex_lock(&_nib_mutex);
_nib_acquire();
for (evtimer_event_t *ptr = _nib_evtimer.events;
(ptr != NULL) && (tmp = (ptr->next), 1);
ptr = tmp) {
evtimer_del((evtimer_t *)(&_nib_evtimer), ptr);
}
_nib_init();
mutex_unlock(&_nib_mutex);
_nib_release();
}
void gnrc_ipv6_nib_init_iface(gnrc_netif_t *netif)
@ -180,7 +180,7 @@ int gnrc_ipv6_nib_get_next_hop_l2addr(const ipv6_addr_t *dst,
ipv6_addr_to_str(addr_str, dst, sizeof(addr_str)),
(netif != NULL) ? (unsigned)netif->pid : 0U);
gnrc_netif_acquire(netif);
mutex_lock(&_nib_mutex);
_nib_acquire();
do { /* XXX: hidden goto ;-) */
_nib_onl_entry_t *node = _nib_onl_get(dst,
(netif == NULL) ? 0 : netif->pid);
@ -266,7 +266,7 @@ int gnrc_ipv6_nib_get_next_hop_l2addr(const ipv6_addr_t *dst,
}
}
} while (0);
mutex_unlock(&_nib_mutex);
_nib_release();
gnrc_netif_release(netif);
return res;
}
@ -277,7 +277,7 @@ void gnrc_ipv6_nib_handle_pkt(gnrc_netif_t *netif, const ipv6_hdr_t *ipv6,
DEBUG("nib: Handle packet (icmpv6->type = %u)\n", icmpv6->type);
assert(netif != NULL);
gnrc_netif_acquire(netif);
mutex_lock(&_nib_mutex);
_nib_acquire();
switch (icmpv6->type) {
#if GNRC_IPV6_NIB_CONF_ROUTER
case ICMPV6_RTR_SOL:
@ -307,7 +307,7 @@ void gnrc_ipv6_nib_handle_pkt(gnrc_netif_t *netif, const ipv6_hdr_t *ipv6,
break;
#endif /* GNRC_IPV6_NIB_CONF_MULTIHOP_DAD */
}
mutex_unlock(&_nib_mutex);
_nib_release();
gnrc_netif_release(netif);
}
@ -315,7 +315,7 @@ void gnrc_ipv6_nib_handle_timer_event(void *ctx, uint16_t type)
{
DEBUG("nib: Handle timer event (ctx = %p, type = 0x%04x, now = %ums)\n",
ctx, type, (unsigned)xtimer_now_usec() / 1000);
mutex_lock(&_nib_mutex);
_nib_acquire();
switch (type) {
#if GNRC_IPV6_NIB_CONF_ARSM
case GNRC_IPV6_NIB_SND_UC_NS:
@ -381,7 +381,7 @@ void gnrc_ipv6_nib_handle_timer_event(void *ctx, uint16_t type)
default:
break;
}
mutex_unlock(&_nib_mutex);
_nib_release();
}
#if GNRC_IPV6_NIB_CONF_ROUTER

View File

@ -27,9 +27,9 @@ int gnrc_ipv6_nib_abr_add(const ipv6_addr_t *addr)
_nib_abr_entry_t *abr;
_nib_offl_entry_t *offl = NULL;
mutex_lock(&_nib_mutex);
_nib_acquire();
if ((abr = _nib_abr_add(addr)) == NULL) {
mutex_unlock(&_nib_mutex);
_nib_release();
return -ENOMEM;
}
abr->valid_until = 0U;
@ -45,15 +45,15 @@ int gnrc_ipv6_nib_abr_add(const ipv6_addr_t *addr)
}
}
#endif /* MODULE_GNRC_SIXLOWPAN_CTX */
mutex_unlock(&_nib_mutex);
_nib_release();
return 0;
}
void gnrc_ipv6_nib_abr_del(const ipv6_addr_t *addr)
{
mutex_lock(&_nib_mutex);
_nib_acquire();
_nib_abr_remove(addr);
mutex_unlock(&_nib_mutex);
_nib_release();
}
#endif /* GNRC_IPV6_NIB_CONF_6LBR */
@ -61,7 +61,7 @@ bool gnrc_ipv6_nib_abr_iter(void **state, gnrc_ipv6_nib_abr_t *entry)
{
_nib_abr_entry_t *abr = *state;
mutex_lock(&_nib_mutex);
_nib_acquire();
while ((abr = _nib_abr_iter(abr)) != NULL) {
if (!ipv6_addr_is_unspecified(&abr->addr)) {
memcpy(&entry->addr, &abr->addr, sizeof(entry->addr));
@ -70,7 +70,7 @@ bool gnrc_ipv6_nib_abr_iter(void **state, gnrc_ipv6_nib_abr_t *entry)
break;
}
}
mutex_unlock(&_nib_mutex);
_nib_release();
*state = abr;
return (*state != NULL);
}

View File

@ -26,9 +26,9 @@ int gnrc_ipv6_nib_ft_get(const ipv6_addr_t *dst, gnrc_pktsnip_t *pkt,
int res;
assert((dst != NULL) && (fte != NULL));
mutex_lock(&_nib_mutex);
_nib_acquire();
res = _nib_get_route(dst, pkt, fte);
mutex_unlock(&_nib_mutex);
_nib_release();
return res;
}
@ -43,7 +43,7 @@ int gnrc_ipv6_nib_ft_add(const ipv6_addr_t *dst, unsigned dst_len,
if ((iface == 0) || ((is_default_route) && (next_hop == NULL))) {
return -EINVAL;
}
mutex_lock(&_nib_mutex);
_nib_acquire();
if (is_default_route) {
_nib_dr_entry_t *ptr;
@ -78,13 +78,13 @@ int gnrc_ipv6_nib_ft_add(const ipv6_addr_t *dst, unsigned dst_len,
res = -ENOTSUP;
}
#endif
mutex_unlock(&_nib_mutex);
_nib_release();
return res;
}
void gnrc_ipv6_nib_ft_del(const ipv6_addr_t *dst, unsigned dst_len)
{
mutex_lock(&_nib_mutex);
_nib_acquire();
if ((dst == NULL) || (dst_len == 0) || ipv6_addr_is_unspecified(dst)) {
_nib_dr_entry_t *entry = _nib_drl_get_dr();
@ -105,7 +105,7 @@ void gnrc_ipv6_nib_ft_del(const ipv6_addr_t *dst, unsigned dst_len)
}
}
#endif
mutex_unlock(&_nib_mutex);
_nib_release();
}
bool gnrc_ipv6_nib_ft_iter(const ipv6_addr_t *next_hop, unsigned iface,

View File

@ -32,10 +32,10 @@ int gnrc_ipv6_nib_nc_set(const ipv6_addr_t *ipv6, unsigned iface,
assert(ipv6 != NULL);
assert(l2addr_len <= GNRC_IPV6_NIB_L2ADDR_MAX_LEN);
assert((iface > KERNEL_PID_UNDEF) && (iface <= KERNEL_PID_LAST));
mutex_lock(&_nib_mutex);
_nib_acquire();
node = _nib_nc_add(ipv6, iface, GNRC_IPV6_NIB_NC_INFO_NUD_STATE_UNMANAGED);
if (node == NULL) {
mutex_unlock(&_nib_mutex);
_nib_release();
return -ENOMEM;
}
#if GNRC_IPV6_NIB_CONF_ARSM
@ -51,7 +51,7 @@ int gnrc_ipv6_nib_nc_set(const ipv6_addr_t *ipv6, unsigned iface,
GNRC_IPV6_NIB_NC_INFO_NUD_STATE_MASK);
node->info |= (GNRC_IPV6_NIB_NC_INFO_AR_STATE_MANUAL |
GNRC_IPV6_NIB_NC_INFO_NUD_STATE_UNMANAGED);
mutex_unlock(&_nib_mutex);
_nib_release();
return 0;
}
@ -59,7 +59,7 @@ void gnrc_ipv6_nib_nc_del(const ipv6_addr_t *ipv6, unsigned iface)
{
_nib_onl_entry_t *node = NULL;
mutex_lock(&_nib_mutex);
_nib_acquire();
while ((node = _nib_onl_iter(node)) != NULL) {
if ((_nib_onl_get_if(node) == iface) &&
ipv6_addr_equal(ipv6, &node->ipv6)) {
@ -67,14 +67,14 @@ void gnrc_ipv6_nib_nc_del(const ipv6_addr_t *ipv6, unsigned iface)
break;
}
}
mutex_unlock(&_nib_mutex);
_nib_release();
}
void gnrc_ipv6_nib_nc_mark_reachable(const ipv6_addr_t *ipv6)
{
_nib_onl_entry_t *node = NULL;
mutex_lock(&_nib_mutex);
_nib_acquire();
while ((node = _nib_onl_iter(node)) != NULL) {
if ((node->mode & _NC) && ipv6_addr_equal(ipv6, &node->ipv6)) {
/* only set reachable if not unmanaged */
@ -84,7 +84,7 @@ void gnrc_ipv6_nib_nc_mark_reachable(const ipv6_addr_t *ipv6)
break;
}
}
mutex_unlock(&_nib_mutex);
_nib_release();
}
bool gnrc_ipv6_nib_nc_iter(unsigned iface, void **state,
@ -92,7 +92,7 @@ bool gnrc_ipv6_nib_nc_iter(unsigned iface, void **state,
{
_nib_onl_entry_t *node = *state;
mutex_lock(&_nib_mutex);
_nib_acquire();
while ((node = _nib_onl_iter(node)) != NULL) {
if ((node->mode & _NC) &&
((iface == 0) || (_nib_onl_get_if(node) == iface))) {
@ -101,7 +101,7 @@ bool gnrc_ipv6_nib_nc_iter(unsigned iface, void **state,
}
}
*state = node;
mutex_unlock(&_nib_mutex);
_nib_release();
return (*state != NULL);
}

View File

@ -42,11 +42,11 @@ int gnrc_ipv6_nib_pl_set(unsigned iface,
ipv6_addr_is_multicast(pfx) || (pref_ltime > valid_ltime)) {
return -EINVAL;
}
mutex_lock(&_nib_mutex);
_nib_acquire();
dst = _nib_pl_add(iface, pfx, pfx_len, valid_ltime,
pref_ltime);
if (dst == NULL) {
mutex_unlock(&_nib_mutex);
_nib_release();
return -ENOMEM;
}
#ifdef MODULE_GNRC_NETIF
@ -54,7 +54,7 @@ int gnrc_ipv6_nib_pl_set(unsigned iface,
int idx;
if (netif == NULL) {
mutex_unlock(&_nib_mutex);
_nib_release();
return 0;
}
gnrc_netif_acquire(netif);
@ -78,7 +78,7 @@ int gnrc_ipv6_nib_pl_set(unsigned iface,
#endif
gnrc_netif_release(netif);
#endif /* MODULE_GNRC_NETIF */
mutex_unlock(&_nib_mutex);
_nib_release();
#if defined(MODULE_GNRC_NETIF) && GNRC_IPV6_NIB_CONF_ROUTER
/* update prefixes down-stream */
_handle_snd_mc_ra(netif);
@ -92,14 +92,14 @@ void gnrc_ipv6_nib_pl_del(unsigned iface,
_nib_offl_entry_t *dst = NULL;
assert(pfx != NULL);
mutex_lock(&_nib_mutex);
_nib_acquire();
while ((dst = _nib_offl_iter(dst)) != NULL) {
assert(dst->next_hop != NULL);
if ((pfx_len == dst->pfx_len) &&
((iface == 0) || (iface == _nib_onl_get_if(dst->next_hop))) &&
(ipv6_addr_match_prefix(pfx, &dst->pfx) >= pfx_len)) {
_nib_pl_remove(dst);
mutex_unlock(&_nib_mutex);
_nib_release();
#if GNRC_IPV6_NIB_CONF_ROUTER
gnrc_netif_t *netif = gnrc_netif_get_by_pid(iface);
@ -111,7 +111,7 @@ void gnrc_ipv6_nib_pl_del(unsigned iface,
return;
}
}
mutex_unlock(&_nib_mutex);
_nib_release();
}
bool gnrc_ipv6_nib_pl_iter(unsigned iface, void **state,
@ -119,7 +119,7 @@ bool gnrc_ipv6_nib_pl_iter(unsigned iface, void **state,
{
_nib_offl_entry_t *dst = *state;
mutex_lock(&_nib_mutex);
_nib_acquire();
while ((dst = _nib_offl_iter(dst)) != NULL) {
const _nib_onl_entry_t *node = dst->next_hop;
if ((node != NULL) && (dst->mode & _PL) &&
@ -133,7 +133,7 @@ bool gnrc_ipv6_nib_pl_iter(unsigned iface, void **state,
break;
}
}
mutex_unlock(&_nib_mutex);
_nib_release();
*state = dst;
return (*state != NULL);
}