Cleanups:

- Convert cp to cp(); so that automatic indenters work.
 - Convert constructions like if(x == NULL) to if(!x).
 - Move all assignments out of conditions.
This commit is contained in:
Guus Sliepen 2002-09-09 19:40:12 +00:00
parent 5638b9830f
commit 5fc1ed17f4
26 changed files with 508 additions and 426 deletions

View file

@ -1,6 +1,6 @@
dnl Process this file with autoconf to produce a configure script.
dnl $Id: configure.in,v 1.13.2.57 2002/09/06 11:08:21 zarq Exp $
dnl $Id: configure.in,v 1.13.2.58 2002/09/09 19:39:53 guus Exp $
AC_PREREQ(2.53)
AC_INIT(src/tincd.c)
@ -129,7 +129,7 @@ AC_FUNC_ALLOCA
AC_TYPE_SIGNAL
AC_CHECK_FUNCS([asprintf daemon fcloseall flock ftime get_current_dir_name \
putenv select strdup strerror strsignal strtol unsetenv \
freeaddrinfo gai_strerror getaddrinfo getnameinfo])
freeaddrinfo gai_strerror getaddrinfo getnameinfo mlockall])
jm_FUNC_MALLOC
jm_FUNC_REALLOC

View file

@ -46,11 +46,11 @@ extern volatile char *cp_file[];
extern volatile int cp_index;
extern void cp_trace(void);
#define cp { cp_line[cp_index] = __LINE__; cp_file[cp_index] = __FILE__; cp_index++; cp_index %= 16; }
#define ecp { fprintf(stderr, "Explicit checkpoint in %s line %d\n", __FILE__, __LINE__); }
#define cp() { cp_line[cp_index] = __LINE__; cp_file[cp_index] = __FILE__; cp_index++; cp_index %= 16; }
#define ecp() { fprintf(stderr, "Explicit checkpoint in %s line %d\n", __FILE__, __LINE__); }
#else
#define cp
#define ecp
#define cp()
#define ecp()
#define cp_trace()
#endif

View file

