From 83263b74460656ba557fd9bb84dc27258549e9cd Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Thu, 24 Jul 2003 12:08:16 +0000 Subject: [PATCH] Sprinkle around a lot of const and some C99 initialisers. --- lib/avl_tree.c | 12 ++++----- lib/avl_tree.h | 10 ++++---- src/conf.c | 18 ++++++------- src/conf.h | 16 ++++++------ src/connection.c | 4 +-- src/edge.c | 16 ++++++------ src/edge.h | 4 +-- src/event.c | 4 +-- src/net.h | 10 ++++---- src/net_packet.c | 6 ++--- src/net_socket.c | 6 ++--- src/netutl.c | 26 +++++++++---------- src/netutl.h | 18 ++++++------- src/node.c | 25 ++++++++++-------- src/node.h | 6 ++--- src/protocol.c | 21 ++++++++------- src/protocol.h | 24 +++++++++--------- src/protocol_edge.c | 6 ++--- src/protocol_key.c | 8 +++--- src/protocol_misc.c | 6 ++--- src/protocol_subnet.c | 6 ++--- src/subnet.c | 59 +++++++++++++++++++++++-------------------- src/subnet.h | 14 +++++----- 23 files changed, 166 insertions(+), 159 deletions(-) diff --git a/lib/avl_tree.c b/lib/avl_tree.c index 65df7b79..be35b969 100644 --- a/lib/avl_tree.c +++ b/lib/avl_tree.c @@ -29,7 +29,7 @@ library for inclusion into tinc (http://tinc.nl.linux.org/) by Guus Sliepen . - $Id: avl_tree.c,v 1.1.2.16 2003/07/17 15:06:25 guus Exp $ + $Id: avl_tree.c,v 1.1.2.17 2003/07/24 12:08:14 guus Exp $ */ #include "system.h" @@ -90,7 +90,7 @@ static int lg(unsigned int u) /* Internal helper functions */ -static int avl_check_balance(avl_node_t *node) +static int avl_check_balance(const avl_node_t *node) { #ifdef AVL_DEPTH int d; @@ -666,7 +666,7 @@ void avl_delete_tree(avl_tree_t *tree) /* Tree walking */ -void avl_foreach(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; @@ -676,7 +676,7 @@ void avl_foreach(avl_tree_t *tree, avl_action_t action) } } -void avl_foreach_node(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; @@ -689,7 +689,7 @@ void avl_foreach_node(avl_tree_t *tree, avl_action_t action) /* Indexing */ #ifdef AVL_COUNT -unsigned int avl_count(avl_tree_t *tree) +unsigned int avl_count(const avl_tree_t *tree) { return AVL_NODE_COUNT(tree->root); } @@ -734,7 +734,7 @@ unsigned int avl_index(const avl_node_t *node) } #endif #ifdef AVL_DEPTH -unsigned int avl_depth(avl_tree_t *tree) +unsigned int avl_depth(const avl_tree_t *tree) { return AVL_NODE_DEPTH(tree->root); } diff --git a/lib/avl_tree.h b/lib/avl_tree.h index b026e1e7..8007a516 100644 --- a/lib/avl_tree.h +++ b/lib/avl_tree.h @@ -29,7 +29,7 @@ library for inclusion into tinc (http://tinc.nl.linux.org/) by Guus Sliepen . - $Id: avl_tree.h,v 1.1.2.9 2003/07/12 17:48:38 guus Exp $ + $Id: avl_tree.h,v 1.1.2.10 2003/07/24 12:08:15 guus Exp $ */ @@ -128,18 +128,18 @@ extern avl_node_t *avl_search_closest_greater_node(const avl_tree_t *, const voi /* Tree walking */ -extern void avl_foreach(avl_tree_t *, avl_action_t); -extern void avl_foreach_node(avl_tree_t *, avl_action_t); +extern void avl_foreach(const avl_tree_t *, avl_action_t); +extern void avl_foreach_node(const avl_tree_t *, avl_action_t); /* Indexing */ #ifdef AVL_COUNT -extern unsigned int avl_count(avl_tree_t *); +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 *); #endif #ifdef AVL_DEPTH -extern unsigned int avl_depth(avl_tree_t *); +extern unsigned int avl_depth(const avl_tree_t *); #endif #endif /* __AVL_TREE_H__ */ diff --git a/src/conf.c b/src/conf.c index d34a087c..4a444433 100644 --- a/src/conf.c +++ b/src/conf.c @@ -19,7 +19,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: conf.c,v 1.9.4.68 2003/07/22 20:55:19 guus Exp $ + $Id: conf.c,v 1.9.4.69 2003/07/24 12:08:15 guus Exp $ */ #include "system.h" @@ -37,7 +37,7 @@ int pingtimeout = 0; /* seconds before timeout */ char *confbase = NULL; /* directory in which all config files are */ char *netname = NULL; /* name of the vpn network */ -static int config_compare(config_t *a, config_t *b) +static int config_compare(const config_t *a, const config_t *b) { int result; @@ -99,7 +99,7 @@ void config_add(avl_tree_t *config_tree, config_t *cfg) avl_insert(config_tree, cfg); } -config_t *lookup_config(avl_tree_t *config_tree, char *variable) +config_t *lookup_config(const avl_tree_t *config_tree, char *variable) { config_t cfg, *found; @@ -120,7 +120,7 @@ config_t *lookup_config(avl_tree_t *config_tree, char *variable) return found; } -config_t *lookup_config_next(avl_tree_t *config_tree, config_t *cfg) +config_t *lookup_config_next(const avl_tree_t *config_tree, const config_t *cfg) { avl_node_t *node; config_t *found; @@ -141,7 +141,7 @@ config_t *lookup_config_next(avl_tree_t *config_tree, config_t *cfg) return NULL; } -bool get_config_bool(config_t *cfg, bool *result) +bool get_config_bool(const config_t *cfg, bool *result) { cp(); @@ -162,7 +162,7 @@ bool get_config_bool(config_t *cfg, bool *result) return false; } -bool get_config_int(config_t *cfg, int *result) +bool get_config_int(const config_t *cfg, int *result) { cp(); @@ -178,7 +178,7 @@ bool get_config_int(config_t *cfg, int *result) return false; } -bool get_config_string(config_t *cfg, char **result) +bool get_config_string(const config_t *cfg, char **result) { cp(); @@ -190,7 +190,7 @@ bool get_config_string(config_t *cfg, char **result) return true; } -bool get_config_address(config_t *cfg, struct addrinfo **result) +bool get_config_address(const config_t *cfg, struct addrinfo **result) { struct addrinfo *ai; @@ -212,7 +212,7 @@ bool get_config_address(config_t *cfg, struct addrinfo **result) return false; } -bool get_config_subnet(config_t *cfg, subnet_t ** result) +bool get_config_subnet(const config_t *cfg, subnet_t ** result) { subnet_t *subnet; diff --git a/src/conf.h b/src/conf.h index b4064cd1..8ceb111e 100644 --- a/src/conf.h +++ b/src/conf.h @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: conf.h,v 1.6.4.40 2003/07/22 20:55:19 guus Exp $ + $Id: conf.h,v 1.6.4.41 2003/07/24 12:08:15 guus Exp $ */ #ifndef __TINC_CONF_H__ @@ -47,13 +47,13 @@ extern void exit_configuration(avl_tree_t **); 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(avl_tree_t *, char *); -extern config_t *lookup_config_next(avl_tree_t *, config_t *); -extern bool get_config_bool(config_t *, bool *); -extern bool get_config_int(config_t *, int *); -extern bool get_config_string(config_t *, char **); -extern bool get_config_address(config_t *, struct addrinfo **); -extern bool get_config_subnet(config_t *, struct subnet_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 int read_config_file(avl_tree_t *, const char *); extern bool read_server_config(void); diff --git a/src/connection.c b/src/connection.c index eba74ae4..ccec2ed8 100644 --- a/src/connection.c +++ b/src/connection.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: connection.c,v 1.1.2.41 2003/07/22 20:55:19 guus Exp $ + $Id: connection.c,v 1.1.2.42 2003/07/24 12:08:15 guus Exp $ */ #include "system.h" @@ -35,7 +35,7 @@ avl_tree_t *connection_tree; /* Meta connections */ connection_t *broadcast; -static int connection_compare(connection_t *a, connection_t *b) +static int connection_compare(const connection_t *a, const connection_t *b) { return (void *)a - (void *)b; } diff --git a/src/edge.c b/src/edge.c index 48ead007..76bdc41b 100644 --- a/src/edge.c +++ b/src/edge.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: edge.c,v 1.1.2.22 2003/07/17 15:06:26 guus Exp $ + $Id: edge.c,v 1.1.2.23 2003/07/24 12:08:15 guus Exp $ */ #include "system.h" @@ -32,12 +32,12 @@ avl_tree_t *edge_weight_tree; /* Tree with all edges, sorted on weight */ -static int edge_compare(edge_t *a, 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(edge_t *a, edge_t *b) +static int edge_weight_compare(const edge_t *a, const edge_t *b) { int result; @@ -123,15 +123,15 @@ void edge_del(edge_t *e) avl_delete(edge_weight_tree, e); } -edge_t *lookup_edge(node_t *from, node_t *to) +edge_t *lookup_edge(const node_t *from, const node_t *to) { - edge_t v; + edge_t v = { + .from = from, + .to = to + }; cp(); - v.from = from; - v.to = to; - return avl_search(from->edge_tree, &v); } diff --git a/src/edge.h b/src/edge.h index b841bc9b..0f723132 100644 --- a/src/edge.h +++ b/src/edge.h @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: edge.h,v 1.1.2.14 2003/07/17 15:06:26 guus Exp $ + $Id: edge.h,v 1.1.2.15 2003/07/24 12:08:15 guus Exp $ */ #ifndef __TINC_EDGE_H__ @@ -50,7 +50,7 @@ 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 edge_t *lookup_edge(const struct node_t *, const struct node_t *); extern void dump_edges(void); #endif /* __TINC_EDGE_H__ */ diff --git a/src/event.c b/src/event.c index 4eae34d1..4e0f6a09 100644 --- a/src/event.c +++ b/src/event.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: event.c,v 1.1.4.9 2003/07/17 15:06:26 guus Exp $ + $Id: event.c,v 1.1.4.10 2003/07/24 12:08:15 guus Exp $ */ #include "system.h" @@ -32,7 +32,7 @@ extern time_t now; int id; -static int event_compare(event_t *a, event_t *b) +static int event_compare(const event_t *a, const event_t *b) { if(a->time > b->time) return 1; diff --git a/src/net.h b/src/net.h index 22d78b2b..8ab33615 100644 --- a/src/net.h +++ b/src/net.h @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net.h,v 1.9.4.66 2003/07/22 20:55:20 guus Exp $ + $Id: net.h,v 1.9.4.67 2003/07/24 12:08:15 guus Exp $ */ #ifndef __TINC_NET_H__ @@ -126,11 +126,11 @@ 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(sockaddr_t *); -extern int setup_vpn_in_socket(sockaddr_t *); -extern void send_packet(struct node_t *, vpn_packet_t *); +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 *, char *, int); -extern void broadcast_packet(struct node_t *, vpn_packet_t *); +extern void broadcast_packet(const struct node_t *, vpn_packet_t *); extern bool setup_network_connections(void); extern void setup_outgoing_connection(struct outgoing_t *); extern void try_outgoing_connections(void); diff --git a/src/net_packet.c b/src/net_packet.c index cac24ee6..ff57753f 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net_packet.c,v 1.1.2.35 2003/07/22 20:55:20 guus Exp $ + $Id: net_packet.c,v 1.1.2.36 2003/07/24 12:08:15 guus Exp $ */ #include "system.h" @@ -323,7 +323,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *inpkt) /* send a packet to the given vpn ip. */ -void send_packet(node_t *n, vpn_packet_t *packet) +void send_packet(const node_t *n, vpn_packet_t *packet) { node_t *via; @@ -358,7 +358,7 @@ void send_packet(node_t *n, vpn_packet_t *packet) /* Broadcast a packet using the minimum spanning tree */ -void broadcast_packet(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; diff --git a/src/net_socket.c b/src/net_socket.c index 98f5d1a2..aa7d3d99 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net_socket.c,v 1.1.2.30 2003/07/22 20:55:20 guus Exp $ + $Id: net_socket.c,v 1.1.2.31 2003/07/24 12:08:15 guus Exp $ */ #include "system.h" @@ -43,7 +43,7 @@ int listen_sockets; /* Setup sockets */ -int setup_listen_socket(sockaddr_t *sa) +int setup_listen_socket(const sockaddr_t *sa) { int nfd, flags; char *addrstr; @@ -119,7 +119,7 @@ int setup_listen_socket(sockaddr_t *sa) return nfd; } -int setup_vpn_in_socket(sockaddr_t *sa) +int setup_vpn_in_socket(const sockaddr_t *sa) { int nfd, flags; char *addrstr; diff --git a/src/netutl.c b/src/netutl.c index 0d34d8d6..cd50792f 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: netutl.c,v 1.12.4.48 2003/07/22 20:55:20 guus Exp $ + $Id: netutl.c,v 1.12.4.49 2003/07/24 12:08:15 guus Exp $ */ #include "system.h" @@ -34,7 +34,7 @@ bool hostnames = false; Turn a string into a struct addrinfo. Return NULL on failure. */ -struct addrinfo *str2addrinfo(char *address, char *service, int socktype) +struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype) { struct addrinfo hint, *ai; int err; @@ -57,7 +57,7 @@ struct addrinfo *str2addrinfo(char *address, char *service, int socktype) return ai; } -sockaddr_t str2sockaddr(char *address, char *port) +sockaddr_t str2sockaddr(const char *address, const char *port) { struct addrinfo hint, *ai; sockaddr_t result; @@ -87,7 +87,7 @@ sockaddr_t str2sockaddr(char *address, char *port) return result; } -void sockaddr2str(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]; @@ -115,7 +115,7 @@ void sockaddr2str(sockaddr_t *sa, char **addrstr, char **portstr) *portstr = xstrdup(port); } -char *sockaddr2hostname(sockaddr_t *sa) +char *sockaddr2hostname(const sockaddr_t *sa) { char *str; char address[NI_MAXHOST] = "unknown"; @@ -136,7 +136,7 @@ char *sockaddr2hostname(sockaddr_t *sa) return str; } -int sockaddrcmp(sockaddr_t *a, sockaddr_t *b) +int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b) { int result; @@ -186,11 +186,11 @@ void sockaddrunmap(sockaddr_t *sa) /* Subnet mask handling */ -int maskcmp(void *va, void *vb, int masklen, int len) +int maskcmp(const void *va, const void *vb, int masklen, int len) { int i, m, result; - char *a = va; - char *b = vb; + const char *a = va; + const char *b = vb; cp(); @@ -224,11 +224,11 @@ void mask(void *va, int masklen, int len) a[i] = 0; } -void maskcpy(void *va, void *vb, int masklen, int len) +void maskcpy(void *va, const void *vb, int masklen, int len) { int i, m; char *a = va; - char *b = vb; + const char *b = vb; cp(); @@ -244,10 +244,10 @@ void maskcpy(void *va, void *vb, int masklen, int len) a[i] = 0; } -bool maskcheck(void *va, int masklen, int len) +bool maskcheck(const void *va, int masklen, int len) { int i; - char *a = va; + const char *a = va; cp(); diff --git a/src/netutl.h b/src/netutl.h index 66a7c972..d5a7feb8 100644 --- a/src/netutl.h +++ b/src/netutl.h @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: netutl.h,v 1.2.4.17 2003/07/22 20:55:20 guus Exp $ + $Id: netutl.h,v 1.2.4.18 2003/07/24 12:08:15 guus Exp $ */ #ifndef __TINC_NETUTL_H__ @@ -27,15 +27,15 @@ extern bool hostnames; -extern struct addrinfo *str2addrinfo(char *, char *, int); -extern sockaddr_t str2sockaddr(char *, char *); -extern void sockaddr2str(sockaddr_t *, char **, char **); -extern char *sockaddr2hostname(sockaddr_t *); -extern int sockaddrcmp(sockaddr_t *, sockaddr_t *); +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 void sockaddrunmap(sockaddr_t *); -extern int maskcmp(void *, void *, int, int); -extern void maskcpy(void *, void *, int, int); +extern int maskcmp(const void *, const void *, int, int); +extern void maskcpy(void *, const void *, int, int); extern void mask(void *, int, int); -extern bool maskcheck(void *, int, int); +extern bool maskcheck(const void *, int, int); #endif /* __TINC_NETUTL_H__ */ diff --git a/src/node.c b/src/node.c index 5fc94a94..0401144f 100644 --- a/src/node.c +++ b/src/node.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: node.c,v 1.1.2.23 2003/07/17 15:06:26 guus Exp $ + $Id: node.c,v 1.1.2.24 2003/07/24 12:08:15 guus Exp $ */ #include "system.h" @@ -35,12 +35,12 @@ avl_tree_t *node_udp_tree; /* Known nodes, sorted by address and port */ node_t *myself; -static int node_compare(node_t *a, 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(node_t *a, node_t *b) +static int node_udp_compare(const node_t *a, const node_t *b) { int result; @@ -143,20 +143,25 @@ void node_del(node_t *n) avl_delete(node_udp_tree, n); } -node_t *lookup_node(char *name) +node_t *lookup_node(const char *name) { - node_t n; + node_t n = { + .name = name, + }; + cp(); - n.name = name; + return avl_search(node_tree, &n); } -node_t *lookup_node_udp(sockaddr_t *sa) +node_t *lookup_node_udp(const sockaddr_t *sa) { - node_t n; + node_t n = { + .address = *sa, + .name = NULL, + }; + cp(); - n.address = *sa; - n.name = NULL; return avl_search(node_udp_tree, &n); } diff --git a/src/node.h b/src/node.h index 3dd112e6..02d84976 100644 --- a/src/node.h +++ b/src/node.h @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: node.h,v 1.1.2.26 2003/07/22 20:55:20 guus Exp $ + $Id: node.h,v 1.1.2.27 2003/07/24 12:08:15 guus Exp $ */ #ifndef __TINC_NODE_H__ @@ -83,8 +83,8 @@ 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(sockaddr_t *); +extern node_t *lookup_node(const char *); +extern node_t *lookup_node_udp(const sockaddr_t *); extern void dump_nodes(void); #endif /* __TINC_NODE_H__ */ diff --git a/src/protocol.c b/src/protocol.c index ad7c57d7..dad7ccb6 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol.c,v 1.28.4.142 2003/07/22 20:55:20 guus Exp $ + $Id: protocol.c,v 1.28.4.143 2003/07/24 12:08:15 guus Exp $ */ #include "system.h" @@ -53,12 +53,10 @@ static char (*request_name[]) = { static avl_tree_t *past_request_tree; -bool check_id(char *id) +bool check_id(const char *id) { - int i; - - for(i = 0; i < strlen(id); i++) - if(!isalnum(id[i]) && id[i] != '_') + for(; *id; id++) + if(!isalnum(*id) && *id != '_') return false; return true; @@ -180,7 +178,7 @@ bool receive_request(connection_t *c) return true; } -static int past_request_compare(past_request_t *a, 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); } @@ -209,14 +207,15 @@ void exit_requests(void) avl_delete_tree(past_request_tree); } -bool seen_request(char *request) +bool seen_request(const char *request) { - past_request_t p, *new; + past_request_t p = { + .request = request, + }; + past_request_t *new; cp(); - p.request = request; - if(avl_search(past_request_tree, &p)) { ifdebug(SCARY_THINGS) logger(LOG_DEBUG, _("Already seen request")); return true; diff --git a/src/protocol.h b/src/protocol.h index 132a8e6e..fbbe0335 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol.h,v 1.5.4.40 2003/07/22 20:55:20 guus Exp $ + $Id: protocol.h,v 1.5.4.41 2003/07/24 12:08:16 guus Exp $ */ #ifndef __TINC_PROTOCOL_H__ @@ -63,11 +63,11 @@ typedef struct past_request_t { 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(char *); +extern bool check_id(const char *); extern void init_requests(void); extern void exit_requests(void); -extern bool seen_request(char *); +extern bool seen_request(const char *); extern void age_past_requests(void); /* Requests */ @@ -77,18 +77,18 @@ 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_status(struct connection_t *, int, char *); -extern bool send_error(struct connection_t *, int, char *); +extern bool send_status(struct connection_t *, int, const char *); +extern bool send_error(struct connection_t *, int,const char *); extern bool send_termreq(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 *, struct subnet_t *); -extern bool send_del_subnet(struct connection_t *, struct subnet_t *); -extern bool send_add_edge(struct connection_t *, struct edge_t *); -extern bool send_del_edge(struct connection_t *, struct edge_t *); -extern bool send_key_changed(struct connection_t *, struct node_t *); -extern bool send_req_key(struct connection_t *, struct node_t *, struct node_t *); -extern bool send_ans_key(struct connection_t *, struct node_t *, struct node_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_key_changed(struct connection_t *, const struct node_t *); +extern bool send_req_key(struct connection_t *, const struct node_t *, const struct node_t *); +extern bool send_ans_key(struct connection_t *, const struct node_t *, const struct node_t *); extern bool send_tcppacket(struct connection_t *, struct vpn_packet_t *); /* Request handlers */ diff --git a/src/protocol_edge.c b/src/protocol_edge.c index e1e2ca01..4552a528 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol_edge.c,v 1.1.4.19 2003/07/22 20:55:20 guus Exp $ + $Id: protocol_edge.c,v 1.1.4.20 2003/07/24 12:08:16 guus Exp $ */ #include "system.h" @@ -36,7 +36,7 @@ #include "utils.h" #include "xalloc.h" -bool send_add_edge(connection_t *c, edge_t *e) +bool send_add_edge(connection_t *c, const edge_t *e) { bool x; char *address, *port; @@ -163,7 +163,7 @@ bool add_edge_h(connection_t *c) return true; } -bool send_del_edge(connection_t *c, edge_t *e) +bool send_del_edge(connection_t *c, const edge_t *e) { cp(); diff --git a/src/protocol_key.c b/src/protocol_key.c index 421e2a30..cb652c1e 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol_key.c,v 1.1.4.21 2003/07/23 22:17:31 guus Exp $ + $Id: protocol_key.c,v 1.1.4.22 2003/07/24 12:08:16 guus Exp $ */ #include "system.h" @@ -34,7 +34,7 @@ bool mykeyused = false; -bool send_key_changed(connection_t *c, node_t *n) +bool send_key_changed(connection_t *c, const node_t *n) { cp(); @@ -82,7 +82,7 @@ bool key_changed_h(connection_t *c) return true; } -bool send_req_key(connection_t *c, node_t *from, node_t *to) +bool send_req_key(connection_t *c, const node_t *from, const node_t *to) { cp(); @@ -133,7 +133,7 @@ bool req_key_h(connection_t *c) return true; } -bool send_ans_key(connection_t *c, node_t *from, node_t *to) +bool send_ans_key(connection_t *c, const node_t *from, const node_t *to) { char key[MAX_STRING_SIZE]; diff --git a/src/protocol_misc.c b/src/protocol_misc.c index 25a86abe..66f8980a 100644 --- a/src/protocol_misc.c +++ b/src/protocol_misc.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol_misc.c,v 1.1.4.12 2003/07/22 20:55:20 guus Exp $ + $Id: protocol_misc.c,v 1.1.4.13 2003/07/24 12:08:16 guus Exp $ */ #include "system.h" @@ -33,7 +33,7 @@ /* Status and error notification routines */ -bool send_status(connection_t *c, int statusno, char *statusstring) +bool send_status(connection_t *c, int statusno, const char *statusstring) { cp(); @@ -62,7 +62,7 @@ bool status_h(connection_t *c) return true; } -bool send_error(connection_t *c, int err, char *errstring) +bool send_error(connection_t *c, int err, const char *errstring) { cp(); diff --git a/src/protocol_subnet.c b/src/protocol_subnet.c index 48b5efef..bb2f2def 100644 --- a/src/protocol_subnet.c +++ b/src/protocol_subnet.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol_subnet.c,v 1.1.4.14 2003/07/22 20:55:20 guus Exp $ + $Id: protocol_subnet.c,v 1.1.4.15 2003/07/24 12:08:16 guus Exp $ */ #include "system.h" @@ -33,7 +33,7 @@ #include "utils.h" #include "xalloc.h" -bool send_add_subnet(connection_t *c, subnet_t *subnet) +bool send_add_subnet(connection_t *c, const subnet_t *subnet) { bool x; char *netstr; @@ -122,7 +122,7 @@ bool add_subnet_h(connection_t *c) return true; } -bool send_del_subnet(connection_t *c, subnet_t *s) +bool send_del_subnet(connection_t *c, const subnet_t *s) { bool x; char *netstr; diff --git a/src/subnet.c b/src/subnet.c index f5a8bd4b..4541594d 100644 --- a/src/subnet.c +++ b/src/subnet.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: subnet.c,v 1.1.2.47 2003/07/17 15:06:27 guus Exp $ + $Id: subnet.c,v 1.1.2.48 2003/07/24 12:08:16 guus Exp $ */ #include "system.h" @@ -37,7 +37,7 @@ avl_tree_t *subnet_tree; /* Subnet comparison */ -static int subnet_compare_mac(subnet_t *a, subnet_t *b) +static int subnet_compare_mac(const subnet_t *a, const subnet_t *b) { int result; @@ -49,7 +49,7 @@ static int subnet_compare_mac(subnet_t *a, subnet_t *b) return strcmp(a->owner->name, b->owner->name); } -static int subnet_compare_ipv4(subnet_t *a, subnet_t *b) +static int subnet_compare_ipv4(const subnet_t *a, const subnet_t *b) { int result; @@ -66,7 +66,7 @@ static int subnet_compare_ipv4(subnet_t *a, subnet_t *b) return strcmp(a->owner->name, b->owner->name); } -static int subnet_compare_ipv6(subnet_t *a, subnet_t *b) +static int subnet_compare_ipv6(const subnet_t *a, const subnet_t *b) { int result; @@ -83,7 +83,7 @@ static int subnet_compare_ipv6(subnet_t *a, subnet_t *b) return strcmp(a->owner->name, b->owner->name); } -static int subnet_compare(subnet_t *a, subnet_t *b) +static int subnet_compare(const subnet_t *a, const subnet_t *b) { int result; @@ -177,7 +177,7 @@ void subnet_del(node_t *n, subnet_t *subnet) /* Ascii representation of subnets */ -subnet_t *str2net(char *subnetstr) +subnet_t *str2net(const char *subnetstr) { int i, l; subnet_t *subnet; @@ -246,7 +246,7 @@ subnet_t *str2net(char *subnetstr) return NULL; } -char *net2str(subnet_t *subnet) +char *net2str(const subnet_t *subnet) { char *netstr; @@ -296,39 +296,41 @@ char *net2str(subnet_t *subnet) /* Subnet lookup routines */ -subnet_t *lookup_subnet(node_t *owner, subnet_t *subnet) +subnet_t *lookup_subnet(const node_t *owner, const subnet_t *subnet) { cp(); return avl_search(owner->subnet_tree, subnet); } -subnet_t *lookup_subnet_mac(mac_t *address) +subnet_t *lookup_subnet_mac(const mac_t *address) { - subnet_t subnet, *p; + subnet_t subnet = { + .type = SUBNET_MAC, + .net.mac.address = *address, + .owner = NULL + }; + subnet_t *p; cp(); - subnet.type = SUBNET_MAC; - memcpy(&subnet.net.mac.address, address, sizeof(mac_t)); - subnet.owner = NULL; - p = (subnet_t *) avl_search(subnet_tree, &subnet); return p; } -subnet_t *lookup_subnet_ipv4(ipv4_t *address) +subnet_t *lookup_subnet_ipv4(const ipv4_t *address) { - subnet_t subnet, *p; + subnet_t subnet = { + .type = SUBNET_IPV4, + .net.ipv4.address = *address, + .net.ipv4.prefixlength = 32, + .owner = NULL + }; + subnet_t *p; cp(); - subnet.type = SUBNET_IPV4; - memcpy(&subnet.net.ipv4.address, address, sizeof(ipv4_t)); - subnet.net.ipv4.prefixlength = 32; - subnet.owner = NULL; - do { /* Go find subnet */ @@ -356,17 +358,18 @@ subnet_t *lookup_subnet_ipv4(ipv4_t *address) return p; } -subnet_t *lookup_subnet_ipv6(ipv6_t *address) +subnet_t *lookup_subnet_ipv6(const ipv6_t *address) { - subnet_t subnet, *p; + subnet_t subnet = { + .type = SUBNET_IPV6, + .net.ipv6.address = *address, + .net.ipv6.prefixlength = 128, + .owner = NULL + }; + subnet_t *p; cp(); - subnet.type = SUBNET_IPV6; - memcpy(&subnet.net.ipv6.address, address, sizeof(ipv6_t)); - subnet.net.ipv6.prefixlength = 128; - subnet.owner = NULL; - do { /* Go find subnet */ diff --git a/src/subnet.h b/src/subnet.h index 7cb0e9bb..edca1c74 100644 --- a/src/subnet.h +++ b/src/subnet.h @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: subnet.h,v 1.1.2.22 2003/07/22 20:55:20 guus Exp $ + $Id: subnet.h,v 1.1.2.23 2003/07/24 12:08:16 guus Exp $ */ #ifndef __TINC_SUBNET_H__ @@ -72,12 +72,12 @@ 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 char *net2str(subnet_t *); -extern subnet_t *str2net(char *); -extern subnet_t *lookup_subnet(struct node_t *, subnet_t *); -extern subnet_t *lookup_subnet_mac(mac_t *); -extern subnet_t *lookup_subnet_ipv4(ipv4_t *); -extern subnet_t *lookup_subnet_ipv6(ipv6_t *); +extern char *net2str(const subnet_t *); +extern subnet_t *str2net(const char *); +extern subnet_t *lookup_subnet(const struct node_t *, const subnet_t *); +extern subnet_t *lookup_subnet_mac(const mac_t *); +extern subnet_t *lookup_subnet_ipv4(const ipv4_t *); +extern subnet_t *lookup_subnet_ipv6(const ipv6_t *); extern void dump_subnets(void); #endif /* __TINC_SUBNET_H__ */ -- 2.39.5