summaryrefslogtreecommitdiff
path: root/src/ipcpd
diff options
context:
space:
mode:
Diffstat (limited to 'src/ipcpd')
-rw-r--r--src/ipcpd/shim-udp/CMakeLists.txt9
-rw-r--r--src/ipcpd/shim-udp/main.c127
-rw-r--r--src/ipcpd/shim-udp/shim_udp_messages.proto37
3 files changed, 69 insertions, 104 deletions
diff --git a/src/ipcpd/shim-udp/CMakeLists.txt b/src/ipcpd/shim-udp/CMakeLists.txt
index cc419fd0..aaf7e83b 100644
--- a/src/ipcpd/shim-udp/CMakeLists.txt
+++ b/src/ipcpd/shim-udp/CMakeLists.txt
@@ -12,19 +12,14 @@ include_directories(${CURRENT_BINARY_PARENT_DIR})
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_BINARY_DIR}/include)
-protobuf_generate_c(SHIM_UDP_PROTO_SRCS SHIM_UDP_PROTO_HDRS
- shim_udp_messages.proto)
-
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})
-target_link_libraries(ipcpd-shim-udp LINK_PUBLIC ouroboros-dev
- ${PROTOBUF_C_LIBRARY})
+add_executable(ipcpd-shim-udp ${SHIM_UDP_SOURCES} ${IPCP_SOURCES})
+target_link_libraries(ipcpd-shim-udp LINK_PUBLIC ouroboros-dev)
# Find the nsupdate executable
find_program(NSUPDATE_EXECUTABLE
diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c
index 4fafc4de..79d5ea83 100644
--- a/src/ipcpd/shim-udp/main.c
+++ b/src/ipcpd/shim-udp/main.c
@@ -37,7 +37,6 @@
#include "ipcp.h"
#include "shim-data.h"
-#include "shim_udp_messages.pb-c.h"
#include <string.h>
#include <sys/socket.h>
@@ -51,23 +50,32 @@
#include <sys/wait.h>
#include <fcntl.h>
-typedef ShimUdpMsg shim_udp_msg_t;
+#define FLOW_REQ 1
+#define FLOW_REPLY 2
-#define THIS_TYPE IPCP_SHIM_UDP
-#define LISTEN_PORT htons(0x0D1F)
-#define SHIM_UDP_BUF_SIZE 256
-#define SHIM_UDP_MSG_SIZE 256
+#define THIS_TYPE IPCP_SHIM_UDP
+#define LISTEN_PORT htons(0x0D1F)
+#define SHIM_UDP_BUF_SIZE 256
+#define SHIM_UDP_MSG_SIZE 256
#define SHIM_UDP_MAX_SDU_SIZE 8980
-#define DNS_TTL 86400
-#define FD_UPDATE_TIMEOUT 100 /* microseconds */
+#define DNS_TTL 86400
+#define FD_UPDATE_TIMEOUT 100 /* microseconds */
-#define local_ip (udp_data.s_saddr.sin_addr.s_addr)
+#define local_ip (udp_data.s_saddr.sin_addr.s_addr)
-#define UDP_MAX_PORTS 0xFFFF
+#define UDP_MAX_PORTS 0xFFFF
+
+struct mgmt_msg {
+ uint16_t src_udp_port;
+ uint16_t dst_udp_port;
+ uint8_t code;
+ uint8_t qoscube;
+ uint8_t response;
+} __attribute__((packed));
struct uf {
- int udp;
- int skfd;
+ int udp;
+ int skfd;
};
struct {
@@ -172,10 +180,10 @@ static void clr_fd(int fd)
pthread_mutex_unlock(&udp_data.fd_set_lock);
}
-static int send_shim_udp_msg(shim_udp_msg_t * msg,
- uint32_t dst_ip_addr)
+static int send_shim_udp_msg(uint8_t * buf,
+ size_t len,
+ uint32_t dst_ip_addr)
{
- buffer_t buf;
struct sockaddr_in r_saddr;
memset((char *)&r_saddr, 0, sizeof(r_saddr));
@@ -183,30 +191,13 @@ static int send_shim_udp_msg(shim_udp_msg_t * msg,
r_saddr.sin_addr.s_addr = dst_ip_addr;
r_saddr.sin_port = LISTEN_PORT;
- buf.len = shim_udp_msg__get_packed_size(msg);
- if (buf.len == 0) {
- return -1;
- }
-
- buf.data = malloc(SHIM_UDP_MSG_SIZE);
- if (buf.data == NULL)
- return -1;
-
- shim_udp_msg__pack(msg, buf.data);
-
- if (sendto(udp_data.s_fd,
- buf.data,
- buf.len,
- 0,
+ if (sendto(udp_data.s_fd, buf, len, 0,
(struct sockaddr *) &r_saddr,
sizeof(r_saddr)) == -1) {
log_err("Failed to send message.");
- free(buf.data);
return -1;
}
- free(buf.data);
-
return 0;
}
@@ -215,17 +206,29 @@ static int ipcp_udp_port_alloc(uint32_t dst_ip_addr,
const uint8_t * dst,
qoscube_t cube)
{
- shim_udp_msg_t msg = SHIM_UDP_MSG__INIT;
+ uint8_t * buf;
+ struct mgmt_msg * msg;
+ size_t len;
+ int ret;
+
+ len = sizeof(*msg) + ipcp_dir_hash_len();
+
+ buf = malloc(len);
+ if (buf == NULL)
+ return -1;
- msg.code = SHIM_UDP_MSG_CODE__FLOW_REQ;
- msg.src_udp_port = src_udp_port;
- msg.has_hash = true;
- msg.hash.len = ipcp_dir_hash_len();
- msg.hash.data = (uint8_t *) dst;
- msg.has_qoscube = true;
- msg.qoscube = cube;
+ msg = (struct mgmt_msg *) buf;
+ msg->code = FLOW_REQ;
+ msg->src_udp_port = src_udp_port;
+ msg->qoscube = cube;
- return send_shim_udp_msg(&msg, dst_ip_addr);
+ memcpy(msg + 1, dst, ipcp_dir_hash_len());
+
+ ret = send_shim_udp_msg(buf, len, dst_ip_addr);
+
+ free(buf);
+
+ return ret;
}
static int ipcp_udp_port_alloc_resp(uint32_t dst_ip_addr,
@@ -233,16 +236,25 @@ static int ipcp_udp_port_alloc_resp(uint32_t dst_ip_addr,
uint16_t dst_udp_port,
int response)
{
- shim_udp_msg_t msg = SHIM_UDP_MSG__INIT;
+ uint8_t * buf;
+ struct mgmt_msg * msg;
+ int ret;
+
+ buf = malloc(sizeof(*msg));
+ if (buf == NULL)
+ return -1;
- msg.code = SHIM_UDP_MSG_CODE__FLOW_REPLY;
- msg.src_udp_port = src_udp_port;
- msg.has_dst_udp_port = true;
- msg.dst_udp_port = dst_udp_port;
- msg.has_response = true;
- msg.response = response;
+ msg = (struct mgmt_msg *) buf;
+ msg->code = FLOW_REPLY;
+ msg->src_udp_port = src_udp_port;
+ msg->dst_udp_port = dst_udp_port;
+ msg->response = response;
- return send_shim_udp_msg(&msg, dst_ip_addr);
+ ret = send_shim_udp_msg(buf, sizeof(*msg), dst_ip_addr);
+
+ free(buf);
+
+ return ret;
}
static int ipcp_udp_port_req(struct sockaddr_in * c_saddr,
@@ -404,7 +416,7 @@ static void * ipcp_udp_listener(void * o)
(void) o;
while (true) {
- shim_udp_msg_t * msg = NULL;
+ struct mgmt_msg * msg = NULL;
memset(&buf, 0, SHIM_UDP_MSG_SIZE);
n = sizeof(c_saddr);
@@ -419,31 +431,26 @@ static void * ipcp_udp_listener(void * o)
== NULL)
continue;
- msg = shim_udp_msg__unpack(NULL, n, buf);
- if (msg == NULL)
- continue;
+ msg = (struct mgmt_msg *) buf;
switch (msg->code) {
- case SHIM_UDP_MSG_CODE__FLOW_REQ:
+ case FLOW_REQ:
c_saddr.sin_port = msg->src_udp_port;
ipcp_udp_port_req(&c_saddr,
- msg->hash.data,
+ (uint8_t *) (msg + 1),
msg->qoscube);
break;
- case SHIM_UDP_MSG_CODE__FLOW_REPLY:
+ case FLOW_REPLY:
ipcp_udp_port_alloc_reply(msg->src_udp_port,
msg->dst_udp_port,
msg->response);
break;
default:
log_err("Unknown message received %d.", msg->code);
- shim_udp_msg__free_unpacked(msg, NULL);
continue;
}
c_saddr.sin_port = LISTEN_PORT;
-
- shim_udp_msg__free_unpacked(msg, NULL);
}
return 0;
diff --git a/src/ipcpd/shim-udp/shim_udp_messages.proto b/src/ipcpd/shim-udp/shim_udp_messages.proto
deleted file mode 100644
index 377a8a91..00000000
--- a/src/ipcpd/shim-udp/shim_udp_messages.proto
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Ouroboros - Copyright (C) 2016 - 2017
- *
- * Shim UDP message
- *
- * 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/.
- */
-
-syntax = "proto2";
-
-enum shim_udp_msg_code {
- FLOW_REQ = 1;
- FLOW_REPLY = 2;
-};
-
-message shim_udp_msg {
- required shim_udp_msg_code code = 1;
- optional bytes hash = 2;
- required uint32 src_udp_port = 3;
- optional uint32 dst_udp_port = 4;
- optional uint32 qoscube = 5;
- optional sint32 response = 6;
-};