From owner-freebsd-current Wed Aug 9 20:32:07 1995 Return-Path: current-owner Received: (from majordom@localhost) by freefall.FreeBSD.org (8.6.11/8.6.6) id UAA14095 for current-outgoing; Wed, 9 Aug 1995 20:32:07 -0700 Received: from alpha.xerox.com (alpha.Xerox.COM [13.1.64.93]) by freefall.FreeBSD.org (8.6.11/8.6.6) with SMTP id UAA14088 for ; Wed, 9 Aug 1995 20:32:05 -0700 Received: from crevenia.parc.xerox.com ([13.2.116.11]) by alpha.xerox.com with SMTP id <17832(5)>; Wed, 9 Aug 1995 20:31:29 PDT Received: by crevenia.parc.xerox.com id <177475>; Wed, 9 Aug 1995 20:31:24 -0700 Newsgroups: comp.unix.bsd.freebsd.misc From: Bill Fenner To: freebsd-current@freebsd.org Subject: Re: Getting tcpdump to work with the BPF References: <405vs1$ito@galaxy.ee.rochester.edu> <406pje$3tu@sol.ctr.columbia.edu> Organization: Xerox Palo Alto Research Center Message-Id: <95Aug9.203124pdt.177475@crevenia.parc.xerox.com> Date: Wed, 9 Aug 1995 20:31:18 PDT Sender: current-owner@freebsd.org Precedence: bulk In article <406pje$3tu@sol.ctr.columbia.edu>, Bill Paul wrote: >You're not missing anything: it's the Intel EtherExpress 'ix' driver >that's missing something. It doesn't yet include BPF support. Although I know nothing about the EtherExpress in particular, I know what BPF needs; these patches *should* do the trick. Bill --- if_ix.c.orig Thu Aug 10 03:06:30 1995 +++ if_ix.c Thu Aug 10 03:26:52 1995 @@ -67,7 +67,6 @@ extern char all_es_snpa[], all_is_snpa[], all_l1is_snpa[], all_l2is_snpa[]; #endif /* ISO */ -/*ZZZ no work done on this, this is just here to remind me*/ #include "bpfilter.h" #if NBPFILTER > 0 #include @@ -645,6 +644,9 @@ bcopy(sc->arpcom.ac_enaddr, LLADDR(sdl), ETHER_ADDRESS_LENGTH); } printf("ix%d: address %s\n", unit, ether_sprintf(sc->arpcom.ac_enaddr)); +#if NBPFILTER > 0 + bpfattach(&sc->bpf, ifp, DLT_EN10MB, sizeof(struct ether_header)); +#endif return(0); } @@ -1253,10 +1255,6 @@ DEBUGDO(for (i = 0; i < 16; i ++) printf ("%02x", rb[i] & 0xFF);) DEBUGDO(printf(":");) DEBUGEND - /* trickery here, eh points right at memory on - * the board. eh is only used by ether_input, - * it is not passed to the upper layer */ - eh = (struct ether_header *)rb; /* here we go, lets build an mbuf chain up to hold all this */ MGETHDR(m, M_DONTWAIT, MT_DATA); @@ -1265,11 +1263,10 @@ return; } m0 = m; + eh = mtod(m, struct ether_header *); length = rbd->act_count & RBD_STAT_SIZE; - bytesleft = length - sizeof(struct ether_header); - rb += sizeof(struct ether_header); m->m_pkthdr.rcvif = ifp; - m->m_pkthdr.len = bytesleft; + m->m_pkthdr.len = length; m->m_len = MHLEN; while (bytesleft > 0) { if (bytesleft > MINCLSIZE) { @@ -1298,6 +1295,35 @@ } } +#if NBPFILTER > 0 + /* + * Check if there's a BPF listener on this interface. If so, hand off + * the raw packet to bpf. + */ + if (sc->bpf) { + bpf_mtap(sc->bpf, m); + + /* + * If we are in promiscuous mode, we have to check if + * this packet is really ours. + */ + if ((sc->arpcom.ac_if.if_flags & IFF_PROMISC) && + bcmp(eh->ether_dhost, sc->arpcom.ac_enaddr, + sizeof(eh->ether_dhost)) != 0 && + !(eh->ether_dhost.ether_addr_octet[0] & 1)) { + m_freem(m); + return; + } + } +#endif + + /* + * Remove link layer address. + */ + m->m_pkthdr.len -= sizeof(struct ether_header); + m->m_len -= sizeof(struct ether_header); + m->m_data += sizeof(struct ether_header); + ether_input(ifp, eh, m0); ifp->if_ipackets++; return; @@ -1419,6 +1445,14 @@ tb += m_temp->m_len; length += m_temp->m_len; } +#if NBPFILTER > 0 + /* This really wants to be done after the packet has been + * put on the wire, but this appears to be the easiest place + * to insert it. + */ + if (sc->bpf) + bpf_mtap(sc->bpf, m); +#endif m_freem(m); if (length < ETHER_MIN_LENGTH) length = ETHER_MIN_LENGTH; #ifdef DIAGNOSTIC