git: 3155f562c5b1 - stable/13 - libpfctl: implement status counter accessor functions
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 07 Sep 2023 19:25:01 UTC
The branch stable/13 has been updated by kp:
URL: https://cgit.FreeBSD.org/src/commit/?id=3155f562c5b1940a6921d513be724cad4545bdf6
commit 3155f562c5b1940a6921d513be724cad4545bdf6
Author: Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2023-08-29 15:04:17 +0000
Commit: Kristof Provost <kp@FreeBSD.org>
CommitDate: 2023-09-07 19:23:07 +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 3bfa0698e4b1..54e8fedbe4df 100644
--- a/lib/libpfctl/libpfctl.c
+++ b/lib/libpfctl/libpfctl.c
@@ -251,6 +251,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 bcf8644d112c..e500bbf0bddf 100644
--- a/lib/libpfctl/libpfctl.h
+++ b/lib/libpfctl/libpfctl.h
@@ -290,6 +290,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_rules_info(int dev, struct pfctl_rules_info *rules,