fix(net): Use canonical interface name (#2540)

One can define an 'altname' for an interface. That name is valid of
if_nametoindex but it doesn't appear in `/sys/class/net`:

```
sudo ip link property add dev enp0s31f6 altname eno
```

This creates an altname eno for the existing interface enp0s31f6

Before, using eno, would lead to an error in `realpath`.

Ref: https://www.reddit.com/r/Polybar/comments/q8f0ye/error_disabling_module_network_reason_realpath/hgqpq1m/?context=3
This commit is contained in:
Patrick Ziegler
2021-10-15 17:36:32 +02:00
committed by GitHub
parent abd96eb089
commit 4d90ac2f4c
4 changed files with 36 additions and 0 deletions

View File

@ -44,6 +44,14 @@ namespace modules {
throw module_error("Invalid network interface \"" + m_interface + "\"");
}
auto canonical = net::get_canonical_interface(m_interface);
if (canonical.second) {
m_log.info(
"%s: Replacing given interface '%s' with its canonical name '%s'", name(), m_interface, canonical.first);
m_interface = canonical.first;
}
m_ping_nth_update = m_conf.get(name(), "ping-interval", m_ping_nth_update);
m_udspeed_minwidth = m_conf.get(name(), "udspeed-minwidth", m_udspeed_minwidth);
m_accumulate = m_conf.get(name(), "accumulate-stats", m_accumulate);