From cc75cbea1bc33a3ae8eea8799860aef3a50289aa Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 14 Jun 2022 14:45:01 -0400 Subject: [PATCH] zebra: Add `%pNG` to zebra print routines Add `%pNG` so that a nexthop group can be displayed in debugs/logs such that it can provide useful information. Signed-off-by: Donald Sharp --- zebra/zebra_nhg.c | 29 +++++++++++++++++++++++++++++ zebra/zebra_nhg.h | 4 ++++ 2 files changed, 33 insertions(+) diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index cf09902d52..980a661298 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -3425,3 +3425,32 @@ unsigned long zebra_nhg_score_proto(int type) return count; } + +printfrr_ext_autoreg_p("NG", printfrr_nhghe); +static ssize_t printfrr_nhghe(struct fbuf *buf, struct printfrr_eargs *ea, + const void *ptr) +{ + const struct nhg_hash_entry *nhe = ptr; + const struct nhg_connected *dep; + ssize_t ret = 0; + + if (!nhe) + return bputs(buf, "[NULL]"); + + ret += bprintfrr(buf, "%u[", nhe->id); + if (nhe->ifp) + ret += printfrr_nhs(buf, nhe->nhg.nexthop); + else { + int count = zebra_nhg_depends_count(nhe); + + frr_each (nhg_connected_tree_const, &nhe->nhg_depends, dep) { + ret += bprintfrr(buf, "%u", dep->nhe->id); + if (count > 1) + ret += bputs(buf, "/"); + count--; + } + } + + ret += bputs(buf, "]"); + return ret; +} diff --git a/zebra/zebra_nhg.h b/zebra/zebra_nhg.h index 3fbf778be2..0863d90a7e 100644 --- a/zebra/zebra_nhg.h +++ b/zebra/zebra_nhg.h @@ -364,6 +364,10 @@ extern void zebra_nhg_mark_keep(void); struct route_entry; /* Forward ref to avoid circular includes */ extern int nexthop_active_update(struct route_node *rn, struct route_entry *re); +#ifdef _FRR_ATTRIBUTE_PRINTFRR +#pragma FRR printfrr_ext "%pNG" (const struct nhg_hash_entry *) +#endif + #ifdef __cplusplus } #endif -- 2.39.5