From nobody Thu Sep 07 19:25:01 2023 X-Original-To: dev-commits-src-branches@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 4RhThs3TjKz4sFvL; Thu, 7 Sep 2023 19:25:01 +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 4RhThs2VV4z3d8V; Thu, 7 Sep 2023 19:25:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694114701; 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=ZcCaXkAZSP4/SUJapUgnBczlevXzmi40tOOekKXv/dE=; b=OTQQoEh6SMke6ns4zKP9FBycaiKh/oFxHCJI3tz2GFQ5+I/yKIjYhe0Q4x6v6QGUI/PsQd f4xmuvUvbp/MNznoPAjxrmoBYCU8GNusgrRKgcKTul1SpmLu54PEVjmLYaT2oVZIt+Ri7c QFC7EJSS+3n4/4vq4QHn+D+Qg3QacC66qbNSVuAkrMbZZDIr0Fa1aPEEMkapMOR1BQneRI Vluhr05Qz9ihnm1SIxZ5tBtzZT/LzXmh2PLtkWiVZhGTMXRcPkPU+LSbK246u8gZ9iVqA0 Ys9U+Ubu+xhYOyZvoj04ieITNUNPuDqm8SvBbYVgI7w5M0/PXTfzu2Jg3bfdmg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694114701; a=rsa-sha256; cv=none; b=UjtgyG00WdnSTiOWjiVdnbUGdCkhvMsmNIQ0G2sJa2ax6jgjG2nlLq0+eJ+w7nnh/5/ml/ CIuC7RpfijSQWWYz0ckn91YtT4hvg4dv4IGGIC+cR4RNi6vimMOOSO3nXG5jC6FO0+bmdD ulWdL+kMelM7RwKqkVpDcYtCXtqGLv9Z67W4QbCb2797L3fHiWhyryleMQzgDdhubDT6/X 5aRd6oNeJZV0MXk4ptN21dc5KvBX56v11+csYFi79SnAqjZKd3EnoqhGxGG3SrFLpgnnk7 9lplMfqwucclQvX6/hyZLzl1dFlBWm0D2K+x6zatVfKLRSnth58uwE8L61F3aA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694114701; 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=ZcCaXkAZSP4/SUJapUgnBczlevXzmi40tOOekKXv/dE=; b=ZG2kGSZQPwIeZ3hXQDmQPzh4lCl7a8Sujfc46O26drdoYoVMZtlxJymdldLbMA6jXOxNpw Sy4PpORRFt0qMnBSFWv7OrzNM7LoAmdhjx3Nc+f1pWjYoR9fdiPOb/X/TVPCB+ZqRTFGgK Q380UA0byLZeN1Vz+RnI3fxpUf54AKjJ/xqJBxyU/ixhSgbVunLRnI88I6VUXI+2ZMxtoF 3/jGjbCSKFmnRSwdYOAuBrZwfaOt2Zv8nW/3UrzbvNe7Fly07Llf4bd9napdnMvBcKxo0d U1JzWOMgBbcY2NojIhlQHv7o4QixFo7j87xLs/RgJnI3yIpN10taCcXrLw+WHw== 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 4RhThs1RWHz1BYV; Thu, 7 Sep 2023 19:25:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 387JP11s064678; Thu, 7 Sep 2023 19:25:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 387JP1Fo064675; Thu, 7 Sep 2023 19:25:01 GMT (envelope-from git) Date: Thu, 7 Sep 2023 19:25:01 GMT Message-Id: <202309071925.387JP1Fo064675@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: 3155f562c5b1 - stable/13 - libpfctl: implement status counter accessor functions List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3155f562c5b1940a6921d513be724cad4545bdf6 Auto-Submitted: auto-generated The branch stable/13 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=3155f562c5b1940a6921d513be724cad4545bdf6 commit 3155f562c5b1940a6921d513be724cad4545bdf6 Author: Kristof Provost AuthorDate: 2023-08-29 15:04:17 +0000 Commit: Kristof Provost 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,