diff options
author | Dimitri Staessens <dimitri@ouroboros.rocks> | 2021-12-27 12:57:51 +0100 |
---|---|---|
committer | Sander Vrijders <sander@ouroboros.rocks> | 2021-12-29 09:12:27 +0100 |
commit | 98cd70a4b2358d8dd1c3b6e4a061d7eaadcb3bd1 (patch) | |
tree | 5915f73c23cf51ad2bebc5ee43bec934e24f2280 /src | |
parent | ebf1b0c7415f394712c8dd71ae8c8e6821fd5fa3 (diff) | |
download | ouroboros-98cd70a4b2358d8dd1c3b6e4a061d7eaadcb3bd1.tar.gz ouroboros-98cd70a4b2358d8dd1c3b6e4a061d7eaadcb3bd1.zip |
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 <dimitri@ouroboros.rocks>
Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src')
-rw-r--r-- | src/ipcpd/unicast/pff/multipath.c | 26 |
1 files changed, 14 insertions, 12 deletions
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); |