File: nlsocket.html

package info (click to toggle)
pyroute2 0.5.14-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,220 kB
  • sloc: python: 31,916; javascript: 8,256; ansic: 81; makefile: 14
file content (439 lines) | stat: -rw-r--r-- 28,997 bytes parent folder | download
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>Base netlink socket and marshal &#8212; pyroute2 0.5.14 documentation</title>
    <link rel="stylesheet" href="_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <link rel="stylesheet" type="text/css" href="_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="_static/custom.css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <script type="text/javascript" src="_static/language_data.js"></script>
    
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="prev" title="Netlink" href="netlink.html" />
  </head><body>

    <div class="related" role="navigation" aria-label="related navigation">
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="netlink.html" title="Netlink"
             accesskey="P">previous</a> |</li>
        <li class="nav-item"><a href="http://pyroute2.org">Project home</a> &#187;</li>
        <li class="nav-item nav-item-0"><a href="index.html">pyroute2 0.5.14 documentation</a> &#187;</li> 
      </ul>
        </div>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <span class="target" id="module-pyroute2.netlink.nlsocket"></span><div class="section" id="base-netlink-socket-and-marshal">
<h1>Base netlink socket and marshal<a class="headerlink" href="#base-netlink-socket-and-marshal" title="Permalink to this headline">¶</a></h1>
<p>All the netlink providers are derived from the socket
class, so they provide normal socket API, including
<cite>getsockopt()</cite>, <cite>setsockopt()</cite>, they can be used in
poll/select I/O loops etc.</p>
<div class="section" id="asynchronous-i-o">
<h2>asynchronous I/O<a class="headerlink" href="#asynchronous-i-o" title="Permalink to this headline">¶</a></h2>
<p>To run async reader thread, one should call
<cite>NetlinkSocket.bind(async_cache=True)</cite>. In that case
a background thread will be launched. The thread will
automatically collect all the messages and store
into a userspace buffer.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>There is no need to turn on async I/O, if you
don’t plan to receive broadcast messages.</p>
</div>
</div>
<div class="section" id="enobuf-and-async-i-o">
<h2>ENOBUF and async I/O<a class="headerlink" href="#enobuf-and-async-i-o" title="Permalink to this headline">¶</a></h2>
<p>When Netlink messages arrive faster than a program
reads then from the socket, the messages overflow
the socket buffer and one gets ENOBUF on <cite>recv()</cite>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">...</span> <span class="bp">self</span><span class="o">.</span><span class="n">recv</span><span class="p">(</span><span class="n">bufsize</span><span class="p">)</span>
<span class="n">error</span><span class="p">:</span> <span class="p">[</span><span class="n">Errno</span> <span class="mi">105</span><span class="p">]</span> <span class="n">No</span> <span class="n">buffer</span> <span class="n">space</span> <span class="n">available</span>
</pre></div>
</div>
<p>One way to avoid ENOBUF, is to use async I/O. Then the
library not only reads and buffers all the messages, but
also re-prioritizes threads. Suppressing the parser
activity, the library increases the response delay, but
spares CPU to read and enqueue arriving messages as
fast, as it is possible.</p>
<p>With logging level DEBUG you can notice messages, that
the library started to calm down the parser thread:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">DEBUG</span><span class="p">:</span><span class="n">root</span><span class="p">:</span><span class="n">Packet</span> <span class="n">burst</span><span class="p">:</span> <span class="n">the</span> <span class="n">reader</span> <span class="n">thread</span> <span class="n">priority</span>
    <span class="ow">is</span> <span class="n">increased</span><span class="p">,</span> <span class="n">beware</span> <span class="n">of</span> <span class="n">delays</span> <span class="n">on</span> <span class="n">netlink</span> <span class="n">calls</span>
    <span class="n">Counters</span><span class="p">:</span> <span class="n">delta</span><span class="o">=</span><span class="mi">25</span> <span class="n">qsize</span><span class="o">=</span><span class="mi">25</span> <span class="n">delay</span><span class="o">=</span><span class="mf">0.1</span>
