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
|
<table class="head">
<tr>
<td class="head-ltitle">DRBR(9)</td>
<td class="head-vol">Kernel Developer's Manual</td>
<td class="head-rtitle">DRBR(9)</td>
</tr>
</table>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp"><code class="Nm">drbr</code>, <code class="Nm">drbr_free</code>,
<code class="Nm">drbr_enqueue</code>, <code class="Nm">drbr_dequeue</code>,
<code class="Nm">drbr_dequeue_cond</code>,
<code class="Nm">drbr_flush</code>, <code class="Nm">drbr_empty</code>,
<code class="Nm">drbr_inuse</code> — <span class="Nd">network driver
interface to buf_ring</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
<p class="Pp"><code class="In">#include
<<a class="In">sys/param.h</a>></code>
<br/>
<code class="In">#include <<a class="In">net/if.h</a>></code>
<br/>
<code class="In">#include <<a class="In">net/if_var.h</a>></code></p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">drbr_free</code>(<var class="Fa" style="white-space: nowrap;">struct
buf_ring *br</var>, <var class="Fa" style="white-space: nowrap;">struct
malloc_type *type</var>);</p>
<p class="Pp"><var class="Ft">int</var>
<br/>
<code class="Fn">drbr_enqueue</code>(<var class="Fa" style="white-space: nowrap;">struct
ifnet *ifp</var>, <var class="Fa" style="white-space: nowrap;">struct
buf_ring *br</var>, <var class="Fa" style="white-space: nowrap;">struct mbuf
*m</var>);</p>
<p class="Pp"><var class="Ft">struct mbuf *</var>
<br/>
<code class="Fn">drbr_dequeue</code>(<var class="Fa" style="white-space: nowrap;">struct
ifnet *ifp</var>, <var class="Fa" style="white-space: nowrap;">struct
buf_ring *br</var>);</p>
<p class="Pp"><var class="Ft">struct mbuf *</var>
<br/>
<code class="Fn">drbr_dequeue_cond</code>(<var class="Fa" style="white-space: nowrap;">struct
ifnet *ifp</var>, <var class="Fa" style="white-space: nowrap;">struct
buf_ring *br</var>, <var class="Fa" style="white-space: nowrap;">int (*func)
(struct mbuf *, void *)</var>,
<var class="Fa" style="white-space: nowrap;">void *arg</var>);</p>
<p class="Pp"><var class="Ft">void</var>
<br/>
<code class="Fn">drbr_flush</code>(<var class="Fa" style="white-space: nowrap;">struct
ifnet *ifp</var>, <var class="Fa" style="white-space: nowrap;">struct
buf_ring *br</var>);</p>
<p class="Pp"><var class="Ft">int</var>
<br/>
<code class="Fn">drbr_empty</code>(<var class="Fa" style="white-space: nowrap;">struct
ifnet *ifp</var>, <var class="Fa" style="white-space: nowrap;">struct
buf_ring *br</var>);</p>
<p class="Pp"><var class="Ft">int</var>
<br/>
<code class="Fn">drbr_inuse</code>(<var class="Fa" style="white-space: nowrap;">struct
ifnet *ifp</var>, <var class="Fa" style="white-space: nowrap;">struct
buf_ring *br</var>);</p>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
<p class="Pp">The <code class="Nm">drbr</code> functions provide an API to
network drivers for using <a class="Xr">buf_ring(9)</a> for enqueueing and
dequeueing packets. This is meant as a replacement for the IFQ interface for
packet queuing. It allows a packet to be enqueued with a single atomic and
packet dequeue to be done without any per-packet atomics as it is protected
by the driver's tx queue lock. If <code class="Dv">INVARIANTS</code> is
enabled,
<a class="permalink" href="#drbr_dequeue"><code class="Fn" id="drbr_dequeue">drbr_dequeue</code></a>()
will assert that the tx queue lock is held when it is called.</p>
<p class="Pp" id="drbr_free">The
<a class="permalink" href="#drbr_free"><code class="Fn">drbr_free</code></a>()
function frees all the enqueued mbufs and then frees the buf_ring.</p>
<p class="Pp" id="drbr_enqueue">The
<a class="permalink" href="#drbr_enqueue"><code class="Fn">drbr_enqueue</code></a>()
function is used to enqueue an mbuf to a buf_ring, falling back to the
ifnet's IFQ if <a class="Xr">ALTQ(4)</a> is enabled.</p>
<p class="Pp" id="drbr_dequeue~2">The
<a class="permalink" href="#drbr_dequeue~2"><code class="Fn">drbr_dequeue</code></a>()
function is used to dequeue an mbuf from a buf_ring or, if
<a class="Xr">ALTQ(4)</a> is enabled, from the ifnet's IFQ.</p>
<p class="Pp" id="drbr_dequeue_cond">The
<a class="permalink" href="#drbr_dequeue_cond"><code class="Fn">drbr_dequeue_cond</code></a>()
function is used to conditionally dequeue an mbuf from a buf_ring based on
whether <var class="Fa">func</var> returns <code class="Dv">TRUE</code> or
<code class="Dv">FALSE</code>.</p>
<p class="Pp" id="drbr_flush">The
<a class="permalink" href="#drbr_flush"><code class="Fn">drbr_flush</code></a>()
function frees all mbufs enqueued in the buf_ring and the ifnet's IFQ.</p>
<p class="Pp" id="drbr_empty">The
<a class="permalink" href="#drbr_empty"><code class="Fn">drbr_empty</code></a>()
function returns <code class="Dv">TRUE</code> if there are no mbufs
enqueued, <code class="Dv">FALSE</code> otherwise.</p>
<p class="Pp" id="drbr_inuse">The
<a class="permalink" href="#drbr_inuse"><code class="Fn">drbr_inuse</code></a>()
function returns the number of mbufs enqueued. Note to users that this is
intrinsically racy as there is no guarantee that there will not be more
mbufs when <code class="Fn">drbr_dequeue</code>() is actually called.
Provided the tx queue lock is held there will not be less.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="RETURN_VALUES"><a class="permalink" href="#RETURN_VALUES">RETURN
VALUES</a></h1>
<p class="Pp">The <code class="Fn">drbr_enqueue</code>() function returns
<code class="Er">ENOBUFS</code> if there are no slots available in the
buf_ring and <code class="Dv">0</code> on success.</p>
<p class="Pp">The <code class="Fn">drbr_dequeue</code>() and
<code class="Fn">drbr_dequeue_cond</code>() functions return an mbuf on
success and <code class="Dv">NULL</code> if the buf_ring is empty.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
<p class="Pp">These functions were introduced in <span class="Ux">FreeBSD
8.0</span>.</p>
</section>
</div>
<table class="foot">
<tr>
<td class="foot-date">September 27, 2012</td>
<td class="foot-os">FreeBSD 15.0</td>
</tr>
</table>
|