Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 31 Aug 2023 08:56:44 GMT
From:      Kristof Provost <kp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: e3d3d61a7d94 - main - libpfctl: implement status counter accessor functions
Message-ID:  <202308310856.37V8uiVQ083239@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by kp:

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

commit e3d3d61a7d94a4155ef70048a8b578985fca8383
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2023-08-29 15:04:17 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2023-08-31 08:56:31 +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
---
 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,



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