} avl_node_t;
-typedef int (*avl_compare_t)(const void *, const void *);
-typedef void (*avl_action_t)(const void *);
-typedef void (*avl_action_node_t)(const avl_node_t *);
+typedef int (*avl_compare_t)(const void *data1, const void *data2);
+typedef void (*avl_action_t)(const void *data);
+typedef void (*avl_action_node_t)(const avl_node_t *node);
typedef struct avl_tree_t {
/* (De)constructors */
-extern avl_tree_t *avl_alloc_tree(avl_compare_t, avl_action_t);
-extern void avl_free_tree(avl_tree_t *);
+extern avl_tree_t *avl_alloc_tree(avl_compare_t compare, avl_action_t delete);
+extern void avl_free_tree(avl_tree_t *tree);
extern avl_node_t *avl_alloc_node(void);
-extern void avl_free_node(avl_tree_t *tree, avl_node_t *);
+extern void avl_free_node(avl_tree_t *tree, avl_node_t *node);
/* Insertion and deletion */
-extern avl_node_t *avl_insert(avl_tree_t *, void *);
-extern avl_node_t *avl_insert_node(avl_tree_t *, avl_node_t *);
+extern avl_node_t *avl_insert(avl_tree_t *tree, void *data);
+extern avl_node_t *avl_insert_node(avl_tree_t *tree, avl_node_t *node);
-extern void avl_insert_top(avl_tree_t *, avl_node_t *);
-extern void avl_insert_before(avl_tree_t *, avl_node_t *, avl_node_t *);
-extern void avl_insert_after(avl_tree_t *, avl_node_t *, avl_node_t *);
+extern void avl_insert_top(avl_tree_t *tree, avl_node_t *node);
+extern void avl_insert_before(avl_tree_t *tree, avl_node_t *before, avl_node_t *node);
+extern void avl_insert_after(avl_tree_t *tree, avl_node_t *after, avl_node_t *node);
-extern avl_node_t *avl_unlink(avl_tree_t *, void *);
-extern void avl_unlink_node(avl_tree_t *tree, avl_node_t *);
-extern void avl_delete(avl_tree_t *, void *);
-extern void avl_delete_node(avl_tree_t *, avl_node_t *);
+extern avl_node_t *avl_unlink(avl_tree_t *tree, void *data);
+extern void avl_unlink_node(avl_tree_t *tree, avl_node_t *node);
+extern void avl_delete(avl_tree_t *tree, void *data);
+extern void avl_delete_node(avl_tree_t *tree, avl_node_t *node);
/* Fast tree cleanup */
-extern void avl_delete_tree(avl_tree_t *);
+extern void avl_delete_tree(avl_tree_t *tree);
/* Searching */
-extern void *avl_search(const avl_tree_t *, const void *);
-extern void *avl_search_closest(const avl_tree_t *, const void *, int *);
-extern void *avl_search_closest_smaller(const avl_tree_t *, const void *);
-extern void *avl_search_closest_greater(const avl_tree_t *, const void *);
+extern void *avl_search(const avl_tree_t *tree, const void *data);
+extern void *avl_search_closest(const avl_tree_t *tree, const void *data, int *result);
+extern void *avl_search_closest_smaller(const avl_tree_t *tree, const void *data);
+extern void *avl_search_closest_greater(const avl_tree_t *tree, const void *data);
-extern avl_node_t *avl_search_node(const avl_tree_t *, const void *);
-extern avl_node_t *avl_search_closest_node(const avl_tree_t *, const void *, int *);
-extern avl_node_t *avl_search_closest_smaller_node(const avl_tree_t *, const void *);
-extern avl_node_t *avl_search_closest_greater_node(const avl_tree_t *, const void *);
+extern avl_node_t *avl_search_node(const avl_tree_t *tree, const void *data);
+extern avl_node_t *avl_search_closest_node(const avl_tree_t *tree, const void *data, int *result);
+extern avl_node_t *avl_search_closest_smaller_node(const avl_tree_t *tree, const void *data);
+extern avl_node_t *avl_search_closest_greater_node(const avl_tree_t *tree, const void *data);
/* Tree walking */
-extern void avl_foreach(const avl_tree_t *, avl_action_t);
-extern void avl_foreach_node(const avl_tree_t *, avl_action_t);
+extern void avl_foreach(const avl_tree_t *tree, avl_action_t action);
+extern void avl_foreach_node(const avl_tree_t *tree, avl_action_t action);
/* Indexing */
#ifdef AVL_COUNT
-extern unsigned int avl_count(const avl_tree_t *);
-extern avl_node_t *avl_get_node(const avl_tree_t *, unsigned int);
-extern unsigned int avl_index(const avl_node_t *);
+extern unsigned int avl_count(const avl_tree_t *tree);
+extern avl_node_t *avl_get_node(const avl_tree_t *tree, unsigned int index);
+extern unsigned int avl_index(const avl_node_t *node);
#endif
#ifdef AVL_DEPTH
-extern unsigned int avl_depth(const avl_tree_t *);
+extern unsigned int avl_depth(const avl_tree_t *tree);
#endif
#endif
extern char *netname;
extern list_t *cmdline_conf;
-extern void init_configuration(avl_tree_t **);
-extern void exit_configuration(avl_tree_t **);
+extern void init_configuration(avl_tree_t **config_tree);
+extern void exit_configuration(avl_tree_t **config_tree);
extern config_t *new_config(void) __attribute__((__malloc__));
-extern void free_config(config_t *);
-extern void config_add(avl_tree_t *, config_t *);
-extern config_t *lookup_config(const avl_tree_t *, char *);
-extern config_t *lookup_config_next(const avl_tree_t *, const config_t *);
-extern bool get_config_bool(const config_t *, bool *);
-extern bool get_config_int(const config_t *, int *);
-extern bool get_config_string(const config_t *, char **);
-extern bool get_config_address(const config_t *, struct addrinfo **);
-extern bool get_config_subnet(const config_t *, struct subnet_t **);
+extern void free_config(config_t *cfg);
+extern void config_add(avl_tree_t *config_tree, config_t *cfg);
+extern config_t *lookup_config(const avl_tree_t *config_tree, char *variable);
+extern config_t *lookup_config_next(const avl_tree_t *config_tree, const config_t *cfg);
+extern bool get_config_bool(const config_t *cfg, bool *result);
+extern bool get_config_int(const config_t *cfg, int *result);
+extern bool get_config_string(const config_t *cfg, char **result);
+extern bool get_config_address(const config_t *cfg, struct addrinfo **result);
+extern bool get_config_subnet(const config_t *cfg, struct subnet_t **result);
-extern config_t *parse_config_line(char *, const char *, int);
-extern bool read_config_file(avl_tree_t *, const char *);
-extern void read_config_options(avl_tree_t *, const char *);
+extern config_t *parse_config_line(char *line, const char *fname, int lineno);
+extern bool read_config_file(avl_tree_t *config_tree, const char *fname);
+extern void read_config_options(avl_tree_t *config_tree, const char *prefix);
extern bool read_server_config(void);
-extern bool read_connection_config(struct connection_t *);
-extern FILE *ask_and_open(const char *, const char *);
-extern bool is_safe_path(const char *);
+extern bool read_connection_config(struct connection_t *c);
+extern FILE *ask_and_open(const char *fname, const char *what);
#endif
extern void init_connections(void);
extern void exit_connections(void);
extern connection_t *new_connection(void) __attribute__((__malloc__));
-extern void free_connection(connection_t *);
-extern void free_connection_partially(connection_t *);
-extern void connection_add(connection_t *);
-extern void connection_del(connection_t *);
+extern void free_connection(connection_t *c);
+extern void free_connection_partially(connection_t *c);
+extern void connection_add(connection_t *c);
+extern void connection_del(connection_t *c);
extern void dump_connections(void);
#endif
typedef struct devops_t {
bool (*setup)(void);
void (*close)(void);
- bool (*read)(struct vpn_packet_t *);
- bool (*write)(struct vpn_packet_t *);
+ bool (*read)(struct vpn_packet_t *packet);
+ bool (*write)(struct vpn_packet_t *packet);
void (*dump_stats)(void);
} devops_t;
#include "fake-getnameinfo.h"
#ifndef HAVE_DAEMON
-extern int daemon(int, int);
+extern int daemon(int nochdir, int noclose);
#endif
#ifndef HAVE_GET_CURRENT_DIR_NAME
#endif
#ifndef HAVE_ASPRINTF
-extern int asprintf(char **, const char *, ...);
-extern int vasprintf(char **, const char *, va_list ap);
+extern int asprintf(char **buf, const char *fmt, ...);
+extern int vasprintf(char **buf, const char *fmt, va_list ap);
#endif
#ifndef HAVE_GETTIMEOFDAY
-extern int gettimeofday(struct timeval *, void *);
+extern int gettimeofday(struct timeval *tv, void *tz);
#endif
#ifndef HAVE_USLEEP
-extern int usleep(long long);
+extern int usleep(long long usec);
#endif
#endif
extern void init_edges(void);
extern void exit_edges(void);
extern edge_t *new_edge(void) __attribute__((__malloc__));
-extern void free_edge(edge_t *);
+extern void free_edge(edge_t *e);
extern avl_tree_t *new_edge_tree(void) __attribute__((__malloc__));
-extern void free_edge_tree(avl_tree_t *);
-extern void edge_add(edge_t *);
-extern void edge_del(edge_t *);
-extern edge_t *lookup_edge(struct node_t *, struct node_t *);
+extern void free_edge_tree(avl_tree_t *edge_tree);
+extern void edge_add(edge_t *e);
+extern void edge_del(edge_t *e);
+extern edge_t *lookup_edge(struct node_t *from, struct node_t *to);
extern void dump_edges(void);
#endif
extern void exit_events(void);
extern void expire_events(void);
extern event_t *new_event(void) __attribute__((__malloc__));
-extern void free_event(event_t *);
-extern void event_add(event_t *);
-extern void event_del(event_t *);
+extern void free_event(event_t *event);
+extern void event_add(event_t *event);
+extern void event_del(event_t *event);
extern event_t *get_expired_event(void);
extern event_t *peek_next_event(void);
/* (De)constructors */
extern list_t *list_alloc(list_action_t) __attribute__((__malloc__));
-extern void list_free(list_t *);
+extern void list_free(list_t *list);
extern list_node_t *list_alloc_node(void);
-extern void list_free_node(list_t *, list_node_t *);
+extern void list_free_node(list_t *list, list_node_t *node);
/* Insertion and deletion */
-extern list_node_t *list_insert_head(list_t *, void *);
-extern list_node_t *list_insert_tail(list_t *, void *);
+extern list_node_t *list_insert_head(list_t *list, void *data);
+extern list_node_t *list_insert_tail(list_t *list, void *data);
-extern void list_unlink_node(list_t *, list_node_t *);
-extern void list_delete_node(list_t *, list_node_t *);
+extern void list_unlink_node(list_t *list, list_node_t *node);
+extern void list_delete_node(list_t *list, list_node_t *node);
-extern void list_delete_head(list_t *);
-extern void list_delete_tail(list_t *);
+extern void list_delete_head(list_t *list);
+extern void list_delete_tail(list_t *list);
/* Head/tail lookup */
-extern void *list_get_head(list_t *);
-extern void *list_get_tail(list_t *);
+extern void *list_get_head(list_t *list);
+extern void *list_get_tail(list_t *list);
/* Fast list deletion */
-extern void list_delete_list(list_t *);
+extern void list_delete_list(list_t *list);
/* Traversing */
-extern void list_foreach(list_t *, list_action_t);
-extern void list_foreach_node(list_t *, list_action_node_t);
+extern void list_foreach(list_t *list, list_action_t action);
+extern void list_foreach_node(list_t *list, list_action_node_t action);
#endif
#endif
extern debug_t debug_level;
-extern void openlogger(const char *, logmode_t);
+extern void openlogger(const char *ident, logmode_t mode);
extern void reopenlogger(void);
-extern void logger(int, const char *, ...) __attribute__((__format__(printf, 2, 3)));
+extern void logger(int priority, const char *format, ...) __attribute__((__format__(printf, 2, 3)));
extern void closelogger(void);
#define ifdebug(l) if(debug_level >= DEBUG_##l)
#include "connection.h"
-extern bool send_meta(struct connection_t *, const char *, int);
-extern void broadcast_meta(struct connection_t *, const char *, int);
-extern bool flush_meta(struct connection_t *);
-extern bool receive_meta(struct connection_t *);
+extern bool send_meta(struct connection_t *c, const char *buffer, int length);
+extern void broadcast_meta(struct connection_t *c, const char *buffer, int length);
+extern bool flush_meta(struct connection_t *c);
+extern bool receive_meta(struct connection_t *c);
#endif
#include "connection.h"
#include "node.h"
-extern void retry_outgoing(outgoing_t *);
-extern void handle_incoming_vpn_data(int);
-extern void finish_connecting(struct connection_t *);
-extern void do_outgoing_connection(struct connection_t *);
-extern bool handle_new_meta_connection(int);
-extern int setup_listen_socket(const sockaddr_t *);
-extern int setup_vpn_in_socket(const sockaddr_t *);
-extern void send_packet(const struct node_t *, vpn_packet_t *);
-extern void receive_tcppacket(struct connection_t *, const char *, length_t);
-extern void broadcast_packet(const struct node_t *, vpn_packet_t *);
+extern void retry_outgoing(outgoing_t *outgoing);
+extern void handle_incoming_vpn_data(int sock);
+extern void finish_connecting(struct connection_t *c);
+extern void do_outgoing_connection(struct connection_t *c);
+extern bool handle_new_meta_connection(int sock);
+extern int setup_listen_socket(const sockaddr_t *sa);
+extern int setup_vpn_in_socket(const sockaddr_t *sa);
+extern void send_packet(const struct node_t *n, vpn_packet_t *packet);
+extern void receive_tcppacket(struct connection_t *c, const char *buffer, length_t len);
+extern void broadcast_packet(const struct node_t *, vpn_packet_t *packet);
extern char *get_name(void);
extern bool setup_network(void);
-extern void setup_outgoing_connection(struct outgoing_t *);
+extern void setup_outgoing_connection(struct outgoing_t *outgoing);
extern void try_outgoing_connections(void);
extern void close_network_connections(void);
extern int main_loop(void);
-extern void terminate_connection(struct connection_t *, bool);
-extern void flush_queue(struct node_t *);
-extern bool read_rsa_public_key(struct connection_t *);
-extern void send_mtu_probe(struct node_t *);
+extern void terminate_connection(struct connection_t *c, bool report);
+extern void flush_queue(struct node_t *n);
+extern bool read_rsa_public_key(struct connection_t *c);
+extern void send_mtu_probe(struct node_t *n);
extern void load_all_subnets(void);
#ifndef HAVE_MINGW
extern bool hostnames;
-extern struct addrinfo *str2addrinfo(const char *, const char *, int);
-extern sockaddr_t str2sockaddr(const char *, const char *);
-extern void sockaddr2str(const sockaddr_t *, char **, char **);
-extern char *sockaddr2hostname(const sockaddr_t *);
-extern int sockaddrcmp(const sockaddr_t *, const sockaddr_t *);
-extern int sockaddrcmp_noport(const sockaddr_t *, const sockaddr_t *);
-extern void sockaddrunmap(sockaddr_t *);
-extern void sockaddrfree(sockaddr_t *);
-extern void sockaddrcpy(sockaddr_t *, const sockaddr_t *);
-extern void sockaddr_setport(sockaddr_t *, const char *);
-extern int maskcmp(const void *, const void *, int);
-extern void maskcpy(void *, const void *, int, int);
-extern void mask(void *, int, int);
-extern bool maskcheck(const void *, int, int);
+extern struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype);
+extern sockaddr_t str2sockaddr(const char *address, const char *port);
+extern void sockaddr2str(const sockaddr_t *sa, char **addrstr, char **portstr);
+extern char *sockaddr2hostname(const sockaddr_t *sa);
+extern int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b);
+extern int sockaddrcmp_noport(const sockaddr_t *a, const sockaddr_t *b);
+extern void sockaddrunmap(sockaddr_t *sa);
+extern void sockaddrfree(sockaddr_t *sa);
+extern void sockaddrcpy(sockaddr_t *dest, const sockaddr_t *src);
+extern void sockaddr_setport(sockaddr_t *sa, const char *port);
+extern int maskcmp(const void *a, const void *b, int masklen);
+extern void maskcpy(void *dest, const void *src, int masklen, int len);
+extern void mask(void *mask, int masklen, int len);
+extern bool maskcheck(const void *mask, int masklen, int len);
#endif
extern void init_nodes(void);
extern void exit_nodes(void);
extern node_t *new_node(void) __attribute__((__malloc__));
-extern void free_node(node_t *);
-extern void node_add(node_t *);
-extern void node_del(node_t *);
-extern node_t *lookup_node(char *);
-extern node_t *lookup_node_udp(const sockaddr_t *);
-extern void update_node_udp(node_t *, const sockaddr_t *);
+extern void free_node(node_t *n);
+extern void node_add(node_t *n);
+extern void node_del(node_t *n);
+extern node_t *lookup_node(char *name);
+extern node_t *lookup_node_udp(const sockaddr_t *sa);
+extern void update_node_udp(node_t *n, const sockaddr_t *sa);
extern void dump_nodes(void);
#endif
extern bool sigalrm;
extern void setup_signals(void);
-extern bool execute_script(const char *, char **);
+extern bool execute_script(const char *name, char **envp);
extern bool detach(void);
-extern bool kill_other(int);
+extern bool kill_other(int signal);
#ifdef HAVE_MINGW
extern bool init_service(void);
/* Basic functions */
-extern bool send_request(struct connection_t *, const char *, ...) __attribute__((__format__(printf, 2, 3)));
-extern void forward_request(struct connection_t *);
-extern bool receive_request(struct connection_t *);
-extern bool check_id(const char *);
+extern bool send_request(struct connection_t *c, const char *format, ...) __attribute__((__format__(printf, 2, 3)));
+extern void forward_request(struct connection_t *c);
+extern bool receive_request(struct connection_t *c);
+extern bool check_id(const char *name);
extern void init_requests(void);
extern void exit_requests(void);
-extern bool seen_request(char *);
+extern bool seen_request(char *request);
extern void age_past_requests(void);
/* Requests */
-extern bool send_id(struct connection_t *);
-extern bool send_metakey(struct connection_t *);
-extern bool send_challenge(struct connection_t *);
-extern bool send_chal_reply(struct connection_t *);
-extern bool send_ack(struct connection_t *);
-extern bool send_ping(struct connection_t *);
-extern bool send_pong(struct connection_t *);
-extern bool send_add_subnet(struct connection_t *, const struct subnet_t *);
-extern bool send_del_subnet(struct connection_t *, const struct subnet_t *);
-extern bool send_add_edge(struct connection_t *, const struct edge_t *);
-extern bool send_del_edge(struct connection_t *, const struct edge_t *);
+extern bool send_id(struct connection_t *c);
+extern bool send_metakey(struct connection_t *c);
+extern bool send_challenge(struct connection_t *c);
+extern bool send_chal_reply(struct connection_t *c);
+extern bool send_ack(struct connection_t *c);
+extern bool send_ping(struct connection_t *c);
+extern bool send_pong(struct connection_t *c);
+extern bool send_add_subnet(struct connection_t *c, const struct subnet_t *subnet);
+extern bool send_del_subnet(struct connection_t *c, const struct subnet_t *subnet);
+extern bool send_add_edge(struct connection_t *c, const struct edge_t *e);
+extern bool send_del_edge(struct connection_t *c, const struct edge_t *e);
extern void send_key_changed(void);
-extern bool send_req_key(struct node_t *);
-extern bool send_ans_key(struct node_t *);
-extern bool send_tcppacket(struct connection_t *, const struct vpn_packet_t *);
+extern bool send_req_key(struct node_t *n);
+extern bool send_ans_key(struct node_t *n);
+extern bool send_tcppacket(struct connection_t *c, const struct vpn_packet_t *packet);
/* Request handlers */
-extern bool id_h(struct connection_t *);
-extern bool metakey_h(struct connection_t *);
-extern bool challenge_h(struct connection_t *);
-extern bool chal_reply_h(struct connection_t *);
-extern bool ack_h(struct connection_t *);
-extern bool status_h(struct connection_t *);
-extern bool error_h(struct connection_t *);
-extern bool termreq_h(struct connection_t *);
-extern bool ping_h(struct connection_t *);
-extern bool pong_h(struct connection_t *);
-extern bool add_subnet_h(struct connection_t *);
-extern bool del_subnet_h(struct connection_t *);
-extern bool add_edge_h(struct connection_t *);
-extern bool del_edge_h(struct connection_t *);
-extern bool key_changed_h(struct connection_t *);
-extern bool req_key_h(struct connection_t *);
-extern bool ans_key_h(struct connection_t *);
-extern bool tcppacket_h(struct connection_t *);
+extern bool id_h(struct connection_t *c);
+extern bool metakey_h(struct connection_t *c);
+extern bool challenge_h(struct connection_t *c);
+extern bool chal_reply_h(struct connection_t *c);
+extern bool ack_h(struct connection_t *c);
+extern bool ping_h(struct connection_t *c);
+extern bool pong_h(struct connection_t *c);
+extern bool add_subnet_h(struct connection_t *c);
+extern bool del_subnet_h(struct connection_t *c);
+extern bool add_edge_h(struct connection_t *c);
+extern bool del_edge_h(struct connection_t *c);
+extern bool key_changed_h(struct connection_t *c);
+extern bool req_key_h(struct connection_t *c);
+extern bool ans_key_h(struct connection_t *c);
+extern bool tcppacket_h(struct connection_t *c);
#endif
extern mac_t mymac;
extern void age_subnets(void);
-extern void route(struct node_t *, struct vpn_packet_t *);
+extern void route(struct node_t *source, struct vpn_packet_t *packet);
#endif
extern avl_tree_t *subnet_tree;
-extern int subnet_compare(const struct subnet_t *, const struct subnet_t *);
extern subnet_t *new_subnet(void) __attribute__((__malloc__));
-extern void free_subnet(subnet_t *);
+extern void free_subnet(subnet_t *subnet);
extern void init_subnets(void);
extern void exit_subnets(void);
extern avl_tree_t *new_subnet_tree(void) __attribute__((__malloc__));
-extern void free_subnet_tree(avl_tree_t *);
-extern void subnet_add(struct node_t *, subnet_t *);
-extern void subnet_del(struct node_t *, subnet_t *);
-extern void subnet_update(struct node_t *, subnet_t *, bool);
-extern bool net2str(char *, int, const subnet_t *);
-extern bool str2net(subnet_t *, const char *);
-extern subnet_t *lookup_subnet(const struct node_t *, const subnet_t *);
-extern subnet_t *lookup_subnet_mac(const struct node_t *, const mac_t *);
-extern subnet_t *lookup_subnet_ipv4(const ipv4_t *);
-extern subnet_t *lookup_subnet_ipv6(const ipv6_t *);
+extern void free_subnet_tree(avl_tree_t *subnet_tree);
+extern void subnet_add(struct node_t *owner, subnet_t *subnet);
+extern void subnet_del(struct node_t *owner, subnet_t *subnet);
+extern void subnet_update(struct node_t *owner, subnet_t *subnet, bool up);
+extern bool net2str(char *netstr, int len, const subnet_t *subnet);
+extern bool str2net(subnet_t *subnet, const char *netstr);
+extern subnet_t *lookup_subnet(const struct node_t *owner, const subnet_t *subnet);
+extern subnet_t *lookup_subnet_mac(const struct node_t *owner, const mac_t *address);
+extern subnet_t *lookup_subnet_ipv4(const ipv4_t *address);
+extern subnet_t *lookup_subnet_ipv6(const ipv6_t *address);
extern void dump_subnets(void);
extern void subnet_cache_flush(void);