runtime icon indicating copy to clipboard operation
runtime copied to clipboard

GetActiveTcpConnections throw PlatformNotSupportedException on linux if IPV6 not enabled

Open tony-ssdut opened this issue 3 years ago • 7 comments

Description

We ran into a problem with IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections() on net6.0. Our Ubuntu linux machines don't have ipv6, specifically they don't have /proc/net/tcp6, they have /proc/net/tcp.

In StringParsingHelpers.Connections.cs:

internal static TcpConnectionInformation[] ParseActiveTcpConnectionsFromFiles(string tcp4ConnectionsFile, string tcp6ConnectionsFile)
{
    if (!File.Exists(tcp4ConnectionsFile) || !File.Exists(tcp6ConnectionsFile))
    {
         throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform);
    }
Unhandled exception. System.AggregateException: One or more errors occurred. (The information requested is unavailable on the current platform.)
 ---> Elasticsearch.Net.UnexpectedElasticsearchClientException: The information requested is unavailable on the current platform.
 ---> System.PlatformNotSupportedException: The information requested is unavailable on the current platform.
   at System.Net.NetworkInformation.StringParsingHelpers.ParseActiveTcpConnectionsFromFiles(String tcp4ConnectionsFile, String tcp6ConnectionsFile) in /_/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Connections.cs:line 36
   at System.Net.NetworkInformation.LinuxIPGlobalProperties.GetActiveTcpConnections() in /_/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/LinuxIPGlobalProperties.cs:line 10
   

We can't enable IPV6 due to security reason. Also, since net6.0 is the latest LTS .NET version, we can't upgrade to Net 7.0+ as well due to our policy.

So I think we a fix for this issue in Net 6.0.

Reproduction Steps

.NET 6.0 Ubuntu 22.04 disable IPV6 Write a sample to call IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections()

Expected behavior

Get the available IPV4 connection information

Actual behavior

throw PlatformNotSupportedException

Regression?

No response

Known Workarounds

Upgrade to Net7.0+

Configuration

No response

Other information

No response

tony-ssdut avatar Jul 17 '23 01:07 tony-ssdut

Tagging subscribers to this area: @dotnet/ncl See info in area-owners.md if you want to be subscribed.

Issue Details

Description

We ran into a problem with IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections() on net6.0. Our Ubuntu linux machines don't have ipv6, specifically they don't have /proc/net/tcp6, they have /proc/net/tcp.

In StringParsingHelpers.Connections.cs:

internal static TcpConnectionInformation[] ParseActiveTcpConnectionsFromFiles(string tcp4ConnectionsFile, string tcp6ConnectionsFile)
{
    if (!File.Exists(tcp4ConnectionsFile) || !File.Exists(tcp6ConnectionsFile))
    {
         throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform);
    }
Unhandled exception. System.AggregateException: One or more errors occurred. (The information requested is unavailable on the current platform.)
 ---> Elasticsearch.Net.UnexpectedElasticsearchClientException: The information requested is unavailable on the current platform.
 ---> System.PlatformNotSupportedException: The information requested is unavailable on the current platform.
   at System.Net.NetworkInformation.StringParsingHelpers.ParseActiveTcpConnectionsFromFiles(String tcp4ConnectionsFile, String tcp6ConnectionsFile) in /_/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/StringParsingHelpers.Connections.cs:line 36
   at System.Net.NetworkInformation.LinuxIPGlobalProperties.GetActiveTcpConnections() in /_/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/LinuxIPGlobalProperties.cs:line 10
   

We can't enable IPV6 due to security reason. Also, since net6.0 is the latest LTS .NET version, we can't upgrade to Net 7.0+ as well due to our policy.

So I think we a fix for this issue in Net 6.0.

Reproduction Steps

.NET 6.0 Ubuntu 22.04 disable IPV6 Write a sample to call IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections()

Expected behavior

Get the available IPV4 connection information

Actual behavior

throw PlatformNotSupportedException

Regression?

No response

Known Workarounds

Upgrade to Net7.0+

Configuration

No response

Other information

No response

Author: dev-tony-hu
Assignees: -
Labels:

area-System.Net

Milestone: -

ghost avatar Jul 17 '23 01:07 ghost

@dev-tony-hu can you share more details why you cannot upgrade to FTS instead of LTS? Especially given that the next LTS is around the corner, so you can upgrade again soon after that.

Another alternative would be to adopt 8.0 RC1 when it releases in about 2 months. It will be go-live. Would that work for you?

Overall, it would help to know the kind of application you have and impact on you / your customers if it is not fixed. How did you discover the bug? Is it blocking initial deployment of your app? Or are you perhaps changing Linux distros?

karelz avatar Jul 20 '23 09:07 karelz

This issue has been marked needs-author-action and may be missing some important information.

ghost avatar Jul 21 '23 11:07 ghost

@dev-tony-hu can you share more details why you cannot upgrade to FTS instead of LTS? Especially given that the next LTS is around the corner, so you can upgrade again soon after that.

Another alternative would be to adopt 8.0 RC1 when it releases in about 2 months. It will be go-live. Would that work for you?

Overall, it would help to know the kind of application you have and impact on you / your customers if it is not fixed. How did you discover the bug? Is it blocking initial deployment of your app? Or are you perhaps changing Linux distros?

Hello @karelz Our progress can't upgrade to net8.0 right now have two reasons.

  1. Due to our policy, we can only upgrade to latest public release LTS version.
  2. Our program has some components that can't upgrade due to some unsupported function in net 8.0, like binary serialization. We are working on it, but it may take quite some time.

I tested the net8.0 preview version already, it was fixed, that's why I have a backporting request.

Our use case is that we have thousands of VMs on azure and AWS, and we use this API to monitor the TCP requests on them. Due to security reason, we are going to disabled IPV6 recently, and after test, we found this API broken after disable IPV6 on VMs. Hopes this can be fixed in net 6.0 new version.

tony-ssdut avatar Jul 24 '23 03:07 tony-ssdut

@dev-tony-hu we will need more information about your service and the impact on you/your customers. If you don't feel comfortable sharing them on GitHub, you can create a support case with Microsoft (if you have that option), or reach me via email.

Regarding your LTS policy -- .NET 8.0 is LTS release, so that should be mute. Binary serialization is often misused and poses security risk to apps, that's why we are moving away from it. Given your general security concerns, I would expect that to be top priority for you -- therefore I would hope, that migration to .NET 8.0 might not be that far away for your app. Is that the case? Another alternative: Did you consider to delay disabling of IPv6 rollout until the other problems are solved?

karelz avatar Jul 31 '23 05:07 karelz

This issue has been marked needs-author-action and may be missing some important information.

ghost avatar Aug 03 '23 15:08 ghost

Not enough information to justify backport yet. Closing. Feel free to reopen when you have additional info available. Thanks!

karelz avatar Aug 08 '23 06:08 karelz