From nobody Sun Mar 24 16:19:26 2024 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 4V2h8v07WGz5G08m; Sun, 24 Mar 2024 16:19:27 +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 4V2h8t6kTKz4FqN; Sun, 24 Mar 2024 16:19:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711297166; 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=JpUbkcG+fEKVGJ7k8e5qXkS60Q6pV1GZ76JlTNYuheM=; b=vs9bbG0F9GbV+1r2Amy+5BH08158B1ObUek7yVK5DAjZXefCOjgFxH1+j3smYHljdLJYec CrnCBDOuC4TMMkkwl//FuhgvfYLILm80u2pEv8Osf+5jVFdBua0JP3Ksc00Z7ChnYMeIv0 aKfDDlypIDMbK6G8LvnwP8tVRYhb8zf0IBih1mVFWaKiY+ncutJVwN3Ql0YOqWiyAP8zdM zMCI+MrfvYqi7qdo5F3WspnvTpbLW9V/n1/eSX1PTxk/Da7g4z0ypp/ZF2YWZdb/T+sklB G71lo34VskjdbVZFdl16zWMsh8mSu0tfMeV20PrhGdCYSv5bPB3UY0dqdekWMQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1711297166; a=rsa-sha256; cv=none; b=KfdSDEp5bQiE9BIcqERRrKD+uXaQx60OQMrxrbiaqmk4EdvGCyD9PB3lOmwGsZMhdYWCGh PpWbmtCE+Jg2y0+vwLHvdD5FNHEKJXq7+aJLcBnf2USYDpMIqv99q1pT+wNQ/ZxpgcNuwM V+zbvoMvmr3KvH29Tykb2zzD7cwIw3enf9MWzTc2066fEsqh+59+xrKqgg18u/rUPV7LbA mE7uQYdtFHGN7mOpF0TGcuEnS6cWnrckcJwO9WcLhPRduu/qXa8alPxYyXL+Uk5tbze+J0 TOHw4pzl0c7FWUauuD+lMY+5pYd3Tl4q9sYhOPBeZxoa8yYfy7X8aDf1Nu/Rpg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711297166; 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=JpUbkcG+fEKVGJ7k8e5qXkS60Q6pV1GZ76JlTNYuheM=; b=Kdrzmdx9Y+7fmq6QXeUXYKFquMfRvkQJFsEYtzKecd8G0Q0wSKD7k59XvBsyctExI1gqCh ze6lB6buZjWIBCI/u45n4k/ZrDfnhCSBkwlcLTLTRnkMUbRsxDcLglo9PbmaH6JhgIsRCY xZYnMIBrLX7rjOhO8Wp6bbXBonn0EMii3ctGZxdoSHXdMkBSImU5sYUcwy6U4rCU1lkesM BxfSFdJ9ja5NXFe7jMmT8V/l3K1GKLLW4UFIU8O90r38BWzXMZntsa4IJt3eZ+zi88MY4L tO3iNNxX4njM+p5tQekwnkSjVJrTJLpM0NcQjp5RZrx1vNqSxVr2BAYIAknAdA== 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 4V2h8t6LBkzfVJ; Sun, 24 Mar 2024 16:19:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 42OGJQfQ079306; Sun, 24 Mar 2024 16:19:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42OGJQ6l079303; Sun, 24 Mar 2024 16:19:26 GMT (envelope-from git) Date: Sun, 24 Mar 2024 16:19:26 GMT Message-Id: <202403241619.42OGJQ6l079303@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 7142ab479066 - main - icmp: do not store per-VNET identical array of strings 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: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7142ab4790666022a2a3d85910e9cd8e241d9b87 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=7142ab4790666022a2a3d85910e9cd8e241d9b87 commit 7142ab4790666022a2a3d85910e9cd8e241d9b87 Author: Gleb Smirnoff AuthorDate: 2024-03-24 16:13:23 +0000 Commit: Gleb Smirnoff CommitDate: 2024-03-24 16:13:23 +0000 icmp: do not store per-VNET identical array of strings We need per-VNET struct counter_rate, but we don't need per-VNET set of const char *. Also, identical word "response" can go into the format string instead of being stored 7 times. Reviewed by: kp, zlei, tuexen Differential Revision: https://reviews.freebsd.org/D44475 --- sys/netinet/ip_icmp.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index 3da86efa6e72..c2aa1ded3266 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -1091,28 +1091,26 @@ ip_next_mtu(int mtu, int dir) * the 'final' error, but it doesn't make sense to solve the printing * delay with more complex code. */ -struct icmp_rate { - const char *descr; - struct counter_rate cr; -}; -VNET_DEFINE_STATIC(struct icmp_rate, icmp_rates[BANDLIM_MAX]) = { - { "icmp unreach response" }, - { "icmp ping response" }, - { "icmp tstamp response" }, - { "closed port RST response" }, - { "open port RST response" }, - { "icmp6 unreach response" }, - { "sctp ootb response" } -}; +VNET_DEFINE_STATIC(struct counter_rate, icmp_rates[BANDLIM_MAX]); #define V_icmp_rates VNET(icmp_rates) +static const char *icmp_rate_descrs[BANDLIM_MAX] = { + [BANDLIM_ICMP_UNREACH] = "icmp unreach", + [BANDLIM_ICMP_ECHO] = "icmp ping", + [BANDLIM_ICMP_TSTAMP] = "icmp tstamp", + [BANDLIM_RST_CLOSEDPORT] = "closed port RST", + [BANDLIM_RST_OPENPORT] = "open port RST", + [BANDLIM_ICMP6_UNREACH] = "icmp6 unreach", + [BANDLIM_SCTP_OOTB] = "sctp ootb", +}; + static void icmp_bandlimit_init(void) { for (int i = 0; i < BANDLIM_MAX; i++) { - V_icmp_rates[i].cr.cr_rate = counter_u64_alloc(M_WAITOK); - V_icmp_rates[i].cr.cr_ticks = ticks; + V_icmp_rates[i].cr_rate = counter_u64_alloc(M_WAITOK); + V_icmp_rates[i].cr_ticks = ticks; } } VNET_SYSINIT(icmp_bandlimit, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY, @@ -1123,7 +1121,7 @@ icmp_bandlimit_uninit(void) { for (int i = 0; i < BANDLIM_MAX; i++) - counter_u64_free(V_icmp_rates[i].cr.cr_rate); + counter_u64_free(V_icmp_rates[i].cr_rate); } VNET_SYSUNINIT(icmp_bandlimit, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, icmp_bandlimit_uninit, NULL); @@ -1142,7 +1140,7 @@ badport_bandlim(int which) if ((V_icmplim + V_icmplim_curr_jitter) <= 0) V_icmplim_curr_jitter = -V_icmplim + 1; - pps = counter_ratecheck(&V_icmp_rates[which].cr, V_icmplim + + pps = counter_ratecheck(&V_icmp_rates[which], V_icmplim + V_icmplim_curr_jitter); if (pps > 0) { /* @@ -1160,8 +1158,9 @@ badport_bandlim(int which) if (pps == -1) return (-1); if (pps > 0 && V_icmplim_output) - log(LOG_NOTICE, "Limiting %s from %jd to %d packets/sec\n", - V_icmp_rates[which].descr, (intmax_t )pps, V_icmplim + + log(LOG_NOTICE, + "Limiting %s response from %jd to %d packets/sec\n", + icmp_rate_descrs[which], (intmax_t )pps, V_icmplim + V_icmplim_curr_jitter); return (0); }