summaryrefslogtreecommitdiffstats
path: root/sys/netinet/in_pcb.c
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/in_pcb.c
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/in_pcb.c')
-rw-r--r--sys/netinet/in_pcb.c41
1 files changed, 41 insertions, 0 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.
*/
OpenPOWER on IntegriCloud