diff --git a/src/connection.h b/src/connection.h index 495c38e1..92cd23b4 100644 --- a/src/connection.h +++ b/src/connection.h @@ -104,7 +104,6 @@ typedef struct connection_t { struct event outev; /* events on this metadata connection */ time_t last_ping_time; /* last time we saw some activity from the other end or pinged them */ - time_t last_flushed_time; /* last time buffer was empty. Only meaningful if outbuflen > 0 */ avl_tree_t *config_tree; /* Pointer to configuration tree belonging to him */ } connection_t; diff --git a/src/meta.c b/src/meta.c index 3e750451..b7546267 100644 --- a/src/meta.c +++ b/src/meta.c @@ -45,7 +45,6 @@ bool send_meta(connection_t *c, const char *buffer, int length) c->name, c->hostname); if(!c->outbuflen) { - c->last_flushed_time = now; if(event_add(&c->outev, NULL) < 0) { logger(LOG_EMERG, _("event_add failed: %s"), strerror(errno)); abort(); @@ -239,7 +238,7 @@ bool receive_meta(connection_t *c) return false; } - c->last_ping_time = now; + c->last_ping_time = time(NULL); return true; } diff --git a/src/net.c b/src/net.c index df5fae77..9681a7bb 100644 --- a/src/net.c +++ b/src/net.c @@ -41,8 +41,6 @@ volatile bool running = false; -time_t now = 0; - /* Purge edges and subnets of unreachable nodes. Use carefully. */ static void purge(void) @@ -208,6 +206,7 @@ static void check_dead_connections(void) { avl_node_t *node, *next; connection_t *c; + time_t now = time(NULL); cp(); @@ -243,16 +242,6 @@ static void check_dead_connections(void) } } } - - if(c->outbuflen > 0 && c->last_flushed_time + pingtimeout < now) { - if(c->status.active) { - ifdebug(CONNECTIONS) logger(LOG_INFO, - _("%s (%s) could not flush for %ld seconds (%d bytes remaining)"), - c->name, c->hostname, now - c->last_flushed_time, c->outbuflen); - c->status.timeout = true; - terminate_connection(c, true); - } - } } } @@ -437,16 +426,13 @@ int main_loop(void) signal_set(&sigalrm_event, SIGALRM, sigalrm_handler, NULL); signal_add(&sigalrm_event, NULL); - last_ping_check = now; + last_ping_check = time(NULL); - srand(now); + srand(time(NULL)); running = true; while(running) { - now = time(NULL); - - // tv.tv_sec = 1 + (rand() & 7); /* Approx. 5 seconds, randomized to prevent global synchronisation effects */ tv.tv_sec = 1; tv.tv_usec = 0; @@ -463,7 +449,6 @@ int main_loop(void) } r = event_loop(EVLOOP_ONCE); - now = time(NULL); if(r < 0) { logger(LOG_ERR, _("Error while waiting for input: %s"), strerror(errno)); @@ -477,9 +462,9 @@ int main_loop(void) /* Let's check if everybody is still alive */ - if(last_ping_check + pingtimeout < now) { + if(last_ping_check + pingtimeout < time(NULL)) { check_dead_connections(); - last_ping_check = now; + last_ping_check = time(NULL); } } diff --git a/src/net.h b/src/net.h index 28ec2eeb..943b7e61 100644 --- a/src/net.h +++ b/src/net.h @@ -128,7 +128,6 @@ extern int keylifetime; extern bool do_prune; extern bool do_purge; extern char *myport; -extern time_t now; extern EVP_CIPHER_CTX packet_ctx; /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */ diff --git a/src/net_packet.c b/src/net_packet.c index 596b9d53..61465a25 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -263,9 +263,6 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) inpkt = outpkt; } - if(n->connection) - n->connection->last_ping_time = now; - if(!inpkt->data[12] && !inpkt->data[13]) mtu_probe_h(n, inpkt); else diff --git a/src/net_setup.c b/src/net_setup.c index 814d698f..22a95615 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -580,8 +580,6 @@ bool setup_network_connections(void) { cp(); - now = time(NULL); - init_connections(); init_subnets(); init_nodes(); diff --git a/src/net_socket.c b/src/net_socket.c index bba0d97d..287d6888 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -261,7 +261,7 @@ void finish_connecting(connection_t *c) configure_tcp(c); - c->last_ping_time = now; + c->last_ping_time = time(NULL); c->status.connecting = false; send_id(c); @@ -391,7 +391,7 @@ void setup_outgoing_connection(outgoing_t *outgoing) } c->outgoing = outgoing; - c->last_ping_time = now; + c->last_ping_time = time(NULL); connection_add(c); @@ -437,7 +437,7 @@ void handle_new_meta_connection(int sock, short events, void *data) c->address = sa; c->hostname = sockaddr2hostname(&sa); c->socket = fd; - c->last_ping_time = now; + c->last_ping_time = time(NULL); ifdebug(CONNECTIONS) logger(LOG_NOTICE, _("Connection from %s"), c->hostname); diff --git a/src/protocol.c b/src/protocol.c index 93f27514..6ad9740f 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -211,7 +211,7 @@ bool seen_request(char *request) } else { new = xmalloc(sizeof(*new)); new->request = xstrdup(request); - new->firstseen = now; + new->firstseen = time(NULL); avl_insert(past_request_tree, new); event_add(&past_request_event, &(struct timeval){10, 0}); return false; @@ -223,6 +223,7 @@ void age_past_requests(int fd, short events, void *data) avl_node_t *node, *next; past_request_t *p; int left = 0, deleted = 0; + time_t now = time(NULL); cp(); diff --git a/src/protocol_misc.c b/src/protocol_misc.c index 52e97e54..ca1dc315 100644 --- a/src/protocol_misc.c +++ b/src/protocol_misc.c @@ -116,7 +116,7 @@ bool send_ping(connection_t *c) cp(); c->status.pinged = true; - c->last_ping_time = now; + c->last_ping_time = time(NULL); return send_request(c, "%d", PING); } diff --git a/src/route.c b/src/route.c index 32afa0d6..5ccf9bd0 100644 --- a/src/route.c +++ b/src/route.c @@ -77,6 +77,7 @@ static uint16_t inet_checksum(void *data, int len, uint16_t prevsum) static bool ratelimit(int frequency) { static time_t lasttime = 0; static int count = 0; + time_t now = time(NULL); if(lasttime == now) { if(++count > frequency) @@ -103,6 +104,7 @@ static void age_subnets(int fd, short events, void *data) connection_t *c; avl_node_t *node, *next, *node2; bool left = false; + time_t now = time(NULL); cp(); @@ -152,7 +154,7 @@ static void learn_mac(mac_t *address) subnet = new_subnet(); subnet->type = SUBNET_MAC; - subnet->expires = now + macexpire; + subnet->expires = time(NULL) + macexpire; subnet->net.mac.address = *address; subnet_add(myself, subnet); @@ -167,10 +169,10 @@ static void learn_mac(mac_t *address) if(!timeout_initialized(&age_subnets_event)) timeout_set(&age_subnets_event, age_subnets, NULL); event_add(&age_subnets_event, &(struct timeval){10, 0}); + } else { + if(subnet->expires) + subnet->expires = time(NULL) + macexpire; } - - if(subnet->expires) - subnet->expires = now + macexpire; } static void route_mac(node_t *source, vpn_packet_t *packet)