From 9de8dc4948cf7ce239232aae0889c39ffa39ede2 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Mon, 28 Aug 2017 18:54:22 +0200 Subject: tools: Add tool to connect IPCP components This enables user-written tools to instruct IPCPs to establish and tear down connections (a.k.a. adjacencies) between its internal components (Management and Data Transfer). For more info, do "irm ipcp connect" or "irm ipcp disconnect" on the command line. This commit exposes a deletion bug in the RIB where FSO's fail to unpack/parse. This will be fixed when the RIB is deprecated. --- src/tools/irm/irm_ipcp_connect.c | 94 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/tools/irm/irm_ipcp_connect.c (limited to 'src/tools/irm/irm_ipcp_connect.c') diff --git a/src/tools/irm/irm_ipcp_connect.c b/src/tools/irm/irm_ipcp_connect.c new file mode 100644 index 00000000..168c8d17 --- /dev/null +++ b/src/tools/irm/irm_ipcp_connect.c @@ -0,0 +1,94 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * Connect components of normal IPC Processes + * + * 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/. + */ + +#include + +#include "irm_ops.h" +#include "irm_utils.h" + +#include +#include +#include + +#define DT "dt" +#define MGMT "mgmt" + +static void usage(void) +{ + printf("Usage: irm ipcp connect\n" + " name \n" + " comp \n" + " dst \n" + "where COMPONENT = {" DT " " MGMT "},\n\n"); +} + +int do_connect_ipcp(int argc, + char ** argv) +{ + char * name = NULL; + char * dst_name = NULL; + char * comp_name = NULL; + pid_t * apis = NULL; + ssize_t len = 0; + + while (argc > 0) { + if (strcmp(*argv, "name") == 0) { + name = *(argv + 1); + } else if (matches(*argv, "dst") == 0) { + dst_name = *(argv + 1); + } else if (matches(*argv, "comp") == 0) { + comp_name = *(argv + 1); + } else { + printf("\"%s\" is unknown, try \"irm " + "ipcpi connect\".\n", *argv); + return -1; + } + + argc -= 2; + argv += 2; + } + + if (name == NULL || dst_name == NULL || comp_name == NULL) { + usage(); + return -1; + } + + len = irm_list_ipcps(name, &apis); + if (len != 1) + return -1; + + if (!strcmp(comp_name, DT)) + comp_name = DT_AE; + + if (!strcmp(comp_name , MGMT)) + comp_name = MGMT_AE; + + if (irm_connect_ipcp(apis[0], dst_name, comp_name)) { + free(apis); + return -1; + } + + if (apis != NULL) + free(apis); + + return 0; +} -- cgit v1.2.3