From owner-freebsd-current@FreeBSD.ORG Tue Aug 28 21:29:27 2007 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 430F216A417; Tue, 28 Aug 2007 21:29:27 +0000 (UTC) (envelope-from thompsa@FreeBSD.org) Received: from heff.fud.org.nz (203-109-251-39.static.bliink.ihug.co.nz [203.109.251.39]) by mx1.freebsd.org (Postfix) with ESMTP id 49B6613C457; Tue, 28 Aug 2007 21:29:26 +0000 (UTC) (envelope-from thompsa@FreeBSD.org) Received: by heff.fud.org.nz (Postfix, from userid 1001) id 2FC7A1CC58; Wed, 29 Aug 2007 09:29:24 +1200 (NZST) Date: Wed, 29 Aug 2007 09:29:24 +1200 From: Andrew Thompson To: "Bruce M. Simpson" Message-ID: <20070828212924.GB43049@heff.fud.org.nz> References: <20070828040026.GB42201@heff.fud.org.nz> <46D3C9F3.2010802@FreeBSD.org> <20070828103110.GA43049@heff.fud.org.nz> <46D483F2.2040207@FreeBSD.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="G4iJoqBmSsgzjUCe" Content-Disposition: inline In-Reply-To: <46D483F2.2040207@FreeBSD.org> User-Agent: Mutt/1.5.13 (2006-08-11) Cc: FreeBSD Current Subject: Re: multicast packets from bpf X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Aug 2007 21:29:27 -0000 --G4iJoqBmSsgzjUCe Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Aug 28, 2007 at 09:22:10PM +0100, Bruce M. Simpson wrote: > Andrew Thompson wrote: > >I had originally started to put it there but realised that I need a > >pointer to the ifnet to read if_broadcastaddr, I didnt think it was > >worth changing the function parameters when the check can also just go > >in bpfwrite. I dont mind moving it if its the more correct place to put > >it. > > > > It's already got a switch..case breakout for the DLTs and knows how to > grok the 802.11 header format which can have up to 6 (yes, 6) 802.3 > style MAC addresses, all of which mean different things depending on > whether you are STA, AP, Mesh Portal, Mesh AP... :-) > > So it seems like the right place. bpf_movein() is static and referenced > once within its translation unit, so it is a candidate for inlining; I > would change ifp-?if_mtu to ifp in the call. The patch has been updated (attached). > >Is the tapwrite patch still needed? The mbuf is passed to ether_input > >which should do the right thing. > > > > Good point. A casual reading suggests it *may* no longer be needed since > my pass over ether_input(), but seeing as we're due to branch and all, > I'll leave garbage collecting the 10 lines in tapwrite() to someone > else. :-) I would leave it there for the moment. Andrew --G4iJoqBmSsgzjUCe Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="bpf_mcast2.diff" Index: bpf.c =================================================================== RCS file: /home/ncvs/src/sys/net/bpf.c,v retrieving revision 1.180 diff -u -p -r1.180 bpf.c --- bpf.c 6 Aug 2007 14:26:00 -0000 1.180 +++ bpf.c 28 Aug 2007 21:22:59 -0000 @@ -102,7 +102,7 @@ static void bpf_attachd(struct bpf_d *, static void bpf_detachd(struct bpf_d *); static void bpf_freed(struct bpf_d *); static void bpf_mcopy(const void *, void *, size_t); -static int bpf_movein(struct uio *, int, int, struct mbuf **, +static int bpf_movein(struct uio *, int, struct ifnet *, struct mbuf **, struct sockaddr *, int *, struct bpf_insn *); static int bpf_setif(struct bpf_d *, struct ifreq *); static void bpf_timed_out(void *); @@ -158,10 +158,11 @@ static struct filterops bpfread_filtops { 1, NULL, filt_bpfdetach, filt_bpfread }; static int -bpf_movein(struct uio *uio, int linktype, int mtu, struct mbuf **mp, +bpf_movein(struct uio *uio, int linktype, struct ifnet *ifp, struct mbuf **mp, struct sockaddr *sockp, int *hdrlen, struct bpf_insn *wfilter) { const struct ieee80211_bpf_params *p; + struct ether_header *eh; struct mbuf *m; int error; int len; @@ -241,7 +242,7 @@ bpf_movein(struct uio *uio, int linktype len = uio->uio_resid; - if (len - hlen > mtu) + if (len - hlen > ifp->if_mtu) return (EMSGSIZE); if ((unsigned)len > MCLBYTES) @@ -273,6 +274,20 @@ bpf_movein(struct uio *uio, int linktype goto bad; } + /* Check for multicast destination */ + switch (linktype) { + case DLT_EN10MB: + eh = mtod(m, struct ether_header *); + if (ETHER_IS_MULTICAST(eh->ether_dhost)) { + if (bcmp(ifp->if_broadcastaddr, eh->ether_dhost, + ETHER_ADDR_LEN) == 0) + m->m_flags |= M_BCAST; + else + m->m_flags |= M_MCAST; + } + break; + } + /* * Make room for link header, and copy it to sockaddr */ @@ -615,7 +630,7 @@ bpfwrite(struct cdev *dev, struct uio *u bzero(&dst, sizeof(dst)); m = NULL; hlen = 0; - error = bpf_movein(uio, (int)d->bd_bif->bif_dlt, ifp->if_mtu, + error = bpf_movein(uio, (int)d->bd_bif->bif_dlt, ifp, &m, &dst, &hlen, d->bd_wfilter); if (error) return (error); --G4iJoqBmSsgzjUCe--