Linux NIC speed type made long to fit the actual value (#32223)
authorMarie Píchová <mapichov@microsoft.com>
Fri, 14 Feb 2020 10:53:11 +0000 (11:53 +0100)
committerGitHub <noreply@github.com>
Fri, 14 Feb 2020 10:53:11 +0000 (11:53 +0100)
Fixes #18090

Linux pal level struct for network info had only int32 field for speed. Even though our public API has it as long. The problem was in value overflowing in calculation MBits --> Bits.

src/libraries/Common/src/Interop/Unix/System.Native/Interop.EnumerateInterfaceAddresses.cs
src/libraries/Native/Unix/System.Native/pal_interfaceaddresses.c
src/libraries/Native/Unix/System.Native/pal_interfaceaddresses.h
src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/NetworkInterfaceBasicTest.cs

index ada781b..8e03a33 100644 (file)
@@ -32,8 +32,8 @@ internal static partial class Interop
         public unsafe struct NetworkInterfaceInfo
         {
             public fixed byte Name[16];
+            public long Speed;
             public int InterfaceIndex;
-            public int Speed;
             public int Mtu;
             public ushort HardwareType;
             public byte OperationalState;
index 4db081d..a656046 100644 (file)
@@ -373,7 +373,7 @@ int32_t SystemNative_GetNetworkInterfaces(int32_t * interfaceCount, NetworkInter
                         ecmd.cmd = ETHTOOL_GSET;
                         if (ioctl(socketfd, SIOCETHTOOL, &ifr) == 0)
                         {
-                            nii->Speed = (int)ethtool_cmd_speed(&ecmd);
+                            nii->Speed = (int64_t)ethtool_cmd_speed(&ecmd);
                             if (nii->Speed > 0)
                             {
                                 // If we did not get -1
index ab4392a..feb1da2 100644 (file)
@@ -37,8 +37,8 @@ typedef struct
 typedef struct
 {
     char Name[16];              // OS Interface name.
+    int64_t Speed;              // Link speed for physical interfaces.
     uint32_t InterfaceIndex;    // Interface index.
-    int32_t Speed;              // Link speed for physical interfaces.
     int32_t Mtu;                // Interface MTU.
     uint16_t HardwareType;      // Interface mapped from L2 to NetworkInterfaceType.
     uint8_t OperationalState;   // Operational status.
index b5088ab..e26f9d1 100644 (file)
@@ -53,7 +53,6 @@ namespace System.Net.NetworkInformation.Tests
 
         [Fact]
         [PlatformSpecific(TestPlatforms.Linux)]  // Some APIs are not supported on Linux
-        [ActiveIssue("https://github.com/dotnet/runtime/issues/18090")]
         public void BasicTest_AccessInstanceProperties_NoExceptions_Linux()
         {
             foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())