From nobody Fri Jan 13 21:25:50 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Ntvbf75Dqz2ql66; Fri, 13 Jan 2023 21:25:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Ntvbf6VzTz44Fr; Fri, 13 Jan 2023 21:25:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673645150; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hdl/QshcVYWOkfYqrLjBkqRQVLqfeVnWlVxk5RJzaVk=; b=p69nL/XLn5rWlhJ4Xxgq8yPaIKlH90BdpM6bod5MUdYnXAOQ5lrJzaQs/3iRqsqmaVT7ye 2vo8K/dT+cDrUpPnZU1DtNq/qwQauPavp+eYxCBPAzKWxk881bER632vW0jaays1byRE93 a1rBUuxk/hKZPAkPU/395a1twjV4mSD1/zmLcdyZdxV2j2LRCuNZnOwcoitAR0Nm/KQ3Al cb1h6Y6uNYLM/WZwn6GkMEYBiQx9JMNJa/4MJBj+bom5NGRwWAI1gMAjnJBz7o/TD5V0n7 +S6h2+BM37Rwn6YAtOBXsueF1QsK+MWIcuW1CN9gWgenRd1u7eWWsIDUWG+99A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673645150; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hdl/QshcVYWOkfYqrLjBkqRQVLqfeVnWlVxk5RJzaVk=; b=ctR4PdsiBXQlLcPFLs5EN+d/IWG/Bp7IFjeSEJjsg8+KL/lxqulkgDRBV8gQScKElileXY uqMdlW5VzsExqN+HBVaZCVbtdgs4aivSlDUJTd+fIgJxGboR48+HSMAX/Pc53JZdCrQXTf GKqVlh7ldTJmiEaVUv1O0Fha15qZTZ7eVgjDiuYNkGovNGKHlweQ87P22NJ6CDOhtA90D9 IY54dzNda6r93MSd6/ZMWQpZ60qX/qaJ6Vcb9jorI7tMG96MmovSHrOBsvSV7lKrFJeV+b vVBakGtg9bEmw5QXhhVy2bVVuXLce2q/vZw0bN7QI4VXItJvtkKp7iYwJC36VA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1673645150; a=rsa-sha256; cv=none; b=BMiTn/c4LeBCH/rqX79gfvj0Zm6wROXIx8QVUB4U0KAS+A+R4x8MwX2fj7CcAz34u3kWB9 +j4Qme9eALfbXHxah9Mlq7W+kMFdDFT5iv6Rt4QQ2P4fboPVsdn6aoPDRgqLfDpIB93h58 SesyFVMcjlaBPCPwjgkhxOa/QKvJmZgSlfJ5cZd0g3g8p1Ky6A5VoNf8nDtUVX6idGk/rs ts+Bt7EUZZUipoR1HphzOggETMY5/jww1KhoikFXukPAsjZEkPahzN1NnMCRLl92+v4lo0 om5fUUUT4qcYSqPIwNSm4wIXBqh3ojOEmiKfjb6LyaLOJa1R5JNWQ6N8/QywPw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Ntvbf5bmnzMvJ; Fri, 13 Jan 2023 21:25:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30DLPoYC042414; Fri, 13 Jan 2023 21:25:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30DLPo4r042413; Fri, 13 Jan 2023 21:25:50 GMT (envelope-from git) Date: Fri, 13 Jan 2023 21:25:50 GMT Message-Id: <202301132125.30DLPo4r042413@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 65768d03cdf6 - stable/13 - routing: improve multiline debug List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 65768d03cdf65a48129c35c1dbb851d480c7aeac Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=65768d03cdf65a48129c35c1dbb851d480c7aeac commit 65768d03cdf65a48129c35c1dbb851d480c7aeac Author: Alexander V. Chernikov AuthorDate: 2022-08-29 15:14:49 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-01-13 21:24:12 +0000 routing: improve multiline debug Add IF_DEBUG_LEVEL() macro to ensure all debug output preparation is run only if the current debug level is sufficient. Consistently use it within routing subsystem. MFC after: 2 weeks (cherry picked from commit 578a99c939b6f7a774f399fc7b64ee956c4ae200) --- sys/net/route/nhgrp.c | 25 +++++++++++-------------- sys/net/route/nhgrp_ctl.c | 12 ++++++------ sys/net/route/nhop_ctl.c | 23 +++++++++++------------ sys/net/route/route_ctl.c | 19 +++++++++---------- sys/net/route/route_debug.h | 3 +++ sys/net/route/route_helpers.c | 34 +++++++++++++++++++--------------- 6 files changed, 59 insertions(+), 57 deletions(-) diff --git a/sys/net/route/nhgrp.c b/sys/net/route/nhgrp.c index 358e5d1eaace..de07eb76113f 100644 --- a/sys/net/route/nhgrp.c +++ b/sys/net/route/nhgrp.c @@ -179,13 +179,11 @@ link_nhgrp(struct nh_control *ctl, struct nhgrp_priv *grp_priv) NHOPS_WUNLOCK(ctl); -#if DEBUG_MAX_LEVEL >= LOG_DEBUG2 - { - char nhgrp_buf[NHOP_PRINT_BUFSIZE]; - nhgrp_print_buf(grp_priv->nhg, nhgrp_buf, sizeof(nhgrp_buf)); - FIB_RH_LOG(LOG_DEBUG2, ctl->ctl_rh, "linked %s", nhgrp_buf); + IF_DEBUG_LEVEL(LOG_DEBUG2) { + char nhgrp_buf[NHOP_PRINT_BUFSIZE] __unused; + FIB_RH_LOG(LOG_DEBUG2, ctl->ctl_rh, "linked %s", + nhgrp_print_buf(grp_priv->nhg, nhgrp_buf, sizeof(nhgrp_buf))); } -#endif consider_resize(ctl, new_num_buckets, new_num_items); return (1); @@ -214,14 +212,13 @@ unlink_nhgrp(struct nh_control *ctl, struct nhgrp_priv *key) NHOPS_WUNLOCK(ctl); -#if DEBUG_MAX_LEVEL >= LOG_DEBUG2 - { + IF_DEBUG_LEVEL(LOG_DEBUG2) { char nhgrp_buf[NHOP_PRINT_BUFSIZE]; nhgrp_print_buf(nhg_priv_ret->nhg, nhgrp_buf, sizeof(nhgrp_buf)); FIB_RH_LOG(LOG_DEBUG2, ctl->ctl_rh, "unlinked idx#%d %s", idx, nhgrp_buf); } -#endif + return (nhg_priv_ret); } @@ -340,11 +337,11 @@ nhgrp_ctl_unlink_all(struct nh_control *ctl) NHOPS_WLOCK_ASSERT(ctl); CHT_SLIST_FOREACH(&ctl->gr_head, mpath, nhg_priv) { -#if DEBUG_MAX_LEVEL >= LOG_DEBUG - char nhgbuf[NHOP_PRINT_BUFSIZE]; - FIB_RH_LOG(LOG_DEBUG, ctl->ctl_rh, "marking %s unlinked", - nhgrp_print_buf(nhg_priv->nhg, nhgbuf, sizeof(nhgbuf))); -#endif + IF_DEBUG_LEVEL(LOG_DEBUG2) { + char nhgbuf[NHOP_PRINT_BUFSIZE] __unused; + FIB_RH_LOG(LOG_DEBUG2, ctl->ctl_rh, "marking %s unlinked", + nhgrp_print_buf(nhg_priv->nhg, nhgbuf, sizeof(nhgbuf))); + } refcount_release(&nhg_priv->nhg_linked); } CHT_SLIST_FOREACH_END; } diff --git a/sys/net/route/nhgrp_ctl.c b/sys/net/route/nhgrp_ctl.c index 90cd5b1e45a0..ca9e01ed0077 100644 --- a/sys/net/route/nhgrp_ctl.c +++ b/sys/net/route/nhgrp_ctl.c @@ -406,12 +406,12 @@ destroy_nhgrp(struct nhgrp_priv *nhg_priv) KASSERT((nhg_priv->nhg_refcount == 0), ("nhg_refcount != 0")); KASSERT((nhg_priv->nhg_idx == 0), ("gr_idx != 0")); -#if DEBUG_MAX_LEVEL >= LOG_DEBUG - char nhgbuf[NHOP_PRINT_BUFSIZE]; - FIB_NH_LOG(LOG_DEBUG, nhg_priv->nhg_nh_weights[0].nh, - "destroying %s", nhgrp_print_buf(nhg_priv->nhg, - nhgbuf, sizeof(nhgbuf))); -#endif + IF_DEBUG_LEVEL(LOG_DEBUG2) { + char nhgbuf[NHOP_PRINT_BUFSIZE] __unused; + FIB_NH_LOG(LOG_DEBUG2, nhg_priv->nhg_nh_weights[0].nh, + "destroying %s", nhgrp_print_buf(nhg_priv->nhg, + nhgbuf, sizeof(nhgbuf))); + } free_nhgrp_nhops(nhg_priv); destroy_nhgrp_int(nhg_priv); diff --git a/sys/net/route/nhop_ctl.c b/sys/net/route/nhop_ctl.c index 263a71c1322e..e4195d106d01 100644 --- a/sys/net/route/nhop_ctl.c +++ b/sys/net/route/nhop_ctl.c @@ -534,10 +534,11 @@ finalize_nhop(struct nh_control *ctl, struct nhop_object *nh, bool link) return (ENOBUFS); } -#if DEBUG_MAX_LEVEL >= LOG_DEBUG - char nhbuf[NHOP_PRINT_BUFSIZE]; - FIB_NH_LOG(LOG_DEBUG, nh, "finalized: %s", nhop_print_buf(nh, nhbuf, sizeof(nhbuf))); -#endif + IF_DEBUG_LEVEL(LOG_DEBUG) { + char nhbuf[NHOP_PRINT_BUFSIZE] __unused; + FIB_NH_LOG(LOG_DEBUG, nh, "finalized: %s", + nhop_print_buf(nh, nhbuf, sizeof(nhbuf))); + } return (0); } @@ -598,10 +599,11 @@ nhop_free(struct nhop_object *nh) return; } -#if DEBUG_MAX_LEVEL >= LOG_DEBUG - char nhbuf[NHOP_PRINT_BUFSIZE]; - FIB_NH_LOG(LOG_DEBUG, nh, "deleting %s", nhop_print_buf(nh, nhbuf, sizeof(nhbuf))); -#endif + IF_DEBUG_LEVEL(LOG_DEBUG) { + char nhbuf[NHOP_PRINT_BUFSIZE] __unused; + FIB_NH_LOG(LOG_DEBUG, nh, "deleting %s", + nhop_print_buf(nh, nhbuf, sizeof(nhbuf))); + } /* * There are only 2 places, where nh_linked can be decreased: @@ -1189,10 +1191,7 @@ nhops_dump_sysctl(struct rib_head *rh, struct sysctl_req *w) ctl = rh->nh_control; NHOPS_RLOCK(ctl); -#if DEBUG_MAX_LEVEL >= LOG_DEBUG - FIB_LOG(LOG_DEBUG, rh->rib_fibnum, rh->rib_family, "dump %u items", - ctl->nh_head.items_count); -#endif + FIB_RH_LOG(LOG_DEBUG, rh, "dump %u items", ctl->nh_head.items_count); CHT_SLIST_FOREACH(&ctl->nh_head, nhops, nh_priv) { error = dump_nhop_entry(rh, nh_priv->nh, w); if (error != 0) { diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c index 4b7572ce7980..a9ea2ad49103 100644 --- a/sys/net/route/route_ctl.c +++ b/sys/net/route/route_ctl.c @@ -609,13 +609,13 @@ rib_copy_route(struct rtentry *rt, const struct route_nhop_data *rnd_src, MPASS((nh_src->nh_flags & NHF_MULTIPATH) == 0); -#if DEBUG_MAX_LEVEL >= LOG_DEBUG2 + IF_DEBUG_LEVEL(LOG_DEBUG2) { char nhbuf[NHOP_PRINT_BUFSIZE], rtbuf[NHOP_PRINT_BUFSIZE]; nhop_print_buf_any(nh_src, nhbuf, sizeof(nhbuf)); rt_print_buf(rt, rtbuf, sizeof(rtbuf)); FIB_RH_LOG(LOG_DEBUG2, rh_dst, "copying %s -> %s from fib %u", rtbuf, nhbuf, nhop_get_fibnum(nh_src)); -#endif + } struct nhop_object *nh = nhop_alloc(rh_dst->rib_fibnum, rh_dst->rib_family); if (nh == NULL) { FIB_RH_LOG(LOG_INFO, rh_dst, "unable to allocate new nexthop"); @@ -645,11 +645,12 @@ rib_copy_route(struct rtentry *rt, const struct route_nhop_data *rnd_src, error = add_route_flags(rh_dst, rt_new, &rnd, op_flags, rc); if (error != 0) { -#if DEBUG_MAX_LEVEL >= LOG_DEBUG - char buf[NHOP_PRINT_BUFSIZE]; - rt_print_buf(rt_new, buf, sizeof(buf)); - FIB_RH_LOG(LOG_DEBUG, rh_dst, "Unable to add route %s: error %d", buf, error); -#endif + IF_DEBUG_LEVEL(LOG_DEBUG2) { + char buf[NHOP_PRINT_BUFSIZE]; + rt_print_buf(rt_new, buf, sizeof(buf)); + FIB_RH_LOG(LOG_DEBUG, rh_dst, + "Unable to add route %s: error %d", buf, error); + } nhop_free(nh); rt_free_immediate(rt_new); } @@ -1295,15 +1296,13 @@ change_route_conditional(struct rib_head *rnh, struct rtentry *rt, struct rtentry *rt_new; int error = 0; -#if DEBUG_MAX_LEVEL >= LOG_DEBUG2 - { + IF_DEBUG_LEVEL(LOG_DEBUG2) { char buf_old[NHOP_PRINT_BUFSIZE], buf_new[NHOP_PRINT_BUFSIZE]; nhop_print_buf_any(rnd_orig->rnd_nhop, buf_old, NHOP_PRINT_BUFSIZE); nhop_print_buf_any(rnd_new->rnd_nhop, buf_new, NHOP_PRINT_BUFSIZE); FIB_LOG(LOG_DEBUG2, rnh->rib_fibnum, rnh->rib_family, "trying change %s -> %s", buf_old, buf_new); } -#endif RIB_WLOCK(rnh); struct route_nhop_data rnd; diff --git a/sys/net/route/route_debug.h b/sys/net/route/route_debug.h index de80bd1ea78b..b7c8c79f7ffa 100644 --- a/sys/net/route/route_debug.h +++ b/sys/net/route/route_debug.h @@ -83,6 +83,8 @@ #define _output printf #define _DEBUG_PASS_MSG(_l) (DEBUG_VAR_NAME >= (_l)) +#define IF_DEBUG_LEVEL(_l) if ((DEBUG_MAX_LEVEL >= (_l)) && (__predict_false(DEBUG_VAR_NAME >= (_l)))) + /* * Logging for events specific for particular family and fib * Example: [nhop_neigh] inet.0 find_lle: nhop nh#4/inet/vtnet0/10.0.0.1: mapped to lle NULL @@ -155,6 +157,7 @@ struct nhgrp_object; struct llentry; struct nhop_neigh; struct rtentry; +struct ifnet; #define NHOP_PRINT_BUFSIZE 48 char *nhop_print_buf(const struct nhop_object *nh, char *buf, size_t bufsize); diff --git a/sys/net/route/route_helpers.c b/sys/net/route/route_helpers.c index a9d21ebfb507..fe503db368ce 100644 --- a/sys/net/route/route_helpers.c +++ b/sys/net/route/route_helpers.c @@ -261,27 +261,33 @@ rib_lookup(uint32_t fibnum, const struct sockaddr *dst, uint32_t flags, #ifdef ROUTE_MPATH static void notify_add(struct rib_cmd_info *rc, const struct weightened_nhop *wn_src, - route_notification_t *cb, void *cbdata) { + route_notification_t *cb, void *cbdata) +{ rc->rc_nh_new = wn_src->nh; rc->rc_nh_weight = wn_src->weight; -#if DEBUG_MAX_LEVEL >= LOG_DEBUG2 - char nhbuf[NHOP_PRINT_BUFSIZE]; - FIB_NH_LOG(LOG_DEBUG2, wn_src->nh, "RTM_ADD for %s @ w=%u", - nhop_print_buf(wn_src->nh, nhbuf, sizeof(nhbuf)), wn_src->weight); -#endif + + IF_DEBUG_LEVEL(LOG_DEBUG2) { + char nhbuf[NHOP_PRINT_BUFSIZE] __unused; + FIB_NH_LOG(LOG_DEBUG2, wn_src->nh, "RTM_ADD for %s @ w=%u", + nhop_print_buf(wn_src->nh, nhbuf, sizeof(nhbuf)), + wn_src->weight); + } cb(rc, cbdata); } static void notify_del(struct rib_cmd_info *rc, const struct weightened_nhop *wn_src, - route_notification_t *cb, void *cbdata) { + route_notification_t *cb, void *cbdata) +{ rc->rc_nh_old = wn_src->nh; rc->rc_nh_weight = wn_src->weight; -#if DEBUG_MAX_LEVEL >= LOG_DEBUG2 - char nhbuf[NHOP_PRINT_BUFSIZE]; - FIB_NH_LOG(LOG_DEBUG2, wn_src->nh, "RTM_DEL for %s @ w=%u", - nhop_print_buf(wn_src->nh, nhbuf, sizeof(nhbuf)), wn_src->weight); -#endif + + IF_DEBUG_LEVEL(LOG_DEBUG2) { + char nhbuf[NHOP_PRINT_BUFSIZE] __unused; + FIB_NH_LOG(LOG_DEBUG2, wn_src->nh, "RTM_DEL for %s @ w=%u", + nhop_print_buf(wn_src->nh, nhbuf, sizeof(nhbuf)), + wn_src->weight); + } cb(rc, cbdata); } @@ -313,14 +319,12 @@ decompose_change_notification(struct rib_cmd_info *rc, route_notification_t *cb, wn_new = &tmp; num_new = 1; } -#if DEBUG_MAX_LEVEL >= LOG_DEBUG - { + IF_DEBUG_LEVEL(LOG_DEBUG) { char buf_old[NHOP_PRINT_BUFSIZE], buf_new[NHOP_PRINT_BUFSIZE]; nhop_print_buf_any(rc->rc_nh_old, buf_old, NHOP_PRINT_BUFSIZE); nhop_print_buf_any(rc->rc_nh_new, buf_new, NHOP_PRINT_BUFSIZE); FIB_NH_LOG(LOG_DEBUG, wn_old[0].nh, "change %s -> %s", buf_old, buf_new); } -#endif /* Use the fact that each @wn array is sorted */ /*