diff options
author | Sander Vrijders <[email protected]> | 2016-03-17 14:37:49 +0100 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2016-03-17 14:37:49 +0100 |
commit | 722b769e4d519f2428ee893a78cafa999151bb1c (patch) | |
tree | ed681973bedcb9039de26c0d83baa9d5d5f3a22e /src/lib/ipcp.c | |
parent | 7747528435d77ad055a5c3124a89717e42807b9a (diff) | |
download | ouroboros-722b769e4d519f2428ee893a78cafa999151bb1c.tar.gz ouroboros-722b769e4d519f2428ee893a78cafa999151bb1c.zip |
lib: Add communication with IPCP daemon
This adds the messages required for the IRMd to communicate with an
IPC Process through the library.
Diffstat (limited to 'src/lib/ipcp.c')
-rw-r--r-- | src/lib/ipcp.c | 108 |
1 files changed, 104 insertions, 4 deletions
diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c index 294d518c..7870e478 100644 --- a/src/lib/ipcp.c +++ b/src/lib/ipcp.c @@ -31,6 +31,7 @@ #include <ouroboros/logs.h> #include <ouroboros/config.h> #include <ouroboros/utils.h> +#include <ouroboros/sockets.h> #include <stdlib.h> #include <string.h> @@ -38,6 +39,45 @@ #include <sys/types.h> #include <sys/wait.h> +static int send_ipcp_msg(pid_t pid, + struct ipcp_msg * msg) +{ + int sockfd = 0; + buffer_t * buf = NULL; + char * sock_path; + + sock_path = ipcp_sock_path(pid); + if (sock_path == NULL) + return -1; + + sockfd = client_socket_open(sock_path); + if (sockfd < 0) { + free(sock_path); + return -1; + } + + buf = serialize_ipcp_msg(msg); + if (buf == NULL) { + free(sock_path); + close(sockfd); + return -1; + } + + if (write(sockfd, buf->data, buf->size) == -1) { + free(sock_path); + free(buf->data); + free(buf); + close(sockfd); + return -1; + } + + free(buf->data); + free(buf); + + close(sockfd); + return 0; +} + pid_t ipcp_create(rina_name_t name, char * ipcp_type) { @@ -48,6 +88,9 @@ pid_t ipcp_create(rina_name_t name, char * ipcp_dir = "bin/ipcpd"; char * full_name = NULL; + if (ipcp_type == NULL) + return -1; + pid = fork(); if (pid == -1) { LOG_ERR("Failed to fork"); @@ -121,20 +164,58 @@ int ipcp_reg(pid_t pid, char ** difs, size_t difs_size) { - return -1; + struct ipcp_msg msg; + + if (difs == NULL) + return -1; + + msg.code = IPCP_REG; + msg.difs = difs; + msg.difs_size = difs_size; + + if (send_ipcp_msg(pid, &msg)) { + LOG_ERR("Failed to send message to daemon"); + return -1; + } + + return 0; } int ipcp_unreg(pid_t pid, char ** difs, size_t difs_size) { - return -1; + struct ipcp_msg msg; + + if (difs == NULL) + return -1; + + msg.code = IPCP_UNREG; + msg.difs = difs; + msg.difs_size = difs_size; + + if (send_ipcp_msg(pid, &msg)) { + LOG_ERR("Failed to send message to daemon"); + return -1; + } + + return 0; } int ipcp_bootstrap(pid_t pid, struct dif_config conf) { - return -1; + struct ipcp_msg msg; + + msg.code = IPCP_BOOTSTRAP; + msg.conf = &conf; + + if (send_ipcp_msg(pid, &msg)) { + LOG_ERR("Failed to send message to daemon"); + return -1; + } + + return 0; } int ipcp_enroll(pid_t pid, @@ -143,5 +224,24 @@ int ipcp_enroll(pid_t pid, char ** n_1_difs, ssize_t n_1_difs_size) { - return -1; + struct ipcp_msg msg; + + if (n_1_difs == NULL) + return -1; + + if (dif_name == NULL) + return -1; + + msg.code = IPCP_ENROLL; + msg.dif_name = dif_name; + msg.member = &member; + msg.difs = n_1_difs; + msg.difs_size = n_1_difs_size; + + if (send_ipcp_msg(pid, &msg)) { + LOG_ERR("Failed to send message to daemon"); + return -1; + } + + return 0; } |