Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 Jul 2008 14:43:47 -0500
From:      Matthew Grooms <mgrooms@shrew.net>
To:        freebsd-net@freebsd.org
Subject:   Help with tap device configuration oddity
Message-ID:  <4880F273.1090802@shrew.net>

next in thread | raw e-mail | index | archive | help
All,

I noticed a problem with some software I wrote for FreeBSD using tap 
devices. It would appear that you get inconsistent results from ioctl 
calls SIOCSIFADDR and SIOCSIFNETMASK when used with tap than when used 
with a real Ethernet device. I wrote a quick test program to demonstrate 
this which can be found at the following url ...

http://hole.shrew.net/~mgrooms/files/taptest.cpp

g++ taptest.cpp -o taptest

USAGE : taptest <address> <netmask> <mtu> [ifname]

Specify the ifname parameter to configure an
existing adapter. Omit the ifname paramter to
create a tap device and configure it instead.

When I use this with an Ethernet device on CURRENT, I get normal results ...

# ./taptest 10.1.2.3 255.255.255.0 1350 le1
ii : configured adapter le1 [10.1.2.3/255.255.255.0 MTU 1350]

le1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1350
         options=8<VLAN_MTU>
         ether 00:0c:29:bd:60:2b
         inet 10.1.2.3 netmask 0xffffff00 broadcast 10.1.2.255
         media: Ethernet autoselect
         status: active

# netstat -rn
Routing tables

Internet:
Destination        Gateway            Flags    Refs      Use  Netif Expire
default            10.aa.bbb.c        UGS         0       89    le0
10.1.2.0/24        link#2             UC          0        0    le1
...

When I use this with a tap device on CURRENT, I always get a wacky 10/8 
route added and no 10.2.3/24 route like you would expect ...

# ./taptest 10.2.3.4 255.255.255.0 1350
creating tap device
ii : opened tap device /dev/tap0
ii : configured adapter tap0 [10.2.3.4/255.255.255.0 MTU 1350]

tap0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1350
         ether 00:bd:59:d2:02:00
         inet 10.1.2.3 netmask 0xffffff00 broadcast 10.1.2.255
         Opened by PID 1497

# netstat -rn
Routing tables

Internet:
Destination        Gateway            Flags    Refs      Use  Netif Expire
default            10.aa.bbb.c        UGS         0       89    le0
10.0.0.0/8         link#5             UC          0        0   tap0

This really messes with traffic that should go out the default route. I 
tested this on 6.2-RELEASE as well and got similar results ...

# netstat -rn
Routing tables

Internet:
Destination        Gateway            Flags    Refs      Use  Netif Expire
default            10.a.b.c           UGS         0     5940   lnc0
10                 link#7             UC          0        0   tap0

Can someone please explain this to me?

Thanks in advance,

-Matthew



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4880F273.1090802>