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
|
*******************
Netlink Core Module
*******************
.. py:module:: netlink.core
Examples::
import netlink.core as netlink
===============
Object
===============
.. py:class:: Object
Base class for all classes representing a cacheable object
Example::
obj = netlink.Object("route/link", "link")
.. py:method:: clone
Clone the object and return a duplicate (used for COW)
.. py:method:: dump([params=None])
Call the libnl internal dump mechanism to dump the object
according to the parameters specified.
.. py:method:: apply(attr, val)
Applies a attribute=value pair and modifies the object accordingly.
Example::
obj.apply("mtu", 1200) # Sets attribute mtu to 1200 (link obj)
:raises: KeyError if attribute is unknown
:raises: ImmutableError if attribute is not mutable
.. py:attribute:: mark
True if the object is marked, otherwise False.
.. py:attribute:: shared
True if the object is used by multiple parties, otherwise False.
.. py:attribute:: refcnt
Number of users sharing a reference to the object
:rtype: int
.. py:attribute:: attrs
List of attributes
:rtype: list of strings
===============
Cache
===============
.. py:class:: Cache
Base class for all cache implementations.
A cache is a collection of cacheable objects which is typically used
by netlink protocols which handle any kind of object, e.g. network
links, network addresses, neighbours, ...
.. py:method:: subset(filter)
Returns a new cache containing the subset which matches the
provided filter.
:raises: ValueError if no filter is specified
:rtype: :py:class:`Cache`
.. py:method:: dump([params=None, filter=None])
Calls the libnl internal dump mechanism to dump the cache according
to the parameters and filter specified.
.. py:method:: clear()
Remove and possibly destroy all objects in the cache
.. py:method:: refill([socket=None]) -> :py:class:`Cache`
Clears and refills the cache with the content which is provided by
the kernel, e.g. for a link cache this would mean refilling the
cache with all configured network links.
.. py:method:: provide()
Caches which have been "provided" are made available to other users
(of the same application context) which "require" it. F.e. a link
cache is generally provided to allow others to translate interface
indexes to link names
.. py:method:: unprovide()
No longer make the cache available to others. If the cache has been
handed out already, that reference will still be valid.
===============
AbstractAddress
===============
.. py:class:: AbstractAddress
Abstract representation of an address. This class is not to be mistaken
with :py:class:`route.Address` which represents a configured network
address. This class represents the actual address in a family independent
way::
addr = netlink.AbstractAddress('127.0.0.1/8')
print addr # => '127.0.0.1/8'
print addr.prefixlen # => '8'
print addr.family # => 'inet'
print len(addr) # => '4' (32bit ipv4 address)
a = netlink.AbstractAddress('10.0.0.1/24')
b = netlink.AbstractAddress('10.0.0.2/24')
print a == b # => False
.. py:attribute:: prefixlen
Length of prefix in number of bits.
:rtype: int
.. py:attribute:: family
The family type of the address. Setting the address family can be
done with a string or a :py:class:`AddressFamily` object.
:rtype: :py:class:`AddressFamily`
.. py:attribute:: shared
True if address is in use by multiple callers, otherwise False
:rtype: bool
===============
AddressFamily
===============
.. py:class:: AddressFamily
Address family representation::
af = netlink.AddressFamily('inet6')
# raises:
# - ValueError if family name is not known
# - TypeError if invalid type is specified for family
print af # => 'inet6' (string representation)
print int(af) # => 10 (numeric representation)
print repr(af) # => AddressFamily('inet6')
===============
Exceptions
===============
.. py:exception:: NetlinkError
Generic exception raised by netlink modules.
.. py:exception:: KernelError
Raised if an error occured while communicating with the kernel. Contains
the error code returning which is automatically included in the error
message.
.. py:exception:: ImmutableError
Raised if an attribute is modified which is marked immutable.
===============
Socket
===============
.. py:class:: Socket
Netlink socket.
Note: It is not required to manually create and connect netlink sockets
when using caches. The caches will automatically lookup or create a
socket as needed.
.. py:attribute:: local_port
Local port (address) of netlink socket
.. py:attribute:: peer_port
Peer port (remote address) of netlink socket. If set, all messages
will be sent to that peer.
.. py:method:: connect(proto)
Connect the netlink socket using the specified netlink protocol::
sock.connect(netlink.NETLINK_ROUTE)
.. py:method:: disconnect()
Disconnect the socket
.. py:method:: set_bufsize(rx, tx)
Sets the size of the socket buffer
|