summaryrefslogtreecommitdiff
path: root/src/lib
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
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')
-rw-r--r--src/lib/CMakeLists.txt1
-rw-r--r--src/lib/dev.c32
-rw-r--r--src/lib/instance_name.c248
-rw-r--r--src/lib/ipcp.c4
-rw-r--r--src/lib/irm.c201
-rw-r--r--src/lib/irmd_messages.proto37
6 files changed, 169 insertions, 354 deletions
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 2a75ef17..410be6fe 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -27,7 +27,6 @@ set(SOURCE_FILES
cdap.c
dev.c
du_buff.c
- instance_name.c
ipcp.c
irm.c
list.c
diff --git a/src/lib/dev.c b/src/lib/dev.c
index ad311f7f..c6f25cdf 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -28,7 +28,6 @@
#include <ouroboros/dev.h>
#include <ouroboros/sockets.h>
#include <ouroboros/bitmap.h>
-#include <ouroboros/instance_name.h>
#include <ouroboros/shm_du_map.h>
#include <ouroboros/shm_ap_rbuff.h>
#include <ouroboros/utils.h>
@@ -45,7 +44,8 @@ struct flow {
};
struct ap_data {
- instance_name_t * api;
+ char * ap_name;
+ pid_t api;
struct shm_du_map * dum;
struct bmp * fds;
struct shm_ap_rbuff * rb;
@@ -66,30 +66,17 @@ int ap_init(char * ap_name)
return -ENOMEM;
}
- _ap_instance->api = instance_name_create();
- if (_ap_instance->api == NULL) {
- free(_ap_instance);
- return -ENOMEM;
- }
-
- if (instance_name_init_from(_ap_instance->api,
- ap_name,
- getpid()) == NULL) {
- instance_name_destroy(_ap_instance->api);
- free(_ap_instance);
- return -ENOMEM;
- }
+ _ap_instance->api = getpid();
+ _ap_instance->ap_name = ap_name;
_ap_instance->fds = bmp_create(AP_MAX_FLOWS, 0);
if (_ap_instance->fds == NULL) {
- instance_name_destroy(_ap_instance->api);
free(_ap_instance);
return -ENOMEM;
}
_ap_instance->dum = shm_du_map_open();
if (_ap_instance->dum == NULL) {
- instance_name_destroy(_ap_instance->api);
bmp_destroy(_ap_instance->fds);
free(_ap_instance);
return -1;
@@ -97,7 +84,6 @@ int ap_init(char * ap_name)
_ap_instance->rb = shm_ap_rbuff_create();
if (_ap_instance->rb == NULL) {
- instance_name_destroy(_ap_instance->api);
shm_du_map_close(_ap_instance->dum);
bmp_destroy(_ap_instance->fds);
free(_ap_instance);
@@ -124,8 +110,6 @@ void ap_fini(void)
pthread_rwlock_wrlock(&_ap_instance->data_lock);
- if (_ap_instance->api != NULL)
- instance_name_destroy(_ap_instance->api);
if (_ap_instance->fds != NULL)
bmp_destroy(_ap_instance->fds);
if (_ap_instance->dum != NULL)
@@ -168,8 +152,8 @@ int flow_accept(char ** ae_name)
pthread_rwlock_rdlock(&_ap_instance->data_lock);
- msg.ap_name = _ap_instance->api->name;
- msg.pid = _ap_instance->api->id;
+ msg.ap_name = _ap_instance->ap_name;
+ msg.pid = _ap_instance->api;
pthread_rwlock_unlock(&_ap_instance->data_lock);
@@ -238,7 +222,7 @@ int flow_alloc_resp(int fd,
msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC_RESP;
msg.has_pid = true;
- msg.pid = _ap_instance->api->id;
+ msg.pid = _ap_instance->api;
msg.has_port_id = true;
pthread_rwlock_rdlock(&_ap_instance->data_lock);
@@ -299,7 +283,7 @@ int flow_alloc(char * dst_name,
pthread_rwlock_rdlock(&_ap_instance->data_lock);
- msg.pid = _ap_instance->api->id;
+ msg.pid = _ap_instance->api;
pthread_rwlock_unlock(&_ap_instance->data_lock);
diff --git a/src/lib/instance_name.c b/src/lib/instance_name.c
deleted file mode 100644
index 844bb924..00000000
--- a/src/lib/instance_name.c
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
- * 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.
- */
-
-#define OUROBOROS_PREFIX "instance-name"
-
-#include <ouroboros/logs.h>
-#include <ouroboros/common.h>
-#include <ouroboros/instance_name.h>
-#include <ouroboros/utils.h>
-
-#include <string.h>
-#include <math.h>
-#include <stdlib.h>
-
-instance_name_t * instance_name_create()
-{
- instance_name_t * tmp;
-
- tmp = malloc(sizeof *tmp);
- if (tmp == NULL)
- return NULL;
-
- tmp->name = NULL;
- tmp->id = 0;
-
- return tmp;
-}
-
-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 ... */
- instance_name_fini(dst);
-
- dst->name = strdup(name);
- dst->id = id;
-
- if (dst->name == NULL) {
- instance_name_fini(dst);
- return NULL;
- }
-
- return dst;
-}
-
-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 ... */
- instance_name_fini(dst);
-
- dst->name = name;
- dst->id = id;
-
- return dst;
-}
-
-void instance_name_fini(instance_name_t * n)
-{
- if (n == NULL || n->name == NULL)
- return;
-
- free(n->name);
- n->name = NULL;
-}
-
-void instance_name_destroy(instance_name_t * ptr)
-{
- if (ptr == NULL)
- return;
-
- instance_name_fini(ptr);
-
- free(ptr);
-}
-
-int instance_name_cpy(instance_name_t * dst,
- const instance_name_t * src)
-{
- instance_name_t * res;
-
- if (src == NULL || dst == NULL)
- return -EINVAL;
-
- res = instance_name_init_from(dst, src->name, src->id);
- if (res == NULL)
- return -ENOMEM;
-
- return 0;
-}
-
-instance_name_t * instance_name_dup(const instance_name_t * src)
-{
- instance_name_t * tmp;
-
- if (src == NULL)
- return NULL;
-
- tmp = instance_name_create();
- if (tmp == NULL)
- return NULL;
-
- if (instance_name_cpy(tmp, src)) {
- instance_name_destroy(tmp);
- return NULL;
- }
-
- return tmp;
-}
-
-bool instance_name_is_valid(const instance_name_t * n)
-{
- return (n != NULL && n->name != NULL && strlen(n->name));
-}
-
-int instance_name_cmp(const instance_name_t * a,
- const instance_name_t * b)
-{
-
- int ret = 0;
-
- if (a == NULL || b == NULL) {
- LOG_DBGF("Won't compare NULL.");
- return -2;
- }
-
- if (a == b)
- return 0;
-
- ret = strcmp(a->name, b->name);
-
- if (!ret) {
- if (a->id == b-> id)
- return 0;
- else
- return a->id < b->id ? -1 : 1;
- }
-
- return ret;
-}
-
-
-
-#define DELIMITER "/"
-
-char * instance_name_to_string(const instance_name_t * n)
-{
- char * tmp;
- size_t size;
- const char * none = "";
- size_t none_len = strlen(none);
-
- if (n == NULL)
- return NULL;
-
- size = 0;
-
- size += (n->name != NULL ?
- strlen(n->name) : none_len);
- size += strlen(DELIMITER);
-
- size += (n->id == 0 ?
- 1 : n_digits(n->id));
- size += strlen(DELIMITER);
-
- tmp = malloc(size);
- if (!tmp)
- return NULL;
-
- if (sprintf(tmp, "%s%s%d",
- (n->name != NULL ? n->name : none),
- DELIMITER, n->id)
- != size - 1) {
- free(tmp);
- return NULL;
- }
-
- return tmp;
-}
-
-instance_name_t * string_to_instance_name(const char * s)
-{
- instance_name_t * name;
-
- char * tmp1 = NULL;
- char * tmp_ap = NULL;
- char * tmp_s_api = NULL;
- unsigned int tmp_api = 0;
- char * tmp2;
-
- if (s == NULL)
- return NULL;
-
- tmp1 = strdup(s);
- if (tmp1 == NULL) {
- return NULL;
- }
-
- tmp_ap = strtok(tmp1, DELIMITER);
- tmp_s_api = strtok(NULL, DELIMITER);
- if (tmp_s_api != NULL)
- tmp_api = (unsigned int) strtol(tmp_s_api, &tmp2, 10);
-
- name = instance_name_create();
- if (name == NULL) {
- if (tmp1 != NULL)
- free(tmp1);
- return NULL;
- }
-
- if (!instance_name_init_from(name, tmp_ap, tmp_api)) {
- instance_name_destroy(name);
- if (tmp1 != NULL)
- free(tmp1);
- return NULL;
- }
-
- if (tmp1 != NULL)
- free(tmp1);
-
- return name;
-}
diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c
index 77263bcf..70f73e0e 100644
--- a/src/lib/ipcp.c
+++ b/src/lib/ipcp.c
@@ -99,8 +99,7 @@ static ipcp_msg_t * send_recv_ipcp_msg(pid_t pid,
return recv_msg;
}
-pid_t ipcp_create(char * ipcp_name,
- enum ipcp_type ipcp_type)
+pid_t ipcp_create(enum ipcp_type ipcp_type)
{
pid_t pid = 0;
char irmd_pid[10];
@@ -150,7 +149,6 @@ pid_t ipcp_create(char * ipcp_name,
char * argv[] = {full_name,
irmd_pid,
- ipcp_name,
0};
char * envp[] = {0};
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)
diff --git a/src/lib/irmd_messages.proto b/src/lib/irmd_messages.proto
index 34366975..ab09f0db 100644
--- a/src/lib/irmd_messages.proto
+++ b/src/lib/irmd_messages.proto
@@ -25,26 +25,29 @@ import "dif_config.proto";
enum irm_msg_code {
IRM_CREATE_IPCP = 1;
IRM_DESTROY_IPCP = 2;
- IRM_BOOTSTRAP_IPCP = 3;
- IRM_ENROLL_IPCP = 4;
- IRM_AP_REG = 5;
- IRM_AP_UNREG = 6;
- IRM_FLOW_ACCEPT = 7;
- IRM_FLOW_ALLOC_RESP = 8;
- IRM_FLOW_ALLOC = 9;
- IRM_FLOW_ALLOC_RES = 10;
- IRM_FLOW_DEALLOC = 11;
- IPCP_FLOW_REQ_ARR = 12;
- IPCP_FLOW_ALLOC_REPLY = 13;
- IPCP_FLOW_DEALLOC = 14;
- IRM_REPLY = 15;
+ IRM_LIST_IPCPS = 3;
+ IRM_BOOTSTRAP_IPCP = 4;
+ IRM_ENROLL_IPCP = 5;
+ IRM_BIND = 6;
+ IRM_UNBIND = 7;
+ IRM_REG = 8;
+ IRM_UNREG = 9;
+ IRM_FLOW_ACCEPT = 10;
+ IRM_FLOW_ALLOC_RESP = 11;
+ IRM_FLOW_ALLOC = 12;
+ IRM_FLOW_ALLOC_RES = 13;
+ IRM_FLOW_DEALLOC = 14;
+ IPCP_FLOW_REQ_ARR = 15;
+ IPCP_FLOW_ALLOC_REPLY = 16;
+ IPCP_FLOW_DEALLOC = 17;
+ IRM_REPLY = 18;
};
message irm_msg {
required irm_msg_code code = 1;
optional string ap_name = 2;
- optional string ae_name = 4;
- optional uint32 api_id = 3;
+ optional string ae_name = 3;
+ optional uint32 api = 4;
optional uint32 ipcp_type = 5;
repeated string dif_name = 6;
repeated string args = 7;
@@ -53,7 +56,7 @@ message irm_msg {
optional sint32 port_id = 10;
optional int32 pid = 11;
optional dif_config_msg conf = 12;
- optional bool autoexec = 13;
- optional bool hard = 14;
+ optional uint32 opts = 13;
+ repeated int32 pids = 14;
optional sint32 result = 15;
};