From 2c380a53caabfc831d832985becb95b69d202eed Mon Sep 17 00:00:00 2001 From: Rolf Vidar Mazunki Hoksaas Date: Thu, 9 Sep 2021 20:05:18 +0200 Subject: [PATCH 1/6] added support for the {gwaddr} variable --- Makefile | 3 +++ include/modules/network.hpp | 1 + man/waybar-network.5.scd | 2 ++ src/modules/network.cpp | 10 +++++++++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d7182c18..ccf05073 100644 --- a/Makefile +++ b/Makefile @@ -16,5 +16,8 @@ install: build run: build ./build/waybar +debug-run: build + ./build/waybar --log-level debug + clean: rm -rf build diff --git a/include/modules/network.hpp b/include/modules/network.hpp index 009ae5a3..ad28520e 100644 --- a/include/modules/network.hpp +++ b/include/modules/network.hpp @@ -67,6 +67,7 @@ class Network : public ALabel { bool carrier_; std::string ifname_; std::string ipaddr_; + std::string gwaddr_; std::string netmask_; int cidr_; int32_t signal_strength_dbm_; diff --git a/man/waybar-network.5.scd b/man/waybar-network.5.scd index f274881e..f8bdd65d 100644 --- a/man/waybar-network.5.scd +++ b/man/waybar-network.5.scd @@ -131,6 +131,8 @@ Addressed by *network* *{ipaddr}*: The first IP of the interface. +*{gwaddr}*: The default gateway for the interface + *{netmask}*: The subnetmask corresponding to the IP. *{cidr}*: The subnetmask corresponding to the IP in CIDR notation. diff --git a/src/modules/network.cpp b/src/modules/network.cpp index 7d0f6382..a45f2b87 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -348,6 +348,7 @@ auto waybar::modules::Network::update() -> void { fmt::arg("ifname", ifname_), fmt::arg("netmask", netmask_), fmt::arg("ipaddr", ipaddr_), + fmt::arg("gwaddr", gwaddr_), fmt::arg("cidr", cidr_), fmt::arg("frequency", frequency_), fmt::arg("icon", getIcon(signal_strength_, state_)), @@ -376,6 +377,7 @@ auto waybar::modules::Network::update() -> void { fmt::arg("ifname", ifname_), fmt::arg("netmask", netmask_), fmt::arg("ipaddr", ipaddr_), + fmt::arg("gwaddr", gwaddr_), fmt::arg("cidr", cidr_), fmt::arg("frequency", frequency_), fmt::arg("icon", getIcon(signal_strength_, state_)), @@ -409,6 +411,7 @@ void waybar::modules::Network::clearIface() { ifname_.clear(); essid_.clear(); ipaddr_.clear(); + gwaddr_.clear(); netmask_.clear(); carrier_ = false; cidr_ = 0; @@ -581,6 +584,7 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) { break; } + char temp_gw_addr[INET6_ADDRSTRLEN]; case RTM_DELROUTE: is_del_event = true; case RTM_NEWROUTE: { @@ -595,6 +599,7 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) { int temp_idx = -1; uint32_t priority = 0; + /* Find the message(s) concerting the main routing table, each message * corresponds to a single routing table entry. */ @@ -612,9 +617,10 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) { case RTA_GATEWAY: /* The gateway of the route. * - * If someone every needs to figure out the gateway address as well, + * If someone ever needs to figure out the gateway address as well, * it's here as the attribute payload. */ + inet_ntop(net->family_, RTA_DATA(attr), temp_gw_addr, sizeof(temp_gw_addr)); has_gateway = true; break; case RTA_DST: { @@ -655,6 +661,8 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) { net->clearIface(); net->ifid_ = temp_idx; net->route_priority = priority; + net->gwaddr_ = temp_gw_addr; + spdlog::debug("netwok: gateway {}", net->gwaddr_); spdlog::debug("network: new default route via if{} metric {}", temp_idx, priority); From 95ecff05511f71fc542429059b843ecd369854ef Mon Sep 17 00:00:00 2001 From: Rolf Vidar Mazunki Hoksaas Date: Thu, 9 Sep 2021 20:12:20 +0200 Subject: [PATCH 2/6] added example tooltip usage --- resources/config | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/config b/resources/config index 87f24c04..b3157212 100644 --- a/resources/config +++ b/resources/config @@ -117,7 +117,8 @@ "network": { // "interface": "wlp2*", // (Optional) To force the use of this interface "format-wifi": "{essid} ({signalStrength}%) ", - "format-ethernet": "{ifname}: {ipaddr}/{cidr} ", + "format-ethernet": "{ipaddr}/{cidr} ", + "tooltip-format": "{ifname} via {gwaddr} ", "format-linked": "{ifname} (No IP) ", "format-disconnected": "Disconnected ⚠", "format-alt": "{ifname}: {ipaddr}/{cidr}" From 5f083193e4202e616d587b53050111fef1fa031f Mon Sep 17 00:00:00 2001 From: mazunki Date: Sat, 18 Sep 2021 01:12:58 +0200 Subject: [PATCH 3/6] fixed tab indentation to spaces, removed debug --- src/modules/network.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/modules/network.cpp b/src/modules/network.cpp index a45f2b87..0fccf091 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -661,9 +661,7 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) { net->clearIface(); net->ifid_ = temp_idx; net->route_priority = priority; - net->gwaddr_ = temp_gw_addr; - spdlog::debug("netwok: gateway {}", net->gwaddr_); - + net->gwaddr_ = temp_gw_addr; spdlog::debug("network: new default route via if{} metric {}", temp_idx, priority); /* Ask ifname associated with temp_idx as well as carrier status */ From 13239417d817460eee8dd46bd09ddae0fc8dcf5a Mon Sep 17 00:00:00 2001 From: mazunki Date: Sat, 18 Sep 2021 01:20:16 +0200 Subject: [PATCH 4/6] fixed wrong dependency for make target --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ccf05073..94f8ee6e 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ install: build run: build ./build/waybar -debug-run: build +debug-run: build-debug ./build/waybar --log-level debug clean: From 6142dfba6a1ffc5e08ac68df172291d926fa8b03 Mon Sep 17 00:00:00 2001 From: mazunki Date: Sat, 18 Sep 2021 01:51:16 +0200 Subject: [PATCH 5/6] updated original debug message with gateway ip, similar, yet not identical to default via 10.13.37.100 dev enp7s0 metric 2 10.13.37.0/24 dev enp7s0 proto kernel scope link src 10.13.37.97 's output --- src/modules/network.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/network.cpp b/src/modules/network.cpp index 0fccf091..3b9fb187 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -662,7 +662,7 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) { net->ifid_ = temp_idx; net->route_priority = priority; net->gwaddr_ = temp_gw_addr; - spdlog::debug("network: new default route via if{} metric {}", temp_idx, priority); + spdlog::debug("network: new default route via {} on if{} metric {}", temp_gw_addr, temp_idx, priority); /* Ask ifname associated with temp_idx as well as carrier status */ struct ifinfomsg ifinfo_hdr = { From 1c91c71dcde2d77506989b407eefcd18b20f34a3 Mon Sep 17 00:00:00 2001 From: mazunki Date: Sat, 18 Sep 2021 01:51:16 +0200 Subject: [PATCH 6/6] updated original debug message with gateway ip, similar, yet not identical to `ip route` --- src/modules/network.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/network.cpp b/src/modules/network.cpp index 0fccf091..3b9fb187 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -662,7 +662,7 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) { net->ifid_ = temp_idx; net->route_priority = priority; net->gwaddr_ = temp_gw_addr; - spdlog::debug("network: new default route via if{} metric {}", temp_idx, priority); + spdlog::debug("network: new default route via {} on if{} metric {}", temp_gw_addr, temp_idx, priority); /* Ask ifname associated with temp_idx as well as carrier status */ struct ifinfomsg ifinfo_hdr = {