diff options
Diffstat (limited to 'src/ipcpd/shim-udp')
-rw-r--r-- | src/ipcpd/shim-udp/CMakeLists.txt | 17 | ||||
-rw-r--r-- | src/ipcpd/shim-udp/main.c | 40 | ||||
-rw-r--r-- | src/ipcpd/shim-udp/shim_udp_config.h.in | 28 | ||||
-rw-r--r-- | src/ipcpd/shim-udp/tests/CMakeLists.txt | 33 | ||||
-rw-r--r-- | src/ipcpd/shim-udp/tests/shim_udp_test.c | 100 |
5 files changed, 33 insertions, 185 deletions
diff --git a/src/ipcpd/shim-udp/CMakeLists.txt b/src/ipcpd/shim-udp/CMakeLists.txt index 3ff8dd5f..eff3f5d0 100644 --- a/src/ipcpd/shim-udp/CMakeLists.txt +++ b/src/ipcpd/shim-udp/CMakeLists.txt @@ -15,18 +15,14 @@ include_directories(${CMAKE_BINARY_DIR}/include) protobuf_generate_c(SHIM_UDP_PROTO_SRCS SHIM_UDP_PROTO_HDRS shim_udp_messages.proto) -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/shim_udp_config.h.in" - "${CMAKE_CURRENT_BINARY_DIR}/shim_udp_config.h") - -set(IPCP_SHIM_UDP_TARGET ipcpd-shim-udp CACHE STRING "IPCP_SHIM_UDP_TARGET") +set(IPCP_SHIM_UDP_TARGET ipcpd-shim-udp CACHE INTERNAL "") set(SHIM_UDP_SOURCES # Add source files here ${CMAKE_CURRENT_SOURCE_DIR}/main.c) add_executable(ipcpd-shim-udp ${SHIM_UDP_SOURCES} ${IPCP_SOURCES} - ${SHIM_UDP_PROTO_SRCS} "${CMAKE_CURRENT_BINARY_DIR}/shim_udp_config.h") + ${SHIM_UDP_PROTO_SRCS}) target_link_libraries(ipcpd-shim-udp LINK_PUBLIC ouroboros ${PROTOBUF_C_LIBRARY}) @@ -40,10 +36,12 @@ find_program(NSLOOKUP_EXECUTABLE NAMES nslookup DOC "The nslookup tool that resolves DNS names") +mark_as_advanced(NSLOOKUP_EXECUTABLE NSUPDATE_EXECUTABLE) + include(AddCompileFlags) -if (${NSUPDATE_EXECUTABLE} STREQUAL "NSUPDATE_EXECUTABLE-NOTFOUND") +if (NOT NSUPDATE_EXECUTABLE) message(STATUS "Could not find nsupdate. Disabling DDNS functionality.") -elseif (${NSLOOKUP_EXECUTABLE} STREQUAL "NSLOOKUP_EXECUTABLE-NOTFOUND") +elseif (NOT NSLOOKUP_EXECUTABLE) message(STATUS "Could not find nslookup. Disabling DNS lookups.") else () message(STATUS "Found nsupdate: ${NSUPDATE_EXECUTABLE}") @@ -56,6 +54,3 @@ if (CMAKE_BUILD_TYPE MATCHES Debug) endif (CMAKE_BUILD_TYPE MATCHES Debug) install(TARGETS ipcpd-shim-udp RUNTIME DESTINATION sbin) - -# Enable once ipcp-shim-udp has tests -# add_subdirectory(tests) diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c index 195e3bc0..55fe19a6 100644 --- a/src/ipcpd/shim-udp/main.c +++ b/src/ipcpd/shim-udp/main.c @@ -20,9 +20,12 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ +#define _POSIX_C_SOURCE 200112L + +#include "config.h" + #define OUROBOROS_PREFIX "ipcpd/shim-udp" -#include <ouroboros/config.h> #include <ouroboros/hash.h> #include <ouroboros/list.h> #include <ouroboros/utils.h> @@ -32,9 +35,9 @@ #include <ouroboros/errno.h> #include <ouroboros/logs.h> -#include "shim_udp_messages.pb-c.h" #include "ipcp.h" -#include "shim_udp_config.h" +#include "shim-data.h" +#include "shim_udp_messages.pb-c.h" #include <string.h> #include <sys/socket.h> @@ -68,6 +71,8 @@ struct uf { }; struct { + struct shim_data * shim_data; + uint32_t ip_addr; uint32_t dns_addr; /* listen server */ @@ -79,7 +84,7 @@ struct { fd_set flow_fd_s; /* bidir mappings of (n - 1) file descriptor to (n) flow descriptor */ int uf_to_fd[FD_SETSIZE]; - struct uf fd_to_uf[IRMD_MAX_FLOWS]; + struct uf fd_to_uf[SYS_MAX_FLOWS]; pthread_rwlock_t flows_lock; pthread_t sduloop; @@ -98,7 +103,7 @@ static int udp_data_init(void) for (i = 0; i < FD_SETSIZE; ++i) udp_data.uf_to_fd[i] = -1; - for (i = 0; i < IRMD_MAX_FLOWS; ++i) { + for (i = 0; i < SYS_MAX_FLOWS; ++i) { udp_data.fd_to_uf[i].skfd = -1; udp_data.fd_to_uf[i].udp = -1; } @@ -115,6 +120,13 @@ static int udp_data_init(void) return -ENOMEM; } + udp_data.shim_data = shim_data_create(); + if (udp_data.shim_data == NULL) { + fqueue_destroy(udp_data.fq); + flow_set_destroy(udp_data.np1_flows); + return -ENOMEM; + } + pthread_rwlock_init(&udp_data.flows_lock, NULL); pthread_cond_init(&udp_data.fd_set_cond, NULL); pthread_mutex_init(&udp_data.fd_set_lock, NULL); @@ -127,6 +139,8 @@ static void udp_data_fini(void) flow_set_destroy(udp_data.np1_flows); fqueue_destroy(udp_data.fq); + shim_data_destroy(udp_data.shim_data); + pthread_rwlock_destroy(&udp_data.flows_lock); pthread_mutex_destroy(&udp_data.fd_set_lock); pthread_cond_destroy(&udp_data.fd_set_cond); @@ -322,7 +336,7 @@ static int udp_port_to_fd(int udp_port) { int i; - for (i = 0; i < IRMD_MAX_FLOWS; ++i) + for (i = 0; i < SYS_MAX_FLOWS; ++i) if (udp_data.fd_to_uf[i].udp == udp_port) return i; @@ -765,7 +779,7 @@ static int ipcp_udp_reg(const uint8_t * hash) return -ENOMEM; } - if (shim_data_reg_add_entry(ipcpi.shim_data, hash_dup)) { + if (shim_data_reg_add_entry(udp_data.shim_data, hash_dup)) { log_err("Failed to add " HASH_FMT " to local registry.", HASH_VAL(hash)); free(hash_dup); @@ -794,7 +808,7 @@ static int ipcp_udp_reg(const uint8_t * hash) dnsstr, hashstr, DNS_TTL, ipstr); if (ddns_send(cmd)) { - shim_data_reg_del_entry(ipcpi.shim_data, hash_dup); + shim_data_reg_del_entry(udp_data.shim_data, hash_dup); return -1; } } @@ -835,7 +849,7 @@ static int ipcp_udp_unreg(const uint8_t * hash) } #endif - shim_data_reg_del_entry(ipcpi.shim_data, hash); + shim_data_reg_del_entry(udp_data.shim_data, hash); log_dbg("Unregistered " HASH_FMT ".", HASH_VAL(hash)); @@ -855,7 +869,7 @@ static int ipcp_udp_query(const uint8_t * hash) ipcp_hash_str(hashstr, hash); - if (shim_data_dir_has(ipcpi.shim_data, hash)) + if (shim_data_dir_has(udp_data.shim_data, hash)) return 0; #ifdef CONFIG_OUROBOROS_ENABLE_DNS @@ -880,7 +894,7 @@ static int ipcp_udp_query(const uint8_t * hash) } #endif - if (shim_data_dir_add_entry(ipcpi.shim_data, hash, ip_addr)) { + if (shim_data_dir_add_entry(udp_data.shim_data, hash, ip_addr)) { log_err("Failed to add directory entry."); return -1; } @@ -926,12 +940,12 @@ static int ipcp_udp_flow_alloc(int fd, return -1; } - if (!shim_data_dir_has(ipcpi.shim_data, dst)) { + if (!shim_data_dir_has(udp_data.shim_data, dst)) { log_dbg("Could not resolve destination."); close(skfd); return -1; } - ip_addr = (uint32_t) shim_data_dir_get_addr(ipcpi.shim_data, dst); + ip_addr = (uint32_t) shim_data_dir_get_addr(udp_data.shim_data, dst); /* connect to server (store the remote IP address in the fd) */ memset((char *) &r_saddr, 0, sizeof(r_saddr)); diff --git a/src/ipcpd/shim-udp/shim_udp_config.h.in b/src/ipcpd/shim-udp/shim_udp_config.h.in deleted file mode 100644 index c32210e9..00000000 --- a/src/ipcpd/shim-udp/shim_udp_config.h.in +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * Configuration information specific for the shim UDP - * - * Sander Vrijders <sander.vrijders@intec.ugent.be> - * - * 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/. - */ - -#ifndef OUROBOROS_SHIM_UDP_CONFIG -#define OUROBOROS_SHIM_UDP_CONFIG - -#define NSUPDATE_EXEC "@NSUPDATE_EXECUTABLE@" -#define NSLOOKUP_EXEC "@NSLOOKUP_EXECUTABLE@" - -#endif diff --git a/src/ipcpd/shim-udp/tests/CMakeLists.txt b/src/ipcpd/shim-udp/tests/CMakeLists.txt deleted file mode 100644 index bdd7defb..00000000 --- a/src/ipcpd/shim-udp/tests/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -get_filename_component(PARENT_SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) -get_filename_component(PARENT_BINARY_PATH ${CMAKE_CURRENT_BINARY_DIR} DIRECTORY) -get_filename_component(PARENT_DIR ${PARENT_SOURCE_PATH} NAME) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - -include_directories(${PARENT_SOURCE_PATH}) -include_directories(${PARENT_BINARY_PATH}) - -include_directories(${CMAKE_SOURCE_DIR}/include) -include_directories(${CMAKE_BINARY_DIR}/include) - -create_test_sourcelist(${PARENT_DIR}_tests test_suite.c - # Add new tests here - shim_udp_test.c -) - -add_executable(${PARENT_DIR}_test EXCLUDE_FROM_ALL ${IPCP_SOURCES} ${${PARENT_DIR}_tests}) -target_link_libraries(${PARENT_DIR}_test ouroboros) - -include(MacroAddCompileFlags) -MACRO_ADD_COMPILE_FLAGS(${PARENT_DIR}_test -DMAKE_CHECK) - -add_dependencies(check ${PARENT_DIR}_test) - -set(tests_to_run ${${PARENT_DIR}_tests}) -remove(tests_to_run test_suite.c) - -foreach(test ${tests_to_run}) - get_filename_component(test_name ${test} NAME_WE) - add_test(${test_name} ${C_TEST_PATH}/${PARENT_DIR}_test ${test_name}) -endforeach(test) diff --git a/src/ipcpd/shim-udp/tests/shim_udp_test.c b/src/ipcpd/shim-udp/tests/shim_udp_test.c deleted file mode 100644 index 88669a9e..00000000 --- a/src/ipcpd/shim-udp/tests/shim_udp_test.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * Test of the Shim UDP IPCP Daemon - * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> - * - * 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 <ouroboros/config.h> -#include <ouroboros/ipcp.h> -#include <ouroboros/utils.h> -#include <ouroboros/shm_du_map.h> -#include <sys/types.h> -#include <stdlib.h> -#include "main.c" - -#include <ouroboros/logs.h> - -struct ipcp * _ipcp; - -int shim_udp_test(int argc, char ** argv) -{ - struct shm_du_map * dum; - char * ipcp_name = "test-shim-ipcp"; - int i = 0; - - char bogus[16]; - memset(&bogus, 0, 16); - - struct ipcp_config conf; - memset(&conf, 0, sizeof conf); - conf.dif_name = strdup("test-dif"); - conf.type = IPCP_SHIM_UDP; - conf.ip_addr = 0; - - dum = shm_du_map_create(); - if (dum == NULL) { - log_err("Failed to create shared memory."); - exit(1); - } - - _ipcp = ipcp_udp_create(ipcp_name); - if (_ipcp == NULL) { - log_err("Could not instantiate shim IPCP."); - shm_du_map_destroy(dum); - exit(1); - } - - if (ipcp_udp_bootstrap(&conf)) { - log_err("Could not bootstrap."); - } - - if (ipcp_udp_name_reg("bogus name")) { - log_err("Failed to register application."); - shm_du_map_destroy(dum); - exit(1); - } - - if (ipcp_udp_name_unreg("bogus name")) { - log_err("Failed to unregister application."); - shm_du_map_destroy(dum); - exit(1); - } - - for (i = 0; i < 1000; ++i) { - sprintf(bogus, "bogus name %4d", i); - if (ipcp_udp_name_reg(bogus)) { - log_err("Failed to register application %s.", bogus); - shm_du_map_destroy(dum); - exit(1); - } - } - - for (i = 0; i < 1000; ++i) { - sprintf(bogus, "bogus name %4d", i); - if(ipcp_udp_name_unreg(bogus)) { - log_err("Failed to unregister application %s.", bogus); - shm_du_map_destroy(dum); - exit(1); - } - } - - shm_du_map_destroy(dum); - - exit(0); -} |