FreeBSD/sys/netpfil/ipfw/ip_fw_table.c
/*
 * Find and reference existing table optionally
 * creating new one.
 *
 * Saves found table config into @ptc.
 * Note function may drop/acquire UH_WLOCK.
 * Returns 0 if table was found/created and referenced
 * or non-zero return code.
 */
Find and reference existing table optionally
creating new one.

Saves found table config into @ptc.
Note function may drop/acquire UH_WLOCK.
Returns 0 if table was found/created and referenced
or non-zero return code.
Find and reference existing table optionally creating new one . Saves found table config into @ptc . Note function may drop / acquire UH_WLOCK . Returns 0 if table was found / created and referenced or non - zero return code .
static int
find_ref_table(struct ip_fw_chain *ch, struct tid_info *ti,
    struct tentry_info *tei, uint32_t count, int op,
    struct table_config **ptc)
{
	struct namedobj_instance *ni;
	struct table_config *tc;
	uint16_t kidx;
	int error;
	IPFW_UH_WLOCK_ASSERT(ch);
	ni = CHAIN_TO_NI(ch);
	tc = NULL;
	if ((tc = find_table(ni, ti)) != NULL) {
		if (tc->no.subtype != ti->type)
			return (EINVAL);
		if (tc->locked != 0)
			return (EACCES);
		if (op == OP_ADD && count == 1 &&
		    check_table_limit(tc, tei) != 0)
			return (EFBIG);
		tc->no.refcnt++;
		*ptc = tc;
		return (0);
	}
	if (op == OP_DEL)
		return (ESRCH);
	if ((tei->flags & TEI_FLAGS_COMPAT) == 0)
		return (ESRCH);
	IPFW_UH_WUNLOCK(ch);
	error = create_table_compat(ch, ti, &kidx);
	IPFW_UH_WLOCK(ch);
	if (error != 0)
		return (error);
	tc = (struct table_config *)ipfw_objhash_lookup_kidx(ni, kidx);
	KASSERT(tc != NULL, ("create_table_compat returned bad idx %d", kidx));
	*ptc = tc;
	return (0);
}
static int find_ref_table ( struct ip_fw_chain * ch , struct tid_info * ti , struct tentry_info * tei , uint32_t count , int op , struct table_config * * ptc ) { struct namedobj_instance * ni ; struct table_config * tc ; uint16_t kidx ; int error ; IPFW_UH_WLOCK_ASSERT ( ch ) ; ni = CHAIN_TO_NI ( ch ) ; tc = NULL ; if ( ( tc = find_table ( ni , ti ) ) != NULL ) { if ( tc -> no . subtype != ti -> type ) return ( EINVAL ) ; if ( tc -> locked != 0 ) return ( EACCES ) ; if ( op == OP_ADD && count == 1 && check_table_limit ( tc , tei ) != 0 ) return ( EFBIG ) ; tc -> no . refcnt ++ ; * ptc = tc ; return ( 0 ) ; } if ( op == OP_DEL ) return ( ESRCH ) ; if ( ( tei -> flags & TEI_FLAGS_COMPAT ) == 0 ) return ( ESRCH ) ; IPFW_UH_WUNLOCK ( ch ) ; error = create_table_compat ( ch , ti , & kidx ) ; IPFW_UH_WLOCK ( ch ) ; if ( error != 0 ) return ( error ) ; tc = ( struct table_config * ) ipfw_objhash_lookup_kidx ( ni , kidx ) ; KASSERT ( tc != NULL , ( " " , kidx ) ) ; * ptc = tc ; return ( 0 ) ; }
Find and reference existing table optionally
 creating new one.
Find and reference existing table optionally creating new one .
/* check table type */ /* Try to exit early on limit hit */ /* Reference and return */ /* Compatibility mode: create new table for old clients */ /* OK, now we've got referenced table. */