@ -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.57 2002/06/21 10:11:12 guus Exp $
$Id: conf.c,v 1.9.4.58 2002/09/09 19:39:55 guus Exp $
*/
#include "config.h"
@ -72,23 +72,23 @@ int config_compare(config_t *a, config_t *b)
void init_configuration(avl_tree_t **config_tree)
{
cp
cp();
*config_tree = avl_alloc_tree((avl_compare_t)config_compare, (avl_action_t)free_config);
cp
cp();
}
void exit_configuration(avl_tree_t **config_tree)
{
cp
cp();
avl_delete_tree(*config_tree);
*config_tree = NULL;
cp
cp();
}
config_t *new_config(void)
{
config_t *cfg;
cp
cp();
cfg = (config_t *)xmalloc_and_zero(sizeof(*cfg));
return cfg;
@ -96,7 +96,7 @@ cp
void free_config(config_t *cfg)
{
cp
cp();
if(cfg->variable)
free(cfg->variable);
if(cfg->value)
@ -104,20 +104,20 @@ cp
if(cfg->file)
free(cfg->file);
free(cfg);
cp
cp();
}
void config_add(avl_tree_t *config_tree, config_t *cfg)
{
cp
cp();
avl_insert(config_tree, cfg);
cp
cp();
}
config_t *lookup_config(avl_tree_t *config_tree, char *variable)
{
config_t cfg, *found;
cp
cp();
cfg.variable = variable;
cfg.file = "";
cfg.line = 0;
@ -137,7 +137,7 @@ config_t *lookup_config_next(avl_tree_t *config_tree, config_t *cfg)
{
avl_node_t *node;
config_t *found;
cp
cp();
node = avl_search_node(config_tree, cfg);
if(node)
@ -155,7 +155,7 @@ cp
int get_config_bool(config_t *cfg, int *result)
{
cp
cp();
if(!cfg)
return 0;
@ -178,7 +178,7 @@ cp
int get_config_int(config_t *cfg, int *result)
{
cp
cp();
if(!cfg)
return 0;
@ -192,7 +192,7 @@ cp
int get_config_string(config_t *cfg, char **result)
{
cp
cp();
if(!cfg)
return 0;
@ -203,7 +203,7 @@ cp
int get_config_address(config_t *cfg, struct addrinfo **result)
{
struct addrinfo *ai;
cp
cp();
if(!cfg)
return 0;
@ -222,7 +222,7 @@ cp
int get_config_port(config_t *cfg, port_t *result)
{
cp
cp();
if(!cfg)
return 0;
@ -240,7 +240,7 @@ cp
int get_config_subnet(config_t *cfg, subnet_t **result)
{
subnet_t *subnet;
cp
cp();
if(!cfg)
return 0;
@ -295,7 +295,7 @@ char *readline(FILE *fp, char **buf, size_t *buflen)
if(feof(fp))
return NULL;
if((buf != NULL) && (buflen != NULL))
if(buf && buflen)
{
size = *buflen;
line = *buf;
@ -313,7 +313,7 @@ char *readline(FILE *fp, char **buf, size_t *buflen)
{
errno = 0;
p = fgets(idx, maxlen, fp);
if(p == NULL) /* EOF or error */
if(!p) /* EOF or error */
{
if(feof(fp))
break;
@ -325,7 +325,7 @@ char *readline(FILE *fp, char **buf, size_t *buflen)
}
newline = strchr(p, '\n');
if(newline == NULL)
if(!newline)
/* We haven't yet read everything to the end of the line */
{
newsize = size << 1;
@ -341,7 +341,7 @@ char *readline(FILE *fp, char **buf, size_t *buflen)
}
}
if((buf != NULL) && (buflen != NULL))
if(buf && buflen)
{
*buflen = size;
*buf = line;
@ -363,8 +363,10 @@ int read_config_file(avl_tree_t *config_tree, const char *fname)
config_t *cfg;
size_t bufsize;
cp
if((fp = fopen (fname, "r")) == NULL)
cp();
fp = fopen (fname, "r");
if(!fp)
{
syslog(LOG_ERR, _("Cannot open config file %s: %s"), fname, strerror(errno));
return -3;
@ -375,7 +377,9 @@ cp
for(;;)
{
if((line = readline(fp, &buffer, &bufsize)) == NULL)
line = readline(fp, &buffer, &bufsize);
if(!line)
{
err = -1;
break;
@ -389,7 +393,9 @@ cp
lineno++;
if((variable = strtok(line, "\t =")) == NULL)
variable = strtok(line, "\t =");
if(!variable)
continue; /* no tokens on this line */
if(variable[0] == '#')
@ -400,7 +406,9 @@ cp
if(!ignore)
{
if(((value = strtok(NULL, "\t\n\r =")) == NULL) || value[0] == '#')
value = strtok(NULL, "\t\n\r =");
if(!value || value[0] == '#')
{
syslog(LOG_ERR, _("No value for variable `%s' on line %d while reading config file %s"),
variable, lineno, fname);
@ -422,7 +430,7 @@ cp
free(buffer);
fclose (fp);
cp
cp();
return err;
}
@ -430,7 +438,7 @@ int read_server_config()
{
char *fname;
int x;
cp
cp();
asprintf(&fname, "%s/tinc.conf", confbase);
x = read_config_file(config_tree, fname);
if(x == -1) /* System error: complain */
@ -438,7 +446,7 @@ cp
syslog(LOG_ERR, _("Failed to read `%s': %s"), fname, strerror(errno));
}
free(fname);
cp
cp();
return x;
}
@ -571,18 +579,20 @@ FILE *ask_and_safe_open(const char* filename, const char* what, const char* mode
what, filename);
fflush(stdout);
if((fn = readline(stdin, NULL, NULL)) == NULL)
fn = readline(stdin, NULL, NULL);
if(!fn)
{
fprintf(stderr, _("Error while reading stdin: %s\n"), strerror(errno));
return NULL;
}
if(strlen(fn) == 0)
if(!strlen(fn))
/* User just pressed enter. */
fn = xstrdup(filename);
}
if((strchr(fn, '/') == NULL) || (fn[0] != '/'))
if(!strchr(fn, '/') || fn[0] != '/')
{
/* The directory is a relative path or a filename. */
char *p;
@ -597,7 +607,10 @@ FILE *ask_and_safe_open(const char* filename, const char* what, const char* mode
umask(0077); /* Disallow everything for group and other */
/* Open it first to keep the inode busy */
if((r = fopen(fn, mode)) == NULL)
r = fopen(fn, mode);
if(!r)
{
fprintf(stderr, _("Error opening file `%s': %s\n"),
fn, strerror(errno));

View file

@ -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.31 2002/09/04 16:26:44 guus Exp $
$Id: connection.c,v 1.1.2.32 2002/09/09 19:39:58 guus Exp $
*/
#include "config.h"
@ -50,41 +50,41 @@ int connection_compare(connection_t *a, connection_t *b)
void init_connections(void)
{
cp
cp();
connection_tree = avl_alloc_tree((avl_compare_t)connection_compare, NULL);
cp
cp();
broadcast = new_connection();
broadcast->name = xstrdup(_("everyone"));
broadcast->hostname = xstrdup(_("BROADCAST"));
cp
cp();
}
void exit_connections(void)
{
cp
cp();
avl_delete_tree(connection_tree);
cp
cp();
free_connection(broadcast);
cp
cp();
}
connection_t *new_connection(void)
{
connection_t *c;
cp
cp();
c = (connection_t *)xmalloc_and_zero(sizeof(connection_t));
if(!c)
return NULL;
gettimeofday(&c->start, NULL);
cp
cp();
return c;
}
void free_connection(connection_t *c)
{
cp
cp();
if(c->hostname)
free(c->hostname);
if(c->inkey)
@ -96,28 +96,28 @@ cp
if(c->hischallenge)
free(c->hischallenge);
free(c);
cp
cp();
}
void connection_add(connection_t *c)
{
cp
cp();
avl_insert(connection_tree, c);
cp
cp();
}
void connection_del(connection_t *c)
{
cp
cp();
avl_delete(connection_tree, c);
cp
cp();
}
void dump_connections(void)
{
avl_node_t *node;
connection_t *c;
cp
cp();
syslog(LOG_DEBUG, _("Connections:"));
for(node = connection_tree->head; node; node = node->next)
@ -128,17 +128,17 @@ cp
}
syslog(LOG_DEBUG, _("End of connections."));
cp
cp();
}
int read_connection_config(connection_t *c)
{
char *fname;
int x;
cp
cp();
asprintf(&fname, "%s/hosts/%s", confbase, c->name);
x = read_config_file(c->config_tree, fname);
free(fname);
cp
cp();
return x;
}

View file

@ -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.14 2002/09/06 12:19:16 guus Exp $
$Id: edge.c,v 1.1.2.15 2002/09/09 19:39:58 guus Exp $
*/
#include "config.h"
@ -67,30 +67,30 @@ int edge_weight_compare(edge_t *a, edge_t *b)
void init_edges(void)
{
cp
cp();
edge_weight_tree = avl_alloc_tree((avl_compare_t)edge_weight_compare, NULL);
cp
cp();
}
avl_tree_t *new_edge_tree(void)
{
cp
cp();
return avl_alloc_tree((avl_compare_t)edge_compare, NULL);
cp
cp();
}
void free_edge_tree(avl_tree_t *edge_tree)
{
cp
cp();
avl_delete_tree(edge_tree);
cp
cp();
}
void exit_edges(void)
{
cp
cp();
avl_delete_tree(edge_weight_tree);
cp
cp();
}
/* Creation and deletion of connection elements */
@ -98,46 +98,46 @@ cp
edge_t *new_edge(void)
{
edge_t *e;
cp
cp();
e = (edge_t *)xmalloc_and_zero(sizeof(*e));
cp
cp();
return e;
}
void free_edge(edge_t *e)
{
cp
cp();
free(e);
cp
cp();
}
void edge_add(edge_t *e)
{
cp
cp();
avl_insert(edge_weight_tree, e);
avl_insert(e->from->edge_tree, e);
cp
cp();
e->reverse = lookup_edge(e->to, e->from);
if(e->reverse)
e->reverse->reverse = e;
cp
cp();
}
void edge_del(edge_t *e)
{
cp
cp();
if(e->reverse)
e->reverse->reverse = NULL;
cp
cp();
avl_delete(edge_weight_tree, e);
avl_delete(e->from->edge_tree, e);
cp
cp();
}
edge_t *lookup_edge(node_t *from, node_t *to)
{
edge_t v;
cp
cp();
v.from = from;
v.to = to;
@ -150,7 +150,7 @@ void dump_edges(void)
node_t *n;
edge_t *e;
char *address;
cp
cp();
syslog(LOG_DEBUG, _("Edges:"));
for(node = node_tree->head; node; node = node->next)
@ -168,5 +168,5 @@ cp
}
syslog(LOG_DEBUG, _("End of edges."));
cp
cp();
}

View file

@ -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.3 2002/06/21 10:11:12 guus Exp $
$Id: event.c,v 1.1.4.4 2002/09/09 19:39:58 guus Exp $
*/
#include "config.h"
@ -49,53 +49,53 @@ int event_compare(event_t *a, event_t *b)
void init_events(void)
{
cp
cp();
event_tree = avl_alloc_tree((avl_compare_t)event_compare, NULL);
cp
cp();
}
void exit_events(void)
{
cp
cp();
avl_delete_tree(event_tree);
cp
cp();
}
event_t *new_event(void)
{
event_t *event;
cp
cp();
event = (event_t *)xmalloc_and_zero(sizeof(*event));
cp
cp();
return event;
}
void free_event(event_t *event)
{
cp
cp();
free(event);
cp
cp();
}
void event_add(event_t *event)
{
cp
cp();
event->id = ++id;
avl_insert(event_tree, event);
cp
cp();
}
void event_del(event_t *event)
{
cp
cp();
avl_delete(event_tree, event);
cp
cp();
}
event_t *get_expired_event(void)
{
event_t *event;
cp
cp();
if(event_tree->head)
{
event = (event_t *)event_tree->head->data;
@ -105,6 +105,6 @@ cp
return event;
}
}
cp
cp();
return NULL;
}

View file

@ -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: graph.c,v 1.1.2.17 2002/09/06 21:02:36 guus Exp $
$Id: graph.c,v 1.1.2.18 2002/09/09 19:39:58 guus Exp $
*/
/* We need to generate two trees from the graph:
@ -269,9 +269,9 @@ void sssp_bfs(void)
n->status.validkey = 0;
n->status.waitingforkey = 0;
asprintf(&envp[0], "NETNAME=%s", netname?netname:"");
asprintf(&envp[1], "DEVICE=%s", device?device:"");
asprintf(&envp[2], "INTERFACE=%s", interface?interface:"");
asprintf(&envp[0], "NETNAME=%s", netname?:"");
asprintf(&envp[1], "DEVICE=%s", device?:"");
asprintf(&envp[2], "INTERFACE=%s", interface?:"");
asprintf(&envp[3], "NODE=%s", n->name);
sockaddr2str(&n->address, &address, &port);
asprintf(&envp[4], "REMOTEADDRESS=%s", address);

View file

@ -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: device.c,v 1.1.2.9 2002/06/21 10:11:36 guus Exp $
$Id: device.c,v 1.1.2.10 2002/09/09 19:40:12 guus Exp $
*/
#include "config.h"
@ -84,7 +84,9 @@ cp
interface = rindex(device, '/')?rindex(device, '/')+1:device;
#endif
cp
if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0)
device_fd = open(device, O_RDWR | O_NONBLOCK);
if(device_fd < 0)
{
syslog(LOG_ERR, _("Could not open %s: %s"), device, strerror(errno));
return -1;
@ -154,7 +156,9 @@ int read_packet(vpn_packet_t *packet)
cp
if(device_type == DEVICE_TYPE_TUNTAP)
{
if((lenin = read(device_fd, packet->data, MTU)) <= 0)
lenin = read(device_fd, packet->data, MTU);
if(lenin <= 0)
{
syslog(LOG_ERR, _("Error while reading from %s %s: %s"), device_info, device, strerror(errno));
return -1;
@ -164,7 +168,9 @@ cp
}
else /* ethertap */
{
if((lenin = read(device_fd, packet->data - 2, MTU + 2)) <= 0)
lenin = read(device_fd, packet->data - 2, MTU + 2);
if(lenin <= 0)
{
syslog(LOG_ERR, _("Error while reading from %s %s: %s"), device_info, device, strerror(errno));
return -1;

View file

@ -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: meta.c,v 1.1.2.27 2002/09/04 16:26:44 guus Exp $
$Id: meta.c,v 1.1.2.28 2002/09/09 19:39:58 guus Exp $
*/
#include "config.h"
@ -44,7 +44,7 @@ int send_meta(connection_t *c, char *buffer, int length)
char *bufp;
int outlen;
char outbuf[MAXBUFSIZE];
cp
cp();
if(debug_lvl >= DEBUG_META)
syslog(LOG_DEBUG, _("Sending %d bytes of metadata to %s (%s)"), length,
c->name, c->hostname);
@ -63,7 +63,7 @@ cp
syslog(LOG_ERR, _("Sending meta data to %s (%s) failed: %s"), c->name, c->hostname, strerror(errno));
return -1;
}
cp
cp();
return 0;
}
@ -71,14 +71,14 @@ void broadcast_meta(connection_t *from, char *buffer, int length)
{
avl_node_t *node;
connection_t *c;
cp
cp();
for(node = connection_tree->head; node; node = node->next)
{
c = (connection_t *)node->data;
if(c != from && c->status.active)
send_meta(c, buffer, length);
}
cp
cp();
}
int receive_meta(connection_t *c)
@ -88,7 +88,7 @@ int receive_meta(connection_t *c)
int lenin, reqlen;
int decrypted = 0;
char inbuf[MAXBUFSIZE];
cp
cp();
if(getsockopt(c->socket, SOL_SOCKET, SO_ERROR, &x, &l) < 0)
{
syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%s %s (%s)"), __FILE__, __LINE__, c->socket, strerror(errno),
@ -206,6 +206,6 @@ cp
}
c->last_ping_time = now;
cp
cp();
return 0;
}

View file

@ -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.c,v 1.35.4.178 2002/09/06 21:22:35 guus Exp $
$Id: net.c,v 1.35.4.179 2002/09/09 19:39:58 guus Exp $
*/
#include "config.h"
@ -91,7 +91,7 @@ void purge(void)
node_t *n;
edge_t *e;
subnet_t *s;
cp
cp();
if(debug_lvl >= DEBUG_PROTOCOL)
syslog(LOG_DEBUG, _("Purging unreachable nodes"));
@ -124,7 +124,7 @@ cp
node_del(n);
}
}
cp
cp();
}
/*
@ -136,7 +136,7 @@ void build_fdset(fd_set *fs)
avl_node_t *node, *next;
connection_t *c;
int i;
cp
cp();
FD_ZERO(fs);
for(node = connection_tree->head; node; node = next)
@ -161,7 +161,7 @@ cp
}
FD_SET(device_fd, fs);
cp
cp();
}
/*
@ -173,7 +173,7 @@ cp
*/
void terminate_connection(connection_t *c, int report)
{
cp
cp();
if(c->status.remove)
return;
@ -209,7 +209,7 @@ cp
retry_outgoing(c->outgoing);
c->outgoing = NULL;
}
cp
cp();
}
/*
@ -224,7 +224,7 @@ void check_dead_connections(void)
{
avl_node_t *node, *next;
connection_t *c;
cp
cp();
for(node = connection_tree->head; node; node = next)
{
next = node->next;
@ -261,7 +261,7 @@ cp
}
}
}
cp
cp();
}
/*
@ -275,7 +275,7 @@ void check_network_activity(fd_set *f)
int result, i;
int len = sizeof(result);
vpn_packet_t packet;
cp
cp();
if(FD_ISSET(device_fd, f))
{
if(!read_packet(&packet))
@ -321,7 +321,7 @@ cp
if(FD_ISSET(listen_socket[i].tcp, f))
handle_new_meta_connection(listen_socket[i].tcp);
}
cp
cp();
}
/*
@ -334,7 +334,7 @@ void main_loop(void)
int r;
time_t last_ping_check;
event_t *event;
cp
cp();
last_ping_check = now;
srand(now);
@ -348,7 +348,9 @@ cp
build_fdset(&fset);
if((r = select(FD_SETSIZE, &fset, NULL, NULL, &tv)) < 0)
r = select(FD_SETSIZE, &fset, NULL, NULL, &tv);
if(r < 0)
{
if(errno != EINTR && errno != EAGAIN)
{
@ -437,5 +439,5 @@ cp
continue;
}
}
cp
cp();
}

View file

@ -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.20 2002/09/06 10:23:52 guus Exp $
$Id: net_packet.c,v 1.1.2.21 2002/09/09 19:39:58 guus Exp $
*/
#include "config.h"
@ -95,7 +95,7 @@ void receive_udppacket(node_t *n, vpn_packet_t *inpkt)
long int complen = MTU + 12;
EVP_CIPHER_CTX ctx;
char hmac[EVP_MAX_MD_SIZE];
cp
cp();
/* Check the message authentication code */
if(myself->digest && myself->maclength)
@ -158,28 +158,28 @@ cp
}
receive_packet(n, inpkt);
cp
cp();
}
void receive_tcppacket(connection_t *c, char *buffer, int len)
{
vpn_packet_t outpkt;
cp
cp();
outpkt.len = len;
memcpy(outpkt.data, buffer, len);
receive_packet(c->node, &outpkt);
cp
cp();
}
void receive_packet(node_t *n, vpn_packet_t *packet)
{
cp
cp();
if(debug_lvl >= DEBUG_TRAFFIC)
syslog(LOG_DEBUG, _("Received packet of %d bytes from %s (%s)"), packet->len, n->name, n->hostname);
route_incoming(n, packet);
cp
cp();
}
void send_udppacket(node_t *n, vpn_packet_t *inpkt)
@ -196,7 +196,7 @@ void send_udppacket(node_t *n, vpn_packet_t *inpkt)
static int priority = 0;
int origpriority;
int sock;
cp
cp();
/* Make sure we have a valid key */
if(!n->status.validkey)
@ -300,7 +300,7 @@ cp
}
inpkt->len = origlen;
cp
cp();
}
/*
@ -309,7 +309,7 @@ cp
void send_packet(node_t *n, vpn_packet_t *packet)
{
node_t *via;
cp
cp();
if(debug_lvl >= DEBUG_TRAFFIC)
syslog(LOG_ERR, _("Sending packet of %d bytes to %s (%s)"),
packet->len, n->name, n->hostname);
@ -353,7 +353,7 @@ void broadcast_packet(node_t *from, vpn_packet_t *packet)
{
avl_node_t *node;
connection_t *c;
cp
cp();
if(debug_lvl >= DEBUG_TRAFFIC)
syslog(LOG_INFO, _("Broadcasting packet of %d bytes from %s (%s)"),
packet->len, from->name, from->hostname);
@ -364,13 +364,13 @@ cp
if(c->status.active && c->status.mst && c != from->nexthop->connection)
send_packet(c->node, packet);
}
cp
cp();
}
void flush_queue(node_t *n)
{
list_node_t *node, *next;
cp
cp();
if(debug_lvl >= DEBUG_TRAFFIC)
syslog(LOG_INFO, _("Flushing queue for %s (%s)"), n->name, n->hostname);
@ -380,7 +380,7 @@ cp
send_udppacket(n, (vpn_packet_t *)node->data);
list_delete_node(n->queue, node);
}
cp
cp();
}
void handle_incoming_vpn_data(int sock)
@ -391,7 +391,7 @@ void handle_incoming_vpn_data(int sock)
sockaddr_t from;
socklen_t fromlen = sizeof(from);
node_t *n;
cp
cp();
if(getsockopt(sock, SOL_SOCKET, SO_ERROR, &x, &l) < 0)
{
syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%s"),
@ -405,7 +405,9 @@ cp
return;
}
if((pkt.len = recvfrom(sock, (char *)&pkt.seqno, MAXSIZE, 0, &from.sa, &fromlen)) <= 0)
pkt.len = recvfrom(sock, (char *)&pkt.seqno, MAXSIZE, 0, &from.sa, &fromlen);
if(pkt.len <= 0)
{
syslog(LOG_ERR, _("Receiving packet failed: %s"), strerror(errno));
return;
@ -427,5 +429,5 @@ cp
n->connection->last_ping_time = now;
receive_udppacket(n, &pkt);
cp
cp();
}

View file

@ -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_setup.c,v 1.1.2.23 2002/09/04 13:48:52 guus Exp $
$Id: net_setup.c,v 1.1.2.24 2002/09/09 19:39:58 guus Exp $
*/
#include "config.h"
@ -82,7 +82,7 @@ int read_rsa_public_key(connection_t *c)
FILE *fp;
char *fname;
char *key;
cp
cp();
if(!c->rsa_key)
c->rsa_key = RSA_new();
@ -102,7 +102,8 @@ cp
{
if(is_safe_path(fname))
{
if((fp = fopen(fname, "r")) == NULL)
fp = fopen(fname, "r");
if(!fp)
{
syslog(LOG_ERR, _("Error reading RSA public key file `%s': %s"),
fname, strerror(errno));
@ -116,7 +117,8 @@ cp
return 0; /* Woohoo. */
/* If it fails, try PEM_read_RSA_PUBKEY. */
if((fp = fopen(fname, "r")) == NULL)
fp = fopen(fname, "r");
if(!fp)
{
syslog(LOG_ERR, _("Error reading RSA public key file `%s': %s"),
fname, strerror(errno));
@ -143,7 +145,9 @@ cp
/* Else, check if a harnessed public key is in the config file */
asprintf(&fname, "%s/hosts/%s", confbase, c->name);
if((fp = fopen(fname, "r")))
fp = fopen(fname, "r");
if(fp)
{
c->rsa_key = PEM_read_RSAPublicKey(fp, &c->rsa_key, NULL, NULL);
fclose(fp);
@ -157,7 +161,9 @@ cp
/* Try again with PEM_read_RSA_PUBKEY. */
asprintf(&fname, "%s/hosts/%s", confbase, c->name);
if((fp = fopen(fname, "r")))
fp = fopen(fname, "r");
if(fp)
{
c->rsa_key = PEM_read_RSA_PUBKEY(fp, &c->rsa_key, NULL, NULL);
fclose(fp);
@ -176,7 +182,7 @@ int read_rsa_private_key(void)
{
FILE *fp;
char *fname, *key;
cp
cp();
if(get_config_string(lookup_config(config_tree, "PrivateKey"), &key))
{
myself->connection->rsa_key = RSA_new();
@ -191,7 +197,8 @@ cp
if(is_safe_path(fname))
{
if((fp = fopen(fname, "r")) == NULL)
fp = fopen(fname, "r");
if(!fp)
{
syslog(LOG_ERR, _("Error reading RSA private key file `%s': %s"),
fname, strerror(errno));
@ -225,7 +232,7 @@ int setup_myself(void)
char *address = NULL;
struct addrinfo hint, *ai, *aip;
int choice, err;
cp
cp();
myself = new_node();
myself->connection = new_connection();
init_configuration(&myself->connection->config_tree);
@ -252,7 +259,7 @@ cp
myself->name = name;
myself->connection->name = xstrdup(name);
cp
cp();
if(read_rsa_private_key())
return -1;
@ -264,7 +271,7 @@ cp
if(read_rsa_public_key(myself->connection))
return -1;
cp
cp();
if(!get_config_string(lookup_config(myself->connection->config_tree, "Port"), &myport))
asprintf(&myport, "655");
@ -283,7 +290,7 @@ cp
cfg = lookup_config_next(myself->connection->config_tree, cfg);
}
cp
cp();
/* Check some options */
if(get_config_bool(lookup_config(config_tree, "IndirectData"), &choice))
@ -362,7 +369,7 @@ cp
addressfamily = AF_INET;
get_config_bool(lookup_config(config_tree, "Hostnames"), &hostnames);
cp
cp();
/* Generate packet encryption key */
if(get_config_string(lookup_config(myself->connection->config_tree, "Cipher"), &cipher))
@ -373,7 +380,9 @@ cp
}
else
{
if(!(myself->cipher = EVP_get_cipherbyname(cipher)))
myself->cipher = EVP_get_cipherbyname(cipher);
if(!myself->cipher)
{
syslog(LOG_ERR, _("Unrecognized cipher type!"));
return -1;
@ -408,7 +417,9 @@ cp
}
else
{
if(!(myself->digest = EVP_get_digestbyname(digest)))
myself->digest = EVP_get_digestbyname(digest);
if(!myself->digest)
{
syslog(LOG_ERR, _("Unrecognized digest type!"));
return -1;
@ -455,7 +466,7 @@ cp
myself->compression = 0;
myself->connection->outcompression = 0;
cp
cp();
/* Done */
myself->nexthop = myself;
@ -466,7 +477,7 @@ cp
graph();
cp
cp();
/* Open sockets */
memset(&hint, 0, sizeof(hint));
@ -478,7 +489,9 @@ cp
hint.ai_protocol = IPPROTO_TCP;
hint.ai_flags = AI_PASSIVE;
if((err = getaddrinfo(address, myport, &hint, &ai)) || !ai)
err = getaddrinfo(address, myport, &hint, &ai);
if(err || !ai)
{
syslog(LOG_ERR, _("System call `%s' failed: %s"), "getaddrinfo", gai_strerror(err));
return -1;
@ -488,10 +501,14 @@ cp
for(aip = ai; aip; aip = aip->ai_next)
{
if((listen_socket[listen_sockets].tcp = setup_listen_socket((sockaddr_t *)aip->ai_addr)) < 0)
listen_socket[listen_sockets].tcp = setup_listen_socket((sockaddr_t *)aip->ai_addr);
if(listen_socket[listen_sockets].tcp < 0)
continue;
if((listen_socket[listen_sockets].udp = setup_vpn_in_socket((sockaddr_t *)aip->ai_addr)) < 0)
listen_socket[listen_sockets].udp = setup_vpn_in_socket((sockaddr_t *)aip->ai_addr);
if(listen_socket[listen_sockets].udp < 0)
continue;
if(debug_lvl >= DEBUG_CONNECTIONS)
@ -514,7 +531,7 @@ cp
syslog(LOG_ERR, _("Unable to create any listening socket!"));
return -1;
}
cp
cp();
return 0;
}
@ -525,7 +542,7 @@ int setup_network_connections(void)
{
char *envp[4];
int i;
cp
cp();
now = time(NULL);
init_connections();
@ -549,9 +566,9 @@ cp
return -1;
/* Run tinc-up script to further initialize the tap interface */
asprintf(&envp[0], "NETNAME=%s", netname?netname:"");
asprintf(&envp[1], "DEVICE=%s", device?device:"");
asprintf(&envp[2], "INTERFACE=%s", interface?interface:"");
asprintf(&envp[0], "NETNAME=%s", netname?:"");
asprintf(&envp[1], "DEVICE=%s", device?:"");
asprintf(&envp[2], "INTERFACE=%s", interface?:"");
envp[3] = NULL;
execute_script("tinc-up", envp);
@ -563,7 +580,7 @@ cp
return -1;
try_outgoing_connections();
cp
cp();
return 0;
}
@ -576,7 +593,7 @@ void close_network_connections(void)
connection_t *c;
char *envp[4];
int i;
cp
cp();
for(node = connection_tree->head; node; node = next)
{
next = node->next;
@ -602,9 +619,9 @@ cp
exit_nodes();
exit_connections();
asprintf(&envp[0], "NETNAME=%s", netname?netname:"");
asprintf(&envp[1], "DEVICE=%s", device?device:"");
asprintf(&envp[2], "INTERFACE=%s", interface?interface:"");
asprintf(&envp[0], "NETNAME=%s", netname?:"");
asprintf(&envp[1], "DEVICE=%s", device?:"");
asprintf(&envp[2], "INTERFACE=%s", interface?:"");
envp[3] = NULL;
execute_script("tinc-down", envp);
@ -613,6 +630,6 @@ cp
free(envp[i]);
close_device();
cp
cp();
return;
}

View file

@ -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.18 2002/09/04 13:48:52 guus Exp $
$Id: net_socket.c,v 1.1.2.19 2002/09/09 19:39:59 guus Exp $
*/
#include "config.h"
@ -93,8 +93,10 @@ int setup_listen_socket(sockaddr_t *sa)
char *interface;
struct ifreq ifr;
#endif
cp
if((nfd = socket(sa->sa.sa_family, SOCK_STREAM, IPPROTO_TCP)) < 0)
cp();
nfd = socket(sa->sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
if(nfd < 0)
{
syslog(LOG_ERR, _("Creating metasocket failed: %s"), strerror(errno));
return -1;
@ -153,7 +155,7 @@ cp
syslog(LOG_ERR, _("System call `%s' failed: %s"), "listen", strerror(errno));
return -1;
}
cp
cp();
return nfd;
}
@ -166,8 +168,10 @@ int setup_vpn_in_socket(sockaddr_t *sa)
char *interface;
struct ifreq ifr;
#endif
cp
if((nfd = socket(sa->sa.sa_family, SOCK_DGRAM, IPPROTO_UDP)) < 0)
cp();
nfd = socket(sa->sa.sa_family, SOCK_DGRAM, IPPROTO_UDP);
if(nfd < 0)
{
syslog(LOG_ERR, _("Creating UDP socket failed: %s"), strerror(errno));
return -1;
@ -206,14 +210,14 @@ cp
free(addrstr);
return -1;
}
cp
cp();
return nfd;
}
void retry_outgoing(outgoing_t *outgoing)
{
event_t *event;
cp
cp();
outgoing->timeout += 5;
if(outgoing->timeout > maxtimeout)
outgoing->timeout = maxtimeout;
@ -226,13 +230,13 @@ cp
if(debug_lvl >= DEBUG_CONNECTIONS)
syslog(LOG_NOTICE, _("Trying to re-establish outgoing connection in %d seconds"), outgoing->timeout);
cp
cp();
}
int setup_outgoing_socket(connection_t *c)
{
int option;
cp
cp();
if(debug_lvl >= DEBUG_CONNECTIONS)
syslog(LOG_INFO, _("Trying to connect to %s (%s)"), c->name, c->hostname);
@ -267,28 +271,28 @@ cp
if(debug_lvl >= DEBUG_CONNECTIONS)
syslog(LOG_INFO, _("Connected to %s (%s)"), c->name, c->hostname);
cp
cp();
return 0;
}
void finish_connecting(connection_t *c)
{
cp
cp();
if(debug_lvl >= DEBUG_CONNECTIONS)
syslog(LOG_INFO, _("Connected to %s (%s)"), c->name, c->hostname);
c->last_ping_time = now;
send_id(c);
cp
cp();
}
void do_outgoing_connection(connection_t *c)
{
char *address, *port;
int option, result, flags;
cp
cp();
begin:
if(!c->outgoing->ai)
{
@ -385,14 +389,14 @@ begin:
finish_connecting(c);
return;
cp
cp();
}
void setup_outgoing_connection(outgoing_t *outgoing)
{
connection_t *c;
node_t *n;
cp
cp();
n = lookup_node(outgoing->name);
if(n)
@ -442,8 +446,10 @@ int handle_new_meta_connection(int sock)
connection_t *c;
sockaddr_t sa;
int fd, len = sizeof(sa);
cp
if((fd = accept(sock, &sa.sa, &len)) < 0)
cp();
fd = accept(sock, &sa.sa, &len);
if(fd < 0)
{
syslog(LOG_ERR, _("Accepting a new connection failed: %s"), strerror(errno));
return -1;
@ -469,7 +475,7 @@ cp
c->allow_request = ID;
send_id(c);
cp
cp();
return 0;
}
@ -478,7 +484,7 @@ void try_outgoing_connections(void)
static config_t *cfg = NULL;
char *name;
outgoing_t *outgoing;
cp
cp();
for(cfg = lookup_config(config_tree, "ConnectTo"); cfg; cfg = lookup_config_next(config_tree, cfg))
{
get_config_string(cfg, &name);

View file

@ -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.41 2002/06/21 17:49:48 guus Exp $
$Id: netutl.c,v 1.12.4.42 2002/09/09 19:39:59 guus Exp $
*/
#include "config.h"
@ -56,13 +56,15 @@ struct addrinfo *str2addrinfo(char *address, char *service, int socktype)
{
struct addrinfo hint, *ai;
int err;
cp
cp();
memset(&hint, 0, sizeof(hint));
hint.ai_family = addressfamily;
hint.ai_socktype = socktype;
if((err = getaddrinfo(address, service, &hint, &ai)))
err = getaddrinfo(address, service, &hint, &ai);
if(err)
{
if(debug_lvl >= DEBUG_ERROR)
syslog(LOG_WARNING, _("Error looking up %s port %s: %s\n"), address, service, gai_strerror(err));
@ -70,7 +72,7 @@ cp
return NULL;
}
cp
cp();
return ai;
}
@ -79,14 +81,16 @@ sockaddr_t str2sockaddr(char *address, char *port)
struct addrinfo hint, *ai;
sockaddr_t result;
int err;
cp
cp();
memset(&hint, 0, sizeof(hint));
hint.ai_family = AF_UNSPEC;
hint.ai_flags = AI_NUMERICHOST;
hint.ai_socktype = SOCK_STREAM;
if((err = getaddrinfo(address, port, &hint, &ai) || !ai))
err = getaddrinfo(address, port, &hint, &ai);
if(err || !ai)
{
syslog(LOG_ERR, _("Error looking up %s port %s: %s\n"), address, port, gai_strerror(err));
cp_trace();
@ -96,7 +100,7 @@ cp
result = *(sockaddr_t *)ai->ai_addr;
freeaddrinfo(ai);
cp
cp();
return result;
}
@ -106,8 +110,10 @@ void sockaddr2str(sockaddr_t *sa, char **addrstr, char **portstr)
char port[NI_MAXSERV];
char *scopeid;
int err;
cp
if((err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof(port), NI_NUMERICHOST|NI_NUMERICSERV)))
cp();
err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof(port), NI_NUMERICHOST|NI_NUMERICSERV);
if(err)
{
syslog(LOG_ERR, _("Error while translating addresses: %s"), gai_strerror(err));
cp_trace();
@ -115,12 +121,14 @@ cp
exit(0);
}
if((scopeid = strchr(address, '%')))
scopeid = strchr(address, '%');
if(scopeid)
*scopeid = '\0'; /* Descope. */
*addrstr = xstrdup(address);
*portstr = xstrdup(port);
cp
cp();
}
char *sockaddr2hostname(sockaddr_t *sa)
@ -129,21 +137,22 @@ char *sockaddr2hostname(sockaddr_t *sa)
char address[NI_MAXHOST] = "unknown";
char port[NI_MAXSERV] = "unknown";
int err;
cp
if((err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof(port), hostnames?0:(NI_NUMERICHOST|NI_NUMERICSERV))))
cp();
err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof(port), hostnames?0:(NI_NUMERICHOST|NI_NUMERICSERV));
if(err)
{
syslog(LOG_ERR, _("Error while looking up hostname: %s"), gai_strerror(err));
}
asprintf(&str, _("%s port %s"), address, port);
cp
cp();
return str;
}
int sockaddrcmp(sockaddr_t *a, sockaddr_t *b)
{
int result;
cp
cp();
result = a->sa.sa_family - b->sa.sa_family;
if(result)
@ -169,7 +178,7 @@ cp
raise(SIGFPE);
exit(0);
}
cp
cp();
}
void sockaddrunmap(sockaddr_t *sa)
@ -188,11 +197,14 @@ int maskcmp(void *va, void *vb, int masklen, int len)
int i, m, result;
char *a = va;
char *b = vb;
cp
cp();
for(m = masklen, i = 0; m >= 8; m -= 8, i++)
if((result = a[i] - b[i]))
return result;
{
result = a[i] - b[i];
if(result)
return result;
}
if(m)
return (a[i] & (0x100 - (1 << (8 - m)))) - (b[i] & (0x100 - (1 << (8 - m))));
@ -203,7 +215,7 @@ void mask(void *va, int masklen, int len)
{
int i;
char *a = va;
cp
cp();
i = masklen / 8;
masklen %= 8;
@ -219,7 +231,7 @@ void maskcpy(void *va, void *vb, int masklen, int len)
int i, m;
char *a = va;
char *b = vb;
cp
cp();
for(m = masklen, i = 0; m >= 8; m -= 8, i++)
a[i] = b[i];
@ -237,7 +249,7 @@ int maskcheck(void *va, int masklen, int len)
{
int i;
char *a = va;
cp
cp();
i = masklen / 8;
masklen %= 8;

View file

@ -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.15 2002/09/04 13:48:52 guus Exp $
$Id: node.c,v 1.1.2.16 2002/09/09 19:39:59 guus Exp $
*/
#include "config.h"
@ -47,7 +47,7 @@ int node_compare(node_t *a, node_t *b)
int node_udp_compare(node_t *a, node_t *b)
{
int result;
cp
cp();
result = sockaddrcmp(&a->address, &b->address);
if(result)
@ -58,34 +58,34 @@ cp
void init_nodes(void)
{
cp
cp();
node_tree = avl_alloc_tree((avl_compare_t)node_compare, NULL);
node_udp_tree = avl_alloc_tree((avl_compare_t)node_udp_compare, NULL);
cp
cp();
}
void exit_nodes(void)
{
cp
cp();
avl_delete_tree(node_tree);
avl_delete_tree(node_udp_tree);
cp
cp();
}
node_t *new_node(void)
{
node_t *n = (node_t *)xmalloc_and_zero(sizeof(*n));
cp
cp();
n->subnet_tree = new_subnet_tree();
n->edge_tree = new_edge_tree();
n->queue = list_alloc((list_action_t)free);
cp
cp();
return n;
}
void free_node(node_t *n)
{
cp
cp();
if(n->queue)
list_delete_list(n->queue);
if(n->name)
@ -99,15 +99,15 @@ cp
if(n->edge_tree)
free_edge_tree(n->edge_tree);
free(n);
cp
cp();
}
void node_add(node_t *n)
{
cp
cp();
avl_insert(node_tree, n);
avl_insert(node_udp_tree, n);
cp
cp();
}
void node_del(node_t *n)
@ -115,7 +115,7 @@ void node_del(node_t *n)
avl_node_t *node, *next;
edge_t *e;
subnet_t *s;
cp
cp();
for(node = n->subnet_tree->head; node; node = next)
{
next = node->next;
@ -129,16 +129,16 @@ cp
e = (edge_t *)node->data;
edge_del(e);
}
cp
cp();
avl_delete(node_tree, n);
avl_delete(node_udp_tree, n);
cp
cp();
}
node_t *lookup_node(char *name)
{
node_t n;
cp
cp();
n.name = name;
return avl_search(node_tree, &n);
}
@ -146,7 +146,7 @@ cp
node_t *lookup_node_udp(sockaddr_t *sa)
{
node_t n;
cp
cp();
n.address = *sa;
n.name = NULL;
@ -157,7 +157,7 @@ void dump_nodes(void)
{
avl_node_t *node;
node_t *n;
cp
cp();
syslog(LOG_DEBUG, _("Nodes:"));
for(node = node_tree->head; node; node = node->next)
@ -169,5 +169,5 @@ cp
}
syslog(LOG_DEBUG, _("End of nodes."));
cp
cp();
}

View file

@ -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: process.c,v 1.1.2.44 2002/09/04 14:17:28 guus Exp $
$Id: process.c,v 1.1.2.45 2002/09/09 19:39:59 guus Exp $
*/
#include "config.h"
@ -91,7 +91,7 @@ int fcloseall(void)
*/
void cleanup_and_exit(int c)
{
cp
cp();
close_network_connections();
if(debug_lvl > DEBUG_NOTHING)
@ -109,8 +109,10 @@ cp
int write_pidfile(void)
{
int pid;
cp
if((pid = check_pid(pidfilename)))
cp();
pid = check_pid(pidfilename);
if(pid)
{
if(netname)
fprintf(stderr, _("A tincd is already running for net `%s' with pid %d.\n"),
@ -123,7 +125,7 @@ cp
/* if it's locked, write-protected, or whatever */
if(!write_pid(pidfilename))
return 1;
cp
cp();
return 0;
}
@ -133,8 +135,10 @@ cp
int kill_other(int signal)
{
int pid;
cp
if(!(pid = read_pid(pidfilename)))
cp();
pid = read_pid(pidfilename);
if(!pid)
{
if(netname)
fprintf(stderr, _("No other tincd is running for net `%s'.\n"), netname);
@ -155,7 +159,7 @@ cp
fprintf(stderr, _("Removing stale lock file.\n"));
remove_pid(pidfilename);
}
cp
cp();
return 0;
}
@ -164,7 +168,7 @@ cp
*/
int detach(void)
{
cp
cp();
setup_signals();
/* First check if we can open a fresh new pidfile */
@ -199,7 +203,7 @@ cp
syslog(LOG_NOTICE, _("tincd %s starting"), VERSION);
xalloc_fail_func = memory_full;
cp
cp();
return 0;
}
@ -211,7 +215,7 @@ void _execute_script(const char *scriptname, char **envp) __attribute__ ((noret
void _execute_script(const char *scriptname, char **envp)
{
char *s;
cp
cp();
while(*envp)
putenv(*envp++);
@ -238,7 +242,7 @@ int execute_script(const char *name, char **envp)
int status;
struct stat s;
char *scriptname;
cp
cp();
asprintf(&scriptname, "%s/%s", confbase, name);
/* First check if there is a script */
@ -246,7 +250,9 @@ cp
if(stat(scriptname, &s))
return 0;
if((pid = fork()) < 0)
pid = fork();
if(pid < 0)
{
syslog(LOG_ERR, _("System call `%s' failed: %s"), "fork", strerror(errno));
return -1;
@ -289,7 +295,7 @@ cp
return -1;
}
}
cp
cp();
/* Child here */
_execute_script(scriptname, envp);

View file

@ -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.134 2002/09/04 19:57:53 guus Exp $
$Id: protocol.c,v 1.28.4.135 2002/09/09 19:39:59 guus Exp $
*/
#include "config.h"
@ -63,7 +63,7 @@ int send_request(connection_t *c, const char *format, ...)
char buffer[MAXBUFSIZE];
int len, request;
cp
cp();
/* Use vsnprintf instead of vasprintf: faster, no memory
fragmentation, cleanup is automatic, and there is a limit on the
input buffer anyway */
@ -88,7 +88,7 @@ cp
}
buffer[len++] = '\n';
cp
cp();
if(c == broadcast)
return broadcast_meta(NULL, buffer, len);
else
@ -98,7 +98,7 @@ cp
int forward_request(connection_t *from)
{
int request;
cp
cp();
if(debug_lvl >= DEBUG_PROTOCOL)
{
sscanf(from->buffer, "%d", &request);
@ -109,17 +109,17 @@ cp
}
from->buffer[from->reqlen - 1] = '\n';
cp
cp();
return broadcast_meta(from, from->buffer, from->reqlen);
}
int receive_request(connection_t *c)
{
int request;
cp
cp();
if(sscanf(c->buffer, "%d", &request) == 1)
{
if((request < 0) || (request >= LAST) || (request_handlers[request] == NULL))
if((request < 0) || (request >= LAST) || !request_handlers[request])
{
if(debug_lvl >= DEBUG_META)
syslog(LOG_DEBUG, _("Unknown request from %s (%s): %s"),
@ -163,43 +163,43 @@ cp
c->name, c->hostname);
return -1;
}
cp
cp();
return 0;
}
int past_request_compare(past_request_t *a, past_request_t *b)
{
cp
cp();
return strcmp(a->request, b->request);
}
void free_past_request(past_request_t *r)
{
cp
cp();
if(r->request)
free(r->request);
free(r);
cp
cp();
}
void init_requests(void)
{
cp
cp();
past_request_tree = avl_alloc_tree((avl_compare_t)past_request_compare, (avl_action_t)free_past_request);
cp
cp();
}
void exit_requests(void)
{
cp
cp();
avl_delete_tree(past_request_tree);
cp
cp();
}
int seen_request(char *request)
{
past_request_t p, *new;
cp
cp();
p.request = request;
if(avl_search(past_request_tree, &p))
@ -216,7 +216,7 @@ cp
avl_insert(past_request_tree, new);
return 0;
}
cp
cp();
}
void age_past_requests(void)
@ -224,7 +224,7 @@ void age_past_requests(void)
avl_node_t *node, *next;
past_request_t *p;
int left = 0, deleted = 0;
cp
cp();
for(node = past_request_tree->head; node; node = next)
{
next = node->next;
@ -237,7 +237,7 @@ cp
if(debug_lvl >= DEBUG_SCARY_THINGS && left + deleted)
syslog(LOG_DEBUG, _("Aging past requests: deleted %d, left %d\n"), deleted, left);
cp
cp();
}
/* Jumptable for the request handlers */

View file

@ -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_auth.c,v 1.1.4.14 2002/09/04 16:26:45 guus Exp $
$Id: protocol_auth.c,v 1.1.4.15 2002/09/09 19:39:59 guus Exp $
*/
#include "config.h"
@ -55,7 +55,7 @@
int send_id(connection_t *c)
{
cp
cp();
return send_request(c, "%d %s %d", ID, myself->connection->name, myself->connection->protocol_version);
}
@ -63,7 +63,7 @@ int id_h(connection_t *c)
{
char name[MAX_STRING_SIZE];
int bla;
cp
cp();
if(sscanf(c->buffer, "%*d "MAX_STRING" %d", name, &c->protocol_version) != 2)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ID", c->name, c->hostname);
@ -112,7 +112,9 @@ cp
{
init_configuration(&c->config_tree);
if((bla = read_connection_config(c)))
bla = read_connection_config(c);
if(bla)
{
syslog(LOG_ERR, _("Peer %s had unknown identity (%s)"), c->hostname, c->name);
return -1;
@ -133,7 +135,7 @@ cp
c->options |= OPTION_TCPONLY | OPTION_INDIRECT;
c->allow_request = METAKEY;
cp
cp();
return send_metakey(c);
}
@ -141,7 +143,7 @@ int send_metakey(connection_t *c)
{
char buffer[MAX_STRING_SIZE];
int len, x;
cp
cp();
len = RSA_size(c->rsa_key);
/* Allocate buffers for the meta key */
@ -151,7 +153,7 @@ cp
if(!c->outctx)
c->outctx = xmalloc(sizeof(*c->outctx));
cp
cp();
/* Copy random data to the buffer */
RAND_bytes(c->outkey, len);
@ -187,7 +189,7 @@ cp
syslog(LOG_ERR, _("Error during encryption of meta key for %s (%s)"), c->name, c->hostname);
return -1;
}
cp
cp();
/* Convert the encrypted random data to a hexadecimal formatted string */
bin2hex(buffer, buffer, len);
@ -209,7 +211,7 @@ cp
c->status.encryptout = 1;
}
cp
cp();
return x;
}
@ -218,13 +220,13 @@ int metakey_h(connection_t *c)
char buffer[MAX_STRING_SIZE];
int cipher, digest, maclength, compression;
int len;
cp
cp();
if(sscanf(c->buffer, "%*d %d %d %d %d "MAX_STRING, &cipher, &digest, &maclength, &compression, buffer) != 5)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "METAKEY", c->name, c->hostname);
return -1;
}
cp
cp();
len = RSA_size(myself->connection->rsa_key);
/* Check if the length of the meta key is all right */
@ -236,7 +238,7 @@ cp
}
/* Allocate buffers for the meta key */
cp
cp();
if(!c->inkey)
c->inkey = xmalloc(len);
@ -244,11 +246,11 @@ cp
c->inctx = xmalloc(sizeof(*c->inctx));
/* Convert the challenge from hexadecimal back to binary */
cp
cp();
hex2bin(buffer,buffer,len);
/* Decrypt the meta key */
cp
cp();
if(RSA_private_decrypt(len, buffer, c->inkey, myself->connection->rsa_key, RSA_NO_PADDING) != len) /* See challenge() */
{
syslog(LOG_ERR, _("Error during encryption of meta key for %s (%s)"), c->name, c->hostname);
@ -263,7 +265,7 @@ cp
}
/* All incoming requests will now be encrypted. */
cp
cp();
/* Check and lookup cipher and digest algorithms */
if(cipher)
@ -311,7 +313,7 @@ cp
c->incompression = compression;
c->allow_request = CHALLENGE;
cp
cp();
return send_challenge(c);
}
@ -319,7 +321,7 @@ int send_challenge(connection_t *c)
{
char buffer[MAX_STRING_SIZE];
int len, x;
cp
cp();
/* CHECKME: what is most reasonable value for len? */
len = RSA_size(c->rsa_key);
@ -328,22 +330,22 @@ cp
if(!c->hischallenge)
c->hischallenge = xmalloc(len);
cp
cp();
/* Copy random data to the buffer */
RAND_bytes(c->hischallenge, len);
cp
cp();
/* Convert to hex */
bin2hex(c->hischallenge, buffer, len);
buffer[len*2] = '\0';
cp
cp();
/* Send the challenge */
x = send_request(c, "%d %s", CHALLENGE, buffer);
cp
cp();
return x;
}
@ -351,7 +353,7 @@ int challenge_h(connection_t *c)
{
char buffer[MAX_STRING_SIZE];
int len;
cp
cp();
if(sscanf(c->buffer, "%*d "MAX_STRING, buffer) != 1)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "CHALLENGE", c->name, c->hostname);
@ -380,7 +382,7 @@ cp
c->allow_request = CHAL_REPLY;
/* Rest is done by send_chal_reply() */
cp
cp();
return send_chal_reply(c);
}
@ -388,7 +390,7 @@ int send_chal_reply(connection_t *c)
{
char hash[EVP_MAX_MD_SIZE*2+1];
EVP_MD_CTX ctx;
cp
cp();
/* Calculate the hash from the challenge we received */
EVP_DigestInit(&ctx, c->indigest);
@ -402,7 +404,7 @@ cp
/* Send the reply */
cp
cp();
return send_request(c, "%d %s", CHAL_REPLY, hash);
}
@ -411,7 +413,7 @@ int chal_reply_h(connection_t *c)
char hishash[MAX_STRING_SIZE];
char myhash[EVP_MAX_MD_SIZE];
EVP_MD_CTX ctx;
cp
cp();
if(sscanf(c->buffer, "%*d "MAX_STRING, hishash) != 1)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "CHAL_REPLY", c->name, c->hostname);
@ -455,7 +457,7 @@ cp
*/
c->allow_request = ACK;
cp
cp();
return send_ack(c);
}
@ -466,13 +468,13 @@ int send_ack(connection_t *c)
int x;
struct timeval now;
cp
cp();
/* Estimate weight */
gettimeofday(&now, NULL);
c->estimated_weight = (now.tv_sec - c->start.tv_sec) * 1000 + (now.tv_usec - c->start.tv_usec) / 1000;
x = send_request(c, "%d %s %d %lx", ACK, myport, c->estimated_weight, c->options);
cp
cp();
return x;
}
@ -510,7 +512,7 @@ int ack_h(connection_t *c)
int weight;
long int options;
node_t *n;
cp
cp();
if(sscanf(c->buffer, "%*d "MAX_STRING" %d %lx", hisport, &weight, &options) != 3)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ACK", c->name, c->hostname);
@ -557,7 +559,7 @@ cp
/* Create an edge_t for this connection */
c->edge = new_edge();
cp
cp();
c->edge->from = myself;
c->edge->to = n;
sockaddr2str(&c->address, &hisaddress, &dummy);
@ -567,10 +569,10 @@ cp
c->edge->weight = (weight + c->estimated_weight) / 2;
c->edge->connection = c;
c->edge->options = c->options;
cp
cp();
edge_add(c->edge);
cp
cp();
/* Notify everyone of the new edge */
send_add_edge(broadcast, c->edge);
@ -578,6 +580,6 @@ cp
/* Run MST and SSSP algorithms */
graph();
cp
cp();
return 0;
}

View file

@ -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.10 2002/09/04 16:26:45 guus Exp $
$Id: protocol_edge.c,v 1.1.4.11 2002/09/09 19:40:04 guus Exp $
*/
#include "config.h"
@ -49,14 +49,14 @@ int send_add_edge(connection_t *c, edge_t *e)
{
int x;
char *address, *port;
cp
cp();
sockaddr2str(&e->address, &address, &port);
x = send_request(c, "%d %lx %s %s %s %s %lx %d", ADD_EDGE, random(),
e->from->name, e->to->name, address, port,
e->options, e->weight);
free(address);
free(port);
cp
cp();
return x;
}
@ -71,7 +71,7 @@ int add_edge_h(connection_t *c)
sockaddr_t address;
long int options;
int weight;
cp
cp();
if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %lx %d",
from_name, to_name, to_address, to_port, &options, &weight) != 6)
{
@ -172,13 +172,13 @@ cp
/* Run MST before or after we tell the rest? */
graph();
cp
cp();
return 0;
}
int send_del_edge(connection_t *c, edge_t *e)
{
cp
cp();
return send_request(c, "%d %lx %s %s", DEL_EDGE, random(),
e->from->name, e->to->name);
}
@ -189,7 +189,7 @@ int del_edge_h(connection_t *c)
char from_name[MAX_STRING_SIZE];
char to_name[MAX_STRING_SIZE];
node_t *from, *to;
cp
cp();
if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING"", from_name, to_name) != 2)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "DEL_EDGE",
@ -264,6 +264,6 @@ cp
/* Run MST before or after we tell the rest? */
graph();
cp
cp();
return 0;
}

View file

@ -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.11 2002/09/06 14:31:12 guus Exp $
$Id: protocol_key.c,v 1.1.4.12 2002/09/09 19:40:05 guus Exp $
*/
#include "config.h"
@ -47,14 +47,14 @@ int mykeyused = 0;
int send_key_changed(connection_t *c, node_t *n)
{
cp
cp();
/* Only send this message if some other daemon requested our key previously.
This reduces unnecessary key_changed broadcasts.
*/
if(n == myself && !mykeyused)
return 0;
cp
cp();
return send_request(c, "%d %lx %s", KEY_CHANGED, random(), n->name);
}
@ -62,7 +62,7 @@ int key_changed_h(connection_t *c)
{
char name[MAX_STRING_SIZE];
node_t *n;
cp
cp();
if(sscanf(c->buffer, "%*d %*x "MAX_STRING, name) != 1)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "KEY_CHANGED",
@ -88,13 +88,13 @@ cp
/* Tell the others */
forward_request(c);
cp
cp();
return 0;
}
int send_req_key(connection_t *c, node_t *from, node_t *to)
{
cp
cp();
return send_request(c, "%d %s %s", REQ_KEY,
from->name, to->name);
}
@ -104,7 +104,7 @@ int req_key_h(connection_t *c)
char from_name[MAX_STRING_SIZE];
char to_name[MAX_STRING_SIZE];
node_t *from, *to;
cp
cp();
if(sscanf(c->buffer, "%*d "MAX_STRING" "MAX_STRING, from_name, to_name) != 2)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "REQ_KEY",
@ -150,17 +150,17 @@ cp
send_req_key(to->nexthop->connection, from, to);
}
cp
cp();
return 0;
}
int send_ans_key(connection_t *c, node_t *from, node_t *to)
{
char key[MAX_STRING_SIZE];
cp
cp();
bin2hex(from->key, key, from->keylength);
key[from->keylength * 2] = '\0';
cp
cp();
return send_request(c, "%d %s %s %s %d %d %d %d", ANS_KEY,
from->name, to->name, key, from->cipher?from->cipher->nid:0, from->digest?from->digest->type:0, from->maclength, from->compression);
}
@ -172,7 +172,7 @@ int ans_key_h(connection_t *c)
char key[MAX_STRING_SIZE];
int cipher, digest, maclength, compression;
node_t *from, *to;
cp
cp();
if(sscanf(c->buffer, "%*d "MAX_STRING" "MAX_STRING" "MAX_STRING" %d %d %d %d", from_name, to_name, key, &cipher, &digest, &maclength, &compression) != 7)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ANS_KEY",
@ -264,6 +264,6 @@ cp
from->compression = compression;
flush_queue(from);
cp
cp();
return 0;
}

