round #2.
keep track of size (num of elements) in the inpcbtable struct.
passes regress tests.
OK?
Index: netinet/in_pcb.c
===
RCS file: /cvs/src/sys/netinet/in_pcb.c,v
retrieving revision 1.228
diff -u -p -r1.228 in_pcb.c
--- netinet/in_pcb.c19 Feb 2018 08:59:53 - 1.228
+++ netinet/in_pcb.c29 Mar 2018 02:21:34 -
@@ -206,6 +206,7 @@ in_pcbinit(struct inpcbtable *table, int
if (table->inpt_lhashtbl == NULL)
panic("in_pcbinit: hashinit failed for lport");
table->inpt_count = 0;
+ table->inpt_size = hashsize;
arc4random_buf(>inpt_key, sizeof(table->inpt_key));
}
@@ -998,32 +999,34 @@ int
in_pcbresize(struct inpcbtable *table, int hashsize)
{
u_long nhash, nlhash;
+ int osize;
void *nhashtbl, *nlhashtbl, *ohashtbl, *olhashtbl;
struct inpcb *inp0, *inp1;
ohashtbl = table->inpt_hashtbl;
olhashtbl = table->inpt_lhashtbl;
+ osize = table->inpt_size;
nhashtbl = hashinit(hashsize, M_PCB, M_NOWAIT, );
+ if (nhashtbl == NULL)
+ return ENOBUFS;
nlhashtbl = hashinit(hashsize, M_PCB, M_NOWAIT, );
- if (nhashtbl == NULL || nlhashtbl == NULL) {
- if (nhashtbl != NULL)
- free(nhashtbl, M_PCB, 0);
- if (nlhashtbl != NULL)
- free(nlhashtbl, M_PCB, 0);
- return (ENOBUFS);
+ if (nlhashtbl == NULL) {
+ hashfree(nhashtbl, hashsize, M_PCB);
+ return ENOBUFS;
}
table->inpt_hashtbl = nhashtbl;
table->inpt_lhashtbl = nlhashtbl;
table->inpt_hash = nhash;
table->inpt_lhash = nlhash;
+ table->inpt_size = hashsize;
arc4random_buf(>inpt_key, sizeof(table->inpt_key));
TAILQ_FOREACH_SAFE(inp0, >inpt_queue, inp_queue, inp1) {
in_pcbrehash(inp0);
}
- free(ohashtbl, M_PCB, 0);
- free(olhashtbl, M_PCB, 0);
+ hashfree(ohashtbl, osize, M_PCB);
+ hashfree(olhashtbl, osize, M_PCB);
return (0);
}
Index: netinet/in_pcb.h
===
RCS file: /cvs/src/sys/netinet/in_pcb.h,v
retrieving revision 1.106
diff -u -p -r1.106 in_pcb.h
--- netinet/in_pcb.h1 Dec 2017 10:33:33 - 1.106
+++ netinet/in_pcb.h29 Mar 2018 02:21:34 -
@@ -152,7 +152,7 @@ struct inpcbtable {
struct inpcbhead *inpt_hashtbl, *inpt_lhashtbl;
SIPHASH_KEY inpt_key;
u_longinpt_hash, inpt_lhash;
- int inpt_count;
+ int inpt_count, inpt_size;
};
/* flags in inp_flags: */