]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: replace _rnode_zlog with %pZN ext 8535/head
authorDavid Lamparter <equinox@opensourcerouting.org>
Thu, 22 Apr 2021 12:38:31 +0000 (14:38 +0200)
committerDavid Lamparter <equinox@opensourcerouting.org>
Sun, 2 May 2021 14:20:30 +0000 (16:20 +0200)
Since _rnode_zlog was wrapping zlog(), these messages weren't getting an
unique ID assigned through the xref mechanism.  Replace macro with a
small extension that prints (almost) the same thing.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
zebra/zebra_rib.c

index bdacd411bd9ac7ff35077d4b9abfd1303d87fe1c..c4147e44d757a09423254fc48a121cf60def1b70 100644 (file)
@@ -132,41 +132,61 @@ struct wq_nhg_wrapper {
 #define WQ_NHG_WRAPPER_TYPE_CTX  0x01
 #define WQ_NHG_WRAPPER_TYPE_NHG  0x02
 
-static void PRINTFRR(5, 6)
-_rnode_zlog(const char *_func, vrf_id_t vrf_id, struct route_node *rn,
-           int priority, const char *msgfmt, ...)
+/* %pRN is already a printer for route_nodes that just prints the prefix */
+#ifdef _FRR_ATTRIBUTE_PRINTFRR
+#pragma FRR printfrr_ext "%pZN" (struct route_node *)
+#endif
+
+printfrr_ext_autoreg_p("ZN", printfrr_zebra_node);
+static ssize_t printfrr_zebra_node(struct fbuf *buf, struct printfrr_eargs *ea,
+                                  const void *ptr)
 {
-       char buf[SRCDEST2STR_BUFFER + sizeof(" (MRIB)")];
-       char msgbuf[512];
-       va_list ap;
-       uint32_t table = 0;
-
-       va_start(ap, msgfmt);
-       vsnprintf(msgbuf, sizeof(msgbuf), msgfmt, ap);
-       va_end(ap);
-
-       if (rn) {
-               struct rib_table_info *info = srcdest_rnode_table_info(rn);
-               rib_dest_t *dest = NULL;
+       struct route_node *rn = (struct route_node *)ptr;
+       ssize_t rv = 0;
+
+       /* just the table number? */
+       if (ea->fmt[0] == 't') {
+               rib_dest_t *dest;
                struct route_entry *re = NULL;
 
-               srcdest_rnode2str(rn, buf, sizeof(buf));
+               ea->fmt++;
 
-               if (info->safi == SAFI_MULTICAST)
-                       strlcat(buf, " (MRIB)", sizeof(buf));
+               if (!rn)
+                       return bputch(buf, '!');
 
                dest = rib_dest_from_rnode(rn);
                if (dest)
                        re = re_list_first(&dest->routes);
                if (re)
-                       table = re->table;
+                       rv += bprintfrr(buf, "%u", re->table);
+               else
+                       rv += bputch(buf, '?');
+
        } else {
-               snprintf(buf, sizeof(buf), "{(route_node *) NULL}");
-       }
+               char cbuf[PREFIX_STRLEN * 2 + 6];
+               struct rib_table_info *info;
 
-       zlog(priority, "%s: (%u:%u):%s: %s", _func, vrf_id, table, buf, msgbuf);
+               if (!rn)
+                       return bputs(buf, "{(route_node *) NULL}");
+
+               srcdest_rnode2str(rn, cbuf, sizeof(cbuf));
+               rv += bputs(buf, cbuf);
+
+               info = srcdest_rnode_table_info(rn);
+               if (info->safi == SAFI_MULTICAST)
+                       rv += bputs(buf, " (MRIB)");
+       }
+       return rv;
 }
 
+#define rnode_debug(node, vrf_id, msg, ...)                                    \
+       zlog_debug("%s: (%u:%pZNt):%pZN: " msg, __func__, vrf_id, node, node,  \
+                  ##__VA_ARGS__)
+
+#define rnode_info(node, vrf_id, msg, ...)                                     \
+       zlog_info("%s: (%u:%pZNt):%pZN: " msg, __func__, vrf_id, node, node,   \
+                 ##__VA_ARGS__)
+
 static char *_dump_re_status(const struct route_entry *re, char *buf,
                             size_t len)
 {
@@ -191,11 +211,6 @@ static char *_dump_re_status(const struct route_entry *re, char *buf,
        return buf;
 }
 
-#define rnode_debug(node, vrf_id, ...)                                         \
-       _rnode_zlog(__func__, vrf_id, node, LOG_DEBUG, __VA_ARGS__)
-#define rnode_info(node, ...)                                                  \
-       _rnode_zlog(__func__, vrf_id, node, LOG_INFO, __VA_ARGS__)
-
 uint8_t route_distance(int type)
 {
        uint8_t distance;