Skip to content

Commit

Permalink
Remove vlan code
Browse files Browse the repository at this point in the history
Remove vlan code
  • Loading branch information
kroese committed May 11, 2023
2 parents 90308d9 + ab2cc51 commit 790edae
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 59 deletions.
30 changes: 12 additions & 18 deletions run/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,28 @@ 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}
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}
Expand All @@ -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

echo "Healthcheck OK ($IP)"
if [[ "$IP" == "20.20"* ]]; then
echo "Healthcheck OK"
else
echo "Healthcheck OK ( $IP )"
fi

exit 0
2 changes: 1 addition & 1 deletion run/disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -Eeuo pipefail

# Docker environment variables

: ${DISK_IO:='native'} # I/O Mode, can be set to 'native', 'threads' or 'io_turing'
: ${DISK_IO:='native'} # I/O Mode, can be set to 'native', 'threads' or 'io_turing'
: ${DISK_CACHE:='none'} # Caching mode, can be set to 'writeback' for better performance
: ${DISK_DISCARD:='on'} # Controls whether unmap (TRIM) commands are passed to the host.
: ${DISK_ROTATION:='1'} # Rotation rate, set to 1 for SSD storage and increase for HDD
Expand Down
43 changes: 9 additions & 34 deletions run/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=$?; } || :

{ 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}"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -178,6 +153,8 @@ configureNAT () {
$DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS}

{ set +x; } 2>/dev/null

[[ "${DEBUG}" == [Yy1]* ]] && echo
}

# ######################################
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion run/power.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions run/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion run/server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trap 'stop' EXIT SIGINT SIGTERM SIGHUP

html()
{
local h="<!DOCTYPE html><HTML><HEAD><TITLE>VirtualDSM</TITLE>"
local h="<!DOCTYPE html><HTML><HEAD><TITLE>VirtualDSM</TITLE>"
h="${h} <STYLE>body { color: white; background-color: #125bdb; font-family: Verdana,"
h="${h} Arial,sans-serif; } a, a:hover, a:active, a:visited { color: white; }</STYLE></HEAD>"
h="${h}<BODY><BR><BR><H1><CENTER>$1</CENTER></H1></BODY></HTML>"
Expand Down

0 comments on commit 790edae

Please sign in to comment.