# [solved] How to find an unused TAP device ?

## toralf

With kernel 3.8. I just realized that all pre-defined TAP devices are RUNNING even if no virtual linux system is using it. Now I'm wondering whether this is a new feature of the upcoming kernel, a bug of the old - and how I can avoid that.

Background : When I start a user mode linux instance, I currently grep for the next free tap device in this way :

```
for t in $(ifconfig | grep "^tap" | cut -f1 -d:)

do

   ethtool $t | grep -q 'Link detected: no'

   if [[ $? -eq 0 ]]; then

      NET="tuntap,$t"

      break

   fi

done

```

but this doesn't work now anymore.

Here is the diff in dmesg

```
$ diff 3.7.1 3.8.0-rc1+ | grep UP

< br0: flags=4355<UP,BROADCAST,PROMISC,MULTICAST>  mtu 1500

> br0: flags=4419<UP,BROADCAST,RUNNING,PROMISC,MULTICAST>  mtu 1500

< tap0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500

> tap0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
```

 and my config

```
$ head -n 20 /etc/conf.d/net

# /etc/conf.d/net

#

#       KVM

#

bridge_br0="tap0 tap1 tap2 tap3"

config_br0="192.168.0.254/8" 

brctl_br0="setfd 0

sethello 10

stp off"

rc_net_br0_need="net.tap0 net.tap1 net.tap2 net.tap3"

config_tap0="null"

tuntap_tap0="tap"

tunctl_tap0="-u <me>"

...
```

Last edited by toralf on Mon Jan 28, 2013 6:39 pm; edited 1 time in total

----------

## Rexilion

That's a regression, not a feature. The kernel has an explicit goal to consistently (across versions) provide a reliable interface to the user.

I suggest you do a git bisect to speed up the debug. Perhaps:

```
git bisect start HEAD v3.7 -- drivers/net/tun.c
```

Looks like you are in for a treat =) * points down *

 *Quote:*   

> gebruiker@Delta:~/Documenten/Ronald/kernel$ git rev-list --oneline v3.7..v3.8-rc3 -- drivers/net/tun.c 
> 
> 9fdc6be tuntap: dont use a private kmem_cache
> 
> d32649d tuntap: fix sparse warning
> ...

 

----------

## toralf

fixed in git tree

----------

