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.3 2001/10/27 13:13:35 guus Exp $
+ $Id: device.h,v 1.1.2.4 2001/10/31 12:50:24 guus Exp $
*/
#ifndef __TINC_DEVICE_H__
#define __TINC_DEVICE_H__
extern int device_fd;
+extern char *device;
+extern char *interface;
extern int setup_device(void);
extern void close_device(void);
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.4 2001/10/30 12:59:12 guus Exp $
+ $Id: graph.c,v 1.1.2.5 2001/10/31 12:50:24 guus Exp $
*/
/* We need to generate two trees from the graph:
void mst_kruskal(void)
{
- avl_node_t *node;
+ avl_node_t *node, *next;
edge_t *e;
node_t *n;
connection_t *c;
/* Add safe edges */
- while(safe_edges < nodes - 1)
- for(skipped = 0, node = edge_weight_tree->head; node; node = node->next)
+ for(skipped = 0, node = edge_weight_tree->head; node; node = next)
{
+ next = node->next;
e = (edge_t *)node->data;
if(e->from->status.visited == e->to->status.visited)
safe_edges++;
if(skipped)
- break;
+ {
+ next = edge_weight_tree->head;
+ continue;
+ }
}
}
Running time: O(E)
*/
-void sssp_bfs(void)
+void sssp_bfs(int prune)
{
avl_node_t *node, *from, *next, *to;
edge_t *e;
{
check->status.visited = 1;
check->nexthop = (n->nexthop == myself) ? check : n->nexthop;
- check->via = check; /* FIXME: only if !(e->options & INDIRECT), otherwise use n->via */
+ check->via = (e->options & OPTION_INDIRECT || n->via != n) ? n->via : check;
node = avl_alloc_node();
node->data = check;
avl_insert_before(todo_tree, from, node);
}
avl_free_tree(todo_tree);
+
+ /* Nodes we haven't visited are unreachable, prune them. */
+
+ if(prune)
+ for(node = node_tree->head; node; node = next)
+ {
+ next = node->next;
+ n = (node_t *)node->data;
+
+ if(n->status.visited == 0)
+ node_del(n);
+ }
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: graph.h,v 1.1.2.1 2001/10/29 13:14:57 guus Exp $
+ $Id: graph.h,v 1.1.2.2 2001/10/31 12:50:24 guus Exp $
*/
extern void mst_kruskal(void);
-extern void mst_prim(void);
-extern void sssp_bfs(void);
+extern void sssp_bfs(int);
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: device.c,v 1.1.2.3 2001/10/27 13:13:35 guus Exp $
+ $Id: device.c,v 1.1.2.4 2001/10/31 12:50:24 guus Exp $
*/
#include "config.h"
int device_fd = -1;
int device_type;
-char *device_fname;
+char *device;
+char *interface;
+char ifrname[IFNAMSIZ];
char *device_info;
int device_total_in = 0;
struct ifreq ifr;
cp
- if(!get_config_string(lookup_config(config_tree, "Device"), &device_fname))
- device_fname = DEFAULT_DEVICE;
+ if(!get_config_string(lookup_config(config_tree, "Device"), &device))
+ device = DEFAULT_DEVICE;
+ if(!get_config_string(lookup_config(config_tree, "Interface"), &interface))
+ interface = netname;
cp
- if((device_fd = open(device_fname, O_RDWR | O_NONBLOCK)) < 0)
+ if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0)
{
- syslog(LOG_ERR, _("Could not open %s: %m"), device_fname);
+ syslog(LOG_ERR, _("Could not open %s: %m"), device);
return -1;
}
cp
memset(&ifr, 0, sizeof(ifr));
cp
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
- if (netname)
- strncpy(ifr.ifr_name, netname, IFNAMSIZ);
+ if (interface)
+ strncpy(ifr.ifr_name, interface, IFNAMSIZ);
cp
if (!ioctl(device_fd, TUNSETIFF, (void *) &ifr))
{
- device_info = _("Linux tun/tap device");
+ device_info = _("Linux tun/tap device");
device_type = DEVICE_TYPE_TUNTAP;
+ strncpy(ifrname, ifr.ifr_name, IFNAMSIZ);
+ interface = ifrname;
}
else
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);
device_type = DEVICE_TYPE_TUNTAP;
device_info = _("Linux tun/tap device");
+ strncpy(ifrname, ifr.ifr_name, IFNAMSIZ);
+ interface = ifrname;
}
else
#endif
device_type = DEVICE_TYPE_ETHERTAP;
}
- syslog(LOG_INFO, _("%s is a %s"), device_fname, device_info);
+ syslog(LOG_INFO, _("%s is a %s"), device, device_info);
cp
return 0;
}
{
if((lenin = read(device_fd, packet->data, MTU)) <= 0)
{
- syslog(LOG_ERR, _("Error while reading from %s %s: %m"), device_info, device_fname);
+ syslog(LOG_ERR, _("Error while reading from %s %s: %m"), device_info, device);
return -1;
}
if((lenin = readv(device_fd, vector, 2)) <= 0)
{
- syslog(LOG_ERR, _("Error while reading from %s %s: %m"), device_info, device_fname);
+ syslog(LOG_ERR, _("Error while reading from %s %s: %m"), device_info, device);
return -1;
}
{
if(write(device_fd, packet->data, packet->len) < 0)
{
- syslog(LOG_ERR, _("Can't write to %s %s: %m"), device_info, device_fname);
+ syslog(LOG_ERR, _("Can't write to %s %s: %m"), device_info, device);
return -1;
}
}
if(writev(device_fd, vector, 2) < 0)
{
- syslog(LOG_ERR, _("Can't write to %s %s: %m"), device_info, device_fname);
+ syslog(LOG_ERR, _("Can't write to %s %s: %m"), device_info, device);
return -1;
}
}
void dump_device_stats(void)
{
cp
- syslog(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device_fname);
+ syslog(LOG_DEBUG, _("Statistics for %s %s:"), device_info, device);
syslog(LOG_DEBUG, _(" total bytes in: %10d"), device_total_in);
syslog(LOG_DEBUG, _(" total bytes out: %10d"), device_total_out);
cp
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.143 2001/10/30 16:34:32 guus Exp $
+ $Id: net.c,v 1.35.4.144 2001/10/31 12:50:24 guus Exp $
*/
#include "config.h"
/* Deactivate */
c->status.active = 0;
- c->node->connection = NULL;
+ if(c->node)
+ c->node->connection = NULL;
do_prune = 1;
cp
}
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.5 2001/10/30 12:59:12 guus Exp $
+ $Id: node.c,v 1.1.2.6 2001/10/31 12:50:24 guus Exp $
*/
#include "config.h"
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)
+ {
+ next = node->next;
+ s = (subnet_t *)node->data;
+ subnet_del(n, s);
+ }
+
+ for(node = n->subnet_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);
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.29 2001/10/28 10:16:18 guus Exp $
+ $Id: process.c,v 1.1.2.30 2001/10/31 12:50:24 guus Exp $
*/
#include "config.h"
#include "subnet.h"
#include "device.h"
#include "connection.h"
+#include "device.h"
#include "system.h"
char *scriptname;
char *s;
cp
+#ifdef HAVE_UNSETENV
+ unsetenv("NETNAME");
+ unsetenv("DEVICE");
+ unsetenv("INTERFACE");
+#endif
+
if(netname)
{
asprintf(&s, "NETNAME=%s", netname);
putenv(s); /* Don't free s! see man 3 putenv */
}
-#ifdef HAVE_UNSETENV
- else
+
+ if(device)
{
- unsetenv("NETNAME");
+ asprintf(&s, "DEVICE=%s", device);
+ putenv(s); /* Don't free s! see man 3 putenv */
+ }
+
+ if(interface)
+ {
+ asprintf(&s, "INTERFACE=%s", interface);
+ putenv(s); /* Don't free s! see man 3 putenv */
}
-#endif
chdir("/");
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.114 2001/10/30 16:34:32 guus Exp $
+ $Id: protocol.c,v 1.28.4.115 2001/10/31 12:50:24 guus Exp $
*/
#include "config.h"
/* Run MST and SSSP algorithms */
mst_kruskal();
- sssp_bfs();
+ sssp_bfs(0);
cp
return 0;
}
int del_node_h(connection_t *c)
{
node_t *n;
- edge_t *e;
char name[MAX_STRING_SIZE];
ipv4_t address;
port_t port;
connection_t *other;
- avl_node_t *node, *next;
+ avl_node_t *node;
cp
if(sscanf(c->buffer, "%*d "MAX_STRING" %lx:%hd", name, &address, &port) != 3)
{
send_del_node(other, n);
}
- /* Delete all edges associated with the node */
-
- for(node = n->edge_tree->head; node; node = next)
- {
- next = node->next;
- e = (edge_t *)node->data;
- edge_del(e);
- }
-
/* Delete the node */
node_del(n);
mst_kruskal();
- sssp_bfs();
+ sssp_bfs(0);
cp
return 0;
}
/* Run MST before or after we tell the rest? */
mst_kruskal();
- sssp_bfs();
+ sssp_bfs(0);
cp
return 0;
}
/* Run MST before or after we tell the rest? */
mst_kruskal();
- sssp_bfs();
+ sssp_bfs(1);
cp
return 0;
}