FreeBSD/sys/netpfil/pf/pf.c
/* Per-vnet data storage structures initialization. */
Per-vnet data storage structures initialization.
Per - vnet data storage structures initialization .
void
pf_initialize()
{
	struct pf_keyhash	*kh;
	struct pf_idhash	*ih;
	struct pf_srchash	*sh;
	u_int i;
	if (pf_hashsize == 0 || !powerof2(pf_hashsize))
		pf_hashsize = PF_HASHSIZ;
	if (pf_srchashsize == 0 || !powerof2(pf_srchashsize))
		pf_srchashsize = PF_HASHSIZ / 4;
	V_pf_hashseed = arc4random();
	V_pf_state_z = uma_zcreate("pf states", sizeof(struct pf_state),
	    NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
	V_pf_limits[PF_LIMIT_STATES].zone = V_pf_state_z;
	uma_zone_set_max(V_pf_state_z, PFSTATE_HIWAT);
	uma_zone_set_warning(V_pf_state_z, "PF states limit reached");
	V_pf_state_key_z = uma_zcreate("pf state keys",
	    sizeof(struct pf_state_key), pf_state_key_ctor, NULL, NULL, NULL,
	    UMA_ALIGN_PTR, 0);
	V_pf_keyhash = malloc(pf_hashsize * sizeof(struct pf_keyhash),
	    M_PFHASH, M_WAITOK | M_ZERO);
	V_pf_idhash = malloc(pf_hashsize * sizeof(struct pf_idhash),
	    M_PFHASH, M_WAITOK | M_ZERO);
	pf_hashmask = pf_hashsize - 1;
	for (i = 0, kh = V_pf_keyhash, ih = V_pf_idhash; i <= pf_hashmask;
	    i++, kh++, ih++) {
		mtx_init(&kh->lock, "pf_keyhash", NULL, MTX_DEF | MTX_DUPOK);
		mtx_init(&ih->lock, "pf_idhash", NULL, MTX_DEF);
	}
	V_pf_sources_z = uma_zcreate("pf source nodes",
	    sizeof(struct pf_src_node), NULL, NULL, NULL, NULL, UMA_ALIGN_PTR,
	    0);
	V_pf_limits[PF_LIMIT_SRC_NODES].zone = V_pf_sources_z;
	uma_zone_set_max(V_pf_sources_z, PFSNODE_HIWAT);
	uma_zone_set_warning(V_pf_sources_z, "PF source nodes limit reached");
	V_pf_srchash = malloc(pf_srchashsize * sizeof(struct pf_srchash),
	  M_PFHASH, M_WAITOK|M_ZERO);
	pf_srchashmask = pf_srchashsize - 1;
	for (i = 0, sh = V_pf_srchash; i <= pf_srchashmask; i++, sh++)
		mtx_init(&sh->lock, "pf_srchash", NULL, MTX_DEF);
	TAILQ_INIT(&V_pf_altqs[0]);
	TAILQ_INIT(&V_pf_altqs[1]);
	TAILQ_INIT(&V_pf_pabuf);
	V_pf_altqs_active = &V_pf_altqs[0];
	V_pf_altqs_inactive = &V_pf_altqs[1];
	STAILQ_INIT(&V_pf_sendqueue);
	SLIST_INIT(&V_pf_overloadqueue);
	TASK_INIT(&V_pf_overloadtask, 0, pf_overload_task, curvnet);
	TAILQ_INIT(&V_pf_unlinked_rules);
}
void pf_initialize ( ) { struct pf_keyhash * kh ; struct pf_idhash * ih ; struct pf_srchash * sh ; u_int i ; if ( pf_hashsize == 0 || ! powerof2 ( pf_hashsize ) ) pf_hashsize = PF_HASHSIZ ; if ( pf_srchashsize == 0 || ! powerof2 ( pf_srchashsize ) ) pf_srchashsize = PF_HASHSIZ / 4 ; V_pf_hashseed = arc4random ( ) ; V_pf_state_z = uma_zcreate ( " " , sizeof ( struct pf_state ) , NULL , NULL , NULL , NULL , UMA_ALIGN_PTR , 0 ) ; V_pf_limits [ PF_LIMIT_STATES ] . zone = V_pf_state_z ; uma_zone_set_max ( V_pf_state_z , PFSTATE_HIWAT ) ; uma_zone_set_warning ( V_pf_state_z , " " ) ; V_pf_state_key_z = uma_zcreate ( " " , sizeof ( struct pf_state_key ) , pf_state_key_ctor , NULL , NULL , NULL , UMA_ALIGN_PTR , 0 ) ; V_pf_keyhash = malloc ( pf_hashsize * sizeof ( struct pf_keyhash ) , M_PFHASH , M_WAITOK | M_ZERO ) ; V_pf_idhash = malloc ( pf_hashsize * sizeof ( struct pf_idhash ) , M_PFHASH , M_WAITOK | M_ZERO ) ; pf_hashmask = pf_hashsize - 1 ; for ( i = 0 , kh = V_pf_keyhash , ih = V_pf_idhash ; i <= pf_hashmask ; i ++ , kh ++ , ih ++ ) { mtx_init ( & kh -> lock , " " , NULL , MTX_DEF | MTX_DUPOK ) ; mtx_init ( & ih -> lock , " " , NULL , MTX_DEF ) ; } V_pf_sources_z = uma_zcreate ( " " , sizeof ( struct pf_src_node ) , NULL , NULL , NULL , NULL , UMA_ALIGN_PTR , 0 ) ; V_pf_limits [ PF_LIMIT_SRC_NODES ] . zone = V_pf_sources_z ; uma_zone_set_max ( V_pf_sources_z , PFSNODE_HIWAT ) ; uma_zone_set_warning ( V_pf_sources_z , " " ) ; V_pf_srchash = malloc ( pf_srchashsize * sizeof ( struct pf_srchash ) , M_PFHASH , M_WAITOK | M_ZERO ) ; pf_srchashmask = pf_srchashsize - 1 ; for ( i = 0 , sh = V_pf_srchash ; i <= pf_srchashmask ; i ++ , sh ++ ) mtx_init ( & sh -> lock , " " , NULL , MTX_DEF ) ; TAILQ_INIT ( & V_pf_altqs [ 0 ] ) ; TAILQ_INIT ( & V_pf_altqs [ 1 ] ) ; TAILQ_INIT ( & V_pf_pabuf ) ; V_pf_altqs_active = & V_pf_altqs [ 0 ] ; V_pf_altqs_inactive = & V_pf_altqs [ 1 ] ; STAILQ_INIT ( & V_pf_sendqueue ) ; SLIST_INIT ( & V_pf_overloadqueue ) ; TASK_INIT ( & V_pf_overloadtask , 0 , pf_overload_task , curvnet ) ; TAILQ_INIT ( & V_pf_unlinked_rules ) ; }
Per-vnet data storage structures initialization.
Per - vnet data storage structures initialization .
/* States and state keys storage. */ /* Source nodes. */ /* ALTQ */ /* Send & overload+flush queues. */ /* Unlinked, but may be referenced rules. */