FreeBSD/sys/net/bpf.c
/*
 * Check if we need to upgrade our descriptor @d from write-only mode.
 */
Check if we need to upgrade our descriptor @d from write-only mode.
Check if we need to upgrade our descriptor @d from write - only mode .
static int
bpf_check_upgrade(u_long cmd, struct bpf_d *d, struct bpf_insn *fcode, int flen)
{
	int is_snap, need_upgrade;
	if (d->bd_writer == 0 || fcode == NULL)
		return (0);
	need_upgrade = 0;
	if (cmd == BIOCSETF && flen == 1 && fcode[0].code == (BPF_RET | BPF_K))
		is_snap = 1;
	else
		is_snap = 0;
	if (is_snap == 0) {
		need_upgrade = 1;
	} else {
		if (--d->bd_writer == 0) {
			need_upgrade = 1;
		}
	}
	CTR5(KTR_NET,
	    "%s: filter function set by pid %d, "
	    "bd_writer counter %d, snap %d upgrade %d",
	    __func__, d->bd_pid, d->bd_writer,
	    is_snap, need_upgrade);
	return (need_upgrade);
}
static int bpf_check_upgrade ( u_long cmd , struct bpf_d * d , struct bpf_insn * fcode , int flen ) { int is_snap , need_upgrade ; if ( d -> bd_writer == 0 || fcode == NULL ) return ( 0 ) ; need_upgrade = 0 ; if ( cmd == BIOCSETF && flen == 1 && fcode [ 0 ] . code == ( BPF_RET | BPF_K ) ) is_snap = 1 ; else is_snap = 0 ; if ( is_snap == 0 ) { need_upgrade = 1 ; } else { if ( -- d -> bd_writer == 0 ) { need_upgrade = 1 ; } } CTR5 ( KTR_NET , " " " " , __func__ , d -> bd_pid , d -> bd_writer , is_snap , need_upgrade ) ; return ( need_upgrade ) ; }
Check if we need to upgrade our descriptor @d from write-only mode.
Check if we need to upgrade our descriptor @d from write - only mode .
/*
	 * Check if we've already upgraded or new filter is empty.
	 */ /*
	 * Check if cmd looks like snaplen setting from
	 * pcap_bpf.c:pcap_open_live().
	 * Note we're not checking .k value here:
	 * while pcap_open_live() definitely sets to to non-zero value,
	 * we'd prefer to treat k=0 (deny ALL) case the same way: e.g.
	 * do not consider upgrading immediately
	 */ /*
		 * We're setting first filter and it doesn't look like
		 * setting snaplen.  We're probably using bpf directly.
		 * Upgrade immediately.
		 */ /*
		 * Do not require upgrade by first BIOCSETF
		 * (used to set snaplen) by pcap_open_live().
		 */ /*
			 * First snaplen filter has already
			 * been set. This is probably catch-all
			 * filter
			 */