#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)
/* 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;
#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;
/* (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));
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);
/* 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);
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);
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);
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);
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;
}
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;
}
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;
}
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;
/* 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;
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;
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);
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);
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);
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;
#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);
/* 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) {
/* 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) {
}
}
-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) {
/* 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;
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;
}
#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
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;
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;
#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;
#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";
#endif /* !HAVE_GAI_STRERROR */
#ifndef HAVE_FREEADDRINFO
-void freeaddrinfo(struct addrinfo *ai)
-{
+void freeaddrinfo(struct addrinfo *ai) {
struct addrinfo *next;
while(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));
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};
#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;
/* (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));
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);
/* 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();
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();
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
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
/* 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) {
/* 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) {
}
}
-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) {
* 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;
* 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... */
* 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;
* 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
char *hexadecimals = "0123456789ABCDEF";
-int charhex2bin(char c)
-{
+int charhex2bin(char c) {
if(isdigit(c))
return c - '0';
else
}
-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];
}
#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],
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"),
return true;
}
-void dump_device_stats(void)
-{
+void dump_device_stats(void) {
cp();
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
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);
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)
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();
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;
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)
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)
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)
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();
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();
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 */
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;
return err;
}
-bool read_server_config()
-{
+bool read_server_config() {
char *fname;
int x;
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;
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);
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();
return c;
}
-void free_connection(connection_t *c)
-{
+void free_connection(connection_t *c) {
cp();
if(!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;
logger(LOG_DEBUG, _("End of connections."));
}
-bool read_connection_config(connection_t *c)
-{
+bool read_connection_config(connection_t *c) {
char *fname;
int x;
static pid_t reader_pid;
static int sp[2];
-bool setup_device(void)
-{
+bool setup_device(void) {
HKEY key, key2;
int i, err;
return true;
}
-void close_device(void)
-{
+void close_device(void) {
cp();
close(sp[0]);
kill(reader_pid, SIGKILL);
}
-bool read_packet(vpn_packet_t *packet)
-{
+bool read_packet(vpn_packet_t *packet) {
int lenin;
cp();
return true;
}
-bool write_packet(vpn_packet_t *packet)
-{
+bool write_packet(vpn_packet_t *packet) {
long lenout;
cp();
return true;
}
-void dump_device_stats(void)
-{
+void dump_device_stats(void) {
cp();
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
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;
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);
/* 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);
free(e);
}
-void edge_add(edge_t *e)
-{
+void edge_add(edge_t *e) {
cp();
avl_insert(edge_weight_tree, e);
e->reverse->reverse = e;
}
-void edge_del(edge_t *e)
-{
+void edge_del(edge_t *e) {
cp();
if(e->reverse)
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();
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;
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;
Running time: O(E)
*/
-void sssp_bfs(void)
-{
+void sssp_bfs(void) {
avl_node_t *node, *next, *to;
edge_t *e;
node_t *n;
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;
}
}
-void graph(void)
-{
+void graph(void) {
static struct event ev;
sssp_bfs();
static int device_total_in = 0;
static int device_total_out = 0;
-bool setup_device(void)
-{
+bool setup_device(void) {
struct ifreq ifr;
cp();
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();
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"),
return true;
}
-void dump_device_stats(void)
-{
+void dump_device_stats(void) {
cp();
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
#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;
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;
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;
}
}
-bool receive_meta(connection_t *c)
-{
+bool receive_meta(connection_t *c) {
int oldlen, i, result;
int lenin, lenout, reqlen;
bool decrypted = false;
}
}
-bool setup_device(void)
-{
+bool setup_device(void) {
HKEY key, key2;
int i;
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();
return true;
}
-bool write_packet(vpn_packet_t *packet)
-{
+bool write_packet(vpn_packet_t *packet) {
long lenout;
OVERLAPPED overlapped = {0};
return true;
}
-void dump_device_stats(void)
-{
+void dump_device_stats(void) {
cp();
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
/* 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;
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;
- 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)
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);
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);
/*
this is where it all happens...
*/
-int main_loop(void)
-{
+int main_loop(void) {
struct timeval tv;
int r;
struct event timeout_event;
}
}
-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);
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)
/* 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)"),
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;
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();
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;
/*
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();
/* 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;
}
}
-void flush_queue(node_t *n)
-{
+void flush_queue(node_t *n) {
list_node_t *node, *next;
cp();
}
}
-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;
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))
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;
return false;
}
-bool read_rsa_private_key(void)
-{
+bool read_rsa_private_key(void) {
FILE *fp;
char *fname, *key, *pubkey;
struct stat s;
/*
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;
/*
setup all initial network connections
*/
-bool setup_network_connections(void)
-{
+bool setup_network_connections(void) {
cp();
init_connections();
/*
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];
/* Setup sockets */
-static void configure_tcp(connection_t *c)
-{
+static void configure_tcp(connection_t *c) {
int option;
#ifdef O_NONBLOCK
#endif
}
-int setup_listen_socket(const sockaddr_t *sa)
-{
+int setup_listen_socket(const sockaddr_t *sa) {
int nfd;
char *addrstr;
int option;
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;
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);
send_id(c);
}
-void do_outgoing_connection(connection_t *c)
-{
+void do_outgoing_connection(connection_t *c) {
char *address, *port;
int result;
return;
}
-void setup_outgoing_connection(outgoing_t *outgoing)
-{
+void setup_outgoing_connection(outgoing_t *outgoing) {
connection_t *c;
node_t *n;
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;
send_id(c);
}
-void try_outgoing_connections(void)
-{
+void try_outgoing_connections(void) {
static config_t *cfg = NULL;
char *name;
outgoing_t *outgoing;
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;
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;
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;
*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";
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();
}
}
-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)) {
/* 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;
return 0;
}
-void mask(void *va, int masklen, int len)
-{
+void mask(void *va, int masklen, int len) {
int i;
char *a = va;
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;
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;
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();
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();
return n;
}
-void free_node(node_t *n)
-{
+void free_node(node_t *n) {
cp();
if(n->queue)
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;
avl_delete(node_tree, n);
}
-node_t *lookup_node(char *name)
-{
+node_t *lookup_node(char *name) {
node_t n = {0};
cp();
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();
return avl_search(node_udp_tree, &n);
}
-void dump_nodes(void)
-{
+void dump_nodes(void) {
avl_node_t *node;
node_t *n;
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);
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);
/*
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();
/*
kill older tincd for this net
*/
-bool kill_other(int signal)
-{
+bool kill_other(int signal) {
#ifndef HAVE_MINGW
pid_t pid;
/*
Detach from current terminal, write pidfile, kill parent
*/
-bool detach(void)
-{
+bool detach(void) {
cp();
setup_signals();
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;
*/
#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();
}
}
-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));
}
};
#endif
-void setup_signals(void)
-{
+void setup_signals(void) {
#ifndef HAVE_MINGW
int i;
struct sigaction act;
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;
/* 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;
return send_meta(c, buffer, len);
}
-void forward_request(connection_t *from)
-{
+void forward_request(connection_t *from) {
int request;
cp();
broadcast_meta(from, from->buffer, from->reqlen);
}
-bool receive_request(connection_t *c)
-{
+bool receive_request(connection_t *c) {
int request;
cp();
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)
static struct event past_request_event;
-bool seen_request(char *request)
-{
+bool seen_request(char *request) {
past_request_t *new, p = {0};
cp();
}
}
-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;
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);
timeout_set(&past_request_event, age_past_requests, NULL);
}
-void exit_requests(void)
-{
+void exit_requests(void) {
cp();
avl_delete_tree(past_request_tree);
#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();
return send_metakey(c);
}
-bool send_metakey(connection_t *c)
-{
+bool send_metakey(connection_t *c) {
char *buffer;
int len;
bool x;
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;
return send_challenge(c);
}
-bool send_challenge(connection_t *c)
-{
+bool send_challenge(connection_t *c) {
char *buffer;
int len;
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;
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;
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;
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. */
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;
}
}
-bool ack_h(connection_t *c)
-{
+bool ack_h(connection_t *c) {
char hisport[MAX_STRING_SIZE];
char *hisaddress, *dummy;
int weight, mtu;
#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;
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];
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];
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.
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;
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;
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();
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];
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;
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();
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"),
return true;
}
-void dump_device_stats(void)
-{
+void dump_device_stats(void) {
cp();
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
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;
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();
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"),
return true;
}
-void dump_device_stats(void)
-{
+void dump_device_stats(void) {
cp();
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
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 {
return true;
}
-void close_device(void)
-{
+void close_device(void) {
cp();
if(listen_fd >= 0)
unlink(device);
}
-bool read_packet(vpn_packet_t *packet)
-{
+bool read_packet(vpn_packet_t *packet) {
int lenin;
cp();
}
}
-bool write_packet(vpn_packet_t *packet)
-{
+bool write_packet(vpn_packet_t *packet) {
cp();
if(state != 2) {
return true;
}
-void dump_device_stats(void)
-{
+void dump_device_stats(void) {
cp();
logger(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);