diff options
author | 2016-05-23 18:46:13 +0000 | |
---|---|---|
committer | 2016-05-23 18:46:13 +0000 | |
commit | b79e02a80b6de10f8bb4b03316d5ddabec4b1aec (patch) | |
tree | 8cdcadadebbbcf0bfdb6e9ae997adde6cc5d2da9 | |
parent | Simplify label allocation. (diff) | |
download | wireguard-openbsd-b79e02a80b6de10f8bb4b03316d5ddabec4b1aec.tar.xz wireguard-openbsd-b79e02a80b6de10f8bb4b03316d5ddabec4b1aec.zip |
Introduce a garbage collector for dead entries in the LIB.
If we lose a route and all of its associated labels, then there's no
point on keeping an entry for it in the LIB.
-rw-r--r-- | usr.sbin/ldpd/lde.c | 7 | ||||
-rw-r--r-- | usr.sbin/ldpd/lde.h | 8 | ||||
-rw-r--r-- | usr.sbin/ldpd/lde_lib.c | 51 |
3 files changed, 63 insertions, 3 deletions
diff --git a/usr.sbin/ldpd/lde.c b/usr.sbin/ldpd/lde.c index 6190f28a737..75762dba938 100644 --- a/usr.sbin/ldpd/lde.c +++ b/usr.sbin/ldpd/lde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lde.c,v 1.51 2016/05/23 18:31:12 renato Exp $ */ +/* $OpenBSD: lde.c,v 1.52 2016/05/23 18:46:13 renato Exp $ */ /* * Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org> @@ -159,6 +159,10 @@ lde(struct ldpd_conf *xconf, int pipe_parent2lde[2], int pipe_ldpe2lde[2], iev_main->handler, iev_main); event_add(&iev_main->ev, NULL); + /* setup and start the LIB garbage collector */ + evtimer_set(&gc_timer, lde_gc_timer, NULL); + lde_gc_start_timer(); + gettimeofday(&now, NULL); global.uptime = now.tv_sec; @@ -177,6 +181,7 @@ lde(struct ldpd_conf *xconf, int pipe_parent2lde[2], int pipe_ldpe2lde[2], void lde_shutdown(void) { + lde_gc_stop_timer(); lde_nbr_clear(); fec_tree_clear(); diff --git a/usr.sbin/ldpd/lde.h b/usr.sbin/ldpd/lde.h index 02dd3faef38..9097715ebf7 100644 --- a/usr.sbin/ldpd/lde.h +++ b/usr.sbin/ldpd/lde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lde.h,v 1.33 2016/05/23 18:36:55 renato Exp $ */ +/* $OpenBSD: lde.h,v 1.34 2016/05/23 18:46:13 renato Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -160,6 +160,12 @@ void lde_check_release_wcard(struct map *, struct lde_nbr *); void lde_check_withdraw(struct map *, struct lde_nbr *); void lde_check_withdraw_wcard(struct map *, struct lde_nbr *); void lde_label_list_free(struct lde_nbr *); +void lde_gc_timer(int, short, void *); +void lde_gc_start_timer(void); +void lde_gc_stop_timer(void); + +#define LDE_GC_INTERVAL 300 +extern struct event gc_timer; /* l2vpn.c */ struct l2vpn *l2vpn_new(const char *); diff --git a/usr.sbin/ldpd/lde_lib.c b/usr.sbin/ldpd/lde_lib.c index 1f63fa48608..c7582c2eebb 100644 --- a/usr.sbin/ldpd/lde_lib.c +++ b/usr.sbin/ldpd/lde_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lde_lib.c,v 1.52 2016/05/23 18:44:47 renato Exp $ */ +/* $OpenBSD: lde_lib.c,v 1.53 2016/05/23 18:46:13 renato Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -54,6 +54,7 @@ RB_PROTOTYPE(nbr_tree, lde_nbr, entry, lde_nbr_compare) extern struct ldpd_conf *ldeconf; struct fec_tree ft = RB_INITIALIZER(&ft); +struct event gc_timer; /* FEC tree functions */ void @@ -709,3 +710,51 @@ lde_check_withdraw_wcard(struct map *map, struct lde_nbr *ln) lde_map_del(ln, me, 0); } } + +/* gabage collector timer: timer to remove dead entries from the LIB */ + +/* ARGSUSED */ +void +lde_gc_timer(int fd, short event, void *arg) +{ + struct fec *fec, *safe; + struct fec_node *fn; + int count = 0; + + RB_FOREACH_SAFE(fec, fec_tree, &ft, safe) { + fn = (struct fec_node *) fec; + + if (!LIST_EMPTY(&fn->nexthops) || + !LIST_EMPTY(&fn->downstream) || + !LIST_EMPTY(&fn->upstream)) + continue; + + fec_remove(&ft, &fn->fec); + free(fn); + count++; + } + + if (count > 0) + log_debug("%s: %u entries removed", __func__, count); + + lde_gc_start_timer(); +} + +void +lde_gc_start_timer(void) +{ + struct timeval tv; + + timerclear(&tv); + tv.tv_sec = LDE_GC_INTERVAL; + if (evtimer_add(&gc_timer, &tv) == -1) + fatal(__func__); +} + +void +lde_gc_stop_timer(void) +{ + if (evtimer_pending(&gc_timer, NULL) && + evtimer_del(&gc_timer) == -1) + fatal(__func__); +} |