Commit Graph

53 Commits

Author SHA1 Message Date
Arend van Spriel
07ad37d4cb python: genl: capi: add genlmsg_hdr() to capi
Allow using genlmsg_hdr() function and make the header fields
accessible in Python scripts.

Signed-off-by: Arend van Spriel <aspriel@gmail.com>
2015-05-12 13:26:15 +02:00
Arend van Spriel
36f4adfa81 python: capi: add nla_put() function to python capi
Adding nla_put() to the capi using a typemap on the input
parameter which needs to be either a str or bytearray.
Otherwise a SWIG exception with be thrown.

Signed-off-by: Arend van Spriel <aspriel@gmail.com>
2015-05-12 13:26:15 +02:00
Arend van Spriel
ff6467135e python: capi: expose multicast membership functions
Adding functions to add/drop membership to single multicast group.

Signed-off-by: Arend van Spriel <aspriel@gmail.com>
2015-05-12 13:26:15 +02:00
Arend van Spriel
a4a75227df python: disable swig debug print messages
The define was left enabled during development on netlink (and genl)
python swig api. It is a bit annoying in production release so disable
the define.

Signed-off-by: Arend van Spriel <aspriel@gmail.com>
2015-05-12 13:26:15 +02:00
Thomas Haller
c7ae0c7d67 python: fix package meta data in setup.py
http://lists.infradead.org/pipermail/libnl/2015-January/001802.html

Acked-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2015-01-12 14:17:38 +01:00
Michał Górny
425d3d6661 Use paths relative to srcdir in setup.py.
Currently, setup.py is created by configure in builddir while source
files (.py and .i) reside in srcdir. Adjust paths in setup.py
appropriately to make it possible to perform an out-of-source build.

This is far from perfect but it mostly works. Python files are copied
from srcdir, and swig *.i files are read from there. However, swig
output files are created in srcdir rather than builddir, and distutils
copies '..' literally when constructing '.o' paths. As a result,
'../python/foo.i' would end up being compiled to
'build/temp*/../python/foo.i'.

The alternative would be to copy '*.i' files to builddir before
proceeding with the build, either in Makefile or through creating
additional distutils command.
2014-05-25 12:51:32 +02:00
Hiroaki KAWAI
cb319e22f5 python: fix wrongly passing argument to function in ObjIterator.next()
self.__next__() bound method does not take an extra argument.

https://github.com/thom311/libnl/pull/57

Signed-off-by: Hiroaki KAWAI <kawai@stratosphere.co.jp>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-04-09 09:22:47 +02:00
Thomas Haller
815e192db6 python: fix build error for missing library_path in setup.py
Patch obtained from gentoo package.

https://bugs.gentoo.org/show_bug.cgi?id=477110
https://bugs.gentoo.org/show_bug.cgi?id=490584

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-01-21 19:11:16 +01:00
Thomas Graf
2ae5298408 python: Include all files in distribution
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-11-06 10:28:37 +01:00
Nicolas PLANEL
978bb85c7a python: add bridge flags API
Add flags set/get methods aim to change bridge flags :
 o hairpin_mode
 o bpdu_guard
 o root_block
 o fast_leave

Signed-off-by: Nicolas PLANEL <nicolas.planel@enovance.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-22 14:20:41 +02:00
Nicolas PLANEL
07669b0b80 test: add python bridge testing sample
New test sample file, test-create-bridge.py
Create an bridge (testbrige) and attach an already setup interface (testtap1) to it.

Signed-off-by: Nicolas PLANEL <nicolas.planel@enovance.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-22 14:20:41 +02:00
Nicolas PLANEL
defebe30c6 python: add basic netlink protocol bridge interface support
Implements basic bridge interface support using netlink protocol

Signed-off-by: Nicolas PLANEL <nicolas.planel@enovance.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-22 14:20:41 +02:00
Teto
a4e588d04a Fixed ObjIterator for python3, fixed output of _color and added missing parameter to nl_cache_resync
Here are a few things I fixed and that provoked a  python error.

I canno't answer to this thread but one solution I found while using
the python binding is to iterate over all and filter via python
http://list-archives.org/2013/09/09/libnl-lists-infradead-org/missing-feature-for-retrieving-cached-
address-objects/f/5031600704

Example:
cache = nlrta.AddressCache()
cache.resync()

for i in cache:
    print ("item", i ) # then you can filter here

Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-07 09:52:08 +02:00
Nicolas PLANEL
f2e6f502eb python: fixup VLANLink() initialization
The varialble name should be link._rtnl_link
instead of link._link to get rid of the AttributeError.

Traceback (most recent call last):
File "examples/test.py", line 11, in <module>
 eth0 = link.resolve('eth0.800')
