From 726786a98a05cc687bb912e4dc64a6e94d1860cf Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 9 Jul 2026 11:06:01 +0200 Subject: [PATCH] feat: Default host and user ports to TCP only (#1244) --- src/network.sh | 74 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 22 deletions(-) diff --git a/src/network.sh b/src/network.sh index 26a34ef..a480340 100644 --- a/src/network.sh +++ b/src/network.sh @@ -413,14 +413,37 @@ configureDNS() { getHostPorts() { - local list="${HOST_PORTS// /}," local ports="" local port="" + local num="" + local proto="" + local mode="${1:-tcp}" + local list="${HOST_PORTS// /}," for port in ${list//,/ }; do - port="${port%/tcp}" - port="${port%/udp}" - [ -n "$port" ] && ports+="$port," + + proto="tcp" + num="$port" + + if [[ "$port" == *"/udp" ]]; then + proto="udp" + num="${port%/udp}" + elif [[ "$port" == *"/tcp" ]]; then + proto="tcp" + num="${port%/tcp}" + fi + + [ -z "$num" ] && continue + + case "$mode" in + "all" ) + ports+="$num/$proto," ;; + "tcp" ) + [[ "$proto" == "tcp" ]] && ports+="$num," ;; + "udp" ) + [[ "$proto" == "udp" ]] && ports+="$num," ;; + esac + done # Remove duplicates @@ -432,39 +455,51 @@ getHostPorts() { getUserPorts() { - local ssh="22" - local dsm="5000,5001" + local ssh="22/tcp" + local dsm="5000/tcp,5001/tcp" local list="$ssh,$dsm," list+="${USER_PORTS// /}," - local exclude - exclude=$(getHostPorts) + local exclude="" + exclude=$(getHostPorts "all") local ports="" local userport="" local hostport="" + local proto="" + local num="" for userport in ${list//,/ }; do - local num="${userport///tcp}" - num="${num///udp}" + proto="tcp" + num="$userport" + + if [[ "$userport" == *"/udp" ]]; then + proto="udp" + num="${userport%/udp}" + elif [[ "$userport" == *"/tcp" ]]; then + proto="tcp" + num="${userport%/tcp}" + fi + + [ -z "$num" ] && continue for hostport in ${exclude//,/ }; do - local port="${hostport///tcp}" - port="${port///udp}" - - if [[ "$num" == "$port" ]]; then + if [[ "$num/$proto" == "$hostport" ]]; then num="" - if [[ "$port" != "${WEB_PORT:-}" ]]; then - warn "Could not assign port $port to \"USER_PORTS\" because it is already in \"HOST_PORTS\"!" + + if [[ "$hostport" != "${WEB_PORT:-}/tcp" ]]; then + warn "Could not assign port $hostport to \"USER_PORTS\" because it is already in \"HOST_PORTS\"!" fi + + break fi done - [ -n "$num" ] && ports+="$userport," + [ -n "$num" ] && ports+="$num/$proto," done @@ -490,10 +525,6 @@ getSlirp() { if [[ "$port" == *"/udp" ]]; then proto="udp" num="${port%/udp}" - elif [[ "$port" != *"/tcp" ]]; then - args+="hostfwd=$proto::$num-$ip:$num," - proto="udp" - num="${port%/udp}" fi args+="hostfwd=$proto::$num-$ip:$num," @@ -531,7 +562,6 @@ getPasst() { else tcp+="$port," - udp+="$port," fi