From 45ad14035a06e4947b1cc1d908bb665646c1f2a0 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Tue, 1 Mar 2016 15:08:37 +0100 Subject: lib, irmd, tools: Provide more IRM messages This provides the other messages that are used to communicate between the library and the IRM Daemon. The IRM tool just calls the library right now to see if it works. A full fledged program will be provided in a next commit. --- src/lib/irm.c | 116 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 84 insertions(+), 32 deletions(-) (limited to 'src/lib/irm.c') diff --git a/src/lib/irm.c b/src/lib/irm.c index 69a98039..97000029 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -27,81 +27,133 @@ #include #include +static int send_irm_msg(struct irm_msg * msg) +{ + int sockfd; + buffer_t * buf; + + sockfd = client_socket_open(IRM_SOCK_PATH); + if (sockfd < 0) + return -1; + + buf = serialize_irm_msg(msg); + if (buf == NULL) { + close(sockfd); + return -1; + } + + if (write(sockfd, buf->data, buf->size) == -1) { + close(sockfd); + return -1; + } + + close(sockfd); + return 0; +} + int irm_create_ipcp(rina_name_t name, char * ipcp_type) { - int sockfd; struct irm_msg msg; - buffer_t * buf; if (ipcp_type == NULL) return -1; - sockfd = client_socket_open(IRM_SOCK_PATH); - if (sockfd < 0) - return -1; - msg.code = IRM_CREATE_IPCP; - msg.msgs.create_ipcp.name = &name; - msg.msgs.create_ipcp.ipcp_type = ipcp_type; - - buf = serialize_irm_msg(&msg); - if (buf == NULL) { - close(sockfd); - return -1; - } + msg.name = &name; + msg.ipcp_type = ipcp_type; - if (write(sockfd, buf->data, buf->size) == -1) { - close(sockfd); + if (send_irm_msg(&msg)) { + LOG_ERR("Failed to send message to daemon"); return -1; } - close(sockfd); return 0; } -int irm_destroy_ipcp(int ipcp_id) +int irm_destroy_ipcp(rina_name_t name) { + struct irm_msg msg; + + msg.code = IRM_DESTROY_IPCP; + msg.name = &name; + + if (send_irm_msg(&msg)) { + LOG_ERR("Failed to send message to daemon"); + return -1; + } return 0; } -int irm_bootstrap_ipcp(int ipcp_id, +int irm_bootstrap_ipcp(rina_name_t name, struct dif_info info) { + struct irm_msg msg; + + msg.code = IRM_BOOTSTRAP_IPCP; + msg.name = &name; + msg.info = &info; + + if (send_irm_msg(&msg)) { + LOG_ERR("Failed to send message to daemon"); + return -1; + } return 0; } -int irm_enroll_ipcp(int ipcp_id, +int irm_enroll_ipcp(rina_name_t name, char * dif_name) { + struct irm_msg msg; - return 0; -} + msg.code = IRM_ENROLL_IPCP; + msg.name = &name; + msg.dif_name = dif_name; -int irm_reg_ipcp(int ipcp_id, - char ** difs) -{ + if (send_irm_msg(&msg)) { + LOG_ERR("Failed to send message to daemon"); + return -1; + } return 0; } -int irm_unreg_ipcp(int ipcp_id, - char ** difs) +int irm_reg_ipcp(rina_name_t name, + char ** difs, + size_t difs_size) { + struct irm_msg msg; - return 0; -} + msg.code = IRM_REG_IPCP; + msg.name = &name; + msg.difs = difs; + msg.difs_size = difs_size; -char ** irm_list_ipcps() -{ + if (send_irm_msg(&msg)) { + LOG_ERR("Failed to send message to daemon"); + return -1; + } return 0; } -char ** irm_list_ipcp_types() +int irm_unreg_ipcp(rina_name_t name, + char ** difs, + size_t difs_size) { + struct irm_msg msg; + + msg.code = IRM_UNREG_IPCP; + msg.name = &name; + msg.difs = difs; + msg.difs_size = difs_size; + + if (send_irm_msg(&msg)) { + LOG_ERR("Failed to send message to daemon"); + return -1; + } return 0; } -- cgit v1.2.3