diff options
-rw-r--r-- | CMakeLists.txt | 9 | ||||
-rw-r--r-- | include/ouroboros/CMakeLists.txt | 7 | ||||
-rw-r--r-- | include/ouroboros/config.h.in | 31 | ||||
-rw-r--r-- | include/ouroboros/ipcp.h | 16 | ||||
-rw-r--r-- | include/ouroboros/utils.h | 27 | ||||
-rwxr-xr-x | install_debug.sh | 18 | ||||
-rwxr-xr-x | install_release.sh | 18 | ||||
-rw-r--r-- | src/ipcpd/main.c | 5 | ||||
-rw-r--r-- | src/irmd/main.c | 27 | ||||
-rw-r--r-- | src/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/lib/ipcp.c | 103 | ||||
-rw-r--r-- | src/lib/rina_name.c | 13 | ||||
-rw-r--r-- | src/lib/utils.c | 33 |
13 files changed, 267 insertions, 41 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1041197c..243e5d6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,15 @@ set(PACKAGE_BUGREPORT "None" set(PACKAGE_VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}" CACHE STRING "Package version") +SET(CMAKE_SKIP_BUILD_RPATH FALSE) +SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) +SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + +LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) +IF("${isSystemDir}" STREQUAL "-1") + SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") +ENDIF("${isSystemDir}" STREQUAL "-1") + message(STATUS "Package name is: ${PACKAGE_NAME}") message(STATUS "Package description is: ${PACKAGE_DESCRIPTION}") message(STATUS "Package version is: ${PACKAGE_VERSION}") diff --git a/include/ouroboros/CMakeLists.txt b/include/ouroboros/CMakeLists.txt index e862de8c..167cf0e2 100644 --- a/include/ouroboros/CMakeLists.txt +++ b/include/ouroboros/CMakeLists.txt @@ -1,3 +1,7 @@ +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/config.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/config.h") + set(HEADER_FILES bitmap.h cdap.h @@ -11,7 +15,8 @@ set(HEADER_FILES logs.h rina_name.h sockets.h + utils.h ) -install(FILES ${HEADER_FILES} +install(FILES ${HEADER_FILES} "${CMAKE_CURRENT_BINARY_DIR}/config.h" DESTINATION include/ouroboros) diff --git a/include/ouroboros/config.h.in b/include/ouroboros/config.h.in new file mode 100644 index 00000000..0f5c2131 --- /dev/null +++ b/include/ouroboros/config.h.in @@ -0,0 +1,31 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Configuration information + * + * Sander Vrijders <[email protected]> + * + * 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. + */ + +#ifndef OUROBOROS_CONFIG +#define OUROBOROS_CONFIG + +#define PROJECT_NAME "@CMAKE_PROJECT_NAME@" +#define PROJECT_VERSION "@PACKAGE_VERSION@" +#define INSTALL_DIR "@CMAKE_INSTALL_PREFIX@" +#define BUILD_TYPE "@CMAKE_BUILD_TYPE@" + +#endif diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h index 39e9c909..5e3e7f8c 100644 --- a/include/ouroboros/ipcp.h +++ b/include/ouroboros/ipcp.h @@ -23,26 +23,28 @@ #ifndef OUROBOROS_IPCP_H #define OUROBOROS_IPCP_H +#include <sys/types.h> + #include "common.h" #include "rina_name.h" struct ipcp; /* Returns the process id */ -int ipcp_create(rina_name_t name, - char * ipcp_type); -int ipcp_destroy(int pid); +pid_t ipcp_create(rina_name_t name, + char * ipcp_type); +int ipcp_destroy(pid_t pid); -int ipcp_reg(int pid, +int ipcp_reg(pid_t pid, char ** difs, size_t difs_size); -int ipcp_unreg(int pid, +int ipcp_unreg(pid_t pid, char ** difs, size_t difs_size); -int ipcp_bootstrap(int pid, +int ipcp_bootstrap(pid_t pid, struct dif_config conf); -int ipcp_enroll(int pid, +int ipcp_enroll(pid_t pid, char * dif_name, rina_name_t member, char ** n_1_difs, diff --git a/include/ouroboros/utils.h b/include/ouroboros/utils.h new file mode 100644 index 00000000..0e50c039 --- /dev/null +++ b/include/ouroboros/utils.h @@ -0,0 +1,27 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Handy utilities + * + * Sander Vrijders <[email protected]> + * + * 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. + */ + +/* + * Returns the number of characters a uint would + * need when represented as a string + */ +int n_digits(unsigned i); diff --git a/install_debug.sh b/install_debug.sh new file mode 100755 index 00000000..ef6b8a30 --- /dev/null +++ b/install_debug.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +ME=install_debug + +if (($# == 1 )) +then + PREFIX=`echo "$1"|sed -e "s,\/$,,"` +else + PREFIX="/usr/local/ouroboros" +fi + +BUILDDIR=build +DEBUGDIR=debug + +bash compile_debug.sh $PREFIX + +cd $BUILDDIR/$DEBUGDIR +make install diff --git a/install_release.sh b/install_release.sh new file mode 100755 index 00000000..afaee3d5 --- /dev/null +++ b/install_release.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +ME=install_release + +if (($# == 1 )) +then + PREFIX=`echo "$1"|sed -e "s,\/$,,"` +else + PREFIX="/usr/local/ouroboros" +fi + +BUILDDIR=build +RELEASEDIR=release + +bash compile_debug.sh $PREFIX + +cd $BUILDDIR/$RELEASEDIR +make install diff --git a/src/ipcpd/main.c b/src/ipcpd/main.c index b67b0af9..7ffd1c48 100644 --- a/src/ipcpd/main.c +++ b/src/ipcpd/main.c @@ -1,10 +1,15 @@ #define OUROBOROS_PREFIX "ipcp" #include <ouroboros/logs.h> +#include <stdbool.h> int main() { LOG_DBG("Test of the IPCP"); + while (true) { + + } + return 0; } diff --git a/src/irmd/main.c b/src/irmd/main.c index 9a072382..b695519a 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -38,7 +38,7 @@ struct name_to_pid_entry { struct list_head next; - int pid; + pid_t pid; rina_name_t * name; }; @@ -46,8 +46,8 @@ struct irm { struct list_head name_to_pid; }; -static int find_pid_by_name(struct irm * instance, - rina_name_t * name) +static pid_t find_pid_by_name(struct irm * instance, + rina_name_t * name) { struct list_head * pos; @@ -68,11 +68,11 @@ static void create_ipcp(struct irm * instance, rina_name_t name, char * ipcp_type) { - int pid; + pid_t pid; struct name_to_pid_entry * tmp; pid = ipcp_create(name, ipcp_type); - if (pid == 0) { + if (pid == -1) { LOG_ERR("Failed to create IPCP"); return; } @@ -90,14 +90,17 @@ static void create_ipcp(struct irm * instance, return; } + LOG_DBG("Created IPC process with pid %d", pid); + list_add(&tmp->next, &instance->name_to_pid); } static void destroy_ipcp(struct irm * instance, rina_name_t name) { - int pid = 0; + pid_t pid = 0; struct list_head * pos; + struct list_head * n; pid = find_pid_by_name(instance, &name); if (pid == 0) { @@ -105,10 +108,12 @@ static void destroy_ipcp(struct irm * instance, return; } + LOG_DBG("Destroying ipcp with pid %d", pid); + if (ipcp_destroy(pid)) LOG_ERR("Could not destroy IPCP"); - list_for_each(pos, &instance->name_to_pid) { + list_for_each_safe(pos, n, &(instance->name_to_pid)) { struct name_to_pid_entry * tmp = list_entry(pos, struct name_to_pid_entry, next); @@ -121,7 +126,7 @@ static void bootstrap_ipcp(struct irm * instance, rina_name_t name, struct dif_config conf) { - int pid = 0; + pid_t pid = 0; pid = find_pid_by_name(instance, &name); if (pid == 0) { @@ -137,7 +142,7 @@ static void enroll_ipcp(struct irm * instance, rina_name_t name, char * dif_name) { - int pid = 0; + pid_t pid = 0; rina_name_t * member; char ** n_1_difs = NULL; ssize_t n_1_difs_size = 0; @@ -166,7 +171,7 @@ static void reg_ipcp(struct irm * instance, char ** difs, size_t difs_size) { - int pid = 0; + pid_t pid = 0; pid = find_pid_by_name(instance, &name); if (pid == 0) { @@ -183,7 +188,7 @@ static void unreg_ipcp(struct irm * instance, char ** difs, size_t difs_size) { - int pid = 0; + pid_t pid = 0; pid = find_pid_by_name(instance, &name); if (pid == 0) { diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 589c8769..eaff2ddb 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -15,6 +15,7 @@ set(SOURCE_FILES list.c rina_name.c sockets.c + utils.c ) add_library(ouroboros SHARED ${SOURCE_FILES}) diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c index 935330d5..294d518c 100644 --- a/src/lib/ipcp.c +++ b/src/lib/ipcp.c @@ -20,41 +20,124 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#define OUROBOROS_PREFIX "lib-ipcp" + +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 199506L +#endif + #include <ouroboros/ipcp.h> +#include <ouroboros/common.h> +#include <ouroboros/logs.h> +#include <ouroboros/config.h> +#include <ouroboros/utils.h> + +#include <stdlib.h> +#include <string.h> +#include <signal.h> +#include <sys/types.h> +#include <sys/wait.h> -int ipcp_create(rina_name_t name, - char * ipcp_type) +pid_t ipcp_create(rina_name_t name, + char * ipcp_type) { - /* zero means failure */ - return 0; + pid_t pid = 0; + char * api_id = NULL; + char * aei_id = NULL; + size_t len = 0; + char * ipcp_dir = "bin/ipcpd"; + char * full_name = NULL; + + pid = fork(); + if (pid == -1) { + LOG_ERR("Failed to fork"); + return pid; + } + + if (pid != 0) { + return pid; + } + + api_id = malloc(n_digits(name.api_id) + 1); + if (!api_id) { + LOG_ERR("Failed to malloc"); + exit(-1); + } + sprintf(api_id, "%d", name.api_id); + + aei_id = malloc(n_digits(name.aei_id) + 1); + if (!aei_id) { + LOG_ERR("Failed to malloc"); + exit(-1); + } + sprintf(aei_id, "%d", name.aei_id); + + len += strlen(INSTALL_DIR); + len += strlen(ipcp_dir); + len += 2; + full_name = malloc(len); + if (!full_name) { + LOG_ERR("Failed to malloc"); + exit(-1); + } + + strcpy(full_name, INSTALL_DIR); + strcat(full_name, "/"); + strcat(full_name, ipcp_dir); + + char * argv[] = {full_name, + name.ap_name, api_id, + name.ae_name, aei_id, + ipcp_type, 0}; + + char * envp[] = {0}; + + execve(argv[0], &argv[0], envp); + + LOG_DBG("%s", strerror(errno)); + LOG_ERR("Failed to load IPCP daemon"); + LOG_ERR("Make sure to run the installed version"); + exit(-1); } -int ipcp_destroy(int pid) +int ipcp_destroy(pid_t pid) { - return -1; + int status; + + if (kill(pid, SIGTERM)) { + LOG_ERR("Failed to destroy IPCP"); + return -1; + } + + if (waitpid(pid, &status, 0) < 0) { + LOG_ERR("Failed to destroy IPCP"); + return -1; + } + + return 0; } -int ipcp_reg(int pid, +int ipcp_reg(pid_t pid, char ** difs, size_t difs_size) { return -1; } -int ipcp_unreg(int pid, +int ipcp_unreg(pid_t pid, char ** difs, size_t difs_size) { return -1; } -int ipcp_bootstrap(int pid, +int ipcp_bootstrap(pid_t pid, struct dif_config conf) { return -1; } -int ipcp_enroll(int pid, +int ipcp_enroll(pid_t pid, char * dif_name, rina_name_t member, char ** n_1_difs, diff --git a/src/lib/rina_name.c b/src/lib/rina_name.c index b9044277..471f6fda 100644 --- a/src/lib/rina_name.c +++ b/src/lib/rina_name.c @@ -24,6 +24,7 @@ #include <ouroboros/logs.h> #include <ouroboros/common.h> #include <ouroboros/rina_name.h> +#include <ouroboros/utils.h> #include <string.h> #include <math.h> @@ -220,18 +221,6 @@ bool name_is_equal(const rina_name_t * a, const rina_name_t * b) { return name_cmp(NAME_CMP_ALL, a, b); } -static int n_digits(unsigned i) -{ - int n = 1; - - while (i > 9) { - n++; - i /= 10; - } - - return n; -} - #define DELIMITER "/" char * name_to_string(const rina_name_t * n) diff --git a/src/lib/utils.c b/src/lib/utils.c new file mode 100644 index 00000000..ca082642 --- /dev/null +++ b/src/lib/utils.c @@ -0,0 +1,33 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Handy utilities + * + * Sander Vrijders <[email protected]> + * + * 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 n_digits(unsigned i) +{ + int n = 1; + + while (i > 9) { + n++; + i /= 10; + } + + return n; +} |