Compare commits

...

3 Commits

Author SHA1 Message Date
Kroese
3675a50129
fix: Gateway MAC generation (#910)
Some checks are pending
Build / Check (push) Waiting to run
Build / Build (push) Blocked by required conditions
2025-03-03 13:57:53 +01:00
Kroese
91229152bd
feat: Set MTU size for TAP interface (#909) 2025-03-03 13:40:15 +01:00
Kroese
a1993e590a
feat: Automaticly match MTU size (#908) 2025-03-03 12:20:16 +01:00
2 changed files with 17 additions and 4 deletions

View File

@ -37,6 +37,7 @@ RUN set -eu && extra="" && \
net-tools \ net-tools \
e2fsprogs \ e2fsprogs \
qemu-utils \ qemu-utils \
iputils-ping \
ca-certificates \ ca-certificates \
netcat-openbsd \ netcat-openbsd \
qemu-system-x86 \ qemu-system-x86 \

View File

@ -4,6 +4,7 @@ set -Eeuo pipefail
# Docker environment variables # Docker environment variables
: "${MAC:=""}" : "${MAC:=""}"
: "${MTU:=""}"
: "${DHCP:="N"}" : "${DHCP:="N"}"
: "${NETWORK:="Y"}" : "${NETWORK:="Y"}"
: "${USER_PORTS:=""}" : "${USER_PORTS:=""}"
@ -58,6 +59,10 @@ configureDHCP() {
fi ;; fi ;;
esac esac
if ! ip link set dev "$VM_NET_TAP" mtu "$MTU"; then
warn "Failed to set MTU size.."
fi
while ! ip link set "$VM_NET_TAP" up; do while ! ip link set "$VM_NET_TAP" up; do
info "Waiting for MAC address $VM_NET_MAC to become available..." info "Waiting for MAC address $VM_NET_MAC to become available..."
sleep 2 sleep 2
@ -213,8 +218,11 @@ configureNAT() {
error "$tuntap" && return 1 error "$tuntap" && return 1
fi fi
GATEWAY_MAC=$(echo "$VM_NET_MAC" | rev) if ! ip link set dev "$VM_NET_TAP" mtu "$MTU"; then
GATEWAY_MAC="02:${GATEWAY_MAC:0:14}" warn "Failed to set MTU size.."
fi
GATEWAY_MAC=$(echo "$VM_NET_MAC" | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/')
if ! ip link set dev "$VM_NET_TAP" address "$GATEWAY_MAC"; then if ! ip link set dev "$VM_NET_TAP" address "$GATEWAY_MAC"; then
warn "Failed to set gateway MAC address.." warn "Failed to set gateway MAC address.."
@ -345,6 +353,10 @@ getInfo() {
error "$ADD_ERR -e \"VM_NET_DEV=NAME\" to specify another interface name." && exit 27 error "$ADD_ERR -e \"VM_NET_DEV=NAME\" to specify another interface name." && exit 27
fi fi
if [ -z "$MTU" ]; then
MTU=$(cat "/sys/class/net/$VM_NET_DEV/mtu")
fi
if [ -z "$VM_NET_MAC" ]; then if [ -z "$VM_NET_MAC" ]; then
local file="$STORAGE/dsm.mac" local file="$STORAGE/dsm.mac"
[ -s "$file" ] && VM_NET_MAC=$(<"$file") [ -s "$file" ] && VM_NET_MAC=$(<"$file")
@ -387,7 +399,7 @@ getInfo
html "Initializing network..." html "Initializing network..."
if [[ "$DEBUG" == [Yy1]* ]]; then if [[ "$DEBUG" == [Yy1]* ]]; then
info "Host: $HOST IP: $IP Gateway: $GATEWAY Interface: $VM_NET_DEV MAC: $VM_NET_MAC" info "Host: $HOST IP: $IP Gateway: $GATEWAY Interface: $VM_NET_DEV MAC: $VM_NET_MAC MTU: $MTU"
[ -f /etc/resolv.conf ] && grep '^nameserver*' /etc/resolv.conf [ -f /etc/resolv.conf ] && grep '^nameserver*' /etc/resolv.conf
echo echo
fi fi
@ -452,6 +464,6 @@ else
fi fi
NET_OPTS+=" -device $ADAPTER,romfile=,netdev=hostnet0,mac=$VM_NET_MAC,id=net0" NET_OPTS+=" -device $ADAPTER,romfile=,netdev=hostnet0,mac=$VM_NET_MAC,host_mtu=$MTU,id=net0"
return 0 return 0