git: 3836400a785f - stable/13 - pfsync: fix incorrect enabling of defer mode

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Mon, 13 Dec 2021 13:50:38 UTC
The branch stable/13 has been updated by kp:

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

commit 3836400a785f070826b0eaa1e642d761192321bf
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2021-12-02 17:39:23 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2021-12-13 13:49:27 +0000

    pfsync: fix incorrect enabling of defer mode
    
    When we exposed the PFSYNCF_OK flag to userspace in 5f5bf88949d we
    unintentionally caused defer mode to always be enabled.
    The ioctl check only looked for nonzero, not for the PFSYNCF_DEFER flag.
    
    Fix this check and ensure ifconfig sets the flag.
    
    Reviewed by:    glebius
    MFC after:      1 week
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    Differential Revision:  https://reviews.freebsd.org/D33244
    
    (cherry picked from commit 73fd0eaf5930c5b8844ca122dd3068145ccef02c)
---
 sbin/ifconfig/ifpfsync.c   | 2 +-
 sys/netpfil/pf/if_pfsync.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/sbin/ifconfig/ifpfsync.c b/sbin/ifconfig/ifpfsync.c
index 60e3d4360aa3..e3b5e6a30bbc 100644
--- a/sbin/ifconfig/ifpfsync.c
+++ b/sbin/ifconfig/ifpfsync.c
@@ -178,7 +178,7 @@ setpfsync_defer(const char *val, int d, int s, const struct afswtch *rafp)
 	if (ioctl(s, SIOCGETPFSYNC, (caddr_t)&ifr) == -1)
 		err(1, "SIOCGETPFSYNC");
 
-	preq.pfsyncr_defer = d;
+	preq.pfsyncr_defer = d ? PFSYNCF_DEFER : 0;
 	if (ioctl(s, SIOCSETPFSYNC, (caddr_t)&ifr) == -1)
 		err(1, "SIOCSETPFSYNC");
 }
diff --git a/sys/netpfil/pf/if_pfsync.c b/sys/netpfil/pf/if_pfsync.c
index 455e1ad09e93..b4f25728d17b 100644
--- a/sys/netpfil/pf/if_pfsync.c
+++ b/sys/netpfil/pf/if_pfsync.c
@@ -1399,7 +1399,7 @@ pfsyncioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
 			    pfsyncr.pfsyncr_syncpeer.s_addr;
 
 		sc->sc_maxupdates = pfsyncr.pfsyncr_maxupdates;
-		if (pfsyncr.pfsyncr_defer) {
+		if (pfsyncr.pfsyncr_defer & PFSYNCF_DEFER) {
 			sc->sc_flags |= PFSYNCF_DEFER;
 			V_pfsync_defer_ptr = pfsync_defer;
 		} else {