xref: /freebsd/share/man/man9/mbuf.9 (revision 53b2520d01fc8262caf7af67cdac9fbf60f872ce)
1de06f907SNik Clayton.\" Copyright (c) 2000 FreeBSD Inc.
2de06f907SNik Clayton.\" All rights reserved.
3de06f907SNik Clayton.\"
4de06f907SNik Clayton.\" Redistribution and use in source and binary forms, with or without
5de06f907SNik Clayton.\" modification, are permitted provided that the following conditions
6de06f907SNik Clayton.\" are met:
7de06f907SNik Clayton.\" 1. Redistributions of source code must retain the above copyright
8de06f907SNik Clayton.\"    notice, this list of conditions and the following disclaimer.
9de06f907SNik Clayton.\" 2. Redistributions in binary form must reproduce the above copyright
10de06f907SNik Clayton.\"    notice, this list of conditions and the following disclaimer in the
11de06f907SNik Clayton.\"    documentation and/or other materials provided with the distribution.
12de06f907SNik Clayton.\"
13de06f907SNik Clayton.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14de06f907SNik Clayton.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15de06f907SNik Clayton.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16de06f907SNik Clayton.\" ARE DISCLAIMED.  IN NO EVENT SHALL [your name] OR CONTRIBUTORS BE LIABLE
17de06f907SNik Clayton.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18de06f907SNik Clayton.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19de06f907SNik Clayton.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20de06f907SNik Clayton.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21de06f907SNik Clayton.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22de06f907SNik Clayton.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23de06f907SNik Clayton.\" SUCH DAMAGE.
24de06f907SNik Clayton.\"
25de06f907SNik Clayton.\" $FreeBSD$
26de06f907SNik Clayton.\"
27de06f907SNik Clayton.Dd October 17, 2000
28de06f907SNik Clayton.Dt MBUF 9
29de06f907SNik Clayton.Os
30de06f907SNik Clayton.\"
31de06f907SNik Clayton.Sh NAME
32de06f907SNik Clayton.Nm mbuf
33de06f907SNik Clayton.Nd "memory management in the kernel IPC subsystem"
34de06f907SNik Clayton.\"
35de06f907SNik Clayton.Sh SYNOPSIS
3632eef9aeSRuslan Ermilov.In sys/param.h
37f16b3c0dSChad David.In sys/systm.h
3832eef9aeSRuslan Ermilov.In sys/mbuf.h
39de06f907SNik Clayton.\"
40bfd59721SBosko Milekic.Ss Mbuf allocation macros
41de06f907SNik Clayton.Fn MGET "struct mbuf *mbuf" "int how" "short type"
42de06f907SNik Clayton.Fn MGETHDR "struct mbuf *mbuf" "int how" "short type"
43de06f907SNik Clayton.Fn MCLGET "struct mbuf *mbuf" "int how"
44bfd59721SBosko Milekic.Fo MEXTADD
45bfd59721SBosko Milekic.Fa "struct mbuf *mbuf"
46bfd59721SBosko Milekic.Fa "caddr_t buf"
47bfd59721SBosko Milekic.Fa "u_int size"
48bfd59721SBosko Milekic.Fa "void (*free)(void *opt_args)"
49bfd59721SBosko Milekic.Fa "void *opt_args"
505d4050ccSBosko Milekic.Fa "short flags"
515d4050ccSBosko Milekic.Fa "int type"
52bfd59721SBosko Milekic.Fc
53bfd59721SBosko Milekic.Fn MEXTFREE "struct mbuf *mbuf"
54bfd59721SBosko Milekic.Fn MEXT_ADD_REF "struct mbuf *mbuf"
55bfd59721SBosko Milekic.Fn MEXT_REM_REF "struct mbuf *mbuf"
56bfd59721SBosko Milekic.Fn MFREE "struct mbuf *mbuf" "struct mbuf *successor"
57de06f907SNik Clayton.\"
58bfd59721SBosko Milekic.Ss Mbuf utility macros
59f16b3c0dSChad David.Ft void *
60f16b3c0dSChad David.Fn mtod "struct mbuf *mbuf" "type"
61f16b3c0dSChad David.Ft int
62bfd59721SBosko Milekic.Fn MEXT_IS_REF "struct mbuf *mbuf"
63bfd59721SBosko Milekic.Fn M_ALIGN "struct mbuf *mbuf" "u_int len"
64bfd59721SBosko Milekic.Fn MH_ALIGN "struct mbuf *mbuf" "u_int len"
65f16b3c0dSChad David.Ft int
66bfd59721SBosko Milekic.Fn M_LEADINGSPACE "struct mbuf *mbuf"
67f16b3c0dSChad David.Ft int
68bfd59721SBosko Milekic.Fn M_TRAILINGSPACE "struct mbuf *mbuf"
69da72b998SYaroslav Tykhiy.Fn M_MOVE_PKTHDR "struct mbuf *to" "struct mbuf *from"
70bfd59721SBosko Milekic.Fn M_PREPEND "struct mbuf *mbuf" "int len" "int how"
71bfd59721SBosko Milekic.Fn MCHTYPE "struct mbuf *mbuf" "u_int type"
72f16b3c0dSChad David.Ft int
735d4050ccSBosko Milekic.Fn M_WRITABLE "struct mbuf *mbuf"
74bfd59721SBosko Milekic.\"
75bfd59721SBosko Milekic.Ss Mbuf allocation functions
76de06f907SNik Clayton.Ft struct mbuf *
77de06f907SNik Clayton.Fn m_get "int how" "int type"
78de06f907SNik Clayton.Ft struct mbuf *
79328c0bbcSBosko Milekic.Fn m_getm "struct mbuf *orig" "int len" "int how" "int type"
80328c0bbcSBosko Milekic.Ft struct mbuf *
81de06f907SNik Clayton.Fn m_getclr "int how" "int type"
82de06f907SNik Clayton.Ft struct mbuf *
83de06f907SNik Clayton.Fn m_gethdr "int how" "int type"
84bfd59721SBosko Milekic.Ft struct mbuf *
85bfd59721SBosko Milekic.Fn m_free "struct mbuf *mbuf"
86de06f907SNik Clayton.Ft void
87de06f907SNik Clayton.Fn m_freem "struct mbuf *mbuf"
88bfd59721SBosko Milekic.\"
89bfd59721SBosko Milekic.Ss Mbuf utility functions
90de06f907SNik Clayton.Ft void
91de06f907SNik Clayton.Fn m_adj "struct mbuf *mbuf" "int len"
92de06f907SNik Clayton.Ft struct mbuf *
93de06f907SNik Clayton.Fn m_prepend "struct mbuf *mbuf" "int len" "int how"
94de06f907SNik Clayton.Ft struct mbuf *
95de06f907SNik Clayton.Fn m_pullup "struct mbuf *mbuf" "int len"
96de06f907SNik Clayton.Ft struct mbuf *
97de06f907SNik Clayton.Fn m_copym "struct mbuf *mbuf" "int offset" "int len" "int how"
98de06f907SNik Clayton.Ft struct mbuf *
99de06f907SNik Clayton.Fn m_copypacket "struct mbuf *mbuf" "int how"
100de06f907SNik Clayton.Ft struct mbuf *
101de06f907SNik Clayton.Fn m_dup "struct mbuf *mbuf" "int how"
102de06f907SNik Clayton.Ft void
1030d8e4c57SBruce Evans.Fn m_copydata "const struct mbuf *mbuf" "int offset" "int len" "caddr_t buf"
104de06f907SNik Clayton.Ft void
105de06f907SNik Clayton.Fn m_copyback "struct mbuf *mbuf" "int offset" "int len" "caddr_t buf"
106de06f907SNik Clayton.Ft struct mbuf *
107de06f907SNik Clayton.Fo m_devget
108de06f907SNik Clayton.Fa "char *buf"
109de06f907SNik Clayton.Fa "int len"
110de06f907SNik Clayton.Fa "int offset"
111de06f907SNik Clayton.Fa "struct ifnet *ifp"
112de06f907SNik Clayton.Fa "void (*copy)(char *from, caddr_t to, u_int len)"
113de06f907SNik Clayton.Fc
114de06f907SNik Clayton.Ft void
115de06f907SNik Clayton.Fn m_cat "struct mbuf *m" "struct mbuf *n"
116e60fa837SRuslan Ermilov.Ft u_int
1170b1c0994SPoul-Henning Kamp.Fn m_fixhdr "struct mbuf *mbuf"
118da72b998SYaroslav Tykhiy.Ft void
119da72b998SYaroslav Tykhiy.Fn m_dup_pkthdr "struct mbuf *to" "struct mbuf *from"
120da72b998SYaroslav Tykhiy.Ft void
121da72b998SYaroslav Tykhiy.Fn m_move_pkthdr "struct mbuf *to" "struct mbuf *from"
122e60fa837SRuslan Ermilov.Ft u_int
1230b1c0994SPoul-Henning Kamp.Fn m_length "struct mbuf *mbuf" "struct mbuf **last"
124de06f907SNik Clayton.Ft struct mbuf *
125de06f907SNik Clayton.Fn m_split "struct mbuf *mbuf" "int len" "int how"
126de06f907SNik Clayton.\"
127de06f907SNik Clayton.Sh DESCRIPTION
1287b2fd183SYaroslav TykhiyAn
1297b2fd183SYaroslav Tykhiy.Vt mbuf
1307b2fd183SYaroslav Tykhiyis a basic unit of memory management in the kernel IPC subsystem.
1317b2fd183SYaroslav TykhiyNetwork packets and socket buffers are stored in
1327b2fd183SYaroslav Tykhiy.Vt mbufs .
1337b2fd183SYaroslav TykhiyA network packet may span multiple
1347b2fd183SYaroslav Tykhiy.Vt mbufs
1357b2fd183SYaroslav Tykhiyarranged into a
1367b2fd183SYaroslav Tykhiy.Vt mbuf chain
137c4d9468eSRuslan Ermilov(linked list),
138de06f907SNik Claytonwhich allows adding or trimming
139bfd59721SBosko Milekicnetwork headers with little overhead.
140de06f907SNik Clayton.Pp
1417b2fd183SYaroslav TykhiyWhile a developer should not bother with
1427b2fd183SYaroslav Tykhiy.Vt mbuf
1437b2fd183SYaroslav Tykhiyinternals without serious
144de06f907SNik Claytonreason in order to avoid incompatibilities with future changes, it
1457b2fd183SYaroslav Tykhiyis useful to understand the general structure of an
1467b2fd183SYaroslav Tykhiy.Vt mbuf .
147de06f907SNik Clayton.Pp
1487b2fd183SYaroslav TykhiyAn
1497b2fd183SYaroslav Tykhiy.Vt mbuf
1507b2fd183SYaroslav Tykhiyconsists of a variable-sized header and a small internal
151e73145f6SSheldon Hearnbuffer for data.
1527b2fd183SYaroslav TykhiyThe total size of an
1537b2fd183SYaroslav Tykhiy.Vt mbuf ,
154bfd59721SBosko Milekic.Dv MSIZE ,
155de06f907SNik Claytonis a machine-dependent constant defined in
156743d5d51SRuslan Ermilov.In machine/param.h .
1577b2fd183SYaroslav TykhiyThe
1587b2fd183SYaroslav Tykhiy.Vt mbuf
1597b2fd183SYaroslav Tykhiyheader includes:
160de06f907SNik Clayton.Pp
161de06f907SNik Clayton.Bl -tag -width "m_nextpkt" -compact -offset indent
162be82a0bcSYaroslav Tykhiy.It Va m_next
1637b2fd183SYaroslav Tykhiya pointer to the next
1647b2fd183SYaroslav Tykhiy.Vt mbuf
1657b2fd183SYaroslav Tykhiyin the
1667b2fd183SYaroslav Tykhiy.Vt mbuf chain
167be82a0bcSYaroslav Tykhiy.It Va m_nextpkt
1687b2fd183SYaroslav Tykhiya pointer to the next
1697b2fd183SYaroslav Tykhiy.Vt mbuf chain
1707b2fd183SYaroslav Tykhiyin the queue
171be82a0bcSYaroslav Tykhiy.It Va m_data
172de06f907SNik Claytona pointer to the data
173be82a0bcSYaroslav Tykhiy.It Va m_len
174de06f907SNik Claytonthe length of the data
175be82a0bcSYaroslav Tykhiy.It Va m_type
176bfd59721SBosko Milekicthe type of data
177be82a0bcSYaroslav Tykhiy.It Va m_flags
1787b2fd183SYaroslav Tykhiythe
1797b2fd183SYaroslav Tykhiy.Vt mbuf
1807b2fd183SYaroslav Tykhiyflags
181de06f907SNik Clayton.El
182de06f907SNik Clayton.Pp
1837b2fd183SYaroslav TykhiyThe
1847b2fd183SYaroslav Tykhiy.Vt mbuf
1857b2fd183SYaroslav Tykhiyflag bits are defined as follows:
186de06f907SNik Clayton.Bd -literal
187de06f907SNik Clayton/* mbuf flags */
188de06f907SNik Clayton#define	M_EXT		0x0001	/* has associated external storage */
189de06f907SNik Clayton#define	M_PKTHDR	0x0002	/* start of record */
190de06f907SNik Clayton#define	M_EOR		0x0004	/* end of record */
1915d4050ccSBosko Milekic#define	M_RDONLY	0x0008	/* associated data marked read-only */
1925d4050ccSBosko Milekic#define	M_PROTO1	0x0010	/* protocol-specific */
1935d4050ccSBosko Milekic#define	M_PROTO2	0x0020 	/* protocol-specific */
1945d4050ccSBosko Milekic#define	M_PROTO3	0x0040	/* protocol-specific */
1955d4050ccSBosko Milekic#define	M_PROTO4	0x0080	/* protocol-specific */
1965d4050ccSBosko Milekic#define	M_PROTO5	0x0100	/* protocol-specific */
197de06f907SNik Clayton
198de06f907SNik Clayton/* mbuf pkthdr flags, also in m_flags */
1995d4050ccSBosko Milekic#define	M_BCAST		0x0200	/* send/received as link-level broadcast */
2005d4050ccSBosko Milekic#define	M_MCAST		0x0400	/* send/received as link-level multicast */
2015d4050ccSBosko Milekic#define	M_FRAG		0x0800	/* packet is fragment of larger packet */
2025d4050ccSBosko Milekic#define	M_FIRSTFRAG	0x1000	/* packet is first fragment */
2035d4050ccSBosko Milekic#define	M_LASTFRAG	0x2000	/* packet is last fragment */
204de06f907SNik Clayton.Ed
205de06f907SNik Clayton.Pp
2067b2fd183SYaroslav TykhiyThe available
2077b2fd183SYaroslav Tykhiy.Vt mbuf
2087b2fd183SYaroslav Tykhiytypes are defined as follows:
209de06f907SNik Clayton.Bd -literal
210de06f907SNik Clayton/* mbuf types */
211de06f907SNik Clayton#define	MT_FREE		0	/* should be on free list */
212de06f907SNik Clayton#define	MT_DATA		1	/* dynamic (data) allocation */
213de06f907SNik Clayton#define	MT_HEADER	2	/* packet header */
214de06f907SNik Clayton#define	MT_SONAME	8	/* socket name */
215de06f907SNik Clayton#define	MT_FTABLE	11	/* fragment reassembly header */
216de06f907SNik Clayton#define	MT_CONTROL	14	/* extra-data protocol message */
217de06f907SNik Clayton#define	MT_OOBDATA	15	/* expedited data  */
218de06f907SNik Clayton.Ed
219de06f907SNik Clayton.Pp
220de06f907SNik ClaytonIf the
221de06f907SNik Clayton.Dv M_PKTHDR
222de06f907SNik Claytonflag is set, a
2237b2fd183SYaroslav Tykhiy.Vt struct pkthdr Va m_pkthdr
2247b2fd183SYaroslav Tykhiyis added to the
2257b2fd183SYaroslav Tykhiy.Vt mbuf
2267b2fd183SYaroslav Tykhiyheader.
227e73145f6SSheldon HearnIt contains a pointer to the interface
228de06f907SNik Claytonthe packet has been received from
2297b2fd183SYaroslav Tykhiy.Pq Vt struct ifnet Va *rcvif ,
230de06f907SNik Claytonand the total packet length
2317b2fd183SYaroslav Tykhiy.Pq Vt int Va len .
232de06f907SNik Clayton.Pp
2337b2fd183SYaroslav TykhiyIf small enough, data is stored in the internal data buffer of an
2347b2fd183SYaroslav Tykhiy.Vt mbuf .
2357b2fd183SYaroslav TykhiyIf the data is sufficiently large, another
2367b2fd183SYaroslav Tykhiy.Vt mbuf
2377b2fd183SYaroslav Tykhiymay be added to the
2387b2fd183SYaroslav Tykhiy.Vt mbuf chain ,
2397b2fd183SYaroslav Tykhiyor external storage may be associated with the
2407b2fd183SYaroslav Tykhiy.Vt mbuf .
241de06f907SNik Clayton.Dv MHLEN
2427b2fd183SYaroslav Tykhiybytes of data can fit into an
2437b2fd183SYaroslav Tykhiy.Vt mbuf
2447b2fd183SYaroslav Tykhiywith the
245de06f907SNik Clayton.Dv M_PKTHDR
246de06f907SNik Claytonflag set,
247de06f907SNik Clayton.Dv MLEN
248de06f907SNik Claytonbytes can otherwise.
249de06f907SNik Clayton.Pp
2507b2fd183SYaroslav TykhiyIf external storage is being associated with an
2517b2fd183SYaroslav Tykhiy.Vt mbuf ,
2527b2fd183SYaroslav Tykhiythe
253be82a0bcSYaroslav Tykhiy.Va m_ext
25425f1a2e9SSheldon Hearnheader is added at the cost of losing the internal data buffer.
255e73145f6SSheldon HearnIt includes a pointer to external storage, the size of the storage,
256e73145f6SSheldon Hearna pointer to a function used for freeing the storage,
257e73145f6SSheldon Hearna pointer to an optional argument that can be passed to the function,
258e73145f6SSheldon Hearnand a pointer to a reference counter.
2597b2fd183SYaroslav TykhiyAn
2607b2fd183SYaroslav Tykhiy.Vt mbuf
2617b2fd183SYaroslav Tykhiyusing external storage has the
262de06f907SNik Clayton.Dv M_EXT
263de06f907SNik Claytonflag set.
264de06f907SNik Clayton.Pp
265bfd59721SBosko MilekicThe system supplies a macro for allocating the desired external storage
266bfd59721SBosko Milekicbuffer,
267bfd59721SBosko Milekic.Dv MEXTADD .
268bfd59721SBosko Milekic.Pp
269bfd59721SBosko MilekicThe allocation and management of the reference counter is handled by the
270e73145f6SSheldon Hearnsubsystem.
271e73145f6SSheldon HearnThe developer can check whether the reference count for the
2727b2fd183SYaroslav Tykhiyexternal storage of a given
2737b2fd183SYaroslav Tykhiy.Vt mbuf
2747b2fd183SYaroslav Tykhiyis greater than 1 with the
275bfd59721SBosko Milekic.Dv MEXT_IS_REF
276e73145f6SSheldon Hearnmacro.
277e73145f6SSheldon HearnSimilarly, the developer can directly add and remove references,
278e73145f6SSheldon Hearnif absolutely necessary, with the use of the
279bfd59721SBosko Milekic.Dv MEXT_ADD_REF
280bfd59721SBosko Milekicand
281bfd59721SBosko Milekic.Dv MEXT_REM_REF
282bfd59721SBosko Milekicmacros.
283bfd59721SBosko Milekic.Pp
284bfd59721SBosko MilekicThe system also supplies a default type of external storage buffer called an
2857b2fd183SYaroslav Tykhiy.Vt mbuf cluster .
2867b2fd183SYaroslav Tykhiy.Vt Mbuf clusters
2877b2fd183SYaroslav Tykhiycan be allocated and configured with the use of the
288bfd59721SBosko Milekic.Dv MCLGET
289e73145f6SSheldon Hearnmacro.
2907b2fd183SYaroslav TykhiyEach
2917b2fd183SYaroslav Tykhiy.Vt mbuf cluster
2927b2fd183SYaroslav Tykhiyis
293de06f907SNik Clayton.Dv MCLBYTES
294bfd59721SBosko Milekicin size, where MCLBYTES is a machine-dependent constant.
295bfd59721SBosko MilekicThe system defines an advisory macro
296de06f907SNik Clayton.Dv MINCLSIZE ,
2977b2fd183SYaroslav Tykhiywhich is the smallest amount of data to put into an
2987b2fd183SYaroslav Tykhiy.Vt mbuf cluster .
299de06f907SNik ClaytonIt's equal to the sum of
300de06f907SNik Clayton.Dv MLEN
301de06f907SNik Claytonand
302de06f907SNik Clayton.Dv MHLEN .
3037b2fd183SYaroslav TykhiyIt is typically preferable to store data into the data region of an
3047b2fd183SYaroslav Tykhiy.Vt mbuf ,
3057b2fd183SYaroslav Tykhiyif size permits, as opposed to allocating a separate
3067b2fd183SYaroslav Tykhiy.Vt mbuf cluster
3077b2fd183SYaroslav Tykhiyto hold the same data.
308de06f907SNik Clayton.\"
309de06f907SNik Clayton.Ss Macros and Functions
310bfd59721SBosko MilekicThere are numerous predefined macros and functions that provide the
311bfd59721SBosko Milekicdeveloper with common utilities.
312de06f907SNik Clayton.\"
313de06f907SNik Clayton.Bl -ohang -offset indent
314de06f907SNik Clayton.It Fn mtod mbuf type
3157b2fd183SYaroslav TykhiyConvert an
3167b2fd183SYaroslav Tykhiy.Fa mbuf
3177b2fd183SYaroslav Tykhiypointer to a data pointer.
3187b2fd183SYaroslav TykhiyThe macro expands to the data pointer cast to the pointer of the specified
3197b2fd183SYaroslav Tykhiy.Fa type .
320de06f907SNik Clayton.Sy Note :
3217b2fd183SYaroslav TykhiyIt is advisable to ensure that there is enough contiguous data in
3227b2fd183SYaroslav Tykhiy.Fa mbuf .
323de06f907SNik ClaytonSee
324de06f907SNik Clayton.Fn m_pullup
325de06f907SNik Claytonfor details.
326de06f907SNik Clayton.It Fn MGET mbuf how type
3277b2fd183SYaroslav TykhiyAllocate an
3287b2fd183SYaroslav Tykhiy.Vt mbuf
3297b2fd183SYaroslav Tykhiyand initialize it to contain internal data.
33025f1a2e9SSheldon Hearn.Fa mbuf
3317b2fd183SYaroslav Tykhiywill point to the allocated
3327b2fd183SYaroslav Tykhiy.Vt mbuf
3337b2fd183SYaroslav Tykhiyon success, or be set to
334de06f907SNik Clayton.Dv NULL
335e73145f6SSheldon Hearnon failure.
336e73145f6SSheldon HearnThe
337de06f907SNik Clayton.Fa how
338de06f907SNik Claytonargument is to be set to
339c65b53c5STom Rhodes.Dv M_TRYWAIT
340de06f907SNik Claytonor
341c65b53c5STom Rhodes.Dv M_DONTWAIT .
34225f1a2e9SSheldon HearnIt specifies whether the caller is willing to block if necessary.
343e73145f6SSheldon HearnIf
344de06f907SNik Clayton.Fa how
34525f1a2e9SSheldon Hearnis set to
346c65b53c5STom Rhodes.Dv M_TRYWAIT ,
34725f1a2e9SSheldon Hearna failed allocation will result in the caller being put
348bfd59721SBosko Milekicto sleep for a designated
34925f1a2e9SSheldon Hearnkern.ipc.mbuf_wait
350c4d9468eSRuslan Ermilov.Xr ( sysctl 8
351c4d9468eSRuslan Ermilovtunable)
35225f1a2e9SSheldon Hearnnumber of ticks.
3537b2fd183SYaroslav TykhiyA number of other functions and macros related to
3547b2fd183SYaroslav Tykhiy.Vt mbufs
3557b2fd183SYaroslav Tykhiyhave the same argument because they may
3567b2fd183SYaroslav Tykhiyat some point need to allocate new
3577b2fd183SYaroslav Tykhiy.Vt mbufs .
358c65b53c5STom Rhodes.Pp
3597b2fd183SYaroslav TykhiyProgrammers should be careful not to confuse the
3607b2fd183SYaroslav Tykhiy.Vt mbuf
3617b2fd183SYaroslav Tykhiyallocation flag
362c65b53c5STom Rhodes.Dv M_DONTWAIT
363c65b53c5STom Rhodeswith the
364c65b53c5STom Rhodes.Xr malloc 9
365c65b53c5STom Rhodesallocation flag,
366c65b53c5STom Rhodes.Dv M_NOWAIT .
367c65b53c5STom RhodesThey are not the same.
368de06f907SNik Clayton.It Fn MGETHDR mbuf how type
3697b2fd183SYaroslav TykhiyAllocate an
3707b2fd183SYaroslav Tykhiy.Vt mbuf
3717b2fd183SYaroslav Tykhiyand initialize it to contain a packet header
372e73145f6SSheldon Hearnand internal data.
373e73145f6SSheldon HearnSee
374de06f907SNik Clayton.Fn MGET
375de06f907SNik Claytonfor details.
376de06f907SNik Clayton.It Fn MCLGET mbuf how
3777b2fd183SYaroslav TykhiyAllocate and attach an
3787b2fd183SYaroslav Tykhiy.Vt mbuf cluster
3797b2fd183SYaroslav Tykhiyto
3807b2fd183SYaroslav Tykhiy.Fa mbuf .
381e73145f6SSheldon HearnIf the macro fails, the
382de06f907SNik Clayton.Dv M_EXT
3837b2fd183SYaroslav Tykhiyflag won't be set in
3847b2fd183SYaroslav Tykhiy.Fa mbuf .
385da72b998SYaroslav Tykhiy.It Fn M_ALIGN mbuf len
386da72b998SYaroslav TykhiySet the pointer
387da72b998SYaroslav Tykhiy.Fa mbuf->m_data
388da72b998SYaroslav Tykhiyto place an object of the size
389da72b998SYaroslav Tykhiy.Fa len
390da72b998SYaroslav Tykhiyat the end of the internal data area of
391da72b998SYaroslav Tykhiy.Fa mbuf ,
392da72b998SYaroslav Tykhiylong word aligned.
393da72b998SYaroslav TykhiyApplicable only if
394da72b998SYaroslav Tykhiy.Fa mbuf
395da72b998SYaroslav Tykhiyis newly allocated with
396da72b998SYaroslav Tykhiy.Fn MGET
397da72b998SYaroslav Tykhiyor
398da72b998SYaroslav Tykhiy.Fn m_get .
399da72b998SYaroslav Tykhiy.It Fn MH_ALIGN mbuf len
400da72b998SYaroslav TykhiyServes the same purpose as
401da72b998SYaroslav Tykhiy.Fn M_ALIGN
402da72b998SYaroslav Tykhiydoes, but only for
403da72b998SYaroslav Tykhiy.Fa mbuf
404da72b998SYaroslav Tykhiynewly allocated with
405da72b998SYaroslav Tykhiy.Fn MGETHDR
406da72b998SYaroslav Tykhiyor
407da72b998SYaroslav Tykhiy.Fn m_gethdr ,
408da72b998SYaroslav Tykhiyor initialized by
409da72b998SYaroslav Tykhiy.Fn m_dup_pkthdr
410da72b998SYaroslav Tykhiyor
411da72b998SYaroslav Tykhiy.Fn m_move_pkthdr .
412da72b998SYaroslav Tykhiy.It Fn M_LEADINGSPACE mbuf
413da72b998SYaroslav TykhiyReturns the number of bytes available before the beginning
414da72b998SYaroslav Tykhiyof data in
415da72b998SYaroslav Tykhiy.Fa mbuf .
416da72b998SYaroslav Tykhiy.It Fn M_TRAILINGSPACE mbuf
417da72b998SYaroslav TykhiyReturns the number of bytes available after the end of data in
418da72b998SYaroslav Tykhiy.Fa mbuf .
419de06f907SNik Clayton.It Fn M_PREPEND mbuf len how
4207b2fd183SYaroslav TykhiyThis macro operates on an
4217b2fd183SYaroslav Tykhiy.Vt mbuf chain .
422de06f907SNik ClaytonIt is an optimized wrapper for
423de06f907SNik Clayton.Fn m_prepend
424de06f907SNik Claytonthat can make use of possible empty space before data
425c4d9468eSRuslan Ermilov(e.g. left after trimming of a link-layer header).
4267b2fd183SYaroslav TykhiyThe new
4277b2fd183SYaroslav Tykhiy.Vt mbuf chain
4287b2fd183SYaroslav Tykhiypointer or
429de06f907SNik Clayton.Dv NULL
430de06f907SNik Claytonis in
431de06f907SNik Clayton.Fa mbuf
432de06f907SNik Claytonafter the call.
433da72b998SYaroslav Tykhiy.It Fn M_MOVE_PKTHDR to from
434da72b998SYaroslav TykhiyUsing this macro is equivalent to calling
435da72b998SYaroslav Tykhiy.Fn m_move_pkthdr to from .
4365d4050ccSBosko Milekic.It Fn M_WRITABLE mbuf
4377b2fd183SYaroslav TykhiyThis macro will evaluate true if
4387b2fd183SYaroslav Tykhiy.Fa mbuf
4397b2fd183SYaroslav Tykhiyis not marked
4405d4050ccSBosko Milekic.Dv M_RDONLY
4417b2fd183SYaroslav Tykhiyand if either
4427b2fd183SYaroslav Tykhiy.Fa mbuf
4437b2fd183SYaroslav Tykhiydoes not contain external storage or,
4445d4050ccSBosko Milekicif it does,
4455d4050ccSBosko Milekicthen if the reference count of the storage is not greater than 1.
4465d4050ccSBosko MilekicThe
4475d4050ccSBosko Milekic.Dv M_RDONLY
4487b2fd183SYaroslav Tykhiyflag can be set in
4497b2fd183SYaroslav Tykhiy.Fa mbuf->m_flags .
4505d4050ccSBosko MilekicThis can be achieved during setup of the external storage,
4515d4050ccSBosko Milekicby passing the
4525d4050ccSBosko Milekic.Dv M_RDONLY
4535d4050ccSBosko Milekicbit as a
4540b39b3ffSRuslan Ermilov.Fa flags
4555d4050ccSBosko Milekicargument to the
4565d4050ccSBosko Milekic.Fn MEXTADD
4577b2fd183SYaroslav Tykhiymacro, or can be directly set in individual
4587b2fd183SYaroslav Tykhiy.Vt mbufs .
459da72b998SYaroslav Tykhiy.It Fn MCHTYPE mbuf type
460da72b998SYaroslav TykhiyChange the type of
461da72b998SYaroslav Tykhiy.Fa mbuf
462da72b998SYaroslav Tykhiyto
463da72b998SYaroslav Tykhiy.Fa type .
464da72b998SYaroslav TykhiyThis is a relatively expensive operation and should be avoided.
465de06f907SNik Clayton.El
466de06f907SNik Clayton.Pp
467de06f907SNik ClaytonThe functions are:
468de06f907SNik Clayton.Bl -ohang -offset indent
469de06f907SNik Clayton.It Fn m_get how type
470de06f907SNik ClaytonA function version of
471bfd59721SBosko Milekic.Fn MGET
472bfd59721SBosko Milekicfor non-critical paths.
473328c0bbcSBosko Milekic.It Fn m_getm orig len how type
474328c0bbcSBosko MilekicAllocate
4750b39b3ffSRuslan Ermilov.Fa len
4767b2fd183SYaroslav Tykhiybytes worth of
4777b2fd183SYaroslav Tykhiy.Vt mbufs
4787b2fd183SYaroslav Tykhiyand
4797b2fd183SYaroslav Tykhiy.Vt mbuf clusters
4807b2fd183SYaroslav Tykhiyif necessary and append the resulting allocated
4817b2fd183SYaroslav Tykhiy.Vt mbuf chain
4827b2fd183SYaroslav Tykhiyto the
4837b2fd183SYaroslav Tykhiy.Vt mbuf chain
4847b2fd183SYaroslav Tykhiy.Fa orig ,
4857b2fd183SYaroslav Tykhiyif it is
4860b39b3ffSRuslan Ermilov.No non- Ns Dv NULL .
487328c0bbcSBosko MilekicIf the allocation fails at any point,
4880b39b3ffSRuslan Ermilovfree whatever was allocated and return
4890b39b3ffSRuslan Ermilov.Dv NULL .
490328c0bbcSBosko MilekicIf
4910b39b3ffSRuslan Ermilov.Fa orig
4920b39b3ffSRuslan Ermilovis
4930b39b3ffSRuslan Ermilov.No non- Ns Dv NULL ,
494328c0bbcSBosko Milekicit will not be freed.
495328c0bbcSBosko MilekicIt is possible to use
496328c0bbcSBosko Milekic.Fn m_getm
497328c0bbcSBosko Milekicto either append
4980b39b3ffSRuslan Ermilov.Fa len
4997b2fd183SYaroslav Tykhiybytes to an existing
5007b2fd183SYaroslav Tykhiy.Vt mbuf
5017b2fd183SYaroslav Tykhiyor
5027b2fd183SYaroslav Tykhiy.Vt mbuf chain
503328c0bbcSBosko Milekic(for example, one which may be sitting in a pre-allocated ring)
5047b2fd183SYaroslav Tykhiyor to simply perform an all-or-nothing
5057b2fd183SYaroslav Tykhiy.Vt mbuf
5067b2fd183SYaroslav Tykhiyand
5077b2fd183SYaroslav Tykhiy.Vt mbuf cluster
5087b2fd183SYaroslav Tykhiyallocation.
509de06f907SNik Clayton.It Fn m_gethdr how type
510de06f907SNik ClaytonA function version of
511bfd59721SBosko Milekic.Fn MGETHDR
512bfd59721SBosko Milekicfor non-critical paths.
513de06f907SNik Clayton.It Fn m_getclr how type
5147b2fd183SYaroslav TykhiyAllocate an
5157b2fd183SYaroslav Tykhiy.Vt mbuf
5167b2fd183SYaroslav Tykhiyand zero out the data region.
517de06f907SNik Clayton.El
518de06f907SNik Clayton.Pp
5197b2fd183SYaroslav TykhiyThe functions below operate on
5207b2fd183SYaroslav Tykhiy.Vt mbuf chains .
521de06f907SNik Clayton.Bl -ohang -offset indent
522de06f907SNik Clayton.It Fn m_freem mbuf
5237b2fd183SYaroslav TykhiyFree an entire
5247b2fd183SYaroslav Tykhiy.Vt mbuf chain ,
5257b2fd183SYaroslav Tykhiyincluding any external storage.
526de06f907SNik Clayton.\"
527de06f907SNik Clayton.It Fn m_adj mbuf len
528de06f907SNik ClaytonTrim
529de06f907SNik Clayton.Fa len
5307b2fd183SYaroslav Tykhiybytes from the head of an
5317b2fd183SYaroslav Tykhiy.Vt mbuf chain
5327b2fd183SYaroslav Tykhiyif
533de06f907SNik Clayton.Fa len
534de06f907SNik Claytonis positive, from the tail otherwise.
535de06f907SNik Clayton.\"
536de06f907SNik Clayton.It Fn m_prepend mbuf len how
5377b2fd183SYaroslav TykhiyAllocate a new
5387b2fd183SYaroslav Tykhiy.Vt mbuf
5397b2fd183SYaroslav Tykhiyand prepend it to the
5407b2fd183SYaroslav Tykhiy.Vt mbuf chain ,
5417b2fd183SYaroslav Tykhiyhandle
542de06f907SNik Clayton.Dv M_PKTHDR
543de06f907SNik Claytonproperly.
544de06f907SNik Clayton.Sy Note :
5457b2fd183SYaroslav TykhiyIt doesn't allocate any
5467b2fd183SYaroslav Tykhiy.Vt mbuf clusters ,
5477b2fd183SYaroslav Tykhiyso
548de06f907SNik Clayton.Fa len
549de06f907SNik Claytonmust be less than
550de06f907SNik Clayton.Dv MLEN
551de06f907SNik Claytonor
552de06f907SNik Clayton.Dv MHLEN ,
553de06f907SNik Claytondepending on the
554d0353b83SRuslan Ermilov.Dv M_PKTHDR
555d0353b83SRuslan Ermilovflag setting.
556de06f907SNik Clayton.\"
557de06f907SNik Clayton.It Fn m_pullup mbuf len
558de06f907SNik ClaytonArrange that the first
559de06f907SNik Clayton.Fa len
5607b2fd183SYaroslav Tykhiybytes of an
5617b2fd183SYaroslav Tykhiy.Vt mbuf chain
5627b2fd183SYaroslav Tykhiyare contiguous and lay in the data area of
563de06f907SNik Clayton.Fa mbuf ,
564de06f907SNik Claytonso they are accessible with
565de06f907SNik Clayton.Fn mtod mbuf type .
5667b2fd183SYaroslav TykhiyReturn the new
5677b2fd183SYaroslav Tykhiy.Vt mbuf chain
5687b2fd183SYaroslav Tykhiyon success,
569de06f907SNik Clayton.Dv NULL
570de06f907SNik Claytonon failure
5717b2fd183SYaroslav Tykhiy(the
5727b2fd183SYaroslav Tykhiy.Vt mbuf chain
5737b2fd183SYaroslav Tykhiyis freed in this case).
574de06f907SNik Clayton.Sy Note :
5757b2fd183SYaroslav TykhiyIt doesn't allocate any
5767b2fd183SYaroslav Tykhiy.Vt mbuf clusters ,
5777b2fd183SYaroslav Tykhiyso
578de06f907SNik Clayton.Fa len
579de06f907SNik Claytonmust be less than
580de06f907SNik Clayton.Dv MHLEN .
581de06f907SNik Clayton.\"
582de06f907SNik Clayton.It Fn m_copym mbuf offset len how
5837b2fd183SYaroslav TykhiyMake a copy of an
5847b2fd183SYaroslav Tykhiy.Vt mbuf chain
5857b2fd183SYaroslav Tykhiystarting
586de06f907SNik Clayton.Fa offset
587de06f907SNik Claytonbytes from the beginning, continuing for
588de06f907SNik Clayton.Fa len
589e73145f6SSheldon Hearnbytes.
590e73145f6SSheldon HearnIf
591de06f907SNik Clayton.Fa len
592de06f907SNik Claytonis
593de06f907SNik Clayton.Dv M_COPYALL ,
5947b2fd183SYaroslav Tykhiycopy to the end of the
5957b2fd183SYaroslav Tykhiy.Vt mbuf chain .
596de06f907SNik Clayton.Sy Note :
5977b2fd183SYaroslav TykhiyThe copy is read-only, because the
5987b2fd183SYaroslav Tykhiy.Vt mbuf clusters
5997b2fd183SYaroslav Tykhiyare not copied, only their reference counts are incremented.
600de06f907SNik Clayton.\"
601de06f907SNik Clayton.It Fn m_copypacket mbuf how
602de06f907SNik ClaytonCopy an entire packet including header, which must be present.
603de06f907SNik ClaytonThis is an optimized version of the common case
604de06f907SNik Clayton.Fn m_copym mbuf 0 M_COPYALL how .
605de06f907SNik Clayton.Sy Note :
6067b2fd183SYaroslav Tykhiythe copy is read-only, because the
6077b2fd183SYaroslav Tykhiy.Vt mbuf clusters
6087b2fd183SYaroslav Tykhiyare not copied, only their reference counts are incremented.
609de06f907SNik Clayton.\"
610de06f907SNik Clayton.It Fn m_dup mbuf how
6117b2fd183SYaroslav TykhiyCopy a packet header
6127b2fd183SYaroslav Tykhiy.Vt mbuf chain
6137b2fd183SYaroslav Tykhiyinto a completely new
6147b2fd183SYaroslav Tykhiy.Vt mbuf chain ,
6157b2fd183SYaroslav Tykhiyincluding copying any
6167b2fd183SYaroslav Tykhiy.Vt mbuf clusters .
617e73145f6SSheldon HearnUse this instead of
618de06f907SNik Clayton.Fn m_copypacket
6197b2fd183SYaroslav Tykhiywhen you need a writable copy of an
6207b2fd183SYaroslav Tykhiy.Vt mbuf chain .
621de06f907SNik Clayton.\"
622de06f907SNik Clayton.It Fn m_copydata mbuf offset len buf
6237b2fd183SYaroslav TykhiyCopy data from an
6247b2fd183SYaroslav Tykhiy.Vt mbuf chain
6257b2fd183SYaroslav Tykhiystarting
626de06f907SNik Clayton.Fa off
627de06f907SNik Claytonbytes from the beginning, continuing for
628de06f907SNik Clayton.Fa len
629de06f907SNik Claytonbytes, into the indicated buffer
630de06f907SNik Clayton.Fa buf .
631de06f907SNik Clayton.\"
632de06f907SNik Clayton.It Fn m_copyback mbuf offset len buf
633de06f907SNik ClaytonCopy
634de06f907SNik Clayton.Fa len
635de06f907SNik Claytonbytes from the buffer
636de06f907SNik Clayton.Fa buf
6377b2fd183SYaroslav Tykhiyback into the indicated
6387b2fd183SYaroslav Tykhiy.Vt mbuf chain ,
639de06f907SNik Claytonstarting at
640de06f907SNik Clayton.Fa offset
6417b2fd183SYaroslav Tykhiybytes from the beginning of the
6427b2fd183SYaroslav Tykhiy.Vt mbuf chain ,
6437b2fd183SYaroslav Tykhiyextending the
6447b2fd183SYaroslav Tykhiy.Vt mbuf chain
6457b2fd183SYaroslav Tykhiyif necessary.
646de06f907SNik Clayton.Sy Note :
6477b2fd183SYaroslav TykhiyIt doesn't allocate any
6487b2fd183SYaroslav Tykhiy.Vt mbuf clusters ,
6497b2fd183SYaroslav Tykhiyjust adds
6507b2fd183SYaroslav Tykhiy.Vt mbufs
6517b2fd183SYaroslav Tykhiyto the
6527b2fd183SYaroslav Tykhiy.Vt mbuf chain .
653e73145f6SSheldon HearnIt's safe to set
654de06f907SNik Clayton.Fa offset
6557b2fd183SYaroslav Tykhiybeyond the current
6567b2fd183SYaroslav Tykhiy.Vt mbuf chain
6577b2fd183SYaroslav Tykhiyend: zeroed
6587b2fd183SYaroslav Tykhiy.Vt mbufs
6597b2fd183SYaroslav Tykhiywill be allocated to fill the space.
660de06f907SNik Clayton.\"
6615d96084fSYaroslav Tykhiy.It Fn m_length mbuf last
6627b2fd183SYaroslav TykhiyReturn the length of the
6637b2fd183SYaroslav Tykhiy.Vt mbuf chain ,
6647b2fd183SYaroslav Tykhiyand optionally a pointer to the last
6657b2fd183SYaroslav Tykhiy.Vt mbuf .
6660b1c0994SPoul-Henning Kamp.\"
667da72b998SYaroslav Tykhiy.It Fn m_dup_pkthdr to from how
668da72b998SYaroslav TykhiyUpon the function's completion, the
669da72b998SYaroslav Tykhiy.Vt mbuf
670da72b998SYaroslav Tykhiy.Fa to
671da72b998SYaroslav Tykhiywill contain an identical copy of
672da72b998SYaroslav Tykhiy.Fa from->m_pkthdr
673da72b998SYaroslav Tykhiyand the per-packet attributes found in the
674da72b998SYaroslav Tykhiy.Vt mbuf chain
675da72b998SYaroslav Tykhiy.Fa from .
676da72b998SYaroslav TykhiyThe
677da72b998SYaroslav Tykhiy.Vt mbuf
678da72b998SYaroslav Tykhiy.Fa from
679da72b998SYaroslav Tykhiymust have the flag
680da72b998SYaroslav Tykhiy.Dv M_PKTHDR
681da72b998SYaroslav Tykhiyinitially set, and
682da72b998SYaroslav Tykhiy.Fa to
683da72b998SYaroslav Tykhiymust be empty on entry.
684da72b998SYaroslav Tykhiy.\"
685da72b998SYaroslav Tykhiy.It Fn m_move_pkthdr to from
686da72b998SYaroslav TykhiyMove
687da72b998SYaroslav Tykhiy.Va m_pkthdr
688da72b998SYaroslav Tykhiyand the per-packet attributes from the
689da72b998SYaroslav Tykhiy.Vt mbuf chain
690da72b998SYaroslav Tykhiy.Fa from
691da72b998SYaroslav Tykhiyto the
692da72b998SYaroslav Tykhiy.Vt mbuf
693da72b998SYaroslav Tykhiy.Fa to .
694da72b998SYaroslav TykhiyThe
695da72b998SYaroslav Tykhiy.Vt mbuf
696da72b998SYaroslav Tykhiy.Fa from
697da72b998SYaroslav Tykhiymust have the flag
698da72b998SYaroslav Tykhiy.Dv M_PKTHDR
699da72b998SYaroslav Tykhiyinitially set, and
700da72b998SYaroslav Tykhiy.Fa to
701da72b998SYaroslav Tykhiymust be empty on entry.
702da72b998SYaroslav TykhiyUpon the function's completion,
703da72b998SYaroslav Tykhiy.Fa from
704da72b998SYaroslav Tykhiywill have the flag
705da72b998SYaroslav Tykhiy.Dv M_PKTHDR
706da72b998SYaroslav Tykhiyand the per-packet attributes cleared.
707da72b998SYaroslav Tykhiy.\"
7085d96084fSYaroslav Tykhiy.It Fn m_fixhdr mbuf
7097b2fd183SYaroslav TykhiySet the packet-header length to the length of the
7107b2fd183SYaroslav Tykhiy.Vt mbuf chain .
7110b1c0994SPoul-Henning Kamp.\"
712de06f907SNik Clayton.It Fn m_devget buf len offset ifp copy
713de06f907SNik ClaytonCopy data from a device local memory pointed to by
714de06f907SNik Clayton.Fa buf
7157b2fd183SYaroslav Tykhiyto an
7167b2fd183SYaroslav Tykhiy.Vt mbuf chain .
717e73145f6SSheldon HearnThe copy is done using a specified copy routine
718de06f907SNik Clayton.Fa copy ,
719de06f907SNik Claytonor
720de06f907SNik Clayton.Fn bcopy
721de06f907SNik Claytonif
722de06f907SNik Clayton.Fa copy
723de06f907SNik Claytonis
724de06f907SNik Clayton.Dv NULL .
725de06f907SNik Clayton.\"
726de06f907SNik Clayton.It Fn m_cat m n
727de06f907SNik ClaytonConcatenate
728de06f907SNik Clayton.Fa n
729de06f907SNik Claytonto
730de06f907SNik Clayton.Fa m .
7317b2fd183SYaroslav TykhiyBoth
7327b2fd183SYaroslav Tykhiy.Vt mbuf chains
7337b2fd183SYaroslav Tykhiymust be of the same type.
734de06f907SNik Clayton.Fa N
735de06f907SNik Claytonis still valid after the function returned.
736de06f907SNik Clayton.Sy Note :
737de06f907SNik ClaytonIt does not handle
738de06f907SNik Clayton.Dv M_PKTHDR
739de06f907SNik Claytonand friends.
740de06f907SNik Clayton.\"
741de06f907SNik Clayton.It Fn m_split mbuf len how
7427b2fd183SYaroslav TykhiyPartition an
7437b2fd183SYaroslav Tykhiy.Vt mbuf chain
7447b2fd183SYaroslav Tykhiyin two pieces, returning the tail:
745de06f907SNik Claytonall but the first
746de06f907SNik Clayton.Fa len
747e73145f6SSheldon Hearnbytes.
748e73145f6SSheldon HearnIn case of failure, it returns
749de06f907SNik Clayton.Dv NULL
7507b2fd183SYaroslav Tykhiyand attempts to restore the
7517b2fd183SYaroslav Tykhiy.Vt mbuf chain
7527b2fd183SYaroslav Tykhiyto its original state.
7533136363fSRuslan Ermilov.El
7543cab047eSMike Silbersack.Sh STRESS TESTING
755c8185672SRuslan ErmilovWhen running a kernel compiled with the option
756c8185672SRuslan Ermilov.Dv MBUF_STRESS_TEST ,
757c8185672SRuslan Ermilovthe following
758c8185672SRuslan Ermilov.Xr sysctl 8 Ns
759c8185672SRuslan Ermilov-controlled options may be used to create
7603cab047eSMike Silbersackvarious failure/extreme cases for testing of network drivers
7617b2fd183SYaroslav Tykhiyand other parts of the kernel that rely on
7627b2fd183SYaroslav Tykhiy.Vt mbufs .
763c8185672SRuslan Ermilov.Bl -tag -width ident
764c8185672SRuslan Ermilov.It Va net.inet.ip.mbuf_frag_size
765c8185672SRuslan ErmilovCauses
766c8185672SRuslan Ermilov.Fn ip_output
7677b2fd183SYaroslav Tykhiyto fragment outgoing
7687b2fd183SYaroslav Tykhiy.Vt mbuf chains
7697b2fd183SYaroslav Tykhiyinto fragments of the specified size.
770c8185672SRuslan ErmilovSetting this variable to 1 is an excellent way to
7717b2fd183SYaroslav Tykhiytest the long
7727b2fd183SYaroslav Tykhiy.Vt mbuf chain
7737b2fd183SYaroslav Tykhiyhandling ability of network drivers.
774c8185672SRuslan Ermilov.It Va kern.ipc.m_defragrandomfailures
775c8185672SRuslan ErmilovCauses the function
776c8185672SRuslan Ermilov.Fn m_defrag
777c8185672SRuslan Ermilovto randomly fail, returning
778c8185672SRuslan Ermilov.Dv NULL .
779c8185672SRuslan ErmilovAny piece of code which uses
780c8185672SRuslan Ermilov.Fn m_defrag
781c8185672SRuslan Ermilovshould be tested with this feature.
782c8185672SRuslan Ermilov.El
783de06f907SNik Clayton.Sh RETURN VALUES
784de06f907SNik ClaytonSee above.
785de06f907SNik Clayton.Sh HISTORY
786de06f907SNik Clayton.\" Please correct me if I'm wrong
7877b2fd183SYaroslav Tykhiy.Vt Mbufs
7887b2fd183SYaroslav Tykhiyappeared in an early version of
789753d686dSRuslan Ermilov.Bx .
79053b2520dSTom RhodesBesides being used for network packets, they were used
791bfd59721SBosko Milekicto store various dynamic structures, such as routing table
792bfd59721SBosko Milekicentries, interface addresses, protocol control blocks, etc.
793de06f907SNik Clayton.Sh AUTHORS
7946575e6daSRuslan ErmilovThe original
7956575e6daSRuslan Ermilov.Nm
7966575e6daSRuslan Ermilovman page was written by Yar Tikhiy.
797