git: a9706d78bddf - main - pfctl: replace TAILQ concatenation loop with TAILQ_CONCAT

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Sat, 12 Jul 2025 13:38:53 UTC
The branch main has been updated by kp:

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

commit a9706d78bddf3e002d108d7ceb189cf40064fea2
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2025-07-07 07:16:56 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2025-07-12 09:57:51 +0000

    pfctl: replace TAILQ concatenation loop with TAILQ_CONCAT
    
    OK kn@, sashan@, florian@
    
    Obtained from:  OpenBSD, bket <bket@openbsd.org>, c8d5c2349e
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 sbin/pfctl/parse.y          | 14 +++-----------
 sbin/pfctl/pfctl_optimize.c | 17 +++--------------
 2 files changed, 6 insertions(+), 25 deletions(-)

diff --git a/sbin/pfctl/parse.y b/sbin/pfctl/parse.y
index 2188324c15cb..9a917d1d8464 100644
--- a/sbin/pfctl/parse.y
+++ b/sbin/pfctl/parse.y
@@ -7202,19 +7202,11 @@ mv_rules(struct pfctl_ruleset *src, struct pfctl_ruleset *dst)
 	struct pfctl_rule *r;
 
 	for (i = 0; i < PF_RULESET_MAX; ++i) {
-		while ((r = TAILQ_FIRST(src->rules[i].active.ptr))
-		    != NULL) {
-			TAILQ_REMOVE(src->rules[i].active.ptr, r, entries);
-			TAILQ_INSERT_TAIL(dst->rules[i].active.ptr, r, entries);
+		TAILQ_FOREACH(r, src->rules[i].active.ptr, entries)
 			dst->anchor->match++;
-		}
+		TAILQ_CONCAT(dst->rules[i].active.ptr, src->rules[i].active.ptr, entries);
 		src->anchor->match = 0;
-		while ((r = TAILQ_FIRST(src->rules[i].inactive.ptr))
-		    != NULL) {
-			TAILQ_REMOVE(src->rules[i].inactive.ptr, r, entries);
-			TAILQ_INSERT_TAIL(dst->rules[i].inactive.ptr,
-				r, entries);
-		}
+		TAILQ_CONCAT(dst->rules[i].inactive.ptr, src->rules[i].inactive.ptr, entries);
 	}
 }
 
diff --git a/sbin/pfctl/pfctl_optimize.c b/sbin/pfctl/pfctl_optimize.c
index d65503a3efb3..b82e88652f86 100644
--- a/sbin/pfctl/pfctl_optimize.c
+++ b/sbin/pfctl/pfctl_optimize.c
@@ -723,11 +723,7 @@ reorder_rules(struct pfctl *pf, struct superblock *block, int depth)
 	 * it based on a more optimal skipstep order.
 	 */
 	TAILQ_INIT(&head);
-	while ((por = TAILQ_FIRST(&block->sb_rules))) {
-		TAILQ_REMOVE(&block->sb_rules, por, por_entry);
-		TAILQ_INSERT_TAIL(&head, por, por_entry);
-	}
-
+	TAILQ_CONCAT(&head, &block->sb_rules, por_entry);
 
 	while (!TAILQ_EMPTY(&head)) {
 		largest = 1;
@@ -748,11 +744,7 @@ reorder_rules(struct pfctl *pf, struct superblock *block, int depth)
 			 * Nothing useful left.  Leave remaining rules in order.
 			 */
 			DEBUG("(%d) no more commonality for skip steps", depth);
-			while ((por = TAILQ_FIRST(&head))) {
-				TAILQ_REMOVE(&head, por, por_entry);
-				TAILQ_INSERT_TAIL(&block->sb_rules, por,
-				    por_entry);
-			}
+			TAILQ_CONCAT(&block->sb_rules, &head, por_entry);
 		} else {
 			/*
 			 * There is commonality.  Extract those common rules
@@ -863,10 +855,7 @@ block_feedback(struct pfctl *pf, struct superblock *block)
 	 */
 
 	TAILQ_INIT(&queue);
-	while ((por1 = TAILQ_FIRST(&block->sb_rules)) != NULL) {
-		TAILQ_REMOVE(&block->sb_rules, por1, por_entry);
-		TAILQ_INSERT_TAIL(&queue, por1, por_entry);
-	}
+	TAILQ_CONCAT(&queue, &block->sb_rules, por_entry);
 
 	while ((por1 = TAILQ_FIRST(&queue)) != NULL) {
 		TAILQ_REMOVE(&queue, por1, por_entry);