summaryrefslogtreecommitdiff
path: root/src/ipcpd/shim-udp
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-04-26 18:16:08 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-04-26 18:16:08 +0200
commita17657c4321dc0770e5431467261eb2bc579f79c (patch)
tree9f64215f326c3847699ae8856ae9cd0d609cbfac /src/ipcpd/shim-udp
parent45b7d79088174303193f8772c9b14fed2011551e (diff)
downloadouroboros-a17657c4321dc0770e5431467261eb2bc579f79c.tar.gz
ouroboros-a17657c4321dc0770e5431467261eb2bc579f79c.zip
shim-udp: resolve dst_name using DNS
This commits adds the gethostbyname call to resolve the dst_name for a flow allocation using DNS. The DNS server should be specified using the method mandated by the system (e.g. added to /etc/resolv.conf).
Diffstat (limited to 'src/ipcpd/shim-udp')
-rw-r--r--src/ipcpd/shim-udp/CMakeLists.txt15
-rw-r--r--src/ipcpd/shim-udp/main.c28
-rw-r--r--src/ipcpd/shim-udp/tests/shim_udp_test.c14
3 files changed, 37 insertions, 20 deletions
diff --git a/src/ipcpd/shim-udp/CMakeLists.txt b/src/ipcpd/shim-udp/CMakeLists.txt
index 27907880..f730fa3a 100644
--- a/src/ipcpd/shim-udp/CMakeLists.txt
+++ b/src/ipcpd/shim-udp/CMakeLists.txt
@@ -10,6 +10,21 @@ include_directories(${CURRENT_BINARY_PARENT_DIR})
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_BINARY_DIR}/include)
+# Find library needed for gethostbyname.
+include(CheckFunctionExists)
+CHECK_FUNCTION_EXISTS("gethostbyname" CMAKE_HAVE_GETHOSTBYNAME)
+IF(NOT CMAKE_HAVE_GETHOSTBYNAME)
+ CHECK_LIBRARY_EXISTS("nsl" "gethostbyname" "" CMAKE_LIB_NSL_HAS_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)
+ 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)
+
SET(IPCP_SHIM_UDP_TARGET ipcpd-shim-udp CACHE STRING "IPCP_SHIM_UDP_TARGET")
set(SHIM_UDP_SOURCES
diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c
index 785f2344..029df111 100644
--- a/src/ipcpd/shim-udp/main.c
+++ b/src/ipcpd/shim-udp/main.c
@@ -21,7 +21,6 @@
*/
#include <ouroboros/config.h>
-
#include "ipcp.h"
#include "flow.h"
#include <ouroboros/shm_du_map.h>
@@ -310,7 +309,7 @@ int ipcp_udp_bootstrap(struct dif_config * conf)
dnsstr,
INET_ADDRSTRLEN);
else
- strcpy(dnsstr, "not set");
+ strcpy(dnsstr, "not set.\n");
shim_data(_ipcp)->ip_addr = conf->ip_addr;
shim_data(_ipcp)->dns_addr = conf->dns_addr;
@@ -381,7 +380,7 @@ int ipcp_udp_name_unreg(char * name)
}
int ipcp_udp_flow_alloc(uint32_t port_id,
- char * dst_ap_name,
+ char * dst_name,
char * src_ap_name,
char * src_ae_name,
struct qos_spec * qos)
@@ -390,16 +389,18 @@ int ipcp_udp_flow_alloc(uint32_t port_id,
struct sockaddr_in l_saddr;
struct sockaddr_in r_saddr;
+ struct hostent * h;
+
irm_msg_t msg = IRM_MSG__INIT;
irm_msg_t * ret_msg = NULL;
- if (dst_ap_name == NULL || src_ap_name == NULL || src_ae_name == NULL)
+ if (dst_name == NULL || src_ap_name == NULL || src_ae_name == NULL)
return -1;
LOG_DBG("Received flow allocation request from %s to %s.",
- src_ap_name, dst_ap_name);
+ src_ap_name, dst_name);
- if (strlen(dst_ap_name) > 255
+ if (strlen(dst_name) > 255
|| strlen(src_ap_name) > 255
|| strlen(src_ae_name) > 255) {
LOG_ERR("Name too long for this shim.");
@@ -436,20 +437,21 @@ int ipcp_udp_flow_alloc(uint32_t port_id,
return -1;
}
- /* FIXME: use calls to specify DDNS server */
-
-#define IP_ADDR 0x7f000001; /* localhost */
+ h = gethostbyname(dst_name);
+ if (h == NULL) {
+ close(flow->fd);
+ free(flow);
+ return -1;
+ }
- LOG_MISSING;
memset((char *) &r_saddr, 0, sizeof r_saddr);
r_saddr.sin_family = AF_INET;
- /* FIXME: pull in correct IP address */
- r_saddr.sin_addr.s_addr = IP_ADDR; /* FIXME */
+ r_saddr.sin_addr.s_addr = (uint32_t) *(h->h_addr_list[0]);
r_saddr.sin_port = LISTEN_PORT;
/* at least try to get the packet on the wire */
- while (sendto(flow->fd, dst_ap_name, strlen(dst_ap_name), 0,
+ while (sendto(flow->fd, dst_name, strlen(dst_name), 0,
(struct sockaddr *) &r_saddr, sizeof r_saddr) < 0)
flow->flow.port_id = port_id;
diff --git a/src/ipcpd/shim-udp/tests/shim_udp_test.c b/src/ipcpd/shim-udp/tests/shim_udp_test.c
index 4e0c2dd6..d2b9c642 100644
--- a/src/ipcpd/shim-udp/tests/shim_udp_test.c
+++ b/src/ipcpd/shim-udp/tests/shim_udp_test.c
@@ -42,10 +42,10 @@ int shim_udp_test(int argc, char ** argv)
int i = 0;
char bogus[15];
- memset (&bogus, 0, 15);
+ memset(&bogus, 0, 15);
struct dif_config conf;
- memset (&conf, 0, sizeof conf);
+ memset(&conf, 0, sizeof conf);
conf.dif_name = strdup("test-dif");
conf.type = IPCP_SHIM_UDP;
conf.ip_addr = 0;
@@ -63,11 +63,11 @@ int shim_udp_test(int argc, char ** argv)
exit(1);
}
- if (ipcp_udp_bootstrap (&conf)) {
+ if (ipcp_udp_bootstrap(&conf)) {
LOG_ERR("Could not bootstrap.");
}
- if(ipcp_udp_name_reg("bogus name")) {
+ if (ipcp_udp_name_reg("bogus name")) {
LOG_ERR("Failed to register application.");
shm_du_map_close(dum);
exit(1);
@@ -80,8 +80,8 @@ int shim_udp_test(int argc, char ** argv)
}
for (i = 0; i < 1000; ++i) {
- sprintf (bogus, "bogus name %4d", i);
- if(ipcp_udp_name_reg(bogus)) {
+ sprintf(bogus, "bogus name %4d", i);
+ if (ipcp_udp_name_reg(bogus)) {
LOG_ERR("Failed to register application %s.", bogus);
shm_du_map_close(dum);
exit(1);
@@ -89,7 +89,7 @@ int shim_udp_test(int argc, char ** argv)
}
for (i = 0; i < 1000; ++i) {
- sprintf (bogus, "bogus name %4d", i);
+ sprintf(bogus, "bogus name %4d", i);
if(ipcp_udp_name_unreg(bogus)) {
LOG_ERR("Failed to unregister application %s.", bogus);
shm_du_map_close(dum);