</pre></div>
</div>
<p>This state requires no immediate action, but just some
more attention. When the delay between messages on the
parser thread exceeds 1 second, DEBUG messages become
WARNING ones:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">WARNING</span><span class="p">:</span><span class="n">root</span><span class="p">:</span><span class="n">Packet</span> <span class="n">burst</span><span class="p">:</span> <span class="n">the</span> <span class="n">reader</span> <span class="n">thread</span> <span class="n">priority</span>
    <span class="ow">is</span> <span class="n">increased</span><span class="p">,</span> <span class="n">beware</span> <span class="n">of</span> <span class="n">delays</span> <span class="n">on</span> <span class="n">netlink</span> <span class="n">calls</span>
    <span class="n">Counters</span><span class="p">:</span> <span class="n">delta</span><span class="o">=</span><span class="mi">2525</span> <span class="n">qsize</span><span class="o">=</span><span class="mi">213536</span> <span class="n">delay</span><span class="o">=</span><span class="mi">3</span>
</pre></div>
</div>
<p>This state means, that almost all the CPU resources are
dedicated to the reader thread. It doesn’t mean, that
the reader thread consumes 100% CPU – it means, that the
CPU is reserved for the case of more intensive bursts. The
library will return to the normal state only when the
broadcast storm will be over, and then the CPU will be
100% loaded with the parser for some time, when it will
process all the messages queued so far.</p>
</div>
<div class="section" id="when-async-i-o-doesn-t-help">
<h2>when async I/O doesn’t help<a class="headerlink" href="#when-async-i-o-doesn-t-help" title="Permalink to this headline">¶</a></h2>
<p>Sometimes, even turning async I/O doesn’t fix ENOBUF.
Mostly it means, that in this particular case the Python
performance is not enough even to read and store the raw
data from the socket. There is no workaround for such
cases, except of using something <em>not</em> Python-based.</p>
<p>One can still play around with SO_RCVBUF socket option,
but it doesn’t help much. So keep it in mind, and if you
expect massive broadcast Netlink storms, perform stress
testing prior to deploy a solution in the production.</p>
</div>
<div class="section" id="classes">
<h2>classes<a class="headerlink" href="#classes" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pyroute2.netlink.nlsocket.Stats">
<em class="property">class </em><code class="sig-prename descclassname">pyroute2.netlink.nlsocket.</code><code class="sig-name descname">Stats</code><span class="sig-paren">(</span><em class="sig-param">qsize</em>, <em class="sig-param">delta</em>, <em class="sig-param">delay</em><span class="sig-paren">)</span><a class="headerlink" href="#pyroute2.netlink.nlsocket.Stats" title="Permalink to this definition">¶</a></dt>
<dd><dl class="method">
<dt id="pyroute2.netlink.nlsocket.Stats.delay">
<em class="property">property </em><code class="sig-name descname">delay</code><a class="headerlink" href="#pyroute2.netlink.nlsocket.Stats.delay" title="Permalink to this definition">¶</a></dt>
<dd><p>Alias for field number 2</p>
</dd></dl>

<dl class="method">
<dt id="pyroute2.netlink.nlsocket.Stats.delta">
<em class="property">property </em><code class="sig-name descname">delta</code><a class="headerlink" href="#pyroute2.netlink.nlsocket.Stats.delta" title="Permalink to this definition">¶</a></dt>
<dd><p>Alias for field number 1</p>
</dd></dl>

