diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/CMakeLists.txt | 11 | ||||
-rw-r--r-- | src/lib/cacep.c | 170 | ||||
-rw-r--r-- | src/lib/cacep.proto | 29 | ||||
-rw-r--r-- | src/lib/dif_config.proto | 7 | ||||
-rw-r--r-- | src/lib/irm.c | 2 |
5 files changed, 211 insertions, 8 deletions
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index cdd8abb1..688cf6f5 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -8,8 +8,8 @@ protobuf_generate_c(IRM_PROTO_SRCS IRM_PROTO_HDRS irmd_messages.proto) protobuf_generate_c(IPCP_PROTO_SRCS IPCP_PROTO_HDRS ipcpd_messages.proto) protobuf_generate_c(DIF_CONFIG_PROTO_SRCS DIF_CONFIG_PROTO_HDRS dif_config.proto) -protobuf_generate_c(CDAP_PROTO_SRCS CDAP_PROTO_HDRS - cdap.proto) +protobuf_generate_c(CDAP_PROTO_SRCS CDAP_PROTO_HDRS cdap.proto) +protobuf_generate_c(CACEP_PROTO_SRCS CACEP_PROTO_HDRS cacep.proto) if(NOT APPLE) find_library(LIBRT_LIBRARIES rt) @@ -28,6 +28,7 @@ endif() set(SOURCE_FILES # Add source files here bitmap.c + cacep.c cdap.c cdap_req.c dev.c @@ -46,9 +47,9 @@ set(SOURCE_FILES utils.c ) -add_library(ouroboros SHARED ${SOURCE_FILES} - ${IRM_PROTO_SRCS} ${IPCP_PROTO_SRCS} - ${DIF_CONFIG_PROTO_SRCS} ${CDAP_PROTO_SRCS}) +add_library(ouroboros SHARED ${SOURCE_FILES} ${IRM_PROTO_SRCS} + ${IPCP_PROTO_SRCS} ${DIF_CONFIG_PROTO_SRCS} + ${CDAP_PROTO_SRCS} ${CACEP_PROTO_SRCS}) target_link_libraries(ouroboros ${LIBRT_LIBRARIES} ${LIBPTHREAD_LIBRARIES} ${PROTOBUF_C_LIBRARY}) diff --git a/src/lib/cacep.c b/src/lib/cacep.c new file mode 100644 index 00000000..22c6137f --- /dev/null +++ b/src/lib/cacep.c @@ -0,0 +1,170 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * The Common Application Connection Establishment Phase + * + * Sander Vrijders <sander.vrijders@intec.ugent.be> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include <ouroboros/config.h> +#include <ouroboros/cacep.h> +#include <ouroboros/dev.h> +#include <ouroboros/errno.h> + +#include <stdlib.h> +#include <string.h> + +#include "cacep.pb-c.h" +typedef Cacep cacep_t; + +#define BUF_SIZE 2048 + +struct cacep { + int fd; + char * name; + uint64_t address; +}; + +struct cacep * cacep_create(int fd, + const char * name, + uint64_t address) +{ + struct cacep * tmp; + + tmp = malloc(sizeof(*tmp)); + if (tmp == NULL) + return NULL; + + tmp->fd = fd; + tmp->address = address; + tmp->name = strdup(name); + if (tmp->name == NULL) { + free(tmp); + return NULL; + } + + return tmp; +} + +int cacep_destroy(struct cacep * instance) +{ + if (instance == NULL) + return 0; + + free(instance); + + return 0; +} + +static struct cacep_info * read_msg(struct cacep * instance) +{ + struct cacep_info * tmp; + uint8_t buf[BUF_SIZE]; + cacep_t * msg; + ssize_t len; + + len = flow_read(instance->fd, buf, BUF_SIZE); + if (len < 0) + return NULL; + + msg = cacep__unpack(NULL, len, buf); + if (msg == NULL) + return NULL; + + tmp = malloc(sizeof(*tmp)); + if (tmp == NULL) { + cacep__free_unpacked(msg, NULL); + return NULL; + } + + tmp->addr = msg->address; + tmp->name = strdup(msg->name); + if (tmp->name == NULL) { + free(tmp); + cacep__free_unpacked(msg, NULL); + return NULL; + } + + cacep__free_unpacked(msg, NULL); + + return tmp; +} + +static int send_msg(struct cacep * instance) +{ + cacep_t msg = CACEP__INIT; + int ret = 0; + uint8_t * data = NULL; + size_t len = 0; + + msg.name = instance->name; + msg.address = instance->address; + + len = cacep__get_packed_size(&msg); + if (len == 0) + return -1; + + data = malloc(len); + if (data == NULL) + return -ENOMEM; + + cacep__pack(&msg, data); + + if (flow_write(instance->fd, data, len) < 0) + ret = -1; + + free(data); + + return ret; +} + +struct cacep_info * cacep_auth(struct cacep * instance) +{ + struct cacep_info * tmp; + + if (instance == NULL) + return NULL; + + if (send_msg(instance)) + return NULL; + + tmp = read_msg(instance); + if (tmp == NULL) + return NULL; + + return tmp; +} + +struct cacep_info * cacep_auth_wait(struct cacep * instance) +{ + struct cacep_info * tmp; + + if (instance == NULL) + return NULL; + + tmp = read_msg(instance); + if (tmp == NULL) + return NULL; + + if (send_msg(instance)) { + free(tmp->name); + free(tmp); + return NULL; + } + + return tmp; +} diff --git a/src/lib/cacep.proto b/src/lib/cacep.proto new file mode 100644 index 00000000..603b095d --- /dev/null +++ b/src/lib/cacep.proto @@ -0,0 +1,29 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * CACEP message + * + * Dimitri Staessens <dimitri.staessens@intec.ugent.be> + * Sander Vrijders <sander.vrijders@intec.ugent.be> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +syntax = "proto2"; + +message cacep { + required string name = 1; + required uint64 address = 2; +} diff --git a/src/lib/dif_config.proto b/src/lib/dif_config.proto index 8a1d329e..f1f8747b 100644 --- a/src/lib/dif_config.proto +++ b/src/lib/dif_config.proto @@ -37,9 +37,10 @@ message dif_config_msg { optional uint32 min_pdu_size = 10; optional uint32 max_pdu_size = 11; optional uint32 addr_auth_type = 12; + optional uint32 dt_gam_type = 13; // Config for shim UDP - optional uint32 ip_addr = 13; - optional uint32 dns_addr = 14; + optional uint32 ip_addr = 14; + optional uint32 dns_addr = 15; // Config for the shim Ethernet LLC - optional string if_name = 15; + optional string if_name = 16; }
\ No newline at end of file diff --git a/src/lib/irm.c b/src/lib/irm.c index 635c8f9b..ade38b6f 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -120,6 +120,7 @@ int irm_bootstrap_ipcp(pid_t api, config.has_min_pdu_size = true; config.has_max_pdu_size = true; config.has_addr_auth_type = true; + config.has_dt_gam_type = true; config.addr_size = conf->addr_size; config.cep_id_size = conf->cep_id_size; @@ -131,6 +132,7 @@ int irm_bootstrap_ipcp(pid_t api, config.min_pdu_size = conf->min_pdu_size; config.max_pdu_size = conf->max_pdu_size; config.addr_auth_type = conf->addr_auth_type; + config.dt_gam_type = conf->dt_gam_type; break; case IPCP_SHIM_UDP: config.has_ip_addr = true; |