Updated terminate_connection() so you can choose if DEL_HOSTs should be

sent or not.
This commit is contained in:
Guus Sliepen 2001-07-21 15:34:18 +00:00
parent 12f6b80429
commit acb853205d
4 changed files with 42 additions and 38 deletions

View file

@ -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.14 2001/07/20 20:25:10 guus Exp $ $Id: connection.c,v 1.1.2.15 2001/07/21 15:34:18 guus Exp $
*/ */
#include "config.h" #include "config.h"
@ -172,7 +172,6 @@ cp
{ {
avl_delete(id_tree, cl); avl_delete(id_tree, cl);
avl_delete(active_tree, cl); avl_delete(active_tree, cl);
cl->status.active = 0;
} }
cp cp
} }

View file

@ -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.c,v 1.35.4.123 2001/07/20 20:25:10 guus Exp $ $Id: net.c,v 1.35.4.124 2001/07/21 15:34:18 guus Exp $
*/ */
#include "config.h" #include "config.h"
@ -247,7 +247,7 @@ cp
if((cl->options | myself->options) & OPTION_TCPONLY) if((cl->options | myself->options) & OPTION_TCPONLY)
{ {
if(send_tcppacket(cl, packet)) if(send_tcppacket(cl, packet))
terminate_connection(cl); terminate_connection(cl, 1);
} }
else else
send_udppacket(cl, packet); send_udppacket(cl, packet);
@ -1009,10 +1009,10 @@ cp
next = node->next; next = node->next;
p = (connection_t *)node->data; p = (connection_t *)node->data;
p->status.outgoing = 0; p->status.outgoing = 0;
terminate_connection(p); terminate_connection(p, 0);
} }
terminate_connection(myself); terminate_connection(myself, 0);
destroy_trees(); destroy_trees();
@ -1136,8 +1136,9 @@ cp
- Remove associated hosts and subnets - Remove associated hosts and subnets
- Deactivate the host - Deactivate the host
- Since it might still be referenced, put it on the prune list. - Since it might still be referenced, put it on the prune list.
- If report == 1, then send DEL_HOST messages to the other tinc daemons.
*/ */
void terminate_connection(connection_t *cl) void terminate_connection(connection_t *cl, int report)
{ {
connection_t *p; connection_t *p;
subnet_t *subnet; subnet_t *subnet;
@ -1151,6 +1152,8 @@ cp
if(cl->socket) if(cl->socket)
close(cl->socket); close(cl->socket);
connection_del(cl);
if(cl->status.meta) if(cl->status.meta)
{ {
if(debug_lvl >= DEBUG_CONNECTIONS) if(debug_lvl >= DEBUG_CONNECTIONS)
@ -1159,28 +1162,31 @@ cp
close(cl->meta_socket); close(cl->meta_socket);
/* Find all connections that were lost because they were behind cl
(the connection that was dropped). */
for(node = active_tree->head; node; node = next)
{
next = node->next;
p = (connection_t *)node->data;
if(p->nexthop == cl && p != cl)
terminate_connection(p);
}
/* Inform others of termination if it was still active */
if(cl->status.active) if(cl->status.active)
for(node = connection_tree->head; node; node = node->next) {
{ /* Find all connections that were lost because they were behind cl
p = (connection_t *)node->data; (the connection that was dropped). */
if(p->status.active && p != cl)
send_del_host(p, cl); /* Sounds like recursion, but p does not have a meta connection :) */ for(node = active_tree->head; node; node = next)
} {
next = node->next;
p = (connection_t *)node->data;
if(p->nexthop == cl)
terminate_connection(p, report);
}
}
} }
/* Inform others of termination if needed */
if(report)
for(node = connection_tree->head; node; node = node->next)
{
p = (connection_t *)node->data;
if(p->status.active)
send_del_host(p, cl); /* Sounds like recursion, but p does not have a meta connection :) */
}
/* Remove the associated subnets */ /* Remove the associated subnets */
for(node = cl->subnet_tree->head; node; node = next) for(node = cl->subnet_tree->head; node; node = next)
@ -1203,7 +1209,6 @@ cp
/* Schedule it for pruning */ /* Schedule it for pruning */
prune_add(cl); prune_add(cl);
connection_del(cl);
} }
/* /*
@ -1235,7 +1240,7 @@ cp
syslog(LOG_INFO, _("%s (%s) didn't respond to PING"), syslog(LOG_INFO, _("%s (%s) didn't respond to PING"),
cl->name, cl->hostname); cl->name, cl->hostname);
cl->status.timeout = 1; cl->status.timeout = 1;
terminate_connection(cl); terminate_connection(cl, 1);
} }
else else
{ {
@ -1300,7 +1305,7 @@ cp
if(FD_ISSET(p->meta_socket, f)) if(FD_ISSET(p->meta_socket, f))
if(receive_meta(p) < 0) if(receive_meta(p) < 0)
{ {
terminate_connection(p); terminate_connection(p, 1);
return; return;
} }
} }

View file

@ -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.33 2001/06/08 18:02:10 guus Exp $ $Id: net.h,v 1.9.4.34 2001/07/21 15:34:18 guus Exp $
*/ */
#ifndef __TINC_NET_H__ #ifndef __TINC_NET_H__
@ -115,7 +115,7 @@ 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 *); extern void terminate_connection(connection_t *, int);
extern void flush_queue(connection_t *); extern void flush_queue(connection_t *);
#include <config.h> #include <config.h>

