Deleted Added
full compact
bpf.c (147256) bpf.c (147611)
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.

--- 19 unchanged lines hidden (view full) ---

28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)bpf.c 8.4 (Berkeley) 1/9/95
35 *
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.

--- 19 unchanged lines hidden (view full) ---

28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)bpf.c 8.4 (Berkeley) 1/9/95
35 *
36 * $FreeBSD: head/sys/net/bpf.c 147256 2005-06-10 16:49:24Z brooks $
36 * $FreeBSD: head/sys/net/bpf.c 147611 2005-06-26 18:11:11Z dwmalone $
37 */
38
39#include "opt_bpf.h"
40#include "opt_mac.h"
41#include "opt_netgraph.h"
42
43#include <sys/types.h>
44#include <sys/param.h>

--- 56 unchanged lines hidden (view full) ---

101static LIST_HEAD(, bpf_if) bpf_iflist;
102static struct mtx bpf_mtx; /* bpf global lock */
103
104static int bpf_allocbufs(struct bpf_d *);
105static void bpf_attachd(struct bpf_d *d, struct bpf_if *bp);
106static void bpf_detachd(struct bpf_d *d);
107static void bpf_freed(struct bpf_d *);
108static void bpf_mcopy(const void *, void *, size_t);
37 */
38
39#include "opt_bpf.h"
40#include "opt_mac.h"
41#include "opt_netgraph.h"
42
43#include <sys/types.h>
44#include <sys/param.h>

--- 56 unchanged lines hidden (view full) ---

101static LIST_HEAD(, bpf_if) bpf_iflist;
102static struct mtx bpf_mtx; /* bpf global lock */
103
104static int bpf_allocbufs(struct bpf_d *);
105static void bpf_attachd(struct bpf_d *d, struct bpf_if *bp);
106static void bpf_detachd(struct bpf_d *d);
107static void bpf_freed(struct bpf_d *);
108static void bpf_mcopy(const void *, void *, size_t);
109static int bpf_movein(struct uio *, int,
110 struct mbuf **, struct sockaddr *, int *);
109static int bpf_movein(struct uio *, int, int,
110 struct mbuf **, struct sockaddr *);
111static int bpf_setif(struct bpf_d *, struct ifreq *);
112static void bpf_timed_out(void *);
113static __inline void
114 bpf_wakeup(struct bpf_d *);
115static void catchpacket(struct bpf_d *, u_char *, u_int,
116 u_int, void (*)(const void *, void *, size_t));
117static void reset_d(struct bpf_d *);
118static int bpf_setf(struct bpf_d *, struct bpf_program *);

--- 24 unchanged lines hidden (view full) ---

143 .d_name = "bpf",
144 .d_kqfilter = bpfkqfilter,
145};
146
147static struct filterops bpfread_filtops =
148 { 1, NULL, filt_bpfdetach, filt_bpfread };
149
150static int
111static int bpf_setif(struct bpf_d *, struct ifreq *);
112static void bpf_timed_out(void *);
113static __inline void
114 bpf_wakeup(struct bpf_d *);
115static void catchpacket(struct bpf_d *, u_char *, u_int,
116 u_int, void (*)(const void *, void *, size_t));
117static void reset_d(struct bpf_d *);
118static int bpf_setf(struct bpf_d *, struct bpf_program *);

--- 24 unchanged lines hidden (view full) ---

