FreeBSD/sys/netpfil/ipfw/ip_fw_sockopt.c
/*
 * Allocate and initialize skipto cache.
 */
Allocate and initialize skipto cache.
Allocate and initialize skipto cache .
void
ipfw_init_skipto_cache(struct ip_fw_chain *chain)
{
	int *idxmap, *idxmap_back;
	idxmap = malloc(65536 * sizeof(uint32_t *), M_IPFW,
	    M_WAITOK | M_ZERO);
	idxmap_back = malloc(65536 * sizeof(uint32_t *), M_IPFW,
	    M_WAITOK | M_ZERO);
	IPFW_UH_WLOCK(chain);
	if (chain->idxmap != NULL) {
		IPFW_UH_WUNLOCK(chain);
		free(idxmap, M_IPFW);
		free(idxmap_back, M_IPFW);
		return;
	}
	chain->idxmap_back = idxmap_back;
	update_skipto_cache(chain, chain->map);
	IPFW_WLOCK(chain);
	chain->idxmap = idxmap;
	swap_skipto_cache(chain);
	IPFW_WUNLOCK(chain);
	IPFW_UH_WUNLOCK(chain);
}
void ipfw_init_skipto_cache ( struct ip_fw_chain * chain ) { int * idxmap , * idxmap_back ; idxmap = malloc ( 65536 * sizeof ( uint32_t * ) , M_IPFW , M_WAITOK | M_ZERO ) ; idxmap_back = malloc ( 65536 * sizeof ( uint32_t * ) , M_IPFW , M_WAITOK | M_ZERO ) ; IPFW_UH_WLOCK ( chain ) ; if ( chain -> idxmap != NULL ) { IPFW_UH_WUNLOCK ( chain ) ; free ( idxmap , M_IPFW ) ; free ( idxmap_back , M_IPFW ) ; return ; } chain -> idxmap_back = idxmap_back ; update_skipto_cache ( chain , chain -> map ) ; IPFW_WLOCK ( chain ) ; chain -> idxmap = idxmap ; swap_skipto_cache ( chain ) ; IPFW_WUNLOCK ( chain ) ; IPFW_UH_WUNLOCK ( chain ) ; }
Allocate and initialize skipto cache.
Allocate and initialize skipto cache .
/*
	 * Note we may be called at any time after initialization,
	 * for example, on first skipto rule, so we need to
	 * provide valid chain->idxmap on return
	 */ /* Set backup pointer first to permit building cache */ /* It is now safe to set chain->idxmap ptr */