diff options
author | Sander Vrijders <sander.vrijders@ugent.be> | 2017-09-20 12:17:54 +0000 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@ugent.be> | 2017-09-20 12:17:54 +0000 |
commit | 0934aa0242f0d61f2b8f7311402cf009b88f1ca6 (patch) | |
tree | 6b28d7f1fd7407d88c17c5a34b068e72748d7dff /src/ipcpd/normal/pff.c | |
parent | 1f723a8a2a02b4657f1d286f98f714895e15a5d8 (diff) | |
parent | 2c7e3030edb84abae14042f7a1a22b44255324be (diff) | |
download | ouroboros-0934aa0242f0d61f2b8f7311402cf009b88f1ca6.tar.gz ouroboros-0934aa0242f0d61f2b8f7311402cf009b88f1ca6.zip |
Merged in sandervrijders/ouroboros/be-pff (pull request #604)
ipcpd: normal: Make PFF policy-based
Diffstat (limited to 'src/ipcpd/normal/pff.c')
-rw-r--r-- | src/ipcpd/normal/pff.c | 154 |
1 files changed, 51 insertions, 103 deletions
diff --git a/src/ipcpd/normal/pff.c b/src/ipcpd/normal/pff.c index d6c9ddee..27ff17f7 100644 --- a/src/ipcpd/normal/pff.c +++ b/src/ipcpd/normal/pff.c @@ -20,150 +20,98 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#define _POSIX_C_SOURCE 200112L - -#include "config.h" - -#define OUROBOROS_PREFIX "pff" - -#include <ouroboros/logs.h> -#include <ouroboros/hashtable.h> #include <ouroboros/errno.h> -#include <assert.h> -#include <pthread.h> - #include "pff.h" +#include "pol-pff-ops.h" +#include "pol/simple_pff.h" struct pff { - struct htable * table; - pthread_rwlock_t lock; + struct pol_pff_ops * ops; + struct pff_i * pff_i; }; -struct pff * pff_create(void) +struct pff * pff_create(enum pol_pff pol) { - struct pff * tmp; + struct pff * pff; - tmp = malloc(sizeof(*tmp)); - if (tmp == NULL) + pff = malloc(sizeof(*pff)); + if (pff == NULL) return NULL; - if (pthread_rwlock_init(&tmp->lock, NULL)) { - free(tmp); - return NULL; + switch (pol) { + case SIMPLE_PFF: + pff->ops = &simple_pff_ops; + pff->pff_i = pff->ops->create(); + if (pff->pff_i == NULL) + goto err; + break; + default: + goto err; } - tmp->table = htable_create(PFT_SIZE, false); - if (tmp->table == NULL) { - pthread_rwlock_destroy(&tmp->lock); - free(tmp); - return NULL; - } - - return tmp; + return pff; + err: + free(pff); + return NULL; } -void pff_destroy(struct pff * instance) +void pff_destroy(struct pff * pff) { - assert(instance); - - htable_destroy(instance->table); + pff->ops->destroy(pff->pff_i); - pthread_rwlock_destroy(&instance->lock); - free(instance); + free(pff); } -void pff_lock(struct pff * instance) +void pff_lock(struct pff * pff) { - pthread_rwlock_wrlock(&instance->lock); + return pff->ops->lock(pff->pff_i); } -void pff_unlock(struct pff * instance) +void pff_unlock(struct pff * pff) { - pthread_rwlock_unlock(&instance->lock); + return pff->ops->unlock(pff->pff_i); } -int pff_add(struct pff * instance, +int pff_add(struct pff * pff, uint64_t addr, - int fd) + int * fd, + size_t len) { - int * val; - - assert(instance); - - val = malloc(sizeof(*val)); - if (val == NULL) - return -ENOMEM; - - *val = fd; - - if (htable_insert(instance->table, addr, val)) { - free(val); - return -1; - } - - return 0; + return pff->ops->add(pff->pff_i, addr, fd, len); } -int pff_update(struct pff * instance, +int pff_update(struct pff * pff, uint64_t addr, - int fd) + int * fd, + size_t len) { - int * val; - - assert(instance); - - val = malloc(sizeof(*val)); - if (val == NULL) - return -ENOMEM; - *val = fd; - - if (htable_delete(instance->table, addr)) { - free(val); - return -1; - } - - if (htable_insert(instance->table, addr, val)) { - free(val); - return -1; - } - - return 0; + return pff->ops->update(pff->pff_i, addr, fd, len); } -int pff_remove(struct pff * instance, - uint64_t addr) +int pff_del(struct pff * pff, + uint64_t addr) { - assert(instance); - - if (htable_delete(instance->table, addr)) - return -1; - - return 0; + return pff->ops->del(pff->pff_i, addr); } -void pff_flush(struct pff * instance) +void pff_flush(struct pff * pff) { - assert(instance); - - htable_flush(instance->table); + return pff->ops->flush(pff->pff_i); } -int pff_nhop(struct pff * instance, +int pff_nhop(struct pff * pff, uint64_t addr) { - int * j; - int fd = -1; - - assert(instance); - - pthread_rwlock_rdlock(&instance->lock); - - j = (int *) htable_lookup(instance->table, addr); - if (j != NULL) - fd = *j; + return pff->ops->nhop(pff->pff_i, addr); +} - pthread_rwlock_unlock(&instance->lock); +int pff_flow_state_change(struct pff * pff, + int fd, + bool up) +{ + if (pff->ops->flow_state_change != NULL) + return pff->ops->flow_state_change(pff->pff_i, fd, up); - return fd; + return 0; } |