cannot set TUN interface up/down with Python API (wrapper)
David Pradas
david.pradas at toulouse.viveris.com
Fri Apr 17 05:31:13 PDT 2015
Hi,
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()/*/
/
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?
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.
Thank you in advance for your help,
David Pradas
More information about the libnl
mailing list