From 852f7ae7c93bec008bc119817c26161a5b35b0b4 Mon Sep 17 00:00:00 2001 From: Uwe Seimet Date: Fri, 8 Sep 2023 00:06:09 +0200 Subject: [PATCH] Simplify interface search --- cpp/devices/ctapdriver.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/cpp/devices/ctapdriver.cpp b/cpp/devices/ctapdriver.cpp index bec3a37647..83cac81aed 100644 --- a/cpp/devices/ctapdriver.cpp +++ b/cpp/devices/ctapdriver.cpp @@ -154,24 +154,15 @@ bool CTapDriver::Init(const unordered_map& const_params) if (access(string("/sys/class/net/" + BRIDGE_NAME).c_str(), F_OK)) { spdlog::trace("Checking which interface is available for creating the bridge " + BRIDGE_NAME); - string bridge_interface; - for (const string& iface : interfaces) { - if (IsInterfaceUp(iface)) { - spdlog::trace("Interface " + iface + " is up"); - - bridge_interface = iface; - break; - } - else { - spdlog::trace("Interface " + iface + " is not available or is not up"); - } - } - - if (bridge_interface.empty()) { + const auto& it = find_if(interfaces.begin(), interfaces.end(), [] (const string& interface) + { return IsInterfaceUp(interface); } ); + if (it == interfaces.end()) { spdlog::error("No interface is up, not creating bridge " + BRIDGE_NAME); return false; } + const string bridge_interface = *it; + spdlog::info("Creating " + BRIDGE_NAME + " for interface " + bridge_interface); if (bridge_interface == "eth0") {