- Convert cp to cp(); so that automatic indenters work.
- Convert constructions like if(x == NULL) to if(!x).
- Move all assignments out of conditions.
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)
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
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
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"
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;
void free_config(config_t *cfg)
{
-cp
+ cp();
if(cfg->variable)
free(cfg->variable);
if(cfg->value)
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;
{
avl_node_t *node;
config_t *found;
-cp
+ cp();
node = avl_search_node(config_tree, cfg);
if(node)
int get_config_bool(config_t *cfg, int *result)
{
-cp
+ cp();
if(!cfg)
return 0;
int get_config_int(config_t *cfg, int *result)
{
-cp
+ cp();
if(!cfg)
return 0;
int get_config_string(config_t *cfg, char **result)
{
-cp
+ cp();
if(!cfg)
return 0;
int get_config_address(config_t *cfg, struct addrinfo **result)
{
struct addrinfo *ai;
-cp
+ cp();
if(!cfg)
return 0;
int get_config_port(config_t *cfg, port_t *result)
{
-cp
+ cp();
if(!cfg)
return 0;
int get_config_subnet(config_t *cfg, subnet_t **result)
{
subnet_t *subnet;
-cp
+ cp();
if(!cfg)
return 0;
if(feof(fp))
return NULL;
- if((buf != NULL) && (buflen != NULL))
+ if(buf && buflen)
{
size = *buflen;
line = *buf;
{
errno = 0;
p = fgets(idx, maxlen, fp);
- if(p == NULL) /* EOF or error */
+ if(!p) /* EOF or error */
{
if(feof(fp))
break;
}
newline = strchr(p, '\n');
- if(newline == NULL)
+ if(!newline)
/* We haven't yet read everything to the end of the line */
{
newsize = size << 1;
}
}
- if((buf != NULL) && (buflen != NULL))
+ if(buf && buflen)
{
*buflen = size;
*buf = line;
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;
for(;;)
{
- if((line = readline(fp, &buffer, &bufsize)) == NULL)
+ line = readline(fp, &buffer, &bufsize);
+
+ if(!line)
{
err = -1;
break;
lineno++;
- if((variable = strtok(line, "\t =")) == NULL)
+ variable = strtok(line, "\t =");
+
+ if(!variable)
continue; /* no tokens on this line */
if(variable[0] == '#')
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);
free(buffer);
fclose (fp);
-cp
+ cp();
return err;
}
{
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 */
syslog(LOG_ERR, _("Failed to read `%s': %s"), fname, strerror(errno));
}
free(fname);
-cp
+ cp();
return x;
}
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;
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));
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"
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)
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)
}
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;
}
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"
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 */
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;
node_t *n;
edge_t *e;
char *address;
-cp
+ cp();
syslog(LOG_DEBUG, _("Edges:"));
for(node = node_tree->head; node; node = node->next)
}
syslog(LOG_DEBUG, _("End of edges."));
-cp
+ cp();
}
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"
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;
return event;
}
}
-cp
+ cp();
return NULL;
}
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:
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);
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"
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;
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;
}
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;
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"
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);
syslog(LOG_ERR, _("Sending meta data to %s (%s) failed: %s"), c->name, c->hostname, strerror(errno));
return -1;
}
-cp
+ cp();
return 0;
}
{
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)
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),
}
c->last_ping_time = now;
-cp
+ cp();
return 0;
}
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"
node_t *n;
edge_t *e;
subnet_t *s;
-cp
+ cp();
if(debug_lvl >= DEBUG_PROTOCOL)
syslog(LOG_DEBUG, _("Purging unreachable nodes"));
node_del(n);
}
}
-cp
+ cp();
}
/*
avl_node_t *node, *next;
connection_t *c;
int i;
-cp
+ cp();
FD_ZERO(fs);
for(node = connection_tree->head; node; node = next)
}
FD_SET(device_fd, fs);
-cp
+ cp();
}
/*
*/
void terminate_connection(connection_t *c, int report)
{
-cp
+ cp();
if(c->status.remove)
return;
retry_outgoing(c->outgoing);
c->outgoing = NULL;
}
-cp
+ cp();
}
/*
{
avl_node_t *node, *next;
connection_t *c;
-cp
+ cp();
for(node = connection_tree->head; node; node = next)
{
next = node->next;
}
}
}
-cp
+ cp();
}
/*
int result, i;
int len = sizeof(result);
vpn_packet_t packet;
-cp
+ cp();
if(FD_ISSET(device_fd, f))
{
if(!read_packet(&packet))
if(FD_ISSET(listen_socket[i].tcp, f))
handle_new_meta_connection(listen_socket[i].tcp);
}
-cp
+ cp();
}
/*
int r;
time_t last_ping_check;
event_t *event;
-cp
+ cp();
last_ping_check = now;
srand(now);
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)
{
continue;
}
}
-cp
+ cp();
}
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"
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)
}
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)
static int priority = 0;
int origpriority;
int sock;
-cp
+ cp();
/* Make sure we have a valid key */
if(!n->status.validkey)
}
inpkt->len = origlen;
-cp
+ 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);
{
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);
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);
send_udppacket(n, (vpn_packet_t *)node->data);
list_delete_node(n->queue, node);
}
-cp
+ cp();
}
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"),
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;
n->connection->last_ping_time = now;
receive_udppacket(n, &pkt);
-cp
+ cp();
}
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"
FILE *fp;
char *fname;
char *key;
-cp
+ cp();
if(!c->rsa_key)
c->rsa_key = RSA_new();
{
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));
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));
/* 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);
/* 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);
{
FILE *fp;
char *fname, *key;
-cp
+ cp();
if(get_config_string(lookup_config(config_tree, "PrivateKey"), &key))
{
myself->connection->rsa_key = RSA_new();
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));
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);
myself->name = name;
myself->connection->name = xstrdup(name);
-cp
+ cp();
if(read_rsa_private_key())
return -1;
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");
cfg = lookup_config_next(myself->connection->config_tree, cfg);
}
-cp
+ cp();
/* Check some options */
if(get_config_bool(lookup_config(config_tree, "IndirectData"), &choice))
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))
}
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;
}
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;
myself->compression = 0;
myself->connection->outcompression = 0;
-cp
+ cp();
/* Done */
myself->nexthop = myself;
graph();
-cp
+ cp();
/* Open sockets */
memset(&hint, 0, sizeof(hint));
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;
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)
syslog(LOG_ERR, _("Unable to create any listening socket!"));
return -1;
}
-cp
+ cp();
return 0;
}
{
char *envp[4];
int i;
-cp
+ cp();
now = time(NULL);
init_connections();
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);
return -1;
try_outgoing_connections();
-cp
+ cp();
return 0;
}
connection_t *c;
char *envp[4];
int i;
-cp
+ cp();
for(node = connection_tree->head; node; node = next)
{
next = node->next;
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);
free(envp[i]);
close_device();
-cp
+ cp();
return;
}
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"
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;
syslog(LOG_ERR, _("System call `%s' failed: %s"), "listen", strerror(errno));
return -1;
}
-cp
+ cp();
return nfd;
}
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;
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;
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);
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)
{
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)
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;
c->allow_request = ID;
send_id(c);
-cp
+ cp();
return 0;
}
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);
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"
{
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));
return NULL;
}
-cp
+ cp();
return ai;
}
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();
result = *(sockaddr_t *)ai->ai_addr;
freeaddrinfo(ai);
-cp
+ cp();
return result;
}
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();
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)
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)
raise(SIGFPE);
exit(0);
}
-cp
+ cp();
}
void sockaddrunmap(sockaddr_t *sa)
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))));
{
int i;
char *a = va;
-cp
+ cp();
i = masklen / 8;
masklen %= 8;
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];
{
int i;
char *a = va;
-cp
+ cp();
i = masklen / 8;
masklen %= 8;
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"
int node_udp_compare(node_t *a, node_t *b)
{
int result;
-cp
+ cp();
result = sockaddrcmp(&a->address, &b->address);
if(result)
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)
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)
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;
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);
}
node_t *lookup_node_udp(sockaddr_t *sa)
{
node_t n;
-cp
+ cp();
n.address = *sa;
n.name = NULL;
{
avl_node_t *node;
node_t *n;
-cp
+ cp();
syslog(LOG_DEBUG, _("Nodes:"));
for(node = node_tree->head; node; node = node->next)
}
syslog(LOG_DEBUG, _("End of nodes."));
-cp
+ cp();
}
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"
*/
void cleanup_and_exit(int c)
{
-cp
+ cp();
close_network_connections();
if(debug_lvl > DEBUG_NOTHING)
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"),
/* if it's locked, write-protected, or whatever */
if(!write_pid(pidfilename))
return 1;
-cp
+ cp();
return 0;
}
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);
fprintf(stderr, _("Removing stale lock file.\n"));
remove_pid(pidfilename);
}
-cp
+ cp();
return 0;
}
*/
int detach(void)
{
-cp
+ cp();
setup_signals();
/* First check if we can open a fresh new pidfile */
syslog(LOG_NOTICE, _("tincd %s starting"), VERSION);
xalloc_fail_func = memory_full;
-cp
+ cp();
return 0;
}
void _execute_script(const char *scriptname, char **envp)
{
char *s;
-cp
+ cp();
while(*envp)
putenv(*envp++);
int status;
struct stat s;
char *scriptname;
-cp
+ cp();
asprintf(&scriptname, "%s/%s", confbase, name);
/* First check if there is a script */
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;
return -1;
}
}
-cp
+ cp();
/* Child here */
_execute_script(scriptname, envp);
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"
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 */
}
buffer[len++] = '\n';
-cp
+ cp();
if(c == broadcast)
return broadcast_meta(NULL, buffer, len);
else
int forward_request(connection_t *from)
{
int request;
-cp
+ cp();
if(debug_lvl >= DEBUG_PROTOCOL)
{
sscanf(from->buffer, "%d", &request);
}
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"),
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))
avl_insert(past_request_tree, new);
return 0;
}
-cp
+ cp();
}
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;
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 */
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"
int send_id(connection_t *c)
{
-cp
+ cp();
return send_request(c, "%d %s %d", ID, myself->connection->name, myself->connection->protocol_version);
}
{
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);
{
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;
c->options |= OPTION_TCPONLY | OPTION_INDIRECT;
c->allow_request = METAKEY;
-cp
+ cp();
return send_metakey(c);
}
{
char buffer[MAX_STRING_SIZE];
int len, x;
-cp
+ cp();
len = RSA_size(c->rsa_key);
/* Allocate buffers for the meta key */
if(!c->outctx)
c->outctx = xmalloc(sizeof(*c->outctx));
-cp
+ cp();
/* Copy random data to the buffer */
RAND_bytes(c->outkey, len);
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);
c->status.encryptout = 1;
}
-cp
+ cp();
return x;
}
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 */
}
/* Allocate buffers for the meta key */
-cp
+ cp();
if(!c->inkey)
c->inkey = xmalloc(len);
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);
}
/* All incoming requests will now be encrypted. */
-cp
+ cp();
/* Check and lookup cipher and digest algorithms */
if(cipher)
c->incompression = compression;
c->allow_request = CHALLENGE;
-cp
+ cp();
return send_challenge(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);
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;
}
{
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);
c->allow_request = CHAL_REPLY;
/* Rest is done by send_chal_reply() */
-cp
+ cp();
return send_chal_reply(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);
/* Send the reply */
-cp
+ cp();
return send_request(c, "%d %s", CHAL_REPLY, hash);
}
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);
*/
c->allow_request = ACK;
-cp
+ cp();
return send_ack(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;
}
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);
/* 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);
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);
/* Run MST and SSSP algorithms */
graph();
-cp
+ cp();
return 0;
}
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"
{
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;
}
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)
{
/* 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);
}
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",
/* Run MST before or after we tell the rest? */
graph();
-cp
+ cp();
return 0;
}
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"
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);
}
{
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",
/* 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);
}
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",
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);
}
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",
from->compression = compression;
flush_queue(from);
-cp
+ cp();
return 0;
}
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"
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);
}
{
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",
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);
{
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",
}
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;
}
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);
/* Set reqlen to len, this will tell receive_meta() that a tcppacket is coming. */
c->tcplen = len;
-cp
+ cp();
return 0;
}
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"
{
int x;
char *address, *port;
-cp
+ cp();
if(!n->status.reachable)
return 0;
n->prevhop->name, n->via->name);
free(address);
free(port);
-cp
+ cp();
return x;
}
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)
{
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);
}
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",
n->status.reachable = 0;
n->status.validkey = 0;
-cp
+ cp();
return 0;
}
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"
{
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;
}
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);
/* 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;
/* Tell the rest */
forward_request(c);
-cp
+ cp();
return 0;
}
{
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;
}
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);
/* 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"),
/* 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;
subnet_del(owner, find);
-cp
+ cp();
return 0;
}
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"
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 */
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;
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]));
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)
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)
return NULL;
}
-cp
+ cp();
return subnet->owner;
}
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));
ns->nd_ns_hdr.icmp6_cksum = htons(checksum);
write_packet(packet);
-cp
+ cp();
}
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);
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)
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"
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)
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)
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)
int subnet_compare(subnet_t *a, subnet_t *b)
{
int result;
-cp
+ cp();
result = a->type - b->type;
if(result)
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);
}
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 */
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)
char *net2str(subnet_t *subnet)
{
char *netstr;
-cp
+ cp();
switch(subnet->type)
{
case SUBNET_MAC:
cp_trace();
exit(0);
}
-cp
+ cp();
return netstr;
}
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;
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)
}
}
} 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;
/* Check if the found subnet REALLY matches */
-cp
+ cp();
if(p)
{
if(p->type != SUBNET_IPV6)
}
}
} while (p);
-cp
+ cp();
return p;
}
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)
{
free(netstr);
}
syslog(LOG_DEBUG, _("End of subnet list."));
-cp
+ cp();
}
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"
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))
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))
/* 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;
init_configuration(&config_tree);
/* Slllluuuuuuurrrrp! */
-cp
+ cp();
RAND_load_file("/dev/urandom", 1024);
#ifdef HAVE_SSLEAY_ADD_ALL_ALGORITHMS
OpenSSL_add_all_algorithms();
#endif
-cp
+ cp();
if(generate_keys)
{
read_server_config();
if(read_server_config())
exit(1);
-cp
+ cp();
if(detach())
exit(0);
-cp
+ cp();
for(;;)
{
if(!setup_network_connections())