Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177789362
D61835.1795289209.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
8 KB
Referenced Files
None
Subscribers
None
D61835.1795289209.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
@@ -437,15 +437,12 @@
} ipi_list_unconn; /* (r:e/w:h) */
struct inpbucket *ipi_hash_exact; /* (r:e/w:h) */
struct inpbucket *ipi_hash_wild; /* (r:e/w:h) */
+ struct inpbucket *ipi_porthash; /* (r:e/w:h) */
u_long ipi_hashmask; /* (c) */
+ u_long ipi_wildhashmask; /* (c) */
u_long ipi_porthashmask; /* (c) */
u_long ipi_lbgrouphashmask; /* (c) */
- /*
- * Global hash of inpcbs, hashed by only local port number.
- */
- struct inpbucket *ipi_porthash; /* (h) */
-
/*
* Load balance groups used for the SO_REUSEPORT_LB option,
* hashed by local port.
@@ -614,7 +611,7 @@
#define V_ipport_hilastauto VNET(ipport_hilastauto)
void in_pcbinfo_init(struct inpcbinfo *, struct inpcbstorage *,
- u_int, u_int, u_int);
+ u_int, u_int, u_int, u_int);
void in_pcbinfo_destroy(struct inpcbinfo *);
void in_pcbstorage_init(void *);
void in_pcbstorage_destroy(void *);
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
@@ -543,7 +543,8 @@
*/
void
in_pcbinfo_init(struct inpcbinfo *pcbinfo, struct inpcbstorage *pcbstor,
- u_int hash_nelements, u_int porthash_nelements, u_int lbgrouphash_nelements)
+ u_int hash_nelements, u_int wildhash_nelements, u_int porthash_nelements,
+ u_int lbgrouphash_nelements)
{
struct hashalloc_args ha = {
.mtype = M_PCB,
@@ -561,10 +562,16 @@
ha.size = hash_nelements;
ha.lname = "inpcb_exact_bucket";
pcbinfo->ipi_hash_exact = hashalloc(&ha);
- ha.lname = "inpcb_wild_bucket";
- pcbinfo->ipi_hash_wild = hashalloc(&ha);
pcbinfo->ipi_hashmask = ha.size - 1;
+ if (wildhash_nelements > 0) {
+ ha.size = wildhash_nelements;
+ ha.lname = "inpcb_wild_bucket";
+ pcbinfo->ipi_hash_wild = hashalloc(&ha);
+ pcbinfo->ipi_wildhashmask = ha.size - 1;
+ } else
+ pcbinfo->ipi_hash_wild = NULL;
+
if (porthash_nelements > 0) {
ha.size = imin(porthash_nelements, IPPORT_MAX + 1);
ha.lname = "inpcb_port_bucket";
@@ -601,7 +608,10 @@
ha.size = pcbinfo->ipi_hashmask + 1;
hashfree(pcbinfo->ipi_hash_exact, &ha);
- hashfree(pcbinfo->ipi_hash_wild, &ha);
+ if (pcbinfo->ipi_hash_wild != NULL) {
+ ha.size = pcbinfo->ipi_wildhashmask + 1;
+ hashfree(pcbinfo->ipi_hash_wild, &ha);
+ }
if (pcbinfo->ipi_porthash != NULL) {
ha.size = pcbinfo->ipi_porthashmask + 1;
hashfree(pcbinfo->ipi_porthash, &ha);
@@ -1670,23 +1680,28 @@
ii_list_first(const struct inpcb_iterator *ii)
{
const struct inpcbinfo *ipi = ii->ipi;
+ const u_int wildmax = ipi->ipi_hash_wild != NULL ?
+ ipi->ipi_wildhashmask + 1 : 0;
const int hash = ii->hash;
if (hash < 0)
return (CK_LIST_FIRST(&ipi->ipi_list_unconn.head));
- else if (hash <= ipi->ipi_hashmask)
+ else if (wildmax > 0 && hash < wildmax)
return (CK_LIST_FIRST(&ipi->ipi_hash_wild[hash].head));
else
return (CK_LIST_FIRST(
- &ipi->ipi_hash_exact[hash - ipi->ipi_hashmask - 1].head));
+ &ipi->ipi_hash_exact[hash - wildmax].head));
}
static inline struct inpcb *
ii_list_next(const struct inpcb_iterator *ii, struct inpcb *inp)
{
+ const u_int wildmax = ii->ipi->ipi_hash_wild != NULL ?
+ ii->ipi->ipi_wildhashmask + 1 : 0;
+
if (ii->hash < 0)
return (CK_LIST_NEXT(inp, inp_unconn_list));
- else if (ii->hash <= ii->ipi->ipi_hashmask)
+ else if (wildmax > 0 && ii->hash < wildmax)
return (CK_LIST_NEXT(inp, inp_hash_wild));
else
return (CK_LIST_NEXT(inp, inp_hash_exact));
@@ -1696,7 +1711,9 @@
inp_next(struct inpcb_iterator *ii)
{
const struct inpcbinfo *ipi = ii->ipi;
- const int hashmax = (ipi->ipi_hashmask + 1) * 2;
+ const u_int wildmax = ipi->ipi_hash_wild != NULL ?
+ ipi->ipi_wildhashmask + 1 : 0;
+ const u_int hashmax = wildmax + ipi->ipi_hashmask + 1;
inp_match_t *match = ii->match;
void *ctx = ii->ctx;
inp_lookup_t lock = ii->lock;
@@ -1706,7 +1723,7 @@
if ((ii->hash = ii->mode) >= 0) {
/* Targeted iterators support only the exact hash. */
MPASS(ii->hash <= ipi->ipi_hashmask);
- ii->hash += ipi->ipi_hashmask + 1;
+ ii->hash += wildmax;
}
smr_enter(ipi->ipi_smr);
next_first:
@@ -2379,7 +2396,7 @@
("%s: not in SMR read section", __func__));
bucket = &pcbinfo->ipi_hash_wild[INP_PCBHASH_WILD(lport,
- pcbinfo->ipi_hashmask)];
+ pcbinfo->ipi_wildhashmask)];
CK_LIST_FOREACH(inp, &bucket->head, inp_hash_wild) {
inp_lookup_match_t match;
@@ -2432,7 +2449,7 @@
local_wild_mapped = NULL;
#endif
bucket = &pcbinfo->ipi_hash_wild[INP_PCBHASH_WILD(lport,
- pcbinfo->ipi_hashmask)];
+ pcbinfo->ipi_wildhashmask)];
MPASS(*bucketp == NULL);
*bucketp = bucket;
INPBUCKET_LOCK(bucket);
@@ -2785,28 +2802,28 @@
MPASS(inp->inp_flags & INP_UNCONNECTED);
#ifdef INET6
- if (inp->inp_vflag & INP_IPV6) {
-#ifdef INVARIANTS
- hash = INP6_PCBHASH(&inp->in6p_faddr, inp->inp_lport,
- inp->inp_fport, inp->inp_pcbinfo->ipi_hashmask);
-#endif
+ if (inp->inp_vflag & INP_IPV6)
connected = !IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr);
- } else
-#endif
- {
-#ifdef INVARIANTS
- hash = INP_PCBHASH(&inp->inp_faddr, inp->inp_lport,
- inp->inp_fport, inp->inp_pcbinfo->ipi_hashmask);
+ else
#endif
connected = !in_nullhost(inp->inp_faddr);
- }
#ifdef INVARIANTS
if (connected) {
+#ifdef INET6
+ if (inp->inp_vflag & INP_IPV6)
+ hash = INP6_PCBHASH(&inp->in6p_faddr, inp->inp_lport,
+ inp->inp_fport, inp->inp_pcbinfo->ipi_hashmask);
+ else
+#endif
+ hash = INP_PCBHASH(&inp->inp_faddr, inp->inp_lport,
+ inp->inp_fport, inp->inp_pcbinfo->ipi_hashmask);
MPASS(ipictx->ebucket ==
&ipictx->pcbinfo->ipi_hash_exact[hash]);
INPBUCKET_LOCK_ASSERT(ipictx->ebucket);
} else {
+ hash = INP_PCBHASH_WILD(inp->inp_lport,
+ inp->inp_pcbinfo->ipi_wildhashmask);
MPASS(ipictx->wbucket == &ipictx->pcbinfo->ipi_hash_wild[hash]);
INPBUCKET_LOCK_ASSERT(ipictx->wbucket);
}
@@ -2883,23 +2900,27 @@
}
#ifdef INET6
- if (inp->inp_vflag & INP_IPV6) {
- hash = INP6_PCBHASH(&inp->in6p_faddr, inp->inp_lport,
- inp->inp_fport, inp->inp_pcbinfo->ipi_hashmask);
+ if (inp->inp_vflag & INP_IPV6)
connected = !IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr);
- } else
+ else
#endif
- {
- hash = INP_PCBHASH(&inp->inp_faddr, inp->inp_lport,
- inp->inp_fport, inp->inp_pcbinfo->ipi_hashmask);
connected = !in_nullhost(inp->inp_faddr);
- }
if (connected) {
+#ifdef INET6
+ if (inp->inp_vflag & INP_IPV6)
+ hash = INP6_PCBHASH(&inp->in6p_faddr, inp->inp_lport,
+ inp->inp_fport, inp->inp_pcbinfo->ipi_hashmask);
+ else
+#endif
+ hash = INP_PCBHASH(&inp->inp_faddr, inp->inp_lport,
+ inp->inp_fport, inp->inp_pcbinfo->ipi_hashmask);
bucket = &inp->inp_pcbinfo->ipi_hash_exact[hash];
INPBUCKET_LOCK(bucket);
CK_LIST_REMOVE(inp, inp_hash_exact);
} else {
+ hash = INP_PCBHASH_WILD(inp->inp_lport,
+ inp->inp_pcbinfo->ipi_wildhashmask);
bucket = &inp->inp_pcbinfo->ipi_hash_wild[hash];
INPBUCKET_LOCK(bucket);
CK_LIST_REMOVE(inp, inp_hash_wild);
diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c
--- a/sys/netinet/raw_ip.c
+++ b/sys/netinet/raw_ip.c
@@ -147,7 +147,8 @@
rip_init(void *arg __unused)
{
#define INP_PCBHASH_RAW_SIZE 256
- in_pcbinfo_init(&V_ripcbinfo, &ripcbstor, INP_PCBHASH_RAW_SIZE, 0, 0);
+ in_pcbinfo_init(&V_ripcbinfo, &ripcbstor, INP_PCBHASH_RAW_SIZE,
+ 0, 0, 0);
}
VNET_SYSINIT(rip_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, rip_init, NULL);
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -1450,7 +1450,7 @@
__func__);
#endif
in_pcbinfo_init(&V_tcbinfo, &tcpcbstor, tcp_tcbhashsize,
- tcp_tcbhashsize, tcp_tcbhashsize);
+ tcp_tcbhashsize, tcp_tcbhashsize, tcp_tcbhashsize);
syncache_init();
tcp_hc_init();
diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c
--- a/sys/netinet/udp_usrreq.c
+++ b/sys/netinet/udp_usrreq.c
@@ -181,10 +181,10 @@
* a 4-tuple, flip this to 4-tuple.
*/
in_pcbinfo_init(&V_udbinfo, &udpcbstor, UDBHASHSIZE, UDBHASHSIZE,
- UDBHASHSIZE);
+ UDBHASHSIZE, UDBHASHSIZE);
/* Additional pcbinfo for UDP-Lite */
in_pcbinfo_init(&V_ulitecbinfo, &udplitecbstor, UDBHASHSIZE,
- UDBHASHSIZE, UDBHASHSIZE);
+ UDBHASHSIZE, UDBHASHSIZE, UDBHASHSIZE);
}
VNET_SYSINIT(udp_vnet_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH,
udp_vnet_init, NULL);
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
@@ -1088,7 +1088,7 @@
("%s: not in SMR read section", __func__));
bucket = &pcbinfo->ipi_hash_wild[INP_PCBHASH_WILD(lport,
- pcbinfo->ipi_hashmask)];
+ pcbinfo->ipi_wildhashmask)];
CK_LIST_FOREACH(inp, &bucket->head, inp_hash_wild) {
inp_lookup_match_t match;
@@ -1134,7 +1134,7 @@
*/
local_wild = local_exact = jail_wild = NULL;
bucket = &pcbinfo->ipi_hash_wild[INP_PCBHASH_WILD(lport,
- pcbinfo->ipi_hashmask)];
+ pcbinfo->ipi_wildhashmask)];
MPASS(*bucketp == NULL);
*bucketp = bucket;
INPBUCKET_LOCK(bucket);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 21, 7:26 PM (22 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41894463
Default Alt Text
D61835.1795289209.diff (8 KB)
Attached To
Mode
D61835: inpcb: make wildcard hash optional and alternatively sized
Attached
Detach File
Event Timeline