...
File
"/home/ubuntu/libnl/python/build/lib.linux-x86_64-2.7/netlink/route/link.py",
line 151, in __init__
 self._module_lookup('netlink.route.links.' + self.type)
...
File
"/home/ubuntu/libnl/python/build/lib.linux-x86_64-2.7/netlink/route/links/vlan.py",
line 70, in init
 link.vlan = VLANLink(link._link)
AttributeError: 'Link' object has no attribute '_link'

Signed-off-by: Nicolas PLANEL <nicolas.planel@enovance.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-07 09:50:11 +02:00
Arend van Spriel
ae7f8cc988 python: remove use of PyArg_ParseTuple() for callback result
The message receive callback handler in the netlink api processes
the result object from the python callback. It used PyArg_ParseTuple()
to get the value, but this does not work as intended (see ref [1]).
Instead check the type and convert it accordingly.

refs:
[1] http://stackoverflow.com/questions/13636711/what-is-the-proper-usage-of-pyarg-parsetuple

Reported-by: Teto <mattator@gmail.com>
Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-07 09:45:56 +02:00
Arend van Spriel
b9284bcded python: add send and receive functions to Socket class
Adding class methods send_auto_complete() and recvmsgs()
that call their swig capi equivalent function.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-09-05 17:46:00 +02:00
Arend van Spriel
6726895133 python: fix typo in Socket::__str__() function
The property name used in __str__ should be local_port
instead of localPort to get rid of the AttributeError.

>>> str(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../netlink/core.py", line 172, in __str__
    return 'nlsock<{0}>'.format(self.localPort)
AttributeError: 'Socket' object has no attribute 'localPort'

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-09-05 17:46:00 +02:00
Arend van Spriel
fa23414013 python: remove unnecessary callback type definitions
Copied the typedefs when adding callback support, but they serve
no actual use in the swig input file.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-09-05 17:46:00 +02:00
Arend van Spriel
522cf98fc2 python: allow callback function to be a class method
The callback functionality only worked for regular Python
functions. With this patch it also allows the callback
to be a class method (bounded or unbounded) as show in
example below.

class test_class(object):
	def my_callback(self, msg, arg):
		print('handling %s' % str(msg))

s = netlink.core.Socket()
testobj = test_class()
netlink.capi.py_nl_cb_set(cb, netlink.capi.NL_CB_VALID,
			  netlink.capi.NL_CB_CUSTOM,
			  test_class.my_callback, testobj)
netlink.capi.py_nl_cb_err(cb, netlink.capi.NL_CB_CUSTOM,
                          test_class.my_callback, s)

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-09-05 17:46:00 +02:00
Arend van Spriel
2d55872fb1 use Callback object constructing Socket
Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-09-05 17:46:00 +02:00
Arend van Spriel
86207d47ab python: rework netlink callback handling
The initial commit adding netlink callback handling also introduced
memory leak issue. The python callback info was stored in an allocated
structure, but that was never freed.

Only exposing nl_cb_alloc() as is. nl_cb_get() is removed as it is
not very useful to use reference counting mechanism. Python uses
that itself internally. To deal properly with Python callback info
the function nl_cb_put() and nl_cb_clone() have a custom wrapper
taking care of Python reference counting.

This commit also adds a Callback python class using the netlink
callback functions.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-09-05 17:46:00 +02:00
Arend van Spriel
9828326c7f add python examples using swig provided api
using the nl80211 family to show use of generic netlink api and
attribute parsing.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-09-05 17:46:00 +02:00
Yasunobu Chiba
162c906bf2 Add VXLAN support. 2013-08-04 15:43:54 +09:00
Arend van Spriel
89b00119f2 add generic netlink functions to swig
Provide wrapper function for generic netlink library functions. The
genlmsg_parse() function is handled similar to nla_parse_nested() so
it returns tuple with error code and dictionary of parsed attributes.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-07-18 23:22:18 +02:00
Arend van Spriel
7dc033f5cc add python module for generic netlink library
This commit adds creation of the netlink.genl package. The actual
capi.i will be filled in upcoming commits so the module is rather
dumb for now.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-07-18 23:22:18 +02:00
Arend van Spriel
e77ea939c4 add support functions for attributes and callback handlers
added support functions to access the netlink attributes and use
custom callback handlers. Most is wrapped as is, but there are
a couple of special cases handled.

1) void *nla_data(struct nlattr *);
The return value is changed to a Python byte array so it includes
the lenght of the data stream.

2) int nla_parse_nested(...);
This returns a tuple (err, dict). 'err' is the error code and 'dict'
is a dictionary with attribute identifier as key and value represents
a struct nlattr object.

3) macro nla_for_each_nested()
Provide nla_get_nested() which returns a Python list of struct nlattr
objects that is iterable.

