2003-02-25 13:34:36 +03:00
|
|
|
.\" $NetBSD: mbuf.9,v 1.26 2003/02/25 10:35:34 wiz Exp $
|
1997-10-04 18:04:15 +04:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" This documentation is derived from text contributed to The NetBSD Foundation
|
|
|
|
.\" by S.P.Zeidler (aka stargazer).
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by the NetBSD
|
|
|
|
.\" Foundation, Inc. and its contributors.
|
|
|
|
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
.\" contributors may be used to endorse or promote products derived
|
|
|
|
.\" from this software without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
.\"
|
1998-04-22 11:14:30 +04:00
|
|
|
.Dd October 3, 1997
|
1997-10-04 18:04:15 +04:00
|
|
|
.Dt MBUF 9
|
1999-03-16 03:40:46 +03:00
|
|
|
.Os
|
1997-10-04 18:04:15 +04:00
|
|
|
.Sh NAME
|
1997-11-27 09:17:58 +03:00
|
|
|
.Nm mbuf ,
|
1997-11-12 03:47:32 +03:00
|
|
|
.Nm m_get ,
|
|
|
|
.Nm m_getclr ,
|
|
|
|
.Nm m_gethdr ,
|
|
|
|
.Nm m_devget ,
|
|
|
|
.Nm m_copym ,
|
|
|
|
.Nm m_copypacket ,
|
|
|
|
.Nm m_copydata ,
|
|
|
|
.Nm m_copyback ,
|
|
|
|
.Nm m_cat ,
|
2000-10-13 08:19:58 +04:00
|
|
|
.Nm m_dup ,
|
1997-11-12 03:47:32 +03:00
|
|
|
.Nm m_prepend ,
|
2001-06-29 03:02:47 +04:00
|
|
|
.Nm m_pulldown ,
|
1997-11-12 03:47:32 +03:00
|
|
|
.Nm m_pullup ,
|
|
|
|
.Nm m_split ,
|
|
|
|
.Nm m_adj ,
|
|
|
|
.Nm m_free ,
|
|
|
|
.Nm m_freem ,
|
|
|
|
.Nm mtod ,
|
|
|
|
.Nm mtocl ,
|
|
|
|
.Nm cltom ,
|
|
|
|
.Nm MGET ,
|
|
|
|
.Nm MGETHDR ,
|
|
|
|
.Nm MEXTMALLOC ,
|
|
|
|
.Nm MEXTADD ,
|
|
|
|
.Nm MCLGET ,
|
|
|
|
.Nm M_COPY_PKTHDR ,
|
|
|
|
.Nm M_ALIGN ,
|
|
|
|
.Nm MH_ALIGN ,
|
|
|
|
.Nm M_LEADINGSPACE ,
|
|
|
|
.Nm M_TRAILINGSPACE ,
|
|
|
|
.Nm M_PREPEND ,
|
|
|
|
.Nm MCHTYPE ,
|
|
|
|
.Nm MEXTREMOVE ,
|
|
|
|
.Nm MFREE ,
|
1999-11-19 04:12:39 +03:00
|
|
|
.Nd "functions and macros for managing memory used by networking code"
|
1997-10-04 18:04:15 +04:00
|
|
|
.Sh SYNOPSIS
|
2002-02-13 11:17:26 +03:00
|
|
|
.Fd #include \*[Lt]sys/mbuf.h\*[Gt]
|
1997-10-04 18:04:15 +04:00
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_get "int nowait" "int type"
|
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_getclr "int nowait" "int type"
|
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_gethdr "int nowait" "int type"
|
|
|
|
.Ft struct mbuf *
|
2001-11-28 19:39:35 +03:00
|
|
|
.Fn m_devget "char *buf" "int totlen" "int off0" "struct ifnet *ifp" "void (*copy)(const void *, void *, size_t)"
|
1997-10-04 18:04:15 +04:00
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_copym "struct mbuf *m" "int off0" "int len" "int wait"
|
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_copypacket "struct mbuf *m" "int how"
|
|
|
|
.Ft void
|
|
|
|
.Fn m_copydata "struct mbuf *m" "int off" "int len" "caddr_t cp"
|
|
|
|
.Ft void
|
|
|
|
.Fn m_copyback "struct mbuf *m0" "int off" "int len" "caddr_t cp"
|
|
|
|
.Ft void
|
|
|
|
.Fn m_cat "struct mbuf *m" "struct mbuf *n"
|
|
|
|
.Ft struct mbuf *
|
2000-10-13 08:19:58 +04:00
|
|
|
.Fn m_dup "struct mbuf *m" "int off0" "int len" "int wait"
|
|
|
|
.Ft struct mbuf *
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fn m_prepend "struct mbuf *m" "int len" "int how"
|
|
|
|
.Ft struct mbuf *
|
2002-05-12 19:48:36 +04:00
|
|
|
.Fn m_pulldown "struct mbuf *m" "int off" "int len" "int *offp"
|
2001-06-29 03:02:47 +04:00
|
|
|
.Ft struct mbuf *
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fn m_pullup "struct mbuf *n" "int len"
|
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_split "struct mbuf *m0" "int len0" "int wait"
|
|
|
|
.Ft void
|
|
|
|
.Fn m_adj "struct mbuf *mp" "int req_len"
|
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_free "struct mbuf *m"
|
|
|
|
.Ft void
|
|
|
|
.Fn m_freem "struct mbuf *m"
|
2001-06-17 16:36:14 +04:00
|
|
|
.Ft datatype
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fn mtod "struct mbuf *m" "datatype"
|
|
|
|
.Ft u_long
|
|
|
|
.Fn mtocl "void *datapointer"
|
|
|
|
.Ft caddr_t
|
|
|
|
.Fn cltom "u_long clusternum"
|
|
|
|
.Ft void
|
|
|
|
.Fn MGET "struct mbuf *m" "int how" "int type"
|
|
|
|
.Ft void
|
|
|
|
.Fn MGETHDR "struct mbuf *m" "int how" "int type"
|
|
|
|
.Ft void
|
|
|
|
.Fn MEXTMALLOC "struct mbuf *m" "int len" "int how"
|
|
|
|
.Ft void
|
2001-11-28 22:14:56 +03:00
|
|
|
.Fn MEXTADD "struct mbuf *m" "caddr_t buf" "int size" "int type" "void (*free)(caddr_t, u_int, void *)" "void *arg"
|
1997-10-04 18:04:15 +04:00
|
|
|
.Ft void
|
|
|
|
.Fn MCLGET "struct mbuf *m" "int how"
|
|
|
|
.Ft void
|
|
|
|
.Fn M_COPY_PKTHDR "struct mbuf *to" "struct mbuf *from"
|
|
|
|
.Ft void
|
|
|
|
.Fn M_ALIGN "struct mbuf *m" "int len"
|
|
|
|
.Ft void
|
|
|
|
.Fn MH_ALIGN "struct mbuf *m" "int len"
|
|
|
|
.Ft int
|
|
|
|
.Fn M_LEADINGSPACE "struct mbuf *m"
|
|
|
|
.Ft int
|
|
|
|
.Fn M_TRAILINGSPACE "struct mbuf *m"
|
|
|
|
.Ft void
|
|
|
|
.Fn M_PREPEND "struct mbuf *m" "int plen" "int how"
|
|
|
|
.Ft void
|
|
|
|
.Fn MCHTYPE "struct mbuf *m" "int type"
|
|
|
|
.Ft void
|
|
|
|
.Fn MEXTREMOVE "struct mbuf *m"
|
|
|
|
.Ft void
|
|
|
|
.Fn MFREE "struct mbuf *m" "struct mbuf *n"
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
functions and macros provide an easy and consistent way to handle
|
|
|
|
a networking stack's memory management needs.
|
|
|
|
An
|
2000-11-07 09:43:24 +03:00
|
|
|
.Nm
|
1997-10-04 18:04:15 +04:00
|
|
|
consists of a header and a data area.
|
|
|
|
It is of a fixed size,
|
|
|
|
.Dv MSIZE
|
1997-11-27 09:17:58 +03:00
|
|
|
.Pq defined in Aq Pa machine/param.h ,
|
1997-10-04 18:04:15 +04:00
|
|
|
which includes overhead.
|
|
|
|
The header contains a pointer to the next
|
2000-11-07 09:43:24 +03:00
|
|
|
.Nm
|
1997-10-04 18:04:15 +04:00
|
|
|
in the
|
2000-11-07 09:43:24 +03:00
|
|
|
.Sq "mbuf chain" ,
|
1997-10-04 18:04:15 +04:00
|
|
|
a pointer to the next
|
2000-11-07 09:43:24 +03:00
|
|
|
.Sq "mbuf chain" ,
|
1997-10-04 18:04:15 +04:00
|
|
|
a pointer to the data area, the amount of data in this mbuf, its type
|
1997-11-27 09:17:58 +03:00
|
|
|
and a
|
1997-10-04 18:04:15 +04:00
|
|
|
.Dv flags
|
1997-11-27 09:17:58 +03:00
|
|
|
field.
|
1997-10-04 18:04:15 +04:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Dv type
|
|
|
|
variable can signify:
|
|
|
|
.Bl -tag -compact -offset indent -width "XXXXXXXXXXX"
|
|
|
|
.It Dv MT_FREE
|
|
|
|
the mbuf should be on the ``free'' list
|
|
|
|
.It Dv MT_DATA
|
|
|
|
data was dynamically allocated
|
|
|
|
.It Dv MT_HEADER
|
|
|
|
data is a packet header
|
|
|
|
.It Dv MT_SONAME
|
|
|
|
data is a socket name
|
|
|
|
.It Dv MT_SOOPTS
|
|
|
|
data is socket options
|
|
|
|
.It Dv MT_FTABLE
|
1997-11-27 09:17:58 +03:00
|
|
|
data is the fragment reassembly header
|
1997-10-04 18:04:15 +04:00
|
|
|
.It Dv MT_CONTROL
|
|
|
|
mbuf contains ancillary \&(protocol control\&) data
|
|
|
|
.It Dv MT_OOBDATA
|
|
|
|
mbuf contains out-of-band data.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Dv flags
|
|
|
|
variable contains information describing the
|
2003-02-25 13:34:36 +03:00
|
|
|
.Nm ,
|
1997-10-04 18:04:15 +04:00
|
|
|
notably:
|
|
|
|
.Bl -tag -compact -offset indent -width "XXXXXXXXXXX"
|
|
|
|
.It Dv M_EXT
|
|
|
|
has external storage
|
|
|
|
.It Dv M_PKTHDR
|
|
|
|
is start of record
|
|
|
|
.It Dv M_EOR
|
|
|
|
is end of record
|
|
|
|
.It Dv M_CLUSTER
|
|
|
|
external storage is a cluster.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
If an
|
2000-11-07 09:43:24 +03:00
|
|
|
.Nm
|
1997-10-04 18:04:15 +04:00
|
|
|
designates the start of a record
|
1997-11-27 09:17:58 +03:00
|
|
|
.Pq Dv M_PKTHDR ,
|
1997-10-04 18:04:15 +04:00
|
|
|
its
|
|
|
|
.Dv flags
|
1997-11-27 09:17:58 +03:00
|
|
|
field may contain additional information describing the content of
|
1997-10-04 18:04:15 +04:00
|
|
|
the record:
|
|
|
|
.Bl -tag -compact -offset indent -width "XXXXXXXXXXX"
|
|
|
|
.It Dv M_BCAST
|
|
|
|
sent/received as link-level broadcast
|
|
|
|
.It Dv M_MCAST
|
|
|
|
sent/received as link-level multicast
|
2000-08-14 21:34:12 +04:00
|
|
|
.It Dv M_LINK0 ,
|
|
|
|
.It Dv M_LINK1 ,
|
|
|
|
.It Dv M_LINK2
|
1997-10-04 18:04:15 +04:00
|
|
|
three link-level specific flags.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
An
|
2000-11-07 09:43:24 +03:00
|
|
|
.Nm
|
1997-10-04 18:04:15 +04:00
|
|
|
may add a single
|
2000-11-07 09:43:24 +03:00
|
|
|
.Sq "mbuf cluster"
|
1997-10-04 18:04:15 +04:00
|
|
|
of
|
|
|
|
.Dv MCLBYTES
|
1997-11-27 09:17:58 +03:00
|
|
|
bytes
|
|
|
|
.Pq also defined in Aq Pa machine/param.h ,
|
|
|
|
which has no additional overhead
|
1997-10-04 18:04:15 +04:00
|
|
|
and is used instead of the internal data area; this is done when at least
|
|
|
|
.Dv MINCLSIZE
|
|
|
|
bytes of data must be stored.
|
2000-10-13 08:19:58 +04:00
|
|
|
.Pp
|
|
|
|
When the
|
|
|
|
.Dv M_EXT
|
|
|
|
flag is raised for an mbuf,
|
|
|
|
the external storage area could be shared among multiple mbufs.
|
|
|
|
Be careful when you attempt to overwrite the data content of the mbuf.
|
1997-10-04 18:04:15 +04:00
|
|
|
.Bl -tag -width compact
|
|
|
|
.It Fn m_get "int nowait" "int type"
|
1999-03-07 01:09:29 +03:00
|
|
|
Allocates an mbuf and initializes it to contain internal data.
|
|
|
|
The
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa nowait
|
|
|
|
parameter is a choice of
|
|
|
|
.Dv M_WAIT / M_DONTWAIT
|
|
|
|
from caller.
|
|
|
|
.Dv M_WAIT
|
1999-03-07 01:09:29 +03:00
|
|
|
means the call cannot fail, but may take forever.
|
|
|
|
The
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa type
|
|
|
|
parameter is an mbuf type.
|
|
|
|
.It Fn m_getclr "int nowait" "int type"
|
1997-11-27 09:17:58 +03:00
|
|
|
Allocates an mbuf and initializes it to contain internal data, then
|
1999-03-07 01:09:29 +03:00
|
|
|
zeros the data area.
|
|
|
|
The
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa nowait
|
|
|
|
parameter is a choice of
|
|
|
|
.Dv M_WAIT / M_DONTWAIT
|
1999-03-07 01:09:29 +03:00
|
|
|
from caller.
|
|
|
|
The
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa type
|
|
|
|
parameter is an mbuf type.
|
|
|
|
.It Fn m_gethdr "int nowait" "int type"
|
|
|
|
Allocates an mbuf and initializes it to contain a packet header and internal
|
1999-03-07 01:09:29 +03:00
|
|
|
data.
|
|
|
|
The
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa nowait
|
|
|
|
parameter is a choice of
|
|
|
|
.Dv M_WAIT / M_DONTWAIT
|
1999-03-07 01:09:29 +03:00
|
|
|
from caller.
|
|
|
|
The
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa type
|
|
|
|
parameter is an mbuf type.
|
2001-11-28 19:39:35 +03:00
|
|
|
.It Fn m_devget "char *buf" "int totlen" "int off0" "struct ifnet *ifp" "void (*copy)(const void *, void *, size_t)"
|
1997-10-04 18:04:15 +04:00
|
|
|
Copies
|
|
|
|
.Fa len
|
|
|
|
bytes from device local memory into mbufs using copy routine
|
|
|
|
.Fa copy .
|
|
|
|
If parameter
|
|
|
|
.Fa off
|
|
|
|
is non-zero, the packet is supposed to be trailer-encapsulated and
|
|
|
|
.Fa off
|
|
|
|
bytes plus the type and length fields will be skipped before copying.
|
|
|
|
Returns the top of the mbuf chain it created.
|
|
|
|
.It Fn m_copym "struct mbuf *m" "int off0" "int len" "int wait"
|
|
|
|
Creates a copy of an mbuf chain starting
|
|
|
|
.Fa off0
|
|
|
|
bytes from the beginning, continuing for
|
|
|
|
.Fa len
|
2002-10-14 17:43:14 +04:00
|
|
|
bytes.
|
|
|
|
If the
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa len
|
|
|
|
requested is
|
|
|
|
.Dv M_COPYALL ,
|
|
|
|
the complete mbuf chain will be copied.
|
|
|
|
The
|
|
|
|
.Fa wait
|
|
|
|
parameter is a choice of
|
|
|
|
.Dv M_WAIT / M_DONTWAIT
|
|
|
|
from caller.
|
|
|
|
.It Fn m_copypacket "struct mbuf *m" "int how"
|
|
|
|
Copies an entire packet, including header (which must be present).
|
|
|
|
This function is an optimization of the common case
|
1997-11-27 09:17:58 +03:00
|
|
|
.Li m_copym(m, 0, Dv M_COPYALL, Fa how ) .
|
1997-10-04 18:04:15 +04:00
|
|
|
.It Fn m_copydata "struct mbuf *m" "int off" "int len" "caddr_t cp"
|
|
|
|
Copies
|
|
|
|
.Fa len
|
|
|
|
bytes data from mbuf chain
|
|
|
|
.Fa m
|
|
|
|
into the buffer
|
|
|
|
.Fa cp ,
|
|
|
|
starting
|
|
|
|
.Fa off
|
|
|
|
bytes from the beginning.
|
|
|
|
.It Fn m_copyback "struct mbuf *m0" "int off" "int len" "caddr_t cp"
|
|
|
|
Copies
|
|
|
|
.Fa len
|
|
|
|
bytes data from buffer
|
|
|
|
.Fa cp
|
|
|
|
back into the mbuf chain
|
|
|
|
.Fa m0 ,
|
|
|
|
starting
|
|
|
|
.Fa off
|
|
|
|
bytes from the beginning, extending the mbuf chain if necessary.
|
|
|
|
.It Fn m_cat "struct mbuf *m" "struct mbuf *n"
|
1997-11-27 09:17:58 +03:00
|
|
|
Concatenates mbuf chain
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa n
|
|
|
|
to
|
|
|
|
.Fa m .
|
|
|
|
Both chains must be of the same type; packet headers will
|
|
|
|
.Em not
|
|
|
|
be updated if present.
|
2000-10-13 08:19:58 +04:00
|
|
|
.It Fn m_dup "struct mbuf *m" "int off0" "int len" "int wait"
|
|
|
|
Similarly to
|
|
|
|
.Fn m_copym ,
|
|
|
|
the function creates a copy of an mbuf chain starting
|
|
|
|
.Fa off0
|
|
|
|
bytes from the beginning, continuing for
|
|
|
|
.Fa len
|
|
|
|
bytes.
|
|
|
|
While
|
|
|
|
.Fn m_copym
|
|
|
|
tries to share external storage for mbufs with
|
|
|
|
.Dv M_EXT
|
|
|
|
flag,
|
|
|
|
.Fn m_dup
|
|
|
|
will deep-copy the whole data content into new mbuf chain
|
|
|
|
and avoids shared external storage.
|
1997-10-04 18:04:15 +04:00
|
|
|
.It Fn m_prepend "struct mbuf *m" "int len" "int how"
|
|
|
|
Lesser-used path for
|
|
|
|
.Fn M_PREPEND :
|
|
|
|
allocates new mbuf
|
|
|
|
.Fa m
|
|
|
|
of size
|
|
|
|
.Fa len
|
1999-03-07 01:09:29 +03:00
|
|
|
to prepend to the chain, copying junk along.
|
|
|
|
The
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa how
|
|
|
|
parameter is a choice of
|
|
|
|
.Dv M_WAIT / M_DONTWAIT
|
|
|
|
from caller.
|
2002-05-12 19:48:36 +04:00
|
|
|
.It Fn m_pulldown "struct mbuf *m" "int off" "int len" "int *offp"
|
2001-06-29 03:02:47 +04:00
|
|
|
Rearranges an mbuf chain so that
|
|
|
|
.Fa len
|
|
|
|
bytes from offset
|
|
|
|
.Fa off
|
|
|
|
are contiguous and in the data area of an mbuf.
|
|
|
|
The return value points to an mbuf in the middle of the mbuf chain
|
|
|
|
.Fa m .
|
|
|
|
If we call the return value
|
|
|
|
.Fa n ,
|
|
|
|
the contiguous data region is available at
|
|
|
|
.Li "mtod(n, caddr_t) + *offp" ,
|
2001-09-04 06:51:15 +04:00
|
|
|
or
|
2001-06-29 03:02:47 +04:00
|
|
|
.Li "mtod(n, caddr_t)"
|
|
|
|
if
|
|
|
|
.Fa offp
|
|
|
|
is
|
|
|
|
.Dv NULL .
|
2001-09-04 06:51:15 +04:00
|
|
|
The top of the mbuf chain
|
2001-06-29 03:02:47 +04:00
|
|
|
.Fa m ,
|
|
|
|
and mbufs up to
|
|
|
|
.Fa off ,
|
|
|
|
will not be modified.
|
|
|
|
On successful return, it is guaranteed that the mbuf pointed to by
|
|
|
|
.Fa n
|
|
|
|
does not have a shared external storage,
|
2001-06-29 03:15:24 +04:00
|
|
|
therefore it is safe to update the contiguous region.
|
2001-06-29 03:02:47 +04:00
|
|
|
Returns
|
|
|
|
.Dv NULL
|
|
|
|
and frees the mbuf chain on failure.
|
|
|
|
.Fa len
|
|
|
|
must be smaller or equal than
|
|
|
|
.Dv MCLBYTES .
|
1997-10-04 18:04:15 +04:00
|
|
|
.It Fn m_pullup "struct mbuf *m" "int len"
|
1997-11-27 09:17:58 +03:00
|
|
|
Rearranges an mbuf chain so that
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa len
|
|
|
|
bytes are contiguous
|
|
|
|
and in the data area of an mbuf (so that
|
|
|
|
.Fn mtod
|
|
|
|
will work for a structure of size
|
|
|
|
.Fa len ) .
|
|
|
|
Returns the resulting
|
1997-11-27 09:17:58 +03:00
|
|
|
mbuf chain on success, frees it and returns
|
|
|
|
.Dv NULL
|
|
|
|
on failure.
|
1997-10-04 18:04:15 +04:00
|
|
|
If there is room, it will add up to
|
|
|
|
.Dv max_protohdr
|
|
|
|
-
|
|
|
|
.Fa len
|
|
|
|
extra bytes to the
|
1997-11-27 09:17:58 +03:00
|
|
|
contiguous region to possibly avoid being called again.
|
2001-06-29 03:02:47 +04:00
|
|
|
.Fa len
|
|
|
|
must be smaller or equal than
|
|
|
|
.Dv MHLEN .
|
1997-10-04 18:04:15 +04:00
|
|
|
.It Fn m_split "struct mbuf *m0" "int len0" "int wait"
|
|
|
|
Partitions an mbuf chain in two pieces, returning the tail,
|
|
|
|
which is all but the first
|
|
|
|
.Fa len0
|
2002-10-14 17:43:14 +04:00
|
|
|
bytes.
|
|
|
|
In case of failure, it returns
|
1997-10-04 18:04:15 +04:00
|
|
|
.Dv NULL
|
|
|
|
and attempts to
|
|
|
|
restore the chain to its original state.
|
|
|
|
.It Fn m_adj "struct mbuf *mp" "int req_len"
|
|
|
|
Shaves off
|
|
|
|
.Fa req_len
|
1999-03-07 01:09:29 +03:00
|
|
|
bytes from head or tail of the (valid) data area.
|
|
|
|
If
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa req_len
|
|
|
|
is greater than zero, front bytes are being shaved off, if it's smaller,
|
|
|
|
from the back (and if it is zero, the mbuf will stay bearded).
|
|
|
|
This function does not move data in any way, but is used to manipulate the
|
|
|
|
data area pointer and data length variable of the mbuf in a non-clobbering
|
|
|
|
way.
|
|
|
|
.It Fn m_free "struct mbuf *m"
|
|
|
|
Frees mbuf
|
|
|
|
.Fa m .
|
|
|
|
.It Fn m_freem "struct mbuf *m"
|
|
|
|
Frees the mbuf chain beginning with
|
|
|
|
.Fa m .
|
|
|
|
This function contains the elementary sanity check for a
|
|
|
|
.Dv NULL
|
|
|
|
pointer.
|
|
|
|
.It Fn mtod "struct mbuf *m" "datatype"
|
|
|
|
Returns a pointer to the data contained in the specified mbuf
|
|
|
|
.Fa m ,
|
|
|
|
type-casted to the specified data type
|
|
|
|
.Fa datatype .
|
|
|
|
Implemented as a macro.
|
|
|
|
.It Fn mtocl "void *datapointer"
|
|
|
|
Takes a
|
|
|
|
.Fa datapointer
|
|
|
|
within an mbuf cluster and returns the cluster index number of the mbuf
|
|
|
|
owning the data.
|
1997-11-27 09:17:58 +03:00
|
|
|
Avoid this; it may be deprecated in the future.
|
1997-10-04 18:04:15 +04:00
|
|
|
Implemented as a macro.
|
|
|
|
.It Fn cltom "u_long clusternum"
|
|
|
|
Takes an mbuf cluster index number
|
|
|
|
.Fa clusternum
|
|
|
|
and returns a pointer to the beginning of the cluster.
|
|
|
|
Avoid this; it may be deprecated in the future.
|
|
|
|
Implemented as a macro.
|
|
|
|
.It Fn MGET "struct mbuf *m" "int how" "int type"
|
|
|
|
Allocates mbuf
|
|
|
|
.Fa m
|
1999-03-07 01:09:29 +03:00
|
|
|
and initializes it to contain internal data.
|
|
|
|
See
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fn m_get .
|
|
|
|
Implemented as a macro.
|
|
|
|
.It Fn MGETHDR "struct mbuf *m" "int how" "int type"
|
|
|
|
Allocates mbuf
|
|
|
|
.Fa m
|
1999-03-07 01:09:29 +03:00
|
|
|
and initializes it to contain a packet header.
|
|
|
|
See
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fn m_gethdr .
|
|
|
|
Implemented as a macro.
|
|
|
|
.It Fn MEXTMALLOC "struct mbuf *m" "int len" "int how"
|
|
|
|
Allocates external storage of size
|
|
|
|
.Fa len
|
|
|
|
for mbuf
|
|
|
|
.Fa m .
|
|
|
|
The
|
|
|
|
.Fa how
|
|
|
|
parameter is a choice of
|
|
|
|
.Dv M_WAIT / M_DONTWAIT
|
|
|
|
from caller.
|
|
|
|
The flag
|
|
|
|
.Dv M_EXT
|
|
|
|
is set upon success.
|
|
|
|
Implemented as a macro.
|
2001-11-28 22:14:56 +03:00
|
|
|
.It Fn MEXTADD "struct mbuf *m" "caddr_t buf" "int size" "int type" "void (*free)(caddr_t, u_int, void *)" "void *arg"
|
1997-10-04 18:04:15 +04:00
|
|
|
Adds pre-allocated external storage
|
|
|
|
.Fa buf
|
|
|
|
to a normal mbuf
|
|
|
|
.Fa m ;
|
|
|
|
the parameters
|
2001-11-28 22:14:56 +03:00
|
|
|
.Fa size ,
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa type ,
|
|
|
|
.Fa free
|
|
|
|
and
|
|
|
|
.Fa arg
|
|
|
|
describe the external storage.
|
2001-11-28 22:14:56 +03:00
|
|
|
.Fa size
|
|
|
|
is the size of the storage,
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa type
|
2001-11-28 22:14:56 +03:00
|
|
|
describes its
|
1997-11-27 09:17:58 +03:00
|
|
|
.Xr malloc 9
|
2001-11-28 22:14:56 +03:00
|
|
|
type,
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa free
|
|
|
|
is a free routine (if not the usual one), and
|
|
|
|
.Fa arg
|
|
|
|
is a possible argument to the free routine.
|
|
|
|
The flag
|
|
|
|
.Dv M_EXT
|
|
|
|
is set upon success.
|
|
|
|
Implemented as a macro.
|
|
|
|
.It Fn MCLGET "struct mbuf *m" "int how"
|
|
|
|
Allocates and adds an mbuf cluster to a normal mbuf
|
|
|
|
.Fa m .
|
|
|
|
The
|
|
|
|
.Fa how
|
|
|
|
parameter is a choice of
|
|
|
|
.Dv M_WAIT / M_DONTWAIT
|
|
|
|
from caller.
|
|
|
|
The flag
|
|
|
|
.Dv M_EXT
|
|
|
|
is set upon success.
|
|
|
|
Implemented as a macro.
|
|
|
|
.It Fn M_COPY_PKTHDR "struct mbuf *to" "struct mbuf *from"
|
|
|
|
Copies the mbuf pkthdr from mbuf
|
|
|
|
.Fa from
|
|
|
|
to mbuf
|
|
|
|
.Fa to .
|
|
|
|
.Fa from
|
|
|
|
must have the type flag
|
|
|
|
.Dv M_PKTHDR
|
|
|
|
set, and
|
|
|
|
.Fa to
|
|
|
|
must be empty.
|
|
|
|
Implemented as a macro.
|
|
|
|
.It Fn M_ALIGN "struct mbuf *m" "int len"
|
|
|
|
Sets the data pointer of a newly allocated mbuf
|
|
|
|
.Fa m
|
1997-11-27 09:17:58 +03:00
|
|
|
to
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa len
|
|
|
|
bytes from the end of the mbuf data area, so that
|
|
|
|
.Fa len
|
1997-11-27 09:17:58 +03:00
|
|
|
bytes of data written to the mbuf
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa m ,
|
|
|
|
starting at the data pointer, will be aligned to the end of the data area.
|
|
|
|
Implemented as a macro.
|
|
|
|
.It Fn MH_ALIGN "struct mbuf *m" "int len"
|
|
|
|
Sets the data pointer of a newly allocated packetheader mbuf
|
|
|
|
.Fa m
|
1997-11-27 09:17:58 +03:00
|
|
|
to
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa len
|
|
|
|
bytes from the end of the mbuf data area, so that
|
|
|
|
.Fa len
|
1997-11-27 09:17:58 +03:00
|
|
|
bytes of data written to the mbuf
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa m ,
|
|
|
|
starting at the data pointer, will be aligned to the end of the data area.
|
|
|
|
Implemented as a macro.
|
|
|
|
.It Fn M_LEADINGSPACE "struct mbuf *m"
|
|
|
|
Returns the amount of space available before the current start of valid
|
|
|
|
data in mbuf
|
|
|
|
.Fa m .
|
2001-07-28 20:19:12 +04:00
|
|
|
Returns 0 if the mbuf data part is shared across multiple mbufs
|
|
|
|
.Pq i.e. not writable .
|
1997-10-04 18:04:15 +04:00
|
|
|
Implemented as a macro.
|
|
|
|
.It Fn M_TRAILINGSPACE "struct mbuf *m"
|
|
|
|
Returns the amount of space available after the current end of valid
|
|
|
|
data in mbuf
|
|
|
|
.Fa m .
|
2001-07-28 20:19:12 +04:00
|
|
|
Returns 0 if the mbuf data part is shared across multiple mbufs
|
|
|
|
.Pq i.e. not writable .
|
1997-10-04 18:04:15 +04:00
|
|
|
Implemented as a macro.
|
|
|
|
.It Fn M_PREPEND "struct mbuf *m" "int plen" "int how"
|
|
|
|
Prepends space of size
|
|
|
|
.Fa plen
|
|
|
|
to mbuf
|
|
|
|
.Fa m .
|
|
|
|
If a new mbuf must be allocated,
|
|
|
|
.Fa how
|
1999-03-07 01:09:29 +03:00
|
|
|
specifies whether to wait.
|
|
|
|
If
|
1997-10-04 18:04:15 +04:00
|
|
|
.Fa how
|
|
|
|
is
|
|
|
|
.Dv M_DONTWAIT
|
|
|
|
and allocation fails, the original mbuf chain is freed and
|
|
|
|
.Fa m
|
|
|
|
is set to
|
|
|
|
.Dv NULL .
|
|
|
|
Implemented as a macro.
|
|
|
|
.It Fn MCHTYPE "struct mbuf *m" "int type"
|
|
|
|
Change mbuf
|
|
|
|
.Fa m
|
|
|
|
to new type
|
|
|
|
.Fa type .
|
|
|
|
Implemented as a macro.
|
|
|
|
.It Fn MEXTREMOVE "struct mbuf *m"
|
|
|
|
Removes external storage from mbuf
|
|
|
|
.Fa m .
|
|
|
|
The flag
|
|
|
|
.Dv M_EXT
|
|
|
|
is removed.
|
|
|
|
Implemented as a macro.
|
|
|
|
.It Fn MFREE "struct mbuf *m" "struct mbuf *n"
|
|
|
|
Frees a single mbuf
|
|
|
|
.Fa m
|
|
|
|
and places the successor, if any, in mbuf
|
|
|
|
.Fa n .
|
|
|
|
Implemented as a macro.
|
|
|
|
.El
|
2001-12-26 04:07:45 +03:00
|
|
|
.Sh FILES
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
management functions are implemented within the file
|
|
|
|
.Pa sys/kern/uipc_mbuf.c .
|
|
|
|
Function prototypes, and the functions implemented as macros
|
|
|
|
are located in
|
|
|
|
.Pa sys/sys/mbuf.h .
|
|
|
|
Both pathnames are relative to the root of the
|
|
|
|
.Nx
|
|
|
|
source tree,
|
|
|
|
.Pa /usr/src .
|
1997-10-04 18:04:15 +04:00
|
|
|
.Sh SEE ALSO
|
2001-04-09 21:14:38 +04:00
|
|
|
.Pa /usr/share/doc/smm/18.net ,
|
1997-10-04 18:04:15 +04:00
|
|
|
.Xr netstat 1 ,
|
1998-09-03 12:12:56 +04:00
|
|
|
.Xr malloc 9
|
2001-06-29 03:02:47 +04:00
|
|
|
.Rs
|
|
|
|
.%A Jun-ichiro Hagino
|
2003-01-03 07:18:57 +03:00
|
|
|
.%T "Mbuf issues in 4.4BSD IPv6/IPsec support (experiences from KAME IPv6/IPsec implementation)"
|
2001-06-29 03:02:47 +04:00
|
|
|
.%B "Proceedings of the freenix track: 2000 USENIX annual technical conference"
|
|
|
|
.%D June 2000
|
|
|
|
.Re
|
1997-10-04 18:04:15 +04:00
|
|
|
.Sh AUTHORS
|
|
|
|
The original mbuf data structures were designed by Rob Gurwitz
|
|
|
|
when he did the initial TCP/IP implementation at BBN.
|
|
|
|
.br
|
|
|
|
Further extensions and enhancements were made by Bill Joy, Sam Leffler,
|
|
|
|
and Mike Karels at CSRG.
|
|
|
|
.br
|
2003-02-14 18:20:17 +03:00
|
|
|
Current implementation of external storage by
|
|
|
|
.An Matt Thomas
|
|
|
|
.Aq matt@3am-software.com
|
|
|
|
and
|
|
|
|
.An Jason R. Thorpe
|
|
|
|
.Aq thorpej@NetBSD.org .
|