-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathVirtioNetworking.h
More file actions
88 lines (73 loc) · 3.34 KB
/
VirtioNetworking.h
File metadata and controls
88 lines (73 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (C) Microsoft Corporation. All rights reserved.
#pragma once
#include "INetworkingEngine.h"
#include "GnsChannel.h"
#include "DnsResolver.h"
#include "WslCoreHostDnsInfo.h"
#include "GnsPortTrackerChannel.h"
#include "GuestDeviceManager.h"
namespace wsl::core {
enum class VirtioNetworkingFlags
{
None = 0x0,
LocalhostRelay = 0x1,
DnsTunneling = 0x2,
Ipv6 = 0x4,
DnsTunnelingSocket = 0x8,
};
DEFINE_ENUM_FLAG_OPERATORS(VirtioNetworkingFlags);
class VirtioNetworking : public INetworkingEngine
{
public:
VirtioNetworking(
GnsChannel&& gnsChannel,
VirtioNetworkingFlags flags,
LPCWSTR dnsOptions,
std::shared_ptr<GuestDeviceManager> guestDeviceManager,
wil::shared_handle userToken,
wil::unique_socket&& dnsHvsocket = {});
~VirtioNetworking();
// Note: This class cannot be moved because m_networkNotifyHandle captures a 'this' pointer.
VirtioNetworking(const VirtioNetworking&) = delete;
VirtioNetworking(VirtioNetworking&&) = delete;
VirtioNetworking& operator=(const VirtioNetworking&) = delete;
VirtioNetworking& operator=(VirtioNetworking&&) = delete;
// INetworkingEngine
void Initialize() override;
void TraceLoggingRundown() noexcept override;
void FillInitialConfiguration(LX_MINI_INIT_NETWORKING_CONFIGURATION& message) override;
void StartPortTracker(wil::unique_socket&& socket) override;
private:
static void NETIOAPI_API_ OnNetworkConnectivityChange(PVOID context, NL_NETWORK_CONNECTIVITY_HINT hint);
HRESULT HandlePortNotification(const SOCKADDR_INET& addr, int protocol, bool allocate) const noexcept;
int ModifyOpenPorts(_In_ PCWSTR tag, _In_ const SOCKADDR_INET& addr, _In_ int protocol, _In_ bool isOpen) const;
void RefreshGuestConnection() noexcept;
void SetupLoopbackDevice();
void SendDefaultRoute(const std::wstring& gateway, wsl::shared::hns::ModifyRequestType requestType);
void SendIpv6Address(const networking::EndpointIpAddress& ipAddress, wsl::shared::hns::ModifyRequestType requestType);
void UpdateDefaultRoute(const std::wstring& gateway);
void UpdateDnsSettings(const networking::DnsInfo& dns);
void UpdateIpv4Address(const networking::EndpointIpAddress& ipAddress);
void UpdateIpv6Address(const networking::EndpointIpAddress& ipAddress);
void UpdateMtu(std::optional<ULONG> mtu);
mutable wil::srwlock m_lock;
std::shared_ptr<GuestDeviceManager> m_guestDeviceManager;
wil::shared_handle m_userToken;
GnsChannel m_gnsChannel;
std::optional<GnsPortTrackerChannel> m_gnsPortTrackerChannel;
std::shared_ptr<networking::NetworkSettings> m_networkSettings;
VirtioNetworkingFlags m_flags = VirtioNetworkingFlags::None;
LPCWSTR m_dnsOptions = nullptr;
std::optional<networking::DnsResolver> m_dnsTunnelingResolver;
std::optional<GUID> m_localhostAdapterId;
std::optional<GUID> m_adapterId;
ULONG m_networkMtu = 0;
std::wstring m_trackedDeviceOptions;
networking::EndpointIpAddress m_trackedIpv4Address{};
networking::EndpointIpAddress m_trackedIpv6Address{};
std::wstring m_trackedDefaultRoute;
networking::DnsInfo m_trackedDnsSettings{};
// Note: this field must be destroyed first to stop the callbacks before any other field is destroyed.
networking::unique_notify_handle m_networkNotifyHandle;
};
} // namespace wsl::core