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$
|
|
|
|
.\"
|
2021-04-08 18:57:14 +00:00
|
|
|
.Dd April 8, 2021
|
2000-10-26 23:15:47 +00:00
|
|
|
.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
|
2001-12-26 23:14:04 +00:00
|
|
|
.In sys/systm.h
|
2001-10-01 16:09:29 +00:00
|
|
|
.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"
|
2015-01-06 12:59:37 +00:00
|
|
|
.Ft int
|
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"
|
2017-10-09 20:35:31 +00:00
|
|
|
.Fa "char *buf"
|
2000-11-01 23:02:19 +00:00
|
|
|
.Fa "u_int size"
|
2017-10-09 20:35:31 +00:00
|
|
|
.Fa "void (*free)(struct mbuf *)"
|
2008-02-01 19:36:27 +00:00
|
|
|
.Fa "void *opt_arg1"
|
|
|
|
.Fa "void *opt_arg2"
|
2017-10-09 20:35:31 +00:00
|
|
|
.Fa "int flags"
|
2000-11-21 22:29:31 +00:00
|
|
|
.Fa "int type"
|
2000-11-01 23:02:19 +00:00
|
|
|
.Fc
|
|
|
|
.\"
|
|
|
|
.Ss Mbuf utility macros
|
2001-12-26 23:14:04 +00:00
|
|
|
.Fn mtod "struct mbuf *mbuf" "type"
|
2000-11-01 23:02:19 +00:00
|
|
|
.Fn M_ALIGN "struct mbuf *mbuf" "u_int len"
|
|
|
|
.Fn MH_ALIGN "struct mbuf *mbuf" "u_int len"
|
2001-12-26 23:14:04 +00:00
|
|
|
.Ft int
|
2000-11-01 23:02:19 +00:00
|
|
|
.Fn M_LEADINGSPACE "struct mbuf *mbuf"
|
2001-12-26 23:14:04 +00:00
|
|
|
.Ft int
|
2000-11-01 23:02:19 +00:00
|
|
|
.Fn M_TRAILINGSPACE "struct mbuf *mbuf"
|
2003-06-15 14:40:03 +00:00
|
|
|
.Fn M_MOVE_PKTHDR "struct mbuf *to" "struct mbuf *from"
|
2000-11-01 23:02:19 +00:00
|
|
|
.Fn M_PREPEND "struct mbuf *mbuf" "int len" "int how"
|
2014-04-30 07:17:51 +00:00
|
|
|
.Fn MCHTYPE "struct mbuf *mbuf" "short type"
|
2001-12-26 23:14:04 +00:00
|
|
|
.Ft int
|
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 *
|
2014-04-30 07:17:51 +00:00
|
|
|
.Fn m_get "int how" "short type"
|
2000-10-26 23:15:47 +00:00
|
|
|
.Ft struct mbuf *
|
2014-04-30 08:51:30 +00:00
|
|
|
.Fn m_get2 "int size" "int how" "short type" "int flags"
|
|
|
|
.Ft struct mbuf *
|
2014-04-30 07:17:51 +00:00
|
|
|
.Fn m_getm "struct mbuf *orig" "int len" "int how" "short type"
|
2001-02-16 03:23:04 +00:00
|
|
|
.Ft struct mbuf *
|
2013-12-20 23:57:05 +00:00
|
|
|
.Fn m_getjcl "int how" "short type" "int flags" "int size"
|
|
|
|
.Ft struct mbuf *
|
2004-05-04 14:53:34 +00:00
|
|
|
.Fn m_getcl "int how" "short type" "int flags"
|
|
|
|
.Ft struct mbuf *
|
2014-04-30 07:17:51 +00:00
|
|
|
.Fn m_gethdr "int how" "short 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"
|
2005-08-08 00:50:25 +00:00
|
|
|
.Ft void
|
|
|
|
.Fn m_align "struct mbuf *mbuf" "int len"
|
2004-12-08 17:47:49 +00:00
|
|
|
.Ft int
|
|
|
|
.Fn m_append "struct mbuf *mbuf" "int len" "c_caddr_t cp"
|
2000-10-26 23:15:47 +00:00
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_prepend "struct mbuf *mbuf" "int len" "int how"
|
|
|
|
.Ft struct mbuf *
|
2005-03-17 19:34:57 +00:00
|
|
|
.Fn m_copyup "struct mbuf *mbuf" "int len" "int dstoff"
|
|
|
|
.Ft struct mbuf *
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fn m_pullup "struct mbuf *mbuf" "int len"
|
|
|
|
.Ft struct mbuf *
|
2007-02-26 15:17:19 +00:00
|
|
|
.Fn m_pulldown "struct mbuf *mbuf" "int offset" "int len" "int *offsetp"
|
|
|
|
.Ft struct mbuf *
|
2000-10-26 23:15:47 +00:00
|
|
|
.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 *
|
2016-10-10 17:16:02 +00:00
|
|
|
.Fn m_dup "const struct mbuf *mbuf" "int how"
|
2000-10-26 23:15:47 +00:00
|
|
|
.Ft void
|
2001-10-04 09:00:38 +00:00
|
|
|
.Fn m_copydata "const struct mbuf *mbuf" "int offset" "int len" "caddr_t buf"
|
2000-10-26 23:15:47 +00:00
|
|
|
.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"
|
2016-03-02 04:58:51 +00:00
|
|
|
.Ft void
|
|
|
|
.Fn m_catpkt "struct mbuf *m" "struct mbuf *n"
|
2002-11-29 11:36:32 +00:00
|
|
|
.Ft u_int
|
2002-09-18 20:04:30 +00:00
|
|
|
.Fn m_fixhdr "struct mbuf *mbuf"
|
2016-10-10 17:16:02 +00:00
|
|
|
.Ft int
|
|
|
|
.Fn m_dup_pkthdr "struct mbuf *to" "const struct mbuf *from" "int how"
|
2003-06-15 14:40:03 +00:00
|
|
|
.Ft void
|
|
|
|
.Fn m_move_pkthdr "struct mbuf *to" "struct mbuf *from"
|
2002-11-29 11:36:32 +00:00
|
|
|
.Ft u_int
|
2002-09-18 20:04:30 +00:00
|
|
|
.Fn m_length "struct mbuf *mbuf" "struct mbuf **last"
|
2000-10-26 23:15:47 +00:00
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_split "struct mbuf *mbuf" "int len" "int how"
|
2004-02-11 02:39:24 +00:00
|
|
|
.Ft int
|
|
|
|
.Fn m_apply "struct mbuf *mbuf" "int off" "int len" "int (*f)(void *arg, void *data, u_int len)" "void *arg"
|
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_getptr "struct mbuf *mbuf" "int loc" "int *off"
|
2004-04-01 06:50:21 +00:00
|
|
|
.Ft struct mbuf *
|
|
|
|
.Fn m_defrag "struct mbuf *m0" "int how"
|
2006-03-15 21:11:11 +00:00
|
|
|
.Ft struct mbuf *
|
2015-03-12 01:05:54 +00:00
|
|
|
.Fn m_collapse "struct mbuf *m0" "int how" "int maxfrags"
|
|
|
|
.Ft struct mbuf *
|
2006-03-15 21:11:11 +00:00
|
|
|
.Fn m_unshare "struct mbuf *m0" "int how"
|
2000-10-26 23:15:47 +00:00
|
|
|
.\"
|
|
|
|
.Sh DESCRIPTION
|
2003-06-15 14:14:11 +00:00
|
|
|
An
|
|
|
|
.Vt mbuf
|
|
|
|
is a basic unit of memory management in the kernel IPC subsystem.
|
|
|
|
Network packets and socket buffers are stored in
|
|
|
|
.Vt mbufs .
|
|
|
|
A network packet may span multiple
|
|
|
|
.Vt mbufs
|
|
|
|
arranged into a
|
|
|
|
.Vt mbuf 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
|
2003-06-15 14:14:11 +00:00
|
|
|
While a developer should not bother with
|
|
|
|
.Vt mbuf
|
|
|
|
internals without serious
|
2000-10-26 23:15:47 +00:00
|
|
|
reason in order to avoid incompatibilities with future changes, it
|
2003-06-15 14:14:11 +00:00
|
|
|
is useful to understand the general structure of an
|
|
|
|
.Vt mbuf .
|
2000-10-26 23:15:47 +00:00
|
|
|
.Pp
|
2003-06-15 14:14:11 +00:00
|
|
|
An
|
|
|
|
.Vt mbuf
|
|
|
|
consists of a variable-sized header and a small internal
|
2000-11-10 10:08:34 +00:00
|
|
|
buffer for data.
|
2003-06-15 14:14:11 +00:00
|
|
|
The total size of an
|
|
|
|
.Vt mbuf ,
|
2000-11-01 23:02:19 +00:00
|
|
|
.Dv MSIZE ,
|
2004-02-01 22:33:59 +00:00
|
|
|
is a constant defined in
|
|
|
|
.In sys/param.h .
|
2003-06-15 14:14:11 +00:00
|
|
|
The
|
|
|
|
.Vt mbuf
|
|
|
|
header includes:
|
2004-01-18 23:42:28 +00:00
|
|
|
.Bl -tag -width "m_nextpkt" -offset indent
|
2003-06-15 12:42:41 +00:00
|
|
|
.It Va m_next
|
2004-01-18 23:42:28 +00:00
|
|
|
.Pq Vt struct mbuf *
|
|
|
|
A pointer to the next
|
2003-06-15 14:14:11 +00:00
|
|
|
.Vt mbuf
|
|
|
|
in the
|
2004-01-18 23:42:28 +00:00
|
|
|
.Vt mbuf chain .
|
2003-06-15 12:42:41 +00:00
|
|
|
.It Va m_nextpkt
|
2004-01-18 23:42:28 +00:00
|
|
|
.Pq Vt struct mbuf *
|
|
|
|
A pointer to the next
|
2003-06-15 14:14:11 +00:00
|
|
|
.Vt mbuf chain
|
2004-01-18 23:42:28 +00:00
|
|
|
in the queue.
|
2003-06-15 12:42:41 +00:00
|
|
|
.It Va m_data
|
2004-01-18 23:42:28 +00:00
|
|
|
.Pq Vt caddr_t
|
|
|
|
A pointer to data attached to this
|
|
|
|
.Vt mbuf .
|
2003-06-15 12:42:41 +00:00
|
|
|
.It Va m_len
|
2004-01-18 23:42:28 +00:00
|
|
|
.Pq Vt int
|
|
|
|
The length of the data.
|
2003-06-15 12:42:41 +00:00
|
|
|
.It Va m_type
|
2004-01-18 23:42:28 +00:00
|
|
|
.Pq Vt short
|
|
|
|
The type of the data.
|
2003-06-15 12:42:41 +00:00
|
|
|
.It Va m_flags
|
2004-01-18 23:42:28 +00:00
|
|
|
.Pq Vt int
|
|
|
|
The
|
2003-06-15 14:14:11 +00:00
|
|
|
.Vt mbuf
|
2004-01-18 23:42:28 +00:00
|
|
|
flags.
|
2000-10-26 23:15:47 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
2003-06-15 14:14:11 +00:00
|
|
|
The
|
|
|
|
.Vt mbuf
|
|
|
|
flag bits are defined as follows:
|
2000-10-26 23:15:47 +00:00
|
|
|
.Bd -literal
|
2014-06-05 03:16:23 +00:00
|
|
|
#define M_EXT 0x00000001 /* has associated external storage */
|
|
|
|
#define M_PKTHDR 0x00000002 /* start of record */
|
|
|
|
#define M_EOR 0x00000004 /* end of record */
|
|
|
|
#define M_RDONLY 0x00000008 /* associated data marked read-only */
|
2019-06-28 19:49:47 +00:00
|
|
|
#define M_BCAST 0x00000010 /* send/received as link-level broadcast */
|
|
|
|
#define M_MCAST 0x00000020 /* send/received as link-level multicast */
|
|
|
|
#define M_PROMISC 0x00000040 /* packet was not for us */
|
|
|
|
#define M_VLANTAG 0x00000080 /* ether_vtag is valid */
|
2021-01-28 20:56:36 +00:00
|
|
|
#define M_EXTPG 0x00000100 /* has array of unmapped pages and TLS */
|
|
|
|
#define M_NOFREE 0x00000200 /* do not free mbuf, embedded in cluster */
|
2019-06-28 19:49:47 +00:00
|
|
|
#define M_TSTMP 0x00000400 /* rcv_tstmp field is valid */
|
|
|
|
#define M_TSTMP_HPREC 0x00000800 /* rcv_tstmp is high-prec, typically
|
|
|
|
hw-stamped on port (useful for IEEE 1588
|
|
|
|
and 802.1AS) */
|
|
|
|
|
2014-06-05 03:16:23 +00:00
|
|
|
#define M_PROTO1 0x00001000 /* protocol-specific */
|
|
|
|
#define M_PROTO2 0x00002000 /* protocol-specific */
|
|
|
|
#define M_PROTO3 0x00004000 /* protocol-specific */
|
|
|
|
#define M_PROTO4 0x00008000 /* protocol-specific */
|
|
|
|
#define M_PROTO5 0x00010000 /* protocol-specific */
|
|
|
|
#define M_PROTO6 0x00020000 /* protocol-specific */
|
|
|
|
#define M_PROTO7 0x00040000 /* protocol-specific */
|
|
|
|
#define M_PROTO8 0x00080000 /* protocol-specific */
|
|
|
|
#define M_PROTO9 0x00100000 /* protocol-specific */
|
|
|
|
#define M_PROTO10 0x00200000 /* protocol-specific */
|
|
|
|
#define M_PROTO11 0x00400000 /* protocol-specific */
|
|
|
|
#define M_PROTO12 0x00800000 /* protocol-specific */
|
2000-10-26 23:15:47 +00:00
|
|
|
.Ed
|
|
|
|
.Pp
|
2003-06-15 14:14:11 +00:00
|
|
|
The available
|
|
|
|
.Vt mbuf
|
|
|
|
types are defined as follows:
|
2000-10-26 23:15:47 +00:00
|
|
|
.Bd -literal
|
|
|
|
#define MT_DATA 1 /* dynamic (data) allocation */
|
2006-07-24 07:32:23 +00:00
|
|
|
#define MT_HEADER MT_DATA /* packet header */
|
2019-06-28 19:49:47 +00:00
|
|
|
|
|
|
|
#define MT_VENDOR1 4 /* for vendor-internal use */
|
|
|
|
#define MT_VENDOR2 5 /* for vendor-internal use */
|
|
|
|
#define MT_VENDOR3 6 /* for vendor-internal use */
|
|
|
|
#define MT_VENDOR4 7 /* for vendor-internal use */
|
|
|
|
|
2000-10-26 23:15:47 +00:00
|
|
|
#define MT_SONAME 8 /* socket name */
|
2019-06-28 19:49:47 +00:00
|
|
|
|
|
|
|
#define MT_EXP1 9 /* for experimental use */
|
|
|
|
#define MT_EXP2 10 /* for experimental use */
|
|
|
|
#define MT_EXP3 11 /* for experimental use */
|
|
|
|
#define MT_EXP4 12 /* for experimental use */
|
|
|
|
|
2000-10-26 23:15:47 +00:00
|
|
|
#define MT_CONTROL 14 /* extra-data protocol message */
|
2019-06-28 19:49:47 +00:00
|
|
|
#define MT_EXTCONTROL 15 /* control message with externalized contents */
|
|
|
|
#define MT_OOBDATA 16 /* expedited data */
|
2000-10-26 23:15:47 +00:00
|
|
|
.Ed
|
|
|
|
.Pp
|
2010-08-07 13:26:08 +00:00
|
|
|
The available external buffer types are defined as follows:
|
|
|
|
.Bd -literal
|
2019-06-28 19:37:48 +00:00
|
|
|
#define EXT_CLUSTER 1 /* mbuf cluster */
|
|
|
|
#define EXT_SFBUF 2 /* sendfile(2)'s sf_bufs */
|
|
|
|
#define EXT_JUMBOP 3 /* jumbo cluster 4096 bytes */
|
|
|
|
#define EXT_JUMBO9 4 /* jumbo cluster 9216 bytes */
|
|
|
|
#define EXT_JUMBO16 5 /* jumbo cluster 16184 bytes */
|
|
|
|
#define EXT_PACKET 6 /* mbuf+cluster from packet zone */
|
|
|
|
#define EXT_MBUF 7 /* external mbuf reference */
|
2019-06-28 19:49:47 +00:00
|
|
|
#define EXT_RXRING 8 /* data in NIC receive ring */
|
Add an external mbuf buffer type that holds multiple unmapped pages.
Unmapped mbufs allow sendfile to carry multiple pages of data in a
single mbuf, without mapping those pages. It is a requirement for
Netflix's in-kernel TLS, and provides a 5-10% CPU savings on heavy web
serving workloads when used by sendfile, due to effectively
compressing socket buffers by an order of magnitude, and hence
reducing cache misses.
For this new external mbuf buffer type (EXT_PGS), the ext_buf pointer
now points to a struct mbuf_ext_pgs structure instead of a data
buffer. This structure contains an array of physical addresses (this
reduces cache misses compared to an earlier version that stored an
array of vm_page_t pointers). It also stores additional fields needed
for in-kernel TLS such as the TLS header and trailer data that are
currently unused. To more easily detect these mbufs, the M_NOMAP flag
is set in m_flags in addition to M_EXT.
Various functions like m_copydata() have been updated to safely access
packet contents (using uiomove_fromphys()), to make things like BPF
safe.
NIC drivers advertise support for unmapped mbufs on transmit via a new
IFCAP_NOMAP capability. This capability can be toggled via the new
'nomap' and '-nomap' ifconfig(8) commands. For NIC drivers that only
transmit packet contents via DMA and use bus_dma, adding the
capability to if_capabilities and if_capenable should be all that is
required.
If a NIC does not support unmapped mbufs, they are converted to a
chain of mapped mbufs (using sf_bufs to provide the mapping) in
ip_output or ip6_output. If an unmapped mbuf requires software
checksums, it is also converted to a chain of mapped mbufs before
computing the checksum.
Submitted by: gallatin (earlier version)
Reviewed by: gallatin, hselasky, rrs
Discussed with: ae, kp (firewalls)
Relnotes: yes
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D20616
2019-06-29 00:48:33 +00:00
|
|
|
#define EXT_PGS 9 /* array of unmapped pages */
|
2019-06-28 19:49:47 +00:00
|
|
|
|
|
|
|
#define EXT_VENDOR1 224 /* for vendor-internal use */
|
|
|
|
#define EXT_VENDOR2 225 /* for vendor-internal use */
|
|
|
|
#define EXT_VENDOR3 226 /* for vendor-internal use */
|
|
|
|
#define EXT_VENDOR4 227 /* for vendor-internal use */
|
|
|
|
|
|
|
|
#define EXT_EXP1 244 /* for experimental use */
|
|
|
|
#define EXT_EXP2 245 /* for experimental use */
|
|
|
|
#define EXT_EXP3 246 /* for experimental use */
|
|
|
|
#define EXT_EXP4 247 /* for experimental use */
|
|
|
|
|
2019-06-28 19:37:48 +00:00
|
|
|
#define EXT_NET_DRV 252 /* custom ext_buf provided by net driver(s) */
|
|
|
|
#define EXT_MOD_TYPE 253 /* custom module's ext_buf type */
|
|
|
|
#define EXT_DISPOSABLE 254 /* can throw this buffer away w/page flipping */
|
|
|
|
#define EXT_EXTREF 255 /* has externally maintained ref_cnt ptr */
|
2010-08-07 13:26:08 +00:00
|
|
|
.Ed
|
|
|
|
.Pp
|
2000-10-26 23:15:47 +00:00
|
|
|
If the
|
|
|
|
.Dv M_PKTHDR
|
|
|
|
flag is set, a
|
2003-06-15 14:14:11 +00:00
|
|
|
.Vt struct pkthdr Va m_pkthdr
|
|
|
|
is added to the
|
|
|
|
.Vt mbuf
|
|
|
|
header.
|
2000-11-10 10:08:34 +00:00
|
|
|
It contains a pointer to the interface
|
2000-10-26 23:15:47 +00:00
|
|
|
the packet has been received from
|
2003-06-15 14:14:11 +00:00
|
|
|
.Pq Vt struct ifnet Va *rcvif ,
|
2000-10-26 23:15:47 +00:00
|
|
|
and the total packet length
|
2003-06-15 14:14:11 +00:00
|
|
|
.Pq Vt int Va len .
|
2004-05-20 09:34:19 +00:00
|
|
|
Optionally, it may also contain an attached list of packet tags
|
|
|
|
.Pq Vt "struct m_tag" .
|
|
|
|
See
|
|
|
|
.Xr mbuf_tags 9
|
|
|
|
for details.
|
2004-01-21 12:45:37 +00:00
|
|
|
Fields used in offloading checksum calculation to the hardware are kept in
|
|
|
|
.Va m_pkthdr
|
|
|
|
as well.
|
|
|
|
See
|
|
|
|
.Sx HARDWARE-ASSISTED CHECKSUM CALCULATION
|
|
|
|
for details.
|
2000-10-26 23:15:47 +00:00
|
|
|
.Pp
|
2003-06-15 14:14:11 +00:00
|
|
|
If small enough, data is stored in the internal data buffer of an
|
|
|
|
.Vt mbuf .
|
|
|
|
If the data is sufficiently large, another
|
|
|
|
.Vt mbuf
|
|
|
|
may be added to the
|
|
|
|
.Vt mbuf chain ,
|
|
|
|
or external storage may be associated with the
|
|
|
|
.Vt mbuf .
|
2000-10-26 23:15:47 +00:00
|
|
|
.Dv MHLEN
|
2003-06-15 14:14:11 +00:00
|
|
|
bytes of data can fit into an
|
|
|
|
.Vt mbuf
|
|
|
|
with the
|
2000-10-26 23:15:47 +00:00
|
|
|
.Dv M_PKTHDR
|
|
|
|
flag set,
|
|
|
|
.Dv MLEN
|
|
|
|
bytes can otherwise.
|
|
|
|
.Pp
|
2003-06-15 14:14:11 +00:00
|
|
|
If external storage is being associated with an
|
|
|
|
.Vt mbuf ,
|
|
|
|
the
|
2003-06-15 12:42:41 +00:00
|
|
|
.Va 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.
|
2003-06-15 14:14:11 +00:00
|
|
|
An
|
|
|
|
.Vt 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.
|
2000-11-01 23:02:19 +00:00
|
|
|
.Pp
|
|
|
|
The system also supplies a default type of external storage buffer called an
|
2003-06-15 14:14:11 +00:00
|
|
|
.Vt mbuf cluster .
|
|
|
|
.Vt Mbuf clusters
|
|
|
|
can be allocated and configured with the use of the
|
2000-11-01 23:02:19 +00:00
|
|
|
.Dv MCLGET
|
2000-11-10 10:08:34 +00:00
|
|
|
macro.
|
2003-06-15 14:14:11 +00:00
|
|
|
Each
|
|
|
|
.Vt mbuf 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 ,
|
2003-06-15 14:14:11 +00:00
|
|
|
which is the smallest amount of data to put into an
|
|
|
|
.Vt mbuf cluster .
|
2012-10-25 08:38:43 +00:00
|
|
|
It is equal to
|
|
|
|
.Dv MHLEN
|
|
|
|
plus one.
|
2003-06-15 14:14:11 +00:00
|
|
|
It is typically preferable to store data into the data region of an
|
|
|
|
.Vt mbuf ,
|
|
|
|
if size permits, as opposed to allocating a separate
|
|
|
|
.Vt 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
|
2003-06-15 14:14:11 +00:00
|
|
|
Convert an
|
|
|
|
.Fa mbuf
|
|
|
|
pointer to a data pointer.
|
2014-10-21 17:59:27 +00:00
|
|
|
The macro expands to the data pointer cast to the specified
|
2003-06-15 14:14:11 +00:00
|
|
|
.Fa type .
|
2000-10-26 23:15:47 +00:00
|
|
|
.Sy Note :
|
2003-06-15 14:14:11 +00:00
|
|
|
It is advisable to ensure that there is enough contiguous data in
|
|
|
|
.Fa mbuf .
|
2000-10-26 23:15:47 +00:00
|
|
|
See
|
|
|
|
.Fn m_pullup
|
|
|
|
for details.
|
|
|
|
.It Fn MGET mbuf how type
|
2003-06-15 14:14:11 +00:00
|
|
|
Allocate an
|
|
|
|
.Vt mbuf
|
|
|
|
and initialize it to contain internal data.
|
2000-11-10 10:22:49 +00:00
|
|
|
.Fa mbuf
|
2003-06-15 14:14:11 +00:00
|
|
|
will point to the allocated
|
|
|
|
.Vt 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
|
2011-04-18 15:30:25 +00:00
|
|
|
.Dv M_WAITOK
|
2000-10-26 23:15:47 +00:00
|
|
|
or
|
2011-04-18 15:30:25 +00:00
|
|
|
.Dv M_NOWAIT .
|
2000-11-10 10:22:49 +00:00
|
|
|
It specifies whether the caller is willing to block if necessary.
|
2003-06-15 14:14:11 +00:00
|
|
|
A number of other functions and macros related to
|
|
|
|
.Vt mbufs
|
|
|
|
have the same argument because they may
|
|
|
|
at some point need to allocate new
|
|
|
|
.Vt mbufs .
|
2000-10-26 23:15:47 +00:00
|
|
|
.It Fn MGETHDR mbuf how type
|
2003-06-15 14:14:11 +00:00
|
|
|
Allocate an
|
|
|
|
.Vt 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.
|
2010-08-07 13:26:08 +00:00
|
|
|
.It Fn MEXTADD mbuf buf size free opt_arg1 opt_arg2 flags type
|
|
|
|
Associate externally managed data with
|
|
|
|
.Fa mbuf .
|
|
|
|
Any internal data contained in the mbuf will be discarded, and the
|
2012-05-20 16:43:47 +00:00
|
|
|
.Dv M_EXT
|
|
|
|
flag will be set.
|
2010-08-07 13:26:08 +00:00
|
|
|
The
|
|
|
|
.Fa buf
|
|
|
|
and
|
|
|
|
.Fa size
|
|
|
|
arguments are the address and length, respectively, of the data.
|
|
|
|
The
|
|
|
|
.Fa free
|
|
|
|
argument points to a function which will be called to free the data
|
|
|
|
when the mbuf is freed; it is only used if
|
|
|
|
.Fa type
|
|
|
|
is
|
|
|
|
.Dv EXT_EXTREF .
|
|
|
|
The
|
|
|
|
.Fa opt_arg1
|
|
|
|
and
|
|
|
|
.Fa opt_arg2
|
2017-10-09 20:35:31 +00:00
|
|
|
arguments will be saved in
|
|
|
|
.Va ext_arg1
|
|
|
|
and
|
|
|
|
.Va ext_arg2
|
|
|
|
fields of the
|
|
|
|
.Va struct m_ext
|
|
|
|
of the mbuf.
|
2010-08-07 13:26:08 +00:00
|
|
|
The
|
|
|
|
.Fa flags
|
|
|
|
argument specifies additional
|
|
|
|
.Vt mbuf
|
|
|
|
flags; it is not necessary to specify
|
|
|
|
.Dv M_EXT .
|
|
|
|
Finally, the
|
|
|
|
.Fa type
|
|
|
|
argument specifies the type of external data, which controls how it
|
|
|
|
will be disposed of when the
|
|
|
|
.Vt mbuf
|
|
|
|
is freed.
|
|
|
|
In most cases, the correct value is
|
|
|
|
.Dv EXT_EXTREF .
|
2000-10-26 23:15:47 +00:00
|
|
|
.It Fn MCLGET mbuf how
|
2003-06-15 14:14:11 +00:00
|
|
|
Allocate and attach an
|
|
|
|
.Vt mbuf cluster
|
|
|
|
to
|
|
|
|
.Fa mbuf .
|
2015-01-06 12:59:37 +00:00
|
|
|
On success, a non-zero value returned; otherwise, 0.
|
|
|
|
Historically, consumers would check for success by testing the
|
2000-10-26 23:15:47 +00:00
|
|
|
.Dv M_EXT
|
2015-01-06 12:59:37 +00:00
|
|
|
flag on the mbuf, but this is now discouraged to avoid unnecessary awareness
|
|
|
|
of the implementation of external storage in protocol stacks and device
|
|
|
|
drivers.
|
2003-06-15 14:40:03 +00:00
|
|
|
.It Fn M_ALIGN mbuf len
|
|
|
|
Set the pointer
|
|
|
|
.Fa mbuf->m_data
|
|
|
|
to place an object of the size
|
|
|
|
.Fa len
|
|
|
|
at the end of the internal data area of
|
|
|
|
.Fa mbuf ,
|
|
|
|
long word aligned.
|
|
|
|
Applicable only if
|
|
|
|
.Fa mbuf
|
|
|
|
is newly allocated with
|
|
|
|
.Fn MGET
|
|
|
|
or
|
|
|
|
.Fn m_get .
|
|
|
|
.It Fn MH_ALIGN mbuf len
|
|
|
|
Serves the same purpose as
|
|
|
|
.Fn M_ALIGN
|
|
|
|
does, but only for
|
|
|
|
.Fa mbuf
|
|
|
|
newly allocated with
|
|
|
|
.Fn MGETHDR
|
|
|
|
or
|
|
|
|
.Fn m_gethdr ,
|
|
|
|
or initialized by
|
|
|
|
.Fn m_dup_pkthdr
|
|
|
|
or
|
|
|
|
.Fn m_move_pkthdr .
|
2005-08-08 00:50:25 +00:00
|
|
|
.It Fn m_align mbuf len
|
|
|
|
Services the same purpose as
|
|
|
|
.Fn M_ALIGN
|
|
|
|
but handles any type of mbuf.
|
2003-06-15 14:40:03 +00:00
|
|
|
.It Fn M_LEADINGSPACE mbuf
|
|
|
|
Returns the number of bytes available before the beginning
|
|
|
|
of data in
|
|
|
|
.Fa mbuf .
|
|
|
|
.It Fn M_TRAILINGSPACE mbuf
|
|
|
|
Returns the number of bytes available after the end of data in
|
|
|
|
.Fa mbuf .
|
2000-10-26 23:15:47 +00:00
|
|
|
.It Fn M_PREPEND mbuf len how
|
2003-06-15 14:14:11 +00:00
|
|
|
This macro operates on an
|
|
|
|
.Vt 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
|
2004-07-03 18:29:24 +00:00
|
|
|
(e.g.\& left after trimming of a link-layer header).
|
2003-06-15 14:14:11 +00:00
|
|
|
The new
|
|
|
|
.Vt mbuf chain
|
|
|
|
pointer or
|
2000-10-26 23:15:47 +00:00
|
|
|
.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.
|
2003-06-15 14:40:03 +00:00
|
|
|
.It Fn M_MOVE_PKTHDR to from
|
|
|
|
Using this macro is equivalent to calling
|
|
|
|
.Fn m_move_pkthdr to from .
|
2000-11-21 22:29:31 +00:00
|
|
|
.It Fn M_WRITABLE mbuf
|
2003-06-15 14:14:11 +00:00
|
|
|
This macro will evaluate true if
|
|
|
|
.Fa mbuf
|
|
|
|
is not marked
|
2000-11-21 22:29:31 +00:00
|
|
|
.Dv M_RDONLY
|
2003-06-15 14:14:11 +00:00
|
|
|
and if either
|
|
|
|
.Fa mbuf
|
|
|
|
does not contain external storage or,
|
2000-11-21 22:29:31 +00:00
|
|
|
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
|
2003-06-15 14:14:11 +00:00
|
|
|
flag can be set in
|
|
|
|
.Fa mbuf->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
|
2003-06-15 14:14:11 +00:00
|
|
|
macro, or can be directly set in individual
|
|
|
|
.Vt mbufs .
|
2003-06-15 14:40:03 +00:00
|
|
|
.It Fn MCHTYPE mbuf type
|
|
|
|
Change the type of
|
|
|
|
.Fa mbuf
|
|
|
|
to
|
|
|
|
.Fa type .
|
|
|
|
This is a relatively expensive operation and should be avoided.
|
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.
|
2014-04-30 08:51:30 +00:00
|
|
|
.It Fn m_get2 size how type flags
|
|
|
|
Allocate an
|
|
|
|
.Vt mbuf
|
|
|
|
with enough space to hold specified amount of data.
|
2020-09-17 20:53:24 +00:00
|
|
|
If the size is is larger than
|
2020-07-24 00:35:21 +00:00
|
|
|
.Dv MJUMPAGESIZE , NULL
|
|
|
|
will be returned.
|
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
|
2003-06-15 14:14:11 +00:00
|
|
|
bytes worth of
|
|
|
|
.Vt mbufs
|
|
|
|
and
|
|
|
|
.Vt mbuf clusters
|
|
|
|
if necessary and append the resulting allocated
|
|
|
|
.Vt mbuf chain
|
|
|
|
to the
|
|
|
|
.Vt mbuf chain
|
|
|
|
.Fa orig ,
|
|
|
|
if it is
|
2001-02-16 09:05:48 +00:00
|
|
|
.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
|
2003-06-15 14:14:11 +00:00
|
|
|
bytes to an existing
|
|
|
|
.Vt mbuf
|
|
|
|
or
|
|
|
|
.Vt mbuf chain
|
2001-02-16 03:23:04 +00:00
|
|
|
(for example, one which may be sitting in a pre-allocated ring)
|
2003-06-15 14:14:11 +00:00
|
|
|
or to simply perform an all-or-nothing
|
|
|
|
.Vt mbuf
|
|
|
|
and
|
|
|
|
.Vt 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.
|
2004-05-04 14:53:34 +00:00
|
|
|
.It Fn m_getcl how type flags
|
|
|
|
Fetch an
|
|
|
|
.Vt mbuf
|
|
|
|
with a
|
|
|
|
.Vt mbuf cluster
|
|
|
|
attached to it.
|
|
|
|
If one of the allocations fails, the entire allocation fails.
|
|
|
|
This routine is the preferred way of fetching both the
|
|
|
|
.Vt mbuf
|
|
|
|
and
|
|
|
|
.Vt mbuf cluster
|
|
|
|
together, as it avoids having to unlock/relock between allocations.
|
|
|
|
Returns
|
|
|
|
.Dv NULL
|
|
|
|
on failure.
|
2013-12-20 23:57:05 +00:00
|
|
|
.It Fn m_getjcl how type flags size
|
|
|
|
This is like
|
|
|
|
.Fn m_getcl
|
2020-07-24 00:47:14 +00:00
|
|
|
but the specified
|
2013-12-20 23:57:05 +00:00
|
|
|
.Fa size
|
2020-07-24 00:47:14 +00:00
|
|
|
of the cluster to be allocated must be one of
|
|
|
|
.Dv MCLBYTES , MJUMPAGESIZE , MJUM9BYTES ,
|
|
|
|
or
|
2020-09-17 20:53:24 +00:00
|
|
|
.Dv MJUM16BYTES .
|
2004-04-28 14:53:49 +00:00
|
|
|
.It Fn m_free mbuf
|
|
|
|
Frees
|
|
|
|
.Vt mbuf .
|
2004-08-28 03:46:18 +00:00
|
|
|
Returns
|
|
|
|
.Va m_next
|
|
|
|
of the freed
|
|
|
|
.Vt mbuf .
|
2000-10-26 23:15:47 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
2003-06-15 14:14:11 +00:00
|
|
|
The functions below operate on
|
|
|
|
.Vt mbuf chains .
|
2000-10-26 23:15:47 +00:00
|
|
|
.Bl -ohang -offset indent
|
|
|
|
.It Fn m_freem mbuf
|
2003-06-15 14:14:11 +00:00
|
|
|
Free an entire
|
|
|
|
.Vt mbuf chain ,
|
|
|
|
including any external storage.
|
2000-10-26 23:15:47 +00:00
|
|
|
.\"
|
|
|
|
.It Fn m_adj mbuf len
|
|
|
|
Trim
|
|
|
|
.Fa len
|
2003-06-15 14:14:11 +00:00
|
|
|
bytes from the head of an
|
|
|
|
.Vt mbuf chain
|
|
|
|
if
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fa len
|
|
|
|
is positive, from the tail otherwise.
|
|
|
|
.\"
|
2004-12-08 17:47:49 +00:00
|
|
|
.It Fn m_append mbuf len cp
|
|
|
|
Append
|
|
|
|
.Vt len
|
|
|
|
bytes of data
|
|
|
|
.Vt cp
|
|
|
|
to the
|
|
|
|
.Vt mbuf chain .
|
|
|
|
Extend the mbuf chain if the new data does not fit in
|
|
|
|
existing space.
|
|
|
|
.\"
|
2000-10-26 23:15:47 +00:00
|
|
|
.It Fn m_prepend mbuf len how
|
2003-06-15 14:14:11 +00:00
|
|
|
Allocate a new
|
|
|
|
.Vt mbuf
|
|
|
|
and prepend it to the
|
|
|
|
.Vt mbuf chain ,
|
|
|
|
handle
|
2000-10-26 23:15:47 +00:00
|
|
|
.Dv M_PKTHDR
|
|
|
|
properly.
|
|
|
|
.Sy Note :
|
2005-02-13 22:25:33 +00:00
|
|
|
It does not allocate any
|
2003-06-15 14:14:11 +00:00
|
|
|
.Vt mbuf clusters ,
|
|
|
|
so
|
2000-10-26 23:15:47 +00:00
|
|
|
.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
|
|
|
.\"
|
2005-03-17 19:34:57 +00:00
|
|
|
.It Fn m_copyup mbuf len dstoff
|
|
|
|
Similar to
|
|
|
|
.Fn m_pullup
|
|
|
|
but copies
|
|
|
|
.Fa len
|
|
|
|
bytes of data into a new mbuf at
|
|
|
|
.Fa dstoff
|
|
|
|
bytes into the mbuf.
|
|
|
|
The
|
|
|
|
.Fa dstoff
|
|
|
|
argument aligns the data and leaves room for a link layer header.
|
2005-06-15 13:31:23 +00:00
|
|
|
Returns the new
|
2005-03-17 19:34:57 +00:00
|
|
|
.Vt mbuf chain
|
|
|
|
on success,
|
|
|
|
and frees the
|
|
|
|
.Vt mbuf chain
|
|
|
|
and returns
|
|
|
|
.Dv NULL
|
|
|
|
on failure.
|
|
|
|
.Sy Note :
|
|
|
|
The function does not allocate
|
|
|
|
.Vt mbuf clusters ,
|
|
|
|
so
|
|
|
|
.Fa len + dstoff
|
|
|
|
must be less than
|
|
|
|
.Dv MHLEN .
|
|
|
|
.\"
|
2000-10-26 23:15:47 +00:00
|
|
|
.It Fn m_pullup mbuf len
|
|
|
|
Arrange that the first
|
|
|
|
.Fa len
|
2003-06-15 14:14:11 +00:00
|
|
|
bytes of an
|
|
|
|
.Vt 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 .
|
2006-12-08 23:44:30 +00:00
|
|
|
It is important to remember that this may involve
|
|
|
|
reallocating some mbufs and moving data so all pointers
|
|
|
|
referencing data within the old mbuf chain
|
|
|
|
must be recalculated or made invalid.
|
2003-06-15 14:14:11 +00:00
|
|
|
Return the new
|
|
|
|
.Vt mbuf chain
|
|
|
|
on success,
|
2000-10-26 23:15:47 +00:00
|
|
|
.Dv NULL
|
|
|
|
on failure
|
2003-06-15 14:14:11 +00:00
|
|
|
(the
|
|
|
|
.Vt mbuf chain
|
|
|
|
is freed in this case).
|
2000-10-26 23:15:47 +00:00
|
|
|
.Sy Note :
|
2005-02-13 22:25:33 +00:00
|
|
|
It does not allocate any
|
2003-06-15 14:14:11 +00:00
|
|
|
.Vt mbuf clusters ,
|
|
|
|
so
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fa len
|
2012-10-30 10:13:26 +00:00
|
|
|
must be less than or equal to
|
2000-10-26 23:15:47 +00:00
|
|
|
.Dv MHLEN .
|
|
|
|
.\"
|
2007-02-26 15:17:19 +00:00
|
|
|
.It Fn m_pulldown mbuf offset len offsetp
|
|
|
|
Arrange that
|
|
|
|
.Fa len
|
|
|
|
bytes between
|
|
|
|
.Fa offset
|
|
|
|
and
|
|
|
|
.Fa offset + len
|
|
|
|
in the
|
|
|
|
.Vt mbuf chain
|
|
|
|
are contiguous and lay in the data area of
|
|
|
|
.Fa mbuf ,
|
|
|
|
so they are accessible with
|
|
|
|
.Fn mtod mbuf type .
|
2012-05-20 16:43:47 +00:00
|
|
|
.Fa len
|
|
|
|
must be smaller than, or equal to, the size of an
|
2007-02-26 15:17:19 +00:00
|
|
|
.Vt mbuf cluster .
|
|
|
|
Return a pointer to an intermediate
|
|
|
|
.Vt mbuf
|
|
|
|
in the chain containing the requested region;
|
|
|
|
the offset in the data region of the
|
|
|
|
.Vt mbuf chain
|
|
|
|
to the data contained in the returned mbuf is stored in
|
|
|
|
.Fa *offsetp .
|
|
|
|
If
|
2014-10-21 17:17:40 +00:00
|
|
|
.Fa offsetp
|
2007-02-26 15:17:19 +00:00
|
|
|
is NULL, the region may be accessed using
|
|
|
|
.Fn mtod mbuf type .
|
|
|
|
If
|
2014-10-21 17:17:40 +00:00
|
|
|
.Fa offsetp
|
2007-02-26 15:17:19 +00:00
|
|
|
is non-NULL, the region may be accessed using
|
2014-10-21 17:17:40 +00:00
|
|
|
.Fn mtod mbuf uint8_t
|
|
|
|
+ *offsetp.
|
2007-02-26 15:17:19 +00:00
|
|
|
The region of the mbuf chain between its beginning and
|
2014-10-21 17:17:40 +00:00
|
|
|
.Fa offset
|
2007-02-26 15:17:19 +00:00
|
|
|
is not modified, therefore it is safe to hold pointers to data within
|
|
|
|
this region before calling
|
|
|
|
.Fn m_pulldown .
|
|
|
|
.\"
|
2000-10-26 23:15:47 +00:00
|
|
|
.It Fn m_copym mbuf offset len how
|
2003-06-15 14:14:11 +00:00
|
|
|
Make a copy of an
|
|
|
|
.Vt 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 ,
|
2003-06-15 14:14:11 +00:00
|
|
|
copy to the end of the
|
|
|
|
.Vt mbuf chain .
|
2000-10-26 23:15:47 +00:00
|
|
|
.Sy Note :
|
2003-06-15 14:14:11 +00:00
|
|
|
The copy is read-only, because the
|
|
|
|
.Vt mbuf clusters
|
|
|
|
are not copied, only their reference counts are incremented.
|
2000-10-26 23:15:47 +00:00
|
|
|
.\"
|
|
|
|
.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 :
|
2003-06-15 14:14:11 +00:00
|
|
|
the copy is read-only, because the
|
|
|
|
.Vt mbuf clusters
|
|
|
|
are not copied, only their reference counts are incremented.
|
2000-10-26 23:15:47 +00:00
|
|
|
.\"
|
|
|
|
.It Fn m_dup mbuf how
|
2003-06-15 14:14:11 +00:00
|
|
|
Copy a packet header
|
|
|
|
.Vt mbuf chain
|
|
|
|
into a completely new
|
|
|
|
.Vt mbuf chain ,
|
|
|
|
including copying any
|
|
|
|
.Vt mbuf clusters .
|
2000-11-10 10:08:34 +00:00
|
|
|
Use this instead of
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fn m_copypacket
|
2003-06-15 14:14:11 +00:00
|
|
|
when you need a writable copy of an
|
|
|
|
.Vt mbuf chain .
|
2000-10-26 23:15:47 +00:00
|
|
|
.\"
|
|
|
|
.It Fn m_copydata mbuf offset len buf
|
2003-06-15 14:14:11 +00:00
|
|
|
Copy data from an
|
|
|
|
.Vt 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
|
2003-06-15 14:14:11 +00:00
|
|
|
back into the indicated
|
|
|
|
.Vt mbuf chain ,
|
2000-10-26 23:15:47 +00:00
|
|
|
starting at
|
|
|
|
.Fa offset
|
2003-06-15 14:14:11 +00:00
|
|
|
bytes from the beginning of the
|
|
|
|
.Vt mbuf chain ,
|
|
|
|
extending the
|
|
|
|
.Vt mbuf chain
|
|
|
|
if necessary.
|
2000-10-26 23:15:47 +00:00
|
|
|
.Sy Note :
|
2005-02-13 22:25:33 +00:00
|
|
|
It does not allocate any
|
2003-06-15 14:14:11 +00:00
|
|
|
.Vt mbuf clusters ,
|
|
|
|
just adds
|
|
|
|
.Vt mbufs
|
|
|
|
to the
|
|
|
|
.Vt mbuf chain .
|
2005-02-13 23:45:54 +00:00
|
|
|
It is safe to set
|
2000-10-26 23:15:47 +00:00
|
|
|
.Fa offset
|
2003-06-15 14:14:11 +00:00
|
|
|
beyond the current
|
|
|
|
.Vt mbuf chain
|
|
|
|
end: zeroed
|
|
|
|
.Vt mbufs
|
|
|
|
will be allocated to fill the space.
|
2000-10-26 23:15:47 +00:00
|
|
|
.\"
|
2003-06-15 14:47:12 +00:00
|
|
|
.It Fn m_length mbuf last
|
2003-06-15 14:14:11 +00:00
|
|
|
Return the length of the
|
|
|
|
.Vt mbuf chain ,
|
|
|
|
and optionally a pointer to the last
|
|
|
|
.Vt mbuf .
|
2002-09-18 20:04:30 +00:00
|
|
|
.\"
|
2003-06-15 14:40:03 +00:00
|
|
|
.It Fn m_dup_pkthdr to from how
|
|
|
|
Upon the function's completion, the
|
|
|
|
.Vt mbuf
|
|
|
|
.Fa to
|
|
|
|
will contain an identical copy of
|
|
|
|
.Fa from->m_pkthdr
|
|
|
|
and the per-packet attributes found in the
|
|
|
|
.Vt mbuf chain
|
|
|
|
.Fa from .
|
|
|
|
The
|
|
|
|
.Vt mbuf
|
|
|
|
.Fa from
|
|
|
|
must have the flag
|
|
|
|
.Dv M_PKTHDR
|
|
|
|
initially set, and
|
|
|
|
.Fa to
|
|
|
|
must be empty on entry.
|
|
|
|
.\"
|
|
|
|
.It Fn m_move_pkthdr to from
|
|
|
|
Move
|
|
|
|
.Va m_pkthdr
|
|
|
|
and the per-packet attributes from the
|
|
|
|
.Vt mbuf chain
|
|
|
|
.Fa from
|
|
|
|
to the
|
|
|
|
.Vt mbuf
|
|
|
|
.Fa to .
|
|
|
|
The
|
|
|
|
.Vt mbuf
|
|
|
|
.Fa from
|
|
|
|
must have the flag
|
|
|
|
.Dv M_PKTHDR
|
|
|
|
initially set, and
|
|
|
|
.Fa to
|
|
|
|
must be empty on entry.
|
|
|
|
Upon the function's completion,
|
|
|
|
.Fa from
|
|
|
|
will have the flag
|
|
|
|
.Dv M_PKTHDR
|
|
|
|
and the per-packet attributes cleared.
|
|
|
|
.\"
|
2003-06-15 14:47:12 +00:00
|
|
|
.It Fn m_fixhdr mbuf
|
2003-06-15 14:14:11 +00:00
|
|
|
Set the packet-header length to the length of the
|
|
|
|
.Vt mbuf chain .
|
2002-09-18 20:04:30 +00:00
|
|
|
.\"
|
2000-10-26 23:15:47 +00:00
|
|
|
.It Fn m_devget buf len offset ifp copy
|
|
|
|
Copy data from a device local memory pointed to by
|
|
|
|
.Fa buf
|
2003-06-15 14:14:11 +00:00
|
|
|
to an
|
|
|
|
.Vt 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 .
|
2003-06-15 14:14:11 +00:00
|
|
|
Both
|
|
|
|
.Vt mbuf chains
|
|
|
|
must be of the same type.
|
2016-03-02 04:58:51 +00:00
|
|
|
.Fa n
|
|
|
|
is not guaranteed to be valid after
|
|
|
|
.Fn m_cat
|
|
|
|
returns.
|
|
|
|
.Fn m_cat
|
|
|
|
does not update any packet header fields or free mbuf tags.
|
|
|
|
.\"
|
|
|
|
.It Fn m_catpkt m n
|
|
|
|
A variant of
|
|
|
|
.Fn m_cat
|
|
|
|
that operates on packets.
|
|
|
|
Both
|
|
|
|
.Fa m
|
|
|
|
and
|
|
|
|
.Fa n
|
|
|
|
must contain packet headers.
|
|
|
|
.Fa n
|
|
|
|
is not guaranteed to be valid after
|
|
|
|
.Fn m_catpkt
|
|
|
|
returns.
|
2000-10-26 23:15:47 +00:00
|
|
|
.\"
|
|
|
|
.It Fn m_split mbuf len how
|
2003-06-15 14:14:11 +00:00
|
|
|
Partition an
|
|
|
|
.Vt mbuf chain
|
|
|
|
in two pieces, returning the tail:
|
2000-10-26 23:15:47 +00:00
|
|
|
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
|
2003-06-15 14:14:11 +00:00
|
|
|
and attempts to restore the
|
|
|
|
.Vt mbuf chain
|
|
|
|
to its original state.
|
2004-02-11 02:39:24 +00:00
|
|
|
.\"
|
|
|
|
.It Fn m_apply mbuf off len f arg
|
|
|
|
Apply a function to an
|
|
|
|
.Vt mbuf chain ,
|
|
|
|
at offset
|
|
|
|
.Fa off ,
|
|
|
|
for length
|
2004-04-01 07:54:27 +00:00
|
|
|
.Fa len
|
|
|
|
bytes.
|
2004-02-11 02:39:24 +00:00
|
|
|
Typically used to avoid calls to
|
|
|
|
.Fn m_pullup
|
|
|
|
which would otherwise be unnecessary or undesirable.
|
|
|
|
.Fa arg
|
|
|
|
is a convenience argument which is passed to the callback function
|
|
|
|
.Fa f .
|
|
|
|
.Pp
|
|
|
|
Each time
|
|
|
|
.Fn f
|
|
|
|
is called, it will be passed
|
|
|
|
.Fa arg ,
|
|
|
|
a pointer to the
|
|
|
|
.Fa data
|
|
|
|
in the current mbuf, and the length
|
|
|
|
.Fa len
|
|
|
|
of the data in this mbuf to which the function should be applied.
|
|
|
|
.Pp
|
|
|
|
The function should return zero to indicate success;
|
|
|
|
otherwise, if an error is indicated, then
|
|
|
|
.Fn m_apply
|
|
|
|
will return the error and stop iterating through the
|
|
|
|
.Vt mbuf chain .
|
|
|
|
.\"
|
|
|
|
.It Fn m_getptr mbuf loc off
|
|
|
|
Return a pointer to the mbuf containing the data located at
|
|
|
|
.Fa loc
|
|
|
|
bytes from the beginning of the
|
|
|
|
.Vt mbuf chain .
|
|
|
|
The corresponding offset into the mbuf will be stored in
|
|
|
|
.Fa *off .
|
2004-04-01 06:50:21 +00:00
|
|
|
.It Fn m_defrag m0 how
|
2004-04-01 07:54:27 +00:00
|
|
|
Defragment an mbuf chain, returning the shortest possible
|
2004-04-01 07:36:56 +00:00
|
|
|
chain of mbufs and clusters.
|
|
|
|
If allocation fails and this can not be completed,
|
|
|
|
.Dv NULL
|
|
|
|
will be returned and the original chain will be unchanged.
|
|
|
|
Upon success, the original chain will be freed and the new
|
|
|
|
chain will be returned.
|
2004-04-01 06:50:21 +00:00
|
|
|
.Fa how
|
|
|
|
should be either
|
2011-04-18 15:30:25 +00:00
|
|
|
.Dv M_WAITOK
|
2004-04-01 06:50:21 +00:00
|
|
|
or
|
2011-04-18 15:30:25 +00:00
|
|
|
.Dv M_NOWAIT ,
|
2004-04-01 06:50:21 +00:00
|
|
|
depending on the caller's preference.
|
|
|
|
.Pp
|
|
|
|
This function is especially useful in network drivers, where
|
|
|
|
certain long mbuf chains must be shortened before being added
|
|
|
|
to TX descriptor lists.
|
2015-03-12 01:05:54 +00:00
|
|
|
.It Fn m_collapse m0 how maxfrags
|
|
|
|
Defragment an mbuf chain, returning a chain of at most
|
|
|
|
.Fa maxfrags
|
|
|
|
mbufs and clusters.
|
|
|
|
If allocation fails or the chain cannot be collapsed as requested,
|
|
|
|
.Dv NULL
|
|
|
|
will be returned, with the original chain possibly modified.
|
|
|
|
As with
|
|
|
|
.Fn m_defrag ,
|
|
|
|
.Fa how
|
|
|
|
should be one of
|
|
|
|
.Dv M_WAITOK
|
|
|
|
or
|
|
|
|
.Dv M_NOWAIT .
|
2006-03-15 21:11:11 +00:00
|
|
|
.It Fn m_unshare m0 how
|
|
|
|
Create a version of the specified mbuf chain whose
|
|
|
|
contents can be safely modified without affecting other users.
|
|
|
|
If allocation fails and this operation can not be completed,
|
|
|
|
.Dv NULL
|
|
|
|
will be returned.
|
|
|
|
The original mbuf chain is always reclaimed and the reference
|
|
|
|
count of any shared mbuf clusters is decremented.
|
|
|
|
.Fa how
|
|
|
|
should be either
|
2011-04-18 15:30:25 +00:00
|
|
|
.Dv M_WAITOK
|
2006-03-15 21:11:11 +00:00
|
|
|
or
|
2011-04-18 15:30:25 +00:00
|
|
|
.Dv M_NOWAIT ,
|
2006-03-15 21:11:11 +00:00
|
|
|
depending on the caller's preference.
|
|
|
|
As a side-effect of this process the returned
|
|
|
|
mbuf chain may be compacted.
|
|
|
|
.Pp
|
|
|
|
This function is especially useful in the transmit path of
|
|
|
|
network code, when data must be encrypted or otherwise
|
|
|
|
altered prior to transmission.
|
2000-12-29 09:18:45 +00:00
|
|
|
.El
|
2004-01-21 12:45:37 +00:00
|
|
|
.Sh HARDWARE-ASSISTED CHECKSUM CALCULATION
|
|
|
|
This section currently applies to TCP/IP only.
|
|
|
|
In order to save the host CPU resources, computing checksums is
|
|
|
|
offloaded to the network interface hardware if possible.
|
|
|
|
The
|
|
|
|
.Va m_pkthdr
|
|
|
|
member of the leading
|
|
|
|
.Vt mbuf
|
|
|
|
of a packet contains two fields used for that purpose,
|
|
|
|
.Vt int Va csum_flags
|
|
|
|
and
|
|
|
|
.Vt int Va csum_data .
|
|
|
|
The meaning of those fields depends on the direction a packet flows in,
|
|
|
|
and on whether the packet is fragmented.
|
|
|
|
Henceforth,
|
|
|
|
.Va csum_flags
|
|
|
|
or
|
|
|
|
.Va csum_data
|
|
|
|
of a packet
|
|
|
|
will denote the corresponding field of the
|
|
|
|
.Va m_pkthdr
|
|
|
|
member of the leading
|
|
|
|
.Vt mbuf
|
|
|
|
in the
|
|
|
|
.Vt mbuf chain
|
|
|
|
containing the packet.
|
|
|
|
.Pp
|
|
|
|
On output, checksum offloading is attempted after the outgoing
|
|
|
|
interface has been determined for a packet.
|
|
|
|
The interface-specific field
|
|
|
|
.Va ifnet.if_data.ifi_hwassist
|
|
|
|
(see
|
|
|
|
.Xr ifnet 9 )
|
|
|
|
is consulted for the capabilities of the interface to assist in
|
|
|
|
computing checksums.
|
|
|
|
The
|
|
|
|
.Va csum_flags
|
2004-04-01 07:54:27 +00:00
|
|
|
field of the packet header is set to indicate which actions the interface
|
2004-01-21 12:45:37 +00:00
|
|
|
is supposed to perform on it.
|
|
|
|
The actions unsupported by the network interface are done in the
|
|
|
|
software prior to passing the packet down to the interface driver;
|
|
|
|
such actions will never be requested through
|
|
|
|
.Va csum_flags .
|
|
|
|
.Pp
|
|
|
|
The flags demanding a particular action from an interface are as follows:
|
|
|
|
.Bl -tag -width ".Dv CSUM_TCP" -offset indent
|
|
|
|
.It Dv CSUM_IP
|
|
|
|
The IP header checksum is to be computed and stored in the
|
|
|
|
corresponding field of the packet.
|
|
|
|
The hardware is expected to know the format of an IP header
|
|
|
|
to determine the offset of the IP checksum field.
|
|
|
|
.It Dv CSUM_TCP
|
2004-04-01 07:54:27 +00:00
|
|
|
The TCP checksum is to be computed.
|
|
|
|
(See below.)
|
2004-01-21 12:45:37 +00:00
|
|
|
.It Dv CSUM_UDP
|
2004-04-01 07:54:27 +00:00
|
|
|
The UDP checksum is to be computed.
|
|
|
|
(See below.)
|
2004-01-21 12:45:37 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
2004-01-21 13:17:24 +00:00
|
|
|
Should a TCP or UDP checksum be offloaded to the hardware,
|
2004-01-21 12:45:37 +00:00
|
|
|
the field
|
|
|
|
.Va csum_data
|
|
|
|
will contain the byte offset of the checksum field relative to the
|
|
|
|
end of the IP header.
|
|
|
|
In this case, the checksum field will be initially
|
|
|
|
set by the TCP/IP module to the checksum of the pseudo header
|
2004-01-21 13:17:24 +00:00
|
|
|
defined by the TCP and UDP specifications.
|
2004-01-21 12:45:37 +00:00
|
|
|
.Pp
|
|
|
|
On input, an interface indicates the actions it has performed
|
|
|
|
on a packet by setting one or more of the following flags in
|
|
|
|
.Va csum_flags
|
|
|
|
associated with the packet:
|
|
|
|
.Bl -tag -width ".Dv CSUM_IP_CHECKED" -offset indent
|
|
|
|
.It Dv CSUM_IP_CHECKED
|
|
|
|
The IP header checksum has been computed.
|
|
|
|
.It Dv CSUM_IP_VALID
|
|
|
|
The IP header has a valid checksum.
|
|
|
|
This flag can appear only in combination with
|
|
|
|
.Dv CSUM_IP_CHECKED .
|
|
|
|
.It Dv CSUM_DATA_VALID
|
|
|
|
The checksum of the data portion of the IP packet has been computed
|
|
|
|
and stored in the field
|
|
|
|
.Va csum_data
|
|
|
|
in network byte order.
|
|
|
|
.It Dv CSUM_PSEUDO_HDR
|
|
|
|
Can be set only along with
|
|
|
|
.Dv CSUM_DATA_VALID
|
|
|
|
to indicate that the IP data checksum found in
|
|
|
|
.Va csum_data
|
2004-01-21 13:17:24 +00:00
|
|
|
allows for the pseudo header defined by the TCP and UDP specifications.
|
2004-01-21 12:45:37 +00:00
|
|
|
Otherwise the checksum of the pseudo header must be calculated by
|
|
|
|
the host CPU and added to
|
|
|
|
.Va csum_data
|
2004-01-21 13:17:24 +00:00
|
|
|
to obtain the final checksum to be used for TCP or UDP validation purposes.
|
2004-01-21 12:45:37 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
If a particular network interface just indicates success or
|
|
|
|
failure of TCP or UDP checksum validation without returning
|
|
|
|
the exact value of the checksum to the host CPU, its driver can mark
|
|
|
|
.Dv CSUM_DATA_VALID
|
|
|
|
and
|
|
|
|
.Dv CSUM_PSEUDO_HDR
|
|
|
|
in
|
|
|
|
.Va csum_flags ,
|
|
|
|
and set
|
|
|
|
.Va csum_data
|
|
|
|
to
|
|
|
|
.Li 0xFFFF
|
|
|
|
hexadecimal to indicate a valid checksum.
|
2004-04-01 07:54:27 +00:00
|
|
|
It is a peculiarity of the algorithm used that the Internet checksum
|
2004-01-21 12:45:37 +00:00
|
|
|
calculated over any valid packet will be
|
|
|
|
.Li 0xFFFF
|
|
|
|
as long as the original checksum field is included.
|
2003-04-13 23:31:06 +00:00
|
|
|
.Sh STRESS TESTING
|
2003-05-21 15:49:01 +00:00
|
|
|
When running a kernel compiled with the option
|
|
|
|
.Dv MBUF_STRESS_TEST ,
|
|
|
|
the following
|
|
|
|
.Xr sysctl 8 Ns
|
|
|
|
-controlled options may be used to create
|
|
|
|
various failure/extreme cases for testing of network drivers
|
2003-06-15 14:14:11 +00:00
|
|
|
and other parts of the kernel that rely on
|
|
|
|
.Vt mbufs .
|
2003-05-21 15:49:01 +00:00
|
|
|
.Bl -tag -width ident
|
|
|
|
.It Va net.inet.ip.mbuf_frag_size
|
|
|
|
Causes
|
|
|
|
.Fn ip_output
|
2003-06-15 14:14:11 +00:00
|
|
|
to fragment outgoing
|
|
|
|
.Vt mbuf chains
|
|
|
|
into fragments of the specified size.
|
2003-05-21 15:49:01 +00:00
|
|
|
Setting this variable to 1 is an excellent way to
|
2003-06-15 14:14:11 +00:00
|
|
|
test the long
|
|
|
|
.Vt mbuf chain
|
|
|
|
handling ability of network drivers.
|
2003-05-21 15:49:01 +00:00
|
|
|
.It Va kern.ipc.m_defragrandomfailures
|
|
|
|
Causes the function
|
|
|
|
.Fn m_defrag
|
|
|
|
to randomly fail, returning
|
|
|
|
.Dv NULL .
|
|
|
|
Any piece of code which uses
|
|
|
|
.Fn m_defrag
|
|
|
|
should be tested with this feature.
|
|
|
|
.El
|
2000-10-26 23:15:47 +00:00
|
|
|
.Sh RETURN VALUES
|
|
|
|
See above.
|
2004-01-21 12:45:37 +00:00
|
|
|
.Sh SEE ALSO
|
2004-05-20 09:34:19 +00:00
|
|
|
.Xr ifnet 9 ,
|
|
|
|
.Xr mbuf_tags 9
|
2021-04-08 18:57:14 +00:00
|
|
|
.Rs
|
|
|
|
.\" 4.4BSD SMM:18
|
|
|
|
.%A S. J. Leffler
|
|
|
|
.%A W. N. Joy
|
|
|
|
.%A R. S. Fabry
|
|
|
|
.%A M. J. Karels
|
|
|
|
.%T Networking Implementation Notes
|
|
|
|
.%B 4.4BSD System Manager's Manual (SMM)
|
|
|
|
.Re
|
2000-10-26 23:15:47 +00:00
|
|
|
.Sh HISTORY
|
|
|
|
.\" Please correct me if I'm wrong
|
2003-06-15 14:14:11 +00:00
|
|
|
.Vt Mbufs
|
|
|
|
appeared in an early version of
|
2001-08-14 10:01:54 +00:00
|
|
|
.Bx .
|
2003-11-15 14:23:48 +00:00
|
|
|
Besides 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.
|
2007-02-15 14:44:46 +00:00
|
|
|
In more recent
|
|
|
|
.Fx
|
|
|
|
use of
|
|
|
|
.Vt mbufs
|
|
|
|
is almost entirely limited to packet storage, with
|
|
|
|
.Xr uma 9
|
|
|
|
zones being used directly to store other network-related memory.
|
|
|
|
.Pp
|
|
|
|
Historically, the
|
|
|
|
.Vt mbuf
|
|
|
|
allocator has been a special-purpose memory allocator able to run in
|
|
|
|
interrupt contexts and allocating from a special kernel address space map.
|
|
|
|
As of
|
|
|
|
.Fx 5.3 ,
|
|
|
|
the
|
|
|
|
.Vt mbuf
|
|
|
|
allocator is a wrapper around
|
|
|
|
.Xr uma 9 ,
|
|
|
|
allowing caching of
|
|
|
|
.Vt mbufs ,
|
|
|
|
clusters, and
|
|
|
|
.Vt mbuf
|
|
|
|
+ cluster pairs in per-CPU caches, as well as bringing other benefits of
|
|
|
|
slab allocation.
|
2000-10-26 23:15:47 +00:00
|
|
|
.Sh AUTHORS
|
2001-08-08 11:48:28 +00:00
|
|
|
The original
|
|
|
|
.Nm
|
2014-12-21 10:57:42 +00:00
|
|
|
manual page was written by
|
|
|
|
.An Yar Tikhiy .
|
2007-02-15 14:44:46 +00:00
|
|
|
The
|
|
|
|
.Xr uma 9
|
|
|
|
.Vt mbuf
|
2014-12-21 10:57:42 +00:00
|
|
|
allocator was written by
|
|
|
|
.An Bosko Milekic .
|