Skip to content

Commit af9950b

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 af9950b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

network/vif-route-qubes

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,20 @@ if [ "${ip}" ]; then
240240
log error "Cannot set IPv6 route to ${addr}, IPv6 disabled in the kernel"
241241
continue
242242
fi
243-
${cmdprefix} ip route "${ipcmd}" "${addr}" dev "${vif}" metric "$metric"
243+
if [ "$ipcmd" = "add" ] || [ -e /sys/class/net/"$vif" ]; then
244+
${cmdprefix} ip route "${ipcmd}" "${addr}" dev "${vif}" metric "$metric"
245+
fi
244246

245247
network_hooks "${command}" "${vif}" "${addr}"
246248
done
247-
${cmdprefix} ip addr "${ipcmd}" "${back_ip}/32" dev "${vif}"
249+
if [ "$ipcmd" = "add" ] || [ -e /sys/class/net/"$vif" ]; then
250+
${cmdprefix} ip addr "${ipcmd}" "${back_ip}/32" dev "${vif}"
251+
fi
248252
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"
253+
if [ "$ipcmd" = "add" ] || [ -e /sys/class/net/"$vif" ]; then
254+
${cmdprefix} ip addr "${ipcmd}" "${back_ip6}/128" dev "${vif}"
255+
echo 1 >"/proc/sys/net/ipv6/conf/${vif}/proxy_ndp"
256+
fi
251257
fi
252258
else
253259
network_hooks "${command}" "${vif}"

0 commit comments

Comments
 (0)