FreeBSD/sys/netgraph/netflow/netflow.c
/* Allocate memory and set up flow cache */
Allocate memory and set up flow cache
Allocate memory and set up flow cache
void
ng_netflow_cache_init(priv_p priv)
{
	struct flow_hash_entry *hsh;
	int i;
	priv->zone = uma_zcreate("NetFlow IPv4 cache",
	    sizeof(struct flow_entry), NULL, NULL, NULL, NULL,
	    UMA_ALIGN_CACHE, 0);
	uma_zone_set_max(priv->zone, CACHESIZE);
#ifdef INET6	
	priv->zone6 = uma_zcreate("NetFlow IPv6 cache",
	    sizeof(struct flow6_entry), NULL, NULL, NULL, NULL,
	    UMA_ALIGN_CACHE, 0);
	uma_zone_set_max(priv->zone6, CACHESIZE);
#endif	
	priv->hash = malloc(NBUCKETS * sizeof(struct flow_hash_entry),
	    M_NETFLOW_HASH, M_WAITOK | M_ZERO);
	for (i = 0, hsh = priv->hash; i < NBUCKETS; i++, hsh++) {
		mtx_init(&hsh->mtx, "hash mutex", NULL, MTX_DEF);
		TAILQ_INIT(&hsh->head);
	}
#ifdef INET6
	priv->hash6 = malloc(NBUCKETS * sizeof(struct flow_hash_entry),
	    M_NETFLOW_HASH, M_WAITOK | M_ZERO);
	for (i = 0, hsh = priv->hash6; i < NBUCKETS; i++, hsh++) {
		mtx_init(&hsh->mtx, "hash mutex", NULL, MTX_DEF);
		TAILQ_INIT(&hsh->head);
	}
#endif
	priv->nfinfo_bytes = counter_u64_alloc(M_WAITOK);
	priv->nfinfo_packets = counter_u64_alloc(M_WAITOK);
	priv->nfinfo_bytes6 = counter_u64_alloc(M_WAITOK);
	priv->nfinfo_packets6 = counter_u64_alloc(M_WAITOK);
	priv->nfinfo_sbytes = counter_u64_alloc(M_WAITOK);
	priv->nfinfo_spackets = counter_u64_alloc(M_WAITOK);
	priv->nfinfo_sbytes6 = counter_u64_alloc(M_WAITOK);
	priv->nfinfo_spackets6 = counter_u64_alloc(M_WAITOK);
	priv->nfinfo_act_exp = counter_u64_alloc(M_WAITOK);
	priv->nfinfo_inact_exp = counter_u64_alloc(M_WAITOK);
	ng_netflow_v9_cache_init(priv);
	CTR0(KTR_NET, "ng_netflow startup()");
}
void ng_netflow_cache_init ( priv_p priv ) { struct flow_hash_entry * hsh ; int i ; priv -> zone = uma_zcreate ( " " , sizeof ( struct flow_entry ) , NULL , NULL , NULL , NULL , UMA_ALIGN_CACHE , 0 ) ; uma_zone_set_max ( priv -> zone , CACHESIZE ) ; #ifdef INET6 priv -> zone6 = uma_zcreate ( " " , sizeof ( struct flow6_entry ) , NULL , NULL , NULL , NULL , UMA_ALIGN_CACHE , 0 ) ; uma_zone_set_max ( priv -> zone6 , CACHESIZE ) ; #endif priv -> hash = malloc ( NBUCKETS * sizeof ( struct flow_hash_entry ) , M_NETFLOW_HASH , M_WAITOK | M_ZERO ) ; for ( i = 0 , hsh = priv -> hash ; i < NBUCKETS ; i ++ , hsh ++ ) { mtx_init ( & hsh -> mtx , " " , NULL , MTX_DEF ) ; TAILQ_INIT ( & hsh -> head ) ; } #ifdef INET6 priv -> hash6 = malloc ( NBUCKETS * sizeof ( struct flow_hash_entry ) , M_NETFLOW_HASH , M_WAITOK | M_ZERO ) ; for ( i = 0 , hsh = priv -> hash6 ; i < NBUCKETS ; i ++ , hsh ++ ) { mtx_init ( & hsh -> mtx , " " , NULL , MTX_DEF ) ; TAILQ_INIT ( & hsh -> head ) ; } #endif priv -> nfinfo_bytes = counter_u64_alloc ( M_WAITOK ) ; priv -> nfinfo_packets = counter_u64_alloc ( M_WAITOK ) ; priv -> nfinfo_bytes6 = counter_u64_alloc ( M_WAITOK ) ; priv -> nfinfo_packets6 = counter_u64_alloc ( M_WAITOK ) ; priv -> nfinfo_sbytes = counter_u64_alloc ( M_WAITOK ) ; priv -> nfinfo_spackets = counter_u64_alloc ( M_WAITOK ) ; priv -> nfinfo_sbytes6 = counter_u64_alloc ( M_WAITOK ) ; priv -> nfinfo_spackets6 = counter_u64_alloc ( M_WAITOK ) ; priv -> nfinfo_act_exp = counter_u64_alloc ( M_WAITOK ) ; priv -> nfinfo_inact_exp = counter_u64_alloc ( M_WAITOK ) ; ng_netflow_v9_cache_init ( priv ) ; CTR0 ( KTR_NET , " " ) ; }
Allocate memory and set up flow cache
Allocate memory and set up flow cache
/* Initialize cache UMA zone. */ /* Allocate hash. */ /* Initialize hash. */ /* Allocate hash. */ /* Initialize hash. */