From 335f9c127f4bc35bab238f9dbe1692a91fdf51d3 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 29 Apr 2023 06:52:50 +0200 Subject: [PATCH 01/11] Print URL --- run/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/install.sh b/run/install.sh index 2add5b3..98e7ce2 100644 --- a/run/install.sh +++ b/run/install.sh @@ -34,7 +34,7 @@ rm -rf "$TMP" && mkdir -p "$TMP" LOC="$DL/release/7.0.1/42218/DSM_VirtualDSM_42218.pat" { 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 " ") From 0947e3da82afa328118abdabd9cfa826c6ddebf8 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 29 Apr 2023 09:00:43 +0200 Subject: [PATCH 02/11] Create license --- license | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 license diff --git a/license b/license new file mode 100644 index 0000000..9cf1062 --- /dev/null +++ b/license @@ -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. From 0af49abbdfa5e04471edcadd9036163b0247746c Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 29 Apr 2023 09:11:15 +0200 Subject: [PATCH 03/11] Rename license to license.md --- license => license.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename license => license.md (100%) diff --git a/license b/license.md similarity index 100% rename from license rename to license.md From fa21f29661b3d2e136d79b07983b84c87c3bdcd6 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 29 Apr 2023 17:00:49 +0200 Subject: [PATCH 04/11] Address --- run/network.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/run/network.sh b/run/network.sh index 77c5852..47a9114 100644 --- a/run/network.sh +++ b/run/network.sh @@ -48,8 +48,8 @@ configureDHCP() { ip link set "${VM_NET_TAP}" up - ip a flush "${VM_NET_DEV}" - ip a flush "${VM_NET_TAP}" + ip address flush "${VM_NET_DEV}" + ip address flush "${VM_NET_TAP}" DHCP_IP=$(dhclient -v "${VM_NET_TAP}" 2>&1 | grep ^bound | cut -d' ' -f3) @@ -112,7 +112,7 @@ configureNAT () { echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 23 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 #QEMU Works with taps, set tap to the bridge created From 859a445ede153e96875b5c9dc1c0f8546f2fc908 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 29 Apr 2023 18:43:36 +0200 Subject: [PATCH 05/11] Macvlan --- run/network.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/run/network.sh b/run/network.sh index 47a9114..099bec8 100644 --- a/run/network.sh +++ b/run/network.sh @@ -33,11 +33,11 @@ configureDHCP() { ip address add "${IP}" dev "${VM_NET_VLAN}" ip link set dev "${VM_NET_VLAN}" up - ip route flush dev "${VM_NET_DEV}" + #ip route flush dev "${VM_NET_DEV}" ip route flush dev "${VM_NET_VLAN}" - ip route add "${NETWORK}" dev "${VM_NET_VLAN}" metric 0 - ip route add default via "${GATEWAY}" + ip route add "${IP}" dev "${VM_NET_VLAN}" metric 0 + #ip route add default via "${GATEWAY}" echo "INFO: Acquiring an IP address via DHCP using MAC address ${VM_NET_MAC}..." From 18729e0675dc840b44cf8468f135936cf8dccf8d Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 29 Apr 2023 19:12:02 +0200 Subject: [PATCH 06/11] Check IP forwarding setting --- run/network.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/run/network.sh b/run/network.sh index 099bec8..588c4a9 100644 --- a/run/network.sh +++ b/run/network.sh @@ -33,11 +33,11 @@ configureDHCP() { ip address add "${IP}" dev "${VM_NET_VLAN}" ip link set dev "${VM_NET_VLAN}" up - #ip route flush dev "${VM_NET_DEV}" + ip route flush dev "${VM_NET_DEV}" ip route flush dev "${VM_NET_VLAN}" - ip route add "${IP}" dev "${VM_NET_VLAN}" metric 0 - #ip route add default via "${GATEWAY}" + ip route add "${NETWORK}" dev "${VM_NET_VLAN}" metric 0 + ip route add default via "${GATEWAY}" echo "INFO: Acquiring an IP address via DHCP using MAC address ${VM_NET_MAC}..." @@ -130,8 +130,13 @@ configureNAT () { iptables -A POSTROUTING -t mangle -p udp --dport bootpc -j CHECKSUM --checksum-fill || true fi - #Enable port forwarding flag - [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]] && sysctl -w net.ipv4.ip_forward=1 + #Check port forwarding flag + if [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]]; then + if ! sysctl -w net.ipv4.ip_forward=1; then + echo -n "ERROR: IP forwarding is disabled. Please add the following " + echo "docker setting to your container: --sysctl net.ipv4.ip_forward=1" && exit 24 + fi + fi # 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" From a441338be22a3b679090c5b114f518839571e457 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 29 Apr 2023 19:19:57 +0200 Subject: [PATCH 07/11] Check IP forwarding settings --- run/network.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/network.sh b/run/network.sh index 588c4a9..c0d7092 100644 --- a/run/network.sh +++ b/run/network.sh @@ -132,7 +132,7 @@ configureNAT () { #Check port forwarding flag if [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]]; then - if ! sysctl -w net.ipv4.ip_forward=1; then + if ! sysctl -w net.ipv4.ip_forward=1 > /dev/null 2>&1; then echo -n "ERROR: IP forwarding is disabled. Please add the following " echo "docker setting to your container: --sysctl net.ipv4.ip_forward=1" && exit 24 fi From 1fae6801f233a142e29112486e674c6ba982bfc3 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 29 Apr 2023 19:24:21 +0200 Subject: [PATCH 08/11] Display exit codes --- run/network.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/run/network.sh b/run/network.sh index c0d7092..381a5cf 100644 --- a/run/network.sh +++ b/run/network.sh @@ -26,7 +26,7 @@ configureDHCP() { 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 - echo -n "ERROR: Capability NET_ADMIN has not been set. Please add the " + echo -n "ERROR: Capability NET_ADMIN has not been set ($?). Please add the " echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 15 fi @@ -42,7 +42,7 @@ configureDHCP() { 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 - echo -n "ERROR: Capability NET_ADMIN has not been set. Please add the " + echo -n "ERROR: Capability NET_ADMIN has not been set ($?). Please add the " echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 16 fi @@ -75,12 +75,12 @@ configureDHCP() { if [[ ! -e "${TAP_PATH}" ]]; then if ! mknod "${TAP_PATH}" c "$MAJOR" "$MINOR" ; then - echo "ERROR: Cannot mknod: ${TAP_PATH}" && exit 20 + echo "ERROR: Cannot mknod: ${TAP_PATH} ($?)" && exit 20 fi fi if ! exec 30>>"$TAP_PATH"; then - echo -n "ERROR: Cannot create TAP interface. Please add the following docker settings to your " + echo -n "ERROR: Cannot create TAP interface ($?). Please add the following docker settings to your " echo "container: --device-cgroup-rule='c ${MAJOR}:* rwm' --device=/dev/vhost-net" && exit 21 fi @@ -91,7 +91,7 @@ configureDHCP() { fi if ! exec 40>>/dev/vhost-net; then - echo -n "ERROR: VHOST can not be found. Please add the following " + echo -n "ERROR: VHOST can not be found ($?). Please add the following " echo "docker setting to your container: --device=/dev/vhost-net" && exit 22 fi @@ -108,7 +108,7 @@ configureNAT () { #Create bridge with static IP for the VM guest if ! ip link add dev dockerbridge type bridge > /dev/null 2>&1 ; then - echo -n "ERROR: Capability NET_ADMIN has not been set. Please add the " + echo -n "ERROR: Capability NET_ADMIN has not been set ($?). Please add the " echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 23 fi @@ -133,7 +133,7 @@ configureNAT () { #Check port forwarding flag if [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]]; then if ! sysctl -w net.ipv4.ip_forward=1 > /dev/null 2>&1; then - echo -n "ERROR: IP forwarding is disabled. Please add the following " + echo -n "ERROR: IP forwarding is disabled ($?). Please add the following " echo "docker setting to your container: --sysctl net.ipv4.ip_forward=1" && exit 24 fi fi From 4100d6e81bff094869121ddbcde6b35c0b68e472 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 29 Apr 2023 19:27:45 +0200 Subject: [PATCH 09/11] Display exit codes --- run/network.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/run/network.sh b/run/network.sh index 381a5cf..22cbeb0 100644 --- a/run/network.sh +++ b/run/network.sh @@ -26,7 +26,7 @@ configureDHCP() { 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 - echo -n "ERROR: Capability NET_ADMIN has not been set ($?). Please add the " + echo -n "ERROR: Capability NET_ADMIN has not been set (1/$?). Please add the " echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 15 fi @@ -42,7 +42,7 @@ configureDHCP() { 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 - echo -n "ERROR: Capability NET_ADMIN has not been set ($?). Please add the " + echo -n "ERROR: Capability NET_ADMIN has not been set (2/$?). Please add the " echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 16 fi @@ -108,7 +108,7 @@ configureNAT () { #Create bridge with static IP for the VM guest if ! ip link add dev dockerbridge type bridge > /dev/null 2>&1 ; then - echo -n "ERROR: Capability NET_ADMIN has not been set ($?). Please add the " + echo -n "ERROR: Capability NET_ADMIN has not been set (3/$?). Please add the " echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 23 fi From 3fc1d04e64a0c62b82a08f356601d97acda54d07 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 29 Apr 2023 19:40:07 +0200 Subject: [PATCH 10/11] Check exit codes --- run/network.sh | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/run/network.sh b/run/network.sh index 22cbeb0..29b3fd7 100644 --- a/run/network.sh +++ b/run/network.sh @@ -25,8 +25,10 @@ configureDHCP() { 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/) - if ! ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge > /dev/null 2>&1 ; then - echo -n "ERROR: Capability NET_ADMIN has not been set (1/$?). Please add the " + { ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge > /dev/null 2>&1 ; rc=$?; } || : + + if (( rc != 0 )); then + echo -n "ERROR: Capability NET_ADMIN has not been set ($?/1). Please add the " echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 15 fi @@ -41,8 +43,10 @@ configureDHCP() { 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 - echo -n "ERROR: Capability NET_ADMIN has not been set (2/$?). Please add the " + { ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge > /dev/null 2>&1 ; rc=$?; } || : + + if (( rc != 0 )); then + echo -n "ERROR: Capability NET_ADMIN has not been set ($?/2). Please add the " echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 16 fi @@ -74,12 +78,13 @@ configureDHCP() { [[ ! -e "${TAP_PATH}" ]] && [[ -e "/dev0/${TAP_PATH##*/}" ]] && ln -s "/dev0/${TAP_PATH##*/}" "${TAP_PATH}" if [[ ! -e "${TAP_PATH}" ]]; then - if ! mknod "${TAP_PATH}" c "$MAJOR" "$MINOR" ; then - echo "ERROR: Cannot mknod: ${TAP_PATH} ($?)" && exit 20 - fi + { mknod "${TAP_PATH}" c "$MAJOR" "$MINOR" ; rc=$?; } || : + (( rc != 0 )) && echo "ERROR: Cannot mknod: ${TAP_PATH} ($?)" && exit 20 fi - if ! exec 30>>"$TAP_PATH"; then + { exec 30>>"$TAP_PATH"; rc=$?; } || : + + if (( rc != 0 )); then echo -n "ERROR: Cannot create TAP interface ($?). Please add the following docker settings to your " echo "container: --device-cgroup-rule='c ${MAJOR}:* rwm' --device=/dev/vhost-net" && exit 21 fi @@ -90,7 +95,9 @@ configureDHCP() { chmod 660 /dev/vhost-net fi - if ! exec 40>>/dev/vhost-net; then + { exec 40>>/dev/vhost-net; rc=$?; } || : + + if (( rc != 0 )); then echo -n "ERROR: VHOST can not be found ($?). Please add the following " echo "docker setting to your container: --device=/dev/vhost-net" && exit 22 fi @@ -107,8 +114,10 @@ configureNAT () { #Create bridge with static IP for the VM guest - if ! ip link add dev dockerbridge type bridge > /dev/null 2>&1 ; then - echo -n "ERROR: Capability NET_ADMIN has not been set (3/$?). Please add the " + { ip link add dev dockerbridge type bridge > /dev/null 2>&1 ; rc=$?; } || : + + if (( rc != 0 )); then + echo -n "ERROR: Capability NET_ADMIN has not been set ($?/3). Please add the " echo "following docker setting to your container: --cap-add NET_ADMIN" && exit 23 fi @@ -132,7 +141,8 @@ configureNAT () { #Check port forwarding flag if [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]]; then - if ! sysctl -w net.ipv4.ip_forward=1 > /dev/null 2>&1; then + { sysctl -w net.ipv4.ip_forward=1 > /dev/null 2>&1; rc=$?; } || : + if (( rc != 0 )); then echo -n "ERROR: IP forwarding is disabled ($?). Please add the following " echo "docker setting to your container: --sysctl net.ipv4.ip_forward=1" && exit 24 fi From 3acb93ad8165ac6421876c4b649dc303661e8f58 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 29 Apr 2023 19:44:33 +0200 Subject: [PATCH 11/11] Check exit codes --- run/network.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/run/network.sh b/run/network.sh index 29b3fd7..5783e2f 100644 --- a/run/network.sh +++ b/run/network.sh @@ -28,7 +28,7 @@ configureDHCP() { { ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge > /dev/null 2>&1 ; rc=$?; } || : if (( rc != 0 )); then - echo -n "ERROR: Capability NET_ADMIN has not been set ($?/1). Please add the " + 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 fi @@ -46,7 +46,7 @@ configureDHCP() { { ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge > /dev/null 2>&1 ; rc=$?; } || : if (( rc != 0 )); then - echo -n "ERROR: Capability NET_ADMIN has not been set ($?/2). Please add the " + 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 fi @@ -79,13 +79,13 @@ configureDHCP() { if [[ ! -e "${TAP_PATH}" ]]; then { mknod "${TAP_PATH}" c "$MAJOR" "$MINOR" ; rc=$?; } || : - (( rc != 0 )) && echo "ERROR: Cannot mknod: ${TAP_PATH} ($?)" && exit 20 + (( rc != 0 )) && echo "ERROR: Cannot mknod: ${TAP_PATH} ($rc)" && exit 20 fi { exec 30>>"$TAP_PATH"; rc=$?; } || : if (( rc != 0 )); then - echo -n "ERROR: Cannot create TAP interface ($?). Please add the following docker settings to your " + 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 fi @@ -98,7 +98,7 @@ configureDHCP() { { exec 40>>/dev/vhost-net; rc=$?; } || : if (( rc != 0 )); then - echo -n "ERROR: VHOST can not be found ($?). Please add the following " + 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 fi @@ -117,7 +117,7 @@ configureNAT () { { ip link add dev dockerbridge type bridge > /dev/null 2>&1 ; rc=$?; } || : if (( rc != 0 )); then - echo -n "ERROR: Capability NET_ADMIN has not been set ($?/3). Please add the " + 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 fi @@ -143,7 +143,7 @@ configureNAT () { 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 ($?). Please add the following " + 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