network: Fix one case where default route is deleted without notification

When an interface's state is change to "down", all the route
associated with it are deleted without an RTM_DELROUTE event.

So when this happen, reset the module to start looking for a new
external interface / default route.

Fixes #1117
This commit is contained in:
Anthony PERARD 2021-06-02 22:16:28 +01:00
parent efaac20d82
commit 33617b67f0

View File

@ -1,6 +1,7 @@
#include "modules/network.hpp"
#include <spdlog/spdlog.h>
#include <sys/eventfd.h>
#include <linux/if.h>
#include <fstream>
#include <cassert>
#include <optional>
@ -432,6 +433,20 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
return NL_OK;
}
// Check if the interface goes "down" and if we want to detect the
// external interface.
if (net->ifid_ != -1 && !(ifi->ifi_flags & IFF_UP)
&& !net->config_["interface"].isString()) {
// The current interface is now down, all the routes associated with
// it have been deleted, so start looking for a new default route.
spdlog::debug("network: if{} down", net->ifid_);
net->clearIface();
net->dp.emit();
net->want_route_dump_ = true;
net->askForStateDump();
return NL_OK;
}
for (; RTA_OK(ifla, attrlen); ifla = RTA_NEXT(ifla, attrlen)) {
switch (ifla->rta_type) {
case IFLA_IFNAME: