retrive data from mbuf chain
Robert Watson
rwatson at FreeBSD.org
Fri Feb 8 09:52:32 UTC 2008
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
More information about the freebsd-hackers
mailing list