sim/net: Support to set the MTU of the sim netdevice.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
This commit is contained in:
liqinhui 2024-05-08 17:13:12 +08:00 committed by Alan Carvalho de Assis
parent e3056c781e
commit 45fc68e904
3 changed files with 22 additions and 3 deletions

View file

@ -223,6 +223,14 @@ config SIM_NETDEV_VPNKIT
endchoice
config SIM_NETDEV_MTU
int "The MTU of Simulated Network Device"
default 1500
range 1280 65535 if NET_IPv6
range 576 65535 if !NET_IPv6
---help---
The MTU of the network devices.
config SIM_NETDEV_NUMBER
int "Number of Simulated Network Device"
default 1

View file

@ -249,10 +249,20 @@ void sim_tapdev_init(int devidx, void *priv,
close(tapdevfd);
return;
}
#else
#endif
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, gdevname[devidx], IFNAMSIZ);
#endif
ifr.ifr_mtu = CONFIG_SIM_NETDEV_MTU;
ret = ioctl(sockfd, SIOCSIFMTU, &ifr);
if (ret < 0)
{
syslog(LOG_ERR, "TAPDEV: ioctl failed (can't set MTU "
"for %s): %d\n", gdevname[devidx], -ret);
close(sockfd);
close(tapdevfd);
return;
}
ret = ioctl(sockfd, SIOCGIFMTU, &ifr);
close(sockfd);

View file

@ -71,7 +71,8 @@
#include "sim_internal.h"
#define SIM_NETDEV_BUFSIZE (MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE)
#define SIM_NETDEV_BUFSIZE (CONFIG_SIM_NETDEV_MTU + ETH_HDRLEN + \
CONFIG_NET_GUARDSIZE)
/* We don't know packet length before receiving, so we can only offload it
* when netpkt's buffer is long enough.