From 5d87cec1757c4e1c23ae778f2814363c1e39b43c Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Mon, 15 May 2017 18:08:53 +0200 Subject: ipcpd: normal: Make routing a policy This makes the routing component into a policy since different approaches may exist to do this, depending on how high the rank of the DIF is. --- include/ouroboros/ipcp.h | 5 + src/ipcpd/normal/CMakeLists.txt | 9 +- src/ipcpd/normal/dt.c | 9 +- src/ipcpd/normal/fso.proto | 29 -- src/ipcpd/normal/graph.c | 517 ------------------------------ src/ipcpd/normal/graph.h | 53 --- src/ipcpd/normal/main.c | 17 +- src/ipcpd/normal/pol-routing-ops.h | 38 +++ src/ipcpd/normal/pol/fso.proto | 29 ++ src/ipcpd/normal/pol/graph.c | 517 ++++++++++++++++++++++++++++++ src/ipcpd/normal/pol/graph.h | 53 +++ src/ipcpd/normal/pol/link_state.c | 360 +++++++++++++++++++++ src/ipcpd/normal/pol/link_state.h | 43 +++ src/ipcpd/normal/pol/tests/CMakeLists.txt | 34 ++ src/ipcpd/normal/pol/tests/graph_test.c | 240 ++++++++++++++ src/ipcpd/normal/ribconfig.h | 18 +- src/ipcpd/normal/routing.c | 325 +------------------ src/ipcpd/normal/routing.h | 8 +- src/ipcpd/normal/tests/CMakeLists.txt | 34 -- src/ipcpd/normal/tests/graph_test.c | 240 -------------- src/lib/ipcp_config.proto | 7 +- src/lib/irm.c | 2 + src/tools/irm/irm_ipcp_bootstrap.c | 34 +- 23 files changed, 1395 insertions(+), 1226 deletions(-) delete mode 100644 src/ipcpd/normal/fso.proto delete mode 100644 src/ipcpd/normal/graph.c delete mode 100644 src/ipcpd/normal/graph.h create mode 100644 src/ipcpd/normal/pol-routing-ops.h create mode 100644 src/ipcpd/normal/pol/fso.proto create mode 100644 src/ipcpd/normal/pol/graph.c create mode 100644 src/ipcpd/normal/pol/graph.h create mode 100644 src/ipcpd/normal/pol/link_state.c create mode 100644 src/ipcpd/normal/pol/link_state.h create mode 100644 src/ipcpd/normal/pol/tests/CMakeLists.txt create mode 100644 src/ipcpd/normal/pol/tests/graph_test.c delete mode 100644 src/ipcpd/normal/tests/CMakeLists.txt delete mode 100644 src/ipcpd/normal/tests/graph_test.c diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h index 05fdcd49..8979c6d1 100644 --- a/include/ouroboros/ipcp.h +++ b/include/ouroboros/ipcp.h @@ -48,6 +48,10 @@ enum pol_gam { COMPLETE = 0 }; +enum pol_routing { + LINK_STATE = 0 +}; + enum hash_algo { HASH_CRC32 = 0, HASH_MD5, @@ -77,6 +81,7 @@ struct ipcp_config { enum pol_addr_auth addr_auth_type; enum pol_gam dt_gam_type; enum pol_gam rm_gam_type; + enum pol_routing routing_type; /* Shim UDP */ uint32_t ip_addr; diff --git a/src/ipcpd/normal/CMakeLists.txt b/src/ipcpd/normal/CMakeLists.txt index 984ebd3d..336b0e8f 100644 --- a/src/ipcpd/normal/CMakeLists.txt +++ b/src/ipcpd/normal/CMakeLists.txt @@ -15,7 +15,8 @@ include_directories(${CMAKE_BINARY_DIR}/include) set(IPCP_NORMAL_TARGET ipcpd-normal CACHE STRING "IPCP_NORMAL_TARGET") protobuf_generate_c(FLOW_ALLOC_SRCS FLOW_ALLOC_HDRS flow_alloc.proto) -protobuf_generate_c(FSO_SRCS FSO_HDRS fso.proto) +# Add GPB sources of policies last +protobuf_generate_c(FSO_SRCS FSO_HDRS pol/fso.proto) set(SOURCE_FILES # Add source files here @@ -27,7 +28,6 @@ set(SOURCE_FILES enroll.c fa.c gam.c - graph.c main.c neighbors.c pff.c @@ -37,6 +37,8 @@ set(SOURCE_FILES # Add policies last pol/complete.c pol/flat.c + pol/link_state.c + pol/graph.c ) add_executable(ipcpd-normal ${SOURCE_FILES} ${IPCP_SOURCES} @@ -50,5 +52,4 @@ endif (CMAKE_BUILD_TYPE MATCHES Debug) install(TARGETS ipcpd-normal RUNTIME DESTINATION sbin) -# Enable once ipcp-normal has tests -add_subdirectory(tests) +add_subdirectory(pol/tests) diff --git a/src/ipcpd/normal/dt.c b/src/ipcpd/normal/dt.c index 33070fa2..b22fb59c 100644 --- a/src/ipcpd/normal/dt.c +++ b/src/ipcpd/normal/dt.c @@ -143,6 +143,13 @@ int dt_init(void) int i; int j; struct conn_info info; + enum pol_routing pr; + + if (rib_read(BOOT_PATH "/dt/routing/type", &pr, sizeof(pr)) + != sizeof(pr)) { + log_err("Failed to read policy for routing."); + return -1; + } if (dt_pci_init()) { log_err("Failed to init shm dt_pci."); @@ -175,7 +182,7 @@ int dt_init(void) goto fail_nbs; } - if (routing_init(dt.nbs)) { + if (routing_init(pr, dt.nbs)) { log_err("Failed to init routing."); goto fail_nbs_notifier; } diff --git a/src/ipcpd/normal/fso.proto b/src/ipcpd/normal/fso.proto deleted file mode 100644 index 32b281d6..00000000 --- a/src/ipcpd/normal/fso.proto +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * Flow State Object message - * - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -syntax = "proto2"; - -message fso { - required uint64 s_addr = 1; - required uint64 d_addr = 2; - /* Add QoS parameters of link here */ -}; diff --git a/src/ipcpd/normal/graph.c b/src/ipcpd/normal/graph.c deleted file mode 100644 index 78ed203d..00000000 --- a/src/ipcpd/normal/graph.c +++ /dev/null @@ -1,517 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * Undirected graph structure - * - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#define OUROBOROS_PREFIX "graph" - -#include -#include -#include -#include - -#include "graph.h" -#include "ipcp.h" - -#include -#include -#include -#include - -struct edge { - struct list_head next; - struct vertex * nb; - qosspec_t qs; -}; - -struct vertex { - struct list_head next; - uint64_t addr; - struct list_head edges; -}; - -struct graph { - size_t nr_vertices; - struct list_head vertices; - pthread_mutex_t lock; -}; - -static struct edge * find_edge_by_addr(struct vertex * vertex, - uint64_t dst_addr) -{ - struct list_head * p = NULL; - - list_for_each(p, &vertex->edges) { - struct edge * e = list_entry(p, struct edge, next); - if (e->nb->addr == dst_addr) - return e; - } - - return NULL; -} - -static struct vertex * find_vertex_by_addr(struct graph * graph, - uint64_t addr) -{ - struct list_head * p = NULL; - - list_for_each(p, &graph->vertices) { - struct vertex * e = list_entry(p, struct vertex, next); - if (e->addr == addr) - return e; - } - - return NULL; -} - -static struct edge * add_edge(struct vertex * vertex, - struct vertex * nb) -{ - struct edge * edge; - - edge = malloc(sizeof(*edge)); - if (edge == NULL) - return NULL; - - list_head_init(&edge->next); - edge->nb = nb; - - list_add(&edge->next, &vertex->edges); - - return edge; -} - -static void del_edge(struct edge * edge) -{ - list_del(&edge->next); - free(edge); -} - -static struct vertex * add_vertex(struct graph * graph, - uint64_t addr) -{ - struct vertex * vertex; - struct list_head * p; - - vertex = malloc(sizeof(*vertex)); - if (vertex == NULL) - return NULL; - - list_head_init(&vertex->next); - list_head_init(&vertex->edges); - vertex->addr = addr; - - list_for_each(p, &graph->vertices) { - struct vertex * v = list_entry(p, struct vertex, next); - if (v->addr > addr) - break; - } - - list_add_tail(&vertex->next, p); - - graph->nr_vertices++; - - return vertex; -} - -static void del_vertex(struct graph * graph, - struct vertex * vertex) -{ - struct list_head * p = NULL; - struct list_head * n = NULL; - - list_del(&vertex->next); - - list_for_each_safe(p, n, &vertex->edges) { - struct edge * e = list_entry(p, struct edge, next); - del_edge(e); - } - - free(vertex); - - graph->nr_vertices--; -} - -struct graph * graph_create(void) -{ - struct graph * graph; - - graph = malloc(sizeof(*graph)); - if (graph == NULL) - return NULL; - - if (pthread_mutex_init(&graph->lock, NULL)) { - free(graph); - return NULL; - } - - graph->nr_vertices = 0; - list_head_init(&graph->vertices); - - return graph; -} - -void graph_destroy(struct graph * graph) -{ - struct list_head * p = NULL; - struct list_head * n = NULL; - - assert(graph); - - pthread_mutex_lock(&graph->lock); - - list_for_each_safe(p, n, &graph->vertices) { - struct vertex * e = list_entry(p, struct vertex, next); - del_vertex(graph, e); - } - - pthread_mutex_unlock(&graph->lock); - - pthread_mutex_destroy(&graph->lock); - - free(graph); -} - -int graph_update_edge(struct graph * graph, - uint64_t s_addr, - uint64_t d_addr, - qosspec_t qs) -{ - struct vertex * v; - struct edge * e; - struct vertex * nb; - struct edge * nb_e; - - assert(graph); - - pthread_mutex_lock(&graph->lock); - - v = find_vertex_by_addr(graph, s_addr); - if (v == NULL) { - v = add_vertex(graph, s_addr); - if (v == NULL) { - pthread_mutex_unlock(&graph->lock); - log_err("Failed to add vertex."); - return -ENOMEM; - } - } - - nb = find_vertex_by_addr(graph, d_addr); - if (nb == NULL) { - nb = add_vertex(graph, d_addr); - if (nb == NULL) { - if (list_is_empty(&v->edges)) - del_vertex(graph, v); - pthread_mutex_unlock(&graph->lock); - log_err("Failed to add vertex."); - return -ENOMEM; - } - } - - e = find_edge_by_addr(v, d_addr); - if (e == NULL) { - e = add_edge(v, nb); - if (e == NULL) { - if (list_is_empty(&v->edges)) - del_vertex(graph, v); - if (list_is_empty(&nb->edges)) - del_vertex(graph, nb); - pthread_mutex_unlock(&graph->lock); - log_err("Failed to add edge."); - return -ENOMEM; - } - } - - e->qs = qs; - - nb_e = find_edge_by_addr(nb, s_addr); - if (nb_e == NULL) { - nb_e = add_edge(nb, v); - if (nb_e == NULL) { - del_edge(e); - if (list_is_empty(&v->edges)) - del_vertex(graph, v); - if (list_is_empty(&nb->edges)) - del_vertex(graph, nb); - pthread_mutex_unlock(&graph->lock); - log_err("Failed to add edge."); - return -ENOMEM; - } - } - - nb_e->qs = qs; - - pthread_mutex_unlock(&graph->lock); - - return 0; -} - -int graph_del_edge(struct graph * graph, - uint64_t s_addr, - uint64_t d_addr) -{ - struct vertex * v; - struct edge * e; - struct vertex * nb; - struct edge * nb_e; - - assert(graph); - - pthread_mutex_lock(&graph->lock); - - v = find_vertex_by_addr(graph, s_addr); - if (v == NULL) { - pthread_mutex_unlock(&graph->lock); - log_err("No such vertex."); - return -1; - } - - nb = find_vertex_by_addr(graph, d_addr); - if (nb == NULL) { - pthread_mutex_unlock(&graph->lock); - log_err("No such vertex."); - return -1; - } - - e = find_edge_by_addr(v, d_addr); - if (e == NULL) { - pthread_mutex_unlock(&graph->lock); - log_err("No such edge."); - return -1; - } - - nb_e = find_edge_by_addr(nb, s_addr); - if (nb_e == NULL) { - pthread_mutex_unlock(&graph->lock); - log_err("No such edge."); - return -1; - } - - del_edge(e); - del_edge(nb_e); - - /* Removing vertex if it was the last edge */ - if (list_is_empty(&v->edges)) - del_vertex(graph, v); - if (list_is_empty(&nb->edges)) - del_vertex(graph, nb); - - pthread_mutex_unlock(&graph->lock); - - return 0; -} - -static int get_min_vertex(struct vertex ** vertices, - int nr_vertices, - int * dist, - struct vertex ** v) -{ - int min = INT_MAX; - int index = -1; - int i; - - *v = NULL; - - for (i = 0; i < nr_vertices; i++) { - if (vertices[i] == NULL) - continue; - - if (dist[i] < min) { - *v = vertices[i]; - min = dist[i]; - index = i; - } - } - - if (index != -1) - vertices[index] = NULL; - - return index; -} - -static int get_vertex_number(struct vertex ** vertices, - int nr_vertices, - struct vertex * v) - -{ - int i; - - for (i = 0; i < nr_vertices; i++) { - if (vertices[i] == v) - return i; - } - - return -1; -} - -static int get_vertex_index(struct graph * graph, - struct vertex * v) - -{ - struct list_head * p = NULL; - struct vertex * vertex; - int i = 0; - - list_for_each(p, &graph->vertices) { - vertex = list_entry(p, struct vertex, next); - if (vertex == v) - return i; - i++; - } - - return -1; -} - -static struct vertex ** dijkstra(struct graph * graph, - uint64_t src) -{ - int dist[graph->nr_vertices]; - struct vertex * vertices[graph->nr_vertices]; - struct list_head * p = NULL; - int i = 0; - int j = 0; - struct vertex * v = NULL; - struct edge * e = NULL; - int alt; - struct vertex ** prev; - - prev = malloc(sizeof(*prev) * graph->nr_vertices); - if (prev == NULL) - return NULL; - - /* Init the data structures */ - list_for_each(p, &graph->vertices) { - v = list_entry(p, struct vertex, next); - vertices[i] = v; - if (v->addr == src) - dist[i] = 0; - else - dist[i] = INT_MAX; - prev[i] = NULL; - i++; - } - - /* Perform actual Dijkstra */ - i = get_min_vertex(vertices, graph->nr_vertices, dist, &v); - while (v != NULL) { - list_for_each(p, &v->edges) { - e = list_entry(p, struct edge, next); - - j = get_vertex_number(vertices, - graph->nr_vertices, - e->nb); - if (j == -1) - continue; - - /* - * NOTE: Current weight is just hop count. - * Method could be extended to use a different - * weight for a different QoS cube. - */ - alt = dist[i] + 1; - if (alt < dist[j]) { - dist[j] = alt; - prev[j] = v; - } - } - i = get_min_vertex(vertices, graph->nr_vertices, dist, &v); - } - - return prev; -} - -ssize_t graph_routing_table(struct graph * graph, - uint64_t s_addr, - struct routing_table *** table) -{ - struct vertex ** prevs; - struct list_head * p = NULL; - int i = 0; - int index = 0; - int j = 0; - int k = 0; - struct vertex * prev; - struct vertex * nhop; - struct vertex * v; - - pthread_mutex_lock(&graph->lock); - - if (graph->nr_vertices == 0) { - pthread_mutex_unlock(&graph->lock); - return 0; - } - - prevs = dijkstra(graph, s_addr); - if (prevs == NULL) { - pthread_mutex_unlock(&graph->lock); - return -1; - } - - *table = malloc(sizeof(**table) * (graph->nr_vertices - 1)); - if (*table == NULL) { - pthread_mutex_unlock(&graph->lock); - free(prevs); - return -1; - } - - /* - * Now loop through the list of predecessors - * to construct the routing table - */ - list_for_each(p, &graph->vertices) { - v = list_entry(p, struct vertex, next); - prev = prevs[i]; - nhop = v; - - /* This is the src */ - if (prev == NULL) { - i++; - continue; - } - - index = get_vertex_index(graph, prev); - while (prevs[index] != NULL) { - nhop = prev; - prev = prevs[index]; - index = get_vertex_index(graph, prev); - } - - (*table)[j] = malloc(sizeof(***table)); - if ((*table)[j] == NULL) { - pthread_mutex_unlock(&graph->lock); - for (k = 0; k < j; ++k) - free((*table)[k]); - free(*table); - free(prevs); - return -1; - } - - (*table)[j]->dst = v->addr; - (*table)[j]->nhop = nhop->addr; - j++; - i++; - } - - pthread_mutex_unlock(&graph->lock); - - free(prevs); - - return j; -} diff --git a/src/ipcpd/normal/graph.h b/src/ipcpd/normal/graph.h deleted file mode 100644 index 44496bc3..00000000 --- a/src/ipcpd/normal/graph.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * Undirected graph structure - * - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef OUROBOROS_IPCPD_NORMAL_GRAPH_H -#define OUROBOROS_IPCPD_NORMAL_GRAPH_H - -#include -#include - -#include - -struct routing_table { - uint64_t dst; - uint64_t nhop; -}; - -struct graph * graph_create(void); - -void graph_destroy(struct graph * graph); - -int graph_update_edge(struct graph * graph, - uint64_t s_addr, - uint64_t d_addr, - qosspec_t qs); - -int graph_del_edge(struct graph * graph, - uint64_t s_addr, - uint64_t d_addr); - -ssize_t graph_routing_table(struct graph * graph, - uint64_t s_addr, - struct routing_table *** table); - -#endif /* OUROBOROS_IPCPD_NORMAL_GRAPH_H */ diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c index f9718041..0b8a26ab 100644 --- a/src/ipcpd/normal/main.c +++ b/src/ipcpd/normal/main.c @@ -88,7 +88,7 @@ static int boot_components(void) log_dbg("Starting components."); - if (rib_read(BOOT_PATH "/addr_auth/type", &pa, sizeof(pa)) + if (rib_read(BOOT_PATH "/dt/addr_auth/type", &pa, sizeof(pa)) != sizeof(pa)) { log_err("Failed to read policy for address authority."); goto fail_addr_auth; @@ -261,17 +261,17 @@ const struct ros { {BOOT_PATH "/dt/const", "addr_size"}, {BOOT_PATH "/dt/const", "fd_size"}, {BOOT_PATH "/dt/const", "has_ttl"}, + {BOOT_PATH "/dt", "addr_auth"}, + {BOOT_PATH "/dt/addr_auth", "type"}, + {BOOT_PATH "/dt", "routing"}, + {BOOT_PATH "/dt/routing", "type"}, /* RIB MGR COMPONENT */ {BOOT_PATH, "rm"}, - {BOOT_PATH "/rm","gam"}, {BOOT_PATH "/rm/gam", "type"}, {BOOT_PATH "/rm/gam", "cacep"}, - /* ADDR AUTH COMPONENT */ - {BOOT_PATH, "addr_auth"}, - {BOOT_PATH "/addr_auth", "type"}, {NULL, NULL} }; @@ -327,9 +327,12 @@ static int normal_ipcp_bootstrap(const struct ipcp_config * conf) rib_write(BOOT_PATH "/rm/gam/type", &conf->rm_gam_type, sizeof(conf->rm_gam_type)) || - rib_write(BOOT_PATH "/addr_auth/type", + rib_write(BOOT_PATH "/dt/addr_auth/type", &conf->addr_auth_type, - sizeof(conf->addr_auth_type))) { + sizeof(conf->addr_auth_type)) || + rib_write(BOOT_PATH "/dt/routing/type", + &conf->routing_type, + sizeof(conf->routing_type))) { log_err("Failed to write boot info to RIB."); return -1; } diff --git a/src/ipcpd/normal/pol-routing-ops.h b/src/ipcpd/normal/pol-routing-ops.h new file mode 100644 index 00000000..3a60ca6b --- /dev/null +++ b/src/ipcpd/normal/pol-routing-ops.h @@ -0,0 +1,38 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * Routing policy ops + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef OUROBOROS_IPCPD_NORMAL_POL_ROUTING_OPS_H +#define OUROBOROS_IPCPD_NORMAL_POL_ROUTING_OPS_H + +#include "pff.h" + +struct pol_routing_ops { + int (* init)(struct nbs * nbs); + + void (* fini)(void); + + struct routing_i * (* routing_i_create)(struct pff * pff); + + void (* routing_i_destroy)(struct routing_i * instance); +}; + +#endif /* OUROBOROS_IPCPD_NORMAL_POL_ROUTING_OPS_H */ diff --git a/src/ipcpd/normal/pol/fso.proto b/src/ipcpd/normal/pol/fso.proto new file mode 100644 index 00000000..32b281d6 --- /dev/null +++ b/src/ipcpd/normal/pol/fso.proto @@ -0,0 +1,29 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * Flow State Object message + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +syntax = "proto2"; + +message fso { + required uint64 s_addr = 1; + required uint64 d_addr = 2; + /* Add QoS parameters of link here */ +}; diff --git a/src/ipcpd/normal/pol/graph.c b/src/ipcpd/normal/pol/graph.c new file mode 100644 index 00000000..78ed203d --- /dev/null +++ b/src/ipcpd/normal/pol/graph.c @@ -0,0 +1,517 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * Undirected graph structure + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#define OUROBOROS_PREFIX "graph" + +#include +#include +#include +#include + +#include "graph.h" +#include "ipcp.h" + +#include +#include +#include +#include + +struct edge { + struct list_head next; + struct vertex * nb; + qosspec_t qs; +}; + +struct vertex { + struct list_head next; + uint64_t addr; + struct list_head edges; +}; + +struct graph { + size_t nr_vertices; + struct list_head vertices; + pthread_mutex_t lock; +}; + +static struct edge * find_edge_by_addr(struct vertex * vertex, + uint64_t dst_addr) +{ + struct list_head * p = NULL; + + list_for_each(p, &vertex->edges) { + struct edge * e = list_entry(p, struct edge, next); + if (e->nb->addr == dst_addr) + return e; + } + + return NULL; +} + +static struct vertex * find_vertex_by_addr(struct graph * graph, + uint64_t addr) +{ + struct list_head * p = NULL; + + list_for_each(p, &graph->vertices) { + struct vertex * e = list_entry(p, struct vertex, next); + if (e->addr == addr) + return e; + } + + return NULL; +} + +static struct edge * add_edge(struct vertex * vertex, + struct vertex * nb) +{ + struct edge * edge; + + edge = malloc(sizeof(*edge)); + if (edge == NULL) + return NULL; + + list_head_init(&edge->next); + edge->nb = nb; + + list_add(&edge->next, &vertex->edges); + + return edge; +} + +static void del_edge(struct edge * edge) +{ + list_del(&edge->next); + free(edge); +} + +static struct vertex * add_vertex(struct graph * graph, + uint64_t addr) +{ + struct vertex * vertex; + struct list_head * p; + + vertex = malloc(sizeof(*vertex)); + if (vertex == NULL) + return NULL; + + list_head_init(&vertex->next); + list_head_init(&vertex->edges); + vertex->addr = addr; + + list_for_each(p, &graph->vertices) { + struct vertex * v = list_entry(p, struct vertex, next); + if (v->addr > addr) + break; + } + + list_add_tail(&vertex->next, p); + + graph->nr_vertices++; + + return vertex; +} + +static void del_vertex(struct graph * graph, + struct vertex * vertex) +{ + struct list_head * p = NULL; + struct list_head * n = NULL; + + list_del(&vertex->next); + + list_for_each_safe(p, n, &vertex->edges) { + struct edge * e = list_entry(p, struct edge, next); + del_edge(e); + } + + free(vertex); + + graph->nr_vertices--; +} + +struct graph * graph_create(void) +{ + struct graph * graph; + + graph = malloc(sizeof(*graph)); + if (graph == NULL) + return NULL; + + if (pthread_mutex_init(&graph->lock, NULL)) { + free(graph); + return NULL; + } + + graph->nr_vertices = 0; + list_head_init(&graph->vertices); + + return graph; +} + +void graph_destroy(struct graph * graph) +{ + struct list_head * p = NULL; + struct list_head * n = NULL; + + assert(graph); + + pthread_mutex_lock(&graph->lock); + + list_for_each_safe(p, n, &graph->vertices) { + struct vertex * e = list_entry(p, struct vertex, next); + del_vertex(graph, e); + } + + pthread_mutex_unlock(&graph->lock); + + pthread_mutex_destroy(&graph->lock); + + free(graph); +} + +int graph_update_edge(struct graph * graph, + uint64_t s_addr, + uint64_t d_addr, + qosspec_t qs) +{ + struct vertex * v; + struct edge * e; + struct vertex * nb; + struct edge * nb_e; + + assert(graph); + + pthread_mutex_lock(&graph->lock); + + v = find_vertex_by_addr(graph, s_addr); + if (v == NULL) { + v = add_vertex(graph, s_addr); + if (v == NULL) { + pthread_mutex_unlock(&graph->lock); + log_err("Failed to add vertex."); + return -ENOMEM; + } + } + + nb = find_vertex_by_addr(graph, d_addr); + if (nb == NULL) { + nb = add_vertex(graph, d_addr); + if (nb == NULL) { + if (list_is_empty(&v->edges)) + del_vertex(graph, v); + pthread_mutex_unlock(&graph->lock); + log_err("Failed to add vertex."); + return -ENOMEM; + } + } + + e = find_edge_by_addr(v, d_addr); + if (e == NULL) { + e = add_edge(v, nb); + if (e == NULL) { + if (list_is_empty(&v->edges)) + del_vertex(graph, v); + if (list_is_empty(&nb->edges)) + del_vertex(graph, nb); + pthread_mutex_unlock(&graph->lock); + log_err("Failed to add edge."); + return -ENOMEM; + } + } + + e->qs = qs; + + nb_e = find_edge_by_addr(nb, s_addr); + if (nb_e == NULL) { + nb_e = add_edge(nb, v); + if (nb_e == NULL) { + del_edge(e); + if (list_is_empty(&v->edges)) + del_vertex(graph, v); + if (list_is_empty(&nb->edges)) + del_vertex(graph, nb); + pthread_mutex_unlock(&graph->lock); + log_err("Failed to add edge."); + return -ENOMEM; + } + } + + nb_e->qs = qs; + + pthread_mutex_unlock(&graph->lock); + + return 0; +} + +int graph_del_edge(struct graph * graph, + uint64_t s_addr, + uint64_t d_addr) +{ + struct vertex * v; + struct edge * e; + struct vertex * nb; + struct edge * nb_e; + + assert(graph); + + pthread_mutex_lock(&graph->lock); + + v = find_vertex_by_addr(graph, s_addr); + if (v == NULL) { + pthread_mutex_unlock(&graph->lock); + log_err("No such vertex."); + return -1; + } + + nb = find_vertex_by_addr(graph, d_addr); + if (nb == NULL) { + pthread_mutex_unlock(&graph->lock); + log_err("No such vertex."); + return -1; + } + + e = find_edge_by_addr(v, d_addr); + if (e == NULL) { + pthread_mutex_unlock(&graph->lock); + log_err("No such edge."); + return -1; + } + + nb_e = find_edge_by_addr(nb, s_addr); + if (nb_e == NULL) { + pthread_mutex_unlock(&graph->lock); + log_err("No such edge."); + return -1; + } + + del_edge(e); + del_edge(nb_e); + + /* Removing vertex if it was the last edge */ + if (list_is_empty(&v->edges)) + del_vertex(graph, v); + if (list_is_empty(&nb->edges)) + del_vertex(graph, nb); + + pthread_mutex_unlock(&graph->lock); + + return 0; +} + +static int get_min_vertex(struct vertex ** vertices, + int nr_vertices, + int * dist, + struct vertex ** v) +{ + int min = INT_MAX; + int index = -1; + int i; + + *v = NULL; + + for (i = 0; i < nr_vertices; i++) { + if (vertices[i] == NULL) + continue; + + if (dist[i] < min) { + *v = vertices[i]; + min = dist[i]; + index = i; + } + } + + if (index != -1) + vertices[index] = NULL; + + return index; +} + +static int get_vertex_number(struct vertex ** vertices, + int nr_vertices, + struct vertex * v) + +{ + int i; + + for (i = 0; i < nr_vertices; i++) { + if (vertices[i] == v) + return i; + } + + return -1; +} + +static int get_vertex_index(struct graph * graph, + struct vertex * v) + +{ + struct list_head * p = NULL; + struct vertex * vertex; + int i = 0; + + list_for_each(p, &graph->vertices) { + vertex = list_entry(p, struct vertex, next); + if (vertex == v) + return i; + i++; + } + + return -1; +} + +static struct vertex ** dijkstra(struct graph * graph, + uint64_t src) +{ + int dist[graph->nr_vertices]; + struct vertex * vertices[graph->nr_vertices]; + struct list_head * p = NULL; + int i = 0; + int j = 0; + struct vertex * v = NULL; + struct edge * e = NULL; + int alt; + struct vertex ** prev; + + prev = malloc(sizeof(*prev) * graph->nr_vertices); + if (prev == NULL) + return NULL; + + /* Init the data structures */ + list_for_each(p, &graph->vertices) { + v = list_entry(p, struct vertex, next); + vertices[i] = v; + if (v->addr == src) + dist[i] = 0; + else + dist[i] = INT_MAX; + prev[i] = NULL; + i++; + } + + /* Perform actual Dijkstra */ + i = get_min_vertex(vertices, graph->nr_vertices, dist, &v); + while (v != NULL) { + list_for_each(p, &v->edges) { + e = list_entry(p, struct edge, next); + + j = get_vertex_number(vertices, + graph->nr_vertices, + e->nb); + if (j == -1) + continue; + + /* + * NOTE: Current weight is just hop count. + * Method could be extended to use a different + * weight for a different QoS cube. + */ + alt = dist[i] + 1; + if (alt < dist[j]) { + dist[j] = alt; + prev[j] = v; + } + } + i = get_min_vertex(vertices, graph->nr_vertices, dist, &v); + } + + return prev; +} + +ssize_t graph_routing_table(struct graph * graph, + uint64_t s_addr, + struct routing_table *** table) +{ + struct vertex ** prevs; + struct list_head * p = NULL; + int i = 0; + int index = 0; + int j = 0; + int k = 0; + struct vertex * prev; + struct vertex * nhop; + struct vertex * v; + + pthread_mutex_lock(&graph->lock); + + if (graph->nr_vertices == 0) { + pthread_mutex_unlock(&graph->lock); + return 0; + } + + prevs = dijkstra(graph, s_addr); + if (prevs == NULL) { + pthread_mutex_unlock(&graph->lock); + return -1; + } + + *table = malloc(sizeof(**table) * (graph->nr_vertices - 1)); + if (*table == NULL) { + pthread_mutex_unlock(&graph->lock); + free(prevs); + return -1; + } + + /* + * Now loop through the list of predecessors + * to construct the routing table + */ + list_for_each(p, &graph->vertices) { + v = list_entry(p, struct vertex, next); + prev = prevs[i]; + nhop = v; + + /* This is the src */ + if (prev == NULL) { + i++; + continue; + } + + index = get_vertex_index(graph, prev); + while (prevs[index] != NULL) { + nhop = prev; + prev = prevs[index]; + index = get_vertex_index(graph, prev); + } + + (*table)[j] = malloc(sizeof(***table)); + if ((*table)[j] == NULL) { + pthread_mutex_unlock(&graph->lock); + for (k = 0; k < j; ++k) + free((*table)[k]); + free(*table); + free(prevs); + return -1; + } + + (*table)[j]->dst = v->addr; + (*table)[j]->nhop = nhop->addr; + j++; + i++; + } + + pthread_mutex_unlock(&graph->lock); + + free(prevs); + + return j; +} diff --git a/src/ipcpd/normal/pol/graph.h b/src/ipcpd/normal/pol/graph.h new file mode 100644 index 00000000..44496bc3 --- /dev/null +++ b/src/ipcpd/normal/pol/graph.h @@ -0,0 +1,53 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * Undirected graph structure + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef OUROBOROS_IPCPD_NORMAL_GRAPH_H +#define OUROBOROS_IPCPD_NORMAL_GRAPH_H + +#include +#include + +#include + +struct routing_table { + uint64_t dst; + uint64_t nhop; +}; + +struct graph * graph_create(void); + +void graph_destroy(struct graph * graph); + +int graph_update_edge(struct graph * graph, + uint64_t s_addr, + uint64_t d_addr, + qosspec_t qs); + +int graph_del_edge(struct graph * graph, + uint64_t s_addr, + uint64_t d_addr); + +ssize_t graph_routing_table(struct graph * graph, + uint64_t s_addr, + struct routing_table *** table); + +#endif /* OUROBOROS_IPCPD_NORMAL_GRAPH_H */ diff --git a/src/ipcpd/normal/pol/link_state.c b/src/ipcpd/normal/pol/link_state.c new file mode 100644 index 00000000..3e0a63d6 --- /dev/null +++ b/src/ipcpd/normal/pol/link_state.c @@ -0,0 +1,360 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * Link state routing policy + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#define OUROBOROS_PREFIX "link-state-routing" + +#include +#include +#include +#include +#include +#include + +#include "ribmgr.h" +#include "ribconfig.h" +#include "graph.h" +#include "neighbors.h" +#include "ipcp.h" +#include "pff.h" + +#include +#include +#include +#include +#include + +#include "fso.pb-c.h" +typedef Fso fso_t; + +#define BUF_SIZE 256 +#define RECALC_TIME 4 + +struct routing_i { + struct pff * pff; + pthread_t calculator; +}; + +struct { + struct nbs * nbs; + struct nb_notifier nb_notifier; + + struct graph * graph; + + ro_set_t * set; + rqueue_t * queue; + pthread_t rib_listener; +} link_state; + +/* Take under neighbors lock */ +static int addr_to_fd(uint64_t addr) +{ + struct list_head * p = NULL; + + list_for_each(p, &link_state.nbs->list) { + struct nb * e = list_entry(p, struct nb, next); + if (e->conn.conn_info.addr == addr) + return e->conn.flow_info.fd; + } + + return -1; +} + +static void * calculate_pff(void * o) +{ + struct routing_i * instance; + struct routing_table ** table; + ssize_t n_table; + int i; + int fd; + + instance = (struct routing_i *) o; + + while (true) { + table = NULL; + n_table = graph_routing_table(link_state.graph, + ipcpi.dt_addr, &table); + if (n_table < 0) { + sleep(RECALC_TIME); + continue; + } + + pthread_mutex_lock(&link_state.nbs->list_lock); + pff_lock(instance->pff); + + pff_flush(instance->pff); + + for (i = 0; i < n_table; i++) { + fd = addr_to_fd(table[i]->nhop); + if (fd == -1) + continue; + + pff_add(instance->pff, table[i]->dst, fd); + } + + pff_unlock(instance->pff); + pthread_mutex_unlock(&link_state.nbs->list_lock); + + freepp(struct routing_table, table, n_table); + sleep(RECALC_TIME); + } + + return (void *) 0; +} + +static int link_state_neighbor_event(enum nb_event event, + struct conn conn) +{ + char path[RIB_MAX_PATH_LEN + 1]; + char fso_name[RIB_MAX_PATH_LEN + 1]; + fso_t fso = FSO__INIT; + 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); + rib_path_append(rib_path_append(path, ROUTING_NAME), fso_name); + + switch (event) { + case NEIGHBOR_ADDED: + fso.s_addr = ipcpi.dt_addr; + fso.d_addr = conn.conn_info.addr; + + len = fso__get_packed_size(&fso); + if (len == 0) + return -1; + + data = malloc(len); + if (data == NULL) + return -1; + + fso__pack(&fso, data); + + if (rib_add(ROUTING_PATH, fso_name)) { + log_err("Failed to add FSO."); + free(data); + return -1; + } + + if (rib_put(path, data, len)) { + log_err("Failed to put FSO in RIB."); + rib_del(path); + free(data); + return -1; + } + + log_dbg("Added %s to RIB.", path); + + break; + case NEIGHBOR_REMOVED: + if (rib_del(path)) { + log_err("Failed to remove FSO."); + return -1; + } + + log_dbg("Removed %s from RIB.", path); + + break; + case NEIGHBOR_QOS_CHANGE: + log_info("Not currently supported."); + break; + default: + log_info("Unsupported event for routing."); + break; + } + + return 0; +} + +static int read_fso(char * path, + int32_t flag) +{ + ssize_t len; + uint8_t ro[BUF_SIZE]; + fso_t * fso; + qosspec_t qs; + + memset(&qs, 0, sizeof(qs)); + + len = rib_read(path, ro, BUF_SIZE); + if (len < 0) { + log_err("Failed to read FSO."); + return -1; + } + + fso = fso__unpack(NULL, len, ro); + if (fso == NULL) { + log_err("Failed to unpack."); + return -1; + } + + if (flag & RO_MODIFY) { + if (graph_update_edge(link_state.graph, + fso->s_addr, fso->d_addr, qs)) { + fso__free_unpacked(fso, NULL); + return -1; + } + } else if (flag & RO_DELETE) { + if (graph_del_edge(link_state.graph, fso->s_addr, fso->d_addr)) { + fso__free_unpacked(fso, NULL); + return -1; + } + } + + fso__free_unpacked(fso, NULL); + + return 0; +} + +static void * rib_listener(void * o) +{ + int32_t flag; + char path[RIB_MAX_PATH_LEN + 1]; + char ** children; + ssize_t len; + int i; + + (void) o; + + if (ro_set_add(link_state.set, ROUTING_PATH, RO_MODIFY | RO_DELETE)) { + log_err("Failed to add to RO set"); + return (void * ) -1; + } + + len = rib_children(ROUTING_PATH, &children); + if (len < 0) { + log_err("Failed to retrieve children."); + return (void *) -1; + } + + for (i = 0; i < len; i++) { + if (read_fso(children[i], RO_CREATE)) { + log_err("Failed to parse FSO."); + continue; + } + } + + while (rib_event_wait(link_state.set, link_state.queue, NULL) == 0) { + path[0] = '\0'; + flag = rqueue_next(link_state.queue, path); + if (flag < 0) + continue; + + if (read_fso(path, flag)) { + log_err("Failed to parse FSO."); + continue; + } + } + + return (void *) 0; +} + +struct routing_i * link_state_routing_i_create(struct pff * pff) +{ + struct routing_i * tmp; + + assert(pff); + + tmp = malloc(sizeof(*tmp)); + if (tmp == NULL) + return NULL; + + tmp->pff = pff; + + pthread_create(&tmp->calculator, NULL, calculate_pff, (void *) tmp); + + return tmp; +} + +void link_state_routing_i_destroy(struct routing_i * instance) +{ + assert(instance); + + pthread_cancel(instance->calculator); + + pthread_join(instance->calculator, NULL); + + free(instance); +} + +int link_state_init(struct nbs * nbs) +{ + link_state.graph = graph_create(); + if (link_state.graph == NULL) + return -1; + + if (rib_add(RIB_ROOT, ROUTING_NAME)) { + graph_destroy(link_state.graph); + return -1; + } + + 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; + } + + 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; + } + + 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; + } + + pthread_create(&link_state.rib_listener, NULL, rib_listener, NULL); + + return 0; +} + +void link_state_fini(void) +{ + pthread_cancel(link_state.rib_listener); + + pthread_join(link_state.rib_listener, NULL); + + rqueue_destroy(link_state.queue); + + ro_set_destroy(link_state.set); + + graph_destroy(link_state.graph); + + rib_del(ROUTING_PATH); + + nbs_unreg_notifier(link_state.nbs, &link_state.nb_notifier); +} diff --git a/src/ipcpd/normal/pol/link_state.h b/src/ipcpd/normal/pol/link_state.h new file mode 100644 index 00000000..e78d0543 --- /dev/null +++ b/src/ipcpd/normal/pol/link_state.h @@ -0,0 +1,43 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * Link state routing policy + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef OUROBOROS_IPCPD_NORMAL_POL_LINK_STATE_H +#define OUROBOROS_IPCPD_NORMAL_POL_LINK_STATE_H + +#include "pol-routing-ops.h" + +int link_state_init(struct nbs * nbs); + +void link_state_fini(void); + +struct routing_i * link_state_routing_i_create(struct pff * pff); + +void link_state_routing_i_destroy(struct routing_i * instance); + +struct pol_routing_ops link_state_ops = { + .init = link_state_init, + .fini = link_state_fini, + .routing_i_create = link_state_routing_i_create, + .routing_i_destroy = link_state_routing_i_destroy +}; + +#endif /* OUROBOROS_IPCPD_NORMAL_POL_LINK_STATE_H */ diff --git a/src/ipcpd/normal/pol/tests/CMakeLists.txt b/src/ipcpd/normal/pol/tests/CMakeLists.txt new file mode 100644 index 00000000..55ca425a --- /dev/null +++ b/src/ipcpd/normal/pol/tests/CMakeLists.txt @@ -0,0 +1,34 @@ +get_filename_component(CURRENT_SOURCE_PARENT_DIR + ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) +get_filename_component(CURRENT_BINARY_PARENT_DIR + ${CMAKE_CURRENT_BINARY_DIR} DIRECTORY) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +include_directories(${CURRENT_SOURCE_PARENT_DIR}) +include_directories(${CURRENT_BINARY_PARENT_DIR}) + +include_directories(${CMAKE_SOURCE_DIR}/include) +include_directories(${CMAKE_BINARY_DIR}/include) + +get_filename_component(PARENT_PATH ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) +get_filename_component(PARENT_DIR ${PARENT_PATH} NAME) + +create_test_sourcelist(${PARENT_DIR}_tests test_suite.c + # Add new tests here + graph_test.c + ) + +add_executable(${PARENT_DIR}_test EXCLUDE_FROM_ALL ${${PARENT_DIR}_tests}) +target_link_libraries(${PARENT_DIR}_test ouroboros) + +add_dependencies(check ${PARENT_DIR}_test) + +set(tests_to_run ${${PARENT_DIR}_tests}) +remove(tests_to_run test_suite.c) + +foreach (test ${tests_to_run}) + get_filename_component(test_name ${test} NAME_WE) + add_test(${test_name} ${C_TEST_PATH}/${PARENT_DIR}_test ${test_name}) +endforeach (test) diff --git a/src/ipcpd/normal/pol/tests/graph_test.c b/src/ipcpd/normal/pol/tests/graph_test.c new file mode 100644 index 00000000..3d433e34 --- /dev/null +++ b/src/ipcpd/normal/pol/tests/graph_test.c @@ -0,0 +1,240 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * Test of the graph structure + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include + +#include +#include +#include + +#include "graph.c" + +struct graph * graph; +struct routing_table ** table; +ssize_t n_table; +qosspec_t qs; + +int graph_test_entries(int entries) +{ + n_table = graph_routing_table(graph, 1, &table); + + if (n_table != entries) { + printf("Wrong number of entries.\n"); + freepp(struct routing_table, table, n_table); + return -1; + } + + freepp(struct routing_table, table, n_table); + + return 0; +} + +int graph_test_double_link(void) +{ + n_table = graph_routing_table(graph, 1, &table); + if (n_table < 0 || table == NULL) { + printf("Failed to get routing table.\n"); + return -1; + } + + if (n_table != 2) { + printf("Wrong number of entries.\n"); + freepp(struct routing_table, table, n_table); + return -1; + } + + if ((table[0]->dst != 2 && table[0]->nhop != 2) || + (table[0]->dst != 3 && table[0]->nhop != 2)) { + printf("Wrong routing entry.\n"); + freepp(struct routing_table, table, n_table); + return -1; + } + + if ((table[1]->dst != 2 && table[1]->nhop != 2) || + (table[0]->dst != 3 && table[0]->nhop != 2)) { + printf("Wrong routing entry.\n"); + freepp(struct routing_table, table, n_table); + return -1; + } + + freepp(struct routing_table, table, n_table); + + return 0; +} + +int graph_test_single_link(void) +{ + n_table = graph_routing_table(graph, 1, &table); + if (n_table < 0 || table == NULL) { + printf("Failed to get routing table.\n"); + return -1; + } + + if (n_table != 1) { + printf("Wrong number of entries.\n"); + freepp(struct routing_table, table, n_table); + return -1; + } + + if (table[0]->dst != 2 && table[0]->nhop != 2) { + printf("Wrong routing entry.\n"); + freepp(struct routing_table, table, n_table); + return -1; + } + + freepp(struct routing_table, table, n_table); + + return 0; +} + +int graph_test(int argc, + char ** argv) +{ + int i; + int nhop; + int dst; + + (void) argc; + (void) argv; + + memset(&qs, 0, sizeof(qs)); + + graph = graph_create(); + if (graph == NULL) { + printf("Failed to create graph.\n"); + return -1; + } + + graph_destroy(graph); + + graph = graph_create(); + if (graph == NULL) { + printf("Failed to create graph.\n"); + return -1; + } + + if (graph_update_edge(graph, 1, 2, qs)) { + printf("Failed to add edge.\n"); + graph_destroy(graph); + return -1; + } + + if (graph_test_single_link()) { + graph_destroy(graph); + return -1; + } + + if (graph_update_edge(graph, 2, 3, qs)) { + printf("Failed to add edge.\n"); + graph_destroy(graph); + return -1; + } + + if (graph_test_double_link()) { + graph_destroy(graph); + return -1; + } + + if (graph_del_edge(graph, 2, 3)) { + printf("Failed to delete edge.\n"); + graph_destroy(graph); + return -1; + } + + if (graph_test_single_link()) { + graph_destroy(graph); + return -1; + } + + graph_update_edge(graph, 2, 3, qs); + graph_update_edge(graph, 1, 3, qs); + + if (graph_test_entries(2)) { + graph_destroy(graph); + return -1; + } + + graph_update_edge(graph, 3, 4, qs); + graph_update_edge(graph, 4, 5, qs); + + if (graph_test_entries(4)) { + graph_destroy(graph); + return -1; + } + + graph_update_edge(graph, 2, 6, qs); + graph_update_edge(graph, 6, 7, qs); + graph_update_edge(graph, 3, 7, qs); + + if (graph_test_entries(6)) { + graph_destroy(graph); + return -1; + } + + n_table = graph_routing_table(graph, 1, &table); + + for (i = 0; i < 6; i++) { + nhop = table[i]->nhop; + dst = table[i]->dst; + + if (dst == 3 && nhop != 3) { + printf("Wrong entry."); + freepp(struct routing_table, table, n_table); + return -1; + } + + if (dst == 2 && nhop != 2) { + printf("Wrong entry."); + freepp(struct routing_table, table, n_table); + return -1; + } + + if (dst == 6 && nhop != 2) { + printf("Wrong entry."); + freepp(struct routing_table, table, n_table); + return -1; + } + + if (dst == 4 && nhop != 3) { + printf("Wrong entry."); + freepp(struct routing_table, table, n_table); + return -1; + } + + if (dst == 5 && nhop != 3) { + printf("Wrong entry."); + freepp(struct routing_table, table, n_table); + return -1; + } + + if (dst == 7 && nhop != 3) { + printf("Wrong entry."); + freepp(struct routing_table, table, n_table); + return -1; + } + } + + freepp(struct routing_table, table, n_table); + + return 0; +} diff --git a/src/ipcpd/normal/ribconfig.h b/src/ipcpd/normal/ribconfig.h index 2f5daf72..31c79fbe 100644 --- a/src/ipcpd/normal/ribconfig.h +++ b/src/ipcpd/normal/ribconfig.h @@ -26,14 +26,14 @@ /* RIB configuration for normal */ #define RIB_MAX_PATH_LEN 256 -#define DLR "/" -#define BOOT_NAME "boot" -#define MEMBERS_NAME "members" -#define DIR_NAME "directory" -#define ROUTING_NAME "fsdb" -#define DIR_PATH DLR DIR_NAME -#define BOOT_PATH DLR BOOT_NAME -#define MEMBERS_PATH DLR MEMBERS_NAME -#define ROUTING_PATH DLR ROUTING_NAME +#define DLR "/" +#define BOOT_NAME "boot" +#define MEMBERS_NAME "members" +#define DIR_NAME "directory" +#define ROUTING_NAME "fsdb" +#define DIR_PATH DLR DIR_NAME +#define BOOT_PATH DLR BOOT_NAME +#define MEMBERS_PATH DLR MEMBERS_NAME +#define ROUTING_PATH DLR ROUTING_NAME #endif /* OUROBOROS_IPCPD_NORMAL_RIB_CONFIG_H */ diff --git a/src/ipcpd/normal/routing.c b/src/ipcpd/normal/routing.c index cc6cdca8..e1459c15 100644 --- a/src/ipcpd/normal/routing.c +++ b/src/ipcpd/normal/routing.c @@ -23,338 +23,41 @@ #define OUROBOROS_PREFIX "routing" #include -#include -#include #include -#include -#include -#include #include "routing.h" -#include "ribmgr.h" -#include "ribconfig.h" -#include "ipcp.h" -#include "graph.h" -#include "neighbors.h" - -#include -#include -#include -#include - -#include "fso.pb-c.h" -typedef Fso fso_t; - -#define BUF_SIZE 256 -#define RECALC_TIME 4 - -struct routing_i { - struct pff * pff; - pthread_t calculator; -}; +#include "pol/link_state.h" struct { - struct nbs * nbs; - struct nb_notifier nb_notifier; - - struct graph * graph; - - ro_set_t * set; - rqueue_t * queue; - pthread_t rib_listener; + struct pol_routing_ops * ops; } routing; -/* Take under neighbors lock */ -static int addr_to_fd(uint64_t addr) -{ - struct list_head * p = NULL; - - list_for_each(p, &routing.nbs->list) { - struct nb * e = list_entry(p, struct nb, next); - if (e->conn.conn_info.addr == addr) - return e->conn.flow_info.fd; - } - - return -1; -} - -static void * calculate_pff(void * o) -{ - struct routing_i * instance; - struct routing_table ** table; - ssize_t n_table; - int i; - int fd; - - instance = (struct routing_i *) o; - - while (true) { - table = NULL; - n_table = graph_routing_table(routing.graph, - ipcpi.dt_addr, &table); - if (n_table < 0) { - sleep(RECALC_TIME); - continue; - } - - pthread_mutex_lock(&routing.nbs->list_lock); - pff_lock(instance->pff); - - pff_flush(instance->pff); - - for (i = 0; i < n_table; i++) { - fd = addr_to_fd(table[i]->nhop); - if (fd == -1) - continue; - - pff_add(instance->pff, table[i]->dst, fd); - } - - pff_unlock(instance->pff); - pthread_mutex_unlock(&routing.nbs->list_lock); - - freepp(struct routing_table, table, n_table); - sleep(RECALC_TIME); - } - - return (void *) 0; -} - -struct routing_i * routing_i_create(struct pff * pff) -{ - struct routing_i * tmp; - - assert(pff); - - tmp = malloc(sizeof(*tmp)); - if (tmp == NULL) - return NULL; - - tmp->pff = pff; - - pthread_create(&tmp->calculator, NULL, calculate_pff, (void *) tmp); - - return tmp; -} - -void routing_i_destroy(struct routing_i * instance) -{ - assert(instance); - - pthread_cancel(instance->calculator); - - pthread_join(instance->calculator, NULL); - - free(instance); -} - -static int routing_neighbor_event(enum nb_event event, - struct conn conn) +int routing_init(enum pol_routing pr, + struct nbs * nbs) { - char path[RIB_MAX_PATH_LEN + 1]; - char fso_name[RIB_MAX_PATH_LEN + 1]; - fso_t fso = FSO__INIT; - 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); - rib_path_append(rib_path_append(path, ROUTING_NAME), fso_name); - - switch (event) { - case NEIGHBOR_ADDED: - fso.s_addr = ipcpi.dt_addr; - fso.d_addr = conn.conn_info.addr; - - len = fso__get_packed_size(&fso); - if (len == 0) - return -1; - - data = malloc(len); - if (data == NULL) - return -1; - - fso__pack(&fso, data); - - if (rib_add(ROUTING_PATH, fso_name)) { - log_err("Failed to add FSO."); - free(data); - return -1; - } - - if (rib_put(path, data, len)) { - log_err("Failed to put FSO in RIB."); - rib_del(path); - free(data); - return -1; - } - - log_dbg("Added %s to RIB.", path); - - break; - case NEIGHBOR_REMOVED: - if (rib_del(path)) { - log_err("Failed to remove FSO."); - return -1; - } - - log_dbg("Removed %s from RIB.", path); - - break; - case NEIGHBOR_QOS_CHANGE: - log_info("Not currently supported."); + switch (pr) { + case LINK_STATE: + routing.ops = &link_state_ops; break; default: - log_info("Unsupported event for routing."); - break; - } - - return 0; -} - -static int read_fso(char * path, - int32_t flag) -{ - ssize_t len; - uint8_t ro[BUF_SIZE]; - fso_t * fso; - qosspec_t qs; - - memset(&qs, 0, sizeof(qs)); - - len = rib_read(path, ro, BUF_SIZE); - if (len < 0) { - log_err("Failed to read FSO."); - return -1; - } - - fso = fso__unpack(NULL, len, ro); - if (fso == NULL) { - log_err("Failed to unpack."); + log_err("Unknown routing type."); return -1; } - if (flag & RO_MODIFY) { - if (graph_update_edge(routing.graph, - fso->s_addr, fso->d_addr, qs)) { - fso__free_unpacked(fso, NULL); - return -1; - } - } else if (flag & RO_DELETE) { - if (graph_del_edge(routing.graph, fso->s_addr, fso->d_addr)) { - fso__free_unpacked(fso, NULL); - return -1; - } - } - - fso__free_unpacked(fso, NULL); - - return 0; + return routing.ops->init(nbs); } -static void * rib_listener(void * o) +struct routing_i * routing_i_create(struct pff * pff) { - int32_t flag; - char path[RIB_MAX_PATH_LEN + 1]; - char ** children; - ssize_t len; - int i; - - (void) o; - - if (ro_set_add(routing.set, ROUTING_PATH, RO_MODIFY | RO_DELETE)) { - log_err("Failed to add to RO set"); - return (void * ) -1; - } - - len = rib_children(ROUTING_PATH, &children); - if (len < 0) { - log_err("Failed to retrieve children."); - return (void *) -1; - } - - for (i = 0; i < len; i++) { - if (read_fso(children[i], RO_CREATE)) { - log_err("Failed to parse FSO."); - continue; - } - } - - while (rib_event_wait(routing.set, routing.queue, NULL) == 0) { - path[0] = '\0'; - flag = rqueue_next(routing.queue, path); - if (flag < 0) - continue; - - if (read_fso(path, flag)) { - log_err("Failed to parse FSO."); - continue; - } - } - - return (void *) 0; + return routing.ops->routing_i_create(pff); } -int routing_init(struct nbs * nbs) +void routing_i_destroy(struct routing_i * instance) { - routing.graph = graph_create(); - if (routing.graph == NULL) - return -1; - - if (rib_add(RIB_ROOT, ROUTING_NAME)) { - graph_destroy(routing.graph); - return -1; - } - - routing.nbs = nbs; - - routing.nb_notifier.notify_call = routing_neighbor_event; - if (nbs_reg_notifier(routing.nbs, &routing.nb_notifier)) { - graph_destroy(routing.graph); - rib_del(ROUTING_PATH); - return -1; - } - - routing.set = ro_set_create(); - if (routing.set == NULL) { - nbs_unreg_notifier(routing.nbs, &routing.nb_notifier); - graph_destroy(routing.graph); - rib_del(ROUTING_PATH); - return -1; - } - - routing.queue = rqueue_create(); - if (routing.queue == NULL) { - ro_set_destroy(routing.set); - nbs_unreg_notifier(routing.nbs, &routing.nb_notifier); - graph_destroy(routing.graph); - rib_del(ROUTING_PATH); - return -1; - } - - pthread_create(&routing.rib_listener, NULL, rib_listener, NULL); - - return 0; + return routing.ops->routing_i_destroy(instance); } void routing_fini(void) { - pthread_cancel(routing.rib_listener); - - pthread_join(routing.rib_listener, NULL); - - rqueue_destroy(routing.queue); - - ro_set_destroy(routing.set); - - graph_destroy(routing.graph); - - rib_del(ROUTING_PATH); - - nbs_unreg_notifier(routing.nbs, &routing.nb_notifier); + routing.ops->fini(); } diff --git a/src/ipcpd/normal/routing.h b/src/ipcpd/normal/routing.h index 0794ef28..7e47a425 100644 --- a/src/ipcpd/normal/routing.h +++ b/src/ipcpd/normal/routing.h @@ -23,6 +23,7 @@ #ifndef OUROBOROS_IPCPD_NORMAL_ROUTING_H #define OUROBOROS_IPCPD_NORMAL_ROUTING_H +#include #include #include "pff.h" @@ -30,11 +31,8 @@ #include -/* - * Routing will take a type in the future, - * to allow different policies. - */ -int routing_init(struct nbs * nbs); +int routing_init(enum pol_routing pr, + struct nbs * nbs); void routing_fini(void); diff --git a/src/ipcpd/normal/tests/CMakeLists.txt b/src/ipcpd/normal/tests/CMakeLists.txt deleted file mode 100644 index 55ca425a..00000000 --- a/src/ipcpd/normal/tests/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -get_filename_component(CURRENT_SOURCE_PARENT_DIR - ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) -get_filename_component(CURRENT_BINARY_PARENT_DIR - ${CMAKE_CURRENT_BINARY_DIR} DIRECTORY) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - -include_directories(${CURRENT_SOURCE_PARENT_DIR}) -include_directories(${CURRENT_BINARY_PARENT_DIR}) - -include_directories(${CMAKE_SOURCE_DIR}/include) -include_directories(${CMAKE_BINARY_DIR}/include) - -get_filename_component(PARENT_PATH ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) -get_filename_component(PARENT_DIR ${PARENT_PATH} NAME) - -create_test_sourcelist(${PARENT_DIR}_tests test_suite.c - # Add new tests here - graph_test.c - ) - -add_executable(${PARENT_DIR}_test EXCLUDE_FROM_ALL ${${PARENT_DIR}_tests}) -target_link_libraries(${PARENT_DIR}_test ouroboros) - -add_dependencies(check ${PARENT_DIR}_test) - -set(tests_to_run ${${PARENT_DIR}_tests}) -remove(tests_to_run test_suite.c) - -foreach (test ${tests_to_run}) - get_filename_component(test_name ${test} NAME_WE) - add_test(${test_name} ${C_TEST_PATH}/${PARENT_DIR}_test ${test_name}) -endforeach (test) diff --git a/src/ipcpd/normal/tests/graph_test.c b/src/ipcpd/normal/tests/graph_test.c deleted file mode 100644 index 3d433e34..00000000 --- a/src/ipcpd/normal/tests/graph_test.c +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * Test of the graph structure - * - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include - -#include -#include -#include - -#include "graph.c" - -struct graph * graph; -struct routing_table ** table; -ssize_t n_table; -qosspec_t qs; - -int graph_test_entries(int entries) -{ - n_table = graph_routing_table(graph, 1, &table); - - if (n_table != entries) { - printf("Wrong number of entries.\n"); - freepp(struct routing_table, table, n_table); - return -1; - } - - freepp(struct routing_table, table, n_table); - - return 0; -} - -int graph_test_double_link(void) -{ - n_table = graph_routing_table(graph, 1, &table); - if (n_table < 0 || table == NULL) { - printf("Failed to get routing table.\n"); - return -1; - } - - if (n_table != 2) { - printf("Wrong number of entries.\n"); - freepp(struct routing_table, table, n_table); - return -1; - } - - if ((table[0]->dst != 2 && table[0]->nhop != 2) || - (table[0]->dst != 3 && table[0]->nhop != 2)) { - printf("Wrong routing entry.\n"); - freepp(struct routing_table, table, n_table); - return -1; - } - - if ((table[1]->dst != 2 && table[1]->nhop != 2) || - (table[0]->dst != 3 && table[0]->nhop != 2)) { - printf("Wrong routing entry.\n"); - freepp(struct routing_table, table, n_table); - return -1; - } - - freepp(struct routing_table, table, n_table); - - return 0; -} - -int graph_test_single_link(void) -{ - n_table = graph_routing_table(graph, 1, &table); - if (n_table < 0 || table == NULL) { - printf("Failed to get routing table.\n"); - return -1; - } - - if (n_table != 1) { - printf("Wrong number of entries.\n"); - freepp(struct routing_table, table, n_table); - return -1; - } - - if (table[0]->dst != 2 && table[0]->nhop != 2) { - printf("Wrong routing entry.\n"); - freepp(struct routing_table, table, n_table); - return -1; - } - - freepp(struct routing_table, table, n_table); - - return 0; -} - -int graph_test(int argc, - char ** argv) -{ - int i; - int nhop; - int dst; - - (void) argc; - (void) argv; - - memset(&qs, 0, sizeof(qs)); - - graph = graph_create(); - if (graph == NULL) { - printf("Failed to create graph.\n"); - return -1; - } - - graph_destroy(graph); - - graph = graph_create(); - if (graph == NULL) { - printf("Failed to create graph.\n"); - return -1; - } - - if (graph_update_edge(graph, 1, 2, qs)) { - printf("Failed to add edge.\n"); - graph_destroy(graph); - return -1; - } - - if (graph_test_single_link()) { - graph_destroy(graph); - return -1; - } - - if (graph_update_edge(graph, 2, 3, qs)) { - printf("Failed to add edge.\n"); - graph_destroy(graph); - return -1; - } - - if (graph_test_double_link()) { - graph_destroy(graph); - return -1; - } - - if (graph_del_edge(graph, 2, 3)) { - printf("Failed to delete edge.\n"); - graph_destroy(graph); - return -1; - } - - if (graph_test_single_link()) { - graph_destroy(graph); - return -1; - } - - graph_update_edge(graph, 2, 3, qs); - graph_update_edge(graph, 1, 3, qs); - - if (graph_test_entries(2)) { - graph_destroy(graph); - return -1; - } - - graph_update_edge(graph, 3, 4, qs); - graph_update_edge(graph, 4, 5, qs); - - if (graph_test_entries(4)) { - graph_destroy(graph); - return -1; - } - - graph_update_edge(graph, 2, 6, qs); - graph_update_edge(graph, 6, 7, qs); - graph_update_edge(graph, 3, 7, qs); - - if (graph_test_entries(6)) { - graph_destroy(graph); - return -1; - } - - n_table = graph_routing_table(graph, 1, &table); - - for (i = 0; i < 6; i++) { - nhop = table[i]->nhop; - dst = table[i]->dst; - - if (dst == 3 && nhop != 3) { - printf("Wrong entry."); - freepp(struct routing_table, table, n_table); - return -1; - } - - if (dst == 2 && nhop != 2) { - printf("Wrong entry."); - freepp(struct routing_table, table, n_table); - return -1; - } - - if (dst == 6 && nhop != 2) { - printf("Wrong entry."); - freepp(struct routing_table, table, n_table); - return -1; - } - - if (dst == 4 && nhop != 3) { - printf("Wrong entry."); - freepp(struct routing_table, table, n_table); - return -1; - } - - if (dst == 5 && nhop != 3) { - printf("Wrong entry."); - freepp(struct routing_table, table, n_table); - return -1; - } - - if (dst == 7 && nhop != 3) { - printf("Wrong entry."); - freepp(struct routing_table, table, n_table); - return -1; - } - } - - freepp(struct routing_table, table, n_table); - - return 0; -} diff --git a/src/lib/ipcp_config.proto b/src/lib/ipcp_config.proto index b6c8c303..25516c2c 100644 --- a/src/lib/ipcp_config.proto +++ b/src/lib/ipcp_config.proto @@ -38,9 +38,10 @@ message ipcp_config_msg { optional uint32 addr_auth_type = 6; optional uint32 dt_gam_type = 7; optional uint32 rm_gam_type = 8; + optional uint32 routing_type = 9; // Config for shim UDP - optional uint32 ip_addr = 9; - optional uint32 dns_addr = 10; + optional uint32 ip_addr = 10; + optional uint32 dns_addr = 11; // Config for the shim Ethernet LLC - optional string if_name = 11; + optional string if_name = 12; } diff --git a/src/lib/irm.c b/src/lib/irm.c index d2f85bbf..68202ad9 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -126,6 +126,8 @@ int irm_bootstrap_ipcp(pid_t api, config.dt_gam_type = conf->dt_gam_type; config.has_rm_gam_type = true; config.rm_gam_type = conf->rm_gam_type; + config.has_routing_type = true; + config.routing_type = conf->routing_type; break; case IPCP_SHIM_UDP: config.has_ip_addr = true; diff --git a/src/tools/irm/irm_ipcp_bootstrap.c b/src/tools/irm/irm_ipcp_bootstrap.c index 44fdfb3d..6457a983 100644 --- a/src/tools/irm/irm_ipcp_bootstrap.c +++ b/src/tools/irm/irm_ipcp_bootstrap.c @@ -46,18 +46,19 @@ #define SHA3_384 "SHA3_384" #define SHA3_512 "SHA3_512" -#define DEFAULT_HASH_ALGO HASH_SHA3_256 -#define DEFAULT_HASH_STR SHA3_256 -#define DEFAULT_ADDR_SIZE 4 -#define DEFAULT_FD_SIZE 2 -#define DEFAULT_DDNS 0 -#define DEFAULT_ADDR_AUTH FLAT_RANDOM -#define DEFAULT_DT_GAM COMPLETE -#define DEFAULT_RM_GAM COMPLETE -#define ADDR_AUTH_FLAT "flat" - -#define DT_GAM_COMPLETE "complete" -#define RM_GAM_COMPLETE "complete" +#define DEFAULT_HASH_ALGO HASH_SHA3_256 +#define DEFAULT_HASH_STR SHA3_256 +#define DEFAULT_ADDR_SIZE 4 +#define DEFAULT_FD_SIZE 2 +#define DEFAULT_DDNS 0 +#define DEFAULT_ADDR_AUTH FLAT_RANDOM +#define DEFAULT_DT_GAM COMPLETE +#define DEFAULT_RM_GAM COMPLETE +#define DEFAULT_ROUTING LINK_STATE +#define ADDR_AUTH_FLAT "flat" +#define DT_GAM_COMPLETE "complete" +#define RM_GAM_COMPLETE "complete" +#define ROUTING_LINK_STATE "link_state" static void usage(void) { @@ -80,6 +81,7 @@ static void usage(void) " (default: %s)]\n" " [rm_gam " " (default: %s)]\n" + " [routing (default: %s)]\n" "if TYPE == " SHIM_UDP "\n" " ip \n" " [dns " @@ -87,7 +89,8 @@ static void usage(void) "if TYPE == " SHIM_ETH_LLC "\n" " if_name \n", DEFAULT_HASH_STR, DEFAULT_ADDR_SIZE, DEFAULT_FD_SIZE, - ADDR_AUTH_FLAT, DT_GAM_COMPLETE, RM_GAM_COMPLETE, DEFAULT_DDNS); + ADDR_AUTH_FLAT, DT_GAM_COMPLETE, RM_GAM_COMPLETE, + ROUTING_LINK_STATE, DEFAULT_DDNS); } int do_bootstrap_ipcp(int argc, char ** argv) @@ -102,6 +105,7 @@ int do_bootstrap_ipcp(int argc, char ** argv) enum pol_addr_auth addr_auth_type = DEFAULT_ADDR_AUTH; enum pol_gam dt_gam_type = DEFAULT_DT_GAM; enum pol_gam rm_gam_type = DEFAULT_RM_GAM; + enum pol_routing routing_type = DEFAULT_ROUTING; uint32_t ip_addr = 0; uint32_t dns_addr = DEFAULT_DDNS; char * ipcp_type = NULL; @@ -149,6 +153,9 @@ int do_bootstrap_ipcp(int argc, char ** argv) } else if (matches(*argv, "rm_gam") == 0) { if (strcmp(RM_GAM_COMPLETE, *(argv + 1)) == 0) rm_gam_type = COMPLETE; + } else if (matches(*argv, "routing") == 0) { + if (strcmp(ROUTING_LINK_STATE, *(argv + 1)) == 0) + routing_type = LINK_STATE; } else { printf("\"%s\" is unknown, try \"irm " "ipcp bootstrap\".\n", *argv); @@ -191,6 +198,7 @@ int do_bootstrap_ipcp(int argc, char ** argv) conf.addr_auth_type = addr_auth_type; conf.dt_gam_type = dt_gam_type; conf.rm_gam_type = rm_gam_type; + conf.routing_type = routing_type; } else if (strcmp(ipcp_type, SHIM_UDP) == 0) { conf.type = IPCP_SHIM_UDP; if (ip_addr == 0) { -- cgit v1.2.3