Remove vlan code

Remove vlan code
This commit is contained in:
Kroese 2023-05-11 19:43:49 +02:00 committed by GitHub
commit daad343eec
6 changed files with 28 additions and 59 deletions

View File

@ -3,19 +3,16 @@ set -u
[ ! -f "/run/qemu.pid" ] && echo "QEMU not running yet.." && exit 0
# Retrieve IP from guest for Docker healthcheck
# Retrieve IP from guest VM for Docker healthcheck
RESPONSE=$(curl -s -m 6 -S http://127.0.0.1:2210/read?command=10 2>&1)
if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then
echo "Failed to connect to guest: $RESPONSE"
exit 1
echo "Failed to connect to guest: $RESPONSE" && exit 1
fi
# Retrieve the HTTP port number
if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then
echo "Failed to parse response from guest: $RESPONSE"
exit 1
echo "Failed to parse response from guest: $RESPONSE" && exit 1
fi
rest=${RESPONSE#*http_port}
@ -23,16 +20,11 @@ rest=${rest#*:}
rest=${rest%%,*}
PORT=${rest%%\"*}
if [ -z "${PORT}" ]; then
echo "Guest has not set a portnumber yet.."
exit 1
fi
[ -z "${PORT}" ] && echo "Guest has not set a portnumber yet.." && exit 1
# Retrieve the IP address
if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then
echo "Failed to parse response from guest: $RESPONSE"
exit 1
echo "Failed to parse response from guest: $RESPONSE" && exit 1
fi
rest=${RESPONSE#*eth0}
@ -41,15 +33,17 @@ rest=${rest#*:}
rest=${rest#*\"}
IP=${rest%%\"*}
if [ -z "${IP}" ]; then
echo "Guest has not received an IP yet.."
exit 1
fi
[ -z "${IP}" ] && echo "Guest has not received an IP yet.." && exit 1
if ! curl -m 3 -ILfSs "http://${IP}:${PORT}/" > /dev/null; then
echo "Failed to reach ${IP}:${PORT}"
exit 1
fi
if [[ "$IP" == "20.20"* ]]; then
echo "Healthcheck OK"
else
echo "Healthcheck OK ( $IP )"
fi
exit 0

View File

@ -22,49 +22,23 @@ set -Eeuo pipefail
configureDHCP() {
VM_NET_VLAN="${VM_NET_TAP}_vlan"
GATEWAY=$(ip r | grep default | awk '{print $3}')
NETWORK=$(ip -o route | grep "${VM_NET_DEV}" | grep -v default | awk '{print $1}')
IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
[[ "${DEBUG}" == [Yy1]* ]] && set -x
# Create a macvlan network to allow for communication between the host and the VM guest
{ ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge ; rc=$?; } || :
if (( rc != 0 )); then
error "Cannot create macvlan interface. Please make sure the network type is 'macvlan' and not 'ipvlan',"
error "and that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 15
fi
ip address add "${IP}" dev "${VM_NET_VLAN}"
ip link set dev "${VM_NET_VLAN}" up
ip route flush dev "${VM_NET_VLAN}"
ip route del "${NETWORK}" dev "${VM_NET_DEV}"
ip route add "${NETWORK}" dev "${VM_NET_VLAN}" metric 0
# Create a macvtap network for the VM guest
{ ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge ; rc=$?; } || :
if (( rc != 0 )); then
error "Capability NET_ADMIN has not been set most likely. Please add the "
error "following docker setting to your container: --cap-add NET_ADMIN" && exit 16
error "Cannot create macvtap interface. Please make sure the network type is 'macvlan' and not 'ipvlan',"
error "and that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 16
fi
ip link set "${VM_NET_TAP}" up
{ set +x; } 2>/dev/null
TAP_NR=$(</sys/class/net/"${VM_NET_TAP}"/ifindex)
TAP_PATH="/dev/tap${TAP_NR}"
# Create dev file (there is no udev in container: need to be done manually)
IFS=: read -r MAJOR MINOR < <(cat /sys/devices/virtual/net/"${VM_NET_TAP}"/tap*/dev)
if (( MAJOR < 1)); then
error "Cannot find: sys/devices/virtual/net/${VM_NET_TAP}" && exit 18
fi
(( MAJOR < 1)) && error "Cannot find: sys/devices/virtual/net/${VM_NET_TAP}" && exit 18
[[ ! -e "${TAP_PATH}" ]] && [[ -e "/dev0/${TAP_PATH##*/}" ]] && ln -s "/dev0/${TAP_PATH##*/}" "${TAP_PATH}"
@ -92,10 +66,11 @@ configureDHCP() {
configureNAT () {
# Create a bridge with a static IP for the VM guest
VM_NET_IP='20.20.20.21'
[[ "${DEBUG}" == [Yy1]* ]] && set -x
# Create bridge with static IP for the VM guest
{ ip link add dev dockerbridge type bridge ; rc=$?; } || :
if (( rc != 0 )); then
@ -178,6 +153,8 @@ configureNAT () {
$DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS}
{ set +x; } 2>/dev/null
[[ "${DEBUG}" == [Yy1]* ]] && echo
}
# ######################################
@ -236,6 +213,4 @@ fi
NET_OPTS="${NET_OPTS} -device virtio-net-pci,romfile=,netdev=hostnet0,mac=${VM_NET_MAC},id=net0"
[[ "${DEBUG}" == [Yy1]* ]] && echo && info "Finished network setup.." && echo
return 0

View File

@ -78,7 +78,7 @@ _graceful_shutdown() {
done
echo && info "Quitting..."
echo && echo " Quitting..."
echo 'quit' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" >/dev/null 2>&1 || true
return

View File

@ -10,11 +10,11 @@ set -Eeuo pipefail
: ${DISK_SIZE:='16G'} # Initial data disk size
: ${RAM_SIZE:='512M'} # Maximum RAM amount
echo " Starting Virtual DSM for Docker v${VERSION}..."
info () { echo -e "\E[1;34m \E[1;36m$1\E[0m" ; }
error () { echo -e >&2 "\E[1;31m ERROR: $1\E[0m" ; }
echo " Starting Virtual DSM for Docker v${VERSION}..."
trap 'error "Error status $? for: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR
trap 'error "Status $? while: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR
[ ! -f "/run/run.sh" ] && error "Script must run inside Docker container!" && exit 11
[ "$(id -u)" -ne "0" ] && error "Script must be executed with root privileges." && exit 12
@ -61,7 +61,7 @@ else
fi
if [ -n "${KVM_ERR}" ]; then
error "KVM acceleration not detected ${KVM_ERR}, please enable it."
error "KVM acceleration not detected ${KVM_ERR}, see the FAQ about this."
[[ "${DEBUG}" == [Yy1]* ]] && exit 88
else
KVM_OPTS=",accel=kvm -enable-kvm -cpu host"