KeReleaseSpinLock(&Frontend->Lock, Irql);
}
+static NTSTATUS
+FrontendGetLuid(
+ IN PXENVIF_FRONTEND Frontend,
+ IN PMIB_IF_TABLE2 Table,
+ OUT PNET_LUID Luid
+ )
+{
+ ETHERNET_ADDRESS PermanentPhysicalAddress;
+ ULONG Index;
+ PMIB_IF_ROW2 Row;
+
+ MacQueryPermanentAddress(__FrontendGetMac(Frontend),
+ &PermanentPhysicalAddress);
+
+ for (Index = 0; Index < Table->NumEntries; Index++) {
+ Row = &Table->Table[Index];
+
+ if (memcmp(Row->PermanentPhysicalAddress,
+ &PermanentPhysicalAddress,
+ sizeof (ETHERNET_ADDRESS)) == 0)
+ goto found;
+ }
+
+ return STATUS_UNSUCCESSFUL;
+
+found:
+ *Luid = Row->InterfaceLuid;
+
+ return STATUS_SUCCESS;
+}
+
static NTSTATUS
FrontendInsertAddress(
IN OUT PSOCKADDR_INET *AddressTable,
static NTSTATUS
FrontendProcessAddressTable(
IN PXENVIF_FRONTEND Frontend,
- IN PMIB_UNICASTIPADDRESS_TABLE MibTable,
+ IN PMIB_UNICASTIPADDRESS_TABLE Table,
+ IN PNET_LUID Luid,
OUT PSOCKADDR_INET *AddressTable,
OUT PULONG AddressCount
)
{
- PNET_LUID Luid;
ULONG Index;
NTSTATUS status;
+ UNREFERENCED_PARAMETER(Frontend);
+
*AddressTable = NULL;
*AddressCount = 0;
- Luid = PdoGetLuid(__FrontendGetPdo(Frontend));
-
- for (Index = 0; Index < MibTable->NumEntries; Index++) {
- PMIB_UNICASTIPADDRESS_ROW Row = &MibTable->Table[Index];
+ for (Index = 0; Index < Table->NumEntries; Index++) {
+ PMIB_UNICASTIPADDRESS_ROW Row = &Table->Table[Index];
if (Row->InterfaceLuid.Info.IfType != Luid->Info.IfType)
continue;
{
PXENVIF_FRONTEND Frontend = Context;
PKEVENT Event;
+ NTSTATUS (*__GetIfTable2)(PMIB_IF_TABLE2 *);
NTSTATUS (*__NotifyUnicastIpAddressChange)(ADDRESS_FAMILY,
PUNICAST_IPADDRESS_CHANGE_CALLBACK,
PVOID,
Trace("====>\n");
+ status = LinkGetRoutineAddress("netio.sys",
+ "GetIfTable2",
+ (PVOID *)&__GetIfTable2);
+ if (!NT_SUCCESS(status))
+ goto fail1;
+
status = LinkGetRoutineAddress("netio.sys",
"NotifyUnicastIpAddressChange",
(PVOID *)&__NotifyUnicastIpAddressChange);
if (!NT_SUCCESS(status))
- goto fail1;
+ goto fail2;
status = LinkGetRoutineAddress("netio.sys",
"GetUnicastIpAddressTable",
(PVOID *)&__GetUnicastIpAddressTable);
if (!NT_SUCCESS(status))
- goto fail2;
+ goto fail3;
status = LinkGetRoutineAddress("netio.sys",
"FreeMibTable",
(PVOID *)&__FreeMibTable);
if (!NT_SUCCESS(status))
- goto fail3;
+ goto fail4;
status = LinkGetRoutineAddress("netio.sys",
"CancelMibChangeNotify2",
(PVOID *)&__CancelMibChangeNotify2);
if (!NT_SUCCESS(status))
- goto fail4;
+ goto fail5;
status = __NotifyUnicastIpAddressChange(AF_UNSPEC,
FrontendIpAddressChange,
TRUE,
&Handle);
if (!NT_SUCCESS(status))
- goto fail5;
+ goto fail6;
Event = ThreadGetEvent(Self);
for (;;) {
- PMIB_UNICASTIPADDRESS_TABLE MibTable;
+ PMIB_IF_TABLE2 IfTable;
+ NET_LUID Luid;
+ PMIB_UNICASTIPADDRESS_TABLE UnicastIpAddressTable;
KIRQL Irql;
PSOCKADDR_INET AddressTable;
ULONG AddressCount;
if (ThreadIsAlerted(Self))
break;
- status = __GetUnicastIpAddressTable(AF_UNSPEC, &MibTable);
+ IfTable = NULL;
+ UnicastIpAddressTable = NULL;
+
+ status = __GetIfTable2(&IfTable);
if (!NT_SUCCESS(status))
- continue;
+ goto loop;
+
+ status = FrontendGetLuid(Frontend,
+ IfTable,
+ &Luid);
+ if (!NT_SUCCESS(status))
+ goto loop;
+
+ status = __GetUnicastIpAddressTable(AF_UNSPEC,
+ &UnicastIpAddressTable);
+ if (!NT_SUCCESS(status))
+ goto loop;
KeAcquireSpinLock(&Frontend->Lock, &Irql);
// It is not safe to use interfaces before this point
if (Frontend->State != FRONTEND_CONNECTED &&
Frontend->State != FRONTEND_ENABLED)
- goto loop;
+ goto unlock;
status = FrontendProcessAddressTable(Frontend,
- MibTable,
+ UnicastIpAddressTable,
+ &Luid,
&AddressTable,
&AddressCount);
if (!NT_SUCCESS(status))
- goto loop;
+ goto unlock;
TransmitterUpdateAddressTable(__FrontendGetTransmitter(Frontend),
AddressTable,
if (AddressCount != 0)
__FrontendFree(AddressTable);
-loop:
+unlock:
KeReleaseSpinLock(&Frontend->Lock, Irql);
- __FreeMibTable(MibTable);
+loop:
+ if (UnicastIpAddressTable != NULL)
+ __FreeMibTable(UnicastIpAddressTable);
+
+ if (IfTable != NULL)
+ __FreeMibTable(IfTable);
}
status = __CancelMibChangeNotify2(Handle);
return STATUS_SUCCESS;
+fail6:
+ Error("fail6\n");
+
fail5:
Error("fail5\n");
return __PdoGetVifContext(Pdo);
}
-static FORCEINLINE NTSTATUS
-__PdoSetLuid(
- IN PXENVIF_PDO Pdo,
- IN HANDLE Key
- )
-{
- ULONG IfType;
- ULONG NetLuidIndex;
- NTSTATUS status;
-
- status = RegistryQueryDwordValue(Key, "*IfType", &IfType);
- if (!NT_SUCCESS(status))
- goto fail1;
-
- status = RegistryQueryDwordValue(Key, "NetLuidIndex", &NetLuidIndex);
- if (!NT_SUCCESS(status))
- goto fail2;
-
- Pdo->Luid.Info.IfType = IfType;
- Pdo->Luid.Info.NetLuidIndex = NetLuidIndex;
-
- Info("%s: %016llX\n", __PdoGetName(Pdo), Pdo->Luid.Value);
-
- return STATUS_SUCCESS;
-
-fail2:
- Error("fail2\n");
-
-fail1:
- Error("fail1 (%08x)\n", status);
-
- return status;
-}
-
-static FORCEINLINE PNET_LUID
-__PdoGetLuid(
- IN PXENVIF_PDO Pdo
- )
-{
- return &Pdo->Luid;
-}
-
-PNET_LUID
-PdoGetLuid(
- IN PXENVIF_PDO Pdo
- )
-{
- return __PdoGetLuid(Pdo);
-}
-
static FORCEINLINE NTSTATUS
__PdoParseAddress(
IN PCHAR Buffer,
return status;
}
+static FORCEINLINE PETHERNET_ADDRESS
+__PdoGetPermanentAddress(
+ IN PXENVIF_PDO Pdo
+ )
+{
+ return &Pdo->PermanentAddress;
+}
+
PETHERNET_ADDRESS
PdoGetPermanentAddress(
IN PXENVIF_PDO Pdo
)
{
- return &Pdo->PermanentAddress;
+ return __PdoGetPermanentAddress(Pdo);
}
static FORCEINLINE NTSTATUS
if (!NT_SUCCESS(status))
goto fail3;
- status = __PdoSetLuid(Pdo, Key);
- if (!NT_SUCCESS(status))
- goto fail4;
-
status = LinkGetRoutineAddress("netio.sys",
"GetIfTable2",
(PVOID *)&__GetIfTable2);
if (!NT_SUCCESS(status))
- goto fail5;
+ goto fail4;
status = LinkGetRoutineAddress("netio.sys",
"FreeMibTable",
(PVOID *)&__FreeMibTable);
if (!NT_SUCCESS(status))
- goto fail6;
+ goto fail5;
status = __GetIfTable2(&Table);
if (!NT_SUCCESS(status))
- goto fail7;
+ goto fail6;
for (Index = 0; Index < Table->NumEntries; Index++) {
PMIB_IF_ROW2 Row = &Table->Table[Index];
continue;
status = STATUS_UNSUCCESSFUL;
- if (memcmp(Row->PhysicalAddress,
- &Pdo->PermanentAddress,
+ if (memcmp(Row->PermanentPhysicalAddress,
+ __PdoGetPermanentAddress(Pdo),
sizeof (ETHERNET_ADDRESS)) == 0)
- goto fail8;
+ goto fail7;
}
StackLocation = IoGetCurrentIrpStackLocation(Irp);
status = PdoD3ToD0(Pdo);
if (!NT_SUCCESS(status))
- goto fail9;
+ goto fail8;
__PdoSetDevicePnpState(Pdo, Started);
return STATUS_SUCCESS;
-fail9:
- Error("fail9\n");
-
- __FreeMibTable(Table);
- goto fail6;
-
fail8:
Error("fail8\n");
- DriverRequestReboot();
__FreeMibTable(Table);
+ goto fail6;
fail7:
Error("fail7\n");
+ DriverRequestReboot();
+ __FreeMibTable(Table);
+
fail6:
Error("fail6\n");
fail5:
Error("fail5\n");
- RtlZeroMemory(&Pdo->Luid, sizeof (NET_LUID));
-
fail4:
Error("fail4\n");