diff options
author | Sander Vrijders <sander.vrijders@ugent.be> | 2018-10-11 14:10:03 +0200 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@ugent.be> | 2018-10-11 14:10:03 +0200 |
commit | 6856f3e24fa00b99747bab790b478866212b2e2d (patch) | |
tree | ca2a4f818bb1844408f015aa2ebe32cdb8a9e3a1 /src/ipcpd/normal/pol | |
parent | 91299fe1de31465b0b389ba6fee76db23db830fb (diff) | |
parent | 9b8d2830250ecffb298f6c72196cffb94991f4d1 (diff) | |
download | ouroboros-6856f3e24fa00b99747bab790b478866212b2e2d.tar.gz ouroboros-6856f3e24fa00b99747bab790b478866212b2e2d.zip |
Merge branch 'testing' into be
Diffstat (limited to 'src/ipcpd/normal/pol')
-rw-r--r-- | src/ipcpd/normal/pol/link_state.c | 126 |
1 files changed, 64 insertions, 62 deletions
diff --git a/src/ipcpd/normal/pol/link_state.c b/src/ipcpd/normal/pol/link_state.c index e2e9eab5..8db1a9c5 100644 --- a/src/ipcpd/normal/pol/link_state.c +++ b/src/ipcpd/normal/pol/link_state.c @@ -374,7 +374,66 @@ static int lsdb_del_nb(uint64_t addr, return -EPERM; } -static void set_pff_modified(void) +static int nbr_to_fd(uint64_t addr) +{ + struct list_head * p; + + pthread_rwlock_rdlock(&ls.db_lock); + + list_for_each(p, &ls.nbs) { + struct nb * nb = list_entry(p, struct nb, next); + if (nb->addr == addr && nb->type == NB_DT) { + pthread_rwlock_unlock(&ls.db_lock); + return nb->fd; + } + } + + pthread_rwlock_unlock(&ls.db_lock); + + return -1; +} + +static void calculate_pff(struct routing_i * instance) +{ + int fd; + struct list_head table; + struct list_head * p; + struct list_head * q; + int fds[PROG_MAX_FLOWS]; + + if (graph_routing_table(ls.graph, ls.routing_algo, + ipcpi.dt_addr, &table)) + return; + + pff_lock(instance->pff); + + pff_flush(instance->pff); + + /* Calulcate forwarding table from routing table. */ + list_for_each(p, &table) { + int i = 0; + struct routing_table * t = + list_entry(p, struct routing_table, next); + + list_for_each(q, &t->nhops) { + struct nhop * n = list_entry(q, struct nhop, next); + + fd = nbr_to_fd(n->nhop); + if (fd == -1) + continue; + + fds[i++] = fd; + } + + pff_add(instance->pff, t->dst, fds, i); + } + + pff_unlock(instance->pff); + + graph_free_routing_table(ls.graph, &table); +} + +static void set_pff_modified(bool calc) { struct list_head * p; @@ -385,6 +444,8 @@ static void set_pff_modified(void) pthread_mutex_lock(&inst->lock); inst->modified = true; pthread_mutex_unlock(&inst->lock); + if (calc) + calculate_pff(inst); } pthread_mutex_unlock(&ls.routing_i_lock); } @@ -439,7 +500,7 @@ static int lsdb_add_link(uint64_t src, pthread_rwlock_unlock(&ls.db_lock); - set_pff_modified(); + set_pff_modified(true); return 0; } @@ -462,7 +523,7 @@ static int lsdb_del_link(uint64_t src, ls.db_len--; pthread_rwlock_unlock(&ls.db_lock); - set_pff_modified(); + set_pff_modified(false); free(a); return 0; } @@ -473,65 +534,6 @@ static int lsdb_del_link(uint64_t src, return -EPERM; } -static int nbr_to_fd(uint64_t addr) -{ - struct list_head * p; - - pthread_rwlock_rdlock(&ls.db_lock); - - list_for_each(p, &ls.nbs) { - struct nb * nb = list_entry(p, struct nb, next); - if (nb->addr == addr && nb->type == NB_DT) { - pthread_rwlock_unlock(&ls.db_lock); - return nb->fd; - } - } - - pthread_rwlock_unlock(&ls.db_lock); - - return -1; -} - -static void calculate_pff(struct routing_i * instance) -{ - int fd; - struct list_head table; - struct list_head * p; - struct list_head * q; - int fds[PROG_MAX_FLOWS]; - - if (graph_routing_table(ls.graph, ls.routing_algo, - ipcpi.dt_addr, &table)) - return; - - pff_lock(instance->pff); - - pff_flush(instance->pff); - - /* Calulcate forwarding table from routing table. */ - list_for_each(p, &table) { - int i = 0; - struct routing_table * t = - list_entry(p, struct routing_table, next); - - list_for_each(q, &t->nhops) { - struct nhop * n = list_entry(q, struct nhop, next); - - fd = nbr_to_fd(n->nhop); - if (fd == -1) - continue; - - fds[i++] = fd; - } - - pff_add(instance->pff, t->dst, fds, i); - } - - pff_unlock(instance->pff); - - graph_free_routing_table(ls.graph, &table); -} - static void * periodic_recalc_pff(void * o) { bool modified; |