#!/usr/bin/python import os, time, struct, fcntl # The following are from linux/if_tun.h TUNSETIFF = 0x400454ca # ioctl to configure a TUN/TAP interface IFF_TAP = 0x0002 # Ethernet-level tunnel interface IFF_NO_PI = 0x1000 # Protocol information header for tap interfaces intf = 'tap0' # Create a tap interface. tapFd = os.open( '/dev/net/tun', os.O_RDWR ) ioctlData = struct.pack( '16s H 14x', intf, IFF_TAP | IFF_NO_PI ) fcntl.ioctl( tapFd, TUNSETIFF, ioctlData ) # Enable then disable the tap interface. os.system( 'ip link set %s up' % intf ) print 'Enabled tap interface at', time.ctime( time.time() ) time.sleep( 1 ) # A delay here seems to be necessary to trigger the bug. os.system( 'ip link set %s down' % intf ) print 'Disabled tap interface at', time.ctime( time.time() ) time.sleep( 17 ) # A delay here is not necessary, but illustrates that the 30 second # interval starts when the interface is disabled, not when close is # called. # Destroy the tap interface. print 'About to close tap FD at', time.ctime( time.time() ) os.close( tapFd ) print 'Closed tap FD at', time.ctime( time.time() )