fix: Check MTU size

This commit is contained in:
Kroese 2025-03-04 14:50:48 +01:00 committed by GitHub
parent 3675a50129
commit c8f19d5ee9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -59,8 +59,10 @@ configureDHCP() {
fi ;;
esac
if ! ip link set dev "$VM_NET_TAP" mtu "$MTU"; then
warn "Failed to set MTU size.."
if [ -n "$MTU" ] && [[ "$MTU" != "0" ]] && [ "$MTU" -lt "1500" ]; then
if ! ip link set dev "$VM_NET_TAP" mtu "$MTU"; then
warn "Failed to set MTU size.."
fi
fi
while ! ip link set "$VM_NET_TAP" up; do
@ -218,8 +220,10 @@ configureNAT() {
error "$tuntap" && return 1
fi
if ! ip link set dev "$VM_NET_TAP" mtu "$MTU"; then
warn "Failed to set MTU size.."
if [ -n "$MTU" ] && [[ "$MTU" != "0" ]] && [ "$MTU" -lt "1500" ]; then
if ! ip link set dev "$VM_NET_TAP" mtu "$MTU"; then
warn "Failed to set MTU size.."
fi
fi
GATEWAY_MAC=$(echo "$VM_NET_MAC" | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/')
@ -386,6 +390,23 @@ 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
# ######################################
@ -399,7 +420,9 @@ getInfo
html "Initializing network..."
if [[ "$DEBUG" == [Yy1]* ]]; then
info "Host: $HOST IP: $IP Gateway: $GATEWAY Interface: $VM_NET_DEV MAC: $VM_NET_MAC MTU: $MTU"
line="Host: $HOST IP: $IP Gateway: $GATEWAY Interface: $VM_NET_DEV MAC: $VM_NET_MAC"
[ -n "$MTU" ] && [[ "$MTU" != "0" ]] && [[ "$MTU" != "1500" ]] && line+=" MTU: $MTU"
info "$line"
[ -f /etc/resolv.conf ] && grep '^nameserver*' /etc/resolv.conf
echo
fi
@ -464,6 +487,7 @@ else
fi
NET_OPTS+=" -device $ADAPTER,romfile=,netdev=hostnet0,mac=$VM_NET_MAC,host_mtu=$MTU,id=net0"
NET_OPTS+=" -device $ADAPTER,id=net0,netdev=hostnet0,romfile=,mac=$VM_NET_MAC"
setMTU
return 0