Add TUN device. From Max Neklyudov

This commit is contained in:
Gregory Nutt
2015-03-11 06:52:56 -06:00
parent 834072815b
commit 21d6e41032
6 changed files with 1421 additions and 1 deletions
+23
View File
@@ -62,6 +62,7 @@
#define NETDEV_SLIP_FORMAT "sl%d"
#define NETDEV_ETH_FORMAT "eth%d"
#define NETDEV_TUN_FORMAT "tun%d"
#if defined(CONFIG_NET_SLIP)
# define NETDEV_DEFAULT_FORMAT NETDEV_SLIP_FORMAT
@@ -171,6 +172,9 @@ static int find_devnum(FAR const char *devfmt)
int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
{
FAR const char *devfmt;
#ifdef CONFIG_NET_USER_DEVFMT
FAR const char devfmt_str[IFNAMSIZ];
#endif
int devnum;
if (dev)
@@ -206,6 +210,17 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
break;
#endif
#ifdef CONFIG_NET_TUN
case NET_LL_TUN: /* Virtual Network Device (TUN) */
dev->d_llhdrlen = 0;
dev->d_mtu = CONFIG_NET_TUN_MTU;
#ifdef CONFIG_NET_TCP
dev->d_recvwndo = CONFIG_NET_TUN_TCP_RECVWNDO;
#endif
devfmt = NETDEV_TUN_FORMAT;
break;
#endif
#if 0 /* REVISIT: Not yet supported */
case NET_LL_PPP: /* Point-to-Point Protocol (PPP) */
dev->d_llhdrlen = 0;
@@ -242,6 +257,14 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
#else
devnum = g_next_devnum++;
#endif
#ifdef CONFIG_NET_USER_DEVFMT
if (*dev->d_ifname)
{
strncpy(devfmt_str, dev->d_ifname, IFNAMSIZ);
devfmt = devfmt_str;
}
#endif
snprintf(dev->d_ifname, IFNAMSIZ, devfmt, devnum );
/* Add the device to the list of known network devices */