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

Function bpf_buffer_ioctl_sblen

freebsd/net/bpf_buffer.c:162–204  ·  view source on GitHub ↗

* Allocate or resize buffers. */

Source from the content-addressed store, hash-verified

160 * Allocate or resize buffers.
161 */
162int
163bpf_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().

Callers 2

bpf_ioctl_sblenFunction · 0.85
bpfioctlFunction · 0.85

Calls 2

mallocFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected