]> git.meshlink.io Git - meshlink/commitdiff
Use libevent to age learned MAC addresses.
authorGuus Sliepen <guus@tinc-vpn.org>
Thu, 17 May 2007 23:24:40 +0000 (23:24 +0000)
committerGuus Sliepen <guus@tinc-vpn.org>
Thu, 17 May 2007 23:24:40 +0000 (23:24 +0000)
src/net.c
src/route.c
src/route.h

index e09734cf84779e7f08887df1929a7679030387c7..57ac82429e6f97855799a3061c7912cbce4ce09d 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -36,7 +36,6 @@
 #include "netutl.h"
 #include "process.h"
 #include "protocol.h"
-#include "route.h"
 #include "subnet.h"
 #include "xalloc.h"
 
@@ -482,9 +481,6 @@ int main_loop(void)
                        check_dead_connections();
                        last_ping_check = now;
 
-                       if(routing_mode == RMODE_SWITCH)
-                               age_subnets();
-
                        /* Should we regenerate our key? */
 
                        if(keyexpires < now) {
index 0123107e4acabc444efbc8767d07410a26939396..32afa0d6e8f819ff624a6665e384cd118030eb6f 100644 (file)
@@ -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;
index 807b707ad963f4a1dfcf9907564e7bee919fd7a9..0021506c47eb3b5ecfee96466d698f3927cd4b03 100644 (file)
@@ -39,7 +39,6 @@ extern int macexpire;
 
 extern mac_t mymac;
 
-extern void age_subnets(void);
 extern void route(struct node_t *, struct vpn_packet_t *);
 
 #endif                                                 /* __TINC_ROUTE_H__ */