Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/netinet use a hash table to bind to local ports; suggest...
details: https://anonhg.NetBSD.org/src/rev/ce3bf20d7a96
branches: trunk
changeset: 554466:ce3bf20d7a96
user: provos <provos%NetBSD.org@localhost>
date: Tue Oct 28 17:18:37 2003 +0000
description:
use a hash table to bind to local ports; suggested by markus friedl
approved: fvdl@
diffstat:
sys/netinet/in_pcb.c | 18 +++++++++++++++---
sys/netinet/in_pcb_hdr.h | 5 ++++-
2 files changed, 19 insertions(+), 4 deletions(-)
diffs (107 lines):
diff -r ba4f8f9dc9ed -r ce3bf20d7a96 sys/netinet/in_pcb.c
--- a/sys/netinet/in_pcb.c Tue Oct 28 17:02:54 2003 +0000
+++ b/sys/netinet/in_pcb.c Tue Oct 28 17:18:37 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: in_pcb.c,v 1.89 2003/10/23 20:55:08 mycroft Exp $ */
+/* $NetBSD: in_pcb.c,v 1.90 2003/10/28 17:18:37 provos Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -98,7 +98,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.89 2003/10/23 20:55:08 mycroft Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.90 2003/10/28 17:18:37 provos Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@@ -142,6 +142,8 @@
struct in_addr zeroin_addr;
+#define INPCBHASH_PORT(table, lport) \
+ &(table)->inpt_porthashtbl[ ntohs(lport) & (table)->inpt_porthash]
#define INPCBHASH_BIND(table, laddr, lport) \
&(table)->inpt_bindhashtbl[ \
((ntohl((laddr).s_addr) + ntohs(lport))) & (table)->inpt_bindhash]
@@ -171,6 +173,8 @@
}
CIRCLEQ_INIT(&table->inpt_queue);
+ table->inpt_porthashtbl = hashinit(bindhashsize, HASH_LIST, M_PCB,
+ M_WAITOK, &table->inpt_porthash);
table->inpt_bindhashtbl = hashinit(bindhashsize, HASH_LIST, M_PCB,
M_WAITOK, &table->inpt_bindhash);
table->inpt_connecthashtbl = hashinit(connecthashsize, HASH_LIST,
@@ -210,6 +214,8 @@
s = splnet();
CIRCLEQ_INSERT_HEAD(&table->inpt_queue, &inp->inp_head,
inph_queue);
+ LIST_INSERT_HEAD(INPCBHASH_PORT(table, inp->inp_lport), &inp->inp_head,
+ inph_lhash);
in_pcbstate(inp, INP_ATTACHED);
splx(s);
return (0);
@@ -351,6 +357,9 @@
lport = htons(lport);
}
inp->inp_lport = lport;
+ LIST_REMOVE(&inp->inp_head, inph_lhash);
+ LIST_INSERT_HEAD(INPCBHASH_PORT(table, inp->inp_lport), &inp->inp_head,
+ inph_lhash);
in_pcbstate(inp, INP_BOUND);
return (0);
}
@@ -500,6 +509,7 @@
ip_freemoptions(inp->inp_moptions);
s = splnet();
in_pcbstate(inp, INP_ATTACHED);
+ LIST_REMOVE(&inp->inp_head, inph_lhash);
CIRCLEQ_REMOVE(&inp->inp_table->inpt_queue, &inp->inp_head,
inph_queue);
splx(s);
@@ -739,12 +749,14 @@
u_int lport_arg;
int lookup_wildcard;
{
+ struct inpcbhead *head;
struct inpcb_hdr *inph;
struct inpcb *inp, *match = 0;
int matchwild = 3, wildcard;
u_int16_t lport = lport_arg;
- CIRCLEQ_FOREACH(inph, &table->inpt_queue, inph_queue) {
+ head = INPCBHASH_PORT(table, lport);
+ LIST_FOREACH(inph, head, inph_lhash) {
inp = (struct inpcb *)inph;
if (inp->inp_af != AF_INET)
continue;
diff -r ba4f8f9dc9ed -r ce3bf20d7a96 sys/netinet/in_pcb_hdr.h
--- a/sys/netinet/in_pcb_hdr.h Tue Oct 28 17:02:54 2003 +0000
+++ b/sys/netinet/in_pcb_hdr.h Tue Oct 28 17:18:37 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: in_pcb_hdr.h,v 1.1 2003/09/04 09:16:58 itojun Exp $ */
+/* $NetBSD: in_pcb_hdr.h,v 1.2 2003/10/28 17:18:37 provos Exp $ */
/*
* Copyright (C) 2003 WIDE Project.
@@ -72,6 +72,7 @@
*/
struct inpcb_hdr {
LIST_ENTRY(inpcb_hdr) inph_hash;
+ LIST_ENTRY(inpcb_hdr) inph_lhash;
CIRCLEQ_ENTRY(inpcb_hdr) inph_queue;
int inph_af; /* address family - AF_INET */
caddr_t inph_ppcb; /* pointer to per-protocol pcb */
@@ -87,8 +88,10 @@
struct inpcbtable {
CIRCLEQ_HEAD(, inpcb_hdr) inpt_queue;
+ struct inpcbhead *inpt_porthashtbl;
struct inpcbhead *inpt_bindhashtbl;
struct inpcbhead *inpt_connecthashtbl;
+ u_long inpt_porthash;
u_long inpt_bindhash;
u_long inpt_connecthash;
u_int16_t inpt_lastport;
Home |
Main Index |
Thread Index |
Old Index