Date: Wed, 29 Apr 2026 16:19:34 +0000 From: Gleb Smirnoff <glebius@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 9b8eb70ca974 - main - inpcb: improve some internal function names Message-ID: <69f22f96.1ed18.4502c77b@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=9b8eb70ca974c2c700f228adaceb9a6b9e918d00 commit 9b8eb70ca974c2c700f228adaceb9a6b9e918d00 Author: Gleb Smirnoff <glebius@FreeBSD.org> AuthorDate: 2026-04-29 16:19:03 +0000 Commit: Gleb Smirnoff <glebius@FreeBSD.org> CommitDate: 2026-04-29 16:19:03 +0000 inpcb: improve some internal function names The 'hash' subword doesn't bring any additional information. All inpcb lookup functions operate on hashes. For lookup functions that work on either exact hash or wild hash just perform s/hash_//. Rename in_pcblookup_hash() into in_pcblookup_with_lock(), emphasizing its difference to in_pcblookup_smr(). Rename in_pcblookup_hash_locked() to in_pcblookup_internal(), as it doesn't return a locked inpcb and is used only for internal purposes. Note that the IPv6 sibling of this function already lives by name in6_pcblookup_internal(). Some future changes will make such naming more justified. No functional change. Reviewed by: pouria, markj Differential Revision: https://reviews.freebsd.org/D56482 --- sys/netinet/in_pcb.c | 53 ++++++++++++++++++++++++++------------------------ sys/netinet6/in6_pcb.c | 46 +++++++++++++++++++++---------------------- sys/netinet6/in6_pcb.h | 2 +- 3 files changed, 51 insertions(+), 50 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 3bb742f11c87..2e1a00209cb4 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -134,10 +134,9 @@ VNET_DEFINE(int, ipport_reservedlow); VNET_DEFINE(int, ipport_randomized) = 1; #ifdef INET -static struct inpcb *in_pcblookup_hash_locked(struct inpcbinfo *pcbinfo, - struct in_addr faddr, u_int fport_arg, - struct in_addr laddr, u_int lport_arg, - int lookupflags, uint8_t numa_domain, int fib); +static struct inpcb *in_pcblookup_internal(struct inpcbinfo *pcbinfo, + struct in_addr faddr, u_int fport_arg, struct in_addr laddr, + u_int lport_arg, int lookupflags, uint8_t numa_domain, int fib); #define RANGECHK(var, min, max) \ if ((var) < (min)) { (var) = (min); } \ @@ -809,14 +808,14 @@ in_pcb_lport_dest(const struct inpcb *inp, struct sockaddr *lsa, if (fsa != NULL) { #ifdef INET if (lsa->sa_family == AF_INET) { - tmpinp = in_pcblookup_hash_locked(pcbinfo, + tmpinp = in_pcblookup_internal(pcbinfo, faddr, fport, laddr, lport, lookupflags, M_NODOM, RT_ALL_FIBS); } #endif #ifdef INET6 if (lsa->sa_family == AF_INET6) { - tmpinp = in6_pcblookup_hash_locked(pcbinfo, + tmpinp = in6_pcblookup_internal(pcbinfo, faddr6, fport, laddr6, lport, lookupflags, M_NODOM, RT_ALL_FIBS); } @@ -1171,7 +1170,7 @@ in_pcbconnect(struct inpcb *inp, struct sockaddr_in *sin, struct ucred *cred) INP_HASH_WUNLOCK(inp->inp_pcbinfo); return (error); } - } else if (in_pcblookup_hash_locked(inp->inp_pcbinfo, faddr, + } else if (in_pcblookup_internal(inp->inp_pcbinfo, faddr, sin->sin_port, laddr, inp->inp_lport, 0, M_NODOM, RT_ALL_FIBS) != NULL) { INP_HASH_WUNLOCK(inp->inp_pcbinfo); @@ -2242,7 +2241,7 @@ in_pcblookup_exact_match(const struct inpcb *inp, struct in_addr faddr, } static struct inpcb * -in_pcblookup_hash_exact(struct inpcbinfo *pcbinfo, struct in_addr faddr, +in_pcblookup_exact(struct inpcbinfo *pcbinfo, struct in_addr faddr, u_short fport, struct in_addr laddr, u_short lport) { struct inpcbhead *head; @@ -2288,7 +2287,7 @@ in_pcblookup_wild_match(const struct inpcb *inp, struct in_addr laddr, #define INP_LOOKUP_AGAIN ((struct inpcb *)(uintptr_t)-1) static struct inpcb * -in_pcblookup_hash_wild_smr(struct inpcbinfo *pcbinfo, struct in_addr laddr, +in_pcblookup_wild_smr(struct inpcbinfo *pcbinfo, struct in_addr laddr, u_short lport, int fib, const inp_lookup_t lockflags) { struct inpcbhead *head; @@ -2325,7 +2324,7 @@ in_pcblookup_hash_wild_smr(struct inpcbinfo *pcbinfo, struct in_addr laddr, } static struct inpcb * -in_pcblookup_hash_wild_locked(struct inpcbinfo *pcbinfo, struct in_addr laddr, +in_pcblookup_wild_locked(struct inpcbinfo *pcbinfo, struct in_addr laddr, u_short lport, int fib) { struct inpcbhead *head; @@ -2404,7 +2403,7 @@ in_pcblookup_hash_wild_locked(struct inpcbinfo *pcbinfo, struct in_addr laddr, * out incoming packets. */ static struct inpcb * -in_pcblookup_hash_locked(struct inpcbinfo *pcbinfo, struct in_addr faddr, +in_pcblookup_internal(struct inpcbinfo *pcbinfo, struct in_addr faddr, u_int fport_arg, struct in_addr laddr, u_int lport_arg, int lookupflags, uint8_t numa_domain, int fib) { @@ -2419,7 +2418,7 @@ in_pcblookup_hash_locked(struct inpcbinfo *pcbinfo, struct in_addr faddr, ("%s: invalid local address", __func__)); INP_HASH_WLOCK_ASSERT(pcbinfo); - inp = in_pcblookup_hash_exact(pcbinfo, faddr, fport, laddr, lport); + inp = in_pcblookup_exact(pcbinfo, faddr, fport, laddr, lport); if (inp != NULL) return (inp); @@ -2427,7 +2426,7 @@ in_pcblookup_hash_locked(struct inpcbinfo *pcbinfo, struct in_addr faddr, inp = in_pcblookup_lbgroup(pcbinfo, &faddr, fport, &laddr, lport, numa_domain, fib); if (inp == NULL) { - inp = in_pcblookup_hash_wild_locked(pcbinfo, laddr, + inp = in_pcblookup_wild_locked(pcbinfo, laddr, lport, fib); } } @@ -2435,8 +2434,12 @@ in_pcblookup_hash_locked(struct inpcbinfo *pcbinfo, struct in_addr faddr, return (inp); } +/* + * Lookup inpcb using locks. Used by in_pcblookup_smr() in case inp_smr_lock() + * failed. + */ static struct inpcb * -in_pcblookup_hash(struct inpcbinfo *pcbinfo, struct in_addr faddr, +in_pcblookup_with_lock(struct inpcbinfo *pcbinfo, struct in_addr faddr, u_int fport, struct in_addr laddr, u_int lport, int lookupflags, uint8_t numa_domain, int fib) { @@ -2447,7 +2450,7 @@ in_pcblookup_hash(struct inpcbinfo *pcbinfo, struct in_addr faddr, ("%s: LOCKPCB not set", __func__)); INP_HASH_WLOCK(pcbinfo); - inp = in_pcblookup_hash_locked(pcbinfo, faddr, fport, laddr, lport, + inp = in_pcblookup_internal(pcbinfo, faddr, fport, laddr, lport, lookupflags & ~INPLOOKUP_LOCKMASK, numa_domain, fib); if (inp != NULL && !inp_trylock(inp, lockflags)) { in_pcbref(inp); @@ -2463,7 +2466,7 @@ in_pcblookup_hash(struct inpcbinfo *pcbinfo, struct in_addr faddr, } static struct inpcb * -in_pcblookup_hash_smr(struct inpcbinfo *pcbinfo, struct in_addr faddr, +in_pcblookup_smr(struct inpcbinfo *pcbinfo, struct in_addr faddr, u_int fport_arg, struct in_addr laddr, u_int lport_arg, int lookupflags, uint8_t numa_domain, int fib) { @@ -2477,7 +2480,7 @@ in_pcblookup_hash_smr(struct inpcbinfo *pcbinfo, struct in_addr faddr, ("%s: LOCKPCB not set", __func__)); smr_enter(pcbinfo->ipi_smr); - inp = in_pcblookup_hash_exact(pcbinfo, faddr, fport, laddr, lport); + inp = in_pcblookup_exact(pcbinfo, faddr, fport, laddr, lport); if (inp != NULL) { if (__predict_true(inp_smr_lock(inp, lockflags))) { /* @@ -2494,8 +2497,8 @@ in_pcblookup_hash_smr(struct inpcbinfo *pcbinfo, struct in_addr faddr, * We failed to lock the inpcb, or its connection state changed * out from under us. Fall back to a precise search. */ - return (in_pcblookup_hash(pcbinfo, faddr, fport, laddr, lport, - lookupflags, numa_domain, fib)); + return (in_pcblookup_with_lock(pcbinfo, faddr, fport, laddr, + lport, lookupflags, numa_domain, fib)); } if ((lookupflags & INPLOOKUP_WILDCARD) != 0) { @@ -2510,12 +2513,12 @@ in_pcblookup_hash_smr(struct inpcbinfo *pcbinfo, struct in_addr faddr, } inp = INP_LOOKUP_AGAIN; } else { - inp = in_pcblookup_hash_wild_smr(pcbinfo, laddr, lport, + inp = in_pcblookup_wild_smr(pcbinfo, laddr, lport, fib, lockflags); } if (inp == INP_LOOKUP_AGAIN) { - return (in_pcblookup_hash(pcbinfo, faddr, fport, laddr, - lport, lookupflags, numa_domain, fib)); + return (in_pcblookup_with_lock(pcbinfo, faddr, fport, + laddr, lport, lookupflags, numa_domain, fib)); } } @@ -2537,7 +2540,7 @@ in_pcblookup(struct inpcbinfo *pcbinfo, struct in_addr faddr, u_int fport, int fib; fib = (lookupflags & INPLOOKUP_FIB) ? if_getfib(ifp) : RT_ALL_FIBS; - return (in_pcblookup_hash_smr(pcbinfo, faddr, fport, laddr, lport, + return (in_pcblookup_smr(pcbinfo, faddr, fport, laddr, lport, lookupflags, M_NODOM, fib)); } @@ -2550,7 +2553,7 @@ in_pcblookup_mbuf(struct inpcbinfo *pcbinfo, struct in_addr faddr, M_ASSERTPKTHDR(m); fib = (lookupflags & INPLOOKUP_FIB) ? M_GETFIB(m) : RT_ALL_FIBS; - return (in_pcblookup_hash_smr(pcbinfo, faddr, fport, laddr, lport, + return (in_pcblookup_smr(pcbinfo, faddr, fport, laddr, lport, lookupflags, m->m_pkthdr.numa_domain, fib)); } #endif /* INET */ @@ -2563,7 +2566,7 @@ in_pcbjailed(const struct inpcb *inp, unsigned int flag) /* * Insert the PCB into a hash chain using ordering rules which ensure that - * in_pcblookup_hash_wild_*() always encounter the highest-ranking PCB first. + * in_pcblookup_wild_*() always encounter the highest-ranking PCB first. * * Specifically, keep jailed PCBs in front of non-jailed PCBs, and keep PCBs * with exact local addresses ahead of wildcard PCBs. Unbound v4-mapped v6 PCBs diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index bbb7414a206d..8132899bb0d9 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -485,8 +485,8 @@ in6_pcbconnect(struct inpcb *inp, struct sockaddr_in6 *sin6, struct ucred *cred, return (error); } - if (in6_pcblookup_hash_locked(pcbinfo, &sin6->sin6_addr, - sin6->sin6_port, IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr) ? + if (in6_pcblookup_internal(pcbinfo, &sin6->sin6_addr, sin6->sin6_port, + IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr) ? &laddr6.sin6_addr : &inp->in6p_laddr, inp->inp_lport, 0, M_NODOM, RT_ALL_FIBS) != NULL) { INP_HASH_WUNLOCK(pcbinfo); @@ -992,9 +992,8 @@ in6_pcblookup_exact_match(const struct inpcb *inp, const struct in6_addr *faddr, } static struct inpcb * -in6_pcblookup_hash_exact(struct inpcbinfo *pcbinfo, - const struct in6_addr *faddr, u_short fport, - const struct in6_addr *laddr, u_short lport) +in6_pcblookup_exact(struct inpcbinfo *pcbinfo, const struct in6_addr *faddr, + u_short fport, const struct in6_addr *laddr, u_short lport) { struct inpcbhead *head; struct inpcb *inp; @@ -1041,7 +1040,7 @@ in6_pcblookup_wild_match(const struct inpcb *inp, const struct in6_addr *laddr, #define INP_LOOKUP_AGAIN ((struct inpcb *)(uintptr_t)-1) static struct inpcb * -in6_pcblookup_hash_wild_smr(struct inpcbinfo *pcbinfo, +in6_pcblookup_wild_smr(struct inpcbinfo *pcbinfo, const struct in6_addr *laddr, u_short lport, int fib, const inp_lookup_t lockflags) { @@ -1080,7 +1079,7 @@ in6_pcblookup_hash_wild_smr(struct inpcbinfo *pcbinfo, } static struct inpcb * -in6_pcblookup_hash_wild_locked(struct inpcbinfo *pcbinfo, +in6_pcblookup_wild_locked(struct inpcbinfo *pcbinfo, const struct in6_addr *laddr, u_short lport, int fib) { struct inpcbhead *head; @@ -1139,9 +1138,8 @@ in6_pcblookup_hash_wild_locked(struct inpcbinfo *pcbinfo, } struct inpcb * -in6_pcblookup_hash_locked(struct inpcbinfo *pcbinfo, - const struct in6_addr *faddr, u_int fport_arg, - const struct in6_addr *laddr, u_int lport_arg, +in6_pcblookup_internal(struct inpcbinfo *pcbinfo, const struct in6_addr *faddr, + u_int fport_arg, const struct in6_addr *laddr, u_int lport_arg, int lookupflags, uint8_t numa_domain, int fib) { struct inpcb *inp; @@ -1155,7 +1153,7 @@ in6_pcblookup_hash_locked(struct inpcbinfo *pcbinfo, ("%s: invalid local address", __func__)); INP_HASH_LOCK_ASSERT(pcbinfo); - inp = in6_pcblookup_hash_exact(pcbinfo, faddr, fport, laddr, lport); + inp = in6_pcblookup_exact(pcbinfo, faddr, fport, laddr, lport); if (inp != NULL) return (inp); @@ -1163,15 +1161,15 @@ in6_pcblookup_hash_locked(struct inpcbinfo *pcbinfo, inp = in6_pcblookup_lbgroup(pcbinfo, faddr, fport, laddr, lport, numa_domain, fib); if (inp == NULL) { - inp = in6_pcblookup_hash_wild_locked(pcbinfo, - laddr, lport, fib); + inp = in6_pcblookup_wild_locked(pcbinfo, laddr, lport, + fib); } } return (inp); } static struct inpcb * -in6_pcblookup_hash(struct inpcbinfo *pcbinfo, const struct in6_addr *faddr, +in6_pcblookup_with_lock(struct inpcbinfo *pcbinfo, const struct in6_addr *faddr, u_int fport, const struct in6_addr *laddr, u_int lport, int lookupflags, uint8_t numa_domain, int fib) { @@ -1182,7 +1180,7 @@ in6_pcblookup_hash(struct inpcbinfo *pcbinfo, const struct in6_addr *faddr, ("%s: LOCKPCB not set", __func__)); INP_HASH_WLOCK(pcbinfo); - inp = in6_pcblookup_hash_locked(pcbinfo, faddr, fport, laddr, lport, + inp = in6_pcblookup_internal(pcbinfo, faddr, fport, laddr, lport, lookupflags & ~INPLOOKUP_LOCKMASK, numa_domain, fib); if (inp != NULL && !inp_trylock(inp, lockflags)) { in_pcbref(inp); @@ -1198,7 +1196,7 @@ in6_pcblookup_hash(struct inpcbinfo *pcbinfo, const struct in6_addr *faddr, } static struct inpcb * -in6_pcblookup_hash_smr(struct inpcbinfo *pcbinfo, const struct in6_addr *faddr, +in6_pcblookup_smr(struct inpcbinfo *pcbinfo, const struct in6_addr *faddr, u_int fport_arg, const struct in6_addr *laddr, u_int lport_arg, int lookupflags, uint8_t numa_domain, int fib) { @@ -1212,7 +1210,7 @@ in6_pcblookup_hash_smr(struct inpcbinfo *pcbinfo, const struct in6_addr *faddr, ("%s: LOCKPCB not set", __func__)); smr_enter(pcbinfo->ipi_smr); - inp = in6_pcblookup_hash_exact(pcbinfo, faddr, fport, laddr, lport); + inp = in6_pcblookup_exact(pcbinfo, faddr, fport, laddr, lport); if (inp != NULL) { if (__predict_true(inp_smr_lock(inp, lockflags))) { if (__predict_true(in6_pcblookup_exact_match(inp, @@ -1224,8 +1222,8 @@ in6_pcblookup_hash_smr(struct inpcbinfo *pcbinfo, const struct in6_addr *faddr, * We failed to lock the inpcb, or its connection state changed * out from under us. Fall back to a precise search. */ - return (in6_pcblookup_hash(pcbinfo, faddr, fport, laddr, lport, - lookupflags, numa_domain, fib)); + return (in6_pcblookup_with_lock(pcbinfo, faddr, fport, laddr, + lport, lookupflags, numa_domain, fib)); } if ((lookupflags & INPLOOKUP_WILDCARD) != 0) { @@ -1240,12 +1238,12 @@ in6_pcblookup_hash_smr(struct inpcbinfo *pcbinfo, const struct in6_addr *faddr, } inp = INP_LOOKUP_AGAIN; } else { - inp = in6_pcblookup_hash_wild_smr(pcbinfo, laddr, lport, + inp = in6_pcblookup_wild_smr(pcbinfo, laddr, lport, fib, lockflags); } if (inp == INP_LOOKUP_AGAIN) { - return (in6_pcblookup_hash(pcbinfo, faddr, fport, laddr, - lport, lookupflags, numa_domain, fib)); + return (in6_pcblookup_with_lock(pcbinfo, faddr, fport, + laddr, lport, lookupflags, numa_domain, fib)); } } @@ -1267,7 +1265,7 @@ in6_pcblookup(struct inpcbinfo *pcbinfo, const struct in6_addr *faddr, int fib; fib = (lookupflags & INPLOOKUP_FIB) ? if_getfib(ifp) : RT_ALL_FIBS; - return (in6_pcblookup_hash_smr(pcbinfo, faddr, fport, laddr, lport, + return (in6_pcblookup_smr(pcbinfo, faddr, fport, laddr, lport, lookupflags, M_NODOM, fib)); } @@ -1280,7 +1278,7 @@ in6_pcblookup_mbuf(struct inpcbinfo *pcbinfo, const struct in6_addr *faddr, M_ASSERTPKTHDR(m); fib = (lookupflags & INPLOOKUP_FIB) ? M_GETFIB(m) : RT_ALL_FIBS; - return (in6_pcblookup_hash_smr(pcbinfo, faddr, fport, laddr, lport, + return (in6_pcblookup_smr(pcbinfo, faddr, fport, laddr, lport, lookupflags, m->m_pkthdr.numa_domain, fib)); } diff --git a/sys/netinet6/in6_pcb.h b/sys/netinet6/in6_pcb.h index da29b1d2e065..aafc1cda8ca6 100644 --- a/sys/netinet6/in6_pcb.h +++ b/sys/netinet6/in6_pcb.h @@ -76,7 +76,7 @@ int in6_pcbconnect(struct inpcb *, struct sockaddr_in6 *, struct ucred *, void in6_pcbdisconnect(struct inpcb *); struct inpcb *in6_pcblookup_local(struct inpcbinfo *, const struct in6_addr *, u_short, int, int, struct ucred *); -struct inpcb *in6_pcblookup_hash_locked(struct inpcbinfo *pcbinfo, +struct inpcb *in6_pcblookup_internal(struct inpcbinfo *pcbinfo, const struct in6_addr *faddr, u_int fport_arg, const struct in6_addr *laddr, u_int lport_arg, int lookupflags, uint8_t numa_domain, int fib);home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69f22f96.1ed18.4502c77b>
