git: 9a9535e4df50 - stable/14 - libpfctl: implement status counter accessor functions
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 09 Sep 2023 11:51:17 UTC
The branch stable/14 has been updated by kp:
URL: https://cgit.FreeBSD.org/src/commit/?id=9a9535e4df507957fc173208e7c1fd0080bd7a73
commit 9a9535e4df507957fc173208e7c1fd0080bd7a73
Author: Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2023-08-29 15:04:17 +0000
Commit: Kristof Provost <kp@FreeBSD.org>
CommitDate: 2023-09-09 09:05:50 +0000
libpfctl: implement status counter accessor functions
The new nvlist-based status call allows us to easily add new counters.
However, the libpfctl interface defines a TAILQ, so it's not quite
trivial to find the counter consumers are interested in.
Provide convenience functions to access the counters.
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D41649
(cherry picked from commit e3d3d61a7d94a4155ef70048a8b578985fca8383)
---
lib/libpfctl/libpfctl.c | 31 +++++++++++++++++++++++++++++++
lib/libpfctl/libpfctl.h | 3 +++
2 files changed, 34 insertions(+)
diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c
index 7d79d0abb970..1eccf3dfbcdf 100644
--- a/lib/libpfctl/libpfctl.c
+++ b/lib/libpfctl/libpfctl.c
@@ -252,6 +252,37 @@ pfctl_get_status(int dev)
return (status);
}
+static uint64_t
+_pfctl_status_counter(struct pfctl_status_counters *counters, uint64_t id)
+{
+ struct pfctl_status_counter *c;
+
+ TAILQ_FOREACH(c, counters, entry) {
+ if (c->id == id)
+ return (c->counter);
+ }
+
+ return (0);
+}
+
+uint64_t
+pfctl_status_counter(struct pfctl_status *status, int id)
+{
+ return (_pfctl_status_counter(&status->counters, id));
+}
+
+uint64_t
+pfctl_status_fcounter(struct pfctl_status *status, int id)
+{
+ return (_pfctl_status_counter(&status->fcounters, id));
+}
+
+uint64_t
+pfctl_status_scounter(struct pfctl_status *status, int id)
+{
+ return (_pfctl_status_counter(&status->scounters, id));
+}
+
void
pfctl_free_status(struct pfctl_status *status)
{
diff --git a/lib/libpfctl/libpfctl.h b/lib/libpfctl/libpfctl.h
index 35c662816f3b..2559fc9c4843 100644
--- a/lib/libpfctl/libpfctl.h
+++ b/lib/libpfctl/libpfctl.h
@@ -385,6 +385,9 @@ struct pfctl_syncookies {
};
struct pfctl_status* pfctl_get_status(int dev);
+uint64_t pfctl_status_counter(struct pfctl_status *status, int id);
+uint64_t pfctl_status_fcounter(struct pfctl_status *status, int id);
+uint64_t pfctl_status_scounter(struct pfctl_status *status, int id);
void pfctl_free_status(struct pfctl_status *status);
int pfctl_get_eth_rulesets_info(int dev,