git: 5c23343b8c0c - main - routing: convert remnants of DPRINTF to FIB_CTL_LOG().

From: Alexander V. Chernikov <melifaro_at_FreeBSD.org>
Date: Mon, 01 Aug 2022 08:57:31 UTC
The branch main has been updated by melifaro:

URL: https://cgit.FreeBSD.org/src/commit/?id=5c23343b8c0cc018f06a4a2cb2d911770bdc8ee2

commit 5c23343b8c0cc018f06a4a2cb2d911770bdc8ee2
Author:     Alexander V. Chernikov <melifaro@FreeBSD.org>
AuthorDate: 2022-07-29 17:41:16 +0000
Commit:     Alexander V. Chernikov <melifaro@FreeBSD.org>
CommitDate: 2022-08-01 08:55:07 +0000

    routing: convert remnants of DPRINTF to FIB_CTL_LOG().
    
    Convert the last remaining pieces of old-style debug messages
     to the new debugging framework.
    
    Differential Revision: https://reviews.freebsd.org/D35994
    MFC after:      2 weeks
---
 sys/net/route/nhop.c          | 41 ++++++++++++++++++++++++++---------------
 sys/net/route/route_debug.h   |  2 ++
 sys/net/route/route_helpers.c |  2 --
 sys/net/route/route_var.h     |  6 ------
 4 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/sys/net/route/nhop.c b/sys/net/route/nhop.c
index 843ef64bb141..36e5179628a8 100644
--- a/sys/net/route/nhop.c
+++ b/sys/net/route/nhop.c
@@ -48,6 +48,11 @@ __FBSDID("$FreeBSD$");
 #include <net/route/nhop_var.h>
 #include <net/vnet.h>
 
+#define	DEBUG_MOD_NAME	nhop
+#define	DEBUG_MAX_LEVEL	LOG_DEBUG
+#include <net/route/route_debug.h>
+_DECLARE_DEBUG(LOG_INFO);
+
 /*
  * This file contains data structures management logic for the nexthop ("nhop")
  *   route subsystem.
@@ -99,8 +104,7 @@ nhops_init_rib(struct rib_head *rh)
 	rh->nh_control = ctl;
 	ctl->ctl_rh = rh;
 
-	DPRINTF("NHOPS init for fib %u af %u: ctl %p rh %p", rh->rib_fibnum,
-	    rh->rib_family, ctl, rh);
+	FIB_CTL_LOG(LOG_DEBUG2, ctl, "nhops init: ctl %p rh %p", ctl, rh);
 
 	return (0);
 }
@@ -154,7 +158,7 @@ nhops_destroy_rib(struct rib_head *rh)
 
 	NHOPS_WLOCK(ctl);
 	CHT_SLIST_FOREACH(&ctl->nh_head, nhops, nh_priv) {
-		DPRINTF("Marking nhop %u unlinked", nh_priv->nh_idx);
+		FIB_RH_LOG(LOG_DEBUG3, rh, "marking nhop %u unlinked", nh_priv->nh_idx);
 		refcount_release(&nh_priv->nh_linked);
 	} CHT_SLIST_FOREACH_END;
 #ifdef ROUTE_MPATH
@@ -251,8 +255,9 @@ consider_resize(struct nh_control *ctl, uint32_t new_nh_buckets, uint32_t new_id
 		return;
 	}
 
-	DPRINTF("going to resize: nh:[ptr:%p sz:%u] idx:[ptr:%p sz:%u]", nh_ptr,
-	    new_nh_buckets, nh_idx_ptr, new_idx_items);
+	FIB_CTL_LOG(LOG_DEBUG, ctl,
+	    "going to resize: nh:[ptr:%p sz:%u] idx:[ptr:%p sz:%u]",
+	    nh_ptr, new_nh_buckets, nh_idx_ptr, new_idx_items);
 
 	old_idx_ptr = NULL;
 
@@ -296,7 +301,7 @@ link_nhop(struct nh_control *ctl, struct nhop_priv *nh_priv)
 
 	if (bitmask_alloc_idx(&ctl->nh_idx_head, &idx) != 0) {
 		NHOPS_WUNLOCK(ctl);
-		DPRINTF("Unable to allocate nhop index");
+		FIB_CTL_LOG(LOG_INFO, ctl, "Unable to allocate nhop index");
 		RTSTAT_INC(rts_nh_idx_alloc_failure);
 		consider_resize(ctl, num_buckets_new, num_items_new);
 		return (0);
@@ -310,8 +315,9 @@ link_nhop(struct nh_control *ctl, struct nhop_priv *nh_priv)
 
 	NHOPS_WUNLOCK(ctl);
 
-	DPRINTF("Linked nhop priv %p to %d, hash %u, ctl %p", nh_priv, idx,
-	    hash_priv(nh_priv), ctl);
+	FIB_RH_LOG(LOG_DEBUG2, ctl->ctl_rh,
+	    "Linked nhop priv %p to %d, hash %u, ctl %p",
+	    nh_priv, idx, hash_priv(nh_priv), ctl);
 	consider_resize(ctl, num_buckets_new, num_items_new);
 
 	return (idx);
@@ -340,9 +346,9 @@ unlink_nhop(struct nh_control *ctl, struct nhop_priv *nh_priv_del)
 
 		KASSERT((idx != 0), ("bogus nhop index 0"));
 		if ((bitmask_free_idx(&ctl->nh_idx_head, idx)) != 0) {
-			DPRINTF("Unable to remove index %d from fib %u af %d",
-			    idx, ctl->ctl_rh->rib_fibnum,
-			    ctl->ctl_rh->rib_family);
+			FIB_CTL_LOG(LOG_DEBUG, ctl,
+			    "Unable to remove index %d from fib %u af %d",
+			    idx, ctl->ctl_rh->rib_fibnum, ctl->ctl_rh->rib_family);
 		}
 	}
 
@@ -351,12 +357,17 @@ unlink_nhop(struct nh_control *ctl, struct nhop_priv *nh_priv_del)
 	num_items_new = bitmask_get_resize_items(&ctl->nh_idx_head);
 
 	NHOPS_WUNLOCK(ctl);
+		FIB_CTL_LOG(LOG_INFO, ctl, "Unable to unlink nhop priv %p from hash, hash %u ctl %p",
+		    nh_priv_del, hash_priv(nh_priv_del), ctl);
 
-	if (priv_ret == NULL)
-		DPRINTF("Unable to unlink nhop priv %p from hash, hash %u ctl %p",
+	if (priv_ret == NULL) {
+		FIB_CTL_LOG(LOG_INFO, ctl,
+		    "Unable to unlink nhop priv %p from hash, hash %u ctl %p",
 		    nh_priv_del, hash_priv(nh_priv_del), ctl);
-	else
-		DPRINTF("Unlinked nhop %p priv idx %d", priv_ret, idx);
+	} else {
+		FIB_CTL_LOG(LOG_DEBUG2, ctl, "Unlinked nhop %p priv idx %d",
+		    priv_ret, idx);
+	}
 
 	consider_resize(ctl, num_buckets_new, num_items_new);
 
diff --git a/sys/net/route/route_debug.h b/sys/net/route/route_debug.h
index 30d2a1c9a99f..de80bd1ea78b 100644
--- a/sys/net/route/route_debug.h
+++ b/sys/net/route/route_debug.h
@@ -96,6 +96,8 @@
 #define FIB_NH_LOG(_l, _nh, _fmt, ...)  FIB_LOG_##_l(_l, nhop_get_fibnum(_nh), nhop_get_upper_family(_nh), _fmt, ## __VA_ARGS__)
 /* Same as FIB_LOG, but uses rib_head to get fib and family */
 #define FIB_RH_LOG(_l, _rh, _fmt, ...)  FIB_LOG_##_l(_l, (_rh)->rib_fibnum, (_rh)->rib_family, _fmt, ## __VA_ARGS__)
