From nobody Mon Aug 29 15:17:55 2022 X-Original-To: dev-commits-src-all@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 4MGYwM38C8z4bKmm; Mon, 29 Aug 2022 15:17:55 +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 4MGYwM2Ph6z4N1y; Mon, 29 Aug 2022 15:17:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661786275; 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=sYBV8j8dHoqKDNWO9byjxH/IrudoWihC9NfePjndnpw=; b=YVqwCRhQPtExqgSe/chd6EiBb+ADnUQho3PkzjW+27rV4orMss1k5flcE7nqMAG/YCdGfO S+mtByKJyLSi4UyMe8Jvw7uFTVv+c6U0pVnWBqAxRJowhabyI3lezIxvzQFZRC0riPVHxS Bs/TH7dnhzXzsB529+RrhFalMI8ON/OIMi8hi9NaLAUeVULos+uGwBdq2azdHyXD8U98B1 JIB27DjwrUvNu/uO8jVBtdUlQ4tdHxY563RyyXjewjVpidpnzAyLDp+6sdZsSJxZ6K+eUR xAvaHD6z8LGqLn7XbeG1yUdXKE0Z0PeLnce1co2l3mtbJ5xTP87gQd+MeX/bow== 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 4MGYwM19X2zSvK; Mon, 29 Aug 2022 15:17:55 +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 27TFHt5P076582; Mon, 29 Aug 2022 15:17:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27TFHtuW076581; Mon, 29 Aug 2022 15:17:55 GMT (envelope-from git) Date: Mon, 29 Aug 2022 15:17:55 GMT Message-Id: <202208291517.27TFHtuW076581@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 578a99c939b6 - main - routing: improve multiline debug List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 578a99c939b6f7a774f399fc7b64ee956c4ae200 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661786275; 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=sYBV8j8dHoqKDNWO9byjxH/IrudoWihC9NfePjndnpw=; b=s7BZpQUcYmd1zeUphso7BO1aJuuQlWKaDxmOOLbKBR/0iyPciE1Ldq7cNA8kpcC/+Y40rC 9JrzNglkX15YrX7uSQE50Wv+/1EaOH0rRFqd9tt5ca08cp1ThsNd26TUq/b9OwFshs9R35 5fin7NuaoHBbBqVyDX/HeSQJgBTQm8xR3P7UvWu4cHWT9PbEf3pQsZ6sIgXCOaRu8gUwBi UpWAuHccrfNaOiWAEPnPMXZxvKykxzqYJ5F1Im2kWz/W+q7PeE1M6UQcZARpBeaHDWPDSS v/6XvVZMHmTD7CNRXgaKsOvgQIed8RTkFEddwJ6Qzu2XwlRtxGaQ+G361O3Ypg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1661786275; a=rsa-sha256; cv=none; b=BN7czErn9STR2fX2AxpYrQBJDTdGtDD23bLD67GRFRGA9exK3XN45zoxs2ky8+WXtF1t05 I+e6YpNF9vpuNj2UzYBLZ/RqsqH5Xhlr8BlM/Q7xbq2wB0pz3KoYW4bERVQgVvB0/jd6Sc YjiEI70yaj6zV+lptzp0WV4yi8NjdJgxEh92AVYk06akUs5QSALjl1rM9w2P963Ps9EJTj u49DQ51C9eNptSyA/K0nXK1mw4p0Xtq2Gg3uzwHvrAR/Y3aL+ZaWdeVKVjazRJFU8n2Dxw L/aU4vZS07rCSByHPAnHWrhaJoSGvfB9uHcYXqWndvTeArIINlUQLpbsZT8YeA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=578a99c939b6f7a774f399fc7b64ee956c4ae200 commit 578a99c939b6f7a774f399fc7b64ee956c4ae200 Author: Alexander V. Chernikov AuthorDate: 2022-08-29 15:14:49 +0000 Commit: Alexander V. Chernikov CommitDate: 2022-08-29 15:14:49 +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 --- 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 */ /*