Merging of the entire pre5 branch.
This commit is contained in:
parent
c2752b961c
commit
f0aa9641e8
70 changed files with 2575 additions and 4056 deletions
|
|
@ -1,14 +1,17 @@
|
|||
## Produce this file with automake to get Makefile.in
|
||||
# $Id: Makefile.am,v 1.4.4.18 2001/11/16 12:16:28 zarq Exp $
|
||||
# $Id: Makefile.am,v 1.4.4.19 2002/02/10 21:57:52 guus Exp $
|
||||
|
||||
sbin_PROGRAMS = tincd
|
||||
|
||||
tincd_SOURCES = conf.c connection.c device.c edge.c graph.c meta.c net.c node.c process.c \
|
||||
protocol.c route.c subnet.c tincd.c
|
||||
EXTRA_DIST = linux/device.c freebsd/device.c openbsd/device.c solaris/device.c
|
||||
|
||||
tincd_SOURCES = conf.c connection.c device.c edge.c event.c graph.c meta.c net.c netutl.c node.c process.c \
|
||||
protocol.c protocol_auth.c protocol_edge.c protocol_misc.c protocol_key.c protocol_subnet.c \
|
||||
route.c subnet.c tincd.c
|
||||
|
||||
INCLUDES = @INCLUDES@ -I$(top_builddir) -I$(top_srcdir)/lib -I$(top_srcdir)/intl
|
||||
|
||||
noinst_HEADERS = conf.h connection.h device.h edge.h graph.h meta.h net.h node.h process.h \
|
||||
noinst_HEADERS = conf.h connection.h device.h edge.h event.h graph.h meta.h net.h netutl.h node.h process.h \
|
||||
protocol.h route.h subnet.h
|
||||
|
||||
LIBS = @LIBS@ @INTLLIBS@
|
||||
|
|
|
|||
86
src/conf.c
86
src/conf.c
|
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
conf.c -- configuration code
|
||||
Copyright (C) 1998 Robert van der Meulen
|
||||
1998-2001 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
2000,2001 Guus Sliepen <guus@sliepen.warande.net>
|
||||
1998-2002 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
2000-2002 Guus Sliepen <guus@sliepen.warande.net>
|
||||
2000 Cris van Pelt <tribbel@arise.dhs.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
|
|
@ -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.51 2001/11/16 22:31:41 zarq Exp $
|
||||
$Id: conf.c,v 1.9.4.52 2002/02/10 21:57:53 guus Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
|
@ -42,19 +42,17 @@
|
|||
#include <avl_tree.h>
|
||||
|
||||
#include "conf.h"
|
||||
#include "netutl.h" /* for str2address */
|
||||
|
||||
#include "system.h"
|
||||
|
||||
avl_tree_t *config_tree;
|
||||
|
||||
int debug_lvl = 0;
|
||||
int timeout = 0; /* seconds before timeout */
|
||||
int pingtimeout = 0; /* seconds before timeout */
|
||||
char *confbase = NULL; /* directory in which all config files are */
|
||||
char *netname = NULL; /* name of the vpn network */
|
||||
|
||||
/* Will be set if HUP signal is received. It will be processed when it is safe. */
|
||||
int sighup = 0;
|
||||
|
||||
int config_compare(config_t *a, config_t *b)
|
||||
{
|
||||
int result;
|
||||
|
|
@ -202,6 +200,41 @@ cp
|
|||
return 1;
|
||||
}
|
||||
|
||||
int get_config_address(config_t *cfg, ipv4_t **result)
|
||||
{
|
||||
ipv4_t *ip;
|
||||
cp
|
||||
if(!cfg)
|
||||
return 0;
|
||||
|
||||
ip = xmalloc(sizeof(*ip));
|
||||
*ip = str2address(cfg->value);
|
||||
|
||||
if(ip)
|
||||
{
|
||||
*result = ip;
|
||||
return 1;
|
||||
}
|
||||
|
||||
syslog(LOG_ERR, _("IP address expected for configuration variable %s in %s line %d"),
|
||||
cfg->variable, cfg->file, cfg->line);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_config_port(config_t *cfg, port_t *result)
|
||||
{
|
||||
cp
|
||||
if(!cfg)
|
||||
return 0;
|
||||
|
||||
if(sscanf(cfg->value, "%hu", result) == 1)
|
||||
return 1;
|
||||
|
||||
syslog(LOG_ERR, _("Port number expected for configuration variable %s in %s line %d"),
|
||||
cfg->variable, cfg->file, cfg->line);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_config_subnet(config_t *cfg, subnet_t **result)
|
||||
{
|
||||
subnet_t *subnet;
|
||||
|
|
@ -209,34 +242,27 @@ cp
|
|||
if(!cfg)
|
||||
return 0;
|
||||
|
||||
#warning FIXME
|
||||
/* ip = strtoip(cfg->value); */
|
||||
subnet = str2net(cfg->value);
|
||||
|
||||
/* if(!ip) */
|
||||
/* { */
|
||||
/* syslog(LOG_ERR, _("IP address expected for configuration variable %s in %s line %d"), */
|
||||
/* cfg->variable, cfg->file, cfg->line); */
|
||||
/* return 0; */
|
||||
/* } */
|
||||
if(!subnet)
|
||||
{
|
||||
syslog(LOG_ERR, _("Subnet expected for configuration variable %s in %s line %d"),
|
||||
cfg->variable, cfg->file, cfg->line);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Teach newbies what subnets are... */
|
||||
|
||||
/* if((ip->address & ip->mask) != ip->address) */
|
||||
/* { */
|
||||
/* syslog(LOG_ERR, _("Network address and subnet mask for configuration variable %s in %s line %d"), */
|
||||
/* cfg->variable, cfg->file, cfg->line); */
|
||||
/* free(ip); */
|
||||
/* return 0; */
|
||||
/* } */
|
||||
if(subnet->type == SUBNET_IPV4)
|
||||
if((subnet->net.ipv4.address & subnet->net.ipv4.mask) != subnet->net.ipv4.address)
|
||||
{
|
||||
syslog(LOG_ERR, _("Network address and mask length do not match for configuration variable %s in %s line %d"),
|
||||
cfg->variable, cfg->file, cfg->line);
|
||||
free(subnet);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* subnet = new_subnet(); */
|
||||
/* subnet->type = SUBNET_IP; */
|
||||
/* subnet->net.ip.address = ip->address; */
|
||||
/* subnet->net.ip.mask = ip->mask; */
|
||||
|
||||
/* free(ip); */
|
||||
|
||||
/* *result = subnet; */
|
||||
*result = subnet;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
11
src/conf.h
11
src/conf.h
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
conf.h -- header for conf.c
|
||||
Copyright (C) 1998-2001 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
2000,2001 Guus Sliepen <guus@sliepen.warande.net>
|
||||
Copyright (C) 1998-2002 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
2000-2002 Guus Sliepen <guus@sliepen.warande.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
$Id: conf.h,v 1.6.4.30 2001/11/16 12:14:20 zarq Exp $
|
||||
$Id: conf.h,v 1.6.4.31 2002/02/10 21:57:53 guus Exp $
|
||||
*/
|
||||
|
||||
#ifndef __TINC_CONF_H__
|
||||
|
|
@ -37,9 +37,8 @@ typedef struct config_t {
|
|||
extern avl_tree_t *config_tree;
|
||||
|
||||
extern int debug_lvl;
|
||||
extern int timeout;
|
||||
extern int pingtimeout;
|
||||
extern int maxtimeout;
|
||||
extern int sighup;
|
||||
extern int bypass_security;
|
||||
extern char *confbase;
|
||||
extern char *netname;
|
||||
|
|
@ -53,7 +52,9 @@ extern config_t *lookup_config(avl_tree_t *, char *);
|
|||
extern config_t *lookup_config_next(avl_tree_t *, config_t *);
|
||||
extern int get_config_bool(config_t *, int *);
|
||||
extern int get_config_int(config_t *, int *);
|
||||
extern int get_config_port(config_t *, port_t *);
|
||||
extern int get_config_string(config_t *, char **);
|
||||
extern int get_config_address(config_t *, ipv4_t **);
|
||||
struct subnet_t; /* Needed for next line. */
|
||||
extern int get_config_subnet(config_t *, struct subnet_t **);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
connection.c -- connection list management
|
||||
Copyright (C) 2000,2001 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2000,2001 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
Copyright (C) 2000-2002 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2000-2002 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -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.26 2001/11/16 12:20:44 zarq Exp $
|
||||
$Id: connection.c,v 1.1.2.27 2002/02/10 21:57:53 guus Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
|
@ -31,6 +31,7 @@
|
|||
#include <list.h>
|
||||
|
||||
#include "net.h" /* Don't ask. */
|
||||
#include "netutl.h"
|
||||
#include "config.h"
|
||||
#include "conf.h"
|
||||
#include <utils.h>
|
||||
|
|
@ -105,11 +106,12 @@ cp
|
|||
cp
|
||||
}
|
||||
|
||||
connection_t *lookup_connection(struct addrinfo *address)
|
||||
connection_t *lookup_connection(ipv4_t address, port_t port)
|
||||
{
|
||||
connection_t c;
|
||||
cp
|
||||
c.address = address;
|
||||
c.port = port;
|
||||
|
||||
return avl_search(connection_tree, &c);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
connection.h -- header for connection.c
|
||||
Copyright (C) 2000,2001 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2000,2001 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
Copyright (C) 2000-2002 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2000-2002 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -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.h,v 1.1.2.23 2001/11/16 12:01:48 zarq Exp $
|
||||
$Id: connection.h,v 1.1.2.24 2002/02/10 21:57:53 guus Exp $
|
||||
*/
|
||||
|
||||
#ifndef __TINC_CONNECTION_H__
|
||||
|
|
@ -46,30 +46,26 @@
|
|||
#include "node.h"
|
||||
#include "edge.h"
|
||||
|
||||
#include <config.h>
|
||||
#include <dropin.h>
|
||||
|
||||
#define OPTION_INDIRECT 0x0001
|
||||
#define OPTION_TCPONLY 0x0002
|
||||
|
||||
typedef struct connection_status_t {
|
||||
int pinged:1; /* sent ping */
|
||||
int active:1; /* 1 if active.. */
|
||||
int outgoing:1; /* I myself asked for this conn */
|
||||
int termreq:1; /* the termination of this connection was requested */
|
||||
int remove:1; /* Set to 1 if you want this connection removed */
|
||||
int timeout:1; /* 1 if gotten timeout */
|
||||
int encryptout:1; /* 1 if we can encrypt outgoing traffic */
|
||||
int decryptin:1; /* 1 if we have to decrypt incoming traffic */
|
||||
int mst:1; /* 1 if this connection is part of a minimum spanning tree */
|
||||
int unused:17;
|
||||
int unused:18;
|
||||
} connection_status_t;
|
||||
|
||||
typedef struct connection_t {
|
||||
char *name; /* name he claims to have */
|
||||
|
||||
struct addrinfo *address; /* his real (internet) ip */
|
||||
char *port; /* port number of meta connection */
|
||||
ipv4_t address; /* his real (internet) ip */
|
||||
port_t port; /* port number of meta connection */
|
||||
char *hostname; /* the hostname of its real ip */
|
||||
int protocol_version; /* used protocol */
|
||||
|
||||
|
|
@ -78,9 +74,10 @@ typedef struct connection_t {
|
|||
struct connection_status_t status; /* status info */
|
||||
int estimated_weight; /* estimation for the weight of the edge for this connection */
|
||||
struct timeval start; /* time this connection was started, used for above estimation */
|
||||
struct outgoing_t *outgoing; /* used to keep track of outgoing connections */
|
||||
|
||||
struct node_t *node; /* node associated with the other end */
|
||||
struct edge_t *edge; /* edge associated with this connection */
|
||||
struct edge_t *edge; /* edge associated with this connection */
|
||||
|
||||
RSA *rsa_key; /* his public/private key */
|
||||
EVP_CIPHER *incipher; /* Cipher he will use to send data to us */
|
||||
|
|
@ -112,7 +109,7 @@ extern connection_t *new_connection(void);
|
|||
extern void free_connection(connection_t *);
|
||||
extern void connection_add(connection_t *);
|
||||
extern void connection_del(connection_t *);
|
||||
extern connection_t *lookup_connection(struct addrinfo *);
|
||||
extern connection_t *lookup_connection(ipv4_t, short unsigned int);
|
||||
extern void dump_connections(void);
|
||||
extern int read_connection_config(connection_t *);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
net.h -- generic header for device.c
|
||||
Copyright (C) 2001 Ivo Timmermans <zarq@iname.com>
|
||||
2001 Guus Sliepen <guus@sliepen.warande.net>
|
||||
Copyright (C) 2001-2002 Ivo Timmermans <zarq@iname.com>
|
||||
2001-2002 Guus Sliepen <guus@sliepen.warande.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -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.h,v 1.1.2.4 2001/10/31 12:50:24 guus Exp $
|
||||
$Id: device.h,v 1.1.2.5 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#ifndef __TINC_DEVICE_H__
|
||||
|
|
|
|||
52
src/edge.c
52
src/edge.c
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
edge.c -- edge tree management
|
||||
Copyright (C) 2000,2001 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2000,2001 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
Copyright (C) 2000-2002 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2000-2002 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -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.5 2001/11/16 12:21:49 zarq Exp $
|
||||
$Id: edge.c,v 1.1.2.6 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
|
@ -30,6 +30,7 @@
|
|||
#include <list.h>
|
||||
|
||||
#include "net.h" /* Don't ask. */
|
||||
#include "netutl.h"
|
||||
#include "config.h"
|
||||
#include "conf.h"
|
||||
#include <utils.h>
|
||||
|
|
@ -45,12 +46,12 @@ int edge_compare(edge_t *a, edge_t *b)
|
|||
{
|
||||
int result;
|
||||
|
||||
result = strcmp(a->from->name, b->from->name);
|
||||
result = strcmp(a->from.node->name, b->from.node->name);
|
||||
|
||||
if(result)
|
||||
return result;
|
||||
else
|
||||
return strcmp(a->to->name, b->to->name);
|
||||
return strcmp(a->to.node->name, b->to.node->name);
|
||||
}
|
||||
|
||||
/* Evil edge_compare() from a parallel universe ;)
|
||||
|
|
@ -59,7 +60,7 @@ int edge_compare(edge_t *a, edge_t *b)
|
|||
{
|
||||
int result;
|
||||
|
||||
return (result = strcmp(a->from->name, b->from->name)) || (result = strcmp(a->to->name, b->to->name)), result;
|
||||
return (result = strcmp(a->from.node->name, b->from.node->name)) || (result = strcmp(a->to.node->name, b->to.node->name)), result;
|
||||
}
|
||||
|
||||
*/
|
||||
|
|
@ -69,15 +70,15 @@ int edge_name_compare(edge_t *a, edge_t *b)
|
|||
int result;
|
||||
char *name_a1, *name_a2, *name_b1, *name_b2;
|
||||
|
||||
if(strcmp(a->from->name, a->to->name) < 0)
|
||||
name_a1 = a->from->name, name_a2 = a->to->name;
|
||||
if(strcmp(a->from.node->name, a->to.node->name) < 0)
|
||||
name_a1 = a->from.node->name, name_a2 = a->to.node->name;
|
||||
else
|
||||
name_a1 = a->to->name, name_a2 = a->from->name;
|
||||
name_a1 = a->to.node->name, name_a2 = a->from.node->name;
|
||||
|
||||
if(strcmp(b->from->name, b->to->name) < 0)
|
||||
name_b1 = b->from->name, name_b2 = b->to->name;
|
||||
if(strcmp(b->from.node->name, b->to.node->name) < 0)
|
||||
name_b1 = b->from.node->name, name_b2 = b->to.node->name;
|
||||
else
|
||||
name_b1 = b->to->name, name_b2 = b->from->name;
|
||||
name_b1 = b->to.node->name, name_b2 = b->from.node->name;
|
||||
|
||||
result = strcmp(name_a1, name_b1);
|
||||
|
||||
|
|
@ -151,8 +152,8 @@ void edge_add(edge_t *e)
|
|||
cp
|
||||
avl_insert(edge_tree, e);
|
||||
avl_insert(edge_weight_tree, e);
|
||||
avl_insert(e->from->edge_tree, e);
|
||||
avl_insert(e->to->edge_tree, e);
|
||||
avl_insert(e->from.node->edge_tree, e);
|
||||
avl_insert(e->to.node->edge_tree, e);
|
||||
cp
|
||||
}
|
||||
|
||||
|
|
@ -161,8 +162,8 @@ void edge_del(edge_t *e)
|
|||
cp
|
||||
avl_delete(edge_tree, e);
|
||||
avl_delete(edge_weight_tree, e);
|
||||
avl_delete(e->from->edge_tree, e);
|
||||
avl_delete(e->to->edge_tree, e);
|
||||
avl_delete(e->from.node->edge_tree, e);
|
||||
avl_delete(e->to.node->edge_tree, e);
|
||||
cp
|
||||
}
|
||||
|
||||
|
|
@ -170,16 +171,16 @@ edge_t *lookup_edge(node_t *from, node_t *to)
|
|||
{
|
||||
edge_t v, *result;
|
||||
cp
|
||||
v.from = from;
|
||||
v.to = to;
|
||||
v.from.node = from;
|
||||
v.to.node = to;
|
||||
|
||||
result = avl_search(edge_tree, &v);
|
||||
|
||||
if(result)
|
||||
return result;
|
||||
cp
|
||||
v.from = to;
|
||||
v.to = from;
|
||||
v.from.node = to;
|
||||
v.to.node = from;
|
||||
|
||||
return avl_search(edge_tree, &v);
|
||||
}
|
||||
|
|
@ -188,14 +189,21 @@ void dump_edges(void)
|
|||
{
|
||||
avl_node_t *node;
|
||||
edge_t *e;
|
||||
char *from_address, *to_address;
|
||||
cp
|
||||
syslog(LOG_DEBUG, _("Edges:"));
|
||||
|
||||
for(node = edge_tree->head; node; node = node->next)
|
||||
{
|
||||
e = (edge_t *)node->data;
|
||||
syslog(LOG_DEBUG, _(" %s - %s options %ld weight %d"),
|
||||
e->from->name, e->to->name, e->options, e->weight);
|
||||
from_address = address2str(e->from.address);
|
||||
to_address = address2str(e->to.address);
|
||||
syslog(LOG_DEBUG, _(" %s at %s port %hd - %s at %s port %hd options %ld weight %d"),
|
||||
e->from.node->name, from_address, e->from.port,
|
||||
e->to.node->name, to_address, e->to.port,
|
||||
e->options, e->weight);
|
||||
free(from_address);
|
||||
free(to_address);
|
||||
}
|
||||
|
||||
syslog(LOG_DEBUG, _("End of edges."));
|
||||
|
|
|
|||
16
src/edge.h
16
src/edge.h
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
edge.h -- header for edge.c
|
||||
Copyright (C) 2001 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2001 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
Copyright (C) 2001-2002 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2001-2002 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
$Id: edge.h,v 1.1.2.4 2001/11/16 12:13:34 zarq Exp $
|
||||
$Id: edge.h,v 1.1.2.5 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#ifndef __TINC_EDGE_H__
|
||||
|
|
@ -28,18 +28,16 @@
|
|||
#include "node.h"
|
||||
#include "connection.h"
|
||||
|
||||
/* I don't know if halfconnection_t is useful... */
|
||||
|
||||
typedef struct halfconnection_t {
|
||||
struct node_t *node; /* node associated with this end of the connection */
|
||||
|
||||
struct addrinfo *address; /* real (internet) ip on this end of the meta connection */
|
||||
char *hostname; /* the hostname of real ip */
|
||||
ipv4_t address; /* real (internet) ip on this end of the meta connection */
|
||||
port_t port; /* port number of this end of the meta connection */
|
||||
} halfconnection_t;
|
||||
|
||||
typedef struct edge_t {
|
||||
struct node_t *from;
|
||||
struct node_t *to;
|
||||
struct halfconnection_t from;
|
||||
struct halfconnection_t to;
|
||||
|
||||
long int options; /* options turned on for this edge */
|
||||
int weight; /* weight of this edge */
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
device.c -- Interaction with FreeBSD tap device
|
||||
Copyright (C) 2001 Ivo Timmermans <itimmermans@bigfoot.com>,
|
||||
2001 Guus Sliepen <guus@sliepen.warande.net>
|
||||
Copyright (C) 2001-2002 Ivo Timmermans <itimmermans@bigfoot.com>,
|
||||
2001-2002 Guus Sliepen <guus@sliepen.warande.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -17,38 +17,59 @@
|
|||
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.1 2001/10/12 15:22:59 guus Exp $
|
||||
$Id: device.c,v 1.1.2.2 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <fcntl.h>
|
||||
#include <net/if.h>
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <utils.h>
|
||||
#include "conf.h"
|
||||
#include "net.h"
|
||||
#include "subnet.h"
|
||||
|
||||
#include "system.h"
|
||||
|
||||
#define DEFAULT_DEVICE "/dev/tap0"
|
||||
|
||||
int device_fd = -1;
|
||||
int device_type;
|
||||
char *device_fname;
|
||||
char *device;
|
||||
char *interface;
|
||||
char *device_info;
|
||||
|
||||
int device_total_in = 0;
|
||||
int device_total_out = 0;
|
||||
|
||||
*
|
||||
extern subnet_t mymac;
|
||||
|
||||
/*
|
||||
open the local ethertap device
|
||||
*/
|
||||
int setup_device(void)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
|
||||
cp
|
||||
if(!get_config_string(lookup_config(config_tree, "Device"), &device_fname)))
|
||||
device_fname = DEFAULT_DEVICE;
|
||||
if(!get_config_string(lookup_config(config_tree, "Device"), &device))
|
||||
device = DEFAULT_DEVICE;
|
||||
|
||||
if(!get_config_string(lookup_config(config_tree, "Interface"), &interface))
|
||||
interface = netname;
|
||||
cp
|
||||
if((device_fd = open(device_fname, O_RDWR | O_NONBLOCK)) < 0)
|
||||
if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0)
|
||||
{
|
||||
syslog(LOG_ERR, _("Could not open %s: %m"), device_fname);
|
||||
syslog(LOG_ERR, _("Could not open %s: %m"), device);
|
||||
return -1;
|
||||
}
|
||||
cp
|
||||
device_fd = device_fd;
|
||||
|
||||
/* Set default MAC address for ethertap devices */
|
||||
|
||||
|
|
@ -62,11 +83,17 @@ cp
|
|||
|
||||
device_info = _("FreeBSD tap device");
|
||||
|
||||
syslog(LOG_INFO, _("%s is a %s"), device_fname, device_info);
|
||||
syslog(LOG_INFO, _("%s is a %s"), device, device_info);
|
||||
cp
|
||||
return 0;
|
||||
}
|
||||
|
||||
void close_device(void)
|
||||
{
|
||||
cp
|
||||
close(device_fd);
|
||||
}
|
||||
|
||||
/*
|
||||
read, encrypt and send data that is
|
||||
available through the ethertap device
|
||||
|
|
@ -77,7 +104,7 @@ int read_packet(vpn_packet_t *packet)
|
|||
cp
|
||||
if((lenin = read(device_fd, packet->data, MTU)) <= 0)
|
||||
{
|
||||
syslog(LOG_ERR, _("Error while reading from %s %s: %m"), device_info, device_fname);
|
||||
syslog(LOG_ERR, _("Error while reading from %s %s: %m"), device_info, device);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -102,10 +129,19 @@ cp
|
|||
|
||||
if(write(device_fd, packet->data, packet->len) < 0)
|
||||
{
|
||||
syslog(LOG_ERR, _("Error while writing to %s %s: %m"), device_info, device_fname);
|
||||
syslog(LOG_ERR, _("Error while writing to %s %s: %m"), device_info, device);
|
||||
return -1;
|
||||
}
|
||||
|
||||
device_total_out += packet->len;
|
||||
cp
|
||||
}
|
||||
|
||||
void dump_device_stats(void)
|
||||
{
|
||||
cp
|
||||
syslog(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
|
||||
syslog(LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
|
||||
syslog(LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
|
||||
cp
|
||||
}
|
||||
|
|
|
|||
108
src/graph.c
108
src/graph.c
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
graph.c -- graph algorithms
|
||||
Copyright (C) 2001 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2001 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
Copyright (C) 2001-2002 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2001-2002 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -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.5 2001/10/31 12:50:24 guus Exp $
|
||||
$Id: graph.c,v 1.1.2.6 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
/* We need to generate two trees from the graph:
|
||||
|
|
@ -38,14 +38,24 @@
|
|||
|
||||
For the SSSP algorithm Dijkstra's seems to be a nice choice. Currently a
|
||||
simple breadth-first search is presented here.
|
||||
|
||||
The SSSP algorithm will also be used to determine whether nodes are directly,
|
||||
indirectly or not reachable from the source. It will also set the correct
|
||||
destination address and port of a node if possible.
|
||||
*/
|
||||
|
||||
#include <syslog.h>
|
||||
#include "config.h"
|
||||
#include <string.h>
|
||||
#if defined(HAVE_FREEBSD) || defined(HAVE_OPENBSD)
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <avl_tree.h>
|
||||
#include <utils.h>
|
||||
|
||||
#include "netutl.h"
|
||||
#include "node.h"
|
||||
#include "edge.h"
|
||||
#include "connection.h"
|
||||
|
|
@ -67,6 +77,11 @@ void mst_kruskal(void)
|
|||
int safe_edges = 0;
|
||||
int skipped;
|
||||
|
||||
/* Do we have something to do at all? */
|
||||
|
||||
if(!edge_weight_tree->head)
|
||||
return;
|
||||
|
||||
/* Clear visited status on nodes */
|
||||
|
||||
for(node = node_tree->head; node; node = node->next)
|
||||
|
|
@ -78,7 +93,7 @@ void mst_kruskal(void)
|
|||
|
||||
/* Starting point */
|
||||
|
||||
((edge_t *)edge_weight_tree->head->data)->from->status.visited = 1;
|
||||
((edge_t *)edge_weight_tree->head->data)->from.node->status.visited = 1;
|
||||
|
||||
/* Clear MST status on connections */
|
||||
|
||||
|
|
@ -95,14 +110,14 @@ void mst_kruskal(void)
|
|||
next = node->next;
|
||||
e = (edge_t *)node->data;
|
||||
|
||||
if(e->from->status.visited == e->to->status.visited)
|
||||
if(e->from.node->status.visited == e->to.node->status.visited)
|
||||
{
|
||||
skipped = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
e->from->status.visited = 1;
|
||||
e->to->status.visited = 1;
|
||||
e->from.node->status.visited = 1;
|
||||
e->to.node->status.visited = 1;
|
||||
if(e->connection)
|
||||
e->connection->status.mst = 1;
|
||||
|
||||
|
|
@ -120,11 +135,12 @@ void mst_kruskal(void)
|
|||
Running time: O(E)
|
||||
*/
|
||||
|
||||
void sssp_bfs(int prune)
|
||||
void sssp_bfs(void)
|
||||
{
|
||||
avl_node_t *node, *from, *next, *to;
|
||||
edge_t *e;
|
||||
node_t *n, *check;
|
||||
node_t *n;
|
||||
halfconnection_t to_hc, from_hc;
|
||||
avl_tree_t *todo_tree;
|
||||
|
||||
todo_tree = avl_alloc_tree(NULL, NULL);
|
||||
|
|
@ -150,46 +166,82 @@ void sssp_bfs(int prune)
|
|||
|
||||
while(todo_tree->head)
|
||||
{
|
||||
for(from = todo_tree->head; from; from = next)
|
||||
for(from = todo_tree->head; from; from = next) /* "from" is the node from which we start */
|
||||
{
|
||||
next = from->next;
|
||||
n = (node_t *)from->data;
|
||||
|
||||
for(to = n->edge_tree->head; to; to = to->next)
|
||||
for(to = n->edge_tree->head; to; to = to->next) /* "to" is the edge connected to "from" */
|
||||
{
|
||||
e = (edge_t *)to->data;
|
||||
|
||||
if(e->from == n)
|
||||
check = e->to;
|
||||
if(e->from.node == n) /* "from_hc" is the halfconnection with .node == from */
|
||||
to_hc = e->to, from_hc = e->from;
|
||||
else
|
||||
check = e->from;
|
||||
to_hc = e->from, from_hc = e->to;
|
||||
|
||||
if(!check->status.visited)
|
||||
if(!to_hc.node->status.visited)
|
||||
{
|
||||
check->status.visited = 1;
|
||||
check->nexthop = (n->nexthop == myself) ? check : n->nexthop;
|
||||
check->via = (e->options & OPTION_INDIRECT || n->via != n) ? n->via : check;
|
||||
to_hc.node->status.visited = 1;
|
||||
to_hc.node->nexthop = (n->nexthop == myself) ? to_hc.node : n->nexthop;
|
||||
to_hc.node->via = (e->options & OPTION_INDIRECT || n->via != n) ? n->via : to_hc.node;
|
||||
to_hc.node->options = e->options;
|
||||
if(to_hc.node->address != to_hc.address || to_hc.node->port != to_hc.port)
|
||||
{
|
||||
node = avl_unlink(node_udp_tree, to_hc.node);
|
||||
to_hc.node->address = to_hc.address;
|
||||
to_hc.node->port = to_hc.port;
|
||||
if(to_hc.node->hostname)
|
||||
free(to_hc.node->hostname);
|
||||
to_hc.node->hostname = hostlookup(htonl(to_hc.address));
|
||||
avl_insert_node(node_udp_tree, node);
|
||||
}
|
||||
to_hc.node->port = to_hc.port;
|
||||
node = avl_alloc_node();
|
||||
node->data = check;
|
||||
node->data = to_hc.node;
|
||||
avl_insert_before(todo_tree, from, node);
|
||||
}
|
||||
}
|
||||
|
||||
avl_delete_node(todo_tree, from);
|
||||
avl_delete_node(todo_tree, from);
|
||||
}
|
||||
}
|
||||
|
||||
avl_free_tree(todo_tree);
|
||||
|
||||
/* Nodes we haven't visited are unreachable, prune them. */
|
||||
/* Check reachability status. */
|
||||
|
||||
if(prune)
|
||||
for(node = node_tree->head; node; node = next)
|
||||
for(node = node_tree->head; node; node = next)
|
||||
{
|
||||
next = node->next;
|
||||
n = (node_t *)node->data;
|
||||
|
||||
if(n->status.visited)
|
||||
{
|
||||
next = node->next;
|
||||
n = (node_t *)node->data;
|
||||
|
||||
if(n->status.visited == 0)
|
||||
node_del(n);
|
||||
if(!n->status.reachable)
|
||||
{
|
||||
if(debug_lvl >= DEBUG_TRAFFIC)
|
||||
syslog(LOG_DEBUG, _("Node %s (%s) became reachable"), n->name, n->hostname);
|
||||
n->status.reachable = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(n->status.reachable)
|
||||
{
|
||||
if(debug_lvl >= DEBUG_TRAFFIC)
|
||||
syslog(LOG_DEBUG, _("Node %s (%s) became unreachable"), n->name, n->hostname);
|
||||
n->status.reachable = 0;
|
||||
n->status.validkey = 0;
|
||||
n->status.waitingforkey = 0;
|
||||
n->sent_seqno = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void graph(void)
|
||||
{
|
||||
mst_kruskal();
|
||||
sssp_bfs();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
graph.h -- header for graph.c
|
||||
Copyright (C) 2001 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2001 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
Copyright (C) 2001-2002 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2001-2002 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -17,8 +17,9 @@
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
$Id: graph.h,v 1.1.2.2 2001/10/31 12:50:24 guus Exp $
|
||||
$Id: graph.h,v 1.1.2.3 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
extern void graph(void);
|
||||
extern void mst_kruskal(void);
|
||||
extern void sssp_bfs(int);
|
||||
extern void sssp_bfs(void);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
device.c -- Interaction with Linux ethertap and tun/tap device
|
||||
Copyright (C) 2001 Ivo Timmermans <itimmermans@bigfoot.com>,
|
||||
2001 Guus Sliepen <guus@sliepen.warande.net>
|
||||
Copyright (C) 2001-2002 Ivo Timmermans <itimmermans@bigfoot.com>,
|
||||
2001-2002 Guus Sliepen <guus@sliepen.warande.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -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.4 2001/10/31 12:50:24 guus Exp $
|
||||
$Id: device.c,v 1.1.2.5 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
|
@ -63,7 +63,7 @@ char *device_info;
|
|||
int device_total_in = 0;
|
||||
int device_total_out = 0;
|
||||
|
||||
subnet_t mymac;
|
||||
extern subnet_t mymac;
|
||||
|
||||
/*
|
||||
open the local ethertap device
|
||||
|
|
@ -158,9 +158,7 @@ cp
|
|||
}
|
||||
else /* ethertap */
|
||||
{
|
||||
struct iovec vector[2] = {{&packet->len, 2}, {packet->data, MTU}};
|
||||
|
||||
if((lenin = readv(device_fd, vector, 2)) <= 0)
|
||||
if((lenin = read(device_fd, packet->data - 2, MTU + 2)) <= 0)
|
||||
{
|
||||
syslog(LOG_ERR, _("Error while reading from %s %s: %m"), device_info, device);
|
||||
return -1;
|
||||
|
|
@ -197,9 +195,8 @@ cp
|
|||
}
|
||||
else/* ethertap */
|
||||
{
|
||||
struct iovec vector[2] = {{&packet->len, 2}, {packet->data, MTU}};
|
||||
|
||||
if(writev(device_fd, vector, 2) < 0)
|
||||
*(short int *)(packet->data - 2) = packet->len;
|
||||
if(write(device_fd, packet->data - 2, packet->len + 2) < 0)
|
||||
{
|
||||
syslog(LOG_ERR, _("Can't write to %s %s: %m"), device_info, device);
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
meta.c -- handle the meta communication
|
||||
Copyright (C) 2000,2001 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2000,2001 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
Copyright (C) 2000-2002 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2000-2002 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -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.21 2001/10/27 12:13:17 guus Exp $
|
||||
$Id: meta.c,v 1.1.2.22 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
meta.h -- header for meta.c
|
||||
Copyright (C) 2000,2001 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2000,2001 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
Copyright (C) 2000-2002 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2000-2002 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -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.h,v 1.1.2.5 2001/01/07 17:08:58 guus Exp $
|
||||
$Id: meta.h,v 1.1.2.6 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#ifndef __TINC_META_H__
|
||||
|
|
|
|||
60
src/net.h
60
src/net.h
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
net.h -- header for net.c
|
||||
Copyright (C) 1998-2001 Ivo Timmermans <zarq@iname.com>
|
||||
2000,2001 Guus Sliepen <guus@sliepen.warande.net>
|
||||
Copyright (C) 1998-2002 Ivo Timmermans <zarq@iname.com>
|
||||
2000-2002 Guus Sliepen <guus@sliepen.warande.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
$Id: net.h,v 1.9.4.37 2001/11/16 12:08:38 zarq Exp $
|
||||
$Id: net.h,v 1.9.4.38 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#ifndef __TINC_NET_H__
|
||||
|
|
@ -27,41 +27,35 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#define MAXSIZE 1700 /* should be a bit more than the MTU for the tapdevice */
|
||||
#define MTU 1600
|
||||
#define SALTLEN 2 /* to spice things up for the NSA... */
|
||||
#define MTU 1514 /* 1500 bytes payload + 14 bytes ethernet header */
|
||||
#define MAXSIZE 1600 /* MTU + header (seqno) and trailer (CBC padding and HMAC) */
|
||||
|
||||
#define MAC_ADDR_S "%02x:%02x:%02x:%02x:%02x:%02x"
|
||||
#define MAC_ADDR_V(x) ((unsigned char*)&(x))[0],((unsigned char*)&(x))[1], \
|
||||
((unsigned char*)&(x))[2],((unsigned char*)&(x))[3], \
|
||||
((unsigned char*)&(x))[4],((unsigned char*)&(x))[5]
|
||||
|
||||
#define IP_ADDR_S "%d.%d.%d.%d"
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
# define IP_ADDR_V(x) ((unsigned char*)&(x))[0],((unsigned char*)&(x))[1], \
|
||||
((unsigned char*)&(x))[2],((unsigned char*)&(x))[3]
|
||||
#else
|
||||
# define IP_ADDR_V(x) ((unsigned char*)&(x))[3],((unsigned char*)&(x))[2], \
|
||||
((unsigned char*)&(x))[1],((unsigned char*)&(x))[0]
|
||||
#endif
|
||||
|
||||
#define MAXBUFSIZE 4096 /* Probably way too much, but it must fit every possible request. */
|
||||
|
||||
/* tap types */
|
||||
#define TAP_TYPE_ETHERTAP 0
|
||||
#define TAP_TYPE_TUNTAP 1
|
||||
#define MAXBUFSIZE 2048 /* Probably way too much, but it must fit every possible request. */
|
||||
|
||||
typedef struct mac_t
|
||||
{
|
||||
unsigned char x[6];
|
||||
} mac_t;
|
||||
|
||||
typedef unsigned long ipv4_t;
|
||||
|
||||
typedef struct ip_mask_t {
|
||||
ipv4_t address;
|
||||
ipv4_t mask;
|
||||
} ip_mask_t;
|
||||
|
||||
typedef struct ipv6_t
|
||||
{
|
||||
unsigned short x[8];
|
||||
} ipv6_t;
|
||||
|
||||
typedef unsigned short port_t;
|
||||
|
||||
typedef short length_t;
|
||||
|
||||
typedef struct vpn_packet_t {
|
||||
length_t len; /* the actual number of bytes in the `data' field */
|
||||
unsigned char salt[SALTLEN]; /* two bytes of randomness */
|
||||
unsigned int seqno; /* 32 bits sequence number (network byte order of course) */
|
||||
unsigned char data[MAXSIZE];
|
||||
} vpn_packet_t;
|
||||
|
||||
|
|
@ -76,11 +70,16 @@ typedef struct packet_queue_t {
|
|||
queue_element_t *tail;
|
||||
} packet_queue_t;
|
||||
|
||||
typedef struct outgoing_t {
|
||||
char *name;
|
||||
int timeout;
|
||||
} outgoing_t;
|
||||
|
||||
extern int maxtimeout;
|
||||
extern int seconds_till_retry;
|
||||
|
||||
extern char *request_name[256];
|
||||
extern char *status_text[10];
|
||||
extern char *request_name[];
|
||||
extern char *status_text[];
|
||||
|
||||
#include "connection.h" /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
|
||||
|
||||
|
|
@ -89,11 +88,12 @@ extern void receive_packet(struct node_t *, vpn_packet_t *);
|
|||
extern void receive_tcppacket(struct connection_t *, char *, int);
|
||||
extern void broadcast_packet(struct node_t *, vpn_packet_t *);
|
||||
extern int setup_network_connections(void);
|
||||
extern void setup_outgoing_connection(struct outgoing_t *);
|
||||
extern void try_outgoing_connections(void);
|
||||
extern void close_network_connections(void);
|
||||
extern void main_loop(void);
|
||||
extern void terminate_connection(connection_t *, int);
|
||||
extern void flush_queue(struct node_t *);
|
||||
extern int read_rsa_public_key(struct connection_t *);
|
||||
extern RETSIGTYPE try_outgoing_connections(int);
|
||||
|
||||
#endif /* __TINC_NET_H__ */
|
||||
|
|
|
|||
25
src/node.c
25
src/node.c
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
node.c -- node tree management
|
||||
Copyright (C) 2001 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2001 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
Copyright (C) 2001-2002 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2001-2002 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -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.7 2001/11/16 17:39:38 zarq Exp $
|
||||
$Id: node.c,v 1.1.2.8 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
|
@ -47,10 +47,13 @@ int node_udp_compare(node_t *a, node_t *b)
|
|||
{
|
||||
if(a->address < b->address)
|
||||
return -1;
|
||||
else if (a->address > b->address)
|
||||
if (a->address > b->address)
|
||||
return 1;
|
||||
else
|
||||
return a->port - b->port;
|
||||
if (a->port < b->port)
|
||||
return -1;
|
||||
if (a->port > b->port)
|
||||
return 1;
|
||||
return (a->name && b->name)?strcmp(a->name, b->name):0;
|
||||
}
|
||||
|
||||
void init_nodes(void)
|
||||
|
|
@ -140,11 +143,13 @@ cp
|
|||
return avl_search(node_tree, &n);
|
||||
}
|
||||
|
||||
node_t *lookup_node_udp(struct addrinfo *address)
|
||||
node_t *lookup_node_udp(ipv4_t address, port_t port)
|
||||
{
|
||||
node_t n;
|
||||
cp
|
||||
n.name = NULL;
|
||||
n.address = address;
|
||||
n.port = port;
|
||||
return avl_search(node_udp_tree, &n);
|
||||
}
|
||||
|
||||
|
|
@ -158,9 +163,9 @@ cp
|
|||
for(node = node_tree->head; node; node = node->next)
|
||||
{
|
||||
n = (node_t *)node->data;
|
||||
syslog(LOG_DEBUG, _(" %s at %s port %s options %ld status %04x nexthop %s via %s"),
|
||||
n->name, n->hostname, n->port, n->options,
|
||||
n->status, n->nexthop->name, n->via->name);
|
||||
syslog(LOG_DEBUG, _(" %s at %s port %hd cipher %d digest %d maclength %d options %ld status %04x nexthop %s via %s"),
|
||||
n->name, n->hostname, n->port, n->cipher?n->cipher->nid:0, n->digest?n->digest->type:0, n->maclength, n->options,
|
||||
n->status, n->nexthop?n->nexthop->name:"-", n->via?n->via->name:"-");
|
||||
}
|
||||
|
||||
syslog(LOG_DEBUG, _("End of nodes."));
|
||||
|
|
|
|||
25
src/node.h
25
src/node.h
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
node.h -- header for node.c
|
||||
Copyright (C) 2001 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2001 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
Copyright (C) 2001-2002 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2001-2002 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
$Id: node.h,v 1.1.2.9 2001/11/16 15:56:44 zarq Exp $
|
||||
$Id: node.h,v 1.1.2.10 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#ifndef __TINC_NODE_H__
|
||||
|
|
@ -33,23 +33,27 @@ typedef struct node_status_t {
|
|||
int validkey:1; /* 1 if we currently have a valid key for him */
|
||||
int waitingforkey:1; /* 1 if we already sent out a request */
|
||||
int visited:1; /* 1 if this node has been visited by one of the graph algorithms */
|
||||
int unused:28;
|
||||
int reachable:1; /* 1 if this node is reachable in the graph */
|
||||
int unused:27;
|
||||
} node_status_t;
|
||||
|
||||
typedef struct node_t {
|
||||
char *name; /* name of this node */
|
||||
long int options; /* options turned on for this node */
|
||||
|
||||
struct addrinfo *address; /* his real (internet) ip to send UDP packets to */
|
||||
char *port; /* string representation of the port number */
|
||||
ipv4_t address; /* his real (internet) ip to send UDP packets to */
|
||||
port_t port; /* port number of UDP connection */
|
||||
char *hostname; /* the hostname of its real ip */
|
||||
|
||||
struct node_status_t status;
|
||||
|
||||
EVP_CIPHER *cipher; /* Cipher type for UDP packets */
|
||||
const EVP_CIPHER *cipher; /* Cipher type for UDP packets */
|
||||
char *key; /* Cipher key and iv */
|
||||
int keylength; /* Cipher key and iv length*/
|
||||
|
||||
const EVP_MD *digest; /* Digest type for MAC */
|
||||
int maclength; /* Length of MAC */
|
||||
|
||||
list_t *queue; /* Queue for packets awaiting to be encrypted */
|
||||
|
||||
struct node_t *nexthop; /* nearest node from us to him */
|
||||
|
|
@ -60,10 +64,14 @@ typedef struct node_t {
|
|||
avl_tree_t *edge_tree; /* Edges with this node as one of the endpoints */
|
||||
|
||||
struct connection_t *connection; /* Connection associated with this node (if a direct connection exists) */
|
||||
|
||||
unsigned int sent_seqno; /* Sequence number last sent to this node */
|
||||
unsigned int received_seqno; /* Sequence number last received from this node */
|
||||
} node_t;
|
||||
|
||||
extern struct node_t *myself;
|
||||
extern avl_tree_t *node_tree;
|
||||
extern avl_tree_t *node_udp_tree;
|
||||
|
||||
extern void init_nodes(void);
|
||||
extern void exit_nodes(void);
|
||||
|
|
@ -72,8 +80,7 @@ extern void free_node(node_t *n);
|
|||
extern void node_add(node_t *n);
|
||||
extern void node_del(node_t *n);
|
||||
extern node_t *lookup_node(char *);
|
||||
extern node_t *lookup_node_udp(struct addrinfo *);
|
||||
extern node_t *lookup_node_udp(ipv4_t, port_t);
|
||||
extern void dump_nodes(void);
|
||||
|
||||
|
||||
#endif /* __TINC_NODE_H__ */
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
device.c -- Interaction with OpenBSD tun device
|
||||
Copyright (C) 2001 Ivo Timmermans <itimmermans@bigfoot.com>,
|
||||
2001 Guus Sliepen <guus@sliepen.warande.net>
|
||||
Copyright (C) 2001-2002 Ivo Timmermans <itimmermans@bigfoot.com>,
|
||||
2001-2002 Guus Sliepen <guus@sliepen.warande.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -17,9 +17,30 @@
|
|||
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.2 2001/10/12 15:52:03 guus Exp $
|
||||
$Id: device.c,v 1.1.2.3 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <fcntl.h>
|
||||
#include <net/if.h>
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <utils.h>
|
||||
#include "conf.h"
|
||||
#include "net.h"
|
||||
#include "subnet.h"
|
||||
|
||||
#include "system.h"
|
||||
|
||||
#define DEFAULT_DEVICE "/dev/tun0"
|
||||
|
||||
#define DEVICE_TYPE_ETHERTAP 0
|
||||
|
|
@ -27,24 +48,29 @@
|
|||
|
||||
int device_fd = -1;
|
||||
int device_type;
|
||||
char *device_fname;
|
||||
char *device;
|
||||
char *interface;
|
||||
char *device_info;
|
||||
|
||||
int device_total_in = 0;
|
||||
int device_total_out = 0;
|
||||
|
||||
extern subnet_t mymac;
|
||||
|
||||
/*
|
||||
open the local ethertap device
|
||||
*/
|
||||
int setup_device(void)
|
||||
{
|
||||
if(!get_config_string(lookup_config(config_tree, "Device"), &device_fname)))
|
||||
device_fname = DEFAULT_DEVICE;
|
||||
if(!get_config_string(lookup_config(config_tree, "Device"), &device))
|
||||
device = DEFAULT_DEVICE;
|
||||
|
||||
if(!get_config_string(lookup_config(config_tree, "Interface"), &interface))
|
||||
interface = netname;
|
||||
cp
|
||||
if((device_fd = open(device_fname, O_RDWR | O_NONBLOCK)) < 0)
|
||||
if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0)
|
||||
{
|
||||
syslog(LOG_ERR, _("Could not open %s: %m"), device_fname);
|
||||
syslog(LOG_ERR, _("Could not open %s: %m"), device);
|
||||
return -1;
|
||||
}
|
||||
cp
|
||||
|
|
@ -60,28 +86,35 @@ cp
|
|||
|
||||
device_info = _("OpenBSD tun device");
|
||||
|
||||
syslog(LOG_INFO, _("%s is a %s"), device_fname, device_info);
|
||||
syslog(LOG_INFO, _("%s is a %s"), device, device_info);
|
||||
cp
|
||||
return 0;
|
||||
}
|
||||
|
||||
void close_device(void)
|
||||
{
|
||||
cp
|
||||
close(device_fd);
|
||||
cp
|
||||
}
|
||||
|
||||
int read_packet(vpn_packet_t *packet)
|
||||
{
|
||||
int lenin;
|
||||
u_int32_t type;
|
||||
cp
|
||||
struct iovec vector[2] = {{&type, sizeof(type)}, {packet->data + 14, MTU - 14}};
|
||||
cp
|
||||
|
||||
if((lenin = readv(device_fd, vector, 2)) <= 0)
|
||||
{
|
||||
syslog(LOG_ERR, _("Error while reading from %s %s: %m"), device_info, device_fname);
|
||||
syslog(LOG_ERR, _("Error while reading from %s %s: %m"), device_info, device);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(vp->data, mymac.net.mac.address.x, 6);
|
||||
memcpy(vp->data + 6, mymac.net.mac.address.x, 6);
|
||||
vp->data[12] = 0x08;
|
||||
vp->data[13] = 0x00;
|
||||
memcpy(packet->data, mymac.net.mac.address.x, 6);
|
||||
memcpy(packet->data + 6, mymac.net.mac.address.x, 6);
|
||||
packet->data[12] = 0x08;
|
||||
packet->data[13] = 0x00;
|
||||
|
||||
packet->len = lenin + 10;
|
||||
|
||||
|
|
@ -89,7 +122,7 @@ cp
|
|||
|
||||
if(debug_lvl >= DEBUG_TRAFFIC)
|
||||
{
|
||||
syslog(LOG_DEBUG, _("Read packet of %d bytes from %s"), device_info, packet.len);
|
||||
syslog(LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len, device_info);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -99,20 +132,32 @@ cp
|
|||
int write_packet(vpn_packet_t *packet)
|
||||
{
|
||||
u_int32_t type = htonl(AF_INET);
|
||||
struct iovec vector[2];
|
||||
cp
|
||||
if(debug_lvl >= DEBUG_TRAFFIC)
|
||||
syslog(LOG_DEBUG, _("Writing packet of %d bytes to %s"),
|
||||
packet->len, device_info);
|
||||
|
||||
|
||||
struct iovec vector[2] = {{&type, sizeof(type)}, {packet->data + 14, packet->len - 14}};
|
||||
vector[0].iov_base = &type;
|
||||
vector[0].iov_len = sizeof(type);
|
||||
vector[1].iov_base = packet->data + 14;
|
||||
vector[1].iov_len = packet->len - 14;
|
||||
|
||||
if(writev(device_fd, vector, 2) < 0)
|
||||
{
|
||||
syslog(LOG_ERR, _("Can't write to %s %s: %m"), device_info, packet.len);
|
||||
syslog(LOG_ERR, _("Can't write to %s %s: %m"), device_info, device);
|
||||
return -1;
|
||||
}
|
||||
|
||||
device_total_out += packet->len;
|
||||
cp
|
||||
}
|
||||
|
||||
void dump_device_stats(void)
|
||||
{
|
||||
cp
|
||||
syslog(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
|
||||
syslog(LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
|
||||
syslog(LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
|
||||
cp
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
process.c -- process management functions
|
||||
Copyright (C) 1999-2001 Ivo Timmermans <itimmermans@bigfoot.com>,
|
||||
2000,2001 Guus Sliepen <guus@sliepen.warande.net>
|
||||
Copyright (C) 1999-2002 Ivo Timmermans <itimmermans@bigfoot.com>,
|
||||
2000-2002 Guus Sliepen <guus@sliepen.warande.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -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.32 2001/11/03 22:53:02 guus Exp $
|
||||
$Id: process.c,v 1.1.2.33 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
|
@ -59,6 +59,10 @@ sigset_t emptysigset;
|
|||
|
||||
static int saved_debug_lvl = 0;
|
||||
|
||||
extern int sighup;
|
||||
extern int sigalrm;
|
||||
extern int do_purge;
|
||||
|
||||
void memory_full(int size)
|
||||
{
|
||||
syslog(LOG_ERR, _("Memory exhausted (couldn't allocate %d bytes), exiting."), size);
|
||||
|
|
@ -342,6 +346,7 @@ sigsegv_handler(int a, siginfo_t *info, void *b)
|
|||
act.sa_mask = emptysigset;
|
||||
act.sa_flags = SA_SIGINFO;
|
||||
act.sa_sigaction = sigsegv_square;
|
||||
sigaction(SIGSEGV, &act, NULL);
|
||||
|
||||
close_network_connections();
|
||||
sleep(5);
|
||||
|
|
@ -351,7 +356,7 @@ sigsegv_handler(int a, siginfo_t *info, void *b)
|
|||
else
|
||||
{
|
||||
syslog(LOG_NOTICE, _("Not restarting."));
|
||||
exit(0);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -382,6 +387,14 @@ sigint_handler(int a, siginfo_t *info, void *b)
|
|||
}
|
||||
}
|
||||
|
||||
RETSIGTYPE
|
||||
sigalrm_handler(int a, siginfo_t *info, void *b)
|
||||
{
|
||||
if(debug_lvl > DEBUG_NOTHING)
|
||||
syslog(LOG_NOTICE, _("Got ALRM signal"));
|
||||
sigalrm = 1;
|
||||
}
|
||||
|
||||
RETSIGTYPE
|
||||
sigusr1_handler(int a, siginfo_t *info, void *b)
|
||||
{
|
||||
|
|
@ -397,6 +410,13 @@ sigusr2_handler(int a, siginfo_t *info, void *b)
|
|||
dump_subnets();
|
||||
}
|
||||
|
||||
RETSIGTYPE
|
||||
sigwinch_handler(int a, siginfo_t *info, void *b)
|
||||
{
|
||||
extern int do_purge;
|
||||
do_purge = 1;
|
||||
}
|
||||
|
||||
RETSIGTYPE
|
||||
unexpected_signal_handler(int a, siginfo_t *info, void *b)
|
||||
{
|
||||
|
|
@ -427,7 +447,8 @@ struct {
|
|||
{ SIGUSR1, sigusr1_handler },
|
||||
{ SIGUSR2, sigusr2_handler },
|
||||
{ SIGCHLD, ignore_signal_handler },
|
||||
{ SIGALRM, ignore_signal_handler },
|
||||
{ SIGALRM, sigalrm_handler },
|
||||
{ SIGWINCH, sigwinch_handler },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
|
|
@ -447,7 +468,7 @@ setup_signals(void)
|
|||
for(i = 0; i < NSIG; i++)
|
||||
{
|
||||
if(!do_detach)
|
||||
act.sa_sigaction = SIG_DFL;
|
||||
act.sa_sigaction = (void(*)(int, siginfo_t *, void *))SIG_DFL;
|
||||
else
|
||||
act.sa_sigaction = unexpected_signal_handler;
|
||||
sigaction(i, &act, NULL);
|
||||
|
|
@ -455,7 +476,7 @@ setup_signals(void)
|
|||
|
||||
/* If we didn't detach, allow coredumps */
|
||||
if(!do_detach)
|
||||
sighandlers[3].handler = SIG_DFL;
|
||||
sighandlers[3].handler = (void(*)(int, siginfo_t *, void *))SIG_DFL;
|
||||
|
||||
/* Then, for each known signal that we want to catch, assign a
|
||||
handler to the signal, with error checking this time. */
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
process.h -- header file for process.c
|
||||
Copyright (C) 1999-2001 Ivo Timmermans <itimmermans@bigfoot.com>,
|
||||
2000,2001 Guus Sliepen <guus@sliepen.warande.net>
|
||||
Copyright (C) 1999-2002 Ivo Timmermans <itimmermans@bigfoot.com>,
|
||||
2000-2002 Guus Sliepen <guus@sliepen.warande.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -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.h,v 1.1.2.9 2001/09/01 12:36:53 guus Exp $
|
||||
$Id: process.h,v 1.1.2.10 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#ifndef __TINC_PROCESS_H__
|
||||
|
|
|
|||
1392
src/protocol.c
1392
src/protocol.c
File diff suppressed because it is too large
Load diff
|
|
@ -17,7 +17,7 @@
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
$Id: protocol.h,v 1.5.4.24 2001/10/28 08:41:19 guus Exp $
|
||||
$Id: protocol.h,v 1.5.4.25 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#ifndef __TINC_PROTOCOL_H__
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
incompatible version have different protocols.
|
||||
*/
|
||||
|
||||
#define PROT_CURRENT 11
|
||||
#define PROT_CURRENT 12
|
||||
|
||||
/* Request numbers */
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ enum {
|
|||
ID = 0, METAKEY, CHALLENGE, CHAL_REPLY, ACK,
|
||||
STATUS, ERROR, TERMREQ,
|
||||
PING, PONG,
|
||||
ADD_NODE, DEL_NODE,
|
||||
// ADD_NODE, DEL_NODE,
|
||||
ADD_SUBNET, DEL_SUBNET,
|
||||
ADD_EDGE, DEL_EDGE,
|
||||
KEY_CHANGED, REQ_KEY, ANS_KEY,
|
||||
|
|
@ -53,33 +53,58 @@ enum {
|
|||
#define MAX_STRING_SIZE 1024
|
||||
#define MAX_STRING "%1024s"
|
||||
|
||||
extern int (*request_handlers[])(connection_t*);
|
||||
/* Basic functions */
|
||||
|
||||
extern int send_id(connection_t*);
|
||||
extern int send_metakey(connection_t*);
|
||||
extern int send_challenge(connection_t*);
|
||||
extern int send_chal_reply(connection_t*);
|
||||
extern int send_ack(connection_t*);
|
||||
extern int send_status(connection_t*, int, char*);
|
||||
extern int send_error(connection_t*, int, char*);
|
||||
extern int send_termreq(connection_t*);
|
||||
extern int send_ping(connection_t*);
|
||||
extern int send_pong(connection_t*);
|
||||
extern int send_add_node(connection_t*, node_t*);
|
||||
extern int send_del_node(connection_t*, node_t*);
|
||||
extern int send_add_subnet(connection_t*, subnet_t*);
|
||||
extern int send_del_subnet(connection_t*, subnet_t*);
|
||||
extern int send_add_edge(connection_t*, edge_t*);
|
||||
extern int send_del_edge(connection_t*, edge_t*);
|
||||
extern int send_key_changed(connection_t*, node_t*);
|
||||
extern int send_req_key(connection_t*, node_t*, node_t*);
|
||||
extern int send_ans_key(connection_t*, node_t*, node_t*, char*);
|
||||
extern int send_tcppacket(connection_t *, vpn_packet_t *);
|
||||
|
||||
/* Old functions */
|
||||
|
||||
extern int notify_others(connection_t *, connection_t *, int (*function)(connection_t*, connection_t*));
|
||||
extern int send_request(connection_t*, const char*, ...);
|
||||
extern int receive_request(connection_t *);
|
||||
extern int check_id(char *);
|
||||
|
||||
/* Requests */
|
||||
|
||||
extern int send_id(connection_t *);
|
||||
extern int send_metakey(connection_t *);
|
||||
extern int send_challenge(connection_t *);
|
||||
extern int send_chal_reply(connection_t *);
|
||||
extern int send_ack(connection_t *);
|
||||
extern int send_status(connection_t *, int, char *);
|
||||
extern int send_error(connection_t *, int, char *);
|
||||
extern int send_termreq(connection_t *);
|
||||
extern int send_ping(connection_t *);
|
||||
extern int send_pong(connection_t *);
|
||||
// extern int send_add_node(connection_t *, node_t *);
|
||||
// extern int send_del_node(connection_t *, node_t *);
|
||||
extern int send_add_subnet(connection_t *, subnet_t *);
|
||||
extern int send_del_subnet(connection_t *, subnet_t *);
|
||||
extern int send_add_edge(connection_t *, edge_t *);
|
||||
extern int send_del_edge(connection_t *, edge_t *);
|
||||
extern int send_key_changed(connection_t *, node_t *);
|
||||
extern int send_req_key(connection_t *, node_t *, node_t *);
|
||||
extern int send_ans_key(connection_t *, node_t *, node_t *);
|
||||
extern int send_tcppacket(connection_t *, vpn_packet_t *);
|
||||
|
||||
/* Request handlers */
|
||||
|
||||
extern int (*request_handlers[])(connection_t *);
|
||||
|
||||
extern int id_h(connection_t *);
|
||||
extern int metakey_h(connection_t *);
|
||||
extern int challenge_h(connection_t *);
|
||||
extern int chal_reply_h(connection_t *);
|
||||
extern int ack_h(connection_t *);
|
||||
extern int status_h(connection_t *);
|
||||
extern int error_h(connection_t *);
|
||||
extern int termreq_h(connection_t *);
|
||||
extern int ping_h(connection_t *);
|
||||
extern int pong_h(connection_t *);
|
||||
// extern int add_node_h(connection_t *);
|
||||
// extern int del_node_h(connection_t *);
|
||||
extern int add_subnet_h(connection_t *);
|
||||
extern int del_subnet_h(connection_t *);
|
||||
extern int add_edge_h(connection_t *);
|
||||
extern int del_edge_h(connection_t *);
|
||||
extern int key_changed_h(connection_t *);
|
||||
extern int req_key_h(connection_t *);
|
||||
extern int ans_key_h(connection_t *);
|
||||
extern int tcppacket_h(connection_t *);
|
||||
|
||||
#endif /* __TINC_PROTOCOL_H__ */
|
||||
|
|
|
|||
52
src/route.c
52
src/route.c
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
route.c -- routing
|
||||
Copyright (C) 2000,2001 Ivo Timmermans <itimmermans@bigfoot.com>,
|
||||
2000,2001 Guus Sliepen <guus@sliepen.warande.net>
|
||||
Copyright (C) 2000-2002 Ivo Timmermans <itimmermans@bigfoot.com>,
|
||||
2000-2002 Guus Sliepen <guus@sliepen.warande.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -17,17 +17,17 @@
|
|||
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.21 2001/11/16 17:40:50 zarq Exp $
|
||||
$Id: route.c,v 1.1.2.22 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef HAVE_FREEBSD
|
||||
#if defined(HAVE_FREEBSD) || defined(HAVE_OPENBSD)
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#ifdef HAVE_SOLARIS
|
||||
#if defined(HAVE_SOLARIS) || defined(HAVE_OPENBSD)
|
||||
#include <net/if.h>
|
||||
#define ETHER_ADDR_LEN 6
|
||||
#else
|
||||
|
|
@ -66,7 +66,7 @@ cp
|
|||
if(!subnet || subnet->owner!=myself)
|
||||
{
|
||||
if(debug_lvl >= DEBUG_TRAFFIC)
|
||||
syslog(LOG_INFO, _("Learned new MAC address %hhx:%hhx:%hhx:%hhx:%hhx:%hhx"),
|
||||
syslog(LOG_INFO, _("Learned new MAC address %hx:%hx:%hx:%hx:%hx:%hx"),
|
||||
address->x[0], address->x[1], address->x[2], address->x[3], address->x[4], address->x[5]);
|
||||
|
||||
subnet = new_subnet();
|
||||
|
|
@ -103,10 +103,26 @@ cp
|
|||
return NULL;
|
||||
}
|
||||
|
||||
node_t *route_ipv4(vpn_packet_t *packet)
|
||||
{
|
||||
ipv4_t dest;
|
||||
subnet_t *subnet;
|
||||
cp
|
||||
#ifdef HAVE_SOLARIS
|
||||
/* The other form gives bus errors on a SparcStation 20. */
|
||||
dest = ((packet->data[30] * 0x100 + packet->data[31]) * 0x100 + packet->data[32]) * 0x100 + packet->data[33];
|
||||
#else
|
||||
dest = ntohl(*((unsigned long*)(&packet->data[30])));
|
||||
#endif
|
||||
cp
|
||||
subnet = lookup_subnet_ipv4(&dest);
|
||||
cp
|
||||
if(!subnet)
|
||||
{
|
||||
if(debug_lvl >= DEBUG_TRAFFIC)
|
||||
{
|
||||
syslog(LOG_WARNING, _("Cannot route packet: unknown destination address %d.%d.%d.%d"),
|
||||
packet->data[30], packet->data[31], packet->data[32], packet->data[33]);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
|
@ -115,21 +131,25 @@ cp
|
|||
return subnet->owner;
|
||||
}
|
||||
|
||||
node_t *route_ip(vpn_packet_t *packet)
|
||||
node_t *route_ipv6(vpn_packet_t *packet)
|
||||
{
|
||||
struct addrinfo *dest;
|
||||
subnet_t *subnet;
|
||||
cp
|
||||
#warning FIXME
|
||||
memcpy(&dest, &packet->data[30], 0);
|
||||
|
||||
subnet = lookup_subnet_ip(&dest);
|
||||
subnet = lookup_subnet_ipv6((ipv6_t *)&packet->data[38]);
|
||||
cp
|
||||
if(!subnet)
|
||||
{
|
||||
if(debug_lvl >= DEBUG_TRAFFIC)
|
||||
{
|
||||
syslog(LOG_WARNING, _("Cannot route packet: unknown IP destination address"));
|
||||
syslog(LOG_WARNING, _("Cannot route packet: unknown IPv6 destination address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx"),
|
||||
ntohs(*(short unsigned int *)&packet->data[38]),
|
||||
ntohs(*(short unsigned int *)&packet->data[40]),
|
||||
ntohs(*(short unsigned int *)&packet->data[42]),
|
||||
ntohs(*(short unsigned int *)&packet->data[44]),
|
||||
ntohs(*(short unsigned int *)&packet->data[46]),
|
||||
ntohs(*(short unsigned int *)&packet->data[48]),
|
||||
ntohs(*(short unsigned int *)&packet->data[50]),
|
||||
ntohs(*(short unsigned int *)&packet->data[52]));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
|
@ -143,7 +163,7 @@ void route_arp(vpn_packet_t *packet)
|
|||
struct ether_arp *arp;
|
||||
subnet_t *subnet;
|
||||
unsigned char ipbuf[4];
|
||||
struct addrinfo *dest;
|
||||
ipv4_t dest;
|
||||
cp
|
||||
/* First, snatch the source address from the ARP packet */
|
||||
|
||||
|
|
@ -172,9 +192,9 @@ cp
|
|||
}
|
||||
|
||||
/* Check if the IP address exists on the VPN */
|
||||
#warning FIXME
|
||||
|
||||
dest = ntohl(*((unsigned long*)(arp->arp_tpa)));
|
||||
subnet = lookup_subnet_ip(&dest);
|
||||
subnet = lookup_subnet_ipv4(&dest);
|
||||
|
||||
if(!subnet)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
route.h -- header file for route.c
|
||||
Copyright (C) 2000,2001 Ivo Timmermans <zarq@iname.com>
|
||||
2000,2001 Guus Sliepen <guus@sliepen.warande.net>
|
||||
Copyright (C) 2000-2002 Ivo Timmermans <zarq@iname.com>
|
||||
2000-2002 Guus Sliepen <guus@sliepen.warande.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -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.h,v 1.1.2.4 2001/10/27 12:13:17 guus Exp $
|
||||
$Id: route.h,v 1.1.2.5 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#ifndef __TINC_ROUTE_H__
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
device.c -- Interaction with Solaris tun device
|
||||
Copyright (C) 2001 Ivo Timmermans <itimmermans@bigfoot.com>,
|
||||
2001 Guus Sliepen <guus@sliepen.warande.net>
|
||||
Copyright (C) 2001-2002 Ivo Timmermans <itimmermans@bigfoot.com>,
|
||||
2001-2002 Guus Sliepen <guus@sliepen.warande.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -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.3 2001/11/05 19:06:07 guus Exp $
|
||||
$Id: device.c,v 1.1.2.4 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
|
||||
|
|
@ -157,7 +157,7 @@ cp
|
|||
|
||||
if(debug_lvl >= DEBUG_TRAFFIC)
|
||||
{
|
||||
syslog(LOG_DEBUG, _("Read packet of %d bytes from %s"), device_info, packet->len);
|
||||
syslog(LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len, device_info);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
209
src/subnet.c
209
src/subnet.c
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
subnet.c -- handle subnet lookups and lists
|
||||
Copyright (C) 2000,2001 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2000,2001 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
Copyright (C) 2000-2002 Guus Sliepen <guus@sliepen.warande.net>,
|
||||
2000-2002 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -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.28 2001/10/30 12:59:12 guus Exp $
|
||||
$Id: subnet.c,v 1.1.2.29 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
|
@ -25,6 +25,10 @@
|
|||
#include <stdio.h>
|
||||
#include <syslog.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "conf.h"
|
||||
#include "net.h"
|
||||
|
|
@ -102,10 +106,12 @@ cp
|
|||
case SUBNET_IPV6:
|
||||
return subnet_compare_ipv6(a, b);
|
||||
default:
|
||||
syslog(LOG_ERR, _("subnet_compare() was called with unknown subnet type %d, restarting!"), a->type);
|
||||
sighup = 1;
|
||||
return 0;
|
||||
syslog(LOG_ERR, _("subnet_compare() was called with unknown subnet type %d, exitting!"), a->type);
|
||||
cp_trace();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Initialising trees */
|
||||
|
|
@ -178,65 +184,108 @@ cp
|
|||
|
||||
subnet_t *str2net(char *subnetstr)
|
||||
{
|
||||
int type;
|
||||
int i, l;
|
||||
subnet_t *subnet;
|
||||
cp
|
||||
if(sscanf(subnetstr, "%d,", &type) != 1)
|
||||
return NULL;
|
||||
unsigned short int x[6];
|
||||
cp
|
||||
subnet = new_subnet();
|
||||
cp
|
||||
switch(type)
|
||||
if(sscanf(subnetstr, "%hu.%hu.%hu.%hu/%d",
|
||||
&x[0],
|
||||
&x[1],
|
||||
&x[2],
|
||||
&x[3],
|
||||
&subnet->net.ipv4.masklength) == 5)
|
||||
{
|
||||
case SUBNET_MAC:
|
||||
if(sscanf(subnetstr, "%d,%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &subnet->type,
|
||||
&subnet->net.mac.address.x[0],
|
||||
&subnet->net.mac.address.x[1],
|
||||
&subnet->net.mac.address.x[2],
|
||||
&subnet->net.mac.address.x[3],
|
||||
&subnet->net.mac.address.x[4],
|
||||
&subnet->net.mac.address.x[5]) != 7)
|
||||
{
|
||||
free_subnet(subnet);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
case SUBNET_IPV4:
|
||||
if(sscanf(subnetstr, "%d,%lx/%lx", &subnet->type, &subnet->net.ipv4.address, &subnet->net.ipv4.mask) != 3)
|
||||
{
|
||||
free_subnet(subnet);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
case SUBNET_IPV6:
|
||||
if(sscanf(subnetstr, "%d,%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx/%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx", &subnet->type,
|
||||
&subnet->net.ipv6.address.x[0],
|
||||
&subnet->net.ipv6.address.x[1],
|
||||
&subnet->net.ipv6.address.x[2],
|
||||
&subnet->net.ipv6.address.x[3],
|
||||
&subnet->net.ipv6.address.x[4],
|
||||
&subnet->net.ipv6.address.x[5],
|
||||
&subnet->net.ipv6.address.x[6],
|
||||
&subnet->net.ipv6.address.x[7],
|
||||
&subnet->net.ipv6.mask.x[0],
|
||||
&subnet->net.ipv6.mask.x[1],
|
||||
&subnet->net.ipv6.mask.x[2],
|
||||
&subnet->net.ipv6.mask.x[3],
|
||||
&subnet->net.ipv6.mask.x[4],
|
||||
&subnet->net.ipv6.mask.x[5],
|
||||
&subnet->net.ipv6.mask.x[6],
|
||||
&subnet->net.ipv6.mask.x[7]) != 17)
|
||||
{
|
||||
free_subnet(subnet);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
free_subnet(subnet);
|
||||
return NULL;
|
||||
subnet->type = SUBNET_IPV4;
|
||||
subnet->net.ipv4.address = (((((x[0] << 8) + x[1]) << 8) + x[2]) << 8) + x[3];
|
||||
subnet->net.ipv4.mask = ~((1 << (32 - subnet->net.ipv4.masklength)) - 1);
|
||||
return subnet;
|
||||
}
|
||||
cp
|
||||
return subnet;
|
||||
|
||||
if(sscanf(subnetstr, "%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx/%d",
|
||||
&subnet->net.ipv6.address.x[0],
|
||||
&subnet->net.ipv6.address.x[1],
|
||||
&subnet->net.ipv6.address.x[2],
|
||||
&subnet->net.ipv6.address.x[3],
|
||||
&subnet->net.ipv6.address.x[4],
|
||||
&subnet->net.ipv6.address.x[5],
|
||||
&subnet->net.ipv6.address.x[6],
|
||||
&subnet->net.ipv6.address.x[7],
|
||||
&subnet->net.ipv6.masklength) == 9)
|
||||
{
|
||||
subnet->type = SUBNET_IPV6;
|
||||
for(l = subnet->net.ipv6.masklength, i = 0; i < 8; l -= 16, i++)
|
||||
{
|
||||
subnet->net.ipv6.address.x[i] = htons(subnet->net.ipv6.address.x[i]);
|
||||
if(l >= 16)
|
||||
subnet->net.ipv6.mask.x[i] = 65535;
|
||||
else if (l > 0)
|
||||
subnet->net.ipv6.mask.x[i] = htons(65536 - (1 << l));
|
||||
else
|
||||
subnet->net.ipv6.mask.x[i] = 0;
|
||||
}
|
||||
return subnet;
|
||||
}
|
||||
|
||||
if(sscanf(subnetstr, "%hu.%hu.%hu.%hu",
|
||||
&x[0],
|
||||
&x[1],
|
||||
&x[2],
|
||||
&x[3]) == 4)
|
||||
{
|
||||
subnet->type = SUBNET_IPV4;
|
||||
subnet->net.ipv4.address = (((((x[0] << 8) + x[1]) << 8) + x[2]) << 8) + x[3];
|
||||
subnet->net.ipv4.mask = ~0;
|
||||
subnet->net.ipv4.masklength = 32;
|
||||
return subnet;
|
||||
}
|
||||
|
||||
if(sscanf(subnetstr, "%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",
|
||||
&subnet->net.ipv6.address.x[0],
|
||||
&subnet->net.ipv6.address.x[1],
|
||||
&subnet->net.ipv6.address.x[2],
|
||||
&subnet->net.ipv6.address.x[3],
|
||||
&subnet->net.ipv6.address.x[4],
|
||||
&subnet->net.ipv6.address.x[5],
|
||||
&subnet->net.ipv6.address.x[6],
|
||||
&subnet->net.ipv6.address.x[7]) == 8)
|
||||
{
|
||||
subnet->type = SUBNET_IPV6;
|
||||
subnet->net.ipv6.masklength = 128;
|
||||
for(l = subnet->net.ipv6.masklength, i = 0; i < 8; l -= 16, i++)
|
||||
{
|
||||
subnet->net.ipv6.address.x[i] = htons(subnet->net.ipv6.address.x[i]);
|
||||
if(l >= 16)
|
||||
subnet->net.ipv6.mask.x[i] = 65535;
|
||||
else if (l > 0)
|
||||
subnet->net.ipv6.mask.x[i] = htons(65536 - (1 << l));
|
||||
else
|
||||
subnet->net.ipv6.mask.x[i] = 0;
|
||||
}
|
||||
return subnet;
|
||||
}
|
||||
|
||||
if(sscanf(subnetstr, "%hx:%hx:%hx:%hx:%hx:%hx",
|
||||
&x[0],
|
||||
&x[1],
|
||||
&x[2],
|
||||
&x[3],
|
||||
&x[4],
|
||||
&x[5]) == 6)
|
||||
{
|
||||
subnet->type = SUBNET_MAC;
|
||||
subnet->net.mac.address.x[0] = x[0];
|
||||
subnet->net.mac.address.x[1] = x[1];
|
||||
subnet->net.mac.address.x[2] = x[2];
|
||||
subnet->net.mac.address.x[3] = x[3];
|
||||
subnet->net.mac.address.x[4] = x[4];
|
||||
subnet->net.mac.address.x[5] = x[5];
|
||||
return subnet;
|
||||
}
|
||||
|
||||
free(subnet);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *net2str(subnet_t *subnet)
|
||||
|
|
@ -246,7 +295,7 @@ cp
|
|||
switch(subnet->type)
|
||||
{
|
||||
case SUBNET_MAC:
|
||||
asprintf(&netstr, "%d,%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", subnet->type,
|
||||
asprintf(&netstr, "%hx:%hx:%hx:%hx:%hx:%hx",
|
||||
subnet->net.mac.address.x[0],
|
||||
subnet->net.mac.address.x[1],
|
||||
subnet->net.mac.address.x[2],
|
||||
|
|
@ -255,26 +304,24 @@ cp
|
|||
subnet->net.mac.address.x[5]);
|
||||
break;
|
||||
case SUBNET_IPV4:
|
||||
asprintf(&netstr, "%d,%lx/%lx", subnet->type, subnet->net.ipv4.address, subnet->net.ipv4.mask);
|
||||
asprintf(&netstr, "%hu.%hu.%hu.%hu/%d",
|
||||
(unsigned short int)((subnet->net.ipv4.address >> 24) & 255),
|
||||
(unsigned short int)((subnet->net.ipv4.address >> 16) & 255),
|
||||
(unsigned short int)((subnet->net.ipv4.address >> 8) & 255),
|
||||
(unsigned short int)(subnet->net.ipv4.address & 255),
|
||||
subnet->net.ipv4.masklength);
|
||||
break;
|
||||
case SUBNET_IPV6:
|
||||
asprintf(&netstr, "%d,%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx/%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx", subnet->type,
|
||||
subnet->net.ipv6.address.x[0],
|
||||
subnet->net.ipv6.address.x[1],
|
||||
subnet->net.ipv6.address.x[2],
|
||||
subnet->net.ipv6.address.x[3],
|
||||
subnet->net.ipv6.address.x[4],
|
||||
subnet->net.ipv6.address.x[5],
|
||||
subnet->net.ipv6.address.x[6],
|
||||
subnet->net.ipv6.address.x[7],
|
||||
subnet->net.ipv6.mask.x[0],
|
||||
subnet->net.ipv6.mask.x[1],
|
||||
subnet->net.ipv6.mask.x[2],
|
||||
subnet->net.ipv6.mask.x[3],
|
||||
subnet->net.ipv6.mask.x[4],
|
||||
subnet->net.ipv6.mask.x[5],
|
||||
subnet->net.ipv6.mask.x[6],
|
||||
subnet->net.ipv6.mask.x[7]);
|
||||
asprintf(&netstr, "%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx/%d",
|
||||
ntohs(subnet->net.ipv6.address.x[0]),
|
||||
ntohs(subnet->net.ipv6.address.x[1]),
|
||||
ntohs(subnet->net.ipv6.address.x[2]),
|
||||
ntohs(subnet->net.ipv6.address.x[3]),
|
||||
ntohs(subnet->net.ipv6.address.x[4]),
|
||||
ntohs(subnet->net.ipv6.address.x[5]),
|
||||
ntohs(subnet->net.ipv6.address.x[6]),
|
||||
ntohs(subnet->net.ipv6.address.x[7]),
|
||||
subnet->net.ipv6.masklength);
|
||||
break;
|
||||
default:
|
||||
asprintf(&netstr, _("unknown subnet type"));
|
||||
|
|
@ -342,8 +389,8 @@ subnet_t *lookup_subnet_ipv6(ipv6_t *address)
|
|||
int i;
|
||||
cp
|
||||
subnet.type = SUBNET_IPV6;
|
||||
memcpy(&subnet.net.ipv6.address, address, sizeof(ipv6_t));
|
||||
memset(&subnet.net.ipv6.mask, 0xFF, 16);
|
||||
memcpy(subnet.net.ipv6.address.x, address, sizeof(ipv6_t));
|
||||
memset(subnet.net.ipv6.mask.x, 0xFF, 16);
|
||||
|
||||
p = (subnet_t *)avl_search_closest_greater(subnet_tree, &subnet);
|
||||
|
||||
|
|
@ -366,7 +413,7 @@ cp
|
|||
{
|
||||
subnet = (subnet_t *)node->data;
|
||||
netstr = net2str(subnet);
|
||||
syslog(LOG_DEBUG, " %s owner %s", netstr, subnet->owner->name);
|
||||
syslog(LOG_DEBUG, _(" %s owner %s"), netstr, subnet->owner->name);
|
||||
free(netstr);
|
||||
}
|
||||
syslog(LOG_DEBUG, _("End of subnet list."));
|
||||
|
|
|
|||
28
src/subnet.h
28
src/subnet.h
|
|
@ -17,7 +17,7 @@
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
$Id: subnet.h,v 1.1.2.14 2001/11/16 12:10:54 zarq Exp $
|
||||
$Id: subnet.h,v 1.1.2.15 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#ifndef __TINC_SUBNET_H__
|
||||
|
|
@ -28,7 +28,8 @@
|
|||
enum
|
||||
{
|
||||
SUBNET_MAC = 0,
|
||||
SUBNET_IP,
|
||||
SUBNET_IPV4,
|
||||
SUBNET_IPV6,
|
||||
SUBNET_TYPES /* Guardian */
|
||||
};
|
||||
|
||||
|
|
@ -37,11 +38,19 @@ typedef struct subnet_mac_t
|
|||
mac_t address;
|
||||
} subnet_mac_t;
|
||||
|
||||
typedef struct subnet_ip_t
|
||||
typedef struct subnet_ipv4_t
|
||||
{
|
||||
struct addrinfo *address;
|
||||
struct addrinfo *mask;
|
||||
} subnet_ip_t;
|
||||
ipv4_t address;
|
||||
ipv4_t mask;
|
||||
int masklength;
|
||||
} subnet_ipv4_t;
|
||||
|
||||
typedef struct subnet_ipv6_t
|
||||
{
|
||||
ipv6_t address;
|
||||
ipv6_t mask;
|
||||
int masklength;
|
||||
} subnet_ipv6_t;
|
||||
|
||||
#include "node.h"
|
||||
|
||||
|
|
@ -56,9 +65,9 @@ typedef struct subnet_t {
|
|||
union net
|
||||
{
|
||||
subnet_mac_t mac;
|
||||
subnet_ip_t ip;
|
||||
subnet_ipv4_t ipv4;
|
||||
subnet_ipv6_t ipv6;
|
||||
} net;
|
||||
|
||||
} subnet_t;
|
||||
|
||||
extern subnet_t *new_subnet(void);
|
||||
|
|
@ -73,7 +82,8 @@ extern char *net2str(subnet_t *);
|
|||
extern subnet_t *str2net(char *);
|
||||
extern subnet_t *lookup_subnet(struct node_t *, subnet_t *);
|
||||
extern subnet_t *lookup_subnet_mac(mac_t *);
|
||||
extern subnet_t *lookup_subnet_ip(struct addrinfo *);
|
||||
extern subnet_t *lookup_subnet_ipv4(ipv4_t *);
|
||||
extern subnet_t *lookup_subnet_ipv6(ipv6_t *);
|
||||
extern void dump_subnets(void);
|
||||
|
||||
#endif /* __TINC_SUBNET_H__ */
|
||||
|
|
|
|||
17
src/tincd.c
17
src/tincd.c
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
tincd.c -- the main file for tincd
|
||||
Copyright (C) 1998-2001 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
2000,2001 Guus Sliepen <guus@sliepen.warande.net>
|
||||
Copyright (C) 1998-2002 Ivo Timmermans <itimmermans@bigfoot.com>
|
||||
2000-2002 Guus Sliepen <guus@sliepen.warande.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -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.56 2001/11/16 22:40:26 zarq Exp $
|
||||
$Id: tincd.c,v 1.10.4.57 2002/02/10 21:57:54 guus Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
|
@ -41,12 +41,14 @@
|
|||
#include <openssl/rand.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#include <utils.h>
|
||||
#include <xalloc.h>
|
||||
|
||||
#include "conf.h"
|
||||
#include "net.h"
|
||||
#include "netutl.h"
|
||||
#include "process.h"
|
||||
#include "protocol.h"
|
||||
#include "subnet.h"
|
||||
|
|
@ -295,7 +297,7 @@ main(int argc, char **argv, char **envp)
|
|||
if(show_version)
|
||||
{
|
||||
printf(_("%s version %s (built %s %s, protocol %d)\n"), PACKAGE, VERSION, __DATE__, __TIME__, PROT_CURRENT);
|
||||
printf(_("Copyright (C) 1998-2001 Ivo Timmermans, Guus Sliepen and others.\n"
|
||||
printf(_("Copyright (C) 1998-2002 Ivo Timmermans, Guus Sliepen and others.\n"
|
||||
"See the AUTHORS file for a complete list.\n\n"
|
||||
"tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
|
||||
"and you are welcome to redistribute it under certain conditions;\n"
|
||||
|
|
@ -327,6 +329,13 @@ main(int argc, char **argv, char **envp)
|
|||
/* Slllluuuuuuurrrrp! */
|
||||
cp
|
||||
RAND_load_file("/dev/urandom", 1024);
|
||||
|
||||
#ifdef HAVE_SSLEAY_ADD_ALL_ALGORITHMS
|
||||
SSLeay_add_all_algorithms();
|
||||
#else
|
||||
OpenSSL_add_all_algorithms();
|
||||
#endif
|
||||
|
||||
cp
|
||||
if(generate_keys)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue