Download raw body.
more bgpd rde_rib.c refactoring
Make rib_remove static and factor out the common code from
rib_dump_abort() and rib_dump_terminate() into rib_dump_free().
Also in rib_dump_r() skip empty rib entries. Those entries hold no
prefixes and can always be skipped.
--
:wq Claudio
Index: rde_rib.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde_rib.c,v
diff -u -p -r1.270 rde_rib.c
--- rde_rib.c 24 Sep 2025 12:52:57 -0000 1.270
+++ rde_rib.c 24 Sep 2025 12:59:48 -0000
@@ -42,7 +42,7 @@ struct rib flowrib = { .id = 1, .tree =
struct rib_entry *rib_add(struct rib *, struct pt_entry *);
static inline int rib_compare(const struct rib_entry *,
const struct rib_entry *);
-void rib_remove(struct rib_entry *);
+static void rib_remove(struct rib_entry *);
static inline int rib_empty(struct rib_entry *);
static void rib_dump_abort(uint16_t);
@@ -374,7 +374,7 @@ rib_add(struct rib *rib, struct pt_entry
return (re);
}
-void
+static void
rib_remove(struct rib_entry *re)
{
if (!rib_empty(re))
@@ -436,6 +436,8 @@ rib_dump_r(struct rib_context *ctx)
for (i = 0; re != NULL; re = next) {
next = RB_NEXT(rib_tree, unused, re);
+ if (rib_empty(re))
+ continue;
if (re->rib_id != ctx->ctx_id)
fatalx("%s: Unexpected RIB %u != %u.", __func__,
re->rib_id, ctx->ctx_id);
@@ -495,13 +497,8 @@ rib_dump_runner(void)
}
static void
-rib_dump_abort(uint16_t id)
+rib_dump_free(struct rib_context *ctx)
{
- struct rib_context *ctx, *next;
-
- LIST_FOREACH_SAFE(ctx, &rib_dumps, entry, next) {
- if (id != ctx->ctx_id)
- continue;
if (ctx->ctx_done)
ctx->ctx_done(ctx->ctx_arg, ctx->ctx_aid);
if (ctx->ctx_re && rib_empty(re_unlock(ctx->ctx_re)))
@@ -510,6 +507,17 @@ rib_dump_abort(uint16_t id)
prefix_adjout_destroy(ctx->ctx_p);
LIST_REMOVE(ctx, entry);
free(ctx);
+}
+
+static void
+rib_dump_abort(uint16_t id)
+{
+ struct rib_context *ctx, *next;
+
+ LIST_FOREACH_SAFE(ctx, &rib_dumps, entry, next) {
+ if (id != ctx->ctx_id)
+ continue;
+ rib_dump_free(ctx);
}
}
@@ -521,14 +529,7 @@ rib_dump_terminate(void *arg)
LIST_FOREACH_SAFE(ctx, &rib_dumps, entry, next) {
if (ctx->ctx_arg != arg)
continue;
- if (ctx->ctx_done)
- ctx->ctx_done(ctx->ctx_arg, ctx->ctx_aid);
- if (ctx->ctx_re && rib_empty(re_unlock(ctx->ctx_re)))
- rib_remove(ctx->ctx_re);
- if (ctx->ctx_p && prefix_is_dead(prefix_unlock(ctx->ctx_p)))
- prefix_adjout_destroy(ctx->ctx_p);
- LIST_REMOVE(ctx, entry);
- free(ctx);
+ rib_dump_free(ctx);
}
}
more bgpd rde_rib.c refactoring