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:
Guus Sliepen 2001-10-27 12:13:17 +00:00
parent 1935c44a1e
commit 82e3837109
23 changed files with 1402 additions and 1596 deletions

View file

@ -19,7 +19,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: conf.c,v 1.9.4.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"
@ -220,6 +220,59 @@ cp
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
file was on EOF, return NULL. Otherwise, return all the data in a

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: 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__
@ -25,6 +25,7 @@
#include <avl_tree.h>
#include "net.h"
#include "subnet.h"
typedef struct config_t {
char *variable;
@ -47,12 +48,15 @@ extern void exit_configuration(avl_tree_t **);
extern config_t *new_config(void);
extern void free_config(config_t *);
extern void config_add(avl_tree_t *, config_t *);
extern config_t *config_lookup(avl_tree_t *, char *);
extern config_t *config_lookup_next(avl_tree_t *, config_t *);
extern config_t *lookup_config(avl_tree_t *, char *);
extern config_t *lookup_config_next(avl_tree_t *, config_t *);
extern 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_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_server_config(void);

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: connection.c,v 1.1.2.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"
@ -71,8 +71,6 @@ void free_connection(connection_t *c)
cp
if(c->hostname)
free(c->hostname);
if(c->rsa_key)
RSA_free(c->rsa_key);
if(c->inkey)
free(c->inkey);
if(c->outkey)
@ -120,10 +118,22 @@ cp
{
c = (connection_t *)node->data;
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);
}
syslog(LOG_DEBUG, _("End of connections."));
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;
}

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: connection.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__
@ -26,8 +26,6 @@
#include <avl_tree.h>
#include <list.h>
#include "config.h"
#ifdef HAVE_OPENSSL_EVP_H
# include <openssl/evp.h>
#else
@ -46,26 +44,24 @@
#include "node.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 meta:1; /* meta connection exists */
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 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 decryptin:1; /* 1 if we have to decrypt incoming traffic */
int unused:18;
} status_bits_t;
#define OPTION_INDIRECT 0x0001
#define OPTION_TCPONLY 0x0002
} connection_status_t;
typedef struct connection_t {
char *name; /* name he claims to have */
ipv4_t address; /* his real (internet) ip */
short unsigned int port; /* port number of meta connection */
char *hostname; /* the hostname of its real ip */
@ -73,7 +69,7 @@ typedef struct connection_t {
int socket; /* socket used 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 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 */
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;
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__ */

View file

@ -17,16 +17,18 @@
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.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__
#define __TINC_DEVICE_H__
extern void setup_device(void);
extern int device_fd;
extern int setup_device(void);
extern void close_device(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);
#endif __TINC_DEVICE_H__
#endif /* __TINC_DEVICE_H__ */

View file

@ -17,9 +17,21 @@
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: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 LINUX_IF_TUN_H
#include LINUX_IF_TUN_H
@ -31,6 +43,13 @@
#define DEFAULT_DEVICE "/dev/tap0"
#endif
#include <utils.h>
#include "conf.h"
#include "net.h"
#include "subnet.h"
#include "system.h"
#define DEVICE_TYPE_ETHERTAP 0
#define DEVICE_TYPE_TUNTAP 1
@ -42,6 +61,8 @@ char *device_info;
int device_total_in = 0;
int device_total_out = 0;
subnet_t mymac;
/*
open the local ethertap device
*/
@ -50,7 +71,7 @@ int setup_device(void)
struct ifreq ifr;
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;
cp
@ -60,8 +81,6 @@ cp
return -1;
}
cp
device_fd = device_fd;
/* Set default MAC address for ethertap devices */
mymac.type = SUBNET_MAC;
@ -90,14 +109,14 @@ cp
if (!ioctl(device_fd, (('T'<< 8) | 202), (void *) &ifr))
{
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");
}
else
#endif
{
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);
@ -125,7 +144,7 @@ cp
}
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)
{
@ -135,13 +154,12 @@ cp
packet->len = lenin - 2;
}
#endif
device_total_in += packet->len;
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;
@ -159,21 +177,22 @@ cp
{
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;
}
}
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)
{
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;
}
}
device_total_out += packet->len;
cp
return 0;
}

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: 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"
@ -39,7 +39,7 @@
#include "system.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;
int outlen;
@ -47,41 +47,41 @@ int send_meta(connection_t *cl, char *buffer, int length)
cp
if(debug_lvl >= DEBUG_META)
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;
length = outlen;
}
else
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;
}
cp
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;
connection_t *p;
connection_t *c;
cp
for(node = connection_tree->head; node; node = node->next)
{
p = (connection_t *)node->data;
if(p != cl && p->status.active)
send_meta(p, buffer, length);
c = (connection_t *)node->data;
if(c != from && c->status.active)
send_meta(c, buffer, length);
}
cp
}
int receive_meta(connection_t *cl)
int receive_meta(connection_t *c)
{
int x, l = sizeof(x);
int oldlen, i;
@ -89,16 +89,16 @@ int receive_meta(connection_t *cl)
int decrypted = 0;
char inbuf[MAXBUFSIZE];
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,
cl->name, cl->hostname);
syslog(LOG_ERR, _("This is a bug: %s:%d: %d:%m %s (%s)"), __FILE__, __LINE__, c->socket,
c->name, c->hostname);
return -1;
}
if(x)
{
syslog(LOG_ERR, _("Metadata socket error for %s (%s): %s"),
cl->name, cl->hostname, strerror(x));
c->name, c->hostname, strerror(x));
return -1;
}
@ -111,7 +111,7 @@ cp
- 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)
{
@ -119,45 +119,45 @@ cp
{
if(debug_lvl >= DEBUG_CONNECTIONS)
syslog(LOG_NOTICE, _("Connection closed by %s (%s)"),
cl->name, cl->hostname);
c->name, c->hostname);
}
else
if(errno==EINTR)
return 0;
else
syslog(LOG_ERR, _("Metadata socket read error for %s (%s): %m"),
cl->name, cl->hostname);
c->name, c->hostname);
return -1;
}
oldlen = cl->buflen;
cl->buflen += lenin;
oldlen = c->buflen;
c->buflen += lenin;
while(lenin)
{
/* Decrypt */
if(cl->status.decryptin && !decrypted)
if(c->status.decryptin && !decrypted)
{
EVP_DecryptUpdate(cl->cipher_inctx, inbuf, &lenin, cl->buffer + oldlen, lenin);
memcpy(cl->buffer + oldlen, inbuf, lenin);
EVP_DecryptUpdate(c->inctx, inbuf, &lenin, c->buffer + oldlen, lenin);
memcpy(c->buffer + oldlen, inbuf, lenin);
decrypted = 1;
}
/* 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;
lenin -= cl->tcplen;
memmove(cl->buffer, cl->buffer + cl->tcplen, cl->buflen);
c->buflen -= c->tcplen;
lenin -= c->tcplen;
memmove(c->buffer, c->buffer + c->tcplen, c->buflen);
oldlen = 0;
cl->tcplen = 0;
c->tcplen = 0;
continue;
}
else
@ -170,11 +170,11 @@ cp
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;
break;
}
@ -182,12 +182,12 @@ cp
if(reqlen)
{
if(receive_request(cl))
if(receive_request(c))
return -1;
cl->buflen -= reqlen;
c->buflen -= reqlen;
lenin -= reqlen;
memmove(cl->buffer, cl->buffer + reqlen, cl->buflen);
memmove(c->buffer, c->buffer + reqlen, c->buflen);
oldlen = 0;
continue;
}
@ -197,14 +197,14 @@ cp
}
}
if(cl->buflen >= MAXBUFSIZE)
if(c->buflen >= MAXBUFSIZE)
{
syslog(LOG_ERR, _("Metadata read buffer overflow for %s (%s)"),
cl->name, cl->hostname);
c->name, c->hostname);
return -1;
}
cl->last_ping_time = time(NULL);
c->last_ping_time = time(NULL);
cp
return 0;
}

1067
src/net.c

File diff suppressed because it is too large Load diff

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: net.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__
@ -59,6 +59,11 @@ typedef struct 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];
@ -85,19 +90,6 @@ typedef struct packet_queue_t {
queue_element_t *tail;
} 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 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 */
extern int str2opt(const char *);
extern char *opt2str(int);
extern void send_packet(connection_t *, vpn_packet_t *);
extern void receive_packet(connection_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 void send_packet(struct node_t *, vpn_packet_t *);
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 close_network_connections(void);
extern void main_loop(void);
extern void terminate_connection(connection_t *, int);
extern void flush_queue(connection_t *);
#include <config.h>
#ifdef HAVE_OPENSSL_RSA_H
# include <openssl/rsa.h>
#else
# include <rsa.h>
#endif
extern int read_rsa_public_key(connection_t *);
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__ */

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: netutl.c,v 1.12.4.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"
@ -46,15 +46,11 @@ char *hostlookup(unsigned long addr)
char *name;
struct hostent *host = NULL;
struct in_addr in;
config_t const *cfg;
int lookup_hostname;
int lookup_hostname = 0;
cp
in.s_addr = addr;
lookup_hostname = 0;
if((cfg = get_config_val(config, config_hostnames)) != NULL)
if(cfg->data.val == stupid_true)
lookup_hostname = 1;
get_config_int(lookup_config(config_tree, "Hostnames"), &lookup_hostname);
if(lookup_hostname)
host = gethostbyaddr((char *)&in, sizeof(in), AF_INET);

View file

@ -17,14 +17,13 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: netutl.h,v 1.2.4.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__
#define __TINC_NETUTL_H__
#include "net.h"
#include "conf.h"
extern char *hostlookup(unsigned long);
extern ip_mask_t *strtoip(char*);

View file

@ -17,20 +17,45 @@
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.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);
}
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)
{
cp
node_tree = avl_alloc_tree((avl_compare_t)node_compare, NULL);
node_udp_tree = avl_alloc_tree((avl_compare_t)node_udp_compare, NULL);
cp
}
@ -38,6 +63,7 @@ void exit_nodes(void)
{
cp
avl_delete_tree(node_tree);
avl_delete_tree(node_udp_tree);
cp
}
@ -62,12 +88,26 @@ cp
free(n->hostname);
if(n->key)
free(n->key);
if(n->config)
clear_config(&n->config);
free(n);
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 n;
@ -76,17 +116,13 @@ cp
return avl_search(node_tree, &n);
}
int read_host_config(nodet *n)
node_t *lookup_node_udp(ipv4_t address, port_t port)
{
char *fname;
int x;
node_t n;
cp
asprintf(&fname, "%s/hosts/%s", confbase, n->name);
x = read_config_file(&n->config, fname);
free(fname);
cp
return x;
n.address = address;
n.port = port;
return avl_search(node_udp_tree, &n);
}
void dump_nodes(void)
@ -98,10 +134,10 @@ cp
for(node = node_tree->head; node; node = node->next)
{
n = (connection_t *)node->data;
syslog(LOG_DEBUG, _(" %s at %s port %hd options %ld sockets %d, %d status %04x"),
n = (node_t *)node->data;
syslog(LOG_DEBUG, _(" %s at %s port %hd options %ld status %04x"),
n->name, n->hostname, n->port, n->options,
n->socket, n->meta_socket, n->status);
n->status);
}
syslog(LOG_DEBUG, _("End of nodes."));

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: node.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__
@ -25,31 +25,52 @@
#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 {
char *name; /* name of this connection */
int protocol_version; /* used protocol */
long int options; /* options turned on for this connection */
char *name; /* name of this node */
long int options; /* options turned on for this node */
ipv4_t address; /* his real (internet) ip to send UDP packets to */
short unsigned int 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 */
char *key; /* Cipher key and iv */
int keylength; /* Cipher key and iv length*/
list_t *queue; /* Queue for packets awaiting to be encrypted */
struct node_t *nexthop; /* nearest meta-hop from us to him */
struct node_t *prevhop; /* nearest meta-hop from him to us */
struct node_t *nexthop; /* nearest node from us to him */
struct node_t *via; /* next hop for UDP packets */
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;
struct node_t *myself;
extern struct node_t *myself;
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__ */

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: process.c,v 1.1.2.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"
@ -42,6 +42,7 @@
#include "conf.h"
#include "process.h"
#include "subnet.h"
#include "device.h"
#include "connection.h"
#include "system.h"
@ -87,8 +88,7 @@ cp
close_network_connections();
if(debug_lvl > DEBUG_NOTHING)
syslog(LOG_INFO, _("Total bytes written: tap %d, socket %d; bytes read: tap %d, socket %d"),
total_tap_out, total_socket_out, total_tap_in, total_socket_in);
dump_device_stats();
syslog(LOG_NOTICE, _("Terminating"));

