X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Froute.c;h=32afa0d6e8f819ff624a6665e384cd118030eb6f;hb=8852d4407d87cf5dcf2c212d352279015aa050c0;hp=0123107e4acabc444efbc8767d07410a26939396;hpb=a530f94e7c4acd94d1cd568b384931eec6f60563;p=tinc diff --git a/src/route.c b/src/route.c index 0123107e..32afa0d6 100644 --- a/src/route.c +++ b/src/route.c @@ -51,6 +51,8 @@ static const size_t icmp6_size = sizeof(struct icmp6_hdr); static const size_t ns_size = sizeof(struct nd_neighbor_solicit); static const size_t opt_size = sizeof(struct nd_opt_hdr); +static struct event age_subnets_event; + /* RFC 1071 */ static uint16_t inet_checksum(void *data, int len, uint16_t prevsum) @@ -95,6 +97,42 @@ static bool checklength(node_t *source, vpn_packet_t *packet, length_t length) { return true; } +static void age_subnets(int fd, short events, void *data) +{ + subnet_t *s; + connection_t *c; + avl_node_t *node, *next, *node2; + bool left = false; + + cp(); + + for(node = myself->subnet_tree->head; node; node = next) { + next = node->next; + s = node->data; + if(s->expires && s->expires < now) { + ifdebug(TRAFFIC) { + char netstr[MAXNETSTR]; + if(net2str(netstr, sizeof netstr, s)) + logger(LOG_INFO, _("Subnet %s expired"), netstr); + } + + for(node2 = connection_tree->head; node2; node2 = node2->next) { + c = node2->data; + if(c->status.active) + send_del_subnet(c, s); + } + + subnet_del(myself, s); + } else { + if(s->expires) + left = true; + } + } + + if(left) + event_add(&age_subnets_event, &(struct timeval){10, 0}); +} + static void learn_mac(mac_t *address) { subnet_t *subnet; @@ -125,41 +163,16 @@ static void learn_mac(mac_t *address) if(c->status.active) send_add_subnet(c, subnet); } + + if(!timeout_initialized(&age_subnets_event)) + timeout_set(&age_subnets_event, age_subnets, NULL); + event_add(&age_subnets_event, &(struct timeval){10, 0}); } if(subnet->expires) subnet->expires = now + macexpire; } -void age_subnets(void) -{ - subnet_t *s; - connection_t *c; - avl_node_t *node, *next, *node2; - - cp(); - - for(node = myself->subnet_tree->head; node; node = next) { - next = node->next; - s = node->data; - if(s->expires && s->expires < now) { - ifdebug(TRAFFIC) { - char netstr[MAXNETSTR]; - if(net2str(netstr, sizeof netstr, s)) - logger(LOG_INFO, _("Subnet %s expired"), netstr); - } - - for(node2 = connection_tree->head; node2; node2 = node2->next) { - c = node2->data; - if(c->status.active) - send_del_subnet(c, s); - } - - subnet_del(myself, s); - } - } -} - static void route_mac(node_t *source, vpn_packet_t *packet) { subnet_t *subnet;