From 7834e92b218da69cd934679dec9c2d714d89d15e Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Mon, 13 Jun 2016 13:48:17 +0200 Subject: lib, irmd, tools, ipcpd: updates to dev API. The registration function has been moved to the irm tool, applications now need to be registered by an administrator. Currently only supports one instance per registered name, and an AP can be registered under only one name. The irmd can now start a registered server application on demand. For the full functionality of the tool, execute "irm register". AP name removed from flow allocation. Flow allocation does not send the source ap name as it is quite useless. The accept() call now only returns the AE name. --- src/tools/irm/CMakeLists.txt | 4 +- src/tools/irm/irm.c | 5 +- src/tools/irm/irm_ops.h | 4 +- src/tools/irm/irm_register.c | 123 ++++++++++++++++++++++++++++++++++++ src/tools/irm/irm_register_ipcp.c | 79 ----------------------- src/tools/irm/irm_unregister.c | 116 ++++++++++++++++++++++++++++++++++ src/tools/irm/irm_unregister_ipcp.c | 80 ----------------------- 7 files changed, 246 insertions(+), 165 deletions(-) create mode 100644 src/tools/irm/irm_register.c delete mode 100644 src/tools/irm/irm_register_ipcp.c create mode 100644 src/tools/irm/irm_unregister.c delete mode 100644 src/tools/irm/irm_unregister_ipcp.c (limited to 'src/tools/irm') diff --git a/src/tools/irm/CMakeLists.txt b/src/tools/irm/CMakeLists.txt index f356d068..eb385908 100644 --- a/src/tools/irm/CMakeLists.txt +++ b/src/tools/irm/CMakeLists.txt @@ -11,8 +11,8 @@ set(SOURCE_FILES irm_destroy_ipcp.c irm_bootstrap_ipcp.c irm_enroll_ipcp.c - irm_register_ipcp.c - irm_unregister_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 d05e083e..a1dc5ade 100644 --- a/src/tools/irm/irm.c +++ b/src/tools/irm/irm.c @@ -34,6 +34,7 @@ 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"); } @@ -51,8 +52,8 @@ static const struct cmd { { "destroy_ipcp", do_destroy_ipcp }, { "bootstrap_ipcp", do_bootstrap_ipcp }, { "enroll_ipcp", do_enroll_ipcp }, - { "register_ipcp", do_register_ipcp }, - { "unregister_ipcp", do_unregister_ipcp }, + { "register", do_register }, + { "unregister", do_unregister }, { "help", do_help }, { 0 } }; diff --git a/src/tools/irm/irm_ops.h b/src/tools/irm/irm_ops.h index ff63b6bf..ea51cbeb 100644 --- a/src/tools/irm/irm_ops.h +++ b/src/tools/irm/irm_ops.h @@ -24,5 +24,5 @@ int do_create_ipcp(int argc, char ** argv); int do_destroy_ipcp(int argc, char ** argv); int do_bootstrap_ipcp(int argc, char ** argv); int do_enroll_ipcp(int argc, char ** argv); -int do_register_ipcp(int argc, char ** argv); -int do_unregister_ipcp(int argc, char ** argv); +int do_register(int argc, char ** argv); +int do_unregister(int argc, char ** argv); diff --git a/src/tools/irm/irm_register.c b/src/tools/irm/irm_register.c new file mode 100644 index 00000000..67c81025 --- /dev/null +++ b/src/tools/irm/irm_register.c @@ -0,0 +1,123 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Register AP's in DIFs + * + * 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 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 +#include +#include + +#include "irm_ops.h" +#include "irm_utils.h" + +#define MAX_DIFS 128 + +static void usage() +{ + printf("Usage: irm register\n" + " n \n" + " apn \n" + " [api ]\n" + " [auto] (instantiate apn if not running)\n" + " [dif ]\n" + " [... (maximum %d difs)]\n" + " [-- ]\n" + , MAX_DIFS); +} + + +int do_register(int argc, char ** argv) +{ + char * name = NULL; + char ** args = NULL; + char * difs[MAX_DIFS]; + size_t difs_len = 0; + bool api_opt = false; + bool args_opt = false; + bool autoexec = false; + int i = argc; + + instance_name_t api = {NULL, 0}; + + while (i > 0) { + if (matches(*argv, "name") == 0) { + name = *(argv + 1); + } else if (matches(*argv, "apn") == 0) { + api.name = *(argv + 1); + } else if (matches(*argv, "api") == 0) { + api.id = atoi(*(argv + 1)); + api_opt = true; + } else if (strcmp(*argv, "auto") == 0) { + autoexec = true; + ++i; + --argv; + } else if (strcmp(*argv, "--") == 0) { + ++argv; + --i; + args_opt = true; + break; + } else if (matches(*argv, "dif") == 0) { + difs[difs_len++] = *(argv + 1); + if (difs_len > MAX_DIFS) { + printf("Too many difs specified\n"); + return -1; + } + } else { + printf("\"%s\" is unknown, try \"irm " + "register\".\n", *argv); + return -1; + } + + i -= 2; + argv += 2; + } + + if (name == NULL || api.name == NULL) { + usage(); + return -1; + } + + if (api_opt && kill(api.id, 0) < 0) { + printf("No application running with that pid."); + return -1; + } + + if (api_opt && autoexec) { + printf("Instance is given, auto disabled.\n"); + autoexec = false; + } + + args = argv; + + if (args_opt && api_opt) { + printf("Instance is given, args ignored.\n"); + args = NULL; + i = 0; + } + + return irm_reg(name, &api, i, args, autoexec, difs, difs_len); +} diff --git a/src/tools/irm/irm_register_ipcp.c b/src/tools/irm/irm_register_ipcp.c deleted file mode 100644 index f0c1ccff..00000000 --- a/src/tools/irm/irm_register_ipcp.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - * - * Register IPC Processes in an N-1 DIF - * - * 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 MAX_DIFS 128 - -static void usage() -{ - printf("Usage: irm register_ipcp\n" - " ap \n" - " [api ]\n" - " dif \n" - " [dif ]\n" - " [... (maximum %d difs)]\n", MAX_DIFS); -} - - -int do_register_ipcp(int argc, char ** argv) -{ - char * difs[MAX_DIFS]; - size_t difs_size = 0; - instance_name_t api = {NULL, 0}; - - while (argc > 0) { - if (matches(*argv, "ap") == 0) { - api.name = *(argv + 1); - } else if (matches(*argv, "api") == 0) { - api.id = atoi(*(argv + 1)); - } else if (matches(*argv, "dif") == 0) { - difs[difs_size++] = *(argv + 1); - if (difs_size > MAX_DIFS) { - printf("Too many difs specified\n"); - return -1; - } - } else { - printf("\"%s\" is unknown, try \"irm " - "register_ipcp\".\n", *argv); - return -1; - } - - argc -= 2; - argv += 2; - } - - if (difs_size == 0 || api.name == NULL) { - usage(); - return -1; - } - - return irm_reg_ipcp(&api, difs, difs_size); -} diff --git a/src/tools/irm/irm_unregister.c b/src/tools/irm/irm_unregister.c new file mode 100644 index 00000000..d778e285 --- /dev/null +++ b/src/tools/irm/irm_unregister.c @@ -0,0 +1,116 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Unregister IPC Processes in an N-1 DIF + * + * 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 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 +#include +#include + +#include "irm_ops.h" +#include "irm_utils.h" + +#define MAX_DIFS 128 + +static void usage() +{ + printf("Usage: irm unregister\n" + " [name ]\n" + " [apn ]\n" + " [api ]\n" + " dif \n" + " [dif ]\n" + " [... (maximum %d difs)]\n" + " [hard] (unregisters everything using that name)\n" + , MAX_DIFS); +} + +int do_unregister(int argc, char ** argv) +{ + instance_name_t api = {NULL, 0}; + char * difs[MAX_DIFS]; + size_t difs_len = 0; + char * name = NULL; + bool hard_opt = false; + bool ap_id = false; + instance_name_t * ptr_api = NULL; + + while (argc > 0) { + if (matches(*argv, "name") == 0) { + name = *(argv + 1); + } else if (matches(*argv, "ap") == 0) { + api.name = *(argv + 1); + ptr_api = &api; + } else if (matches(*argv, "api") == 0) { + api.id = atoi(*(argv + 1)); + ap_id = true; + } else if (strcmp(*argv, "hard") == 0) { + hard_opt = true; + /* this has no value */ + ++argc; + --argv; + } else if (matches(*argv, "dif") == 0) { + difs[difs_len++] = *(argv + 1); + if (difs_len > MAX_DIFS) { + printf("Too many difs specified\n"); + return -1; + } + } else { + printf("\"%s\" is unknown, try \"irm " + "unregister\".\n", *argv); + return -1; + } + + argc -= 2; + argv += 2; + } + + if (difs_len == 0) { + usage(); + return -1; + } + + if (name == NULL && api.name == NULL) { + printf("apn or name must be set.\n"); + usage(); + return -1; + } + + if (ap_id && api.name == NULL) { + printf("api requires apn.\n"); + usage(); + return -1; + } + + if (hard_opt && api.name != NULL) { + printf("apn and/or api must not be set when using hard.\n"); + usage(); + return -1; + } + + return irm_unreg(name, ptr_api, difs, difs_len, hard_opt); +} diff --git a/src/tools/irm/irm_unregister_ipcp.c b/src/tools/irm/irm_unregister_ipcp.c deleted file mode 100644 index 3fd6f148..00000000 --- a/src/tools/irm/irm_unregister_ipcp.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - * - * Unregister IPC Processes in an N-1 DIF - * - * 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 MAX_DIFS 128 - -static void usage() -{ - printf("Usage: irm unregister_ipcp\n" - " ap \n" - " [api ]\n" - " dif \n" - " [dif ]\n" - " [... (maximum %d difs)]\n", MAX_DIFS); -} - - -int do_unregister_ipcp(int argc, char ** argv) -{ - instance_name_t api = {NULL, 0}; - char * difs[MAX_DIFS]; - size_t difs_size = 0; - - - while (argc > 0) { - if (matches(*argv, "ap") == 0) { - api.name = *(argv + 1); - } else if (matches(*argv, "api") == 0) { - api.id = atoi(*(argv + 1)); - } else if (matches(*argv, "dif") == 0) { - difs[difs_size++] = *(argv + 1); - if (difs_size > MAX_DIFS) { - printf("Too many difs specified\n"); - return -1; - } - } else { - printf("\"%s\" is unknown, try \"irm " - "unregister_ipcp\".\n", *argv); - return -1; - } - - argc -= 2; - argv += 2; - } - - if (difs_size == 0 || api.name == NULL) { - usage(); - return -1; - } - - return irm_unreg_ipcp(&api, difs, difs_size); -} -- cgit v1.2.3