Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 83 additions & 5 deletions client/data/Methods/Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace specify_client.data;
Expand Down Expand Up @@ -37,7 +34,7 @@
NetAdapters = Utils.GetWmi("Win32_NetworkAdapterConfiguration",
"Description, DHCPEnabled, DHCPServer, DNSDomain, DNSDomainSuffixSearchOrder, DNSHostName, "
+ "DNSServerSearchOrder, IPEnabled, IPAddress, IPSubnet, DHCPLeaseObtained, DHCPLeaseExpires, "
+ "DefaultIPGateway, MACAddress, InterfaceIndex");
+ "DefaultIPGateway, MACAddress, InterfaceIndex, Index");

NetAdapters2 = Utils.GetWmi("MSFT_NetAdapter",
"*",
Expand All @@ -58,6 +55,7 @@
// This statement will avoid errors if the WMI value is not valid.
ReceiveSideScaling = rcvSideScaling is not null && rcvSideScaling != 0;

await GetNetworkAdapterAdvancedConfig();
AutoTuningLevelLocal = GetAutoTuningLevels();

if (!Settings.RedactNetworking)
Expand Down Expand Up @@ -343,6 +341,86 @@
// If this catch happens, the error has already been reported in GetHostsFile() and does not need to be reported again.
return "";
}


}

private const string RegKeyNetworkAdapterAdvancedConfig = "SYSTEM\\CurrentControlSet\\Control\\Class\\{4d36e972-e325-11ce-bfc1-08002be10318}";

/// <summary>
/// Retrive network adapters configuration, set in "Advanced" tab in adapter's options.
/// </summary>
/// <returns></returns>
public static async Task GetNetworkAdapterAdvancedConfig()
{
using RegistryKey subkey = Registry.LocalMachine.OpenSubKey(RegKeyNetworkAdapterAdvancedConfig);
if (subkey == null)
{
DebugLog.LogEvent($"Registry key for storing network adapters advanced configuration is missing!", DebugLog.Region.Networking, DebugLog.EventType.ERROR);
return;
}
foreach (var adapter in NetAdapters)
{
Dictionary<string,NetAdapterAdvancedParameter> netAdapterConfig = new();
try
{
using RegistryKey adapterKey = subkey.OpenSubKey(((uint)adapter["Index"]).ToString("0000"));
if (adapterKey == null)
{
DebugLog.LogEvent($"Could not find advanced configuration for {adapter["Description"]}", DebugLog.Region.Networking, DebugLog.EventType.ERROR);
continue;
}

using RegistryKey adapterParamsKey = adapterKey.OpenSubKey("NDI\\Params");
if (adapterParamsKey == null)
{
//No advanced configuration options are available for the adapter.
continue;
}

var parameterNames = adapterParamsKey.GetSubKeyNames();

foreach (string parameterName in parameterNames)
{
NetAdapterAdvancedParameter netAdapterParameter = new NetAdapterAdvancedParameter();
netAdapterParameter.CurrentValue = adapterKey.GetValue(parameterName)?.ToString();

using RegistryKey parameterKey = adapterParamsKey.OpenSubKey($"{parameterName}");

if (parameterKey == null)
{
DebugLog.LogEvent($"Missing parameter definitions for {parameterName} for network adapter: {adapter["Description"]}", DebugLog.Region.Networking, DebugLog.EventType.WARNING);
continue;
}

netAdapterParameter.Description = parameterKey.GetValue("ParamDesc")?.ToString();
netAdapterParameter.DefaultValue = parameterKey.GetValue("default")?.ToString();
netAdapterParameter.Type = parameterKey.GetValue("Type").ToString();

if (netAdapterParameter.Type.Equals("enum", StringComparison.OrdinalIgnoreCase))
{
using RegistryKey parameterEnumsKey = parameterKey.OpenSubKey("Enum");

if (parameterEnumsKey == null)
{
DebugLog.LogEvent($"Missing enum definitions for {parameterName} for network adapter: {adapter["Description"]}", DebugLog.Region.Networking, DebugLog.EventType.WARNING);
continue;
}

netAdapterParameter.PossibleEnumValues = parameterEnumsKey.GetValueNames()
.ToDictionary(x => x, x => parameterEnumsKey.GetValue(x)?.ToString());
netAdapterParameter.CurrentValueName = netAdapterParameter.PossibleEnumValues[netAdapterParameter.CurrentValue];

}
netAdapterConfig.Add(parameterName, netAdapterParameter);
}

adapter.Add("AdvancedConfiguration", netAdapterConfig);
}
catch (Exception e)
{
DebugLog.LogEvent($"Failed to read advanced configuration for network adapter: {adapter["Description"]}", DebugLog.Region.Networking, DebugLog.EventType.ERROR);
DebugLog.LogEvent($"{e}", DebugLog.Region.Networking, DebugLog.EventType.ERROR);
}
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment on lines +419 to +423
}
}
}
10 changes: 10 additions & 0 deletions client/data/Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ public class NetworkRoute
public List<double> PacketLoss = new List<double>();
}

public class NetAdapterAdvancedParameter
{
public string Description { get; set; }
public string Type { get; set; }
public string DefaultValue { get; set; }
public string CurrentValue { get; set; }
public string CurrentValueName { get; set; }
public Dictionary<string, string> PossibleEnumValues { get; set; }
}

public class InstalledApp
{
public string Name;
Expand Down