File diff suppressed because it is too large Load diff

View file

@ -17,13 +17,14 @@
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.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__
#define __TINC_PROTOCOL_H__
#include "net.h"
#include "node.h"
#include "subnet.h"
/* Protocol version. Different versions are incompatible,
@ -36,11 +37,12 @@
enum {
ALL = -1, /* Guardian for allow_request */
ID = 0, METAKEY, CHALLENGE, CHAL_REPLY,
ID = 0, METAKEY, CHALLENGE, CHAL_REPLY, ACK,
STATUS, ERROR, TERMREQ,
PING, PONG,
ADD_HOST, DEL_HOST,
ADD_NODE, DEL_NODE,
ADD_SUBNET, DEL_SUBNET,
ADD_VERTEX, DEL_VERTEX,
KEY_CHANGED, REQ_KEY, ANS_KEY,
PACKET,
LAST /* Guardian for the highest request number */
@ -54,21 +56,24 @@ enum {
extern int (*request_handlers[])(connection_t*);
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_metakey(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_host(connection_t*, connection_t*);
extern int send_del_host(connection_t*, 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_key_changed(connection_t*, connection_t*);
extern int send_req_key(connection_t*, connection_t*);
extern int send_ans_key(connection_t*, connection_t*, char*);
extern int send_add_vertex(connection_t*, node_t*);
extern int send_del_vertex(connection_t*, node_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 */

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: route.c,v 1.1.2.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"
@ -56,7 +56,7 @@ void learn_mac(mac_t *address)
{
subnet_t *subnet;
avl_node_t *node;
connection_t *p;
connection_t *c;
cp
subnet = lookup_subnet_mac(address);
@ -77,14 +77,14 @@ cp
for(node = connection_tree->head; node; node = node->next)
{
p = (connection_t *)node->data;
if(p->status.active)
send_add_subnet(p, subnet);
c = (connection_t *)node->data;
if(c->status.active)
send_add_subnet(c, subnet);
}
}
}
connection_t *route_mac(vpn_packet_t *packet)
node_t *route_mac(vpn_packet_t *packet)
{
subnet_t *subnet;
cp
@ -102,7 +102,7 @@ cp
return NULL;
}
connection_t *route_ipv4(vpn_packet_t *packet)
node_t *route_ipv4(vpn_packet_t *packet)
{
ipv4_t dest;
subnet_t *subnet;
@ -130,15 +130,26 @@ cp
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
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
return NULL;
return subnet->owner;
}
void route_arp(vpn_packet_t *packet)
@ -213,7 +224,7 @@ cp
void route_outgoing(vpn_packet_t *packet)
{
unsigned short int type;
connection_t *cl;
node_t *n;
cp
/* FIXME: multicast? */
@ -224,10 +235,10 @@ cp
switch(type)
{
case 0x0800:
cl = route_ipv4(packet);
n = route_ipv4(packet);
break;
case 0x86DD:
cl = route_ipv6(packet);
n = route_ipv6(packet);
break;
case 0x0806:
route_arp(packet);
@ -239,14 +250,14 @@ cp
}
return;
}
if(cl)
send_packet(cl, packet);
if(n)
send_packet(n, packet);
break;
case RMODE_SWITCH:
cl = route_mac(packet);
if(cl)
send_packet(cl, packet);
n = route_mac(packet);
if(n)
send_packet(n, packet);
else
broadcast_packet(myself, packet);
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)
{

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: route.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__
@ -31,9 +31,8 @@ enum
};
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 *);
#endif /* __TINC_ROUTE_H__ */

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: subnet.c,v 1.1.2.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"
@ -28,7 +28,7 @@
#include "conf.h"
#include "net.h"
#include "connection.h"
#include "node.h"
#include "subnet.h"
#include "system.h"
@ -51,8 +51,14 @@ cp
int subnet_compare_mac(subnet_t *a, subnet_t *b)
{
int result;
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)
@ -60,43 +66,36 @@ int subnet_compare_ipv4(subnet_t *a, subnet_t *b)
cp
/* 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.mask < b->net.ipv4.mask)
return -1;
else if(a->net.ipv4.mask > b->net.ipv4.mask)
return 1;
else
return 0;
}
else
{
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;
}
if(a->net.ipv4.mask < b->net.ipv4.mask)
return -1;
else if(a->net.ipv4.mask > b->net.ipv4.mask)
return 1;
return strcmp(a->owner->name, b->owner->name);
}
int subnet_compare_ipv6(subnet_t *a, subnet_t *b)
{
int result;
cp
/* Same as ipv4 case, but with nasty 128 bit addresses */
if(memcmp(&a->net.ipv6.mask, &b->net.ipv6.mask, sizeof(ipv6_t)) > 0)
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;
result = memcmp(a->net.ipv6.address.x, b->net.ipv6.address.x, sizeof(ipv6_t));
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)
@ -138,37 +137,21 @@ cp
/* Linked list management */
void subnet_add(connection_t *cl, subnet_t *subnet)
void subnet_add(node_t *n, subnet_t *subnet)
{
cp
subnet->owner = cl;
subnet->owner = n;
while(!avl_insert(subnet_tree, subnet))
{
subnet_t *old;
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);
avl_insert(subnet_tree, subnet);
cp
avl_insert(n->subnet_tree, subnet);
cp
}
void subnet_del(subnet_t *subnet)
void subnet_del(node_t *n, subnet_t *subnet)
{
cp
avl_delete(subnet->owner->subnet_tree, subnet);
avl_delete(n->subnet_tree, subnet);
cp
avl_delete(subnet_tree, subnet);
cp
@ -285,6 +268,12 @@ cp
/* 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 subnet, *p;

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: subnet.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__
@ -50,9 +50,11 @@ typedef struct subnet_ipv6_t
ipv6_t mask;
} subnet_ipv6_t;
#include "node.h"
typedef struct subnet_t {
struct connection_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 *owner; /* the owner of 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?) */
@ -67,16 +69,15 @@ typedef struct subnet_t {
} subnet_t;
#include "connection.h"
extern subnet_t *new_subnet(void);
extern void free_subnet(subnet_t *);
extern void init_subnets(void);
extern void subnet_add(struct connection_t *, subnet_t *);
extern void subnet_del(subnet_t *);
extern void subnet_add(struct node_t *, subnet_t *);
extern void subnet_del(struct node_t *, subnet_t *);
extern char *net2str(subnet_t *);
extern subnet_t *str2net(char *);
extern 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_ipv4(ipv4_t *);
extern subnet_t *lookup_subnet_ipv6(ipv6_t *);

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: tincd.c,v 1.10.4.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"
@ -205,7 +205,7 @@ int keygen(int bits)
{
RSA *rsa_key;
FILE *f;
config_t const *cfg;
char *name = NULL;
char *filename;
fprintf(stderr, _("Generating %d bits keys:\n"), bits);
@ -219,8 +219,10 @@ int keygen(int bits)
else
fprintf(stderr, _("Done.\n"));
if(config && (cfg = get_config_val(config, config_name)))
asprintf(&filename, "%s/hosts/%s", confbase, cfg->data.ptr);
get_config_string(lookup_config(config_tree, "Name"), &name);
if(name)
asprintf(&filename, "%s/hosts/%s", confbase, name);
else
asprintf(&filename, "%s/rsa_key.pub", confbase);
@ -350,8 +352,8 @@ cp
if(do_detach)
{
syslog(LOG_NOTICE, _("Restarting in %d seconds!"), MAXTIMEOUT);
sleep(MAXTIMEOUT);
syslog(LOG_NOTICE, _("Restarting in %d seconds!"), maxtimeout);
sleep(maxtimeout);
}
else
{

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: 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"
@ -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)
{
return a->meta_socket - b->meta_socket;
return a->socket - b->socket;
}
int vertex_compare(vertex_t *a, vertex_t *b)
@ -97,29 +97,38 @@ cp
void free_vertex(vertex_t *v)
{
cp
if(v->from.hostname)
free(v->from.hostname)
if(v->to.hostname)
free(v->to.hostname)
free(v);
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 v, *result;
cp
v.from.node = from;
v.to.node = to;
v.from = from;
v.to = to;
result = avl_search(vertex_tree, &v);
if(result)
return result;
cp
v.from.node = to;
v.to.node = from;
v.from = to;
v.to = from;
return avl_search(vertex_tree, &v);
}
@ -135,7 +144,7 @@ cp
{
v = (vertex_t *)node->data;
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."));

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: 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__
@ -28,6 +28,8 @@
#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 */
@ -37,8 +39,8 @@ typedef struct halfconnection_t {
} halfconnection_t;
typedef struct vertex_t {
struct halfconnection_t from;
struct halfconnection_t to;
struct node_t *from;
struct node_t *to;
long int options; /* options turned on for this connection */
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 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__ */