23 lines
778 B
Bash
23 lines
778 B
Bash
#!/usr/bin/env bash
|
|
|
|
if [[ "$(realpath "$(dirname "$(realpath -s "$0")")/../../../")" == "/" ]]; then
|
|
. /usr/local/libexec/zio-helpers
|
|
else
|
|
. "$(dirname "$(realpath -s "$0")")/../libexec/zio-helpers"
|
|
fi
|
|
|
|
vm_state="$1"
|
|
vm_ip="$2"
|
|
vm_port="$3"
|
|
vm_proto="$4"
|
|
host_port="$5"
|
|
|
|
if [ $vm_state == "stopped" ] || [ $vm_state == "reconnect" ]; then
|
|
iptables -D FORWARD -o virbr0 -p $vm_proto -d $vm_ip --dport $vm_port -j ACCEPT
|
|
iptables -t nat -D PREROUTING -p $vm_proto --dport $host_port -j DNAT --to $vm_ip:$vm_port
|
|
fi
|
|
|
|
if [ $vm_state == "start" ] || [ $vm_state == "reconnect" ]; then
|
|
iptables -I FORWARD -o virbr0 -p $vm_proto -d $vm_ip --dport $vm_port -j ACCEPT
|
|
iptables -t nat -I PREROUTING -p $vm_proto --dport $host_port -j DNAT --to $vm_ip:$vm_port
|
|
fi |