FreeBSD/sys/netpfil/pf/pf.c
/*
 * Can return locked on failure, so that we can consistently
 * allocate and insert a new one.
 */
Can return locked on failure, so that we can consistently
allocate and insert a new one.
Can return locked on failure so that we can consistently allocate and insert a new one .
struct pf_src_node *
pf_find_src_node(struct pf_addr *src, struct pf_rule *rule, sa_family_t af,
	int returnlocked)
{
	struct pf_srchash *sh;
	struct pf_src_node *n;
	counter_u64_add(V_pf_status.scounters[SCNT_SRC_NODE_SEARCH], 1);
	sh = &V_pf_srchash[pf_hashsrc(src, af)];
	PF_HASHROW_LOCK(sh);
	LIST_FOREACH(n, &sh->nodes, entry)
		if (n->rule.ptr == rule && n->af == af &&
		    ((af == AF_INET && n->addr.v4.s_addr == src->v4.s_addr) ||
		    (af == AF_INET6 && bcmp(&n->addr, src, sizeof(*src)) == 0)))
			break;
	if (n != NULL) {
		n->states++;
		PF_HASHROW_UNLOCK(sh);
	} else if (returnlocked == 0)
		PF_HASHROW_UNLOCK(sh);
	return (n);
}
struct pf_src_node * pf_find_src_node ( struct pf_addr * src , struct pf_rule * rule , sa_family_t af , int returnlocked ) { struct pf_srchash * sh ; struct pf_src_node * n ; counter_u64_add ( V_pf_status . scounters [ SCNT_SRC_NODE_SEARCH ] , 1 ) ; sh = & V_pf_srchash [ pf_hashsrc ( src , af ) ] ; PF_HASHROW_LOCK ( sh ) ; LIST_FOREACH ( n , & sh -> nodes , entry ) if ( n -> rule . ptr == rule && n -> af == af && ( ( af == AF_INET && n -> addr . v4 . s_addr == src -> v4 . s_addr ) || ( af == AF_INET6 && bcmp ( & n -> addr , src , sizeof ( * src ) ) == 0 ) ) ) break ; if ( n != NULL ) { n -> states ++ ; PF_HASHROW_UNLOCK ( sh ) ; } else if ( returnlocked == 0 ) PF_HASHROW_UNLOCK ( sh ) ; return ( n ) ; }
Can return locked on failure, so that we can consistently
 allocate and insert a new one.
Can return locked on failure so that we can consistently allocate and insert a new one .