+/* Same as FIB_LOG, but uses nh_control to get fib and family from linked rib */
+#define FIB_CTL_LOG(_l, _ctl, _fmt, ...)  FIB_LOG_##_l(_l, (_ctl)->ctl_rh->rib_fibnum, (_ctl)->ctl_rh->rib_family, _fmt, ## __VA_ARGS__)
 
 /*
  * Generic logging for routing subsystem
diff --git a/sys/net/route/route_helpers.c b/sys/net/route/route_helpers.c
index 001ebc5e388b..6c7f16eb047e 100644
--- a/sys/net/route/route_helpers.c
+++ b/sys/net/route/route_helpers.c
@@ -383,8 +383,6 @@ rib_decompose_notification(struct rib_cmd_info *rc, route_notification_t *cb,
 	struct rib_cmd_info rc_new;
 
 	rc_new = *rc;
-	DPRINTF("cb=%p cmd=%d nh_old=%p nh_new=%p",
-	    cb, rc->cmd, rc->nh_old, rc->nh_new);
 	switch (rc->rc_cmd) {
 	case RTM_ADD:
 		if (!NH_IS_NHGRP(rc->rc_nh_new))
diff --git a/sys/net/route/route_var.h b/sys/net/route/route_var.h
index 740729ecb415..e54ea08f4e80 100644
--- a/sys/net/route/route_var.h
+++ b/sys/net/route/route_var.h
@@ -41,12 +41,6 @@
 #include <sys/counter.h>
 #include <net/route/nhop.h>
 
-#ifdef	RTDEBUG
-#define	DPRINTF(_fmt, ...)	printf("%s: " _fmt "\n", __func__ , ## __VA_ARGS__)
-#else
-#define	DPRINTF(_fmt, ...)
-#endif
-
 struct nh_control;
 /* Sets prefix-specific nexthop flags (NHF_DEFAULT, RTF/NHF_HOST, RTF_BROADCAST,..) */
 typedef int rnh_set_nh_pfxflags_f_t(u_int fibnum, const struct sockaddr *addr,