Copyright (C) 1998-2005 Ivo Timmermans,
2000-2011 Guus Sliepen <guus@tinc-vpn.org>
2006 Scott Lamb <slamb@slamb.org>
+ 2011 Loïc Grenié <loic.grenie@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
time_t now = 0;
int contradicting_add_edge = 0;
int contradicting_del_edge = 0;
+static int sleeptime = 10;
/* Purge edges and subnets of unreachable nodes. Use carefully. */
for(snode = n->subnet_tree->head; snode; snode = snext) {
snext = snode->next;
s = snode->data;
- send_del_subnet(broadcast, s);
+ send_del_subnet(everyone, s);
if(!strictsubnets)
subnet_del(n, s);
}
enext = enode->next;
e = enode->data;
if(!tunnelserver)
- send_del_edge(broadcast, e);
+ send_del_edge(everyone, e);
edge_del(e);
}
}
if(c->edge) {
if(report && !tunnelserver)
- send_del_edge(broadcast, c->edge);
+ send_del_edge(everyone, c->edge);
edge_del(c->edge);
e = lookup_edge(c->node, myself);
if(e) {
if(!tunnelserver)
- send_del_edge(broadcast, e);
+ send_del_edge(everyone, e);
edge_del(e);
}
}
/* check input from kernel */
if(device_fd >= 0 && FD_ISSET(device_fd, readset)) {
- if(read_packet(&packet)) {
+ if(devops.read(&packet)) {
errors = 0;
packet.priority = 0;
route(myself, &packet);
for(i = 0; i < listen_sockets; i++) {
if(FD_ISSET(listen_socket[i].udp, readset))
- handle_incoming_vpn_data(listen_socket[i].udp);
+ handle_incoming_vpn_data(i);
if(FD_ISSET(listen_socket[i].tcp, readset))
handle_new_meta_connection(listen_socket[i].tcp);
keyexpires = now + keylifetime;
}
- if(contradicting_del_edge > 10 && contradicting_add_edge > 10) {
- logger(LOG_WARNING, "Possible node with same Name as us!");
-
- if(rand() % 3 == 0) {
- logger(LOG_ERR, "Shutting down, check configuration of all nodes for duplicate Names!");
- running = false;
- break;
- }
-
- contradicting_add_edge = 0;
- contradicting_del_edge = 0;
+ /* Detect ADD_EDGE/DEL_EDGE storms that are caused when
+ * two tinc daemons with the same name are on the VPN.
+ * If so, sleep a while. If this happens multiple times
+ * in a row, sleep longer. */
+
+ if(contradicting_del_edge > 100 && contradicting_add_edge > 100) {
+ logger(LOG_WARNING, "Possible node with same Name as us! Sleeping %d seconds.", sleeptime);
+ usleep(sleeptime * 1000000LL);
+ sleeptime *= 2;
+ if(sleeptime < 0)
+ sleeptime = 3600;
+ } else {
+ sleeptime /= 2;
+ if(sleeptime < 10)
+ sleeptime = 10;
}
+
+ contradicting_add_edge = 0;
+ contradicting_del_edge = 0;
}
if(sigalrm) {
struct stat s;
sighup = false;
+
+ reopenlogger();
/* Reread our own configuration file */
next = node->next;
subnet = node->data;
if(subnet->expires == 1) {
- send_del_subnet(broadcast, subnet);
+ send_del_subnet(everyone, subnet);
if(subnet->owner->status.reachable)
subnet_update(subnet->owner, subnet, false);
subnet_del(subnet->owner, subnet);
} else if(subnet->expires == -1) {
subnet->expires = 0;
} else {
- send_add_subnet(broadcast, subnet);
+ send_add_subnet(everyone, subnet);
if(subnet->owner->status.reachable)
subnet_update(subnet->owner, subnet, true);
}