## Produce this file with automake to get Makefile.in
-# $Id: Makefile.am,v 1.4.4.16 2001/10/28 10:16:18 guus Exp $
+# $Id: Makefile.am,v 1.4.4.17 2001/10/30 12:59:12 guus Exp $
sbin_PROGRAMS = tincd
INCLUDES = @INCLUDES@ -I$(top_builddir) -I$(top_srcdir)/lib -I$(top_srcdir)/intl
-noinst_HEADERS = conf.h connection.h device.h edge.h meta.h net.h netutl.h node.h process.h \
+noinst_HEADERS = conf.h connection.h device.h edge.h graph.h meta.h net.h netutl.h node.h process.h \
protocol.h route.h subnet.h
LIBS = @LIBS@ @INTLLIBS@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: edge.c,v 1.1.2.3 2001/10/28 22:42:49 guus Exp $
+ $Id: edge.c,v 1.1.2.4 2001/10/30 12:59:12 guus Exp $
*/
#include "config.h"
avl_tree_t *new_edge_tree(void)
{
cp
- edge_tree = avl_alloc_tree((avl_compare_t)edge_name_compare, NULL);
+ return avl_alloc_tree((avl_compare_t)edge_name_compare, NULL);
cp
}
for(node = edge_tree->head; node; node = node->next)
{
e = (edge_t *)node->data;
- syslog(LOG_DEBUG, _(" %s - %s options %ld"),
- e->from->name, e->to->name, e->options);
+ syslog(LOG_DEBUG, _(" %s - %s options %ld weight %d"),
+ e->from->name, e->to->name, e->options, e->weight);
}
syslog(LOG_DEBUG, _("End of edges."));
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: graph.c,v 1.1.2.3 2001/10/29 13:14:57 guus Exp $
+ $Id: graph.c,v 1.1.2.4 2001/10/30 12:59:12 guus Exp $
*/
/* We need to generate two trees from the graph:
favour Kruskal's, because we make an extra AVL tree of edges sorted on
weights (metric). That tree only has to be updated when an edge is added or
removed, and during the MST algorithm we just have go linearly through that
- tree, adding safe edges until #edges = #nodes - 1.
+ tree, adding safe edges until #edges = #nodes - 1. The implementation here
+ however is not so fast, because I tried to avoid having to make a forest and
+ merge trees.
For the SSSP algorithm Dijkstra's seems to be a nice choice. Currently a
simple breadth-first search is presented here.
int safe_edges = 0;
int skipped;
- syslog(LOG_DEBUG, _("Running Kruskal's algorithm:"));
-
/* Clear visited status on nodes */
for(node = node_tree->head; node; node = node->next)
while(safe_edges < nodes - 1)
for(skipped = 0, node = edge_weight_tree->head; node; node = node->next)
{
-// Algorithm should work without this:
-// if(safe_edges = nodes - 1)
-// break;
-
e = (edge_t *)node->data;
if(e->from->status.visited == e->to->status.visited)
safe_edges++;
- syslog(LOG_DEBUG, _("Adding safe edge %s - %s weight %d"), e->from->name, e->to->name, e->weight);
-
if(skipped)
break;
}
-
- syslog(LOG_DEBUG, _("Done."));
-
- if(safe_edges != nodes - 1)
- {
- syslog(LOG_ERR, _("Implementation of Kruskal's algorithm is screwed: %d nodes, found %d safe edges"), nodes, safe_edges);
- }
}
/* Implementation of a simple breadth-first search algorithm.
avl_node_t *node, *from, *next, *to;
edge_t *e;
node_t *n, *check;
- int nodes = 0;
- int visited = 0;
avl_tree_t *todo_tree;
- syslog(LOG_DEBUG, _("Running BFS algorithm:"));
-
todo_tree = avl_alloc_tree(NULL, NULL);
/* Clear visited status on nodes */
{
n = (node_t *)node->data;
n->status.visited = 0;
- nodes++;
}
/* Begin with myself */
node = avl_alloc_node();
node->data = myself;
avl_insert_top(todo_tree, node);
- visited++;
/* Loop while todo_tree is filled */
if(!check->status.visited)
{
check->status.visited = 1;
- check->nexthop = (n->nexthop == myself) ? n : n->nexthop;
+ check->nexthop = (n->nexthop == myself) ? check : n->nexthop;
check->via = check; /* FIXME: only if !(e->options & INDIRECT), otherwise use n->via */
node = avl_alloc_node();
node->data = check;
avl_insert_before(todo_tree, from, node);
- visited++;
- syslog(LOG_DEBUG, _("Node %s nexthop %s via %s"), check->name, check->nexthop->name, check->via->name);
}
}
}
}
- syslog(LOG_DEBUG, _("Done."));
-
avl_free_tree(todo_tree);
-
- if(visited != nodes)
- {
- syslog(LOG_ERR, _("Implementation of BFS algorithm is screwed: %d nodes, visited %d"), nodes, visited);
- }
}
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.141 2001/10/28 10:16:18 guus Exp $
+ $Id: net.c,v 1.35.4.142 2001/10/30 12:59:12 guus Exp $
*/
#include "config.h"
return;
}
- if(!n->status.active)
- {
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_INFO, _("%s (%s) is not active, dropping packet"),
- n->name, n->hostname);
-
- return;
- }
-/* FIXME
- if(n->via == myself)
- via = n->nexthop;
- else
- via = n->via;
-
- if(via != n && debug_lvl >= DEBUG_TRAFFIC)
+ if(n->via != n && debug_lvl >= DEBUG_TRAFFIC)
syslog(LOG_ERR, _("Sending packet to %s via %s (%s)"),
- n->name, via->name, via->hostname);
+ n->name, n->via->name, n->via->hostname);
- if((myself->options | via->options) & OPTION_TCPONLY)
+ if((myself->options | n->via->options) & OPTION_TCPONLY)
{
- if(send_tcppacket(via->connection, packet))
- terminate_connection(via->connection, 1);
+ if(send_tcppacket(n->via->connection, packet))
+ terminate_connection(n->via->connection, 1);
}
else
- send_udppacket(via, packet);
-*/
+ send_udppacket(n->via, packet);
}
/* Broadcast a packet to all active direct connections */
if(!n)
{
- syslog(LOG_WARNING, _("Received UDP packets on port %hd from unknown source %x:%hd"), myself->port, ntohl(from.sin_addr.s_addr), ntohs(from.sin_port));
+ syslog(LOG_WARNING, _("Received UDP packet on port %hd from unknown source %x:%hd"), myself->port, ntohl(from.sin_addr.s_addr), ntohs(from.sin_port));
return;
}
/*
get_config_string(cfg, &name);
cfg = lookup_config_next(config_tree, cfg); /* Next time skip to next ConnectTo line */
- if(!setup_outgoing_connection(name)) /* function returns 0 when there are no problems */
+ if(setup_outgoing_connection(name)) /* function returns 0 when there are no problems */
retry = 1;
}
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.4 2001/10/28 22:42:49 guus Exp $
+ $Id: node.c,v 1.1.2.5 2001/10/30 12:59:12 guus Exp $
*/
#include "config.h"
return strcmp(a->name, b->name);
}
-int node_udp_compare(connection_t *a, connection_t *b)
+int node_udp_compare(node_t *a, node_t *b)
{
if(a->address < b->address)
return -1;
for(node = node_tree->head; node; node = node->next)
{
n = (node_t *)node->data;
- syslog(LOG_DEBUG, _(" %s at %s port %hd options %ld status %04x"),
+ syslog(LOG_DEBUG, _(" %s at %s port %hd options %ld status %04x nexthop %s via %s"),
n->name, n->hostname, n->port, n->options,
- n->status);
+ n->status, n->nexthop->name, n->via->name);
}
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: protocol.c,v 1.28.4.112 2001/10/28 22:42:49 guus Exp $
+ $Id: protocol.c,v 1.28.4.113 2001/10/30 12:59:12 guus Exp $
*/
#include "config.h"
#include "connection.h"
#include "node.h"
#include "edge.h"
+#include "graph.h"
#include "system.h"
int weight;
node_t *n;
subnet_t *s;
+ edge_t *e;
+ connection_t *other;
avl_node_t *node, *node2;
cp
if(sscanf(c->buffer, "%*d %hd %d", &port, &weight) != 2)
{
n = new_node();
n->name = xstrdup(c->name);
+ n->address = c->address;
n->hostname = xstrdup(c->hostname);
n->port = port;
c->allow_request = ALL;
c->status.active = 1;
+ c->node->cipher = EVP_bf_cbc();
+ c->node->keylength = c->node->cipher->key_len + c->node->cipher->iv_len;
if(debug_lvl >= DEBUG_CONNECTIONS)
syslog(LOG_NOTICE, _("Connection with %s (%s) activated"), c->name, c->hostname);
if(n == c->node || n == myself)
continue;
- /* Notify others of this connection */
-
- if(n->connection)
- send_add_node(n->connection, c->node);
-
- /* Notify new connection of everything we know */
-
send_add_node(c, n);
for(node2 = c->node->subnet_tree->head; node2; node2 = node2->next)
send_add_subnet(c, s);
}
}
+
+ /* Send all known edges */
+
+ for(node = edge_tree->head; node; node = node->next)
+ {
+ e = (edge_t *)node->data;
+
+ if(e == c->edge)
+ continue;
+
+ send_add_edge(c, e);
+ }
+
+ /* Notify others of this connection */
+
+ for(node = connection_tree->head; node; node = node->next)
+ {
+ other = (connection_t *)node->data;
+
+ if(other == c)
+ continue;
+
+ send_add_node(other, c->node);
+ send_add_edge(other, c->edge);
+ }
+
+ /* Run MST and SSSP algorithms */
+
+ mst_kruskal();
+ sssp_bfs();
cp
return 0;
}
int send_add_edge(connection_t *c, edge_t *e)
{
cp
- return send_request(c, "%d %s %s %lx", ADD_NODE,
- e->from->name, e->to->name, e->options);
+ return send_request(c, "%d %s %s %lx %d", ADD_NODE,
+ e->from->name, e->to->name, e->options, e->weight);
}
int add_edge_h(connection_t *c)
char from_name[MAX_STRING_SIZE];
char to_name[MAX_STRING_SIZE];
long int options;
+ int weight;
avl_node_t *node;
cp
- if(sscanf(c->buffer, "%*d "MAX_STRING" "MAX_STRING" %lx", from_name, to_name, &options) != 3)
+ if(sscanf(c->buffer, "%*d "MAX_STRING" "MAX_STRING" %lx %d", from_name, to_name, &options, &weight) != 4)
{
syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ADD_EDGE", c->name, c->hostname);
return -1;
e->from = from;
e->to = to;
e->options = options;
+ e->weight = weight;
edge_add(e);
}
send_add_edge(other, e);
}
+ /* Run MST before or after we tell the rest? */
+
+ mst_kruskal();
+ sssp_bfs();
cp
return 0;
}
/* Delete the edge */
edge_del(e);
+
+ /* Run MST before or after we tell the rest? */
+
+ mst_kruskal();
+ sssp_bfs();
cp
return 0;
}
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.27 2001/10/28 22:42:49 guus Exp $
+ $Id: subnet.c,v 1.1.2.28 2001/10/30 12:59:12 guus Exp $
*/
#include "config.h"
int subnet_compare_mac(subnet_t *a, subnet_t *b)
{
- int result;
cp
- 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);
+ return memcmp(&a->net.mac.address, &b->net.mac.address, sizeof(mac_t));
}
int subnet_compare_ipv4(subnet_t *a, subnet_t *b)
else if(a->net.ipv4.mask > b->net.ipv4.mask)
return 1;
- return strcmp(a->owner->name, b->owner->name);
+ return 0;
}
int subnet_compare_ipv6(subnet_t *a, subnet_t *b)
if(result)
return result;
- return strcmp(a->owner->name, b->owner->name);
+ return 0;
}
int subnet_compare(subnet_t *a, subnet_t *b)
free(subnet);
}
-/* Linked list management */
+/* Adding and removing subnets */
void subnet_add(node_t *n, subnet_t *subnet)
{