| 1 | // Copyright (C) Microsoft Corporation. All rights reserved. |
| 2 | |
| 3 | #pragma once |
| 4 | |
| 5 | #include "precomp.h" |
| 6 | #include "WslCoreNetworkEndpoint.h" |
| 7 | #include "WslCoreNetworkEndpointSettings.h" |
| 8 | |
| 9 | namespace wsl::core::networking { |
| 10 | |
| 11 | enum class GnsCallbackFlags |
| 12 | { |
| 13 | DontWait = 0, |
| 14 | Wait = 1 |
| 15 | }; |
| 16 | |
| 17 | using GnsMessageCallback = std::function<HRESULT(LX_MESSAGE_TYPE, const std::wstring&, GnsCallbackFlags)>; |
| 18 | using GnsMessageCallbackWithCallbackResult = |
| 19 | std::function<HRESULT(LX_MESSAGE_TYPE, const std::wstring&, GnsCallbackFlags, _Out_opt_ int*)>; |
| 20 | using AddNetworkEndpointCallback = std::function<void(GUID)>; |
| 21 | |
| 22 | DEFINE_ENUM_FLAG_OPERATORS(GnsCallbackFlags); |
| 23 | |
| 24 | class IMirroredNetworkManager |
| 25 | { |
| 26 | public: |
| 27 | IMirroredNetworkManager() noexcept = default; |
| 28 | virtual ~IMirroredNetworkManager() noexcept = default; |
| 29 | |
| 30 | // Disable copy and assign. |
| 31 | IMirroredNetworkManager(const IMirroredNetworkManager&) = delete; |
| 32 | IMirroredNetworkManager& operator=(const IMirroredNetworkManager&) = delete; |
| 33 | |
| 34 | // Disable move semantics. |
| 35 | IMirroredNetworkManager(IMirroredNetworkManager&&) noexcept = delete; |
| 36 | IMirroredNetworkManager& operator=(IMirroredNetworkManager&&) = delete; |
| 37 | |
| 38 | enum class HnsStatus |
| 39 | { |
| 40 | NoNetworkEverConnected, |
| 41 | NetworkConnectedWithHnsNotification, |
| 42 | NetworkConnectedNoHnsNotification |
| 43 | }; |
| 44 | |
| 45 | virtual HnsStatus Stop() noexcept = 0; |
| 46 | |
| 47 | virtual _Check_return_ HRESULT EnumerateNetworks(_Out_ std::vector<GUID>& NetworkIds) const noexcept = 0; |
| 48 | |
| 49 | virtual void AddEndpoint(networking::NetworkEndpoint&& newEndpoint, wsl::shared::hns::HNSEndpoint&& endpointProperties) noexcept = 0; |
| 50 | |
| 51 | virtual void SendCreateNotificationsForInitialEndpoints() noexcept = 0; |
| 52 | |
| 53 | // This API is not serialized with other API calls. |
| 54 | virtual HRESULT WaitForMirroredGoalState() noexcept = 0; |
| 55 | |
| 56 | virtual _Check_return_ bool DoesEndpointExist(GUID networkId) const noexcept = 0; |
| 57 | |
| 58 | virtual void OnNetworkConnectivityHintChange() noexcept = 0; |
| 59 | virtual void OnNetworkEndpointChange() noexcept = 0; |
| 60 | virtual void OnDnsSuffixChange() noexcept = 0; |
| 61 | |
| 62 | virtual void TunAdapterStateChanged(_In_ const std::string& interfaceName, _In_ bool up) noexcept = 0; |
| 63 | |
| 64 | // Client should call this if they detect the network is in a bad state and needs to be reconnected |
| 65 | virtual void ReconnectGuestNetwork() = 0; |
| 66 | |
| 67 | // Returns the network settings of the endpoint. |
| 68 | virtual std::shared_ptr<NetworkSettings> GetEndpointSettings(const wsl::shared::hns::HNSEndpoint& endpointProperties) const = 0; |
| 69 | |
| 70 | virtual void TraceLoggingRundown() const = 0; |
| 71 | }; |
| 72 | |
| 73 | } // namespace wsl::core::networking |