From nobody Wed Oct 20 13:33:52 2021 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 772851806BDC; Wed, 20 Oct 2021 13:33:52 +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 4HZBQm1nCnz4gc9; Wed, 20 Oct 2021 13:33:52 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 1C4833E3; Wed, 20 Oct 2021 13:33:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 19KDXqZB070302; Wed, 20 Oct 2021 13:33:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19KDXq8M070301; Wed, 20 Oct 2021 13:33:52 GMT (envelope-from git) Date: Wed, 20 Oct 2021 13:33:52 GMT Message-Id: <202110201333.19KDXq8M070301@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: fc391b7a56d9 - stable/13 - pf: Introduce pf_nvbool() 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: fc391b7a56d9b8eec3f1585397c8263923153442 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=fc391b7a56d9b8eec3f1585397c8263923153442 commit fc391b7a56d9b8eec3f1585397c8263923153442 Author: Kristof Provost AuthorDate: 2021-10-13 09:00:46 +0000 Commit: Kristof Provost CommitDate: 2021-10-20 07:51:34 +0000 pf: Introduce pf_nvbool() Similar to the existing functions for strings and ints, this lets us simplify some of the nvlist conversion code. MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 776df104fa54bb581e1fb88ac44af4fa7fd4052b) --- sys/netpfil/pf/pf_nv.c | 14 ++++++++++++-- sys/netpfil/pf/pf_nv.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/sys/netpfil/pf/pf_nv.c b/sys/netpfil/pf/pf_nv.c index d1eca90e0ee5..5eda6b3917f4 100644 --- a/sys/netpfil/pf/pf_nv.c +++ b/sys/netpfil/pf/pf_nv.c @@ -99,6 +99,17 @@ __FBSDID("$FreeBSD$"); } \ } +int +pf_nvbool(const nvlist_t *nvl, const char *name, bool *val) +{ + if (! nvlist_exists_bool(nvl, name)) + return (EINVAL); + + *val = nvlist_get_bool(nvl, name); + + return (0); +} + int pf_nvbinary(const nvlist_t *nvl, const char *name, void *data, size_t expected_size) @@ -840,8 +851,7 @@ pf_nvstate_kill_to_kstate_kill(const nvlist_t *nvl, sizeof(kill->psk_ifname))); PFNV_CHK(pf_nvstring(nvl, "label", kill->psk_label, sizeof(kill->psk_label))); - if (nvlist_exists_bool(nvl, "kill_match")) - kill->psk_kill_match = nvlist_get_bool(nvl, "kill_match"); + PFNV_CHK(pf_nvbool(nvl, "kill_match", &kill->psk_kill_match)); errout: return (error); diff --git a/sys/netpfil/pf/pf_nv.h b/sys/netpfil/pf/pf_nv.h index f1cdc52aad6b..7ac3bc4153ee 100644 --- a/sys/netpfil/pf/pf_nv.h +++ b/sys/netpfil/pf/pf_nv.h @@ -70,6 +70,7 @@ PF_NV_DEF_UINT(uint16, uint16_t, UINT16_MAX); PF_NV_DEF_UINT(uint32, uint32_t, UINT32_MAX); PF_NV_DEF_UINT(uint64, uint64_t, UINT64_MAX); +int pf_nvbool(const nvlist_t *, const char *, bool *); int pf_nvbinary(const nvlist_t *, const char *, void *, size_t); int pf_nvint(const nvlist_t *, const char *, int *); int pf_nvstring(const nvlist_t *, const char *, char *, size_t);