git: c57262716b08 - main - ipfilter: Add htable (hash table) tunable

From: Cy Schubert <cy_at_FreeBSD.org>
Date: Wed, 05 Nov 2025 15:34:00 UTC
The branch main has been updated by cy:

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

commit c57262716b08717b6a9c5533941d4e0a2d180d46
Author:     Cy Schubert <cy@FreeBSD.org>
AuthorDate: 2025-10-22 22:51:43 +0000
Commit:     Cy Schubert <cy@FreeBSD.org>
CommitDate: 2025-11-05 15:32:16 +0000

    ipfilter: Add htable (hash table) tunable
    
    This is in preparation for addition of a hash table max size.
    
    Reviewed by:            markj
    MFC after:              1 week
    Differential revision:  https://reviews.freebsd.org/D53283
---
 sys/netpfil/ipfilter/netinet/ip_htable.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/sys/netpfil/ipfilter/netinet/ip_htable.c b/sys/netpfil/ipfilter/netinet/ip_htable.c
index 3f765cfab947..9680017eb399 100644
--- a/sys/netpfil/ipfilter/netinet/ip_htable.c
+++ b/sys/netpfil/ipfilter/netinet/ip_htable.c
@@ -96,6 +96,7 @@ typedef struct ipf_htable_softc_s {
 	u_long		ipf_nhtnodes[LOOKUP_POOL_SZ];
 	iphtable_t	*ipf_htables[LOOKUP_POOL_SZ];
 	iphtent_t	*ipf_node_explist;
+	ipftuneable_t	*ipf_htable_tune;
 } ipf_htable_softc_t;
 
 ipf_lookup_t ipf_htable_backend = {
@@ -122,6 +123,14 @@ ipf_lookup_t ipf_htable_backend = {
 };
 
 
+static ipftuneable_t ipf_htable_tuneables[] = {
+	{ { NULL },
+		NULL,                   0,      0,
+		0,
+		0,      NULL, NULL }
+};
+
+
 /* ------------------------------------------------------------------------ */
 /* Function:    ipf_htable_soft_create                                      */
 /* Returns:     void *   - NULL = failure, else pointer to local context    */
@@ -142,6 +151,18 @@ ipf_htable_soft_create(ipf_main_softc_t *softc)
 
 	bzero((char *)softh, sizeof(*softh));
 
+	softh->ipf_htable_tune = ipf_tune_array_copy(softh,
+						sizeof(ipf_htable_tuneables),
+						ipf_htable_tuneables);
+	if (softh->ipf_htable_tune == NULL) {
+		ipf_htable_soft_destroy(softc, softh);
+		return (NULL);
+	}
+	if (ipf_tune_array_link(softc, softh->ipf_htable_tune) == -1) {
+		ipf_htable_soft_destroy(softc, softh);
+		return (NULL);
+	}
+
 	return (softh);
 }
 
@@ -160,6 +181,12 @@ ipf_htable_soft_destroy(ipf_main_softc_t *softc, void *arg)
 {
 	ipf_htable_softc_t *softh = arg;
 
+	if (softh->ipf_htable_tune != NULL) {
+		ipf_tune_array_unlink(softc, softh->ipf_htable_tune);
+		KFREES(softh->ipf_htable_tune, sizeof(ipf_htable_tuneables));
+		softh->ipf_htable_tune = NULL;
+	}
+
 	KFREE(softh);
 }