Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F164928111
D56174.id174592.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D56174.id174592.diff
View Options
diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h
--- a/sys/netinet/in_pcb.h
+++ b/sys/netinet/in_pcb.h
@@ -470,19 +470,18 @@
struct inpcbhead *ipi_hash_exact; /* (r:e/w:h) */
struct inpcbhead *ipi_hash_wild; /* (r:e/w:h) */
u_long ipi_hashmask; /* (c) */
+ u_long ipi_porthashmask; /* (h) */
/*
* Global hash of inpcbs, hashed by only local port number.
*/
struct inpcbhead *ipi_porthashbase; /* (h) */
- u_long ipi_porthashmask; /* (h) */
/*
* Load balance groups used for the SO_REUSEPORT_LB option,
* hashed by local port.
*/
struct inpcblbgrouphead *ipi_lbgrouphashbase; /* (r:e/w:h) */
- u_long ipi_lbgrouphashmask; /* (h) */
/*
* Pointer to network stack instance
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c
--- a/sys/netinet/in_pcb.c
+++ b/sys/netinet/in_pcb.c
@@ -305,7 +305,7 @@
INP_HASH_LOCK_ASSERT(pcbinfo);
hdr = &pcbinfo->ipi_lbgrouphashbase[
- INP_PCBPORTHASH(inp->inp_lport, pcbinfo->ipi_lbgrouphashmask)];
+ INP_PCBPORTHASH(inp->inp_lport, pcbinfo->ipi_porthashmask)];
CK_LIST_FOREACH(grp, hdr, il_list) {
struct inpcb *inp1;
@@ -413,7 +413,7 @@
}
#endif
- idx = INP_PCBPORTHASH(inp->inp_lport, pcbinfo->ipi_lbgrouphashmask);
+ idx = INP_PCBPORTHASH(inp->inp_lport, pcbinfo->ipi_porthashmask);
hdr = &pcbinfo->ipi_lbgrouphashbase[idx];
CK_LIST_FOREACH(grp, hdr, il_list) {
if (grp->il_cred->cr_prison == inp->inp_cred->cr_prison &&
@@ -474,7 +474,7 @@
INP_HASH_WLOCK_ASSERT(pcbinfo);
hdr = &pcbinfo->ipi_lbgrouphashbase[
- INP_PCBPORTHASH(inp->inp_lport, pcbinfo->ipi_lbgrouphashmask)];
+ INP_PCBPORTHASH(inp->inp_lport, pcbinfo->ipi_porthashmask)];
CK_LIST_FOREACH(grp, hdr, il_list) {
for (i = 0; i < grp->il_inpcnt; ++i) {
if (grp->il_inp[i] != inp)
@@ -545,9 +545,6 @@
return (error);
}
-/* Make sure it is safe to use hashinit(9) on CK_LIST. */
-CTASSERT(sizeof(struct inpcbhead) == sizeof(LIST_HEAD(, inpcb)));
-
/*
* Initialize an inpcbinfo - a per-VNET instance of connections db.
*/
@@ -555,6 +552,11 @@
in_pcbinfo_init(struct inpcbinfo *pcbinfo, struct inpcbstorage *pcbstor,
u_int hash_nelements, u_int porthash_nelements)
{
+ struct hashalloc_args ha = {
+ .mtype = M_PCB,
+ .mflags = M_WAITOK,
+ .head = HASH_HEAD_CK_LIST,
+ };
mtx_init(&pcbinfo->ipi_lock, pcbstor->ips_infolock_name, NULL, MTX_DEF);
mtx_init(&pcbinfo->ipi_hash_lock, pcbstor->ips_hashlock_name,
@@ -564,15 +566,17 @@
#endif
CK_LIST_INIT(&pcbinfo->ipi_listhead);
pcbinfo->ipi_count = 0;
- pcbinfo->ipi_hash_exact = hashinit(hash_nelements, M_PCB,
- &pcbinfo->ipi_hashmask);
- pcbinfo->ipi_hash_wild = hashinit(hash_nelements, M_PCB,
- &pcbinfo->ipi_hashmask);
- porthash_nelements = imin(porthash_nelements, IPPORT_MAX + 1);
- pcbinfo->ipi_porthashbase = hashinit(porthash_nelements, M_PCB,
- &pcbinfo->ipi_porthashmask);
- pcbinfo->ipi_lbgrouphashbase = hashinit(porthash_nelements, M_PCB,
- &pcbinfo->ipi_lbgrouphashmask);
+
+ ha.size = hash_nelements;
+ pcbinfo->ipi_hash_exact = hashalloc(&ha);
+ pcbinfo->ipi_hash_wild = hashalloc(&ha);
+ pcbinfo->ipi_hashmask = ha.size - 1;
+
+ ha.size = imin(porthash_nelements, IPPORT_MAX + 1);
+ pcbinfo->ipi_porthashbase = hashalloc(&ha);
+ pcbinfo->ipi_lbgrouphashbase = hashalloc(&ha);
+ pcbinfo->ipi_porthashmask = ha.size - 1;
+
pcbinfo->ipi_zone = pcbstor->ips_zone;
pcbinfo->ipi_smr = uma_zone_get_smr(pcbinfo->ipi_zone);
}
@@ -583,16 +587,20 @@
void
in_pcbinfo_destroy(struct inpcbinfo *pcbinfo)
{
+ struct hashalloc_args ha = {
+ .mtype = M_PCB,
+ .head = HASH_HEAD_CK_LIST,
+ };
KASSERT(pcbinfo->ipi_count == 0,
("%s: ipi_count = %u", __func__, pcbinfo->ipi_count));
- hashdestroy(pcbinfo->ipi_hash_exact, M_PCB, pcbinfo->ipi_hashmask);
- hashdestroy(pcbinfo->ipi_hash_wild, M_PCB, pcbinfo->ipi_hashmask);
- hashdestroy(pcbinfo->ipi_porthashbase, M_PCB,
- pcbinfo->ipi_porthashmask);
- hashdestroy(pcbinfo->ipi_lbgrouphashbase, M_PCB,
- pcbinfo->ipi_lbgrouphashmask);
+ ha.size = pcbinfo->ipi_hashmask + 1;
+ hashfree(pcbinfo->ipi_hash_exact, &ha);
+ hashfree(pcbinfo->ipi_hash_wild, &ha);
+ ha.size = pcbinfo->ipi_porthashmask + 1;
+ hashfree(pcbinfo->ipi_porthashbase, &ha);
+ hashfree(pcbinfo->ipi_lbgrouphashbase, &ha);
mtx_destroy(&pcbinfo->ipi_hash_lock);
mtx_destroy(&pcbinfo->ipi_lock);
}
@@ -2107,7 +2115,7 @@
NET_EPOCH_ASSERT();
hdr = &pcbinfo->ipi_lbgrouphashbase[
- INP_PCBPORTHASH(lport, pcbinfo->ipi_lbgrouphashmask)];
+ INP_PCBPORTHASH(lport, pcbinfo->ipi_porthashmask)];
/*
* Search for an LB group match based on the following criteria:
diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c
--- a/sys/netinet6/in6_pcb.c
+++ b/sys/netinet6/in6_pcb.c
@@ -879,7 +879,7 @@
NET_EPOCH_ASSERT();
hdr = &pcbinfo->ipi_lbgrouphashbase[
- INP_PCBPORTHASH(lport, pcbinfo->ipi_lbgrouphashmask)];
+ INP_PCBPORTHASH(lport, pcbinfo->ipi_porthashmask)];
/*
* Search for an LB group match based on the following criteria:
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Aug 5, 10:13 PM (54 m, 29 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
36052316
Default Alt Text
D56174.id174592.diff (4 KB)
Attached To
Mode
D56174: inpcb: use hashalloc(9)
Attached
Detach File
Event Timeline
Log In to Comment