From 0d789ed8d938cc342c8f2138280795a1d5a61e3d Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Tue, 28 Jun 2016 16:11:19 +0200 Subject: lib, irmd, ipcpd: Change of IRM API This changes the IRM API after discussions with Dimitri. The register operation is now split into a bind and register operation. The same for unregister; unbind and unregister. PIDs are now used as the application instance name. A name for a PID is only provided for scriptability in bash. It is therefore also no longer passed down to the IPCP. Every operation on an IPCP through the IRM API has to use the PID. Quering of the PIDs by name is possible. The IRM tool has been updated to use this new API as well. A subcommand 'ipcp' has been added for operations that take effect on IPCPs only. Fixes #12 --- src/tools/irm/CMakeLists.txt | 11 +- src/tools/irm/irm.c | 16 ++- src/tools/irm/irm_bind.c | 81 +++++++++++++++ src/tools/irm/irm_bootstrap_ipcp.c | 192 ----------------------------------- src/tools/irm/irm_create_ipcp.c | 89 ----------------- src/tools/irm/irm_destroy_ipcp.c | 63 ------------ src/tools/irm/irm_enroll_ipcp.c | 67 ------------- src/tools/irm/irm_ipcp.c | 77 ++++++++++++++ src/tools/irm/irm_ipcp_bootstrap.c | 200 +++++++++++++++++++++++++++++++++++++ src/tools/irm/irm_ipcp_create.c | 85 ++++++++++++++++ src/tools/irm/irm_ipcp_destroy.c | 70 +++++++++++++ src/tools/irm/irm_ipcp_enroll.c | 74 ++++++++++++++ src/tools/irm/irm_ops.h | 4 + src/tools/irm/irm_register.c | 66 ++---------- src/tools/irm/irm_unbind.c | 63 ++++++++++++ src/tools/irm/irm_unregister.c | 53 ++-------- 16 files changed, 682 insertions(+), 529 deletions(-) create mode 100644 src/tools/irm/irm_bind.c delete mode 100644 src/tools/irm/irm_bootstrap_ipcp.c delete mode 100644 src/tools/irm/irm_create_ipcp.c delete mode 100644 src/tools/irm/irm_destroy_ipcp.c delete mode 100644 src/tools/irm/irm_enroll_ipcp.c create mode 100644 src/tools/irm/irm_ipcp.c create mode 100644 src/tools/irm/irm_ipcp_bootstrap.c create mode 100644 src/tools/irm/irm_ipcp_create.c create mode 100644 src/tools/irm/irm_ipcp_destroy.c create mode 100644 src/tools/irm/irm_ipcp_enroll.c create mode 100644 src/tools/irm/irm_unbind.c (limited to 'src/tools/irm') diff --git a/src/tools/irm/CMakeLists.txt b/src/tools/irm/CMakeLists.txt index d1f227a8..68297615 100644 --- a/src/tools/irm/CMakeLists.txt +++ b/src/tools/irm/CMakeLists.txt @@ -7,10 +7,13 @@ include_directories(${CMAKE_BINARY_DIR}/include) set(SOURCE_FILES # Add source files here irm.c - irm_create_ipcp.c - irm_destroy_ipcp.c - irm_bootstrap_ipcp.c - irm_enroll_ipcp.c + irm_ipcp_create.c + irm_ipcp_destroy.c + irm_ipcp_bootstrap.c + irm_ipcp_enroll.c + irm_unbind.c + irm_bind.c + irm_ipcp.c irm_register.c irm_unregister.c irm_utils.c diff --git a/src/tools/irm/irm.c b/src/tools/irm/irm.c index a1dc5ade..14420207 100644 --- a/src/tools/irm/irm.c +++ b/src/tools/irm/irm.c @@ -21,7 +21,6 @@ */ #include -#include #include #include #include @@ -32,10 +31,8 @@ static void usage() { printf("Usage: irm [OPERATION]\n\n" - "where OPERATION = {create_ipcp destroy_ipcp \n" - " bootstrap_ipcp enroll_ipcp\n" - " register unregister\n" - " register_ipcp unregister_ipcp\n"); + "where OPERATION = {ipcp bind unbind\n" + " register unregister\n"); } static int do_help(int argc, char **argv) @@ -48,10 +45,9 @@ static const struct cmd { const char * cmd; int (* func)(int argc, char ** argv); } cmds[] = { - { "create_ipcp", do_create_ipcp }, - { "destroy_ipcp", do_destroy_ipcp }, - { "bootstrap_ipcp", do_bootstrap_ipcp }, - { "enroll_ipcp", do_enroll_ipcp }, + { "ipcp", ipcp_cmd }, + { "bind", do_bind }, + { "unbind", do_unbind }, { "register", do_register }, { "unregister", do_unregister }, { "help", do_help }, @@ -78,7 +74,7 @@ int main(int argc, char ** argv) { if (argc < 2) { usage(); - return 0; + return -1; } return do_cmd(argv[1], argc - 1, argv + 1); diff --git a/src/tools/irm/irm_bind.c b/src/tools/irm/irm_bind.c new file mode 100644 index 00000000..85e5bd3d --- /dev/null +++ b/src/tools/irm/irm_bind.c @@ -0,0 +1,81 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Bind AP to a name + * + * Sander Vrijders + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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 "irm_ops.h" +#include "irm_utils.h" + +static void usage() +{ + printf("Usage: irm bind\n" + " name \n" + " apn \n" + " [auto] (instantiate apn if not running)\n" + " [unique] (there can only be one instantiation)\n" + " [-- ]\n"); +} + + +int do_bind(int argc, char ** argv) +{ + char * name = NULL; + char * ap_name = NULL; + uint16_t flags = 0; + + while (argc > 0) { + if (matches(*argv, "name") == 0) { + name = *(argv + 1); + ++argv; + --argc; + } else if (matches(*argv, "apn") == 0) { + ap_name = *(argv + 1); + ++argv; + --argc; + } else if (strcmp(*argv, "auto") == 0) { + flags |= BIND_AP_AUTO; + } else if (strcmp(*argv, "unique") == 0) { + flags |= BIND_AP_UNIQUE; + } else if (strcmp(*argv, "--") == 0) { + ++argv; + --argc; + break; + } else { + printf("\"%s\" is unknown, try \"irm " + "bind\".\n", *argv); + return -1; + } + + ++argv; + --argc; + } + + if (name == NULL || ap_name == NULL) { + usage(); + return -1; + } + + return irm_bind(name, ap_name, flags, argc, argv); +} diff --git a/src/tools/irm/irm_bootstrap_ipcp.c b/src/tools/irm/irm_bootstrap_ipcp.c deleted file mode 100644 index e11b5f3f..00000000 --- a/src/tools/irm/irm_bootstrap_ipcp.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - * - * Bootstrap IPC Processes - * - * Sander Vrijders - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * 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 - -#include "irm_ops.h" -#include "irm_utils.h" - -#define NORMAL "normal" -#define SHIM_UDP "shim-udp" -#define SHIM_ETH_LLC "shim-eth-llc" -#define LOCAL "local" - -#define DEFAULT_ADDR_SIZE 4 -#define DEFAULT_CEP_ID_SIZE 2 -#define DEFAULT_PDU_LEN_SIZE 2 -#define DEFAULT_QOS_ID_SIZE 1 -#define DEFAULT_SEQ_NO_SIZE 4 -#define DEFAULT_TTL_SIZE 1 -#define DEFAULT_CHK_SIZE 2 -#define DEFAULT_MIN_PDU_SIZE 0 -#define DEFAULT_MAX_PDU_SIZE 9000 -#define DEFAULT_DDNS 0 - -static void usage() -{ - /* FIXME: Add dif_config stuff */ - printf("Usage: irm bootstrap_ipcp\n" - " ap \n" - " [api ]\n" - " dif \n" - " type [TYPE]\n\n" - "where TYPE = {" NORMAL " " LOCAL " " - SHIM_UDP " " SHIM_ETH_LLC"}\n\n" - "if TYPE == " NORMAL "\n" - " [addr
(default: %d)]\n" - " [cep_id (default: %d)]\n" - " [pdu_len (default: %d)]\n" - " [qos_id (default: %d)]\n" - " [seqno (default: %d)]\n" - " [ttl