4) allocate struct nla_policy array
Provide nla_policy_array() function that allocates consecutive space
in memory for struct nla_policy array entries. Each entry is put in
a Python list so the entry fields can be modified in Python. This
array object can be passed to the nla_parse_nested() function.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-07-18 23:22:18 +02:00
Michael Braun
c76393e203 Add macvlan support
This patch add support for kernel macvlan interfaces.

Signed-off-by: Michael Braun <michael-dev@fami-braun.de>
2013-05-16 17:04:08 +02:00
Antoni S. Puimedon
72c2cb9e29 Enabled the use of Links as context managers.
With this change you can still set do modifications of
Links and then to change to pass the changes to the
kernel. But it additionally enables you to interact
with this part of libnl-python in a more pythonic
way. Instead of:

    eth0 = links['eth0']
    eth0.mtu = 5000
    eth0.change()

you can do:

    with links['eth0'] as eth0:
        eth0.mtu = 5000
2012-10-04 16:36:55 -04:00
Коренберг Марк
ffa461d37c Fixed memory leak in Cache destructor
destructor of Cache was missing due to typo
2012-06-08 22:26:35 +06:00
Коренберг Марк (ноутбук дома)
dca358c6a2 rtnl_link_(get|set)_weight is deprecated in libnl.
So, remove from python binding. Should not break compatibility.
2012-06-08 22:26:35 +06:00
Коренберг Марк
87d370912c netlink.nlattr re-implemented in more pythonic way 2012-06-08 22:26:35 +06:00
Коренберг Марк
139e3d3203 nl_pickup removed from python binding 2012-06-08 22:26:35 +06:00
Коренберг Марк (ноутбук дома)
08e8b35d9f Remove unnecessary comments 2012-06-08 22:26:35 +06:00
Коренберг Марк (ноутбук дома)
482c602b74 Refine some places
No real logick change
2012-06-08 22:26:35 +06:00
Коренберг Марк (ноутбук дома)
454ea4a5b4 pylint's first review and trivial fixes 2012-06-08 22:26:35 +06:00
Коренберг Марк (ноутбук дома)
8959d95e22 Using only single quotes now and multi-line lists
Nothing algorithmic changed really, just cosmetics
2012-06-08 22:26:35 +06:00
Коренберг Марк (ноутбук дома)
83f06bfbb8 Fix indentation (spaces vs tabs)
Now, python files use pseudo-tab equal 4 spaces
2012-06-08 22:26:35 +06:00
Коренберг Марк (ноутбук дома)
fb890a5b5e Code cleanups
1. unused "import struct" removed
2. AddressFamily.__len__ is defined, but why in so way? removed.
3. comparison against instancemethod type fixed
2012-06-08 22:26:35 +06:00
Коренберг Марк (ноутбук дома)
c1547d90d7 Flags properties description and implementation fixed
1. Address, Link and Vlan classes affected with same bug
2. Flags property are not designed as set class. Setting to property will
   not replace flags, just add flags to set. So, jist document that, and
   fixed obvious logick.
2012-06-08 22:26:35 +06:00
Коренберг Марк (ноутбук дома)
38fefc5c1b Fixed various str-related logick 2012-06-08 22:26:35 +06:00
Коренберг Марк (ноутбук дома)
b369d22f92 Fix whitespaces at EOL
Make git happy with that
2012-06-08 22:26:35 +06:00
Коренберг Марк (ноутбук дома)
4be1ae2ae2 Introduce Python's absolute_imports
Helps greatly when porting to Python 3
2012-06-08 22:26:35 +06:00
Коренберг Марк (ноутбук дома)
f55ea7ff9d Fix typo in still unused function that generate colored message 2012-06-08 22:26:35 +06:00
Коренберг Марк (ноутбук дома)
1e75bd006b Make syntax highlighters happy
Fix typo in docstring
2012-06-08 22:26:35 +06:00
Коренберг Марк
9d60ef0d59 Removed generated .pyc files from repository 2012-06-08 22:26:34 +06:00
Коренберг Марк (ноутбук дома)
bf54d6d03a Fixed address deletion
1. rtnl_addr_delete require three arguments
2. comment fixed (fixed copy-past from link.py)
2012-06-08 22:26:34 +06:00
Thomas Graf
9c7593cc9b python: Link against nl-3 and nl-route-3 2011-10-26 10:54:10 +02:00
Thomas Graf
23333e5e35 python: Include python/ in distribution and provide a README on how to build & install 2011-08-12 10:45:47 +02:00
Thomas Graf
20e9797652 use rtnl_link_set/get_type() 2011-07-21 17:52:43 +02:00
Thomas Graf
bf1b5d28c0 removed autogenerated swig interface files from git tree 2011-07-21 17:49:21 +02:00