EVENT_OFF(bm->t_bgp_zebra_l3_vni);
bgp_mac_finish();
+#if ENABLE_BGP_VNC
+ rfapi_terminate();
+#endif
}
struct peer *peer_lookup_in_view(struct vty *vty, struct bgp *bgp,
void rfapi_init(void)
{
+ rfapi_rib_init();
+ rfapi_import_init();
bgp_rfapi_cfg_init();
vnc_debug_init();
rfapi_vty_init();
}
+void rfapi_terminate(void)
+{
+ rfapi_import_terminate();
+ rfapi_rib_terminate();
+}
+
#ifdef DEBUG_RFAPI
static void rfapi_print_exported(struct bgp *bgp)
{
#include "bgpd/bgp_nexthop.h"
extern void rfapi_init(void);
+extern void rfapi_terminate(void);
extern void vnc_zebra_init(struct event_loop *master);
extern void vnc_zebra_destroy(void);
#undef DEBUG_IT_NODES
#undef DEBUG_BI_SEARCH
+/*
+ * Hash to keep track of outstanding timers so we can force them to
+ * expire at shutdown time, thus freeing their allocated memory.
+ */
+PREDECL_HASH(rwcb);
+
/*
* Allocated for each withdraw timer instance; freed when the timer
* expires or is canceled
*/
struct rfapi_withdraw {
+ struct rwcb_item rwcbi;
+
struct rfapi_import_table *import_table;
struct agg_node *node;
struct bgp_path_info *info;
+ void (*timer_service_func)(struct event *t); /* for cleanup */
safi_t safi; /* used only for bulk operations */
/*
* For import table node reference count checking (i.e., debugging).
int lockoffset;
};
+static int _rwcb_cmp(const struct rfapi_withdraw *w1, const struct rfapi_withdraw *w2)
+{
+ return (w1 != w2);
+}
+
+static uint32_t _rwcb_hash(const struct rfapi_withdraw *w)
+{
+ return (uintptr_t)w & 0xffffffff;
+}
+
+DECLARE_HASH(rwcb, struct rfapi_withdraw, rwcbi, _rwcb_cmp, _rwcb_hash);
+static struct rwcb_head _rwcbhash;
+
/*
* DEBUG FUNCTION
* Count remote routes and compare with actively-maintained values.
struct rfapi_withdraw *wcb =
EVENT_ARG(bpi->extra->vnc->vnc.import.timer);
+ rwcb_del(&_rwcbhash, wcb);
XFREE(MTYPE_RFAPI_WITHDRAW, wcb);
EVENT_OFF(bpi->extra->vnc->vnc.import.timer);
}
/* This callback is responsible for the withdraw object's memory */
if (early_exit) {
+ rwcb_del(&_rwcbhash, wcb);
XFREE(MTYPE_RFAPI_WITHDRAW, wcb);
return;
}
RFAPI_CHECK_REFCOUNT(wcb->node, SAFI_MPLS_VPN, 1 + wcb->lockoffset);
agg_unlock_node(wcb->node); /* decr ref count */
+ rwcb_del(&_rwcbhash, wcb);
XFREE(MTYPE_RFAPI_WITHDRAW, wcb);
}
done:
RFAPI_CHECK_REFCOUNT(wcb->node, SAFI_ENCAP, 1);
agg_unlock_node(wcb->node); /* decr ref count */
+ rwcb_del(&_rwcbhash, wcb);
XFREE(MTYPE_RFAPI_WITHDRAW, wcb);
skiplist_free(vpn_node_sl);
}
wcb->node = rn;
wcb->info = bpi;
wcb->import_table = import_table;
+ wcb->timer_service_func = timer_service_func;
+ rwcb_add(&_rwcbhash, wcb);
bgp_attr_intern(bpi->attr);
if (VNC_DEBUG(VERBOSE)) {
wcb->info = bpi;
wcb->node = rn;
wcb->import_table = it;
+ rwcb_add(&_rwcbhash, wcb);
memset(&t, 0, sizeof(t));
t.arg = wcb;
rfapiWithdrawTimerEncap(&t); /* frees wcb */
struct rfapi_withdraw *wcb = EVENT_ARG(
bpi->extra->vnc->vnc.import.timer);
+ rwcb_del(&_rwcbhash, wcb);
XFREE(MTYPE_RFAPI_WITHDRAW, wcb);
EVENT_OFF(bpi->extra->vnc->vnc.import
.timer);
wcb->info = bpi;
wcb->node = rn;
wcb->import_table = import_table;
+ rwcb_add(&_rwcbhash, wcb);
memset(&t, 0, sizeof(t));
t.arg = wcb;
rfapiWithdrawTimerEncap(
struct rfapi_withdraw *wcb =
EVENT_ARG(bpi->extra->vnc->vnc.import.timer);
+ rwcb_del(&_rwcbhash, wcb);
XFREE(MTYPE_RFAPI_WITHDRAW, wcb);
EVENT_OFF(bpi->extra->vnc->vnc.import.timer);
}
wcb->node = rn;
wcb->import_table = it;
wcb->lockoffset = lockoffset;
+ rwcb_add(&_rwcbhash, wcb);
memset(&t, 0, sizeof(t));
t.arg = wcb;
rfapiWithdrawTimerVPN(&t); /* frees wcb */
struct rfapi_withdraw *wcb = EVENT_ARG(
bpi->extra->vnc->vnc.import.timer);
+ rwcb_del(&_rwcbhash, wcb);
XFREE(MTYPE_RFAPI_WITHDRAW, wcb);
EVENT_OFF(bpi->extra->vnc->vnc.import
.timer);
struct rfapi_withdraw *wcb =
EVENT_ARG(bpi->extra->vnc->vnc.import.timer);
+ rwcb_del(&_rwcbhash, wcb);
XFREE(MTYPE_RFAPI_WITHDRAW, wcb);
EVENT_OFF(bpi->extra->vnc->vnc.import.timer);
}
RFAPI_UPDATE_ITABLE_COUNT(
bpi, wcb->import_table,
afi, 1);
+ rwcb_del(&_rwcbhash, wcb);
XFREE(MTYPE_RFAPI_WITHDRAW,
wcb);
EVENT_OFF(bpi->extra->vnc->vnc
else
return RFAPI_LIFETIME_INFINITE_WITHDRAW_DELAY;
}
+
+void rfapi_import_init(void)
+{
+ rwcb_init(&_rwcbhash);
+}
+
+void rfapi_import_terminate(void)
+{
+ struct rfapi_withdraw *wcb;
+ struct bgp_path_info *bpi;
+ void (*timer_service_func)(struct event *t);
+ struct event t;
+
+ vnc_zlog_debug_verbose("%s: cleaning up %zu pending timers", __func__,
+ rwcb_count(&_rwcbhash));
+
+ /*
+ * clean up memory allocations stored in pending timers
+ */
+ while ((wcb = rwcb_pop(&_rwcbhash))) {
+ bpi = wcb->info;
+ assert(wcb == EVENT_ARG(bpi->extra->vnc->vnc.import.timer));
+ EVENT_OFF(bpi->extra->vnc->vnc.import.timer);
+
+ timer_service_func = wcb->timer_service_func;
+ memset(&t, 0, sizeof(t));
+ t.arg = wcb;
+ (*timer_service_func)(&t); /* frees wcb */
+ }
+}
--------------------------------------------*/
extern uint32_t rfapiGetHolddownFromLifetime(uint32_t lifetime);
+extern void rfapi_import_init(void);
+extern void rfapi_import_terminate(void);
+
#endif /* QUAGGA_HGP_RFAPI_IMPORT_H */
#include "lib/log.h"
#include "lib/skiplist.h"
#include "lib/workqueue.h"
+#include <typesafe.h>
#include "bgpd/bgpd.h"
#include "bgpd/bgp_route.h"
#define DEBUG_PENDING_DELETE_ROUTE 0
#define DEBUG_NHL 0
#define DEBUG_RIB_SL_RD 0
-#define DEBUG_CLEANUP 0
+#define DEBUG_CLEANUP 0
/* forward decl */
#if DEBUG_NHL
-static void rfapiRibShowRibSl(void *stream, struct prefix *pfx,
- struct skiplist *sl);
+static void rfapiRibShowRibSl(void *stream, const struct prefix *pfx, struct skiplist *sl);
#endif
/*
}
+/*
+ * Hash to keep track of outstanding timers so we can force them to
+ * expire at shutdown time, thus freeing their allocated memory.
+ */
+PREDECL_HASH(rrtcb);
+
+/*
+ * Timer control block for recently-deleted and expired routes
+ */
+struct rfapi_rib_tcb {
+ struct rrtcb_item tcbi;
+
+ struct rfapi_descriptor *rfd;
+ struct skiplist *sl;
+ struct rfapi_info *ri;
+ struct agg_node *rn;
+ int flags;
+#define RFAPI_RIB_TCB_FLAG_DELETED 0x00000001
+};
+
+static int _rrtcb_cmp(const struct rfapi_rib_tcb *t1, const struct rfapi_rib_tcb *t2)
+{
+ return (t1 != t2);
+}
+
+static uint32_t _rrtcb_hash(const struct rfapi_rib_tcb *t)
+{
+ return (uintptr_t)t & 0xffffffff;
+}
+
+DECLARE_HASH(rrtcb, struct rfapi_rib_tcb, tcbi, _rrtcb_cmp, _rrtcb_hash);
+static struct rrtcb_head _rrtcbhash;
+
static void rfapi_info_free(struct rfapi_info *goner)
{
if (goner) {
+#if DEBUG_CLEANUP
+ zlog_debug("%s: ri %p, timer %p", __func__, goner, goner->timer);
+#endif
if (goner->tea_options) {
rfapiFreeBgpTeaOptionChain(goner->tea_options);
goner->tea_options = NULL;
struct rfapi_rib_tcb *tcb;
tcb = EVENT_ARG(goner->timer);
+#if DEBUG_CLEANUP
+ zlog_debug("%s: ri %p, tcb %p", __func__, goner, tcb);
+#endif
EVENT_OFF(goner->timer);
+ rrtcb_del(&_rrtcbhash, tcb);
XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb);
}
XFREE(MTYPE_RFAPI_INFO, goner);
}
}
-/*
- * Timer control block for recently-deleted and expired routes
- */
-struct rfapi_rib_tcb {
- struct rfapi_descriptor *rfd;
- struct skiplist *sl;
- struct rfapi_info *ri;
- struct agg_node *rn;
- int flags;
-#define RFAPI_RIB_TCB_FLAG_DELETED 0x00000001
-};
-
-/*
- * remove route from rib
- */
-static void rfapiRibExpireTimer(struct event *t)
+static void _rfapiRibExpireTimer(struct rfapi_rib_tcb *tcb)
{
- struct rfapi_rib_tcb *tcb = EVENT_ARG(t);
-
RFAPI_RIB_CHECK_COUNTS(1, 0);
/*
agg_unlock_node(tcb->rn);
}
+ rrtcb_del(&_rrtcbhash, tcb);
XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb);
RFAPI_RIB_CHECK_COUNTS(1, 0);
}
+/*
+ * remove route from rib
+ */
+static void rfapiRibExpireTimer(struct event *t)
+{
+ struct rfapi_rib_tcb *tcb = EVENT_ARG(t);
+
+ _rfapiRibExpireTimer(tcb);
+}
+
static void rfapiRibStartTimer(struct rfapi_descriptor *rfd,
struct rfapi_info *ri,
struct agg_node *rn, /* route node attached to */
event_add_timer(bm->master, rfapiRibExpireTimer, tcb, ri->lifetime,
&ri->timer);
+
+ rrtcb_add(&_rrtcbhash, tcb);
}
extern void rfapi_rib_key_init(struct prefix *prefix, /* may be NULL */
tcb = EVENT_ARG(
ri->timer);
EVENT_OFF(ri->timer);
+ rrtcb_del(&_rrtcbhash, tcb);
XFREE(MTYPE_RFAPI_RECENT_DELETE,
tcb);
}
int rib_node_started_nonempty = 0;
int sendingsomeroutes = 0;
const struct prefix *p;
-#if DEBUG_PROCESS_PENDING_NODE
- unsigned int count_rib_initial = 0;
- unsigned int count_pend_vn_initial = 0;
- unsigned int count_pend_cost_initial = 0;
-#endif
assert(pn);
p = agg_node_get_prefix(pn);
slPendPt = (struct skiplist *)(pn->aggregate);
lPendCost = (struct list *)(pn->info);
-#if DEBUG_PROCESS_PENDING_NODE
- /* debugging */
- if (slRibPt)
- count_rib_initial = skiplist_count(slRibPt);
-
- if (slPendPt)
- count_pend_vn_initial = skiplist_count(slPendPt);
-
- if (lPendCost && lPendCost != (struct list *)1)
- count_pend_cost_initial = lPendCost->count;
-#endif
-
-
/*
* Handle special case: delete all routes at prefix
*/
tcb = EVENT_ARG(ri->timer);
EVENT_OFF(ri->timer);
+ rrtcb_del(&_rrtcbhash, tcb);
XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb);
}
tcb = EVENT_ARG(ori->timer);
EVENT_OFF(ori->timer);
+ rrtcb_del(&_rrtcbhash, tcb);
XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb);
}
#endif
} else {
+#if DEBUG_PROCESS_PENDING_NODE
+ vnc_zlog_debug_verbose("%s: slRibPt ri %p matched in pending list",
+ __func__, ori);
+#endif
+
/*
* Found in pending list. If same lifetime,
* cost, options,
rfapi_info_free(
ri); /* grr... */
}
- }
#if DEBUG_PROCESS_PENDING_NODE
- vnc_zlog_debug_verbose(
- "%s: slRibPt ri %p matched in pending list, %s",
- __func__, ori,
- (same ? "same info"
- : "different info"));
+ vnc_zlog_debug_verbose("%s: same info", __func__);
#endif
+ }
}
}
/*
tcb = EVENT_ARG(ri->timer);
EVENT_OFF(ri->timer);
+ rrtcb_del(&_rrtcbhash, tcb);
XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb);
}
RFAPI_RIB_CHECK_COUNTS(0, delete_list->count);
/*
* This one is for debugging (set stream to NULL to send output to log)
*/
-static void rfapiRibShowRibSl(void *stream, struct prefix *pfx,
- struct skiplist *sl)
+static void rfapiRibShowRibSl(void *stream, const struct prefix *pfx, struct skiplist *sl)
{
int (*fp)(void *, const char *, ...);
struct vty *vty;
fp(out, "\n");
}
}
+
+void rfapi_rib_init(void)
+{
+ rrtcb_init(&_rrtcbhash);
+}
+
+void rfapi_rib_terminate(void)
+{
+ struct rfapi_rib_tcb *tcb;
+
+ vnc_zlog_debug_verbose("%s: cleaning up %zu pending timers", __func__,
+ rrtcb_count(&_rrtcbhash));
+
+ /*
+ * Clean up memory allocations stored in pending timers
+ */
+ while ((tcb = rrtcb_pop(&_rrtcbhash))) {
+ assert(tcb == EVENT_ARG(tcb->ri->timer));
+ EVENT_OFF(tcb->ri->timer);
+ _rfapiRibExpireTimer(tcb); /* deletes hash entry, frees tcb */
+ }
+}
extern void rfapiAdbFree(struct rfapi_adb *adb);
+extern void rfapi_rib_init(void);
+extern void rfapi_rib_terminate(void);
+
#endif /* QUAGGA_HGP_RFAPI_RIB_H */
password zebra
log stdout notifications
log commands
+#debug bgp vnc verbose
router bgp 5226
bgp router-id 3.3.3.3
bgp cluster-id 3.3.3.3
)
num = "0 exist"
-luCommand("r1", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI clear")
-luCommand("r2", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI clear")
-luCommand("r3", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI clear")
-luCommand("r4", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI clear")
+luCommand("r1", 'vtysh -c "show bgp ipv4 vpn"', num, "wait", "VPN SAFI clear")
+luCommand("r2", 'vtysh -c "show bgp ipv4 vpn"', num, "wait", "VPN SAFI clear")
+luCommand("r3", 'vtysh -c "show bgp ipv4 vpn"', num, "wait", "VPN SAFI clear")
+luCommand("r4", 'vtysh -c "show bgp ipv4 vpn"', num, "wait", "VPN SAFI clear")
luCommand(
"r1",
password zebra
log stdout notifications
log commands
+#debug bgp vnc verbose
router bgp 5226
bgp router-id 3.3.3.3
bgp cluster-id 3.3.3.3