diff options
Diffstat (limited to 'sys/netinet')
-rw-r--r-- | sys/netinet/in_pcb.c | 41 | ||||
-rw-r--r-- | sys/netinet/in_pcb.h | 5 | ||||
-rw-r--r-- | sys/netinet/ip_divert.c | 27 | ||||
-rw-r--r-- | sys/netinet/raw_ip.c | 20 | ||||
-rw-r--r-- | sys/netinet/tcp_subr.c | 27 | ||||
-rw-r--r-- | sys/netinet/udp_usrreq.c | 26 |
6 files changed, 62 insertions, 84 deletions
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 204d90453bd9..8a291e4e61ab 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 6e3a24bef0db..4ba19e61d9d2 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 22e52bafbf2b..2e8703439da0 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 9341cf29bbe6..88c1e61d4528 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 4ebdf281c79b..4a2f21f18b34 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 8a9f2e8ab6f9..e0189d3227a0 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 |