<dl class="method">
<dt id="pyroute2.netlink.nlsocket.Stats.qsize">
<em class="property">property </em><code class="sig-name descname">qsize</code><a class="headerlink" href="#pyroute2.netlink.nlsocket.Stats.qsize" title="Permalink to this definition">¶</a></dt>
<dd><p>Alias for field number 0</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="pyroute2.netlink.nlsocket.Marshal">
<em class="property">class </em><code class="sig-prename descclassname">pyroute2.netlink.nlsocket.</code><code class="sig-name descname">Marshal</code><a class="headerlink" href="#pyroute2.netlink.nlsocket.Marshal" title="Permalink to this definition">¶</a></dt>
<dd><p>Generic marshalling class</p>
<dl class="method">
<dt id="pyroute2.netlink.nlsocket.Marshal.parse">
<code class="sig-name descname">parse</code><span class="sig-paren">(</span><em class="sig-param">data</em>, <em class="sig-param">seq=None</em>, <em class="sig-param">callback=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pyroute2.netlink.nlsocket.Marshal.parse" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse string data.</p>
<p>At this moment all transport, except of the native
Netlink is deprecated in this library, so we should
not support any defragmentation on that level</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="pyroute2.netlink.nlsocket.NetlinkMixin">
<em class="property">class </em><code class="sig-prename descclassname">pyroute2.netlink.nlsocket.</code><code class="sig-name descname">NetlinkMixin</code><span class="sig-paren">(</span><em class="sig-param">family=16</em>, <em class="sig-param">port=None</em>, <em class="sig-param">pid=None</em>, <em class="sig-param">fileno=None</em>, <em class="sig-param">sndbuf=1048576</em>, <em class="sig-param">rcvbuf=1048576</em>, <em class="sig-param">all_ns=False</em>, <em class="sig-param">async_qsize=None</em>, <em class="sig-param">nlm_generator=None</em>, <em class="sig-param">target='localhost'</em><span class="sig-paren">)</span><a class="headerlink" href="#pyroute2.netlink.nlsocket.NetlinkMixin" title="Permalink to this definition">¶</a></dt>
<dd><p>Generic netlink socket</p>
<dl class="method">
<dt id="pyroute2.netlink.nlsocket.NetlinkMixin.register_callback">
<code class="sig-name descname">register_callback</code><span class="sig-paren">(</span><em class="sig-param">callback</em>, <em class="sig-param">predicate=&lt;function NetlinkMixin.&lt;lambda&gt;&gt;</em>, <em class="sig-param">args=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pyroute2.netlink.nlsocket.NetlinkMixin.register_callback" title="Permalink to this definition">¶</a></dt>
<dd><p>Register a callback to run on a message arrival.</p>
<p>Callback is the function that will be called with the
message as the first argument. Predicate is the optional
callable object, that returns True or False. Upon True,
the callback will be called. Upon False it will not.
Args is a list or tuple of arguments.</p>
<p>Simplest example, assume ipr is the IPRoute() instance:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># create a simplest callback that will print messages</span>
<span class="k">def</span> <span class="nf">cb</span><span class="p">(</span><span class="n">msg</span><span class="p">):</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>

<span class="c1"># register callback for any message:</span>
<span class="n">ipr</span><span class="o">.</span><span class="n">register_callback</span><span class="p">(</span><span class="n">cb</span><span class="p">)</span>
</pre></div>
</div>
<p>More complex example, with filtering:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Set object&#39;s attribute after the message key</span>
<span class="k">def</span> <span class="nf">cb</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
    <span class="n">obj</span><span class="o">.</span><span class="n">some_attr</span> <span class="o">=</span> <span class="n">msg</span><span class="p">[</span><span class="s2">&quot;some key&quot;</span><span class="p">]</span>

<span class="c1"># Register the callback only for the loopback device, index 1:</span>
<span class="n">ipr</span><span class="o">.</span><span class="n">register_callback</span><span class="p">(</span><span class="n">cb</span><span class="p">,</span>
                      <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;index&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">,</span>
                      <span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="p">))</span>
</pre></div>
</div>
<p>Please note: you do <strong>not</strong> need to register the default 0 queue
to invoke callbacks on broadcast messages. Callbacks are
iterated <strong>before</strong> messages get enqueued.</p>
</dd></dl>

<dl class="method">
<dt id="pyroute2.netlink.nlsocket.NetlinkMixin.unregister_callback">
<code class="sig-name descname">unregister_callback</code><span class="sig-paren">(</span><em class="sig-param">callback</em><span class="sig-paren">)</span><a class="headerlink" href="#pyroute2.netlink.nlsocket.NetlinkMixin.unregister_callback" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove the first reference to the function from the callback
register</p>
</dd></dl>

<dl class="method">
<dt id="pyroute2.netlink.nlsocket.NetlinkMixin.register_policy">
<code class="sig-name descname">register_policy</code><span class="sig-paren">(</span><em class="sig-param">policy</em>, <em class="sig-param">msg_class=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pyroute2.netlink.nlsocket.NetlinkMixin.register_policy" title="Permalink to this definition">¶</a></dt>
<dd><p>Register netlink encoding/decoding policy. Can
be specified in two ways:
<cite>nlsocket.register_policy(MSG_ID, msg_class)</cite>
to register one particular rule, or
<cite>nlsocket.register_policy({MSG_ID1: msg_class})</cite>
to register several rules at once.
E.g.:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">policy</span> <span class="o">=</span> <span class="p">{</span><span class="n">RTM_NEWLINK</span><span class="p">:</span> <span class="n">ifinfmsg</span><span class="p">,</span>
          <span class="n">RTM_DELLINK</span><span class="p">:</span> <span class="n">ifinfmsg</span><span class="p">,</span>
          <span class="n">RTM_NEWADDR</span><span class="p">:</span> <span class="n">ifaddrmsg</span><span class="p">,</span>
          <span class="n">RTM_DELADDR</span><span class="p">:</span> <span class="n">ifaddrmsg</span><span class="p">}</span>
<span class="n">nlsocket</span><span class="o">.</span><span class="n">register_policy</span><span class="p">(</span><span class="n">policy</span><span class="p">)</span>
</pre></div>
</div>
<p>One can call <cite>register_policy()</cite> as many times,
as one want to – it will just extend the current
policy scheme, not replace it.</p>
</dd></dl>

<dl class="method">
<dt id="pyroute2.netlink.nlsocket.NetlinkMixin.unregister_policy">
<code class="sig-name descname">unregister_policy</code><span class="sig-paren">(</span><em class="sig-param">policy</em><span class="sig-paren">)</span><a class="headerlink" href="#pyroute2.netlink.nlsocket.NetlinkMixin.unregister_policy" title="Permalink to this definition">¶</a></dt>
<dd><p>Unregister policy. Policy can be:</p>
<blockquote>
<div><ul class="simple">
<li><p>int – then it will just remove one policy</p></li>
<li><p>list or tuple of ints – remove all given</p></li>
<li><p>dict – remove policies by keys from dict</p></li>
</ul>
</div></blockquote>
<p>In the last case the routine will ignore dict values,
it is implemented so just to make it compatible with
<cite>get_policy_map()</cite> return value.</p>
</dd></dl>

<dl class="method">
<dt id="pyroute2.netlink.nlsocket.NetlinkMixin.get_policy_map">
<code class="sig-name descname">get_policy_map</code><span class="sig-paren">(</span><em class="sig-param">policy=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pyroute2.netlink.nlsocket.NetlinkMixin.get_policy_map" title="Permalink to this definition">¶</a></dt>
<dd><p>Return policy for a given message type or for all
message types. Policy parameter can be either int,
or a list of ints. Always return dictionary.</p>
</dd></dl>

<dl class="method">
<dt id="pyroute2.netlink.nlsocket.NetlinkMixin.put">
<code class="sig-name descname">put</code><span class="sig-paren">(</span><em class="sig-param">msg</em>, <em class="sig-param">msg_type</em>, <em class="sig-param">msg_flags=1</em>, <em class="sig-param">addr=(0</em>, <em class="sig-param">0)</em>, <em class="sig-param">msg_seq=0</em>, <em class="sig-param">msg_pid=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pyroute2.netlink.nlsocket.NetlinkMixin.put" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct a message from a dictionary and send it to
the socket. Parameters:</p>
<blockquote>
<div><ul class="simple">
<li><p>msg – the message in the dictionary format</p></li>
<li><p>msg_type – the message type</p></li>
<li><p>msg_flags – the message flags to use in the request</p></li>
<li><p>addr – <cite>sendto()</cite> addr, default <cite>(0, 0)</cite></p></li>
<li><p>msg_seq – sequence number to use</p></li>
<li><p>msg_pid – pid to use, if <cite>None</cite> – use os.getpid()</p></li>
</ul>
</div></blockquote>
<p>Example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">s</span> <span class="o">=</span> <span class="n">IPRSocket</span><span class="p">()</span>
<span class="n">s</span><span class="o">.</span><span class="n">bind</span><span class="p">()</span>
<span class="n">s</span><span class="o">.</span><span class="n">put</span><span class="p">({</span><span class="s1">&#39;index&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">},</span> <span class="n">RTM_GETLINK</span><span class="p">)</span>
<span class="n">s</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="n">s</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
<p>Please notice, that the return value of <cite>s.get()</cite> can be
not the result of <cite>s.put()</cite>, but any broadcast message.
To fix that, use <cite>msg_seq</cite> – the response must contain the
same <cite>msg[‘header’][‘sequence_number’]</cite> value.</p>
</dd></dl>

<dl class="method">
<dt id="pyroute2.netlink.nlsocket.NetlinkMixin.get">
<code class="sig-name descname">get</code><span class="sig-paren">(</span><em class="sig-param">bufsize=16384</em>, <em class="sig-param">msg_seq=0</em>, <em class="sig-param">terminate=None</em>, <em class="sig-param">callback=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pyroute2.netlink.nlsocket.NetlinkMixin.get" title="Permalink to this definition">¶</a></dt>
<dd><p>Get parsed messages list. If <cite>msg_seq</cite> is given, return
only messages with that <cite>msg[‘header’][‘sequence_number’]</cite>,
saving all other messages into <cite>self.backlog</cite>.</p>
<p>The routine is thread-safe.</p>
<p>The <cite>bufsize</cite> parameter can be:</p>
<blockquote>
<div><ul class="simple">
<li><dl class="simple">
<dt>-1: bufsize will be calculated from the first 4 bytes of</dt><dd><p>the network data</p>
</dd>
</dl>
</li>
<li><p>0: bufsize will be calculated from SO_RCVBUF sockopt</p></li>
<li><p>int &gt;= 0: just a bufsize</p></li>
</ul>
</div></blockquote>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="pyroute2.netlink.nlsocket.BatchBacklogQueue">
<em class="property">class </em><code class="sig-prename descclassname">pyroute2.netlink.nlsocket.</code><code class="sig-name descname">BatchBacklogQueue</code><a class="headerlink" href="#pyroute2.netlink.nlsocket.BatchBacklogQueue" title="Permalink to this definition">¶</a></dt>
<dd><dl class="method">
<dt id="pyroute2.netlink.nlsocket.BatchBacklogQueue.append">
<code class="sig-name descname">append</code><span class="sig-paren">(</span><em class="sig-param">*argv</em>, <em class="sig-param">**kwarg</em><span class="sig-paren">)</span><a class="headerlink" href="#pyroute2.netlink.nlsocket.BatchBacklogQueue.append" title="Permalink to this definition">¶</a></dt>
<dd><p>Append object to the end of the list.</p>
</dd></dl>

<dl class="method">
<dt id="pyroute2.netlink.nlsocket.BatchBacklogQueue.pop">
<code class="sig-name descname">pop</code><span class="sig-paren">(</span><em class="sig-param">*argv</em>, <em class="sig-param">**kwarg</em><span class="sig-paren">)</span><a class="headerlink" href="#pyroute2.netlink.nlsocket.BatchBacklogQueue.pop" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove and return item at index (default last).</p>
<p>Raises IndexError if list is empty or index is out of range.</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="pyroute2.netlink.nlsocket.BatchBacklog">
<em class="property">class </em><code class="sig-prename descclassname">pyroute2.netlink.nlsocket.</code><code class="sig-name descname">BatchBacklog</code><a class="headerlink" href="#pyroute2.netlink.nlsocket.BatchBacklog" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="class">
<dt id="pyroute2.netlink.nlsocket.BatchSocket">
<em class="property">class </em><code class="sig-prename descclassname">pyroute2.netlink.nlsocket.</code><code class="sig-name descname">BatchSocket</code><span class="sig-paren">(</span><em class="sig-param">family=16</em>, <em class="sig-param">port=None</em>, <em class="sig-param">pid=None</em>, <em class="sig-param">fileno=None</em>, <em class="sig-param">sndbuf=1048576</em>, <em class="sig-param">rcvbuf=1048576</em>, <em class="sig-param">all_ns=False</em>, <em class="sig-param">async_qsize=None</em>, <em class="sig-param">nlm_generator=None</em>, <em class="sig-param">target='localhost'</em><span class="sig-paren">)</span><a class="headerlink" href="#pyroute2.netlink.nlsocket.BatchSocket" title="Permalink to this definition">¶</a></dt>
<dd><dl class="method">
<dt id="pyroute2.netlink.nlsocket.BatchSocket.get">
<code class="sig-name descname">get</code><span class="sig-paren">(</span><em class="sig-param">*argv</em>, <em class="sig-param">**kwarg</em><span class="sig-paren">)</span><a class="headerlink" href="#pyroute2.netlink.nlsocket.BatchSocket.get" title="Permalink to this definition">¶</a></dt>
<dd><p>Get parsed messages list. If <cite>msg_seq</cite> is given, return
only messages with that <cite>msg[‘header’][‘sequence_number’]</cite>,
saving all other messages into <cite>self.backlog</cite>.</p>
<p>The routine is thread-safe.</p>
<p>The <cite>bufsize</cite> parameter can be:</p>
<blockquote>
<div><ul class="simple">
<li><dl class="simple">
<dt>-1: bufsize will be calculated from the first 4 bytes of</dt><dd><p>the network data</p>
</dd>
</dl>
</li>
<li><p>0: bufsize will be calculated from SO_RCVBUF sockopt</p></li>
<li><p>int &gt;= 0: just a bufsize</p></li>
</ul>
</div></blockquote>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="pyroute2.netlink.nlsocket.NetlinkSocket">
<em class="property">class </em><code class="sig-prename descclassname">pyroute2.netlink.nlsocket.</code><code class="sig-name descname">NetlinkSocket</code><span class="sig-paren">(</span><em class="sig-param">family=16</em>, <em class="sig-param">port=None</em>, <em class="sig-param">pid=None</em>, <em class="sig-param">fileno=None</em>, <em class="sig-param">sndbuf=1048576</em>, <em class="sig-param">rcvbuf=1048576</em>, <em class="sig-param">all_ns=False</em>, <em class="sig-param">async_qsize=None</em>, <em class="sig-param">nlm_generator=None</em>, <em class="sig-param">target='localhost'</em><span class="sig-paren">)</span><a class="headerlink" href="#pyroute2.netlink.nlsocket.NetlinkSocket" title="Permalink to this definition">¶</a></dt>
<dd><dl class="method">
<dt id="pyroute2.netlink.nlsocket.NetlinkSocket.bind">
<code class="sig-name descname">bind</code><span class="sig-paren">(</span><em class="sig-param">groups=0</em>, <em class="sig-param">pid=None</em>, <em class="sig-param">**kwarg</em><span class="sig-paren">)</span><a class="headerlink" href="#pyroute2.netlink.nlsocket.NetlinkSocket.bind" title="Permalink to this definition">¶</a></dt>
<dd><p>Bind the socket to given multicast groups, using
given pid.</p>
<blockquote>
<div><ul class="simple">
<li><p>If pid is None, use automatic port allocation</p></li>
<li><p>If pid == 0, use process’ pid</p></li>
<li><p>If pid == &lt;int&gt;, use the value instead of pid</p></li>
</ul>
</div></blockquote>
</dd></dl>

<dl class="method">
<dt id="pyroute2.netlink.nlsocket.NetlinkSocket.close">
<code class="sig-name descname">close</code><span class="sig-paren">(</span><em class="sig-param">code=104</em><span class="sig-paren">)</span><a class="headerlink" href="#pyroute2.netlink.nlsocket.NetlinkSocket.close" title="Permalink to this definition">¶</a></dt>
<dd><p>Correctly close the socket and free all resources.</p>
</dd></dl>

</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Base netlink socket and marshal</a><ul>
<li><a class="reference internal" href="#asynchronous-i-o">asynchronous I/O</a></li>
<li><a class="reference internal" href="#enobuf-and-async-i-o">ENOBUF and async I/O</a></li>
<li><a class="reference internal" href="#when-async-i-o-doesn-t-help">when async I/O doesn’t help</a></li>
<li><a class="reference internal" href="#classes">classes</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="netlink.html"
                        title="previous chapter">Netlink</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/nlsocket.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="netlink.html" title="Netlink"
             >previous</a> |</li>
        <li class="nav-item"><a href="http://pyroute2.org">Project home</a> &#187;</li>
        <li class="nav-item nav-item-0"><a href="index.html">pyroute2 0.5.14 documentation</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2013, Peter V. Saveliev.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 2.1.2.
    </div>
  </body>
</html>