1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
.\" $OpenBSD: ml_init.9,v 1.9 2015/11/21 00:32:46 dlg Exp $
.\"
.\" Copyright (c) 2015 David Gwynne <dlg@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: November 21 2015 $
.Dt ML_INIT 9
.Os
.Sh NAME
.Nm ml_init ,
.Nm ml_enqueue ,
.Nm ml_dequeue ,
.Nm ml_requeue ,
.Nm ml_enlist ,
.Nm ml_dechain ,
.Nm ml_len ,
.Nm ml_empty ,
.Nm MBUF_LIST_INITIALIZER ,
.Nm MBUF_LIST_FIRST ,
.Nm MBUF_LIST_NEXT ,
.Nm MBUF_LIST_FOREACH
.Nd mbuf list API
.Sh SYNOPSIS
.In sys/mbuf.h
.Ft void
.Fn ml_init "struct mbuf_list *ml"
.Ft void
.Fn ml_enqueue "struct mbuf_list *ml" "struct mbuf *m"
.Ft struct mbuf *
.Fn ml_dequeue "struct mbuf_list *ml"
.Ft void
.Fn ml_requeue "struct mbuf_list *ml" "struct mbuf *m"
.Ft void
.Fn ml_enlist "struct mbuf_list *ml" "struct mbuf_list *src"
.Ft struct mbuf *
.Fn ml_dechain "struct mbuf_list *ml"
.Ft struct mbuf *
.Fo ml_filter
.Fa "struct mbuf_list *ml"
.Fa "int (*filter)(void *, struct mbuf *)"
.Fa "void *context"
.Fc
.Ft unsigned int
.Fn ml_len "struct mbuf_list *ml"
.Ft int
.Fn ml_empty "struct mbuf_list *ml"
.Ft unsigned int
.Fn ml_purge "struct mbuf_list *ml"
.Ft struct mbuf_list
.Fn MBUF_LIST_INITIALIZER
.Ft struct mbuf *
.Fn MBUF_LIST_FIRST "struct mbuf_list *ml"
.Ft struct mbuf *
.Fn MBUF_LIST_NEXT "struct mbuf *m"
.Fn MBUF_LIST_FOREACH "struct mbuf_list *ml" "VARNAME"
.Sh DESCRIPTION
The mbuf list API provides implementations of data structures and operations
for managing lists of mbufs between contexts.
.Pp
mbuf_list structures support the following functionality:
.Pp
.Bl -enum -compact -offset indent
.It
Insertion of a new mbuf at the end of the list.
.It
Removal of an mbuf from the head of the list.
.It
Reinsertion of an mbuf at the head of the list.
.It
Removal of the entire chain of mbufs on the list.
.El
.Bl -tag -width Ds
.It Fn ml_init "struct mbuf_list *ml"
Initialise the
.Fa ml
mbuf_list structure.
.It Fn MBUF_LIST_INITIALIZER
An initialiser for an mbuf_list structure declaration.
.It Fn ml_enqueue "struct mbuf_list *ml" "struct mbuf *m"
Enqueue mbuf
.Fa m
on the end of the
.Fa ml
mbuf list.
.It Fn ml_dequeue "struct mbuf_list *ml"
Dequeue an mbuf from the front of the
.Fa ml
mbuf list.
.It Fn ml_requeue "struct mbuf_list *ml" "struct mbuf *m"
Enqueue mbuf
.Fa m
at the head of the
.Fa ml
mbuf list.
.It Fn ml_enlist "struct mbuf_list *ml" "struct mbuf_list *src"
Enqueue all the mbufs on the
.Fa src
mbuf list on to the end of the
.Fa ml
mbuf list.
.It Fn ml_dechain "struct mbuf_list *ml"
Dequeues all mbufs from the
.Fa ml
mbuf list.
.It Fo ml_filter
.Fa "struct mbuf_list *ml"
.Fa "int (*filter)(void *, struct mbuf *)"
.Fa "void *context"
.Fc
Iterates over the mbufs on the
.Fa ml
mbuf list, passing each of them to the
.Fa filter
function.
If the
.Fa filter
returns non-zero, the packet is removed from the
.Fa ml
mbuf list to be returned as part of an mbuf chain by
.Fn ml_filter .
.Fa context
is passed as the first argument to each call of
.Fa filter .
.It Fn ml_len "struct mbuf_list *ml"
Return the number of mbufs on the
.Fa ml
mbuf list.
.It Fn ml_empty "struct mbuf_list *ml"
Return if the
.Fa ml
mbuf list is empty.
.It Fn ml_purge "struct mbuf_list *ml"
Free all the mbufs on the
.Fa ml
mbuf list.
.It Fn MBUF_LIST_FIRST "struct mbuf_list *ml"
Access the first mbuf in the
.Fa ml
mbuf list for traversal.
.It Fn MBUF_LIST_NEXT "struct mbuf *m"
Access the next mbuf in the mbuf list after
.Fa m .
.It Fn MBUF_LIST_FOREACH "struct mbuf_list *ml" "VARNAME"
A convenience macro that can be used to iterate over the contents of the
.Fa ml
mbuf list.
.Fa VARNAME
identifies the name (not the address) of an mbuf pointer that will
be set to each entry on the list.
Note that it is unsafe to modify the list while iterating over it.
.El
.Sh CONTEXT
.Fn ml_init ,
.Fn ml_enqueue ,
.Fn ml_dequeue ,
.Fn ml_requeue ,
.Fn ml_enlist ,
.Fn ml_dechain ,
.Fn ml_len ,
.Fn ml_empty ,
.Fn ml_purge ,
.Fn MBUF_LIST_INITIALIZER ,
.Fn MBUF_LIST_FIRST ,
.Fn MBUF_LIST_NEXT ,
and
.Fn MBUF_LIST_FOREACH
can be called during autoconf, from process context, or from interrupt context.
.Sh RETURN VALUES
.Fn ml_dequeue
returns the mbuf that was at the head of its list.
If the list was empty,
.Dv NULL
is returned.
.Pp
.Fn ml_dechain
returns all the mbufs that were on the list via
a pointer to an mbuf with the chain accessible via m_nextpkt members.
If the list was empty,
.Dv NULL
is returned.
.Pp
.Fn ml_filter
returns the mbufs that were successfully matched by the filter
function on the list via a pointer to a chain of mbufs.
If no packets matched the filter,
.Dv NULL
is returned.
.Pp
.Fn ml_len
returns the number of mbufs on the list.
.Pp
.Fn ml_empty
return a non-zero value if the list is empty, otherwise 0.
.Pp
.Fn ml_purge
returns the number of mbufs that were freed.
.Pp
.Fn MBUF_LIST_FIRST
returns the first mbuf in the mbuf list, or
.Dv NULL
if the list is empty.
.Pp
.Fn MBUF_LIST_NEXT
returns the next mbuf in the mbuf list, or
.Dv NULL
if the end of the list has been reached.
.Sh SEE ALSO
.Xr mbuf 9
|