- Global time_t now, so that we don't have to call time() too often.

- MAC addresses expire after a time configurable by MACExpire (default 600
  seconds)
This commit is contained in:
Guus Sliepen 2002-03-01 14:09:31 +00:00
parent 7496ecc45a
commit 14979f835d
11 changed files with 70 additions and 33 deletions

View file

@ -17,7 +17,7 @@
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"
@ -34,6 +34,7 @@
#include "system.h"
avl_tree_t *event_tree;
extern time_t now;
int id;
@ -98,7 +99,7 @@ cp
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;

View file

@ -17,7 +17,7 @@
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"
@ -204,7 +204,7 @@ cp
return -1;
}
c->last_ping_time = time(NULL);
c->last_ping_time = now;
cp
return 0;
}

View file

@ -17,7 +17,7 @@
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"
@ -73,6 +73,8 @@ int do_purge = 0;
int sighup = 0;
int sigalrm = 0;
time_t now = 0;
/*
put all file descriptors in an fd_set array
*/
@ -229,12 +231,9 @@ cp
*/
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;
@ -359,12 +358,14 @@ void main_loop(void)
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;
@ -394,25 +395,26 @@ cp
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;
}
}

View file

@ -17,7 +17,7 @@
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__
@ -115,6 +115,7 @@ extern int keylifetime;
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);

View file

@ -17,7 +17,7 @@
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"
@ -399,10 +399,9 @@ cp
return;
}
/*
if(n->connection)
n->connection->last_ping_time = time(NULL);
*/
n->connection->last_ping_time = now;
receive_udppacket(n, &pkt);
cp
}

View file

@ -17,7 +17,7 @@
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"
@ -328,6 +328,9 @@ cp
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)
@ -392,7 +395,7 @@ cp
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... */
@ -514,6 +517,8 @@ cp
int setup_network_connections(void)
{
cp
now = time(NULL);
init_connections();
init_subnets();
init_nodes();

View file

@ -17,7 +17,7 @@
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"
@ -204,7 +204,7 @@ cp
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);
@ -260,7 +260,7 @@ cp
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
@ -407,7 +407,7 @@ cp
}
c->outgoing = outgoing;
c->last_ping_time = time(NULL);
c->last_ping_time = now;
connection_add(c);
@ -439,7 +439,7 @@ cp
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);

View file

@ -17,7 +17,7 @@
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"
@ -122,7 +122,7 @@ int send_ping(connection_t *c)
{
cp
c->status.pinged = 1;
c->last_ping_time = time(NULL);
c->last_ping_time = now;
cp
return send_request(c, "%d", PING);
}

View file

@ -17,7 +17,7 @@
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"
@ -52,6 +52,7 @@
int routing_mode = RMODE_ROUTER;
int priorityinheritance = 0;
int macexpire = 600;
subnet_t mymac;
void learn_mac(mac_t *address)
@ -84,6 +85,31 @@ cp
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)

View file

@ -17,7 +17,7 @@
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__
@ -32,7 +32,9 @@ enum
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 *);

View file

@ -17,7 +17,7 @@
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__
@ -36,6 +36,7 @@ enum
typedef struct subnet_mac_t
{
mac_t address;
time_t lastseen;
} subnet_mac_t;
typedef struct subnet_ipv4_t