diff options
Diffstat (limited to 'src/ipcpd/normal/pol')
-rw-r--r-- | src/ipcpd/normal/pol/complete.c | 180 | ||||
-rw-r--r-- | src/ipcpd/normal/pol/complete.h | 41 | ||||
-rw-r--r-- | src/ipcpd/normal/pol/flat.c | 106 | ||||
-rw-r--r-- | src/ipcpd/normal/pol/flat.h | 4 | ||||
-rw-r--r-- | src/ipcpd/normal/pol/link_state.c | 52 |
5 files changed, 40 insertions, 343 deletions
diff --git a/src/ipcpd/normal/pol/complete.c b/src/ipcpd/normal/pol/complete.c deleted file mode 100644 index 6c6e7372..00000000 --- a/src/ipcpd/normal/pol/complete.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * Sets up a complete graph - * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., http://www.fsf.org/about/contact/. - */ - -#define _POSIX_C_SOURCE 200112L - -#define OUROBOROS_PREFIX "complete" - -#include <ouroboros/qoscube.h> -#include <ouroboros/rib.h> -#include <ouroboros/dev.h> -#include <ouroboros/logs.h> -#include <ouroboros/errno.h> -#include <ouroboros/cacep.h> - -#include "neighbors.h" -#include "ribconfig.h" -#include "ipcp.h" -#include "ae.h" - -#include <string.h> -#include <stdlib.h> -#include <assert.h> - -#define COMPLETE_REFRESH 1000 /* ms */ - -struct complete { - struct nbs * nbs; - struct ae * ae; - pthread_t allocator; - pthread_t listener; -}; - -static void * listener(void * o) -{ - struct complete * complete; - struct conn conn; - - complete = (struct complete *) o; - - while (true) { - if (connmgr_wait(complete->ae, &conn)) { - log_err("Error while getting next connection."); - continue; - } - - if (nbs_add(complete->nbs, conn)) { - log_err("Failed to add neighbor."); - continue; - } - } - - return (void *) 0; -} - -static void path_reset(char * path) -{ - path[strlen(MEMBERS_PATH)] = '\0'; -} - -static void * allocator(void * o) -{ - qosspec_t qs; - ssize_t len; - char ** children; - ssize_t i; - struct complete * complete; - struct conn conn; - uint64_t addr; - char path[RIB_MAX_PATH_LEN]; - struct timespec to = {(COMPLETE_REFRESH / 1000), - (COMPLETE_REFRESH % 1000) * 1000000}; - - strcpy(path, MEMBERS_PATH); - - complete = (struct complete *) o; - - qosspec_init(&qs); - - while (true) { - len = rib_children(MEMBERS_PATH, &children); - for (i = 0; i < len; ++i) { - if (strcmp(children[i], ipcpi.name) != 0) { - path_reset(path); - rib_path_append(path, children[i]); - if (rib_read(path, &addr, - sizeof(addr)) != - sizeof(addr)) { - log_err("Failed to read address."); - free(children[i]); - continue; - } - - if (nbs_has(complete->nbs, addr)) { - free(children[i]); - continue; - } - - if (connmgr_alloc(complete->ae, children[i], - &qs, &conn)) { - log_warn("Failed conn to neighbor."); - free(children[i]); - continue; - } - - if (nbs_add(complete->nbs, conn)) { - log_err("Failed to add neighbor."); - free(children[i]); - continue; - } - } - - free(children[i]); - } - - if (len > 0) - free(children); - - nanosleep(&to, NULL); - } - - return (void *) 0; -} - -void * complete_create(struct nbs * nbs, - struct ae * ae) -{ - struct complete * complete; - - complete = malloc(sizeof(*complete)); - if (complete == NULL) - return NULL; - - complete->nbs = nbs; - complete->ae = ae; - - if (pthread_create(&complete->allocator, NULL, - allocator, (void *) complete)) - return NULL; - - if (pthread_create(&complete->listener, NULL, - listener, (void *) complete)) - return NULL; - - return complete; -} - -void complete_destroy(void * ops_o) -{ - struct complete * complete; - - assert(ops_o); - - complete = (struct complete *) ops_o; - - pthread_cancel(complete->allocator); - pthread_cancel(complete->listener); - pthread_join(complete->allocator, NULL); - pthread_join(complete->listener, NULL); - - free(complete); -} diff --git a/src/ipcpd/normal/pol/complete.h b/src/ipcpd/normal/pol/complete.h deleted file mode 100644 index 54c4a9ef..00000000 --- a/src/ipcpd/normal/pol/complete.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * Sets up a complete graph - * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., http://www.fsf.org/about/contact/. - */ - -#ifndef OUROBOROS_IPCPD_NORMAL_POL_COMPLETE_H -#define OUROBOROS_IPCPD_NORMAL_POL_COMPLETE_H - -#include <ouroboros/ipcp.h> -#include <ouroboros/qos.h> - -#include "pol-gam-ops.h" - -void * complete_create(struct nbs * nbs, - struct ae * ae); - -void complete_destroy(void * ops_o); - -struct pol_gam_ops complete_ops = { - .create = complete_create, - .destroy = complete_destroy -}; - -#endif /* OUROBOROS_IPCPD_NORMAL_POL_COMPLETE_H */ diff --git a/src/ipcpd/normal/pol/flat.c b/src/ipcpd/normal/pol/flat.c index 1fece07f..7a5a785e 100644 --- a/src/ipcpd/normal/pol/flat.c +++ b/src/ipcpd/normal/pol/flat.c @@ -42,47 +42,21 @@ #define NAME_LEN 8 #define REC_DIF_SIZE 10000 -/* convert 32 bit addr to a hex string */ -static void addr_name(char * name, - uint32_t addr) -{ - sprintf(name, "%8x", (uint32_t) (addr)); -} - -static int addr_taken(char * name, - char ** members, - size_t len) -{ - size_t i; - char path[RIB_MAX_PATH_LEN + 1]; - - size_t reset; - strcpy(path, MEMBERS_PATH); - - reset = strlen(path); - - for (i = 0; i < len; ++i) { - ssize_t j; - ssize_t c; - char ** addrs; - rib_path_append(path, members[i]); - c = rib_children(path, &addrs); - for (j = 0; j < c; ++j) - if (strcmp(addrs[j], name) == 0) { - freepp(char, addrs, c); - return 1; - } - freepp(char, addrs, c); - path[reset] = '\0'; - } - - return 0; -} +struct { + uint8_t addr_size; +} flat; #define INVALID_ADDRESS 0 -int flat_init(void) +int flat_init(const void * info) { + flat.addr_size = *((uint8_t *) info); + + if (flat.addr_size != 4) { + log_err("Flat address policy mandates 4 byte addresses."); + return -1; + } + return 0; } @@ -94,66 +68,12 @@ int flat_fini(void) uint64_t flat_address(void) { struct timespec t; - - char path[RIB_MAX_PATH_LEN]; - char name[NAME_LEN + 1]; - uint32_t addr; - uint8_t addr_size; - - char ** members; - ssize_t n_members; - - strcpy(path, MEMBERS_PATH); - - if (!rib_has(path)) { - log_err("Could not read members from RIB."); - return INVALID_ADDRESS; - } - - if (rib_read("/" BOOT_NAME "/dt/const/addr_size", - &addr_size, sizeof(addr_size)) != sizeof(addr_size)) { - log_err("Failed to read address size."); - return INVALID_ADDRESS; - } - - if (addr_size != 4) { - log_err("Flat address policy mandates 4 byte addresses."); - return INVALID_ADDRESS; - } - - n_members = rib_children(path, &members); - if (n_members > REC_DIF_SIZE) - log_warn("DIF exceeding recommended size for flat addresses."); - - rib_path_append(path, ipcpi.name); - - if (!rib_has(path)) { - log_err("This ipcp is not a member."); - freepp(char, members, n_members); - return INVALID_ADDRESS; - } + uint32_t addr; clock_gettime(CLOCK_REALTIME, &t); srand(t.tv_nsec); - assert(n_members > 0); - - do { - addr = (rand() % (RAND_MAX - 1) + 1) & 0xFFFFFFFF; - addr_name(name, addr); - } while (addr_taken(name, members, n_members)); - - freepp(char, members, n_members); - - if (rib_add(path, name)) { - log_err("Failed to add address to RIB."); - return INVALID_ADDRESS; - } - - if (rib_write(path, &addr, sizeof(addr))) { - log_err("Failed to write address in RIB."); - return INVALID_ADDRESS; - } + addr = (rand() % (RAND_MAX - 1) + 1) & 0xFFFFFFFF; return addr; } diff --git a/src/ipcpd/normal/pol/flat.h b/src/ipcpd/normal/pol/flat.h index af49d283..57af591e 100644 --- a/src/ipcpd/normal/pol/flat.h +++ b/src/ipcpd/normal/pol/flat.h @@ -25,8 +25,10 @@ #include "pol-addr-auth-ops.h" -int flat_init(void); +int flat_init(const void * info); + int flat_fini(void); + uint64_t flat_address(void); struct pol_addr_auth_ops flat_ops = { diff --git a/src/ipcpd/normal/pol/link_state.c b/src/ipcpd/normal/pol/link_state.c index 9dfed5c0..512ced7f 100644 --- a/src/ipcpd/normal/pol/link_state.c +++ b/src/ipcpd/normal/pol/link_state.c @@ -130,10 +130,6 @@ static int link_state_neighbor_event(enum nb_event event, size_t len; uint8_t * data; - /* Only announce the flow if our address is bigger */ - if (ipcpi.dt_addr < conn.conn_info.addr) - return 0; - path[0] = '\0'; sprintf(fso_name, "%" PRIu64 "-%" PRIu64, ipcpi.dt_addr, conn.conn_info.addr); @@ -305,42 +301,42 @@ int link_state_init(struct nbs * nbs) { link_state.graph = graph_create(); if (link_state.graph == NULL) - return -1; + goto fail_graph; - if (rib_add(RIB_ROOT, ROUTING_NAME)) { - graph_destroy(link_state.graph); - return -1; - } + if (rib_add(RIB_ROOT, ROUTING_NAME)) + goto fail_rib_add; link_state.nbs = nbs; link_state.nb_notifier.notify_call = link_state_neighbor_event; - if (nbs_reg_notifier(link_state.nbs, &link_state.nb_notifier)) { - graph_destroy(link_state.graph); - rib_del(ROUTING_PATH); - return -1; - } + if (nbs_reg_notifier(link_state.nbs, &link_state.nb_notifier)) + goto fail_nbs_reg_notifier; link_state.set = ro_set_create(); - if (link_state.set == NULL) { - nbs_unreg_notifier(link_state.nbs, &link_state.nb_notifier); - graph_destroy(link_state.graph); - rib_del(ROUTING_PATH); - return -1; - } + if (link_state.set == NULL) + goto fail_ro_set_create; link_state.queue = rqueue_create(); - if (link_state.queue == NULL) { - ro_set_destroy(link_state.set); - nbs_unreg_notifier(link_state.nbs, &link_state.nb_notifier); - graph_destroy(link_state.graph); - rib_del(ROUTING_PATH); - return -1; - } + if (link_state.queue == NULL) + goto fail_rqueue_create; - pthread_create(&link_state.rib_listener, NULL, rib_listener, NULL); + if (pthread_create(&link_state.rib_listener, NULL, rib_listener, NULL)) + goto fail_listener_create; return 0; + + fail_listener_create: + ro_set_destroy(link_state.set); + fail_rqueue_create: + ro_set_destroy(link_state.set); + fail_ro_set_create: + nbs_unreg_notifier(link_state.nbs, &link_state.nb_notifier); + fail_nbs_reg_notifier: + rib_del(ROUTING_PATH); + fail_rib_add: + graph_destroy(link_state.graph); + fail_graph: + return -1; } void link_state_fini(void) |