143 .d_name = "bpf",
144 .d_kqfilter = bpfkqfilter,
145};
146
147static struct filterops bpfread_filtops =
148 { 1, NULL, filt_bpfdetach, filt_bpfread };
149
150static int
151bpf_movein(uio, linktype, mp, sockp, datlen)
151bpf_movein(uio, linktype, mtu, mp, sockp)
152 struct uio *uio;
152 struct uio *uio;
153 int linktype, *datlen;
153 int linktype;
154 int mtu;
154 struct mbuf **mp;
155 struct sockaddr *sockp;
156{
157 struct mbuf *m;
158 int error;
159 int len;
160 int hlen;
161

--- 20 unchanged lines hidden (view full) ---

182 break;
183
184 case DLT_FDDI:
185 sockp->sa_family = AF_IMPLINK;
186 hlen = 0;
187 break;
188
189 case DLT_RAW:
155 struct mbuf **mp;
156 struct sockaddr *sockp;
157{
158 struct mbuf *m;
159 int error;
160 int len;
161 int hlen;
162

--- 20 unchanged lines hidden (view full) ---

183 break;
184
185 case DLT_FDDI:
186 sockp->sa_family = AF_IMPLINK;
187 hlen = 0;
188 break;
189
190 case DLT_RAW:
190 case DLT_NULL:
191 sockp->sa_family = AF_UNSPEC;
192 hlen = 0;
193 break;
194
191 sockp->sa_family = AF_UNSPEC;
192 hlen = 0;
193 break;
194
195 case DLT_NULL:
196 /*
197 * null interface types require a 4 byte pseudo header which
198 * corresponds to the address family of the packet.
199 */
200 sockp->sa_family = AF_UNSPEC;
201 hlen = 4;
202 break;
203
195 case DLT_ATM_RFC1483:
196 /*
197 * en atm driver requires 4-byte atm pseudo header.
198 * though it isn't standard, vpi:vci needs to be
199 * specified anyway.
200 */
201 sockp->sa_family = AF_UNSPEC;
202 hlen = 12; /* XXX 4(ATM_PH) + 3(LLC) + 5(SNAP) */

--- 4 unchanged lines hidden (view full) ---

207 hlen = 4; /* This should match PPP_HDRLEN */
208 break;
209
210 default:
211 return (EIO);
212 }
213
214 len = uio->uio_resid;
204 case DLT_ATM_RFC1483:
205 /*
206 * en atm driver requires 4-byte atm pseudo header.
207 * though it isn't standard, vpi:vci needs to be
208 * specified anyway.
209 */
210 sockp->sa_family = AF_UNSPEC;
211 hlen = 12; /* XXX 4(ATM_PH) + 3(LLC) + 5(SNAP) */

--- 4 unchanged lines hidden (view full) ---

216 hlen = 4; /* This should match PPP_HDRLEN */
217 break;
218
219 default:
220 return (EIO);
221 }
222
223 len = uio->uio_resid;
215 *datlen = len - hlen;
224
225 if (len - hlen > mtu)
226 return (EMSGSIZE);
227
216 if ((unsigned)len > MCLBYTES)
217 return (EIO);
218
219 if (len > MHLEN) {
220 m = m_getcl(M_TRYWAIT, MT_DATA, M_PKTHDR);
221 } else {
222 MGETHDR(m, M_TRYWAIT, MT_DATA);
223 }

--- 340 unchanged lines hidden (view full) ---

564 struct uio *uio;
565 int ioflag;
566{
567 struct bpf_d *d = dev->si_drv1;
568 struct ifnet *ifp;
569 struct mbuf *m;
570 int error;
571 struct sockaddr dst;
228 if ((unsigned)len > MCLBYTES)
229 return (EIO);
230
231 if (len > MHLEN) {
232 m = m_getcl(M_TRYWAIT, MT_DATA, M_PKTHDR);
233 } else {
234 MGETHDR(m, M_TRYWAIT, MT_DATA);
235 }

--- 340 unchanged lines hidden (view full) ---

576 struct uio *uio;
577 int ioflag;
578{
579 struct bpf_d *d = dev->si_drv1;
580 struct ifnet *ifp;
581 struct mbuf *m;
582 int error;
583 struct sockaddr dst;
572 int datlen;
573
574 if (d->bd_bif == NULL)
575 return (ENXIO);
576
577 ifp = d->bd_bif->bif_ifp;
578
579 if ((ifp->if_flags & IFF_UP) == 0)
580 return (ENETDOWN);
581
582 if (uio->uio_resid == 0)
583 return (0);
584
585 bzero(&dst, sizeof(dst));
584
585 if (d->bd_bif == NULL)
586 return (ENXIO);
587
588 ifp = d->bd_bif->bif_ifp;
589
590 if ((ifp->if_flags & IFF_UP) == 0)
591 return (ENETDOWN);
592
593 if (uio->uio_resid == 0)
594 return (0);
595
596 bzero(&dst, sizeof(dst));
586 error = bpf_movein(uio, (int)d->bd_bif->bif_dlt, &m, &dst, &datlen);
597 error = bpf_movein(uio, (int)d->bd_bif->bif_dlt, ifp->if_mtu, &m, &dst);
587 if (error)
588 return (error);
589
598 if (error)
599 return (error);
600
590 if (datlen > ifp->if_mtu) {
591 m_freem(m);
592 return (EMSGSIZE);
593 }
594
595 if (d->bd_hdrcmplt)
596 dst.sa_family = pseudo_AF_HDRCMPLT;
597
598#ifdef MAC
599 BPFD_LOCK(d);
600 mac_create_mbuf_from_bpfdesc(d, m);
601 BPFD_UNLOCK(d);
602#endif

--- 1099 unchanged lines hidden ---
601 if (d->bd_hdrcmplt)
602 dst.sa_family = pseudo_AF_HDRCMPLT;
603
604#ifdef MAC
605 BPFD_LOCK(d);
606 mac_create_mbuf_from_bpfdesc(d, m);
607 BPFD_UNLOCK(d);
608#endif

--- 1099 unchanged lines hidden ---