diff options
author | Sander Vrijders <sander.vrijders@ugent.be> | 2017-09-25 14:26:26 +0200 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@ugent.be> | 2017-09-25 14:26:26 +0200 |
commit | e245a809296dad1ea22956f015751cc172a44ad2 (patch) | |
tree | 38171f07be9f2a18e15212eef5fc6f3fd5516041 /src/ipcpd/normal/pol/link_state.c | |
parent | baa9da56af12d14d63d504101c7efeb20da71a78 (diff) | |
download | ouroboros-e245a809296dad1ea22956f015751cc172a44ad2.tar.gz ouroboros-e245a809296dad1ea22956f015751cc172a44ad2.zip |
ipcpd: normal: Return list as routing table
This returns a list as routing table instead of a pointer to a pointer
to a pointer, which simplifies the looping through the routing table
and makes it more extensible for future additions.
Diffstat (limited to 'src/ipcpd/normal/pol/link_state.c')
-rw-r--r-- | src/ipcpd/normal/pol/link_state.c | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/src/ipcpd/normal/pol/link_state.c b/src/ipcpd/normal/pol/link_state.c index 26370682..ca837cc1 100644 --- a/src/ipcpd/normal/pol/link_state.c +++ b/src/ipcpd/normal/pol/link_state.c @@ -378,19 +378,18 @@ static int nbr_to_fd(uint64_t addr) static void * calculate_pff(void * o) { - struct routing_i * instance; - struct routing_table ** table; - ssize_t n_table; - int i; - int fd; + struct routing_i * instance; + int i; + int fd; + struct list_head table; + struct list_head * p; + struct list_head * q; + int fds[1024]; instance = (struct routing_i *) o; while (true) { - table = NULL; - n_table = graph_routing_table(ls.graph, - ipcpi.dt_addr, &table); - if (n_table < 0) { + if (graph_routing_table(ls.graph, ipcpi.dt_addr, &table)) { sleep(RECALC_TIME); continue; } @@ -399,17 +398,28 @@ static void * calculate_pff(void * o) pff_flush(instance->pff); - for (i = 0; i < n_table; i++) { - fd = nbr_to_fd(table[i]->nhop); - if (fd == -1) - continue; + list_for_each(p, &table) { + 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; - pff_add(instance->pff, table[i]->dst, &fd, 1); + fds[i++] = fd; + } + + pff_add(instance->pff, t->dst, fds, i); } pff_unlock(instance->pff); - freepp(struct routing_table, table, n_table); + graph_free_routing_table(ls.graph, &table); + sleep(RECALC_TIME); } |