git: 8d261cd2d38f - stable/13 - pf: remove pd_refs from pfsync

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Thu, 30 Mar 2023 03:07:45 UTC
The branch stable/13 has been updated by kp:

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

commit 8d261cd2d38fb1cbf4ba5450fafa92f85f64eb82
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2023-03-24 06:04:56 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2023-03-30 00:23:30 +0000

    pf: remove pd_refs from pfsync
    
    It only served to complicate cleanup, and added no value.
    
    While here drop packets in pfsync_defer_tmo() if we don't have a syncif,
    rather than just leaving them on the queue.
    
    Reviewed by:    markj
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    Differential Revision:  https://reviews.freebsd.org/D39248
    
    (cherry picked from commit 27b23cdec9d1255e014ea0decac42a5be8d00735)
---
 sys/netpfil/pf/if_pfsync.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/sys/netpfil/pf/if_pfsync.c b/sys/netpfil/pf/if_pfsync.c
index a05fd85423ee..b05e1ae9550a 100644
--- a/sys/netpfil/pf/if_pfsync.c
+++ b/sys/netpfil/pf/if_pfsync.c
@@ -184,7 +184,6 @@ struct pfsync_upd_req_item {
 struct pfsync_deferral {
 	struct pfsync_softc		*pd_sc;
 	TAILQ_ENTRY(pfsync_deferral)	pd_entry;
-	u_int				pd_refs;
 	struct callout			pd_tmo;
 
 	struct pf_kstate		*pd_st;
@@ -414,10 +413,8 @@ pfsync_clone_destroy(struct ifnet *ifp)
 			if (ret > 0) {
 				pfsync_undefer(pd, 1);
 			} else {
-				pd->pd_refs++;
 				callout_drain(&pd->pd_tmo);
 			}
-			free(pd, M_PFSYNC);
 			PFSYNC_BUCKET_LOCK(b);
 		}
 		MPASS(b->b_deferred == 0);
@@ -1782,7 +1779,6 @@ pfsync_defer(struct pf_kstate *st, struct mbuf *m)
 	st->state_flags |= PFSTATE_ACK;
 
 	pd->pd_sc = sc;
-	pd->pd_refs = 0;
 	pd->pd_st = st;
 	pf_ref_state(st);
 	pd->pd_m = m;
@@ -1833,21 +1829,21 @@ pfsync_defer_tmo(void *arg)
 
 	PFSYNC_BUCKET_LOCK_ASSERT(b);
 
+	TAILQ_REMOVE(&b->b_deferrals, pd, pd_entry);
+	b->b_deferred--;
+	pd->pd_st->state_flags &= ~PFSTATE_ACK;	/* XXX: locking! */
+	PFSYNC_BUCKET_UNLOCK(b);
+	free(pd, M_PFSYNC);
+
 	if (sc->sc_sync_if == NULL) {
-		PFSYNC_BUCKET_UNLOCK(b);
+		pf_release_state(st);
+		m_freem(m);
 		return;
 	}
 
 	NET_EPOCH_ENTER(et);
 	CURVNET_SET(sc->sc_sync_if->if_vnet);
 
-	TAILQ_REMOVE(&b->b_deferrals, pd, pd_entry);
-	b->b_deferred--;
-	pd->pd_st->state_flags &= ~PFSTATE_ACK;	/* XXX: locking! */
-	if (pd->pd_refs == 0)
-		free(pd, M_PFSYNC);
-	PFSYNC_BUCKET_UNLOCK(b);
-
 	pfsync_tx(sc, m);
 
 	pf_release_state(st);