diff options
-rw-r--r-- | include/ouroboros/config.h.in | 5 | ||||
-rw-r--r-- | src/ipcpd/shim-udp/CMakeLists.txt | 40 | ||||
-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/lib/dev.c | 14 |
5 files changed, 84 insertions, 43 deletions
diff --git a/include/ouroboros/config.h.in b/include/ouroboros/config.h.in index 380c1065..2a496343 100644 --- a/include/ouroboros/config.h.in +++ b/include/ouroboros/config.h.in @@ -26,10 +26,11 @@ #define PROJECT_NAME "@CMAKE_PROJECT_NAME@" #define PROJECT_VERSION "@PACKAGE_VERSION@" #define INSTALL_DIR "@CMAKE_INSTALL_PREFIX@" -#define BUILD_TYPE "@CMAKE_BUILD_TYPE@" #define _POSIX_C_SOURCE 199506L #define IPCP_SHIM_UDP_EXEC "@IPCP_SHIM_UDP_TARGET@" #define IPCP_NORMAL_EXEC "@IPCP_NORMAL_TARGET@" -#define NSUPDATE_EXEC "@NSUPDATE_EXECUTABLE@" +#define AP_MAX_FLOWS 256 +#define DU_BUFF_HEADSPACE 128 +#define DU_BUFF_TAILSPACE 0 #endif diff --git a/src/ipcpd/shim-udp/CMakeLists.txt b/src/ipcpd/shim-udp/CMakeLists.txt index c71fa00b..a50fe8bd 100644 --- a/src/ipcpd/shim-udp/CMakeLists.txt +++ b/src/ipcpd/shim-udp/CMakeLists.txt @@ -1,5 +1,7 @@ -get_filename_component(CURRENT_SOURCE_PARENT_DIR ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) -get_filename_component(CURRENT_BINARY_PARENT_DIR ${CMAKE_CURRENT_BINARY_DIR} DIRECTORY) +get_filename_component(CURRENT_SOURCE_PARENT_DIR + ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) +get_filename_component(CURRENT_BINARY_PARENT_DIR + ${CMAKE_CURRENT_BINARY_DIR} DIRECTORY) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) @@ -18,33 +20,47 @@ IF(NOT CMAKE_HAVE_GETHOSTBYNAME) IF (CMAKE_LIB_NSL_HAS_GETHOSTBYNAME) SET (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -lnsl) ELSE (CMAKE_LIB_NSL_HAS_GETHOSTBYNAME) - CHECK_LIBRARY_EXISTS("bsd" "gethostbyname" "" CMAKE_LIB_BSD_HAS_GETHOSTBYNAME) + CHECK_LIBRARY_EXISTS("bsd" "gethostbyname" "" + CMAKE_LIB_BSD_HAS_GETHOSTBYNAME) IF (CMAKE_LIB_BSD_HAS_GETHOSTBYNAME) SET (X11_X_EXTRA_LIBS ${X11_X_EXTRA_LIBS} -lbsd) ENDIF (CMAKE_LIB_BSD_HAS_GETHOSTBYNAME) ENDIF (CMAKE_LIB_NSL_HAS_GETHOSTBYNAME) ENDIF(NOT CMAKE_HAVE_GETHOSTBYNAME) -# Find the nsupdate executable -find_program(NSUPDATE_EXECUTABLE - NAMES nsupdate - DOC "The nsupdate tool that enables DDNS") +# Enable DNS by default +if (NOT DISABLE_DNS MATCHES True) + # Find the nsupdate executable + find_program(NSUPDATE_EXECUTABLE + NAMES nsupdate + DOC "The nsupdate tool that enables DDNS") -if (${NSUPDATE_EXECUTABLE} STREQUAL "NSUPDATE_EXECUTABLE-NOTFOUND") - message(FATAL_ERROR "Could not find nsupdate, which is needed for DDNS") -else() - message("-- Found nsupdate: ${NSUPDATE_EXECUTABLE}") + if (${NSUPDATE_EXECUTABLE} STREQUAL "NSUPDATE_EXECUTABLE-NOTFOUND") + message(FATAL_ERROR "Could not find nsupdate, which is needed for DDNS") + else() + message("-- Found nsupdate: ${NSUPDATE_EXECUTABLE}") + endif() endif() +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(SHIM_UDP_SOURCES # Add source files here ${CMAKE_CURRENT_SOURCE_DIR}/main.c) -add_executable (ipcpd-shim-udp ${SHIM_UDP_SOURCES} ${IPCP_SOURCES}) +add_executable (ipcpd-shim-udp ${SHIM_UDP_SOURCES} ${IPCP_SOURCES} + "${CMAKE_CURRENT_BINARY_DIR}/shim_udp_config.h") target_link_libraries (ipcpd-shim-udp LINK_PUBLIC ouroboros) +# Enable DNS by default +if (NOT DISABLE_DNS MATCHES True) + MACRO_ADD_COMPILE_FLAGS(ipcpd-shim-udp -DCONFIG_OUROBOROS_ENABLE_DNS) +endif() + include(MacroAddCompileFlags) if (CMAKE_BUILD_TYPE MATCHES Debug) MACRO_ADD_COMPILE_FLAGS(ipcpd-shim-udp -DCONFIG_OUROBOROS_DEBUG) diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c index e213f019..b45bee76 100644 --- a/src/ipcpd/shim-udp/main.c +++ b/src/ipcpd/shim-udp/main.c @@ -23,6 +23,7 @@ #include <ouroboros/config.h> #include "ipcp.h" #include "flow.h" +#include "shim_udp_config.h" #include <ouroboros/shm_du_map.h> #include <ouroboros/shm_ap_rbuff.h> #include <ouroboros/list.h> @@ -31,6 +32,7 @@ #include <ouroboros/dif_config.h> #include <ouroboros/sockets.h> #include <ouroboros/bitmap.h> +#include <ouroboros/dev.h> #define OUROBOROS_PREFIX "ipcpd/shim-udp" @@ -74,19 +76,6 @@ struct ipcp * _ipcp; * the info */ -#define UNKNOWN_AP "__UNKNOWN_AP__" -#define UNKNOWN_AE "__UNKNOWN_AE__" - -#define AP_MAX_FLOWS 256 - -#ifndef DU_BUFF_HEADSPACE - #define DU_BUFF_HEADSPACE 128 -#endif - -#ifndef DU_BUFF_TAILSPACE - #define DU_BUFF_TAILSPACE 0 -#endif - /* the shim needs access to these internals */ struct shim_ap_data { instance_name_t * api; @@ -332,8 +321,11 @@ static void * ipcp_udp_listener() } /* echo back the packet */ - while(send(fd, buf, strlen(buf), 0) < 0) - ; + if (send(fd, buf, strlen(buf), 0) < 0) { + LOG_ERR("Failed to echo back the packet."); + close(fd); + continue; + } /* reply to IRM */ @@ -413,12 +405,16 @@ int ipcp_udp_bootstrap(struct dif_config * conf) ipstr, INET_ADDRSTRLEN); - if (conf->dns_addr != 0) + if (conf->dns_addr != 0) { inet_ntop(AF_INET, &conf->dns_addr, dnsstr, INET_ADDRSTRLEN); - else +#ifndef CONFIG_OUROBOROS_ENABLE_DNS + LOG_WARN("DNS address ignored since shim-udp was " + "compiled without DNS support."); +#endif + } else strcpy(dnsstr, "not set"); shim_data(_ipcp)->ip_addr = conf->ip_addr; @@ -480,6 +476,7 @@ int ipcp_udp_bootstrap(struct dif_config * conf) return 0; } +#ifdef CONFIG_OUROBOROS_ENABLE_DNS /* FIXME: Dependency on nsupdate to be removed in the end */ static int ddns_send(char * cmd) { @@ -524,15 +521,18 @@ static int ddns_send(char * cmd) close(pipe_fd[1]); return 0; } +#endif int ipcp_udp_name_reg(char * name) { +#ifdef CONFIG_OUROBOROS_ENABLE_DNS char ipstr[INET_ADDRSTRLEN]; char dnsstr[INET_ADDRSTRLEN]; /* max DNS name length + max IP length + command length */ char cmd[100]; uint32_t dns_addr; uint32_t ip_addr; +#endif if (_ipcp->state != IPCP_ENROLLED) { LOG_DBGF("Won't register with non-enrolled IPCP."); @@ -549,6 +549,7 @@ int ipcp_udp_name_reg(char * name) return -1; } +#ifdef CONFIG_OUROBOROS_ENABLE_DNS /* register application with DNS server */ dns_addr = shim_data(_ipcp)->dns_addr; @@ -565,6 +566,7 @@ int ipcp_udp_name_reg(char * name) return -1; } } +#endif LOG_DBG("Registered %s.", name); @@ -573,16 +575,19 @@ int ipcp_udp_name_reg(char * name) int ipcp_udp_name_unreg(char * name) { +#ifdef CONFIG_OUROBOROS_ENABLE_DNS char dnsstr[INET_ADDRSTRLEN]; /* max DNS name length + max IP length + max command length */ char cmd[100]; uint32_t dns_addr; +#endif if (strlen(name) > 24) { LOG_ERR("DNS names cannot be longer than 24 chars."); return -1; } +#ifdef CONFIG_OUROBOROS_ENABLE_DNS /* unregister application with DNS server */ dns_addr = shim_data(_ipcp)->dns_addr; @@ -593,6 +598,7 @@ int ipcp_udp_name_unreg(char * name) ddns_send(cmd); } +#endif ipcp_data_del_reg_entry(_ipcp->data, name); diff --git a/src/ipcpd/shim-udp/shim_udp_config.h.in b/src/ipcpd/shim-udp/shim_udp_config.h.in new file mode 100644 index 00000000..00b0b910 --- /dev/null +++ b/src/ipcpd/shim-udp/shim_udp_config.h.in @@ -0,0 +1,28 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Configuration information specific for the shim UDP + * + * 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_SHIM_UDP_CONFIG +#define OUROBOROS_SHIM_UDP_CONFIG + +#define NSUPDATE_EXEC "@NSUPDATE_EXECUTABLE@" + +#endif diff --git a/src/lib/dev.c b/src/lib/dev.c index c1cfe043..24e688ef 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -22,6 +22,7 @@ #define OUROBOROS_PREFIX "libouroboros-dev" +#include <ouroboros/config.h> #include <ouroboros/logs.h> #include <ouroboros/dev.h> #include <ouroboros/sockets.h> @@ -34,16 +35,6 @@ #include <stdlib.h> #include <string.h> -#define AP_MAX_FLOWS 256 - -#ifndef DU_BUFF_HEADSPACE - #define DU_BUFF_HEADSPACE 128 -#endif - -#ifndef DU_BUFF_TAILSPACE - #define DU_BUFF_TAILSPACE 0 -#endif - struct flow { struct shm_ap_rbuff * rb; int port_id; @@ -161,7 +152,7 @@ int ap_reg(char ** difs, } if (_ap_instance == NULL) { - LOG_DBG("ap_init was not called"); + LOG_DBG("ap_init was not called."); return -1; } @@ -416,7 +407,6 @@ int flow_cntl(int fd, int cmd, int oflags) ssize_t flow_write(int fd, void * buf, size_t count) { - /* the AP chooses the amount of headspace and tailspace */ size_t index = shm_create_du_buff(_ap_instance->dum, count + DU_BUFF_HEADSPACE + DU_BUFF_TAILSPACE, |