MCPcopy Create free account
hub / github.com/F-Stack/f-stack / bpf_setif

Function bpf_setif

freebsd/net/bpf.c:2053–2088  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

2051 * Return an errno or 0.
2052 */
2053static int
2054bpf_setif(struct bpf_d *d, struct ifreq *ifr)
2055{
2056 struct bpf_if *bp;
2057 struct ifnet *theywant;
2058
2059 BPF_LOCK_ASSERT();
2060
2061 theywant = ifunit(ifr->ifr_name);
2062 if (theywant == NULL || theywant->if_bpf == NULL)
2063 return (ENXIO);
2064
2065 bp = theywant->if_bpf;
2066 /*
2067 * At this point, we expect the buffer is already allocated. If not,
2068 * return an error.
2069 */
2070 switch (d->bd_bufmode) {
2071 case BPF_BUFMODE_BUFFER:
2072 case BPF_BUFMODE_ZBUF:
2073 if (d->bd_sbuf == NULL)
2074 return (EINVAL);
2075 break;
2076
2077 default:
2078 panic("bpf_setif: bufmode %d", d->bd_bufmode);
2079 }
2080 if (bp != d->bd_bif)
2081 bpf_attachd(d, bp);
2082 else {
2083 BPFD_LOCK(d);
2084 reset_d(d);
2085 BPFD_UNLOCK(d);
2086 }
2087 return (0);
2088}
2089
2090/*
2091 * Support for select() and poll() system calls

Callers 1

bpfioctlFunction · 0.85

Calls 4

ifunitFunction · 0.85
bpf_attachdFunction · 0.85
reset_dFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected