MCPcopy Create free account
hub / github.com/Alexays/Waybar / handleEvents

Method handleEvents

src/modules/network.cpp:481–801  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

479}
480
481int waybar::modules::Network::handleEvents(struct nl_msg* msg, void* data) {
482 auto net = static_cast<waybar::modules::Network*>(data);
483 std::lock_guard<std::mutex> lock(net->mutex_);
484 auto nh = nlmsg_hdr(msg);
485 bool is_del_event = false;
486
487 switch (nh->nlmsg_type) {
488 case RTM_DELLINK:
489 is_del_event = true;
490 case RTM_NEWLINK: {
491 struct ifinfomsg* ifi = static_cast<struct ifinfomsg*>(NLMSG_DATA(nh));
492 struct nlattr* attrs[IFLA_MAX + 1];
493 std::string ifname;
494 std::vector<std::string> altnames;
495 std::optional<bool> carrier;
496
497 if (nlmsg_parse(nh, sizeof(*ifi), attrs, IFLA_MAX, nullptr) < 0) {
498 spdlog::error("network: failed to parse netlink attributes");
499 return NL_SKIP;
500 }
501
502 if (net->ifid_ != -1 && ifi->ifi_index != net->ifid_) {
503 return NL_OK;
504 }
505
506 // Check if the interface goes "down" and if we want to detect the
507 // external interface.
508 if (net->ifid_ != -1 && !(ifi->ifi_flags & IFF_UP) && !net->config_["interface"].isString()) {
509 // The current interface is now down, all the routes associated with
510 // it have been deleted, so start looking for a new default route.
511 spdlog::debug("network: if{} down", net->ifid_);
512 net->clearIface();
513 net->dp.emit();
514 net->want_route_dump_ = true;
515 net->askForStateDump();
516 return NL_OK;
517 }
518
519 if (attrs[IFLA_IFNAME] != nullptr) {
520 const char* ifname_ptr = nla_get_string(attrs[IFLA_IFNAME]);
521 size_t ifname_len = nla_len(attrs[IFLA_IFNAME]) - 1; // minus \0
522 ifname = std::string(ifname_ptr, ifname_len);
523 }
524
525 if (attrs[IFLA_CARRIER] != nullptr) {
526 carrier = nla_get_u8(attrs[IFLA_CARRIER]) == 1;
527 }
528
529 if (attrs[IFLA_PROP_LIST] != nullptr) {
530 struct nlattr* prop;
531 int rem;
532
533 nla_for_each_nested(prop, attrs[IFLA_PROP_LIST], rem) {
534 if (nla_type(prop) == IFLA_ALT_IFNAME) {
535 const char* altname_ptr = nla_get_string(prop);
536 size_t altname_len = nla_len(prop) - 1; // minus \0
537 altnames.emplace_back(altname_ptr, altname_len);
538 }

Callers

nothing calls this directly

Calls 7

clearIfaceMethod · 0.80
askForStateDumpMethod · 0.80
emptyMethod · 0.80
wake_upMethod · 0.80
valueMethod · 0.80
matchInterfaceMethod · 0.80
emitMethod · 0.45

Tested by

no test coverage detected