summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-03-28 14:43:16 +0200
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-03-28 14:43:16 +0200
commita14d696bdbc72754e8019fa9579d5a338cc85a05 (patch)
tree2533a574e03a9954b9eeaf7750219d3175ce8b99 /src
parentd37add0f20c93432c0b4c12866810c124a7a18ec (diff)
downloadouroboros-a14d696bdbc72754e8019fa9579d5a338cc85a05.tar.gz
ouroboros-a14d696bdbc72754e8019fa9579d5a338cc85a05.zip
lib: Update irm.h API
Removes rina_name_t from that API. Passing ap_name and api_id as params instead. The IRM tool has been updated accordingly. Some errors in the build related to protobuf-c have also been resolved.
Diffstat (limited to 'src')
-rw-r--r--src/lib/.gitignore1
-rw-r--r--src/lib/CMakeLists.txt11
-rw-r--r--src/lib/irm.c141
-rw-r--r--src/lib/sockets.c7
-rw-r--r--src/tools/irm/irm_bootstrap_ipcp.c20
-rw-r--r--src/tools/irm/irm_create_ipcp.c28
-rw-r--r--src/tools/irm/irm_destroy_ipcp.c17
-rw-r--r--src/tools/irm/irm_enroll_ipcp.c29
-rw-r--r--src/tools/irm/irm_register_ipcp.c32
-rw-r--r--src/tools/irm/irm_unregister_ipcp.c31
-rw-r--r--src/tools/irm/irm_utils.c16
-rw-r--r--src/tools/irm/irm_utils.h2
12 files changed, 181 insertions, 154 deletions
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 e05dce8b..0427e236 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -34,10 +34,13 @@ set(SOURCE_FILES
shm_du_map.c
sockets.c
utils.c
-)
+ )
-add_library(ouroboros SHARED ${SOURCE_FILES} ${PROTO_SRCS} ${PROTO_HDRS})
-target_link_libraries(ouroboros rt pthread ${PROTOBUF_LIBRARIES})
+install(FILES ${PROTO_HDRS}
+ DESTINATION include/ouroboros)
+
+add_library(ouroboros SHARED ${SOURCE_FILES} ${PROTO_SRCS})
+target_link_libraries(ouroboros rt pthread ${PROTOBUF_C_LIBRARY})
include(MacroAddCompileFlags)
if (CMAKE_BUILD_TYPE MATCHES Debug)
@@ -46,4 +49,6 @@ 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/irm.c b/src/lib/irm.c
index 9fd13d52..92d8b3a5 100644
--- a/src/lib/irm.c
+++ b/src/lib/irm.c
@@ -26,26 +26,25 @@
#include <ouroboros/common.h>
#include <ouroboros/logs.h>
#include <ouroboros/sockets.h>
+
#include <stdlib.h>
-int irm_create_ipcp(rina_name_t name,
+int irm_create_ipcp(char * ap_name,
+ int api_id,
char * ipcp_type)
{
- struct irm_msg msg;
+ irm_msg_t msg = IRM_MSG__INIT;
- if (ipcp_type == NULL)
- return -1;
+ if (ipcp_type == NULL || ap_name == NULL)
+ return -EINVAL;
- if (!name_is_ok(&name)) {
- LOG_ERR("Bad name");
- return -1;
- }
-
- msg.code = IRM_CREATE_IPCP;
- msg.name = &name;
+ msg.code = IRM_MSG_CODE__IRM_CREATE_IPCP;
+ msg.ap_name = ap_name;
+ msg.has_api_id = true;
+ msg.api_id = api_id;
msg.ipcp_type = ipcp_type;
- if (send_irmd_msg(&msg)) {
+ if (send_irm_msg(&msg)) {
LOG_ERR("Failed to send message to daemon");
return -1;
}
@@ -53,19 +52,21 @@ int irm_create_ipcp(rina_name_t name,
return 0;
}
-int irm_destroy_ipcp(rina_name_t name)
+int irm_destroy_ipcp(char * ap_name,
+ int api_id)
{
- struct irm_msg msg;
+ irm_msg_t msg = IRM_MSG__INIT;
- if (!name_is_ok(&name)) {
- LOG_ERR("Bad name");
- return -1;
+ if (ap_name == NULL) {
+ return -EINVAL;
}
- msg.code = IRM_DESTROY_IPCP;
- msg.name = &name;
+ msg.code = IRM_MSG_CODE__IRM_DESTROY_IPCP;
+ msg.ap_name = ap_name;
+ msg.has_api_id = true;
+ msg.api_id = api_id;
- if (send_irmd_msg(&msg)) {
+ if (send_irm_msg(&msg)) {
LOG_ERR("Failed to send message to daemon");
return -1;
}
@@ -73,21 +74,22 @@ int irm_destroy_ipcp(rina_name_t name)
return 0;
}
-int irm_bootstrap_ipcp(rina_name_t name,
- struct dif_config conf)
+int irm_bootstrap_ipcp(char * ap_name,
+ int api_id,
+ struct dif_config * conf)
{
- struct irm_msg msg;
+ irm_msg_t msg = IRM_MSG__INIT;
- if (!name_is_ok(&name)) {
- LOG_ERR("Bad name");
- return -1;
+ if (ap_name == NULL || conf == NULL) {
+ return -EINVAL;
}
- msg.code = IRM_BOOTSTRAP_IPCP;
- msg.name = &name;
- msg.conf = &conf;
+ msg.code = IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP;
+ msg.ap_name = ap_name;
+ msg.has_api_id = true;
+ msg.api_id = api_id;
- if (send_irmd_msg(&msg)) {
+ if (send_irm_msg(&msg)) {
LOG_ERR("Failed to send message to daemon");
return -1;
}
@@ -95,45 +97,61 @@ int irm_bootstrap_ipcp(rina_name_t name,
return 0;
}
-int irm_enroll_ipcp(rina_name_t name,
+int irm_enroll_ipcp(char * ap_name,
+ int api_id,
char * dif_name)
{
- struct irm_msg msg;
+ irm_msg_t msg = IRM_MSG__INIT;
- if (!name_is_ok(&name)) {
- LOG_ERR("Bad name");
- return -1;
+ if (ap_name == NULL || dif_name == NULL) {
+ return -EINVAL;
}
- msg.code = IRM_ENROLL_IPCP;
- msg.name = &name;
- msg.dif_name = dif_name;
+ msg.code = IRM_MSG_CODE__IRM_ENROLL_IPCP;
+ msg.ap_name = ap_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;
- if (send_irmd_msg(&msg)) {
+ if (send_irm_msg(&msg)) {
LOG_ERR("Failed to send message to daemon");
+ free(msg.dif_name);
return -1;
}
+ free(msg.dif_name);
+
return 0;
}
-int irm_reg_ipcp(rina_name_t name,
+int irm_reg_ipcp(char * ap_name,
+ int api_id,
char ** difs,
size_t difs_size)
{
- struct irm_msg msg;
+ irm_msg_t msg = IRM_MSG__INIT;
- if (!name_is_ok(&name)) {
- LOG_ERR("Bad name");
- return -1;
+ if (ap_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 = ap_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)) {
+ if (send_irm_msg(&msg)) {
LOG_ERR("Failed to send message to daemon");
return -1;
}
@@ -141,23 +159,28 @@ int irm_reg_ipcp(rina_name_t name,
return 0;
}
-int irm_unreg_ipcp(rina_name_t name,
+int irm_unreg_ipcp(char * ap_name,
+ int api_id,
char ** difs,
size_t difs_size)
{
- struct irm_msg msg;
+ irm_msg_t msg = IRM_MSG__INIT;
- if (!name_is_ok(&name)) {
- LOG_ERR("Bad name");
- return -1;
+ if (ap_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 = ap_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)) {
+ if (send_irm_msg(&msg)) {
LOG_ERR("Failed to send message to daemon");
return -1;
}
diff --git a/src/lib/sockets.c b/src/lib/sockets.c
index b157b628..b98f6bbc 100644
--- a/src/lib/sockets.c
+++ b/src/lib/sockets.c
@@ -166,6 +166,13 @@ struct irm_msg * send_recv_irmd_msg(struct irm_msg * msg)
return recv_msg;
}
+
+int send_irm_msg(irm_msg_t * msg)
+{
+
+ return -1;
+}
+
char * ipcp_sock_path(pid_t pid)
{
char * full_name = NULL;
diff --git a/src/tools/irm/irm_bootstrap_ipcp.c b/src/tools/irm/irm_bootstrap_ipcp.c
index 89950069..0843083d 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,32 @@ static void usage()
int do_bootstrap_ipcp(int argc, char ** argv)
{
- rina_name_t name;
+ char * ap_name = NULL;
+ int api_id = 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) {
+ ap_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 (ap_name == NULL) {
usage();
return -1;
}
- return irm_bootstrap_ipcp(name, conf);
+ return irm_bootstrap_ipcp(ap_name, api_id, &conf);
}
diff --git a/src/tools/irm/irm_create_ipcp.c b/src/tools/irm/irm_create_ipcp.c
index 854a15f9..3262bd5c 100644
--- a/src/tools/irm/irm_create_ipcp.c
+++ b/src/tools/irm/irm_create_ipcp.c
@@ -40,31 +40,31 @@ 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;
+ char * ap_name = NULL;
+ int api_id = 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) {
+ ap_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 || ap_name == NULL) {
usage();
return -1;
}
- return irm_create_ipcp(name, ipcp_type);
+ return irm_create_ipcp(ap_name, api_id, ipcp_type);
}
diff --git a/src/tools/irm/irm_destroy_ipcp.c b/src/tools/irm/irm_destroy_ipcp.c
index 4f02f9cb..fbbeb5bd 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,15 @@ static void usage()
int do_destroy_ipcp(int argc, char ** argv)
{
- rina_name_t name;
-
- name.ap_name = NULL;
- name.api_id = 0;
+ char * ap_name = NULL;
+ int api_id = 0;
while (argc > 0) {
- if (!parse_name(argv, &name)) {
+ if (matches(*argv, "ap") == 0) {
+ ap_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 +55,10 @@ int do_destroy_ipcp(int argc, char ** argv)
argv += 2;
}
- if (name.ap_name == NULL) {
+ if (ap_name == NULL) {
usage();
return -1;
}
- return irm_destroy_ipcp(name);
+ return irm_destroy_ipcp(ap_name, api_id);
}
diff --git a/src/tools/irm/irm_enroll_ipcp.c b/src/tools/irm/irm_enroll_ipcp.c
index 1dcdc919..70798821 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,31 @@ static void usage()
int do_enroll_ipcp(int argc, char ** argv)
{
- rina_name_t name;
+ char * ap_name = NULL;
+ int api_id = 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) {
+ ap_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 || ap_name == NULL) {
usage();
return -1;
}
- return irm_enroll_ipcp(name, dif_name);
+ return irm_enroll_ipcp(ap_name, api_id, dif_name);
}
diff --git a/src/tools/irm/irm_register_ipcp.c b/src/tools/irm/irm_register_ipcp.c
index 468ef28f..b8808ecd 100644
--- a/src/tools/irm/irm_register_ipcp.c
+++ b/src/tools/irm/irm_register_ipcp.c
@@ -45,36 +45,36 @@ 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;
+ char * ap_name = NULL;
+ int 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 "
- "register_ipcp\".\n", *argv);
+ if (matches(*argv, "ap") == 0) {
+ ap_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 || ap_name == NULL) {
usage();
return -1;
}
- return irm_reg_ipcp(name, difs, difs_size);
+ return irm_reg_ipcp(ap_name, api_id, difs, difs_size);
}
diff --git a/src/tools/irm/irm_unregister_ipcp.c b/src/tools/irm/irm_unregister_ipcp.c
index 0b669503..1321c263 100644
--- a/src/tools/irm/irm_unregister_ipcp.c
+++ b/src/tools/irm/irm_unregister_ipcp.c
@@ -45,36 +45,37 @@ static void usage()
int do_unregister_ipcp(int argc, char ** argv)
{
- rina_name_t name;
+ char * ap_name = NULL;
+ int api_id = 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) {
+ ap_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 || ap_name == NULL) {
usage();
return -1;
}
- return irm_unreg_ipcp(name, difs, difs_size);
+ return irm_unreg_ipcp(ap_name, api_id, 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..3d328d95 100644
--- a/src/tools/irm/irm_utils.h
+++ b/src/tools/irm/irm_utils.h
@@ -25,5 +25,3 @@
#include <stdbool.h>
int matches(const char * cmd, const char * pattern);
-
-bool parse_name(char ** argv, rina_name_t * name);