Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Feb 2008 09:52:31 +0000 (GMT)
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Biks N <freebsd.dev@gmail.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: retrive data from mbuf chain
Message-ID:  <20080208094836.P3375@fledge.watson.org>
In-Reply-To: <50cd4e5f0802071222w1222d901o3ce8770b5f5725b4@mail.gmail.com>
References:  <50cd4e5f0802071222w1222d901o3ce8770b5f5725b4@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

On Thu, 7 Feb 2008, Biks N wrote:

> I am new to FreeBSD kernel programming.
>
> Currently I am trying to work on mbuf data manupulation.
>
>> From my understanding: data (payload) is stored into one or more mufs
> which are chained together through m_next pointer.
>
> Now, I need to retrive all data in mbuf chain ( mbufs linked by m_next). I 
> am working ip_output() in netinet/ip_output.c
>
> Does there exist inbuilt function/macro to retrive all the data in mbuf 
> chain?

netsmb and friends use a kernel library, mchain, to do marshalling and 
unmarashalling.  This is generally not used by lower level protocol code 
because casting to a data structure via m_pull() and mtod() generally does the 
trick.  However, for more complex protocols with conditional structuring, 
mchain can make life easier.  mdchain(9) describes functions for pulling data 
out of mbuf chains, and mbchain(9) describes functions for constructing a 
chain.  You'll need to declare a module dependency on mchain.

NAME
      mdchain, md_initm, md_done, md_append_record, md_next_record,
      md_get_uint8, md_get_uint16, md_get_uint16be, md_get_uint16le,
      md_get_uint32, md_get_uint32be, md_get_uint32le, md_get_int64,
      md_get_int64be, md_get_int64le, md_get_mem, md_get_mbuf, md_get_uio --
      set of functions to dissect an mbuf chain to various data types

NAME
      mbchain, mb_init, mb_initm, mb_done, mb_detach, mb_fixhdr, mb_reserve,
      mb_put_uint8, mb_put_uint16be, mb_put_uint16le, mb_put_uint32be,
      mb_put_uint32le, mb_put_int64be, mb_put_int64le, mb_put_mem, mb_put_mbuf,
      mb_put_uio -- set of functions to build an mbuf chain from various data
      types

I'm not sure if these routines introduce additional data copies or not, but if 
implementing an RPC-like protocol they presumably make life a lot easier.

Robert N M Watson
Computer Laboratory
University of Cambridge



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080208094836.P3375>