Skip to content

Commit 99bd2ec

Browse files
committed
Avoid de-configuring non-existing interface
When 'vif-route-qubes offline' is called, the interface (usually) doesn't exist anymore. In that case, commands are called with 'do_without_error', but while it doesn't fail the script, it still logs misleading error message. Avoid calling 'ip' on non-existing interface to remove its address/route, as those are removed by the kernel implicitly anyway. But still call them on online action (if interface doesn't exist at this point, it will fail, and that's intentional to get proper error message), or when the interface still exist at the time the script is called (in which case, it may still race against disappearing the interface, but then there is 'do_without_error' prefix as the last resort). This way, it avoids confusing error in the common case, but still ensure things are cleaned up in the unusual case of interface staying there.
1 parent 254075f commit 99bd2ec

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

network/vif-route-qubes

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ table inet qubes-nat-accel {
144144
fi
145145
;;
146146
offline)
147-
do_without_error ifdown "${vif}"
147+
if [ -e /sys/class/net/"$vif" ]; then
148+
do_without_error ifdown "${vif}"
149+
fi
148150
ipcmd='del'
149151
nftables_cmd=delete
150152
cmdprefix='do_without_error'
@@ -240,14 +242,20 @@ if [ "${ip}" ]; then
240242
log error "Cannot set IPv6 route to ${addr}, IPv6 disabled in the kernel"
241243
continue
242244
fi
243-
${cmdprefix} ip route "${ipcmd}" "${addr}" dev "${vif}" metric "$metric"
245+
if [ "$ipcmd" = "add" ] || [ -e /sys/class/net/"$vif" ]; then
246+
${cmdprefix} ip route "${ipcmd}" "${addr}" dev "${vif}" metric "$metric"
247+
fi
244248

245249
network_hooks "${command}" "${vif}" "${addr}"
246250
done
247-
${cmdprefix} ip addr "${ipcmd}" "${back_ip}/32" dev "${vif}"
251+
if [ "$ipcmd" = "add" ] || [ -e /sys/class/net/"$vif" ]; then
252+
${cmdprefix} ip addr "${ipcmd}" "${back_ip}/32" dev "${vif}"
253+
fi
248254
if [[ -n "${back_ip6}" ]] && [[ "${back_ip6}" != "fe80:"* ]] && [[ "$ipv6_disabled" = '0' ]]; then
249-
${cmdprefix} ip addr "${ipcmd}" "${back_ip6}/128" dev "${vif}"
250-
echo 1 >"/proc/sys/net/ipv6/conf/${vif}/proxy_ndp"
255+
if [ "$ipcmd" = "add" ] || [ -e /sys/class/net/"$vif" ]; then
256+
${cmdprefix} ip addr "${ipcmd}" "${back_ip6}/128" dev "${vif}"
257+
echo 1 >"/proc/sys/net/ipv6/conf/${vif}/proxy_ndp"
258+
fi
251259
fi
252260
else
253261
network_hooks "${command}" "${vif}"

0 commit comments

Comments
 (0)