From 22af69545afdf4b71e8a586811dfeab5067f4bb5 Mon Sep 17 00:00:00 2001 From: sunil Date: Wed, 28 Nov 2018 20:39:00 +0530 Subject: [PATCH] feat(net): Support bridge interfaces (#1528) Bridge interfaces don't provide linkspeed via ethtool but everything else works the same as with ethernet links. Fixes #1522 --- include/adapters/net.hpp | 3 ++- src/adapters/net.cpp | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/adapters/net.hpp b/include/adapters/net.hpp index 8d0f46c9..97d6d391 100644 --- a/include/adapters/net.hpp +++ b/include/adapters/net.hpp @@ -87,7 +87,7 @@ namespace net { void set_unknown_up(bool unknown = true); protected: - void check_tuntap(); + void check_tuntap_or_bridge(); bool test_interface() const; string format_speedrate(float bytes_diff, int minwidth) const; void query_ip6(); @@ -97,6 +97,7 @@ namespace net { link_status m_status{}; string m_interface; bool m_tuntap{false}; + bool m_bridge{false}; bool m_unknown_up{false}; }; diff --git a/src/adapters/net.cpp b/src/adapters/net.cpp index 03bb5004..05f30320 100644 --- a/src/adapters/net.cpp +++ b/src/adapters/net.cpp @@ -45,7 +45,7 @@ namespace net { throw network_error("Failed to open socket"); } - check_tuntap(); + check_tuntap_or_bridge(); } /** @@ -174,9 +174,9 @@ namespace net { /** * Query driver info to check if the - * interface is a TUN/TAP device + * interface is a TUN/TAP device or BRIDGE */ - void network::check_tuntap() { + void network::check_tuntap_or_bridge() { struct ethtool_drvinfo driver {}; struct ifreq request {}; @@ -204,6 +204,11 @@ namespace net { } else { m_tuntap = false; } + + if (strncmp(driver.driver, "bridge", 6) == 0) { + m_bridge = true; + } + } /** @@ -248,6 +253,13 @@ namespace net { return false; } + if(m_bridge) { + /* If bridge network then link speed cannot be computed + * TODO: Identify the physical network in bridge and compute the link speed + */ + return true; + } + struct ifreq request {}; struct ethtool_cmd data {};