Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 18 Jul 2021 00:36:00 GMT
From:      "Bjoern A. Zeeb" <bz@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 834afdc9242d - stable/13 - LinuxKPI: add net_ratelimit()
Message-ID:  <202107180036.16I0a0SP048556@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=834afdc9242db433def9f5aad2a75dc2f558142c

commit 834afdc9242db433def9f5aad2a75dc2f558142c
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2021-03-23 17:00:22 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2021-07-18 00:34:59 +0000

    LinuxKPI: add net_ratelimit()
    
    Add a net_ratelimit() compat implementation based on ppsratecheck().
    Add a sysctl to allow tuning of the number of messages.
    
    Sponsored by:   The FreeBSD Foundation
    Reviewed by:    hselasky
    Differential Revision:  https://reviews.freebsd.org/D29399
    
    (cherry picked from commit bc042266b2bfc3f52f685df7ccdd6e857b4b9da9)
---
 sys/compat/linuxkpi/common/include/linux/net.h | 10 ++++++++++
 sys/compat/linuxkpi/common/src/linux_compat.c  | 15 +++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/net.h b/sys/compat/linuxkpi/common/include/linux/net.h
index 282a45d2db32..5365cd0e9552 100644
--- a/sys/compat/linuxkpi/common/include/linux/net.h
+++ b/sys/compat/linuxkpi/common/include/linux/net.h
@@ -76,4 +76,14 @@ sock_release(struct socket *so)
 	soclose(so);
 }
 
+
+int linuxkpi_net_ratelimit(void);
+
+static inline int
+net_ratelimit(void)
+{
+
+	return (linuxkpi_net_ratelimit());
+}
+
 #endif	/* _LINUX_NET_H_ */
diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c
index 4337f1f7bbd7..9dfa5446e0cc 100644
--- a/sys/compat/linuxkpi/common/src/linux_compat.c
+++ b/sys/compat/linuxkpi/common/src/linux_compat.c
@@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/rwlock.h>
 #include <sys/mman.h>
 #include <sys/stack.h>
+#include <sys/time.h>
 #include <sys/user.h>
 
 #include <vm/vm.h>
@@ -99,6 +100,12 @@ int linuxkpi_debug;
 SYSCTL_INT(_compat_linuxkpi, OID_AUTO, debug, CTLFLAG_RWTUN,
     &linuxkpi_debug, 0, "Set to enable pr_debug() prints. Clear to disable.");
 
+static struct timeval lkpi_net_lastlog;
+static int lkpi_net_curpps;
+static int lkpi_net_maxpps = 99;
+SYSCTL_INT(_compat_linuxkpi, OID_AUTO, net_ratelimit, CTLFLAG_RWTUN,
+    &lkpi_net_maxpps, 0, "Limit number of LinuxKPI net messages per second.");
+
 MALLOC_DEFINE(M_KMALLOC, "linux", "Linux kmalloc compat");
 
 #include <linux/rbtree.h>
@@ -2565,6 +2572,14 @@ linux_dump_stack(void)
 #endif
 }
 
+int
+linuxkpi_net_ratelimit(void)
+{
+
+	return (ppsratecheck(&lkpi_net_lastlog, &lkpi_net_curpps,
+	   lkpi_net_maxpps));
+}
+
 #if defined(__i386__) || defined(__amd64__)
 bool linux_cpu_has_clflush;
 #endif



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202107180036.16I0a0SP048556>