Skip to content

Commit

Permalink
network: Fix use of carrier information
Browse files Browse the repository at this point in the history
Some RTM_NEWLINK messages may not have the IFLA_CARRIER information.
This is the case when a WiFi interface report scan result are
available. `carrier` is used regardless of if it is present in the
message or not. This would result in the interface appearing
"disconnected" in waybar when it isn't.

This patch now check that `carrier` is available before using it.

The same thing could potentially happen to `ifname` so check if it's
set before recording it.

Fixes: c1427ff (network: Handle carrier information)
Fixes Alexays#388
  • Loading branch information
tperard committed May 26, 2021
1 parent 94a882b commit 28dfb0b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/modules/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
struct rtattr *ifla = IFLA_RTA(ifi);
const char *ifname = NULL;
size_t ifname_len = 0;
bool carrier = false;
std::optional<bool> carrier;

if (net->ifid_ != -1 && ifi->ifi_index != net->ifid_) {
return NL_OK;
Expand All @@ -446,11 +446,13 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {

if (!is_del_event && ifi->ifi_index == net->ifid_) {
// Update inferface information
if (net->ifname_.empty()) {
if (net->ifname_.empty() && ifname != NULL) {
std::string new_ifname (ifname, ifname_len);
net->ifname_ = new_ifname;
}
net->carrier_ = carrier;
if (carrier.has_value()) {
net->carrier_ = carrier.value();
}
} else if (!is_del_event && net->ifid_ == -1) {
// Checking if it's an interface we care about.
std::string new_ifname (ifname, ifname_len);
Expand All @@ -459,7 +461,9 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {

net->ifname_ = new_ifname;
net->ifid_ = ifi->ifi_index;
net->carrier_ = carrier;
if (carrier.has_value()) {
net->carrier_ = carrier.value();
}
net->thread_timer_.wake_up();
/* An address for this new interface should be received via an
* RTM_NEWADDR event either because we ask for a dump of both links
Expand Down

0 comments on commit 28dfb0b

Please sign in to comment.