cannot set TUN interface up/down with Python API (wrapper)

Thomas Haller thaller at redhat.com
Mon Apr 20 06:26:13 PDT 2015


On Fri, 2015-04-17 at 14:31 +0200, David Pradas wrote:
> Hi,


Hi David,


> I'm having a problem when using the Pyhton API (wrapper) for link 
> management (change address, set state up/down). I am not able to set a 
> TUN interface up/down with the python wrapper. However, I am capable of 
> doing that with the "C" API.

> This is the procedure I follow:
> 
> 1. I first create the TUN interface "tun0":
> 
> /sudo ip tuntap add dev tun0 mode tun/
> 
> 2. Then, I execute my python script (test.py):
> 
> /#!/usr/bin/env python2//
> //import netlink.route.link as link//
> //import netlink.core as netlink//
> //import netlink.route.address as address//
> //
> //sock = netlink.Socket()//
> //sock.connect(netlink.NETLINK_ROUTE)//
> //cache = link.LinkCache()//
> //cache.refill(sock)//
> //iface = cache['tun0']//
> //iface.flags = ['-up']//
> /*/iface.change()/*/

can you attach a small (working) reproducer? Where is this test.py
script?

You say it works via the "C" API. Did you write the same code in plain C
and that was working?


> 3. Finally, I obtain the following output when the file "test.py" has 
> been executed.
> 
> I get an " Invalid input data or parameter" exception when I call the 
> "iface.change()" :
> 
> //  nl_recvmsgs_report() returns error
> //  Traceback (most recent call last):
> //  File "./test.py", line 12, in <module>
> //    iface.change()
> //  File "/usr/local/lib/python2.7/dist-packages/netlink/route/link.py", 
> line 409, in change
> //    raise netlink.KernelError(ret)
> // netlink.core.KernelError: Kernel returned: Invalid input data or 
> parameter
> 
> On the other hand, I am capable of setting up/down other interfaces 
> which are not tun/tap (such as "eth") following the same method. 
> However, even in that case, I obtain the following error:
> 
> // File "./test.py", line 12, in <module>
> //   iface.change()
> //  File "/usr/local/lib/python2.7/dist-packages/netlink/route/link.py", 
> line 409, in change
> //    raise netlink.KernelError(ret)
> // netlink.core.KernelError: Kernel returned: Message sequence number 
> mismatch
> 
> I can not figure out where the problem is. Any ideas please?

Hm... I don't know. Try enabling debug logging for libnl via

export NLDBG=100



> I am running Ubuntu 14.04 LTS 64 bits and using the last release of 
> libnl 3.2.26 (I have also tried 3.2.25 with same results) . FYI: the 
> Python wrapper was correctly working with Ubuntu 12.04 LTS 64 bits, i.e. 
> I could set the TUN up/down without problems.

you could try whether an older version works, and then finding the
version that breaks your script (e.g. using git bisec).


Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/libnl/attachments/20150420/de9a13b5/attachment.sig>


More information about the libnl mailing list