[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [win-pv-devel] [PATCH 2/2] Publish network information to xenstore using documented paths
My recent patch series to Xen added documented paths for advertising vif hotplug capability and paths for publishing network interface information (name, IP addresses, etc.). This patch modifies XENVIF to make use of those new paths. Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx> --- src/xenvif/fdo.c | 8 +++ src/xenvif/frontend.c | 134 +++++++++++++++++++++++++++++++------------------- src/xenvif/mac.c | 91 +++++++++++----------------------- 3 files changed, 120 insertions(+), 113 deletions(-) diff --git a/src/xenvif/fdo.c b/src/xenvif/fdo.c index 479de93..0fc27ca 100644 --- a/src/xenvif/fdo.c +++ b/src/xenvif/fdo.c @@ -1318,6 +1318,14 @@ __FdoD3ToD0( if (!NT_SUCCESS(status)) goto fail1; + (VOID) XENBUS_STORE(Printf, + &Fdo->StoreInterface, + NULL, + "feature/hotplug", + "vif", + "%u", + TRUE); + Trace("<====\n"); return STATUS_SUCCESS; diff --git a/src/xenvif/frontend.c b/src/xenvif/frontend.c index 69aed73..98efee5 100644 --- a/src/xenvif/frontend.c +++ b/src/xenvif/frontend.c @@ -87,6 +87,8 @@ struct _XENVIF_FRONTEND { ULONG StatisticsCount; PXENVIF_THREAD MibThread; + CHAR Alias[IF_MAX_STRING_SIZE + 1]; + NET_IFINDEX InterfaceIndex; PSOCKADDR_INET AddressTable; ULONG AddressCount; }; @@ -458,15 +460,15 @@ fail1: } static NTSTATUS -FrontendGetInterfaceIndex( +FrontendProcessInterfaceTable( IN PXENVIF_FRONTEND Frontend, - IN PMIB_IF_TABLE2 Table, - OUT PNET_IFINDEX InterfaceIndex + IN PMIB_IF_TABLE2 Table ) { ETHERNET_ADDRESS PermanentPhysicalAddress; ULONG Index; PMIB_IF_ROW2 Row; + NTSTATUS status; MacQueryPermanentAddress(__FrontendGetMac(Frontend), &PermanentPhysicalAddress); @@ -494,12 +496,13 @@ FrontendGetInterfaceIndex( return STATUS_UNSUCCESSFUL; found: - *InterfaceIndex = Row->InterfaceIndex; + Frontend->InterfaceIndex = Row->InterfaceIndex; - Trace("[%u]: %ws (%ws)\n", - Row->InterfaceIndex, - Row->Alias, - Row->Description); + status = RtlStringCbPrintfA(Frontend->Alias, + sizeof (Frontend->Alias), + "%ws", + Row->Alias); + ASSERT(NT_SUCCESS(status)); return STATUS_SUCCESS; } @@ -564,8 +567,7 @@ fail1: static NTSTATUS FrontendProcessAddressTable( IN PXENVIF_FRONTEND Frontend, - IN PMIB_UNICASTIPADDRESS_TABLE Table, - IN NET_IFINDEX InterfaceIndex + IN PMIB_UNICASTIPADDRESS_TABLE Table ) { ULONG Index; @@ -583,7 +585,7 @@ FrontendProcessAddressTable( for (Index = 0; Index < Table->NumEntries; Index++) { PMIB_UNICASTIPADDRESS_ROW Row = &Table->Table[Index]; - if (Row->InterfaceIndex != InterfaceIndex) + if (Row->InterfaceIndex != Frontend->InterfaceIndex) continue; if (Row->Address.si_family != AF_INET && @@ -604,6 +606,43 @@ fail1: } static NTSTATUS +FrontendDumpAlias( + IN PXENVIF_FRONTEND Frontend + ) +{ + NTSTATUS status; + + status = XENBUS_STORE(Remove, + &Frontend->StoreInterface, + NULL, + __FrontendGetPrefix(Frontend), + "name"); + if (!NT_SUCCESS(status) && + status != STATUS_OBJECT_NAME_NOT_FOUND) + goto fail1; + + status = XENBUS_STORE(Printf, + &Frontend->StoreInterface, + NULL, + __FrontendGetPrefix(Frontend), + "name", + "%s", + Frontend->Alias); + if (!NT_SUCCESS(status)) + goto fail2; + + return STATUS_SUCCESS; + +fail2: + Error("fail2\n"); + +fail1: + Error("fail1 (%08x)\n", status); + + return status; +} + +static NTSTATUS FrontendDumpAddressTable( IN PXENVIF_FRONTEND Frontend ) @@ -647,7 +686,7 @@ FrontendDumpAddressTable( switch (Frontend->AddressTable[Index].si_family) { case AF_INET: { IPV4_ADDRESS Address; - CHAR Node[sizeof ("ipv4/address/XXXXXXXX")]; + CHAR Node[sizeof ("ipv4/XXXXXXXX")]; RtlCopyMemory(Address.Byte, &Frontend->AddressTable[Index].Ipv4.sin_addr.s_addr, @@ -655,7 +694,7 @@ FrontendDumpAddressTable( status = RtlStringCbPrintfA(Node, sizeof (Node), - "ipv4/address/%u", + "ipv4/%u", IpVersion4Count); ASSERT(NT_SUCCESS(status)); @@ -672,19 +711,12 @@ 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; } case AF_INET6: { IPV6_ADDRESS Address; - CHAR Node[sizeof ("ipv6/address/XXXXXXXX")]; + CHAR Node[sizeof ("ipv6/XXXXXXXX")]; RtlCopyMemory(Address.Byte, &Frontend->AddressTable[Index].Ipv6.sin6_addr.s6_addr, @@ -692,7 +724,7 @@ FrontendDumpAddressTable( status = RtlStringCbPrintfA(Node, sizeof (Node), - "ipv6/address/%u", + "ipv6/%u", IpVersion6Count); ASSERT(NT_SUCCESS(status)); @@ -713,17 +745,6 @@ 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; } @@ -842,7 +863,6 @@ FrontendMib( for (;;) { PMIB_IF_TABLE2 IfTable; - NET_IFINDEX InterfaceIndex; PMIB_UNICASTIPADDRESS_TABLE UnicastIpAddressTable; KIRQL Irql; @@ -867,9 +887,8 @@ FrontendMib( if (!NT_SUCCESS(status)) goto loop; - status = FrontendGetInterfaceIndex(Frontend, - IfTable, - &InterfaceIndex); + status = FrontendProcessInterfaceTable(Frontend, + IfTable); if (!NT_SUCCESS(status)) goto loop; @@ -878,22 +897,19 @@ FrontendMib( 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 unlock; - status = FrontendProcessAddressTable(Frontend, - UnicastIpAddressTable, - InterfaceIndex); + UnicastIpAddressTable); if (!NT_SUCCESS(status)) - goto unlock; + goto loop; - (VOID) FrontendDumpAddressTable(Frontend); + KeAcquireSpinLock(&Frontend->Lock, &Irql); + + if (Frontend->State == FRONTEND_CONNECTED || + Frontend->State == FRONTEND_ENABLED) { + (VOID) FrontendDumpAlias(Frontend); + (VOID) FrontendDumpAddressTable(Frontend); + } -unlock: KeReleaseSpinLock(&Frontend->Lock, Irql); loop: @@ -1409,6 +1425,12 @@ FrontendClose( FrontendReleaseBackend(Frontend); + (VOID) XENBUS_STORE(Remove, + &Frontend->StoreInterface, + NULL, + NULL, + __FrontendGetPrefix(Frontend)); + XENBUS_STORE(Release, &Frontend->StoreInterface); Trace("<====\n"); @@ -2262,7 +2284,7 @@ FrontendInitialize( if (!NT_SUCCESS(status)) goto fail2; - Length = sizeof ("data/vif/") + (ULONG)strlen(Name); + Length = sizeof ("attr/vif/") + (ULONG)strlen(Name); Prefix = __FrontendAllocate(Length); status = STATUS_NO_MEMORY; @@ -2271,7 +2293,7 @@ FrontendInitialize( status = RtlStringCbPrintfA(Prefix, Length, - "data/vif/%s", + "attr/vif/%s", Name); if (!NT_SUCCESS(status)) goto fail4; @@ -2415,6 +2437,16 @@ FrontendTeardown( ThreadJoin(Frontend->MibThread); Frontend->MibThread = NULL; + if (Frontend->AddressCount != 0) { + __FrontendFree(Frontend->AddressTable); + + Frontend->AddressTable = NULL; + Frontend->AddressCount = 0; + } + + RtlZeroMemory(Frontend->Alias, sizeof (Frontend->Alias)); + Frontend->InterfaceIndex = 0; + ThreadAlert(Frontend->EjectThread); ThreadJoin(Frontend->EjectThread); Frontend->EjectThread = NULL; diff --git a/src/xenvif/mac.c b/src/xenvif/mac.c index 91467d6..0a771a4 100644 --- a/src/xenvif/mac.c +++ b/src/xenvif/mac.c @@ -101,19 +101,6 @@ __MacSetPermanentAddress( Mac->PermanentAddress = *Address; - (VOID) XENBUS_STORE(Printf, - &Mac->StoreInterface, - NULL, - FrontendGetPrefix(Frontend), - "mac/unicast/permanent", - "%02x:%02x:%02x:%02x:%02x:%02x", - Mac->PermanentAddress.Byte[0], - Mac->PermanentAddress.Byte[1], - Mac->PermanentAddress.Byte[2], - Mac->PermanentAddress.Byte[3], - Mac->PermanentAddress.Byte[4], - Mac->PermanentAddress.Byte[5]); - Info("%s: %02X:%02X:%02X:%02X:%02X:%02X\n", FrontendGetPrefix(Frontend), Mac->PermanentAddress.Byte[0], @@ -155,19 +142,6 @@ __MacSetCurrentAddress( Mac->CurrentAddress = *Address; - (VOID) XENBUS_STORE(Printf, - &Mac->StoreInterface, - NULL, - FrontendGetPrefix(Frontend), - "mac/unicast/current", - "%02x:%02x:%02x:%02x:%02x:%02x", - Mac->CurrentAddress.Byte[0], - Mac->CurrentAddress.Byte[1], - Mac->CurrentAddress.Byte[2], - Mac->CurrentAddress.Byte[3], - Mac->CurrentAddress.Byte[4], - Mac->CurrentAddress.Byte[5]); - Info("%s: %02X:%02X:%02X:%02X:%02X:%02X\n", FrontendGetPrefix(Frontend), Mac->CurrentAddress.Byte[0], @@ -261,7 +235,7 @@ fail1: } static NTSTATUS -MacDumpMulticastList( +MacDumpAddressTable( IN PXENVIF_MAC Mac ) { @@ -283,46 +257,48 @@ MacDumpMulticastList( if (!Mac->Connected) goto fail1; - if (Mac->MulticastCount != 0) { - Address = __MacAllocate(sizeof (ETHERNET_ADDRESS) * - Mac->MulticastCount); + Count = 1 + Mac->MulticastCount; + + Address = __MacAllocate(sizeof (ETHERNET_ADDRESS) * + Count); - status = STATUS_NO_MEMORY; - if (Address == NULL) - goto fail2; + status = STATUS_NO_MEMORY; + if (Address == NULL) + goto fail2; - Count = 0; - for (ListEntry = Mac->MulticastList.Flink; - ListEntry != &Mac->MulticastList; - ListEntry = ListEntry->Flink) { - PXENVIF_MAC_MULTICAST Multicast; + Index = 0; - Multicast = CONTAINING_RECORD(ListEntry, - XENVIF_MAC_MULTICAST, - ListEntry); + MacQueryCurrentAddress(Mac, &Address[Index]); + Index++; - Address[Count++] = Multicast->Address; - } - ASSERT3U(Count, ==, Mac->MulticastCount); - } else { - Address = NULL; - Count = 0; + for (ListEntry = Mac->MulticastList.Flink; + ListEntry != &Mac->MulticastList; + ListEntry = ListEntry->Flink) { + PXENVIF_MAC_MULTICAST Multicast; + + Multicast = CONTAINING_RECORD(ListEntry, + XENVIF_MAC_MULTICAST, + ListEntry); + + Address[Index++] = Multicast->Address; } + ASSERT3U(Index, ==, Count); + KeReleaseSpinLock(&Mac->Lock, Irql); (VOID) XENBUS_STORE(Remove, &Mac->StoreInterface, NULL, FrontendGetPrefix(Frontend), - "mac/multicast"); + "mac"); for (Index = 0; Index < Count; Index++) { - CHAR Node[sizeof ("mac/multicast/XX")]; + CHAR Node[sizeof ("mac/XX")]; status = RtlStringCbPrintfA(Node, sizeof (Node), - "mac/multicast/%u", + "mac/%u", Index); ASSERT(NT_SUCCESS(status)); @@ -338,15 +314,6 @@ MacDumpMulticastList( Address[Index].Byte[3], Address[Index].Byte[4], Address[Index].Byte[5]); - - Trace("%s: %02x:%02x:%02x:%02x:%02x:%02x\n", - FrontendGetPrefix(Frontend), - Address[Index].Byte[0], - Address[Index].Byte[1], - Address[Index].Byte[2], - Address[Index].Byte[3], - Address[Index].Byte[4], - Address[Index].Byte[5]); } if (Address != NULL) @@ -454,7 +421,7 @@ MacConnect( Mac->Connected = TRUE; KeReleaseSpinLockFromDpcLevel(&Mac->Lock); - (VOID) MacDumpMulticastList(Mac); + (VOID) MacDumpAddressTable(Mac); return STATUS_SUCCESS; @@ -767,7 +734,7 @@ MacAddMulticastAddress( Mac->MulticastCount++; KeReleaseSpinLock(&Mac->Lock, Irql); - (VOID) MacDumpMulticastList(Mac); + (VOID) MacDumpAddressTable(Mac); Trace("%s: %02X:%02X:%02X:%02X:%02X:%02X\n", FrontendGetPrefix(Frontend), @@ -827,7 +794,7 @@ found: KeReleaseSpinLock(&Mac->Lock, Irql); - (VOID) MacDumpMulticastList(Mac); + (VOID) MacDumpAddressTable(Mac); Trace("%s: %02X:%02X:%02X:%02X:%02X:%02X\n", FrontendGetPrefix(Frontend), -- 2.1.1 _______________________________________________ win-pv-devel mailing list win-pv-devel@xxxxxxxxxxxxxxxxxxxx http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |