From 9e24a5bfca6d817431b9108d8cdad81832b7f4fb Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 10 Aug 2020 14:42:58 -0400 Subject: [PATCH] add check for no default route on down fix macos bits for down install lokinet-vpn with cmake --- daemon/CMakeLists.txt | 2 +- daemon/lokinet-vpn.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index d2817dd9e..f0957b844 100644 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt @@ -25,9 +25,9 @@ else() endif() target_compile_definitions(${exe} PRIVATE -DVERSIONTAG=${GIT_VERSION_REAL}) add_log_tag(${exe}) + install(TARGETS ${exe} RUNTIME DESTINATION bin COMPONENT lokinet) endforeach() - install(TARGETS lokinet RUNTIME DESTINATION bin COMPONENT lokinet) if(WIN32) install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap.ps1 DESTINATION bin COMPONENT lokinet) else() diff --git a/daemon/lokinet-vpn.cpp b/daemon/lokinet-vpn.cpp index ac75a4069..6ae88cb58 100644 --- a/daemon/lokinet-vpn.cpp +++ b/daemon/lokinet-vpn.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #ifdef _WIN32 // add the unholy windows headers for iphlpapi @@ -247,6 +248,11 @@ main(int argc, char* argv[]) { DelDefaultRouteViaInterface(ifname); const auto gateways = GetGatewaysNotOnInterface(ifname); + if (gateways.empty()) + { + std::cout << "cannot determine default gateway" << std::endl; + return 1; + } const auto ourGateway = gateways[0]; for (const auto& ip : firstHops) { @@ -385,6 +391,10 @@ GetGatewaysNotOnInterface(std::string ifname) #undef FREE return gateways; #elif __APPLE__ + const auto maybe = llarp::GetIfAddr(ifname); + if(not maybe.has_value()) + return gateways; + const auto interface = maybe->toString(); // mac os is so godawful man FILE* p = popen("netstat -rn -f inet", "r"); if (p == nullptr) @@ -406,7 +416,7 @@ GetGatewaysNotOnInterface(std::string ifname) if (pos != std::string::npos) { auto gateway = line_str.substr(0, pos); - if (gateway != ifname) + if (gateway != interface) gateways.emplace_back(std::move(gateway)); } }