master
h 94 lines 3.12 KB
Raw
1 // Copyright (C) Microsoft Corporation. All rights reserved.
2
3 #pragma once
4 #include <Interface.h>
5 #include <RoutingTable.h>
6 #include <IpRuleManager.h>
7 #include <IpNeighborManager.h>
8 #include <conncheckshared.h>
9 #include "hns_schema.h"
10
11 class NetworkManager
12 {
13 public:
14 NetworkManager(RoutingTable& routingTable);
15
16 Interface CreateVirtualWifiAdapter(Interface& baseAdapter, const std::string& wifiName);
17
18 Interface CreateProxyWifiAdapter(Interface& baseAdapter, const std::string& wifiName);
19
20 void SetAdapterConfiguration(Interface& adapter, const wsl::shared::hns::HNSEndpoint& configuration);
21
22 enum class InterfaceState
23 {
24 Up,
25 Down
26 };
27
28 void SetInterfaceState(Interface& adapter, InterfaceState state);
29
30 void SetAdapterName(Interface& adapter, const std::string& name);
31
32 void SetAdapterNamespace(Interface& adapter, int namespaceFd);
33
34 void SetWiphyNamespace(Interface& adapter, int namespaceFd);
35
36 std::optional<int> FindRoutingTableIdForInterface(const Interface& interface) const;
37
38 void ChangePrimaryRoutingTable(int newTableId);
39
40 std::vector<Route> ListRoutes(int family) const;
41
42 void ModifyRoute(const Route& route, Operation operation);
43
44 void ModifyAddress(Interface& adapter, const Address& address, Operation operation);
45
46 void ResetRoutingTable(int addressFamily, const Interface& interface);
47
48 void SetAdapterMacAddress(Interface& interface, const MacAddress& address);
49
50 void DisassociateAdapterFromBond(const std::string& bondInterfaceName, Interface& interface);
51
52 void AssociateAdapterWithBond(const std::string& bondInterfaceName, Interface& interface);
53
54 void ActivateAdapterWithBond(const std::string& bondInterfaceName, const Interface& interface);
55
56 Interface CreateBondAdapter(const std::string& name);
57
58 void EnableLoopbackRouting(Interface& interface);
59
60 void InitializeLoopbackConfiguration(Interface& gelnic, wsl::shared::hns::CreateDeviceFlags flags);
61
62 void AddMirroredLoopbackRoutingRules(Interface& gelnic, int addressFamily);
63
64 void UpdateMirroredLoopbackRulesForInterface(const std::string& interfaceName, Operation operation);
65
66 void UpdateLoopbackRoute(Interface& interface, const Address& address, Operation operation);
67
68 void ResetLoopbackRoutes();
69
70 void CreateTunAdapter(const std::string& name);
71
72 void DisableRouterDiscovery();
73
74 void DisableDAD();
75
76 void DisableIpv6AddressGeneration();
77
78 void EnableIpv4ArpFilter();
79
80 wsl::shared::conncheck::ConnCheckResult SendConnectRequest(const char* remoteAddress);
81
82 private:
83 void InitializeLoopbackConfigurationImpl(Interface& gelnic, int addressFamily);
84
85 RoutingTable& routingTable;
86 // Custom routing tables used for loopback mirroring. Not to be confused with the Linux "local" table
87 RoutingTable loopbackRoutingTable;
88 RoutingTable localRoutingTable;
89
90 IpRuleManager ruleManager;
91 IpNeighborManager neighborManager;
92
93 void ModifyNetSetting(int addressFamily, const char* settingName, const char* scope, const char* settingValue, size_t settingValueLen);
94 };