Big bad commit:
- Transition to new node/vertex/connection structures - Use new configuration handling everywhere - Linux tun/tap device handling cleanup - Start of IPv6 support in route.c It compiles, but it won't link.
This commit is contained in:
parent
1935c44a1e
commit
82e3837109
23 changed files with 1402 additions and 1596 deletions
55
src/conf.c
55
src/conf.c
|
@ -19,7 +19,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: conf.c,v 1.9.4.44 2001/10/10 20:34:27 guus Exp $
|
$Id: conf.c,v 1.9.4.45 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -220,6 +220,59 @@ cp
|
||||||
return 0;
|
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->value, cfg->file, cfg->line);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_config_subnet(config_t *cfg, subnet_t **result)
|
||||||
|
{
|
||||||
|
ip_mask_t *ip;
|
||||||
|
subnet_t *subnet;
|
||||||
|
cp
|
||||||
|
if(!cfg)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
ip = strtoip(cfg->value);
|
||||||
|
|
||||||
|
if(!ip)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, _("IP address expected for configuration variable %s in %s line %d"),
|
||||||
|
cfg->value, cfg->file, cfg->line);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Teach newbies what subnets are... */
|
||||||
|
|
||||||
|
if((subnet->net.ipv4.address & subnet->net.ipv4.mask) != subnet->net.ipv4.address)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, _("Network address and subnet mask for configuration variable %s in %s line %d"),
|
||||||
|
cfg->value, cfg->file, cfg->line);
|
||||||
|
free(ip);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
subnet = new_subnet();
|
||||||
|
subnet->type = SUBNET_IPV4;
|
||||||
|
subnet->net.ipv4.address = ip->address;
|
||||||
|
subnet->net.ipv4.mask = ip->mask;
|
||||||
|
|
||||||
|
free(ip);
|
||||||
|
|
||||||
|
*result = subnet;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Read exactly one line and strip the trailing newline if any. If the
|
Read exactly one line and strip the trailing newline if any. If the
|
||||||
file was on EOF, return NULL. Otherwise, return all the data in a
|
file was on EOF, return NULL. Otherwise, return all the data in a
|
||||||
|
|
12
src/conf.h
12
src/conf.h
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: conf.h,v 1.6.4.27 2001/10/10 20:34:27 guus Exp $
|
$Id: conf.h,v 1.6.4.28 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TINC_CONF_H__
|
#ifndef __TINC_CONF_H__
|
||||||
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include <avl_tree.h>
|
#include <avl_tree.h>
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
#include "subnet.h"
|
||||||
|
|
||||||
typedef struct config_t {
|
typedef struct config_t {
|
||||||
char *variable;
|
char *variable;
|
||||||
|
@ -47,12 +48,15 @@ extern void exit_configuration(avl_tree_t **);
|
||||||
extern config_t *new_config(void);
|
extern config_t *new_config(void);
|
||||||
extern void free_config(config_t *);
|
extern void free_config(config_t *);
|
||||||
extern void config_add(avl_tree_t *, config_t *);
|
extern void config_add(avl_tree_t *, config_t *);
|
||||||
extern config_t *config_lookup(avl_tree_t *, char *);
|
extern config_t *lookup_config(avl_tree_t *, char *);
|
||||||
extern config_t *config_lookup_next(avl_tree_t *, config_t *);
|
extern config_t *lookup_config_next(avl_tree_t *, config_t *);
|
||||||
extern int get_config_bool(config_t *, int *);
|
extern int get_config_bool(config_t *, int *);
|
||||||
extern int get_config_int(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_string(config_t *, char **);
|
||||||
extern int get_config_ip(config_t *, ip_mask_t **);
|
extern int get_config_ip(config_t *, struct ip_mask_t **);
|
||||||
|
struct subnet_t; /* Needed for next line. */
|
||||||
|
extern int get_config_subnet(config_t *, struct subnet_t **);
|
||||||
|
|
||||||
extern int read_config_file(avl_tree_t *, const char *);
|
extern int read_config_file(avl_tree_t *, const char *);
|
||||||
extern int read_server_config(void);
|
extern int read_server_config(void);
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: connection.c,v 1.1.2.19 2001/10/10 20:35:10 guus Exp $
|
$Id: connection.c,v 1.1.2.20 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -71,8 +71,6 @@ void free_connection(connection_t *c)
|
||||||
cp
|
cp
|
||||||
if(c->hostname)
|
if(c->hostname)
|
||||||
free(c->hostname);
|
free(c->hostname);
|
||||||
if(c->rsa_key)
|
|
||||||
RSA_free(c->rsa_key);
|
|
||||||
if(c->inkey)
|
if(c->inkey)
|
||||||
free(c->inkey);
|
free(c->inkey);
|
||||||
if(c->outkey)
|
if(c->outkey)
|
||||||
|
@ -120,10 +118,22 @@ cp
|
||||||
{
|
{
|
||||||
c = (connection_t *)node->data;
|
c = (connection_t *)node->data;
|
||||||
syslog(LOG_DEBUG, _(" %s at %s port %hd options %ld socket %d status %04x"),
|
syslog(LOG_DEBUG, _(" %s at %s port %hd options %ld socket %d status %04x"),
|
||||||
c->node->name, c->hostname, c->port, c->options,
|
c->name, c->hostname, c->port, c->options,
|
||||||
c->socket, c->status);
|
c->socket, c->status);
|
||||||
}
|
}
|
||||||
|
|
||||||
syslog(LOG_DEBUG, _("End of connections."));
|
syslog(LOG_DEBUG, _("End of connections."));
|
||||||
cp
|
cp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int read_connection_config(connection_t *c)
|
||||||
|
{
|
||||||
|
char *fname;
|
||||||
|
int x;
|
||||||
|
cp
|
||||||
|
asprintf(&fname, "%s/hosts/%s", confbase, c->name);
|
||||||
|
x = read_config_file(c->config_tree, fname);
|
||||||
|
free(fname);
|
||||||
|
cp
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: connection.h,v 1.1.2.16 2001/10/10 20:35:10 guus Exp $
|
$Id: connection.h,v 1.1.2.17 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TINC_CONNECTION_H__
|
#ifndef __TINC_CONNECTION_H__
|
||||||
|
@ -26,8 +26,6 @@
|
||||||
#include <avl_tree.h>
|
#include <avl_tree.h>
|
||||||
#include <list.h>
|
#include <list.h>
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#ifdef HAVE_OPENSSL_EVP_H
|
#ifdef HAVE_OPENSSL_EVP_H
|
||||||
# include <openssl/evp.h>
|
# include <openssl/evp.h>
|
||||||
#else
|
#else
|
||||||
|
@ -46,26 +44,24 @@
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "vertex.h"
|
#include "vertex.h"
|
||||||
|
|
||||||
typedef struct status_bits_t {
|
#define OPTION_INDIRECT 0x0001
|
||||||
|
#define OPTION_TCPONLY 0x0002
|
||||||
|
|
||||||
|
typedef struct connection_status_t {
|
||||||
int pinged:1; /* sent ping */
|
int pinged:1; /* sent ping */
|
||||||
int meta:1; /* meta connection exists */
|
|
||||||
int active:1; /* 1 if active.. */
|
int active:1; /* 1 if active.. */
|
||||||
int outgoing:1; /* I myself asked for this conn */
|
int outgoing:1; /* I myself asked for this conn */
|
||||||
int termreq:1; /* the termination of this connection was requested */
|
int termreq:1; /* the termination of this connection was requested */
|
||||||
int remove:1; /* Set to 1 if you want this connection removed */
|
int remove:1; /* Set to 1 if you want this connection removed */
|
||||||
int timeout:1; /* 1 if gotten timeout */
|
int timeout:1; /* 1 if gotten timeout */
|
||||||
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 dataopen:1; /* 1 if we have a valid UDP connection open */
|
|
||||||
int encryptout:1; /* 1 if we can encrypt outgoing traffic */
|
int encryptout:1; /* 1 if we can encrypt outgoing traffic */
|
||||||
int decryptin:1; /* 1 if we have to decrypt incoming traffic */
|
int decryptin:1; /* 1 if we have to decrypt incoming traffic */
|
||||||
int unused:18;
|
int unused:18;
|
||||||
} status_bits_t;
|
} connection_status_t;
|
||||||
|
|
||||||
#define OPTION_INDIRECT 0x0001
|
|
||||||
#define OPTION_TCPONLY 0x0002
|
|
||||||
|
|
||||||
typedef struct connection_t {
|
typedef struct connection_t {
|
||||||
|
char *name; /* name he claims to have */
|
||||||
|
|
||||||
ipv4_t address; /* his real (internet) ip */
|
ipv4_t address; /* his real (internet) ip */
|
||||||
short unsigned int port; /* port number of meta connection */
|
short unsigned int port; /* port number of meta connection */
|
||||||
char *hostname; /* the hostname of its real ip */
|
char *hostname; /* the hostname of its real ip */
|
||||||
|
@ -73,7 +69,7 @@ typedef struct connection_t {
|
||||||
|
|
||||||
int socket; /* socket used for this connection */
|
int socket; /* socket used for this connection */
|
||||||
long int options; /* options for this connection */
|
long int options; /* options for this connection */
|
||||||
status_bits_t status; /* status info */
|
struct connection_status_t status; /* status info */
|
||||||
|
|
||||||
struct node_t *node; /* node associated with the other end */
|
struct node_t *node; /* node associated with the other end */
|
||||||
struct vertex_t *vertex; /* vertex associated with this connection */
|
struct vertex_t *vertex; /* vertex associated with this connection */
|
||||||
|
@ -96,8 +92,20 @@ typedef struct connection_t {
|
||||||
int allow_request; /* defined if there's only one request possible */
|
int allow_request; /* defined if there's only one request possible */
|
||||||
|
|
||||||
time_t last_ping_time; /* last time we saw some activity from the other end */
|
time_t last_ping_time; /* last time we saw some activity from the other end */
|
||||||
|
|
||||||
|
avl_tree_t *config_tree; /* Pointer to configuration tree belonging to him */
|
||||||
} connection_t;
|
} connection_t;
|
||||||
|
|
||||||
extern avl_tree_t *connection_tree;
|
extern avl_tree_t *connection_tree;
|
||||||
|
|
||||||
|
extern void init_connections(void);
|
||||||
|
extern void exit_connection(void);
|
||||||
|
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(ipv4_t, short unsigned int);
|
||||||
|
extern void dump_connections(void);
|
||||||
|
extern int read_connection_config(connection_t *);
|
||||||
|
|
||||||
#endif /* __TINC_CONNECTION_H__ */
|
#endif /* __TINC_CONNECTION_H__ */
|
||||||
|
|
10
src/device.h
10
src/device.h
|
@ -17,16 +17,18 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: device.h,v 1.1.2.1 2001/10/12 15:16:03 guus Exp $
|
$Id: device.h,v 1.1.2.2 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TINC_DEVICE_H__
|
#ifndef __TINC_DEVICE_H__
|
||||||
#define __TINC_DEVICE_H__
|
#define __TINC_DEVICE_H__
|
||||||
|
|
||||||
extern void setup_device(void);
|
extern int device_fd;
|
||||||
|
|
||||||
|
extern int setup_device(void);
|
||||||
extern void close_device(void);
|
extern void close_device(void);
|
||||||
extern vpn_packet_t *read_packet(void);
|
extern vpn_packet_t *read_packet(void);
|
||||||
extern void write_packet(vpn_packet_t *);
|
extern int write_packet(vpn_packet_t *);
|
||||||
extern void dump_device_stats(void);
|
extern void dump_device_stats(void);
|
||||||
|
|
||||||
#endif __TINC_DEVICE_H__
|
#endif /* __TINC_DEVICE_H__ */
|
||||||
|
|
|
@ -17,9 +17,21 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: device.c,v 1.1.2.1 2001/10/12 15:16:03 guus Exp $
|
$Id: device.c,v 1.1.2.2 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <syslog.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#ifdef HAVE_TUNTAP
|
#ifdef HAVE_TUNTAP
|
||||||
#ifdef LINUX_IF_TUN_H
|
#ifdef LINUX_IF_TUN_H
|
||||||
#include LINUX_IF_TUN_H
|
#include LINUX_IF_TUN_H
|
||||||
|
@ -31,6 +43,13 @@
|
||||||
#define DEFAULT_DEVICE "/dev/tap0"
|
#define DEFAULT_DEVICE "/dev/tap0"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <utils.h>
|
||||||
|
#include "conf.h"
|
||||||
|
#include "net.h"
|
||||||
|
#include "subnet.h"
|
||||||
|
|
||||||
|
#include "system.h"
|
||||||
|
|
||||||
#define DEVICE_TYPE_ETHERTAP 0
|
#define DEVICE_TYPE_ETHERTAP 0
|
||||||
#define DEVICE_TYPE_TUNTAP 1
|
#define DEVICE_TYPE_TUNTAP 1
|
||||||
|
|
||||||
|
@ -42,6 +61,8 @@ char *device_info;
|
||||||
int device_total_in = 0;
|
int device_total_in = 0;
|
||||||
int device_total_out = 0;
|
int device_total_out = 0;
|
||||||
|
|
||||||
|
subnet_t mymac;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
open the local ethertap device
|
open the local ethertap device
|
||||||
*/
|
*/
|
||||||
|
@ -50,7 +71,7 @@ int setup_device(void)
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
|
|
||||||
cp
|
cp
|
||||||
if(!get_config_string(lookup_config(config_tree, "Device"), &device_fname)))
|
if(!get_config_string(lookup_config(config_tree, "Device"), &device_fname))
|
||||||
device_fname = DEFAULT_DEVICE;
|
device_fname = DEFAULT_DEVICE;
|
||||||
|
|
||||||
cp
|
cp
|
||||||
|
@ -60,8 +81,6 @@ cp
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
cp
|
cp
|
||||||
device_fd = device_fd;
|
|
||||||
|
|
||||||
/* Set default MAC address for ethertap devices */
|
/* Set default MAC address for ethertap devices */
|
||||||
|
|
||||||
mymac.type = SUBNET_MAC;
|
mymac.type = SUBNET_MAC;
|
||||||
|
@ -90,14 +109,14 @@ cp
|
||||||
if (!ioctl(device_fd, (('T'<< 8) | 202), (void *) &ifr))
|
if (!ioctl(device_fd, (('T'<< 8) | 202), (void *) &ifr))
|
||||||
{
|
{
|
||||||
syslog(LOG_WARNING, _("Old ioctl() request was needed for %s"), device_fname);
|
syslog(LOG_WARNING, _("Old ioctl() request was needed for %s"), device_fname);
|
||||||
device_type = TAP_TYPE_TUNTAP;
|
device_type = DEVICE_TYPE_TUNTAP;
|
||||||
device_info = _("Linux tun/tap device");
|
device_info = _("Linux tun/tap device");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
device_info = _("Linux ethertap device");
|
device_info = _("Linux ethertap device");
|
||||||
device_type = TAP_TYPE_ETHERTAP;
|
device_type = DEVICE_TYPE_ETHERTAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
syslog(LOG_INFO, _("%s is a %s"), device_fname, device_info);
|
syslog(LOG_INFO, _("%s is a %s"), device_fname, device_info);
|
||||||
|
@ -125,7 +144,7 @@ cp
|
||||||
}
|
}
|
||||||
else /* ethertap */
|
else /* ethertap */
|
||||||
{
|
{
|
||||||
struct iovec vector[2] = {{packet->len, 2}, {packet->data, MTU}};
|
struct iovec vector[2] = {{&packet->len, 2}, {packet->data, MTU}};
|
||||||
|
|
||||||
if((lenin = readv(device_fd, vector, 2)) <= 0)
|
if((lenin = readv(device_fd, vector, 2)) <= 0)
|
||||||
{
|
{
|
||||||
|
@ -135,13 +154,12 @@ cp
|
||||||
|
|
||||||
packet->len = lenin - 2;
|
packet->len = lenin - 2;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
device_total_in += packet->len;
|
device_total_in += packet->len;
|
||||||
|
|
||||||
if(debug_lvl >= DEBUG_TRAFFIC)
|
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;
|
return 0;
|
||||||
|
@ -159,21 +177,22 @@ cp
|
||||||
{
|
{
|
||||||
if(write(device_fd, packet->data, packet->len) < 0)
|
if(write(device_fd, packet->data, packet->len) < 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_fname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else/* ethertap */
|
else/* ethertap */
|
||||||
{
|
{
|
||||||
struct iovec vector[2] = {{packet->len, 2}, {packet->data, MTU}};
|
struct iovec vector[2] = {{&packet->len, 2}, {packet->data, MTU}};
|
||||||
|
|
||||||
if(writev(device_fd, vector, 2) < 0)
|
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_fname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
device_total_out += packet->len;
|
device_total_out += packet->len;
|
||||||
cp
|
cp
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
82
src/meta.c
82
src/meta.c
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: meta.c,v 1.1.2.20 2001/07/20 13:54:19 guus Exp $
|
$Id: meta.c,v 1.1.2.21 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
|
|
||||||
int send_meta(connection_t *cl, char *buffer, int length)
|
int send_meta(connection_t *c, char *buffer, int length)
|
||||||
{
|
{
|
||||||
char *bufp;
|
char *bufp;
|
||||||
int outlen;
|
int outlen;
|
||||||
|
@ -47,41 +47,41 @@ int send_meta(connection_t *cl, char *buffer, int length)
|
||||||
cp
|
cp
|
||||||
if(debug_lvl >= DEBUG_META)
|
if(debug_lvl >= DEBUG_META)
|
||||||
syslog(LOG_DEBUG, _("Sending %d bytes of metadata to %s (%s)"), length,
|
syslog(LOG_DEBUG, _("Sending %d bytes of metadata to %s (%s)"), length,
|
||||||
cl->name, cl->hostname);
|
c->name, c->hostname);
|
||||||
|
|
||||||
if(cl->status.encryptout)
|
if(c->status.encryptout)
|
||||||
{
|
{
|
||||||
EVP_EncryptUpdate(cl->cipher_outctx, outbuf, &outlen, buffer, length);
|
EVP_EncryptUpdate(c->outctx, outbuf, &outlen, buffer, length);
|
||||||
bufp = outbuf;
|
bufp = outbuf;
|
||||||
length = outlen;
|
length = outlen;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
bufp = buffer;
|
bufp = buffer;
|
||||||
|
|
||||||
if(write(cl->meta_socket, bufp, length) < 0)
|
if(write(c->socket, bufp, length) < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Sending meta data to %s (%s) failed: %m"), cl->name, cl->hostname);
|
syslog(LOG_ERR, _("Sending meta data to %s (%s) failed: %m"), c->name, c->hostname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
cp
|
cp
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void broadcast_meta(connection_t *cl, char *buffer, int length)
|
void broadcast_meta(connection_t *from, char *buffer, int length)
|
||||||
{
|
{
|
||||||
avl_node_t *node;
|
avl_node_t *node;
|
||||||
connection_t *p;
|
connection_t *c;
|
||||||
cp
|
cp
|
||||||
for(node = connection_tree->head; node; node = node->next)
|
for(node = connection_tree->head; node; node = node->next)
|
||||||
{
|
{
|
||||||
p = (connection_t *)node->data;
|
c = (connection_t *)node->data;
|
||||||
if(p != cl && p->status.active)
|
if(c != from && c->status.active)
|
||||||
send_meta(p, buffer, length);
|
send_meta(c, buffer, length);
|
||||||
}
|
}
|
||||||
cp
|
cp
|
||||||
}
|
}
|
||||||
|
|
||||||
int receive_meta(connection_t *cl)
|
int receive_meta(connection_t *c)
|
||||||
{
|
{
|
||||||
int x, l = sizeof(x);
|
int x, l = sizeof(x);
|
||||||
int oldlen, i;
|
int oldlen, i;
|
||||||
|
@ -89,16 +89,16 @@ int receive_meta(connection_t *cl)
|
||||||
int decrypted = 0;
|
int decrypted = 0;
|
||||||
char inbuf[MAXBUFSIZE];
|
char inbuf[MAXBUFSIZE];
|
||||||
cp
|
cp
|
||||||
if(getsockopt(cl->meta_socket, SOL_SOCKET, SO_ERROR, &x, &l) < 0)
|
if(getsockopt(c->socket, SOL_SOCKET, SO_ERROR, &x, &l) < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%m %s (%s)"), __FILE__, __LINE__, cl->meta_socket,
|
syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%m %s (%s)"), __FILE__, __LINE__, c->socket,
|
||||||
cl->name, cl->hostname);
|
c->name, c->hostname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(x)
|
if(x)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Metadata socket error for %s (%s): %s"),
|
syslog(LOG_ERR, _("Metadata socket error for %s (%s): %s"),
|
||||||
cl->name, cl->hostname, strerror(x));
|
c->name, c->hostname, strerror(x));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ cp
|
||||||
- If not, keep stuff in buffer and exit.
|
- If not, keep stuff in buffer and exit.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
lenin = read(cl->meta_socket, cl->buffer + cl->buflen, MAXBUFSIZE - cl->buflen);
|
lenin = read(c->socket, c->buffer + c->buflen, MAXBUFSIZE - c->buflen);
|
||||||
|
|
||||||
if(lenin<=0)
|
if(lenin<=0)
|
||||||
{
|
{
|
||||||
|
@ -119,45 +119,45 @@ cp
|
||||||
{
|
{
|
||||||
if(debug_lvl >= DEBUG_CONNECTIONS)
|
if(debug_lvl >= DEBUG_CONNECTIONS)
|
||||||
syslog(LOG_NOTICE, _("Connection closed by %s (%s)"),
|
syslog(LOG_NOTICE, _("Connection closed by %s (%s)"),
|
||||||
cl->name, cl->hostname);
|
c->name, c->hostname);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if(errno==EINTR)
|
if(errno==EINTR)
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
syslog(LOG_ERR, _("Metadata socket read error for %s (%s): %m"),
|
syslog(LOG_ERR, _("Metadata socket read error for %s (%s): %m"),
|
||||||
cl->name, cl->hostname);
|
c->name, c->hostname);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
oldlen = cl->buflen;
|
oldlen = c->buflen;
|
||||||
cl->buflen += lenin;
|
c->buflen += lenin;
|
||||||
|
|
||||||
while(lenin)
|
while(lenin)
|
||||||
{
|
{
|
||||||
/* Decrypt */
|
/* Decrypt */
|
||||||
|
|
||||||
if(cl->status.decryptin && !decrypted)
|
if(c->status.decryptin && !decrypted)
|
||||||
{
|
{
|
||||||
EVP_DecryptUpdate(cl->cipher_inctx, inbuf, &lenin, cl->buffer + oldlen, lenin);
|
EVP_DecryptUpdate(c->inctx, inbuf, &lenin, c->buffer + oldlen, lenin);
|
||||||
memcpy(cl->buffer + oldlen, inbuf, lenin);
|
memcpy(c->buffer + oldlen, inbuf, lenin);
|
||||||
decrypted = 1;
|
decrypted = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Are we receiving a TCPpacket? */
|
/* Are we receiving a TCPpacket? */
|
||||||
|
|
||||||
if(cl->tcplen)
|
if(c->tcplen)
|
||||||
{
|
{
|
||||||
if(cl->tcplen <= cl->buflen)
|
if(c->tcplen <= c->buflen)
|
||||||
{
|
{
|
||||||
receive_tcppacket(cl, cl->buffer, cl->tcplen);
|
receive_tcppacket(c, c->buffer, c->tcplen);
|
||||||
|
|
||||||
cl->buflen -= cl->tcplen;
|
c->buflen -= c->tcplen;
|
||||||
lenin -= cl->tcplen;
|
lenin -= c->tcplen;
|
||||||
memmove(cl->buffer, cl->buffer + cl->tcplen, cl->buflen);
|
memmove(c->buffer, c->buffer + c->tcplen, c->buflen);
|
||||||
oldlen = 0;
|
oldlen = 0;
|
||||||
cl->tcplen = 0;
|
c->tcplen = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -170,11 +170,11 @@ cp
|
||||||
|
|
||||||
reqlen = 0;
|
reqlen = 0;
|
||||||
|
|
||||||
for(i = oldlen; i < cl->buflen; i++)
|
for(i = oldlen; i < c->buflen; i++)
|
||||||
{
|
{
|
||||||
if(cl->buffer[i] == '\n')
|
if(c->buffer[i] == '\n')
|
||||||
{
|
{
|
||||||
cl->buffer[i] = '\0'; /* replace end-of-line by end-of-string so we can use sscanf */
|
c->buffer[i] = '\0'; /* replace end-of-line by end-of-string so we can use sscanf */
|
||||||
reqlen = i + 1;
|
reqlen = i + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -182,12 +182,12 @@ cp
|
||||||
|
|
||||||
if(reqlen)
|
if(reqlen)
|
||||||
{
|
{
|
||||||
if(receive_request(cl))
|
if(receive_request(c))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
cl->buflen -= reqlen;
|
c->buflen -= reqlen;
|
||||||
lenin -= reqlen;
|
lenin -= reqlen;
|
||||||
memmove(cl->buffer, cl->buffer + reqlen, cl->buflen);
|
memmove(c->buffer, c->buffer + reqlen, c->buflen);
|
||||||
oldlen = 0;
|
oldlen = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -197,14 +197,14 @@ cp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cl->buflen >= MAXBUFSIZE)
|
if(c->buflen >= MAXBUFSIZE)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Metadata read buffer overflow for %s (%s)"),
|
syslog(LOG_ERR, _("Metadata read buffer overflow for %s (%s)"),
|
||||||
cl->name, cl->hostname);
|
c->name, c->hostname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cl->last_ping_time = time(NULL);
|
c->last_ping_time = time(NULL);
|
||||||
cp
|
cp
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
44
src/net.h
44
src/net.h
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: net.h,v 1.9.4.34 2001/07/21 15:34:18 guus Exp $
|
$Id: net.h,v 1.9.4.35 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TINC_NET_H__
|
#ifndef __TINC_NET_H__
|
||||||
|
@ -59,6 +59,11 @@ typedef struct mac_t
|
||||||
|
|
||||||
typedef unsigned long ipv4_t;
|
typedef unsigned long ipv4_t;
|
||||||
|
|
||||||
|
typedef struct ip_mask_t {
|
||||||
|
ipv4_t address;
|
||||||
|
ipv4_t mask;
|
||||||
|
} ip_mask_t;
|
||||||
|
|
||||||
typedef struct ipv6_t
|
typedef struct ipv6_t
|
||||||
{
|
{
|
||||||
unsigned short x[8];
|
unsigned short x[8];
|
||||||
|
@ -85,19 +90,6 @@ typedef struct packet_queue_t {
|
||||||
queue_element_t *tail;
|
queue_element_t *tail;
|
||||||
} packet_queue_t;
|
} packet_queue_t;
|
||||||
|
|
||||||
typedef struct enc_key_t {
|
|
||||||
int length;
|
|
||||||
char *key;
|
|
||||||
time_t expiry;
|
|
||||||
} enc_key_t;
|
|
||||||
|
|
||||||
extern int tap_fd;
|
|
||||||
|
|
||||||
extern int total_tap_in;
|
|
||||||
extern int total_tap_out;
|
|
||||||
extern int total_socket_in;
|
|
||||||
extern int total_socket_out;
|
|
||||||
|
|
||||||
extern int seconds_till_retry;
|
extern int seconds_till_retry;
|
||||||
|
|
||||||
extern char *request_name[256];
|
extern char *request_name[256];
|
||||||
|
@ -105,26 +97,16 @@ extern char *status_text[10];
|
||||||
|
|
||||||
#include "connection.h" /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
|
#include "connection.h" /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
|
||||||
|
|
||||||
extern int str2opt(const char *);
|
extern void send_packet(struct node_t *, vpn_packet_t *);
|
||||||
extern char *opt2str(int);
|
extern void receive_packet(struct node_t *, vpn_packet_t *);
|
||||||
extern void send_packet(connection_t *, vpn_packet_t *);
|
extern void receive_tcppacket(struct connection_t *, char *, int);
|
||||||
extern void receive_packet(connection_t *, vpn_packet_t *);
|
extern void broadcast_packet(struct node_t *, vpn_packet_t *);
|
||||||
extern void receive_tcppacket(connection_t *, char *, int);
|
|
||||||
extern void accept_packet(vpn_packet_t *);
|
|
||||||
extern void broadcast_packet(connection_t *, vpn_packet_t *);
|
|
||||||
extern int setup_network_connections(void);
|
extern int setup_network_connections(void);
|
||||||
extern void close_network_connections(void);
|
extern void close_network_connections(void);
|
||||||
extern void main_loop(void);
|
extern void main_loop(void);
|
||||||
extern void terminate_connection(connection_t *, int);
|
extern void terminate_connection(connection_t *, int);
|
||||||
extern void flush_queue(connection_t *);
|
extern void flush_queue(struct node_t *);
|
||||||
|
extern int read_rsa_public_key(struct connection_t *);
|
||||||
#include <config.h>
|
extern RETSIGTYPE try_outgoing_connections(int);
|
||||||
#ifdef HAVE_OPENSSL_RSA_H
|
|
||||||
# include <openssl/rsa.h>
|
|
||||||
#else
|
|
||||||
# include <rsa.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern int read_rsa_public_key(connection_t *);
|
|
||||||
|
|
||||||
#endif /* __TINC_NET_H__ */
|
#endif /* __TINC_NET_H__ */
|
||||||
|
|
10
src/netutl.c
10
src/netutl.c
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: netutl.c,v 1.12.4.19 2001/05/07 19:08:46 guus Exp $
|
$Id: netutl.c,v 1.12.4.20 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -46,15 +46,11 @@ char *hostlookup(unsigned long addr)
|
||||||
char *name;
|
char *name;
|
||||||
struct hostent *host = NULL;
|
struct hostent *host = NULL;
|
||||||
struct in_addr in;
|
struct in_addr in;
|
||||||
config_t const *cfg;
|
int lookup_hostname = 0;
|
||||||
int lookup_hostname;
|
|
||||||
cp
|
cp
|
||||||
in.s_addr = addr;
|
in.s_addr = addr;
|
||||||
|
|
||||||
lookup_hostname = 0;
|
get_config_int(lookup_config(config_tree, "Hostnames"), &lookup_hostname);
|
||||||
if((cfg = get_config_val(config, config_hostnames)) != NULL)
|
|
||||||
if(cfg->data.val == stupid_true)
|
|
||||||
lookup_hostname = 1;
|
|
||||||
|
|
||||||
if(lookup_hostname)
|
if(lookup_hostname)
|
||||||
host = gethostbyaddr((char *)&in, sizeof(in), AF_INET);
|
host = gethostbyaddr((char *)&in, sizeof(in), AF_INET);
|
||||||
|
|
|
@ -17,14 +17,13 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: netutl.h,v 1.2.4.6 2001/01/07 17:09:02 guus Exp $
|
$Id: netutl.h,v 1.2.4.7 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TINC_NETUTL_H__
|
#ifndef __TINC_NETUTL_H__
|
||||||
#define __TINC_NETUTL_H__
|
#define __TINC_NETUTL_H__
|
||||||
|
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "conf.h"
|
|
||||||
|
|
||||||
extern char *hostlookup(unsigned long);
|
extern char *hostlookup(unsigned long);
|
||||||
extern ip_mask_t *strtoip(char*);
|
extern ip_mask_t *strtoip(char*);
|
||||||
|
|
70
src/node.c
70
src/node.c
|
@ -17,20 +17,45 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: node.c,v 1.1.2.1 2001/10/10 08:49:47 guus Exp $
|
$Id: node.c,v 1.1.2.2 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
avl_tree_t *node_tree; /* Known nodes, sorted by name */
|
#include "config.h"
|
||||||
|
|
||||||
int node_compare(connection_t *a, connection_t *b)
|
#include <string.h>
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
|
#include <avl_tree.h>
|
||||||
|
#include "node.h"
|
||||||
|
#include "net.h"
|
||||||
|
#include <utils.h>
|
||||||
|
#include <xalloc.h>
|
||||||
|
|
||||||
|
#include "system.h"
|
||||||
|
|
||||||
|
avl_tree_t *node_tree; /* Known nodes, sorted by name */
|
||||||
|
avl_tree_t *node_udp_tree; /* Known nodes, sorted by address and port */
|
||||||
|
|
||||||
|
int node_compare(node_t *a, node_t *b)
|
||||||
{
|
{
|
||||||
return strcmp(a->name, b->name);
|
return strcmp(a->name, b->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int node_udp_compare(connection_t *a, connection_t *b)
|
||||||
|
{
|
||||||
|
if(a->address < b->address)
|
||||||
|
return -1;
|
||||||
|
else if (a->address > b->address)
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return a->port - b->port;
|
||||||
|
}
|
||||||
|
|
||||||
void init_nodes(void)
|
void init_nodes(void)
|
||||||
{
|
{
|
||||||
cp
|
cp
|
||||||
node_tree = avl_alloc_tree((avl_compare_t)node_compare, NULL);
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +63,7 @@ void exit_nodes(void)
|
||||||
{
|
{
|
||||||
cp
|
cp
|
||||||
avl_delete_tree(node_tree);
|
avl_delete_tree(node_tree);
|
||||||
|
avl_delete_tree(node_udp_tree);
|
||||||
cp
|
cp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,12 +88,26 @@ cp
|
||||||
free(n->hostname);
|
free(n->hostname);
|
||||||
if(n->key)
|
if(n->key)
|
||||||
free(n->key);
|
free(n->key);
|
||||||
if(n->config)
|
|
||||||
clear_config(&n->config);
|
|
||||||
free(n);
|
free(n);
|
||||||
cp
|
cp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void node_add(node_t *n)
|
||||||
|
{
|
||||||
|
cp
|
||||||
|
avl_insert(node_tree, n);
|
||||||
|
avl_insert(node_udp_tree, n);
|
||||||
|
cp
|
||||||
|
}
|
||||||
|
|
||||||
|
void node_del(node_t *n)
|
||||||
|
{
|
||||||
|
cp
|
||||||
|
avl_delete(node_tree, n);
|
||||||
|
avl_delete(node_udp_tree, n);
|
||||||
|
cp
|
||||||
|
}
|
||||||
|
|
||||||
node_t *lookup_node(char *name)
|
node_t *lookup_node(char *name)
|
||||||
{
|
{
|
||||||
node_t n;
|
node_t n;
|
||||||
|
@ -76,17 +116,13 @@ cp
|
||||||
return avl_search(node_tree, &n);
|
return avl_search(node_tree, &n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node_t *lookup_node_udp(ipv4_t address, port_t port)
|
||||||
int read_host_config(nodet *n)
|
|
||||||
{
|
{
|
||||||
char *fname;
|
node_t n;
|
||||||
int x;
|
|
||||||
cp
|
cp
|
||||||
asprintf(&fname, "%s/hosts/%s", confbase, n->name);
|
n.address = address;
|
||||||
x = read_config_file(&n->config, fname);
|
n.port = port;
|
||||||
free(fname);
|
return avl_search(node_udp_tree, &n);
|
||||||
cp
|
|
||||||
return x;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dump_nodes(void)
|
void dump_nodes(void)
|
||||||
|
@ -98,10 +134,10 @@ cp
|
||||||
|
|
||||||
for(node = node_tree->head; node; node = node->next)
|
for(node = node_tree->head; node; node = node->next)
|
||||||
{
|
{
|
||||||
n = (connection_t *)node->data;
|
n = (node_t *)node->data;
|
||||||
syslog(LOG_DEBUG, _(" %s at %s port %hd options %ld sockets %d, %d status %04x"),
|
syslog(LOG_DEBUG, _(" %s at %s port %hd options %ld status %04x"),
|
||||||
n->name, n->hostname, n->port, n->options,
|
n->name, n->hostname, n->port, n->options,
|
||||||
n->socket, n->meta_socket, n->status);
|
n->status);
|
||||||
}
|
}
|
||||||
|
|
||||||
syslog(LOG_DEBUG, _("End of nodes."));
|
syslog(LOG_DEBUG, _("End of nodes."));
|
||||||
|
|
39
src/node.h
39
src/node.h
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: node.h,v 1.1.2.4 2001/10/10 20:35:10 guus Exp $
|
$Id: node.h,v 1.1.2.5 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TINC_NODE_H__
|
#ifndef __TINC_NODE_H__
|
||||||
|
@ -25,31 +25,52 @@
|
||||||
|
|
||||||
#include <avl_tree.h>
|
#include <avl_tree.h>
|
||||||
|
|
||||||
|
#include "subnet.h"
|
||||||
|
#include "connection.h"
|
||||||
|
|
||||||
|
typedef struct node_status_t {
|
||||||
|
int active:1; /* 1 if active.. */
|
||||||
|
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 unused:29;
|
||||||
|
} node_status_t;
|
||||||
|
|
||||||
typedef struct node_t {
|
typedef struct node_t {
|
||||||
char *name; /* name of this connection */
|
char *name; /* name of this node */
|
||||||
int protocol_version; /* used protocol */
|
long int options; /* options turned on for this node */
|
||||||
long int options; /* options turned on for this connection */
|
|
||||||
|
|
||||||
ipv4_t address; /* his real (internet) ip to send UDP packets to */
|
ipv4_t address; /* his real (internet) ip to send UDP packets to */
|
||||||
short unsigned int port; /* port number of UDP connection */
|
short unsigned int port; /* port number of UDP connection */
|
||||||
char *hostname; /* the hostname of its real ip */
|
char *hostname; /* the hostname of its real ip */
|
||||||
|
|
||||||
|
struct node_status_t status;
|
||||||
|
|
||||||
EVP_CIPHER *cipher; /* Cipher type for UDP packets */
|
EVP_CIPHER *cipher; /* Cipher type for UDP packets */
|
||||||
char *key; /* Cipher key and iv */
|
char *key; /* Cipher key and iv */
|
||||||
int keylength; /* Cipher key and iv length*/
|
int keylength; /* Cipher key and iv length*/
|
||||||
|
|
||||||
list_t *queue; /* Queue for packets awaiting to be encrypted */
|
list_t *queue; /* Queue for packets awaiting to be encrypted */
|
||||||
|
|
||||||
struct node_t *nexthop; /* nearest meta-hop from us to him */
|
struct node_t *nexthop; /* nearest node from us to him */
|
||||||
struct node_t *prevhop; /* nearest meta-hop from him to us */
|
|
||||||
struct node_t *via; /* next hop for UDP packets */
|
struct node_t *via; /* next hop for UDP packets */
|
||||||
|
|
||||||
avl_tree_t *subnet_tree; /* Pointer to a tree of subnets belonging to this node */
|
avl_tree_t *subnet_tree; /* Pointer to a tree of subnets belonging to this node */
|
||||||
|
|
||||||
struct config_t *config; /* Pointer to configuration tree belonging to this node */
|
struct connection_t *connection; /* Connection associated with this node (if a direct connection exists) */
|
||||||
} node_t;
|
} node_t;
|
||||||
|
|
||||||
struct node_t *myself;
|
extern struct node_t *myself;
|
||||||
extern avl_tree_t *node_tree;
|
extern avl_tree_t *node_tree;
|
||||||
|
|
||||||
|
extern void init_nodes(void);
|
||||||
|
extern void exit_nodes(void);
|
||||||
|
extern node_t *new_node(void);
|
||||||
|
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(ipv4_t, port_t);
|
||||||
|
extern void dump_nodes(void);
|
||||||
|
|
||||||
|
|
||||||
#endif /* __TINC_NODE_H__ */
|
#endif /* __TINC_NODE_H__ */
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: process.c,v 1.1.2.25 2001/09/05 18:38:09 zarq Exp $
|
$Id: process.c,v 1.1.2.26 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -42,6 +42,7 @@
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "process.h"
|
#include "process.h"
|
||||||
#include "subnet.h"
|
#include "subnet.h"
|
||||||
|
#include "device.h"
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
@ -87,8 +88,7 @@ cp
|
||||||
close_network_connections();
|
close_network_connections();
|
||||||
|
|
||||||
if(debug_lvl > DEBUG_NOTHING)
|
if(debug_lvl > DEBUG_NOTHING)
|
||||||
syslog(LOG_INFO, _("Total bytes written: tap %d, socket %d; bytes read: tap %d, socket %d"),
|
dump_device_stats();
|
||||||
total_tap_out, total_socket_out, total_tap_in, total_socket_in);
|
|
||||||
|
|
||||||
syslog(LOG_NOTICE, _("Terminating"));
|
syslog(LOG_NOTICE, _("Terminating"));
|
||||||
|
|
||||||
|
|
1216
src/protocol.c
1216
src/protocol.c
File diff suppressed because it is too large
Load diff
|
@ -17,13 +17,14 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: protocol.h,v 1.5.4.22 2001/09/24 14:12:00 guus Exp $
|
$Id: protocol.h,v 1.5.4.23 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TINC_PROTOCOL_H__
|
#ifndef __TINC_PROTOCOL_H__
|
||||||
#define __TINC_PROTOCOL_H__
|
#define __TINC_PROTOCOL_H__
|
||||||
|
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
#include "node.h"
|
||||||
#include "subnet.h"
|
#include "subnet.h"
|
||||||
|
|
||||||
/* Protocol version. Different versions are incompatible,
|
/* Protocol version. Different versions are incompatible,
|
||||||
|
@ -36,11 +37,12 @@
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ALL = -1, /* Guardian for allow_request */
|
ALL = -1, /* Guardian for allow_request */
|
||||||
ID = 0, METAKEY, CHALLENGE, CHAL_REPLY,
|
ID = 0, METAKEY, CHALLENGE, CHAL_REPLY, ACK,
|
||||||
STATUS, ERROR, TERMREQ,
|
STATUS, ERROR, TERMREQ,
|
||||||
PING, PONG,
|
PING, PONG,
|
||||||
ADD_HOST, DEL_HOST,
|
ADD_NODE, DEL_NODE,
|
||||||
ADD_SUBNET, DEL_SUBNET,
|
ADD_SUBNET, DEL_SUBNET,
|
||||||
|
ADD_VERTEX, DEL_VERTEX,
|
||||||
KEY_CHANGED, REQ_KEY, ANS_KEY,
|
KEY_CHANGED, REQ_KEY, ANS_KEY,
|
||||||
PACKET,
|
PACKET,
|
||||||
LAST /* Guardian for the highest request number */
|
LAST /* Guardian for the highest request number */
|
||||||
|
@ -54,21 +56,24 @@ enum {
|
||||||
extern int (*request_handlers[])(connection_t*);
|
extern int (*request_handlers[])(connection_t*);
|
||||||
|
|
||||||
extern int send_id(connection_t*);
|
extern int send_id(connection_t*);
|
||||||
|
extern int send_metakey(connection_t*);
|
||||||
extern int send_challenge(connection_t*);
|
extern int send_challenge(connection_t*);
|
||||||
extern int send_chal_reply(connection_t*);
|
extern int send_chal_reply(connection_t*);
|
||||||
extern int send_metakey(connection_t*);
|
extern int send_ack(connection_t*);
|
||||||
extern int send_status(connection_t*, int, char*);
|
extern int send_status(connection_t*, int, char*);
|
||||||
extern int send_error(connection_t*, int, char*);
|
extern int send_error(connection_t*, int, char*);
|
||||||
extern int send_termreq(connection_t*);
|
extern int send_termreq(connection_t*);
|
||||||
extern int send_ping(connection_t*);
|
extern int send_ping(connection_t*);
|
||||||
extern int send_pong(connection_t*);
|
extern int send_pong(connection_t*);
|
||||||
extern int send_add_host(connection_t*, connection_t*);
|
extern int send_add_node(connection_t*, node_t*);
|
||||||
extern int send_del_host(connection_t*, connection_t*);
|
extern int send_del_node(connection_t*, node_t*);
|
||||||
extern int send_add_subnet(connection_t*, subnet_t*);
|
extern int send_add_subnet(connection_t*, subnet_t*);
|
||||||
extern int send_del_subnet(connection_t*, subnet_t*);
|
extern int send_del_subnet(connection_t*, subnet_t*);
|
||||||
extern int send_key_changed(connection_t*, connection_t*);
|
extern int send_add_vertex(connection_t*, node_t*);
|
||||||
extern int send_req_key(connection_t*, connection_t*);
|
extern int send_del_vertex(connection_t*, node_t*);
|
||||||
extern int send_ans_key(connection_t*, connection_t*, char*);
|
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 *);
|
extern int send_tcppacket(connection_t *, vpn_packet_t *);
|
||||||
|
|
||||||
/* Old functions */
|
/* Old functions */
|
||||||
|
|
53
src/route.c
53
src/route.c
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: route.c,v 1.1.2.18 2001/07/21 20:21:25 guus Exp $
|
$Id: route.c,v 1.1.2.19 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -56,7 +56,7 @@ void learn_mac(mac_t *address)
|
||||||
{
|
{
|
||||||
subnet_t *subnet;
|
subnet_t *subnet;
|
||||||
avl_node_t *node;
|
avl_node_t *node;
|
||||||
connection_t *p;
|
connection_t *c;
|
||||||
cp
|
cp
|
||||||
subnet = lookup_subnet_mac(address);
|
subnet = lookup_subnet_mac(address);
|
||||||
|
|
||||||
|
@ -77,14 +77,14 @@ cp
|
||||||
|
|
||||||
for(node = connection_tree->head; node; node = node->next)
|
for(node = connection_tree->head; node; node = node->next)
|
||||||
{
|
{
|
||||||
p = (connection_t *)node->data;
|
c = (connection_t *)node->data;
|
||||||
if(p->status.active)
|
if(c->status.active)
|
||||||
send_add_subnet(p, subnet);
|
send_add_subnet(c, subnet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connection_t *route_mac(vpn_packet_t *packet)
|
node_t *route_mac(vpn_packet_t *packet)
|
||||||
{
|
{
|
||||||
subnet_t *subnet;
|
subnet_t *subnet;
|
||||||
cp
|
cp
|
||||||
|
@ -102,7 +102,7 @@ cp
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
connection_t *route_ipv4(vpn_packet_t *packet)
|
node_t *route_ipv4(vpn_packet_t *packet)
|
||||||
{
|
{
|
||||||
ipv4_t dest;
|
ipv4_t dest;
|
||||||
subnet_t *subnet;
|
subnet_t *subnet;
|
||||||
|
@ -130,15 +130,26 @@ cp
|
||||||
return subnet->owner;
|
return subnet->owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
connection_t *route_ipv6(vpn_packet_t *packet)
|
node_t *route_ipv6(vpn_packet_t *packet)
|
||||||
{
|
{
|
||||||
|
ipv6_t dest;
|
||||||
|
subnet_t *subnet;
|
||||||
cp
|
cp
|
||||||
if(debug_lvl > DEBUG_NOTHING)
|
memcpy(&dest, &packet->data[30], sizeof(ipv6_t));
|
||||||
|
|
||||||
|
subnet = lookup_subnet_ipv6(&dest);
|
||||||
|
cp
|
||||||
|
if(!subnet)
|
||||||
{
|
{
|
||||||
syslog(LOG_WARNING, _("Cannot route packet: IPv6 routing not yet implemented"));
|
if(debug_lvl >= DEBUG_TRAFFIC)
|
||||||
|
{
|
||||||
|
syslog(LOG_WARNING, _("Cannot route packet: unknown IPv6 destination address"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
cp
|
cp
|
||||||
return NULL;
|
return subnet->owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
void route_arp(vpn_packet_t *packet)
|
void route_arp(vpn_packet_t *packet)
|
||||||
|
@ -213,7 +224,7 @@ cp
|
||||||
void route_outgoing(vpn_packet_t *packet)
|
void route_outgoing(vpn_packet_t *packet)
|
||||||
{
|
{
|
||||||
unsigned short int type;
|
unsigned short int type;
|
||||||
connection_t *cl;
|
node_t *n;
|
||||||
cp
|
cp
|
||||||
/* FIXME: multicast? */
|
/* FIXME: multicast? */
|
||||||
|
|
||||||
|
@ -224,10 +235,10 @@ cp
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
case 0x0800:
|
case 0x0800:
|
||||||
cl = route_ipv4(packet);
|
n = route_ipv4(packet);
|
||||||
break;
|
break;
|
||||||
case 0x86DD:
|
case 0x86DD:
|
||||||
cl = route_ipv6(packet);
|
n = route_ipv6(packet);
|
||||||
break;
|
break;
|
||||||
case 0x0806:
|
case 0x0806:
|
||||||
route_arp(packet);
|
route_arp(packet);
|
||||||
|
@ -239,14 +250,14 @@ cp
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(cl)
|
if(n)
|
||||||
send_packet(cl, packet);
|
send_packet(n, packet);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RMODE_SWITCH:
|
case RMODE_SWITCH:
|
||||||
cl = route_mac(packet);
|
n = route_mac(packet);
|
||||||
if(cl)
|
if(n)
|
||||||
send_packet(cl, packet);
|
send_packet(n, packet);
|
||||||
else
|
else
|
||||||
broadcast_packet(myself, packet);
|
broadcast_packet(myself, packet);
|
||||||
break;
|
break;
|
||||||
|
@ -257,7 +268,7 @@ cp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void route_incoming(connection_t *source, vpn_packet_t *packet)
|
void route_incoming(node_t *source, vpn_packet_t *packet)
|
||||||
{
|
{
|
||||||
switch(routing_mode)
|
switch(routing_mode)
|
||||||
{
|
{
|
||||||
|
@ -286,7 +297,7 @@ void route_incoming(connection_t *source, vpn_packet_t *packet)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RMODE_HUB:
|
case RMODE_HUB:
|
||||||
broadcast_packet(source,packet); /* Spread it on */
|
broadcast_packet(source, packet); /* Spread it on */
|
||||||
accept_packet(packet);
|
accept_packet(packet);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: route.h,v 1.1.2.3 2001/03/04 13:59:32 guus Exp $
|
$Id: route.h,v 1.1.2.4 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TINC_ROUTE_H__
|
#ifndef __TINC_ROUTE_H__
|
||||||
|
@ -31,9 +31,8 @@ enum
|
||||||
};
|
};
|
||||||
|
|
||||||
extern int routing_mode;
|
extern int routing_mode;
|
||||||
extern subnet_t mymac;
|
|
||||||
|
|
||||||
extern void route_incoming(connection_t *, vpn_packet_t *);
|
extern void route_incoming(node_t *, vpn_packet_t *);
|
||||||
extern void route_outgoing(vpn_packet_t *);
|
extern void route_outgoing(vpn_packet_t *);
|
||||||
|
|
||||||
#endif /* __TINC_ROUTE_H__ */
|
#endif /* __TINC_ROUTE_H__ */
|
||||||
|
|
99
src/subnet.c
99
src/subnet.c
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: subnet.c,v 1.1.2.24 2001/08/28 20:52:39 guus Exp $
|
$Id: subnet.c,v 1.1.2.25 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "connection.h"
|
#include "node.h"
|
||||||
#include "subnet.h"
|
#include "subnet.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
|
||||||
|
@ -51,8 +51,14 @@ cp
|
||||||
|
|
||||||
int subnet_compare_mac(subnet_t *a, subnet_t *b)
|
int subnet_compare_mac(subnet_t *a, subnet_t *b)
|
||||||
{
|
{
|
||||||
|
int result;
|
||||||
cp
|
cp
|
||||||
return memcmp(&a->net.mac.address, &b->net.mac.address, sizeof(mac_t));
|
result = memcmp(&a->net.mac.address, &b->net.mac.address, sizeof(mac_t));
|
||||||
|
|
||||||
|
if(result)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
return strcmp(a->owner->name, b->owner->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
int subnet_compare_ipv4(subnet_t *a, subnet_t *b)
|
int subnet_compare_ipv4(subnet_t *a, subnet_t *b)
|
||||||
|
@ -60,43 +66,36 @@ int subnet_compare_ipv4(subnet_t *a, subnet_t *b)
|
||||||
cp
|
cp
|
||||||
/* We compare as if a subnet is a number that equals (address << 32 + netmask). */
|
/* We compare as if a subnet is a number that equals (address << 32 + netmask). */
|
||||||
|
|
||||||
if(a->net.ipv4.address == b->net.ipv4.address)
|
if(a->net.ipv4.address < b->net.ipv4.address)
|
||||||
{
|
return -1;
|
||||||
if(a->net.ipv4.mask < b->net.ipv4.mask)
|
else if(a->net.ipv4.address > b->net.ipv4.address)
|
||||||
return -1;
|
return 1;
|
||||||
else if(a->net.ipv4.mask > b->net.ipv4.mask)
|
|
||||||
return 1;
|
if(a->net.ipv4.mask < b->net.ipv4.mask)
|
||||||
else
|
return -1;
|
||||||
return 0;
|
else if(a->net.ipv4.mask > b->net.ipv4.mask)
|
||||||
}
|
return 1;
|
||||||
else
|
|
||||||
{
|
return strcmp(a->owner->name, b->owner->name);
|
||||||
if(a->net.ipv4.address < b->net.ipv4.address)
|
|
||||||
return -1;
|
|
||||||
else if(a->net.ipv4.address > b->net.ipv4.address)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int subnet_compare_ipv6(subnet_t *a, subnet_t *b)
|
int subnet_compare_ipv6(subnet_t *a, subnet_t *b)
|
||||||
{
|
{
|
||||||
|
int result;
|
||||||
cp
|
cp
|
||||||
/* Same as ipv4 case, but with nasty 128 bit addresses */
|
/* Same as ipv4 case, but with nasty 128 bit addresses */
|
||||||
|
|
||||||
if(memcmp(&a->net.ipv6.mask, &b->net.ipv6.mask, sizeof(ipv6_t)) > 0)
|
result = memcmp(a->net.ipv6.address.x, b->net.ipv6.address.x, sizeof(ipv6_t));
|
||||||
if((a->net.ipv6.address.x[0] & b->net.ipv6.mask.x[0]) == b->net.ipv6.address.x[0] &&
|
|
||||||
(a->net.ipv6.address.x[1] & b->net.ipv6.mask.x[1]) == b->net.ipv6.address.x[1] &&
|
|
||||||
(a->net.ipv6.address.x[2] & b->net.ipv6.mask.x[2]) == b->net.ipv6.address.x[2] &&
|
|
||||||
(a->net.ipv6.address.x[3] & b->net.ipv6.mask.x[3]) == b->net.ipv6.address.x[3] &&
|
|
||||||
(a->net.ipv6.address.x[4] & b->net.ipv6.mask.x[4]) == b->net.ipv6.address.x[4] &&
|
|
||||||
(a->net.ipv6.address.x[5] & b->net.ipv6.mask.x[5]) == b->net.ipv6.address.x[5] &&
|
|
||||||
(a->net.ipv6.address.x[6] & b->net.ipv6.mask.x[6]) == b->net.ipv6.address.x[6] &&
|
|
||||||
(a->net.ipv6.address.x[7] & b->net.ipv6.mask.x[7]) == b->net.ipv6.address.x[7])
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return memcmp(&a->net.ipv6.address, &b->net.ipv6.address, sizeof(ipv6_t));
|
if(result)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
result = memcmp(a->net.ipv6.mask.x, b->net.ipv6.mask.x, sizeof(ipv6_t));
|
||||||
|
|
||||||
|
if(result)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
return strcmp(a->owner->name, b->owner->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
int subnet_compare(subnet_t *a, subnet_t *b)
|
int subnet_compare(subnet_t *a, subnet_t *b)
|
||||||
|
@ -138,37 +137,21 @@ cp
|
||||||
|
|
||||||
/* Linked list management */
|
/* Linked list management */
|
||||||
|
|
||||||
void subnet_add(connection_t *cl, subnet_t *subnet)
|
void subnet_add(node_t *n, subnet_t *subnet)
|
||||||
{
|
{
|
||||||
cp
|
cp
|
||||||
subnet->owner = cl;
|
subnet->owner = n;
|
||||||
|
|
||||||
while(!avl_insert(subnet_tree, subnet))
|
avl_insert(subnet_tree, subnet);
|
||||||
{
|
cp
|
||||||
subnet_t *old;
|
avl_insert(n->subnet_tree, subnet);
|
||||||
|
|
||||||
old = (subnet_t *)avl_search(subnet_tree, subnet);
|
|
||||||
|
|
||||||
if(debug_lvl >= DEBUG_PROTOCOL)
|
|
||||||
{
|
|
||||||
char *subnetstr;
|
|
||||||
subnetstr = net2str(subnet);
|
|
||||||
syslog(LOG_WARNING, _("Duplicate subnet %s for %s (%s), previous owner %s (%s)!"),
|
|
||||||
subnetstr, cl->name, cl->hostname, old->owner->name, old->owner->hostname);
|
|
||||||
free(subnetstr);
|
|
||||||
}
|
|
||||||
|
|
||||||
subnet_del(old);
|
|
||||||
}
|
|
||||||
|
|
||||||
avl_insert(cl->subnet_tree, subnet);
|
|
||||||
cp
|
cp
|
||||||
}
|
}
|
||||||
|
|
||||||
void subnet_del(subnet_t *subnet)
|
void subnet_del(node_t *n, subnet_t *subnet)
|
||||||
{
|
{
|
||||||
cp
|
cp
|
||||||
avl_delete(subnet->owner->subnet_tree, subnet);
|
avl_delete(n->subnet_tree, subnet);
|
||||||
cp
|
cp
|
||||||
avl_delete(subnet_tree, subnet);
|
avl_delete(subnet_tree, subnet);
|
||||||
cp
|
cp
|
||||||
|
@ -285,6 +268,12 @@ cp
|
||||||
|
|
||||||
/* Subnet lookup routines */
|
/* Subnet lookup routines */
|
||||||
|
|
||||||
|
subnet_t *lookup_subnet(node_t *owner, subnet_t *subnet)
|
||||||
|
{
|
||||||
|
cp
|
||||||
|
return avl_search(owner->subnet_tree, subnet);
|
||||||
|
}
|
||||||
|
|
||||||
subnet_t *lookup_subnet_mac(mac_t *address)
|
subnet_t *lookup_subnet_mac(mac_t *address)
|
||||||
{
|
{
|
||||||
subnet_t subnet, *p;
|
subnet_t subnet, *p;
|
||||||
|
|
15
src/subnet.h
15
src/subnet.h
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: subnet.h,v 1.1.2.10 2001/01/08 21:32:30 guus Exp $
|
$Id: subnet.h,v 1.1.2.11 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TINC_SUBNET_H__
|
#ifndef __TINC_SUBNET_H__
|
||||||
|
@ -50,9 +50,11 @@ typedef struct subnet_ipv6_t
|
||||||
ipv6_t mask;
|
ipv6_t mask;
|
||||||
} subnet_ipv6_t;
|
} subnet_ipv6_t;
|
||||||
|
|
||||||
|
#include "node.h"
|
||||||
|
|
||||||
typedef struct subnet_t {
|
typedef struct subnet_t {
|
||||||
struct connection_t *owner; /* the owner of this subnet */
|
struct node_t *owner; /* the owner of this subnet */
|
||||||
struct connection_t *uplink; /* the uplink which we should send packets to for this subnet */
|
struct node_t *uplink; /* the uplink which we should send packets to for this subnet */
|
||||||
|
|
||||||
int type; /* subnet type (IPv4? IPv6? MAC? something even weirder?) */
|
int type; /* subnet type (IPv4? IPv6? MAC? something even weirder?) */
|
||||||
|
|
||||||
|
@ -67,16 +69,15 @@ typedef struct subnet_t {
|
||||||
|
|
||||||
} subnet_t;
|
} subnet_t;
|
||||||
|
|
||||||
#include "connection.h"
|
|
||||||
|
|
||||||
extern subnet_t *new_subnet(void);
|
extern subnet_t *new_subnet(void);
|
||||||
extern void free_subnet(subnet_t *);
|
extern void free_subnet(subnet_t *);
|
||||||
extern void init_subnets(void);
|
extern void init_subnets(void);
|
||||||
extern void subnet_add(struct connection_t *, subnet_t *);
|
extern void subnet_add(struct node_t *, subnet_t *);
|
||||||
extern void subnet_del(subnet_t *);
|
extern void subnet_del(struct node_t *, subnet_t *);
|
||||||
extern char *net2str(subnet_t *);
|
extern char *net2str(subnet_t *);
|
||||||
extern subnet_t *str2net(char *);
|
extern subnet_t *str2net(char *);
|
||||||
extern int subnet_compare(subnet_t *, subnet_t *);
|
extern int subnet_compare(subnet_t *, subnet_t *);
|
||||||
|
extern subnet_t *lookup_subnet(struct node_t *, subnet_t *);
|
||||||
extern subnet_t *lookup_subnet_mac(mac_t *);
|
extern subnet_t *lookup_subnet_mac(mac_t *);
|
||||||
extern subnet_t *lookup_subnet_ipv4(ipv4_t *);
|
extern subnet_t *lookup_subnet_ipv4(ipv4_t *);
|
||||||
extern subnet_t *lookup_subnet_ipv6(ipv6_t *);
|
extern subnet_t *lookup_subnet_ipv6(ipv6_t *);
|
||||||
|
|
14
src/tincd.c
14
src/tincd.c
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: tincd.c,v 1.10.4.52 2001/09/01 12:36:53 guus Exp $
|
$Id: tincd.c,v 1.10.4.53 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -205,7 +205,7 @@ int keygen(int bits)
|
||||||
{
|
{
|
||||||
RSA *rsa_key;
|
RSA *rsa_key;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
config_t const *cfg;
|
char *name = NULL;
|
||||||
char *filename;
|
char *filename;
|
||||||
|
|
||||||
fprintf(stderr, _("Generating %d bits keys:\n"), bits);
|
fprintf(stderr, _("Generating %d bits keys:\n"), bits);
|
||||||
|
@ -219,8 +219,10 @@ int keygen(int bits)
|
||||||
else
|
else
|
||||||
fprintf(stderr, _("Done.\n"));
|
fprintf(stderr, _("Done.\n"));
|
||||||
|
|
||||||
if(config && (cfg = get_config_val(config, config_name)))
|
get_config_string(lookup_config(config_tree, "Name"), &name);
|
||||||
asprintf(&filename, "%s/hosts/%s", confbase, cfg->data.ptr);
|
|
||||||
|
if(name)
|
||||||
|
asprintf(&filename, "%s/hosts/%s", confbase, name);
|
||||||
else
|
else
|
||||||
asprintf(&filename, "%s/rsa_key.pub", confbase);
|
asprintf(&filename, "%s/rsa_key.pub", confbase);
|
||||||
|
|
||||||
|
@ -350,8 +352,8 @@ cp
|
||||||
|
|
||||||
if(do_detach)
|
if(do_detach)
|
||||||
{
|
{
|
||||||
syslog(LOG_NOTICE, _("Restarting in %d seconds!"), MAXTIMEOUT);
|
syslog(LOG_NOTICE, _("Restarting in %d seconds!"), maxtimeout);
|
||||||
sleep(MAXTIMEOUT);
|
sleep(maxtimeout);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
33
src/vertex.c
33
src/vertex.c
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: vertex.c,v 1.1.2.1 2001/10/10 08:49:47 guus Exp $
|
$Id: vertex.c,v 1.1.2.2 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -44,7 +44,7 @@ avl_tree_t *connection_tree; /* Tree with all meta connections with ourself *
|
||||||
|
|
||||||
int connection_compare(connection_t *a, connection_t *b)
|
int connection_compare(connection_t *a, connection_t *b)
|
||||||
{
|
{
|
||||||
return a->meta_socket - b->meta_socket;
|
return a->socket - b->socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vertex_compare(vertex_t *a, vertex_t *b)
|
int vertex_compare(vertex_t *a, vertex_t *b)
|
||||||
|
@ -97,29 +97,38 @@ cp
|
||||||
void free_vertex(vertex_t *v)
|
void free_vertex(vertex_t *v)
|
||||||
{
|
{
|
||||||
cp
|
cp
|
||||||
if(v->from.hostname)
|
|
||||||
free(v->from.hostname)
|
|
||||||
if(v->to.hostname)
|
|
||||||
free(v->to.hostname)
|
|
||||||
|
|
||||||
free(v);
|
free(v);
|
||||||
cp
|
cp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vertex_add(vertex_t *v)
|
||||||
|
{
|
||||||
|
cp
|
||||||
|
avl_insert(vertex_tree, v);
|
||||||
|
cp
|
||||||
|
}
|
||||||
|
|
||||||
|
void vertex_del(vertex_t *v)
|
||||||
|
{
|
||||||
|
cp
|
||||||
|
avl_delete(vertex_tree, v);
|
||||||
|
cp
|
||||||
|
}
|
||||||
|
|
||||||
vertex_t *lookup_vertex(node_t *from, node_t *to)
|
vertex_t *lookup_vertex(node_t *from, node_t *to)
|
||||||
{
|
{
|
||||||
vertex_t v, *result;
|
vertex_t v, *result;
|
||||||
cp
|
cp
|
||||||
v.from.node = from;
|
v.from = from;
|
||||||
v.to.node = to;
|
v.to = to;
|
||||||
|
|
||||||
result = avl_search(vertex_tree, &v);
|
result = avl_search(vertex_tree, &v);
|
||||||
|
|
||||||
if(result)
|
if(result)
|
||||||
return result;
|
return result;
|
||||||
cp
|
cp
|
||||||
v.from.node = to;
|
v.from = to;
|
||||||
v.to.node = from;
|
v.to = from;
|
||||||
|
|
||||||
return avl_search(vertex_tree, &v);
|
return avl_search(vertex_tree, &v);
|
||||||
}
|
}
|
||||||
|
@ -135,7 +144,7 @@ cp
|
||||||
{
|
{
|
||||||
v = (vertex_t *)node->data;
|
v = (vertex_t *)node->data;
|
||||||
syslog(LOG_DEBUG, _(" %s - %s options %ld"),
|
syslog(LOG_DEBUG, _(" %s - %s options %ld"),
|
||||||
v->from.node->name, v->to.node->name, v->options);
|
v->from->name, v->to->name, v->options);
|
||||||
}
|
}
|
||||||
|
|
||||||
syslog(LOG_DEBUG, _("End of vertices."));
|
syslog(LOG_DEBUG, _("End of vertices."));
|
||||||
|
|
17
src/vertex.h
17
src/vertex.h
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: vertex.h,v 1.1.2.4 2001/10/10 20:35:10 guus Exp $
|
$Id: vertex.h,v 1.1.2.5 2001/10/27 12:13:17 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TINC_VERTEX_H__
|
#ifndef __TINC_VERTEX_H__
|
||||||
|
@ -28,6 +28,8 @@
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
|
|
||||||
|
/* I don't know if halfconnection_t is useful... */
|
||||||
|
|
||||||
typedef struct halfconnection_t {
|
typedef struct halfconnection_t {
|
||||||
struct node_t *node; /* node associated with this end of the connection */
|
struct node_t *node; /* node associated with this end of the connection */
|
||||||
|
|
||||||
|
@ -37,8 +39,8 @@ typedef struct halfconnection_t {
|
||||||
} halfconnection_t;
|
} halfconnection_t;
|
||||||
|
|
||||||
typedef struct vertex_t {
|
typedef struct vertex_t {
|
||||||
struct halfconnection_t from;
|
struct node_t *from;
|
||||||
struct halfconnection_t to;
|
struct node_t *to;
|
||||||
|
|
||||||
long int options; /* options turned on for this connection */
|
long int options; /* options turned on for this connection */
|
||||||
int metric; /* weight of this vertex */
|
int metric; /* weight of this vertex */
|
||||||
|
@ -48,4 +50,13 @@ typedef struct vertex_t {
|
||||||
|
|
||||||
extern avl_tree_t *vertex_tree; /* Tree with all known vertices (replaces active_tree) */
|
extern avl_tree_t *vertex_tree; /* Tree with all known vertices (replaces active_tree) */
|
||||||
|
|
||||||
|
extern void init_vertices(void);
|
||||||
|
extern void exit_vertices(void);
|
||||||
|
extern vertex_t *new_vertex(void);
|
||||||
|
extern void free_vertex(vertex_t *);
|
||||||
|
extern void vertex_add(vertex_t *);
|
||||||
|
extern void vertex_del(vertex_t *);
|
||||||
|
extern vertex_t *lookup_vertex(struct node_t *, struct node_t *);
|
||||||
|
extern void dump_vertices(void);
|
||||||
|
|
||||||
#endif /* __TINC_VERTEX_H__ */
|
#endif /* __TINC_VERTEX_H__ */
|
||||||
|
|
Loading…
Reference in a new issue