summaryrefslogtreecommitdiff
path: root/src/lib/irm.c
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-06-28 16:11:19 +0200
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-06-28 16:22:01 +0200
commit0d789ed8d938cc342c8f2138280795a1d5a61e3d (patch)
treeb0a3b305473a68ee18262e7f103185b9ce9cb98c /src/lib/irm.c
parentacd29da104d0d8ddace2b2693314542bb5a56fcc (diff)
downloadouroboros-0d789ed8d938cc342c8f2138280795a1d5a61e3d.tar.gz
ouroboros-0d789ed8d938cc342c8f2138280795a1d5a61e3d.zip
lib, irmd, ipcpd: Change of IRM API
This changes the IRM API after discussions with Dimitri. The register operation is now split into a bind and register operation. The same for unregister; unbind and unregister. PIDs are now used as the application instance name. A name for a PID is only provided for scriptability in bash. It is therefore also no longer passed down to the IPCP. Every operation on an IPCP through the IRM API has to use the PID. Quering of the PIDs by name is possible. The IRM tool has been updated to use this new API as well. A subcommand 'ipcp' has been added for operations that take effect on IPCPs only. Fixes #12
Diffstat (limited to 'src/lib/irm.c')
-rw-r--r--src/lib/irm.c201
1 files changed, 140 insertions, 61 deletions
diff --git a/src/lib/irm.c b/src/lib/irm.c
index 8fd0a7e7..e3902469 100644
--- a/src/lib/irm.c
+++ b/src/lib/irm.c
@@ -27,22 +27,18 @@
#include <ouroboros/common.h>
#include <ouroboros/logs.h>
#include <ouroboros/sockets.h>
-#include <ouroboros/instance_name.h>
#include <stdlib.h>
-pid_t irm_create_ipcp(char * ipcp_name,
+pid_t irm_create_ipcp(char * name,
enum ipcp_type ipcp_type)
{
irm_msg_t msg = IRM_MSG__INIT;
irm_msg_t * recv_msg = NULL;
int ret = -1;
- if (ipcp_name == NULL)
- return -EINVAL;
-
msg.code = IRM_MSG_CODE__IRM_CREATE_IPCP;
- msg.ap_name = ipcp_name;
+ msg.dst_name = name;
msg.has_ipcp_type = true;
msg.ipcp_type = ipcp_type;
@@ -61,19 +57,18 @@ pid_t irm_create_ipcp(char * ipcp_name,
return ret;
}
-int irm_destroy_ipcp(instance_name_t * api)
+int irm_destroy_ipcp(pid_t api)
{
irm_msg_t msg = IRM_MSG__INIT;
irm_msg_t * recv_msg = NULL;
int ret = -1;
- if (api == NULL || api->name == NULL)
+ if (api == 0)
return -EINVAL;
- msg.code = IRM_MSG_CODE__IRM_DESTROY_IPCP;
- msg.ap_name = api->name;
- msg.has_api_id = true;
- msg.api_id = api->id;
+ msg.code = IRM_MSG_CODE__IRM_DESTROY_IPCP;
+ msg.has_api = true;
+ msg.api = api;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
@@ -90,7 +85,7 @@ int irm_destroy_ipcp(instance_name_t * api)
return ret;
}
-int irm_bootstrap_ipcp(instance_name_t * api,
+int irm_bootstrap_ipcp(pid_t api,
struct dif_config * conf)
{
irm_msg_t msg = IRM_MSG__INIT;
@@ -98,13 +93,12 @@ int irm_bootstrap_ipcp(instance_name_t * api,
irm_msg_t * recv_msg = NULL;
int ret = -1;
- if (api == NULL || api->name == NULL || conf == NULL)
+ if (api == 0 || 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_MSG_CODE__IRM_BOOTSTRAP_IPCP;
+ msg.has_api = true;
+ msg.api = api;
msg.conf = &config;
config.dif_name = conf->dif_name;
@@ -163,20 +157,60 @@ int irm_bootstrap_ipcp(instance_name_t * api,
return ret;
}
-int irm_enroll_ipcp(instance_name_t * api,
- char * dif_name)
+ssize_t irm_list_ipcps(char * name,
+ pid_t ** apis)
+{
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ ssize_t nr = -1;
+ int i;
+
+ if (apis == NULL)
+ return -EINVAL;
+
+ msg.code = IRM_MSG_CODE__IRM_LIST_IPCPS;
+ msg.dst_name = name;
+
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL) {
+ free(msg.dif_name);
+ return -1;
+ }
+
+ if (recv_msg->pids == NULL) {
+ irm_msg__free_unpacked(recv_msg, NULL);
+ return -1;
+ }
+
+ nr = recv_msg->n_pids;
+ *apis = malloc(nr * sizeof(pid_t));
+ if (*apis == NULL) {
+ irm_msg__free_unpacked(recv_msg, NULL);
+ return -ENOMEM;
+ }
+
+ for (i = 0; i < nr; i++) {
+ (*apis)[i] = recv_msg->pids[i];
+ }
+
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return nr;
+}
+
+int irm_enroll_ipcp(pid_t api,
+ char * dif_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)
+ if (api == 0 || 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.has_api = true;
+ msg.api = api;
msg.n_dif_name = 1;
msg.dif_name = malloc(sizeof(*(msg.dif_name)));
if (msg.dif_name == NULL) {
@@ -203,39 +237,30 @@ int irm_enroll_ipcp(instance_name_t * api,
return ret;
}
-int irm_reg(char * name,
- instance_name_t * api,
- int argc,
- char ** argv,
- bool autoexec,
- char ** difs,
- size_t difs_len)
+int irm_bind(char * name,
+ char * ap_name,
+ uint16_t opts,
+ int argc,
+ char ** argv)
{
irm_msg_t msg = IRM_MSG__INIT;
irm_msg_t * recv_msg = NULL;
int ret = -1;
- if (name == NULL || api->name == NULL)
+ if (name == NULL || ap_name == NULL)
return -EINVAL;
- msg.code = IRM_MSG_CODE__IRM_AP_REG;
+ msg.code = IRM_MSG_CODE__IRM_BIND;
msg.dst_name = name;
- msg.ap_name = api->name;
- if (difs != NULL) {
- msg.dif_name = difs;
- msg.n_dif_name = difs_len;
- }
+ msg.ap_name = ap_name;
if (argv != NULL) {
msg.n_args = argc;
msg.args = argv;
- } else {
- msg.has_api_id = true;
- msg.api_id = api->id;
}
- msg.has_autoexec = true;
- msg.autoexec = autoexec;
+ msg.has_opts = true;
+ msg.opts = opts;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
@@ -252,36 +277,90 @@ int irm_reg(char * name,
return ret;
}
-int irm_unreg(char * name,
- const instance_name_t * api,
- char ** difs,
- size_t difs_len,
- bool hard)
+int irm_unbind(char * name,
+ char * ap_name,
+ uint16_t opts)
{
irm_msg_t msg = IRM_MSG__INIT;
irm_msg_t * recv_msg = NULL;
int ret = -1;
- if (name == NULL && api == NULL)
+ if (name == NULL || ap_name == NULL)
return -EINVAL;
- if (difs == NULL ||
- difs_len == 0 ||
- difs[0] == NULL)
+ msg.code = IRM_MSG_CODE__IRM_UNBIND;
+
+ msg.dst_name = name;
+ msg.ap_name = ap_name;
+ msg.has_opts = true;
+ msg.opts = opts;
+
+ 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 irm_reg(char * name,
+ char ** difs,
+ size_t difs_size)
+{
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
+
+ if (name == NULL || difs == NULL || difs_size == 0)
return -EINVAL;
- msg.code = IRM_MSG_CODE__IRM_AP_UNREG;
- if (api != NULL) {
- msg.ap_name = api->name;
- msg.has_api_id = true;
- msg.api_id = api->id;
+ msg.code = IRM_MSG_CODE__IRM_REG;
+
+ msg.dst_name = name;
+
+ msg.dif_name = difs;
+ msg.n_dif_name = difs_size;
+
+ 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 irm_unreg(char * name,
+ char ** difs,
+ size_t difs_size)
+{
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
+
+ if (name == NULL || difs == NULL || difs_size == 0)
+ return -EINVAL;
+
+ msg.code = IRM_MSG_CODE__IRM_UNREG;
+
+ msg.dst_name = name;
+
msg.dif_name = difs;
- msg.n_dif_name = difs_len;
- if (name != NULL)
- msg.dst_name = name;
- msg.hard = hard;
+ msg.n_dif_name = difs_size;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)