git: 2193c63f9ad1 - stable/14 - icmp: do not store per-VNET identical array of strings
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 26 Jun 2024 04:50:19 UTC
The branch stable/14 has been updated by zlei:
URL: https://cgit.FreeBSD.org/src/commit/?id=2193c63f9ad16ce6fa9ed1747a87a4db26feda68
commit 2193c63f9ad16ce6fa9ed1747a87a4db26feda68
Author: Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2024-03-24 16:13:23 +0000
Commit: Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2024-06-26 04:48:42 +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
(cherry picked from commit 7142ab4790666022a2a3d85910e9cd8e241d9b87)
---
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 c99499d689db..89ba56dd1b11 100644
--- a/sys/netinet/ip_icmp.c
+++ b/sys/netinet/ip_icmp.c
@@ -1093,28 +1093,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,
@@ -1125,7 +1123,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);
@@ -1144,7 +1142,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) {
/*
@@ -1162,8 +1160,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);
}