From 98cd70a4b2358d8dd1c3b6e4a061d7eaadcb3bd1 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Mon, 27 Dec 2021 12:57:51 +0100 Subject: ipcpd: Use wrlock for rotating multipath pff entry The multipath pff entry was modified (rotated) under a read lock, which is now changed to a write lock. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/ipcpd/unicast/pff/multipath.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/ipcpd/unicast') diff --git a/src/ipcpd/unicast/pff/multipath.c b/src/ipcpd/unicast/pff/multipath.c index 43135d27..b03ce32f 100644 --- a/src/ipcpd/unicast/pff/multipath.c +++ b/src/ipcpd/unicast/pff/multipath.c @@ -58,21 +58,23 @@ struct pff_i * multipath_pff_create(void) tmp = malloc(sizeof(*tmp)); if (tmp == NULL) - return NULL; + goto fail_malloc; - if (pthread_rwlock_init(&tmp->lock, NULL)) { - free(tmp); - return NULL; - } + if (pthread_rwlock_init(&tmp->lock, NULL)) + goto fail_rwlock; tmp->pft = pft_create(PFT_SIZE, false); - if (tmp->pft == NULL) { - pthread_rwlock_destroy(&tmp->lock); - free(tmp); - return NULL; - } + if (tmp->pft == NULL) + goto fail_pft; return tmp; + + fail_pft: + pthread_rwlock_destroy(&tmp->lock); + fail_rwlock: + free(tmp); + fail_malloc: + return NULL; } void multipath_pff_destroy(struct pff_i * pff_i) @@ -80,8 +82,8 @@ void multipath_pff_destroy(struct pff_i * pff_i) assert(pff_i); pft_destroy(pff_i->pft); - pthread_rwlock_destroy(&pff_i->lock); + free(pff_i); } @@ -177,7 +179,7 @@ int multipath_pff_nhop(struct pff_i * pff_i, assert(pff_i); - pthread_rwlock_rdlock(&pff_i->lock); + pthread_rwlock_wrlock(&pff_i->lock); if (pft_lookup(pff_i->pft, addr, &fds, &len)) { pthread_rwlock_unlock(&pff_i->lock); -- cgit v1.2.3