[prev in list] [next in list] [prev in thread] [next in thread]
List: openbsd-tech
Subject: Re: use hashfree on pcb hash tables
From: David Hill <dhill () mindcry ! org>
Date: 2018-03-29 2:32:55
Message-ID: 20180329023255.GA19355 () 4f13f0ba3d3ecd708d7281913f4c08614778da6b077a360b
[Download RAW message or body]
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.c 19 Feb 2018 08:59:53 -0000 1.228
+++ netinet/in_pcb.c 29 Mar 2018 02:21:34 -0000
@@ -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(&table->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, &nhash);
+ if (nhashtbl == NULL)
+ return ENOBUFS;
nlhashtbl = hashinit(hashsize, M_PCB, M_NOWAIT, &nlhash);
- 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(&table->inpt_key, sizeof(table->inpt_key));
TAILQ_FOREACH_SAFE(inp0, &table->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.h 1 Dec 2017 10:33:33 -0000 1.106
+++ netinet/in_pcb.h 29 Mar 2018 02:21:34 -0000
@@ -152,7 +152,7 @@ struct inpcbtable {
struct inpcbhead *inpt_hashtbl, *inpt_lhashtbl;
SIPHASH_KEY inpt_key;
u_long inpt_hash, inpt_lhash;
- int inpt_count;
+ int inpt_count, inpt_size;
};
/* flags in inp_flags: */
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic