diff options
author | Sander Vrijders <[email protected]> | 2016-03-01 15:43:41 +0100 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2016-03-01 15:43:41 +0100 |
commit | 52a5113760802e16b07d9d954237871d52cff70a (patch) | |
tree | 07b806048cc9a792b5127bd5decb81b7ca907197 /src/lib/irm.c | |
parent | e5bfc52e93654a8be7893cf5573c9c04e9c96c55 (diff) | |
parent | 45ad14035a06e4947b1cc1d908bb665646c1f2a0 (diff) | |
download | ouroboros-52a5113760802e16b07d9d954237871d52cff70a.tar.gz ouroboros-52a5113760802e16b07d9d954237871d52cff70a.zip |
Merged in sandervrijders/ouroboros/be (pull request #17)
lib, irmd, tools: Provide more IRM messages
Diffstat (limited to 'src/lib/irm.c')
-rw-r--r-- | src/lib/irm.c | 116 |
1 files changed, 84 insertions, 32 deletions
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 <ouroboros/logs.h> #include <ouroboros/sockets.h> +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; } |