Skip to content

Commit 5c98be5

Browse files
author
3np
committed
refactor qubes-ns generation in network-proxy-setup.sh
1 parent 0541c27 commit 5c98be5

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

vm-systemd/network-proxy-setup.sh

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,22 @@ if [ "x$network" != "x" ]; then
1818
gateway6=$(qubesdb-read /qubes-netvm-gateway6 ||:)
1919
#netmask=$(qubesdb-read /qubes-netvm-netmask)
2020
primary_dns=$(qubesdb-read /qubes-netvm-primary-dns 2>/dev/null || echo "$gateway")
21-
secondary_dns=$(qubesdb-read /qubes-netvm-secondary-dns)
21+
secondary_dns=$(qubesdb-read /qubes-netvm-secondary-dns ||:)
2222
primary_dns6=$(qubesdb-read /qubes-netvm-primary-dns6 ||:)
2323
secondary_dns6=$(qubesdb-read /qubes-netvm-secondary-dns6 ||:)
24+
gen_ns_spec() {
25+
i=1
26+
for ns in "${primary_dns}" "${secondary_dns}" "${primary_dns6}" "${secondary_dns6}"; do
27+
if [ "x${ns}" != "x" ]; then
28+
echo "NS${i}=${ns}"
29+
((i++))
30+
fi
31+
done
32+
}
2433
modprobe netbk 2> /dev/null || modprobe xen-netback || "${modprobe_fail_cmd}"
25-
if [ -n "$primary_dns6" ]; then
26-
cat > /var/run/qubes/qubes-ns<< EOF
27-
NS1=$primary_dns6
28-
NS2=$secondary_dns6
29-
NS3=$primary_dns
30-
NS4=$secondary_dns
31-
EOF
32-
else
33-
cat > /var/run/qubes/qubes-ns<< EOF
34-
NS1=$primary_dns
35-
NS2=$secondary_dns
36-
EOF
37-
fi
34+
gen_ns_spec > /var/run/qubes/qubes-ns
3835
/usr/lib/qubes/qubes-setup-dnat-to-ns
36+
3937
echo "1" > /proc/sys/net/ipv4/ip_forward
4038
# enable also IPv6 forwarding, if IPv6 is enabled
4139
if [ -n "$gateway6" ]; then

0 commit comments

Comments
 (0)