From 037fec33cda726d0078e23798f462ad273153dd5 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sat, 14 May 2016 16:39:27 +0200 Subject: ipcpd: shim-udp: complete locking Added necessary locks for the shim-udp. This PR also improves thread management, the main thread now starts a mainloop thread, which spawns sdu handler threads when it the IPCP is enrolled. If the IPCP exits the enrolled state, the sdu loop is cancelled. --- src/ipcpd/ipcp.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'src/ipcpd/ipcp.c') diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c index 13632a80..060178bf 100644 --- a/src/ipcpd/ipcp.c +++ b/src/ipcpd/ipcp.c @@ -29,6 +29,22 @@ #define OUROBOROS_PREFIX "ipcpd/ipcp" #include +struct ipcp * ipcp_instance_create() +{ + struct ipcp * i = malloc(sizeof *i); + if (i == NULL) + return NULL; + + i->data = NULL; + i->ops = NULL; + i->irmd_fd = -1; + i->state = IPCP_INIT; + + rw_lock_init(&i->state_lock); + + return i; +} + int ipcp_arg_check(int argc, char * argv[]) { if (argc != 3) @@ -52,25 +68,33 @@ void * ipcp_main_loop(void * o) uint8_t buf[IPCP_MSG_BUF_SIZE]; struct ipcp * _ipcp = (struct ipcp *) o; - ipcp_msg_t * msg; - ssize_t count; - buffer_t buffer; - ipcp_msg_t ret_msg = IPCP_MSG__INIT; + ipcp_msg_t * msg; + ssize_t count; + buffer_t buffer; + ipcp_msg_t ret_msg = IPCP_MSG__INIT; dif_config_msg_t * conf_msg; struct dif_config conf; + char * sock_path; + if (_ipcp == NULL) { LOG_ERR("Invalid ipcp struct."); return (void *) 1; } - sockfd = server_socket_open(ipcp_sock_path(getpid())); + sock_path = ipcp_sock_path(getpid()); + if (sock_path == NULL) + return (void *) 1; + + sockfd = server_socket_open(sock_path); if (sockfd < 0) { LOG_ERR("Could not open server socket."); return (void *) 1; } + free(sock_path); + while (true) { ret_msg.code = IPCP_MSG_CODE__IPCP_REPLY; -- cgit v1.2.3