forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose a global switch to disable IPV6 (dotnet#55012)
Fixes dotnet#47583. Resolves dotnet#52287, dotnet#54807 and similar issues, without changing customer application code. Introduces an AppContext switch `System.Net.DisableIPv6` and environment variable `DOTNET_SYSTEM_NET_DISABLEIPV6` to emulate the lack of OS-level IPv6 support. This is useful to workaround dual-stack socket issues when the OS reports support of IPv6, but some other underlying infrastructure element (typically VPN) doesn't function well with IPv6 request. For consistency, this switch also impacts NameResolution and Ping, not only Sockets.
- Loading branch information
1 parent
e4cc8f9
commit 067aa16
Showing
10 changed files
with
133 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/libraries/Common/src/System/Net/SocketProtocolSupportPal.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Net.Sockets; | ||
|
||
namespace System.Net | ||
{ | ||
internal static partial class SocketProtocolSupportPal | ||
{ | ||
private const string DisableIPv6AppCtxSwitch = "System.Net.DisableIPv6"; | ||
private const string DisableIPv6EnvironmentVariable = "DOTNET_SYSTEM_NET_DISABLEIPV6"; | ||
|
||
public static bool OSSupportsIPv6 { get; } = IsSupported(AddressFamily.InterNetworkV6) && !IsIPv6Disabled(); | ||
public static bool OSSupportsIPv4 { get; } = IsSupported(AddressFamily.InterNetwork); | ||
public static bool OSSupportsUnixDomainSockets { get; } = IsSupported(AddressFamily.Unix); | ||
|
||
private static bool IsIPv6Disabled() | ||
{ | ||
// First check for the AppContext switch, giving it priority over the environment variable. | ||
if (AppContext.TryGetSwitch(DisableIPv6AppCtxSwitch, out bool disabled)) | ||
{ | ||
return disabled; | ||
} | ||
|
||
// AppContext switch wasn't used. Check the environment variable. | ||
string? envVar = Environment.GetEnvironmentVariable(DisableIPv6EnvironmentVariable); | ||
|
||
if (envVar is not null) | ||
{ | ||
return envVar == "1" || envVar.Equals("true", StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters