From 176698e8c2fd7ab8007b8074515d6144e7177d8e Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Fri, 25 Aug 2017 17:19:17 +0200 Subject: ipcpd: Deprecate gam as autonomous component The graph adjacency manager has been deprecated in favor of providing an external interface into the connectivity manager so that adjacencies can be controlled from the command line, user scripts or user applications. The gam and its associated policies were removed from the normal IPCP and the IRM configuration tools. The "/members" part of the RIB was deprecated. Removal of the gam means that initial connectivity based on changes in the RIB can't be provided, so some changes were required throughout the normal IPCP. The enrollment procedure was revised to establish its own connectivity. First, it gets boot information from a peer by establishing a connection to the remote enrollment component and downloading the IPCP configuratoin. This is now done using its own protocol buffers message in anticipation of deprecation of the RIB and CDAP for communication within a DIF. After the boot information is downloaded, it establishes a data transfer flow for enrolling the directory (DHT). After the DHT has enrolled, it signals the peer to that enrollment is done, and the data transfer connection is torn down. Signaling connections is done via the nbs struct, which is now passed to the connmgr, which enables control of the connectivity graph from external sources. --- src/ipcpd/normal/pol/complete.c | 180 -------------------------------------- src/ipcpd/normal/pol/complete.h | 41 --------- src/ipcpd/normal/pol/flat.c | 106 +++------------------- src/ipcpd/normal/pol/flat.h | 4 +- src/ipcpd/normal/pol/link_state.c | 51 +++++------ 5 files changed, 42 insertions(+), 340 deletions(-) delete mode 100644 src/ipcpd/normal/pol/complete.c delete mode 100644 src/ipcpd/normal/pol/complete.h (limited to 'src/ipcpd/normal/pol') 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 - * Sander Vrijders - * - * 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 -#include -#include -#include -#include -#include - -#include "neighbors.h" -#include "ribconfig.h" -#include "ipcp.h" -#include "ae.h" - -#include -#include -#include - -#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 - * Sander Vrijders - * - * 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 -#include - -#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..6bc59d6b 100644 --- a/src/ipcpd/normal/pol/link_state.c +++ b/src/ipcpd/normal/pol/link_state.c @@ -130,9 +130,10 @@ 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 */ + /* 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, @@ -305,42 +306,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) -- cgit v1.2.3 From 999b5dec615ce4cfb30ee909bdd16e79a5e2a1ce Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Mon, 28 Aug 2017 20:12:55 +0200 Subject: ipcpd: Address comments on 176698e --- src/ipcpd/normal/connmgr.c | 3 +-- src/ipcpd/normal/dt.c | 2 +- src/ipcpd/normal/main.c | 2 +- src/ipcpd/normal/pol/link_state.c | 5 ----- src/ipcpd/normal/sdu_sched.c | 2 +- 5 files changed, 4 insertions(+), 10 deletions(-) (limited to 'src/ipcpd/normal/pol') diff --git a/src/ipcpd/normal/connmgr.c b/src/ipcpd/normal/connmgr.c index 11f83247..fa43b97a 100644 --- a/src/ipcpd/normal/connmgr.c +++ b/src/ipcpd/normal/connmgr.c @@ -207,9 +207,8 @@ int connmgr_ae_init(enum ae_id id, ae = connmgr.aes + id; - if (pthread_mutex_init(&ae->lock, NULL)) { + if (pthread_mutex_init(&ae->lock, NULL)) return -1; - } if (pthread_cond_init(&ae->cond, NULL)) { pthread_mutex_destroy(&ae->lock); diff --git a/src/ipcpd/normal/dt.c b/src/ipcpd/normal/dt.c index aa089852..282f6bee 100644 --- a/src/ipcpd/normal/dt.c +++ b/src/ipcpd/normal/dt.c @@ -207,7 +207,7 @@ int dt_init(enum pol_routing pr, if (connmgr_ae_init(AEID_DT, &info, dt.nbs)) { log_err("Failed to register with connmgr."); goto fail_connmgr_ae_init; - }; + } if (routing_init(pr, dt.nbs)) { log_err("Failed to init routing."); diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c index bef04b7a..0a41f883 100644 --- a/src/ipcpd/normal/main.c +++ b/src/ipcpd/normal/main.c @@ -250,7 +250,7 @@ static int normal_ipcp_enroll(const char * dst, if (dt_start()) { log_err("Failed to initialize IPCP components."); goto fail_dt_start; - }; + } if (connmgr_alloc(AEID_DT, dst, NULL, &dt_conn)) { log_err("Failed to create a data transfer flow."); diff --git a/src/ipcpd/normal/pol/link_state.c b/src/ipcpd/normal/pol/link_state.c index 6bc59d6b..512ced7f 100644 --- a/src/ipcpd/normal/pol/link_state.c +++ b/src/ipcpd/normal/pol/link_state.c @@ -130,11 +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); diff --git a/src/ipcpd/normal/sdu_sched.c b/src/ipcpd/normal/sdu_sched.c index 045d536a..10b0f02f 100644 --- a/src/ipcpd/normal/sdu_sched.c +++ b/src/ipcpd/normal/sdu_sched.c @@ -172,7 +172,7 @@ void sdu_sched_add(struct sdu_sched * sdu_sched, { qoscube_t qc; - /* assert(sdu_sched); */ + assert(sdu_sched); ipcp_flow_get_qoscube(fd, &qc); flow_set_add(sdu_sched->set[qc], fd); -- cgit v1.2.3