mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2026-08-28 20:06:05 +00:00
feat: Default host and user ports to TCP only (#1244)
This commit is contained in:
+52
-22
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user