summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-03-30 17:25:30 +0200
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-03-30 18:02:25 +0200
commit08941177f030b77fb44238a7e589322d2e0fcaa2 (patch)
treee823d98180ea74d476466a862223a69d52308ffd /src
parenta3f002d6f2d102588f988c99eb16c64a68706dd2 (diff)
downloadouroboros-08941177f030b77fb44238a7e589322d2e0fcaa2.tar.gz
ouroboros-08941177f030b77fb44238a7e589322d2e0fcaa2.zip
lib, irmd: Update communication with IRMd
All messages sent to the IRMd now also get a reply back with the result of the operation.
Diffstat (limited to 'src')
-rw-r--r--src/irmd/main.c311
-rw-r--r--src/lib/dev.c78
-rw-r--r--src/lib/ipcp.c8
-rw-r--r--src/lib/irm.c92
-rw-r--r--src/lib/irmd_messages.proto23
-rw-r--r--src/lib/sockets.c35
-rw-r--r--src/lib/tests/shm_du_map_test.c1
7 files changed, 374 insertions, 174 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 547286e8..af0f85e2 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -46,8 +46,9 @@ struct irm {
struct list_head name_to_pid;
};
-static pid_t find_pid_by_name(struct irm * instance,
- instance_name_t * api)
+struct irm * instance = NULL;
+
+static pid_t find_pid_by_name(instance_name_t * api)
{
struct list_head * pos;
@@ -64,9 +65,8 @@ static pid_t find_pid_by_name(struct irm * instance,
return 0;
}
-static void create_ipcp(struct irm * instance,
- instance_name_t * api,
- char * ipcp_type)
+static int create_ipcp(instance_name_t * api,
+ char * ipcp_type)
{
pid_t pid;
struct name_to_pid_entry * tmp;
@@ -74,12 +74,12 @@ static void create_ipcp(struct irm * instance,
pid = ipcp_create(api, ipcp_type);
if (pid == -1) {
LOG_ERR("Failed to create IPCP");
- return;
+ return -1;
}
tmp = malloc(sizeof(*tmp));
if (tmp == NULL)
- return;
+ return -1;
INIT_LIST_HEAD(&tmp->next);
@@ -87,25 +87,25 @@ static void create_ipcp(struct irm * instance,
tmp->api = instance_name_dup(api);
if (tmp->api == NULL) {
free(tmp);
- return;
+ return -1;
}
LOG_DBG("Created IPC process with pid %d", pid);
list_add(&tmp->next, &instance->name_to_pid);
+ return 0;
}
-static void destroy_ipcp(struct irm * instance,
- instance_name_t * api)
+static int destroy_ipcp(instance_name_t * api)
{
pid_t pid = 0;
struct list_head * pos;
struct list_head * n;
- pid = find_pid_by_name(instance, api);
+ pid = find_pid_by_name(api);
if (pid == 0) {
LOG_ERR("No such IPCP");
- return;
+ return -1;
}
LOG_DBG("Destroying ipcp with pid %d", pid);
@@ -120,92 +120,159 @@ static void destroy_ipcp(struct irm * instance,
if (instance_name_cmp(api, tmp->api) == 0)
list_del(&tmp->next);
}
+
+ return 0;
}
-static void bootstrap_ipcp(struct irm * instance,
- instance_name_t * api,
- struct dif_config * conf)
+static int bootstrap_ipcp(instance_name_t * api,
+ struct dif_config * conf)
{
pid_t pid = 0;
- pid = find_pid_by_name(instance, api);
+ pid = find_pid_by_name(api);
if (pid == 0) {
LOG_ERR("No such IPCP");
- return;
+ return -1;
}
- if (ipcp_bootstrap(pid, conf))
+ if (ipcp_bootstrap(pid, conf)) {
LOG_ERR("Could not bootstrap IPCP");
+ return -1;
+ }
+
+ return 0;
}
-static void enroll_ipcp(struct irm * instance,
- instance_name_t * api,
- char * dif_name)
+static int enroll_ipcp(instance_name_t * api,
+ char * dif_name)
{
pid_t pid = 0;
char * member;
char ** n_1_difs = NULL;
ssize_t n_1_difs_size = 0;
- pid = find_pid_by_name(instance, api);
+ pid = find_pid_by_name(api);
if (pid == 0) {
LOG_ERR("No such IPCP");
- return;
+ return -1;
}
member = da_resolve_daf(dif_name);
if (member == NULL) {
LOG_ERR("Could not find a member of that DIF");
- return;
+ return -1;
}
n_1_difs_size = da_resolve_dap(member, n_1_difs);
if (n_1_difs_size != 0)
if (ipcp_enroll(pid, dif_name, member,
- n_1_difs, n_1_difs_size))
+ n_1_difs, n_1_difs_size)) {
LOG_ERR("Could not enroll IPCP");
+ return -1;
+ }
+
+ return 0;
}
-static void reg_ipcp(struct irm * instance,
- instance_name_t * api,
- char ** difs,
- size_t difs_size)
+static int reg_ipcp(instance_name_t * api,
+ char ** difs,
+ size_t difs_size)
{
pid_t pid = 0;
- pid = find_pid_by_name(instance, api);
+ pid = find_pid_by_name(api);
if (pid == 0) {
LOG_ERR("No such IPCP");
- return;
+ return -1;
}
- if (ipcp_reg(pid, difs, difs_size))
+ if (ipcp_reg(pid, difs, difs_size)) {
LOG_ERR("Could not register IPCP to N-1 DIF(s)");
+ return -1;
+ }
+
+ return 0;
}
-static void unreg_ipcp(struct irm * instance,
- instance_name_t * api,
- char ** difs,
- size_t difs_size)
+static int unreg_ipcp(instance_name_t * api,
+ char ** difs,
+ size_t difs_size)
{
pid_t pid = 0;
- pid = find_pid_by_name(instance, api);
+ pid = find_pid_by_name(api);
if (pid == 0) {
LOG_ERR("No such IPCP");
- return;
+ return -1;
}
- if (ipcp_unreg(pid, difs, difs_size))
+ if (ipcp_unreg(pid, difs, difs_size)) {
LOG_ERR("Could not unregister IPCP from N-1 DIF(s)");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int ap_reg(char * ap_name,
+ char ** difs,
+ size_t difs_size)
+{
+ return -1;
+}
+
+static int ap_unreg(char * ap_name,
+ char ** difs,
+ size_t difs_size)
+{
+ return -1;
+}
+
+static int flow_accept(int fd,
+ char * ap_name,
+ char * ae_name)
+{
+ return -1;
+}
+
+static int flow_alloc_resp(int fd,
+ int result)
+{
+
+ return -1;
+}
+
+static int flow_alloc(char * dst_ap_name,
+ char * src_ap_name,
+ char * src_ae_name,
+ struct qos_spec * qos,
+ int oflags)
+{
+ return -1;
+}
+
+static int flow_alloc_res(int fd)
+{
+
+ return -1;
+}
+
+static int flow_dealloc(int fd)
+{
+ return -1;
+}
+
+static int flow_cntl(int fd,
+ int oflags)
+{
+ return -1;
}
/* FIXME: Close sockfd on closing and release irm */
int main()
{
- struct irm * instance = NULL;
- int sockfd;
- uint8_t buf[IRM_MSG_BUF_SIZE];
+ int sockfd;
+ uint8_t buf[IRM_MSG_BUF_SIZE];
instance = malloc(sizeof(*instance));
if (instance == NULL)
@@ -222,6 +289,10 @@ int main()
irm_msg_t * msg;
ssize_t count;
instance_name_t api;
+ buffer_t buffer;
+ irm_msg_t ret_msg = IRM_MSG__INIT;
+
+ ret_msg.code = IRM_MSG_CODE__IRM_REPLY;
cli_sockfd = accept(sockfd, 0, 0);
if (cli_sockfd < 0) {
@@ -230,47 +301,125 @@ int main()
}
count = read(cli_sockfd, buf, IRM_MSG_BUF_SIZE);
- if (count > 0) {
- msg = irm_msg__unpack(NULL, count, buf);
- if (msg == NULL)
- continue;
-
- api.name = msg->ap_name;
- api.id = msg->api_id;
-
- switch (msg->code) {
- case IRM_MSG_CODE__IRM_CREATE_IPCP:
- create_ipcp(instance, &api, msg->ipcp_type);
- break;
- case IRM_MSG_CODE__IRM_DESTROY_IPCP:
- destroy_ipcp(instance, &api);
- break;
- case IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP:
- bootstrap_ipcp(instance, &api, NULL);
- break;
- case IRM_MSG_CODE__IRM_ENROLL_IPCP:
- if (msg->n_dif_name != 1)
- continue;
- enroll_ipcp(instance, &api, msg->dif_name[0]);
- break;
- case IRM_MSG_CODE__IRM_REG_IPCP:
- reg_ipcp(instance, &api,
- msg->dif_name,
- msg->n_dif_name);
- break;
- case IRM_MSG_CODE__IRM_UNREG_IPCP:
- unreg_ipcp(instance, &api,
- msg->dif_name,
- msg->n_dif_name);
- break;
- default:
- LOG_ERR("Don't know that message code");
- break;
- }
-
- irm_msg__free_unpacked(msg, NULL);
+ if (count <= 0) {
+ LOG_ERR("Failed to read from socket");
+ close(cli_sockfd);
+ continue;
+ }
+
+ msg = irm_msg__unpack(NULL, count, buf);
+ if (msg == NULL) {
+ close(cli_sockfd);
+ continue;
+ }
+
+ api.name = msg->ap_name;
+ api.id = msg->api_id;
+
+ switch (msg->code) {
+ case IRM_MSG_CODE__IRM_CREATE_IPCP:
+ ret_msg.has_result = true;
+ ret_msg.result = create_ipcp(&api,
+ msg->ipcp_type);
+ break;
+ case IRM_MSG_CODE__IRM_DESTROY_IPCP:
+ ret_msg.has_result = true;
+ ret_msg.result = destroy_ipcp(&api);
+ break;
+ case IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP:
+ ret_msg.has_result = true;
+ ret_msg.result = bootstrap_ipcp(&api, NULL);
+ break;
+ case IRM_MSG_CODE__IRM_ENROLL_IPCP:
+ ret_msg.has_result = true;
+ ret_msg.result = enroll_ipcp(&api,
+ msg->dif_name[0]);
+ break;
+ case IRM_MSG_CODE__IRM_REG_IPCP:
+ ret_msg.has_result = true;
+ ret_msg.result = reg_ipcp(&api,
+ msg->dif_name,
+ msg->n_dif_name);
+ break;
+ case IRM_MSG_CODE__IRM_UNREG_IPCP:
+ ret_msg.has_result = true;
+ ret_msg.result = unreg_ipcp(&api,
+ msg->dif_name,
+ msg->n_dif_name);
+ break;
+ case IRM_MSG_CODE__IRM_AP_REG:
+ ret_msg.has_fd = true;
+ ret_msg.fd = ap_reg(msg->ap_name,
+ msg->dif_name,
+ msg->n_dif_name);
+ break;
+ case IRM_MSG_CODE__IRM_AP_UNREG:
+ ret_msg.has_result = true;
+ ret_msg.result = ap_unreg(msg->ap_name,
+ msg->dif_name,
+ msg->n_dif_name);
+ break;
+ case IRM_MSG_CODE__IRM_FLOW_ACCEPT:
+ ret_msg.has_fd = true;
+ ret_msg.fd = flow_accept(msg->fd,
+ ret_msg.ap_name,
+ ret_msg.ae_name);
+ break;
+ case IRM_MSG_CODE__IRM_FLOW_ALLOC_RESP:
+ ret_msg.has_result = true;
+ ret_msg.result = flow_alloc_resp(msg->fd,
+ msg->result);
+ break;
+ case IRM_MSG_CODE__IRM_FLOW_ALLOC:
+ ret_msg.has_fd = true;
+ ret_msg.fd = flow_alloc(msg->dst_ap_name,
+ msg->ap_name,
+ msg->ae_name,
+ NULL,
+ msg->oflags);
+ break;
+ case IRM_MSG_CODE__IRM_FLOW_ALLOC_RES:
+ ret_msg.has_result = true;
+ ret_msg.result = flow_alloc_res(msg->fd);
+ break;
+ case IRM_MSG_CODE__IRM_FLOW_DEALLOC:
+ ret_msg.has_result = true;
+ ret_msg.result = flow_dealloc(msg->fd);
+ break;
+ case IRM_MSG_CODE__IRM_FLOW_CONTROL:
+ ret_msg.has_result = true;
+ ret_msg.result = flow_cntl(msg->fd,
+ msg->oflags);
+ break;
+ default:
+ LOG_ERR("Don't know that message code");
+ break;
+ }
+
+ irm_msg__free_unpacked(msg, NULL);
+
+ buffer.size = irm_msg__get_packed_size(&ret_msg);
+ if (buffer.size == 0) {
+ LOG_ERR("Failed to send reply message");
+ close(cli_sockfd);
+ continue;
+ }
+
+ buffer.data = malloc(buffer.size);
+ if (buffer.data == NULL) {
+ close(cli_sockfd);
+ continue;
+ }
+
+ irm_msg__pack(&ret_msg, buffer.data);
+
+ if (write(cli_sockfd, buffer.data, buffer.size) == -1) {
+ free(buffer.data);
+ close(cli_sockfd);
+ continue;
}
+ free(buffer.data);
close(cli_sockfd);
}
diff --git a/src/lib/dev.c b/src/lib/dev.c
index 5c11d8bf..c138b009 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -49,7 +49,11 @@ int ap_reg(char * ap_name,
msg.n_dif_name = difs_size;
recv_msg = send_recv_irm_msg(&msg);
- if (recv_msg == NULL) {
+ if (recv_msg == NULL)
+ return -1;
+
+ if (recv_msg->has_fd == false) {
+ irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
@@ -64,6 +68,8 @@ int ap_unreg(char * ap_name,
size_t difs_size)
{
irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
if (ap_name == NULL ||
difs == NULL ||
@@ -77,12 +83,19 @@ int ap_unreg(char * ap_name,
msg.dif_name = difs;
msg.n_dif_name = difs_size;
- if (send_irm_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ 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;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
int flow_accept(int fd,
@@ -102,9 +115,8 @@ int flow_accept(int fd,
msg.fd = fd;
recv_msg = send_recv_irm_msg(&msg);
- if (recv_msg == NULL) {
+ if (recv_msg == NULL)
return -1;
- }
if (recv_msg->has_fd == false) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -122,6 +134,8 @@ int flow_alloc_resp(int fd,
int result)
{
irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC_RESP;
msg.has_fd = true;
@@ -129,12 +143,19 @@ int flow_alloc_resp(int fd,
msg.has_result = true;
msg.result = result;
- if (send_irm_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ 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;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
int flow_alloc(char * dst_ap_name,
@@ -150,8 +171,7 @@ int flow_alloc(char * dst_ap_name,
if (dst_ap_name == NULL ||
src_ap_name == NULL ||
qos == NULL) {
- LOG_ERR("Invalid arguments");
- return -1;
+ return -EINVAL;
}
msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC;
@@ -162,9 +182,8 @@ int flow_alloc(char * dst_ap_name,
msg.oflags = oflags;
recv_msg = send_recv_irm_msg(&msg);
- if (recv_msg == NULL) {
+ if (recv_msg == NULL)
return -1;
- }
if (recv_msg->has_fd == false) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -187,9 +206,8 @@ int flow_alloc_res(int fd)
msg.fd = fd;
recv_msg = send_recv_irm_msg(&msg);
- if (recv_msg == NULL) {
+ if (recv_msg == NULL)
return -1;
- }
if (recv_msg->has_result == false) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -205,33 +223,51 @@ int flow_alloc_res(int fd)
int flow_dealloc(int fd)
{
irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
msg.code = IRM_MSG_CODE__IRM_FLOW_DEALLOC;
msg.has_fd = true;
msg.fd = fd;
- if (send_irm_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ 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;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
int flow_cntl(int fd, int oflags)
{
irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
msg.has_fd = true;
msg.fd = fd;
msg.oflags = oflags;
- if (send_irm_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ 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;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
ssize_t flow_write(int fd,
diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c
index 60d5879e..2caeaad3 100644
--- a/src/lib/ipcp.c
+++ b/src/lib/ipcp.c
@@ -22,14 +22,10 @@
#define OUROBOROS_PREFIX "lib-ipcp"
-#ifndef _POSIX_C_SOURCE
-#define _POSIX_C_SOURCE 199506L
-#endif
-
+#include <ouroboros/config.h>
#include <ouroboros/ipcp.h>
#include <ouroboros/common.h>
#include <ouroboros/logs.h>
-#include <ouroboros/config.h>
#include <ouroboros/utils.h>
#include <ouroboros/sockets.h>
@@ -97,6 +93,8 @@ pid_t ipcp_create(instance_name_t * api,
if (ipcp_type == NULL)
return -1;
+ LOG_DBG("%lu", _POSIX_C_SOURCE);
+
pid = fork();
if (pid == -1) {
LOG_ERR("Failed to fork");
diff --git a/src/lib/irm.c b/src/lib/irm.c
index 644e1113..7c187be1 100644
--- a/src/lib/irm.c
+++ b/src/lib/irm.c
@@ -34,6 +34,8 @@ int irm_create_ipcp(instance_name_t * api,
char * ipcp_type)
{
irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
if (api == NULL || ipcp_type == NULL || api->name == NULL)
return -EINVAL;
@@ -44,17 +46,26 @@ int irm_create_ipcp(instance_name_t * api,
msg.api_id = api->id;
msg.ipcp_type = ipcp_type;
- if (send_irm_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ 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;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
int irm_destroy_ipcp(instance_name_t * api)
{
irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
if (api == NULL || api->name == NULL)
return -EINVAL;
@@ -64,18 +75,27 @@ int irm_destroy_ipcp(instance_name_t * api)
msg.has_api_id = true;
msg.api_id = api->id;
- if (send_irm_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ 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;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
int irm_bootstrap_ipcp(instance_name_t * api,
struct dif_config * conf)
{
irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
if (api == NULL || api->name == NULL || conf == NULL)
return -EINVAL;
@@ -85,18 +105,27 @@ int irm_bootstrap_ipcp(instance_name_t * api,
msg.has_api_id = true;
msg.api_id = api->id;
- if (send_irm_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ 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;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
int irm_enroll_ipcp(instance_name_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)
return -EINVAL;
@@ -113,15 +142,22 @@ int irm_enroll_ipcp(instance_name_t * api,
}
msg.dif_name[0] = dif_name;
- if (send_irm_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ recv_msg = send_recv_irm_msg(&msg);
+ if (recv_msg == NULL) {
free(msg.dif_name);
return -1;
}
- free(msg.dif_name);
+ 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 0;
+ free(msg.dif_name);
+ return ret;
}
int irm_reg_ipcp(instance_name_t * api,
@@ -129,6 +165,8 @@ int irm_reg_ipcp(instance_name_t * api,
size_t difs_size)
{
irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
if (api->name == NULL ||
difs == NULL ||
@@ -144,12 +182,19 @@ int irm_reg_ipcp(instance_name_t * api,
msg.dif_name = difs;
msg.n_dif_name = difs_size;
- if (send_irm_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ 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;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
int irm_unreg_ipcp(const instance_name_t * api,
@@ -157,6 +202,8 @@ int irm_unreg_ipcp(const instance_name_t * api,
size_t difs_size)
{
irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
+ int ret = -1;
if (api == NULL ||
api->name == NULL ||
@@ -173,10 +220,17 @@ int irm_unreg_ipcp(const instance_name_t * api,
msg.dif_name = difs;
msg.n_dif_name = difs_size;
- if (send_irm_msg(&msg)) {
- LOG_ERR("Failed to send message to daemon");
+ 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;
}
- return 0;
+ ret = recv_msg->result;
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ return ret;
}
diff --git a/src/lib/irmd_messages.proto b/src/lib/irmd_messages.proto
index c61d1b6d..a524a7fb 100644
--- a/src/lib/irmd_messages.proto
+++ b/src/lib/irmd_messages.proto
@@ -6,19 +6,16 @@ enum irm_msg_code {
IRM_REG_IPCP = 5;
IRM_UNREG_IPCP = 6;
IRM_AP_REG = 7;
- IRM_AP_REG_R = 8;
- IRM_AP_UNREG = 9;
- IRM_FLOW_ACCEPT = 10;
- IRM_FLOW_ACCEPT_R = 11;
- IRM_FLOW_ALLOC_RESP = 12;
- IRM_FLOW_ALLOC = 13;
- IRM_FLOW_ALLOC_R = 14;
- IRM_FLOW_ALLOC_RES = 15;
- IRM_FLOW_ALLOC_RES_R = 16;
- IRM_FLOW_DEALLOC = 17;
- IRM_FLOW_CONTROL = 18;
- IRM_FLOW_WRITE = 19;
- IRM_FLOW_READ = 20;
+ IRM_AP_UNREG = 8;
+ IRM_FLOW_ACCEPT = 9;
+ IRM_FLOW_ALLOC_RESP = 10;
+ IRM_FLOW_ALLOC = 11;
+ IRM_FLOW_ALLOC_RES = 12;
+ IRM_FLOW_DEALLOC = 13;
+ IRM_FLOW_CONTROL = 14;
+ IRM_FLOW_WRITE = 15;
+ IRM_FLOW_READ = 16;
+ IRM_REPLY = 17;
};
message irm_msg {
diff --git a/src/lib/sockets.c b/src/lib/sockets.c
index a699206d..f9024f70 100644
--- a/src/lib/sockets.c
+++ b/src/lib/sockets.c
@@ -96,41 +96,6 @@ int server_socket_open(char * file_name)
return sockfd;
}
-int send_irm_msg(irm_msg_t * msg)
-{
- int sockfd;
- buffer_t buf;
-
- sockfd = client_socket_open(IRM_SOCK_PATH);
- if (sockfd < 0)
- return -1;
-
- buf.size = irm_msg__get_packed_size(msg);
- if (buf.size == 0) {
- close(sockfd);
- return -1;
- }
-
- buf.data = malloc(buf.size);
- if (buf.data == NULL) {
- close(sockfd);
- return -ENOMEM;
- }
-
- irm_msg__pack(msg, buf.data);
-
- if (write(sockfd, buf.data, buf.size) == -1) {
- free(buf.data);
- close(sockfd);
- return -1;
- }
-
- free(buf.data);
-
- close(sockfd);
- return 0;
-}
-
irm_msg_t * send_recv_irm_msg(irm_msg_t * msg)
{
int sockfd;
diff --git a/src/lib/tests/shm_du_map_test.c b/src/lib/tests/shm_du_map_test.c
index f636c941..85a82e4d 100644
--- a/src/lib/tests/shm_du_map_test.c
+++ b/src/lib/tests/shm_du_map_test.c
@@ -20,6 +20,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <ouroboros/config.h>
#include <ouroboros/shm_du_map.h>
#include <sys/types.h>
#include <stdlib.h>