diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-05-14 16:39:27 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-05-14 21:34:04 +0200 |
commit | 037fec33cda726d0078e23798f462ad273153dd5 (patch) | |
tree | 25c9ef679a0aaa93e5f01f2a68512d8eaf76f3e7 /src/ipcpd/ipcp.c | |
parent | c56a4ed3b865b4b240c6f01809c935b7b86d160b (diff) | |
download | ouroboros-037fec33cda726d0078e23798f462ad273153dd5.tar.gz ouroboros-037fec33cda726d0078e23798f462ad273153dd5.zip |
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.
Diffstat (limited to 'src/ipcpd/ipcp.c')
-rw-r--r-- | src/ipcpd/ipcp.c | 34 |
1 files changed, 29 insertions, 5 deletions
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 <ouroboros/logs.h> +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; |