From owner-freebsd-hackers@FreeBSD.ORG Sun Aug 22 14:03:18 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B61C116A4CE for ; Sun, 22 Aug 2004 14:03:18 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id A797F43D45; Sun, 22 Aug 2004 14:03:18 +0000 (GMT) (envelope-from bmilekic@FreeBSD.org) Received: from freefall.freebsd.org (bmilekic@localhost [127.0.0.1]) i7ME3IHw046479; Sun, 22 Aug 2004 14:03:18 GMT (envelope-from bmilekic@freefall.freebsd.org) Received: (from bmilekic@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i7ME3Id8046478; Sun, 22 Aug 2004 14:03:18 GMT (envelope-from bmilekic) Date: Sun, 22 Aug 2004 14:03:18 +0000 From: Bosko Milekic To: Paolo Pisati , FreeBSD_Hackers Message-ID: <20040822140318.GA45977@freefall.freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i Subject: Re: Playing with mbuf in userland X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Aug 2004 14:03:18 -0000 Paolo Pisati wrote: >Hi, > >i'm developing a little app that manipulates mbuf. >Right now i'm still working on it as userland app but i >would like to test it with some real mbufs straight >from the stack. >Do you know how i can get some of these structs in >an easy way? >I mean, is it possible to copy some of these struct from >stack to userland? >Or should i fake it in userland? One way to do this would be to instrument a for-superuser-only socket option that would copy out all of the data, including the metadata and mbuf headers, out to userland, while taking care to modify references within the mbufs to userland locations {*}. To do this, in turn, you would need to obtain the userland target addresses of all mbufs and clusters you're copying out beforehand, and overwrite all mbufs' m_next, m_nextpkt, m_data, and in some cases, m_ext.ext_buf references before doing the copyout in-kernel. This can be a pretty involved copy and would require careful implementation. {*} The data is the socket buffer is kept as an mbuf chain so this is possible. Another option to look into would be to implement a sysctl(8)-exported handler that iterates over the mbuf chain and prints out the mbuf chains in something like XML, which your userland application can then more or less easily parse, and reproduce the chain ("fake it up") in userland. This solution is rather attractive because you can do all sorts of things with the intermediate-parsing-language right from the kernel, as well as from userland (at the parsing stages). To see an example of a sysctl(8) handler, refer to src/sys/vm/uma_core.c (the bottom) in FreeBSD 5.x. In any case, I would be very interested in seeing what you come up with, as this could be a very useful diagnostic tool. -Bosko -- Bosko Milekic "For the wicked / Carry us away / Captivity require from us a song / How can we sing king alpha's song in a strange land?" --Bob Marley