TUN driver: Implement TAP (OSI layer 2) mode.

Enable by setting the IFF_TAP flag instead of the IFF_TUN flag in ifr_flags.
This commit is contained in:
Thomas Keh 2017-04-13 13:07:03 +02:00
parent dc2890904d
commit 7e293b28ee
2 changed files with 17 additions and 2 deletions

View File

@ -1159,7 +1159,7 @@ static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
int intf;
FAR struct ifreq *ifr = (FAR struct ifreq *)arg;
if (!ifr || (ifr->ifr_flags & IFF_MASK) != IFF_TUN)
if (!ifr || ((ifr->ifr_flags & IFF_MASK) != IFF_TUN && (ifr->ifr_flags & IFF_MASK) != IFF_TAP))
{
return -EINVAL;
}
@ -1191,6 +1191,21 @@ static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
priv = filep->f_priv;
strncpy(ifr->ifr_name, priv->dev.d_ifname, IFNAMSIZ);
if ((ifr->ifr_flags & IFF_MASK) == IFF_TAP)
{
/* TAP device -> handling raw Ethernet packets
* -> set appropriate Ethernet header length
*/
priv->dev.d_llhdrlen = ETH_HDRLEN;
}
else if ((ifr->ifr_flags & IFF_MASK) == IFF_TUN)
{
/* TUN device -> handling an application data stream
* -> no header
*/
priv->dev.d_llhdrlen = 0;
}
tundev_unlock(tun);
return OK;

View File

@ -251,7 +251,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
#ifdef CONFIG_NET_TUN
case NET_LL_TUN: /* Virtual Network Device (TUN) */
dev->d_llhdrlen = 0;
dev->d_llhdrlen = 0; /* this will be overwritten by tun_ioctl if used as a TAP (layer 2) device */
dev->d_mtu = CONFIG_NET_TUN_MTU;
#ifdef CONFIG_NET_TCP
dev->d_recvwndo = CONFIG_NET_TUN_TCP_RECVWNDO;