Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Oct 2021 13:33:50 GMT
From:      Kristof Provost <kp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: a90b5b1104db - stable/12 - pf: Introduce pf_nvbool()
Message-ID:  <202110201333.19KDXoef070198@gitrepo.freebsd.org>

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

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

commit a90b5b1104db4d50a5fb65861c6cc627c0a38dfe
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2021-10-13 09:00:46 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2021-10-20 07:53:23 +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);



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