summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorDimitri Staessens <[email protected]>2018-03-22 11:02:15 +0100
committerSander Vrijders <[email protected]>2018-03-22 12:36:58 +0100
commit751fb58bcf5fdb31c0627a5153684e96126cffb6 (patch)
tree5c4e8d8b2b2b323738703644c422a7e6c7095d5e /src/lib
parentfd5508b8daec47e9f646c086d4cc310583154b97 (diff)
downloadouroboros-751fb58bcf5fdb31c0627a5153684e96126cffb6.tar.gz
ouroboros-751fb58bcf5fdb31c0627a5153684e96126cffb6.zip
lib: Simplify reg/unreg API
The reg/unreg API is simplified to registering and unregistering a single name with a single IPCP. The functionality associated with registering names was moved from the IRMd to the irm tool. The function to list IPCPs was simplified to return all IPCPs in the system with their basic properties needed for management. The above changes led to some needed changes in the irm tool and the management functions that were depending on the previous behaviour of list_ipcps. Command line functionality to list IPCPs in the system is also added to the irm tool. Some older code was refactored. Signed-off-by: Dimitri Staessens <[email protected]> Signed-off-by: Sander Vrijders <[email protected]>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/dev.c9
-rw-r--r--src/lib/ipcpd_messages.proto5
-rw-r--r--src/lib/irm.c135
-rw-r--r--src/lib/irmd_messages.proto40
4 files changed, 95 insertions, 94 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c
index d0766783..d9589b08 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -209,9 +209,8 @@ static int proc_announce(char * prog)
msg.code = IRM_MSG_CODE__IRM_PROC_ANNOUNCE;
msg.has_pid = true;
-
- msg.pid = ai.pid;
- msg.prog_name = prog;
+ msg.pid = ai.pid;
+ msg.prog = prog;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL) {
@@ -550,7 +549,7 @@ int flow_accept(qosspec_t * qs,
return fd;
}
-int flow_alloc(const char * dst_name,
+int flow_alloc(const char * dst,
qosspec_t * qs,
const struct timespec * timeo)
{
@@ -560,7 +559,7 @@ int flow_alloc(const char * dst_name,
int fd;
msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC;
- msg.dst_name = (char *) dst_name;
+ msg.dst = (char *) dst;
msg.has_pid = true;
msg.has_qoscube = true;
msg.pid = ai.pid;
diff --git a/src/lib/ipcpd_messages.proto b/src/lib/ipcpd_messages.proto
index 2d3bad7f..de78d809 100644
--- a/src/lib/ipcpd_messages.proto
+++ b/src/lib/ipcpd_messages.proto
@@ -40,15 +40,14 @@ enum ipcp_msg_code {
message ipcp_msg {
required ipcp_msg_code code = 1;
- optional string name = 2;
optional bytes hash = 3;
optional int32 port_id = 4;
- optional string dst_name = 5;
+ optional string dst = 5;
optional uint32 qoscube = 6;
optional ipcp_config_msg conf = 7;
optional int32 pid = 8;
optional layer_info_msg layer_info = 9;
optional int32 response = 10;
- optional string comp_name = 11;
+ optional string comp = 11;
optional int32 result = 12;
};
diff --git a/src/lib/irm.c b/src/lib/irm.c
index c12ab893..6a9f837e 100644
--- a/src/lib/irm.c
+++ b/src/lib/irm.c
@@ -34,7 +34,7 @@
#include <sys/stat.h>
pid_t irm_create_ipcp(const char * name,
- enum ipcp_type ipcp_type)
+ enum ipcp_type type)
{
irm_msg_t msg = IRM_MSG__INIT;
irm_msg_t * recv_msg = NULL;
@@ -44,9 +44,9 @@ pid_t irm_create_ipcp(const char * name,
return -EINVAL;
msg.code = IRM_MSG_CODE__IRM_CREATE_IPCP;
- msg.dst_name = (char *) name;
+ msg.name = (char *) name;
msg.has_ipcp_type = true;
- msg.ipcp_type = ipcp_type;
+ msg.ipcp_type = type;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
@@ -54,7 +54,7 @@ pid_t irm_create_ipcp(const char * name,
if (!recv_msg->has_result) {
irm_msg__free_unpacked(recv_msg, NULL);
- return -1;
+ return -EIRMD;
}
ret = recv_msg->result;
@@ -174,8 +174,8 @@ int irm_connect_ipcp(pid_t pid,
int ret;
msg.code = IRM_MSG_CODE__IRM_CONNECT_IPCP;
- msg.dst_name = (char *) dst;
- msg.comp_name = (char *) component;
+ msg.dst = (char *) dst;
+ msg.comp = (char *) component;
msg.has_pid = true;
msg.pid = pid;
@@ -202,11 +202,11 @@ int irm_disconnect_ipcp(pid_t pid,
irm_msg_t * recv_msg = NULL;
int ret;
- msg.code = IRM_MSG_CODE__IRM_DISCONNECT_IPCP;
- msg.dst_name = (char *) dst;
- msg.comp_name = (char *) component;
- msg.has_pid = true;
- msg.pid = pid;
+ msg.code = IRM_MSG_CODE__IRM_DISCONNECT_IPCP;
+ msg.dst = (char *) dst;
+ msg.comp = (char *) component;
+ msg.has_pid = true;
+ msg.pid = pid;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
@@ -223,38 +223,47 @@ int irm_disconnect_ipcp(pid_t pid,
return ret;
}
-ssize_t irm_list_ipcps(const char * name,
- pid_t ** pids)
+ssize_t irm_list_ipcps(struct ipcp_info ** ipcps)
{
irm_msg_t msg = IRM_MSG__INIT;
- irm_msg_t * recv_msg = NULL;
- size_t nr = 0;
+ irm_msg_t * recv_msg;
+ size_t nr;
size_t i;
- if (pids == NULL)
+ if (ipcps == NULL)
return -EINVAL;
+ *ipcps = NULL;
+
msg.code = IRM_MSG_CODE__IRM_LIST_IPCPS;
- msg.dst_name = (char *) name;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
return -EIRMD;
- if (recv_msg->pids == NULL) {
+ if (recv_msg->ipcps == NULL) {
irm_msg__free_unpacked(recv_msg, NULL);
- return -1;
+ return 0;
+ }
+
+ nr = recv_msg->n_ipcps;
+ if (nr == 0) {
+ irm_msg__free_unpacked(recv_msg, NULL);
+ return 0;
}
- nr = recv_msg->n_pids;
- *pids = malloc(nr * sizeof(pid_t));
- if (*pids == NULL) {
+ *ipcps = malloc(nr * sizeof(**ipcps));
+ if (*ipcps == NULL) {
irm_msg__free_unpacked(recv_msg, NULL);
return -ENOMEM;
}
- for (i = 0; i < nr; i++)
- (*pids)[i] = recv_msg->pids[i];
+ for (i = 0; i < nr; i++) {
+ (*ipcps)[i].pid = recv_msg->ipcps[i]->pid;
+ (*ipcps)[i].type = recv_msg->ipcps[i]->type;
+ strcpy((*ipcps)[i].name, recv_msg->ipcps[i]->name);
+ strcpy((*ipcps)[i].layer, recv_msg->ipcps[i]->layer);
+ }
irm_msg__free_unpacked(recv_msg, NULL);
@@ -262,30 +271,23 @@ ssize_t irm_list_ipcps(const char * name,
}
int irm_enroll_ipcp(pid_t pid,
- const char * layer_name)
+ const char * dst)
{
irm_msg_t msg = IRM_MSG__INIT;
irm_msg_t * recv_msg = NULL;
int ret = -1;
- if (pid == -1 || layer_name == NULL)
+ if (pid == -1 || dst == NULL)
return -EINVAL;
msg.code = IRM_MSG_CODE__IRM_ENROLL_IPCP;
msg.has_pid = true;
msg.pid = pid;
- msg.n_layer_name = 1;
- msg.layer_name = malloc(sizeof(*(msg.layer_name)));
- if (msg.layer_name == NULL)
- return -ENOMEM;
-
- msg.layer_name[0] = (char *) layer_name;
+ msg.dst = (char *) dst;
recv_msg = send_recv_irm_msg(&msg);
- if (recv_msg == NULL) {
- free(msg.layer_name);
+ if (recv_msg == NULL)
return -EIRMD;
- }
if (!recv_msg->has_result) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -295,7 +297,6 @@ int irm_enroll_ipcp(pid_t pid,
ret = recv_msg->result;
irm_msg__free_unpacked(recv_msg, NULL);
- free(msg.layer_name);
return ret;
}
@@ -403,9 +404,9 @@ int irm_bind_program(const char * prog,
return ret;
}
- msg.code = IRM_MSG_CODE__IRM_BIND_PROGRAM;
- msg.dst_name = (char *) name;
- msg.prog_name = full_name;
+ msg.code = IRM_MSG_CODE__IRM_BIND_PROGRAM;
+ msg.name = (char *) name;
+ msg.prog = full_name;
if (argv != NULL) {
msg.n_args = argc;
@@ -443,10 +444,10 @@ int irm_bind_process(pid_t pid,
if (name == NULL)
return -EINVAL;
- msg.code = IRM_MSG_CODE__IRM_BIND_PROCESS;
- msg.has_pid = true;
- msg.pid = pid;
- msg.dst_name = (char *) name;
+ msg.code = IRM_MSG_CODE__IRM_BIND_PROCESS;
+ msg.has_pid = true;
+ msg.pid = pid;
+ msg.name = (char *) name;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
@@ -473,9 +474,9 @@ int irm_unbind_program(const char * prog,
if (name == NULL)
return -EINVAL;
- msg.code = IRM_MSG_CODE__IRM_UNBIND_PROGRAM;
- msg.prog_name = (char *) prog;
- msg.dst_name = (char *) name;
+ msg.code = IRM_MSG_CODE__IRM_UNBIND_PROGRAM;
+ msg.prog = (char *) prog;
+ msg.name = (char *) name;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
@@ -502,10 +503,10 @@ int irm_unbind_process(pid_t pid,
if (name == NULL)
return -EINVAL;
- msg.code = IRM_MSG_CODE__IRM_UNBIND_PROCESS;
- msg.has_pid = true;
- msg.pid = pid;
- msg.dst_name = (char *) name;
+ msg.code = IRM_MSG_CODE__IRM_UNBIND_PROCESS;
+ msg.has_pid = true;
+ msg.pid = pid;
+ msg.name = (char *) name;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
@@ -522,23 +523,20 @@ int irm_unbind_process(pid_t pid,
return ret;
}
-int irm_reg(const char * name,
- char ** layers,
- size_t len)
+int irm_reg(pid_t pid,
+ const char * name)
{
irm_msg_t msg = IRM_MSG__INIT;
irm_msg_t * recv_msg = NULL;
int ret = -1;
- if (name == NULL || layers == NULL || len == 0)
+ if (name == NULL)
return -EINVAL;
- msg.code = IRM_MSG_CODE__IRM_REG;
-
- msg.dst_name = (char *) name;
-
- msg.layer_name = layers;
- msg.n_layer_name = len;
+ msg.code = IRM_MSG_CODE__IRM_REG;
+ msg.has_pid = true;
+ msg.pid = pid;
+ msg.name = (char *) name;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
@@ -556,23 +554,20 @@ int irm_reg(const char * name,
}
-int irm_unreg(const char * name,
- char ** layers,
- size_t len)
+int irm_unreg(pid_t pid,
+ const char * name)
{
irm_msg_t msg = IRM_MSG__INIT;
irm_msg_t * recv_msg = NULL;
int ret = -1;
- if (name == NULL || layers == NULL || len == 0)
+ if (name == NULL)
return -EINVAL;
- msg.code = IRM_MSG_CODE__IRM_UNREG;
-
- msg.dst_name = (char *) name;
-
- msg.layer_name = (char **) layers;
- msg.n_layer_name = len;
+ msg.code = IRM_MSG_CODE__IRM_UNREG;
+ msg.has_pid = true;
+ msg.pid = pid;
+ msg.name = (char *) name;
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 51b15023..16dfe828 100644
--- a/src/lib/irmd_messages.proto
+++ b/src/lib/irmd_messages.proto
@@ -48,23 +48,31 @@ enum irm_msg_code {
IRM_REPLY = 21;
};
+message ipcp_info_msg {
+ required uint32 pid = 1;
+ required uint32 type = 2;
+ required string name = 3;
+ required string layer = 4;
+};
+
message irm_msg {
required irm_msg_code code = 1;
- optional string prog_name = 2;
+ optional string prog = 2;
optional sint32 pid = 3;
- optional uint32 ipcp_type = 4;
- repeated string layer_name = 5;
- repeated string args = 6;
- optional sint32 response = 7;
- optional string dst_name = 8;
- optional bytes hash = 9;
- optional sint32 port_id = 10;
- optional sint32 qoscube = 11;
- optional ipcp_config_msg conf = 12;
- optional uint32 opts = 13;
- repeated sint32 pids = 14;
- optional uint32 timeo_sec = 15;
- optional uint32 timeo_nsec = 16;
- optional string comp_name = 17;
- optional sint32 result = 18;
+ optional string name = 4;
+ optional uint32 ipcp_type = 5;
+ optional string layer = 6;
+ repeated string args = 7;
+ optional sint32 response = 8;
+ optional string dst = 9;
+ optional bytes hash = 10;
+ optional sint32 port_id = 11;
+ optional sint32 qoscube = 12;
+ optional ipcp_config_msg conf = 13;
+ optional uint32 opts = 14;
+ repeated ipcp_info_msg ipcps = 15;
+ optional uint32 timeo_sec = 16;
+ optional uint32 timeo_nsec = 17;
+ optional string comp = 18;
+ optional sint32 result = 19;
};