summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmake/FindProtobufC.cmake72
-rw-r--r--include/ouroboros/CMakeLists.txt5
-rw-r--r--include/ouroboros/config.h.in9
-rw-r--r--include/ouroboros/da.h2
-rw-r--r--include/ouroboros/flow.h61
-rw-r--r--include/ouroboros/instance_name.h (renamed from include/ouroboros/rina_name.h)51
-rw-r--r--include/ouroboros/ipcp.h75
-rw-r--r--include/ouroboros/irm.h31
-rw-r--r--include/ouroboros/shm_du_map.h4
-rw-r--r--include/ouroboros/sockets.h82
-rw-r--r--src/ipcpd/CMakeLists.txt1
-rw-r--r--src/ipcpd/shm_pci.c146
-rw-r--r--src/ipcpd/shm_pci.h43
-rw-r--r--src/irmd/main.c385
-rw-r--r--src/lib/.gitignore1
-rw-r--r--src/lib/CMakeLists.txt54
-rw-r--r--src/lib/dev.c191
-rw-r--r--src/lib/flow.c83
-rw-r--r--src/lib/instance_name.c (renamed from src/lib/rina_name.c)155
-rw-r--r--src/lib/ipcp.c431
-rw-r--r--src/lib/ipcpd_messages.proto23
-rw-r--r--src/lib/irm.c232
-rw-r--r--src/lib/irmd_messages.proto39
-rw-r--r--src/lib/sockets.c678
-rw-r--r--src/lib/tests/shm_du_map_test.c1
-rw-r--r--src/tools/echo/echo_client.c1
-rw-r--r--src/tools/echo/echo_server.c1
-rw-r--r--src/tools/irm/irm.c2
-rw-r--r--src/tools/irm/irm_bootstrap_ipcp.c19
-rw-r--r--src/tools/irm/irm_create_ipcp.c28
-rw-r--r--src/tools/irm/irm_destroy_ipcp.c16
-rw-r--r--src/tools/irm/irm_enroll_ipcp.c28
-rw-r--r--src/tools/irm/irm_register_ipcp.c31
-rw-r--r--src/tools/irm/irm_unregister_ipcp.c30
-rw-r--r--src/tools/irm/irm_utils.c16
-rw-r--r--src/tools/irm/irm_utils.h6
36 files changed, 1706 insertions, 1327 deletions
diff --git a/cmake/FindProtobufC.cmake b/cmake/FindProtobufC.cmake
new file mode 100644
index 00000000..bfa50110
--- /dev/null
+++ b/cmake/FindProtobufC.cmake
@@ -0,0 +1,72 @@
+function(PROTOBUF_GENERATE_C SRCS HDRS)
+ if(NOT ARGN)
+ message(SEND_ERROR "Error: PROTOBUF_GENERATE_C() called without any proto files")
+ return()
+ endif()
+
+ if(PROTOBUF_GENERATE_C_APPEND_PATH)
+ # Create an include path for each file specified
+ foreach(FIL ${ARGN})
+ get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
+ get_filename_component(ABS_PATH ${ABS_FIL} PATH)
+ list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
+ if(${_contains_already} EQUAL -1)
+ list(APPEND _protobuf_include_path -I ${ABS_PATH})
+ endif()
+ endforeach()
+ else()
+ set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})
+ endif()
+
+ set(${SRCS})
+ set(${HDRS})
+ foreach(FIL ${ARGN})
+ get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
+ get_filename_component(FIL_WE ${FIL} NAME_WE)
+
+ list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.c")
+ list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.h")
+
+ add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.c"
+ "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.h"
+ COMMAND ${PROTOBUF_PROTOC_C_EXECUTABLE}
+ ARGS --c_out=${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
+ DEPENDS ${ABS_FIL} ${PROTOBUF_PROTOC_C_EXECUTABLE}
+ COMMENT "Running C protocol buffer compiler on ${FIL}"
+ VERBATIM )
+ endforeach()
+
+ set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
+ set(${SRCS} ${${SRCS}} PARENT_SCOPE)
+ set(${HDRS} ${${HDRS}} PARENT_SCOPE)
+endfunction()
+
+# By default have PROTOBUF_GENERATE_C macro pass -I to protoc
+# for each directory where a proto file is referenced.
+if(NOT DEFINED PROTOBUF_GENERATE_C_APPEND_PATH)
+ set(PROTOBUF_GENERATE_C_APPEND_PATH TRUE)
+endif()
+
+# Find library
+find_library(PROTOBUF_C_LIBRARY
+ NAMES libprotobuf-c.so libprotobuf-c
+)
+mark_as_advanced(PROTOBUF_C_LIBRARY)
+
+# Find the include directory
+find_path(PROTOBUF_C_INCLUDE_DIR
+ google/protobuf-c/protobuf-c.h
+)
+mark_as_advanced(PROTOBUF_C_INCLUDE_DIR)
+
+# Find the protoc-c Executable
+find_program(PROTOBUF_PROTOC_C_EXECUTABLE
+ NAMES protoc-c
+ DOC "The Google Protocol Buffers C Compiler"
+)
+mark_as_advanced(PROTOBUF_PROTOC_C_EXECUTABLE)
+
+find_package(PackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(ProtobufC DEFAULT_MSG
+ PROTOBUF_C_LIBRARY PROTOBUF_C_INCLUDE_DIR PROTOBUF_PROTOC_C_EXECUTABLE)
diff --git a/include/ouroboros/CMakeLists.txt b/include/ouroboros/CMakeLists.txt
index a196140b..0b52a2bc 100644
--- a/include/ouroboros/CMakeLists.txt
+++ b/include/ouroboros/CMakeLists.txt
@@ -9,15 +9,16 @@ set(HEADER_FILES
da.h
dev.h
du_buff.h
+ flow.h
+ instance_name.h
ipcp.h
irm.h
list.h
logs.h
- rina_name.h
shm_du_map.h
sockets.h
utils.h
)
install(FILES ${HEADER_FILES} "${CMAKE_CURRENT_BINARY_DIR}/config.h"
- DESTINATION include/ouroboros)
+ DESTINATION include/ouroboros)
diff --git a/include/ouroboros/config.h.in b/include/ouroboros/config.h.in
index 0f5c2131..01d7888e 100644
--- a/include/ouroboros/config.h.in
+++ b/include/ouroboros/config.h.in
@@ -23,9 +23,10 @@
#ifndef OUROBOROS_CONFIG
#define OUROBOROS_CONFIG
-#define PROJECT_NAME "@CMAKE_PROJECT_NAME@"
-#define PROJECT_VERSION "@PACKAGE_VERSION@"
-#define INSTALL_DIR "@CMAKE_INSTALL_PREFIX@"
-#define BUILD_TYPE "@CMAKE_BUILD_TYPE@"
+#define PROJECT_NAME "@CMAKE_PROJECT_NAME@"
+#define PROJECT_VERSION "@PACKAGE_VERSION@"
+#define INSTALL_DIR "@CMAKE_INSTALL_PREFIX@"
+#define BUILD_TYPE "@CMAKE_BUILD_TYPE@"
+#define _POSIX_C_SOURCE 199506L
#endif
diff --git a/include/ouroboros/da.h b/include/ouroboros/da.h
index f678007d..9ecd4bd8 100644
--- a/include/ouroboros/da.h
+++ b/include/ouroboros/da.h
@@ -24,7 +24,7 @@
#define OUROBOROS_DA_H
#include "common.h"
-#include "rina_name.h"
+#include "instance_name.h"
char * da_resolve_daf(char * daf_name);
/*
diff --git a/include/ouroboros/flow.h b/include/ouroboros/flow.h
new file mode 100644
index 00000000..7d8c311e
--- /dev/null
+++ b/include/ouroboros/flow.h
@@ -0,0 +1,61 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * Flows
+ *
+ * Dimitri Staessens <dimitri.staessens@intec.ugent.be>
+ *
+ * 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_FLOW_H
+#define OUROBOROS_FLOW_H
+
+#include <ouroboros/common.h>
+
+#include <pthread.h>
+
+/* same values as fcntl.h */
+#define FLOW_O_RDONLY 00000000
+#define FLOW_O_WRONLY 00000001
+#define FLOW_O_RDWR 00000002
+#define FLOW_O_ACCMODE 00000003
+
+#define FLOW_O_NONBLOCK 00004000
+#define FLOW_O_DEFAULT 00000002
+
+#define FLOW_O_INVALID (FLOW_O_WRONLY | FLOW_O_RDWR)
+
+enum flow_state {
+ FLOW_INIT = 0,
+ FLOW_ALLOCATED,
+ FLOW_PENDING
+};
+
+typedef struct flow {
+ int32_t port_id;
+ uint16_t oflags;
+ enum flow_state state;
+
+ pthread_mutex_t lock;
+} flow_t;
+
+flow_t * flow_create(int32_t port_id);
+void flow_destroy(flow_t * flow);
+
+int flow_set_opts(flow_t * flow, uint16_t opts);
+uint16_t flow_get_opts(const flow_t * flow);
+
+#endif /* OUROBOROS_FLOW_H */
diff --git a/include/ouroboros/rina_name.h b/include/ouroboros/instance_name.h
index f8af00c2..351b222f 100644
--- a/include/ouroboros/rina_name.h
+++ b/include/ouroboros/instance_name.h
@@ -19,21 +19,21 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#ifndef RINA_NAME_H
-#define RINA_NAME_H
+#ifndef INSTANCE_NAME_H
+#define INSTANCE_NAME_H
#include "common.h"
typedef struct {
- char * ap_name;
- unsigned int api_id;
-} rina_name_t;
+ char * name;
+ uint16_t id;
+} instance_name_t;
/*
* Allocates a new name, returning the allocated object.
* In case of an error, a NULL is returned.
*/
-rina_name_t * name_create();
+instance_name_t * instance_name_create();
/*
* Initializes a previously dynamically allocated name (i.e. name_create())
@@ -46,49 +46,44 @@ rina_name_t * name_create();
*
* It is allowed to call name_init() over an already initialized object
*/
-rina_name_t * name_init_from(rina_name_t * dst,
- const char * ap_name,
- unsigned int api_id);
+instance_name_t * instance_name_init_from(instance_name_t * dst,
+ const char * name,
+ uint16_t api_id);
/* Takes ownership of the passed parameters */
-rina_name_t * name_init_with(rina_name_t * dst,
- char * ap_name,
- unsigned int api_id);
+instance_name_t * instance_name_init_with(instance_name_t * dst,
+ char * name,
+ uint16_t id);
/*
* Finalize a name object, releasing all the embedded resources (without
* releasing the object itself). After name_fini() execution the passed
* object will be in the same states as at the end of name_init().
*/
-void name_fini(rina_name_t * dst);
+void instance_name_fini(instance_name_t * dst);
/* Releases all the associated resources bound to a name object */
-void name_destroy(rina_name_t * ptr);
+void instance_name_destroy(instance_name_t * ptr);
/* Duplicates a name object, returning the pointer to the new object */
-rina_name_t * name_dup(const rina_name_t * src);
+instance_name_t * instance_name_dup(const instance_name_t * src);
/*
* Copies the source object contents into the destination object, both must
* be previously allocated
*/
-int name_cpy(const rina_name_t * src, rina_name_t * dst);
+int instance_name_cpy(instance_name_t * dst,
+ const instance_name_t * src);
-bool name_is_equal(const rina_name_t * a, const rina_name_t * b);
-bool name_is_ok(const rina_name_t * n);
+int instance_name_cmp(const instance_name_t * a,
+ const instance_name_t * b);
-#define NAME_CMP_APN 0x01
-#define NAME_CMP_API 0x02
-#define NAME_CMP_ALL (NAME_CMP_APN | NAME_CMP_API)
-
-bool name_cmp(uint8_t flags,
- const rina_name_t * a,
- const rina_name_t * b);
+bool instance_name_is_valid(const instance_name_t * n);
/* Returns a name as a (newly allocated) string */
-char * name_to_string(const rina_name_t * n);
+char * instance_name_to_string(const instance_name_t * n);
/* Inverse of name_tostring() */
-rina_name_t * string_to_name(const char * s);
+instance_name_t * string_to_instance_name(const char * s);
-#endif
+#endif /* INSTANCE_NAME_H */
diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h
index b8775fc0..fdaf5c4a 100644
--- a/include/ouroboros/ipcp.h
+++ b/include/ouroboros/ipcp.h
@@ -23,31 +23,66 @@
#ifndef OUROBOROS_IPCP_H
#define OUROBOROS_IPCP_H
-#include <sys/types.h>
+#include <ouroboros/common.h>
+#include <ouroboros/instance_name.h>
-#include "common.h"
-#include "rina_name.h"
+#include <sys/types.h>
struct ipcp;
/* Returns the process id */
-pid_t ipcp_create(rina_name_t name,
- char * ipcp_type);
-int ipcp_destroy(pid_t pid);
-
-int ipcp_reg(pid_t pid,
- char ** difs,
- size_t difs_size);
-int ipcp_unreg(pid_t pid,
+pid_t ipcp_create(instance_name_t * api,
+ char * ipcp_type);
+int ipcp_destroy(pid_t pid);
+
+int ipcp_reg(pid_t pid,
char ** difs,
- size_t difs_size);
+ size_t difs_size);
+int ipcp_unreg(pid_t pid,
+ char ** difs,
+ size_t difs_size);
+
+int ipcp_bootstrap(pid_t pid,
+ struct dif_config * conf);
+int ipcp_enroll(pid_t pid,
+ char * member_name,
+ char * n_1_dif);
+
+/* Flow related ops, these go from IRMd to IPCP */
+
+int ipcp_ap_reg(pid_t pid,
+ uint32_t reg_api_id,
+ char * ap_name);
+int ipcp_ap_unreg(pid_t pid,
+ uint32_t reg_api_id);
+
+int ipcp_flow_alloc(pid_t pid,
+ uint32_t port_id,
+ char * dst_ap_name,
+ char * src_ap_name,
+ char * src_ae_name,
+ struct qos_spec * qos);
+int ipcp_flow_alloc_resp(pid_t pid,
+ uint32_t port_id,
+ int result);
+
+/* These operations go from the IPCP to the IRMd */
+
+/* Returns the port_id */
+int ipcp_flow_req_arr(pid_t pid,
+ uint32_t reg_api_id,
+ char * ap_name,
+ char * ae_name);
+int ipcp_flow_alloc_reply(pid_t pid,
+ uint32_t port_id,
+ int result);
+
+/*
+ * This operation can go both ways
+ * pid == 0 means the IRMd is the destination
+ */
+int ipcp_flow_dealloc(pid_t pid,
+ uint32_t port_id);
-int ipcp_bootstrap(pid_t pid,
- struct dif_config conf);
-int ipcp_enroll(pid_t pid,
- char * dif_name,
- char * member_name,
- char ** n_1_difs,
- ssize_t n_1_difs_size);
-#endif
+#endif /* OUROBOROS_IPCP_H */
diff --git a/include/ouroboros/irm.h b/include/ouroboros/irm.h
index a6f0d9f3..780bf77b 100644
--- a/include/ouroboros/irm.h
+++ b/include/ouroboros/irm.h
@@ -24,22 +24,21 @@
#define OUROBOROS_IRM_H
#include "common.h"
-#include "rina_name.h"
+#include "instance_name.h"
-int irm_create_ipcp(rina_name_t name,
- char * ipcp_type);
-int irm_destroy_ipcp(rina_name_t name);
+int irm_create_ipcp(instance_name_t * api,
+ char * ipcp_type);
+int irm_destroy_ipcp(instance_name_t * api);
-int irm_bootstrap_ipcp(rina_name_t name,
- struct dif_config conf);
-int irm_enroll_ipcp(rina_name_t name,
- char * dif_name);
+int irm_bootstrap_ipcp(instance_name_t * api,
+ struct dif_config * conf);
+int irm_enroll_ipcp(instance_name_t * api,
+ char * dif_name);
-int irm_reg_ipcp(rina_name_t name,
- char ** difs,
- size_t difs_size);
-int irm_unreg_ipcp(rina_name_t name,
- char ** difs,
- size_t difs_size);
-
-#endif
+int irm_reg_ipcp(instance_name_t * api,
+ char ** difs,
+ size_t difs_size);
+int irm_unreg_ipcp(const instance_name_t * api,
+ char ** difs,
+ size_t difs_size);
+#endif /* OUROBOROS_IRM_H */
diff --git a/include/ouroboros/shm_du_map.h b/include/ouroboros/shm_du_map.h
index 68492a91..fb51768d 100644
--- a/include/ouroboros/shm_du_map.h
+++ b/include/ouroboros/shm_du_map.h
@@ -24,10 +24,6 @@
#ifndef OUROBOROS_SHM_DU_MAP_H
#define OUROBOROS_SHM_DU_MAP_H
-#ifndef _POSIX_C_SOURCE
-#define _POSIX_C_SOURCE 199506L
-#endif
-
#ifndef SHM_DU_BUFF_BLOCK_SIZE
#define SHM_DU_BUFF_BLOCK_SIZE sysconf(_SC_PAGESIZE)
#endif
diff --git a/include/ouroboros/sockets.h b/include/ouroboros/sockets.h
index 45d7a27d..0c517bd4 100644
--- a/include/ouroboros/sockets.h
+++ b/include/ouroboros/sockets.h
@@ -24,87 +24,27 @@
#define OUROBOROS_SOCKETS_H
#include <ouroboros/common.h>
-#include <ouroboros/rina_name.h>
#include <sys/types.h>
+#include "irmd_messages.pb-c.h"
+typedef IrmMsg irm_msg_t;
+
+#include "ipcpd_messages.pb-c.h"
+typedef IpcpMsg ipcp_msg_t;
+
#define IRM_SOCK_PATH "/tmp/irm_sock"
#define IRM_MSG_BUF_SIZE 256
#define IPCP_SOCK_PATH_PREFIX "/tmp/ipcp_sock"
-#define IPCP_MSG_BUFS_SIZE IRM_MSG_BUF_SIZE
-
-enum irm_msg_code {
- IRM_CREATE_IPCP,
- IRM_DESTROY_IPCP,
- IRM_BOOTSTRAP_IPCP,
- IRM_ENROLL_IPCP,
- IRM_REG_IPCP,
- IRM_UNREG_IPCP,
- IRM_AP_REG,
- IRM_AP_REG_R,
- IRM_AP_UNREG,
- IRM_FLOW_ACCEPT,
- IRM_FLOW_ACCEPT_R,
- IRM_FLOW_ALLOC_RESP,
- IRM_FLOW_ALLOC,
- IRM_FLOW_ALLOC_R,
- IRM_FLOW_ALLOC_RES,
- IRM_FLOW_ALLOC_RES_R,
- IRM_FLOW_DEALLOC,
- IRM_FLOW_CONTROL,
- IRM_FLOW_WRITE,
- IRM_FLOW_READ
-};
-
-struct irm_msg {
- enum irm_msg_code code;
- rina_name_t * name;
- char * ipcp_type;
- struct dif_config * conf;
- char * dif_name;
- char ** difs;
- size_t difs_size;
- char * ap_name;
- char * ae_name;
- int fd;
- int result;
- struct qos_spec * qos;
- int oflags;
- char * dst_ap_name;
- ssize_t count;
-};
-
-enum ipcp_msg_code {
- IPCP_BOOTSTRAP,
- IPCP_ENROLL,
- IPCP_REG,
- IPCP_UNREG
-};
-
-struct ipcp_msg {
- enum ipcp_msg_code code;
- struct dif_config * conf;
- char * dif_name;
- char * ap_name;
- char ** difs;
- size_t difs_size;
-};
+#define IPCP_MSG_BUF_SIZE IRM_MSG_BUF_SIZE
/* Returns the full socket path of an IPCP */
-char * ipcp_sock_path(pid_t pid);
-
-int server_socket_open(char * file_name);
-int client_socket_open(char * file_name);
+char * ipcp_sock_path(pid_t pid);
-int send_irmd_msg(struct irm_msg * msg);
-struct irm_msg * send_recv_irmd_msg(struct irm_msg * msg);
+int server_socket_open(char * file_name);
+int client_socket_open(char * file_name);
-/* Caller has to free the buffer */
-buffer_t * serialize_irm_msg(struct irm_msg * msg);
-buffer_t * serialize_ipcp_msg(struct ipcp_msg * msg);
-/* Caller has to free all the allocated fields in the message */
-struct irm_msg * deserialize_irm_msg(buffer_t * data);
-struct ipcp_msg * deserialize_ipcp_msg(buffer_t * data);
+irm_msg_t * send_recv_irm_msg(irm_msg_t * msg);
#endif
diff --git a/src/ipcpd/CMakeLists.txt b/src/ipcpd/CMakeLists.txt
index df6ba5e1..bcb5b986 100644
--- a/src/ipcpd/CMakeLists.txt
+++ b/src/ipcpd/CMakeLists.txt
@@ -8,6 +8,7 @@ set(SOURCE_FILES
# Add source files here
main.c
pci.c
+ shm_pci.c
)
add_executable (ipcpd ${SOURCE_FILES})
diff --git a/src/ipcpd/shm_pci.c b/src/ipcpd/shm_pci.c
new file mode 100644
index 00000000..d44e0e8f
--- /dev/null
+++ b/src/ipcpd/shm_pci.c
@@ -0,0 +1,146 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * Protocol Control Information in Shared Memory Map
+ *
+ * Dimitri Staessens <dimitri.staessens@intec.ugent.be>
+ * Sander Vrijders <sander.vrijders@intec.ugent.be>
+ *
+ * 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 "shm_pci.h"
+#include <malloc.h>
+#include <errno.h>
+
+#define SHM_PCI_HEAD_SIZE(a, b) a.addr_size * 2 + \
+ a.cep_id_size * 2 + \
+ a.pdu_length_size + \
+ b.ttl_size + \
+ a.seqno_size + \
+ a.qos_id_size
+#define SHM_PCI_TAIL_SIZE(b) b.chk_size
+
+#define OUROBOROS_PREFIX "ipcpd/shm_pci"
+
+#include <ouroboros/logs.h>
+
+struct shm_pci {
+ /* head */
+ uint8_t * dst_addr;
+ uint8_t * src_addr;
+ uint8_t * dst_cep_id;
+ uint8_t * src_cep_id;
+ uint8_t * pdu_length;
+ uint8_t * ttl;
+ uint8_t * seqno;
+ uint8_t * qos_id;
+
+ uint8_t * chk;
+
+ struct shm_du_buff * dub;
+
+ struct ipcp_dtp_const dtpc;
+ struct ipcp_dup_const dupc;
+
+};
+
+shm_pci_t * shm_pci_create(struct shm_du_buff * dub,
+ const struct ipcp_dtp_const * dtpc,
+ const struct ipcp_dup_const * dupc)
+{
+ struct shm_pci * p;
+
+ if (dub == NULL) {
+ LOG_DBGF("Bogus input. Bugging out.");
+ return NULL;
+ }
+
+ p = malloc(sizeof *p);
+
+ if (p == NULL)
+ return NULL;
+
+ p->dub = dub;
+
+ p->dtpc = *dtpc;
+ p->dupc = *dupc;
+
+ p->dst_addr = NULL;
+ p->src_addr = NULL;
+ p->dst_cep_id = NULL;
+ p->src_cep_id = NULL;
+ p->pdu_length = NULL;
+ p->ttl = NULL;
+ p->seqno = NULL;
+ p->qos_id = NULL;
+ p->chk = NULL;
+
+ return p;
+}
+
+void shm_pci_destroy(shm_pci_t * pci)
+{
+ free(pci);
+}
+
+int shm_pci_init(shm_pci_t * pci)
+{
+ if (pci == NULL) {
+ LOG_DBGF("Bogus input. Bugging out.");
+ return -EINVAL;
+ }
+
+ uint8_t * pci_head = shm_du_buff_head_alloc(
+ pci->dub, SHM_PCI_HEAD_SIZE(pci->dtpc, pci->dupc));
+ uint8_t * pci_tail = shm_du_buff_tail_alloc(
+ pci->dub, SHM_PCI_TAIL_SIZE(pci->dupc));
+
+ if (pci_head == NULL) {
+ LOG_DBG("Failed to allocate space for PCI at head.");
+ return -ENOBUFS;
+ }
+
+ if (pci_tail == NULL) {
+ LOG_DBG("Failed to allocate space for PCI at tail.");
+ return -ENOBUFS;
+ }
+
+ pci->dst_addr = pci_head;
+ pci->src_addr = (pci_head += pci->dtpc.addr_size);
+ pci->dst_cep_id = (pci_head += pci->dtpc.addr_size);
+ pci->src_cep_id = (pci_head += pci->dtpc.cep_id_size);
+ pci->pdu_length = (pci_head += pci->dtpc.cep_id_size);
+ pci->ttl = (pci_head += pci->dtpc.pdu_length_size);
+ pci->seqno = (pci_head += pci->dupc.ttl_size);
+ pci->qos_id = (pci_head += pci->dtpc.seqno_size);
+
+ pci->chk = (pci_tail);
+
+ return 0;
+}
+
+void shm_pci_release(shm_pci_t * pci)
+{
+ if (pci == NULL)
+ return;
+
+ if (pci->dub == NULL)
+ return;
+
+ shm_du_buff_head_release(pci->dub, SHM_PCI_HEAD_SIZE(pci->dtpc,
+ pci->dupc));
+ shm_du_buff_tail_release(pci->dub, SHM_PCI_TAIL_SIZE(pci->dupc));
+}
diff --git a/src/ipcpd/shm_pci.h b/src/ipcpd/shm_pci.h
new file mode 100644
index 00000000..cb8dd5dd
--- /dev/null
+++ b/src/ipcpd/shm_pci.h
@@ -0,0 +1,43 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * Protocol Control Information in Shared Memory Map
+ *
+ * Dimitri Staessens <dimitri.staessens@intec.ugent.be>
+ * Sander Vrijders <sander.vrijders@intec.ugent.be>
+ *
+ * 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_IPCP_SHM_PCI_H
+#define OUROBOROS_IPCP_SHM_PCI_H
+
+#include <ouroboros/shm_du_map.h>
+
+#include <dt_const.h>
+
+struct shm_pci;
+
+typedef struct shm_pci shm_pci_t;
+
+shm_pci_t * shm_pci_create(struct shm_du_buff * dub,
+ const struct ipcp_dtp_const * dtpc,
+ const struct ipcp_dup_const * dupc);
+void shm_pci_destroy(shm_pci_t * pci);
+
+int shm_pci_init(shm_pci_t * pci);
+void shm_pci_release(shm_pci_t * pci);
+
+#endif /* OUROBOROS_IPCP_SHM_PCI_H */
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 622b367d..0256248b 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -29,7 +29,7 @@
#include <ouroboros/ipcp.h>
#include <ouroboros/da.h>
#include <ouroboros/list.h>
-#include <ouroboros/rina_name.h>
+#include <ouroboros/instance_name.h>
#include <sys/socket.h>
#include <sys/un.h>
@@ -37,17 +37,18 @@
#include <errno.h>
struct name_to_pid_entry {
- struct list_head next;
- pid_t pid;
- rina_name_t * name;
+ struct list_head next;
+ pid_t pid;
+ instance_name_t * api;
};
struct irm {
struct list_head name_to_pid;
};
-static pid_t find_pid_by_name(struct irm * instance,
- rina_name_t * name)
+struct irm * instance = NULL;
+
+static pid_t find_pid_by_name(instance_name_t * api)
{
struct list_head * pos;
@@ -55,57 +56,56 @@ static pid_t find_pid_by_name(struct irm * instance,
struct name_to_pid_entry * tmp =
list_entry(pos, struct name_to_pid_entry, next);
- LOG_DBG("name is %s", name->ap_name);
+ LOG_DBG("name is %s", api->name);
- if (name_is_equal(name, tmp->name))
+ if (instance_name_cmp(api, tmp->api) == 0)
return tmp->pid;
}
return 0;
}
-static void create_ipcp(struct irm * instance,
- rina_name_t name,
- char * ipcp_type)
+static int create_ipcp(instance_name_t * api,
+ char * ipcp_type)
{
pid_t pid;
struct name_to_pid_entry * tmp;
- pid = ipcp_create(name, ipcp_type);
+ pid = ipcp_create(api, ipcp_type);
if (pid == -1) {
LOG_ERR("Failed to create IPCP");
- return;
+ return -1;
}
tmp = malloc(sizeof(*tmp));
if (tmp == NULL)
- return;
+ return -1;
INIT_LIST_HEAD(&tmp->next);
tmp->pid = pid;
- tmp->name = name_dup(&name);
- if (tmp->name == NULL) {
+ tmp->api = instance_name_dup(api);
+ if (tmp->api == NULL) {
free(tmp);
- return;
+ return -1;
}
LOG_DBG("Created IPC process with pid %d", pid);
list_add(&tmp->next, &instance->name_to_pid);
+ return 0;
}
-static void destroy_ipcp(struct irm * instance,
- rina_name_t name)
+static int destroy_ipcp(instance_name_t * api)
{
pid_t pid = 0;
struct list_head * pos;
struct list_head * n;
- pid = find_pid_by_name(instance, &name);
+ pid = find_pid_by_name(api);
if (pid == 0) {
LOG_ERR("No such IPCP");
- return;
+ return -1;
}
LOG_DBG("Destroying ipcp with pid %d", pid);
@@ -117,94 +117,178 @@ static void destroy_ipcp(struct irm * instance,
struct name_to_pid_entry * tmp =
list_entry(pos, struct name_to_pid_entry, next);
- if (name_is_equal(&name, tmp->name))
+ if (instance_name_cmp(api, tmp->api) == 0)
list_del(&tmp->next);
}
+
+ return 0;
}
-static void bootstrap_ipcp(struct irm * instance,
- rina_name_t name,
- struct dif_config conf)
+static int bootstrap_ipcp(instance_name_t * api,
+ struct dif_config * conf)
{
pid_t pid = 0;
- pid = find_pid_by_name(instance, &name);
+ pid = find_pid_by_name(api);
if (pid == 0) {
LOG_ERR("No such IPCP");
- return;
+ return -1;
}
- if (ipcp_bootstrap(pid, conf))
+ if (ipcp_bootstrap(pid, conf)) {
LOG_ERR("Could not bootstrap IPCP");
+ return -1;
+ }
+
+ return 0;
}
-static void enroll_ipcp(struct irm * instance,
- rina_name_t name,
- char * dif_name)
+static int enroll_ipcp(instance_name_t * api,
+ char * dif_name)
{
- pid_t pid = 0;
- char * member;
+ pid_t pid = 0;
+ char * member;
char ** n_1_difs = NULL;
ssize_t n_1_difs_size = 0;
- pid = find_pid_by_name(instance, &name);
+ pid = find_pid_by_name(api);
if (pid == 0) {
LOG_ERR("No such IPCP");
- return;
+ return -1;
}
member = da_resolve_daf(dif_name);
if (member == NULL) {
LOG_ERR("Could not find a member of that DIF");
- return;
+ return -1;
}
n_1_difs_size = da_resolve_dap(member, n_1_difs);
if (n_1_difs_size != 0)
- if (ipcp_enroll(pid, dif_name, member,
- n_1_difs, n_1_difs_size))
+ if (ipcp_enroll(pid, member, n_1_difs[0])) {
LOG_ERR("Could not enroll IPCP");
+ return -1;
+ }
+
+ return 0;
}
-static void reg_ipcp(struct irm * instance,
- rina_name_t name,
- char ** difs,
- size_t difs_size)
+static int reg_ipcp(instance_name_t * api,
+ char ** difs,
+ size_t difs_size)
{
pid_t pid = 0;
- pid = find_pid_by_name(instance, &name);
+ pid = find_pid_by_name(api);
if (pid == 0) {
LOG_ERR("No such IPCP");
- return;
+ return -1;
}
- if (ipcp_reg(pid, difs, difs_size))
+ if (ipcp_reg(pid, difs, difs_size)) {
LOG_ERR("Could not register IPCP to N-1 DIF(s)");
+ return -1;
+ }
+
+ return 0;
}
-static void unreg_ipcp(struct irm * instance,
- rina_name_t name,
- char ** difs,
- size_t difs_size)
+static int unreg_ipcp(instance_name_t * api,
+ char ** difs,
+ size_t difs_size)
{
pid_t pid = 0;
- pid = find_pid_by_name(instance, &name);
+ pid = find_pid_by_name(api);
if (pid == 0) {
LOG_ERR("No such IPCP");
- return;
+ return -1;
}
- if (ipcp_unreg(pid, difs, difs_size))
+ if (ipcp_unreg(pid, difs, difs_size)) {
LOG_ERR("Could not unregister IPCP from N-1 DIF(s)");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int ap_reg(char * ap_name,
+ char ** difs,
+ size_t difs_size)
+{
+ return -1;
+}
+
+static int ap_unreg(char * ap_name,
+ char ** difs,
+ size_t difs_size)
+{
+ return -1;
+}
+
+static int flow_accept(int fd,
+ char * ap_name,
+ char * ae_name)
+{
+ return -1;
+}
+
+static int flow_alloc_resp(int fd,
+ int result)
+{
+
+ return -1;
+}
+
+static int flow_alloc(char * dst_ap_name,
+ char * src_ap_name,
+ char * src_ae_name,
+ struct qos_spec * qos,
+ int oflags)
+{
+ return -1;
+}
+
+static int flow_alloc_res(int fd)
+{
+
+ return -1;
+}
+
+static int flow_dealloc(int fd)
+{
+ return -1;
+}
+
+static int flow_cntl(int fd,
+ int oflags)
+{
+ return -1;
+}
+
+static int flow_req_arr(uint32_t reg_api_id,
+ char * ap_name,
+ char * ae_name)
+{
+ return -1;
+}
+
+static int flow_alloc_reply(uint32_t port_id,
+ int result)
+{
+ return -1;
+}
+
+static int flow_dealloc_ipcp(uint32_t port_id)
+{
+ return -1;
}
/* FIXME: Close sockfd on closing and release irm */
int main()
{
- struct irm * instance = NULL;
- int sockfd;
+ int sockfd;
uint8_t buf[IRM_MSG_BUF_SIZE];
instance = malloc(sizeof(*instance));
@@ -219,10 +303,13 @@ int main()
while (true) {
int cli_sockfd;
- struct irm_msg * msg;
+ irm_msg_t * msg;
ssize_t count;
+ instance_name_t api;
buffer_t buffer;
- int i;
+ irm_msg_t ret_msg = IRM_MSG__INIT;
+
+ ret_msg.code = IRM_MSG_CODE__IRM_REPLY;
cli_sockfd = accept(sockfd, 0, 0);
if (cli_sockfd < 0) {
@@ -231,62 +318,140 @@ int main()
}
count = read(cli_sockfd, buf, IRM_MSG_BUF_SIZE);
- if (count > 0) {
- buffer.size = count;
- buffer.data = buf;
- msg = deserialize_irm_msg(&buffer);
- if (msg == NULL)
- continue;
-
- switch (msg->code) {
- case IRM_CREATE_IPCP:
- create_ipcp(instance,
- *(msg->name),
- msg->ipcp_type);
- free(msg->ipcp_type);
- break;
- case IRM_DESTROY_IPCP:
- destroy_ipcp(instance,
- *(msg->name));
- break;
- case IRM_BOOTSTRAP_IPCP:
- bootstrap_ipcp(instance,
- *(msg->name),
- *(msg->conf));
- free(msg->conf);
- break;
- case IRM_ENROLL_IPCP:
- enroll_ipcp(instance,
- *(msg->name),
- msg->dif_name);
- free(msg->dif_name);
- break;
- case IRM_REG_IPCP:
- reg_ipcp(instance,
- *(msg->name),
- msg->difs,
- msg->difs_size);
- for (i = 0; i < msg->difs_size; i++)
- free(msg->difs[i]);
- free(msg->difs);
- break;
- case IRM_UNREG_IPCP:
- unreg_ipcp(instance,
- *(msg->name),
- msg->difs,
- msg->difs_size);
- for (i = 0; i < msg->difs_size; i++)
- free(msg->difs[i]);
- free(msg->difs);
- break;
- default:
- LOG_ERR("Don't know that message code");
- break;
- }
- name_destroy(msg->name);
- free(msg);
+ if (count <= 0) {
+ LOG_ERR("Failed to read from socket");
+ close(cli_sockfd);
+ continue;
+ }
+
+ msg = irm_msg__unpack(NULL, count, buf);
+ if (msg == NULL) {
+ close(cli_sockfd);
+ continue;
+ }
+
+ api.name = msg->ap_name;
+ api.id = msg->api_id;
+
+ switch (msg->code) {
+ case IRM_MSG_CODE__IRM_CREATE_IPCP:
+ ret_msg.has_result = true;
+ ret_msg.result = create_ipcp(&api,
+ msg->ipcp_type);
+ break;
+ case IRM_MSG_CODE__IRM_DESTROY_IPCP:
+ ret_msg.has_result = true;
+ ret_msg.result = destroy_ipcp(&api);
+ break;
+ case IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP:
+ ret_msg.has_result = true;
+ ret_msg.result = bootstrap_ipcp(&api, NULL);
+ break;
+ case IRM_MSG_CODE__IRM_ENROLL_IPCP:
+ ret_msg.has_result = true;
+ ret_msg.result = enroll_ipcp(&api,
+ msg->dif_name[0]);
+ break;
+ case IRM_MSG_CODE__IRM_REG_IPCP:
+ ret_msg.has_result = true;
+ ret_msg.result = reg_ipcp(&api,
+ msg->dif_name,
+ msg->n_dif_name);
+ break;
+ case IRM_MSG_CODE__IRM_UNREG_IPCP:
+ ret_msg.has_result = true;
+ ret_msg.result = unreg_ipcp(&api,
+ msg->dif_name,
+ msg->n_dif_name);
+ break;
+ case IRM_MSG_CODE__IRM_AP_REG:
+ ret_msg.has_fd = true;
+ ret_msg.fd = ap_reg(msg->ap_name,
+ msg->dif_name,
+ msg->n_dif_name);
+ break;
+ case IRM_MSG_CODE__IRM_AP_UNREG:
+ ret_msg.has_result = true;
+ ret_msg.result = ap_unreg(msg->ap_name,
+ msg->dif_name,
+ msg->n_dif_name);
+ break;
+ case IRM_MSG_CODE__IRM_FLOW_ACCEPT:
+ ret_msg.has_fd = true;
+ ret_msg.fd = flow_accept(msg->fd,
+ ret_msg.ap_name,
+ ret_msg.ae_name);
+ break;
+ case IRM_MSG_CODE__IRM_FLOW_ALLOC_RESP:
+ ret_msg.has_result = true;
+ ret_msg.result = flow_alloc_resp(msg->fd,
+ msg->result);
+ break;
+ case IRM_MSG_CODE__IRM_FLOW_ALLOC:
+ ret_msg.has_fd = true;
+ ret_msg.fd = flow_alloc(msg->dst_ap_name,
+ msg->ap_name,
+ msg->ae_name,
+ NULL,
+ msg->oflags);
+ break;
+ case IRM_MSG_CODE__IRM_FLOW_ALLOC_RES:
+ ret_msg.has_result = true;
+ ret_msg.result = flow_alloc_res(msg->fd);
+ break;
+ case IRM_MSG_CODE__IRM_FLOW_DEALLOC:
+ ret_msg.has_result = true;
+ ret_msg.result = flow_dealloc(msg->fd);
+ break;
+ case IRM_MSG_CODE__IRM_FLOW_CONTROL:
+ ret_msg.has_result = true;
+ ret_msg.result = flow_cntl(msg->fd,
+ msg->oflags);
+ break;
+ case IRM_MSG_CODE__IPCP_FLOW_REQ_ARR:
+ ret_msg.has_fd = true;
+ ret_msg.fd = flow_req_arr(msg->port_id,
+ msg->ap_name,
+ msg->ae_name);
+ break;
+ case IRM_MSG_CODE__IPCP_FLOW_ALLOC_REPLY:
+ ret_msg.has_result = true;
+ ret_msg.result = flow_alloc_reply(msg->port_id,
+ msg->result);
+ break;
+ case IRM_MSG_CODE__IPCP_FLOW_DEALLOC:
+ ret_msg.has_result = true;
+ ret_msg.result = flow_dealloc_ipcp(msg->port_id);
+ break;
+ default:
+ LOG_ERR("Don't know that message code");
+ break;
+ }
+
+ irm_msg__free_unpacked(msg, NULL);
+
+ buffer.size = irm_msg__get_packed_size(&ret_msg);
+ if (buffer.size == 0) {
+ LOG_ERR("Failed to send reply message");
+ close(cli_sockfd);
+ continue;
+ }
+
+ buffer.data = malloc(buffer.size);
+ if (buffer.data == NULL) {
+ close(cli_sockfd);
+ continue;
+ }
+
+ irm_msg__pack(&ret_msg, buffer.data);
+
+ if (write(cli_sockfd, buffer.data, buffer.size) == -1) {
+ free(buffer.data);
+ close(cli_sockfd);
+ continue;
}
+ free(buffer.data);
close(cli_sockfd);
}
diff --git a/src/lib/.gitignore b/src/lib/.gitignore
new file mode 100644
index 00000000..8704469b
--- /dev/null
+++ b/src/lib/.gitignore
@@ -0,0 +1 @@
+*.pb-c.[ch] \ No newline at end of file
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 42a4d5c0..1f7b0f55 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -4,40 +4,54 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_BINARY_DIR}/include)
+find_package(ProtobufC REQUIRED)
+include_directories(${PROTOBUF_INCLUDE_DIRS})
+protobuf_generate_c(IRM_PROTO_SRCS IRM_PROTO_HDRS irmd_messages.proto)
+protobuf_generate_c(IPCP_PROTO_SRCS IPCP_PROTO_HDRS ipcpd_messages.proto)
+
find_library(LIBRT_LIBRARIES rt)
if(NOT LIBRT_LIBRARIES)
- message(FATAL_ERROR "librt not found")
+ message(FATAL_ERROR "librt not found")
endif()
find_library(LIBPTHREAD_LIBRARIES pthread)
if(NOT LIBPTHREAD_LIBRARIES)
- message(FATAL_ERROR "libpthread not found")
+ message(FATAL_ERROR "libpthread not found")
endif()
set(SOURCE_FILES
- # Add source files here
- bitmap.c
- cdap.c
- da.c
- dev.c
- du_buff.c
- ipcp.c
- irm.c
- list.c
- rina_name.c
- shm_du_map.c
- sockets.c
- utils.c
-)
-
-add_library(ouroboros SHARED ${SOURCE_FILES})
-target_link_libraries(ouroboros ${LIBRT_LIBRARIES} ${LIBPTHREAD_LIBRARIES})
+ # Add source files here
+ bitmap.c
+ cdap.c
+ da.c
+ dev.c
+ du_buff.c
+ flow.c
+ instance_name.c
+ ipcp.c
+ irm.c
+ list.c
+ shm_du_map.c
+ sockets.c
+ utils.c
+ )
+
+install(FILES ${IRM_PROTO_HDRS} ${IPCP_PROTO_HDRS}
+ DESTINATION include/ouroboros)
+
+add_library(ouroboros SHARED ${SOURCE_FILES}
+ ${IRM_PROTO_SRCS} ${IPCP_PROTO_SRCS})
+
+target_link_libraries(ouroboros ${LIBRT_LIBRARIES}
+ ${LIBPTHREAD_LIBRARIES} ${PROTOBUF_C_LIBRARY})
include(MacroAddCompileFlags)
if (CMAKE_BUILD_TYPE MATCHES Debug)
- MACRO_ADD_COMPILE_FLAGS(ouroboros -DCONFIG_OUROBOROS_DEBUG)
+ MACRO_ADD_COMPILE_FLAGS(ouroboros -DCONFIG_OUROBOROS_DEBUG)
endif (CMAKE_BUILD_TYPE MATCHES Debug)
install(TARGETS ouroboros LIBRARY DESTINATION lib)
+target_include_directories(ouroboros PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
+
add_subdirectory(tests)
diff --git a/src/lib/dev.c b/src/lib/dev.c
index 7c0c8a15..c138b009 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -32,30 +32,33 @@ int ap_reg(char * ap_name,
char ** difs,
size_t difs_size)
{
- struct irm_msg msg;
- struct irm_msg * recv_msg = NULL;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
int fd = 0;
if (ap_name == NULL ||
difs == NULL ||
- difs_size == 0) {
- LOG_ERR("Invalid arguments");
- return -1;
+ difs_size == 0 ||
+ difs[0] == NULL) {
+ return -EINVAL;
}
- msg.code = IRM_AP_REG;
+ msg.code = IRM_MSG_CODE__IRM_AP_REG;
msg.ap_name = ap_name;
- msg.difs = difs;
- msg.difs_size = difs_size;
+ msg.dif_name = difs;
+ msg.n_dif_name = difs_size;
+
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
- recv_msg = send_recv_irmd_msg(&msg);
- if (recv_msg == NULL) {
- LOG_ERR("Failed to send and receive message");
+ if (recv_msg->has_fd == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
fd = recv_msg->fd;
- free(recv_msg);
+ irm_msg__free_unpacked(recv_msg, NULL);
return fd;
}
@@ -64,76 +67,95 @@ int ap_unreg(char * ap_name,
char ** difs,
size_t difs_size)
{
- struct irm_msg msg;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
if (ap_name == NULL ||
difs == NULL ||
- difs_size == 0) {
- LOG_ERR("Invalid arguments");
- return -1;
+ difs_size == 0 ||
+ difs[0] == NULL) {
+ return -EINVAL;
}
- msg.code = IRM_AP_UNREG;
+ msg.code = IRM_MSG_CODE__IRM_AP_UNREG;
msg.ap_name = ap_name;
- msg.difs = difs;
- msg.difs_size = difs_size;
+ msg.dif_name = difs;
+ msg.n_dif_name = difs_size;
- if (send_irmd_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
int flow_accept(int fd,
char * ap_name,
char * ae_name)
{
- struct irm_msg msg;
- struct irm_msg * recv_msg = NULL;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
int cli_fd = 0;
if (ap_name == NULL) {
- LOG_ERR("Invalid arguments");
- return -1;
+ return -EINVAL;
}
- msg.code = IRM_FLOW_ACCEPT;
+ msg.code = IRM_MSG_CODE__IRM_FLOW_ACCEPT;
+ msg.has_fd = true;
msg.fd = fd;
- recv_msg = send_recv_irmd_msg(&msg);
- if (recv_msg == NULL) {
- LOG_ERR("Failed to send and receive message");
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
return -1;
- }
+ if (recv_msg->has_fd == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
+ return -1;
+ }
cli_fd = recv_msg->fd;
ap_name = recv_msg->ap_name;
- if (ae_name == NULL)
- ae_name = "";
- else
- ae_name = recv_msg->ae_name;
- free(recv_msg);
+ ae_name = recv_msg->ae_name;
+ irm_msg__free_unpacked(recv_msg, NULL);
return cli_fd;
}
int flow_alloc_resp(int fd,
int result)
{
- struct irm_msg msg;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
- msg.code = IRM_FLOW_ALLOC_RESP;
+ msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC_RESP;
+ msg.has_fd = true;
msg.fd = fd;
+ msg.has_result = true;
msg.result = result;
- if (send_irmd_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
int flow_alloc(char * dst_ap_name,
@@ -142,87 +164,110 @@ int flow_alloc(char * dst_ap_name,
struct qos_spec * qos,
int oflags)
{
- struct irm_msg msg;
- struct irm_msg * recv_msg = NULL;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
int fd = 0;
if (dst_ap_name == NULL ||
- src_ap_name == NULL) {
- LOG_ERR("Invalid arguments");
- return -1;
+ src_ap_name == NULL ||
+ qos == NULL) {
+ return -EINVAL;
}
- msg.code = IRM_FLOW_ALLOC;
+ msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC;
msg.dst_ap_name = dst_ap_name;
msg.ap_name = src_ap_name;
- if (src_ae_name == NULL)
- msg.ae_name = "";
- else
- msg.ae_name = src_ae_name;
- msg.qos = qos;
+ msg.ae_name = src_ae_name;
+ msg.has_oflags = true;
msg.oflags = oflags;
- recv_msg = send_recv_irmd_msg(&msg);
- if (recv_msg == NULL) {
- LOG_ERR("Failed to send and receive message");
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_fd == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
fd = recv_msg->fd;
- free(recv_msg);
-
+ irm_msg__free_unpacked(recv_msg, NULL);
return fd;
}
int flow_alloc_res(int fd)
{
- struct irm_msg msg;
- struct irm_msg * recv_msg = NULL;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
int result = 0;
- msg.code = IRM_FLOW_ALLOC_RES;
+ msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC_RES;
+ msg.has_fd = true;
msg.fd = fd;
- recv_msg = send_recv_irmd_msg(&msg);
- if (recv_msg == NULL) {
- LOG_ERR("Failed to send and receive message");
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
result = recv_msg->result;
- free(recv_msg);
+ irm_msg__free_unpacked(recv_msg, NULL);
return result;
}
int flow_dealloc(int fd)
{
- struct irm_msg msg;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
- msg.code = IRM_FLOW_DEALLOC;
+ msg.code = IRM_MSG_CODE__IRM_FLOW_DEALLOC;
+ msg.has_fd = true;
msg.fd = fd;
- if (send_irmd_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
int flow_cntl(int fd, int oflags)
{
- struct irm_msg msg;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
+ msg.has_fd = true;
msg.fd = fd;
msg.oflags = oflags;
- if (send_irmd_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
ssize_t flow_write(int fd,
diff --git a/src/lib/flow.c b/src/lib/flow.c
new file mode 100644
index 00000000..04166298
--- /dev/null
+++ b/src/lib/flow.c
@@ -0,0 +1,83 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * Flows
+ *
+ * Dimitri Staessens <dimitri.staessens@intec.ugent.be>
+ *
+ * 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 <malloc.h>
+#include <ouroboros/flow.h>
+
+#define OUROBOROS_PREFIX "ipcpd/flow"
+
+#include <ouroboros/logs.h>
+
+flow_t * flow_create(int32_t port_id)
+{
+ flow_t * flow = malloc(sizeof *flow);
+ if (flow == NULL) {
+ LOG_DBGF("Could not malloc flow.");
+ return NULL;
+ }
+
+ flow->port_id = port_id;
+ flow->oflags = FLOW_O_DEFAULT;
+ flow->state = FLOW_INIT;
+
+ pthread_mutex_init(&flow->lock, NULL);
+
+ return flow;
+}
+
+void flow_destroy(flow_t * flow)
+{
+ free(flow);
+}
+
+int flow_set_opts(flow_t * flow, uint16_t opts)
+{
+ if (flow == NULL) {
+ LOG_DBGF("Non-existing flow.");
+ return -1;
+ }
+
+ pthread_mutex_lock(&flow->lock);
+
+ if ((opts & FLOW_O_ACCMODE) == FLOW_O_ACCMODE) {
+ flow->oflags = FLOW_O_DEFAULT;
+ pthread_mutex_unlock(&flow->lock);
+ LOG_WARN("Invalid flow options. Setting default.");
+ return -1;
+ }
+
+ flow->oflags = opts;
+
+ pthread_mutex_unlock(&flow->lock);
+
+ return 0;
+}
+
+uint16_t flow_get_opts(const flow_t * flow)
+{
+ if (flow == NULL) {
+ LOG_DBGF("Non-existing flow.");
+ return FLOW_O_INVALID;
+ }
+
+ return flow->oflags;
+}
diff --git a/src/lib/rina_name.c b/src/lib/instance_name.c
index 2dcfbb08..0f666211 100644
--- a/src/lib/rina_name.c
+++ b/src/lib/instance_name.c
@@ -19,11 +19,11 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#define OUROBOROS_PREFIX "name-utils"
+#define OUROBOROS_PREFIX "instance-name"
#include <ouroboros/logs.h>
#include <ouroboros/common.h>
-#include <ouroboros/rina_name.h>
+#include <ouroboros/instance_name.h>
#include <ouroboros/utils.h>
#include <string.h>
@@ -31,6 +31,8 @@
#include <malloc.h>
#include <stdlib.h>
+#define instance_name_is_equal(a, b) (instance_name_cmp(a, b) == 0)
+
static char * strdup(const char * src)
{
int len = 0;
@@ -50,153 +52,144 @@ static char * strdup(const char * src)
return dst;
}
-rina_name_t * name_create()
+instance_name_t * instance_name_create()
{
- rina_name_t * tmp;
+ instance_name_t * tmp;
- tmp = malloc(sizeof(rina_name_t));
+ tmp = malloc(sizeof *tmp);
- tmp->ap_name = NULL;
- tmp->api_id = 0;
+ tmp->name = NULL;
+ tmp->id = 0;
return tmp;
}
-rina_name_t * name_init_from(rina_name_t * dst,
- const char * ap_name,
- unsigned int api_id)
+instance_name_t * instance_name_init_from(instance_name_t * dst,
+ const char * name,
+ uint16_t id)
{
if (dst == NULL)
return NULL;
/* Clean up the destination, leftovers might be there ... */
- name_fini(dst);
+ instance_name_fini(dst);
- dst->ap_name = strdup(ap_name);
- dst->api_id = api_id;
+ dst->name = strdup(name);
+ dst->id = id;
- if (dst->ap_name == NULL) {
- name_fini(dst);
+ if (dst->name == NULL) {
+ instance_name_fini(dst);
return NULL;
}
return dst;
}
-rina_name_t * name_init_with(rina_name_t * dst,
- char * ap_name,
- unsigned int api_id)
+instance_name_t * instance_name_init_with(instance_name_t * dst,
+ char * name,
+ uint16_t id)
{
if (dst == NULL)
return NULL;
/* Clean up the destination, leftovers might be there ... */
- name_fini(dst);
+ instance_name_fini(dst);
- dst->ap_name = ap_name;
- dst->api_id = api_id;
+ dst->name = name;
+ dst->id = id;
return dst;
}
-void name_fini(rina_name_t * n)
+void instance_name_fini(instance_name_t * n)
{
- if (n == NULL)
+ if (n == NULL || n->name == NULL)
return;
- if (n->ap_name != NULL) {
- free(n->ap_name);
- n->ap_name = NULL;
- }
+ free(n->name);
+ n->name = NULL;
}
-void name_destroy(rina_name_t * ptr)
+void instance_name_destroy(instance_name_t * ptr)
{
if (ptr == NULL)
return;
- name_fini(ptr);
+ instance_name_fini(ptr);
free(ptr);
}
-int name_cpy(const rina_name_t * src,
- rina_name_t * dst)
+int instance_name_cpy(instance_name_t * dst,
+ const instance_name_t * src)
{
- rina_name_t * res;
+ instance_name_t * res;
if (src == NULL || dst == NULL)
return -1;
- res = name_init_from(dst,
- src->ap_name,
- src->api_id);
+ res = instance_name_init_from(dst, src->name, src->id);
if (res == NULL)
return -1;
return 0;
}
-rina_name_t * name_dup(const rina_name_t * src)
+instance_name_t * instance_name_dup(const instance_name_t * src)
{
- rina_name_t * tmp;
+ instance_name_t * tmp;
if (src == NULL)
return NULL;
- tmp = name_create();
+ tmp = instance_name_create();
if (tmp == NULL)
return NULL;
- if (name_cpy(src, tmp)) {
- name_destroy(tmp);
+ if (instance_name_cpy(tmp, src)) {
+ instance_name_destroy(tmp);
return NULL;
}
return tmp;
}
-#define NAME_CMP_FIELD(X, Y, FIELD) \
- ((X->FIELD != NULL && Y->FIELD != NULL) ? \
- strcmp(X->FIELD, Y->FIELD) : \
- ((X->FIELD == NULL && Y->FIELD == NULL) ? 0 : -1))
-
-bool name_is_ok(const rina_name_t * n)
-{ return (n != NULL &&
- n->ap_name != NULL &&
- strlen(n->ap_name)); }
+bool instance_name_is_valid(const instance_name_t * n)
+{
+ return (n != NULL && n->name != NULL && strlen(n->name));
+}
-bool name_cmp(uint8_t flags,
- const rina_name_t * a,
- const rina_name_t * b)
+int instance_name_cmp(const instance_name_t * a,
+ const instance_name_t * b)
{
- if (a == b)
- return true;
- if (a == NULL || b == NULL)
- return false;
+ int ret = 0;
+
+ if (a == NULL || b == NULL) {
+ LOG_DBGF("Won't compare NULL.");
+ return -2;
+ }
- if (!(flags & NAME_CMP_ALL))
- LOG_DBG("No flags, name comparison will be meaningless ...");
+ if (a == b)
+ return 0;
- if (flags & NAME_CMP_APN)
- if (NAME_CMP_FIELD(a, b, ap_name))
- return false;
+ ret = strcmp(a->name, b->name);
- if (flags & NAME_CMP_API)
- if (a->api_id != b->api_id)
- return false;
+ if (!ret) {
+ if (a->id == b-> id)
+ return 0;
+ else
+ return a->id < b->id ? -1 : 1;
+ }
- return true;
+ return ret;
}
-bool name_is_equal(const rina_name_t * a,
- const rina_name_t * b)
-{ return name_cmp(NAME_CMP_ALL, a, b); }
+
#define DELIMITER "/"
-char * name_to_string(const rina_name_t * n)
+char * instance_name_to_string(const instance_name_t * n)
{
char * tmp;
size_t size;
@@ -206,14 +199,14 @@ char * name_to_string(const rina_name_t * n)
if (n == NULL)
return NULL;
- size = 0;
+ size = 0;
- size += (n->ap_name != NULL ?
- strlen(n->ap_name) : none_len);
+ size += (n->name != NULL ?
+ strlen(n->name) : none_len);
size += strlen(DELIMITER);
- size += (n->api_id == 0 ?
- 1 : n_digits(n->api_id));
+ size += (n->id == 0 ?
+ 1 : n_digits(n->id));
size += strlen(DELIMITER);
tmp = malloc(size);
@@ -221,8 +214,8 @@ char * name_to_string(const rina_name_t * n)
return NULL;
if (sprintf(tmp, "%s%s%d",
- (n->ap_name != NULL ? n->ap_name : none),
- DELIMITER, n->api_id)
+ (n->name != NULL ? n->name : none),
+ DELIMITER, n->id)
!= size - 1) {
free(tmp);
return NULL;
@@ -231,9 +224,9 @@ char * name_to_string(const rina_name_t * n)
return tmp;
}
-rina_name_t * string_to_name(const char * s)
+instance_name_t * string_to_instance_name(const char * s)
{
- rina_name_t * name;
+ instance_name_t * name;
char * tmp1 = NULL;
char * tmp_ap = NULL;
@@ -254,15 +247,15 @@ rina_name_t * string_to_name(const char * s)
if (tmp_s_api != NULL)
tmp_api = (unsigned int) strtol(tmp_s_api, &tmp2, 10);
- name = name_create();
+ name = instance_name_create();
if (name == NULL) {
if (tmp1 != NULL)
free(tmp1);
return NULL;
}
- if (!name_init_from(name, tmp_ap, tmp_api)) {
- name_destroy(name);
+ if (!instance_name_init_from(name, tmp_ap, tmp_api)) {
+ instance_name_destroy(name);
if (tmp1 != NULL)
free(tmp1);
return NULL;
diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c
index 53d717ba..d61fcb50 100644
--- a/src/lib/ipcp.c
+++ b/src/lib/ipcp.c
@@ -22,14 +22,10 @@
#define OUROBOROS_PREFIX "lib-ipcp"
-#ifndef _POSIX_C_SOURCE
-#define _POSIX_C_SOURCE 199506L
-#endif
-
+#include <ouroboros/config.h>
#include <ouroboros/ipcp.h>
#include <ouroboros/common.h>
#include <ouroboros/logs.h>
-#include <ouroboros/config.h>
#include <ouroboros/utils.h>
#include <ouroboros/sockets.h>
@@ -39,47 +35,72 @@
#include <sys/types.h>
#include <sys/wait.h>
-static int send_ipcp_msg(pid_t pid,
- struct ipcp_msg * msg)
+static ipcp_msg_t * send_recv_ipcp_msg(pid_t pid,
+ ipcp_msg_t * msg)
{
int sockfd = 0;
- buffer_t * buf = NULL;
- char * sock_path;
+ buffer_t buf;
+ char * sock_path = NULL;
+ ssize_t count = 0;
+ ipcp_msg_t * recv_msg = NULL;
sock_path = ipcp_sock_path(pid);
if (sock_path == NULL)
- return -1;
+ return NULL;
sockfd = client_socket_open(sock_path);
if (sockfd < 0) {
free(sock_path);
- return -1;
+ return NULL;
}
- buf = serialize_ipcp_msg(msg);
- if (buf == NULL) {
+ buf.size = ipcp_msg__get_packed_size(msg);
+ if (buf.size == 0) {
+ close(sockfd);
free(sock_path);
+ return NULL;
+ }
+
+ buf.data = malloc(buf.size);
+ if (buf.data == NULL) {
close(sockfd);
- return -1;
+ free(sock_path);
+ return NULL;
}
- if (write(sockfd, buf->data, buf->size) == -1) {
+ ipcp_msg__pack(msg, buf.data);
+
+ if (write(sockfd, buf.data, buf.size) == -1) {
free(sock_path);
- free(buf->data);
- free(buf);
+ free(buf.data);
close(sockfd);
- return -1;
+ return NULL;
}
- free(buf->data);
- free(buf);
+ count = read(sockfd, buf.data, IPCP_MSG_BUF_SIZE);
+ if (count <= 0) {
+ free(sock_path);
+ free(buf.data);
+ close(sockfd);
+ return NULL;
+ }
+
+ recv_msg = ipcp_msg__unpack(NULL, count, buf.data);
+ if (recv_msg == NULL) {
+ free(sock_path);
+ free(buf.data);
+ close(sockfd);
+ return NULL;
+ }
+ free(buf.data);
+ free(sock_path);
close(sockfd);
- return 0;
+ return recv_msg;
}
-pid_t ipcp_create(rina_name_t name,
- char * ipcp_type)
+pid_t ipcp_create(instance_name_t * api,
+ char * ipcp_type)
{
pid_t pid = 0;
char * api_id = NULL;
@@ -90,6 +111,8 @@ pid_t ipcp_create(rina_name_t name,
if (ipcp_type == NULL)
return -1;
+ LOG_DBG("%lu", _POSIX_C_SOURCE);
+
pid = fork();
if (pid == -1) {
LOG_ERR("Failed to fork");
@@ -100,12 +123,12 @@ pid_t ipcp_create(rina_name_t name,
return pid;
}
- api_id = malloc(n_digits(name.api_id) + 1);
+ api_id = malloc(n_digits(api->id) + 1);
if (!api_id) {
LOG_ERR("Failed to malloc");
exit(EXIT_FAILURE);
}
- sprintf(api_id, "%d", name.api_id);
+ sprintf(api_id, "%d", api->id);
len += strlen(INSTALL_DIR);
len += strlen(ipcp_dir);
@@ -122,7 +145,7 @@ pid_t ipcp_create(rina_name_t name,
strcat(full_name, ipcp_dir);
char * argv[] = {full_name,
- name.ap_name, api_id,
+ api->name, api_id,
ipcp_type, 0};
char * envp[] = {0};
@@ -158,84 +181,362 @@ int ipcp_reg(pid_t pid,
char ** difs,
size_t difs_size)
{
- struct ipcp_msg msg;
+ ipcp_msg_t msg = IPCP_MSG__INIT;
+ ipcp_msg_t * recv_msg = NULL;
+ int ret = -1;
- if (difs == NULL)
- return -1;
+ if (difs == NULL ||
+ difs_size == 0 ||
+ difs[0] == NULL)
+ return -EINVAL;
- msg.code = IPCP_REG;
- msg.difs = difs;
- msg.difs_size = difs_size;
+ msg.code = IPCP_MSG_CODE__IPCP_REG;
+ msg.dif_name = difs;
+ msg.n_dif_name = difs_size;
+
+ recv_msg = send_recv_ipcp_msg(pid, &msg);
+ if (recv_msg == NULL)
+ return -1;
- if (send_ipcp_msg(pid, &msg)) {
- LOG_ERR("Failed to send message to daemon");
+ if (recv_msg->has_result == false) {
+ ipcp_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ ipcp_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
int ipcp_unreg(pid_t pid,
char ** difs,
size_t difs_size)
{
- struct ipcp_msg msg;
+ ipcp_msg_t msg = IPCP_MSG__INIT;
+ ipcp_msg_t * recv_msg = NULL;
+ int ret = -1;
- if (difs == NULL)
- return -1;
+ if (difs == NULL ||
+ difs_size == 0 ||
+ difs[0] == NULL)
+ return -EINVAL;
- msg.code = IPCP_UNREG;
- msg.difs = difs;
- msg.difs_size = difs_size;
+ msg.code = IPCP_MSG_CODE__IPCP_UNREG;
+ msg.dif_name = difs;
+ msg.n_dif_name = difs_size;
- if (send_ipcp_msg(pid, &msg)) {
- LOG_ERR("Failed to send message to daemon");
+ recv_msg = send_recv_ipcp_msg(pid, &msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_result == false) {
+ ipcp_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ ipcp_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
int ipcp_bootstrap(pid_t pid,
- struct dif_config conf)
+ struct dif_config * conf)
{
- struct ipcp_msg msg;
+ ipcp_msg_t msg = IPCP_MSG__INIT;
+ ipcp_msg_t * recv_msg = NULL;
+ int ret = -1;
- msg.code = IPCP_BOOTSTRAP;
- msg.conf = &conf;
+ msg.code = IPCP_MSG_CODE__IPCP_BOOTSTRAP;
- if (send_ipcp_msg(pid, &msg)) {
- LOG_ERR("Failed to send message to daemon");
+ recv_msg = send_recv_ipcp_msg(pid, &msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_result == false) {
+ ipcp_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ ipcp_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
int ipcp_enroll(pid_t pid,
- char * dif_name,
char * member_name,
- char ** n_1_difs,
- ssize_t n_1_difs_size)
+ char * n_1_dif)
{
- struct ipcp_msg msg;
+ ipcp_msg_t msg = IPCP_MSG__INIT;
+ ipcp_msg_t * recv_msg = NULL;
+ int ret = -1;
+
+ if (n_1_dif == NULL || member_name == NULL)
+ return -EINVAL;
- if (n_1_difs == NULL)
+ msg.code = IPCP_MSG_CODE__IPCP_ENROLL;
+ msg.dif_name = malloc(sizeof(*(msg.dif_name)));
+ if (msg.dif_name == NULL) {
+ LOG_ERR("Failed to malloc");
return -1;
+ }
+ msg.dif_name[0] = n_1_dif;
+ msg.ap_name = member_name;
- if (dif_name == NULL)
+ recv_msg = send_recv_ipcp_msg(pid, &msg);
+ if (recv_msg == NULL) {
+ free(msg.dif_name);
return -1;
+ }
- msg.code = IPCP_ENROLL;
- msg.dif_name = dif_name;
- msg.ap_name = member_name;
- msg.difs = n_1_difs;
- msg.difs_size = n_1_difs_size;
+ if (recv_msg->has_result == false) {
+ ipcp_msg__free_unpacked(recv_msg, NULL);
+ free(msg.dif_name);
+ return -1;
+ }
+
+ ret = recv_msg->result;
+ ipcp_msg__free_unpacked(recv_msg, NULL);
+ free(msg.dif_name);
+
+ return ret;
+}
+
+int ipcp_ap_reg(pid_t pid,
+ uint32_t reg_api_id,
+ char * ap_name)
+{
+ ipcp_msg_t msg = IPCP_MSG__INIT;
+ ipcp_msg_t * recv_msg = NULL;
+ int ret = -1;
- if (send_ipcp_msg(pid, &msg)) {
- LOG_ERR("Failed to send message to daemon");
+ if (ap_name == NULL)
+ return -1;
+
+ msg.code = IPCP_MSG_CODE__IPCP_AP_REG;
+ msg.ap_name = ap_name;
+ msg.has_port_id = true;
+ msg.port_id = reg_api_id;
+
+ recv_msg = send_recv_ipcp_msg(pid, &msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_result == false) {
+ ipcp_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ ipcp_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
+}
+
+int ipcp_ap_unreg(pid_t pid,
+ uint32_t reg_api_id)
+{
+ ipcp_msg_t msg = IPCP_MSG__INIT;
+ ipcp_msg_t * recv_msg = NULL;
+ int ret = -1;
+
+ msg.code = IPCP_MSG_CODE__IPCP_AP_UNREG;
+ msg.has_port_id = true;
+ msg.port_id = reg_api_id;
+
+ recv_msg = send_recv_ipcp_msg(pid, &msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_result == false) {
+ ipcp_msg__free_unpacked(recv_msg, NULL);
+ return -1;
+ }
+
+ ret = recv_msg->result;
+ ipcp_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
+}
+
+int ipcp_flow_alloc(pid_t pid,
+ uint32_t port_id,
+ char * dst_ap_name,
+ char * src_ap_name,
+ char * src_ae_name,
+ struct qos_spec * qos)
+{
+ ipcp_msg_t msg = IPCP_MSG__INIT;
+ ipcp_msg_t * recv_msg = NULL;
+ int ret = -1;
+
+ if (dst_ap_name == NULL || src_ap_name == NULL || src_ae_name == NULL)
+ return -EINVAL;
+
+ msg.code = IPCP_MSG_CODE__IPCP_FLOW_ALLOC;
+ msg.ap_name = src_ap_name;
+ msg.ae_name = src_ae_name;
+ msg.dst_ap_name = dst_ap_name;
+ msg.has_port_id = true;
+ msg.port_id = port_id;
+
+ recv_msg = send_recv_ipcp_msg(pid, &msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_result == false) {
+ ipcp_msg__free_unpacked(recv_msg, NULL);
+ return -1;
+ }
+
+ ret = recv_msg->result;
+ ipcp_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
+}
+
+int ipcp_flow_alloc_resp(pid_t pid,
+ uint32_t port_id,
+ int result)
+{
+ ipcp_msg_t msg = IPCP_MSG__INIT;
+ ipcp_msg_t * recv_msg = NULL;
+ int ret = -1;
+
+ msg.code = IPCP_MSG_CODE__IPCP_FLOW_ALLOC_RESP;
+ msg.has_port_id = true;
+ msg.port_id = port_id;
+ msg.has_result = true;
+ msg.result = result;
+
+ recv_msg = send_recv_ipcp_msg(pid, &msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_result == false) {
+ ipcp_msg__free_unpacked(recv_msg, NULL);
+ return -1;
+ }
+
+ ret = recv_msg->result;
+ ipcp_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
+}
+
+int ipcp_flow_req_arr(pid_t pid,
+ uint32_t reg_api_id,
+ char * ap_name,
+ char * ae_name)
+{
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int fd = -1;
+
+ if (ap_name == NULL || ae_name == NULL)
+ return -EINVAL;
+
+ msg.code = IRM_MSG_CODE__IPCP_FLOW_REQ_ARR;
+ msg.ap_name = ap_name;
+ msg.ae_name = ae_name;
+ msg.port_id = reg_api_id;
+ msg.has_port_id = true;
+ msg.pid = pid;
+ msg.has_pid = true;
+
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_fd == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
+ return -1;
+ }
+
+ fd = recv_msg->fd;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return fd;
+}
+
+int ipcp_flow_alloc_reply(pid_t pid,
+ uint32_t port_id,
+ int result)
+{
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
+
+ msg.code = IRM_MSG_CODE__IPCP_FLOW_ALLOC_REPLY;
+ msg.port_id = port_id;
+ msg.has_port_id = true;
+ msg.result = result;
+ msg.has_result = true;
+
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
+ return -1;
+ }
+
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
+}
+
+
+int ipcp_flow_dealloc(pid_t pid,
+ uint32_t port_id)
+{
+ if (pid != 0) {
+ ipcp_msg_t msg = IPCP_MSG__INIT;
+ ipcp_msg_t * recv_msg = NULL;
+ int ret = -1;
+
+ msg.code = IPCP_MSG_CODE__IPCP_FLOW_DEALLOC;
+ msg.has_port_id = true;
+ msg.port_id = port_id;
+
+ recv_msg = send_recv_ipcp_msg(pid, &msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_result == false) {
+ ipcp_msg__free_unpacked(recv_msg, NULL);
+ return -1;
+ }
+
+ ret = recv_msg->result;
+ ipcp_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
+ } else {
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
+
+ msg.code = IRM_MSG_CODE__IPCP_FLOW_DEALLOC;
+ msg.has_port_id = true;
+ msg.port_id = port_id;
+
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
+ return -1;
+ }
+
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
+ }
}
diff --git a/src/lib/ipcpd_messages.proto b/src/lib/ipcpd_messages.proto
new file mode 100644
index 00000000..bcdd54ae
--- /dev/null
+++ b/src/lib/ipcpd_messages.proto
@@ -0,0 +1,23 @@
+enum ipcp_msg_code {
+ IPCP_BOOTSTRAP = 1;
+ IPCP_ENROLL = 2;
+ IPCP_REG = 3;
+ IPCP_UNREG = 4;
+ IPCP_AP_REG = 5;
+ IPCP_AP_UNREG = 6;
+ IPCP_FLOW_ALLOC = 7;
+ IPCP_FLOW_ALLOC_RESP = 8;
+ IPCP_FLOW_DEALLOC = 9;
+ IPCP_REPLY = 10;
+};
+
+message ipcp_msg {
+ required ipcp_msg_code code = 1;
+ optional string ap_name = 2;
+ // Missing dif_config field here
+ repeated string dif_name = 4;
+ optional int32 result = 5;
+ optional uint32 port_id = 6;
+ optional string ae_name = 7;
+ optional string dst_ap_name = 8;
+};
diff --git a/src/lib/irm.c b/src/lib/irm.c
index 9fd13d52..7c187be1 100644
--- a/src/lib/irm.c
+++ b/src/lib/irm.c
@@ -26,141 +26,211 @@
#include <ouroboros/common.h>
#include <ouroboros/logs.h>
#include <ouroboros/sockets.h>
+#include <ouroboros/instance_name.h>
+
#include <stdlib.h>
-int irm_create_ipcp(rina_name_t name,
- char * ipcp_type)
+int irm_create_ipcp(instance_name_t * api,
+ char * ipcp_type)
{
- struct irm_msg msg;
-
- if (ipcp_type == NULL)
- return -1;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
- if (!name_is_ok(&name)) {
- LOG_ERR("Bad name");
- return -1;
- }
+ if (api == NULL || ipcp_type == NULL || api->name == NULL)
+ return -EINVAL;
- msg.code = IRM_CREATE_IPCP;
- msg.name = &name;
+ msg.code = IRM_MSG_CODE__IRM_CREATE_IPCP;
+ msg.ap_name = api->name;
+ msg.has_api_id = true;
+ msg.api_id = api->id;
msg.ipcp_type = ipcp_type;
- if (send_irmd_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
-int irm_destroy_ipcp(rina_name_t name)
+int irm_destroy_ipcp(instance_name_t * api)
{
- struct irm_msg msg;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
- if (!name_is_ok(&name)) {
- LOG_ERR("Bad name");
- return -1;
- }
+ if (api == NULL || api->name == NULL)
+ return -EINVAL;
- msg.code = IRM_DESTROY_IPCP;
- msg.name = &name;
+ msg.code = IRM_MSG_CODE__IRM_DESTROY_IPCP;
+ msg.ap_name = api->name;
+ msg.has_api_id = true;
+ msg.api_id = api->id;
+
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
- if (send_irmd_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
-int irm_bootstrap_ipcp(rina_name_t name,
- struct dif_config conf)
+int irm_bootstrap_ipcp(instance_name_t * api,
+ struct dif_config * conf)
{
- struct irm_msg msg;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
- if (!name_is_ok(&name)) {
- LOG_ERR("Bad name");
- return -1;
- }
+ if (api == NULL || api->name == NULL || conf == NULL)
+ return -EINVAL;
+
+ msg.code = IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP;
+ msg.ap_name = api->name;
+ msg.has_api_id = true;
+ msg.api_id = api->id;
- msg.code = IRM_BOOTSTRAP_IPCP;
- msg.name = &name;
- msg.conf = &conf;
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
- if (send_irmd_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
-int irm_enroll_ipcp(rina_name_t name,
- char * dif_name)
+int irm_enroll_ipcp(instance_name_t * api,
+ char * dif_name)
{
- struct irm_msg msg;
-
- if (!name_is_ok(&name)) {
- LOG_ERR("Bad name");
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
+
+ if (api == NULL || api->name == NULL || dif_name == NULL)
+ return -EINVAL;
+
+ msg.code = IRM_MSG_CODE__IRM_ENROLL_IPCP;
+ msg.ap_name = api->name;
+ msg.has_api_id = true;
+ msg.api_id = api->id;
+ msg.n_dif_name = 1;
+ msg.dif_name = malloc(sizeof(*(msg.dif_name)));
+ if (msg.dif_name == NULL) {
+ LOG_ERR("Failed to malloc");
return -1;
}
+ msg.dif_name[0] = dif_name;
- msg.code = IRM_ENROLL_IPCP;
- msg.name = &name;
- msg.dif_name = dif_name;
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL) {
+ free(msg.dif_name);
+ return -1;
+ }
- if (send_irmd_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ free(msg.dif_name);
+ return ret;
}
-int irm_reg_ipcp(rina_name_t name,
- char ** difs,
- size_t difs_size)
+int irm_reg_ipcp(instance_name_t * api,
+ char ** difs,
+ size_t difs_size)
{
- struct irm_msg msg;
-
- if (!name_is_ok(&name)) {
- LOG_ERR("Bad name");
- return -1;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
+
+ if (api->name == NULL ||
+ difs == NULL ||
+ difs_size == 0 ||
+ difs[0] == NULL) {
+ return -EINVAL;
}
- msg.code = IRM_REG_IPCP;
- msg.name = &name;
- msg.difs = difs;
- msg.difs_size = difs_size;
+ msg.code = IRM_MSG_CODE__IRM_REG_IPCP;
+ msg.ap_name = api->name;
+ msg.has_api_id = true;
+ msg.api_id = api->id;
+ msg.dif_name = difs;
+ msg.n_dif_name = difs_size;
- if (send_irmd_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
-int irm_unreg_ipcp(rina_name_t name,
- char ** difs,
- size_t difs_size)
+int irm_unreg_ipcp(const instance_name_t * api,
+ char ** difs,
+ size_t difs_size)
{
- struct irm_msg msg;
-
- if (!name_is_ok(&name)) {
- LOG_ERR("Bad name");
- return -1;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
+
+ if (api == NULL ||
+ api->name == NULL ||
+ difs == NULL ||
+ difs_size == 0 ||
+ difs[0] == NULL) {
+ return -EINVAL;
}
- msg.code = IRM_UNREG_IPCP;
- msg.name = &name;
- msg.difs = difs;
- msg.difs_size = difs_size;
+ msg.code = IRM_MSG_CODE__IRM_UNREG_IPCP;
+ msg.ap_name = api->name;
+ msg.has_api_id = true;
+ msg.api_id = api->id;
+ msg.dif_name = difs;
+ msg.n_dif_name = difs_size;
+
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL)
+ return -1;
- if (send_irmd_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ if (recv_msg->has_result == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
diff --git a/src/lib/irmd_messages.proto b/src/lib/irmd_messages.proto
new file mode 100644
index 00000000..44070755
--- /dev/null
+++ b/src/lib/irmd_messages.proto
@@ -0,0 +1,39 @@
+enum irm_msg_code {
+ IRM_CREATE_IPCP = 1;
+ IRM_DESTROY_IPCP = 2;
+ IRM_BOOTSTRAP_IPCP = 3;
+ IRM_ENROLL_IPCP = 4;
+ IRM_REG_IPCP = 5;
+ IRM_UNREG_IPCP = 6;
+ IRM_AP_REG = 7;
+ IRM_AP_UNREG = 8;
+ IRM_FLOW_ACCEPT = 9;
+ IRM_FLOW_ALLOC_RESP = 10;
+ IRM_FLOW_ALLOC = 11;
+ IRM_FLOW_ALLOC_RES = 12;
+ IRM_FLOW_DEALLOC = 13;
+ IRM_FLOW_CONTROL = 14;
+ IRM_FLOW_WRITE = 15;
+ IRM_FLOW_READ = 16;
+ IPCP_FLOW_REQ_ARR = 17;
+ IPCP_FLOW_ALLOC_REPLY = 18;
+ IPCP_FLOW_DEALLOC = 19;
+ IRM_REPLY = 20;
+};
+
+message irm_msg {
+ required irm_msg_code code = 1;
+ optional string ap_name = 2;
+ optional uint32 api_id = 3;
+ optional string ae_name = 4;
+ optional string ipcp_type = 5;
+ // Missing dif_config field here
+ repeated string dif_name = 7;
+ optional int32 fd = 8;
+ optional int32 result = 9;
+ // Missing qos_spec here
+ optional int32 oflags = 10;
+ optional string dst_ap_name = 11;
+ optional uint32 port_id = 12;
+ optional int32 pid = 13;
+};
diff --git a/src/lib/sockets.c b/src/lib/sockets.c
index b157b628..f9024f70 100644
--- a/src/lib/sockets.c
+++ b/src/lib/sockets.c
@@ -96,76 +96,58 @@ int server_socket_open(char * file_name)
return sockfd;
}
-int send_irmd_msg(struct irm_msg * msg)
-{
- int sockfd;
- buffer_t * buf;
-
- sockfd = client_socket_open(IRM_SOCK_PATH);
- if (sockfd < 0)
- return -1;
-
- buf = serialize_irm_msg(msg);
- if (buf == NULL) {
- close(sockfd);
- return -1;
- }
-
- if (write(sockfd, buf->data, buf->size) == -1) {
- free(buf->data);
- free(buf);
- close(sockfd);
- return -1;
- }
-
- free(buf->data);
- free(buf);
-
- close(sockfd);
- return 0;
-}
-
-struct irm_msg * send_recv_irmd_msg(struct irm_msg * msg)
+irm_msg_t * send_recv_irm_msg(irm_msg_t * msg)
{
int sockfd;
- buffer_t * buf;
+ buffer_t buf;
ssize_t count = 0;
- struct irm_msg * recv_msg = NULL;
+ irm_msg_t * recv_msg = NULL;
sockfd = client_socket_open(IRM_SOCK_PATH);
if (sockfd < 0)
return NULL;
- buf = serialize_irm_msg(msg);
- if (buf == NULL) {
+ buf.size = irm_msg__get_packed_size(msg);
+ if (buf.size == 0) {
close(sockfd);
return NULL;
}
- if (write(sockfd, buf->data, buf->size) == -1) {
- free(buf->data);
- free(buf);
+ LOG_DBG("Size will be %lu", buf.size);
+ buf.data = malloc(buf.size);
+ if (buf.data == NULL) {
close(sockfd);
return NULL;
}
- count = read(sockfd, buf->data, IRM_MSG_BUF_SIZE);
- if (count <= 0) {
- free(buf->data);
- free(buf);
+ irm_msg__pack(msg, buf.data);
+
+ if (write(sockfd, buf.data, buf.size) == -1) {
+ free(buf.data);
close(sockfd);
return NULL;
}
- recv_msg = deserialize_irm_msg(buf);
+ count = read(sockfd, buf.data, IRM_MSG_BUF_SIZE);
+ if (count <= 0) {
+ free(buf.data);
+ close(sockfd);
+ return NULL;
+ }
- free(buf->data);
- free(buf);
+ recv_msg = irm_msg__unpack(NULL, count, buf.data);
+ if (recv_msg == NULL) {
+ free(buf.data);
+ close(sockfd);
+ return NULL;
+ }
+ free(buf.data);
close(sockfd);
return recv_msg;
}
+
char * ipcp_sock_path(pid_t pid)
{
char * full_name = NULL;
@@ -196,611 +178,3 @@ char * ipcp_sock_path(pid_t pid)
return full_name;
}
-
-static int serialized_string_len(uint8_t * data)
-{
- uint8_t * seek = data;
-
- while (*seek != '\0')
- seek++;
-
- return (seek - data) + 1;
-}
-
-static void ser_copy_value(size_t flen,
- void * dst,
- void * src,
- int * offset)
-{
- memcpy(dst + *offset, src, flen);
- *offset += flen;
-}
-
-static void ser_copy_name(rina_name_t * name,
- uint8_t * data,
- int * offset)
-{
- ser_copy_value(strlen(name->ap_name) + 1,
- data, name->ap_name, offset);
- ser_copy_value(sizeof(int), data,
- &name->api_id, offset);
-}
-
-static void deser_copy_value(size_t flen,
- void * dst,
- void * src,
- int * offset)
-{
- memcpy(dst, src + *offset, flen);
- *offset += flen;
-}
-
-static int deser_copy_string(uint8_t * data,
- char ** dst,
- int * offset)
-{
- size_t flen;
-
- flen = serialized_string_len(data + *offset);
- *dst = malloc(sizeof(**dst) * (flen + 1));
- if (*dst == NULL)
- return -1;
- deser_copy_value(flen, *dst, data, offset);
- return 0;
-}
-
-static void deser_copy_int(uint8_t * data,
- unsigned int * dst,
- int * offset)
-{
- *dst = 0;
- deser_copy_value(sizeof(int), dst, data, offset);
-}
-
-static void deser_copy_size_t(uint8_t * data,
- size_t * dst,
- int * offset)
-{
- *dst = 0;
- deser_copy_value(sizeof(size_t), dst, data, offset);
-}
-
-static rina_name_t * deser_copy_name(uint8_t * data,
- int * offset)
-{
- rina_name_t * name;
-
- name = name_create();
- if (name == NULL) {
- LOG_ERR("Failed to alloc memory");
- return NULL;
- }
-
- if (deser_copy_string(data, &name->ap_name, offset)) {
- name_destroy(name);
- return NULL;
- }
-
- deser_copy_int(data, &name->api_id, offset);
-
- return name;
-}
-
-
-/* Move these to a separate file? */
-static buffer_t * buffer_create()
-{
- buffer_t * buf;
-
- buf = malloc(sizeof(*buf));
- if (buf == NULL)
- return NULL;
-
- buf->data = malloc(IRM_MSG_BUF_SIZE);
- if (buf->data == NULL) {
- free(buf);
- return NULL;
- }
-
- return buf;
-}
-
-static void buffer_destroy(buffer_t * buf)
-{
- if (buf->data != NULL)
- free(buf->data);
-
- if (buf != NULL)
- free(buf);
-}
-
-buffer_t * serialize_irm_msg(struct irm_msg * msg)
-{
- buffer_t * buf;
- uint8_t * data;
- int offset = 0;
- int i;
- char ** pos;
-
- if (msg == NULL)
- return NULL;
-
- buf = buffer_create();
- if (buf == NULL)
- return NULL;
-
- data = buf->data;
-
- ser_copy_value(sizeof(enum irm_msg_code), data, &msg->code, &offset);
-
- ser_copy_name(msg->name, data, &offset);
-
- switch (msg->code) {
- case IRM_CREATE_IPCP:
- if (msg->ipcp_type == NULL ||
- !name_is_ok(msg->name)) {
- LOG_ERR("Null pointer passed");
- buffer_destroy(buf);
- return NULL;
- }
- ser_copy_name(msg->name, data, &offset);
- ser_copy_value(strlen(msg->ipcp_type) + 1, data,
- msg->ipcp_type, &offset);
- break;
- case IRM_DESTROY_IPCP:
- if (!name_is_ok(msg->name)) {
- LOG_ERR("Null pointer passed");
- buffer_destroy(buf);
- return NULL;
- }
- ser_copy_name(msg->name, data, &offset);
- break;
- case IRM_BOOTSTRAP_IPCP:
- if (!name_is_ok(msg->name)) {
- LOG_ERR("Null pointer passed");
- buffer_destroy(buf);
- return NULL;
- }
- ser_copy_name(msg->name, data, &offset);
- /* FIXME: Fields missing, need to define dif_conf properly */
- break;
- case IRM_ENROLL_IPCP:
- if (msg->dif_name == NULL ||
- !name_is_ok(msg->name)) {
- buffer_destroy(buf);
- return NULL;
- }
-
- ser_copy_name(msg->name, data, &offset);
- ser_copy_value(strlen(msg->dif_name) + 1, data,
- msg->dif_name, &offset);
-
- break;
- case IRM_REG_IPCP:
- case IRM_UNREG_IPCP:
- if (msg->difs == NULL ||
- msg->difs[0] == NULL ||
- !name_is_ok(msg->name)) {
- buffer_destroy(buf);
- return NULL;
- }
-
- ser_copy_name(msg->name, data, &offset);
-
- ser_copy_value(sizeof(size_t), data, &msg->difs_size, &offset);
-
- pos = msg->difs;
- for (i = 0; i < msg->difs_size; i++) {
- ser_copy_value(strlen(*pos) + 1, data, *pos, &offset);
- pos++;
- }
-
- break;
- case IRM_AP_REG:
- case IRM_AP_UNREG:
- if (msg->ap_name == NULL ||
- msg->difs == NULL ||
- msg->difs[0] == NULL) {
- LOG_ERR("Invalid arguments");
- buffer_destroy(buf);
- return NULL;
- }
-
- ser_copy_value(strlen(msg->ap_name) + 1,
- data, msg->ap_name, &offset);
-
- ser_copy_value(sizeof(size_t), data, &msg->difs_size, &offset);
-
- pos = msg->difs;
- for (i = 0; i < msg->difs_size; i++) {
- ser_copy_value(strlen(*pos) + 1, data, *pos, &offset);
- pos++;
- }
-
- break;
- case IRM_FLOW_ACCEPT:
- if (msg->ap_name == NULL ||
- msg->ae_name == NULL) {
- LOG_ERR("Invalid arguments");
- buffer_destroy(buf);
- return NULL;
- }
-
- ser_copy_value(sizeof(int), data, &msg->fd, &offset);
-
- ser_copy_value(strlen(msg->ap_name) + 1,
- data, msg->ap_name, &offset);
-
- ser_copy_value(strlen(msg->ae_name) + 1,
- data, msg->ae_name, &offset);
-
- break;
- case IRM_FLOW_ALLOC_RESP:
- ser_copy_value(sizeof(int), data, &msg->fd, &offset);
-
- ser_copy_value(sizeof(int), data, &msg->result, &offset);
-
- break;
- case IRM_FLOW_ALLOC:
- if (msg->ap_name == NULL ||
- msg->ae_name == NULL ||
- msg->dst_ap_name == NULL ||
- msg->qos == NULL) {
- LOG_ERR("Invalid arguments");
- buffer_destroy(buf);
- return NULL;
- }
-
- ser_copy_value(strlen(msg->dst_ap_name) + 1,
- data, msg->dst_ap_name, &offset);
-
- ser_copy_value(strlen(msg->ap_name) + 1,
- data, msg->ap_name, &offset);
-
- ser_copy_value(strlen(msg->ae_name) + 1,
- data, msg->ae_name, &offset);
-
- /* FIXME: Serialize qos spec here */
-
- ser_copy_value(sizeof(int), data, &msg->oflags, &offset);
-
- break;
- case IRM_FLOW_ALLOC_RES:
- case IRM_FLOW_DEALLOC:
- ser_copy_value(sizeof(int), data, &msg->fd, &offset);
- break;
- case IRM_FLOW_CONTROL:
- ser_copy_value(sizeof(int), data, &msg->fd, &offset);
- ser_copy_value(sizeof(int), data, &msg->oflags, &offset);
- break;
- case IRM_FLOW_WRITE:
- LOG_MISSING;
- break;
- case IRM_FLOW_READ:
- LOG_MISSING;
- break;
- case IRM_AP_REG_R:
- case IRM_FLOW_ALLOC_R:
- ser_copy_value(sizeof(int), data, &msg->fd, &offset);
- break;
- case IRM_FLOW_ACCEPT_R:
- ser_copy_value(sizeof(int), data, &msg->fd, &offset);
-
- ser_copy_value(strlen(msg->ap_name) + 1,
- data, msg->ap_name, &offset);
-
- ser_copy_value(strlen(msg->ae_name) + 1,
- data, msg->ae_name, &offset);
- break;
- case IRM_FLOW_ALLOC_RES_R:
- ser_copy_value(sizeof(int), data, &msg->result, &offset);
- break;
- default:
- LOG_ERR("Don't know that code");
- buffer_destroy(buf);
- return NULL;
- }
-
- buf->size = offset;
-
- return buf;
-}
-
-struct irm_msg * deserialize_irm_msg(buffer_t * data)
-{
- struct irm_msg * msg;
- int i, j;
- int offset = 0;
- size_t difs_size;
-
- if (data == NULL || data->data == NULL) {
- LOG_ERR("Got a null pointer");
- return NULL;
- }
-
- msg = malloc(sizeof(*msg));
- if (msg == NULL) {
- LOG_ERR("Failed to allocate memory");
- return NULL;
- }
-
- deser_copy_value(sizeof(enum irm_msg_code),
- &msg->code, data->data, &offset);
-
- switch (msg->code) {
- case IRM_CREATE_IPCP:
- msg->name = deser_copy_name(data->data, &offset);
- if (msg->name == NULL) {
- LOG_ERR("Failed to reconstruct name");
- free(msg);
- return NULL;
- }
-
- if (deser_copy_string(data->data,
- &msg->ipcp_type,
- &offset)) {
- name_destroy(msg->name);
- free(msg);
- return NULL;
- }
-
- break;
- case IRM_DESTROY_IPCP:
- msg->name = deser_copy_name(data->data, &offset);
- if (msg->name == NULL) {
- LOG_ERR("Failed to reconstruct name");
- free(msg);
- return NULL;
- }
-
- break;
- case IRM_BOOTSTRAP_IPCP:
- msg->name = deser_copy_name(data->data, &offset);
- if (msg->name == NULL) {
- LOG_ERR("Failed to reconstruct name");
- free(msg);
- return NULL;
- }
-
- break;
- case IRM_ENROLL_IPCP:
- msg->name = deser_copy_name(data->data, &offset);
- if (msg->name == NULL) {
- LOG_ERR("Failed to reconstruct name");
- free(msg);
- return NULL;
- }
-
- if (deser_copy_string(data->data,
- &msg->dif_name,
- &offset)) {
- name_destroy(msg->name);
- free(msg);
- return NULL;
- }
-
- break;
- case IRM_REG_IPCP:
- case IRM_UNREG_IPCP:
- msg->name = deser_copy_name(data->data, &offset);
- if (msg->name == NULL) {
- LOG_ERR("Failed to reconstruct name");
- free(msg);
- return NULL;
- }
-
- deser_copy_size_t(data->data, &difs_size, &offset);
- msg->difs_size = difs_size;
-
- msg->difs = malloc(sizeof(*(msg->difs)) * difs_size);
- if (msg->difs == NULL) {
- name_destroy(msg->name);
- free(msg);
- return NULL;
- }
-
- for (i = 0; i < difs_size; i++) {
- if (deser_copy_string(data->data,
- &msg->difs[i],
- &offset)) {
- for (j = 0; j < i; j++)
- free(msg->difs[j]);
- free(msg->difs);
- name_destroy(msg->name);
- free(msg);
- return NULL;
- }
- }
-
- break;
- case IRM_AP_REG:
- case IRM_AP_REG_R:
- case IRM_AP_UNREG:
- case IRM_FLOW_ACCEPT:
- case IRM_FLOW_ACCEPT_R:
- case IRM_FLOW_ALLOC_RESP:
- case IRM_FLOW_ALLOC:
- case IRM_FLOW_ALLOC_R:
- case IRM_FLOW_ALLOC_RES:
- case IRM_FLOW_ALLOC_RES_R:
- case IRM_FLOW_DEALLOC:
- case IRM_FLOW_CONTROL:
- case IRM_FLOW_WRITE:
- case IRM_FLOW_READ:
- LOG_MISSING;
- break;
- default:
- LOG_ERR("Don't know that code");
- free(msg);
- return NULL;
- }
-
- return msg;
-}
-
-buffer_t * serialize_ipcp_msg(struct ipcp_msg * msg)
-{
- buffer_t * buf = NULL;
- uint8_t * data = NULL;
- int offset = 0;
- char ** pos = NULL;
- int i = 0;
-
- if (msg == NULL)
- return NULL;
-
- buf = buffer_create();
- if (buf == NULL)
- return NULL;
-
- data = buf->data;
-
- ser_copy_value(sizeof(enum ipcp_msg_code),
- data, &msg->code, &offset);
-
- switch (msg->code) {
- case IPCP_BOOTSTRAP:
- break;
- case IPCP_ENROLL:
- if (msg->dif_name == NULL) {
- buffer_destroy(buf);
- return NULL;
- }
-
- ser_copy_value(strlen(msg->dif_name) + 1, data,
- msg->dif_name, &offset);
-
- if (msg->ap_name == NULL) {
- LOG_ERR("Null pointer passed");
- buffer_destroy(buf);
- return NULL;
- }
- ser_copy_value(strlen(msg->ap_name) + 1, data,
- msg->ap_name, &offset);
-
- /* All these operations end with a list of DIFs */
- case IPCP_REG:
- case IPCP_UNREG:
- if (msg->difs == NULL || msg->difs[0] == NULL) {
- buffer_destroy(buf);
- return NULL;
- }
-
- ser_copy_value(sizeof(size_t), data, &msg->difs_size, &offset);
-
- pos = msg->difs;
- for (i = 0; i < msg->difs_size; i++) {
- ser_copy_value(strlen(*pos) + 1, data, *pos, &offset);
- pos++;
- }
- break;
- default:
- LOG_ERR("Don't know that code");
- buffer_destroy(buf);
- return NULL;
- }
-
- buf->size = offset;
-
- return buf;
-}
-
-struct ipcp_msg * deserialize_ipcp_msg(buffer_t * data)
-{
- struct ipcp_msg * msg;
- int i, j;
- int offset = 0;
- size_t difs_size;
-
- if (data == NULL || data->data == NULL) {
- LOG_ERR("Got a null pointer");
- return NULL;
- }
-
- msg = malloc(sizeof(*msg));
- if (msg == NULL) {
- LOG_ERR("Failed to allocate memory");
- return NULL;
- }
-
- deser_copy_value(sizeof(enum ipcp_msg_code),
- &msg->code, data->data, &offset);
-
- switch (msg->code) {
- case IPCP_BOOTSTRAP:
- break;
- case IPCP_ENROLL:
- if (deser_copy_string(data->data,
- &msg->dif_name,
- &offset)) {
- free(msg);
- return NULL;
- }
-
- deser_copy_string(data->data,
- &msg->ap_name,
- &offset);
- if (msg->ap_name == NULL) {
- LOG_ERR("Failed to reconstruct name");
- free(msg->dif_name);
- free(msg);
- return NULL;
- }
-
- deser_copy_size_t(data->data, &difs_size, &offset);
- msg->difs_size = difs_size;
-
- msg->difs = malloc(sizeof(*(msg->difs)) * difs_size);
- if (msg->difs == NULL) {
- free(msg->ap_name);
- free(msg->dif_name);
- free(msg);
- return NULL;
- }
-
- for (i = 0; i < difs_size; i++) {
- if (deser_copy_string(data->data,
- &msg->difs[i],
- &offset)) {
- for (j = 0; j < i; j++)
- free(msg->difs[j]);
- free(msg->dif_name);
- free(msg->difs);
- free(msg->ap_name);
- free(msg);
- return NULL;
- }
- }
- break;
- case IPCP_REG:
- case IPCP_UNREG:
- deser_copy_size_t(data->data, &difs_size, &offset);
- msg->difs_size = difs_size;
-
- msg->difs = malloc(sizeof(*(msg->difs)) * difs_size);
- if (msg->difs == NULL) {
- free(msg);
- return NULL;
- }
-
- for (i = 0; i < difs_size; i++) {
- if (deser_copy_string(data->data,
- &msg->difs[i],
- &offset)) {
- for (j = 0; j < i; j++)
- free(msg->difs[j]);
- free(msg->difs);
- free(msg);
- return NULL;
- }
- }
-
- break;
- default:
- LOG_ERR("Don't know that code");
- free(msg);
- return NULL;
- }
-
- return msg;
-}
diff --git a/src/lib/tests/shm_du_map_test.c b/src/lib/tests/shm_du_map_test.c
index f636c941..85a82e4d 100644
--- a/src/lib/tests/shm_du_map_test.c
+++ b/src/lib/tests/shm_du_map_test.c
@@ -20,6 +20,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <ouroboros/config.h>
#include <ouroboros/shm_du_map.h>
#include <sys/types.h>
#include <stdlib.h>
diff --git a/src/tools/echo/echo_client.c b/src/tools/echo/echo_client.c
index 196296f2..8d3fc322 100644
--- a/src/tools/echo/echo_client.c
+++ b/src/tools/echo/echo_client.c
@@ -23,7 +23,6 @@
#define CLIENT_AP_NAME "echo-client"
#include <ouroboros/dev.h>
-#include <ouroboros/rina_name.h>
int client_main()
{
diff --git a/src/tools/echo/echo_server.c b/src/tools/echo/echo_server.c
index 289f537a..b1547d8c 100644
--- a/src/tools/echo/echo_server.c
+++ b/src/tools/echo/echo_server.c
@@ -26,7 +26,6 @@
#include <stdlib.h>
#include <ouroboros/dev.h>
-#include <ouroboros/rina_name.h>
#define DIF_NAME "*"
diff --git a/src/tools/irm/irm.c b/src/tools/irm/irm.c
index 895d52c2..d05e083e 100644
--- a/src/tools/irm/irm.c
+++ b/src/tools/irm/irm.c
@@ -21,7 +21,7 @@
*/
#include <ouroboros/common.h>
-#include <ouroboros/rina_name.h>
+#include <ouroboros/instance_name.h>
#include <ouroboros/irm.h>
#include <stdio.h>
#include <string.h>
diff --git a/src/tools/irm/irm_bootstrap_ipcp.c b/src/tools/irm/irm_bootstrap_ipcp.c
index 89950069..c7b82c4a 100644
--- a/src/tools/irm/irm_bootstrap_ipcp.c
+++ b/src/tools/irm/irm_bootstrap_ipcp.c
@@ -21,6 +21,7 @@
*/
#include <stdio.h>
+#include <stdlib.h>
#include <ouroboros/irm.h>
#include <ouroboros/common.h>
@@ -38,29 +39,31 @@ static void usage()
int do_bootstrap_ipcp(int argc, char ** argv)
{
- rina_name_t name;
+ instance_name_t api = {NULL, 0};
struct dif_config conf;
conf.qosspecs = NULL;
- name.ap_name = NULL;
- name.api_id = 0;
-
while (argc > 0) {
- if (!parse_name(argv, &name)) {
+ if (matches(*argv, "ap") == 0) {
+ api.name = *(argv + 1);
+ } else if (matches(*argv, "api") == 0) {
+ api.id = atoi(*(argv + 1));
+ } else {
printf("\"%s\" is unknown, try \"irm "
- "enroll_ipcp\".\n", *argv);
+ "destroy_ipcp\".\n", *argv);
return -1;
}
+
argc -= 2;
argv += 2;
}
- if (name.ap_name == NULL) {
+ if (api.name == NULL) {
usage();
return -1;
}
- return irm_bootstrap_ipcp(name, conf);
+ return irm_bootstrap_ipcp(&api, &conf);
}
diff --git a/src/tools/irm/irm_create_ipcp.c b/src/tools/irm/irm_create_ipcp.c
index 854a15f9..73d20dce 100644
--- a/src/tools/irm/irm_create_ipcp.c
+++ b/src/tools/irm/irm_create_ipcp.c
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <ouroboros/irm.h>
#include <ouroboros/common.h>
+#include <ouroboros/instance_name.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@@ -40,31 +41,30 @@ static void usage()
int do_create_ipcp(int argc, char ** argv)
{
- rina_name_t name;
char * ipcp_type = NULL;
-
- name.ap_name = NULL;
- name.api_id = 0;
+ instance_name_t api = {NULL, 0};
while (argc > 0) {
- if (!parse_name(argv, &name)) {
- if (matches(*argv, "type") == 0) {
- ipcp_type = *(argv + 1);
- } else {
- printf("\"%s\" is unknown, try \"irm "
- "create_ipcp\".\n", *argv);
- return -1;
- }
+ if (matches(*argv, "type") == 0) {
+ ipcp_type = *(argv + 1);
+ } else if (matches(*argv, "ap") == 0) {
+ api.name = *(argv + 1);
+ } else if (matches(*argv, "api") == 0) {
+ api.id = atoi(*(argv + 1));
+ } else {
+ printf("\"%s\" is unknown, try \"irm "
+ "create_ipcp\".\n", *argv);
+ return -1;
}
argc -= 2;
argv += 2;
}
- if (ipcp_type == NULL || name.ap_name == NULL) {
+ if (ipcp_type == NULL || api.name == NULL) {
usage();
return -1;
}
- return irm_create_ipcp(name, ipcp_type);
+ return irm_create_ipcp(&api, ipcp_type);
}
diff --git a/src/tools/irm/irm_destroy_ipcp.c b/src/tools/irm/irm_destroy_ipcp.c
index 4f02f9cb..fe6ef57e 100644
--- a/src/tools/irm/irm_destroy_ipcp.c
+++ b/src/tools/irm/irm_destroy_ipcp.c
@@ -21,6 +21,7 @@
*/
#include <stdio.h>
+#include <stdlib.h>
#include <ouroboros/irm.h>
#include <ouroboros/common.h>
@@ -36,13 +37,14 @@ static void usage()
int do_destroy_ipcp(int argc, char ** argv)
{
- rina_name_t name;
-
- name.ap_name = NULL;
- name.api_id = 0;
+ instance_name_t api = {NULL, 0};
while (argc > 0) {
- if (!parse_name(argv, &name)) {
+ if (matches(*argv, "ap") == 0) {
+ api.name = *(argv + 1);
+ } else if (matches(*argv, "api") == 0) {
+ api.id = atoi(*(argv + 1));
+ } else {
printf("\"%s\" is unknown, try \"irm "
"destroy_ipcp\".\n", *argv);
return -1;
@@ -52,10 +54,10 @@ int do_destroy_ipcp(int argc, char ** argv)
argv += 2;
}
- if (name.ap_name == NULL) {
+ if (api.name == NULL) {
usage();
return -1;
}
- return irm_destroy_ipcp(name);
+ return irm_destroy_ipcp(&api);
}
diff --git a/src/tools/irm/irm_enroll_ipcp.c b/src/tools/irm/irm_enroll_ipcp.c
index 1dcdc919..5c9572bf 100644
--- a/src/tools/irm/irm_enroll_ipcp.c
+++ b/src/tools/irm/irm_enroll_ipcp.c
@@ -21,6 +21,7 @@
*/
#include <stdio.h>
+#include <stdlib.h>
#include <ouroboros/irm.h>
#include <ouroboros/common.h>
@@ -37,31 +38,30 @@ static void usage()
int do_enroll_ipcp(int argc, char ** argv)
{
- rina_name_t name;
+ instance_name_t api = {NULL, 0};
char * dif_name = NULL;
- name.ap_name = NULL;
- name.api_id = 0;
-
while (argc > 0) {
- if (!parse_name(argv, &name)) {
- if (matches(*argv, "dif") == 0) {
- dif_name = *(argv + 1);
- } else {
- printf("\"%s\" is unknown, try \"irm "
- "enroll_ipcp\".\n", *argv);
- return -1;
- }
+ if (matches(*argv, "ap") == 0) {
+ api.name = *(argv + 1);
+ } else if (matches(*argv, "api") == 0) {
+ api.id = atoi(*(argv + 1));
+ } else if (matches(*argv, "dif") == 0) {
+ dif_name = *(argv + 1);
+ } else {
+ printf("\"%s\" is unknown, try \"irm "
+ "enroll_ipcp\".\n", *argv);
+ return -1;
}
argc -= 2;
argv += 2;
}
- if (dif_name == NULL || name.ap_name == NULL) {
+ if (dif_name == NULL || api.name == NULL) {
usage();
return -1;
}
- return irm_enroll_ipcp(name, dif_name);
+ return irm_enroll_ipcp(&api, dif_name);
}
diff --git a/src/tools/irm/irm_register_ipcp.c b/src/tools/irm/irm_register_ipcp.c
index 468ef28f..f0c1ccff 100644
--- a/src/tools/irm/irm_register_ipcp.c
+++ b/src/tools/irm/irm_register_ipcp.c
@@ -45,36 +45,35 @@ static void usage()
int do_register_ipcp(int argc, char ** argv)
{
- rina_name_t name;
char * difs[MAX_DIFS];
size_t difs_size = 0;
-
- name.ap_name = NULL;
- name.api_id = 0;
+ instance_name_t api = {NULL, 0};
while (argc > 0) {
- if (!parse_name(argv, &name)) {
- if (matches(*argv, "dif") == 0) {
- difs[difs_size++] = *(argv + 1);
- if (difs_size > MAX_DIFS) {
- printf("Too many difs specified\n");
- return -1;
- }
- } else {
- printf("\"%s\" is unknown, try \"irm "
- "register_ipcp\".\n", *argv);
+ if (matches(*argv, "ap") == 0) {
+ api.name = *(argv + 1);
+ } else if (matches(*argv, "api") == 0) {
+ api.id = atoi(*(argv + 1));
+ } else if (matches(*argv, "dif") == 0) {
+ difs[difs_size++] = *(argv + 1);
+ if (difs_size > MAX_DIFS) {
+ printf("Too many difs specified\n");
return -1;
}
+ } else {
+ printf("\"%s\" is unknown, try \"irm "
+ "register_ipcp\".\n", *argv);
+ return -1;
}
argc -= 2;
argv += 2;
}
- if (difs_size == 0 || name.ap_name == NULL) {
+ if (difs_size == 0 || api.name == NULL) {
usage();
return -1;
}
- return irm_reg_ipcp(name, difs, difs_size);
+ return irm_reg_ipcp(&api, difs, difs_size);
}
diff --git a/src/tools/irm/irm_unregister_ipcp.c b/src/tools/irm/irm_unregister_ipcp.c
index 0b669503..3fd6f148 100644
--- a/src/tools/irm/irm_unregister_ipcp.c
+++ b/src/tools/irm/irm_unregister_ipcp.c
@@ -45,36 +45,36 @@ static void usage()
int do_unregister_ipcp(int argc, char ** argv)
{
- rina_name_t name;
+ instance_name_t api = {NULL, 0};
char * difs[MAX_DIFS];
size_t difs_size = 0;
- name.ap_name = NULL;
- name.api_id = 0;
while (argc > 0) {
- if (!parse_name(argv, &name)) {
- if (matches(*argv, "dif") == 0) {
- difs[difs_size++] = *(argv + 1);
- if (difs_size > MAX_DIFS) {
- printf("Too many difs specified\n");
- return -1;
- }
- } else {
- printf("\"%s\" is unknown, try \"irm "
- "unregister_ipcp\".\n", *argv);
+ if (matches(*argv, "ap") == 0) {
+ api.name = *(argv + 1);
+ } else if (matches(*argv, "api") == 0) {
+ api.id = atoi(*(argv + 1));
+ } else if (matches(*argv, "dif") == 0) {
+ difs[difs_size++] = *(argv + 1);
+ if (difs_size > MAX_DIFS) {
+ printf("Too many difs specified\n");
return -1;
}
+ } else {
+ printf("\"%s\" is unknown, try \"irm "
+ "unregister_ipcp\".\n", *argv);
+ return -1;
}
argc -= 2;
argv += 2;
}
- if (difs_size == 0 || name.ap_name == NULL) {
+ if (difs_size == 0 || api.name == NULL) {
usage();
return -1;
}
- return irm_unreg_ipcp(name, difs, difs_size);
+ return irm_unreg_ipcp(&api, difs, difs_size);
}
diff --git a/src/tools/irm/irm_utils.c b/src/tools/irm/irm_utils.c
index 04cb7242..feb8ac98 100644
--- a/src/tools/irm/irm_utils.c
+++ b/src/tools/irm/irm_utils.c
@@ -36,19 +36,3 @@ int matches(const char * cmd, const char * pattern)
return memcmp(pattern, cmd, len);
}
-
-
-bool parse_name(char ** argv,
- rina_name_t * name)
-{
- bool found = true;
-
- if (matches(*argv, "ap") == 0)
- name->ap_name = *(argv + 1);
- else if (matches(*argv, "api") == 0)
- name->api_id = atoi(*(argv + 1));
- else
- found = false;
-
- return found;
-}
diff --git a/src/tools/irm/irm_utils.h b/src/tools/irm/irm_utils.h
index 2a478d09..da2259c6 100644
--- a/src/tools/irm/irm_utils.h
+++ b/src/tools/irm/irm_utils.h
@@ -20,10 +20,4 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include <ouroboros/rina_name.h>
-
-#include <stdbool.h>
-
int matches(const char * cmd, const char * pattern);
-
-bool parse_name(char ** argv, rina_name_t * name);