|
@@ -78,20 +78,23 @@ if [ "${ip}" ]; then
|
|
|
appvm_ip="$(qubesdb-read "/mapped-ip/$ip4/visible-ip" 2>/dev/null || :)"
|
|
|
fi
|
|
|
|
|
|
-# Apply NAT if IP visible from the VM is different than the "real" one
|
|
|
-# See vif-qubes-nat.sh for details
|
|
|
-# XXX: supported only for the first IPv4 address, IPv6 is dropped if this
|
|
|
-# feature is enabled
|
|
|
-if [ -n "$appvm_ip" ] && [ -n "$appvm_gw_ip" ] && [ "$appvm_ip" != "$netvm_ip" ]; then
|
|
|
- # shellcheck disable=SC2154
|
|
|
- if test "$command" == online; then
|
|
|
- # shellcheck disable=SC2154
|
|
|
- echo 1 >"/proc/sys/net/ipv4/conf/${vif}/proxy_arp"
|
|
|
- fi
|
|
|
+readonly max_domid=32752
|
|
|
|
|
|
- # shellcheck source=network/vif-qubes-nat.sh
|
|
|
- . "$dir/vif-qubes-nat.sh"
|
|
|
+# if domid is 0 something is seriously wrong, so don’t check for that case
|
|
|
+if ! [[ $vif =~ ^vif([1-9][0-9]{,4})\.(0|[1-9][0-9]*)$ ]]; then
|
|
|
+ printf 'Bad interface name %q\n' "$vif">&2
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
+
|
|
|
+domid=${BASH_REMATCH[1]} sub=${BASH_REMATCH[2]}
|
|
|
+
|
|
|
+# metric must be positive, but prefer later interface
|
|
|
+# 32752 is max XID aka domid
|
|
|
+if (( domid > max_domid )); then
|
|
|
+ printf %s\\n "domid $domid too large"
|
|
|
+ exit 1
|
|
|
fi
|
|
|
+metric=$(( max_domid - domid ))
|
|
|
|
|
|
# shellcheck disable=SC2154
|
|
|
case "$command" in
|
|
@@ -101,6 +104,8 @@ case "$command" in
|
|
|
iptables_cmd='-I PREROUTING 1'
|
|
|
cmdprefix=''
|
|
|
ipv6_disabled=$(cat /proc/sys/net/ipv6/conf/"${vif}"/disable_ipv6 || echo 1)
|
|
|
+ # without a MAC address we will fail later with a confusing error
|
|
|
+ mac=$(xenstore-read "backend/vif/$domid/$sub/mac") || exit 1
|
|
|
;;
|
|
|
offline)
|
|
|
do_without_error ifdown "${vif}"
|
|
@@ -112,23 +117,14 @@ case "$command" in
|
|
|
;;
|
|
|
esac
|
|
|
|
|
|
-readonly max_domid=32752
|
|
|
-
|
|
|
-# if domid is 0 something is seriously wrong, so don’t check for that case
|
|
|
-if ! [[ $vif =~ ^vif([1-9][0-9]{,4})\.(0|[1-9][0-9]*)$ ]]; then
|
|
|
- printf 'Bad interface name %q\n' "$vif">&2
|
|
|
- exit 1
|
|
|
-fi
|
|
|
-
|
|
|
-domid=${BASH_REMATCH[1]} sub=${BASH_REMATCH[2]}
|
|
|
-
|
|
|
-# metric must be positive, but prefer later interface
|
|
|
-# 32752 is max XID aka domid
|
|
|
-if (( domid > max_domid )); then
|
|
|
- printf %s\\n "domid $domid too large"
|
|
|
- exit 1
|
|
|
+# Apply NAT if IP visible from the VM is different than the "real" one
|
|
|
+# See vif-qubes-nat.sh for details
|
|
|
+# XXX: supported only for the first IPv4 address, IPv6 is dropped if this
|
|
|
+# feature is enabled
|
|
|
+if [ -n "$appvm_ip" ] && [ -n "$appvm_gw_ip" ] && [ "$appvm_ip" != "$netvm_ip" ]; then
|
|
|
+ # shellcheck source=network/vif-qubes-nat.sh
|
|
|
+ . "$dir/vif-qubes-nat.sh"
|
|
|
fi
|
|
|
-metric=$(( max_domid - domid ))
|
|
|
|
|
|
# add anti-spoofing rules before enabling the interface
|
|
|
if [ "${ip}" ]; then
|
|
@@ -147,7 +143,6 @@ if [ "${ip}" ]; then
|
|
|
"COMMIT" | \
|
|
|
${cmdprefix} $ipt --noflush $ipt_arg
|
|
|
if [[ "$command" = 'online' ]]; then
|
|
|
- mac=$(xenstore-read "backend/vif/$domid/$sub/mac") &&
|
|
|
ip -- neighbour "${ipcmd}" to "${addr}" \
|
|
|
dev "${vif}" lladdr "$mac" nud permanent
|
|
|
fi
|