Unverified Commit 1d8ddfef authored by Kroese's avatar Kroese Committed by GitHub
Browse files

fix: Do not set MTU size for legacy Windows versions (#669)

parent 6bf56aea
Loading
Loading
Loading
Loading
+30 −6
Original line number Diff line number Diff line
@@ -59,9 +59,11 @@ configureDHCP() {
      fi ;;
  esac

  if [[ "$MTU" != "0" ]] && [[ "$MTU" != "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
    info "Waiting for MAC address $VM_NET_MAC to become available..."
@@ -226,9 +228,11 @@ configureNAT() {
    error "$tuntap" && return 1
  fi

  if [[ "$MTU" != "0" ]] && [[ "$MTU" != "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/')

@@ -361,6 +365,22 @@ 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 [[ "${BOOT_MODE:-}" == "windows_legacy" ]]; then
    if [[ "$MTU" != "0" ]] && [[ "$MTU" != "1500" ]]; then
      warn "MTU size is $MTU, but cannot be set for legacy Windows versions!" && MTU="0"
    fi
  fi

  if [ -z "$MAC" ]; then
    local file="$STORAGE/$PROCESS.mac"
    [ -s "$file" ] && MAC=$(<"$file")
@@ -402,7 +422,10 @@ 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"
  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
fi
@@ -456,7 +479,8 @@ 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"
[[ "$MTU" != "0" ]] && [[ "$MTU" != "1500" ]] && NET_OPTS+=",host_mtu=$MTU"

html "Initialized network successfully..."
return 0