diff options
| author | David Lönnhager <david.l@mullvad.net> | 2021-02-24 12:13:20 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2021-03-01 16:50:42 +0100 |
| commit | 575fb84c82416aaeed780a33af4b8abb819488d5 (patch) | |
| tree | af3869b81ab2a254a6097e82e9ecc1e3e6ba292a /windows | |
| parent | 76800f07ca161c5af0a3afc5b503b7f60f73b4d8 (diff) | |
| download | mullvadvpn-575fb84c82416aaeed780a33af4b8abb819488d5.tar.xz mullvadvpn-575fb84c82416aaeed780a33af4b8abb819488d5.zip | |
Return error codes from winnet route manager
Diffstat (limited to 'windows')
| -rw-r--r-- | windows/winnet/src/winnet/routing/routemanager.cpp | 15 | ||||
| -rw-r--r-- | windows/winnet/src/winnet/routing/routemanager.h | 45 | ||||
| -rw-r--r-- | windows/winnet/src/winnet/winnet.cpp | 27 | ||||
| -rw-r--r-- | windows/winnet/src/winnet/winnet.h | 13 |
4 files changed, 86 insertions, 14 deletions
diff --git a/windows/winnet/src/winnet/routing/routemanager.cpp b/windows/winnet/src/winnet/routing/routemanager.cpp index dc38466440..2c2257e916 100644 --- a/windows/winnet/src/winnet/routing/routemanager.cpp +++ b/windows/winnet/src/winnet/routing/routemanager.cpp @@ -52,7 +52,7 @@ NET_LUID InterfaceLuidFromGateway(const NodeAddress &gateway) if (matches.empty()) { - THROW_ERROR("Unable to find network adapter with specified gateway"); + THROW_ERROR_TYPE(error::DeviceGatewayNotFound, "Unable to find network adapter with specified gateway"); } // @@ -128,7 +128,7 @@ InterfaceAndGateway ResolveNode(ADDRESS_FAMILY family, const std::optional<Node> const auto default_route = GetBestDefaultRoute(family); if (!default_route.has_value()) { - THROW_ERROR("Unable to determine details of default route"); + THROW_ERROR_TYPE(error::NoDefaultRoute, "Unable to determine details of default route"); } return default_route.value(); } @@ -145,8 +145,7 @@ InterfaceAndGateway ResolveNode(ADDRESS_FAMILY family, const std::optional<Node> { const auto msg = std::string("Unable to derive interface LUID from interface alias: ") .append(common::string::ToAnsi(deviceName)); - - THROW_ERROR(msg.c_str()); + THROW_ERROR_TYPE(error::DeviceNameNotFound, msg.c_str()); } auto onLinkProvider = [&family]() @@ -242,11 +241,15 @@ void RouteManager::addRoutes(const std::vector<Route> &routes) *existingRecord = std::move(newRecord); } } + catch (const error::RouteManagerError&) + { + undoEvents(eventLog); + throw; + } catch (...) { undoEvents(eventLog); - - THROW_ERROR("Failed during batch insertion of routes"); + THROW_ERROR("Unexpected error during batch insertion of routes"); } } } diff --git a/windows/winnet/src/winnet/routing/routemanager.h b/windows/winnet/src/winnet/routing/routemanager.h index 07cc7dbf40..42949a657b 100644 --- a/windows/winnet/src/winnet/routing/routemanager.h +++ b/windows/winnet/src/winnet/routing/routemanager.h @@ -18,6 +18,51 @@ namespace winnet::routing { +namespace error +{ + +class RouteManagerError : public std::runtime_error +{ +public: + + RouteManagerError(const char* message) + : std::runtime_error(message) + { + } +}; + +class NoDefaultRoute : public RouteManagerError +{ +public: + + NoDefaultRoute(const char* message) + : RouteManagerError(message) + { + } +}; + +class DeviceNameNotFound : public RouteManagerError +{ +public: + + DeviceNameNotFound(const char* message) + : RouteManagerError(message) + { + } +}; + +class DeviceGatewayNotFound : public RouteManagerError +{ +public: + + DeviceGatewayNotFound(const char* message) + : RouteManagerError(message) + { + } +}; + +} + class RouteManager { public: diff --git a/windows/winnet/src/winnet/winnet.cpp b/windows/winnet/src/winnet/winnet.cpp index 9ed2ec103e..e82345ebee 100644 --- a/windows/winnet/src/winnet/winnet.cpp +++ b/windows/winnet/src/winnet/winnet.cpp @@ -280,7 +280,7 @@ WinNet_ActivateRouteManager( extern "C"
WINNET_LINKAGE
-bool
+WINNET_AR_STATUS
WINNET_API
WinNet_AddRoutes(
const WINNET_ROUTE *routes,
@@ -291,7 +291,7 @@ WinNet_AddRoutes( if (nullptr == g_RouteManager)
{
- return false;
+ return WINNET_AR_STATUS_GENERAL_ERROR;
}
try
@@ -302,22 +302,37 @@ WinNet_AddRoutes( }
g_RouteManager->addRoutes(winnet::ConvertRoutes(routes, numRoutes));
- return true;
+ return WINNET_AR_STATUS_SUCCESS;
+ }
+ catch (const winnet::routing::error::NoDefaultRoute &err)
+ {
+ common::error::UnwindException(err, g_RouteManagerLogSink);
+ return WINNET_AR_STATUS_NO_DEFAULT_ROUTE;
+ }
+ catch (const winnet::routing::error::DeviceNameNotFound &err)
+ {
+ common::error::UnwindException(err, g_RouteManagerLogSink);
+ return WINNET_AR_STATUS_NAME_NOT_FOUND;
+ }
+ catch (const winnet::routing::error::DeviceGatewayNotFound &err)
+ {
+ common::error::UnwindException(err, g_RouteManagerLogSink);
+ return WINNET_AR_STATUS_GATEWAY_NOT_FOUND;
}
catch (const std::exception &err)
{
common::error::UnwindException(err, g_RouteManagerLogSink);
- return false;
+ return WINNET_AR_STATUS_GENERAL_ERROR;
}
catch (...)
{
- return false;
+ return WINNET_AR_STATUS_GENERAL_ERROR;
}
}
extern "C"
WINNET_LINKAGE
-bool
+WINNET_AR_STATUS
WINNET_API
WinNet_AddRoute(
const WINNET_ROUTE *route
diff --git a/windows/winnet/src/winnet/winnet.h b/windows/winnet/src/winnet/winnet.h index 32d377e73f..8cd1703f79 100644 --- a/windows/winnet/src/winnet/winnet.h +++ b/windows/winnet/src/winnet/winnet.h @@ -96,9 +96,18 @@ WinNet_ActivateRouteManager( void *logSinkContext ); +enum WINNET_AR_STATUS +{ + WINNET_AR_STATUS_SUCCESS = 0, + WINNET_AR_STATUS_GENERAL_ERROR = 1, + WINNET_AR_STATUS_NO_DEFAULT_ROUTE = 2, + WINNET_AR_STATUS_NAME_NOT_FOUND = 3, + WINNET_AR_STATUS_GATEWAY_NOT_FOUND = 4, +}; + extern "C" WINNET_LINKAGE -bool +WINNET_AR_STATUS WINNET_API WinNet_AddRoutes( const WINNET_ROUTE *routes, @@ -107,7 +116,7 @@ WinNet_AddRoutes( extern "C" WINNET_LINKAGE -bool +WINNET_AR_STATUS WINNET_API WinNet_AddRoute( const WINNET_ROUTE *route |
