From nobody Thu Aug 31 08:56:45 2023 X-Original-To: dev-commits-src-main@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 4Rbw593vpTz4rwXT; Thu, 31 Aug 2023 08:56:45 +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 4Rbw593NSBz4Z8X; Thu, 31 Aug 2023 08:56:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1693472205; 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=vh1v8JV3MGEs6IzaUXrqzLh8EdySI5Ld2sCNXUIBmKk=; b=qMwQjhF6cB4t12cAgPPakPS8HWObgmdx3gDDRtogREZZZDyeGsTKZ9FeK19D7//qGXw+hy 2XInSFDB1OCH3vuuxyNe1jf9G2ePgSX6ZIj3l6+BmtSaPUz4Nck+TWb0ZyYhhxh8neV/SG kHfBcDVbsWsbQQuRNIFLhCqbtSK54I6juOXkik5+rOpU3k1/piB3ei4rHDV25zOtNsqkFC 5AkXQcMaEOYpi1l0oPXKPaIVGXtcZyrTuFWHCC9Vkdrh/f+0YpOgDHLsUWr+ka2XnKKNpT y+Ro0TAZyejWHsbc3vPyVnfNTzSIfkiknbdquLrx3bSQLF80WaPsHeKvIYH/4w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1693472205; a=rsa-sha256; cv=none; b=qrCcxICmVbl2D5IosLApIH557mufhn4X8JzYZvH75CEQAuqj45ZSBMtVe+Tzv4chSdWZfz pkSoiyGqevnJWCvN9BaFgisJ3QaC6OyUcJYd9TJt5tV0IaLtZyTxLBKw5bgtX+8OWel/nJ uZDL8vGndyUZ7iQ4ObpGBDjXieuPR+6J+eP2NIlDC0Yoj2rngq/dsBcwTGYEC4/U4P9dSC ncAtQx2IIrnItylN2K2oVfv4Yqd+z7HP3hlgxuVW0KB5Im/CCU4SjOZQEFRwH/I3GbaDLi w0K7AO+YCw2jxupwTjaKFIauXmGDD65lv+tOfy9Kjw4JrDzDwqhDG3ALO9+2dg== 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=1693472205; 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=vh1v8JV3MGEs6IzaUXrqzLh8EdySI5Ld2sCNXUIBmKk=; b=KxyX1GDAGUGYrMNb29qBDGr/OL7HXzuetEGgHcIjVrR4CLlSBxAqZgjiMqZf1b0M9WWr16 AKJe6ZmaUnhfFJnOIWzoQvnLXs21vAdWOnos/0HawOre9CTntyRa6T8PgX26V+MvtSqisL BAyb2NCKtXf8qKL+8AahYFYiwgviYnRSiSceMVhKALJHzFI+eFulRPca3TOzYkcA0sKg0Y Jsn1N2/+ujF/7LFkj5JLKmTb/Ps8vCv1k4+0gGUMvyyDaDIAtzabkwjNiSoTEpWybHJiKw r0oHPJ0ZRGdbv4eynj+YQGgqEcjPr/A1EnUtCHRcXXXCHQ4cM0WVFFywdupmsA== 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 4Rbw592MJgz1B4J; Thu, 31 Aug 2023 08:56:45 +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 37V8ujgW083292; Thu, 31 Aug 2023 08:56:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37V8ujFh083289; Thu, 31 Aug 2023 08:56:45 GMT (envelope-from git) Date: Thu, 31 Aug 2023 08:56:45 GMT Message-Id: <202308310856.37V8ujFh083289@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 6fbb9fbf7d65 - main - snmp_pf: use libpfctl's pfctl_get_status() rather than DIOCGETSTATUS List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 6fbb9fbf7d659574512d706912e8fd0576b13573 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=6fbb9fbf7d659574512d706912e8fd0576b13573 commit 6fbb9fbf7d659574512d706912e8fd0576b13573 Author: Kristof Provost AuthorDate: 2023-08-29 15:16:19 +0000 Commit: Kristof Provost CommitDate: 2023-08-31 08:56:32 +0000 snmp_pf: use libpfctl's pfctl_get_status() rather than DIOCGETSTATUS Prefer libpfctl functions over direct access to the ioctl whenever possible. This will allow subsequent removal of DIOCGETSTATUS (in 15) as there already is an nvlist-based alternative. MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D41650 --- usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c | 74 ++++++++++++++++--------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c b/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c index 134c05171749..a5786007d3f4 100644 --- a/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c +++ b/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c @@ -54,7 +54,7 @@ static int dev = -1; static int started; static uint64_t pf_tick; -static struct pf_status pfs; +static struct pfctl_status *pfs; enum { IN, OUT }; enum { IPV4, IPV6 }; @@ -166,18 +166,18 @@ pf_status(struct snmp_context __unused *ctx, struct snmp_value *val, switch (which) { case LEAF_pfStatusRunning: - val->v.uint32 = pfs.running; + val->v.uint32 = pfs->running; break; case LEAF_pfStatusRuntime: - runtime = (pfs.since > 0) ? - time(NULL) - pfs.since : 0; + runtime = (pfs->since > 0) ? + time(NULL) - pfs->since : 0; val->v.uint32 = runtime * 100; break; case LEAF_pfStatusDebug: - val->v.uint32 = pfs.debug; + val->v.uint32 = pfs->debug; break; case LEAF_pfStatusHostId: - sprintf(str, "0x%08x", ntohl(pfs.hostid)); + sprintf(str, "0x%08x", ntohl(pfs->hostid)); return (string_get(val, str, strlen(str))); default: @@ -205,22 +205,22 @@ pf_counter(struct snmp_context __unused *ctx, struct snmp_value *val, switch (which) { case LEAF_pfCounterMatch: - val->v.counter64 = pfs.counters[PFRES_MATCH]; + val->v.counter64 = pfctl_status_counter(pfs, PFRES_MATCH); break; case LEAF_pfCounterBadOffset: - val->v.counter64 = pfs.counters[PFRES_BADOFF]; + val->v.counter64 = pfctl_status_counter(pfs, PFRES_BADOFF); break; case LEAF_pfCounterFragment: - val->v.counter64 = pfs.counters[PFRES_FRAG]; + val->v.counter64 = pfctl_status_counter(pfs, PFRES_FRAG); break; case LEAF_pfCounterShort: - val->v.counter64 = pfs.counters[PFRES_SHORT]; + val->v.counter64 = pfctl_status_counter(pfs, PFRES_SHORT); break; case LEAF_pfCounterNormalize: - val->v.counter64 = pfs.counters[PFRES_NORM]; + val->v.counter64 = pfctl_status_counter(pfs, PFRES_NORM); break; case LEAF_pfCounterMemDrop: - val->v.counter64 = pfs.counters[PFRES_MEMORY]; + val->v.counter64 = pfctl_status_counter(pfs, PFRES_MEMORY); break; default: @@ -248,19 +248,19 @@ pf_statetable(struct snmp_context __unused *ctx, struct snmp_value *val, switch (which) { case LEAF_pfStateTableCount: - val->v.uint32 = pfs.states; + val->v.uint32 = pfs->states; break; case LEAF_pfStateTableSearches: val->v.counter64 = - pfs.fcounters[FCNT_STATE_SEARCH]; + pfctl_status_fcounter(pfs, FCNT_STATE_SEARCH); break; case LEAF_pfStateTableInserts: val->v.counter64 = - pfs.fcounters[FCNT_STATE_INSERT]; + pfctl_status_fcounter(pfs, FCNT_STATE_INSERT); break; case LEAF_pfStateTableRemovals: val->v.counter64 = - pfs.fcounters[FCNT_STATE_REMOVALS]; + pfctl_status_fcounter(pfs, FCNT_STATE_REMOVALS); break; default: @@ -288,19 +288,19 @@ pf_srcnodes(struct snmp_context __unused *ctx, struct snmp_value *val, switch (which) { case LEAF_pfSrcNodesCount: - val->v.uint32 = pfs.src_nodes; + val->v.uint32 = pfs->src_nodes; break; case LEAF_pfSrcNodesSearches: val->v.counter64 = - pfs.scounters[SCNT_SRC_NODE_SEARCH]; + pfctl_status_scounter(pfs, SCNT_SRC_NODE_SEARCH); break; case LEAF_pfSrcNodesInserts: val->v.counter64 = - pfs.scounters[SCNT_SRC_NODE_INSERT]; + pfctl_status_scounter(pfs, SCNT_SRC_NODE_INSERT); break; case LEAF_pfSrcNodesRemovals: val->v.counter64 = - pfs.scounters[SCNT_SRC_NODE_REMOVALS]; + pfctl_status_scounter(pfs, SCNT_SRC_NODE_REMOVALS); break; default: @@ -461,51 +461,51 @@ pf_logif(struct snmp_context __unused *ctx, struct snmp_value *val, switch (which) { case LEAF_pfLogInterfaceName: - strlcpy(str, pfs.ifname, sizeof str); + strlcpy(str, pfs->ifname, sizeof str); return (string_get(val, str, strlen(str))); case LEAF_pfLogInterfaceIp4BytesIn: - val->v.counter64 = pfs.bcounters[IPV4][IN]; + val->v.counter64 = pfs->bcounters[IPV4][IN]; break; case LEAF_pfLogInterfaceIp4BytesOut: - val->v.counter64 = pfs.bcounters[IPV4][OUT]; + val->v.counter64 = pfs->bcounters[IPV4][OUT]; break; case LEAF_pfLogInterfaceIp4PktsInPass: val->v.counter64 = - pfs.pcounters[IPV4][IN][PF_PASS]; + pfs->pcounters[IPV4][IN][PF_PASS]; break; case LEAF_pfLogInterfaceIp4PktsInDrop: val->v.counter64 = - pfs.pcounters[IPV4][IN][PF_DROP]; + pfs->pcounters[IPV4][IN][PF_DROP]; break; case LEAF_pfLogInterfaceIp4PktsOutPass: val->v.counter64 = - pfs.pcounters[IPV4][OUT][PF_PASS]; + pfs->pcounters[IPV4][OUT][PF_PASS]; break; case LEAF_pfLogInterfaceIp4PktsOutDrop: val->v.counter64 = - pfs.pcounters[IPV4][OUT][PF_DROP]; + pfs->pcounters[IPV4][OUT][PF_DROP]; break; case LEAF_pfLogInterfaceIp6BytesIn: - val->v.counter64 = pfs.bcounters[IPV6][IN]; + val->v.counter64 = pfs->bcounters[IPV6][IN]; break; case LEAF_pfLogInterfaceIp6BytesOut: - val->v.counter64 = pfs.bcounters[IPV6][OUT]; + val->v.counter64 = pfs->bcounters[IPV6][OUT]; break; case LEAF_pfLogInterfaceIp6PktsInPass: val->v.counter64 = - pfs.pcounters[IPV6][IN][PF_PASS]; + pfs->pcounters[IPV6][IN][PF_PASS]; break; case LEAF_pfLogInterfaceIp6PktsInDrop: val->v.counter64 = - pfs.pcounters[IPV6][IN][PF_DROP]; + pfs->pcounters[IPV6][IN][PF_DROP]; break; case LEAF_pfLogInterfaceIp6PktsOutPass: val->v.counter64 = - pfs.pcounters[IPV6][OUT][PF_PASS]; + pfs->pcounters[IPV6][OUT][PF_PASS]; break; case LEAF_pfLogInterfaceIp6PktsOutDrop: val->v.counter64 = - pfs.pcounters[IPV6][OUT][PF_DROP]; + pfs->pcounters[IPV6][OUT][PF_DROP]; break; default: @@ -1286,9 +1286,10 @@ pfs_refresh(void) if (started && this_tick <= pf_tick) return (0); - bzero(&pfs, sizeof(struct pf_status)); + pfctl_free_status(pfs); + pfs = pfctl_get_status(dev); - if (ioctl(dev, DIOCGETSTATUS, &pfs)) { + if (pfs == NULL) { syslog(LOG_ERR, "pfs_refresh(): ioctl(): %s", strerror(errno)); return (-1); @@ -1755,6 +1756,9 @@ pf_fini(void) l1 = l2; } + pfctl_free_status(pfs); + pfs = NULL; + close(dev); return (0); }