From nobody Mon Mar 13 16:49:24 2023 X-Original-To: dev-commits-src-main@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 4Pb2gT0pW8z3xwQp; Mon, 13 Mar 2023 16:49:25 +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 4Pb2gS4mw7z4Jc7; Mon, 13 Mar 2023 16:49:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678726164; 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=3ZaomUTVa8TDOm+W7rnzAMr24bvx9mPjB/f0lIQvsu4=; b=s3iHCUi48kM6KQJ0e8Fy+6eJ8f91H+UqP0cKjTgIfC3o043CYcq0xXcz6pYPSuK5McgIWT v+oEYegjox87Uj5DTu2O8V8ZRSSNaS9Fx+vmyaBwipj861GqR+uu5m8q1pq01HvM7WQKEB 6ZVQOSFvnthTP3CMoFjoBlf7Tr5xm/HM3Bmr6C8WBbwCjkDHFMClAw+yxWQD7T/v958lwm G0eKq0jRkyTY2ddo7kVWZHXqQBy3YcxdSZl8+kGbsUa3K8zb9w7IeyJNUOpgqIBgFkeqB+ BkbvPpBLgxttPNGQ2YHQjnzQBZWu0SotY3NcHvvtFNzVOq3l0rcOWZXg5n1B/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678726164; 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=3ZaomUTVa8TDOm+W7rnzAMr24bvx9mPjB/f0lIQvsu4=; b=LyLc7FQiA2INFqaoHOnA3qigV1BL4vvGR1ALofLQC7mWDHG1pZit0MYKVQ7VZeHGd5sQcP q7kmKKOwf0ZNCWtVViJ3Yv+IAwZnuysCsv5/EnoltZOhpyhobWYLqSg7aCQ2gCyFPYaOfX 2fslbgc19314lhH/MMYh4ft1vka2RdfYarXoaDtDiEYilWYsPh2023iCdj/aj0xhGcExF0 X2gkVPkpBs42RTlHZCaLHRa2PJwkd93zLRU8lra3UOkXBlalfiRc2ZEWMDhwiKdV1Rt7lx RjKQeCGK+zmdqR3I+JTHLdZbKeUjiem5h/mWSoroAyPFtSJ4Q0dBO7D7Wc04pQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1678726164; a=rsa-sha256; cv=none; b=sc4hKF8xa+xGdDSAAOXJMYZDMvvZWHYy/aJxETLXUw546t08bHZ12M8N5irYq9Fz/TX05j hGZpXmjK9wgV1Gp3rTsgmmnGrsIoRVPlAwnhFl3pu+l09sY45DK8mOeu+iP7ZGFH77nw70 13wEUKpVmKfD2AiiYoEKzifhKrJcgOYH28JxteDnsh1PndXOSxGQKg9q6IHi9FBsGwhngP 0Kzpo0ohiG85c/zbs5w7i20fyH+5Gli7MmV24NnMv8tvpuGED8L2vK5SEC9pmdZkAoL118 eQzEGP+x1JqJtM1lKZJ87aPTwWGzTfuS2ELrrtDU4DmVOifdEeI2hISpQ4LJUQ== 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 4Pb2gS3st9z11Kf; Mon, 13 Mar 2023 16:49:24 +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 32DGnOLR023775; Mon, 13 Mar 2023 16:49:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32DGnOrT023774; Mon, 13 Mar 2023 16:49:24 GMT (envelope-from git) Date: Mon, 13 Mar 2023 16:49:24 GMT Message-Id: <202303131649.32DGnOrT023774@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Pawel Biernacki Subject: git: 35b6e52c30a2 - main - net.inet6.ip6.log_interval: use ppsratecheck(9) internally List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kaktus X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 35b6e52c30a290e081710b87ff0be21f4941d3f4 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kaktus: URL: https://cgit.FreeBSD.org/src/commit/?id=35b6e52c30a290e081710b87ff0be21f4941d3f4 commit 35b6e52c30a290e081710b87ff0be21f4941d3f4 Author: Pawel Biernacki AuthorDate: 2023-03-13 16:39:20 +0000 Commit: Pawel Biernacki CommitDate: 2023-03-13 16:47:06 +0000 net.inet6.ip6.log_interval: use ppsratecheck(9) internally Reported by: mjg Differential Revision: https://reviews.freebsd.org/D38758 --- sys/netinet6/in6_proto.c | 18 ++++++++++++++++-- sys/netinet6/ip6_forward.c | 8 ++------ sys/netinet6/ip6_mroute.c | 4 +--- sys/netinet6/ip6_var.h | 6 ++---- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c index 1f2a41dd51de..971b61c74899 100644 --- a/sys/netinet6/in6_proto.c +++ b/sys/netinet6/in6_proto.c @@ -161,7 +161,6 @@ VNET_DEFINE(int, ip6_accept_rtadv) = 0; VNET_DEFINE(int, ip6_no_radr) = 0; VNET_DEFINE(int, ip6_norbit_raif) = 0; VNET_DEFINE(int, ip6_rfc6204w3) = 0; -VNET_DEFINE(int, ip6_log_interval) = 5; VNET_DEFINE(int, ip6_hdrnestlimit) = 15;/* How many header options will we * process? */ VNET_DEFINE(int, ip6_dad_count) = 1; /* DupAddrDetectionTransmits */ @@ -173,7 +172,6 @@ VNET_DEFINE(int, ip6_rr_prune) = 5; /* router renumbering prefix VNET_DEFINE(int, ip6_mcast_pmtu) = 0; /* enable pMTU discovery for multicast? */ VNET_DEFINE(int, ip6_v6only) = 1; -VNET_DEFINE(time_t, ip6_log_time) = (time_t)0L; #ifdef IPSTEALTH VNET_DEFINE(int, ip6stealth) = 0; #endif @@ -199,6 +197,14 @@ VNET_DEFINE(int, icmp6_nodeinfo) = (ICMP6_NODEINFO_FQDNOK|ICMP6_NODEINFO_NODEADDROK); VNET_DEFINE(int, icmp6_nodeinfo_oldmcprefix) = 1; +VNET_DEFINE_STATIC(int, ip6_log_interval) = 5; +VNET_DEFINE_STATIC(int, ip6_log_count) = 0; +VNET_DEFINE_STATIC(struct timeval, ip6_log_last) = { 0 }; + +#define V_ip6_log_interval VNET(ip6_log_interval) +#define V_ip6_log_count VNET(ip6_log_count) +#define V_ip6_log_last VNET(ip6_log_last) + /* * sysctl related items. */ @@ -254,6 +260,14 @@ sysctl_ip6_tempvltime(SYSCTL_HANDLER_ARGS) return (0); } +int +ip6_log_ratelimit(void) +{ + + return (ppsratecheck(&V_ip6_log_last, &V_ip6_log_count, + V_ip6_log_interval)); +} + SYSCTL_INT(_net_inet6_ip6, IPV6CTL_FORWARDING, forwarding, CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_forwarding), 0, "Enable forwarding of IPv6 packets between interfaces"); diff --git a/sys/netinet6/ip6_forward.c b/sys/netinet6/ip6_forward.c index fc00eab4b784..293fcd977344 100644 --- a/sys/netinet6/ip6_forward.c +++ b/sys/netinet6/ip6_forward.c @@ -114,9 +114,7 @@ ip6_forward(struct mbuf *m, int srcrt) IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src)) { IP6STAT_INC(ip6s_cantforward); /* XXX in6_ifstat_inc(rt->rt_ifp, ifs6_in_discard) */ - if (V_ip6_log_cannot_forward && - (V_ip6_log_time + V_ip6_log_interval < time_uptime)) { - V_ip6_log_time = time_uptime; + if (V_ip6_log_cannot_forward && ip6_log_ratelimit()) { log(LOG_DEBUG, "cannot forward " "from %s to %s nxt %d received on %s\n", @@ -222,9 +220,7 @@ again: IP6STAT_INC(ip6s_badscope); in6_ifstat_inc(nh->nh_ifp, ifs6_in_discard); - if (V_ip6_log_cannot_forward && - (V_ip6_log_time + V_ip6_log_interval < time_uptime)) { - V_ip6_log_time = time_uptime; + if (V_ip6_log_cannot_forward && ip6_log_ratelimit()) { log(LOG_DEBUG, "cannot forward " "src %s, dst %s, nxt %d, rcvif %s, outif %s\n", diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c index cdccd04abc63..9b2325c8e7a2 100644 --- a/sys/netinet6/ip6_mroute.c +++ b/sys/netinet6/ip6_mroute.c @@ -1099,9 +1099,7 @@ X_ip6_mforward(struct ip6_hdr *ip6, struct ifnet *ifp, struct mbuf *m) */ if (IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src)) { IP6STAT_INC(ip6s_cantforward); - if (V_ip6_log_cannot_forward && - (V_ip6_log_time + V_ip6_log_interval < time_uptime)) { - V_ip6_log_time = time_uptime; + if (V_ip6_log_cannot_forward && ip6_log_ratelimit()) { log(LOG_DEBUG, "cannot forward " "from %s to %s nxt %d received on %s\n", diff --git a/sys/netinet6/ip6_var.h b/sys/netinet6/ip6_var.h index 469b49459e2c..bfc9f72be8ea 100644 --- a/sys/netinet6/ip6_var.h +++ b/sys/netinet6/ip6_var.h @@ -293,8 +293,6 @@ VNET_DECLARE(int, ip6_norbit_raif); /* Disable R-bit in NA on RA * receiving IF. */ VNET_DECLARE(int, ip6_rfc6204w3); /* Accept defroute from RA even when forwarding enabled */ -VNET_DECLARE(int, ip6_log_interval); -VNET_DECLARE(time_t, ip6_log_time); VNET_DECLARE(int, ip6_hdrnestlimit); /* upper limit of # of extension * headers */ VNET_DECLARE(int, ip6_dad_count); /* DupAddrDetectionTransmits */ @@ -304,8 +302,6 @@ VNET_DECLARE(int, ip6_dad_count); /* DupAddrDetectionTransmits */ #define V_ip6_no_radr VNET(ip6_no_radr) #define V_ip6_norbit_raif VNET(ip6_norbit_raif) #define V_ip6_rfc6204w3 VNET(ip6_rfc6204w3) -#define V_ip6_log_interval VNET(ip6_log_interval) -#define V_ip6_log_time VNET(ip6_log_time) #define V_ip6_hdrnestlimit VNET(ip6_hdrnestlimit) #define V_ip6_dad_count VNET(ip6_dad_count) @@ -415,6 +411,8 @@ u_int32_t ip6_randomid(void); u_int32_t ip6_randomflowlabel(void); void in6_delayed_cksum(struct mbuf *m, uint32_t plen, u_short offset); +int ip6_log_ratelimit(void); + /* * Argument type for the last arg of ip6proto_ctlinput_t(). *