Use libevent to age learned MAC addresses.
This commit is contained in:
parent
a530f94e7c
commit
8852d4407d
3 changed files with 42 additions and 34 deletions
|
@ -36,7 +36,6 @@
|
||||||
#include "netutl.h"
|
#include "netutl.h"
|
||||||
#include "process.h"
|
#include "process.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "route.h"
|
|
||||||
#include "subnet.h"
|
#include "subnet.h"
|
||||||
#include "xalloc.h"
|
#include "xalloc.h"
|
||||||
|
|
||||||
|
@ -482,9 +481,6 @@ int main_loop(void)
|
||||||
check_dead_connections();
|
check_dead_connections();
|
||||||
last_ping_check = now;
|
last_ping_check = now;
|
||||||
|
|
||||||
if(routing_mode == RMODE_SWITCH)
|
|
||||||
age_subnets();
|
|
||||||
|
|
||||||
/* Should we regenerate our key? */
|
/* Should we regenerate our key? */
|
||||||
|
|
||||||
if(keyexpires < now) {
|
if(keyexpires < now) {
|
||||||
|
|
71
src/route.c
71
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 ns_size = sizeof(struct nd_neighbor_solicit);
|
||||||
static const size_t opt_size = sizeof(struct nd_opt_hdr);
|
static const size_t opt_size = sizeof(struct nd_opt_hdr);
|
||||||
|
|
||||||
|
static struct event age_subnets_event;
|
||||||
|
|
||||||
/* RFC 1071 */
|
/* RFC 1071 */
|
||||||
|
|
||||||
static uint16_t inet_checksum(void *data, int len, uint16_t prevsum)
|
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;
|
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)
|
static void learn_mac(mac_t *address)
|
||||||
{
|
{
|
||||||
subnet_t *subnet;
|
subnet_t *subnet;
|
||||||
|
@ -125,41 +163,16 @@ static void learn_mac(mac_t *address)
|
||||||
if(c->status.active)
|
if(c->status.active)
|
||||||
send_add_subnet(c, subnet);
|
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)
|
if(subnet->expires)
|
||||||
subnet->expires = now + macexpire;
|
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)
|
static void route_mac(node_t *source, vpn_packet_t *packet)
|
||||||
{
|
{
|
||||||
subnet_t *subnet;
|
subnet_t *subnet;
|
||||||
|
|
|
@ -39,7 +39,6 @@ extern int macexpire;
|
||||||
|
|
||||||
extern mac_t mymac;
|
extern mac_t mymac;
|
||||||
|
|
||||||
extern void age_subnets(void);
|
|
||||||
extern void route(struct node_t *, struct vpn_packet_t *);
|
extern void route(struct node_t *, struct vpn_packet_t *);
|
||||||
|
|
||||||
#endif /* __TINC_ROUTE_H__ */
|
#endif /* __TINC_ROUTE_H__ */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue