along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: event.c,v 1.1.4.1 2002/02/11 10:05:58 guus Exp $
+ $Id: event.c,v 1.1.4.2 2002/03/01 14:09:30 guus Exp $
*/
#include "config.h"
#include "system.h"
avl_tree_t *event_tree;
+extern time_t now;
int id;
if(event_tree->head)
{
event = (event_t *)event_tree->head->data;
- if(event->time < time(NULL))
+ if(event->time < now)
{
avl_delete(event_tree, event);
return event;
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: meta.c,v 1.1.2.24 2002/02/18 16:25:16 guus Exp $
+ $Id: meta.c,v 1.1.2.25 2002/03/01 14:09:31 guus Exp $
*/
#include "config.h"
return -1;
}
- c->last_ping_time = time(NULL);
+ c->last_ping_time = now;
cp
return 0;
}
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.159 2002/03/01 13:18:54 guus Exp $
+ $Id: net.c,v 1.35.4.160 2002/03/01 14:09:31 guus Exp $
*/
#include "config.h"
int sighup = 0;
int sigalrm = 0;
+time_t now = 0;
+
/*
put all file descriptors in an fd_set array
*/
*/
void check_dead_connections(void)
{
- time_t now;
avl_node_t *node, *next;
connection_t *c;
cp
- now = time(NULL);
-
for(node = connection_tree->head; node; node = next)
{
next = node->next;
int t;
event_t *event;
cp
- last_ping_check = time(NULL);
+ last_ping_check = now;
- srand(time(NULL));
+ srand(now);
for(;;)
{
+ now = time(NULL);
+
tv.tv_sec = 1 + (rand() & 7); /* Approx. 5 seconds, randomized to prevent global synchronisation effects */
tv.tv_usec = 0;
do_purge = 0;
}
- t = time(NULL);
-
/* Let's check if everybody is still alive */
- if(last_ping_check + pingtimeout < t)
+ if(last_ping_check + pingtimeout < now)
{
check_dead_connections();
- last_ping_check = time(NULL);
+ last_ping_check = now;
+
+ if(routing_mode != RMODE_ROUTER)
+ age_mac();
/* Should we regenerate our key? */
- if(keyexpires < t)
+ if(keyexpires < now)
{
if(debug_lvl >= DEBUG_STATUS)
syslog(LOG_INFO, _("Regenerating symmetric key"));
RAND_pseudo_bytes(myself->key, myself->keylength);
send_key_changed(myself->connection, myself);
- keyexpires = time(NULL) + keylifetime;
+ keyexpires = now + keylifetime;
}
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: net.h,v 1.9.4.45 2002/03/01 13:18:54 guus Exp $
+ $Id: net.h,v 1.9.4.46 2002/03/01 14:09:31 guus Exp $
*/
#ifndef __TINC_NET_H__
extern int do_prune;
extern int do_purge;
extern char *myport;
+extern time_t now;
extern void retry_outgoing(outgoing_t *);
extern void handle_incoming_vpn_data(int);
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.6 2002/03/01 12:26:56 guus Exp $
+ $Id: net_packet.c,v 1.1.2.7 2002/03/01 14:09:31 guus Exp $
*/
#include "config.h"
return;
}
-/*
if(n->connection)
- n->connection->last_ping_time = time(NULL);
-*/
+ n->connection->last_ping_time = now;
+
receive_udppacket(n, &pkt);
cp
}
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.7 2002/03/01 13:18:54 guus Exp $
+ $Id: net_setup.c,v 1.1.2.8 2002/03/01 14:09:31 guus Exp $
*/
#include "config.h"
get_config_bool(lookup_config(config_tree, "PriorityInheritance"), &priorityinheritance);
+ if(!get_config_int(lookup_config(config_tree, "MACExpire"), &macexpire))
+ macexpire= 600;
+
if(get_config_int(lookup_config(myself->connection->config_tree, "MaxTimeout"), &maxtimeout))
{
if(maxtimeout <= 0)
if(!get_config_int(lookup_config(config_tree, "KeyExpire"), &keylifetime))
keylifetime = 3600;
- keyexpires = time(NULL) + keylifetime;
+ keyexpires = now + keylifetime;
/* Check if we want to use message authentication codes... */
int setup_network_connections(void)
{
cp
+ now = time(NULL);
+
init_connections();
init_subnets();
init_nodes();
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.6 2002/03/01 13:18:54 guus Exp $
+ $Id: net_socket.c,v 1.1.2.7 2002/03/01 14:09:31 guus Exp $
*/
#include "config.h"
event = new_event();
event->handler = (event_handler_t)setup_outgoing_connection;
- event->time = time(NULL) + outgoing->timeout;
+ event->time = now + outgoing->timeout;
event->data = outgoing;
event_add(event);
if(debug_lvl >= DEBUG_CONNECTIONS)
syslog(LOG_INFO, _("Connected to %s (%s)"), c->name, c->hostname);
- c->last_ping_time = time(NULL);
+ c->last_ping_time = now;
send_id(c);
cp
}
c->outgoing = outgoing;
- c->last_ping_time = time(NULL);
+ c->last_ping_time = now;
connection_add(c);
c->address = sa;
c->hostname = sockaddr2hostname(&sa);
c->socket = fd;
- c->last_ping_time = time(NULL);
+ c->last_ping_time = now;
if(debug_lvl >= DEBUG_CONNECTIONS)
syslog(LOG_NOTICE, _("Connection from %s"), c->hostname);
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: protocol_misc.c,v 1.1.4.1 2002/02/11 10:05:58 guus Exp $
+ $Id: protocol_misc.c,v 1.1.4.2 2002/03/01 14:09:31 guus Exp $
*/
#include "config.h"
{
cp
c->status.pinged = 1;
- c->last_ping_time = time(NULL);
+ c->last_ping_time = now;
cp
return send_request(c, "%d", PING);
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: route.c,v 1.1.2.25 2002/03/01 12:26:56 guus Exp $
+ $Id: route.c,v 1.1.2.26 2002/03/01 14:09:31 guus Exp $
*/
#include "config.h"
int routing_mode = RMODE_ROUTER;
int priorityinheritance = 0;
+int macexpire = 600;
subnet_t mymac;
void learn_mac(mac_t *address)
send_add_subnet(c, subnet);
}
}
+
+ subnet->net.mac.lastseen = now;
+}
+
+void age_mac(void)
+{
+ subnet_t *s;
+ connection_t *c;
+ avl_node_t *node, *next, *node2;
+cp
+ for(node = myself->subnet_tree->head; node; node = next)
+ {
+ s = (subnet_t *)node->data;
+ if(s->type == SUBNET_MAC && s->net.mac.lastseen && s->net.mac.lastseen + macexpire < now)
+ {
+ for(node2 = connection_tree->head; node2; node2 = node2->next)
+ {
+ c = (connection_t *)node2->data;
+ if(c->status.active)
+ send_del_subnet(c, s);
+ }
+ subnet_del(myself, s);
+ }
+ }
+cp
}
node_t *route_mac(vpn_packet_t *packet)
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: route.h,v 1.1.2.6 2002/03/01 12:26:56 guus Exp $
+ $Id: route.h,v 1.1.2.7 2002/03/01 14:09:31 guus Exp $
*/
#ifndef __TINC_ROUTE_H__
extern int routing_mode;
extern int priorityinheritance;
+extern int macexpire;
+extern void age_mac(void);
extern void route_incoming(node_t *, vpn_packet_t *);
extern void route_outgoing(vpn_packet_t *);
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: subnet.h,v 1.1.2.16 2002/02/18 16:25:19 guus Exp $
+ $Id: subnet.h,v 1.1.2.17 2002/03/01 14:09:31 guus Exp $
*/
#ifndef __TINC_SUBNET_H__
typedef struct subnet_mac_t
{
mac_t address;
+ time_t lastseen;
} subnet_mac_t;
typedef struct subnet_ipv4_t