View file

@ -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.4 2002/06/21 10:11:19 guus Exp $
$Id: protocol_misc.c,v 1.1.4.5 2002/09/09 19:40:08 guus Exp $
*/
#include "config.h"
@ -44,10 +44,10 @@
int send_status(connection_t *c, int statusno, char *statusstring)
{
cp
cp();
if(!statusstring)
statusstring = status_text[statusno];
cp
cp();
return send_request(c, "%d %d %s", STATUS, statusno, statusstring);
}
@ -55,7 +55,7 @@ int status_h(connection_t *c)
{
int statusno;
char statusstring[MAX_STRING_SIZE];
cp
cp();
if(sscanf(c->buffer, "%*d %d "MAX_STRING, &statusno, statusstring) != 2)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "STATUS",
@ -69,13 +69,13 @@ cp
c->name, c->hostname, status_text[statusno], statusstring);
}
cp
cp();
return 0;
}
int send_error(connection_t *c, int err, char *errstring)
{
cp
cp();
if(!errstring)
errstring = strerror(err);
return send_request(c, "%d %d %s", ERROR, err, errstring);
@ -85,7 +85,7 @@ int error_h(connection_t *c)
{
int err;
char errorstring[MAX_STRING_SIZE];
cp
cp();
if(sscanf(c->buffer, "%*d %d "MAX_STRING, &err, errorstring) != 2)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ERROR",
@ -100,55 +100,55 @@ cp
}
terminate_connection(c, c->status.active);
cp
cp();
return 0;
}
int send_termreq(connection_t *c)
{
cp
cp();
return send_request(c, "%d", TERMREQ);
}
int termreq_h(connection_t *c)
{
cp
cp();
terminate_connection(c, c->status.active);
cp
cp();
return 0;
}
int send_ping(connection_t *c)
{
cp
cp();
c->status.pinged = 1;
c->last_ping_time = now;
cp
cp();
return send_request(c, "%d", PING);
}
int ping_h(connection_t *c)
{
cp
cp();
return send_pong(c);
}
int send_pong(connection_t *c)
{
cp
cp();
return send_request(c, "%d", PONG);
}
int pong_h(connection_t *c)
{
cp
cp();
c->status.pinged = 0;
/* Succesful connection, reset timeout if this is an outgoing connection. */
if(c->outgoing)
c->outgoing->timeout = 0;
cp
cp();
return 0;
}
@ -157,21 +157,21 @@ cp
int send_tcppacket(connection_t *c, vpn_packet_t *packet)
{
int x;
cp
cp();
/* Evil hack. */
x = send_request(c, "%d %hd", PACKET, packet->len);
if(x)
return x;
cp
cp();
return send_meta(c, packet->data, packet->len);
}
int tcppacket_h(connection_t *c)
{
short int len;
cp
cp();
if(sscanf(c->buffer, "%*d %hd", &len) != 1)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "PACKET", c->name, c->hostname);
@ -181,7 +181,7 @@ cp
/* Set reqlen to len, this will tell receive_meta() that a tcppacket is coming. */
c->tcplen = len;
cp
cp();
return 0;
}

