git: 0736a38072b5 - main - frag6: Reduce code duplication

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Sun, 31 Dec 2023 16:24:22 UTC
The branch main has been updated by markj:

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

commit 0736a38072b52204289c669770a34d0b801a8a7e
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2023-12-31 16:15:48 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-12-31 16:15:48 +0000

    frag6: Reduce code duplication
    
    The code which removes a fragment queue from the per-VNET hash table was
    duplicated three times.  Factor it out into a function.  No functional
    change intended.
    
    Reviewed by:    kp, bz
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D43228
---
 sys/netinet6/frag6.c | 44 +++++++++++++++++++-------------------------
 1 file changed, 19 insertions(+), 25 deletions(-)

diff --git a/sys/netinet6/frag6.c b/sys/netinet6/frag6.c
index a3a6e7eca14a..fbdbc3ef2f28 100644
--- a/sys/netinet6/frag6.c
+++ b/sys/netinet6/frag6.c
@@ -288,6 +288,20 @@ ip6_deletefraghdr(struct mbuf *m, int offset, int wait __unused)
 	return (0);
 }
 
+static void
+frag6_rmqueue(struct ip6q *q6, uint32_t bucket)
+{
+	IP6QB_LOCK_ASSERT(bucket);
+
+	TAILQ_REMOVE(IP6QB_HEAD(bucket), q6, ip6q_tq);
+	V_ip6qb[bucket].count--;
+#ifdef MAC
+	mac_ip6q_destroy(q6);
+#endif
+	free(q6, M_FRAG6);
+	atomic_subtract_int(&V_frag6_nfragpackets, 1);
+}
+
 /*
  * Free a fragment reassembly header and all associated datagrams.
  */
@@ -324,14 +338,8 @@ frag6_freef(struct ip6q *q6, uint32_t bucket)
 		free(af6, M_FRAG6);
 	}
 
-	TAILQ_REMOVE(IP6QB_HEAD(bucket), q6, ip6q_tq);
-	V_ip6qb[bucket].count--;
 	atomic_subtract_int(&frag6_nfrags, q6->ip6q_nfrag);
-#ifdef MAC
-	mac_ip6q_destroy(q6);
-#endif
-	free(q6, M_FRAG6);
-	atomic_subtract_int(&V_frag6_nfragpackets, 1);
+	frag6_rmqueue(q6, bucket);
 }
 
 /*
@@ -637,15 +645,8 @@ frag6_input(struct mbuf **mp, int *offp, int proto)
 	if (q6->ip6q_unfrglen >= 0) {
 		/* The 1st fragment has already arrived. */
 		if (q6->ip6q_unfrglen + fragoff + frgpartlen > IPV6_MAXPACKET) {
-			if (only_frag) {
-				TAILQ_REMOVE(head, q6, ip6q_tq);
-				V_ip6qb[bucket].count--;
-				atomic_subtract_int(&V_frag6_nfragpackets, 1);
-#ifdef MAC
-				mac_ip6q_destroy(q6);
-#endif
-				free(q6, M_FRAG6);
-			}
+			if (only_frag)
+				frag6_rmqueue(q6, bucket);
 			IP6QB_UNLOCK(bucket);
 			icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER,
 			    offset - sizeof(struct ip6_frag) +
@@ -654,15 +655,8 @@ frag6_input(struct mbuf **mp, int *offp, int proto)
 			return (IPPROTO_DONE);
 		}
 	} else if (fragoff + frgpartlen > IPV6_MAXPACKET) {
-		if (only_frag) {
-			TAILQ_REMOVE(head, q6, ip6q_tq);
-			V_ip6qb[bucket].count--;
-			atomic_subtract_int(&V_frag6_nfragpackets, 1);
-#ifdef MAC
-			mac_ip6q_destroy(q6);
-#endif
-			free(q6, M_FRAG6);
-		}
+		if (only_frag)
+			frag6_rmqueue(q6, bucket);
 		IP6QB_UNLOCK(bucket);
 		icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER,
 		    offset - sizeof(struct ip6_frag) +