summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-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
6 files changed, 144 insertions, 93 deletions
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>