FreeBSD/sys/netpfil/ipfw/ip_fw_sockopt.c
/*
 * Find the smallest rule >= key, id.
 * We could use bsearch but it is so simple that we code it directly
 */
Find the smallest rule >= key, id.
We could use bsearch but it is so simple that we code it directly
Find the smallest rule > = key id . We could use bsearch but it is so simple that we code it directly
int
ipfw_find_rule(struct ip_fw_chain *chain, uint32_t key, uint32_t id)
{
	int i, lo, hi;
	struct ip_fw *r;
  	for (lo = 0, hi = chain->n_rules - 1; lo < hi;) {
		i = (lo + hi) / 2;
		r = chain->map[i];
		if (r->rulenum < key)
			lo = i + 1;	
		else if (r->rulenum > key)
			hi = i;		
		else if (r->id < id)
			lo = i + 1;	
		else 
			hi = i;		
	}
	return hi;
}
int ipfw_find_rule ( struct ip_fw_chain * chain , uint32_t key , uint32_t id ) { int i , lo , hi ; struct ip_fw * r ; for ( lo = 0 , hi = chain -> n_rules - 1 ; lo < hi ; ) { i = ( lo + hi ) / 2 ; r = chain -> map [ i ] ; if ( r -> rulenum < key ) lo = i + 1 ; else if ( r -> rulenum > key ) hi = i ; else if ( r -> id < id ) lo = i + 1 ; else hi = i ; } return hi ; }
Find the smallest rule >= key, id.
Find the smallest rule > = key id .
/* continue from the next one */ /* this might be good */ /* continue from the next one */ /* r->id >= id */ /* this might be good */