summaryrefslogtreecommitdiff
path: root/include/ouroboros
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-03-11 16:52:28 +0100
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-03-11 16:52:28 +0100
commitf5cf4e478bf7dec70dc22d80de706f82ef4b38f1 (patch)
tree60160c5cac28eb8cfcd376428429e03cf2e7e203 /include/ouroboros
parentd68e4e5e540720d9b02e2062e3982f1c438eb1e0 (diff)
downloadouroboros-f5cf4e478bf7dec70dc22d80de706f82ef4b38f1.tar.gz
ouroboros-f5cf4e478bf7dec70dc22d80de706f82ef4b38f1.zip
lib: Add helpers for RINA names
This adds helper functions for RINA names, to aid with handling them.
Diffstat (limited to 'include/ouroboros')
-rw-r--r--include/ouroboros/CMakeLists.txt1
-rw-r--r--include/ouroboros/common.h7
-rw-r--r--include/ouroboros/da.h8
-rw-r--r--include/ouroboros/ipcp.h20
-rw-r--r--include/ouroboros/irm.h1
-rw-r--r--include/ouroboros/list.h26
-rw-r--r--include/ouroboros/rina_name.h102
-rw-r--r--include/ouroboros/sockets.h3
8 files changed, 126 insertions, 42 deletions
diff --git a/include/ouroboros/CMakeLists.txt b/include/ouroboros/CMakeLists.txt
index dc827fbe..e862de8c 100644
--- a/include/ouroboros/CMakeLists.txt
+++ b/include/ouroboros/CMakeLists.txt
@@ -9,6 +9,7 @@ set(HEADER_FILES
irm.h
list.h
logs.h
+ rina_name.h
sockets.h
)
diff --git a/include/ouroboros/common.h b/include/ouroboros/common.h
index 00d1f482..1ff4267b 100644
--- a/include/ouroboros/common.h
+++ b/include/ouroboros/common.h
@@ -35,13 +35,6 @@ typedef struct {
size_t size;
} buffer_t;
-typedef struct {
- char * ap_name;
- int api_id;
- char * ae_name;
- int aei_id;
-} rina_name_t;
-
/* FIXME: may need revision */
struct qos_spec {
char * qos_name;
diff --git a/include/ouroboros/da.h b/include/ouroboros/da.h
index 17c25203..2a046f6b 100644
--- a/include/ouroboros/da.h
+++ b/include/ouroboros/da.h
@@ -24,8 +24,14 @@
#define OUROBOROS_DA_H
#include "common.h"
+#include "rina_name.h"
rina_name_t * da_resolve_daf(char * daf_name);
-char ** da_resolve_dap(rina_name_t * name);
+/*
+ * n_1_difs is an out parameter
+ * The amount of n_1_difs is returned
+ */
+ssize_t da_resolve_dap(rina_name_t * name,
+ char ** n_1_difs);
#endif
diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h
index c8682ec3..39e9c909 100644
--- a/include/ouroboros/ipcp.h
+++ b/include/ouroboros/ipcp.h
@@ -24,24 +24,28 @@
#define OUROBOROS_IPCP_H
#include "common.h"
+#include "rina_name.h"
struct ipcp;
-struct ipcp * ipcp_create(rina_name_t name,
- char * ipcp_type);
-int ipcp_destroy(struct ipcp * instance);
+/* Returns the process id */
+int ipcp_create(rina_name_t name,
+ char * ipcp_type);
+int ipcp_destroy(int pid);
-int ipcp_reg(struct ipcp * instance,
+int ipcp_reg(int pid,
char ** difs,
size_t difs_size);
-int ipcp_unreg(struct ipcp * instance,
+int ipcp_unreg(int pid,
char ** difs,
size_t difs_size);
-int ipcp_bootstrap(struct ipcp * instance,
+int ipcp_bootstrap(int pid,
struct dif_config conf);
-int ipcp_enroll(struct ipcp * instance,
+int ipcp_enroll(int pid,
char * dif_name,
- rina_name_t member);
+ rina_name_t member,
+ char ** n_1_difs,
+ ssize_t n_1_difs_size);
#endif
diff --git a/include/ouroboros/irm.h b/include/ouroboros/irm.h
index 459b0e9f..a6f0d9f3 100644
--- a/include/ouroboros/irm.h
+++ b/include/ouroboros/irm.h
@@ -24,6 +24,7 @@
#define OUROBOROS_IRM_H
#include "common.h"
+#include "rina_name.h"
int irm_create_ipcp(rina_name_t name,
char * ipcp_type);
diff --git a/include/ouroboros/list.h b/include/ouroboros/list.h
index 1a96ddb4..f446749d 100644
--- a/include/ouroboros/list.h
+++ b/include/ouroboros/list.h
@@ -241,30 +241,4 @@ void list_splice_init(struct list_head * list,
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
-/**
- * list_for_each_entry - iterate over list of given type
- * @pos: the type * to use as a loop counter.
- * @head: the head for your list.
- * @member: the name of the list_struct within the struct.
- */
-#define list_for_each_entry(pos, head, member) \
- for (pos = list_entry((head)->next, typeof(*pos), member); \
- &pos->member != (head); \
- pos = list_entry(pos->member.next, typeof(*pos), member))
-
-/**
- * list_for_each_entry_safe - iterate over list of given type safe
- * against removal of list entry
- * @pos: the type * to use as a loop counter.
- * @n: another type * to use as temporary storage
- * @head: the head for your list.
- * @member: the name of the list_struct within the struct.
- */
-#define list_for_each_entry_safe(pos, n, head, member) \
- for (pos = list_entry((head)->next, typeof(*pos), member), \
- n = list_entry(pos->member.next, typeof(*pos), member); \
- &pos->member != (head); \
- pos = n, n = list_entry(n->member.next, typeof(*n), member))
-
-
#endif
diff --git a/include/ouroboros/rina_name.h b/include/ouroboros/rina_name.h
new file mode 100644
index 00000000..d802ae14
--- /dev/null
+++ b/include/ouroboros/rina_name.h
@@ -0,0 +1,102 @@
+/*
+ * RINA naming related utilities
+ *
+ * Sander Vrijders <sander.vrijders@intec.ugent.be>
+ * Francesco Salvestrini <f.salvestrini@nextworks.it>
+ *
+ * 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 RINA_NAME_H
+#define RINA_NAME_H
+
+#include "common.h"
+
+typedef struct {
+ char * ap_name;
+ unsigned int api_id;
+ char * ae_name;
+ unsigned int aei_id;
+} rina_name_t;
+
+/*
+ * Allocates a new name, returning the allocated object.
+ * In case of an error, a NULL is returned.
+ */
+rina_name_t * name_create();
+
+/*
+ * Initializes a previously dynamically allocated name (i.e. name_create())
+ * or a statically one (e.g. declared into a struct not as a pointer).
+ * Returns the passed object pointer in case everything is ok, a NULL
+ * otherwise.
+ *
+ * A call to name_destroy() is allowed in case of error, in order to
+ * release the associated resources.
+ *
+ * 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,
+ const char * ae_name,
+ unsigned int aei_id);
+
+/* Takes ownership of the passed parameters */
+rina_name_t * name_init_with(rina_name_t * dst,
+ char * ap_name,
+ unsigned int api_id,
+ char * ae_name,
+ unsigned int aei_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);
+
+/* Releases all the associated resources bound to a name object */
+void name_destroy(rina_name_t * ptr);
+
+/* Duplicates a name object, returning the pointer to the new object */
+rina_name_t * name_dup(const rina_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);
+
+bool name_is_equal(const rina_name_t * a, const rina_name_t * b);
+bool name_is_ok(const rina_name_t * n);
+
+#define NAME_CMP_APN 0x01
+#define NAME_CMP_API 0x02
+#define NAME_CMP_AEN 0x04
+#define NAME_CMP_AEI 0x08
+#define NAME_CMP_ALL (NAME_CMP_APN | NAME_CMP_API | NAME_CMP_AEN | NAME_CMP_AEI)
+
+bool name_cmp(uint8_t flags,
+ const rina_name_t * a,
+ const rina_name_t * b);
+
+/* Returns a name as a (newly allocated) string */
+char * name_to_string(const rina_name_t * n);
+
+/* Inverse of name_tostring() */
+rina_name_t * string_to_name(const char * s);
+
+#endif
diff --git a/include/ouroboros/sockets.h b/include/ouroboros/sockets.h
index e2409c2b..b34537a7 100644
--- a/include/ouroboros/sockets.h
+++ b/include/ouroboros/sockets.h
@@ -23,6 +23,9 @@
#ifndef OUROBOROS_SOCKETS_H
#define OUROBOROS_SOCKETS_H
+#include "common.h"
+#include "rina_name.h"
+
#define IRM_SOCK_PATH "/tmp/irm_sock"
#define IRM_MSG_BUF_SIZE 256