From owner-freebsd-net Tue Nov 26 12:54:26 2002 Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D2AA437B401 for ; Tue, 26 Nov 2002 12:54:23 -0800 (PST) Received: from ns1.interbgc.com (mail.interbgc.com [217.9.224.3]) by mx1.FreeBSD.org (Postfix) with SMTP id D5EDD43E9C for ; Tue, 26 Nov 2002 12:54:19 -0800 (PST) (envelope-from misho@interbgc.com) Received: (qmail 63099 invoked by alias); 26 Nov 2002 20:54:02 -0000 Message-ID: <20021126205402.63098.qmail@ns1.interbgc.com> References: <127338536921.20021126141359@netasq.com> In-Reply-To: <127338536921.20021126141359@netasq.com> From: Mihail Balikov To: Fabien THOMAS Cc: freebsd-net@freebsd.org X-Priority: 3 Subject: Re: bpf_tap problem with PKTHDR Date: Tue, 26 Nov 2002 22:54:02 +0200 Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org I found similar problem with bpf flag BIOCSSEESENT. Here is simple workaround: if_ethersubr.c: ether_input() /* Check for a BPF tap */ if (ifp->if_bpf != NULL) { /* This kludge is OK; BPF treats the "mbuf" as read-only */ struct mbuf m0; m0.m_next = m; m0.m_data = (char *)eh; m0.m_len = ETHER_HDR_LEN; /* make BOICSSEESENT happy */ m0.m_pkthdr.rcvif = ifp; bpf_mtap(ifp, &m0); } But there's no reason for such "kludge", if ethernet header is first mbuf. regards, Mihail Fabien THOMAS writes: > Hi, > > It seems there is a problem in the bpf_mtap code: > > Actually the code assume in the seesent case that mbuf will have a pkthdr structure. > > There is 2 problems here: > + they did not check for that with (m_flag & M_PKTHDR) > + at the upper level the caller forge fake mbuf that did not > contain any pkthdr and did not initialize the m_flags field > > what do you think about that ? > > if_ethersubr.c case: > > /* Check for a BPF tap */ > if (ifp->if_bpf != NULL) { > struct m_hdr mh; > > /* This kludge is OK; BPF treats the "mbuf" as read-only */ > mh.mh_next = m; > mh.mh_data = (char *)eh; > mh.mh_len = ETHER_HDR_LEN; > bpf_mtap(ifp, (struct mbuf *)&mh); > } > > > bpf_mtap function: > /* > * Incoming linkage from device drivers, when packet is in an mbuf chain. > */ > void > bpf_mtap(ifp, m) > struct ifnet *ifp; > struct mbuf *m; > { > struct bpf_if *bp = ifp->if_bpf; > struct bpf_d *d; > u_int pktlen, slen; > struct mbuf *m0; > > pktlen = 0; > for (m0 = m; m0 != 0; m0 = m0->m_next) > pktlen += m0->m_len; > > for (d = bp->bif_dlist; d != 0; d = d->bd_next) { > if (!d->bd_seesent && (m->m_pkthdr.rcvif == NULL)) > continue; > ++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); > } > } > > fabien To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message