## Produce this file with automake to get Makefile.in
-# $Id: Makefile.am,v 1.4.4.25 2002/08/24 12:11:40 guus Exp $
+# $Id: Makefile.am,v 1.4.4.26 2002/09/03 20:43:24 guus Exp $
sbin_PROGRAMS = tincd
EXTRA_DIST = linux/device.c freebsd/device.c openbsd/device.c solaris/device.c netbsd/device.c darwin/device.c cygwin/device.c
-tincd_SOURCES = conf.c connection.c device.c edge.c event.c graph.c meta.c net.c net_packet.c net_setup.c \
- net_socket.c netutl.c node.c process.c protocol.c protocol_auth.c protocol_edge.c protocol_misc.c \
+tincd_SOURCES = conf.c connection.c device.c event.c meta.c net.c net_packet.c net_setup.c \
+ net_socket.c netutl.c node.c process.c protocol.c protocol_auth.c protocol_node.c protocol_misc.c \
protocol_key.c protocol_subnet.c route.c subnet.c tincd.c
INCLUDES = @INCLUDES@ -I$(top_builddir) -I$(top_srcdir)/lib
-noinst_HEADERS = conf.h connection.h device.h edge.h event.h graph.h meta.h net.h netutl.h node.h process.h \
+noinst_HEADERS = conf.h connection.h device.h event.h meta.h net.h netutl.h node.h process.h \
protocol.h route.h subnet.h
LIBS = @LIBS@
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.27 2002/06/21 10:11:12 guus Exp $
+ $Id: connection.h,v 1.1.2.28 2002/09/03 20:43:24 guus Exp $
*/
#ifndef __TINC_CONNECTION_H__
#include "conf.h"
#include "node.h"
-#include "edge.h"
#define OPTION_INDIRECT 0x0001
#define OPTION_TCPONLY 0x0002
char *name; /* name he claims to have */
sockaddr_t address; /* his real (internet) ip */
+ sockaddr_t myaddress; /* our own address as seen by him */
+
char *hostname; /* the hostname of its real ip */
int protocol_version; /* used protocol */
int socket; /* socket used for this connection */
long int options; /* options for this connection */
struct connection_status_t status; /* status info */
- int estimated_weight; /* estimation for the weight of the edge for this connection */
+ int estimated_weight; /* estimation for the weight for this connection */
struct timeval start; /* time this connection was started, used for above estimation */
struct outgoing_t *outgoing; /* used to keep track of outgoing connections */
struct node_t *node; /* node associated with the other end */
- struct edge_t *edge; /* edge associated with this connection */
RSA *rsa_key; /* his public/private key */
const EVP_CIPHER *incipher; /* Cipher he will use to send data to us */
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: net.c,v 1.35.4.174 2002/06/21 10:11:12 guus Exp $
+ $Id: net.c,v 1.35.4.175 2002/09/03 20:43:25 guus Exp $
*/
#include "config.h"
#include "process.h"
#include "protocol.h"
#include "subnet.h"
-#include "graph.h"
#include "process.h"
#include "route.h"
#include "device.h"
time_t now = 0;
-/* Purge edges and subnets of unreachable nodes. Use carefully. */
+/* Purge subnets of unreachable nodes. Use carefully. */
void purge(void)
{
- avl_node_t *nnode, *nnext, *enode, *enext, *snode, *snext, *cnode;
+ avl_node_t *nnode, *nnext, *snode, *snext, *cnode;
node_t *n;
- edge_t *e;
subnet_t *s;
connection_t *c;
cp
subnet_del(n, s);
}
- for(enode = n->edge_tree->head; enode; enode = enext)
- {
- enext = enode->next;
- e = (edge_t *)enode->data;
-
- for(cnode = connection_tree->head; cnode; cnode = cnode->next)
- {
- c = (connection_t *)cnode->data;
- if(c->status.active)
- send_del_edge(c, e);
- }
-
- edge_del(e);
- }
-
node_del(n);
}
}
/*
Terminate a connection:
- Close the socket
- - Remove associated edge and tell other connections about it if report = 1
+ - Tell other connections about it if report = 1
- Check if we need to retry making an outgoing connection
- Deactivate the host
*/
void terminate_connection(connection_t *c, int report)
{
- avl_node_t *node;
+ avl_node_t *node, *node2;
connection_t *other;
+ node_t *n;
cp
if(c->status.remove)
return;
c->status.active = 0;
if(c->node)
- c->node->connection = NULL;
-
- if(c->socket)
- close(c->socket);
-
- if(c->edge)
{
- if(report)
+ if(report && c->node->connection)
{
for(node = connection_tree->head; node; node = node->next)
{
other = (connection_t *)node->data;
- if(other->status.active && other != c)
- send_del_edge(other, c->edge);
+ if(other == c)
+ continue;
+ for(node2 = node_tree->head; node2; node2 = node2->next)
+ {
+ n = (node_t *)node2->data;
+ if(n->nexthop == c->node)
+ {
+ send_del_node(other, n);
+ n->status.reachable = 0;
+ }
+ }
}
}
-
- edge_del(c->edge);
-
- /* Run MST and SSSP algorithms */
-
- graph();
+ c->node->connection = NULL;
}
+ if(c->socket)
+ close(c->socket);
+
/* Check if this was our outgoing connection */
if(c->outgoing)
*/
void check_dead_connections(void)
{
- avl_node_t *node, *next;
+ avl_node_t *node;
connection_t *c;
cp
- for(node = connection_tree->head; node; node = next)
+ for(node = connection_tree->head; node; node = node->next)
{
- next = node->next;
c = (connection_t *)node->data;
- if(c->last_ping_time + pingtimeout < now)
+ if(c->last_ping_time + pingtimeout < now && !c->status.remove)
{
if(c->status.active)
{
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: net_packet.c,v 1.1.2.17 2002/06/21 10:11:12 guus Exp $
+ $Id: net_packet.c,v 1.1.2.18 2002/09/03 20:43:25 guus Exp $
*/
#include "config.h"
#include "process.h"
#include "protocol.h"
#include "subnet.h"
-#include "graph.h"
#include "process.h"
#include "route.h"
#include "device.h"
return;
}
- via = (n->via == myself)?n->nexthop:n->via;
+ via = (n->options & OPTION_INDIRECT)?n->nexthop:n;
if(via != n && debug_lvl >= DEBUG_TRAFFIC)
syslog(LOG_ERR, _("Sending packet to %s via %s (%s)"),
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: net_setup.c,v 1.1.2.21 2002/07/10 11:27:06 guus Exp $
+ $Id: net_setup.c,v 1.1.2.22 2002/09/03 20:43:25 guus Exp $
*/
#include "config.h"
#include "process.h"
#include "protocol.h"
#include "subnet.h"
-#include "graph.h"
#include "process.h"
#include "route.h"
#include "device.h"
myself->status.reachable = 1;
node_add(myself);
- graph();
-
cp
/* Open sockets */
init_connections();
init_subnets();
init_nodes();
- init_edges();
init_events();
init_requests();
exit_requests();
exit_events();
- exit_edges();
exit_subnets();
exit_nodes();
exit_connections();
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: net_socket.c,v 1.1.2.16 2002/06/21 10:11:12 guus Exp $
+ $Id: net_socket.c,v 1.1.2.17 2002/09/03 20:43:25 guus Exp $
*/
#include "config.h"
#include "process.h"
#include "protocol.h"
#include "subnet.h"
-#include "graph.h"
#include "process.h"
#include "route.h"
#include "device.h"
return -1;
}
- if(listen(nfd, 3))
+ if(listen(nfd, 0))
{
close(nfd);
syslog(LOG_ERR, _("System call `%s' failed: %s"), "listen", strerror(errno));
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.13 2002/06/21 10:11:13 guus Exp $
+ $Id: node.c,v 1.1.2.14 2002/09/03 20:43:25 guus Exp $
*/
#include "config.h"
node_t *n = (node_t *)xmalloc_and_zero(sizeof(*n));
cp
n->subnet_tree = new_subnet_tree();
- n->edge_tree = new_edge_tree();
n->queue = list_alloc((list_action_t)free);
cp
return n;
free(n->key);
if(n->subnet_tree)
free_subnet_tree(n->subnet_tree);
- if(n->edge_tree)
- free_edge_tree(n->edge_tree);
free(n);
cp
}
void node_del(node_t *n)
{
avl_node_t *node, *next;
- edge_t *e;
subnet_t *s;
cp
for(node = n->subnet_tree->head; node; node = next)
s = (subnet_t *)node->data;
subnet_del(n, s);
}
-
- for(node = n->edge_tree->head; node; node = next)
- {
- next = node->next;
- e = (edge_t *)node->data;
- edge_del(e);
- }
cp
avl_delete(node_tree, n);
avl_delete(node_udp_tree, n);
for(node = node_tree->head; node; node = node->next)
{
n = (node_t *)node->data;
- syslog(LOG_DEBUG, _(" %s at %s cipher %d digest %d maclength %d compression %d options %lx status %04x nexthop %s via %s"),
+ syslog(LOG_DEBUG, _(" %s at %s cipher %d digest %d maclength %d compression %d options %lx status %04x nexthop %s distance %d"),
n->name, n->hostname, n->cipher?n->cipher->nid:0, n->digest?n->digest->type:0, n->maclength, n->compression, n->options,
- n->status, n->nexthop?n->nexthop->name:"-", n->via?n->via->name:"-");
+ n->status, n->nexthop?n->nexthop->name:"-", n->distance);
}
syslog(LOG_DEBUG, _("End of nodes."));
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.16 2002/06/21 10:11:13 guus Exp $
+ $Id: node.h,v 1.1.2.17 2002/09/03 20:43:25 guus Exp $
*/
#ifndef __TINC_NODE_H__
struct node_status_t status;
+ int distance; /* Distance from us to that node */
+
const EVP_CIPHER *cipher; /* Cipher type for UDP packets */
char *key; /* Cipher key and iv */
int keylength; /* Cipher key and iv length*/
avl_tree_t *subnet_tree; /* Pointer to a tree of subnets belonging to this node */
- avl_tree_t *edge_tree; /* Edges with this node as one of the endpoints */
-
struct connection_t *connection; /* Connection associated with this node (if a direct connection exists) */
uint32_t sent_seqno; /* Sequence number last sent to this node */
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.42 2002/07/10 11:27:06 guus Exp $
+ $Id: process.c,v 1.1.2.43 2002/09/03 20:43:25 guus Exp $
*/
#include "config.h"
{
dump_device_stats();
dump_nodes();
- dump_edges();
dump_subnets();
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: protocol.c,v 1.28.4.129 2002/06/21 10:11:13 guus Exp $
+ $Id: protocol.c,v 1.28.4.130 2002/09/03 20:43:25 guus Exp $
*/
#include "config.h"
status_h, error_h, termreq_h,
ping_h, pong_h,
add_subnet_h, del_subnet_h,
- add_edge_h, del_edge_h,
+ add_node_h, del_node_h,
key_changed_h, req_key_h, ans_key_h,
tcppacket_h,
};
"STATUS", "ERROR", "TERMREQ",
"PING", "PONG",
"ADD_SUBNET", "DEL_SUBNET",
- "ADD_EDGE", "DEL_EDGE",
+ "ADD_NODE", "DEL_NODE",
"KEY_CHANGED", "REQ_KEY", "ANS_KEY",
"PACKET",
};
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.30 2002/06/21 10:11:13 guus Exp $
+ $Id: protocol.h,v 1.5.4.31 2002/09/03 20:43:25 guus Exp $
*/
#ifndef __TINC_PROTOCOL_H__
incompatible version have different protocols.
*/
-#define PROT_CURRENT 14
+#define PROT_CURRENT 15
/* Request numbers */
ID = 0, METAKEY, CHALLENGE, CHAL_REPLY, ACK,
STATUS, ERROR, TERMREQ,
PING, PONG,
-// ADD_NODE, DEL_NODE,
ADD_SUBNET, DEL_SUBNET,
- ADD_EDGE, DEL_EDGE,
+ ADD_NODE, DEL_NODE,
KEY_CHANGED, REQ_KEY, ANS_KEY,
PACKET,
LAST /* Guardian for the highest request number */
extern int send_termreq(connection_t *);
extern int send_ping(connection_t *);
extern int send_pong(connection_t *);
-// extern int send_add_node(connection_t *, node_t *);
-// extern int send_del_node(connection_t *, node_t *);
extern int send_add_subnet(connection_t *, subnet_t *);
extern int send_del_subnet(connection_t *, subnet_t *);
-extern int send_add_edge(connection_t *, edge_t *);
-extern int send_del_edge(connection_t *, edge_t *);
+extern int send_add_node(connection_t *, node_t *);
+extern int send_del_node(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 *);
extern int termreq_h(connection_t *);
extern int ping_h(connection_t *);
extern int pong_h(connection_t *);
-// extern int add_node_h(connection_t *);
-// extern int del_node_h(connection_t *);
extern int add_subnet_h(connection_t *);
extern int del_subnet_h(connection_t *);
-extern int add_edge_h(connection_t *);
-extern int del_edge_h(connection_t *);
+extern int add_node_h(connection_t *);
+extern int del_node_h(connection_t *);
extern int key_changed_h(connection_t *);
extern int req_key_h(connection_t *);
extern int ans_key_h(connection_t *);
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: protocol_auth.c,v 1.1.4.9 2002/06/21 10:11:13 guus Exp $
+ $Id: protocol_auth.c,v 1.1.4.10 2002/09/03 20:43:25 guus Exp $
*/
#include "config.h"
#include "meta.h"
#include "connection.h"
#include "node.h"
-#include "edge.h"
-#include "graph.h"
#include "system.h"
int send_ack(connection_t *c)
{
/* ACK message contains rest of the information the other end needs
- to create node_t and edge_t structures. */
+ to create node_t structures. */
int x;
char *address, *port;
gettimeofday(&now, NULL);
c->estimated_weight = (now.tv_sec - c->start.tv_sec) * 1000 + (now.tv_usec - c->start.tv_usec) / 1000;
sockaddr2str(&c->address, &address, &port);
- x = send_request(c, "%d %s %s %d %lx", ACK, myport, address, c->estimated_weight, c->options);
+ x = send_request(c, "%d %s %s %lx", ACK, myport, address, c->options);
free(address);
free(port);
cp
avl_node_t *node, *node2;
node_t *n;
subnet_t *s;
- edge_t *e;
+ connection_t *other;
- /* Send all known subnets */
+ /* Send all known nodes and subnets */
for(node = node_tree->head; node; node = node->next)
{
n = (node_t *)node->data;
+
+ if(n != c->node && n != myself)
+ send_add_node(c, n);
for(node2 = n->subnet_tree->head; node2; node2 = node2->next)
{
}
}
- /* Send all known edges */
-
- for(node = edge_tree->head; node; node = node->next)
+ /* Inform others of this new node */
+
+ for(node = connection_tree->head; node; node = node->next)
{
- e = (edge_t *)node->data;
-
- if(e == c->edge)
- continue;
-
- send_add_edge(c, e);
+ other = (connection_t *)node->data;
+
+ if(other->status.active && other != c)
+ send_add_node(other, c->node);
}
}
char myaddress[MAX_STRING_SIZE];
char hisport[MAX_STRING_SIZE];
char *hisaddress, *dummy;
- int weight;
long int options;
node_t *n;
- connection_t *other;
avl_node_t *node;
cp
- if(sscanf(c->buffer, "%*d "MAX_STRING" "MAX_STRING" %d %lx", hisport, myaddress, &weight, &options) != 4)
+ if(sscanf(c->buffer, "%*d "MAX_STRING" "MAX_STRING" %lx", hisport, myaddress, &options) != 3)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ACK", c->name, c->hostname);
return -1;
syslog(LOG_DEBUG, _("Established a second connection with %s (%s), closing old connection"), n->name, n->hostname);
terminate_connection(n->connection, 0);
}
-
- /* FIXME: check if information in existing node matches that of the other end of this connection */
}
- n->connection = c;
c->node = n;
c->options |= options;
-
- /* Create an edge_t for this connection */
-
- c->edge = new_edge();
-cp
- c->edge->from.node = myself;
- c->edge->from.udpaddress = str2sockaddr(myaddress, myport);
- c->edge->to.node = n;
+ c->myaddress = str2sockaddr(myaddress, myport);
+
+ n->connection = c;
sockaddr2str(&c->address, &hisaddress, &dummy);
- c->edge->to.udpaddress = str2sockaddr(hisaddress, hisport);
- free(hisaddress);
- free(dummy);
- c->edge->weight = (weight + c->estimated_weight) / 2;
- c->edge->connection = c;
- c->edge->options = c->options;
-cp
- edge_add(c->edge);
+ node = avl_unlink(node_udp_tree, n);
+ n->address = str2sockaddr(hisaddress, hisport);
+ avl_insert_node(node_udp_tree, node);
+ if(n->hostname)
+ free(n->hostname);
+ n->hostname = sockaddr2hostname(&n->address);
+ n->options = c->options;
+ n->distance = 1;
+ n->via = n->nexthop = n;
+ n->status.reachable = 1;
+ n->status.validkey = 0;
+ n->status.waitingforkey = 0;
/* Activate this connection */
syslog(LOG_NOTICE, _("Connection with %s (%s) activated"), c->name, c->hostname);
cp
- /* Send him everything we know */
+ /* Send him everything we know and tell the others about him */
send_everything(c);
-
- /* Notify others of this connection */
-
- for(node = connection_tree->head; node; node = node->next)
- {
- other = (connection_t *)node->data;
-
- if(other->status.active && other != c)
- send_add_edge(other, c->edge);
- }
-
- /* Run MST and SSSP algorithms */
-
- graph();
cp
return 0;
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: protocol_key.c,v 1.1.4.7 2002/06/21 10:11:19 guus Exp $
+ $Id: protocol_key.c,v 1.1.4.8 2002/09/03 20:43:25 guus Exp $
*/
#include "config.h"
#include "meta.h"
#include "connection.h"
#include "node.h"
-#include "edge.h"
#include "system.h"
n->status.validkey = 0;
n->status.waitingforkey = 0;
- n->sent_seqno = 0;
/* Tell the others */
if(to == myself) /* Yes, send our own key back */
{
mykeyused = 1;
- from->received_seqno = 0;
+ from->sent_seqno = 0;
send_ans_key(c, myself, from);
}
else
from->status.validkey = 1;
from->status.waitingforkey = 0;
-
+ from->received_seqno = 0;
+
/* Check and lookup cipher and digest algorithms */
if(cipher)
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: protocol_node.c,v 1.1.4.1 2002/09/02 22:40:42 guus Exp $
+ $Id: protocol_node.c,v 1.1.4.2 2002/09/03 20:43:25 guus Exp $
*/
#include "config.h"
int x;
char *address, *port;
cp
+ if(!n->status.reachable)
+ return 0;
+
sockaddr2str(&n->address, &address, &port);
x = send_request(c, "%d %s %s %s %lx %d", ADD_NODE,
n->name, address, port,
- n->options, n->distance + 1);
+ n->options, n->distance + 1); // Alternatively, use n->distance + c->estimated_weight
free(address);
free(port);
cp
return -1;
}
+ /* This node is indirect if it's nexthop is as well */
+
+ if(c->node->options & OPTION_INDIRECT)
+ options |= OPTION_INDIRECT;
+
/* Lookup nodes */
n = lookup_node(name);
n->hostname = sockaddr2hostname(&n->address);
n->options = options;
n->distance = distance;
- n->nexthop = c->node;
+ n->via = n->nexthop = c->node;
+ n->status.reachable = 1;
node_add(n);
}
else
{
// If this ADD_NODE is closer or more direct, use it instead of the old one.
- if((n->options & OPTION_INDIRECT) && !(options & OPTION_INDIRECT) || n->distance > distance)
+ if(((n->options & OPTION_INDIRECT) && !(options & OPTION_INDIRECT)) || n->distance > distance)
{
- free(n->hostname);
+ avl_node_t *node = avl_unlink(node_udp_tree, n);
n->address = str2sockaddr(address, port);
+ avl_insert_node(node_udp_tree, node);
+ if(n->hostname)
+ free(n->hostname);
n->hostname = sockaddr2hostname(&n->address);
n->options = options;
n->distance = distance;
- n->nexthop = c->node;
+ n->via = n->nexthop = c->node;
+ n->status.reachable = 1;
+ n->status.validkey = 0;
+ n->status.waitingforkey = 0;
}
else
// Otherwise, just ignore it.
send_del_node(other, n);
}
- /* Delete the node */
+ /* "Delete" the node */
- node_del(n);
-
- exit:
+ n->status.reachable = 0;
+ n->status.validkey = 0;
cp
return 0;
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: protocol_subnet.c,v 1.1.4.4 2002/06/21 10:11:19 guus Exp $
+ $Id: protocol_subnet.c,v 1.1.4.5 2002/09/03 20:43:26 guus Exp $
*/
#include "config.h"
#include "meta.h"
#include "connection.h"
#include "node.h"
-#include "edge.h"
-#include "graph.h"
#include "system.h"