library for inclusion into tinc (http://tinc.nl.linux.org/) by
Guus Sliepen <guus@sliepen.eu.org>.
- $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"
/* 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;
/* 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;
}
}
-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;
/* 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);
}
}
#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);
}
library for inclusion into tinc (http://tinc.nl.linux.org/) by
Guus Sliepen <guus@sliepen.eu.org>.
- $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 $
*/
/* 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__ */
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"
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;
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;
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;
return NULL;
}
-bool get_config_bool(config_t *cfg, bool *result)
+bool get_config_bool(const config_t *cfg, bool *result)
{
cp();
return false;
}
-bool get_config_int(config_t *cfg, int *result)
+bool get_config_int(const config_t *cfg, int *result)
{
cp();
return false;
}
-bool get_config_string(config_t *cfg, char **result)
+bool get_config_string(const config_t *cfg, char **result)
{
cp();
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;
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;
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__
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);
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"
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;
}
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"
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;
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);
}
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__
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__ */
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"
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;
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__
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);
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"
/*
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;
/* 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;
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"
/* Setup sockets */
-int setup_listen_socket(sockaddr_t *sa)
+int setup_listen_socket(const sockaddr_t *sa)
{
int nfd, flags;
char *addrstr;
return nfd;
}
-int setup_vpn_in_socket(sockaddr_t *sa)
+int setup_vpn_in_socket(const sockaddr_t *sa)
{
int nfd, flags;
char *addrstr;
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"
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;
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;
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];
*portstr = xstrdup(port);
}
-char *sockaddr2hostname(sockaddr_t *sa)
+char *sockaddr2hostname(const sockaddr_t *sa)
{
char *str;
char address[NI_MAXHOST] = "unknown";
return str;
}
-int sockaddrcmp(sockaddr_t *a, sockaddr_t *b)
+int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b)
{
int result;
/* 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();
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();
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();
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__
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__ */
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"
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;
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);
}
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__
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__ */
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"
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;
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);
}
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;
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__
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 */
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 */
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"
#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;
return true;
}
-bool send_del_edge(connection_t *c, edge_t *e)
+bool send_del_edge(connection_t *c, const edge_t *e)
{
cp();
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"
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();
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();
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];
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"
/* 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();
return true;
}
-bool send_error(connection_t *c, int err, char *errstring)
+bool send_error(connection_t *c, int err, const char *errstring)
{
cp();
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"
#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;
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;
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"
/* 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;
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;
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;
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;
/* Ascii representation of subnets */
-subnet_t *str2net(char *subnetstr)
+subnet_t *str2net(const char *subnetstr)
{
int i, l;
subnet_t *subnet;
return NULL;
}
-char *net2str(subnet_t *subnet)
+char *net2str(const subnet_t *subnet)
{
char *netstr;
/* 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 */
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 */
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__
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__ */