FreeBSD/sys/net/bpf.c
/*
 * Attach file to the bpf interface, i.e. make d listen on bp.
 */
Attach file to the bpf interface, i.e. make d listen on bp.
Attach file to the bpf interface i . e . make d listen on bp .
static void
bpf_attachd(struct bpf_d *d, struct bpf_if *bp)
{
	int op_w;
	BPF_LOCK_ASSERT();
	op_w = V_bpf_optimize_writers || d->bd_writer;
	if (d->bd_bif != NULL)
		bpf_detachd_locked(d);
	BPFIF_WLOCK(bp);
	BPFD_LOCK(d);
	d->bd_bif = bp;
	if (op_w != 0) {
		LIST_INSERT_HEAD(&bp->bif_wlist, d, bd_next);
		d->bd_writer = 2;
	} else
		LIST_INSERT_HEAD(&bp->bif_dlist, d, bd_next);
	BPFD_UNLOCK(d);
	BPFIF_WUNLOCK(bp);
	bpf_bpfd_cnt++;
	CTR3(KTR_NET, "%s: bpf_attach called by pid %d, adding to %s list",
	    __func__, d->bd_pid, d->bd_writer ? "writer" : "active");
	if (op_w == 0)
		EVENTHANDLER_INVOKE(bpf_track, bp->bif_ifp, bp->bif_dlt, 1);
}
static void bpf_attachd ( struct bpf_d * d , struct bpf_if * bp ) { int op_w ; BPF_LOCK_ASSERT ( ) ; op_w = V_bpf_optimize_writers || d -> bd_writer ; if ( d -> bd_bif != NULL ) bpf_detachd_locked ( d ) ; BPFIF_WLOCK ( bp ) ; BPFD_LOCK ( d ) ; d -> bd_bif = bp ; if ( op_w != 0 ) { LIST_INSERT_HEAD ( & bp -> bif_wlist , d , bd_next ) ; d -> bd_writer = 2 ; } else LIST_INSERT_HEAD ( & bp -> bif_dlist , d , bd_next ) ; BPFD_UNLOCK ( d ) ; BPFIF_WUNLOCK ( bp ) ; bpf_bpfd_cnt ++ ; CTR3 ( KTR_NET , " " , __func__ , d -> bd_pid , d -> bd_writer ? " " : " " ) ; if ( op_w == 0 ) EVENTHANDLER_INVOKE ( bpf_track , bp -> bif_ifp , bp -> bif_dlt , 1 ) ; }
Attach file to the bpf interface, i.e.
Attach file to the bpf interface i . e .
/*
	 * Save sysctl value to protect from sysctl change
	 * between reads
	 */ /*
	 * Point d at bp, and add d to the interface's list.
	 * Since there are many applications using BPF for
	 * sending raw packets only (dhcpd, cdpd are good examples)
	 * we can delay adding d to the list of active listeners until
	 * some filter is configured.
	 */ /* Add to writers-only list */ /*
		 * We decrement bd_writer on every filter set operation.
		 * First BIOCSETF is done by pcap_open_live() to set up
		 * snap length. After that appliation usually sets its own filter
		 */