bpf.c (109580) | bpf.c (109623) |
---|---|
1/* 2 * Copyright (c) 1990, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from the Stanford/CMU enet packet filter, 6 * (net/enet.c) distributed as part of 4.3BSD, and code contributed 7 * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence 8 * Berkeley Laboratory. --- 23 unchanged lines hidden (view full) --- 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)bpf.c 8.4 (Berkeley) 1/9/95 39 * | 1/* 2 * Copyright (c) 1990, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from the Stanford/CMU enet packet filter, 6 * (net/enet.c) distributed as part of 4.3BSD, and code contributed 7 * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence 8 * Berkeley Laboratory. --- 23 unchanged lines hidden (view full) --- 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)bpf.c 8.4 (Berkeley) 1/9/95 39 * |
40 * $FreeBSD: head/sys/net/bpf.c 109580 2003-01-20 19:08:46Z sam $ | 40 * $FreeBSD: head/sys/net/bpf.c 109623 2003-01-21 08:56:16Z alfred $ |
41 */ 42 43#include "opt_bpf.h" 44#include "opt_mac.h" 45#include "opt_netgraph.h" 46 47#include <sys/param.h> 48#include <sys/systm.h> --- 153 unchanged lines hidden (view full) --- 202 } 203 204 len = uio->uio_resid; 205 *datlen = len - hlen; 206 if ((unsigned)len > MCLBYTES) 207 return (EIO); 208 209 if (len > MHLEN) { | 41 */ 42 43#include "opt_bpf.h" 44#include "opt_mac.h" 45#include "opt_netgraph.h" 46 47#include <sys/param.h> 48#include <sys/systm.h> --- 153 unchanged lines hidden (view full) --- 202 } 203 204 len = uio->uio_resid; 205 *datlen = len - hlen; 206 if ((unsigned)len > MCLBYTES) 207 return (EIO); 208 209 if (len > MHLEN) { |
210 m = m_getcl(M_TRYWAIT, MT_DATA, M_PKTHDR); | 210 m = m_getcl(0, MT_DATA, M_PKTHDR); |
211 } else { | 211 } else { |
212 MGETHDR(m, M_TRYWAIT, MT_DATA); | 212 MGETHDR(m, 0, MT_DATA); |
213 } 214 if (m == NULL) 215 return (ENOBUFS); 216 m->m_pkthdr.len = m->m_len = len; 217 m->m_pkthdr.rcvif = NULL; 218 *mp = m; 219 220 /* --- 114 unchanged lines hidden (view full) --- 335 return (EBUSY); 336 } 337 dev->si_drv1 = (struct bpf_d *)~0; /* mark device in use */ 338 mtx_unlock(&bpf_mtx); 339 340 if ((dev->si_flags & SI_NAMED) == 0) 341 make_dev(&bpf_cdevsw, minor(dev), UID_ROOT, GID_WHEEL, 0600, 342 "bpf%d", dev2unit(dev)); | 213 } 214 if (m == NULL) 215 return (ENOBUFS); 216 m->m_pkthdr.len = m->m_len = len; 217 m->m_pkthdr.rcvif = NULL; 218 *mp = m; 219 220 /* --- 114 unchanged lines hidden (view full) --- 335 return (EBUSY); 336 } 337 dev->si_drv1 = (struct bpf_d *)~0; /* mark device in use */ 338 mtx_unlock(&bpf_mtx); 339 340 if ((dev->si_flags & SI_NAMED) == 0) 341 make_dev(&bpf_cdevsw, minor(dev), UID_ROOT, GID_WHEEL, 0600, 342 "bpf%d", dev2unit(dev)); |
343 MALLOC(d, struct bpf_d *, sizeof(*d), M_BPF, M_WAITOK | M_ZERO); | 343 MALLOC(d, struct bpf_d *, sizeof(*d), M_BPF, M_ZERO); |
344 dev->si_drv1 = d; 345 d->bd_bufsize = bpf_bufsize; 346 d->bd_sig = SIGIO; 347 d->bd_seesent = 1; 348#ifdef MAC 349 mac_init_bpfdesc(d); 350 mac_create_bpfdesc(td->td_ucred, d); 351#endif --- 590 unchanged lines hidden (view full) --- 942 free((caddr_t)old, M_BPF); 943 return (0); 944 } 945 flen = fp->bf_len; 946 if (flen > BPF_MAXINSNS) 947 return (EINVAL); 948 949 size = flen * sizeof(*fp->bf_insns); | 344 dev->si_drv1 = d; 345 d->bd_bufsize = bpf_bufsize; 346 d->bd_sig = SIGIO; 347 d->bd_seesent = 1; 348#ifdef MAC 349 mac_init_bpfdesc(d); 350 mac_create_bpfdesc(td->td_ucred, d); 351#endif --- 590 unchanged lines hidden (view full) --- 942 free((caddr_t)old, M_BPF); 943 return (0); 944 } 945 flen = fp->bf_len; 946 if (flen > BPF_MAXINSNS) 947 return (EINVAL); 948 949 size = flen * sizeof(*fp->bf_insns); |
950 fcode = (struct bpf_insn *)malloc(size, M_BPF, M_WAITOK); | 950 fcode = (struct bpf_insn *)malloc(size, M_BPF, 0); |
951 if (copyin((caddr_t)fp->bf_insns, (caddr_t)fcode, size) == 0 && 952 bpf_validate(fcode, (int)flen)) { 953 BPFD_LOCK(d); 954 d->bd_filter = fcode; 955 reset_d(d); 956 BPFD_UNLOCK(d); 957 if (old != 0) 958 free((caddr_t)old, M_BPF); --- 283 unchanged lines hidden (view full) --- 1242 1243/* 1244 * Initialize all nonzero fields of a descriptor. 1245 */ 1246static int 1247bpf_allocbufs(d) 1248 register struct bpf_d *d; 1249{ | 951 if (copyin((caddr_t)fp->bf_insns, (caddr_t)fcode, size) == 0 && 952 bpf_validate(fcode, (int)flen)) { 953 BPFD_LOCK(d); 954 d->bd_filter = fcode; 955 reset_d(d); 956 BPFD_UNLOCK(d); 957 if (old != 0) 958 free((caddr_t)old, M_BPF); --- 283 unchanged lines hidden (view full) --- 1242 1243/* 1244 * Initialize all nonzero fields of a descriptor. 1245 */ 1246static int 1247bpf_allocbufs(d) 1248 register struct bpf_d *d; 1249{ |
1250 d->bd_fbuf = (caddr_t)malloc(d->bd_bufsize, M_BPF, M_WAITOK); | 1250 d->bd_fbuf = (caddr_t)malloc(d->bd_bufsize, M_BPF, 0); |
1251 if (d->bd_fbuf == 0) 1252 return (ENOBUFS); 1253 | 1251 if (d->bd_fbuf == 0) 1252 return (ENOBUFS); 1253 |
1254 d->bd_sbuf = (caddr_t)malloc(d->bd_bufsize, M_BPF, M_WAITOK); | 1254 d->bd_sbuf = (caddr_t)malloc(d->bd_bufsize, M_BPF, 0); |
1255 if (d->bd_sbuf == 0) { 1256 free(d->bd_fbuf, M_BPF); 1257 return (ENOBUFS); 1258 } 1259 d->bd_slen = 0; 1260 d->bd_hlen = 0; 1261 return (0); 1262} --- 294 unchanged lines hidden --- | 1255 if (d->bd_sbuf == 0) { 1256 free(d->bd_fbuf, M_BPF); 1257 return (ENOBUFS); 1258 } 1259 d->bd_slen = 0; 1260 d->bd_hlen = 0; 1261 return (0); 1262} --- 294 unchanged lines hidden --- |