2000-10-26 23:15:47 +00:00
|
|
|
.\" Copyright (c) 2000 FreeBSD Inc.
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" 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.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 [your name] 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.
|
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
|
|
|
.Dd October 17, 2000
|
|
|
|
.Dt MBUF 9
|
|
|
|
.Os
|
|
|
|
.\"
|
|
|
|
.Sh NAME
|
|
|
|
.Nm mbuf
|
|
|
|
.Nd "memory management in the kernel IPC subsystem"
|
|
|
|
.\"
|
|
|
|
.Sh SYNOPSIS
|
2001-10-01 16:09:29 +00:00
|
|
|
.In sys/param.h
|
|
|
|
.In sys/mbuf.h
|
2000-10-26 23:15:47 +00:00
|
|
|
.\"
|
2000-11-01 23:02:19 +00:00
|
|
|
.Ss Mbuf allocation macros
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fn MGET "struct mbuf *mbuf" "int how" "short type"
|
2001-07-14 19:41:16 +00:00
|
|
|
.Fn MGETHDR "struct mbuf *mbuf" "int how" "short type"
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fn MCLGET "struct mbuf *mbuf" "int how"
|
2000-11-01 23:02:19 +00:00
|
|
|
.Fo MEXTADD
|
|
|
|
.Fa "struct mbuf *mbuf"
|
|
|
|
.Fa "caddr_t buf"
|
|
|
|
.Fa "u_int size"
|
|
|
|
.Fa "void (*free)(void *opt_args)"
|
|
|
|
.Fa "void *opt_args"
|
2000-11-21 22:29:31 +00:00
|
|
|
.Fa "short flags"
|
|
|
|
.Fa "int type"
|
2000-11-01 23:02:19 +00:00
|
|
|
.Fc
|
|
|
|
.Fn MEXTFREE "struct mbuf *mbuf"
|
|
|
|
.Fn MEXT_ADD_REF "struct mbuf *mbuf"
|
|
|
|
.Fn MEXT_REM_REF "struct mbuf *mbuf"
|
|
|
|
.Fn MFREE "struct mbuf *mbuf" "struct mbuf *successor"
|
|
|
|
.\"
|
|
|
|
.Ss Mbuf utility macros
|
|
|
|
.Fn mtod "struct mbuf *mbuf" "any type"
|
2001-07-14 19:41:16 +00:00
|
|
|
.Fn MEXT_IS_REF "struct mbuf *mbuf"
|
2000-11-01 23:02:19 +00:00
|
|
|
.Fn M_COPY_PKTHDR "struct mbuf *to" "struct mbuf *from"
|
|
|
|
.Fn M_ALIGN "struct mbuf *mbuf" "u_int len"
|
|
|
|
.Fn MH_ALIGN "struct mbuf *mbuf" "u_int len"
|
|
|
|
.Fn M_LEADINGSPACE "struct mbuf *mbuf"
|
|
|
|
.Fn M_TRAILINGSPACE "struct mbuf *mbuf"
|
|
|
|
.Fn M_PREPEND "struct mbuf *mbuf" "int len" "int how"
|
|
|
|
.Fn MCHTYPE "struct mbuf *mbuf" "u_int type"
|
2000-11-21 22:29:31 +00:00
|
|
|
.Fn M_WRITABLE "struct mbuf *mbuf"
|
2000-10-26 23:15:47 +00:00
|
|
|
.\"
|
2000-11-01 23:02:19 +00:00
|
|
|
.Ss Mbuf allocation functions
|
2000-10-26 23:15:47 +00:00
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_get "int how" "int type"
|
|
|
|
.Ft struct mbuf *
|
2001-02-16 03:23:04 +00:00
|
|
|
.Fn m_getm "struct mbuf *orig" "int len" "int how" "int type"
|
|
|
|
.Ft struct mbuf *
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fn m_getclr "int how" "int type"
|
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_gethdr "int how" "int type"
|
2000-11-01 23:02:19 +00:00
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_free "struct mbuf *mbuf"
|
2000-10-26 23:15:47 +00:00
|
|
|
.Ft void
|
|
|
|
.Fn m_freem "struct mbuf *mbuf"
|
2000-11-01 23:02:19 +00:00
|
|
|
.\"
|
|
|
|
.Ss Mbuf utility functions
|
2000-10-26 23:15:47 +00:00
|
|
|
.Ft void
|
|
|
|
.Fn m_adj "struct mbuf *mbuf" "int len"
|
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_prepend "struct mbuf *mbuf" "int len" "int how"
|
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_pullup "struct mbuf *mbuf" "int len"
|
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_copym "struct mbuf *mbuf" "int offset" "int len" "int how"
|
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_copypacket "struct mbuf *mbuf" "int how"
|
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_dup "struct mbuf *mbuf" "int how"
|
|
|
|
.Ft void
|
|
|
|
.Fn m_copydata "struct mbuf *mbuf" "int offset" "int len" "caddr_t buf"
|
|
|
|
.Ft void
|
|
|
|
.Fn m_copyback "struct mbuf *mbuf" "int offset" "int len" "caddr_t buf"
|
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fo m_devget
|
|
|
|
.Fa "char *buf"
|
|
|
|
.Fa "int len"
|
|
|
|
.Fa "int offset"
|
|
|
|
.Fa "struct ifnet *ifp"
|
|
|
|
.Fa "void (*copy)(char *from, caddr_t to, u_int len)"
|
|
|
|
.Fc
|
|
|
|
.Ft void
|
|
|
|
.Fn m_cat "struct mbuf *m" "struct mbuf *n"
|
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_split "struct mbuf *mbuf" "int len" "int how"
|
|
|
|
.\"
|
|
|
|
.Sh DESCRIPTION
|
2000-11-01 23:02:19 +00:00
|
|
|
An mbuf is a basic unit of memory management in the kernel IPC subsystem.
|
2000-11-10 10:08:34 +00:00
|
|
|
Network packets and socket buffers are stored in mbufs.
|
|
|
|
A network packet may span multiple mbufs arranged into a chain
|
2001-08-07 15:48:51 +00:00
|
|
|
(linked list),
|
2000-10-26 23:15:47 +00:00
|
|
|
which allows adding or trimming
|
2000-11-01 23:02:19 +00:00
|
|
|
network headers with little overhead.
|
2000-10-26 23:15:47 +00:00
|
|
|
.Pp
|
2000-11-01 23:02:19 +00:00
|
|
|
While a developer should not bother with mbuf internals without serious
|
2000-10-26 23:15:47 +00:00
|
|
|
reason in order to avoid incompatibilities with future changes, it
|
2000-11-01 23:02:19 +00:00
|
|
|
is useful to understand the mbuf's general structure.
|
2000-10-26 23:15:47 +00:00
|
|
|
.Pp
|
2000-11-01 23:02:19 +00:00
|
|
|
An mbuf consists of a variable-sized header and a small internal
|
2000-11-10 10:08:34 +00:00
|
|
|
buffer for data.
|
|
|
|
The mbuf's total size,
|
2000-11-01 23:02:19 +00:00
|
|
|
.Dv MSIZE ,
|
2000-10-26 23:15:47 +00:00
|
|
|
is a machine-dependent constant defined in
|
|
|
|
.Pa machine/param.h .
|
|
|
|
The mbuf header includes:
|
|
|
|
.Pp
|
|
|
|
.Bl -tag -width "m_nextpkt" -compact -offset indent
|
|
|
|
.It Fa m_next
|
|
|
|
a pointer to the next buffer in the chain
|
|
|
|
.It Fa m_nextpkt
|
|
|
|
a pointer to the next chain in the queue
|
|
|
|
.It Fa m_data
|
|
|
|
a pointer to the data
|
|
|
|
.It Fa m_len
|
|
|
|
the length of the data
|
|
|
|
.It Fa m_type
|
2000-11-01 23:02:19 +00:00
|
|
|
the type of data
|
2000-10-26 23:15:47 +00:00
|
|
|
.It Fa m_flags
|
|
|
|
the mbuf flags
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The mbuf flag bits are defined as follows:
|
|
|
|
.Bd -literal
|
|
|
|
/* mbuf flags */
|
|
|
|
#define M_EXT 0x0001 /* has associated external storage */
|
|
|
|
#define M_PKTHDR 0x0002 /* start of record */
|
|
|
|
#define M_EOR 0x0004 /* end of record */
|
2000-11-21 22:29:31 +00:00
|
|
|
#define M_RDONLY 0x0008 /* associated data marked read-only */
|
|
|
|
#define M_PROTO1 0x0010 /* protocol-specific */
|
|
|
|
#define M_PROTO2 0x0020 /* protocol-specific */
|
|
|
|
#define M_PROTO3 0x0040 /* protocol-specific */
|
|
|
|
#define M_PROTO4 0x0080 /* protocol-specific */
|
|
|
|
#define M_PROTO5 0x0100 /* protocol-specific */
|
2000-10-26 23:15:47 +00:00
|
|
|
|
|
|
|
/* mbuf pkthdr flags, also in m_flags */
|
2000-11-21 22:29:31 +00:00
|
|
|
#define M_BCAST 0x0200 /* send/received as link-level broadcast */
|
|
|
|
#define M_MCAST 0x0400 /* send/received as link-level multicast */
|
|
|
|
#define M_FRAG 0x0800 /* packet is fragment of larger packet */
|
|
|
|
#define M_FIRSTFRAG 0x1000 /* packet is first fragment */
|
|
|
|
#define M_LASTFRAG 0x2000 /* packet is last fragment */
|
2000-10-26 23:15:47 +00:00
|
|
|
.Ed
|
|
|
|
.Pp
|
2000-11-01 23:02:19 +00:00
|
|
|
The available mbuf types are defined as follows:
|
2000-10-26 23:15:47 +00:00
|
|
|
.Bd -literal
|
|
|
|
/* mbuf types */
|
|
|
|
#define MT_FREE 0 /* should be on free list */
|
|
|
|
#define MT_DATA 1 /* dynamic (data) allocation */
|
|
|
|
#define MT_HEADER 2 /* packet header */
|
|
|
|
#define MT_SONAME 8 /* socket name */
|
|
|
|
#define MT_FTABLE 11 /* fragment reassembly header */
|
|
|
|
#define MT_CONTROL 14 /* extra-data protocol message */
|
|
|
|
#define MT_OOBDATA 15 /* expedited data */
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
If the
|
|
|
|
.Dv M_PKTHDR
|
|
|
|
flag is set, a
|
2000-11-10 10:22:49 +00:00
|
|
|
.Li struct pkthdr m_pkthdr
|
2000-11-10 10:08:34 +00:00
|
|
|
is added to the mbuf header.
|
|
|
|
It contains a pointer to the interface
|
2000-10-26 23:15:47 +00:00
|
|
|
the packet has been received from
|
|
|
|
.Pq Fa struct ifnet *rcvif ,
|
|
|
|
and the total packet length
|
|
|
|
.Pq Fa int len .
|
|
|
|
.Pp
|
2000-11-10 10:08:34 +00:00
|
|
|
If small enough, data is stored in the mbuf's internal data buffer.
|
|
|
|
If the data is sufficiently large, another mbuf may be added to the chain,
|
|
|
|
or external storage may be associated with the mbuf.
|
2000-10-26 23:15:47 +00:00
|
|
|
.Dv MHLEN
|
2000-11-10 10:22:49 +00:00
|
|
|
bytes of data can fit into an mbuf with the
|
2000-10-26 23:15:47 +00:00
|
|
|
.Dv M_PKTHDR
|
|
|
|
flag set,
|
|
|
|
.Dv MLEN
|
|
|
|
bytes can otherwise.
|
|
|
|
.Pp
|
2000-11-01 23:02:19 +00:00
|
|
|
If external storage is being associated with an mbuf, the
|
2001-07-14 19:41:16 +00:00
|
|
|
.Dv m_ext
|
2000-11-10 10:22:49 +00:00
|
|
|
header is added at the cost of losing the internal data buffer.
|
2000-11-10 10:08:34 +00:00
|
|
|
It includes a pointer to external storage, the size of the storage,
|
|
|
|
a pointer to a function used for freeing the storage,
|
|
|
|
a pointer to an optional argument that can be passed to the function,
|
|
|
|
and a pointer to a reference counter.
|
|
|
|
An mbuf using external storage has the
|
2000-10-26 23:15:47 +00:00
|
|
|
.Dv M_EXT
|
|
|
|
flag set.
|
|
|
|
.Pp
|
2000-11-01 23:02:19 +00:00
|
|
|
The system supplies a macro for allocating the desired external storage
|
|
|
|
buffer,
|
|
|
|
.Dv MEXTADD .
|
|
|
|
.Pp
|
|
|
|
The allocation and management of the reference counter is handled by the
|
2000-11-10 10:08:34 +00:00
|
|
|
subsystem.
|
|
|
|
The developer can check whether the reference count for the
|
2000-11-01 23:02:19 +00:00
|
|
|
given mbuf's external storage is greater than 1 with the
|
|
|
|
.Dv MEXT_IS_REF
|
2000-11-10 10:08:34 +00:00
|
|
|
macro.
|
|
|
|
Similarly, the developer can directly add and remove references,
|
|
|
|
if absolutely necessary, with the use of the
|
2000-11-01 23:02:19 +00:00
|
|
|
.Dv MEXT_ADD_REF
|
|
|
|
and
|
|
|
|
.Dv MEXT_REM_REF
|
|
|
|
macros.
|
|
|
|
.Pp
|
|
|
|
The system also supplies a default type of external storage buffer called an
|
|
|
|
.Dq mbuf cluster .
|
|
|
|
Mbuf clusters can be allocated and configured with the use of the
|
|
|
|
.Dv MCLGET
|
2000-11-10 10:08:34 +00:00
|
|
|
macro.
|
|
|
|
Each cluster is
|
2000-10-26 23:15:47 +00:00
|
|
|
.Dv MCLBYTES
|
2000-11-01 23:02:19 +00:00
|
|
|
in size, where MCLBYTES is a machine-dependent constant.
|
|
|
|
The system defines an advisory macro
|
2000-10-26 23:15:47 +00:00
|
|
|
.Dv MINCLSIZE ,
|
|
|
|
which is the smallest amount of data to put into a cluster.
|
|
|
|
It's equal to the sum of
|
|
|
|
.Dv MLEN
|
|
|
|
and
|
|
|
|
.Dv MHLEN .
|
2000-11-01 23:02:19 +00:00
|
|
|
It is typically preferable to store data into an mbuf's data region, if size
|
|
|
|
permits, as opposed to allocating a separate mbuf cluster to hold the same
|
|
|
|
data.
|
2000-10-26 23:15:47 +00:00
|
|
|
.\"
|
|
|
|
.Ss Macros and Functions
|
2001-07-14 19:41:16 +00:00
|
|
|
There are numerous predefined macros and functions that provide the
|
2000-11-01 23:02:19 +00:00
|
|
|
developer with common utilities.
|
2000-10-26 23:15:47 +00:00
|
|
|
.\"
|
|
|
|
.Bl -ohang -offset indent
|
|
|
|
.It Fn mtod mbuf type
|
2000-11-01 23:02:19 +00:00
|
|
|
Convert an mbuf pointer to a data pointer.
|
|
|
|
The macro expands to the data pointer cast to the pointer of the specified type.
|
2000-10-26 23:15:47 +00:00
|
|
|
.Sy Note :
|
2000-11-01 23:02:19 +00:00
|
|
|
It is advisable to ensure that there is enough contiguous data in the mbuf.
|
2000-10-26 23:15:47 +00:00
|
|
|
See
|
|
|
|
.Fn m_pullup
|
|
|
|
for details.
|
|
|
|
.It Fn MGET mbuf how type
|
2000-11-01 23:02:19 +00:00
|
|
|
Allocate an mbuf and initialize it to contain internal data.
|
2000-11-10 10:22:49 +00:00
|
|
|
.Fa mbuf
|
2000-11-01 23:02:19 +00:00
|
|
|
will point to the allocated mbuf on success, or be set to
|
2000-10-26 23:15:47 +00:00
|
|
|
.Dv NULL
|
2000-11-10 10:08:34 +00:00
|
|
|
on failure.
|
|
|
|
The
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fa how
|
|
|
|
argument is to be set to
|
2000-12-24 03:08:17 +00:00
|
|
|
.Dv M_TRYWAIT
|
2000-10-26 23:15:47 +00:00
|
|
|
or
|
|
|
|
.Dv M_DONTWAIT .
|
2000-11-10 10:22:49 +00:00
|
|
|
It specifies whether the caller is willing to block if necessary.
|
2001-07-14 19:41:16 +00:00
|
|
|
If
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fa how
|
2000-11-10 10:22:49 +00:00
|
|
|
is set to
|
2000-12-24 03:08:17 +00:00
|
|
|
.Dv M_TRYWAIT ,
|
2000-11-10 10:22:49 +00:00
|
|
|
a failed allocation will result in the caller being put
|
2000-11-01 23:02:19 +00:00
|
|
|
to sleep for a designated
|
2000-11-10 10:22:49 +00:00
|
|
|
kern.ipc.mbuf_wait
|
2001-08-07 15:48:51 +00:00
|
|
|
.Xr ( sysctl 8
|
|
|
|
tunable)
|
2000-11-10 10:22:49 +00:00
|
|
|
number of ticks.
|
2000-11-01 23:02:19 +00:00
|
|
|
A number of other mbuf-related
|
2000-10-26 23:15:47 +00:00
|
|
|
functions and macros have the same argument because they may
|
2000-11-01 23:02:19 +00:00
|
|
|
at some point need to allocate new mbufs.
|
2000-10-26 23:15:47 +00:00
|
|
|
.It Fn MGETHDR mbuf how type
|
2000-11-01 23:02:19 +00:00
|
|
|
Allocate an mbuf and initialize it to contain a packet header
|
2000-11-10 10:08:34 +00:00
|
|
|
and internal data.
|
|
|
|
See
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fn MGET
|
|
|
|
for details.
|
|
|
|
.It Fn MCLGET mbuf how
|
2000-11-10 10:08:34 +00:00
|
|
|
Allocate and attach an mbuf cluster to an mbuf.
|
|
|
|
If the macro fails, the
|
2000-10-26 23:15:47 +00:00
|
|
|
.Dv M_EXT
|
|
|
|
flag won't be set in the mbuf.
|
|
|
|
.It Fn M_PREPEND mbuf len how
|
2000-11-01 23:02:19 +00:00
|
|
|
This macro operates on an mbuf chain.
|
2000-10-26 23:15:47 +00:00
|
|
|
It is an optimized wrapper for
|
|
|
|
.Fn m_prepend
|
|
|
|
that can make use of possible empty space before data
|
2001-08-07 15:48:51 +00:00
|
|
|
(e.g. left after trimming of a link-layer header).
|
2000-10-26 23:15:47 +00:00
|
|
|
The new chain pointer or
|
|
|
|
.Dv NULL
|
2001-07-14 19:41:16 +00:00
|
|
|
is in
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fa mbuf
|
|
|
|
after the call.
|
2000-11-21 22:29:31 +00:00
|
|
|
.It Fn M_WRITABLE mbuf
|
|
|
|
This macro will evaluate true if the mbuf is not marked
|
|
|
|
.Dv M_RDONLY
|
|
|
|
and if either the mbuf does not contain external storage or,
|
|
|
|
if it does,
|
2001-07-14 19:41:16 +00:00
|
|
|
then if the reference count of the storage is not greater than 1.
|
2000-11-21 22:29:31 +00:00
|
|
|
The
|
|
|
|
.Dv M_RDONLY
|
|
|
|
flag can be set in the mbuf's
|
2001-02-01 16:38:02 +00:00
|
|
|
.Dv m_flags .
|
2000-11-21 22:29:31 +00:00
|
|
|
This can be achieved during setup of the external storage,
|
|
|
|
by passing the
|
|
|
|
.Dv M_RDONLY
|
|
|
|
bit as a
|
2001-02-16 09:05:48 +00:00
|
|
|
.Fa flags
|
2000-11-21 22:29:31 +00:00
|
|
|
argument to the
|
|
|
|
.Fn MEXTADD
|
|
|
|
macro, or can be directly set in individual mbufs.
|
2000-10-26 23:15:47 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The functions are:
|
2001-07-14 19:41:16 +00:00
|
|
|
.Bl -ohang -offset indent
|
2000-10-26 23:15:47 +00:00
|
|
|
.It Fn m_get how type
|
|
|
|
A function version of
|
2000-11-01 23:02:19 +00:00
|
|
|
.Fn MGET
|
|
|
|
for non-critical paths.
|
2001-02-16 03:23:04 +00:00
|
|
|
.It Fn m_getm orig len how type
|
|
|
|
Allocate
|
2001-02-16 09:05:48 +00:00
|
|
|
.Fa len
|
2001-02-16 03:23:04 +00:00
|
|
|
bytes worth of mbufs and mbuf clusters if necessary and append the resulting
|
|
|
|
allocated chain to the
|
2001-02-16 09:05:48 +00:00
|
|
|
.Fa orig
|
|
|
|
mbuf chain, if it is
|
|
|
|
.No non- Ns Dv NULL .
|
2001-02-16 03:23:04 +00:00
|
|
|
If the allocation fails at any point,
|
2001-02-16 09:05:48 +00:00
|
|
|
free whatever was allocated and return
|
|
|
|
.Dv NULL .
|
2001-02-16 03:23:04 +00:00
|
|
|
If
|
2001-02-16 09:05:48 +00:00
|
|
|
.Fa orig
|
|
|
|
is
|
|
|
|
.No non- Ns Dv NULL ,
|
2001-02-16 03:23:04 +00:00
|
|
|
it will not be freed.
|
|
|
|
It is possible to use
|
|
|
|
.Fn m_getm
|
|
|
|
to either append
|
2001-02-16 09:05:48 +00:00
|
|
|
.Fa len
|
2001-02-16 03:23:04 +00:00
|
|
|
bytes to an existing mbuf or mbuf chain
|
|
|
|
(for example, one which may be sitting in a pre-allocated ring)
|
|
|
|
or to simply perform an all-or-nothing mbuf and mbuf cluster allocation.
|
2000-10-26 23:15:47 +00:00
|
|
|
.It Fn m_gethdr how type
|
|
|
|
A function version of
|
2000-11-01 23:02:19 +00:00
|
|
|
.Fn MGETHDR
|
|
|
|
for non-critical paths.
|
2000-10-26 23:15:47 +00:00
|
|
|
.It Fn m_getclr how type
|
2000-11-01 23:02:19 +00:00
|
|
|
Allocate an mbuf and zero out the data region.
|
2000-10-26 23:15:47 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The functions below operate on mbuf chains.
|
|
|
|
.Bl -ohang -offset indent
|
|
|
|
.It Fn m_freem mbuf
|
|
|
|
Free an entire mbuf chain, including any external
|
|
|
|
storage.
|
|
|
|
.\"
|
|
|
|
.It Fn m_adj mbuf len
|
|
|
|
Trim
|
|
|
|
.Fa len
|
2000-11-10 10:22:49 +00:00
|
|
|
bytes from the head of an mbuf chain if
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fa len
|
|
|
|
is positive, from the tail otherwise.
|
|
|
|
.\"
|
|
|
|
.It Fn m_prepend mbuf len how
|
|
|
|
Allocate a new mbuf and prepend it to the chain, handle
|
|
|
|
.Dv M_PKTHDR
|
|
|
|
properly.
|
|
|
|
.Sy Note :
|
|
|
|
It doesn't allocate any clusters, so
|
|
|
|
.Fa len
|
|
|
|
must be less than
|
|
|
|
.Dv MLEN
|
|
|
|
or
|
|
|
|
.Dv MHLEN ,
|
|
|
|
depending on the
|
2001-02-01 16:38:02 +00:00
|
|
|
.Dv M_PKTHDR
|
|
|
|
flag setting.
|
2000-10-26 23:15:47 +00:00
|
|
|
.\"
|
|
|
|
.It Fn m_pullup mbuf len
|
|
|
|
Arrange that the first
|
|
|
|
.Fa len
|
2000-11-10 10:22:49 +00:00
|
|
|
bytes of an mbuf chain are contiguous and lay in the data area of
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fa mbuf ,
|
|
|
|
so they are accessible with
|
|
|
|
.Fn mtod mbuf type .
|
|
|
|
Return the new chain on success,
|
|
|
|
.Dv NULL
|
|
|
|
on failure
|
2001-08-07 15:48:51 +00:00
|
|
|
(the chain is freed in this case).
|
2000-10-26 23:15:47 +00:00
|
|
|
.Sy Note :
|
|
|
|
It doesn't allocate any clusters, so
|
|
|
|
.Fa len
|
|
|
|
must be less than
|
|
|
|
.Dv MHLEN .
|
|
|
|
.\"
|
|
|
|
.It Fn m_copym mbuf offset len how
|
2001-07-14 19:41:16 +00:00
|
|
|
Make a copy of an mbuf chain starting
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fa offset
|
2001-07-14 19:41:16 +00:00
|
|
|
bytes from the beginning, continuing for
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fa len
|
2000-11-10 10:08:34 +00:00
|
|
|
bytes.
|
|
|
|
If
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fa len
|
|
|
|
is
|
|
|
|
.Dv M_COPYALL ,
|
|
|
|
copy to the end of the mbuf chain.
|
|
|
|
.Sy Note :
|
|
|
|
The copy is read-only, because clusters are not
|
|
|
|
copied, only their reference counts are incremented.
|
|
|
|
.\"
|
|
|
|
.It Fn m_copypacket mbuf how
|
|
|
|
Copy an entire packet including header, which must be present.
|
|
|
|
This is an optimized version of the common case
|
|
|
|
.Fn m_copym mbuf 0 M_COPYALL how .
|
|
|
|
.Sy Note :
|
|
|
|
the copy is read-only, because clusters are not
|
|
|
|
copied, only their reference counts are incremented.
|
|
|
|
.\"
|
|
|
|
.It Fn m_dup mbuf how
|
|
|
|
Copy a packet header mbuf chain into a completely new chain, including
|
2000-11-10 10:08:34 +00:00
|
|
|
copying any mbuf clusters.
|
|
|
|
Use this instead of
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fn m_copypacket
|
|
|
|
when you need a writable copy of an mbuf chain.
|
|
|
|
.\"
|
|
|
|
.It Fn m_copydata mbuf offset len buf
|
2000-11-10 10:22:49 +00:00
|
|
|
Copy data from an mbuf chain starting
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fa off
|
|
|
|
bytes from the beginning, continuing for
|
|
|
|
.Fa len
|
2001-07-14 19:41:16 +00:00
|
|
|
bytes, into the indicated buffer
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fa buf .
|
|
|
|
.\"
|
|
|
|
.It Fn m_copyback mbuf offset len buf
|
|
|
|
Copy
|
|
|
|
.Fa len
|
|
|
|
bytes from the buffer
|
|
|
|
.Fa buf
|
|
|
|
back into the indicated mbuf chain,
|
|
|
|
starting at
|
|
|
|
.Fa offset
|
|
|
|
bytes from the beginning of the chain, extending the mbuf chain if necessary.
|
|
|
|
.Sy Note :
|
2000-11-10 10:08:34 +00:00
|
|
|
It doesn't allocate any clusters, just adds mbufs to the chain.
|
|
|
|
It's safe to set
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fa offset
|
|
|
|
beyond the current chain end: zeroed mbufs will be allocated to fill the
|
|
|
|
space.
|
|
|
|
.\"
|
|
|
|
.It Fn m_devget buf len offset ifp copy
|
|
|
|
Copy data from a device local memory pointed to by
|
|
|
|
.Fa buf
|
2000-11-10 10:22:49 +00:00
|
|
|
to an mbuf chain.
|
2000-11-10 10:08:34 +00:00
|
|
|
The copy is done using a specified copy routine
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fa copy ,
|
|
|
|
or
|
|
|
|
.Fn bcopy
|
|
|
|
if
|
|
|
|
.Fa copy
|
|
|
|
is
|
|
|
|
.Dv NULL .
|
|
|
|
.\"
|
|
|
|
.It Fn m_cat m n
|
|
|
|
Concatenate
|
|
|
|
.Fa n
|
|
|
|
to
|
|
|
|
.Fa m .
|
|
|
|
Both chains must be of the same type.
|
|
|
|
.Fa N
|
|
|
|
is still valid after the function returned.
|
|
|
|
.Sy Note :
|
|
|
|
It does not handle
|
|
|
|
.Dv M_PKTHDR
|
|
|
|
and friends.
|
|
|
|
.\"
|
|
|
|
.It Fn m_split mbuf len how
|
|
|
|
Partition an mbuf chain in two pieces, returning the tail:
|
|
|
|
all but the first
|
|
|
|
.Fa len
|
2000-11-10 10:08:34 +00:00
|
|
|
bytes.
|
|
|
|
In case of failure, it returns
|
2000-10-26 23:15:47 +00:00
|
|
|
.Dv NULL
|
|
|
|
and attempts to restore the chain to its original state.
|
2000-12-29 09:18:45 +00:00
|
|
|
.El
|
2000-10-26 23:15:47 +00:00
|
|
|
.Sh RETURN VALUES
|
|
|
|
See above.
|
|
|
|
.Sh HISTORY
|
|
|
|
.\" Please correct me if I'm wrong
|
2001-08-14 10:01:54 +00:00
|
|
|
Mbufs appeared in an early version of
|
|
|
|
.Bx .
|
2000-11-10 10:08:34 +00:00
|
|
|
Besides for being used for network packets, they were used
|
2000-11-01 23:02:19 +00:00
|
|
|
to store various dynamic structures, such as routing table
|
|
|
|
entries, interface addresses, protocol control blocks, etc.
|
2000-10-26 23:15:47 +00:00
|
|
|
.Sh AUTHORS
|
2001-08-08 11:48:28 +00:00
|
|
|
The original
|
|
|
|
.Nm
|
|
|
|
man page was written by Yar Tikhiy.
|