cannot set TUN interface up/down with Python API (wrapper)
Julien BERNARD
jbernard at toulouse.viveris.fr
Wed Jun 24 06:25:23 PDT 2015
Hi,
>
> The last working revision is 88940b71f81525b1080fcdd5a029537e9a85ca38,
> the revision just after the 3.2.3 release.
> The next revision (ef75c4edf0930b4d745da695c5fe0075c7b3afdd)
> introduces a segfault in the script that is resolved in the 3.2.5
> release (this should be the fix introduced by the revision
> 4035e5b5e88529e6c7a12c41dcd8637ed69498d9).
> Thus, I applied the fix on the revision
> ef75c4edf0930b4d745da695c5fe0075c7b3afdd and I can confirm that the
> problem was introduced by this revision.
> However I'm not familiar enough with all of this to determine exactly
> what causes the bug.
>
> Could you please help me to understand what really causes this error?
I managed to fix the problem.
In fact the error is caused by the link type set to 'tun' which is not
supported (there is nor tun.c in route/link/ neither in the python wrapper).
In C it works because I think there is a default behavior for tun
interface but this should not correcly be implemented in python.
At the moment, in order to make this work, I simply redefined the link
type as 'dummy' before changing the flags.
The script is thus as follow:
#!/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.type = 'dummy'
iface.flags = ['-up']
iface.change()
The libnl still returns an error (the same as for classic ethernet
interfaces: netlink.core.KernelError: Kernel returned: Message sequence
number mismatch) but this works.
I will try to find out why there is this problem and if there is
something to fix in the python wrapper I would report it.
Regards,
--
Julien BERNARD
More information about the libnl
mailing list