FreeBSD/sys/netpfil/pf/pf.c
/*
 * Find state by key.
 * Returns with ID hash slot locked on success.
 */
Find state by key.
Returns with ID hash slot locked on success.
Find state by key . Returns with ID hash slot locked on success .
static struct pf_state *
pf_find_state(struct pfi_kif *kif, struct pf_state_key_cmp *key, u_int dir)
{
	struct pf_keyhash	*kh;
	struct pf_state_key	*sk;
	struct pf_state		*s;
	int idx;
	counter_u64_add(V_pf_status.fcounters[FCNT_STATE_SEARCH], 1);
	kh = &V_pf_keyhash[pf_hashkey((struct pf_state_key *)key)];
	PF_HASHROW_LOCK(kh);
	LIST_FOREACH(sk, &kh->keys, entry)
		if (bcmp(sk, key, sizeof(struct pf_state_key_cmp)) == 0)
			break;
	if (sk == NULL) {
		PF_HASHROW_UNLOCK(kh);
		return (NULL);
	}
	idx = (dir == PF_IN ? PF_SK_WIRE : PF_SK_STACK);
	TAILQ_FOREACH(s, &sk->states[idx], key_list[idx])
		if (s->kif == V_pfi_all || s->kif == kif) {
			PF_STATE_LOCK(s);
			PF_HASHROW_UNLOCK(kh);
			if (s->timeout >= PFTM_MAX) {
				PF_STATE_UNLOCK(s);
				return (NULL);
			}
			return (s);
		}
	PF_HASHROW_UNLOCK(kh);
	return (NULL);
}
static struct pf_state * pf_find_state ( struct pfi_kif * kif , struct pf_state_key_cmp * key , u_int dir ) { struct pf_keyhash * kh ; struct pf_state_key * sk ; struct pf_state * s ; int idx ; counter_u64_add ( V_pf_status . fcounters [ FCNT_STATE_SEARCH ] , 1 ) ; kh = & V_pf_keyhash [ pf_hashkey ( ( struct pf_state_key * ) key ) ] ; PF_HASHROW_LOCK ( kh ) ; LIST_FOREACH ( sk , & kh -> keys , entry ) if ( bcmp ( sk , key , sizeof ( struct pf_state_key_cmp ) ) == 0 ) break ; if ( sk == NULL ) { PF_HASHROW_UNLOCK ( kh ) ; return ( NULL ) ; } idx = ( dir == PF_IN ? PF_SK_WIRE : PF_SK_STACK ) ; TAILQ_FOREACH ( s , & sk -> states [ idx ] , key_list [ idx ] ) if ( s -> kif == V_pfi_all || s -> kif == kif ) { PF_STATE_LOCK ( s ) ; PF_HASHROW_UNLOCK ( kh ) ; if ( s -> timeout >= PFTM_MAX ) { PF_STATE_UNLOCK ( s ) ; return ( NULL ) ; } return ( s ) ; } PF_HASHROW_UNLOCK ( kh ) ; return ( NULL ) ; }
Find state by key.
Find state by key .
/* List is sorted, if-bound states before floating ones. */ /*
				 * State is either being processed by
				 * pf_unlink_state() in an other thread, or
				 * is scheduled for immediate expiry.
				 */