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 161238d9c59SYaroslav Tykhiy.Bl -tag -width "m_nextpkt" -offset indent 162be82a0bcSYaroslav Tykhiy.It Va m_next 163238d9c59SYaroslav Tykhiy.Pq Vt struct mbuf * 164238d9c59SYaroslav TykhiyA pointer to the next 1657b2fd183SYaroslav Tykhiy.Vt mbuf 1667b2fd183SYaroslav Tykhiyin the 167238d9c59SYaroslav Tykhiy.Vt mbuf chain . 168be82a0bcSYaroslav Tykhiy.It Va m_nextpkt 169238d9c59SYaroslav Tykhiy.Pq Vt struct mbuf * 170238d9c59SYaroslav TykhiyA pointer to the next 1717b2fd183SYaroslav Tykhiy.Vt mbuf chain 172238d9c59SYaroslav Tykhiyin the queue. 173be82a0bcSYaroslav Tykhiy.It Va m_data 174238d9c59SYaroslav Tykhiy.Pq Vt caddr_t 175238d9c59SYaroslav TykhiyA pointer to data attached to this 176238d9c59SYaroslav Tykhiy.Vt mbuf . 177be82a0bcSYaroslav Tykhiy.It Va m_len 178238d9c59SYaroslav Tykhiy.Pq Vt int 179238d9c59SYaroslav TykhiyThe length of the data. 180be82a0bcSYaroslav Tykhiy.It Va m_type 181238d9c59SYaroslav Tykhiy.Pq Vt short 182238d9c59SYaroslav TykhiyThe type of the data. 183be82a0bcSYaroslav Tykhiy.It Va m_flags 184238d9c59SYaroslav Tykhiy.Pq Vt int 185238d9c59SYaroslav TykhiyThe 1867b2fd183SYaroslav Tykhiy.Vt mbuf 187238d9c59SYaroslav Tykhiyflags. 188de06f907SNik Clayton.El 189de06f907SNik Clayton.Pp 1907b2fd183SYaroslav TykhiyThe 1917b2fd183SYaroslav Tykhiy.Vt mbuf 1927b2fd183SYaroslav Tykhiyflag bits are defined as follows: 193de06f907SNik Clayton.Bd -literal 194de06f907SNik Clayton/* mbuf flags */ 195de06f907SNik Clayton#define M_EXT 0x0001 /* has associated external storage */ 196de06f907SNik Clayton#define M_PKTHDR 0x0002 /* start of record */ 197de06f907SNik Clayton#define M_EOR 0x0004 /* end of record */ 1985d4050ccSBosko Milekic#define M_RDONLY 0x0008 /* associated data marked read-only */ 1995d4050ccSBosko Milekic#define M_PROTO1 0x0010 /* protocol-specific */ 2005d4050ccSBosko Milekic#define M_PROTO2 0x0020 /* protocol-specific */ 2015d4050ccSBosko Milekic#define M_PROTO3 0x0040 /* protocol-specific */ 2025d4050ccSBosko Milekic#define M_PROTO4 0x0080 /* protocol-specific */ 2035d4050ccSBosko Milekic#define M_PROTO5 0x0100 /* protocol-specific */ 204f434362aSYaroslav Tykhiy#define M_PROTO6 0x4000 /* protocol-specific (avoid M_BCAST conflict) */ 205f434362aSYaroslav Tykhiy#define M_FREELIST 0x8000 /* mbuf is on the free list */ 206de06f907SNik Clayton 207f434362aSYaroslav Tykhiy/* mbuf pkthdr flags (also stored in m_flags) */ 2085d4050ccSBosko Milekic#define M_BCAST 0x0200 /* send/received as link-level broadcast */ 2095d4050ccSBosko Milekic#define M_MCAST 0x0400 /* send/received as link-level multicast */ 2105d4050ccSBosko Milekic#define M_FRAG 0x0800 /* packet is fragment of larger packet */ 2115d4050ccSBosko Milekic#define M_FIRSTFRAG 0x1000 /* packet is first fragment */ 2125d4050ccSBosko Milekic#define M_LASTFRAG 0x2000 /* packet is last fragment */ 213de06f907SNik Clayton.Ed 214de06f907SNik Clayton.Pp 2157b2fd183SYaroslav TykhiyThe available 2167b2fd183SYaroslav Tykhiy.Vt mbuf 2177b2fd183SYaroslav Tykhiytypes are defined as follows: 218de06f907SNik Clayton.Bd -literal 219de06f907SNik Clayton/* mbuf types */ 220de06f907SNik Clayton#define MT_DATA 1 /* dynamic (data) allocation */ 221de06f907SNik Clayton#define MT_HEADER 2 /* packet header */ 222de06f907SNik Clayton#define MT_SONAME 8 /* socket name */ 223de06f907SNik Clayton#define MT_FTABLE 11 /* fragment reassembly header */ 224d2b73059SYaroslav Tykhiy#define MT_TAG 13 /* volatile metadata associated to pkts */ 225de06f907SNik Clayton#define MT_CONTROL 14 /* extra-data protocol message */ 226de06f907SNik Clayton#define MT_OOBDATA 15 /* expedited data */ 227de06f907SNik Clayton.Ed 228de06f907SNik Clayton.Pp 229de06f907SNik ClaytonIf the 230de06f907SNik Clayton.Dv M_PKTHDR 231de06f907SNik Claytonflag is set, a 2327b2fd183SYaroslav Tykhiy.Vt struct pkthdr Va m_pkthdr 2337b2fd183SYaroslav Tykhiyis added to the 2347b2fd183SYaroslav Tykhiy.Vt mbuf 2357b2fd183SYaroslav Tykhiyheader. 236e73145f6SSheldon HearnIt contains a pointer to the interface 237de06f907SNik Claytonthe packet has been received from 2387b2fd183SYaroslav Tykhiy.Pq Vt struct ifnet Va *rcvif , 239de06f907SNik Claytonand the total packet length 2407b2fd183SYaroslav Tykhiy.Pq Vt int Va len . 241de06f907SNik Clayton.Pp 2427b2fd183SYaroslav TykhiyIf small enough, data is stored in the internal data buffer of an 2437b2fd183SYaroslav Tykhiy.Vt mbuf . 2447b2fd183SYaroslav TykhiyIf the data is sufficiently large, another 2457b2fd183SYaroslav Tykhiy.Vt mbuf 2467b2fd183SYaroslav Tykhiymay be added to the 2477b2fd183SYaroslav Tykhiy.Vt mbuf chain , 2487b2fd183SYaroslav Tykhiyor external storage may be associated with the 2497b2fd183SYaroslav Tykhiy.Vt mbuf . 250de06f907SNik Clayton.Dv MHLEN 2517b2fd183SYaroslav Tykhiybytes of data can fit into an 2527b2fd183SYaroslav Tykhiy.Vt mbuf 2537b2fd183SYaroslav Tykhiywith the 254de06f907SNik Clayton.Dv M_PKTHDR 255de06f907SNik Claytonflag set, 256de06f907SNik Clayton.Dv MLEN 257de06f907SNik Claytonbytes can otherwise. 258de06f907SNik Clayton.Pp 2597b2fd183SYaroslav TykhiyIf external storage is being associated with an 2607b2fd183SYaroslav Tykhiy.Vt mbuf , 2617b2fd183SYaroslav Tykhiythe 262be82a0bcSYaroslav Tykhiy.Va m_ext 26325f1a2e9SSheldon Hearnheader is added at the cost of losing the internal data buffer. 264e73145f6SSheldon HearnIt includes a pointer to external storage, the size of the storage, 265e73145f6SSheldon Hearna pointer to a function used for freeing the storage, 266e73145f6SSheldon Hearna pointer to an optional argument that can be passed to the function, 267e73145f6SSheldon Hearnand a pointer to a reference counter. 2687b2fd183SYaroslav TykhiyAn 2697b2fd183SYaroslav Tykhiy.Vt mbuf 2707b2fd183SYaroslav Tykhiyusing external storage has the 271de06f907SNik Clayton.Dv M_EXT 272de06f907SNik Claytonflag set. 273de06f907SNik Clayton.Pp 274bfd59721SBosko MilekicThe system supplies a macro for allocating the desired external storage 275bfd59721SBosko Milekicbuffer, 276bfd59721SBosko Milekic.Dv MEXTADD . 277bfd59721SBosko Milekic.Pp 278bfd59721SBosko MilekicThe allocation and management of the reference counter is handled by the 279e73145f6SSheldon Hearnsubsystem. 280e73145f6SSheldon HearnThe developer can check whether the reference count for the 2817b2fd183SYaroslav Tykhiyexternal storage of a given 2827b2fd183SYaroslav Tykhiy.Vt mbuf 2837b2fd183SYaroslav Tykhiyis greater than 1 with the 284bfd59721SBosko Milekic.Dv MEXT_IS_REF 285e73145f6SSheldon Hearnmacro. 286e73145f6SSheldon HearnSimilarly, the developer can directly add and remove references, 287e73145f6SSheldon Hearnif absolutely necessary, with the use of the 288bfd59721SBosko Milekic.Dv MEXT_ADD_REF 289bfd59721SBosko Milekicand 290bfd59721SBosko Milekic.Dv MEXT_REM_REF 291bfd59721SBosko Milekicmacros. 292bfd59721SBosko Milekic.Pp 293bfd59721SBosko MilekicThe system also supplies a default type of external storage buffer called an 2947b2fd183SYaroslav Tykhiy.Vt mbuf cluster . 2957b2fd183SYaroslav Tykhiy.Vt Mbuf clusters 2967b2fd183SYaroslav Tykhiycan be allocated and configured with the use of the 297bfd59721SBosko Milekic.Dv MCLGET 298e73145f6SSheldon Hearnmacro. 2997b2fd183SYaroslav TykhiyEach 3007b2fd183SYaroslav Tykhiy.Vt mbuf cluster 3017b2fd183SYaroslav Tykhiyis 302de06f907SNik Clayton.Dv MCLBYTES 303bfd59721SBosko Milekicin size, where MCLBYTES is a machine-dependent constant. 304bfd59721SBosko MilekicThe system defines an advisory macro 305de06f907SNik Clayton.Dv MINCLSIZE , 3067b2fd183SYaroslav Tykhiywhich is the smallest amount of data to put into an 3077b2fd183SYaroslav Tykhiy.Vt mbuf cluster . 308de06f907SNik ClaytonIt's equal to the sum of 309de06f907SNik Clayton.Dv MLEN 310de06f907SNik Claytonand 311de06f907SNik Clayton.Dv MHLEN . 3127b2fd183SYaroslav TykhiyIt is typically preferable to store data into the data region of an 3137b2fd183SYaroslav Tykhiy.Vt mbuf , 3147b2fd183SYaroslav Tykhiyif size permits, as opposed to allocating a separate 3157b2fd183SYaroslav Tykhiy.Vt mbuf cluster 3167b2fd183SYaroslav Tykhiyto hold the same data. 317de06f907SNik Clayton.\" 318de06f907SNik Clayton.Ss Macros and Functions 319bfd59721SBosko MilekicThere are numerous predefined macros and functions that provide the 320bfd59721SBosko Milekicdeveloper with common utilities. 321de06f907SNik Clayton.\" 322de06f907SNik Clayton.Bl -ohang -offset indent 323de06f907SNik Clayton.It Fn mtod mbuf type 3247b2fd183SYaroslav TykhiyConvert an 3257b2fd183SYaroslav Tykhiy.Fa mbuf 3267b2fd183SYaroslav Tykhiypointer to a data pointer. 3277b2fd183SYaroslav TykhiyThe macro expands to the data pointer cast to the pointer of the specified 3287b2fd183SYaroslav Tykhiy.Fa type . 329de06f907SNik Clayton.Sy Note : 3307b2fd183SYaroslav TykhiyIt is advisable to ensure that there is enough contiguous data in 3317b2fd183SYaroslav Tykhiy.Fa mbuf . 332de06f907SNik ClaytonSee 333de06f907SNik Clayton.Fn m_pullup 334de06f907SNik Claytonfor details. 335de06f907SNik Clayton.It Fn MGET mbuf how type 3367b2fd183SYaroslav TykhiyAllocate an 3377b2fd183SYaroslav Tykhiy.Vt mbuf 3387b2fd183SYaroslav Tykhiyand initialize it to contain internal data. 33925f1a2e9SSheldon Hearn.Fa mbuf 3407b2fd183SYaroslav Tykhiywill point to the allocated 3417b2fd183SYaroslav Tykhiy.Vt mbuf 3427b2fd183SYaroslav Tykhiyon success, or be set to 343de06f907SNik Clayton.Dv NULL 344e73145f6SSheldon Hearnon failure. 345e73145f6SSheldon HearnThe 346de06f907SNik Clayton.Fa how 347de06f907SNik Claytonargument is to be set to 348c65b53c5STom Rhodes.Dv M_TRYWAIT 349de06f907SNik Claytonor 350c65b53c5STom Rhodes.Dv M_DONTWAIT . 35125f1a2e9SSheldon HearnIt specifies whether the caller is willing to block if necessary. 352e73145f6SSheldon HearnIf 353de06f907SNik Clayton.Fa how 35425f1a2e9SSheldon Hearnis set to 355c65b53c5STom Rhodes.Dv M_TRYWAIT , 35625f1a2e9SSheldon Hearna failed allocation will result in the caller being put 357bfd59721SBosko Milekicto sleep for a designated 35825f1a2e9SSheldon Hearnkern.ipc.mbuf_wait 359c4d9468eSRuslan Ermilov.Xr ( sysctl 8 360c4d9468eSRuslan Ermilovtunable) 36125f1a2e9SSheldon Hearnnumber of ticks. 3627b2fd183SYaroslav TykhiyA number of other functions and macros related to 3637b2fd183SYaroslav Tykhiy.Vt mbufs 3647b2fd183SYaroslav Tykhiyhave the same argument because they may 3657b2fd183SYaroslav Tykhiyat some point need to allocate new 3667b2fd183SYaroslav Tykhiy.Vt mbufs . 367c65b53c5STom Rhodes.Pp 3687b2fd183SYaroslav TykhiyProgrammers should be careful not to confuse the 3697b2fd183SYaroslav Tykhiy.Vt mbuf 3707b2fd183SYaroslav Tykhiyallocation flag 371c65b53c5STom Rhodes.Dv M_DONTWAIT 372c65b53c5STom Rhodeswith the 373c65b53c5STom Rhodes.Xr malloc 9 374c65b53c5STom Rhodesallocation flag, 375c65b53c5STom Rhodes.Dv M_NOWAIT . 376c65b53c5STom RhodesThey are not the same. 377de06f907SNik Clayton.It Fn MGETHDR mbuf how type 3787b2fd183SYaroslav TykhiyAllocate an 3797b2fd183SYaroslav Tykhiy.Vt mbuf 3807b2fd183SYaroslav Tykhiyand initialize it to contain a packet header 381e73145f6SSheldon Hearnand internal data. 382e73145f6SSheldon HearnSee 383de06f907SNik Clayton.Fn MGET 384de06f907SNik Claytonfor details. 385de06f907SNik Clayton.It Fn MCLGET mbuf how 3867b2fd183SYaroslav TykhiyAllocate and attach an 3877b2fd183SYaroslav Tykhiy.Vt mbuf cluster 3887b2fd183SYaroslav Tykhiyto 3897b2fd183SYaroslav Tykhiy.Fa mbuf . 390e73145f6SSheldon HearnIf the macro fails, the 391de06f907SNik Clayton.Dv M_EXT 3927b2fd183SYaroslav Tykhiyflag won't be set in 3937b2fd183SYaroslav Tykhiy.Fa mbuf . 394da72b998SYaroslav Tykhiy.It Fn M_ALIGN mbuf len 395da72b998SYaroslav TykhiySet the pointer 396da72b998SYaroslav Tykhiy.Fa mbuf->m_data 397da72b998SYaroslav Tykhiyto place an object of the size 398da72b998SYaroslav Tykhiy.Fa len 399da72b998SYaroslav Tykhiyat the end of the internal data area of 400da72b998SYaroslav Tykhiy.Fa mbuf , 401da72b998SYaroslav Tykhiylong word aligned. 402da72b998SYaroslav TykhiyApplicable only if 403da72b998SYaroslav Tykhiy.Fa mbuf 404da72b998SYaroslav Tykhiyis newly allocated with 405da72b998SYaroslav Tykhiy.Fn MGET 406da72b998SYaroslav Tykhiyor 407da72b998SYaroslav Tykhiy.Fn m_get . 408da72b998SYaroslav Tykhiy.It Fn MH_ALIGN mbuf len 409da72b998SYaroslav TykhiyServes the same purpose as 410da72b998SYaroslav Tykhiy.Fn M_ALIGN 411da72b998SYaroslav Tykhiydoes, but only for 412da72b998SYaroslav Tykhiy.Fa mbuf 413da72b998SYaroslav Tykhiynewly allocated with 414da72b998SYaroslav Tykhiy.Fn MGETHDR 415da72b998SYaroslav Tykhiyor 416da72b998SYaroslav Tykhiy.Fn m_gethdr , 417da72b998SYaroslav Tykhiyor initialized by 418da72b998SYaroslav Tykhiy.Fn m_dup_pkthdr 419da72b998SYaroslav Tykhiyor 420da72b998SYaroslav Tykhiy.Fn m_move_pkthdr . 421da72b998SYaroslav Tykhiy.It Fn M_LEADINGSPACE mbuf 422da72b998SYaroslav TykhiyReturns the number of bytes available before the beginning 423da72b998SYaroslav Tykhiyof data in 424da72b998SYaroslav Tykhiy.Fa mbuf . 425da72b998SYaroslav Tykhiy.It Fn M_TRAILINGSPACE mbuf 426da72b998SYaroslav TykhiyReturns the number of bytes available after the end of data in 427da72b998SYaroslav Tykhiy.Fa mbuf . 428de06f907SNik Clayton.It Fn M_PREPEND mbuf len how 4297b2fd183SYaroslav TykhiyThis macro operates on an 4307b2fd183SYaroslav Tykhiy.Vt mbuf chain . 431de06f907SNik ClaytonIt is an optimized wrapper for 432de06f907SNik Clayton.Fn m_prepend 433de06f907SNik Claytonthat can make use of possible empty space before data 434c4d9468eSRuslan Ermilov(e.g. left after trimming of a link-layer header). 4357b2fd183SYaroslav TykhiyThe new 4367b2fd183SYaroslav Tykhiy.Vt mbuf chain 4377b2fd183SYaroslav Tykhiypointer or 438de06f907SNik Clayton.Dv NULL 439de06f907SNik Claytonis in 440de06f907SNik Clayton.Fa mbuf 441de06f907SNik Claytonafter the call. 442da72b998SYaroslav Tykhiy.It Fn M_MOVE_PKTHDR to from 443da72b998SYaroslav TykhiyUsing this macro is equivalent to calling 444da72b998SYaroslav Tykhiy.Fn m_move_pkthdr to from . 4455d4050ccSBosko Milekic.It Fn M_WRITABLE mbuf 4467b2fd183SYaroslav TykhiyThis macro will evaluate true if 4477b2fd183SYaroslav Tykhiy.Fa mbuf 4487b2fd183SYaroslav Tykhiyis not marked 4495d4050ccSBosko Milekic.Dv M_RDONLY 4507b2fd183SYaroslav Tykhiyand if either 4517b2fd183SYaroslav Tykhiy.Fa mbuf 4527b2fd183SYaroslav Tykhiydoes not contain external storage or, 4535d4050ccSBosko Milekicif it does, 4545d4050ccSBosko Milekicthen if the reference count of the storage is not greater than 1. 4555d4050ccSBosko MilekicThe 4565d4050ccSBosko Milekic.Dv M_RDONLY 4577b2fd183SYaroslav Tykhiyflag can be set in 4587b2fd183SYaroslav Tykhiy.Fa mbuf->m_flags . 4595d4050ccSBosko MilekicThis can be achieved during setup of the external storage, 4605d4050ccSBosko Milekicby passing the 4615d4050ccSBosko Milekic.Dv M_RDONLY 4625d4050ccSBosko Milekicbit as a 4630b39b3ffSRuslan Ermilov.Fa flags 4645d4050ccSBosko Milekicargument to the 4655d4050ccSBosko Milekic.Fn MEXTADD 4667b2fd183SYaroslav Tykhiymacro, or can be directly set in individual 4677b2fd183SYaroslav Tykhiy.Vt mbufs . 468da72b998SYaroslav Tykhiy.It Fn MCHTYPE mbuf type 469da72b998SYaroslav TykhiyChange the type of 470da72b998SYaroslav Tykhiy.Fa mbuf 471da72b998SYaroslav Tykhiyto 472da72b998SYaroslav Tykhiy.Fa type . 473da72b998SYaroslav TykhiyThis is a relatively expensive operation and should be avoided. 474de06f907SNik Clayton.El 475de06f907SNik Clayton.Pp 476de06f907SNik ClaytonThe functions are: 477de06f907SNik Clayton.Bl -ohang -offset indent 478de06f907SNik Clayton.It Fn m_get how type 479de06f907SNik ClaytonA function version of 480bfd59721SBosko Milekic.Fn MGET 481bfd59721SBosko Milekicfor non-critical paths. 482328c0bbcSBosko Milekic.It Fn m_getm orig len how type 483328c0bbcSBosko MilekicAllocate 4840b39b3ffSRuslan Ermilov.Fa len 4857b2fd183SYaroslav Tykhiybytes worth of 4867b2fd183SYaroslav Tykhiy.Vt mbufs 4877b2fd183SYaroslav Tykhiyand 4887b2fd183SYaroslav Tykhiy.Vt mbuf clusters 4897b2fd183SYaroslav Tykhiyif necessary and append the resulting allocated 4907b2fd183SYaroslav Tykhiy.Vt mbuf chain 4917b2fd183SYaroslav Tykhiyto the 4927b2fd183SYaroslav Tykhiy.Vt mbuf chain 4937b2fd183SYaroslav Tykhiy.Fa orig , 4947b2fd183SYaroslav Tykhiyif it is 4950b39b3ffSRuslan Ermilov.No non- Ns Dv NULL . 496328c0bbcSBosko MilekicIf the allocation fails at any point, 4970b39b3ffSRuslan Ermilovfree whatever was allocated and return 4980b39b3ffSRuslan Ermilov.Dv NULL . 499328c0bbcSBosko MilekicIf 5000b39b3ffSRuslan Ermilov.Fa orig 5010b39b3ffSRuslan Ermilovis 5020b39b3ffSRuslan Ermilov.No non- Ns Dv NULL , 503328c0bbcSBosko Milekicit will not be freed. 504328c0bbcSBosko MilekicIt is possible to use 505328c0bbcSBosko Milekic.Fn m_getm 506328c0bbcSBosko Milekicto either append 5070b39b3ffSRuslan Ermilov.Fa len 5087b2fd183SYaroslav Tykhiybytes to an existing 5097b2fd183SYaroslav Tykhiy.Vt mbuf 5107b2fd183SYaroslav Tykhiyor 5117b2fd183SYaroslav Tykhiy.Vt mbuf chain 512328c0bbcSBosko Milekic(for example, one which may be sitting in a pre-allocated ring) 5137b2fd183SYaroslav Tykhiyor to simply perform an all-or-nothing 5147b2fd183SYaroslav Tykhiy.Vt mbuf 5157b2fd183SYaroslav Tykhiyand 5167b2fd183SYaroslav Tykhiy.Vt mbuf cluster 5177b2fd183SYaroslav Tykhiyallocation. 518de06f907SNik Clayton.It Fn m_gethdr how type 519de06f907SNik ClaytonA function version of 520bfd59721SBosko Milekic.Fn MGETHDR 521bfd59721SBosko Milekicfor non-critical paths. 522de06f907SNik Clayton.It Fn m_getclr how type 5237b2fd183SYaroslav TykhiyAllocate an 5247b2fd183SYaroslav Tykhiy.Vt mbuf 5257b2fd183SYaroslav Tykhiyand zero out the data region. 526de06f907SNik Clayton.El 527de06f907SNik Clayton.Pp 5287b2fd183SYaroslav TykhiyThe functions below operate on 5297b2fd183SYaroslav Tykhiy.Vt mbuf chains . 530de06f907SNik Clayton.Bl -ohang -offset indent 531de06f907SNik Clayton.It Fn m_freem mbuf 5327b2fd183SYaroslav TykhiyFree an entire 5337b2fd183SYaroslav Tykhiy.Vt mbuf chain , 5347b2fd183SYaroslav Tykhiyincluding any external storage. 535de06f907SNik Clayton.\" 536de06f907SNik Clayton.It Fn m_adj mbuf len 537de06f907SNik ClaytonTrim 538de06f907SNik Clayton.Fa len 5397b2fd183SYaroslav Tykhiybytes from the head of an 5407b2fd183SYaroslav Tykhiy.Vt mbuf chain 5417b2fd183SYaroslav Tykhiyif 542de06f907SNik Clayton.Fa len 543de06f907SNik Claytonis positive, from the tail otherwise. 544de06f907SNik Clayton.\" 545de06f907SNik Clayton.It Fn m_prepend mbuf len how 5467b2fd183SYaroslav TykhiyAllocate a new 5477b2fd183SYaroslav Tykhiy.Vt mbuf 5487b2fd183SYaroslav Tykhiyand prepend it to the 5497b2fd183SYaroslav Tykhiy.Vt mbuf chain , 5507b2fd183SYaroslav Tykhiyhandle 551de06f907SNik Clayton.Dv M_PKTHDR 552de06f907SNik Claytonproperly. 553de06f907SNik Clayton.Sy Note : 5547b2fd183SYaroslav TykhiyIt doesn't allocate any 5557b2fd183SYaroslav Tykhiy.Vt mbuf clusters , 5567b2fd183SYaroslav Tykhiyso 557de06f907SNik Clayton.Fa len 558de06f907SNik Claytonmust be less than 559de06f907SNik Clayton.Dv MLEN 560de06f907SNik Claytonor 561de06f907SNik Clayton.Dv MHLEN , 562de06f907SNik Claytondepending on the 563d0353b83SRuslan Ermilov.Dv M_PKTHDR 564d0353b83SRuslan Ermilovflag setting. 565de06f907SNik Clayton.\" 566de06f907SNik Clayton.It Fn m_pullup mbuf len 567de06f907SNik ClaytonArrange that the first 568de06f907SNik Clayton.Fa len 5697b2fd183SYaroslav Tykhiybytes of an 5707b2fd183SYaroslav Tykhiy.Vt mbuf chain 5717b2fd183SYaroslav Tykhiyare contiguous and lay in the data area of 572de06f907SNik Clayton.Fa mbuf , 573de06f907SNik Claytonso they are accessible with 574de06f907SNik Clayton.Fn mtod mbuf type . 5757b2fd183SYaroslav TykhiyReturn the new 5767b2fd183SYaroslav Tykhiy.Vt mbuf chain 5777b2fd183SYaroslav Tykhiyon success, 578de06f907SNik Clayton.Dv NULL 579de06f907SNik Claytonon failure 5807b2fd183SYaroslav Tykhiy(the 5817b2fd183SYaroslav Tykhiy.Vt mbuf chain 5827b2fd183SYaroslav Tykhiyis freed in this case). 583de06f907SNik Clayton.Sy Note : 5847b2fd183SYaroslav TykhiyIt doesn't allocate any 5857b2fd183SYaroslav Tykhiy.Vt mbuf clusters , 5867b2fd183SYaroslav Tykhiyso 587de06f907SNik Clayton.Fa len 588de06f907SNik Claytonmust be less than 589de06f907SNik Clayton.Dv MHLEN . 590de06f907SNik Clayton.\" 591de06f907SNik Clayton.It Fn m_copym mbuf offset len how 5927b2fd183SYaroslav TykhiyMake a copy of an 5937b2fd183SYaroslav Tykhiy.Vt mbuf chain 5947b2fd183SYaroslav Tykhiystarting 595de06f907SNik Clayton.Fa offset 596de06f907SNik Claytonbytes from the beginning, continuing for 597de06f907SNik Clayton.Fa len 598e73145f6SSheldon Hearnbytes. 599e73145f6SSheldon HearnIf 600de06f907SNik Clayton.Fa len 601de06f907SNik Claytonis 602de06f907SNik Clayton.Dv M_COPYALL , 6037b2fd183SYaroslav Tykhiycopy to the end of the 6047b2fd183SYaroslav Tykhiy.Vt mbuf chain . 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_copypacket mbuf how 611de06f907SNik ClaytonCopy an entire packet including header, which must be present. 612de06f907SNik ClaytonThis is an optimized version of the common case 613de06f907SNik Clayton.Fn m_copym mbuf 0 M_COPYALL how . 614de06f907SNik Clayton.Sy Note : 6157b2fd183SYaroslav Tykhiythe copy is read-only, because the 6167b2fd183SYaroslav Tykhiy.Vt mbuf clusters 6177b2fd183SYaroslav Tykhiyare not copied, only their reference counts are incremented. 618de06f907SNik Clayton.\" 619de06f907SNik Clayton.It Fn m_dup mbuf how 6207b2fd183SYaroslav TykhiyCopy a packet header 6217b2fd183SYaroslav Tykhiy.Vt mbuf chain 6227b2fd183SYaroslav Tykhiyinto a completely new 6237b2fd183SYaroslav Tykhiy.Vt mbuf chain , 6247b2fd183SYaroslav Tykhiyincluding copying any 6257b2fd183SYaroslav Tykhiy.Vt mbuf clusters . 626e73145f6SSheldon HearnUse this instead of 627de06f907SNik Clayton.Fn m_copypacket 6287b2fd183SYaroslav Tykhiywhen you need a writable copy of an 6297b2fd183SYaroslav Tykhiy.Vt mbuf chain . 630de06f907SNik Clayton.\" 631de06f907SNik Clayton.It Fn m_copydata mbuf offset len buf 6327b2fd183SYaroslav TykhiyCopy data from an 6337b2fd183SYaroslav Tykhiy.Vt mbuf chain 6347b2fd183SYaroslav Tykhiystarting 635de06f907SNik Clayton.Fa off 636de06f907SNik Claytonbytes from the beginning, continuing for 637de06f907SNik Clayton.Fa len 638de06f907SNik Claytonbytes, into the indicated buffer 639de06f907SNik Clayton.Fa buf . 640de06f907SNik Clayton.\" 641de06f907SNik Clayton.It Fn m_copyback mbuf offset len buf 642de06f907SNik ClaytonCopy 643de06f907SNik Clayton.Fa len 644de06f907SNik Claytonbytes from the buffer 645de06f907SNik Clayton.Fa buf 6467b2fd183SYaroslav Tykhiyback into the indicated 6477b2fd183SYaroslav Tykhiy.Vt mbuf chain , 648de06f907SNik Claytonstarting at 649de06f907SNik Clayton.Fa offset 6507b2fd183SYaroslav Tykhiybytes from the beginning of the 6517b2fd183SYaroslav Tykhiy.Vt mbuf chain , 6527b2fd183SYaroslav Tykhiyextending the 6537b2fd183SYaroslav Tykhiy.Vt mbuf chain 6547b2fd183SYaroslav Tykhiyif necessary. 655de06f907SNik Clayton.Sy Note : 6567b2fd183SYaroslav TykhiyIt doesn't allocate any 6577b2fd183SYaroslav Tykhiy.Vt mbuf clusters , 6587b2fd183SYaroslav Tykhiyjust adds 6597b2fd183SYaroslav Tykhiy.Vt mbufs 6607b2fd183SYaroslav Tykhiyto the 6617b2fd183SYaroslav Tykhiy.Vt mbuf chain . 662e73145f6SSheldon HearnIt's safe to set 663de06f907SNik Clayton.Fa offset 6647b2fd183SYaroslav Tykhiybeyond the current 6657b2fd183SYaroslav Tykhiy.Vt mbuf chain 6667b2fd183SYaroslav Tykhiyend: zeroed 6677b2fd183SYaroslav Tykhiy.Vt mbufs 6687b2fd183SYaroslav Tykhiywill be allocated to fill the space. 669de06f907SNik Clayton.\" 6705d96084fSYaroslav Tykhiy.It Fn m_length mbuf last 6717b2fd183SYaroslav TykhiyReturn the length of the 6727b2fd183SYaroslav Tykhiy.Vt mbuf chain , 6737b2fd183SYaroslav Tykhiyand optionally a pointer to the last 6747b2fd183SYaroslav Tykhiy.Vt mbuf . 6750b1c0994SPoul-Henning Kamp.\" 676da72b998SYaroslav Tykhiy.It Fn m_dup_pkthdr to from how 677da72b998SYaroslav TykhiyUpon the function's completion, the 678da72b998SYaroslav Tykhiy.Vt mbuf 679da72b998SYaroslav Tykhiy.Fa to 680da72b998SYaroslav Tykhiywill contain an identical copy of 681da72b998SYaroslav Tykhiy.Fa from->m_pkthdr 682da72b998SYaroslav Tykhiyand the per-packet attributes found in the 683da72b998SYaroslav Tykhiy.Vt mbuf chain 684da72b998SYaroslav Tykhiy.Fa from . 685da72b998SYaroslav TykhiyThe 686da72b998SYaroslav Tykhiy.Vt mbuf 687da72b998SYaroslav Tykhiy.Fa from 688da72b998SYaroslav Tykhiymust have the flag 689da72b998SYaroslav Tykhiy.Dv M_PKTHDR 690da72b998SYaroslav Tykhiyinitially set, and 691da72b998SYaroslav Tykhiy.Fa to 692da72b998SYaroslav Tykhiymust be empty on entry. 693da72b998SYaroslav Tykhiy.\" 694da72b998SYaroslav Tykhiy.It Fn m_move_pkthdr to from 695da72b998SYaroslav TykhiyMove 696da72b998SYaroslav Tykhiy.Va m_pkthdr 697da72b998SYaroslav Tykhiyand the per-packet attributes from the 698da72b998SYaroslav Tykhiy.Vt mbuf chain 699da72b998SYaroslav Tykhiy.Fa from 700da72b998SYaroslav Tykhiyto the 701da72b998SYaroslav Tykhiy.Vt mbuf 702da72b998SYaroslav Tykhiy.Fa to . 703da72b998SYaroslav TykhiyThe 704da72b998SYaroslav Tykhiy.Vt mbuf 705da72b998SYaroslav Tykhiy.Fa from 706da72b998SYaroslav Tykhiymust have the flag 707da72b998SYaroslav Tykhiy.Dv M_PKTHDR 708da72b998SYaroslav Tykhiyinitially set, and 709da72b998SYaroslav Tykhiy.Fa to 710da72b998SYaroslav Tykhiymust be empty on entry. 711da72b998SYaroslav TykhiyUpon the function's completion, 712da72b998SYaroslav Tykhiy.Fa from 713da72b998SYaroslav Tykhiywill have the flag 714da72b998SYaroslav Tykhiy.Dv M_PKTHDR 715da72b998SYaroslav Tykhiyand the per-packet attributes cleared. 716da72b998SYaroslav Tykhiy.\" 7175d96084fSYaroslav Tykhiy.It Fn m_fixhdr mbuf 7187b2fd183SYaroslav TykhiySet the packet-header length to the length of the 7197b2fd183SYaroslav Tykhiy.Vt mbuf chain . 7200b1c0994SPoul-Henning Kamp.\" 721de06f907SNik Clayton.It Fn m_devget buf len offset ifp copy 722de06f907SNik ClaytonCopy data from a device local memory pointed to by 723de06f907SNik Clayton.Fa buf 7247b2fd183SYaroslav Tykhiyto an 7257b2fd183SYaroslav Tykhiy.Vt mbuf chain . 726e73145f6SSheldon HearnThe copy is done using a specified copy routine 727de06f907SNik Clayton.Fa copy , 728de06f907SNik Claytonor 729de06f907SNik Clayton.Fn bcopy 730de06f907SNik Claytonif 731de06f907SNik Clayton.Fa copy 732de06f907SNik Claytonis 733de06f907SNik Clayton.Dv NULL . 734de06f907SNik Clayton.\" 735de06f907SNik Clayton.It Fn m_cat m n 736de06f907SNik ClaytonConcatenate 737de06f907SNik Clayton.Fa n 738de06f907SNik Claytonto 739de06f907SNik Clayton.Fa m . 7407b2fd183SYaroslav TykhiyBoth 7417b2fd183SYaroslav Tykhiy.Vt mbuf chains 7427b2fd183SYaroslav Tykhiymust be of the same type. 743de06f907SNik Clayton.Fa N 744de06f907SNik Claytonis still valid after the function returned. 745de06f907SNik Clayton.Sy Note : 746de06f907SNik ClaytonIt does not handle 747de06f907SNik Clayton.Dv M_PKTHDR 748de06f907SNik Claytonand friends. 749de06f907SNik Clayton.\" 750de06f907SNik Clayton.It Fn m_split mbuf len how 7517b2fd183SYaroslav TykhiyPartition an 7527b2fd183SYaroslav Tykhiy.Vt mbuf chain 7537b2fd183SYaroslav Tykhiyin two pieces, returning the tail: 754de06f907SNik Claytonall but the first 755de06f907SNik Clayton.Fa len 756e73145f6SSheldon Hearnbytes. 757e73145f6SSheldon HearnIn case of failure, it returns 758de06f907SNik Clayton.Dv NULL 7597b2fd183SYaroslav Tykhiyand attempts to restore the 7607b2fd183SYaroslav Tykhiy.Vt mbuf chain 7617b2fd183SYaroslav Tykhiyto its original state. 7623136363fSRuslan Ermilov.El 7633cab047eSMike Silbersack.Sh STRESS TESTING 764c8185672SRuslan ErmilovWhen running a kernel compiled with the option 765c8185672SRuslan Ermilov.Dv MBUF_STRESS_TEST , 766c8185672SRuslan Ermilovthe following 767c8185672SRuslan Ermilov.Xr sysctl 8 Ns 768c8185672SRuslan Ermilov-controlled options may be used to create 7693cab047eSMike Silbersackvarious failure/extreme cases for testing of network drivers 7707b2fd183SYaroslav Tykhiyand other parts of the kernel that rely on 7717b2fd183SYaroslav Tykhiy.Vt mbufs . 772c8185672SRuslan Ermilov.Bl -tag -width ident 773c8185672SRuslan Ermilov.It Va net.inet.ip.mbuf_frag_size 774c8185672SRuslan ErmilovCauses 775c8185672SRuslan Ermilov.Fn ip_output 7767b2fd183SYaroslav Tykhiyto fragment outgoing 7777b2fd183SYaroslav Tykhiy.Vt mbuf chains 7787b2fd183SYaroslav Tykhiyinto fragments of the specified size. 779c8185672SRuslan ErmilovSetting this variable to 1 is an excellent way to 7807b2fd183SYaroslav Tykhiytest the long 7817b2fd183SYaroslav Tykhiy.Vt mbuf chain 7827b2fd183SYaroslav Tykhiyhandling ability of network drivers. 783c8185672SRuslan Ermilov.It Va kern.ipc.m_defragrandomfailures 784c8185672SRuslan ErmilovCauses the function 785c8185672SRuslan Ermilov.Fn m_defrag 786c8185672SRuslan Ermilovto randomly fail, returning 787c8185672SRuslan Ermilov.Dv NULL . 788c8185672SRuslan ErmilovAny piece of code which uses 789c8185672SRuslan Ermilov.Fn m_defrag 790c8185672SRuslan Ermilovshould be tested with this feature. 791c8185672SRuslan Ermilov.El 792de06f907SNik Clayton.Sh RETURN VALUES 793de06f907SNik ClaytonSee above. 794de06f907SNik Clayton.Sh HISTORY 795de06f907SNik Clayton.\" Please correct me if I'm wrong 7967b2fd183SYaroslav Tykhiy.Vt Mbufs 7977b2fd183SYaroslav Tykhiyappeared in an early version of 798753d686dSRuslan Ermilov.Bx . 79953b2520dSTom RhodesBesides being used for network packets, they were used 800bfd59721SBosko Milekicto store various dynamic structures, such as routing table 801bfd59721SBosko Milekicentries, interface addresses, protocol control blocks, etc. 802de06f907SNik Clayton.Sh AUTHORS 8036575e6daSRuslan ErmilovThe original 8046575e6daSRuslan Ermilov.Nm 8056575e6daSRuslan Ermilovman page was written by Yar Tikhiy. 806