View file

@ -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_node.c,v 1.1.4.6 2002/09/04 08:48:03 guus Exp $
$Id: protocol_node.c,v 1.1.4.7 2002/09/09 19:40:08 guus Exp $
*/
#include "config.h"
@ -47,7 +47,7 @@ int send_add_node(connection_t *c, node_t *n)
{
int x;
char *address, *port;
cp
cp();
if(!n->status.reachable)
return 0;
@ -58,7 +58,7 @@ cp
n->prevhop->name, n->via->name);
free(address);
free(port);
cp
cp();
return x;
}
@ -74,7 +74,7 @@ int add_node_h(connection_t *c)
long int options;
int distance;
avl_node_t *node;
cp
cp();
if(sscanf(c->buffer, "%*d "MAX_STRING" "MAX_STRING" "MAX_STRING" %lx %d "MAX_STRING" "MAX_STRING,
name, address, port, &options, &distance, prevhopname, vianame) != 7)
{
@ -176,13 +176,13 @@ cp
send_add_node(other, n);
}
cp
cp();
return 0;
}
int send_del_node(connection_t *c, node_t *n)
{
cp
cp();
return send_request(c, "%d %s %s", DEL_NODE, n->name, n->prevhop->name);
}
@ -193,7 +193,7 @@ int del_node_h(connection_t *c)
node_t *n, *prevhop;
connection_t *other;
avl_node_t *node;
cp
cp();
if(sscanf(c->buffer, "%*d "MAX_STRING" "MAX_STRING, name, prevhopname) != 2)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "DEL_NODE",
@ -241,6 +241,6 @@ cp
n->status.reachable = 0;
n->status.validkey = 0;
cp
cp();
return 0;
}

