FreeBSD/sys/net/bpf.c
/*
 * Detach a file from its current interface (if attached at all) and attach
 * to the interface indicated by the name stored in ifr.
 * Return an errno or 0.
 */
Detach a file from its current interface (if attached at all) and attach
to the interface indicated by the name stored in ifr.
Return an errno or 0.
Detach a file from its current interface ( if attached at all ) and attach to the interface indicated by the name stored in ifr . Return an errno or 0 .
static int
bpf_setif(struct bpf_d *d, struct ifreq *ifr)
{
	struct bpf_if *bp;
	struct ifnet *theywant;
	BPF_LOCK_ASSERT();
	theywant = ifunit(ifr->ifr_name);
	if (theywant == NULL || theywant->if_bpf == NULL)
		return (ENXIO);
	bp = theywant->if_bpf;
	BPFIF_RLOCK(bp);
	if (bp->bif_flags & BPFIF_FLAG_DYING) {
		BPFIF_RUNLOCK(bp);
		return (ENXIO);
	}
	BPFIF_RUNLOCK(bp);
	switch (d->bd_bufmode) {
	case BPF_BUFMODE_BUFFER:
	case BPF_BUFMODE_ZBUF:
		if (d->bd_sbuf == NULL)
			return (EINVAL);
		break;
	default:
		panic("bpf_setif: bufmode %d", d->bd_bufmode);
	}
	if (bp != d->bd_bif)
		bpf_attachd(d, bp);
	BPFD_LOCK(d);
	reset_d(d);
	BPFD_UNLOCK(d);
	return (0);
}
static int bpf_setif ( struct bpf_d * d , struct ifreq * ifr ) { struct bpf_if * bp ; struct ifnet * theywant ; BPF_LOCK_ASSERT ( ) ; theywant = ifunit ( ifr -> ifr_name ) ; if ( theywant == NULL || theywant -> if_bpf == NULL ) return ( ENXIO ) ; bp = theywant -> if_bpf ; BPFIF_RLOCK ( bp ) ; if ( bp -> bif_flags & BPFIF_FLAG_DYING ) { BPFIF_RUNLOCK ( bp ) ; return ( ENXIO ) ; } BPFIF_RUNLOCK ( bp ) ; switch ( d -> bd_bufmode ) { case BPF_BUFMODE_BUFFER : case BPF_BUFMODE_ZBUF : if ( d -> bd_sbuf == NULL ) return ( EINVAL ) ; break ; default : panic ( " " , d -> bd_bufmode ) ; } if ( bp != d -> bd_bif ) bpf_attachd ( d , bp ) ; BPFD_LOCK ( d ) ; reset_d ( d ) ; BPFD_UNLOCK ( d ) ; return ( 0 ) ; }
Detach a file from its current interface (if attached at all) and attach
 to the interface indicated by the name stored in ifr.
Detach a file from its current interface ( if attached at all ) and attach to the interface indicated by the name stored in ifr .
/* Check if interface is not being detached from BPF */ /*
	 * At this point, we expect the buffer is already allocated.  If not,
	 * return an error.
	 */