From f02d3ed3e135b5326003e7f69f8331ff6a3cc219 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Fri, 18 May 2007 10:00:00 +0000 Subject: [PATCH] K&R style braces --- lib/avl_tree.c | 93 ++++++++++++++--------------------------- lib/dropin.c | 9 ++-- lib/fake-getaddrinfo.c | 12 ++---- lib/fake-getnameinfo.c | 3 +- lib/list.c | 45 +++++++------------- lib/pidfile.c | 12 ++---- lib/utils.c | 12 ++---- src/bsd/device.c | 6 +-- src/conf.c | 51 ++++++++-------------- src/connection.c | 27 ++++-------- src/cygwin/device.c | 15 +++---- src/edge.c | 36 ++++++---------- src/graph.c | 12 ++---- src/linux/device.c | 15 +++---- src/meta.c | 12 ++---- src/mingw/device.c | 15 +++---- src/net.c | 18 +++----- src/net_packet.c | 33 +++++---------- src/net_setup.c | 15 +++---- src/net_socket.c | 24 ++++------- src/netutl.c | 30 +++++-------- src/node.c | 33 +++++---------- src/process.c | 33 +++++---------- src/protocol.c | 30 +++++-------- src/protocol_auth.c | 33 +++++---------- src/protocol_edge.c | 12 ++---- src/protocol_key.c | 18 +++----- src/raw_socket/device.c | 15 +++---- src/solaris/device.c | 15 +++---- src/uml_socket/device.c | 15 +++---- 30 files changed, 233 insertions(+), 466 deletions(-) diff --git a/lib/avl_tree.c b/lib/avl_tree.c index 3bfdfeee..c1856c7f 100644 --- a/lib/avl_tree.c +++ b/lib/avl_tree.c @@ -54,8 +54,7 @@ #ifndef AVL_DEPTH static int lg(unsigned int u) __attribute__ ((__const__)); -static int lg(unsigned int u) -{ +static int lg(unsigned int u) { int r = 1; if(!u) @@ -90,8 +89,7 @@ static int lg(unsigned int u) /* Internal helper functions */ -static int avl_check_balance(const avl_node_t *node) -{ +static int avl_check_balance(const avl_node_t *node) { #ifdef AVL_DEPTH int d; @@ -118,8 +116,7 @@ static int avl_check_balance(const avl_node_t *node) #endif } -static void avl_rebalance(avl_tree_t *tree, avl_node_t *node) -{ +static void avl_rebalance(avl_tree_t *tree, avl_node_t *node) { avl_node_t *child; avl_node_t *gchild; avl_node_t *parent; @@ -262,8 +259,7 @@ static void avl_rebalance(avl_tree_t *tree, avl_node_t *node) /* (De)constructors */ -avl_tree_t *avl_alloc_tree(avl_compare_t compare, avl_action_t delete) -{ +avl_tree_t *avl_alloc_tree(avl_compare_t compare, avl_action_t delete) { avl_tree_t *tree; tree = xmalloc_and_zero(sizeof(avl_tree_t)); @@ -273,18 +269,15 @@ avl_tree_t *avl_alloc_tree(avl_compare_t compare, avl_action_t delete) return tree; } -void avl_free_tree(avl_tree_t *tree) -{ +void avl_free_tree(avl_tree_t *tree) { free(tree); } -avl_node_t *avl_alloc_node(void) -{ +avl_node_t *avl_alloc_node(void) { return xmalloc_and_zero(sizeof(avl_node_t)); } -void avl_free_node(avl_tree_t *tree, avl_node_t *node) -{ +void avl_free_node(avl_tree_t *tree, avl_node_t *node) { if(node->data && tree->delete) tree->delete(node->data); @@ -293,8 +286,7 @@ void avl_free_node(avl_tree_t *tree, avl_node_t *node) /* Searching */ -void *avl_search(const avl_tree_t *tree, const void *data) -{ +void *avl_search(const avl_tree_t *tree, const void *data) { avl_node_t *node; node = avl_search_node(tree, data); @@ -302,8 +294,7 @@ void *avl_search(const avl_tree_t *tree, const void *data) return node ? node->data : NULL; } -void *avl_search_closest(const avl_tree_t *tree, const void *data, int *result) -{ +void *avl_search_closest(const avl_tree_t *tree, const void *data, int *result) { avl_node_t *node; node = avl_search_closest_node(tree, data, result); @@ -311,8 +302,7 @@ void *avl_search_closest(const avl_tree_t *tree, const void *data, int *result) return node ? node->data : NULL; } -void *avl_search_closest_smaller(const avl_tree_t *tree, const void *data) -{ +void *avl_search_closest_smaller(const avl_tree_t *tree, const void *data) { avl_node_t *node; node = avl_search_closest_smaller_node(tree, data); @@ -320,8 +310,7 @@ void *avl_search_closest_smaller(const avl_tree_t *tree, const void *data) return node ? node->data : NULL; } -void *avl_search_closest_greater(const avl_tree_t *tree, const void *data) -{ +void *avl_search_closest_greater(const avl_tree_t *tree, const void *data) { avl_node_t *node; node = avl_search_closest_greater_node(tree, data); @@ -329,8 +318,7 @@ void *avl_search_closest_greater(const avl_tree_t *tree, const void *data) return node ? node->data : NULL; } -avl_node_t *avl_search_node(const avl_tree_t *tree, const void *data) -{ +avl_node_t *avl_search_node(const avl_tree_t *tree, const void *data) { avl_node_t *node; int result; @@ -340,8 +328,7 @@ avl_node_t *avl_search_node(const avl_tree_t *tree, const void *data) } avl_node_t *avl_search_closest_node(const avl_tree_t *tree, const void *data, - int *result) -{ + int *result) { avl_node_t *node; int c; @@ -383,8 +370,7 @@ avl_node_t *avl_search_closest_node(const avl_tree_t *tree, const void *data, } avl_node_t *avl_search_closest_smaller_node(const avl_tree_t *tree, - const void *data) -{ + const void *data) { avl_node_t *node; int result; @@ -397,8 +383,7 @@ avl_node_t *avl_search_closest_smaller_node(const avl_tree_t *tree, } avl_node_t *avl_search_closest_greater_node(const avl_tree_t *tree, - const void *data) -{ + const void *data) { avl_node_t *node; int result; @@ -412,8 +397,7 @@ avl_node_t *avl_search_closest_greater_node(const avl_tree_t *tree, /* Insertion and deletion */ -avl_node_t *avl_insert(avl_tree_t *tree, void *data) -{ +avl_node_t *avl_insert(avl_tree_t *tree, void *data) { avl_node_t *closest, *new; int result; @@ -452,8 +436,7 @@ avl_node_t *avl_insert(avl_tree_t *tree, void *data) return new; } -avl_node_t *avl_insert_node(avl_tree_t *tree, avl_node_t *node) -{ +avl_node_t *avl_insert_node(avl_tree_t *tree, avl_node_t *node) { avl_node_t *closest; int result; @@ -486,15 +469,13 @@ avl_node_t *avl_insert_node(avl_tree_t *tree, avl_node_t *node) return node; } -void avl_insert_top(avl_tree_t *tree, avl_node_t *node) -{ +void avl_insert_top(avl_tree_t *tree, avl_node_t *node) { node->prev = node->next = node->parent = NULL; tree->head = tree->tail = tree->root = node; } void avl_insert_before(avl_tree_t *tree, avl_node_t *before, - avl_node_t *node) -{ + avl_node_t *node) { if(!before) { if(tree->tail) avl_insert_after(tree, tree->tail, node); @@ -523,8 +504,7 @@ void avl_insert_before(avl_tree_t *tree, avl_node_t *before, avl_rebalance(tree, before); } -void avl_insert_after(avl_tree_t *tree, avl_node_t *after, avl_node_t *node) -{ +void avl_insert_after(avl_tree_t *tree, avl_node_t *after, avl_node_t *node) { if(!after) { if(tree->head) avl_insert_before(tree, tree->head, node); @@ -553,8 +533,7 @@ void avl_insert_after(avl_tree_t *tree, avl_node_t *after, avl_node_t *node) avl_rebalance(tree, after); } -avl_node_t *avl_unlink(avl_tree_t *tree, void *data) -{ +avl_node_t *avl_unlink(avl_tree_t *tree, void *data) { avl_node_t *node; node = avl_search_node(tree, data); @@ -565,8 +544,7 @@ avl_node_t *avl_unlink(avl_tree_t *tree, void *data) return node; } -void avl_unlink_node(avl_tree_t *tree, avl_node_t *node) -{ +void avl_unlink_node(avl_tree_t *tree, avl_node_t *node) { avl_node_t *parent; avl_node_t **superparent; avl_node_t *subst, *left, *right; @@ -634,14 +612,12 @@ void avl_unlink_node(avl_tree_t *tree, avl_node_t *node) #endif } -void avl_delete_node(avl_tree_t *tree, avl_node_t *node) -{ +void avl_delete_node(avl_tree_t *tree, avl_node_t *node) { avl_unlink_node(tree, node); avl_free_node(tree, node); } -void avl_delete(avl_tree_t *tree, void *data) -{ +void avl_delete(avl_tree_t *tree, void *data) { avl_node_t *node; node = avl_search_node(tree, data); @@ -652,8 +628,7 @@ void avl_delete(avl_tree_t *tree, void *data) /* Fast tree cleanup */ -void avl_delete_tree(avl_tree_t *tree) -{ +void avl_delete_tree(avl_tree_t *tree) { avl_node_t *node, *next; for(node = tree->head; node; node = next) { @@ -666,8 +641,7 @@ void avl_delete_tree(avl_tree_t *tree) /* Tree walking */ -void avl_foreach(const avl_tree_t *tree, avl_action_t action) -{ +void avl_foreach(const avl_tree_t *tree, avl_action_t action) { avl_node_t *node, *next; for(node = tree->head; node; node = next) { @@ -676,8 +650,7 @@ void avl_foreach(const avl_tree_t *tree, avl_action_t action) } } -void avl_foreach_node(const avl_tree_t *tree, avl_action_t action) -{ +void avl_foreach_node(const avl_tree_t *tree, avl_action_t action) { avl_node_t *node, *next; for(node = tree->head; node; node = next) { @@ -689,13 +662,11 @@ void avl_foreach_node(const avl_tree_t *tree, avl_action_t action) /* Indexing */ #ifdef AVL_COUNT -unsigned int avl_count(const avl_tree_t *tree) -{ +unsigned int avl_count(const avl_tree_t *tree) { return AVL_NODE_COUNT(tree->root); } -avl_node_t *avl_get_node(const avl_tree_t *tree, unsigned int index) -{ +avl_node_t *avl_get_node(const avl_tree_t *tree, unsigned int index) { avl_node_t *node; unsigned int c; @@ -717,8 +688,7 @@ avl_node_t *avl_get_node(const avl_tree_t *tree, unsigned int index) return NULL; } -unsigned int avl_index(const avl_node_t *node) -{ +unsigned int avl_index(const avl_node_t *node) { avl_node_t *next; unsigned int index; @@ -734,8 +704,7 @@ unsigned int avl_index(const avl_node_t *node) } #endif #ifdef AVL_DEPTH -unsigned int avl_depth(const avl_tree_t *tree) -{ +unsigned int avl_depth(const avl_tree_t *tree) { return AVL_NODE_DEPTH(tree->root); } #endif diff --git a/lib/dropin.c b/lib/dropin.c index a3c28b04..773fe488 100644 --- a/lib/dropin.c +++ b/lib/dropin.c @@ -38,8 +38,7 @@ Unless the argument noclose is non-zero, daemon() will redirect standard input, standard output and standard error to /dev/null. */ -int daemon(int nochdir, int noclose) -{ +int daemon(int nochdir, int noclose) { #ifdef HAVE_FORK pid_t pid; int fd; @@ -97,8 +96,7 @@ int daemon(int nochdir, int noclose) current directory name. If the environment variable PWD is set, and its value is correct, then that value will be returned. */ -char *get_current_dir_name(void) -{ +char *get_current_dir_name(void) { size_t size; char *buf; char *r; @@ -125,8 +123,7 @@ char *get_current_dir_name(void) #endif #ifndef HAVE_ASPRINTF -int asprintf(char **buf, const char *fmt, ...) -{ +int asprintf(char **buf, const char *fmt, ...) { int status; va_list ap; int len; diff --git a/lib/fake-getaddrinfo.c b/lib/fake-getaddrinfo.c index 14420b58..0c27025b 100644 --- a/lib/fake-getaddrinfo.c +++ b/lib/fake-getaddrinfo.c @@ -17,8 +17,7 @@ #include "xalloc.h" #ifndef HAVE_GAI_STRERROR -char *gai_strerror(int ecode) -{ +char *gai_strerror(int ecode) { switch (ecode) { case EAI_NODATA: return "No address associated with hostname"; @@ -33,8 +32,7 @@ char *gai_strerror(int ecode) #endif /* !HAVE_GAI_STRERROR */ #ifndef HAVE_FREEADDRINFO -void freeaddrinfo(struct addrinfo *ai) -{ +void freeaddrinfo(struct addrinfo *ai) { struct addrinfo *next; while(ai) { @@ -46,8 +44,7 @@ void freeaddrinfo(struct addrinfo *ai) #endif /* !HAVE_FREEADDRINFO */ #ifndef HAVE_GETADDRINFO -static struct addrinfo *malloc_ai(uint16_t port, uint32_t addr) -{ +static struct addrinfo *malloc_ai(uint16_t port, uint32_t addr) { struct addrinfo *ai; ai = xmalloc_and_zero(sizeof(struct addrinfo) + sizeof(struct sockaddr_in)); @@ -62,8 +59,7 @@ static struct addrinfo *malloc_ai(uint16_t port, uint32_t addr) return ai; } -int getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res) -{ +int getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res) { struct addrinfo *prev = NULL; struct hostent *hp; struct in_addr in = {0}; diff --git a/lib/fake-getnameinfo.c b/lib/fake-getnameinfo.c index 796efdf8..05f0875a 100644 --- a/lib/fake-getnameinfo.c +++ b/lib/fake-getnameinfo.c @@ -16,8 +16,7 @@ #ifndef HAVE_GETNAMEINFO -int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) -{ +int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) { struct sockaddr_in *sin = (struct sockaddr_in *)sa; struct hostent *hp; int len; diff --git a/lib/list.c b/lib/list.c index 2f9f611d..c5dccb79 100644 --- a/lib/list.c +++ b/lib/list.c @@ -27,8 +27,7 @@ /* (De)constructors */ -list_t *list_alloc(list_action_t delete) -{ +list_t *list_alloc(list_action_t delete) { list_t *list; list = xmalloc_and_zero(sizeof(list_t)); @@ -37,18 +36,15 @@ list_t *list_alloc(list_action_t delete) return list; } -void list_free(list_t *list) -{ +void list_free(list_t *list) { free(list); } -list_node_t *list_alloc_node(void) -{ +list_node_t *list_alloc_node(void) { return xmalloc_and_zero(sizeof(list_node_t)); } -void list_free_node(list_t *list, list_node_t *node) -{ +void list_free_node(list_t *list, list_node_t *node) { if(node->data && list->delete) list->delete(node->data); @@ -57,8 +53,7 @@ void list_free_node(list_t *list, list_node_t *node) /* Insertion and deletion */ -list_node_t *list_insert_head(list_t *list, void *data) -{ +list_node_t *list_insert_head(list_t *list, void *data) { list_node_t *node; node = list_alloc_node(); @@ -78,8 +73,7 @@ list_node_t *list_insert_head(list_t *list, void *data) return node; } -list_node_t *list_insert_tail(list_t *list, void *data) -{ +list_node_t *list_insert_tail(list_t *list, void *data) { list_node_t *node; node = list_alloc_node(); @@ -99,8 +93,7 @@ list_node_t *list_insert_tail(list_t *list, void *data) return node; } -void list_unlink_node(list_t *list, list_node_t *node) -{ +void list_unlink_node(list_t *list, list_node_t *node) { if(node->prev) node->prev->next = node->next; else @@ -114,34 +107,29 @@ void list_unlink_node(list_t *list, list_node_t *node) list->count--; } -void list_delete_node(list_t *list, list_node_t *node) -{ +void list_delete_node(list_t *list, list_node_t *node) { list_unlink_node(list, node); list_free_node(list, node); } -void list_delete_head(list_t *list) -{ +void list_delete_head(list_t *list) { list_delete_node(list, list->head); } -void list_delete_tail(list_t *list) -{ +void list_delete_tail(list_t *list) { list_delete_node(list, list->tail); } /* Head/tail lookup */ -void *list_get_head(list_t *list) -{ +void *list_get_head(list_t *list) { if(list->head) return list->head->data; else return NULL; } -void *list_get_tail(list_t *list) -{ +void *list_get_tail(list_t *list) { if(list->tail) return list->tail->data; else @@ -150,8 +138,7 @@ void *list_get_tail(list_t *list) /* Fast list deletion */ -void list_delete_list(list_t *list) -{ +void list_delete_list(list_t *list) { list_node_t *node, *next; for(node = list->head; node; node = next) { @@ -164,8 +151,7 @@ void list_delete_list(list_t *list) /* Traversing */ -void list_foreach_node(list_t *list, list_action_node_t action) -{ +void list_foreach_node(list_t *list, list_action_node_t action) { list_node_t *node, *next; for(node = list->head; node; node = next) { @@ -174,8 +160,7 @@ void list_foreach_node(list_t *list, list_action_node_t action) } } -void list_foreach(list_t *list, list_action_t action) -{ +void list_foreach(list_t *list, list_action_t action) { list_node_t *node, *next; for(node = list->head; node; node = next) { diff --git a/lib/pidfile.c b/lib/pidfile.c index 830d3f35..b67e1876 100644 --- a/lib/pidfile.c +++ b/lib/pidfile.c @@ -34,8 +34,7 @@ * 0 is returned if either there's no pidfile, it's empty * or no pid can be read. */ -pid_t read_pid (char *pidfile) -{ +pid_t read_pid (char *pidfile) { FILE *f; long pid; @@ -52,8 +51,7 @@ pid_t read_pid (char *pidfile) * table (using /proc) to determine if the process already exists. If * so the pid is returned, otherwise 0. */ -pid_t check_pid (char *pidfile) -{ +pid_t check_pid (char *pidfile) { pid_t pid = read_pid(pidfile); /* Amazing ! _I_ am already holding the pid file... */ @@ -78,8 +76,7 @@ pid_t check_pid (char *pidfile) * Writes the pid to the specified file. If that fails 0 is * returned, otherwise the pid. */ -pid_t write_pid (char *pidfile) -{ +pid_t write_pid (char *pidfile) { FILE *f; int fd; pid_t pid; @@ -123,8 +120,7 @@ pid_t write_pid (char *pidfile) * Remove the the specified file. The result from unlink(2) * is returned */ -int remove_pid (char *pidfile) -{ +int remove_pid (char *pidfile) { return unlink (pidfile); } #endif diff --git a/lib/utils.c b/lib/utils.c index 4b93b042..b00a73bc 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -31,8 +31,7 @@ volatile int cp_index = 0; char *hexadecimals = "0123456789ABCDEF"; -int charhex2bin(char c) -{ +int charhex2bin(char c) { if(isdigit(c)) return c - '0'; else @@ -40,15 +39,13 @@ int charhex2bin(char c) } -void hex2bin(char *src, char *dst, int length) -{ +void hex2bin(char *src, char *dst, int length) { int i; for(i = 0; i < length; i++) dst[i] = charhex2bin(src[i * 2]) * 16 + charhex2bin(src[i * 2 + 1]); } -void bin2hex(char *src, char *dst, int length) -{ +void bin2hex(char *src, char *dst, int length) { int i; for(i = length - 1; i >= 0; i--) { dst[i * 2 + 1] = hexadecimals[(unsigned char) src[i] & 15]; @@ -57,8 +54,7 @@ void bin2hex(char *src, char *dst, int length) } #ifdef ENABLE_TRACING -void cp_trace() -{ +void cp_trace() { logger(LOG_DEBUG, "Checkpoint trace: %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d...", cp_file[(cp_index + 15) % 16], cp_line[(cp_index + 15) % 16], cp_file[(cp_index + 14) % 16], cp_line[(cp_index + 14) % 16], diff --git a/src/bsd/device.c b/src/bsd/device.c index 5bd253cf..474612f1 100644 --- a/src/bsd/device.c +++ b/src/bsd/device.c @@ -227,8 +227,7 @@ bool read_packet(vpn_packet_t *packet) { return true; } -bool write_packet(vpn_packet_t *packet) -{ +bool write_packet(vpn_packet_t *packet) { cp(); ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Writing packet of %d bytes to %s"), @@ -289,8 +288,7 @@ bool write_packet(vpn_packet_t *packet) return true; } -void dump_device_stats(void) -{ +void dump_device_stats(void) { cp(); logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device); diff --git a/src/conf.c b/src/conf.c index 56810337..87e2ec54 100644 --- a/src/conf.c +++ b/src/conf.c @@ -38,8 +38,7 @@ int pingtimeout = 0; /* seconds to wait for response */ char *confbase = NULL; /* directory in which all config files are */ char *netname = NULL; /* name of the vpn network */ -static int config_compare(const config_t *a, const config_t *b) -{ +static int config_compare(const config_t *a, const config_t *b) { int result; result = strcasecmp(a->variable, b->variable); @@ -55,30 +54,26 @@ static int config_compare(const config_t *a, const config_t *b) return strcmp(a->file, b->file); } -void init_configuration(avl_tree_t ** config_tree) -{ +void init_configuration(avl_tree_t ** config_tree) { cp(); *config_tree = avl_alloc_tree((avl_compare_t) config_compare, (avl_action_t) free_config); } -void exit_configuration(avl_tree_t ** config_tree) -{ +void exit_configuration(avl_tree_t ** config_tree) { cp(); avl_delete_tree(*config_tree); *config_tree = NULL; } -config_t *new_config(void) -{ +config_t *new_config(void) { cp(); return xmalloc_and_zero(sizeof(config_t)); } -void free_config(config_t *cfg) -{ +void free_config(config_t *cfg) { cp(); if(cfg->variable) @@ -93,15 +88,13 @@ void free_config(config_t *cfg) free(cfg); } -void config_add(avl_tree_t *config_tree, config_t *cfg) -{ +void config_add(avl_tree_t *config_tree, config_t *cfg) { cp(); avl_insert(config_tree, cfg); } -config_t *lookup_config(avl_tree_t *config_tree, char *variable) -{ +config_t *lookup_config(avl_tree_t *config_tree, char *variable) { config_t cfg, *found; cp(); @@ -121,8 +114,7 @@ config_t *lookup_config(avl_tree_t *config_tree, char *variable) return found; } -config_t *lookup_config_next(avl_tree_t *config_tree, const config_t *cfg) -{ +config_t *lookup_config_next(avl_tree_t *config_tree, const config_t *cfg) { avl_node_t *node; config_t *found; @@ -142,8 +134,7 @@ config_t *lookup_config_next(avl_tree_t *config_tree, const config_t *cfg) return NULL; } -bool get_config_bool(const config_t *cfg, bool *result) -{ +bool get_config_bool(const config_t *cfg, bool *result) { cp(); if(!cfg) @@ -163,8 +154,7 @@ bool get_config_bool(const config_t *cfg, bool *result) return false; } -bool get_config_int(const config_t *cfg, int *result) -{ +bool get_config_int(const config_t *cfg, int *result) { cp(); if(!cfg) @@ -179,8 +169,7 @@ bool get_config_int(const config_t *cfg, int *result) return false; } -bool get_config_string(const config_t *cfg, char **result) -{ +bool get_config_string(const config_t *cfg, char **result) { cp(); if(!cfg) @@ -191,8 +180,7 @@ bool get_config_string(const config_t *cfg, char **result) return true; } -bool get_config_address(const config_t *cfg, struct addrinfo **result) -{ +bool get_config_address(const config_t *cfg, struct addrinfo **result) { struct addrinfo *ai; cp(); @@ -213,8 +201,7 @@ bool get_config_address(const config_t *cfg, struct addrinfo **result) return false; } -bool get_config_subnet(const config_t *cfg, subnet_t ** result) -{ +bool get_config_subnet(const config_t *cfg, subnet_t ** result) { subnet_t subnet = {0}; cp(); @@ -254,8 +241,7 @@ bool get_config_subnet(const config_t *cfg, subnet_t ** result) given, and buf needs to be expanded, the var pointed to by buflen will be increased. */ -static char *readline(FILE * fp, char **buf, size_t *buflen) -{ +static char *readline(FILE * fp, char **buf, size_t *buflen) { char *newline = NULL; char *p; char *line; /* The array that contains everything that has been read so far */ @@ -317,8 +303,7 @@ static char *readline(FILE * fp, char **buf, size_t *buflen) Parse a configuration file and put the results in the configuration tree starting at *base. */ -int read_config_file(avl_tree_t *config_tree, const char *fname) -{ +int read_config_file(avl_tree_t *config_tree, const char *fname) { int err = -2; /* Parse error */ FILE *fp; char *buffer, *line; @@ -408,8 +393,7 @@ int read_config_file(avl_tree_t *config_tree, const char *fname) return err; } -bool read_server_config() -{ +bool read_server_config() { char *fname; int x; @@ -427,8 +411,7 @@ bool read_server_config() return x == 0; } -FILE *ask_and_open(const char *filename, const char *what, const char *mode) -{ +FILE *ask_and_open(const char *filename, const char *what, const char *mode) { FILE *r; char *directory; char *fn; diff --git a/src/connection.c b/src/connection.c index 5cd7a747..58e2d355 100644 --- a/src/connection.c +++ b/src/connection.c @@ -35,13 +35,11 @@ avl_tree_t *connection_tree; /* Meta connections */ connection_t *broadcast; -static int connection_compare(const connection_t *a, const connection_t *b) -{ +static int connection_compare(const connection_t *a, const connection_t *b) { return (void *)a - (void *)b; } -void init_connections(void) -{ +void init_connections(void) { cp(); connection_tree = avl_alloc_tree((avl_compare_t) connection_compare, (avl_action_t) free_connection); @@ -50,16 +48,14 @@ void init_connections(void) broadcast->hostname = xstrdup(_("BROADCAST")); } -void exit_connections(void) -{ +void exit_connections(void) { cp(); avl_delete_tree(connection_tree); free_connection(broadcast); } -connection_t *new_connection(void) -{ +connection_t *new_connection(void) { connection_t *c; cp(); @@ -75,8 +71,7 @@ connection_t *new_connection(void) return c; } -void free_connection(connection_t *c) -{ +void free_connection(connection_t *c) { cp(); if(!c) @@ -104,22 +99,19 @@ void free_connection(connection_t *c) free(c); } -void connection_add(connection_t *c) -{ +void connection_add(connection_t *c) { cp(); avl_insert(connection_tree, c); } -void connection_del(connection_t *c) -{ +void connection_del(connection_t *c) { cp(); avl_delete(connection_tree, c); } -void dump_connections(void) -{ +void dump_connections(void) { avl_node_t *node; connection_t *c; @@ -137,8 +129,7 @@ void dump_connections(void) logger(LOG_DEBUG, _("End of connections.")); } -bool read_connection_config(connection_t *c) -{ +bool read_connection_config(connection_t *c) { char *fname; int x; diff --git a/src/cygwin/device.c b/src/cygwin/device.c index 3be59ce9..db8cc9e6 100644 --- a/src/cygwin/device.c +++ b/src/cygwin/device.c @@ -46,8 +46,7 @@ static int device_total_out = 0; static pid_t reader_pid; static int sp[2]; -bool setup_device(void) -{ +bool setup_device(void) { HKEY key, key2; int i, err; @@ -218,8 +217,7 @@ bool setup_device(void) return true; } -void close_device(void) -{ +void close_device(void) { cp(); close(sp[0]); @@ -229,8 +227,7 @@ void close_device(void) kill(reader_pid, SIGKILL); } -bool read_packet(vpn_packet_t *packet) -{ +bool read_packet(vpn_packet_t *packet) { int lenin; cp(); @@ -251,8 +248,7 @@ bool read_packet(vpn_packet_t *packet) return true; } -bool write_packet(vpn_packet_t *packet) -{ +bool write_packet(vpn_packet_t *packet) { long lenout; cp(); @@ -270,8 +266,7 @@ bool write_packet(vpn_packet_t *packet) return true; } -void dump_device_stats(void) -{ +void dump_device_stats(void) { cp(); logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device); diff --git a/src/edge.c b/src/edge.c index 99ec1415..97a57a64 100644 --- a/src/edge.c +++ b/src/edge.c @@ -32,13 +32,11 @@ avl_tree_t *edge_weight_tree; /* Tree with all edges, sorted on weight */ -static int edge_compare(const edge_t *a, const edge_t *b) -{ +static int edge_compare(const edge_t *a, const edge_t *b) { return strcmp(a->to->name, b->to->name); } -static int edge_weight_compare(const edge_t *a, const edge_t *b) -{ +static int edge_weight_compare(const edge_t *a, const edge_t *b) { int result; result = a->weight - b->weight; @@ -54,29 +52,25 @@ static int edge_weight_compare(const edge_t *a, const edge_t *b) return strcmp(a->to->name, b->to->name); } -void init_edges(void) -{ +void init_edges(void) { cp(); edge_weight_tree = avl_alloc_tree((avl_compare_t) edge_weight_compare, NULL); } -avl_tree_t *new_edge_tree(void) -{ +avl_tree_t *new_edge_tree(void) { cp(); return avl_alloc_tree((avl_compare_t) edge_compare, (avl_action_t) free_edge); } -void free_edge_tree(avl_tree_t *edge_tree) -{ +void free_edge_tree(avl_tree_t *edge_tree) { cp(); avl_delete_tree(edge_tree); } -void exit_edges(void) -{ +void exit_edges(void) { cp(); avl_delete_tree(edge_weight_tree); @@ -84,15 +78,13 @@ void exit_edges(void) /* Creation and deletion of connection elements */ -edge_t *new_edge(void) -{ +edge_t *new_edge(void) { cp(); return xmalloc_and_zero(sizeof(edge_t)); } -void free_edge(edge_t *e) -{ +void free_edge(edge_t *e) { cp(); sockaddrfree(&e->address); @@ -100,8 +92,7 @@ void free_edge(edge_t *e) free(e); } -void edge_add(edge_t *e) -{ +void edge_add(edge_t *e) { cp(); avl_insert(edge_weight_tree, e); @@ -113,8 +104,7 @@ void edge_add(edge_t *e) e->reverse->reverse = e; } -void edge_del(edge_t *e) -{ +void edge_del(edge_t *e) { cp(); if(e->reverse) @@ -124,8 +114,7 @@ void edge_del(edge_t *e) avl_delete(e->from->edge_tree, e); } -edge_t *lookup_edge(node_t *from, node_t *to) -{ +edge_t *lookup_edge(node_t *from, node_t *to) { edge_t v; cp(); @@ -136,8 +125,7 @@ edge_t *lookup_edge(node_t *from, node_t *to) return avl_search(from->edge_tree, &v); } -void dump_edges(void) -{ +void dump_edges(void) { avl_node_t *node, *node2; node_t *n; edge_t *e; diff --git a/src/graph.c b/src/graph.c index 95894772..c04cef40 100644 --- a/src/graph.c +++ b/src/graph.c @@ -63,8 +63,7 @@ Please note that sorting on weight is already done by add_edge(). */ -void mst_kruskal(void) -{ +void mst_kruskal(void) { avl_node_t *node, *next; edge_t *e; node_t *n; @@ -147,8 +146,7 @@ void mst_kruskal(void) Running time: O(E) */ -void sssp_bfs(void) -{ +void sssp_bfs(void) { avl_node_t *node, *next, *to; edge_t *e; node_t *n; @@ -315,8 +313,7 @@ void sssp_bfs(void) dot -Tpng graph_filename -o image_filename.png -Gconcentrate=true */ -static void dump_graph(int fd, short events, void *data) -{ +static void dump_graph(int fd, short events, void *data) { avl_node_t *node; node_t *n; edge_t *e; @@ -369,8 +366,7 @@ static void dump_graph(int fd, short events, void *data) } } -void graph(void) -{ +void graph(void) { static struct event ev; sssp_bfs(); diff --git a/src/linux/device.c b/src/linux/device.c index 302fa628..519896e7 100644 --- a/src/linux/device.c +++ b/src/linux/device.c @@ -51,8 +51,7 @@ char *device_info; static int device_total_in = 0; static int device_total_out = 0; -bool setup_device(void) -{ +bool setup_device(void) { struct ifreq ifr; cp(); @@ -112,15 +111,13 @@ bool setup_device(void) return true; } -void close_device(void) -{ +void close_device(void) { cp(); close(device_fd); } -bool read_packet(vpn_packet_t *packet) -{ +bool read_packet(vpn_packet_t *packet) { int lenin; cp(); @@ -169,8 +166,7 @@ bool read_packet(vpn_packet_t *packet) return true; } -bool write_packet(vpn_packet_t *packet) -{ +bool write_packet(vpn_packet_t *packet) { cp(); ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Writing packet of %d bytes to %s"), @@ -208,8 +204,7 @@ bool write_packet(vpn_packet_t *packet) return true; } -void dump_device_stats(void) -{ +void dump_device_stats(void) { cp(); logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device); diff --git a/src/meta.c b/src/meta.c index b7546267..4ed1384b 100644 --- a/src/meta.c +++ b/src/meta.c @@ -34,8 +34,7 @@ #include "utils.h" #include "xalloc.h" -bool send_meta(connection_t *c, const char *buffer, int length) -{ +bool send_meta(connection_t *c, const char *buffer, int length) { int outlen; int result; @@ -83,8 +82,7 @@ bool send_meta(connection_t *c, const char *buffer, int length) return true; } -void flush_meta(int fd, short events, void *data) -{ +void flush_meta(int fd, short events, void *data) { connection_t *c = data; int result; @@ -123,8 +121,7 @@ void flush_meta(int fd, short events, void *data) c->outbufstart = 0; /* avoid unnecessary memmoves */ } -void broadcast_meta(connection_t *from, const char *buffer, int length) -{ +void broadcast_meta(connection_t *from, const char *buffer, int length) { avl_node_t *node; connection_t *c; @@ -138,8 +135,7 @@ void broadcast_meta(connection_t *from, const char *buffer, int length) } } -bool receive_meta(connection_t *c) -{ +bool receive_meta(connection_t *c) { int oldlen, i, result; int lenin, lenout, reqlen; bool decrypted = false; diff --git a/src/mingw/device.c b/src/mingw/device.c index 2813a883..0e203e64 100644 --- a/src/mingw/device.c +++ b/src/mingw/device.c @@ -123,8 +123,7 @@ DWORD WINAPI tapreader(void *bla) { } } -bool setup_device(void) -{ +bool setup_device(void) { HKEY key, key2; int i; @@ -308,15 +307,13 @@ bool setup_device(void) return true; } -void close_device(void) -{ +void close_device(void) { cp(); CloseHandle(device_handle); } -bool read_packet(vpn_packet_t *packet) -{ +bool read_packet(vpn_packet_t *packet) { unsigned char bufno; cp(); @@ -338,8 +335,7 @@ bool read_packet(vpn_packet_t *packet) return true; } -bool write_packet(vpn_packet_t *packet) -{ +bool write_packet(vpn_packet_t *packet) { long lenout; OVERLAPPED overlapped = {0}; @@ -358,8 +354,7 @@ bool write_packet(vpn_packet_t *packet) return true; } -void dump_device_stats(void) -{ +void dump_device_stats(void) { cp(); logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device); diff --git a/src/net.c b/src/net.c index 5638e64d..33d90da8 100644 --- a/src/net.c +++ b/src/net.c @@ -41,8 +41,7 @@ /* Purge edges and subnets of unreachable nodes. Use carefully. */ -static void purge(void) -{ +static void purge(void) { avl_node_t *nnode, *nnext, *enode, *enext, *snode, *snext; node_t *n; edge_t *e; @@ -105,8 +104,7 @@ static void purge(void) put all file descriptors into events While we're at it, purge stuf that needs to be removed. */ -static int build_fdset(void) -{ +static int build_fdset(void) { avl_node_t *node, *next; connection_t *c; int i, max = 0; @@ -134,8 +132,7 @@ static int build_fdset(void) - Check if we need to retry making an outgoing connection - Deactivate the host */ -void terminate_connection(connection_t *c, bool report) -{ +void terminate_connection(connection_t *c, bool report) { cp(); if(c->status.remove) @@ -200,8 +197,7 @@ void terminate_connection(connection_t *c, bool report) end does not reply in time, we consider them dead and close the connection. */ -static void timeout_handler(int fd, short events, void *event) -{ +static void timeout_handler(int fd, short events, void *event) { avl_node_t *node, *next; connection_t *c; time_t now = time(NULL); @@ -245,8 +241,7 @@ static void timeout_handler(int fd, short events, void *event) event_add(event, &(struct timeval){pingtimeout, 0}); } -void handle_meta_connection_data(int fd, short events, void *data) -{ +void handle_meta_connection_data(int fd, short events, void *data) { connection_t *c = data; int result; socklen_t len = sizeof(result); @@ -387,8 +382,7 @@ static void sigalrm_handler(int signal, short events, void *data) { /* this is where it all happens... */ -int main_loop(void) -{ +int main_loop(void) { struct timeval tv; int r; struct event timeout_event; diff --git a/src/net_packet.c b/src/net_packet.c index 61465a25..4269d422 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -114,8 +114,7 @@ void mtu_probe_h(node_t *n, vpn_packet_t *packet) { } } -static length_t compress_packet(uint8_t *dest, const uint8_t *source, length_t len, int level) -{ +static length_t compress_packet(uint8_t *dest, const uint8_t *source, length_t len, int level) { if(level == 10) { lzo_uint lzolen = MAXSIZE; lzo1x_1_compress(source, len, dest, &lzolen, lzo_wrkmem); @@ -135,8 +134,7 @@ static length_t compress_packet(uint8_t *dest, const uint8_t *source, length_t l return -1; } -static length_t uncompress_packet(uint8_t *dest, const uint8_t *source, length_t len, int level) -{ +static length_t uncompress_packet(uint8_t *dest, const uint8_t *source, length_t len, int level) { if(level > 9) { lzo_uint lzolen = MAXSIZE; if(lzo1x_decompress_safe(source, len, dest, &lzolen, NULL) == LZO_E_OK) @@ -156,8 +154,7 @@ static length_t uncompress_packet(uint8_t *dest, const uint8_t *source, length_t /* VPN packet I/O */ -static void receive_packet(node_t *n, vpn_packet_t *packet) -{ +static void receive_packet(node_t *n, vpn_packet_t *packet) { cp(); ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Received packet of %d bytes from %s (%s)"), @@ -166,8 +163,7 @@ static void receive_packet(node_t *n, vpn_packet_t *packet) route(n, packet); } -static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) -{ +static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) { vpn_packet_t pkt1, pkt2; vpn_packet_t *pkt[] = { &pkt1, &pkt2, &pkt1, &pkt2 }; int nextpkt = 0; @@ -269,8 +265,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) receive_packet(n, inpkt); } -void receive_tcppacket(connection_t *c, char *buffer, int len) -{ +void receive_tcppacket(connection_t *c, char *buffer, int len) { vpn_packet_t outpkt; cp(); @@ -281,8 +276,7 @@ void receive_tcppacket(connection_t *c, char *buffer, int len) receive_packet(c->node, &outpkt); } -static void send_udppacket(node_t *n, vpn_packet_t *origpkt) -{ +static void send_udppacket(node_t *n, vpn_packet_t *origpkt) { vpn_packet_t pkt1, pkt2; vpn_packet_t *pkt[] = { &pkt1, &pkt2, &pkt1, &pkt2 }; vpn_packet_t *inpkt = origpkt; @@ -407,8 +401,7 @@ end: /* send a packet to the given vpn ip. */ -void send_packet(const node_t *n, vpn_packet_t *packet) -{ +void send_packet(const node_t *n, vpn_packet_t *packet) { node_t *via; cp(); @@ -444,8 +437,7 @@ void send_packet(const node_t *n, vpn_packet_t *packet) /* Broadcast a packet using the minimum spanning tree */ -void broadcast_packet(const node_t *from, vpn_packet_t *packet) -{ +void broadcast_packet(const node_t *from, vpn_packet_t *packet) { avl_node_t *node; connection_t *c; @@ -465,8 +457,7 @@ void broadcast_packet(const node_t *from, vpn_packet_t *packet) } } -void flush_queue(node_t *n) -{ +void flush_queue(node_t *n) { list_node_t *node, *next; cp(); @@ -480,8 +471,7 @@ void flush_queue(node_t *n) } } -void handle_incoming_vpn_data(int sock, short events, void *data) -{ +void handle_incoming_vpn_data(int sock, short events, void *data) { vpn_packet_t pkt; char *hostname; sockaddr_t from; @@ -512,8 +502,7 @@ void handle_incoming_vpn_data(int sock, short events, void *data) receive_udppacket(n, &pkt); } -void handle_device_data(int sock, short events, void *data) -{ +void handle_device_data(int sock, short events, void *data) { vpn_packet_t packet; if(read_packet(&packet)) diff --git a/src/net_setup.c b/src/net_setup.c index 22a95615..327cdcc4 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -46,8 +46,7 @@ char *myport; static struct event device_ev; -bool read_rsa_public_key(connection_t *c) -{ +bool read_rsa_public_key(connection_t *c) { FILE *fp; char *fname; char *key; @@ -147,8 +146,7 @@ bool read_rsa_public_key(connection_t *c) return false; } -bool read_rsa_private_key(void) -{ +bool read_rsa_private_key(void) { FILE *fp; char *fname, *key, *pubkey; struct stat s; @@ -241,8 +239,7 @@ void regenerate_key() { /* Configure node_t myself and set up the local sockets (listen only) */ -bool setup_myself(void) -{ +bool setup_myself(void) { config_t *cfg; subnet_t *subnet; char *name, *hostname, *mode, *afname, *cipher, *digest; @@ -576,8 +573,7 @@ bool setup_myself(void) /* setup all initial network connections */ -bool setup_network_connections(void) -{ +bool setup_network_connections(void) { cp(); init_connections(); @@ -612,8 +608,7 @@ bool setup_network_connections(void) /* close all open network connections */ -void close_network_connections(void) -{ +void close_network_connections(void) { avl_node_t *node, *next; connection_t *c; char *envp[5]; diff --git a/src/net_socket.c b/src/net_socket.c index 287d6888..9c8ef05a 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -51,8 +51,7 @@ int listen_sockets; /* Setup sockets */ -static void configure_tcp(connection_t *c) -{ +static void configure_tcp(connection_t *c) { int option; #ifdef O_NONBLOCK @@ -80,8 +79,7 @@ static void configure_tcp(connection_t *c) #endif } -int setup_listen_socket(const sockaddr_t *sa) -{ +int setup_listen_socket(const sockaddr_t *sa) { int nfd; char *addrstr; int option; @@ -139,8 +137,7 @@ int setup_listen_socket(const sockaddr_t *sa) return nfd; } -int setup_vpn_in_socket(const sockaddr_t *sa) -{ +int setup_vpn_in_socket(const sockaddr_t *sa) { int nfd; char *addrstr; int option; @@ -253,8 +250,7 @@ void retry_outgoing(outgoing_t *outgoing) { outgoing->timeout); } -void finish_connecting(connection_t *c) -{ +void finish_connecting(connection_t *c) { cp(); ifdebug(CONNECTIONS) logger(LOG_INFO, _("Connected to %s (%s)"), c->name, c->hostname); @@ -267,8 +263,7 @@ void finish_connecting(connection_t *c) send_id(c); } -void do_outgoing_connection(connection_t *c) -{ +void do_outgoing_connection(connection_t *c) { char *address, *port; int result; @@ -353,8 +348,7 @@ begin: return; } -void setup_outgoing_connection(outgoing_t *outgoing) -{ +void setup_outgoing_connection(outgoing_t *outgoing) { connection_t *c; node_t *n; @@ -409,8 +403,7 @@ void setup_outgoing_connection(outgoing_t *outgoing) accept a new tcp connect and create a new connection */ -void handle_new_meta_connection(int sock, short events, void *data) -{ +void handle_new_meta_connection(int sock, short events, void *data) { connection_t *c; sockaddr_t sa; int fd; @@ -457,8 +450,7 @@ void handle_new_meta_connection(int sock, short events, void *data) send_id(c); } -void try_outgoing_connections(void) -{ +void try_outgoing_connections(void) { static config_t *cfg = NULL; char *name; outgoing_t *outgoing; diff --git a/src/netutl.c b/src/netutl.c index 83e19ed8..ca30ec49 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -34,8 +34,7 @@ bool hostnames = false; Turn a string into a struct addrinfo. Return NULL on failure. */ -struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype) -{ +struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype) { struct addrinfo *ai, hint = {0}; int err; @@ -55,8 +54,7 @@ struct addrinfo *str2addrinfo(const char *address, const char *service, int sock return ai; } -sockaddr_t str2sockaddr(const char *address, const char *port) -{ +sockaddr_t str2sockaddr(const char *address, const char *port) { struct addrinfo *ai, hint = {0}; sockaddr_t result; int err; @@ -84,8 +82,7 @@ sockaddr_t str2sockaddr(const char *address, const char *port) return result; } -void sockaddr2str(const sockaddr_t *sa, char **addrstr, char **portstr) -{ +void sockaddr2str(const sockaddr_t *sa, char **addrstr, char **portstr) { char address[NI_MAXHOST]; char port[NI_MAXSERV]; char *scopeid; @@ -118,8 +115,7 @@ void sockaddr2str(const sockaddr_t *sa, char **addrstr, char **portstr) *portstr = xstrdup(port); } -char *sockaddr2hostname(const sockaddr_t *sa) -{ +char *sockaddr2hostname(const sockaddr_t *sa) { char *str; char address[NI_MAXHOST] = "unknown"; char port[NI_MAXSERV] = "unknown"; @@ -144,8 +140,7 @@ char *sockaddr2hostname(const sockaddr_t *sa) return str; } -int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b) -{ +int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b) { int result; cp(); @@ -213,8 +208,7 @@ void sockaddrfree(sockaddr_t *a) { } } -void sockaddrunmap(sockaddr_t *sa) -{ +void sockaddrunmap(sockaddr_t *sa) { cp(); if(sa->sa.sa_family == AF_INET6 && IN6_IS_ADDR_V4MAPPED(&sa->in6.sin6_addr)) { @@ -225,8 +219,7 @@ void sockaddrunmap(sockaddr_t *sa) /* Subnet mask handling */ -int maskcmp(const void *va, const void *vb, int masklen) -{ +int maskcmp(const void *va, const void *vb, int masklen) { int i, m, result; const char *a = va; const char *b = vb; @@ -246,8 +239,7 @@ int maskcmp(const void *va, const void *vb, int masklen) return 0; } -void mask(void *va, int masklen, int len) -{ +void mask(void *va, int masklen, int len) { int i; char *a = va; @@ -263,8 +255,7 @@ void mask(void *va, int masklen, int len) a[i] = 0; } -void maskcpy(void *va, const void *vb, int masklen, int len) -{ +void maskcpy(void *va, const void *vb, int masklen, int len) { int i, m; char *a = va; const char *b = vb; @@ -283,8 +274,7 @@ void maskcpy(void *va, const void *vb, int masklen, int len) a[i] = 0; } -bool maskcheck(const void *va, int masklen, int len) -{ +bool maskcheck(const void *va, int masklen, int len) { int i; const char *a = va; diff --git a/src/node.c b/src/node.c index 61af6414..9d4d2f43 100644 --- a/src/node.c +++ b/src/node.c @@ -35,13 +35,11 @@ avl_tree_t *node_udp_tree; /* Known nodes, sorted by address and port */ node_t *myself; -static int node_compare(const node_t *a, const node_t *b) -{ +static int node_compare(const node_t *a, const node_t *b) { return strcmp(a->name, b->name); } -static int node_udp_compare(const node_t *a, const node_t *b) -{ +static int node_udp_compare(const node_t *a, const node_t *b) { int result; cp(); @@ -54,24 +52,21 @@ static int node_udp_compare(const node_t *a, const node_t *b) return (a->name && b->name) ? strcmp(a->name, b->name) : 0; } -void init_nodes(void) -{ +void init_nodes(void) { cp(); node_tree = avl_alloc_tree((avl_compare_t) node_compare, (avl_action_t) free_node); node_udp_tree = avl_alloc_tree((avl_compare_t) node_udp_compare, NULL); } -void exit_nodes(void) -{ +void exit_nodes(void) { cp(); avl_delete_tree(node_udp_tree); avl_delete_tree(node_tree); } -node_t *new_node(void) -{ +node_t *new_node(void) { node_t *n = xmalloc_and_zero(sizeof(*n)); cp(); @@ -86,8 +81,7 @@ node_t *new_node(void) return n; } -void free_node(node_t *n) -{ +void free_node(node_t *n) { cp(); if(n->queue) @@ -117,15 +111,13 @@ void free_node(node_t *n) free(n); } -void node_add(node_t *n) -{ +void node_add(node_t *n) { cp(); avl_insert(node_tree, n); } -void node_del(node_t *n) -{ +void node_del(node_t *n) { avl_node_t *node, *next; edge_t *e; subnet_t *s; @@ -147,8 +139,7 @@ void node_del(node_t *n) avl_delete(node_tree, n); } -node_t *lookup_node(char *name) -{ +node_t *lookup_node(char *name) { node_t n = {0}; cp(); @@ -158,8 +149,7 @@ node_t *lookup_node(char *name) return avl_search(node_tree, &n); } -node_t *lookup_node_udp(const sockaddr_t *sa) -{ +node_t *lookup_node_udp(const sockaddr_t *sa) { node_t n = {0}; cp(); @@ -170,8 +160,7 @@ node_t *lookup_node_udp(const sockaddr_t *sa) return avl_search(node_udp_tree, &n); } -void dump_nodes(void) -{ +void dump_nodes(void) { avl_node_t *node; node_t *n; diff --git a/src/process.c b/src/process.c index 44a4c766..dcc6cb33 100644 --- a/src/process.c +++ b/src/process.c @@ -47,8 +47,7 @@ sigset_t emptysigset; static int saved_debug_level = -1; -static void memory_full(int size) -{ +static void memory_full(int size) { logger(LOG_ERR, _("Memory exhausted (couldn't allocate %d bytes), exitting."), size); cp_trace(); exit(1); @@ -170,8 +169,7 @@ DWORD WINAPI controlhandler(DWORD request, DWORD type, LPVOID boe, LPVOID bah) { return NO_ERROR; } -VOID WINAPI run_service(DWORD argc, LPTSTR* argv) -{ +VOID WINAPI run_service(DWORD argc, LPTSTR* argv) { int err = 1; extern int main2(int argc, char **argv); @@ -229,8 +227,7 @@ bool init_service(void) { /* check for an existing tinc for this net, and write pid to pidfile */ -static bool write_pidfile(void) -{ +static bool write_pidfile(void) { pid_t pid; cp(); @@ -259,8 +256,7 @@ static bool write_pidfile(void) /* kill older tincd for this net */ -bool kill_other(int signal) -{ +bool kill_other(int signal) { #ifndef HAVE_MINGW pid_t pid; @@ -300,8 +296,7 @@ bool kill_other(int signal) /* Detach from current terminal, write pidfile, kill parent */ -bool detach(void) -{ +bool detach(void) { cp(); setup_signals(); @@ -347,8 +342,7 @@ bool detach(void) return true; } -bool execute_script(const char *name, char **envp) -{ +bool execute_script(const char *name, char **envp) { #ifdef HAVE_SYSTEM int status, len; struct stat s; @@ -431,16 +425,14 @@ bool execute_script(const char *name, char **envp) */ #ifndef HAVE_MINGW -static RETSIGTYPE fatal_signal_square(int a) -{ +static RETSIGTYPE fatal_signal_square(int a) { logger(LOG_ERR, _("Got another fatal signal %d (%s): not restarting."), a, strsignal(a)); cp_trace(); exit(1); } -static RETSIGTYPE fatal_signal_handler(int a) -{ +static RETSIGTYPE fatal_signal_handler(int a) { struct sigaction act; logger(LOG_ERR, _("Got fatal signal %d (%s)"), a, strsignal(a)); cp_trace(); @@ -463,14 +455,12 @@ static RETSIGTYPE fatal_signal_handler(int a) } } -static RETSIGTYPE unexpected_signal_handler(int a) -{ +static RETSIGTYPE unexpected_signal_handler(int a) { logger(LOG_WARNING, _("Got unexpected signal %d (%s)"), a, strsignal(a)); cp_trace(); } -static RETSIGTYPE ignore_signal_handler(int a) -{ +static RETSIGTYPE ignore_signal_handler(int a) { ifdebug(SCARY_THINGS) logger(LOG_DEBUG, _("Ignored signal %d (%s)"), a, strsignal(a)); } @@ -487,8 +477,7 @@ static struct { }; #endif -void setup_signals(void) -{ +void setup_signals(void) { #ifndef HAVE_MINGW int i; struct sigaction act; diff --git a/src/protocol.c b/src/protocol.c index 6ad9740f..0fbf2a96 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -55,8 +55,7 @@ static char (*request_name[]) = { static avl_tree_t *past_request_tree; -bool check_id(const char *id) -{ +bool check_id(const char *id) { for(; *id; id++) if(!isalnum(*id) && *id != '_') return false; @@ -67,8 +66,7 @@ bool check_id(const char *id) /* Generic request routines - takes care of logging and error detection as well */ -bool send_request(connection_t *c, const char *format, ...) -{ +bool send_request(connection_t *c, const char *format, ...) { va_list args; char buffer[MAXBUFSIZE]; int len, request; @@ -108,8 +106,7 @@ bool send_request(connection_t *c, const char *format, ...) return send_meta(c, buffer, len); } -void forward_request(connection_t *from) -{ +void forward_request(connection_t *from) { int request; cp(); @@ -130,8 +127,7 @@ void forward_request(connection_t *from) broadcast_meta(from, from->buffer, from->reqlen); } -bool receive_request(connection_t *c) -{ +bool receive_request(connection_t *c) { int request; cp(); @@ -180,13 +176,11 @@ bool receive_request(connection_t *c) return true; } -static int past_request_compare(const past_request_t *a, const past_request_t *b) -{ +static int past_request_compare(const past_request_t *a, const past_request_t *b) { return strcmp(a->request, b->request); } -static void free_past_request(past_request_t *r) -{ +static void free_past_request(past_request_t *r) { cp(); if(r->request) @@ -197,8 +191,7 @@ static void free_past_request(past_request_t *r) static struct event past_request_event; -bool seen_request(char *request) -{ +bool seen_request(char *request) { past_request_t *new, p = {0}; cp(); @@ -218,8 +211,7 @@ bool seen_request(char *request) } } -void age_past_requests(int fd, short events, void *data) -{ +void age_past_requests(int fd, short events, void *data) { avl_node_t *node, *next; past_request_t *p; int left = 0, deleted = 0; @@ -245,8 +237,7 @@ void age_past_requests(int fd, short events, void *data) event_add(&past_request_event, &(struct timeval){10, 0}); } -void init_requests(void) -{ +void init_requests(void) { cp(); past_request_tree = avl_alloc_tree((avl_compare_t) past_request_compare, (avl_action_t) free_past_request); @@ -254,8 +245,7 @@ void init_requests(void) timeout_set(&past_request_event, age_past_requests, NULL); } -void exit_requests(void) -{ +void exit_requests(void) { cp(); avl_delete_tree(past_request_tree); diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 0efeceb2..f7e92528 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -40,16 +40,14 @@ #include "utils.h" #include "xalloc.h" -bool send_id(connection_t *c) -{ +bool send_id(connection_t *c) { cp(); return send_request(c, "%d %s %d", ID, myself->connection->name, myself->connection->protocol_version); } -bool id_h(connection_t *c) -{ +bool id_h(connection_t *c) { char name[MAX_STRING_SIZE]; cp(); @@ -116,8 +114,7 @@ bool id_h(connection_t *c) return send_metakey(c); } -bool send_metakey(connection_t *c) -{ +bool send_metakey(connection_t *c) { char *buffer; int len; bool x; @@ -202,8 +199,7 @@ bool send_metakey(connection_t *c) return x; } -bool metakey_h(connection_t *c) -{ +bool metakey_h(connection_t *c) { char buffer[MAX_STRING_SIZE]; int cipher, digest, maclength, compression; int len; @@ -302,8 +298,7 @@ bool metakey_h(connection_t *c) return send_challenge(c); } -bool send_challenge(connection_t *c) -{ +bool send_challenge(connection_t *c) { char *buffer; int len; @@ -334,8 +329,7 @@ bool send_challenge(connection_t *c) return send_request(c, "%d %s", CHALLENGE, buffer); } -bool challenge_h(connection_t *c) -{ +bool challenge_h(connection_t *c) { char buffer[MAX_STRING_SIZE]; int len; @@ -373,8 +367,7 @@ bool challenge_h(connection_t *c) return send_chal_reply(c); } -bool send_chal_reply(connection_t *c) -{ +bool send_chal_reply(connection_t *c) { char hash[EVP_MAX_MD_SIZE * 2 + 1]; EVP_MD_CTX ctx; @@ -400,8 +393,7 @@ bool send_chal_reply(connection_t *c) return send_request(c, "%d %s", CHAL_REPLY, hash); } -bool chal_reply_h(connection_t *c) -{ +bool chal_reply_h(connection_t *c) { char hishash[MAX_STRING_SIZE]; char myhash[EVP_MAX_MD_SIZE]; EVP_MD_CTX ctx; @@ -460,8 +452,7 @@ bool chal_reply_h(connection_t *c) return send_ack(c); } -bool send_ack(connection_t *c) -{ +bool send_ack(connection_t *c) { /* ACK message contains rest of the information the other end needs to create node_t and edge_t structures. */ @@ -491,8 +482,7 @@ bool send_ack(connection_t *c) return send_request(c, "%d %s %d %lx", ACK, myport, c->estimated_weight, c->options); } -static void send_everything(connection_t *c) -{ +static void send_everything(connection_t *c) { avl_node_t *node, *node2; node_t *n; subnet_t *s; @@ -524,8 +514,7 @@ static void send_everything(connection_t *c) } } -bool ack_h(connection_t *c) -{ +bool ack_h(connection_t *c) { char hisport[MAX_STRING_SIZE]; char *hisaddress, *dummy; int weight, mtu; diff --git a/src/protocol_edge.c b/src/protocol_edge.c index bcc17db0..df39bb97 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -36,8 +36,7 @@ #include "utils.h" #include "xalloc.h" -bool send_add_edge(connection_t *c, const edge_t *e) -{ +bool send_add_edge(connection_t *c, const edge_t *e) { bool x; char *address, *port; @@ -54,8 +53,7 @@ bool send_add_edge(connection_t *c, const edge_t *e) return x; } -bool add_edge_h(connection_t *c) -{ +bool add_edge_h(connection_t *c) { edge_t *e; node_t *from, *to; char from_name[MAX_STRING_SIZE]; @@ -167,16 +165,14 @@ bool add_edge_h(connection_t *c) return true; } -bool send_del_edge(connection_t *c, const edge_t *e) -{ +bool send_del_edge(connection_t *c, const edge_t *e) { cp(); return send_request(c, "%d %lx %s %s", DEL_EDGE, random(), e->from->name, e->to->name); } -bool del_edge_h(connection_t *c) -{ +bool del_edge_h(connection_t *c) { edge_t *e; char from_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE]; diff --git a/src/protocol_key.c b/src/protocol_key.c index a3ef4d60..0cf33d70 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -37,8 +37,7 @@ bool mykeyused = false; -bool send_key_changed(connection_t *c, const node_t *n) -{ +bool send_key_changed(connection_t *c, const node_t *n) { cp(); /* Only send this message if some other daemon requested our key previously. @@ -51,8 +50,7 @@ bool send_key_changed(connection_t *c, const node_t *n) return send_request(c, "%d %lx %s", KEY_CHANGED, random(), n->name); } -bool key_changed_h(connection_t *c) -{ +bool key_changed_h(connection_t *c) { char name[MAX_STRING_SIZE]; node_t *n; @@ -86,15 +84,13 @@ bool key_changed_h(connection_t *c) return true; } -bool send_req_key(connection_t *c, const node_t *from, const node_t *to) -{ +bool send_req_key(connection_t *c, const node_t *from, const node_t *to) { cp(); return send_request(c, "%d %s %s", REQ_KEY, from->name, to->name); } -bool req_key_h(connection_t *c) -{ +bool req_key_h(connection_t *c) { char from_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE]; node_t *from, *to; @@ -140,8 +136,7 @@ bool req_key_h(connection_t *c) return true; } -bool send_ans_key(connection_t *c, const node_t *from, const node_t *to) -{ +bool send_ans_key(connection_t *c, const node_t *from, const node_t *to) { char *key; cp(); @@ -157,8 +152,7 @@ bool send_ans_key(connection_t *c, const node_t *from, const node_t *to) from->compression); } -bool ans_key_h(connection_t *c) -{ +bool ans_key_h(connection_t *c) { char from_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE]; char key[MAX_STRING_SIZE]; diff --git a/src/raw_socket/device.c b/src/raw_socket/device.c index 33857ba1..ac7cc57a 100644 --- a/src/raw_socket/device.c +++ b/src/raw_socket/device.c @@ -39,8 +39,7 @@ char *device_info; static int device_total_in = 0; static int device_total_out = 0; -bool setup_device(void) -{ +bool setup_device(void) { struct ifreq ifr; struct sockaddr_ll sa; @@ -85,15 +84,13 @@ bool setup_device(void) return true; } -void close_device(void) -{ +void close_device(void) { cp(); close(device_fd); } -bool read_packet(vpn_packet_t *packet) -{ +bool read_packet(vpn_packet_t *packet) { int lenin; cp(); @@ -114,8 +111,7 @@ bool read_packet(vpn_packet_t *packet) return true; } -bool write_packet(vpn_packet_t *packet) -{ +bool write_packet(vpn_packet_t *packet) { cp(); ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Writing packet of %d bytes to %s"), @@ -132,8 +128,7 @@ bool write_packet(vpn_packet_t *packet) return true; } -void dump_device_stats(void) -{ +void dump_device_stats(void) { cp(); logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device); diff --git a/src/solaris/device.c b/src/solaris/device.c index 9c2a762a..c66db906 100644 --- a/src/solaris/device.c +++ b/src/solaris/device.c @@ -42,8 +42,7 @@ char *device_info = NULL; static int device_total_in = 0; static int device_total_out = 0; -bool setup_device(void) -{ +bool setup_device(void) { int ip_fd = -1, if_fd = -1; int ppa; char *ptr; @@ -108,15 +107,13 @@ bool setup_device(void) return true; } -void close_device(void) -{ +void close_device(void) { cp(); close(device_fd); } -bool read_packet(vpn_packet_t *packet) -{ +bool read_packet(vpn_packet_t *packet) { int lenin; cp(); @@ -153,8 +150,7 @@ bool read_packet(vpn_packet_t *packet) return true; } -bool write_packet(vpn_packet_t *packet) -{ +bool write_packet(vpn_packet_t *packet) { cp(); ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Writing packet of %d bytes to %s"), @@ -171,8 +167,7 @@ bool write_packet(vpn_packet_t *packet) return true; } -void dump_device_stats(void) -{ +void dump_device_stats(void) { cp(); logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device); diff --git a/src/uml_socket/device.c b/src/uml_socket/device.c index a7a70fb3..669d78ed 100644 --- a/src/uml_socket/device.c +++ b/src/uml_socket/device.c @@ -57,8 +57,7 @@ static struct request { static struct sockaddr_un data_sun; -bool setup_device(void) -{ +bool setup_device(void) { struct sockaddr_un listen_sun; static const int one = 1; struct { @@ -154,8 +153,7 @@ bool setup_device(void) return true; } -void close_device(void) -{ +void close_device(void) { cp(); if(listen_fd >= 0) @@ -173,8 +171,7 @@ void close_device(void) unlink(device); } -bool read_packet(vpn_packet_t *packet) -{ +bool read_packet(vpn_packet_t *packet) { int lenin; cp(); @@ -254,8 +251,7 @@ bool read_packet(vpn_packet_t *packet) } } -bool write_packet(vpn_packet_t *packet) -{ +bool write_packet(vpn_packet_t *packet) { cp(); if(state != 2) { @@ -281,8 +277,7 @@ bool write_packet(vpn_packet_t *packet) return true; } -void dump_device_stats(void) -{ +void dump_device_stats(void) { cp(); logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device); -- 2.39.5