diff options
Diffstat (limited to 'src/ipcpd/broadcast/dt.c')
-rw-r--r-- | src/ipcpd/broadcast/dt.c | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/src/ipcpd/broadcast/dt.c b/src/ipcpd/broadcast/dt.c index 6e8bacf1..938c9085 100644 --- a/src/ipcpd/broadcast/dt.c +++ b/src/ipcpd/broadcast/dt.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Forward loop for broadcast * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -33,7 +33,6 @@ #define DT "dt" #define OUROBOROS_PREFIX DT -#include <ouroboros/endian.h> #include <ouroboros/dev.h> #include <ouroboros/errno.h> #include <ouroboros/fqueue.h> @@ -41,17 +40,16 @@ #include <ouroboros/logs.h> #include <ouroboros/notifier.h> #include <ouroboros/utils.h> +#include <ouroboros/pthread.h> -#include "comp.h" -#include "connmgr.h" +#include "common/comp.h" +#include "common/connmgr.h" #include "dt.h" -#include "ipcp.h" #include <assert.h> #include <stdlib.h> #include <inttypes.h> #include <string.h> -#include <pthread.h> struct nb { struct list_head next; @@ -80,15 +78,16 @@ static int dt_add_nb(int fd) list_for_each(p, &fwd.nbs) { struct nb * el = list_entry(p, struct nb, next); if (el->fd == fd) { - log_dbg("Already know neighbor."); pthread_rwlock_unlock(&fwd.nbs_lock); - return -EPERM; + log_warn("Already know neighbor on fd %d.", fd); + return 0; } } nb = malloc(sizeof(*nb)); if (nb == NULL) { pthread_rwlock_unlock(&fwd.nbs_lock); + log_err("Failed to malloc neighbor struct."); return -ENOMEM; } @@ -98,10 +97,10 @@ static int dt_add_nb(int fd) ++fwd.nbs_len; - log_dbg("Neighbor %d added.", fd); - pthread_rwlock_unlock(&fwd.nbs_lock); + log_dbg("Neighbor %d added.", fd); + return 0; } @@ -126,6 +125,8 @@ static int dt_del_nb(int fd) pthread_rwlock_unlock(&fwd.nbs_lock); + log_err("Neighbor not found on fd %d.", fd); + return -EPERM; } @@ -158,8 +159,7 @@ static void dt_packet(uint8_t * buf, pthread_rwlock_rdlock(&fwd.nbs_lock); - pthread_cleanup_push((void (*))(void *) pthread_rwlock_unlock, - &fwd.nbs_lock); + pthread_cleanup_push(__cleanup_rwlock_unlock, &fwd.nbs_lock); list_for_each(p, &fwd.nbs) { struct nb * nb = list_entry(p, struct nb, next); @@ -170,6 +170,11 @@ static void dt_packet(uint8_t * buf, pthread_cleanup_pop(true); } +static void __cleanup_fqueue_destroy(void * fq) +{ + fqueue_destroy((fqueue_t *) fq); +} + static void * dt_reader(void * o) { fqueue_t * fq; @@ -184,13 +189,12 @@ static void * dt_reader(void * o) if (fq == NULL) return (void *) -1; - pthread_cleanup_push((void (*) (void *)) fqueue_destroy, - (void *) fq); + pthread_cleanup_push(__cleanup_fqueue_destroy, (void *) fq); while (true) { ret = fevent(fwd.set, fq, NULL); if (ret < 0) { - log_warn("Event error: %d.", ret); + log_warn("Event warning: %d.", ret); continue; } @@ -225,13 +229,13 @@ static void handle_event(void * self, switch (event) { case NOTIFY_DT_CONN_ADD: - if (dt_add_nb(c->flow_info.fd)) - log_dbg("Failed to add neighbor."); + if (dt_add_nb(c->flow_info.fd) < 0) + log_err("Failed to add neighbor."); fset_add(fwd.set, c->flow_info.fd); break; case NOTIFY_DT_CONN_DEL: - if (dt_del_nb(c->flow_info.fd)) - log_dbg("Failed to delete neighbor."); + if (dt_del_nb(c->flow_info.fd) < 0) + log_err("Failed to delete neighbor."); fset_del(fwd.set, c->flow_info.fd); break; default: |