K&R style braces

This commit is contained in:
Guus Sliepen 2007-05-18 10:00:00 +00:00
parent 760dd966ef
commit f02d3ed3e1
30 changed files with 233 additions and 466 deletions

View file

@ -54,8 +54,7 @@
#ifndef AVL_DEPTH #ifndef AVL_DEPTH
static int lg(unsigned int u) __attribute__ ((__const__)); static int lg(unsigned int u) __attribute__ ((__const__));
static int lg(unsigned int u) static int lg(unsigned int u) {
{
int r = 1; int r = 1;
if(!u) if(!u)
@ -90,8 +89,7 @@ static int lg(unsigned int u)
/* Internal helper functions */ /* 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 #ifdef AVL_DEPTH
int d; int d;
@ -118,8 +116,7 @@ static int avl_check_balance(const avl_node_t *node)
#endif #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 *child;
avl_node_t *gchild; avl_node_t *gchild;
avl_node_t *parent; avl_node_t *parent;
@ -262,8 +259,7 @@ static void avl_rebalance(avl_tree_t *tree, avl_node_t *node)
/* (De)constructors */ /* (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; avl_tree_t *tree;
tree = xmalloc_and_zero(sizeof(avl_tree_t)); 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; return tree;
} }
void avl_free_tree(avl_tree_t *tree) void avl_free_tree(avl_tree_t *tree) {
{
free(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)); 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) if(node->data && tree->delete)
tree->delete(node->data); tree->delete(node->data);
@ -293,8 +286,7 @@ void avl_free_node(avl_tree_t *tree, avl_node_t *node)
/* Searching */ /* 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; avl_node_t *node;
node = avl_search_node(tree, data); 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; 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; avl_node_t *node;
node = avl_search_closest_node(tree, data, result); 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; 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; avl_node_t *node;
node = avl_search_closest_smaller_node(tree, data); 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; 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; avl_node_t *node;
node = avl_search_closest_greater_node(tree, data); 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; 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; avl_node_t *node;
int result; 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, avl_node_t *avl_search_closest_node(const avl_tree_t *tree, const void *data,
int *result) int *result) {
{
avl_node_t *node; avl_node_t *node;
int c; 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, avl_node_t *avl_search_closest_smaller_node(const avl_tree_t *tree,
const void *data) const void *data) {
{
avl_node_t *node; avl_node_t *node;
int result; 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, avl_node_t *avl_search_closest_greater_node(const avl_tree_t *tree,
const void *data) const void *data) {
{
avl_node_t *node; avl_node_t *node;
int result; int result;
@ -412,8 +397,7 @@ avl_node_t *avl_search_closest_greater_node(const avl_tree_t *tree,
/* Insertion and deletion */ /* 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; avl_node_t *closest, *new;
int result; int result;
@ -452,8 +436,7 @@ avl_node_t *avl_insert(avl_tree_t *tree, void *data)
return new; 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; avl_node_t *closest;
int result; int result;
@ -486,15 +469,13 @@ avl_node_t *avl_insert_node(avl_tree_t *tree, avl_node_t *node)
return 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; node->prev = node->next = node->parent = NULL;
tree->head = tree->tail = tree->root = node; tree->head = tree->tail = tree->root = node;
} }
void avl_insert_before(avl_tree_t *tree, avl_node_t *before, void avl_insert_before(avl_tree_t *tree, avl_node_t *before,
avl_node_t *node) avl_node_t *node) {
{
if(!before) { if(!before) {
if(tree->tail) if(tree->tail)
avl_insert_after(tree, tree->tail, node); 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); 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(!after) {
if(tree->head) if(tree->head)
avl_insert_before(tree, tree->head, node); 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_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; avl_node_t *node;
node = avl_search_node(tree, data); node = avl_search_node(tree, data);
@ -565,8 +544,7 @@ avl_node_t *avl_unlink(avl_tree_t *tree, void *data)
return node; 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 *parent;
avl_node_t **superparent; avl_node_t **superparent;
avl_node_t *subst, *left, *right; avl_node_t *subst, *left, *right;
@ -634,14 +612,12 @@ void avl_unlink_node(avl_tree_t *tree, avl_node_t *node)
#endif #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_unlink_node(tree, node);
avl_free_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; avl_node_t *node;
node = avl_search_node(tree, data); node = avl_search_node(tree, data);
@ -652,8 +628,7 @@ void avl_delete(avl_tree_t *tree, void *data)
/* Fast tree cleanup */ /* Fast tree cleanup */
void avl_delete_tree(avl_tree_t *tree) void avl_delete_tree(avl_tree_t *tree) {
{
avl_node_t *node, *next; avl_node_t *node, *next;
for(node = tree->head; node; node = next) { for(node = tree->head; node; node = next) {
@ -666,8 +641,7 @@ void avl_delete_tree(avl_tree_t *tree)
/* Tree walking */ /* 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; avl_node_t *node, *next;
for(node = tree->head; node; 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; avl_node_t *node, *next;
for(node = tree->head; node; 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 */ /* Indexing */
#ifdef AVL_COUNT #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); 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; avl_node_t *node;
unsigned int c; unsigned int c;
@ -717,8 +688,7 @@ avl_node_t *avl_get_node(const avl_tree_t *tree, unsigned int index)
return NULL; return NULL;
} }
unsigned int avl_index(const avl_node_t *node) unsigned int avl_index(const avl_node_t *node) {
{
avl_node_t *next; avl_node_t *next;
unsigned int index; unsigned int index;
@ -734,8 +704,7 @@ unsigned int avl_index(const avl_node_t *node)
} }
#endif #endif
#ifdef AVL_DEPTH #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); return AVL_NODE_DEPTH(tree->root);
} }
#endif #endif

View file

@ -38,8 +38,7 @@
Unless the argument noclose is non-zero, daemon() will redirect Unless the argument noclose is non-zero, daemon() will redirect
standard input, standard output and standard error to /dev/null. 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 #ifdef HAVE_FORK
pid_t pid; pid_t pid;
int fd; int fd;
@ -97,8 +96,7 @@ int daemon(int nochdir, int noclose)
current directory name. If the environment variable PWD is set, and current directory name. If the environment variable PWD is set, and
its value is correct, then that value will be returned. 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; size_t size;
char *buf; char *buf;
char *r; char *r;
@ -125,8 +123,7 @@ char *get_current_dir_name(void)
#endif #endif
#ifndef HAVE_ASPRINTF #ifndef HAVE_ASPRINTF
int asprintf(char **buf, const char *fmt, ...) int asprintf(char **buf, const char *fmt, ...) {
{
int status; int status;
va_list ap; va_list ap;
int len; int len;

View file

@ -17,8 +17,7 @@
#include "xalloc.h" #include "xalloc.h"
#ifndef HAVE_GAI_STRERROR #ifndef HAVE_GAI_STRERROR
char *gai_strerror(int ecode) char *gai_strerror(int ecode) {
{
switch (ecode) { switch (ecode) {
case EAI_NODATA: case EAI_NODATA:
return "No address associated with hostname"; return "No address associated with hostname";
@ -33,8 +32,7 @@ char *gai_strerror(int ecode)
#endif /* !HAVE_GAI_STRERROR */ #endif /* !HAVE_GAI_STRERROR */
#ifndef HAVE_FREEADDRINFO #ifndef HAVE_FREEADDRINFO
void freeaddrinfo(struct addrinfo *ai) void freeaddrinfo(struct addrinfo *ai) {
{
struct addrinfo *next; struct addrinfo *next;
while(ai) { while(ai) {
@ -46,8 +44,7 @@ void freeaddrinfo(struct addrinfo *ai)
#endif /* !HAVE_FREEADDRINFO */ #endif /* !HAVE_FREEADDRINFO */
#ifndef HAVE_GETADDRINFO #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; struct addrinfo *ai;
ai = xmalloc_and_zero(sizeof(struct addrinfo) + sizeof(struct sockaddr_in)); 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; 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 addrinfo *prev = NULL;
struct hostent *hp; struct hostent *hp;
struct in_addr in = {0}; struct in_addr in = {0};

View file

@ -16,8 +16,7 @@
#ifndef HAVE_GETNAMEINFO #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 sockaddr_in *sin = (struct sockaddr_in *)sa;
struct hostent *hp; struct hostent *hp;
int len; int len;

View file

@ -27,8 +27,7 @@
/* (De)constructors */ /* (De)constructors */
list_t *list_alloc(list_action_t delete) list_t *list_alloc(list_action_t delete) {
{
list_t *list; list_t *list;
list = xmalloc_and_zero(sizeof(list_t)); list = xmalloc_and_zero(sizeof(list_t));
@ -37,18 +36,15 @@ list_t *list_alloc(list_action_t delete)
return list; return list;
} }
void list_free(list_t *list) void list_free(list_t *list) {
{
free(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)); 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) if(node->data && list->delete)
list->delete(node->data); list->delete(node->data);
@ -57,8 +53,7 @@ void list_free_node(list_t *list, list_node_t *node)
/* Insertion and deletion */ /* 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; list_node_t *node;
node = list_alloc_node(); node = list_alloc_node();
@ -78,8 +73,7 @@ list_node_t *list_insert_head(list_t *list, void *data)
return node; 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; list_node_t *node;
node = list_alloc_node(); node = list_alloc_node();
@ -99,8 +93,7 @@ list_node_t *list_insert_tail(list_t *list, void *data)
return node; 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) if(node->prev)
node->prev->next = node->next; node->prev->next = node->next;
else else
@ -114,34 +107,29 @@ void list_unlink_node(list_t *list, list_node_t *node)
list->count--; 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_unlink_node(list, node);
list_free_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); 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); list_delete_node(list, list->tail);
} }
/* Head/tail lookup */ /* Head/tail lookup */
void *list_get_head(list_t *list) void *list_get_head(list_t *list) {
{
if(list->head) if(list->head)
return list->head->data; return list->head->data;
else else
return NULL; return NULL;
} }
void *list_get_tail(list_t *list) void *list_get_tail(list_t *list) {
{
if(list->tail) if(list->tail)
return list->tail->data; return list->tail->data;
else else
@ -150,8 +138,7 @@ void *list_get_tail(list_t *list)
/* Fast list deletion */ /* Fast list deletion */
void list_delete_list(list_t *list) void list_delete_list(list_t *list) {
{
list_node_t *node, *next; list_node_t *node, *next;
for(node = list->head; node; node = next) { for(node = list->head; node; node = next) {
@ -164,8 +151,7 @@ void list_delete_list(list_t *list)
/* Traversing */ /* 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; list_node_t *node, *next;
for(node = list->head; node; 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; list_node_t *node, *next;
for(node = list->head; node; node = next) { for(node = list->head; node; node = next) {

View file

@ -34,8 +34,7 @@
* 0 is returned if either there's no pidfile, it's empty * 0 is returned if either there's no pidfile, it's empty
* or no pid can be read. * or no pid can be read.
*/ */
pid_t read_pid (char *pidfile) pid_t read_pid (char *pidfile) {
{
FILE *f; FILE *f;
long pid; long pid;
@ -52,8 +51,7 @@ pid_t read_pid (char *pidfile)
* table (using /proc) to determine if the process already exists. If * table (using /proc) to determine if the process already exists. If
* so the pid is returned, otherwise 0. * 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); pid_t pid = read_pid(pidfile);
/* Amazing ! _I_ am already holding the pid file... */ /* 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 * Writes the pid to the specified file. If that fails 0 is
* returned, otherwise the pid. * returned, otherwise the pid.
*/ */
pid_t write_pid (char *pidfile) pid_t write_pid (char *pidfile) {
{
FILE *f; FILE *f;
int fd; int fd;
pid_t pid; pid_t pid;
@ -123,8 +120,7 @@ pid_t write_pid (char *pidfile)
* Remove the the specified file. The result from unlink(2) * Remove the the specified file. The result from unlink(2)
* is returned * is returned
*/ */
int remove_pid (char *pidfile) int remove_pid (char *pidfile) {
{
return unlink (pidfile); return unlink (pidfile);
} }
#endif #endif

View file

@ -31,8 +31,7 @@ volatile int cp_index = 0;
char *hexadecimals = "0123456789ABCDEF"; char *hexadecimals = "0123456789ABCDEF";
int charhex2bin(char c) int charhex2bin(char c) {
{
if(isdigit(c)) if(isdigit(c))
return c - '0'; return c - '0';
else 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; int i;
for(i = 0; i < length; i++) for(i = 0; i < length; i++)
dst[i] = charhex2bin(src[i * 2]) * 16 + charhex2bin(src[i * 2 + 1]); 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; int i;
for(i = length - 1; i >= 0; i--) { for(i = length - 1; i >= 0; i--) {
dst[i * 2 + 1] = hexadecimals[(unsigned char) src[i] & 15]; 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 #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...", 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 + 15) % 16], cp_line[(cp_index + 15) % 16],
cp_file[(cp_index + 14) % 16], cp_line[(cp_index + 14) % 16], cp_file[(cp_index + 14) % 16], cp_line[(cp_index + 14) % 16],

View file

@ -227,8 +227,7 @@ bool read_packet(vpn_packet_t *packet) {
return true; return true;
} }
bool write_packet(vpn_packet_t *packet) bool write_packet(vpn_packet_t *packet) {
{
cp(); cp();
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Writing packet of %d bytes to %s"), 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; return true;
} }
void dump_device_stats(void) void dump_device_stats(void) {
{
cp(); cp();
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device); logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);

View file

@ -38,8 +38,7 @@ int pingtimeout = 0; /* seconds to wait for response */
char *confbase = NULL; /* directory in which all config files are */ char *confbase = NULL; /* directory in which all config files are */
char *netname = NULL; /* name of the vpn network */ 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; int result;
result = strcasecmp(a->variable, b->variable); 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); return strcmp(a->file, b->file);
} }
void init_configuration(avl_tree_t ** config_tree) void init_configuration(avl_tree_t ** config_tree) {
{
cp(); cp();
*config_tree = avl_alloc_tree((avl_compare_t) config_compare, (avl_action_t) free_config); *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(); cp();
avl_delete_tree(*config_tree); avl_delete_tree(*config_tree);
*config_tree = NULL; *config_tree = NULL;
} }
config_t *new_config(void) config_t *new_config(void) {
{
cp(); cp();
return xmalloc_and_zero(sizeof(config_t)); return xmalloc_and_zero(sizeof(config_t));
} }
void free_config(config_t *cfg) void free_config(config_t *cfg) {
{
cp(); cp();
if(cfg->variable) if(cfg->variable)
@ -93,15 +88,13 @@ void free_config(config_t *cfg)
free(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(); cp();
avl_insert(config_tree, cfg); 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; config_t cfg, *found;
cp(); cp();
@ -121,8 +114,7 @@ config_t *lookup_config(avl_tree_t *config_tree, char *variable)
return found; 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; avl_node_t *node;
config_t *found; config_t *found;
@ -142,8 +134,7 @@ config_t *lookup_config_next(avl_tree_t *config_tree, const config_t *cfg)
return NULL; return NULL;
} }
bool get_config_bool(const config_t *cfg, bool *result) bool get_config_bool(const config_t *cfg, bool *result) {
{
cp(); cp();
if(!cfg) if(!cfg)
@ -163,8 +154,7 @@ bool get_config_bool(const config_t *cfg, bool *result)
return false; return false;
} }
bool get_config_int(const config_t *cfg, int *result) bool get_config_int(const config_t *cfg, int *result) {
{
cp(); cp();
if(!cfg) if(!cfg)
@ -179,8 +169,7 @@ bool get_config_int(const config_t *cfg, int *result)
return false; return false;
} }
bool get_config_string(const config_t *cfg, char **result) bool get_config_string(const config_t *cfg, char **result) {
{
cp(); cp();
if(!cfg) if(!cfg)
@ -191,8 +180,7 @@ bool get_config_string(const config_t *cfg, char **result)
return true; 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; struct addrinfo *ai;
cp(); cp();
@ -213,8 +201,7 @@ bool get_config_address(const config_t *cfg, struct addrinfo **result)
return false; 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}; subnet_t subnet = {0};
cp(); 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 given, and buf needs to be expanded, the var pointed to by buflen
will be increased. 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 *newline = NULL;
char *p; char *p;
char *line; /* The array that contains everything that has been read so far */ 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 Parse a configuration file and put the results in the configuration tree
starting at *base. 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 */ int err = -2; /* Parse error */
FILE *fp; FILE *fp;
char *buffer, *line; char *buffer, *line;
@ -408,8 +393,7 @@ int read_config_file(avl_tree_t *config_tree, const char *fname)
return err; return err;
} }
bool read_server_config() bool read_server_config() {
{
char *fname; char *fname;
int x; int x;
@ -427,8 +411,7 @@ bool read_server_config()
return x == 0; 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; FILE *r;
char *directory; char *directory;
char *fn; char *fn;

View file

@ -35,13 +35,11 @@
avl_tree_t *connection_tree; /* Meta connections */ avl_tree_t *connection_tree; /* Meta connections */
connection_t *broadcast; 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; return (void *)a - (void *)b;
} }
void init_connections(void) void init_connections(void) {
{
cp(); cp();
connection_tree = avl_alloc_tree((avl_compare_t) connection_compare, (avl_action_t) free_connection); 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")); broadcast->hostname = xstrdup(_("BROADCAST"));
} }
void exit_connections(void) void exit_connections(void) {
{
cp(); cp();
avl_delete_tree(connection_tree); avl_delete_tree(connection_tree);
free_connection(broadcast); free_connection(broadcast);
} }
connection_t *new_connection(void) connection_t *new_connection(void) {
{
connection_t *c; connection_t *c;
cp(); cp();
@ -75,8 +71,7 @@ connection_t *new_connection(void)
return c; return c;
} }
void free_connection(connection_t *c) void free_connection(connection_t *c) {
{
cp(); cp();
if(!c) if(!c)
@ -104,22 +99,19 @@ void free_connection(connection_t *c)
free(c); free(c);
} }
void connection_add(connection_t *c) void connection_add(connection_t *c) {
{
cp(); cp();
avl_insert(connection_tree, c); avl_insert(connection_tree, c);
} }
void connection_del(connection_t *c) void connection_del(connection_t *c) {
{
cp(); cp();
avl_delete(connection_tree, c); avl_delete(connection_tree, c);
} }
void dump_connections(void) void dump_connections(void) {
{
avl_node_t *node; avl_node_t *node;
connection_t *c; connection_t *c;
@ -137,8 +129,7 @@ void dump_connections(void)
logger(LOG_DEBUG, _("End of connections.")); logger(LOG_DEBUG, _("End of connections."));
} }
bool read_connection_config(connection_t *c) bool read_connection_config(connection_t *c) {
{
char *fname; char *fname;
int x; int x;

View file

@ -46,8 +46,7 @@ static int device_total_out = 0;
static pid_t reader_pid; static pid_t reader_pid;
static int sp[2]; static int sp[2];
bool setup_device(void) bool setup_device(void) {
{
HKEY key, key2; HKEY key, key2;
int i, err; int i, err;
@ -218,8 +217,7 @@ bool setup_device(void)
return true; return true;
} }
void close_device(void) void close_device(void) {
{
cp(); cp();
close(sp[0]); close(sp[0]);
@ -229,8 +227,7 @@ void close_device(void)
kill(reader_pid, SIGKILL); kill(reader_pid, SIGKILL);
} }
bool read_packet(vpn_packet_t *packet) bool read_packet(vpn_packet_t *packet) {
{
int lenin; int lenin;
cp(); cp();
@ -251,8 +248,7 @@ bool read_packet(vpn_packet_t *packet)
return true; return true;
} }
bool write_packet(vpn_packet_t *packet) bool write_packet(vpn_packet_t *packet) {
{
long lenout; long lenout;
cp(); cp();
@ -270,8 +266,7 @@ bool write_packet(vpn_packet_t *packet)
return true; return true;
} }
void dump_device_stats(void) void dump_device_stats(void) {
{
cp(); cp();
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device); logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);

View file

@ -32,13 +32,11 @@
avl_tree_t *edge_weight_tree; /* Tree with all edges, sorted on weight */ 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); 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; int result;
result = a->weight - b->weight; 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); return strcmp(a->to->name, b->to->name);
} }
void init_edges(void) void init_edges(void) {
{
cp(); cp();
edge_weight_tree = avl_alloc_tree((avl_compare_t) edge_weight_compare, NULL); 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(); cp();
return avl_alloc_tree((avl_compare_t) edge_compare, (avl_action_t) free_edge); 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(); cp();
avl_delete_tree(edge_tree); avl_delete_tree(edge_tree);
} }
void exit_edges(void) void exit_edges(void) {
{
cp(); cp();
avl_delete_tree(edge_weight_tree); avl_delete_tree(edge_weight_tree);
@ -84,15 +78,13 @@ void exit_edges(void)
/* Creation and deletion of connection elements */ /* Creation and deletion of connection elements */
edge_t *new_edge(void) edge_t *new_edge(void) {
{
cp(); cp();
return xmalloc_and_zero(sizeof(edge_t)); return xmalloc_and_zero(sizeof(edge_t));
} }
void free_edge(edge_t *e) void free_edge(edge_t *e) {
{
cp(); cp();
sockaddrfree(&e->address); sockaddrfree(&e->address);
@ -100,8 +92,7 @@ void free_edge(edge_t *e)
free(e); free(e);
} }
void edge_add(edge_t *e) void edge_add(edge_t *e) {
{
cp(); cp();
avl_insert(edge_weight_tree, e); avl_insert(edge_weight_tree, e);
@ -113,8 +104,7 @@ void edge_add(edge_t *e)
e->reverse->reverse = e; e->reverse->reverse = e;
} }
void edge_del(edge_t *e) void edge_del(edge_t *e) {
{
cp(); cp();
if(e->reverse) if(e->reverse)
@ -124,8 +114,7 @@ void edge_del(edge_t *e)
avl_delete(e->from->edge_tree, 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; edge_t v;
cp(); cp();
@ -136,8 +125,7 @@ edge_t *lookup_edge(node_t *from, node_t *to)
return avl_search(from->edge_tree, &v); return avl_search(from->edge_tree, &v);
} }
void dump_edges(void) void dump_edges(void) {
{
avl_node_t *node, *node2; avl_node_t *node, *node2;
node_t *n; node_t *n;
edge_t *e; edge_t *e;

View file

@ -63,8 +63,7 @@
Please note that sorting on weight is already done by add_edge(). 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; avl_node_t *node, *next;
edge_t *e; edge_t *e;
node_t *n; node_t *n;
@ -147,8 +146,7 @@ void mst_kruskal(void)
Running time: O(E) Running time: O(E)
*/ */
void sssp_bfs(void) void sssp_bfs(void) {
{
avl_node_t *node, *next, *to; avl_node_t *node, *next, *to;
edge_t *e; edge_t *e;
node_t *n; node_t *n;
@ -315,8 +313,7 @@ void sssp_bfs(void)
dot -Tpng graph_filename -o image_filename.png -Gconcentrate=true 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; avl_node_t *node;
node_t *n; node_t *n;
edge_t *e; 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; static struct event ev;
sssp_bfs(); sssp_bfs();

View file

@ -51,8 +51,7 @@ char *device_info;
static int device_total_in = 0; static int device_total_in = 0;
static int device_total_out = 0; static int device_total_out = 0;
bool setup_device(void) bool setup_device(void) {
{
struct ifreq ifr; struct ifreq ifr;
cp(); cp();
@ -112,15 +111,13 @@ bool setup_device(void)
return true; return true;
} }
void close_device(void) void close_device(void) {
{
cp(); cp();
close(device_fd); close(device_fd);
} }
bool read_packet(vpn_packet_t *packet) bool read_packet(vpn_packet_t *packet) {
{
int lenin; int lenin;
cp(); cp();
@ -169,8 +166,7 @@ bool read_packet(vpn_packet_t *packet)
return true; return true;
} }
bool write_packet(vpn_packet_t *packet) bool write_packet(vpn_packet_t *packet) {
{
cp(); cp();
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Writing packet of %d bytes to %s"), 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; return true;
} }
void dump_device_stats(void) void dump_device_stats(void) {
{
cp(); cp();
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device); logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);

View file

@ -34,8 +34,7 @@
#include "utils.h" #include "utils.h"
#include "xalloc.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 outlen;
int result; int result;
@ -83,8 +82,7 @@ bool send_meta(connection_t *c, const char *buffer, int length)
return true; return true;
} }
void flush_meta(int fd, short events, void *data) void flush_meta(int fd, short events, void *data) {
{
connection_t *c = data; connection_t *c = data;
int result; int result;
@ -123,8 +121,7 @@ void flush_meta(int fd, short events, void *data)
c->outbufstart = 0; /* avoid unnecessary memmoves */ 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; avl_node_t *node;
connection_t *c; 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 oldlen, i, result;
int lenin, lenout, reqlen; int lenin, lenout, reqlen;
bool decrypted = false; bool decrypted = false;

View file

@ -123,8 +123,7 @@ DWORD WINAPI tapreader(void *bla) {
} }
} }
bool setup_device(void) bool setup_device(void) {
{
HKEY key, key2; HKEY key, key2;
int i; int i;
@ -308,15 +307,13 @@ bool setup_device(void)
return true; return true;
} }
void close_device(void) void close_device(void) {
{
cp(); cp();
CloseHandle(device_handle); CloseHandle(device_handle);
} }
bool read_packet(vpn_packet_t *packet) bool read_packet(vpn_packet_t *packet) {
{
unsigned char bufno; unsigned char bufno;
cp(); cp();
@ -338,8 +335,7 @@ bool read_packet(vpn_packet_t *packet)
return true; return true;
} }
bool write_packet(vpn_packet_t *packet) bool write_packet(vpn_packet_t *packet) {
{
long lenout; long lenout;
OVERLAPPED overlapped = {0}; OVERLAPPED overlapped = {0};
@ -358,8 +354,7 @@ bool write_packet(vpn_packet_t *packet)
return true; return true;
} }
void dump_device_stats(void) void dump_device_stats(void) {
{
cp(); cp();
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device); logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);

View file

@ -41,8 +41,7 @@
/* Purge edges and subnets of unreachable nodes. Use carefully. */ /* 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; avl_node_t *nnode, *nnext, *enode, *enext, *snode, *snext;
node_t *n; node_t *n;
edge_t *e; edge_t *e;
@ -105,8 +104,7 @@ static void purge(void)
put all file descriptors into events put all file descriptors into events
While we're at it, purge stuf that needs to be removed. 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; avl_node_t *node, *next;
connection_t *c; connection_t *c;
int i, max = 0; int i, max = 0;
@ -134,8 +132,7 @@ static int build_fdset(void)
- Check if we need to retry making an outgoing connection - Check if we need to retry making an outgoing connection
- Deactivate the host - Deactivate the host
*/ */
void terminate_connection(connection_t *c, bool report) void terminate_connection(connection_t *c, bool report) {
{
cp(); cp();
if(c->status.remove) 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 end does not reply in time, we consider them dead
and close the connection. 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; avl_node_t *node, *next;
connection_t *c; connection_t *c;
time_t now = time(NULL); 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}); 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; connection_t *c = data;
int result; int result;
socklen_t len = sizeof(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... this is where it all happens...
*/ */
int main_loop(void) int main_loop(void) {
{
struct timeval tv; struct timeval tv;
int r; int r;
struct event timeout_event; struct event timeout_event;

View file

@ -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) { if(level == 10) {
lzo_uint lzolen = MAXSIZE; lzo_uint lzolen = MAXSIZE;
lzo1x_1_compress(source, len, dest, &lzolen, lzo_wrkmem); 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; 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) { if(level > 9) {
lzo_uint lzolen = MAXSIZE; lzo_uint lzolen = MAXSIZE;
if(lzo1x_decompress_safe(source, len, dest, &lzolen, NULL) == LZO_E_OK) 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 */ /* 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(); cp();
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Received packet of %d bytes from %s (%s)"), 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); 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 pkt1, pkt2;
vpn_packet_t *pkt[] = { &pkt1, &pkt2, &pkt1, &pkt2 }; vpn_packet_t *pkt[] = { &pkt1, &pkt2, &pkt1, &pkt2 };
int nextpkt = 0; int nextpkt = 0;
@ -269,8 +265,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt)
receive_packet(n, 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; vpn_packet_t outpkt;
cp(); cp();
@ -281,8 +276,7 @@ void receive_tcppacket(connection_t *c, char *buffer, int len)
receive_packet(c->node, &outpkt); 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 pkt1, pkt2;
vpn_packet_t *pkt[] = { &pkt1, &pkt2, &pkt1, &pkt2 }; vpn_packet_t *pkt[] = { &pkt1, &pkt2, &pkt1, &pkt2 };
vpn_packet_t *inpkt = origpkt; vpn_packet_t *inpkt = origpkt;
@ -407,8 +401,7 @@ end:
/* /*
send a packet to the given vpn ip. 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; node_t *via;
cp(); cp();
@ -444,8 +437,7 @@ void send_packet(const node_t *n, vpn_packet_t *packet)
/* Broadcast a packet using the minimum spanning tree */ /* 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; avl_node_t *node;
connection_t *c; 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; list_node_t *node, *next;
cp(); 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; vpn_packet_t pkt;
char *hostname; char *hostname;
sockaddr_t from; sockaddr_t from;
@ -512,8 +502,7 @@ void handle_incoming_vpn_data(int sock, short events, void *data)
receive_udppacket(n, &pkt); 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; vpn_packet_t packet;
if(read_packet(&packet)) if(read_packet(&packet))

View file

@ -46,8 +46,7 @@
char *myport; char *myport;
static struct event device_ev; static struct event device_ev;
bool read_rsa_public_key(connection_t *c) bool read_rsa_public_key(connection_t *c) {
{
FILE *fp; FILE *fp;
char *fname; char *fname;
char *key; char *key;
@ -147,8 +146,7 @@ bool read_rsa_public_key(connection_t *c)
return false; return false;
} }
bool read_rsa_private_key(void) bool read_rsa_private_key(void) {
{
FILE *fp; FILE *fp;
char *fname, *key, *pubkey; char *fname, *key, *pubkey;
struct stat s; struct stat s;
@ -241,8 +239,7 @@ void regenerate_key() {
/* /*
Configure node_t myself and set up the local sockets (listen only) Configure node_t myself and set up the local sockets (listen only)
*/ */
bool setup_myself(void) bool setup_myself(void) {
{
config_t *cfg; config_t *cfg;
subnet_t *subnet; subnet_t *subnet;
char *name, *hostname, *mode, *afname, *cipher, *digest; char *name, *hostname, *mode, *afname, *cipher, *digest;
@ -576,8 +573,7 @@ bool setup_myself(void)
/* /*
setup all initial network connections setup all initial network connections
*/ */
bool setup_network_connections(void) bool setup_network_connections(void) {
{
cp(); cp();
init_connections(); init_connections();
@ -612,8 +608,7 @@ bool setup_network_connections(void)
/* /*
close all open network connections close all open network connections
*/ */
void close_network_connections(void) void close_network_connections(void) {
{
avl_node_t *node, *next; avl_node_t *node, *next;
connection_t *c; connection_t *c;
char *envp[5]; char *envp[5];

View file

@ -51,8 +51,7 @@ int listen_sockets;
/* Setup sockets */ /* Setup sockets */
static void configure_tcp(connection_t *c) static void configure_tcp(connection_t *c) {
{
int option; int option;
#ifdef O_NONBLOCK #ifdef O_NONBLOCK
@ -80,8 +79,7 @@ static void configure_tcp(connection_t *c)
#endif #endif
} }
int setup_listen_socket(const sockaddr_t *sa) int setup_listen_socket(const sockaddr_t *sa) {
{
int nfd; int nfd;
char *addrstr; char *addrstr;
int option; int option;
@ -139,8 +137,7 @@ int setup_listen_socket(const sockaddr_t *sa)
return nfd; return nfd;
} }
int setup_vpn_in_socket(const sockaddr_t *sa) int setup_vpn_in_socket(const sockaddr_t *sa) {
{
int nfd; int nfd;
char *addrstr; char *addrstr;
int option; int option;
@ -253,8 +250,7 @@ void retry_outgoing(outgoing_t *outgoing) {
outgoing->timeout); outgoing->timeout);
} }
void finish_connecting(connection_t *c) void finish_connecting(connection_t *c) {
{
cp(); cp();
ifdebug(CONNECTIONS) logger(LOG_INFO, _("Connected to %s (%s)"), c->name, c->hostname); 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); send_id(c);
} }
void do_outgoing_connection(connection_t *c) void do_outgoing_connection(connection_t *c) {
{
char *address, *port; char *address, *port;
int result; int result;
@ -353,8 +348,7 @@ begin:
return; return;
} }
void setup_outgoing_connection(outgoing_t *outgoing) void setup_outgoing_connection(outgoing_t *outgoing) {
{
connection_t *c; connection_t *c;
node_t *n; node_t *n;
@ -409,8 +403,7 @@ void setup_outgoing_connection(outgoing_t *outgoing)
accept a new tcp connect and create a accept a new tcp connect and create a
new connection 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; connection_t *c;
sockaddr_t sa; sockaddr_t sa;
int fd; int fd;
@ -457,8 +450,7 @@ void handle_new_meta_connection(int sock, short events, void *data)
send_id(c); send_id(c);
} }
void try_outgoing_connections(void) void try_outgoing_connections(void) {
{
static config_t *cfg = NULL; static config_t *cfg = NULL;
char *name; char *name;
outgoing_t *outgoing; outgoing_t *outgoing;

View file

@ -34,8 +34,7 @@ bool hostnames = false;
Turn a string into a struct addrinfo. Turn a string into a struct addrinfo.
Return NULL on failure. 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}; struct addrinfo *ai, hint = {0};
int err; int err;
@ -55,8 +54,7 @@ struct addrinfo *str2addrinfo(const char *address, const char *service, int sock
return ai; 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}; struct addrinfo *ai, hint = {0};
sockaddr_t result; sockaddr_t result;
int err; int err;
@ -84,8 +82,7 @@ sockaddr_t str2sockaddr(const char *address, const char *port)
return result; 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 address[NI_MAXHOST];
char port[NI_MAXSERV]; char port[NI_MAXSERV];
char *scopeid; char *scopeid;
@ -118,8 +115,7 @@ void sockaddr2str(const sockaddr_t *sa, char **addrstr, char **portstr)
*portstr = xstrdup(port); *portstr = xstrdup(port);
} }
char *sockaddr2hostname(const sockaddr_t *sa) char *sockaddr2hostname(const sockaddr_t *sa) {
{
char *str; char *str;
char address[NI_MAXHOST] = "unknown"; char address[NI_MAXHOST] = "unknown";
char port[NI_MAXSERV] = "unknown"; char port[NI_MAXSERV] = "unknown";
@ -144,8 +140,7 @@ char *sockaddr2hostname(const sockaddr_t *sa)
return str; return str;
} }
int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b) int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b) {
{
int result; int result;
cp(); cp();
@ -213,8 +208,7 @@ void sockaddrfree(sockaddr_t *a) {
} }
} }
void sockaddrunmap(sockaddr_t *sa) void sockaddrunmap(sockaddr_t *sa) {
{
cp(); cp();
if(sa->sa.sa_family == AF_INET6 && IN6_IS_ADDR_V4MAPPED(&sa->in6.sin6_addr)) { 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 */ /* 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; int i, m, result;
const char *a = va; const char *a = va;
const char *b = vb; const char *b = vb;
@ -246,8 +239,7 @@ int maskcmp(const void *va, const void *vb, int masklen)
return 0; return 0;
} }
void mask(void *va, int masklen, int len) void mask(void *va, int masklen, int len) {
{
int i; int i;
char *a = va; char *a = va;
@ -263,8 +255,7 @@ void mask(void *va, int masklen, int len)
a[i] = 0; 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; int i, m;
char *a = va; char *a = va;
const char *b = vb; const char *b = vb;
@ -283,8 +274,7 @@ void maskcpy(void *va, const void *vb, int masklen, int len)
a[i] = 0; a[i] = 0;
} }
bool maskcheck(const void *va, int masklen, int len) bool maskcheck(const void *va, int masklen, int len) {
{
int i; int i;
const char *a = va; const char *a = va;

View file

@ -35,13 +35,11 @@ avl_tree_t *node_udp_tree; /* Known nodes, sorted by address and port */
node_t *myself; 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); 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; int result;
cp(); 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; return (a->name && b->name) ? strcmp(a->name, b->name) : 0;
} }
void init_nodes(void) void init_nodes(void) {
{
cp(); cp();
node_tree = avl_alloc_tree((avl_compare_t) node_compare, (avl_action_t) free_node); 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); node_udp_tree = avl_alloc_tree((avl_compare_t) node_udp_compare, NULL);
} }
void exit_nodes(void) void exit_nodes(void) {
{
cp(); cp();
avl_delete_tree(node_udp_tree); avl_delete_tree(node_udp_tree);
avl_delete_tree(node_tree); avl_delete_tree(node_tree);
} }
node_t *new_node(void) node_t *new_node(void) {
{
node_t *n = xmalloc_and_zero(sizeof(*n)); node_t *n = xmalloc_and_zero(sizeof(*n));
cp(); cp();
@ -86,8 +81,7 @@ node_t *new_node(void)
return n; return n;
} }
void free_node(node_t *n) void free_node(node_t *n) {
{
cp(); cp();
if(n->queue) if(n->queue)
@ -117,15 +111,13 @@ void free_node(node_t *n)
free(n); free(n);
} }
void node_add(node_t *n) void node_add(node_t *n) {
{
cp(); cp();
avl_insert(node_tree, n); avl_insert(node_tree, n);
} }
void node_del(node_t *n) void node_del(node_t *n) {
{
avl_node_t *node, *next; avl_node_t *node, *next;
edge_t *e; edge_t *e;
subnet_t *s; subnet_t *s;
@ -147,8 +139,7 @@ void node_del(node_t *n)
avl_delete(node_tree, n); avl_delete(node_tree, n);
} }
node_t *lookup_node(char *name) node_t *lookup_node(char *name) {
{
node_t n = {0}; node_t n = {0};
cp(); cp();
@ -158,8 +149,7 @@ node_t *lookup_node(char *name)
return avl_search(node_tree, &n); 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}; node_t n = {0};
cp(); cp();
@ -170,8 +160,7 @@ node_t *lookup_node_udp(const sockaddr_t *sa)
return avl_search(node_udp_tree, &n); return avl_search(node_udp_tree, &n);
} }
void dump_nodes(void) void dump_nodes(void) {
{
avl_node_t *node; avl_node_t *node;
node_t *n; node_t *n;

View file

@ -47,8 +47,7 @@ sigset_t emptysigset;
static int saved_debug_level = -1; 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); logger(LOG_ERR, _("Memory exhausted (couldn't allocate %d bytes), exitting."), size);
cp_trace(); cp_trace();
exit(1); exit(1);
@ -170,8 +169,7 @@ DWORD WINAPI controlhandler(DWORD request, DWORD type, LPVOID boe, LPVOID bah) {
return NO_ERROR; return NO_ERROR;
} }
VOID WINAPI run_service(DWORD argc, LPTSTR* argv) VOID WINAPI run_service(DWORD argc, LPTSTR* argv) {
{
int err = 1; int err = 1;
extern int main2(int argc, char **argv); 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 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; pid_t pid;
cp(); cp();
@ -259,8 +256,7 @@ static bool write_pidfile(void)
/* /*
kill older tincd for this net kill older tincd for this net
*/ */
bool kill_other(int signal) bool kill_other(int signal) {
{
#ifndef HAVE_MINGW #ifndef HAVE_MINGW
pid_t pid; pid_t pid;
@ -300,8 +296,7 @@ bool kill_other(int signal)
/* /*
Detach from current terminal, write pidfile, kill parent Detach from current terminal, write pidfile, kill parent
*/ */
bool detach(void) bool detach(void) {
{
cp(); cp();
setup_signals(); setup_signals();
@ -347,8 +342,7 @@ bool detach(void)
return true; return true;
} }
bool execute_script(const char *name, char **envp) bool execute_script(const char *name, char **envp) {
{
#ifdef HAVE_SYSTEM #ifdef HAVE_SYSTEM
int status, len; int status, len;
struct stat s; struct stat s;
@ -431,16 +425,14 @@ bool execute_script(const char *name, char **envp)
*/ */
#ifndef HAVE_MINGW #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, logger(LOG_ERR, _("Got another fatal signal %d (%s): not restarting."), a,
strsignal(a)); strsignal(a));
cp_trace(); cp_trace();
exit(1); exit(1);
} }
static RETSIGTYPE fatal_signal_handler(int a) static RETSIGTYPE fatal_signal_handler(int a) {
{
struct sigaction act; struct sigaction act;
logger(LOG_ERR, _("Got fatal signal %d (%s)"), a, strsignal(a)); logger(LOG_ERR, _("Got fatal signal %d (%s)"), a, strsignal(a));
cp_trace(); 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)); logger(LOG_WARNING, _("Got unexpected signal %d (%s)"), a, strsignal(a));
cp_trace(); 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)); ifdebug(SCARY_THINGS) logger(LOG_DEBUG, _("Ignored signal %d (%s)"), a, strsignal(a));
} }
@ -487,8 +477,7 @@ static struct {
}; };
#endif #endif
void setup_signals(void) void setup_signals(void) {
{
#ifndef HAVE_MINGW #ifndef HAVE_MINGW
int i; int i;
struct sigaction act; struct sigaction act;

View file

@ -55,8 +55,7 @@ static char (*request_name[]) = {
static avl_tree_t *past_request_tree; static avl_tree_t *past_request_tree;
bool check_id(const char *id) bool check_id(const char *id) {
{
for(; *id; id++) for(; *id; id++)
if(!isalnum(*id) && *id != '_') if(!isalnum(*id) && *id != '_')
return false; return false;
@ -67,8 +66,7 @@ bool check_id(const char *id)
/* Generic request routines - takes care of logging and error /* Generic request routines - takes care of logging and error
detection as well */ detection as well */
bool send_request(connection_t *c, const char *format, ...) bool send_request(connection_t *c, const char *format, ...) {
{
va_list args; va_list args;
char buffer[MAXBUFSIZE]; char buffer[MAXBUFSIZE];
int len, request; int len, request;
@ -108,8 +106,7 @@ bool send_request(connection_t *c, const char *format, ...)
return send_meta(c, buffer, len); return send_meta(c, buffer, len);
} }
void forward_request(connection_t *from) void forward_request(connection_t *from) {
{
int request; int request;
cp(); cp();
@ -130,8 +127,7 @@ void forward_request(connection_t *from)
broadcast_meta(from, from->buffer, from->reqlen); broadcast_meta(from, from->buffer, from->reqlen);
} }
bool receive_request(connection_t *c) bool receive_request(connection_t *c) {
{
int request; int request;
cp(); cp();
@ -180,13 +176,11 @@ bool receive_request(connection_t *c)
return true; 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); 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(); cp();
if(r->request) if(r->request)
@ -197,8 +191,7 @@ static void free_past_request(past_request_t *r)
static struct event past_request_event; static struct event past_request_event;
bool seen_request(char *request) bool seen_request(char *request) {
{
past_request_t *new, p = {0}; past_request_t *new, p = {0};
cp(); 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; avl_node_t *node, *next;
past_request_t *p; past_request_t *p;
int left = 0, deleted = 0; 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}); event_add(&past_request_event, &(struct timeval){10, 0});
} }
void init_requests(void) void init_requests(void) {
{
cp(); cp();
past_request_tree = avl_alloc_tree((avl_compare_t) past_request_compare, (avl_action_t) free_past_request); 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); timeout_set(&past_request_event, age_past_requests, NULL);
} }
void exit_requests(void) void exit_requests(void) {
{
cp(); cp();
avl_delete_tree(past_request_tree); avl_delete_tree(past_request_tree);

View file

@ -40,16 +40,14 @@
#include "utils.h" #include "utils.h"
#include "xalloc.h" #include "xalloc.h"
bool send_id(connection_t *c) bool send_id(connection_t *c) {
{
cp(); cp();
return send_request(c, "%d %s %d", ID, myself->connection->name, return send_request(c, "%d %s %d", ID, myself->connection->name,
myself->connection->protocol_version); myself->connection->protocol_version);
} }
bool id_h(connection_t *c) bool id_h(connection_t *c) {
{
char name[MAX_STRING_SIZE]; char name[MAX_STRING_SIZE];
cp(); cp();
@ -116,8 +114,7 @@ bool id_h(connection_t *c)
return send_metakey(c); return send_metakey(c);
} }
bool send_metakey(connection_t *c) bool send_metakey(connection_t *c) {
{
char *buffer; char *buffer;
int len; int len;
bool x; bool x;
@ -202,8 +199,7 @@ bool send_metakey(connection_t *c)
return x; return x;
} }
bool metakey_h(connection_t *c) bool metakey_h(connection_t *c) {
{
char buffer[MAX_STRING_SIZE]; char buffer[MAX_STRING_SIZE];
int cipher, digest, maclength, compression; int cipher, digest, maclength, compression;
int len; int len;
@ -302,8 +298,7 @@ bool metakey_h(connection_t *c)
return send_challenge(c); return send_challenge(c);
} }
bool send_challenge(connection_t *c) bool send_challenge(connection_t *c) {
{
char *buffer; char *buffer;
int len; int len;
@ -334,8 +329,7 @@ bool send_challenge(connection_t *c)
return send_request(c, "%d %s", CHALLENGE, buffer); 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]; char buffer[MAX_STRING_SIZE];
int len; int len;
@ -373,8 +367,7 @@ bool challenge_h(connection_t *c)
return send_chal_reply(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]; char hash[EVP_MAX_MD_SIZE * 2 + 1];
EVP_MD_CTX ctx; EVP_MD_CTX ctx;
@ -400,8 +393,7 @@ bool send_chal_reply(connection_t *c)
return send_request(c, "%d %s", CHAL_REPLY, hash); 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 hishash[MAX_STRING_SIZE];
char myhash[EVP_MAX_MD_SIZE]; char myhash[EVP_MAX_MD_SIZE];
EVP_MD_CTX ctx; EVP_MD_CTX ctx;
@ -460,8 +452,7 @@ bool chal_reply_h(connection_t *c)
return send_ack(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 /* ACK message contains rest of the information the other end needs
to create node_t and edge_t structures. */ 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); 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; avl_node_t *node, *node2;
node_t *n; node_t *n;
subnet_t *s; 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 hisport[MAX_STRING_SIZE];
char *hisaddress, *dummy; char *hisaddress, *dummy;
int weight, mtu; int weight, mtu;

View file

@ -36,8 +36,7 @@
#include "utils.h" #include "utils.h"
#include "xalloc.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; bool x;
char *address, *port; char *address, *port;
@ -54,8 +53,7 @@ bool send_add_edge(connection_t *c, const edge_t *e)
return x; return x;
} }
bool add_edge_h(connection_t *c) bool add_edge_h(connection_t *c) {
{
edge_t *e; edge_t *e;
node_t *from, *to; node_t *from, *to;
char from_name[MAX_STRING_SIZE]; char from_name[MAX_STRING_SIZE];
@ -167,16 +165,14 @@ bool add_edge_h(connection_t *c)
return true; 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(); cp();
return send_request(c, "%d %lx %s %s", DEL_EDGE, random(), return send_request(c, "%d %lx %s %s", DEL_EDGE, random(),
e->from->name, e->to->name); e->from->name, e->to->name);
} }
bool del_edge_h(connection_t *c) bool del_edge_h(connection_t *c) {
{
edge_t *e; edge_t *e;
char from_name[MAX_STRING_SIZE]; char from_name[MAX_STRING_SIZE];
char to_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE];

View file

@ -37,8 +37,7 @@
bool mykeyused = false; 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(); cp();
/* Only send this message if some other daemon requested our key previously. /* 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); 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]; char name[MAX_STRING_SIZE];
node_t *n; node_t *n;
@ -86,15 +84,13 @@ bool key_changed_h(connection_t *c)
return true; 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(); cp();
return send_request(c, "%d %s %s", REQ_KEY, from->name, to->name); 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 from_name[MAX_STRING_SIZE];
char to_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE];
node_t *from, *to; node_t *from, *to;
@ -140,8 +136,7 @@ bool req_key_h(connection_t *c)
return true; 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; char *key;
cp(); cp();
@ -157,8 +152,7 @@ bool send_ans_key(connection_t *c, const node_t *from, const node_t *to)
from->compression); from->compression);
} }
bool ans_key_h(connection_t *c) bool ans_key_h(connection_t *c) {
{
char from_name[MAX_STRING_SIZE]; char from_name[MAX_STRING_SIZE];
char to_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE];
char key[MAX_STRING_SIZE]; char key[MAX_STRING_SIZE];

View file

@ -39,8 +39,7 @@ char *device_info;
static int device_total_in = 0; static int device_total_in = 0;
static int device_total_out = 0; static int device_total_out = 0;
bool setup_device(void) bool setup_device(void) {
{
struct ifreq ifr; struct ifreq ifr;
struct sockaddr_ll sa; struct sockaddr_ll sa;
@ -85,15 +84,13 @@ bool setup_device(void)
return true; return true;
} }
void close_device(void) void close_device(void) {
{
cp(); cp();
close(device_fd); close(device_fd);
} }
bool read_packet(vpn_packet_t *packet) bool read_packet(vpn_packet_t *packet) {
{
int lenin; int lenin;
cp(); cp();
@ -114,8 +111,7 @@ bool read_packet(vpn_packet_t *packet)
return true; return true;
} }
bool write_packet(vpn_packet_t *packet) bool write_packet(vpn_packet_t *packet) {
{
cp(); cp();
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Writing packet of %d bytes to %s"), 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; return true;
} }
void dump_device_stats(void) void dump_device_stats(void) {
{
cp(); cp();
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device); logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);

View file

@ -42,8 +42,7 @@ char *device_info = NULL;
static int device_total_in = 0; static int device_total_in = 0;
static int device_total_out = 0; static int device_total_out = 0;
bool setup_device(void) bool setup_device(void) {
{
int ip_fd = -1, if_fd = -1; int ip_fd = -1, if_fd = -1;
int ppa; int ppa;
char *ptr; char *ptr;
@ -108,15 +107,13 @@ bool setup_device(void)
return true; return true;
} }
void close_device(void) void close_device(void) {
{
cp(); cp();
close(device_fd); close(device_fd);
} }
bool read_packet(vpn_packet_t *packet) bool read_packet(vpn_packet_t *packet) {
{
int lenin; int lenin;
cp(); cp();
@ -153,8 +150,7 @@ bool read_packet(vpn_packet_t *packet)
return true; return true;
} }
bool write_packet(vpn_packet_t *packet) bool write_packet(vpn_packet_t *packet) {
{
cp(); cp();
ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Writing packet of %d bytes to %s"), 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; return true;
} }
void dump_device_stats(void) void dump_device_stats(void) {
{
cp(); cp();
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device); logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);

View file

@ -57,8 +57,7 @@ static struct request {
static struct sockaddr_un data_sun; static struct sockaddr_un data_sun;
bool setup_device(void) bool setup_device(void) {
{
struct sockaddr_un listen_sun; struct sockaddr_un listen_sun;
static const int one = 1; static const int one = 1;
struct { struct {
@ -154,8 +153,7 @@ bool setup_device(void)
return true; return true;
} }
void close_device(void) void close_device(void) {
{
cp(); cp();
if(listen_fd >= 0) if(listen_fd >= 0)
@ -173,8 +171,7 @@ void close_device(void)
unlink(device); unlink(device);
} }
bool read_packet(vpn_packet_t *packet) bool read_packet(vpn_packet_t *packet) {
{
int lenin; int lenin;
cp(); 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(); cp();
if(state != 2) { if(state != 2) {
@ -281,8 +277,7 @@ bool write_packet(vpn_packet_t *packet)
return true; return true;
} }
void dump_device_stats(void) void dump_device_stats(void) {
{
cp(); cp();
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device); logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);