View file

@ -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: protocol.c,v 1.28.4.102 2001/07/20 20:25:10 guus Exp $ $Id: protocol.c,v 1.28.4.103 2001/07/21 15:34:18 guus Exp $
*/ */
#include "config.h" #include "config.h"
@ -245,7 +245,7 @@ cp
cl->status.outgoing = 1; cl->status.outgoing = 1;
old->status.outgoing = 0; old->status.outgoing = 0;
} }
terminate_connection(old); terminate_connection(old, 0);
return 0; return 0;
} }
@ -829,7 +829,7 @@ cp
if((old = lookup_id(name))) if((old = lookup_id(name)))
{ {
if((new->address == old->address) && (new->port == old->port)) if((new->address == old->address) && (new->port == old->port) && (cl == old->nexthop))
{ {
if(debug_lvl >= DEBUG_CONNECTIONS) if(debug_lvl >= DEBUG_CONNECTIONS)
syslog(LOG_NOTICE, _("Got duplicate ADD_HOST for %s (%s) from %s (%s)"), syslog(LOG_NOTICE, _("Got duplicate ADD_HOST for %s (%s) from %s (%s)"),
@ -843,7 +843,7 @@ cp
syslog(LOG_NOTICE, _("Removing old entry for %s (%s) in favour of new connection"), syslog(LOG_NOTICE, _("Removing old entry for %s (%s) in favour of new connection"),
old->name, old->hostname); old->name, old->hostname);
terminate_connection(old); terminate_connection(old, 0);
} }
} }
@ -933,7 +933,7 @@ cp
/* Ok, since EVERYTHING seems to check out all right, delete it */ /* Ok, since EVERYTHING seems to check out all right, delete it */
terminate_connection(old); terminate_connection(old, 0);
/* Tell the rest about the deleted host */ /* Tell the rest about the deleted host */
@ -1006,7 +1006,7 @@ cp
cl->name, cl->hostname, strerror(err), errorstring); cl->name, cl->hostname, strerror(err), errorstring);
} }
terminate_connection(cl); terminate_connection(cl, 1);
cp cp
return 0; return 0;
} }
@ -1020,7 +1020,7 @@ cp
int termreq_h(connection_t *cl) int termreq_h(connection_t *cl)
{ {
cp cp
terminate_connection(cl); terminate_connection(cl, 1);
cp cp
return 0; return 0;
} }