Date: Thu, 11 Dec 2025 18:05:52 +0000 From: Mark Johnston <markj@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: e29fe1c251a1 - stable/15 - divert: Use CK_SLISTs for the divcb hash table Message-ID: <693b0800.21788.53469aa1@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/15 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=e29fe1c251a1a95ccb989779d0d7921666c038d4 commit e29fe1c251a1a95ccb989779d0d7921666c038d4 Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2025-12-03 13:43:04 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2025-12-11 17:59:09 +0000 divert: Use CK_SLISTs for the divcb hash table The hash table is accessed in ip_divert_packet(), and there the accesses are synchronized only by the net epoch, so plain SLIST is not safe. Reviewed by: ae MFC after: 1 week Sponsored by: OPNsense Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D54011 (cherry picked from commit 74f7e916211acafd10af05efd893ccbac1881119) --- sys/netinet/ip_divert.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index 5a561814cdb5..f98a599e7554 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -35,6 +35,7 @@ #include "opt_sctp.h" #include <sys/param.h> +#include <sys/ck.h> #include <sys/eventhandler.h> #include <sys/kernel.h> #include <sys/lock.h> @@ -137,7 +138,7 @@ static int div_output_outbound(int family, struct socket *so, struct mbuf *m); struct divcb { union { - SLIST_ENTRY(divcb) dcb_next; + CK_SLIST_ENTRY(divcb) dcb_next; intptr_t dcb_bound; #define DCB_UNBOUND ((intptr_t)-1) }; @@ -147,7 +148,7 @@ struct divcb { struct epoch_context dcb_epochctx; }; -SLIST_HEAD(divhashhead, divcb); +CK_SLIST_HEAD(divhashhead, divcb); VNET_DEFINE_STATIC(struct divhashhead, divhash[DIVHASHSIZE]) = {}; #define V_divhash VNET(divhash) @@ -273,7 +274,7 @@ divert_packet(struct mbuf *m, bool incoming) } /* Put packet on socket queue, if any */ - SLIST_FOREACH(dcb, &V_divhash[DIVHASH(nport)], dcb_next) + CK_SLIST_FOREACH(dcb, &V_divhash[DIVHASH(nport)], dcb_next) if (dcb->dcb_port == nport) break; @@ -601,7 +602,7 @@ div_detach(struct socket *so) so->so_pcb = NULL; DIVERT_LOCK(); if (dcb->dcb_bound != DCB_UNBOUND) - SLIST_REMOVE(&V_divhash[DCBHASH(dcb)], dcb, divcb, dcb_next); + CK_SLIST_REMOVE(&V_divhash[DCBHASH(dcb)], dcb, divcb, dcb_next); V_dcb_count--; V_dcb_gencnt++; DIVERT_UNLOCK(); @@ -620,16 +621,16 @@ div_bind(struct socket *so, struct sockaddr *nam, struct thread *td) return EINVAL; port = ((struct sockaddr_in *)nam)->sin_port; DIVERT_LOCK(); - SLIST_FOREACH(dcb, &V_divhash[DIVHASH(port)], dcb_next) + CK_SLIST_FOREACH(dcb, &V_divhash[DIVHASH(port)], dcb_next) if (dcb->dcb_port == port) { DIVERT_UNLOCK(); return (EADDRINUSE); } dcb = so->so_pcb; if (dcb->dcb_bound != DCB_UNBOUND) - SLIST_REMOVE(&V_divhash[DCBHASH(dcb)], dcb, divcb, dcb_next); + CK_SLIST_REMOVE(&V_divhash[DCBHASH(dcb)], dcb, divcb, dcb_next); dcb->dcb_port = port; - SLIST_INSERT_HEAD(&V_divhash[DIVHASH(port)], dcb, dcb_next); + CK_SLIST_INSERT_HEAD(&V_divhash[DIVHASH(port)], dcb, dcb_next); DIVERT_UNLOCK(); return (0); @@ -668,7 +669,7 @@ div_pcblist(SYSCTL_HANDLER_ARGS) DIVERT_LOCK(); for (int i = 0; i < DIVHASHSIZE; i++) - SLIST_FOREACH(dcb, &V_divhash[i], dcb_next) { + CK_SLIST_FOREACH(dcb, &V_divhash[i], dcb_next) { if (dcb->dcb_gencnt <= xig.xig_gen) { struct xinpcb xi;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?693b0800.21788.53469aa1>
