Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Dec 2022 14:51:55 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 57cc96f49e1f - main - pf: Fix definitions of pf_pfil_*_hooked
Message-ID:  <202212141451.2BEEptcH018877@gitrepo.freebsd.org>

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

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

commit 57cc96f49e1fd49602f12f6b58bddb5112d4e0bc
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-12-14 14:29:59 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-12-14 14:29:59 +0000

    pf: Fix definitions of pf_pfil_*_hooked
    
    This use of "volatile" in the vnet definitions doesn't have any effect.
    VNET_DEFINE_STATE(volatile int, ...) should work, but let's avoid using
    "volatile" altogether and convert to atomic_load/atomic_store.  Also
    convert to bool while here.
    
    Reviewed by:    kp, mjg
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D37684
---
 sys/netpfil/pf/pf_ioctl.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c
index 5f702f08929e..ae53e40d66b6 100644
--- a/sys/netpfil/pf/pf_ioctl.c
+++ b/sys/netpfil/pf/pf_ioctl.c
@@ -260,9 +260,9 @@ static struct cdevsw pf_cdevsw = {
 	.d_version =	D_VERSION,
 };
 
-volatile VNET_DEFINE_STATIC(int, pf_pfil_hooked);
+VNET_DEFINE_STATIC(bool, pf_pfil_hooked);
 #define V_pf_pfil_hooked	VNET(pf_pfil_hooked)
-volatile VNET_DEFINE_STATIC(int, pf_pfil_eth_hooked);
+VNET_DEFINE_STATIC(bool, pf_pfil_eth_hooked);
 #define V_pf_pfil_eth_hooked	VNET(pf_pfil_eth_hooked)
 
 /*
@@ -383,8 +383,8 @@ pfattach_vnet(void)
 	bzero(&V_pf_status, sizeof(V_pf_status));
 	V_pf_status.debug = PF_DEBUG_URGENT;
 
-	V_pf_pfil_hooked = 0;
-	V_pf_pfil_eth_hooked = 0;
+	V_pf_pfil_hooked = false;
+	V_pf_pfil_eth_hooked = false;
 
 	/* XXX do our best to avoid a conflict */
 	V_pf_status.hostid = arc4random();
@@ -6534,7 +6534,7 @@ hook_pf_eth(void)
 	struct pfil_link_args pla;
 	int ret __diagused;
 
-	if (V_pf_pfil_eth_hooked)
+	if (atomic_load_bool(&V_pf_pfil_eth_hooked))
 		return;
 
 	pha.pa_version = PFIL_VERSION;
@@ -6563,7 +6563,7 @@ hook_pf_eth(void)
 	ret = pfil_link(&pla);
 	MPASS(ret == 0);
 
-	V_pf_pfil_eth_hooked = 1;
+	atomic_store_bool(&V_pf_pfil_eth_hooked, true);
 }
 
 static void
@@ -6573,7 +6573,7 @@ hook_pf(void)
 	struct pfil_link_args pla;
 	int ret __diagused;
 
-	if (V_pf_pfil_hooked)
+	if (atomic_load_bool(&V_pf_pfil_hooked))
 		return;
 
 	pha.pa_version = PFIL_VERSION;
@@ -6625,27 +6625,27 @@ hook_pf(void)
 	MPASS(ret == 0);
 #endif
 
-	V_pf_pfil_hooked = 1;
+	atomic_store_bool(&V_pf_pfil_hooked, true);
 }
 
 static void
 dehook_pf_eth(void)
 {
 
-	if (V_pf_pfil_eth_hooked == 0)
+	if (!atomic_load_bool(&V_pf_pfil_eth_hooked))
 		return;
 
 	pfil_remove_hook(V_pf_eth_in_hook);
 	pfil_remove_hook(V_pf_eth_out_hook);
 
-	V_pf_pfil_eth_hooked = 0;
+	atomic_store_bool(&V_pf_pfil_eth_hooked, false);
 }
 
 static void
 dehook_pf(void)
 {
 
-	if (V_pf_pfil_hooked == 0)
+	if (!atomic_load_bool(&V_pf_pfil_hooked))
 		return;
 
 #ifdef INET
@@ -6657,7 +6657,7 @@ dehook_pf(void)
 	pfil_remove_hook(V_pf_ip6_out_hook);
 #endif
 
-	V_pf_pfil_hooked = 0;
+	atomic_store_bool(&V_pf_pfil_hooked, false);
 }
 
 static void



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