mirror of
https://github.com/apache/nuttx.git
synced 2026-05-21 13:13:08 +08:00
Add TUN device. From Max Neklyudov
This commit is contained in:
@@ -67,6 +67,10 @@ ifeq ($(CONFIG_NET_SLIP),y)
|
||||
CSRCS += slip.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NET_TUN),y)
|
||||
CSRCS += tun.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ARCH_PHY_INTERRUPT),y)
|
||||
CSRCS += phy_notify.c
|
||||
endif
|
||||
|
||||
+1252
File diff suppressed because it is too large
Load Diff
@@ -73,7 +73,8 @@ enum net_lltype_e
|
||||
{
|
||||
NET_LL_ETHERNET = 0, /* Ethernet */
|
||||
NET_LL_SLIP, /* Serial Line Internet Protocol (SLIP) */
|
||||
NET_LL_PPP /* Point-to-Point Protocol (PPP) */
|
||||
NET_LL_PPP, /* Point-to-Point Protocol (PPP) */
|
||||
NET_LL_TUN, /* TUN Virtual Network Device */
|
||||
};
|
||||
|
||||
/* This defines a bitmap big enough for one bit for each socket option */
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/net/tun.h
|
||||
*
|
||||
* Copyright (C) 2015 Max Nekludov. All rights reserved.
|
||||
* Author : Max Nekludov <macscomp@gmail.com>
|
||||
*
|
||||
* Includes some definitions that a compatible with the LGPL GNU C Library
|
||||
* header file of the same name.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_NET_TUN_H
|
||||
#define __INCLUDE_NUTTX_NET_TUN_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/net/ioctl.h>
|
||||
|
||||
#ifdef CONFIG_NET_TUN
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define TUNSETIFF _SIOC(0x1001)
|
||||
|
||||
/* TUNSETIFF ifr flags */
|
||||
|
||||
#define IFF_TUN 0x0001
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: tun_initialize
|
||||
*
|
||||
* Description:
|
||||
* Instantiate a SLIP network interface.
|
||||
*
|
||||
* Parameters:
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; Negated errno on failure.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int tun_initialize(void);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_NET_TUN */
|
||||
#endif /* __INCLUDE_NUTTX_NET_TUN_H */
|
||||
+36
@@ -102,6 +102,17 @@ config NET_SLIP_TCP_RECVWNDO
|
||||
incoming data, or high (32768 bytes) if the application processes
|
||||
data quickly.
|
||||
|
||||
config NET_TUN_MTU
|
||||
int "TUN packet buffer size (MTU)"
|
||||
default 296
|
||||
depends on NET_TUN
|
||||
range 296 1518
|
||||
|
||||
config NET_TUN_TCP_RECVWNDO
|
||||
int "TUN TCP receive window size"
|
||||
default 256
|
||||
depends on NET_TUN && NET_TCP
|
||||
|
||||
config NET_GUARDSIZE
|
||||
int "Driver I/O guard size"
|
||||
default 2
|
||||
@@ -121,6 +132,13 @@ config NET_MULTILINK
|
||||
bool
|
||||
default n
|
||||
|
||||
config NET_USER_DEVFMT
|
||||
bool "User provided devfmt"
|
||||
default n
|
||||
depends on EXPERIMENTAL
|
||||
---help---
|
||||
netdev_register will get devfmt form d_ifname if it is initialized.
|
||||
|
||||
config NET_ETHERNET
|
||||
bool "Ethernet support"
|
||||
default y if !NET_SLIP
|
||||
@@ -179,6 +197,24 @@ config SLIP_DEFPRIO
|
||||
The priority of the SLIP RX and TX tasks. Default: 128
|
||||
|
||||
endif # NET_SLIP
|
||||
|
||||
config NET_TUN
|
||||
bool "TUN Virtual Network Device support"
|
||||
default n
|
||||
|
||||
if NET_TUN
|
||||
|
||||
config TUN_NINTERFACES
|
||||
int "Number of TUN interfaces"
|
||||
default 1
|
||||
range 1 8
|
||||
---help---
|
||||
Selects the number of TUN
|
||||
interfaces to support.
|
||||
Default: 1
|
||||
|
||||
endif # NET_TUN
|
||||
|
||||
endmenu # Data link support
|
||||
|
||||
source "net/netdev/Kconfig"
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user