From 3bebab119c5a2c59121355c72b4e69b2817eea3a Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Wed, 2 Mar 2016 11:42:01 +0100 Subject: tools: Parse command line params This adds initial support to the irm tool for parsing command line parameters. --- src/lib/sockets.c | 2 +- src/tools/irm/main.c | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/lib/sockets.c b/src/lib/sockets.c index c0331063..6cd70a8b 100644 --- a/src/lib/sockets.c +++ b/src/lib/sockets.c @@ -48,7 +48,7 @@ int client_socket_open(char * file_name) if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr))) { - LOG_ERR("Failed to connect to server"); + LOG_ERR("Failed to connect to daemon"); return -1; } diff --git a/src/tools/irm/main.c b/src/tools/irm/main.c index ac09e1e7..ea88e4a6 100644 --- a/src/tools/irm/main.c +++ b/src/tools/irm/main.c @@ -20,13 +20,25 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define OUROBOROS_PREFIX "irm" - -#include #include #include +#include + +int main (int argc, char ** argv) { + + char * operation; + + if (argc < 2) { + printf("Usage: irm [OPERATION]\n\n" + "where OPERATION = {create_ipcp destroy_ipcp \n" + " bootstrap_ipcp enroll_ipcp\n" + " register_ipcp unregister_ipcp}\n"); + return 0; + } + + operation = argv[1]; + printf("Operation is %s\n", operation); -int main () { char * ap_name = "test"; char * ipcp_type = "normal-ipcp"; rina_name_t name; @@ -39,32 +51,26 @@ int main () { size_t difs_size = 1; if (irm_create_ipcp(name, ipcp_type)) { - LOG_ERR("Failed to create IPCP"); return -1; } if (irm_destroy_ipcp(name)) { - LOG_ERR("Failed to destroy IPCP"); return -1; } if (irm_bootstrap_ipcp(name, info)) { - LOG_ERR("Failed to bootstrap IPCP"); return -1; } if (irm_enroll_ipcp(name, dif_name)) { - LOG_ERR("Failed to enroll IPCP"); return -1; } if (irm_reg_ipcp(name, &dif_name, difs_size)) { - LOG_ERR("Failed to register IPCP"); return -1; } if (irm_unreg_ipcp(name, &dif_name, difs_size)) { - LOG_ERR("Failed to unregister IPCP"); return -1; } -- cgit v1.2.3 From ccbfc46ada3317b0f3655b751d473643d4dcab72 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Wed, 2 Mar 2016 19:43:07 +0100 Subject: tools: irm: Parse arguments for irm and create_ipcp This parses the arguments passed to irm at the top level, and also the arguments supplied when calling irm create_ipcp. It subsequently calls irm_create_ipcp with these arguments. --- src/tools/irm/CMakeLists.txt | 9 +++- src/tools/irm/irm.c | 84 +++++++++++++++++++++++++++++++++++++ src/tools/irm/irm_bootstrap_ipcp.c | 32 ++++++++++++++ src/tools/irm/irm_create_ipcp.c | 83 ++++++++++++++++++++++++++++++++++++ src/tools/irm/irm_destroy_ipcp.c | 32 ++++++++++++++ src/tools/irm/irm_enroll_ipcp.c | 32 ++++++++++++++ src/tools/irm/irm_ops.h | 28 +++++++++++++ src/tools/irm/irm_register_ipcp.c | 32 ++++++++++++++ src/tools/irm/irm_unregister_ipcp.c | 32 ++++++++++++++ src/tools/irm/irm_utils.c | 33 +++++++++++++++ src/tools/irm/irm_utils.h | 23 ++++++++++ src/tools/irm/main.c | 79 ---------------------------------- 12 files changed, 419 insertions(+), 80 deletions(-) create mode 100644 src/tools/irm/irm.c create mode 100644 src/tools/irm/irm_bootstrap_ipcp.c create mode 100644 src/tools/irm/irm_create_ipcp.c create mode 100644 src/tools/irm/irm_destroy_ipcp.c create mode 100644 src/tools/irm/irm_enroll_ipcp.c create mode 100644 src/tools/irm/irm_ops.h create mode 100644 src/tools/irm/irm_register_ipcp.c create mode 100644 src/tools/irm/irm_unregister_ipcp.c create mode 100644 src/tools/irm/irm_utils.c create mode 100644 src/tools/irm/irm_utils.h delete mode 100644 src/tools/irm/main.c diff --git a/src/tools/irm/CMakeLists.txt b/src/tools/irm/CMakeLists.txt index 82c73e38..b0d2697b 100644 --- a/src/tools/irm/CMakeLists.txt +++ b/src/tools/irm/CMakeLists.txt @@ -6,7 +6,14 @@ include_directories(${CMAKE_BINARY_DIR}/include) set(SOURCE_FILES # Add source files here - main.c + irm.c + irm_create_ipcp.c + irm_destroy_ipcp.c + irm_bootstrap_ipcp.c + irm_enroll_ipcp.c + irm_register_ipcp.c + irm_unregister_ipcp.c + irm_utils.c ) add_executable (irm ${SOURCE_FILES}) diff --git a/src/tools/irm/irm.c b/src/tools/irm/irm.c new file mode 100644 index 00000000..cca8def4 --- /dev/null +++ b/src/tools/irm/irm.c @@ -0,0 +1,84 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * A tool to instruct the IRM + * + * 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 "irm_ops.h" +#include "irm_utils.h" + +static void usage() +{ + printf("Usage: irm [OPERATION]\n\n" + "where OPERATION = {create_ipcp destroy_ipcp \n" + " bootstrap_ipcp enroll_ipcp\n" + " register_ipcp unregister_ipcp\n" + " help}\n"); +} + +static int do_help(int argc, char **argv) +{ + usage(); + return 0; +} + +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 }, + { "register_ipcp", do_register_ipcp }, + { "unregister_ipcp", do_unregister_ipcp }, + { "help", do_help }, + { 0 } +}; + +static int do_cmd(const char * argv0, + int argc, + char ** argv) +{ + const struct cmd * c; + + for (c = cmds; c->cmd; ++c) { + if (matches(argv0, c->cmd) == 0) + return -(c->func(argc-1, argv+1)); + } + + fprintf(stderr, "\"%s\" is unknown, try \"irm help\".\n", argv0); + return -1; +} + + +int main (int argc, char ** argv) { + + if (argc < 2) { + usage(); + return 0; + } + + return do_cmd(argv[1], argc-1, argv+1); +} diff --git a/src/tools/irm/irm_bootstrap_ipcp.c b/src/tools/irm/irm_bootstrap_ipcp.c new file mode 100644 index 00000000..ca0fba0e --- /dev/null +++ b/src/tools/irm/irm_bootstrap_ipcp.c @@ -0,0 +1,32 @@ +/* + * 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 "irm_ops.h" + +int do_bootstrap_ipcp(int argc, char ** argv) +{ + printf("Nothing here in %s\n", __FUNCTION__); + + return -1; +} diff --git a/src/tools/irm/irm_create_ipcp.c b/src/tools/irm/irm_create_ipcp.c new file mode 100644 index 00000000..5a8478e6 --- /dev/null +++ b/src/tools/irm/irm_create_ipcp.c @@ -0,0 +1,83 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Create 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 "irm_ops.h" +#include "irm_utils.h" + +static void usage() +{ + printf("Usage: irm create_ipcp\n" + " ap \n" + " [api ]\n" + " [ae ]\n" + " type \n"); +} + +int do_create_ipcp(int argc, char ** argv) +{ + char * ap_name = NULL; + int api_id = 0; + char * ae_name = ""; + int aei_id = 0; + rina_name_t name; + char * ipcp_type = NULL; + + while (argc > 0) { + if (matches(*argv, "ap") == 0) { + ap_name = *(argv + 1); + } else if (matches(*argv, "api") == 0) { + api_id = atoi(*(argv + 1)); + } else if (matches(*argv, "ae") == 0) { + ae_name = *(argv + 1); + } else if (matches(*argv, "aei") == 0) { + aei_id = atoi(*(argv + 1)); + } else if (matches(*argv, "type") == 0) { + ipcp_type = *(argv + 1); + } else { + printf("\"%s\" is unknown, try \"irm " + "create_ipcp\".\n", *argv); + return -1; + } + + argc -= 2; + argv += 2;; + } + + if (ipcp_type == NULL || ap_name == NULL) { + usage(); + return -1; + } + + name.ap_name = ap_name; + name.api_id = api_id; + name.ae_name = ae_name; + name.aei_id = aei_id; + + return irm_create_ipcp(name, ipcp_type); +} diff --git a/src/tools/irm/irm_destroy_ipcp.c b/src/tools/irm/irm_destroy_ipcp.c new file mode 100644 index 00000000..69170b11 --- /dev/null +++ b/src/tools/irm/irm_destroy_ipcp.c @@ -0,0 +1,32 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Destroy 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 "irm_ops.h" + +int do_destroy_ipcp(int argc, char ** argv) +{ + printf("Nothing here in %s\n", __FUNCTION__); + + return -1; +} diff --git a/src/tools/irm/irm_enroll_ipcp.c b/src/tools/irm/irm_enroll_ipcp.c new file mode 100644 index 00000000..058feee2 --- /dev/null +++ b/src/tools/irm/irm_enroll_ipcp.c @@ -0,0 +1,32 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Enroll 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 "irm_ops.h" + +int do_enroll_ipcp(int argc, char ** argv) +{ + printf("Nothing here in %s\n", __FUNCTION__); + + return -1; +} diff --git a/src/tools/irm/irm_ops.h b/src/tools/irm/irm_ops.h new file mode 100644 index 00000000..ff63b6bf --- /dev/null +++ b/src/tools/irm/irm_ops.h @@ -0,0 +1,28 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Functions of the IRM tool that are one level deep + * + * 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. + */ + +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); diff --git a/src/tools/irm/irm_register_ipcp.c b/src/tools/irm/irm_register_ipcp.c new file mode 100644 index 00000000..f271afc4 --- /dev/null +++ b/src/tools/irm/irm_register_ipcp.c @@ -0,0 +1,32 @@ +/* + * 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 "irm_ops.h" + +int do_register_ipcp(int argc, char ** argv) +{ + printf("Nothing here in %s\n", __FUNCTION__); + + return -1; +} diff --git a/src/tools/irm/irm_unregister_ipcp.c b/src/tools/irm/irm_unregister_ipcp.c new file mode 100644 index 00000000..bda406c7 --- /dev/null +++ b/src/tools/irm/irm_unregister_ipcp.c @@ -0,0 +1,32 @@ +/* + * 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 "irm_ops.h" + +int do_unregister_ipcp(int argc, char ** argv) +{ + printf("Nothing here in %s\n", __FUNCTION__); + + return -1; +} diff --git a/src/tools/irm/irm_utils.c b/src/tools/irm/irm_utils.c new file mode 100644 index 00000000..34bec18c --- /dev/null +++ b/src/tools/irm/irm_utils.c @@ -0,0 +1,33 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Handy helper functions for the IRM tool + * + * 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 + +int matches(const char * cmd, const char * pattern) +{ + int len = strlen(cmd); + + if (len > strlen(pattern)) + return -1; + + return memcmp(pattern, cmd, len); +} diff --git a/src/tools/irm/irm_utils.h b/src/tools/irm/irm_utils.h new file mode 100644 index 00000000..da2259c6 --- /dev/null +++ b/src/tools/irm/irm_utils.h @@ -0,0 +1,23 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Handy helper functions for the IRM tool + * + * 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. + */ + +int matches(const char * cmd, const char * pattern); diff --git a/src/tools/irm/main.c b/src/tools/irm/main.c deleted file mode 100644 index ea88e4a6..00000000 --- a/src/tools/irm/main.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - * - * A tool to instruct the IRM - * - * 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 - -int main (int argc, char ** argv) { - - char * operation; - - if (argc < 2) { - printf("Usage: irm [OPERATION]\n\n" - "where OPERATION = {create_ipcp destroy_ipcp \n" - " bootstrap_ipcp enroll_ipcp\n" - " register_ipcp unregister_ipcp}\n"); - return 0; - } - - operation = argv[1]; - printf("Operation is %s\n", operation); - - char * ap_name = "test"; - char * ipcp_type = "normal-ipcp"; - rina_name_t name; - name.ap_name = ap_name; - name.api_id = 1; - name.ae_name = ""; - name.aei_id = 0; - struct dif_info info; - char * dif_name = "wienerschnitzel"; - size_t difs_size = 1; - - if (irm_create_ipcp(name, ipcp_type)) { - return -1; - } - - if (irm_destroy_ipcp(name)) { - return -1; - } - - if (irm_bootstrap_ipcp(name, info)) { - return -1; - } - - if (irm_enroll_ipcp(name, dif_name)) { - return -1; - } - - if (irm_reg_ipcp(name, &dif_name, difs_size)) { - return -1; - } - - if (irm_unreg_ipcp(name, &dif_name, difs_size)) { - return -1; - } - - - return 0; -} -- cgit v1.2.3 From bd2dc6141b59d8fe67e7765b5dfce5b819ed7e33 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Thu, 3 Mar 2016 14:09:57 +0100 Subject: tools: irm: Provide all IRM calls This commit makes all IRM calls available to the user of the 'irm' tool. The bootstrap_ipcp call does not yet take the anything except the AP name. This will be added once we stabilize what should be configurable in the IPCP. --- src/tools/irm/irm.c | 8 +++--- src/tools/irm/irm_bootstrap_ipcp.c | 40 ++++++++++++++++++++++++-- src/tools/irm/irm_create_ipcp.c | 41 +++++++++++---------------- src/tools/irm/irm_destroy_ipcp.c | 37 ++++++++++++++++++++++-- src/tools/irm/irm_enroll_ipcp.c | 43 ++++++++++++++++++++++++++-- src/tools/irm/irm_register_ipcp.c | 56 +++++++++++++++++++++++++++++++++++-- src/tools/irm/irm_unregister_ipcp.c | 56 +++++++++++++++++++++++++++++++++++-- src/tools/irm/irm_utils.c | 25 +++++++++++++++++ src/tools/irm/irm_utils.h | 4 +++ 9 files changed, 271 insertions(+), 39 deletions(-) diff --git a/src/tools/irm/irm.c b/src/tools/irm/irm.c index cca8def4..44018b90 100644 --- a/src/tools/irm/irm.c +++ b/src/tools/irm/irm.c @@ -33,8 +33,7 @@ static void usage() printf("Usage: irm [OPERATION]\n\n" "where OPERATION = {create_ipcp destroy_ipcp \n" " bootstrap_ipcp enroll_ipcp\n" - " register_ipcp unregister_ipcp\n" - " help}\n"); + " register_ipcp unregister_ipcp\n"); } static int do_help(int argc, char **argv) @@ -65,10 +64,11 @@ static int do_cmd(const char * argv0, for (c = cmds; c->cmd; ++c) { if (matches(argv0, c->cmd) == 0) - return -(c->func(argc-1, argv+1)); + return c->func(argc - 1, argv + 1); } fprintf(stderr, "\"%s\" is unknown, try \"irm help\".\n", argv0); + return -1; } @@ -80,5 +80,5 @@ int main (int argc, char ** argv) { return 0; } - return do_cmd(argv[1], argc-1, argv+1); + return do_cmd(argv[1], argc - 1, argv + 1); } diff --git a/src/tools/irm/irm_bootstrap_ipcp.c b/src/tools/irm/irm_bootstrap_ipcp.c index ca0fba0e..6b640c14 100644 --- a/src/tools/irm/irm_bootstrap_ipcp.c +++ b/src/tools/irm/irm_bootstrap_ipcp.c @@ -21,12 +21,48 @@ */ #include +#include +#include #include "irm_ops.h" +#include "irm_utils.h" + +static void usage() +{ + /* FIXME: Add dif_info stuff */ + printf("Usage: irm bootstrap_ipcp\n" + " ap \n" + " [api ]\n" + " [ae ]\n"); +} + int do_bootstrap_ipcp(int argc, char ** argv) { - printf("Nothing here in %s\n", __FUNCTION__); + rina_name_t name; + struct dif_info info; + + name.ap_name = NULL; + name.api_id = 0; + name.ae_name = ""; + name.aei_id = 0; + + while (argc > 0) { + if (!parse_name(argv, &name)) { + printf("\"%s\" is unknown, try \"irm " + "enroll_ipcp\".\n", *argv); + return -1; + } + + argc -= 2; + argv += 2; + } + + if (name.ap_name == NULL) { + usage(); + return -1; + } - return -1; + return irm_bootstrap_ipcp(name, info); } diff --git a/src/tools/irm/irm_create_ipcp.c b/src/tools/irm/irm_create_ipcp.c index 5a8478e6..5c847988 100644 --- a/src/tools/irm/irm_create_ipcp.c +++ b/src/tools/irm/irm_create_ipcp.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -41,43 +42,33 @@ static void usage() int do_create_ipcp(int argc, char ** argv) { - char * ap_name = NULL; - int api_id = 0; - char * ae_name = ""; - int aei_id = 0; rina_name_t name; char * ipcp_type = NULL; + name.ap_name = NULL; + name.api_id = 0; + name.ae_name = ""; + name.aei_id = 0; + while (argc > 0) { - if (matches(*argv, "ap") == 0) { - ap_name = *(argv + 1); - } else if (matches(*argv, "api") == 0) { - api_id = atoi(*(argv + 1)); - } else if (matches(*argv, "ae") == 0) { - ae_name = *(argv + 1); - } else if (matches(*argv, "aei") == 0) { - aei_id = atoi(*(argv + 1)); - } else if (matches(*argv, "type") == 0) { - ipcp_type = *(argv + 1); - } else { - printf("\"%s\" is unknown, try \"irm " - "create_ipcp\".\n", *argv); - return -1; + if (!parse_name(argv, &name)) { + if (matches(*argv, "type") == 0) { + ipcp_type = *(argv + 1); + } else { + printf("\"%s\" is unknown, try \"irm " + "create_ipcp\".\n", *argv); + return -1; + } } argc -= 2; - argv += 2;; + argv += 2; } - if (ipcp_type == NULL || ap_name == NULL) { + if (ipcp_type == NULL || name.ap_name == NULL) { usage(); return -1; } - name.ap_name = ap_name; - name.api_id = api_id; - name.ae_name = ae_name; - name.aei_id = aei_id; - return irm_create_ipcp(name, ipcp_type); } diff --git a/src/tools/irm/irm_destroy_ipcp.c b/src/tools/irm/irm_destroy_ipcp.c index 69170b11..467d1b50 100644 --- a/src/tools/irm/irm_destroy_ipcp.c +++ b/src/tools/irm/irm_destroy_ipcp.c @@ -21,12 +21,45 @@ */ #include +#include +#include #include "irm_ops.h" +#include "irm_utils.h" + +static void usage() +{ + printf("Usage: irm destroy_ipcp\n" + " ap \n" + " [api ]\n" + " [ae ]\n"); +} int do_destroy_ipcp(int argc, char ** argv) { - printf("Nothing here in %s\n", __FUNCTION__); + rina_name_t name; + + name.ap_name = NULL; + name.api_id = 0; + name.ae_name = ""; + name.aei_id = 0; + + while (argc > 0) { + if (!parse_name(argv, &name)) { + printf("\"%s\" is unknown, try \"irm " + "destroy_ipcp\".\n", *argv); + return -1; + } + + argc -= 2; + argv += 2; + } + + if (name.ap_name == NULL) { + usage(); + return -1; + } - return -1; + return irm_destroy_ipcp(name); } diff --git a/src/tools/irm/irm_enroll_ipcp.c b/src/tools/irm/irm_enroll_ipcp.c index 058feee2..94f28f82 100644 --- a/src/tools/irm/irm_enroll_ipcp.c +++ b/src/tools/irm/irm_enroll_ipcp.c @@ -21,12 +21,51 @@ */ #include +#include +#include #include "irm_ops.h" +#include "irm_utils.h" + +static void usage() +{ + printf("Usage: irm enroll_ipcp\n" + " ap \n" + " [api ]\n" + " [ae ]\n" + " dif \n"); +} int do_enroll_ipcp(int argc, char ** argv) { - printf("Nothing here in %s\n", __FUNCTION__); + rina_name_t name; + char * dif_name = NULL; + + name.ap_name = NULL; + name.api_id = 0; + name.ae_name = ""; + name.aei_id = 0; + + while (argc > 0) { + if (!parse_name(argv, &name)) { + if (matches(*argv, "dif") == 0) { + dif_name = *(argv + 1); + } else { + printf("\"%s\" is unknown, try \"irm " + "enroll_ipcp\".\n", *argv); + return -1; + } + } + + argc -= 2; + argv += 2; + } + + if (dif_name == NULL || name.ap_name == NULL) { + usage(); + return -1; + } - return -1; + return irm_enroll_ipcp(name, dif_name); } diff --git a/src/tools/irm/irm_register_ipcp.c b/src/tools/irm/irm_register_ipcp.c index f271afc4..c69ad350 100644 --- a/src/tools/irm/irm_register_ipcp.c +++ b/src/tools/irm/irm_register_ipcp.c @@ -21,12 +21,64 @@ */ #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" + " [ae ]\n" + " dif \n" + " [dif ]\n" + " [... (maximum %d difs)]\n", MAX_DIFS); +} + int do_register_ipcp(int argc, char ** argv) { - printf("Nothing here in %s\n", __FUNCTION__); + rina_name_t name; + char * difs[MAX_DIFS]; + size_t difs_size = 0; + + name.ap_name = NULL; + name.api_id = 0; + name.ae_name = ""; + name.aei_id = 0; + + while (argc > 0) { + if (!parse_name(argv, &name)) { + 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 || name.ap_name == NULL) { + usage(); + return -1; + } - return -1; + return irm_reg_ipcp(name, difs, difs_size); } diff --git a/src/tools/irm/irm_unregister_ipcp.c b/src/tools/irm/irm_unregister_ipcp.c index bda406c7..a2dffc6c 100644 --- a/src/tools/irm/irm_unregister_ipcp.c +++ b/src/tools/irm/irm_unregister_ipcp.c @@ -21,12 +21,64 @@ */ #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" + " [ae ]\n" + " dif \n" + " [dif ]\n" + " [... (maximum %d difs)]\n", MAX_DIFS); +} + int do_unregister_ipcp(int argc, char ** argv) { - printf("Nothing here in %s\n", __FUNCTION__); + rina_name_t name; + char * difs[MAX_DIFS]; + size_t difs_size = 0; + + name.ap_name = NULL; + name.api_id = 0; + name.ae_name = ""; + name.aei_id = 0; + + while (argc > 0) { + if (!parse_name(argv, &name)) { + 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 || name.ap_name == NULL) { + usage(); + return -1; + } - return -1; + return irm_unreg_ipcp(name, difs, difs_size); } diff --git a/src/tools/irm/irm_utils.c b/src/tools/irm/irm_utils.c index 34bec18c..021227fd 100644 --- a/src/tools/irm/irm_utils.c +++ b/src/tools/irm/irm_utils.c @@ -21,6 +21,11 @@ */ #include +#include +#include +#include + +#include "irm_utils.h" int matches(const char * cmd, const char * pattern) { @@ -31,3 +36,23 @@ int matches(const char * cmd, const char * pattern) return memcmp(pattern, cmd, len); } + + +bool parse_name(char ** argv, + rina_name_t * name) +{ + bool found = true; + + if (matches(*argv, "ap") == 0) + name->ap_name = *(argv + 1); + else if (matches(*argv, "api") == 0) + name->api_id = atoi(*(argv + 1)); + else if (matches(*argv, "ae") == 0) + name->ae_name = *(argv + 1); + else if (matches(*argv, "aei") == 0) + name->aei_id = atoi(*(argv + 1)); + else + found = false; + + return found; +} diff --git a/src/tools/irm/irm_utils.h b/src/tools/irm/irm_utils.h index da2259c6..9332b108 100644 --- a/src/tools/irm/irm_utils.h +++ b/src/tools/irm/irm_utils.h @@ -20,4 +20,8 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include + int matches(const char * cmd, const char * pattern); + +bool parse_name(char ** argv, rina_name_t * name); -- cgit v1.2.3 From ef2a4f128fa0250db5457069e397bf328c6da25e Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Thu, 3 Mar 2016 15:06:09 +0100 Subject: lib, irmd: Fix memleaks Fixes a couple of memleaks found while executing with valgrind. --- src/irmd/main.c | 11 ++--------- src/lib/irm.c | 8 ++++++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/irmd/main.c b/src/irmd/main.c index 73533ef0..0c69de2f 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -78,18 +78,12 @@ static void unreg_ipcp(rina_name_t * name, int main() { int sockfd; - uint8_t * buf; + uint8_t buf[IRM_MSG_BUF_SIZE]; sockfd = server_socket_open(IRM_SOCK_PATH); if (sockfd < 0) return -1; - buf = malloc(sizeof(*buf) * IRM_MSG_BUF_SIZE); - if (buf == NULL) { - LOG_ERR("Cannot allocate memory"); - return -ENOMEM; - } - while (true) { int cli_sockfd; struct irm_msg * msg; @@ -140,12 +134,11 @@ int main() LOG_ERR("Don't know that message code"); break; } + free(msg); } close(cli_sockfd); } - free(buf); - return 0; } diff --git a/src/lib/irm.c b/src/lib/irm.c index 97000029..8756d7fc 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -26,6 +26,7 @@ #include #include #include +#include static int send_irm_msg(struct irm_msg * msg) { @@ -47,8 +48,11 @@ static int send_irm_msg(struct irm_msg * msg) return -1; } - close(sockfd); - return 0; + free(buf->data); + free(buf); + + close(sockfd); + return 0; } int irm_create_ipcp(rina_name_t name, -- cgit v1.2.3 From 4ada2b9494b28a5c724714a4d1fc5b2fb879b0fe Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Thu, 3 Mar 2016 17:21:50 +0100 Subject: tools: irm: Change description in irm file This adds the word daemon to the description of the IRM tool. --- src/tools/irm/irm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/irm/irm.c b/src/tools/irm/irm.c index 44018b90..0325c810 100644 --- a/src/tools/irm/irm.c +++ b/src/tools/irm/irm.c @@ -1,7 +1,7 @@ /* * Ouroboros - Copyright (C) 2016 * - * A tool to instruct the IRM + * A tool to instruct the IRM daemon * * Sander Vrijders * -- cgit v1.2.3