From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 18 06:47:25 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6F6B016A407 for ; Wed, 18 Apr 2007 06:47:25 +0000 (UTC) (envelope-from yar@comp.chem.msu.su) Received: from comp.chem.msu.su (comp.chem.msu.su [158.250.32.97]) by mx1.freebsd.org (Postfix) with ESMTP id A1E2D13C4BE for ; Wed, 18 Apr 2007 06:47:24 +0000 (UTC) (envelope-from yar@comp.chem.msu.su) Received: from comp.chem.msu.su (localhost [127.0.0.1]) by comp.chem.msu.su (8.13.4/8.13.4) with ESMTP id l3I6lKDO037180; Wed, 18 Apr 2007 10:47:20 +0400 (MSD) (envelope-from yar@comp.chem.msu.su) Received: (from yar@localhost) by comp.chem.msu.su (8.13.4/8.13.4/Submit) id l3I6lKdk037178; Wed, 18 Apr 2007 10:47:20 +0400 (MSD) (envelope-from yar) Date: Wed, 18 Apr 2007 10:47:20 +0400 From: Yar Tikhiy To: Alan Garfield Message-ID: <20070418064720.GA36635@comp.chem.msu.su> References: <1176707646.5068.23.camel@hiro.auspc.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1176707646.5068.23.camel@hiro.auspc.com.au> User-Agent: Mutt/1.5.9i Cc: freebsd-hackers@freebsd.org Subject: Re: mbuf and IP frame lengths X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Apr 2007 06:47:25 -0000 On Mon, Apr 16, 2007 at 05:14:06PM +1000, Alan Garfield wrote: > Hi all! > > A question, is it ok to just say pass an entire rx buffer of your > ethernet device up the chain and let the ip stack figure out the frame > size. > > I have a device that can only ever receive 255 bytes of data, I receive > this data from a buffer in the PRS. On an interrupt I read this data out > of the PRS buffer into a local buffer, which I then :- > > ---- > eh = mtod(m, struct ether_header *); > > // Copy buf into mbuf Please use plain C comments for the sake of style(9) if you want your driver to be a good example. > bcopy(buf + 1, (char *)eh, FIFO_SIZE - 1); See below. > > // Set the header length > m->m_pkthdr.len = m->m_len = FIFO_SIZE - 1; Ditto. > JNET_UNLOCK(sc); > (*ifp->if_input)(ifp, m); > JNET_LOCK(sc); > ---- > > FIFO_SIZE = 256, minus 1 for a control character in the device (which > handily keeps under the 256 frame size). The constant 1 there is worth a symbolic name. E.g.: /* The offset of an actual Ethernet frame into the FIFO */ #define FRAME_OFFSET 1 /* XXX is frame size fixed? */ #define FRAME_SIZE (FIFO_SIZE - FRAME_OFFSET) > The interface is working just fine, but I'm not sure if I'm completely > correct in the way I'm doing this. AFAIK it's OK to pass a longer mbuf chain. E.g., real Ethernet has a limit on minimum frame size, which is 46 bytes of payload plus a header and an FCS, and Ethernet II encapsulation doesn't specify payload size; but it doesn't mean that you can't send an IPv4 packet with less than 26 bytes of IP payload over Ethernet. My only reservation is that less data could be copied from the device memory if the driver knew the actual frame size, but your device might have no such notion at all, relying on the upper layer, such as IP, to specify accurate data size. > I've tried casting the buffer to struct ip* to get ip->ip_len but I > always get a "dereferencing pointer to incomplete type" error (don't > exactly know why). Perhaps it's because your driver doesn't include all IP related headers. But in fact it shouldn't try to analyze IP headers because that isn't its job. -- Yar