xref: /openbsd-src/share/man/man9/ml_init.9 (revision eb6d7a504237aff733382ec23d2953a1a5b9c61e)
1*eb6d7a50Sjmc.\"     $OpenBSD: ml_init.9,v 1.15 2020/01/23 07:12:42 jmc Exp $
2162361b3Smpi.\"
3162361b3Smpi.\"  Copyright (c) 2015 David Gwynne <dlg@openbsd.org>
4162361b3Smpi.\"
5162361b3Smpi.\" Permission to use, copy, modify, and distribute this software for any
6162361b3Smpi.\" purpose with or without fee is hereby granted, provided that the above
7162361b3Smpi.\" copyright notice and this permission notice appear in all copies.
8162361b3Smpi.\"
9162361b3Smpi.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10162361b3Smpi.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11162361b3Smpi.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12162361b3Smpi.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13162361b3Smpi.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14162361b3Smpi.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15162361b3Smpi.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16162361b3Smpi.\"
17*eb6d7a50Sjmc.Dd $Mdocdate: January 23 2020 $
18162361b3Smpi.Dt ML_INIT 9
19162361b3Smpi.Os
20162361b3Smpi.Sh NAME
21162361b3Smpi.Nm ml_init ,
22162361b3Smpi.Nm ml_enqueue ,
23162361b3Smpi.Nm ml_dequeue ,
24e4e00e5dSdlg.Nm ml_enlist ,
25162361b3Smpi.Nm ml_dechain ,
26162361b3Smpi.Nm ml_len ,
27162361b3Smpi.Nm ml_empty ,
287b44842eSdlg.Nm ml_hdatalen ,
29851dfe97Sjmc.Nm ml_purge ,
30162361b3Smpi.Nm MBUF_LIST_INITIALIZER ,
319d8f0f2bSdlg.Nm MBUF_LIST_FIRST ,
329d8f0f2bSdlg.Nm MBUF_LIST_NEXT ,
33e02f8b36Sschwarze.Nm MBUF_LIST_FOREACH
34162361b3Smpi.Nd mbuf list API
35162361b3Smpi.Sh SYNOPSIS
36162361b3Smpi.In sys/mbuf.h
37db5275bdSdlg.Ft void
385dfee228Sschwarze.Fn ml_init "struct mbuf_list *ml"
39162361b3Smpi.Ft void
405dfee228Sschwarze.Fn ml_enqueue "struct mbuf_list *ml" "struct mbuf *m"
41162361b3Smpi.Ft struct mbuf *
425dfee228Sschwarze.Fn ml_dequeue "struct mbuf_list *ml"
4363676e14Sdlg.Ft void
44e4e00e5dSdlg.Fn ml_enlist "struct mbuf_list *ml" "struct mbuf_list *src"
45162361b3Smpi.Ft struct mbuf *
465dfee228Sschwarze.Fn ml_dechain "struct mbuf_list *ml"
47162361b3Smpi.Ft unsigned int
485dfee228Sschwarze.Fn ml_len "struct mbuf_list *ml"
49162361b3Smpi.Ft int
505dfee228Sschwarze.Fn ml_empty "struct mbuf_list *ml"
51164d10c5Sdlg.Ft unsigned int
527b44842eSdlg.Fn ml_hdatalen "struct mbuf_list *ml"
537b44842eSdlg.Ft unsigned int
54164d10c5Sdlg.Fn ml_purge "struct mbuf_list *ml"
55162361b3Smpi.Ft struct mbuf_list
565dfee228Sschwarze.Fn MBUF_LIST_INITIALIZER
579d8f0f2bSdlg.Ft struct mbuf *
589d8f0f2bSdlg.Fn MBUF_LIST_FIRST "struct mbuf_list *ml"
599d8f0f2bSdlg.Ft struct mbuf *
609d8f0f2bSdlg.Fn MBUF_LIST_NEXT "struct mbuf *m"
615dfee228Sschwarze.Fn MBUF_LIST_FOREACH "struct mbuf_list *ml" "VARNAME"
62162361b3Smpi.Sh DESCRIPTION
63dff908caSsobradoThe mbuf list API provides implementations of data structures and operations
64162361b3Smpifor managing lists of mbufs between contexts.
65162361b3Smpi.Pp
66162361b3Smpimbuf_list structures support the following functionality:
67162361b3Smpi.Pp
68162361b3Smpi.Bl -enum -compact -offset indent
69162361b3Smpi.It
70162361b3SmpiInsertion of a new mbuf at the end of the list.
71162361b3Smpi.It
72162361b3SmpiRemoval of an mbuf from the head of the list.
738962f3c0Sjmc.El
74162361b3Smpi.Bl -tag -width Ds
755dfee228Sschwarze.It Fn ml_init "struct mbuf_list *ml"
76162361b3SmpiInitialise the
77162361b3Smpi.Fa ml
78162361b3Smpimbuf_list structure.
795dfee228Sschwarze.It Fn MBUF_LIST_INITIALIZER
80162361b3SmpiAn initialiser for an mbuf_list structure declaration.
815dfee228Sschwarze.It Fn ml_enqueue "struct mbuf_list *ml" "struct mbuf *m"
82162361b3SmpiEnqueue mbuf
83162361b3Smpi.Fa m
84162361b3Smpion the end of the
85162361b3Smpi.Fa ml
86162361b3Smpimbuf list.
875dfee228Sschwarze.It Fn ml_dequeue "struct mbuf_list *ml"
88162361b3SmpiDequeue an mbuf from the front of the
89162361b3Smpi.Fa ml
90162361b3Smpimbuf list.
91e4e00e5dSdlg.It Fn ml_enlist "struct mbuf_list *ml" "struct mbuf_list *src"
92e4e00e5dSdlgEnqueue all the mbufs on the
93e4e00e5dSdlg.Fa src
94e4e00e5dSdlgmbuf list on to the end of the
95e4e00e5dSdlg.Fa ml
96e4e00e5dSdlgmbuf list.
975dfee228Sschwarze.It Fn ml_dechain "struct mbuf_list *ml"
98162361b3SmpiDequeues all mbufs from the
99162361b3Smpi.Fa ml
100162361b3Smpimbuf list.
1015dfee228Sschwarze.It Fn ml_len "struct mbuf_list *ml"
102162361b3SmpiReturn the number of mbufs on the
103162361b3Smpi.Fa ml
104162361b3Smpimbuf list.
1055dfee228Sschwarze.It Fn ml_empty "struct mbuf_list *ml"
106162361b3SmpiReturn if the
107162361b3Smpi.Fa ml
108162361b3Smpimbuf list is empty.
1097b44842eSdlg.It Fn ml_hdatalen "struct mbuf_list *ml"
1107b44842eSdlgReturn the number of bytes in the packet at the head of the
1117b44842eSdlg.Fa ml
1127b44842eSdlgmbuf list.
113164d10c5Sdlg.It Fn ml_purge "struct mbuf_list *ml"
114164d10c5SdlgFree all the mbufs on the
115164d10c5Sdlg.Fa ml
116164d10c5Sdlgmbuf list.
1179d8f0f2bSdlg.It Fn MBUF_LIST_FIRST "struct mbuf_list *ml"
1189d8f0f2bSdlgAccess the first mbuf in the
1199d8f0f2bSdlg.Fa ml
1209d8f0f2bSdlgmbuf list for traversal.
1219d8f0f2bSdlg.It Fn MBUF_LIST_NEXT "struct mbuf *m"
1229d8f0f2bSdlgAccess the next mbuf in the mbuf list after
1239d8f0f2bSdlg.Fa m .
1245dfee228Sschwarze.It Fn MBUF_LIST_FOREACH "struct mbuf_list *ml" "VARNAME"
125162361b3SmpiA convenience macro that can be used to iterate over the contents of the
126162361b3Smpi.Fa ml
127162361b3Smpimbuf list.
128162361b3Smpi.Fa VARNAME
129162361b3Smpiidentifies the name (not the address) of an mbuf pointer that will
130162361b3Smpibe set to each entry on the list.
131162361b3SmpiNote that it is unsafe to modify the list while iterating over it.
132162361b3Smpi.El
133162361b3Smpi.Sh CONTEXT
134162361b3Smpi.Fn ml_init ,
135162361b3Smpi.Fn ml_enqueue ,
136162361b3Smpi.Fn ml_dequeue ,
137e4e00e5dSdlg.Fn ml_enlist ,
138162361b3Smpi.Fn ml_dechain ,
139162361b3Smpi.Fn ml_len ,
140162361b3Smpi.Fn ml_empty ,
141164d10c5Sdlg.Fn ml_purge ,
142162361b3Smpi.Fn MBUF_LIST_INITIALIZER ,
1439d8f0f2bSdlg.Fn MBUF_LIST_FIRST ,
1449d8f0f2bSdlg.Fn MBUF_LIST_NEXT ,
145162361b3Smpiand
146162361b3Smpi.Fn MBUF_LIST_FOREACH
147162361b3Smpican be called during autoconf, from process context, or from interrupt context.
148162361b3Smpi.Sh RETURN VALUES
149162361b3Smpi.Fn ml_dequeue
150162361b3Smpireturns the mbuf that was at the head of its list.
151162361b3SmpiIf the list was empty,
152162361b3Smpi.Dv NULL
153162361b3Smpiis returned.
154162361b3Smpi.Pp
155162361b3Smpi.Fn ml_dechain
156162361b3Smpireturns all the mbufs that were on the list via
157162361b3Smpia pointer to an mbuf with the chain accessible via m_nextpkt members.
158162361b3SmpiIf the list was empty,
159162361b3Smpi.Dv NULL
160162361b3Smpiis returned.
161162361b3Smpi.Pp
162162361b3Smpi.Fn ml_len
163162361b3Smpireturns the number of mbufs on the list.
164162361b3Smpi.Pp
165162361b3Smpi.Fn ml_empty
166162361b3Smpireturn a non-zero value if the list is empty, otherwise 0.
167164d10c5Sdlg.Pp
1687b44842eSdlg.Fn ml_hdatalen
169*eb6d7a50Sjmcreturns the size of a packet on the list, or 0 if the list is empty.
1707b44842eSdlg.Pp
171164d10c5Sdlg.Fn ml_purge
172164d10c5Sdlgreturns the number of mbufs that were freed.
1739d8f0f2bSdlg.Pp
1749d8f0f2bSdlg.Fn MBUF_LIST_FIRST
1759d8f0f2bSdlgreturns the first mbuf in the mbuf list, or
1769d8f0f2bSdlg.Dv NULL
1779d8f0f2bSdlgif the list is empty.
1789d8f0f2bSdlg.Pp
1799d8f0f2bSdlg.Fn MBUF_LIST_NEXT
1809d8f0f2bSdlgreturns the next mbuf in the mbuf list, or
1819d8f0f2bSdlg.Dv NULL
1829d8f0f2bSdlgif the end of the list has been reached.
183162361b3Smpi.Sh SEE ALSO
184162361b3Smpi.Xr mbuf 9
185