From fa0a0dbc88adcf9cff8bf35a253f020a49ff4084 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Wed, 22 Jun 2016 16:05:56 +0200 Subject: lib: Add errnos specific for Ouroboros This adds error numbers specificly for Ouroboros. It also refactors some of the header files that are installed. Fixes #2 --- src/ipcpd/CMakeLists.txt | 1 - src/ipcpd/flow.c | 54 ------------------------------- src/ipcpd/flow.h | 9 +----- src/ipcpd/local/main.c | 2 +- src/lib/dev.c | 84 +++++++++++++++++++++++++++++++++--------------- src/lib/instance_name.c | 4 +-- src/lib/irm.c | 17 +++++----- 7 files changed, 71 insertions(+), 100 deletions(-) delete mode 100644 src/ipcpd/flow.c (limited to 'src') diff --git a/src/ipcpd/CMakeLists.txt b/src/ipcpd/CMakeLists.txt index 49bd49f2..bb482ed9 100644 --- a/src/ipcpd/CMakeLists.txt +++ b/src/ipcpd/CMakeLists.txt @@ -1,6 +1,5 @@ set(IPCP_SOURCES # Add source files here - ${CMAKE_CURRENT_SOURCE_DIR}/flow.c ${CMAKE_CURRENT_SOURCE_DIR}/ipcp.c ${CMAKE_CURRENT_SOURCE_DIR}/ipcp-data.c ) diff --git a/src/ipcpd/flow.c b/src/ipcpd/flow.c deleted file mode 100644 index 4ca61341..00000000 --- a/src/ipcpd/flow.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - * - * Flows - * - * 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 - * 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. - */ - -#include -#include "flow.h" - -#define OUROBOROS_PREFIX "ipcpd/flow" - -#include -#include - -struct flow * flow_create(int port_id) -{ - struct flow * flow = malloc(sizeof *flow); - if (flow == NULL) { - LOG_DBGF("Could not malloc flow."); - return NULL; - } - - INIT_LIST_HEAD(&flow->list); - - flow->port_id = port_id; - flow->state = FLOW_NULL; - - pthread_mutex_init(&flow->lock, NULL); - - return flow; -} - -void flow_destroy(struct flow * flow) -{ - if (flow == NULL) - return; - free(flow); -} diff --git a/src/ipcpd/flow.h b/src/ipcpd/flow.h index 6f50698e..e27882e2 100644 --- a/src/ipcpd/flow.h +++ b/src/ipcpd/flow.h @@ -24,21 +24,14 @@ #define OUROBOROS_IPCP_FLOW_H #include -#include +#include #include #include struct flow { - struct list_head list; - int port_id; struct shm_ap_rbuff * rb; enum flow_state state; - - pthread_mutex_t lock; }; -struct flow * flow_create(int port_id); -void flow_destroy(struct flow * flow); - #endif /* OUROBOROS_FLOW_H */ diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c index 1e033a21..06e2b0a4 100644 --- a/src/ipcpd/local/main.c +++ b/src/ipcpd/local/main.c @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #define OUROBOROS_PREFIX "ipcpd/local" diff --git a/src/lib/dev.c b/src/lib/dev.c index 1725cca3..d0f29ade 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -23,6 +23,7 @@ #define OUROBOROS_PREFIX "libouroboros-dev" #include +#include #include #include #include @@ -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(); @@ -91,7 +92,7 @@ int ap_init(char * ap_name) instance_name_destroy(_ap_instance->api); bmp_destroy(_ap_instance->fds); free(_ap_instance); - return -1; + return -ENOSHM; } _ap_instance->rb = shm_ap_rbuff_create(); @@ -100,7 +101,7 @@ int ap_init(char * ap_name) shm_du_map_close(_ap_instance->dum); bmp_destroy(_ap_instance->fds); free(_ap_instance); - return -1; + return -ENOSHM; } for (i = 0; i < AP_MAX_FLOWS; ++i) { @@ -174,7 +175,7 @@ int flow_accept(char ** ae_name) recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { - return -1; + return -EIRM; } if (!recv_msg->has_pid || !recv_msg->has_port_id) { @@ -199,7 +200,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 -ENOSHM; } if (ae_name != NULL) { @@ -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); @@ -253,7 +260,7 @@ int flow_alloc_resp(int fd, recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { pthread_rwlock_unlock(&_ap_instance->data_lock); - return -1; + return -EIRM; } if (!recv_msg->has_result) { @@ -298,7 +305,7 @@ int flow_alloc(char * dst_name, recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { - return -1; + return -EIRM; } if (!recv_msg->has_pid || !recv_msg->has_port_id) { @@ -323,7 +330,7 @@ int flow_alloc(char * dst_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 -ENOSHM; } _ap_instance->flows[fd].port_id = recv_msg->port_id; @@ -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); @@ -359,7 +372,7 @@ int flow_alloc_res(int fd) recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { - return -1; + return -EIRM; } if (!recv_msg->has_result) { @@ -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; @@ -399,7 +418,7 @@ int flow_dealloc(int fd) recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { pthread_rwlock_unlock(&_ap_instance->data_lock); - return -1; + return -EIRM; } if (!recv_msg->has_result) { @@ -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 -ENOSHM; } } 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/irm.c b/src/lib/irm.c index ff5c3237..01ee498c 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -22,6 +22,7 @@ #define OUROBOROS_PREFIX "libouroboros-irm" +#include #include #include #include @@ -47,7 +48,7 @@ pid_t irm_create_ipcp(char * ipcp_name, recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) - return -1; + return -EIRM; if (recv_msg->has_result == false) { irm_msg__free_unpacked(recv_msg, NULL); @@ -76,7 +77,7 @@ int irm_destroy_ipcp(instance_name_t * api) recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) - return -1; + return -EIRM; if (recv_msg->has_result == false) { irm_msg__free_unpacked(recv_msg, NULL); @@ -143,12 +144,12 @@ 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); if (recv_msg == NULL) { - return -1; + return -EIRM; } if (recv_msg->has_result == false) { @@ -180,14 +181,14 @@ 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; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { free(msg.dif_name); - return -1; + return -EIRM; } if (recv_msg->has_result == false) { @@ -238,7 +239,7 @@ int irm_reg(char * name, recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) - return -1; + return -EIRM; if (recv_msg->has_result == false) { irm_msg__free_unpacked(recv_msg, NULL); @@ -284,7 +285,7 @@ int irm_unreg(char * name, recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) - return -1; + return -EIRM; if (recv_msg->has_result == false) { irm_msg__free_unpacked(recv_msg, NULL); -- cgit v1.2.3 From 34bcd67e4811be85e11253e4176ec9fec5c3bbef Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Wed, 22 Jun 2016 16:29:27 +0200 Subject: lib: Remove implementation specific errnos This removes any implementation specific error numbers. Only errors that are implementation independent should be returned. --- include/ouroboros/errno.h | 6 ++---- src/lib/dev.c | 20 ++++++++++---------- src/lib/irm.c | 12 ++++++------ 3 files changed, 18 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/include/ouroboros/errno.h b/include/ouroboros/errno.h index 49720548..62629134 100644 --- a/include/ouroboros/errno.h +++ b/include/ouroboros/errno.h @@ -25,9 +25,7 @@ #include -#define ENOSHM 1000 /* Creation or access of shared memory failed */ -#define EIRM 1001 /* Could not talk to the IPC Resource Manager */ -#define ENOTALLOC 1002 /* Flow is not allocated */ -#define EIPCPTYPE 1003 /* Unknown IPCP type */ +#define ENOTALLOC 1000 /* Flow is not allocated */ +#define EIPCPTYPE 1001 /* Unknown IPCP type */ #endif diff --git a/src/lib/dev.c b/src/lib/dev.c index d0f29ade..ad311f7f 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -92,7 +92,7 @@ int ap_init(char * ap_name) instance_name_destroy(_ap_instance->api); bmp_destroy(_ap_instance->fds); free(_ap_instance); - return -ENOSHM; + return -1; } _ap_instance->rb = shm_ap_rbuff_create(); @@ -101,7 +101,7 @@ int ap_init(char * ap_name) shm_du_map_close(_ap_instance->dum); bmp_destroy(_ap_instance->fds); free(_ap_instance); - return -ENOSHM; + return -1; } for (i = 0; i < AP_MAX_FLOWS; ++i) { @@ -175,7 +175,7 @@ int flow_accept(char ** ae_name) recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { - return -EIRM; + return -1; } if (!recv_msg->has_pid || !recv_msg->has_port_id) { @@ -200,7 +200,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 -ENOSHM; + return -1; } if (ae_name != NULL) { @@ -260,7 +260,7 @@ int flow_alloc_resp(int fd, recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { pthread_rwlock_unlock(&_ap_instance->data_lock); - return -EIRM; + return -1; } if (!recv_msg->has_result) { @@ -305,7 +305,7 @@ int flow_alloc(char * dst_name, recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { - return -EIRM; + return -1; } if (!recv_msg->has_pid || !recv_msg->has_port_id) { @@ -330,7 +330,7 @@ int flow_alloc(char * dst_name, pthread_rwlock_unlock(&_ap_instance->flows_lock); pthread_rwlock_unlock(&_ap_instance->data_lock); irm_msg__free_unpacked(recv_msg, NULL); - return -ENOSHM; + return -1; } _ap_instance->flows[fd].port_id = recv_msg->port_id; @@ -372,7 +372,7 @@ int flow_alloc_res(int fd) recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { - return -EIRM; + return -1; } if (!recv_msg->has_result) { @@ -418,7 +418,7 @@ int flow_dealloc(int fd) recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { pthread_rwlock_unlock(&_ap_instance->data_lock); - return -EIRM; + return -1; } if (!recv_msg->has_result) { @@ -511,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 -ENOSHM; + return -1; } } else { /* blocking */ while ((index = shm_create_du_buff(_ap_instance->dum, diff --git a/src/lib/irm.c b/src/lib/irm.c index 01ee498c..8fd0a7e7 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -48,7 +48,7 @@ pid_t irm_create_ipcp(char * ipcp_name, recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) - return -EIRM; + return -1; if (recv_msg->has_result == false) { irm_msg__free_unpacked(recv_msg, NULL); @@ -77,7 +77,7 @@ int irm_destroy_ipcp(instance_name_t * api) recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) - return -EIRM; + return -1; if (recv_msg->has_result == false) { irm_msg__free_unpacked(recv_msg, NULL); @@ -149,7 +149,7 @@ int irm_bootstrap_ipcp(instance_name_t * api, recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { - return -EIRM; + return -1; } if (recv_msg->has_result == false) { @@ -188,7 +188,7 @@ int irm_enroll_ipcp(instance_name_t * api, recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { free(msg.dif_name); - return -EIRM; + return -1; } if (recv_msg->has_result == false) { @@ -239,7 +239,7 @@ int irm_reg(char * name, recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) - return -EIRM; + return -1; if (recv_msg->has_result == false) { irm_msg__free_unpacked(recv_msg, NULL); @@ -285,7 +285,7 @@ int irm_unreg(char * name, recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) - return -EIRM; + return -1; if (recv_msg->has_result == false) { irm_msg__free_unpacked(recv_msg, NULL); -- cgit v1.2.3 From cf5d13dfd66afd68dd7fe93d009a4539c236b095 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Wed, 22 Jun 2016 16:53:52 +0200 Subject: lib: Change DA header to NSM Functionality that was previously thought to be part of the DIF Allocator is actually namespace management. Hence the file has been renamed and the API updated. --- include/ouroboros/CMakeLists.txt | 2 +- include/ouroboros/da.h | 37 --------------------------------- include/ouroboros/ipcp.h | 2 +- include/ouroboros/nsm.h | 43 ++++++++++++++++++++++++++++++++++++++ src/ipcpd/ipcp-ops.h | 2 +- src/ipcpd/ipcp.c | 2 +- src/irmd/main.c | 16 +++----------- src/lib/CMakeLists.txt | 2 +- src/lib/da.c | 34 ------------------------------ src/lib/ipcp.c | 13 +++++------- src/lib/ipcpd_messages.proto | 2 +- src/lib/nsm.c | 45 ++++++++++++++++++++++++++++++++++++++++ 12 files changed, 102 insertions(+), 98 deletions(-) delete mode 100644 include/ouroboros/da.h create mode 100644 include/ouroboros/nsm.h delete mode 100644 src/lib/da.c create mode 100644 src/lib/nsm.c (limited to 'src') diff --git a/include/ouroboros/CMakeLists.txt b/include/ouroboros/CMakeLists.txt index 9e9fc789..c5f65d49 100644 --- a/include/ouroboros/CMakeLists.txt +++ b/include/ouroboros/CMakeLists.txt @@ -4,13 +4,13 @@ configure_file( set(HEADER_FILES cdap.h - da.h dev.h dif_config.h errno.h flow.h instance_name.h irm.h + nsm.h qos.h ) diff --git a/include/ouroboros/da.h b/include/ouroboros/da.h deleted file mode 100644 index 406be7a8..00000000 --- a/include/ouroboros/da.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - * - * The API to consult the DIF Allocator - * - * 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_DA_H -#define OUROBOROS_DA_H - -#include -#include - -char * da_resolve_daf(char * daf_name); -/* - * n_1_difs is an out parameter - * The amount of n_1_difs is returned - */ -ssize_t da_resolve_dap(char * name, - char ** n_1_difs); - -#endif diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h index 89b9fa92..0d62bd59 100644 --- a/include/ouroboros/ipcp.h +++ b/include/ouroboros/ipcp.h @@ -46,7 +46,7 @@ int ipcp_unreg(pid_t pid, size_t difs_size); int ipcp_enroll(pid_t pid, - char * member_name, + char * dif_name, char * n_1_dif); int ipcp_bootstrap(pid_t pid, diff --git a/include/ouroboros/nsm.h b/include/ouroboros/nsm.h new file mode 100644 index 00000000..69b1d9d2 --- /dev/null +++ b/include/ouroboros/nsm.h @@ -0,0 +1,43 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * The API to instruct the global Namespace Manager + * + * 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_NSM_H +#define OUROBOROS_NSM_H + +#include +#include + +int nsm_reg(char * name, + char ** dafs, + size_t dafs_size); + +int nsm_unreg(char * name, + char ** dafs, + size_t dafs_size); + +/* + * dafs is an out parameter + * The amount of DAFs is returned + */ +ssize_t nsm_resolve(char * name, + char ** dafs); +#endif diff --git a/src/ipcpd/ipcp-ops.h b/src/ipcpd/ipcp-ops.h index ffbc9cd7..a1d9f23f 100644 --- a/src/ipcpd/ipcp-ops.h +++ b/src/ipcpd/ipcp-ops.h @@ -30,7 +30,7 @@ struct ipcp_ops { int (* ipcp_bootstrap)(struct dif_config * conf); - int (* ipcp_enroll)(char * member_name, + int (* ipcp_enroll)(char * dif_name, char * n_1_dif); int (* ipcp_reg)(char ** dif_names, size_t len); diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c index 901abae6..b5108712 100644 --- a/src/ipcpd/ipcp.c +++ b/src/ipcpd/ipcp.c @@ -159,7 +159,7 @@ void * ipcp_main_loop(void * o) } ret_msg.has_result = true; ret_msg.result = - _ipcp->ops->ipcp_enroll(msg->member_name, + _ipcp->ops->ipcp_enroll(msg->dif_name, msg->n_1_dif); break; diff --git a/src/irmd/main.c b/src/irmd/main.c index 50055c4d..dff052a1 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -572,7 +572,6 @@ static int bootstrap_ipcp(instance_name_t * api, static int enroll_ipcp(instance_name_t * api, char * dif_name) { - char * member = NULL; char ** n_1_difs = NULL; ssize_t n_1_difs_size = 0; struct ipcp_entry * entry = NULL; @@ -596,16 +595,7 @@ static int enroll_ipcp(instance_name_t * api, return -1; } - member = da_resolve_daf(dif_name); - if (member == NULL) { - free(entry->dif_name); - entry->dif_name = NULL; - pthread_rwlock_unlock(&instance->reg_lock); - pthread_rwlock_unlock(&instance->state_lock); - return -1; - } - - n_1_difs_size = da_resolve_dap(member, n_1_difs); + n_1_difs_size = nsm_resolve(dif_name, n_1_difs); if (n_1_difs_size < 1) { free(entry->dif_name); entry->dif_name = NULL; @@ -615,7 +605,7 @@ static int enroll_ipcp(instance_name_t * api, return -1; } - if (ipcp_enroll(api->id, member, n_1_difs[0])) { + if (ipcp_enroll(api->id, dif_name, n_1_difs[0])) { free(entry->dif_name); entry->dif_name = NULL; pthread_rwlock_unlock(&instance->reg_lock); 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/da.c b/src/lib/da.c deleted file mode 100644 index 8e7756d1..00000000 --- a/src/lib/da.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - * - * The API to instruct the DIF Allocator - * - * 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. - */ - -#include - -char * da_resolve_daf(char * daf_name) -{ - return NULL; -} - -ssize_t da_resolve_dap(char * name, - char ** n_1_difs) -{ - 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/nsm.c b/src/lib/nsm.c new file mode 100644 index 00000000..069db139 --- /dev/null +++ b/src/lib/nsm.c @@ -0,0 +1,45 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * The API to instruct the global Namespace Manager + * + * 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. + */ + +#include + +int nsm_reg(char * name, + char ** dafs, + size_t dafs_size) +{ + + return -1; +} + +int nsm_unreg(char * name, + char ** dafs, + size_t dafs_size) +{ + + return -1; +} + +ssize_t nsm_resolve(char * name, + char ** dafs) +{ + return -1; +} -- cgit v1.2.3