FreeBSD/sys/netpfil/ipfw/ip_fw_table.c
/*
 * Finds algorithm by index, table type or supplied name.
 *
 * Returns pointer to algo or NULL.
 */
Finds algorithm by index, table type or supplied name.
Returns pointer to algo or NULL.
Finds algorithm by index table type or supplied name . Returns pointer to algo or NULL .
static struct table_algo *
find_table_algo(struct tables_config *tcfg, struct tid_info *ti, char *name)
{
	int i, l;
	struct table_algo *ta;
	if (ti->type > IPFW_TABLE_MAXTYPE)
		return (NULL);
	if (ti->atype != 0) {
		if (ti->atype > tcfg->algo_count)
			return (NULL);
		return (tcfg->algo[ti->atype]);
	}
	if (name == NULL) {
		return (tcfg->def_algo[ti->type]);
	}
	for (i = 1; i <= tcfg->algo_count; i++) {
		ta = tcfg->algo[i];
		l = strlen(ta->name);
		if (strncmp(name, ta->name, l) != 0)
			continue;
		if (name[l] != '\0' && name[l] != ' ')
			continue;
		if (ti->type != 0 && ti->type != ta->type)
			return (NULL);
		return (ta);
	}
	return (NULL);
}
static struct table_algo * find_table_algo ( struct tables_config * tcfg , struct tid_info * ti , char * name ) { int i , l ; struct table_algo * ta ; if ( ti -> type > IPFW_TABLE_MAXTYPE ) return ( NULL ) ; if ( ti -> atype != 0 ) { if ( ti -> atype > tcfg -> algo_count ) return ( NULL ) ; return ( tcfg -> algo [ ti -> atype ] ) ; } if ( name == NULL ) { return ( tcfg -> def_algo [ ti -> type ] ) ; } for ( i = 1 ; i <= tcfg -> algo_count ; i ++ ) { ta = tcfg -> algo [ i ] ; l = strlen ( ta -> name ) ; if ( strncmp ( name , ta -> name , l ) != 0 ) continue ; if ( name [ l ] != ' \0 ' && name [ l ] != ' ' ) continue ; if ( ti -> type != 0 && ti -> type != ta -> type ) return ( NULL ) ; return ( ta ) ; } return ( NULL ) ; }
Finds algorithm by index, table type or supplied name.
Finds algorithm by index table type or supplied name .
/* Search by index */ /* Return default algorithm for given type if set */ /* Search by name */ /* TODO: better search */ /*
		 * One can supply additional algorithm
		 * parameters so we compare only the first word
		 * of supplied name:
		 * 'addr:chash hsize=32'
		 * '^^^^^^^^^'
		 *
		 */ /* Check if we're requesting proper table type */