Display network exit codes

Display network exit codes
This commit is contained in:
Kroese 2023-04-29 19:52:36 +02:00 committed by GitHub
commit ba0af3bec1
3 changed files with 53 additions and 19 deletions

19
license.md Normal file
View File

@ -0,0 +1,19 @@
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -34,7 +34,7 @@ rm -rf "$TMP" && mkdir -p "$TMP"
LOC="$DL/release/7.0.1/42218/DSM_VirtualDSM_42218.pat" LOC="$DL/release/7.0.1/42218/DSM_VirtualDSM_42218.pat"
{ curl -r 64493568-69886247 -sfk -o "$RD" "$LOC"; rc=$?; } || : { curl -r 64493568-69886247 -sfk -o "$RD" "$LOC"; rc=$?; } || :
(( rc != 0 )) && echo "ERROR: Failed to download extractor, reason: $rc" && exit 60 (( rc != 0 )) && echo "ERROR: Failed to download $LOC, reason: $rc" && exit 60
SUM=$(md5sum "$RD" | cut -f 1 -d " ") SUM=$(md5sum "$RD" | cut -f 1 -d " ")

View File

@ -25,8 +25,10 @@ configureDHCP() {
NETWORK=$(ip -o route | grep "${VM_NET_DEV}" | grep -v default | awk '{print $1}') 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/) IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
if ! ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge > /dev/null 2>&1 ; then { ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge > /dev/null 2>&1 ; rc=$?; } || :
echo -n "ERROR: Capability NET_ADMIN has not been set. Please add the "
if (( rc != 0 )); then
echo -n "ERROR: Capability NET_ADMIN has not been set ($rc/1). Please add the "
echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 15 echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 15
fi fi
@ -41,15 +43,17 @@ configureDHCP() {
echo "INFO: Acquiring an IP address via DHCP using MAC address ${VM_NET_MAC}..." echo "INFO: Acquiring an IP address via DHCP using MAC address ${VM_NET_MAC}..."
if ! ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge > /dev/null 2>&1 ; then { ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge > /dev/null 2>&1 ; rc=$?; } || :
echo -n "ERROR: Capability NET_ADMIN has not been set. Please add the "
if (( rc != 0 )); then
echo -n "ERROR: Capability NET_ADMIN has not been set ($rc/2). Please add the "
echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 16 echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 16
fi fi
ip link set "${VM_NET_TAP}" up ip link set "${VM_NET_TAP}" up
ip a flush "${VM_NET_DEV}" ip address flush "${VM_NET_DEV}"
ip a flush "${VM_NET_TAP}" ip address flush "${VM_NET_TAP}"
DHCP_IP=$(dhclient -v "${VM_NET_TAP}" 2>&1 | grep ^bound | cut -d' ' -f3) DHCP_IP=$(dhclient -v "${VM_NET_TAP}" 2>&1 | grep ^bound | cut -d' ' -f3)
@ -74,13 +78,14 @@ configureDHCP() {
[[ ! -e "${TAP_PATH}" ]] && [[ -e "/dev0/${TAP_PATH##*/}" ]] && ln -s "/dev0/${TAP_PATH##*/}" "${TAP_PATH}" [[ ! -e "${TAP_PATH}" ]] && [[ -e "/dev0/${TAP_PATH##*/}" ]] && ln -s "/dev0/${TAP_PATH##*/}" "${TAP_PATH}"
if [[ ! -e "${TAP_PATH}" ]]; then if [[ ! -e "${TAP_PATH}" ]]; then
if ! mknod "${TAP_PATH}" c "$MAJOR" "$MINOR" ; then { mknod "${TAP_PATH}" c "$MAJOR" "$MINOR" ; rc=$?; } || :
echo "ERROR: Cannot mknod: ${TAP_PATH}" && exit 20 (( rc != 0 )) && echo "ERROR: Cannot mknod: ${TAP_PATH} ($rc)" && exit 20
fi
fi fi
if ! exec 30>>"$TAP_PATH"; then { exec 30>>"$TAP_PATH"; rc=$?; } || :
echo -n "ERROR: Cannot create TAP interface. Please add the following docker settings to your "
if (( rc != 0 )); then
echo -n "ERROR: Cannot create TAP interface ($rc). Please add the following docker settings to your "
echo "container: --device-cgroup-rule='c ${MAJOR}:* rwm' --device=/dev/vhost-net" && exit 21 echo "container: --device-cgroup-rule='c ${MAJOR}:* rwm' --device=/dev/vhost-net" && exit 21
fi fi
@ -90,8 +95,10 @@ configureDHCP() {
chmod 660 /dev/vhost-net chmod 660 /dev/vhost-net
fi fi
if ! exec 40>>/dev/vhost-net; then { exec 40>>/dev/vhost-net; rc=$?; } || :
echo -n "ERROR: VHOST can not be found. Please add the following "
if (( rc != 0 )); then
echo -n "ERROR: VHOST can not be found ($rc). Please add the following "
echo "docker setting to your container: --device=/dev/vhost-net" && exit 22 echo "docker setting to your container: --device=/dev/vhost-net" && exit 22
fi fi
@ -107,12 +114,14 @@ configureNAT () {
#Create bridge with static IP for the VM guest #Create bridge with static IP for the VM guest
if ! ip link add dev dockerbridge type bridge > /dev/null 2>&1 ; then { ip link add dev dockerbridge type bridge > /dev/null 2>&1 ; rc=$?; } || :
echo -n "ERROR: Capability NET_ADMIN has not been set. Please add the "
if (( rc != 0 )); then
echo -n "ERROR: Capability NET_ADMIN has not been set ($rc/3). Please add the "
echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 23 echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 23
fi fi
ip addr add ${VM_NET_IP%.*}.1/24 broadcast ${VM_NET_IP%.*}.255 dev dockerbridge ip address add ${VM_NET_IP%.*}.1/24 broadcast ${VM_NET_IP%.*}.255 dev dockerbridge
ip link set dockerbridge up ip link set dockerbridge up
#QEMU Works with taps, set tap to the bridge created #QEMU Works with taps, set tap to the bridge created
@ -130,8 +139,14 @@ configureNAT () {
iptables -A POSTROUTING -t mangle -p udp --dport bootpc -j CHECKSUM --checksum-fill || true iptables -A POSTROUTING -t mangle -p udp --dport bootpc -j CHECKSUM --checksum-fill || true
fi fi
#Enable port forwarding flag #Check port forwarding flag
[[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]] && sysctl -w net.ipv4.ip_forward=1 if [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]]; then
{ sysctl -w net.ipv4.ip_forward=1 > /dev/null 2>&1; rc=$?; } || :
if (( rc != 0 )); then
echo -n "ERROR: IP forwarding is disabled ($rc). Please add the following "
echo "docker setting to your container: --sysctl net.ipv4.ip_forward=1" && exit 24
fi
fi
# dnsmasq configuration: # dnsmasq configuration:
DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-range=$VM_NET_IP,$VM_NET_IP --dhcp-host=$VM_NET_MAC,,$VM_NET_IP,$VM_NET_HOST,infinite --dhcp-option=option:netmask,255.255.255.0" DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-range=$VM_NET_IP,$VM_NET_IP --dhcp-host=$VM_NET_MAC,,$VM_NET_IP,$VM_NET_HOST,infinite --dhcp-option=option:netmask,255.255.255.0"