-/* $OpenBSD: bpf.c,v 1.8 1997/02/12 03:35:11 deraadt Exp $ */
-/* $NetBSD: bpf.c,v 1.27 1996/05/07 05:26:02 thorpej Exp $ */
+/* $OpenBSD: bpf.c,v 1.9 1997/03/17 16:29:37 niklas Exp $ */
+/* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */
/*
* Copyright (c) 1990, 1991, 1993
#include <sys/protosw.h>
#include <sys/socket.h>
+#include <sys/errno.h>
+#include <sys/kernel.h>
+
#include <net/if.h>
#include <net/bpf.h>
#include <net/bpfdesc.h>
-#include <sys/errno.h>
-
#include <netinet/in.h>
#include <netinet/if_arc.h>
#include <netinet/if_ether.h>
-#include <sys/kernel.h>
/*
* Older BSDs don't have kernel malloc.
*/
#if BSD < 199103
extern bcopy();
-static caddr_t bpf_alloc();
+caddr_t bpf_alloc();
#include <net/bpf_compat.h>
#define BPF_BUFSIZE (MCLBYTES-8)
#define UIOMOVE(cp, len, code, uio) uiomove(cp, len, code, uio)
struct bpf_if *bpf_iflist;
struct bpf_d bpf_dtab[NBPFILTER];
-static int bpf_allocbufs __P((struct bpf_d *));
-static int bpf_allocbufs __P((struct bpf_d *));
-static void bpf_freed __P((struct bpf_d *));
-static void bpf_freed __P((struct bpf_d *));
-static void bpf_ifname __P((struct ifnet *, struct ifreq *));
-static void bpf_ifname __P((struct ifnet *, struct ifreq *));
-static void bpf_mcopy __P((const void *, void *, size_t));
-static int bpf_movein __P((struct uio *, int,
- struct mbuf **, struct sockaddr *));
-static void bpf_attachd __P((struct bpf_d *, struct bpf_if *));
-static void bpf_detachd __P((struct bpf_d *));
-static int bpf_setif __P((struct bpf_d *, struct ifreq *));
-static int bpf_setif __P((struct bpf_d *, struct ifreq *));
+int bpf_allocbufs __P((struct bpf_d *));
+void bpf_freed __P((struct bpf_d *));
+void bpf_ifname __P((struct ifnet *, struct ifreq *));
+void bpf_mcopy __P((const void *, void *, size_t));
+int bpf_movein __P((struct uio *, int, struct mbuf **, struct sockaddr *));
+void bpf_attachd __P((struct bpf_d *, struct bpf_if *));
+void bpf_detachd __P((struct bpf_d *));
+int bpf_setif __P((struct bpf_d *, struct ifreq *));
#if BSD >= 199103
-int bpfselect __P((dev_t, int, struct proc *));
+int bpfselect __P((dev_t, int, struct proc *));
#endif
-static __inline void
- bpf_wakeup __P((struct bpf_d *));
-static void catchpacket __P((struct bpf_d *, u_char *, size_t, size_t,
- void (*)(const void *, void *, size_t)));
-static void reset_d __P((struct bpf_d *));
+static __inline void bpf_wakeup __P((struct bpf_d *));
+void bpf_catchpacket __P((struct bpf_d *, u_char *, size_t, size_t,
+ void (*)(const void *, void *, size_t)));
+void bpf_reset_d __P((struct bpf_d *));
-static int
+int
bpf_movein(uio, linktype, mp, sockp)
register struct uio *uio;
int linktype;
* Attach file to the bpf interface, i.e. make d listen on bp.
* Must be called at splimp.
*/
-static void
+void
bpf_attachd(d, bp)
struct bpf_d *d;
struct bpf_if *bp;
/*
* Detach a file from its interface.
*/
-static void
+void
bpf_detachd(d)
struct bpf_d *d;
{
* Support for SunOS, which does not have tsleep.
*/
#if BSD < 199103
-static
+int
bpf_timeout(arg)
caddr_t arg;
{
* Reset a descriptor by flushing its packet buffer and clearing the
* receive and drop counts. Should be called at splimp.
*/
-static void
-reset_d(d)
+void
+bpf_reset_d(d)
struct bpf_d *d;
{
if (d->bd_hbuf) {
*/
case BIOCFLUSH:
s = splimp();
- reset_d(d);
+ bpf_reset_d(d);
splx(s);
break;
return (EINVAL);
s = splimp();
d->bd_filter = 0;
- reset_d(d);
+ bpf_reset_d(d);
splx(s);
if (old != 0)
free((caddr_t)old, M_DEVBUF);
bpf_validate(fcode, (int)flen)) {
s = splimp();
d->bd_filter = fcode;
- reset_d(d);
+ bpf_reset_d(d);
splx(s);
if (old != 0)
free((caddr_t)old, M_DEVBUF);
* to the interface indicated by the name stored in ifr.
* Return an errno or 0.
*/
-static int
+int
bpf_setif(d, ifr)
struct bpf_d *d;
struct ifreq *ifr;
bpf_attachd(d, bp);
}
- reset_d(d);
+ bpf_reset_d(d);
splx(s);
return (0);
}
/*
* Copy the interface name to the ifreq.
*/
-static void
+void
bpf_ifname(ifp, ifr)
struct ifnet *ifp;
struct ifreq *ifr;
{
-
bcopy(ifp->if_xname, ifr->ifr_name, IFNAMSIZ);
}
++d->bd_rcount;
slen = bpf_filter(d->bd_filter, pkt, pktlen, pktlen);
if (slen != 0)
- catchpacket(d, pkt, pktlen, slen, bcopy);
+ bpf_catchpacket(d, pkt, pktlen, slen, bcopy);
}
}
* Copy data from an mbuf chain into a buffer. This code is derived
* from m_copydata in sys/uipc_mbuf.c.
*/
-static void
+void
bpf_mcopy(src_arg, dst_arg, len)
const void *src_arg;
void *dst_arg;
++d->bd_rcount;
slen = bpf_filter(d->bd_filter, (u_char *)m, pktlen, 0);
if (slen != 0)
- catchpacket(d, (u_char *)m, pktlen, slen, bpf_mcopy);
+ bpf_catchpacket(d, (u_char *)m, pktlen, slen, bpf_mcopy);
}
}
* bpf_mcopy is passed in to copy mbuf chains. In the latter case,
* pkt is really an mbuf.
*/
-static void
-catchpacket(d, pkt, pktlen, snaplen, cpfn)
+void
+bpf_catchpacket(d, pkt, pktlen, snaplen, cpfn)
register struct bpf_d *d;
register u_char *pkt;
register size_t pktlen, snaplen;
/*
* Initialize all nonzero fields of a descriptor.
*/
-static int
+int
bpf_allocbufs(d)
register struct bpf_d *d;
{
* Free buffers currently in use by a descriptor.
* Called on close.
*/
-static void
+void
bpf_freed(d)
register struct bpf_d *d;
{
* is admittedly a hack.
* If resources unavaiable, return 0.
*/
-static caddr_t
+caddr_t
bpf_alloc(size, canwait)
register int size;
register int canwait;