From bfb86b66c8e7d9d8dc45d9075a4db6d10931dccf Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Tue, 7 Feb 2017 20:45:14 +0100 Subject: ipcpd: Refactor ipcpi struct The ipcp-ops header was removed and merged into ipcp.h. The common components dif_name and ipcp_type have been moved to the main ipcp struct. After this move, ipcp_data only contained shim information, so it was renamed to shim_data. The ipcp_init() function checks the type and will only include the shim_data if the type is not an IPCP_NORMAL. All ipcps have been adapted to this change in API. --- src/ipcpd/CMakeLists.txt | 2 +- src/ipcpd/ipcp-data.c | 533 ------------------------------------------ src/ipcpd/ipcp-data.h | 103 -------- src/ipcpd/ipcp.c | 32 +-- src/ipcpd/ipcp.h | 36 ++- src/ipcpd/local/main.c | 16 +- src/ipcpd/normal/main.c | 4 +- src/ipcpd/shim-data.c | 511 ++++++++++++++++++++++++++++++++++++++++ src/ipcpd/shim-data.h | 97 ++++++++ src/ipcpd/shim-eth-llc/main.c | 60 ++--- src/ipcpd/shim-udp/main.c | 30 ++- 11 files changed, 722 insertions(+), 702 deletions(-) delete mode 100644 src/ipcpd/ipcp-data.c delete mode 100644 src/ipcpd/ipcp-data.h create mode 100644 src/ipcpd/shim-data.c create mode 100644 src/ipcpd/shim-data.h diff --git a/src/ipcpd/CMakeLists.txt b/src/ipcpd/CMakeLists.txt index afce9441..9c77683a 100644 --- a/src/ipcpd/CMakeLists.txt +++ b/src/ipcpd/CMakeLists.txt @@ -1,7 +1,7 @@ set(IPCP_SOURCES # Add source files here ${CMAKE_CURRENT_SOURCE_DIR}/ipcp.c - ${CMAKE_CURRENT_SOURCE_DIR}/ipcp-data.c + ${CMAKE_CURRENT_SOURCE_DIR}/shim-data.c ${CMAKE_CURRENT_SOURCE_DIR}/timerwheel.c ) diff --git a/src/ipcpd/ipcp-data.c b/src/ipcpd/ipcp-data.c deleted file mode 100644 index 47c4c472..00000000 --- a/src/ipcpd/ipcp-data.c +++ /dev/null @@ -1,533 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * IPC process utilities - * - * Dimitri Staessens - * Sander Vrijders - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#define OUROBOROS_PREFIX "ipcp-utils" - -#include -#include -#include -#include -#include - -#include "ipcp-data.h" -#include "ipcp.h" - -#include -#include -#include - -struct reg_entry { - struct list_head list; - char * name; -}; - -struct dir_entry { - struct list_head list; - char * name; - uint64_t addr; -}; - -static struct reg_entry * reg_entry_create(char * name) -{ - struct reg_entry * entry = malloc(sizeof(*entry)); - if (entry == NULL) - return NULL; - - assert(name); - - entry->name = name; - if (entry->name == NULL) - return NULL; - - return entry; -} - -static void reg_entry_destroy(struct reg_entry * entry) -{ - assert(entry); - - if (entry->name != NULL) - free(entry->name); - - free(entry); -} - -static struct dir_entry * dir_entry_create(char * name, - uint64_t addr) -{ - struct dir_entry * entry = malloc(sizeof(*entry)); - if (entry == NULL) - return NULL; - - assert(name); - - entry->addr = addr; - entry->name = name; - if (entry->name == NULL) - return NULL; - - return entry; -} - -static void dir_entry_destroy(struct dir_entry * entry) -{ - assert(entry); - - if (entry->name != NULL) - free(entry->name); - - free(entry); -} - -struct ipcp_data * ipcp_data_create() -{ - struct ipcp_data * data = malloc(sizeof(*data)); - if (data == NULL) - return NULL; - - data->type = 0; - - return data; -} - -struct ipcp_data * ipcp_data_init(struct ipcp_data * dst, - enum ipcp_type ipcp_type) -{ - if (dst == NULL) - return NULL; - - dst->type = ipcp_type; - dst->dif_name = NULL; - - /* init the lists */ - list_head_init(&dst->registry); - list_head_init(&dst->directory); - list_head_init(&dst->dir_queries); - - /* init the locks */ - pthread_rwlock_init(&dst->reg_lock, NULL); - pthread_rwlock_init(&dst->dir_lock, NULL); - pthread_mutex_init(&dst->dir_queries_lock, NULL); - - return dst; -} - -static void clear_registry(struct ipcp_data * data) -{ - struct list_head * h; - struct list_head * t; - - assert(data); - - list_for_each_safe(h, t, &data->registry) { - struct reg_entry * e = list_entry(h, struct reg_entry, list); - list_del(&e->list); - reg_entry_destroy(e); - } -} - -static void clear_directory(struct ipcp_data * data) -{ - struct list_head * h; - struct list_head * t; - - assert(data); - - list_for_each_safe(h, t, &data->directory) { - struct dir_entry * e = list_entry(h, struct dir_entry, list); - list_del(&e->list); - dir_entry_destroy(e); - } -} - -static void clear_dir_queries(struct ipcp_data * data) -{ - struct list_head * h; - struct list_head * t; - - assert(data); - - list_for_each_safe(h, t, &data->dir_queries) { - struct dir_query * e = list_entry(h, struct dir_query, next); - list_del(&e->next); - ipcp_data_dir_query_destroy(e); - } -} - -void ipcp_data_destroy(struct ipcp_data * data) -{ - if (data == NULL) - return; - - /* clear the lists */ - pthread_rwlock_wrlock(&data->reg_lock); - clear_registry(data); - pthread_rwlock_unlock(&data->reg_lock); - - pthread_rwlock_wrlock(&data->dir_lock); - clear_directory(data); - pthread_rwlock_unlock(&data->dir_lock); - - pthread_mutex_lock(&data->dir_queries_lock); - clear_dir_queries(data); - pthread_mutex_unlock(&data->dir_queries_lock); - - if (data->dif_name != NULL) - free(data->dif_name); - - pthread_rwlock_destroy(&data->dir_lock); - pthread_rwlock_destroy(&data->reg_lock); - pthread_mutex_destroy(&data->dir_queries_lock); - - free(data); -} - -static struct reg_entry * find_reg_entry_by_name(struct ipcp_data * data, - const char * name) -{ - struct list_head * h; - - assert(data); - assert(name); - - list_for_each(h, &data->registry) { - struct reg_entry * e = list_entry(h, struct reg_entry, list); - if (!strcmp(e->name, name)) - return e; - } - - return NULL; -} - -static struct dir_entry * find_dir_entry(struct ipcp_data * data, - const char * name, - uint64_t addr) -{ - struct list_head * h; - list_for_each(h, &data->directory) { - struct dir_entry * e = list_entry(h, struct dir_entry, list); - if (e->addr == addr && !strcmp(e->name, name)) - return e; - } - - return NULL; -} - -static struct dir_entry * find_dir_entry_any(struct ipcp_data * data, - const char * name) -{ - struct list_head * h; - list_for_each(h, &data->directory) { - struct dir_entry * e = list_entry(h, struct dir_entry, list); - if (!strcmp(e->name, name)) - return e; - } - - return NULL; -} - -int ipcp_data_reg_add_entry(struct ipcp_data * data, - char * name) -{ - struct reg_entry * entry; - - if (data == NULL || name == NULL) - return -1; - - pthread_rwlock_wrlock(&data->reg_lock); - - if (find_reg_entry_by_name(data, name)) { - pthread_rwlock_unlock(&data->reg_lock); - return -1; - } - - entry = reg_entry_create(name); - if (entry == NULL) { - pthread_rwlock_unlock(&data->reg_lock); - return -1; - } - - list_add(&entry->list, &data->registry); - - pthread_rwlock_unlock(&data->reg_lock); - - return 0; -} - -int ipcp_data_reg_del_entry(struct ipcp_data * data, - const char * name) -{ - struct reg_entry * e; - if (data == NULL) - return -1; - - pthread_rwlock_wrlock(&data->reg_lock); - - e = find_reg_entry_by_name(data, name); - if (e == NULL) { - pthread_rwlock_unlock(&data->reg_lock); - return 0; /* nothing to do */ - } - - list_del(&e->list); - - pthread_rwlock_unlock(&data->reg_lock); - - reg_entry_destroy(e); - - return 0; -} - -bool ipcp_data_reg_has(struct ipcp_data * data, - const char * name) -{ - bool ret = false; - - if (data == NULL || name == NULL) - return false; - - pthread_rwlock_rdlock(&data->reg_lock); - - ret = (find_reg_entry_by_name(data, name) != NULL); - - pthread_rwlock_unlock(&data->reg_lock); - - return ret; -} - -int ipcp_data_dir_add_entry(struct ipcp_data * data, - char * name, - uint64_t addr) -{ - struct dir_entry * entry; - char * entry_name; - - if (data == NULL || name == NULL) - return -1; - - pthread_rwlock_wrlock(&data->dir_lock); - - if (find_dir_entry(data, name, addr) != NULL) { - pthread_rwlock_unlock(&data->dir_lock); - return -1; - } - - entry_name = strdup(name); - if (entry_name == NULL) { - pthread_rwlock_unlock(&data->dir_lock); - return -1; - } - - entry = dir_entry_create(entry_name, addr); - if (entry == NULL) { - pthread_rwlock_unlock(&data->dir_lock); - return -1; - } - - list_add(&entry->list,&data->directory); - - pthread_rwlock_unlock(&data->dir_lock); - - LOG_DBG("Added directory entry for %s.", entry_name); - - return 0; -} - -int ipcp_data_dir_del_entry(struct ipcp_data * data, - const char * name, - uint64_t addr) -{ - struct dir_entry * e; - if (data == NULL) - return -1; - - pthread_rwlock_wrlock(&data->dir_lock); - - e = find_dir_entry(data, name, addr); - if (e == NULL) { - pthread_rwlock_unlock(&data->dir_lock); - return 0; /* nothing to do */ - } - - list_del(&e->list); - - pthread_rwlock_unlock(&data->dir_lock); - - dir_entry_destroy(e); - - return 0; -} - -bool ipcp_data_dir_has(struct ipcp_data * data, - const char * name) -{ - bool ret = false; - - pthread_rwlock_rdlock(&data->dir_lock); - - ret = (find_dir_entry_any(data, name) != NULL); - - pthread_rwlock_unlock(&data->dir_lock); - - return ret; -} - -uint64_t ipcp_data_dir_get_addr(struct ipcp_data * data, - const char * name) -{ - struct dir_entry * entry; - uint64_t addr; - - pthread_rwlock_rdlock(&data->dir_lock); - - entry = find_dir_entry_any(data, name); - - if (entry == NULL) { - pthread_rwlock_unlock(&data->dir_lock); - return 0; /* undefined behaviour, 0 may be a valid address */ - } - - addr = entry->addr; - - pthread_rwlock_unlock(&data->dir_lock); - - return addr; -} - -struct dir_query * ipcp_data_dir_query_create(char * name) -{ - struct dir_query * query; - pthread_condattr_t cattr; - - query = malloc(sizeof(*query)); - if (query == NULL) - return NULL; - - query->name = strdup(name); - if (query->name == NULL) { - free(query); - return NULL; - } - - query->state = QUERY_INIT; - - pthread_condattr_init(&cattr); -#ifndef __APPLE__ - pthread_condattr_setclock(&cattr, PTHREAD_COND_CLOCK); -#endif - pthread_cond_init(&query->cond, &cattr); - pthread_mutex_init(&query->lock, NULL); - - list_head_init(&query->next); - - return query; -} - -void ipcp_data_dir_query_respond(struct dir_query * query) -{ - assert(query); - - pthread_mutex_lock(&query->lock); - - if (query->state != QUERY_PENDING) { - pthread_mutex_unlock(&query->lock); - return; - } - - query->state = QUERY_RESPONSE; - pthread_cond_broadcast(&query->cond); - - while (query->state == QUERY_RESPONSE) - pthread_cond_wait(&query->cond, &query->lock); - - pthread_mutex_unlock(&query->lock); -} - -void ipcp_data_dir_query_destroy(struct dir_query * query) -{ - assert(query); - - pthread_mutex_lock(&query->lock); - - if (query->state == QUERY_DESTROY) { - pthread_mutex_unlock(&query->lock); - return; - } - - if (query->state == QUERY_INIT) - query->state = QUERY_DONE; - - if (query->state == QUERY_PENDING) { - query->state = QUERY_DESTROY; - pthread_cond_broadcast(&query->cond); - } - - while (query->state != QUERY_DONE) - pthread_cond_wait(&query->cond, &query->lock); - - pthread_mutex_unlock(&query->lock); - - pthread_cond_destroy(&query->cond); - pthread_mutex_destroy(&query->lock); - - free(query->name); - free(query); -} - -int ipcp_data_dir_query_wait(struct dir_query * query, - const struct timespec * timeout) -{ - struct timespec abstime; - int ret = 0; - - assert(query); - assert(timeout); - - clock_gettime(PTHREAD_COND_CLOCK, &abstime); - ts_add(&abstime, timeout, &abstime); - - pthread_mutex_lock(&query->lock); - - if (query->state != QUERY_INIT) { - pthread_mutex_unlock(&query->lock); - return -EINVAL; - } - - query->state = QUERY_PENDING; - - while (query->state == QUERY_PENDING) { - if ((ret = -pthread_cond_timedwait(&query->cond, - &query->lock, - &abstime)) == -ETIMEDOUT) - break; - } - - if (query->state == QUERY_DESTROY) - ret = -1; - - query->state = QUERY_DONE; - pthread_cond_broadcast(&query->cond); - - pthread_mutex_unlock(&query->lock); - - return ret; -} diff --git a/src/ipcpd/ipcp-data.h b/src/ipcpd/ipcp-data.h deleted file mode 100644 index 877aa04a..00000000 --- a/src/ipcpd/ipcp-data.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * Utitilies for building IPC processes - * - * Dimitri Staessens - * Sander Vrijders - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef IPCPD_IPCP_DATA_H -#define IPCPD_IPCP_DATA_H - -#include -#include - -#include "ipcp-ops.h" - -#include -#include - -enum dir_query_state { - QUERY_INIT = 0, - QUERY_PENDING, - QUERY_RESPONSE, - QUERY_DONE, - QUERY_DESTROY -}; - -struct dir_query { - struct list_head next; - char * name; - enum dir_query_state state; - - pthread_mutex_t lock; - pthread_cond_t cond; -}; - -struct ipcp_data { - enum ipcp_type type; - char * dif_name; - - struct list_head registry; - pthread_rwlock_t reg_lock; - - struct list_head directory; - pthread_rwlock_t dir_lock; - - struct list_head dir_queries; - pthread_mutex_t dir_queries_lock; -}; - -struct ipcp_data * ipcp_data_create(void); - -struct ipcp_data * ipcp_data_init(struct ipcp_data * dst, - enum ipcp_type ipcp_type); - -void ipcp_data_destroy(struct ipcp_data * data); - -int ipcp_data_reg_add_entry(struct ipcp_data * data, - char * name); - -int ipcp_data_reg_del_entry(struct ipcp_data * data, - const char * name); - -bool ipcp_data_reg_has(struct ipcp_data * data, - const char * name); - -int ipcp_data_dir_add_entry(struct ipcp_data * data, - char * name, - uint64_t addr); - -int ipcp_data_dir_del_entry(struct ipcp_data * data, - const char * name, - uint64_t addr); - -bool ipcp_data_dir_has(struct ipcp_data * data, - const char * name); - -uint64_t ipcp_data_dir_get_addr(struct ipcp_data * data, - const char * name); - -struct dir_query * ipcp_data_dir_query_create(char * name); - -void ipcp_data_dir_query_respond(struct dir_query * query); - -void ipcp_data_dir_query_destroy(struct dir_query * query); - -int ipcp_data_dir_query_wait(struct dir_query * query, - const struct timespec * timeout); -#endif /* IPCPD_IPCP_DATA_H */ diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c index fe87fbd9..53213c39 100644 --- a/src/ipcpd/ipcp.c +++ b/src/ipcpd/ipcp.c @@ -270,15 +270,17 @@ static void * ipcp_main_loop(void * o) return (void *) 0; } -int ipcp_init(enum ipcp_type type, struct ipcp_ops * ops) +int ipcp_init(enum ipcp_type type, + struct ipcp_ops * ops) { pthread_condattr_t cattr; struct timeval tv = {(IPCP_ACCEPT_TIMEOUT / 1000), (IPCP_ACCEPT_TIMEOUT % 1000) * 1000}; - ipcpi.irmd_fd = -1; - ipcpi.state = IPCP_NULL; + ipcpi.irmd_fd = -1; + ipcpi.state = IPCP_NULL; + ipcpi.shim_data = NULL; ipcpi.threadpool = malloc(sizeof(pthread_t) * IPCPD_THREADPOOL_SIZE); if (ipcpi.threadpool == NULL) { @@ -305,15 +307,6 @@ int ipcp_init(enum ipcp_type type, struct ipcp_ops * ops) ipcpi.ops = ops; - ipcpi.data = ipcp_data_create(); - if (ipcpi.data == NULL) { - free(ipcpi.threadpool); - free(ipcpi.sock_path); - return -ENOMEM; - } - - ipcp_data_init(ipcpi.data, type); - pthread_rwlock_init(&ipcpi.state_lock, NULL); pthread_mutex_init(&ipcpi.state_mtx, NULL); pthread_condattr_init(&cattr); @@ -322,6 +315,16 @@ int ipcp_init(enum ipcp_type type, struct ipcp_ops * ops) #endif pthread_cond_init(&ipcpi.state_cond, &cattr); + if (type == IPCP_NORMAL) + return 0; + + ipcpi.shim_data = shim_data_create(); + if (ipcpi.shim_data == NULL) { + free(ipcpi.threadpool); + free(ipcpi.sock_path); + return -ENOMEM; + } + return 0; } @@ -364,7 +367,7 @@ void ipcp_fini() free(ipcpi.sock_path); free(ipcpi.threadpool); - ipcp_data_destroy(ipcpi.data); + shim_data_destroy(ipcpi.shim_data); pthread_cond_destroy(&ipcpi.state_cond); pthread_mutex_destroy(&ipcpi.state_mtx); @@ -422,7 +425,8 @@ int ipcp_wait_state(enum ipcp_state state, return ret; } -int ipcp_parse_arg(int argc, char * argv[]) +int ipcp_parse_arg(int argc, + char * argv[]) { char * log_file; size_t len = 0; diff --git a/src/ipcpd/ipcp.h b/src/ipcpd/ipcp.h index 8b590cc2..9a4d272a 100644 --- a/src/ipcpd/ipcp.h +++ b/src/ipcpd/ipcp.h @@ -23,9 +23,9 @@ #define IPCPD_IPCP_H #include +#include -#include "ipcp-ops.h" -#include "ipcp-data.h" +#include "shim-data.h" #include #include @@ -37,16 +37,42 @@ enum ipcp_state { IPCP_SHUTDOWN }; +struct ipcp_ops { + int (* ipcp_bootstrap)(struct dif_config * conf); + + int (* ipcp_enroll)(char * dif_name); + + int (* ipcp_name_reg)(char * name); + + int (* ipcp_name_unreg)(char * name); + + int (* ipcp_name_query)(char * name); + + int (* ipcp_flow_alloc)(int fd, + char * dst_ap_name, + char * src_ae_name, + qoscube_t qos); + + int (* ipcp_flow_alloc_resp)(int fd, + int response); + + int (* ipcp_flow_dealloc)(int fd); +}; + struct ipcp { int irmd_api; char * name; + enum ipcp_type type; + char * dif_name; + uint64_t address; - struct ipcp_data * data; struct ipcp_ops * ops; int irmd_fd; + struct shim_data * shim_data; + enum ipcp_state state; pthread_rwlock_t state_lock; pthread_mutex_t state_mtx; @@ -57,7 +83,7 @@ struct ipcp { pthread_t * threadpool; } ipcpi; -int ipcp_init(enum ipcp_type type, +int ipcp_init(enum ipcp_type type, struct ipcp_ops * ops); int ipcp_boot(void); @@ -73,7 +99,7 @@ enum ipcp_state ipcp_get_state(void); int ipcp_wait_state(enum ipcp_state state, const struct timespec * timeout); -int ipcp_parse_arg(int argc, +int ipcp_parse_arg(int argc, char * argv[]); #endif diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c index c2b22732..2cba053a 100644 --- a/src/ipcpd/local/main.c +++ b/src/ipcpd/local/main.c @@ -115,7 +115,9 @@ static void * ipcp_local_sdu_loop(void * o) return (void *) 0; } -void ipcp_sig_handler(int sig, siginfo_t * info, void * c) +void ipcp_sig_handler(int sig, + siginfo_t * info, + void * c) { (void) c; @@ -176,7 +178,7 @@ static int ipcp_local_name_reg(char * name) pthread_rwlock_rdlock(&ipcpi.state_lock); - if (ipcp_data_reg_add_entry(ipcpi.data, name_dup)) { + if (shim_data_reg_add_entry(ipcpi.shim_data, name_dup)) { pthread_rwlock_unlock(&ipcpi.state_lock); LOG_DBG("Failed to add %s to local registry.", name); free(name_dup); @@ -194,7 +196,7 @@ static int ipcp_local_name_unreg(char * name) { pthread_rwlock_rdlock(&ipcpi.state_lock); - ipcp_data_reg_del_entry(ipcpi.data, name); + shim_data_reg_del_entry(ipcpi.shim_data, name); pthread_rwlock_unlock(&ipcpi.state_lock); @@ -209,7 +211,7 @@ static int ipcp_local_name_query(char * name) pthread_rwlock_rdlock(&ipcpi.state_lock); - ret = (ipcp_data_reg_has(ipcpi.data, name) ? 0 : -1); + ret = (shim_data_reg_has(ipcpi.shim_data, name) ? 0 : -1); pthread_rwlock_unlock(&ipcpi.state_lock); @@ -253,7 +255,8 @@ static int ipcp_local_flow_alloc(int fd, return 0; } -static int ipcp_local_flow_alloc_resp(int fd, int response) +static int ipcp_local_flow_alloc_resp(int fd, + int response) { int out_fd = -1; int ret = -1; @@ -325,7 +328,8 @@ static struct ipcp_ops local_ops = { .ipcp_flow_dealloc = ipcp_local_flow_dealloc }; -int main(int argc, char * argv[]) +int main(int argc, + char * argv[]) { struct sigaction sig_act; sigset_t sigset; diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c index b9cc6e57..97484958 100644 --- a/src/ipcpd/normal/main.c +++ b/src/ipcpd/normal/main.c @@ -150,8 +150,8 @@ static int boot_components(void) return -1; } - ipcpi.data->dif_name = strdup(buf); - if (ipcpi.data->dif_name == NULL) { + ipcpi.dif_name = strdup(buf); + if (ipcpi.dif_name == NULL) { LOG_ERR("Failed to set DIF name."); return -1; } diff --git a/src/ipcpd/shim-data.c b/src/ipcpd/shim-data.c new file mode 100644 index 00000000..933f3a64 --- /dev/null +++ b/src/ipcpd/shim-data.c @@ -0,0 +1,511 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * IPC process utilities + * + * Dimitri Staessens + * Sander Vrijders + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include + +#include "shim-data.h" +#include "ipcp.h" + +#include +#include +#include + +struct reg_entry { + struct list_head list; + char * name; +}; + +struct dir_entry { + struct list_head list; + char * name; + uint64_t addr; +}; + +static struct reg_entry * reg_entry_create(char * name) +{ + struct reg_entry * entry = malloc(sizeof(*entry)); + if (entry == NULL) + return NULL; + + assert(name); + + entry->name = name; + if (entry->name == NULL) + return NULL; + + return entry; +} + +static void reg_entry_destroy(struct reg_entry * entry) +{ + assert(entry); + + if (entry->name != NULL) + free(entry->name); + + free(entry); +} + +static struct dir_entry * dir_entry_create(char * name, + uint64_t addr) +{ + struct dir_entry * entry = malloc(sizeof(*entry)); + if (entry == NULL) + return NULL; + + assert(name); + + entry->addr = addr; + entry->name = name; + if (entry->name == NULL) + return NULL; + + return entry; +} + +static void dir_entry_destroy(struct dir_entry * entry) +{ + assert(entry); + + if (entry->name != NULL) + free(entry->name); + + free(entry); +} + +struct shim_data * shim_data_create() +{ + struct shim_data * sd = malloc(sizeof(*sd)); + if (sd == NULL) + return NULL; + + /* init the lists */ + list_head_init(&sd->registry); + list_head_init(&sd->directory); + list_head_init(&sd->dir_queries); + + /* init the locks */ + pthread_rwlock_init(&sd->reg_lock, NULL); + pthread_rwlock_init(&sd->dir_lock, NULL); + pthread_mutex_init(&sd->dir_queries_lock, NULL); + + return sd; +} + +static void clear_registry(struct shim_data * data) +{ + struct list_head * h; + struct list_head * t; + + assert(data); + + list_for_each_safe(h, t, &data->registry) { + struct reg_entry * e = list_entry(h, struct reg_entry, list); + list_del(&e->list); + reg_entry_destroy(e); + } +} + +static void clear_directory(struct shim_data * data) +{ + struct list_head * h; + struct list_head * t; + + assert(data); + + list_for_each_safe(h, t, &data->directory) { + struct dir_entry * e = list_entry(h, struct dir_entry, list); + list_del(&e->list); + dir_entry_destroy(e); + } +} + +static void clear_dir_queries(struct shim_data * data) +{ + struct list_head * h; + struct list_head * t; + + assert(data); + + list_for_each_safe(h, t, &data->dir_queries) { + struct dir_query * e = list_entry(h, struct dir_query, next); + list_del(&e->next); + shim_data_dir_query_destroy(e); + } +} + +void shim_data_destroy(struct shim_data * data) +{ + if (data == NULL) + return; + + /* clear the lists */ + pthread_rwlock_wrlock(&data->reg_lock); + clear_registry(data); + pthread_rwlock_unlock(&data->reg_lock); + + pthread_rwlock_wrlock(&data->dir_lock); + clear_directory(data); + pthread_rwlock_unlock(&data->dir_lock); + + pthread_mutex_lock(&data->dir_queries_lock); + clear_dir_queries(data); + pthread_mutex_unlock(&data->dir_queries_lock); + + pthread_rwlock_destroy(&data->dir_lock); + pthread_rwlock_destroy(&data->reg_lock); + pthread_mutex_destroy(&data->dir_queries_lock); + + free(data); +} + +static struct reg_entry * find_reg_entry_by_name(struct shim_data * data, + const char * name) +{ + struct list_head * h; + + assert(data); + assert(name); + + list_for_each(h, &data->registry) { + struct reg_entry * e = list_entry(h, struct reg_entry, list); + if (!strcmp(e->name, name)) + return e; + } + + return NULL; +} + +static struct dir_entry * find_dir_entry(struct shim_data * data, + const char * name, + uint64_t addr) +{ + struct list_head * h; + list_for_each(h, &data->directory) { + struct dir_entry * e = list_entry(h, struct dir_entry, list); + if (e->addr == addr && !strcmp(e->name, name)) + return e; + } + + return NULL; +} + +static struct dir_entry * find_dir_entry_any(struct shim_data * data, + const char * name) +{ + struct list_head * h; + list_for_each(h, &data->directory) { + struct dir_entry * e = list_entry(h, struct dir_entry, list); + if (!strcmp(e->name, name)) + return e; + } + + return NULL; +} + +int shim_data_reg_add_entry(struct shim_data * data, + char * name) +{ + struct reg_entry * entry; + + if (data == NULL || name == NULL) + return -1; + + pthread_rwlock_wrlock(&data->reg_lock); + + if (find_reg_entry_by_name(data, name)) { + pthread_rwlock_unlock(&data->reg_lock); + return -1; + } + + entry = reg_entry_create(name); + if (entry == NULL) { + pthread_rwlock_unlock(&data->reg_lock); + return -1; + } + + list_add(&entry->list, &data->registry); + + pthread_rwlock_unlock(&data->reg_lock); + + return 0; +} + +int shim_data_reg_del_entry(struct shim_data * data, + const char * name) +{ + struct reg_entry * e; + if (data == NULL) + return -1; + + pthread_rwlock_wrlock(&data->reg_lock); + + e = find_reg_entry_by_name(data, name); + if (e == NULL) { + pthread_rwlock_unlock(&data->reg_lock); + return 0; /* nothing to do */ + } + + list_del(&e->list); + + pthread_rwlock_unlock(&data->reg_lock); + + reg_entry_destroy(e); + + return 0; +} + +bool shim_data_reg_has(struct shim_data * data, + const char * name) +{ + bool ret = false; + + if (data == NULL || name == NULL) + return false; + + pthread_rwlock_rdlock(&data->reg_lock); + + ret = (find_reg_entry_by_name(data, name) != NULL); + + pthread_rwlock_unlock(&data->reg_lock); + + return ret; +} + +int shim_data_dir_add_entry(struct shim_data * data, + char * name, + uint64_t addr) +{ + struct dir_entry * entry; + char * entry_name; + + if (data == NULL || name == NULL) + return -1; + + pthread_rwlock_wrlock(&data->dir_lock); + + if (find_dir_entry(data, name, addr) != NULL) { + pthread_rwlock_unlock(&data->dir_lock); + return -1; + } + + entry_name = strdup(name); + if (entry_name == NULL) { + pthread_rwlock_unlock(&data->dir_lock); + return -1; + } + + entry = dir_entry_create(entry_name, addr); + if (entry == NULL) { + pthread_rwlock_unlock(&data->dir_lock); + return -1; + } + + list_add(&entry->list,&data->directory); + + pthread_rwlock_unlock(&data->dir_lock); + + return 0; +} + +int shim_data_dir_del_entry(struct shim_data * data, + const char * name, + uint64_t addr) +{ + struct dir_entry * e; + if (data == NULL) + return -1; + + pthread_rwlock_wrlock(&data->dir_lock); + + e = find_dir_entry(data, name, addr); + if (e == NULL) { + pthread_rwlock_unlock(&data->dir_lock); + return 0; /* nothing to do */ + } + + list_del(&e->list); + + pthread_rwlock_unlock(&data->dir_lock); + + dir_entry_destroy(e); + + return 0; +} + +bool shim_data_dir_has(struct shim_data * data, + const char * name) +{ + bool ret = false; + + pthread_rwlock_rdlock(&data->dir_lock); + + ret = (find_dir_entry_any(data, name) != NULL); + + pthread_rwlock_unlock(&data->dir_lock); + + return ret; +} + +uint64_t shim_data_dir_get_addr(struct shim_data * data, + const char * name) +{ + struct dir_entry * entry; + uint64_t addr; + + pthread_rwlock_rdlock(&data->dir_lock); + + entry = find_dir_entry_any(data, name); + + if (entry == NULL) { + pthread_rwlock_unlock(&data->dir_lock); + return 0; /* undefined behaviour, 0 may be a valid address */ + } + + addr = entry->addr; + + pthread_rwlock_unlock(&data->dir_lock); + + return addr; +} + +struct dir_query * shim_data_dir_query_create(char * name) +{ + struct dir_query * query; + pthread_condattr_t cattr; + + query = malloc(sizeof(*query)); + if (query == NULL) + return NULL; + + query->name = strdup(name); + if (query->name == NULL) { + free(query); + return NULL; + } + + query->state = QUERY_INIT; + + pthread_condattr_init(&cattr); +#ifndef __APPLE__ + pthread_condattr_setclock(&cattr, PTHREAD_COND_CLOCK); +#endif + pthread_cond_init(&query->cond, &cattr); + pthread_mutex_init(&query->lock, NULL); + + list_head_init(&query->next); + + return query; +} + +void shim_data_dir_query_respond(struct dir_query * query) +{ + assert(query); + + pthread_mutex_lock(&query->lock); + + if (query->state != QUERY_PENDING) { + pthread_mutex_unlock(&query->lock); + return; + } + + query->state = QUERY_RESPONSE; + pthread_cond_broadcast(&query->cond); + + while (query->state == QUERY_RESPONSE) + pthread_cond_wait(&query->cond, &query->lock); + + pthread_mutex_unlock(&query->lock); +} + +void shim_data_dir_query_destroy(struct dir_query * query) +{ + assert(query); + + pthread_mutex_lock(&query->lock); + + if (query->state == QUERY_DESTROY) { + pthread_mutex_unlock(&query->lock); + return; + } + + if (query->state == QUERY_INIT) + query->state = QUERY_DONE; + + if (query->state == QUERY_PENDING) { + query->state = QUERY_DESTROY; + pthread_cond_broadcast(&query->cond); + } + + while (query->state != QUERY_DONE) + pthread_cond_wait(&query->cond, &query->lock); + + pthread_mutex_unlock(&query->lock); + + pthread_cond_destroy(&query->cond); + pthread_mutex_destroy(&query->lock); + + free(query->name); + free(query); +} + +int shim_data_dir_query_wait(struct dir_query * query, + const struct timespec * timeout) +{ + struct timespec abstime; + int ret = 0; + + assert(query); + assert(timeout); + + clock_gettime(PTHREAD_COND_CLOCK, &abstime); + ts_add(&abstime, timeout, &abstime); + + pthread_mutex_lock(&query->lock); + + if (query->state != QUERY_INIT) { + pthread_mutex_unlock(&query->lock); + return -EINVAL; + } + + query->state = QUERY_PENDING; + + while (query->state == QUERY_PENDING) { + if ((ret = -pthread_cond_timedwait(&query->cond, + &query->lock, + &abstime)) == -ETIMEDOUT) + break; + } + + if (query->state == QUERY_DESTROY) + ret = -1; + + query->state = QUERY_DONE; + pthread_cond_broadcast(&query->cond); + + pthread_mutex_unlock(&query->lock); + + return ret; +} diff --git a/src/ipcpd/shim-data.h b/src/ipcpd/shim-data.h new file mode 100644 index 00000000..28087901 --- /dev/null +++ b/src/ipcpd/shim-data.h @@ -0,0 +1,97 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * Utitilies for building IPC processes + * + * Dimitri Staessens + * Sander Vrijders + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef IPCPD_IPCP_DATA_H +#define IPCPD_IPCP_DATA_H + +#include +#include + +#include +#include +#include + + +enum dir_query_state { + QUERY_INIT = 0, + QUERY_PENDING, + QUERY_RESPONSE, + QUERY_DONE, + QUERY_DESTROY +}; + +struct dir_query { + struct list_head next; + char * name; + enum dir_query_state state; + + pthread_mutex_t lock; + pthread_cond_t cond; +}; + +struct shim_data { + struct list_head registry; + pthread_rwlock_t reg_lock; + + struct list_head directory; + pthread_rwlock_t dir_lock; + + struct list_head dir_queries; + pthread_mutex_t dir_queries_lock; +}; + +struct shim_data * shim_data_create(void); + +void shim_data_destroy(struct shim_data * data); + +int shim_data_reg_add_entry(struct shim_data * data, + char * name); + +int shim_data_reg_del_entry(struct shim_data * data, + const char * name); + +bool shim_data_reg_has(struct shim_data * data, + const char * name); + +int shim_data_dir_add_entry(struct shim_data * data, + char * name, + uint64_t addr); + +int shim_data_dir_del_entry(struct shim_data * data, + const char * name, + uint64_t addr); + +bool shim_data_dir_has(struct shim_data * data, + const char * name); + +uint64_t shim_data_dir_get_addr(struct shim_data * data, + const char * name); + +struct dir_query * shim_data_dir_query_create(char * name); + +void shim_data_dir_query_respond(struct dir_query * query); + +void shim_data_dir_query_destroy(struct dir_query * query); + +int shim_data_dir_query_wait(struct dir_query * query, + const struct timespec * timeout); +#endif /* IPCPD_SHIM_DATA_H */ diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c index bc0d8a27..fba4f5f3 100644 --- a/src/ipcpd/shim-eth-llc/main.c +++ b/src/ipcpd/shim-eth-llc/main.c @@ -415,11 +415,12 @@ static int eth_llc_ipcp_sap_alloc_reply(uint8_t ssap, } -static int eth_llc_ipcp_name_query_req(char * name, uint8_t * r_addr) +static int eth_llc_ipcp_name_query_req(char * name, + uint8_t * r_addr) { shim_eth_llc_msg_t msg = SHIM_ETH_LLC_MSG__INIT; - if (ipcp_data_reg_has(ipcpi.data, name)) { + if (shim_data_reg_has(ipcpi.shim_data, name)) { msg.code = SHIM_ETH_LLC_MSG_CODE__NAME_QUERY_REPLY; msg.dst_name = name; @@ -429,29 +430,32 @@ static int eth_llc_ipcp_name_query_req(char * name, uint8_t * r_addr) return 0; } -static int eth_llc_ipcp_name_query_reply(char * name, uint8_t * r_addr) +static int eth_llc_ipcp_name_query_reply(char * name, + uint8_t * r_addr) { uint64_t address = 0; struct list_head * pos; memcpy(&address, r_addr, MAC_SIZE); - ipcp_data_dir_add_entry(ipcpi.data, name, address); + shim_data_dir_add_entry(ipcpi.shim_data, name, address); - pthread_mutex_lock(&ipcpi.data->dir_queries_lock); - list_for_each(pos, &ipcpi.data->dir_queries) { + pthread_mutex_lock(&ipcpi.shim_data->dir_queries_lock); + list_for_each(pos, &ipcpi.shim_data->dir_queries) { struct dir_query * e = list_entry(pos, struct dir_query, next); if (strcmp(e->name, name) == 0) { - ipcp_data_dir_query_respond(e); + shim_data_dir_query_respond(e); } } - pthread_mutex_unlock(&ipcpi.data->dir_queries_lock); + pthread_mutex_unlock(&ipcpi.shim_data->dir_queries_lock); return 0; } -static int eth_llc_ipcp_mgmt_frame(uint8_t * buf, size_t len, uint8_t * r_addr) +static int eth_llc_ipcp_mgmt_frame(uint8_t * buf, + size_t len, + uint8_t * r_addr) { shim_eth_llc_msg_t * msg = shim_eth_llc_msg__unpack(NULL, len, buf); if (msg == NULL) { @@ -461,7 +465,7 @@ static int eth_llc_ipcp_mgmt_frame(uint8_t * buf, size_t len, uint8_t * r_addr) switch (msg->code) { case SHIM_ETH_LLC_MSG_CODE__FLOW_REQ: - if (ipcp_data_reg_has(ipcpi.data, msg->dst_name)) { + if (shim_data_reg_has(ipcpi.shim_data, msg->dst_name)) { eth_llc_ipcp_sap_req(msg->ssap, r_addr, msg->dst_name, @@ -664,7 +668,9 @@ static void * eth_llc_ipcp_sdu_writer(void * o) return (void *) 1; } -void ipcp_sig_handler(int sig, siginfo_t * info, void * c) +void ipcp_sig_handler(int sig, + siginfo_t * info, + void * c) { (void) c; @@ -873,7 +879,7 @@ static int eth_llc_ipcp_name_reg(char * name) pthread_rwlock_rdlock(&ipcpi.state_lock); - if (ipcp_data_reg_add_entry(ipcpi.data, name_dup)) { + if (shim_data_reg_add_entry(ipcpi.shim_data, name_dup)) { pthread_rwlock_unlock(&ipcpi.state_lock); LOG_ERR("Failed to add %s to local registry.", name); free(name_dup); @@ -891,7 +897,7 @@ static int eth_llc_ipcp_name_unreg(char * name) { pthread_rwlock_rdlock(&ipcpi.state_lock); - ipcp_data_reg_del_entry(ipcpi.data, name); + shim_data_reg_del_entry(ipcpi.shim_data, name); pthread_rwlock_unlock(&ipcpi.state_lock); @@ -906,7 +912,7 @@ static int eth_llc_ipcp_name_query(char * name) struct dir_query * query; int ret; - if (ipcp_data_dir_has(ipcpi.data, name)) + if (shim_data_dir_has(ipcpi.shim_data, name)) return 0; msg.code = SHIM_ETH_LLC_MSG_CODE__NAME_QUERY_REQ; @@ -914,22 +920,22 @@ static int eth_llc_ipcp_name_query(char * name) memset(r_addr, 0xff, MAC_SIZE); - query = ipcp_data_dir_query_create(name); + query = shim_data_dir_query_create(name); if (query == NULL) return -1; - pthread_mutex_lock(&ipcpi.data->dir_queries_lock); - list_add(&query->next, &ipcpi.data->dir_queries); - pthread_mutex_unlock(&ipcpi.data->dir_queries_lock); + pthread_mutex_lock(&ipcpi.shim_data->dir_queries_lock); + list_add(&query->next, &ipcpi.shim_data->dir_queries); + pthread_mutex_unlock(&ipcpi.shim_data->dir_queries_lock); eth_llc_ipcp_send_mgmt_frame(&msg, r_addr); - ret = ipcp_data_dir_query_wait(query, &timeout); + ret = shim_data_dir_query_wait(query, &timeout); - pthread_mutex_lock(&ipcpi.data->dir_queries_lock); + pthread_mutex_lock(&ipcpi.shim_data->dir_queries_lock); list_del(&query->next); - ipcp_data_dir_query_destroy(query); - pthread_mutex_unlock(&ipcpi.data->dir_queries_lock); + shim_data_dir_query_destroy(query); + pthread_mutex_unlock(&ipcpi.shim_data->dir_queries_lock); return ret; } @@ -961,12 +967,12 @@ static int eth_llc_ipcp_flow_alloc(int fd, return -1; /* -ENOTENROLLED */ } - if (!ipcp_data_dir_has(ipcpi.data, dst_name)) { + if (!shim_data_dir_has(ipcpi.shim_data, dst_name)) { pthread_rwlock_unlock(&ipcpi.state_lock); LOG_ERR("Destination unreachable."); return -1; } - addr = ipcp_data_dir_get_addr(ipcpi.data, dst_name); + addr = shim_data_dir_get_addr(ipcpi.shim_data, dst_name); pthread_rwlock_wrlock(ð_llc_data.flows_lock); @@ -1007,7 +1013,8 @@ static int eth_llc_ipcp_flow_alloc(int fd, return 0; } -static int eth_llc_ipcp_flow_alloc_resp(int fd, int response) +static int eth_llc_ipcp_flow_alloc_resp(int fd, + int response) { uint8_t ssap = 0; uint8_t r_sap = 0; @@ -1096,7 +1103,8 @@ static struct ipcp_ops eth_llc_ops = { .ipcp_flow_dealloc = eth_llc_ipcp_flow_dealloc }; -int main(int argc, char * argv[]) +int main(int argc, + char * argv[]) { struct sigaction sig_act; sigset_t sigset; diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c index c2f86067..a7c4254a 100644 --- a/src/ipcpd/shim-udp/main.c +++ b/src/ipcpd/shim-udp/main.c @@ -156,7 +156,8 @@ static void clr_fd(int fd) pthread_mutex_unlock(&udp_data.fd_set_lock); } -static int send_shim_udp_msg(shim_udp_msg_t * msg, uint32_t dst_ip_addr) +static int send_shim_udp_msg(shim_udp_msg_t * msg, + uint32_t dst_ip_addr) { buffer_t buf; struct sockaddr_in r_saddr; @@ -518,7 +519,9 @@ static void * ipcp_udp_sdu_loop(void * o) return (void *) 1; } -void ipcp_sig_handler(int sig, siginfo_t * info, void * c) +void ipcp_sig_handler(int sig, + siginfo_t * info, + void * c) { (void) c; @@ -689,7 +692,8 @@ static int ddns_send(char * cmd) return 0; } -static uint32_t ddns_resolve(char * name, uint32_t dns_addr) +static uint32_t ddns_resolve(char * name, + uint32_t dns_addr) { pid_t api = -1; int wstatus; @@ -791,7 +795,7 @@ static int ipcp_udp_name_reg(char * name) pthread_rwlock_rdlock(&ipcpi.state_lock); - if (ipcp_data_reg_add_entry(ipcpi.data, name_dup)) { + if (shim_data_reg_add_entry(ipcpi.shim_data, name_dup)) { pthread_rwlock_unlock(&ipcpi.state_lock); LOG_ERR("Failed to add %s to local registry.", name); free(name_dup); @@ -823,7 +827,7 @@ static int ipcp_udp_name_reg(char * name) if (ddns_send(cmd)) { pthread_rwlock_rdlock(&ipcpi.state_lock); - ipcp_data_reg_del_entry(ipcpi.data, name); + shim_data_reg_del_entry(ipcpi.shim_data, name); pthread_rwlock_unlock(&ipcpi.state_lock); return -1; } @@ -872,7 +876,7 @@ static int ipcp_udp_name_unreg(char * name) pthread_rwlock_rdlock(&ipcpi.state_lock); - ipcp_data_reg_del_entry(ipcpi.data, name); + shim_data_reg_del_entry(ipcpi.shim_data, name); pthread_rwlock_unlock(&ipcpi.state_lock); @@ -902,7 +906,7 @@ static int ipcp_udp_name_query(char * name) return -1; /* -ENOTENROLLED */ } - if (ipcp_data_dir_has(ipcpi.data, name)) { + if (shim_data_dir_has(ipcpi.shim_data, name)) { pthread_rwlock_unlock(&ipcpi.state_lock); return 0; } @@ -940,7 +944,7 @@ static int ipcp_udp_name_query(char * name) } #endif - if (ipcp_data_dir_add_entry(ipcpi.data, name, ip_addr)) { + if (shim_data_dir_add_entry(ipcpi.shim_data, name, ip_addr)) { pthread_rwlock_unlock(&ipcpi.state_lock); LOG_ERR("Failed to add directory entry."); return -1; @@ -1006,13 +1010,13 @@ static int ipcp_udp_flow_alloc(int fd, return -1; /* -ENOTENROLLED */ } - if (!ipcp_data_dir_has(ipcpi.data, dst_name)) { + if (!shim_data_dir_has(ipcpi.shim_data, dst_name)) { pthread_rwlock_unlock(&ipcpi.state_lock); LOG_DBG("Could not resolve destination."); close(skfd); return -1; } - ip_addr = (uint32_t) ipcp_data_dir_get_addr(ipcpi.data, dst_name); + ip_addr = (uint32_t) shim_data_dir_get_addr(ipcpi.shim_data, dst_name); /* connect to server (store the remote IP address in the fd) */ memset((char *) &r_saddr, 0, sizeof(r_saddr)); @@ -1060,7 +1064,8 @@ static int ipcp_udp_flow_alloc(int fd, return fd; } -static int ipcp_udp_flow_alloc_resp(int fd, int response) +static int ipcp_udp_flow_alloc_resp(int fd, + int response) { int skfd = -1; struct sockaddr_in f_saddr; @@ -1166,7 +1171,8 @@ static struct ipcp_ops udp_ops = { .ipcp_flow_dealloc = ipcp_udp_flow_dealloc }; -int main(int argc, char * argv[]) +int main(int argc, + char * argv[]) { struct sigaction sig_act; sigset_t sigset; -- cgit v1.2.3