View file

@ -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.6 2002/09/04 16:26:45 guus Exp $
$Id: protocol_subnet.c,v 1.1.4.7 2002/09/09 19:40:09 guus Exp $
*/
#include "config.h"
@ -47,11 +47,11 @@ int send_add_subnet(connection_t *c, subnet_t *subnet)
{
int x;
char *netstr;
cp
cp();
x = send_request(c, "%d %lx %s %s", ADD_SUBNET, random(),
subnet->owner->name, netstr = net2str(subnet));
free(netstr);
cp
cp();
return x;
}
@ -61,7 +61,7 @@ int add_subnet_h(connection_t *c)
char name[MAX_STRING_SIZE];
node_t *owner;
subnet_t *s;
cp
cp();
if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING, name, subnetstr) != 2)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ADD_SUBNET", c->name, c->hostname);
@ -78,7 +78,9 @@ cp
/* Check if subnet string is valid */
if(!(s = str2net(subnetstr)))
s = str2net(subnetstr);
if(!s)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_SUBNET", c->name, c->hostname, _("invalid subnet string"));
return -1;
@ -124,7 +126,7 @@ cp
/* Tell the rest */
forward_request(c);
cp
cp();
return 0;
}
@ -132,11 +134,11 @@ int send_del_subnet(connection_t *c, subnet_t *s)
{
int x;
char *netstr;
cp
cp();
netstr = net2str(s);
x = send_request(c, "%d %lx %s %s", DEL_SUBNET, random(), s->owner->name, netstr);
free(netstr);
cp
cp();
return x;
}
@ -146,7 +148,7 @@ int del_subnet_h(connection_t *c)
char name[MAX_STRING_SIZE];
node_t *owner;
subnet_t *s, *find;
cp
cp();
if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING, name, subnetstr) != 2)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "DEL_SUBNET", c->name, c->hostname);
@ -163,7 +165,9 @@ cp
/* Check if the owner of the new subnet is in the connection list */
if(!(owner = lookup_node(name)))
owner = lookup_node(name);
if(!owner)
{
if(debug_lvl >= DEBUG_PROTOCOL)
syslog(LOG_WARNING, _("Got %s from %s (%s) for %s which is not in our node tree"),
@ -173,7 +177,9 @@ cp
/* Check if subnet string is valid */
if(!(s = str2net(subnetstr)))
s = str2net(subnetstr);
if(!s)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_SUBNET", c->name, c->hostname, _("invalid subnet string"));
return -1;
@ -216,6 +222,6 @@ cp
subnet_del(owner, find);
cp
cp();
return 0;
}

View file

@ -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: route.c,v 1.1.2.43 2002/06/21 10:11:33 guus Exp $
$Id: route.c,v 1.1.2.44 2002/09/09 19:40:11 guus Exp $
*/
#include "config.h"
@ -72,7 +72,7 @@ void learn_mac(mac_t *address)
subnet_t *subnet;
avl_node_t *node;
connection_t *c;
cp
cp();
subnet = lookup_subnet_mac(address);
/* If we don't know this MAC address yet, store it */
@ -106,7 +106,7 @@ void age_mac(void)
subnet_t *s;
connection_t *c;
avl_node_t *node, *next, *node2;
cp
cp();
for(node = myself->subnet_tree->head; node; node = next)
{
next = node->next;
@ -125,13 +125,13 @@ cp
subnet_del(myself, s);
}
}
cp
cp();
}
node_t *route_mac(vpn_packet_t *packet)
{
subnet_t *subnet;
cp
cp();
/* Learn source address */
learn_mac((mac_t *)(&packet->data[6]));
@ -149,12 +149,12 @@ cp
node_t *route_ipv4(vpn_packet_t *packet)
{
subnet_t *subnet;
cp
cp();
if(priorityinheritance)
packet->priority = packet->data[15];
subnet = lookup_subnet_ipv4((ipv4_t *)&packet->data[30]);
cp
cp();
if(!subnet)
{
if(debug_lvl >= DEBUG_TRAFFIC)
@ -165,16 +165,16 @@ cp
return NULL;
}
cp
cp();
return subnet->owner;
}
node_t *route_ipv6(vpn_packet_t *packet)
{
subnet_t *subnet;
cp
cp();
subnet = lookup_subnet_ipv6((ipv6_t *)&packet->data[38]);
cp
cp();
if(!subnet)
{
if(debug_lvl >= DEBUG_TRAFFIC)
@ -192,7 +192,7 @@ cp
return NULL;
}
cp
cp();
return subnet->owner;
}
@ -224,7 +224,7 @@ void route_neighborsol(vpn_packet_t *packet)
uint8_t junk[4];
} pseudo;
cp
cp();
hdr = (struct ip6_hdr *)(packet->data + 14);
ns = (struct nd_neighbor_solicit *)(packet->data + 14 + sizeof(*hdr));
opt = (struct nd_opt_hdr *)(packet->data + 14 + sizeof(*hdr) + sizeof(*ns));
@ -318,7 +318,7 @@ cp
ns->nd_ns_hdr.icmp6_cksum = htons(checksum);
write_packet(packet);
cp
cp();
}
void route_arp(vpn_packet_t *packet)
@ -326,7 +326,7 @@ void route_arp(vpn_packet_t *packet)
struct ether_arp *arp;
subnet_t *subnet;
uint8_t ipbuf[4];
cp
cp();
/* First, snatch the source address from the ARP packet */
memcpy(mymac.net.mac.address.x, packet->data + 6, 6);
@ -385,14 +385,14 @@ cp
arp->arp_op = htons(ARPOP_REPLY);
write_packet(packet);
cp
cp();
}
void route_outgoing(vpn_packet_t *packet)
{
uint16_t type;
node_t *n = NULL;
cp
cp();
/* FIXME: multicast? */
switch(routing_mode)

View file

@ -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.39 2002/07/11 12:42:43 guus Exp $
$Id: subnet.c,v 1.1.2.40 2002/09/09 19:40:11 guus Exp $
*/
#include "config.h"
@ -51,7 +51,7 @@ avl_tree_t *subnet_tree;
int subnet_compare_mac(subnet_t *a, subnet_t *b)
{
int result;
cp
cp();
result = memcmp(&a->net.mac.address, &b->net.mac.address, sizeof(mac_t));
if(result || !a->owner || !b->owner)
@ -63,7 +63,7 @@ cp
int subnet_compare_ipv4(subnet_t *a, subnet_t *b)
{
int result;
cp
cp();
result = memcmp(&a->net.ipv4.address, &b->net.ipv4.address, sizeof(ipv4_t));
if(result)
@ -80,7 +80,7 @@ cp
int subnet_compare_ipv6(subnet_t *a, subnet_t *b)
{
int result;
cp
cp();
result = memcmp(&a->net.ipv6.address, &b->net.ipv6.address, sizeof(ipv6_t));
if(result)
@ -97,7 +97,7 @@ cp
int subnet_compare(subnet_t *a, subnet_t *b)
{
int result;
cp
cp();
result = a->type - b->type;
if(result)
@ -124,43 +124,43 @@ cp
void init_subnets(void)
{
cp
cp();
subnet_tree = avl_alloc_tree((avl_compare_t)subnet_compare, (avl_action_t)free_subnet);
cp
cp();
}
void exit_subnets(void)
{
cp
cp();
avl_delete_tree(subnet_tree);
cp
cp();
}
avl_tree_t *new_subnet_tree(void)
{
cp
cp();
return avl_alloc_tree((avl_compare_t)subnet_compare, NULL);
cp
cp();
}
void free_subnet_tree(avl_tree_t *subnet_tree)
{
cp
cp();
avl_delete_tree(subnet_tree);
cp
cp();
}
/* Allocating and freeing space for subnets */
subnet_t *new_subnet(void)
{
cp
cp();
return (subnet_t *)xmalloc_and_zero(sizeof(subnet_t));
}
void free_subnet(subnet_t *subnet)
{
cp
cp();
free(subnet);
}
@ -168,22 +168,22 @@ cp
void subnet_add(node_t *n, subnet_t *subnet)
{
cp
cp();
subnet->owner = n;
avl_insert(subnet_tree, subnet);
cp
cp();
avl_insert(n->subnet_tree, subnet);
cp
cp();
}
void subnet_del(node_t *n, subnet_t *subnet)
{
cp
cp();
avl_delete(n->subnet_tree, subnet);
cp
cp();
avl_delete(subnet_tree, subnet);
cp
cp();
}
/* Ascii representation of subnets */
@ -193,9 +193,9 @@ subnet_t *str2net(char *subnetstr)
int i, l;
subnet_t *subnet;
uint16_t x[8];
cp
cp();
subnet = new_subnet();
cp
cp();
if(sscanf(subnetstr, "%hu.%hu.%hu.%hu/%d",
&x[0], &x[1], &x[2], &x[3],
&l) == 5)
@ -254,7 +254,7 @@ cp
char *net2str(subnet_t *subnet)
{
char *netstr;
cp
cp();
switch(subnet->type)
{
case SUBNET_MAC:
@ -291,7 +291,7 @@ cp
cp_trace();
exit(0);
}
cp
cp();
return netstr;
}
@ -299,27 +299,27 @@ cp
subnet_t *lookup_subnet(node_t *owner, subnet_t *subnet)
{
cp
cp();
return avl_search(owner->subnet_tree, subnet);
}
subnet_t *lookup_subnet_mac(mac_t *address)
{
subnet_t subnet, *p;
cp
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);
cp
cp();
return p;
}
subnet_t *lookup_subnet_ipv4(ipv4_t *address)
{
subnet_t subnet, *p;
cp
cp();
subnet.type = SUBNET_IPV4;
memcpy(&subnet.net.ipv4.address, address, sizeof(ipv4_t));
subnet.net.ipv4.prefixlength = 32;
@ -332,7 +332,7 @@ cp
p = (subnet_t *)avl_search_closest_smaller(subnet_tree, &subnet);
/* Check if the found subnet REALLY matches */
cp
cp();
if(p)
{
if(p->type != SUBNET_IPV4)
@ -352,14 +352,14 @@ cp
}
}
} while (p);
cp
cp();
return p;
}
subnet_t *lookup_subnet_ipv6(ipv6_t *address)
{
subnet_t subnet, *p;
cp
cp();
subnet.type = SUBNET_IPV6;
memcpy(&subnet.net.ipv6.address, address, sizeof(ipv6_t));
subnet.net.ipv6.prefixlength = 128;
@ -373,7 +373,7 @@ cp
/* Check if the found subnet REALLY matches */
cp
cp();
if(p)
{
if(p->type != SUBNET_IPV6)
@ -390,7 +390,7 @@ cp
}
}
} while (p);
cp
cp();
return p;
}
@ -399,7 +399,7 @@ void dump_subnets(void)
char *netstr;
subnet_t *subnet;
avl_node_t *node;
cp
cp();
syslog(LOG_DEBUG, _("Subnet list:"));
for(node = subnet_tree->head; node; node = node->next)
{
@ -409,5 +409,5 @@ cp
free(netstr);
}
syslog(LOG_DEBUG, _("End of subnet list."));
cp
cp();
}

