fix: Display MTU value

This commit is contained in:
Kroese 2025-03-04 15:21:30 +01:00 committed by GitHub
parent c8f19d5ee9
commit 0b95e020b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -59,7 +59,7 @@ configureDHCP() {
fi ;;
esac
if [ -n "$MTU" ] && [[ "$MTU" != "0" ]] && [ "$MTU" -lt "1500" ]; then
if [ -n "$MTU" ] && [[ "$MTU" != "0" ]] && [[ "$MTU" != "1500" ]]; then
if ! ip link set dev "$VM_NET_TAP" mtu "$MTU"; then
warn "Failed to set MTU size.."
fi
@ -220,7 +220,7 @@ configureNAT() {
error "$tuntap" && return 1
fi
if [ -n "$MTU" ] && [[ "$MTU" != "0" ]] && [ "$MTU" -lt "1500" ]; then
if [ -n "$MTU" ] && [[ "$MTU" != "0" ]] && [[ "$MTU" != "1500" ]]; then
if ! ip link set dev "$VM_NET_TAP" mtu "$MTU"; then
warn "Failed to set MTU size.."
fi
@ -361,6 +361,16 @@ getInfo() {
MTU=$(cat "/sys/class/net/$VM_NET_DEV/mtu")
fi
if [ "$MTU" -gt "1500" ]; then
info "MTU size is too large: $MTU, ignoring..." && MTU="0"
fi
if [[ "${ADAPTER,,}" != "virtio-net-pci" ]]; then
if [[ "$MTU" != "0" ]] && [[ "$MTU" != "1500" ]]; then
warn "MTU size is $MTU, but cannot be set for $ADAPTER adapters!" && MTU="0"
fi
fi
if [ -z "$VM_NET_MAC" ]; then
local file="$STORAGE/dsm.mac"
[ -s "$file" ] && VM_NET_MAC=$(<"$file")
@ -390,23 +400,6 @@ getInfo() {
return 0
}
setMTU() {
[ -z "$MTU" ] && return 0
[[ "$MTU" == "0" ]] && return 0
[[ "$MTU" == "1500" ]] && return 0
if [[ "${ADAPTER,,}" != "virtio-net-pci" ]]; then
warn "MTU size is $MTU, but cannot be set for $ADAPTER adapters!" && return 0
fi
if [ "$MTU" -gt "1500" ]; then
info "MTU size is too large: $MTU, ignoring..." && return 0
fi
NET_OPTS+=",host_mtu=$MTU"
}
# ######################################
# Configure Network
# ######################################
@ -420,8 +413,9 @@ getInfo
html "Initializing network..."
if [[ "$DEBUG" == [Yy1]* ]]; then
line="Host: $HOST IP: $IP Gateway: $GATEWAY Interface: $VM_NET_DEV MAC: $VM_NET_MAC"
[ -n "$MTU" ] && [[ "$MTU" != "0" ]] && [[ "$MTU" != "1500" ]] && line+=" MTU: $MTU"
mtu=$(cat "/sys/class/net/$VM_NET_DEV/mtu")
line="Host: $HOST IP: $IP Gateway: $GATEWAY Interface: $VM_NET_DEV MAC: $VM_NET_MAC MTU: $mtu"
[[ "$MTU" != "0" ]] && [[ "$MTU" != "$mtu" ]] && line+=" ($MTU)"
info "$line"
[ -f /etc/resolv.conf ] && grep '^nameserver*' /etc/resolv.conf
echo
@ -488,6 +482,6 @@ else
fi
NET_OPTS+=" -device $ADAPTER,id=net0,netdev=hostnet0,romfile=,mac=$VM_NET_MAC"
setMTU
[[ "$MTU" != "0" ]] && NET_OPTS+=",host_mtu=$MTU"
return 0