* 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. */
| 2051 | * Return an errno or 0. |
| 2052 | */ |
| 2053 | static int |
| 2054 | bpf_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 |
no test coverage detected