[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[win-pv-devel] [PATCH] Lookup active network interfaces by index rather than LUID



The frontend address lookup code was failing to check whether the interface
it was querying was actually active, and also using LUID is kind of overkill
when we could just use index.

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/xenvif/frontend.c | 74 ++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 59 insertions(+), 15 deletions(-)

diff --git a/src/xenvif/frontend.c b/src/xenvif/frontend.c
index aea907d..257d314 100644
--- a/src/xenvif/frontend.c
+++ b/src/xenvif/frontend.c
@@ -455,10 +455,10 @@ fail1:
 }
 
 static NTSTATUS
-FrontendGetLuid(
+FrontendGetInterfaceIndex(
     IN  PXENVIF_FRONTEND    Frontend,
     IN  PMIB_IF_TABLE2      Table,
-    OUT PNET_LUID           Luid
+    OUT PNET_IFINDEX        InterfaceIndex
     )
 {
     ETHERNET_ADDRESS        PermanentPhysicalAddress;
@@ -471,16 +471,33 @@ FrontendGetLuid(
     for (Index = 0; Index < Table->NumEntries; Index++) {
         Row = &Table->Table[Index];
 
+        if (!(Row->InterfaceAndOperStatusFlags.HardwareInterface) ||
+            !(Row->InterfaceAndOperStatusFlags.ConnectorPresent))
+            continue;
+
+        if (Row->OperStatus != IfOperStatusUp)
+            continue;
+
+        if (Row->PhysicalAddressLength != sizeof (ETHERNET_ADDRESS))
+            continue;
+
         if (memcmp(Row->PermanentPhysicalAddress,
                    &PermanentPhysicalAddress,
-                   sizeof (ETHERNET_ADDRESS)) == 0)
-            goto found;
+                   sizeof (ETHERNET_ADDRESS)) != 0)
+            continue;
+
+        goto found;
     }
 
     return STATUS_UNSUCCESSFUL;
 
 found:
-    *Luid = Row->InterfaceLuid;
+    *InterfaceIndex = Row->InterfaceIndex;
+
+    Trace("[%u]: %ws (%ws)",
+          Row->InterfaceIndex,
+          Row->Alias,
+          Row->Description);
 
     return STATUS_SUCCESS;
 }
@@ -496,6 +513,8 @@ FrontendInsertAddress(
     PSOCKADDR_INET              Table;
     NTSTATUS                    status;
 
+    Trace("====>\n");
+
     for (Index = 0; Index < *AddressCount; Index++) {
         if ((*AddressTable)[Index].si_family != Address->si_family)
             continue;
@@ -531,6 +550,8 @@ FrontendInsertAddress(
     *AddressTable = Table;
 
 done:
+    Trace("<====\n");
+
     return STATUS_SUCCESS;
 
 fail1:
@@ -543,7 +564,7 @@ static NTSTATUS
 FrontendProcessAddressTable(
     IN  PXENVIF_FRONTEND            Frontend,
     IN  PMIB_UNICASTIPADDRESS_TABLE Table,
-    IN  PNET_LUID                   Luid,
+    IN  NET_IFINDEX                 InterfaceIndex,
     OUT PSOCKADDR_INET              *AddressTable,
     OUT PULONG                      AddressCount
     )
@@ -559,10 +580,7 @@ FrontendProcessAddressTable(
     for (Index = 0; Index < Table->NumEntries; Index++) {
         PMIB_UNICASTIPADDRESS_ROW   Row = &Table->Table[Index];
 
-        if (Row->InterfaceLuid.Info.IfType != Luid->Info.IfType)
-            continue;
-
-        if (Row->InterfaceLuid.Info.NetLuidIndex != Luid->Info.NetLuidIndex)
+        if (Row->InterfaceIndex != InterfaceIndex)
             continue;
 
         if (Row->Address.si_family != AF_INET &&
@@ -600,6 +618,8 @@ FrontendDumpAddressTable(
     ULONG                       IpVersion6Count;
     NTSTATUS                    status;
 
+    Trace("====>\n");
+
     status = XENBUS_STORE(TransactionStart,
                           &Frontend->StoreInterface,
                           &Transaction);
@@ -656,6 +676,13 @@ FrontendDumpAddressTable(
             if (!NT_SUCCESS(status))
                 goto fail4;
 
+            Trace("%s: %u.%u.%u.%u\n",
+                  __FrontendGetPrefix(Frontend),
+                  Address.Byte[0],
+                  Address.Byte[1],
+                  Address.Byte[2],
+                  Address.Byte[3]);
+
             IpVersion4Count++;
             break;
         }
@@ -690,6 +717,17 @@ FrontendDumpAddressTable(
             if (!NT_SUCCESS(status))
                 goto fail4;
 
+            Trace("%s: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
+                  __FrontendGetPrefix(Frontend),
+                  NTOHS(Address.Word[0]),
+                  NTOHS(Address.Word[1]),
+                  NTOHS(Address.Word[2]),
+                  NTOHS(Address.Word[3]),
+                  NTOHS(Address.Word[4]),
+                  NTOHS(Address.Word[5]),
+                  NTOHS(Address.Word[6]),
+                  NTOHS(Address.Word[7]));
+
             IpVersion6Count++;
             break;
         }
@@ -703,6 +741,8 @@ FrontendDumpAddressTable(
                           Transaction,
                           TRUE);
 
+    Trace("<====\n");
+
     return status;
 
 fail4:
@@ -806,12 +846,14 @@ FrontendMib(
 
     for (;;) { 
         PMIB_IF_TABLE2              IfTable;
-        NET_LUID                    Luid;
+        NET_IFINDEX                 InterfaceIndex;
         PMIB_UNICASTIPADDRESS_TABLE UnicastIpAddressTable;
         KIRQL                       Irql;
         PSOCKADDR_INET              AddressTable;
         ULONG                       AddressCount;
 
+        Trace("waiting...\n");
+
         (VOID) KeWaitForSingleObject(Event,
                                      Executive,
                                      KernelMode,
@@ -819,6 +861,8 @@ FrontendMib(
                                      NULL);
         KeClearEvent(Event);
 
+        Trace("awake\n");
+
         if (ThreadIsAlerted(Self))
             break;
 
@@ -829,9 +873,9 @@ FrontendMib(
         if (!NT_SUCCESS(status))
             goto loop;
 
-        status = FrontendGetLuid(Frontend,
-                                 IfTable,
-                                 &Luid);
+        status = FrontendGetInterfaceIndex(Frontend,
+                                           IfTable,
+                                           &InterfaceIndex);
         if (!NT_SUCCESS(status))
             goto loop;
 
@@ -849,7 +893,7 @@ FrontendMib(
 
         status = FrontendProcessAddressTable(Frontend,
                                              UnicastIpAddressTable,
-                                             &Luid,
+                                             InterfaceIndex,
                                              &AddressTable,
                                              &AddressCount);
         if (!NT_SUCCESS(status))
-- 
2.1.1


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.