diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-06-24 18:57:34 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-06-24 18:57:34 +0200 |
commit | 76eff8e31eb1e6a6b65284ec4d33cfa088008c3d (patch) | |
tree | bbb7186d986f9555e457768504f9ad0ad7cbbaad /src/lib | |
parent | 0abbbd9fb6499d02d04a5007e803eb79306c341b (diff) | |
parent | 4b5eaafdc9b61307a6a4074366372df3c170372e (diff) | |
download | ouroboros-76eff8e31eb1e6a6b65284ec4d33cfa088008c3d.tar.gz ouroboros-76eff8e31eb1e6a6b65284ec4d33cfa088008c3d.zip |
Merge branch 'be' of bitbucket.org:ouroboros-rina/ouroboros into be-irmd-registry
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/lib/dev.c | 66 | ||||
-rw-r--r-- | src/lib/instance_name.c | 4 | ||||
-rw-r--r-- | src/lib/ipcp.c | 13 | ||||
-rw-r--r-- | src/lib/ipcpd_messages.proto | 2 | ||||
-rw-r--r-- | src/lib/irm.c | 5 | ||||
-rw-r--r-- | src/lib/nsm.c (renamed from src/lib/da.c) | 25 |
7 files changed, 79 insertions, 38 deletions
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index ed7f2fc6..2a75ef17 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -25,13 +25,13 @@ set(SOURCE_FILES # Add source files here bitmap.c cdap.c - da.c dev.c du_buff.c instance_name.c ipcp.c irm.c list.c + nsm.c shm_ap_rbuff.c shm_du_map.c sockets.c diff --git a/src/lib/dev.c b/src/lib/dev.c index 1725cca3..ad311f7f 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -23,6 +23,7 @@ #define OUROBOROS_PREFIX "libouroboros-dev" #include <ouroboros/config.h> +#include <ouroboros/errno.h> #include <ouroboros/logs.h> #include <ouroboros/dev.h> #include <ouroboros/sockets.h> @@ -62,13 +63,13 @@ int ap_init(char * ap_name) _ap_instance = malloc(sizeof(struct ap_data)); if (_ap_instance == NULL) { - return -1; + return -ENOMEM; } _ap_instance->api = instance_name_create(); if (_ap_instance->api == NULL) { free(_ap_instance); - return -1; + return -ENOMEM; } if (instance_name_init_from(_ap_instance->api, @@ -76,14 +77,14 @@ int ap_init(char * ap_name) getpid()) == NULL) { instance_name_destroy(_ap_instance->api); free(_ap_instance); - return -1; + return -ENOMEM; } _ap_instance->fds = bmp_create(AP_MAX_FLOWS, 0); if (_ap_instance->fds == NULL) { instance_name_destroy(_ap_instance->api); free(_ap_instance); - return -1; + return -ENOMEM; } _ap_instance->dum = shm_du_map_open(); @@ -210,7 +211,7 @@ int flow_accept(char ** ae_name) pthread_rwlock_unlock(&_ap_instance->flows_lock); pthread_rwlock_unlock(&_ap_instance->data_lock); irm_msg__free_unpacked(recv_msg, NULL); - return -1; + return -ENOMEM; } } @@ -232,7 +233,7 @@ int flow_alloc_resp(int fd, irm_msg_t * recv_msg = NULL; int ret = -1; - if (fd < 0) + if (fd < 0 || fd >= AP_MAX_FLOWS) return -EBADF; msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC_RESP; @@ -243,6 +244,12 @@ int flow_alloc_resp(int fd, pthread_rwlock_rdlock(&_ap_instance->data_lock); pthread_rwlock_rdlock(&_ap_instance->flows_lock); + if (_ap_instance->flows[fd].port_id < 0) { + pthread_rwlock_unlock(&_ap_instance->flows_lock); + pthread_rwlock_unlock(&_ap_instance->data_lock); + return -ENOTALLOC; + } + msg.port_id = _ap_instance->flows[fd].port_id; pthread_rwlock_unlock(&_ap_instance->flows_lock); @@ -343,7 +350,7 @@ int flow_alloc_res(int fd) irm_msg_t * recv_msg = NULL; int result = 0; - if (fd < 0) + if (fd < 0 || fd >= AP_MAX_FLOWS) return -EBADF; msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC_RES; @@ -352,6 +359,12 @@ int flow_alloc_res(int fd) pthread_rwlock_rdlock(&_ap_instance->data_lock); pthread_rwlock_rdlock(&_ap_instance->flows_lock); + if (_ap_instance->flows[fd].port_id < 0) { + pthread_rwlock_unlock(&_ap_instance->flows_lock); + pthread_rwlock_unlock(&_ap_instance->data_lock); + return -ENOTALLOC; + } + msg.port_id = _ap_instance->flows[fd].port_id; pthread_rwlock_unlock(&_ap_instance->flows_lock); @@ -386,6 +399,12 @@ int flow_dealloc(int fd) pthread_rwlock_rdlock(&_ap_instance->data_lock); pthread_rwlock_wrlock(&_ap_instance->flows_lock); + if (_ap_instance->flows[fd].port_id < 0) { + pthread_rwlock_unlock(&_ap_instance->flows_lock); + pthread_rwlock_unlock(&_ap_instance->data_lock); + return -ENOTALLOC; + } + msg.port_id = _ap_instance->flows[fd].port_id; _ap_instance->flows[fd].port_id = -1; @@ -421,12 +440,18 @@ int flow_cntl(int fd, int cmd, int oflags) { int old; - if (fd < 0) + if (fd < 0 || fd >= AP_MAX_FLOWS) return -EBADF; pthread_rwlock_rdlock(&_ap_instance->data_lock); pthread_rwlock_wrlock(&_ap_instance->flows_lock); + if (_ap_instance->flows[fd].port_id < 0) { + pthread_rwlock_unlock(&_ap_instance->flows_lock); + pthread_rwlock_unlock(&_ap_instance->data_lock); + return -ENOTALLOC; + } + old = _ap_instance->flows[fd].oflags; switch (cmd) { @@ -454,12 +479,18 @@ ssize_t flow_write(int fd, void * buf, size_t count) if (buf == NULL) return 0; - if (fd < 0) + if (fd < 0 || fd >= AP_MAX_FLOWS) return -EBADF; pthread_rwlock_rdlock(&_ap_instance->data_lock); pthread_rwlock_rdlock(&_ap_instance->flows_lock); + if (_ap_instance->flows[fd].port_id < 0) { + pthread_rwlock_unlock(&_ap_instance->flows_lock); + pthread_rwlock_unlock(&_ap_instance->data_lock); + return -ENOTALLOC; + } + if (_ap_instance->flows[fd].oflags & FLOW_O_NONBLOCK) { index = shm_create_du_buff(_ap_instance->dum, count + DU_BUFF_HEADSPACE + @@ -470,7 +501,7 @@ ssize_t flow_write(int fd, void * buf, size_t count) if (index == -1) { pthread_rwlock_unlock(&_ap_instance->flows_lock); pthread_rwlock_unlock(&_ap_instance->data_lock); - return -1; + return -EAGAIN; } e.index = index; @@ -480,7 +511,7 @@ ssize_t flow_write(int fd, void * buf, size_t count) shm_release_du_buff(_ap_instance->dum, index); pthread_rwlock_unlock(&_ap_instance->flows_lock); pthread_rwlock_unlock(&_ap_instance->data_lock); - return -EPIPE; + return -1; } } else { /* blocking */ while ((index = shm_create_du_buff(_ap_instance->dum, @@ -510,7 +541,7 @@ ssize_t flow_read(int fd, void * buf, size_t count) int n; uint8_t * sdu; - if (fd < 0) + if (fd < 0 || fd >= AP_MAX_FLOWS) return -EBADF; pthread_rwlock_rdlock(&_ap_instance->data_lock); @@ -519,16 +550,17 @@ ssize_t flow_read(int fd, void * buf, size_t count) if (_ap_instance->flows[fd].port_id < 0) { pthread_rwlock_unlock(&_ap_instance->flows_lock); pthread_rwlock_unlock(&_ap_instance->data_lock); - return -1; + return -ENOTALLOC; } if (_ap_instance->flows[fd].oflags & FLOW_O_NONBLOCK) { idx = shm_ap_rbuff_read_port(_ap_instance->rb, _ap_instance->flows[fd].port_id); } else { /* block */ - while ((idx = shm_ap_rbuff_read_port( - _ap_instance->rb, - _ap_instance->flows[fd].port_id)) < 0) + while ((idx = + shm_ap_rbuff_read_port(_ap_instance->rb, + _ap_instance-> + flows[fd].port_id)) < 0) ; } @@ -536,7 +568,7 @@ ssize_t flow_read(int fd, void * buf, size_t count) if (idx < 0) { pthread_rwlock_unlock(&_ap_instance->data_lock); - return -1; + return -EAGAIN; } n = shm_du_map_read_sdu(&sdu, diff --git a/src/lib/instance_name.c b/src/lib/instance_name.c index 10a432d5..844bb924 100644 --- a/src/lib/instance_name.c +++ b/src/lib/instance_name.c @@ -106,11 +106,11 @@ int instance_name_cpy(instance_name_t * dst, instance_name_t * res; if (src == NULL || dst == NULL) - return -1; + return -EINVAL; res = instance_name_init_from(dst, src->name, src->id); if (res == NULL) - return -1; + return -ENOMEM; return 0; } diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c index a43afd21..730880f9 100644 --- a/src/lib/ipcp.c +++ b/src/lib/ipcp.c @@ -275,35 +275,32 @@ int ipcp_bootstrap(pid_t pid, } int ipcp_enroll(pid_t pid, - char * member_name, + char * dif_name, char * n_1_dif) { ipcp_msg_t msg = IPCP_MSG__INIT; ipcp_msg_t * recv_msg = NULL; int ret = -1; - if (n_1_dif == NULL || member_name == NULL) + if (n_1_dif == NULL || dif_name == NULL) return -EINVAL; - msg.code = IPCP_MSG_CODE__IPCP_ENROLL; - msg.member_name = member_name; - msg.n_1_dif = n_1_dif; + msg.code = IPCP_MSG_CODE__IPCP_ENROLL; + msg.dif_name = dif_name; + msg.n_1_dif = n_1_dif; recv_msg = send_recv_ipcp_msg(pid, &msg); if (recv_msg == NULL) { - free(msg.member_name); return -1; } if (recv_msg->has_result == false) { ipcp_msg__free_unpacked(recv_msg, NULL); - free(msg.member_name); return -1; } ret = recv_msg->result; ipcp_msg__free_unpacked(recv_msg, NULL); - free(msg.member_name); return ret; } diff --git a/src/lib/ipcpd_messages.proto b/src/lib/ipcpd_messages.proto index 63e41986..9eb5707c 100644 --- a/src/lib/ipcpd_messages.proto +++ b/src/lib/ipcpd_messages.proto @@ -15,7 +15,7 @@ enum ipcp_msg_code { message ipcp_msg { required ipcp_msg_code code = 1; - optional string member_name = 2; + optional string dif_name = 2; optional string n_1_dif = 3; repeated string dif_names = 4; optional int32 len = 5; diff --git a/src/lib/irm.c b/src/lib/irm.c index ff5c3237..8fd0a7e7 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -22,6 +22,7 @@ #define OUROBOROS_PREFIX "libouroboros-irm" +#include <ouroboros/errno.h> #include <ouroboros/irm.h> #include <ouroboros/common.h> #include <ouroboros/logs.h> @@ -143,7 +144,7 @@ int irm_bootstrap_ipcp(instance_name_t * api, config.if_name = conf->if_name; break; default: - return -1; + return -EIPCPTYPE; } recv_msg = send_recv_irm_msg(&msg); @@ -180,7 +181,7 @@ int irm_enroll_ipcp(instance_name_t * api, msg.dif_name = malloc(sizeof(*(msg.dif_name))); if (msg.dif_name == NULL) { LOG_ERR("Failed to malloc"); - return -1; + return -ENOMEM; } msg.dif_name[0] = dif_name; diff --git a/src/lib/da.c b/src/lib/nsm.c index 8e7756d1..069db139 100644 --- a/src/lib/da.c +++ b/src/lib/nsm.c @@ -1,7 +1,7 @@ /* * Ouroboros - Copyright (C) 2016 * - * The API to instruct the DIF Allocator + * The API to instruct the global Namespace Manager * * Sander Vrijders <sander.vrijders@intec.ugent.be> * @@ -20,15 +20,26 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <ouroboros/da.h> +#include <ouroboros/nsm.h> -char * da_resolve_daf(char * daf_name) +int nsm_reg(char * name, + char ** dafs, + size_t dafs_size) { - return NULL; + + return -1; +} + +int nsm_unreg(char * name, + char ** dafs, + size_t dafs_size) +{ + + return -1; } -ssize_t da_resolve_dap(char * name, - char ** n_1_difs) +ssize_t nsm_resolve(char * name, + char ** dafs) { - return 0; + return -1; } |