git: 37881f65eacd - main - pf: pf_clear_srcnodes() is always called with NULL

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Sat, 28 Sep 2024 19:23:35 UTC
The branch main has been updated by kp:

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

commit 37881f65eacd200b6aa31bcf75bdda089b83fbd5
Author:     Kajetan Staszkiewicz <vegeta@tuxpowered.net>
AuthorDate: 2024-09-28 16:59:13 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2024-09-28 19:23:14 +0000

    pf: pf_clear_srcnodes() is always called with NULL
    
    The functions pf_clear_srcnodes() is only used to perform a removal of
    all source nodes, never of a given one. Remove the code allowing for
    removal of a given source node.
    
    Reviewed by:    kp
    Differential Revision:  https://reviews.freebsd.org/D46819
---
 sys/netpfil/pf/pf_ioctl.c | 42 +++++++++++++++++-------------------------
 1 file changed, 17 insertions(+), 25 deletions(-)

diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c
index 0a573a017ef3..6e2fcd358b68 100644
--- a/sys/netpfil/pf/pf_ioctl.c
+++ b/sys/netpfil/pf/pf_ioctl.c
@@ -233,7 +233,7 @@ static int		 pf_clearstates_nv(struct pfioc_nv *);
 static int		 pf_getstate(struct pfioc_nv *);
 static int		 pf_getstatus(struct pfioc_nv *);
 static int		 pf_clear_tables(void);
-static void		 pf_clear_srcnodes(struct pf_ksrc_node *);
+static void		 pf_clear_srcnodes(void);
 static void		 pf_kill_srcnodes(struct pfioc_src_node_kill *);
 static int		 pf_keepcounters(struct pfioc_nv *);
 static void		 pf_tbladdr_copyout(struct pf_addr_wrap *);
@@ -5427,7 +5427,7 @@ DIOCCHANGEADDR_error:
 	}
 
 	case DIOCCLRSRCNODES: {
-		pf_clear_srcnodes(NULL);
+		pf_clear_srcnodes();
 		pf_purge_expired_src_nodes();
 		break;
 	}
@@ -5904,40 +5904,32 @@ pf_clear_tables(void)
 }
 
 static void
-pf_clear_srcnodes(struct pf_ksrc_node *n)
+pf_clear_srcnodes(void)
 {
-	struct pf_kstate *s;
-	int i;
+	struct pf_kstate	*s;
+	struct pf_srchash	*sh;
+	struct pf_ksrc_node	*sn;
+	int			 i;
 
 	for (i = 0; i <= V_pf_hashmask; i++) {
 		struct pf_idhash *ih = &V_pf_idhash[i];
 
 		PF_HASHROW_LOCK(ih);
 		LIST_FOREACH(s, &ih->states, entry) {
-			if (n == NULL || n == s->src_node)
-				s->src_node = NULL;
-			if (n == NULL || n == s->nat_src_node)
-				s->nat_src_node = NULL;
+			s->src_node = NULL;
+			s->nat_src_node = NULL;
 		}
 		PF_HASHROW_UNLOCK(ih);
 	}
 
-	if (n == NULL) {
-		struct pf_srchash *sh;
-
-		for (i = 0, sh = V_pf_srchash; i <= V_pf_srchashmask;
-		    i++, sh++) {
-			PF_HASHROW_LOCK(sh);
-			LIST_FOREACH(n, &sh->nodes, entry) {
-				n->expire = 1;
-				n->states = 0;
-			}
-			PF_HASHROW_UNLOCK(sh);
+	for (i = 0, sh = V_pf_srchash; i <= V_pf_srchashmask;
+	    i++, sh++) {
+		PF_HASHROW_LOCK(sh);
+		LIST_FOREACH(sn, &sh->nodes, entry) {
+			sn->expire = 1;
+			sn->states = 0;
 		}
-	} else {
-		/* XXX: hash slot should already be locked here. */
-		n->expire = 1;
-		n->states = 0;
+		PF_HASHROW_UNLOCK(sh);
 	}
 }
 
@@ -6406,7 +6398,7 @@ shutdown_pf(void)
 
 		pf_clear_all_states();
 
-		pf_clear_srcnodes(NULL);
+		pf_clear_srcnodes();
 
 		/* status does not use malloced mem so no need to cleanup */
 		/* fingerprints and interfaces have their own cleanup code */