memcpy(&packet->data[6], &tmp, sizeof tmp);
}
+static void age_subnets(int fd, short events, void *data) {
+ subnet_t *s;
+ connection_t *c;
+ splay_node_t *node, *next, *node2;
+ bool left = false;
+ time_t now = time(NULL);
+
+ 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;
- avl_node_t *node;
+ splay_node_t *node;
connection_t *c;
- subnet = lookup_subnet_mac(address);
+ subnet = lookup_subnet_mac(myself, address);
/* If we don't know this MAC address yet, store it */
/* Subnet lookup routines */
subnet_t *lookup_subnet(const node_t *owner, const subnet_t *subnet) {
- return avl_search(owner->subnet_tree, subnet);
+ return splay_search(owner->subnet_tree, subnet);
}
- subnet_t *lookup_subnet_mac(const mac_t *address) {
- subnet_t *p, *r = NULL, subnet = {0};
+ subnet_t *lookup_subnet_mac(const node_t *owner, const mac_t *address) {
+ subnet_t *p, *r = NULL;
- avl_node_t *n;
+ splay_node_t *n;
int i;
// Check if this address is cached
}
subnet_t *lookup_subnet_ipv4(const ipv4_t *address) {
- subnet_t *p, *r = NULL, subnet = {0};
+ subnet_t *p, *r = NULL;
- avl_node_t *n;
+ splay_node_t *n;
int i;
// Check if this address is cached
}
subnet_t *lookup_subnet_ipv6(const ipv6_t *address) {
- subnet_t *p, *r = NULL, subnet = {0};
+ subnet_t *p, *r = NULL;
- avl_node_t *n;
+ splay_node_t *n;
int i;
// Check if this address is cached
extern bool net2str(char *, int, const subnet_t *);
extern bool str2net(subnet_t *, const char *);
extern subnet_t *lookup_subnet(const struct node_t *, const subnet_t *);
- extern subnet_t *lookup_subnet_mac(const mac_t *);
+ extern subnet_t *lookup_subnet_mac(const struct node_t *, const mac_t *);
extern subnet_t *lookup_subnet_ipv4(const ipv4_t *);
extern subnet_t *lookup_subnet_ipv6(const ipv6_t *);
-extern void dump_subnets(void);
+extern bool dump_subnets(struct connection_t *);
extern void subnet_cache_flush(void);
#endif /* __TINC_SUBNET_H__ */