View file

@ -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: tincd.c,v 1.10.4.61 2002/07/16 13:12:49 guus Exp $
$Id: tincd.c,v 1.10.4.62 2002/09/09 19:40:12 guus Exp $
*/
#include "config.h"
@ -269,7 +269,9 @@ int keygen(int bits)
else
asprintf(&filename, "%s/rsa_key.pub", confbase);
if((f = ask_and_safe_open(filename, _("public RSA key"), "a")) == NULL)
f = ask_and_safe_open(filename, _("public RSA key"), "a");
if(!f)
return -1;
if(ftell(f))
@ -280,7 +282,9 @@ int keygen(int bits)
free(filename);
asprintf(&filename, "%s/rsa_key.priv", confbase);
if((f = ask_and_safe_open(filename, _("private RSA key"), "a")) == NULL)
f = ask_and_safe_open(filename, _("private RSA key"), "a");
if(!f)
return -1;
if(ftell(f))
@ -356,10 +360,16 @@ main(int argc, char **argv, char **envp)
/* Lock all pages into memory if requested */
if(do_mlock)
if(mlockall(MCL_CURRENT | MCL_FUTURE)) {
syslog(LOG_ERR, _("System call `%s' failed: %s"), "mlockall", strerror(errno));
return -1;
}
#ifdef HAVE_MLOCKALL
if(mlockall(MCL_CURRENT | MCL_FUTURE))
{
syslog(LOG_ERR, _("System call `%s' failed: %s"), "mlockall", strerror(errno));
#else
{
syslog(LOG_ERR, _("mlockall() not supported on this platform!"));
#endif
return -1;
}
g_argv = argv;
@ -367,7 +377,7 @@ main(int argc, char **argv, char **envp)
init_configuration(&config_tree);
/* Slllluuuuuuurrrrp! */
cp
cp();
RAND_load_file("/dev/urandom", 1024);
#ifdef HAVE_SSLEAY_ADD_ALL_ALGORITHMS
@ -376,7 +386,7 @@ cp
OpenSSL_add_all_algorithms();
#endif
cp
cp();
if(generate_keys)
{
read_server_config();
@ -388,10 +398,10 @@ cp
if(read_server_config())
exit(1);
cp
cp();
if(detach())
exit(0);
cp
cp();
for(;;)
{
if(!setup_network_connections())