mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-11-05 17:44:52 +08:00
Compare commits
2 Commits
c70e12f0a2
...
ea49cb144b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea49cb144b | ||
|
|
b8e778a79d |
@ -185,26 +185,68 @@ configureDNS() {
|
||||
|
||||
getHostPorts() {
|
||||
|
||||
local list="$1"
|
||||
local list="${HOST_PORTS:-}"
|
||||
list=$(echo "${list// /}" | sed 's/,*$//g')
|
||||
list="${list//,,/,}"
|
||||
|
||||
[ -z "$list" ] && list="$MON_PORT" || list+=",$MON_PORT"
|
||||
|
||||
# Remove duplicates
|
||||
list=$(echo "$list," | awk 'BEGIN{RS=ORS=","} !seen[$0]++' | sed 's/,*$//g')
|
||||
|
||||
echo "$list"
|
||||
return 0
|
||||
}
|
||||
|
||||
getUserPorts() {
|
||||
|
||||
local args=""
|
||||
local list=$1
|
||||
local list="${USER_PORTS:-}"
|
||||
list=$(echo "${list// /}" | sed 's/,*$//g')
|
||||
|
||||
local ssh="22"
|
||||
local dsm="5000"
|
||||
local dsm="5000,5001"
|
||||
[ -z "$list" ] && list="$ssh,$dsm" || list+=",$ssh,$dsm"
|
||||
|
||||
echo "$list"
|
||||
list="${list//,,/,}"
|
||||
list="${list//,/ }"
|
||||
list="${list## }"
|
||||
list="${list%% }"
|
||||
|
||||
local exclude
|
||||
exclude=$(getHostPorts)
|
||||
exclude="${exclude//,/ }"
|
||||
exclude="${exclude## }"
|
||||
exclude="${exclude%% }"
|
||||
|
||||
local ports=""
|
||||
|
||||
for userport in $list; do
|
||||
|
||||
local num="${userport///tcp}"
|
||||
num="${num///udp}"
|
||||
[ -z "$num" ] && continue
|
||||
|
||||
for hostport in $exclude; do
|
||||
|
||||
local val="${hostport///tcp}"
|
||||
|
||||
if [[ "$num" == "${val///udp}" ]]; then
|
||||
num=""
|
||||
warn "Could not assign port ${val///udp} to \"USER_PORTS\" because it is already in \"HOST_PORTS\"!"
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
if [ -n "$num" ]; then
|
||||
[ -z "$ports" ] && ports="$userport" || ports+=",$userport"
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
# Remove duplicates
|
||||
ports=$(echo "$ports," | awk 'BEGIN{RS=ORS=","} !seen[$0]++' | sed 's/,*$//g')
|
||||
|
||||
echo "$ports"
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -220,8 +262,8 @@ getSlirp() {
|
||||
|
||||
for port in $list; do
|
||||
|
||||
proto="tcp"
|
||||
num="${port%/tcp}"
|
||||
local proto="tcp"
|
||||
local num="${port%/tcp}"
|
||||
|
||||
if [[ "$port" == *"/udp" ]]; then
|
||||
proto="udp"
|
||||
@ -235,6 +277,8 @@ getSlirp() {
|
||||
args+="hostfwd=$proto::$num-$VM_NET_IP:$num,"
|
||||
done
|
||||
|
||||
args=$(echo "$args" | sed 's/,*$//g')
|
||||
|
||||
echo "${args%?}"
|
||||
return 0
|
||||
}
|
||||
@ -255,7 +299,7 @@ configureSlirp() {
|
||||
NET_OPTS="-netdev user,id=hostnet0,ipv4=on,host=$gateway,net=${gateway%.*}.0/24,dhcpstart=$ip,${ipv6}hostname=$VM_NET_HOST"
|
||||
|
||||
local forward=""
|
||||
forward=$(getUserPorts "${USER_PORTS:-}")
|
||||
forward=$(getSlirp)
|
||||
[ -n "$forward" ] && NET_OPTS+=",$forward"
|
||||
|
||||
if [[ "${DNSMASQ_DISABLE:-}" == [Yy1]* ]]; then
|
||||
@ -299,7 +343,7 @@ configurePasst() {
|
||||
[ -n "$PASST_MTU" ] && PASST_OPTS+=" -m $PASST_MTU"
|
||||
|
||||
local forward=""
|
||||
forward=$(getUserPorts "${USER_PORTS:-}")
|
||||
forward=$(getUserPorts)
|
||||
forward="${forward///tcp}"
|
||||
forward="${forward///udp}"
|
||||
|
||||
@ -447,7 +491,7 @@ configureNAT() {
|
||||
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null
|
||||
fi
|
||||
|
||||
exclude=$(getHostPorts "$HOST_PORTS")
|
||||
exclude=$(getHostPorts)
|
||||
|
||||
if [ -n "$exclude" ]; then
|
||||
if [[ "$exclude" != *","* ]]; then
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user