sim/tapdev: follow the tunnel MTU size
Change-Id: Ia32255517650d95ea3a675ee9fe5b69e923fb51a Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
parent
9cc2f50405
commit
8bce416c25
@ -373,6 +373,7 @@ void vpnkit_ifdown(void);
|
||||
#ifdef CONFIG_SIM_NETDEV
|
||||
int netdriver_init(void);
|
||||
void netdriver_setmacaddr(unsigned char *macaddr);
|
||||
void netdriver_setmtu(int mtu);
|
||||
void netdriver_loop(void);
|
||||
#endif
|
||||
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include <debug.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
#include <nuttx/net/net.h>
|
||||
#include <nuttx/net/netdev.h>
|
||||
@ -69,10 +70,6 @@ static struct work_s g_timer_work;
|
||||
static struct work_s g_avail_work;
|
||||
static struct work_s g_recv_work;
|
||||
|
||||
/* A single packet buffer is used */
|
||||
|
||||
static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
|
||||
|
||||
/* Ethernet peripheral state */
|
||||
|
||||
static struct net_driver_s g_sim_dev;
|
||||
@ -126,10 +123,12 @@ static void netdriver_recv_work(FAR void *arg)
|
||||
|
||||
net_lock();
|
||||
|
||||
/* netdev_read will return 0 on a timeout event and >0 on a data received event */
|
||||
/* netdev_read will return 0 on a timeout event and > 0
|
||||
* on a data received event
|
||||
*/
|
||||
|
||||
dev->d_len = netdev_read((FAR unsigned char *)dev->d_buf,
|
||||
CONFIG_NET_ETH_PKTSIZE);
|
||||
dev->d_pktsize);
|
||||
if (dev->d_len > 0)
|
||||
{
|
||||
NETDEV_RXPACKETS(dev);
|
||||
@ -149,7 +148,9 @@ static void netdriver_recv_work(FAR void *arg)
|
||||
pkt_input(dev);
|
||||
#endif /* CONFIG_NET_PKT */
|
||||
|
||||
/* We only accept IP packets of the configured type and ARP packets */
|
||||
/* We only accept IP packets of the configured type
|
||||
* and ARP packets
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
if (eth->type == HTONS(ETHTYPE_IP))
|
||||
@ -325,14 +326,29 @@ static int netdriver_txavail(FAR struct net_driver_s *dev)
|
||||
int netdriver_init(void)
|
||||
{
|
||||
FAR struct net_driver_s *dev = &g_sim_dev;
|
||||
void *pktbuf;
|
||||
int pktsize;
|
||||
|
||||
/* Internal initialization */
|
||||
|
||||
netdev_init();
|
||||
|
||||
/* Update the buffer size */
|
||||
|
||||
pktsize = dev->d_pktsize ? dev->d_pktsize :
|
||||
(MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE);
|
||||
|
||||
/* Allocate packet buffer */
|
||||
|
||||
pktbuf = kmm_malloc(pktsize);
|
||||
if (pktbuf == NULL)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Set callbacks */
|
||||
|
||||
dev->d_buf = g_pktbuf; /* Single packet buffer */
|
||||
dev->d_buf = pktbuf;
|
||||
dev->d_ifup = netdriver_ifup;
|
||||
dev->d_ifdown = netdriver_ifdown;
|
||||
dev->d_txavail = netdriver_txavail;
|
||||
@ -347,6 +363,11 @@ void netdriver_setmacaddr(unsigned char *macaddr)
|
||||
memcpy(g_sim_dev.d_mac.ether.ether_addr_octet, macaddr, IFHWADDRLEN);
|
||||
}
|
||||
|
||||
void netdriver_setmtu(int mtu)
|
||||
{
|
||||
g_sim_dev.d_pktsize = mtu;
|
||||
}
|
||||
|
||||
void netdriver_loop(void)
|
||||
{
|
||||
if (work_available(&g_recv_work) && netdev_avail())
|
||||
|
@ -92,6 +92,7 @@ struct sel_arg_struct
|
||||
****************************************************************************/
|
||||
|
||||
void netdriver_setmacaddr(unsigned char *macaddr);
|
||||
void netdriver_setmtu(int mtu);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
@ -219,15 +220,29 @@ void tapdev_init(void)
|
||||
ifr.ifr_ifindex = if_nametoindex(gdevname);
|
||||
|
||||
ret = ioctl(sockfd, SIOCBRADDIF, &ifr);
|
||||
close(sockfd);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("TAPDEV: ioctl failed (can't add interface %s to "
|
||||
"bridge %s): %d\r\n",
|
||||
gdevname, CONFIG_SIM_NET_BRIDGE_DEVICE, -ret);
|
||||
close(sockfd);
|
||||
close(tapdevfd);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ret = ioctl(sockfd, SIOCGIFMTU, &ifr);
|
||||
close(sockfd);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("TAPDEV: ioctl failed (can't get MTU "
|
||||
"from %s): %d\r\n", gdevname, -ret);
|
||||
close(tapdevfd);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
netdriver_setmtu(ifr.ifr_mtu);
|
||||
}
|
||||
#endif
|
||||
|
||||
gtapdevfd = tapdevfd;
|
||||
@ -341,7 +356,8 @@ void tapdev_ifup(in_addr_t ifaddr)
|
||||
ret = ioctl(sockfd, SIOCGIFFLAGS, (unsigned long)&ifr);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("TAPDEV: ioctl failed (can't get interface flags): %d\r\n", -ret);
|
||||
printf("TAPDEV: ioctl failed "
|
||||
"(can't get interface flags): %d\r\n", -ret);
|
||||
close(sockfd);
|
||||
return;
|
||||
}
|
||||
@ -350,7 +366,8 @@ void tapdev_ifup(in_addr_t ifaddr)
|
||||
ret = ioctl(sockfd, SIOCSIFFLAGS, (unsigned long)&ifr);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("TAPDEV: ioctl failed (can't set interface flags): %d\r\n", -ret);
|
||||
printf("TAPDEV: ioctl failed "
|
||||
"(can't set interface flags): %d\r\n", -ret);
|
||||
close(sockfd);
|
||||
return;
|
||||
}
|
||||
@ -405,7 +422,8 @@ void tapdev_ifdown(void)
|
||||
ret = ioctl(sockfd, SIOCDELRT, (unsigned long)&ghostroute);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("TAPDEV: ioctl failed (can't delete host route): %d\r\n", -ret);
|
||||
printf("TAPDEV: ioctl failed "
|
||||
"(can't delete host route): %d\r\n", -ret);
|
||||
}
|
||||
|
||||
close(sockfd);
|
||||
|
Loading…
x
Reference in New Issue
Block a user