* Allocate or resize buffers. */
| 160 | * Allocate or resize buffers. |
| 161 | */ |
| 162 | int |
| 163 | bpf_buffer_ioctl_sblen(struct bpf_d *d, u_int *i) |
| 164 | { |
| 165 | u_int size; |
| 166 | caddr_t fbuf, sbuf; |
| 167 | |
| 168 | size = *i; |
| 169 | if (size > bpf_maxbufsize) |
| 170 | *i = size = bpf_maxbufsize; |
| 171 | else if (size < BPF_MINBUFSIZE) |
| 172 | *i = size = BPF_MINBUFSIZE; |
| 173 | |
| 174 | /* Allocate buffers immediately */ |
| 175 | fbuf = (caddr_t)malloc(size, M_BPF, M_WAITOK); |
| 176 | sbuf = (caddr_t)malloc(size, M_BPF, M_WAITOK); |
| 177 | |
| 178 | BPFD_LOCK(d); |
| 179 | if (d->bd_bif != NULL) { |
| 180 | /* Interface already attached, unable to change buffers */ |
| 181 | BPFD_UNLOCK(d); |
| 182 | free(fbuf, M_BPF); |
| 183 | free(sbuf, M_BPF); |
| 184 | return (EINVAL); |
| 185 | } |
| 186 | |
| 187 | /* Free old buffers if set */ |
| 188 | if (d->bd_fbuf != NULL) |
| 189 | free(d->bd_fbuf, M_BPF); |
| 190 | if (d->bd_sbuf != NULL) |
| 191 | free(d->bd_sbuf, M_BPF); |
| 192 | |
| 193 | /* Fill in new data */ |
| 194 | d->bd_bufsize = size; |
| 195 | d->bd_fbuf = fbuf; |
| 196 | d->bd_sbuf = sbuf; |
| 197 | |
| 198 | d->bd_hbuf = NULL; |
| 199 | d->bd_slen = 0; |
| 200 | d->bd_hlen = 0; |
| 201 | |
| 202 | BPFD_UNLOCK(d); |
| 203 | return (0); |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | * Copy buffer storage to user space in read(). |
no test coverage detected