Subject: new mbuf API
To: None <tech-net@netbsd.org>
From: Pavel Cahyna <pavel@NetBSD.org>
List: tech-net
Date: 04/20/2007 17:24:53
Hello,

I would like to commit the new mbuf API, resulting from last year SoC
project, reasonably soon. I described it in an old message:
http://permalink.gmane.org/gmane.os.netbsd.devel.network/7959
so I won't repeat much here.

Since then, I've only swapped the arguments "datatype" with "off" and "len"
with "off", as suggested in that message.

What I've missed there was a description of "guaranteed contiguous
data". The problem is that one function can make part of the mbuf chanin
contiguous (like m_pulldown or one of the new functions), but a
subsequent call can fragment the chain again. To prevent this, I have
introduced the notion of "guaranteed contiguous data". If a function
makes a range of a mbuf chain contiguous, it also marks it as a
guaranteed contiguous region and subsequent calls to mbuf rearranging
functions must keep it contiguous.

Unfortunately m_pulldown can't respect it in all cases: if the
guaranteed contiguous region extends say from byte 0 to byte 20 and
m_pulldown is called to make data contiguous between 10 and 40, it may
need to copy to a new mbuf and it should copy everything between 0 and
40 to respect the former guaranteed contiguous region. But it can't copy
the data between 0 and 10 because m_pulldown is not supposed to touch
the data before the offset "off" where is it told to start (10 in this
case). It is expected that code needing the new feature will use the new
functions instead of m_pulldown.

Another improvement is that m_copyback_cow now supports mbuf chain
expansion, and a bug in this function has been fixed.

The code is at
http://netbsd-soc.sourceforge.net/projects/mbuf/userland/mbuf_impl/sys/,
the two .c files belong under src/sys/kern, mbuf.h under src/sys/sys. As
this changes the implementation of some currently used functions, I would
appreciate some testing, especially of IPv6 and IPSEC.

Pavel