FreeBSD/sys/netpfil/ipfw/ip_fw_sockopt.c
/*
 * Creates named hash instance.
 * Must be called without holding any locks.
 * Return pointer to new instance.
 */
Creates named hash instance.
Must be called without holding any locks.
Return pointer to new instance.
Creates named hash instance . Must be called without holding any locks . Return pointer to new instance .
struct namedobj_instance *
ipfw_objhash_create(uint32_t items)
{
	struct namedobj_instance *ni;
	int i;
	size_t size;
	size = sizeof(struct namedobj_instance) +
	    sizeof(struct namedobjects_head) * NAMEDOBJ_HASH_SIZE +
	    sizeof(struct namedobjects_head) * NAMEDOBJ_HASH_SIZE;
	ni = malloc(size, M_IPFW, M_WAITOK | M_ZERO);
	ni->nn_size = NAMEDOBJ_HASH_SIZE;
	ni->nv_size = NAMEDOBJ_HASH_SIZE;
	ni->names = (struct namedobjects_head *)(ni +1);
	ni->values = &ni->names[ni->nn_size];
	for (i = 0; i < ni->nn_size; i++)
		TAILQ_INIT(&ni->names[i]);
	for (i = 0; i < ni->nv_size; i++)
		TAILQ_INIT(&ni->values[i]);
	ni->hash_f = objhash_hash_name;
	ni->cmp_f = objhash_cmp_name;
	ipfw_objhash_bitmap_alloc(items, (void*)&ni->idx_mask, &ni->max_blocks);
	return (ni);
}
struct namedobj_instance * ipfw_objhash_create ( uint32_t items ) { struct namedobj_instance * ni ; int i ; size_t size ; size = sizeof ( struct namedobj_instance ) + sizeof ( struct namedobjects_head ) * NAMEDOBJ_HASH_SIZE + sizeof ( struct namedobjects_head ) * NAMEDOBJ_HASH_SIZE ; ni = malloc ( size , M_IPFW , M_WAITOK | M_ZERO ) ; ni -> nn_size = NAMEDOBJ_HASH_SIZE ; ni -> nv_size = NAMEDOBJ_HASH_SIZE ; ni -> names = ( struct namedobjects_head * ) ( ni + 1 ) ; ni -> values = & ni -> names [ ni -> nn_size ] ; for ( i = 0 ; i < ni -> nn_size ; i ++ ) TAILQ_INIT ( & ni -> names [ i ] ) ; for ( i = 0 ; i < ni -> nv_size ; i ++ ) TAILQ_INIT ( & ni -> values [ i ] ) ; ni -> hash_f = objhash_hash_name ; ni -> cmp_f = objhash_cmp_name ; ipfw_objhash_bitmap_alloc ( items , ( void * ) & ni -> idx_mask , & ni -> max_blocks ) ; return ( ni ) ; }
Creates named hash instance.
Creates named hash instance .
/* Set default hashing/comparison functions */ /* Allocate bitmask separately due to possible resize */