From a1be2e5f0be6baeb263a8f0eb3cac9df4cd1f5b9 Mon Sep 17 00:00:00 2001 From: timerzz Date: Fri, 10 Oct 2025 10:50:36 +0800 Subject: [PATCH 1/2] feat: allow ip not exist In CNI, MACVLAN can be used only as a Layer 2 network without assigning an IP address. In this case, the container will not be assigned an IP address, but the VM will obtain an IP address using DHCP. Therefore, it is necessary to allow the IP address to be empty. --- src/network.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network.sh b/src/network.sh index ea2e5a7d..9110ff72 100644 --- a/src/network.sh +++ b/src/network.sh @@ -644,7 +644,7 @@ getInfo() { fi GATEWAY=$(ip route list dev "$VM_NET_DEV" | awk ' /^default/ {print $3}' | head -n 1) - IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/ | head -n 1) + IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/ | head -n 1) || IP="" IP6="" # shellcheck disable=SC2143 From f09e44b2db8ea1478b075ea8b1aad47eb14aac78 Mon Sep 17 00:00:00 2001 From: Kroese Date: Fri, 10 Oct 2025 07:01:34 +0200 Subject: [PATCH 2/2] Update network.sh --- src/network.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/network.sh b/src/network.sh index 9110ff72..3be31985 100644 --- a/src/network.sh +++ b/src/network.sh @@ -644,12 +644,17 @@ getInfo() { fi GATEWAY=$(ip route list dev "$VM_NET_DEV" | awk ' /^default/ {print $3}' | head -n 1) - IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/ | head -n 1) || IP="" - IP6="" + { IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/ | head -n 1); rc=$?; } 2>/dev/null || : + + if (( rc != 0 )) && [[ "$DHCP" != [Yy1]* ]]; then + error "Could not determine container IP address!" && exit 26 + fi + IP6="" # shellcheck disable=SC2143 if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then - IP6=$(ip -6 addr show dev "$VM_NET_DEV" scope global up) + { IP6=$(ip -6 addr show dev "$VM_NET_DEV" scope global up); rc=$?; } 2>/dev/null || : + (( rc != 0 )) && IP6="" [ -n "$IP6" ] && IP6=$(echo "$IP6" | sed -e's/^.*inet6 \([^ ]*\)\/.*$/\1/;t;d' | head -n 1) fi