summaryrefslogtreecommitdiffstats
path: root/sys/netinet
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2010-03-14 18:59:11 +0000
committerrwatson <rwatson@FreeBSD.org>2010-03-14 18:59:11 +0000
commit1fdd3bccc0217643bd336f00c0ffe11fcf22f906 (patch)
tree17f74ef6c048f38cf428a40d8856694105998a44 /sys/netinet
parent08d0d0b9a9e34bc0f3e3ea091437486c47f6bae5 (diff)
downloadFreeBSD-src-1fdd3bccc0217643bd336f00c0ffe11fcf22f906.zip
FreeBSD-src-1fdd3bccc0217643bd336f00c0ffe11fcf22f906.tar.gz
Abstract out initialization of most aspects of struct inpcbinfo from
their calling contexts in {IP divert, raw IP sockets, TCP, UDP} and create new helper functions: in_pcbinfo_init() and in_pcbinfo_destroy() to do this work in a central spot. As inpcbinfo becomes more complex due to ongoing work to add connection groups, this will reduce code duplication. MFC after: 1 month Reviewed by: bz Sponsored by: Juniper Networks
Diffstat (limited to 'sys/netinet')
-rw-r--r--sys/netinet/in_pcb.c41
-rw-r--r--sys/netinet/in_pcb.h5
-rw-r--r--sys/netinet/ip_divert.c27
-rw-r--r--sys/netinet/raw_ip.c20
-rw-r--r--sys/netinet/tcp_subr.c27
-rw-r--r--sys/netinet/udp_usrreq.c26
6 files changed, 62 insertions, 84 deletions
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c
index 204d904..8a291e4 100644
--- a/sys/netinet/in_pcb.c
+++ b/sys/netinet/in_pcb.c
@@ -184,6 +184,47 @@ SYSCTL_VNET_INT(_net_inet_ip_portrange, OID_AUTO, randomtime, CTLFLAG_RW,
*/
/*
+ * Initialize an inpcbinfo -- we should be able to reduce the number of
+ * arguments in time.
+ */
+void
+in_pcbinfo_init(struct inpcbinfo *pcbinfo, const char *name,
+ struct inpcbhead *listhead, int hash_nelements, int porthash_nelements,
+ char *inpcbzone_name, uma_init inpcbzone_init, uma_fini inpcbzone_fini,
+ uint32_t inpcbzone_flags)
+{
+
+ INP_INFO_LOCK_INIT(pcbinfo, name);
+#ifdef VIMAGE
+ pcbinfo->ipi_vnet = curvnet;
+#endif
+ pcbinfo->ipi_listhead = listhead;
+ LIST_INIT(pcbinfo->ipi_listhead);
+ pcbinfo->ipi_hashbase = hashinit(hash_nelements, M_PCB,
+ &pcbinfo->ipi_hashmask);
+ pcbinfo->ipi_porthashbase = hashinit(porthash_nelements, M_PCB,
+ &pcbinfo->ipi_porthashmask);
+ pcbinfo->ipi_zone = uma_zcreate(inpcbzone_name, sizeof(struct inpcb),
+ NULL, NULL, inpcbzone_init, inpcbzone_fini, UMA_ALIGN_PTR,
+ inpcbzone_flags);
+ uma_zone_set_max(pcbinfo->ipi_zone, maxsockets);
+}
+
+/*
+ * Destroy an inpcbinfo.
+ */
+void
+in_pcbinfo_destroy(struct inpcbinfo *pcbinfo)
+{
+
+ hashdestroy(pcbinfo->ipi_hashbase, M_PCB, pcbinfo->ipi_hashmask);
+ hashdestroy(pcbinfo->ipi_porthashbase, M_PCB,
+ pcbinfo->ipi_porthashmask);
+ uma_zdestroy(pcbinfo->ipi_zone);
+ INP_INFO_LOCK_DESTROY(pcbinfo);
+}
+
+/*
* Allocate a PCB and associate it with the socket.
* On success return with the PCB locked.
*/
diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h
index 6e3a24b..4ba19e6 100644
--- a/sys/netinet/in_pcb.h
+++ b/sys/netinet/in_pcb.h
@@ -42,6 +42,7 @@
#ifdef _KERNEL
#include <sys/rwlock.h>
#include <net/vnet.h>
+#include <vm/uma.h>
#endif
#define in6pcb inpcb /* for KAME src sync over BSD*'s */
@@ -483,6 +484,10 @@ VNET_DECLARE(int, ipport_tcpallocs);
extern struct callout ipport_tick_callout;
+void in_pcbinfo_destroy(struct inpcbinfo *);
+void in_pcbinfo_init(struct inpcbinfo *, const char *, struct inpcbhead *,
+ int, int, char *, uma_init, uma_fini, uint32_t);
+
void in_pcbpurgeif0(struct inpcbinfo *, struct ifnet *);
int in_pcballoc(struct socket *, struct inpcbinfo *);
int in_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *);
diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c
index 22e52ba..2e87034 100644
--- a/sys/netinet/ip_divert.c
+++ b/sys/netinet/ip_divert.c
@@ -147,35 +147,20 @@ static void
div_init(void)
{
- INP_INFO_LOCK_INIT(&V_divcbinfo, "div");
- LIST_INIT(&V_divcb);
- V_divcbinfo.ipi_listhead = &V_divcb;
-#ifdef VIMAGE
- V_divcbinfo.ipi_vnet = curvnet;
-#endif
/*
- * XXX We don't use the hash list for divert IP, but it's easier
- * to allocate a one entry hash list than it is to check all
- * over the place for hashbase == NULL.
+ * XXX We don't use the hash list for divert IP, but it's easier to
+ * allocate one-entry hash lists than it is to check all over the
+ * place for hashbase == NULL.
*/
- V_divcbinfo.ipi_hashbase = hashinit(1, M_PCB, &V_divcbinfo.ipi_hashmask);
- V_divcbinfo.ipi_porthashbase = hashinit(1, M_PCB,
- &V_divcbinfo.ipi_porthashmask);
- V_divcbinfo.ipi_zone = uma_zcreate("divcb", sizeof(struct inpcb),
- NULL, NULL, div_inpcb_init, div_inpcb_fini, UMA_ALIGN_PTR,
- UMA_ZONE_NOFREE);
- uma_zone_set_max(V_divcbinfo.ipi_zone, maxsockets);
+ in_pcbinfo_init(&V_divcbinfo, "div", &V_divcb, 1, 1, "divcb",
+ div_inpcb_init, div_inpcb_fini, UMA_ZONE_NOFREE);
}
static void
div_destroy(void)
{
- INP_INFO_LOCK_DESTROY(&V_divcbinfo);
- uma_zdestroy(V_divcbinfo.ipi_zone);
- hashdestroy(V_divcbinfo.ipi_hashbase, M_PCB, V_divcbinfo.ipi_hashmask);
- hashdestroy(V_divcbinfo.ipi_porthashbase, M_PCB,
- V_divcbinfo.ipi_porthashmask);
+ in_pcbinfo_destroy(&V_divcbinfo);
}
/*
diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c
index 9341cf2..88c1e61 100644
--- a/sys/netinet/raw_ip.c
+++ b/sys/netinet/raw_ip.c
@@ -185,19 +185,8 @@ void
rip_init(void)
{
- INP_INFO_LOCK_INIT(&V_ripcbinfo, "rip");
- LIST_INIT(&V_ripcb);
-#ifdef VIMAGE
- V_ripcbinfo.ipi_vnet = curvnet;
-#endif
- V_ripcbinfo.ipi_listhead = &V_ripcb;
- V_ripcbinfo.ipi_hashbase =
- hashinit(INP_PCBHASH_RAW_SIZE, M_PCB, &V_ripcbinfo.ipi_hashmask);
- V_ripcbinfo.ipi_porthashbase =
- hashinit(1, M_PCB, &V_ripcbinfo.ipi_porthashmask);
- V_ripcbinfo.ipi_zone = uma_zcreate("ripcb", sizeof(struct inpcb),
- NULL, NULL, rip_inpcb_init, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
- uma_zone_set_max(V_ripcbinfo.ipi_zone, maxsockets);
+ in_pcbinfo_init(&V_ripcbinfo, "rip", &V_ripcb, INP_PCBHASH_RAW_SIZE,
+ 1, "ripcb", rip_inpcb_init, NULL, UMA_ZONE_NOFREE);
EVENTHANDLER_REGISTER(maxsockets_change, rip_zone_change, NULL,
EVENTHANDLER_PRI_ANY);
}
@@ -207,10 +196,7 @@ void
rip_destroy(void)
{
- hashdestroy(V_ripcbinfo.ipi_hashbase, M_PCB,
- V_ripcbinfo.ipi_hashmask);
- hashdestroy(V_ripcbinfo.ipi_porthashbase, M_PCB,
- V_ripcbinfo.ipi_porthashmask);
+ in_pcbinfo_destroy(&V_ripcbinfo);
}
#endif
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index 4ebdf28..4a2f21f 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -376,25 +376,15 @@ tcp_init(void)
TUNABLE_INT_FETCH("net.inet.tcp.sack.enable", &V_tcp_do_sack);
- INP_INFO_LOCK_INIT(&V_tcbinfo, "tcp");
- LIST_INIT(&V_tcb);
-#ifdef VIMAGE
- V_tcbinfo.ipi_vnet = curvnet;
-#endif
- V_tcbinfo.ipi_listhead = &V_tcb;
hashsize = TCBHASHSIZE;
TUNABLE_INT_FETCH("net.inet.tcp.tcbhashsize", &hashsize);
if (!powerof2(hashsize)) {
printf("WARNING: TCB hash size not a power of 2\n");
hashsize = 512; /* safe default */
}
- V_tcbinfo.ipi_hashbase = hashinit(hashsize, M_PCB,
- &V_tcbinfo.ipi_hashmask);
- V_tcbinfo.ipi_porthashbase = hashinit(hashsize, M_PCB,
- &V_tcbinfo.ipi_porthashmask);
- V_tcbinfo.ipi_zone = uma_zcreate("tcp_inpcb", sizeof(struct inpcb),
- NULL, NULL, tcp_inpcb_init, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
- uma_zone_set_max(V_tcbinfo.ipi_zone, maxsockets);
+ in_pcbinfo_init(&V_tcbinfo, "tcp", &V_tcb, hashsize, hashsize,
+ "tcp_inpcb", tcp_inpcb_init, NULL, UMA_ZONE_NOFREE);
+
/*
* These have to be type stable for the benefit of the timers.
*/
@@ -463,18 +453,9 @@ tcp_destroy(void)
tcp_hc_destroy();
syncache_destroy();
tcp_tw_destroy();
-
- /* XXX check that hashes are empty! */
- hashdestroy(V_tcbinfo.ipi_hashbase, M_PCB,
- V_tcbinfo.ipi_hashmask);
- hashdestroy(V_tcbinfo.ipi_porthashbase, M_PCB,
- V_tcbinfo.ipi_porthashmask);
-
+ in_pcbinfo_destroy(&V_tcbinfo);
uma_zdestroy(V_sack_hole_zone);
uma_zdestroy(V_tcpcb_zone);
- uma_zdestroy(V_tcbinfo.ipi_zone);
-
- INP_INFO_LOCK_DESTROY(&V_tcbinfo);
}
#endif
diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c
index 8a9f2e8..e0189d3 100644
--- a/sys/netinet/udp_usrreq.c
+++ b/sys/netinet/udp_usrreq.c
@@ -180,25 +180,11 @@ udp_init(void)
{
V_udp_blackhole = 0;
-
- INP_INFO_LOCK_INIT(&V_udbinfo, "udp");
- LIST_INIT(&V_udb);
-#ifdef VIMAGE
- V_udbinfo.ipi_vnet = curvnet;
-#endif
- V_udbinfo.ipi_listhead = &V_udb;
- V_udbinfo.ipi_hashbase = hashinit(UDBHASHSIZE, M_PCB,
- &V_udbinfo.ipi_hashmask);
- V_udbinfo.ipi_porthashbase = hashinit(UDBHASHSIZE, M_PCB,
- &V_udbinfo.ipi_porthashmask);
- V_udbinfo.ipi_zone = uma_zcreate("udp_inpcb", sizeof(struct inpcb),
- NULL, NULL, udp_inpcb_init, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
- uma_zone_set_max(V_udbinfo.ipi_zone, maxsockets);
-
+ in_pcbinfo_init(&V_udbinfo, "udp", &V_udb, UDBHASHSIZE, UDBHASHSIZE,
+ "udp_inpcb", udp_inpcb_init, NULL, UMA_ZONE_NOFREE);
V_udpcb_zone = uma_zcreate("udpcb", sizeof(struct udpcb),
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
uma_zone_set_max(V_udpcb_zone, maxsockets);
-
EVENTHANDLER_REGISTER(maxsockets_change, udp_zone_change, NULL,
EVENTHANDLER_PRI_ANY);
}
@@ -241,14 +227,8 @@ void
udp_destroy(void)
{
- hashdestroy(V_udbinfo.ipi_hashbase, M_PCB,
- V_udbinfo.ipi_hashmask);
- hashdestroy(V_udbinfo.ipi_porthashbase, M_PCB,
- V_udbinfo.ipi_porthashmask);
-
+ in_pcbinfo_destroy(&V_udbinfo);
uma_zdestroy(V_udpcb_zone);
- uma_zdestroy(V_udbinfo.ipi_zone);
- INP_INFO_LOCK_DESTROY(&V_udbinfo);
}
#endif
OpenPOWER on IntegriCloud