From a315150a16c02f3cb694e639d5aba555fce4b4c3 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Tue, 5 Jul 2016 15:43:13 +0200 Subject: lib: Provide first implementation of revised CDAP This commit introduces a first version of the revised CDAP specification. CACEP (for authentication purposes) has been separated from CDAP. Application developers may use CDAP if they find it useful. Within Ouroboros CDAP will be used to perform operations on the RIB of an IPCP. --- include/ouroboros/CMakeLists.txt | 18 ++-- include/ouroboros/cdap.h | 182 ++++++++++++--------------------------- include/ouroboros/common.h | 16 +--- include/ouroboros/ipcp.h | 2 +- include/ouroboros/shared.h | 38 ++++++++ include/ouroboros/shm_du_map.h | 4 +- 6 files changed, 107 insertions(+), 153 deletions(-) create mode 100644 include/ouroboros/shared.h (limited to 'include') diff --git a/include/ouroboros/CMakeLists.txt b/include/ouroboros/CMakeLists.txt index 68c88a18..ee339294 100644 --- a/include/ouroboros/CMakeLists.txt +++ b/include/ouroboros/CMakeLists.txt @@ -3,14 +3,14 @@ configure_file( "${CMAKE_CURRENT_BINARY_DIR}/config.h") set(HEADER_FILES - cdap.h - dev.h - errno.h - flow.h - irm.h - irm_config.h - nsm.h - qos.h -) + cdap.h + common.h + dev.h + errno.h + flow.h + irm.h + irm_config.h + nsm.h + qos.h) install(FILES ${HEADER_FILES} DESTINATION usr/include/ouroboros) diff --git a/include/ouroboros/cdap.h b/include/ouroboros/cdap.h index 72788ad6..da669feb 100644 --- a/include/ouroboros/cdap.h +++ b/include/ouroboros/cdap.h @@ -4,6 +4,7 @@ * The Common Distributed Application Protocol * * Sander Vrijders + * Dimitri Staessens * * 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 @@ -23,148 +24,75 @@ #ifndef OUROBOROS_CDAP_H #define OUROBOROS_CDAP_H +#include + #include +#include +#include + +#define F_SYNC 0x0001 struct cdap; +/* Callback functions that work on the application's RIB */ struct cdap_ops { - /* Sender related callbacks */ - int (* handle_connect_r)(int fd, - int invoke_id, - int result); - int (* handle_release_r)(int fd, - int invoke_id, - int result); - int (* handle_read_r)(int fd, - int invoke_id, - int result, - char * reason, - char * obj_val, - bool complete); - int (* handle_cancelread_r)(int fd, - int invoke_id, - int result); - int (* handle_write_r)(int fd, - int invoke_id, - int result, - char * reason, - char * obj_val); - int (* handle_create_r)(int fd, - int invoke_id, - int result); - int (* handle_delete_r)(int fd, - int invoke_id, - int result); - int (* handle_start_r)(int fd, - int invoke_id, - int result); - int (* handle_stop_r)(int fd, - int invoke_id, - int result); + int (* cdap_reply)(struct cdap * instance, + int invoke_id, + int result, + buffer_t * val, + size_t len); + + int (* cdap_read)(struct cdap * instance, + char * name); + int (* cdap_write)(struct cdap * instance, + char * name, + buffer_t * val, + size_t len, + uint32_t flags); - /* Receiver related callbacks */ - int (* handle_connect)(int fd, - int invoke_id, - rina_name_t src, - rina_name_t dst, - char * auth_mech, - char * auth_val); - int (* handle_release)(int fd, - int invoke_id); - int (* handle_cancelread)(int fd, - int invoke_id); - int (* handle_write)(int fd, - int invoke_id, - char * obj_name, - char * obj_val); - int (* handle_create)(int fd, - int invoke_id, - char * obj_class, - char * obj_name, - char * obj_val); - int (* handle_delete)(int fd, - int invoke_id, - char * obj_name); - int (* handle_start)(int fd, - int invoke_id, - char * obj_name, - char * obj_val); - int (* handle_stop)(int fd, - int invoke_id, - char * obj_name, - char * obj_val); + int (* cdap_create)(struct cdap * instance, + char * name, + buffer_t val); + int (* cdap_delete)(struct cdap * instance, + char * name, + buffer_t val); + + int (* cdap_start)(struct cdap * instance, + char * name); + int (* cdap_stop)(struct cdap * instance, + char * name); }; -struct cdap * cdap_create(struct cdap_ops ops, - int fd); +/* Assumes flow is blocking */ +struct cdap * cdap_create(struct cdap_ops * ops, + int fd); int cdap_destroy(struct cdap * instance); -/* Sender related functions */ -int cdap_send_connect(struct cdap * instance, - int invoke_id, - rina_name_t src, - rina_name_t dst, - char * auth_mech, - char * auth_val); -int cdap_send_release(struct cdap * instance, - int invoke_id); +/* Returns a positive invoke-id on success to be used in the callback */ int cdap_send_read(struct cdap * instance, - int invoke_id, - char * obj_name); -int cdap_send_cancelread(struct cdap * instance, - int invoke_id, - char * obj_name); + char * name); int cdap_send_write(struct cdap * instance, - int invoke_id, - char * obj_name, - char * obj_val); + char * name, + buffer_t * val, + size_t len, + uint32_t flags); + int cdap_send_create(struct cdap * instance, - int invoke_id, - char * obj_name, - char * obj_val); + char * name, + buffer_t val); int cdap_send_delete(struct cdap * instance, - int invoke_id, - char * obj_name); + char * name, + buffer_t val); + int cdap_send_start(struct cdap * instance, - int invoke_id, - char * obj_name, - char * obj_val); + char * name); int cdap_send_stop(struct cdap * instance, - int invoke_id, - char * obj_name, - char * obj_val); + char * name); -/* Receiver related functions */ -int cdap_send_connect_r(struct cdap * instance, - int invoke_id, - int result); -int cdap_send_release_r(struct cdap * instance, - int invoke_id, - int result); -int cdap_send_read_r(struct cdap * instance, - int invoke_id, - int result, - char * reason, - char * obj_val, - bool complete); -int cdap_send_cancelread_r(struct cdap * instance, - int invoke_id, - int result); -int cdap_send_write_r(struct cdap * instance, - int invoke_id, - int result, - char * obj_name, - char * obj_val); -int cdap_send_create_r(struct cdap * instance, - int invoke_id, - int result); -int cdap_send_delete_r(struct cdap * instance, - int invoke_id, - int result); -int cdap_send_start_r(struct cdap * instance, - int invoke_id, - int result); -int cdap_send_stop_r(struct cdap * instance, - int invoke_id, - int result); +/* Can only be called following a callback function */ +int cdap_send_reply(struct cdap * instance, + int invoke_id, + int result, + buffer_t * val, + size_t len); #endif diff --git a/include/ouroboros/common.h b/include/ouroboros/common.h index 039e1a83..dbd050f1 100644 --- a/include/ouroboros/common.h +++ b/include/ouroboros/common.h @@ -25,24 +25,10 @@ #include #include -#include -#include typedef struct { uint8_t * data; - size_t size; + size_t len; } buffer_t; -/* FIXME: To be decided which QoS cubes we support */ -enum qos_cube { - QOS_CUBE_BE = 0, - QOS_CUBE_VIDEO -}; - -enum flow_state { - FLOW_NULL = 0, - FLOW_PENDING, - FLOW_ALLOCATED -}; - #endif /* OUROBOROS_COMMON_H */ diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h index f5657b64..c1aa452b 100644 --- a/include/ouroboros/ipcp.h +++ b/include/ouroboros/ipcp.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include diff --git a/include/ouroboros/shared.h b/include/ouroboros/shared.h new file mode 100644 index 00000000..f5e34dc8 --- /dev/null +++ b/include/ouroboros/shared.h @@ -0,0 +1,38 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Shared definitions between IRMd and IPCPs + * + * Sander Vrijders + * + * 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_SHARED_H +#define OUROBOROS_SHARED_H + +/* FIXME: To be decided which QoS cubes we support */ +enum qos_cube { + QOS_CUBE_BE = 0, + QOS_CUBE_VIDEO +}; + +enum flow_state { + FLOW_NULL = 0, + FLOW_PENDING, + FLOW_ALLOCATED +}; + +#endif /* OUROBOROS_SHARED_H */ diff --git a/include/ouroboros/shm_du_map.h b/include/ouroboros/shm_du_map.h index e8934bae..9d6d7aaf 100644 --- a/include/ouroboros/shm_du_map.h +++ b/include/ouroboros/shm_du_map.h @@ -24,7 +24,9 @@ #ifndef OUROBOROS_SHM_DU_MAP_H #define OUROBOROS_SHM_DU_MAP_H -#include "common.h" +#include +#include +#include #include #include -- cgit v1.2.3 From daa4e408b3e34bdc228d26816de09d7d1fb9b043 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Tue, 5 Jul 2016 15:58:54 +0200 Subject: lib, irmd: Fix clang and CI compilation errors This commit fixes some errors reported during compilation that were undiscovered by my gcc compiler but found by clang, and errors not found on my system but found by the CI platform. --- include/ouroboros/cdap.h | 2 +- include/ouroboros/dev.h | 1 - src/irmd/main.c | 2 +- src/lib/cdap.c | 36 ++++++++++++++++++++++-------------- 4 files changed, 24 insertions(+), 17 deletions(-) (limited to 'include') diff --git a/include/ouroboros/cdap.h b/include/ouroboros/cdap.h index da669feb..e26f192b 100644 --- a/include/ouroboros/cdap.h +++ b/include/ouroboros/cdap.h @@ -3,7 +3,7 @@ * * The Common Distributed Application Protocol * - * Sander Vrijders + * Sander Vrijders * Dimitri Staessens * * This program is free software; you can redistribute it and/or modify diff --git a/include/ouroboros/dev.h b/include/ouroboros/dev.h index 897bc124..699973a3 100644 --- a/include/ouroboros/dev.h +++ b/include/ouroboros/dev.h @@ -48,7 +48,6 @@ int flow_alloc(char * dst_name, int flow_alloc_res(int fd); int flow_dealloc(int fd); -/* Wraps around fnctl */ int flow_cntl(int fd, int cmd, int oflags); ssize_t flow_write(int fd, void * buf, size_t count); ssize_t flow_read(int fd, void * buf, size_t count); diff --git a/src/irmd/main.c b/src/irmd/main.c index 2ea59eee..38e10cc5 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -1936,7 +1936,7 @@ void * irm_flow_cleaner() pthread_rwlock_rdlock(&instance->state_lock); - if (&instance->state == IRMD_NULL) { + if (instance->state == IRMD_NULL) { pthread_rwlock_unlock(&instance->state_lock); return (void *) 0; } diff --git a/src/lib/cdap.c b/src/lib/cdap.c index 8967c8bd..4275bfc7 100644 --- a/src/lib/cdap.c +++ b/src/lib/cdap.c @@ -53,9 +53,8 @@ static ssize_t cdap_msg_to_buffer(cdap_t * msg, len = msg->n_value; *val = malloc(len * sizeof(**val)); - if (*val == NULL) { + if (*val == NULL) return -1; - } for (i = 0; i < len; i++) { if (msg->value[i].data == NULL) { @@ -76,20 +75,18 @@ static void * sdu_reader(void * o) struct cdap * instance = (struct cdap *) o; cdap_t * msg; uint8_t buf[BUF_SIZE]; - size_t len; + ssize_t len; ssize_t length; buffer_t * val; while (true) { len = flow_read(instance->fd, buf, BUF_SIZE); - if (len < 0) { + if (len < 0) return (void *) -1; - } msg = cdap__unpack(NULL, len, buf); - if (msg == NULL) { + if (msg == NULL) continue; - } switch (msg->opcode) { case OPCODE__READ: @@ -166,6 +163,7 @@ struct cdap * cdap_create(struct cdap_ops * ops, int fd) { struct cdap * instance = NULL; + int flags; if (ops == NULL || fd < 0 || ops->cdap_reply == NULL || @@ -177,6 +175,10 @@ struct cdap * cdap_create(struct cdap_ops * ops, ops->cdap_stop == NULL) return NULL; + flags = flow_cntl(fd, FLOW_F_GETFL, 0); + if (flags & FLOW_O_NONBLOCK) + return NULL; + instance = malloc(sizeof(*instance)); if (instance == NULL) return NULL; @@ -250,15 +252,23 @@ static int write_msg(struct cdap * instance, cdap_t * msg) { buffer_t buf; + int ret; buf.len = cdap__get_packed_size(msg); - if (buf.len == 0) { + if (buf.len == 0) + return -1; + + buf.data = malloc(BUF_SIZE); + if (buf.data == NULL) return -1; - } cdap__pack(msg, buf.data); - return flow_write(instance->fd, buf.data, buf.len); + ret = flow_write(instance->fd, buf.data, buf.len); + + free(buf.data); + + return ret; } static int buffer_to_cdap_msg(cdap_t * msg, @@ -268,9 +278,8 @@ static int buffer_to_cdap_msg(cdap_t * msg, int i; msg->value = malloc(len * sizeof(*msg->value)); - if (msg->value == NULL) { + if (msg->value == NULL) return -1; - } msg->n_value = len; for (i = 0; i < len; i++) { @@ -422,9 +431,8 @@ int cdap_send_reply(struct cdap * instance, msg.has_result = true; msg.result = result; - if (buffer_to_cdap_msg(&msg, val, len)) { + if (buffer_to_cdap_msg(&msg, val, len)) return -1; - } return write_msg(instance, &msg); } -- cgit v1.2.3