X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=NetworkPkg%2FUefiPxeBcDxe%2FPxeBcImpl.c;h=dc77d256f8e97afdfe82e7ea06e9d0f9b952d600;hb=2fad330f6baf350f80d043529f6a78ffec75daaa;hp=5f693729d612d2fa274261c2aadf6f0f8b8518e3;hpb=9063c328dff827ef9deb1ce0dde75112c496e072;p=mirror_edk2.git diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c index 5f693729d6..dc77d256f8 100644 --- a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c +++ b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c @@ -1,7 +1,7 @@ /** @file This implementation of EFI_PXE_BASE_CODE_PROTOCOL and EFI_LOAD_FILE_PROTOCOL. - Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.
+ Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -95,19 +95,19 @@ EfiPxeBcStart ( // // Configure block size for TFTP as a default value to handle all link layers. // - Private->BlockSize = (UINTN) (Private->Ip6MaxPacketSize - - PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE); + Private->BlockSize = Private->Ip6MaxPacketSize - + PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE; // // PXE over IPv6 starts here, initialize the fields and list header. // Private->Ip6Policy = PXEBC_IP6_POLICY_MAX; - Private->ProxyOffer.Dhcp6.Packet.Offer.Size = PXEBC_DHCP6_PACKET_MAX_SIZE; - Private->DhcpAck.Dhcp6.Packet.Ack.Size = PXEBC_DHCP6_PACKET_MAX_SIZE; - Private->PxeReply.Dhcp6.Packet.Ack.Size = PXEBC_DHCP6_PACKET_MAX_SIZE; + Private->ProxyOffer.Dhcp6.Packet.Offer.Size = PXEBC_CACHED_DHCP6_PACKET_MAX_SIZE; + Private->DhcpAck.Dhcp6.Packet.Ack.Size = PXEBC_CACHED_DHCP6_PACKET_MAX_SIZE; + Private->PxeReply.Dhcp6.Packet.Ack.Size = PXEBC_CACHED_DHCP6_PACKET_MAX_SIZE; for (Index = 0; Index < PXEBC_OFFER_MAX_NUM; Index++) { - Private->OfferBuffer[Index].Dhcp6.Packet.Offer.Size = PXEBC_DHCP6_PACKET_MAX_SIZE; + Private->OfferBuffer[Index].Dhcp6.Packet.Offer.Size = PXEBC_CACHED_DHCP6_PACKET_MAX_SIZE; } // @@ -124,6 +124,14 @@ EfiPxeBcStart ( if (EFI_ERROR (Status)) { goto ON_ERROR; } + + // + // Set Ip6 policy to Automatic to start the IP6 router discovery. + // + Status = PxeBcSetIp6Policy (Private); + if (EFI_ERROR (Status)) { + goto ON_ERROR; + } } else { AsciiPrint ("\n>>Start PXE over IPv4"); // @@ -140,18 +148,18 @@ EfiPxeBcStart ( // // Configure block size for TFTP as a default value to handle all link layers. // - Private->BlockSize = (UINTN) (Private->Ip4MaxPacketSize - - PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE); + Private->BlockSize = Private->Ip4MaxPacketSize - + PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE; // // PXE over IPv4 starts here, initialize the fields. // - Private->ProxyOffer.Dhcp4.Packet.Offer.Size = PXEBC_DHCP4_PACKET_MAX_SIZE; - Private->DhcpAck.Dhcp4.Packet.Ack.Size = PXEBC_DHCP4_PACKET_MAX_SIZE; - Private->PxeReply.Dhcp4.Packet.Ack.Size = PXEBC_DHCP4_PACKET_MAX_SIZE; + Private->ProxyOffer.Dhcp4.Packet.Offer.Size = PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE; + Private->DhcpAck.Dhcp4.Packet.Ack.Size = PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE; + Private->PxeReply.Dhcp4.Packet.Ack.Size = PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE; for (Index = 0; Index < PXEBC_OFFER_MAX_NUM; Index++) { - Private->OfferBuffer[Index].Dhcp4.Packet.Offer.Size = PXEBC_DHCP4_PACKET_MAX_SIZE; + Private->OfferBuffer[Index].Dhcp4.Packet.Offer.Size = PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE; } PxeBcSeedDhcp4Packet (&Private->SeedPacket, Private->Udp4Read); @@ -196,6 +204,18 @@ EfiPxeBcStart ( if (EFI_ERROR (Status)) { goto ON_ERROR; } + + // + //DHCP4 service allows only one of its children to be configured in + //the active state, If the DHCP4 D.O.R.A started by IP4 auto + //configuration and has not been completed, the Dhcp4 state machine + //will not be in the right state for the PXE to start a new round D.O.R.A. + //so we need to switch it's policy to static. + // + Status = PxeBcSetIp4Policy (Private); + if (EFI_ERROR (Status)) { + goto ON_ERROR; + } } // @@ -338,6 +358,7 @@ EfiPxeBcStop ( gBS->CloseEvent (Private->IcmpToken.Event); Private->IcmpToken.Event = NULL; } + Private->BootFileName = NULL; } gBS->CloseEvent (Private->UdpTimeOutEvent); @@ -345,6 +366,10 @@ EfiPxeBcStop ( Private->BootFileSize = 0; Private->SolicitTimes = 0; Private->ElapsedTime = 0; + ZeroMem (&Private->StationIp, sizeof (EFI_IP_ADDRESS)); + ZeroMem (&Private->SubnetMask, sizeof (EFI_IP_ADDRESS)); + ZeroMem (&Private->GatewayIp, sizeof (EFI_IP_ADDRESS)); + ZeroMem (&Private->ServerIp, sizeof (EFI_IP_ADDRESS)); // // Reset the mode data. @@ -428,10 +453,6 @@ EfiPxeBcDhcp ( // Start S.A.R.R. process to get a IPv6 address and other boot information. // Status = PxeBcDhcp6Sarr (Private, Private->Dhcp6); - - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } } else { // @@ -443,13 +464,11 @@ EfiPxeBcDhcp ( // Start D.O.R.A. process to get a IPv4 address and other boot information. // Status = PxeBcDhcp4Dora (Private, Private->Dhcp4); - - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } } - -ON_EXIT: + + // + // Reconfigure the UDP instance with the default configuration. + // if (Mode->UsingIpv6) { Private->Udp6Read->Configure (Private->Udp6Read, &Private->Udp6CfgData); } else { @@ -572,6 +591,7 @@ EfiPxeBcDiscover ( // // There are 3 methods to get the information for discover. // + ZeroMem (&DefaultInfo, sizeof (EFI_PXE_BASE_CODE_DISCOVER_INFO)); if (*Layer != EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL) { // // 1. Take the previous setting as the discover info. @@ -601,6 +621,7 @@ EfiPxeBcDiscover ( if (EFI_ERROR (Status)) { goto ON_EXIT; } + ASSERT (NewCreatedInfo != NULL); Info = NewCreatedInfo; } else { // @@ -617,7 +638,7 @@ EfiPxeBcDiscover ( if (Index != Info->IpCnt) { // // It's invalid if the first server doesn't accecpt any response - // and meanwhile any of the rest servers accept any reponse. + // but any of the other servers does accept any response. // Status = EFI_INVALID_PARAMETER; goto ON_EXIT; @@ -690,9 +711,7 @@ EfiPxeBcDiscover ( } } - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } else { + if (!EFI_ERROR (Status)) { // // Parse the cached PXE reply packet, and store it into mode data if valid. // @@ -837,8 +856,7 @@ EfiPxeBcMtftp ( (BufferSize == NULL) || (ServerIp == NULL) || ((BufferPtr == NULL) && DontUseBuffer) || - ((BlockSize != NULL) && (*BlockSize < PXE_MTFTP_DEFAULT_BLOCK_SIZE)) || - (!NetIp4IsUnicast (NTOHL (ServerIp->Addr[0]), 0) && !NetIp6IsValidUnicast (&ServerIp->v6))) { + ((BlockSize != NULL) && (*BlockSize < PXE_MTFTP_DEFAULT_BLOCK_SIZE))) { return EFI_INVALID_PARAMETER; } @@ -847,6 +865,16 @@ EfiPxeBcMtftp ( Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This); Mode = Private->PxeBc.Mode; + if (Mode->UsingIpv6) { + if (!NetIp6IsValidUnicast (&ServerIp->v6)) { + return EFI_INVALID_PARAMETER; + } + } else { + if (IP4_IS_UNSPECIFIED (NTOHL (ServerIp->Addr[0])) || IP4_IS_LOCAL_BROADCAST (NTOHL (ServerIp->Addr[0]))) { + return EFI_INVALID_PARAMETER; + } + } + if (Mode->UsingIpv6) { // // Set configuration data for Mtftp6 instance. @@ -964,11 +992,9 @@ EfiPxeBcMtftp ( Mode->IcmpErrorReceived = TRUE; } - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - -ON_EXIT: + // + // Reconfigure the UDP instance with the default configuration. + // if (Mode->UsingIpv6) { Private->Udp6Read->Configure (Private->Udp6Read, &Private->Udp6CfgData); } else { @@ -1059,7 +1085,8 @@ EfiPxeBcUdpWrite ( DoNotFragment = TRUE; } - if (!Mode->UsingIpv6 && GatewayIp != NULL && !NetIp4IsUnicast (NTOHL (GatewayIp->Addr[0]), 0)) { + if (!Mode->UsingIpv6 && GatewayIp != NULL && Mode->SubnetMask.Addr[0] != 0 && + !NetIp4IsUnicast (NTOHL (GatewayIp->Addr[0]), EFI_NTOHL(Mode->SubnetMask))) { // // Gateway is provided but it's not a unicast IPv4 address, while it will be ignored for IPv6. // @@ -1108,7 +1135,9 @@ EfiPxeBcUdpWrite ( &Private->SubnetMask.v4, &Private->GatewayIp.v4, &Private->CurSrcPort, - DoNotFragment + DoNotFragment, + Private->Mode.TTL, + Private->Mode.ToS ); } @@ -1260,7 +1289,7 @@ EfiPxeBcUdpRead ( UINTN FragmentIndex; UINT8 *FragmentBuffer; - if (This == NULL || DestIp == NULL || DestPort == NULL) { + if (This == NULL) { return EFI_INVALID_PARAMETER; } @@ -1271,9 +1300,9 @@ EfiPxeBcUdpRead ( Udp4Rx = NULL; Udp6Rx = NULL; - if (((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) != 0 && DestPort == NULL) || - ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_IP) != 0 && SrcIp == NULL) || - ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT) != 0 && SrcPort == NULL)) { + if (((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) == 0 && DestPort == NULL) || + ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_IP) == 0 && SrcIp == NULL) || + ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT) == 0 && SrcPort == NULL)) { return EFI_INVALID_PARAMETER; } @@ -1568,13 +1597,16 @@ EfiPxeBcSetIpFilter ( // return EFI_INVALID_PARAMETER; } - if ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0 && - (NetIp4IsUnicast (EFI_IP4 (NewFilter->IpList[Index].v4), 0) || - NetIp6IsValidUnicast (&NewFilter->IpList[Index].v6))) { - // - // If EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP is set and IPv4/IPv6 address - // is in IpList, promiscuous mode is needed. - // + if (Mode->UsingIpv6) { + if ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0 && + NetIp6IsValidUnicast (&NewFilter->IpList[Index].v6)) { + NeedPromiscuous = TRUE; + } + } else if ((EFI_NTOHL(Mode->StationIp) != 0) && + (EFI_NTOHL(Mode->SubnetMask) != 0) && + IP4_NET_EQUAL(EFI_NTOHL(Mode->StationIp), EFI_NTOHL(NewFilter->IpList[Index].v4), EFI_NTOHL(Mode->SubnetMask.v4)) && + NetIp4IsUnicast (EFI_IP4 (NewFilter->IpList[Index].v4), EFI_NTOHL(Mode->SubnetMask)) && + ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0)) { NeedPromiscuous = TRUE; } } @@ -1893,7 +1925,7 @@ EfiPxeBcSetParameters ( // Update the previous PxeBcCallback protocol. // Status = gBS->HandleProtocol ( - Private->Controller, + Mode->UsingIpv6 ? Private->Ip6Nic->Controller : Private->Ip4Nic->Controller, &gEfiPxeBaseCodeCallbackProtocolGuid, (VOID **) &Private->PxeBcCallback ); @@ -1968,9 +2000,7 @@ EfiPxeBcSetStationIP ( return EFI_INVALID_PARAMETER; } - if (NewStationIp != NULL && - (!NetIp4IsUnicast (NTOHL (NewStationIp->Addr[0]), 0) && - !NetIp6IsValidUnicast (&NewStationIp->v6))) { + if (NewStationIp != NULL && !NetIp6IsValidUnicast (&NewStationIp->v6)) { return EFI_INVALID_PARAMETER; } @@ -1984,6 +2014,14 @@ EfiPxeBcSetStationIP ( return EFI_INVALID_PARAMETER; } + if (!Mode->UsingIpv6 && NewStationIp != NULL) { + if (IP4_IS_UNSPECIFIED(NTOHL (NewStationIp->Addr[0])) || + IP4_IS_LOCAL_BROADCAST(NTOHL (NewStationIp->Addr[0])) || + (NewSubnetMask != NULL && NewSubnetMask->Addr[0] != 0 && !NetIp4IsUnicast (NTOHL (NewStationIp->Addr[0]), NTOHL (NewSubnetMask->Addr[0])))) { + return EFI_INVALID_PARAMETER; + } + } + if (!Mode->Started) { return EFI_NOT_STARTED; } @@ -2029,7 +2067,7 @@ EfiPxeBcSetStationIP ( CopyMem (&Private->SubnetMask ,NewSubnetMask, sizeof (EFI_IP_ADDRESS)); } - Status = PxeBcFlushStaionIp (Private, NewStationIp, NewSubnetMask); + Status = PxeBcFlushStationIp (Private, NewStationIp, NewSubnetMask); ON_EXIT: return Status; } @@ -2309,8 +2347,12 @@ EfiPxeLoadFile ( EFI_PXE_BASE_CODE_PROTOCOL *PxeBc; BOOLEAN UsingIpv6; EFI_STATUS Status; - BOOLEAN MediaPresent; + EFI_STATUS MediaStatus; + if (FilePath == NULL || !IsDevicePathEnd (FilePath)) { + return EFI_INVALID_PARAMETER; + } + VirtualNic = PXEBC_VIRTUAL_NIC_FROM_LOADFILE (This); Private = VirtualNic->Private; PxeBc = &Private->PxeBc; @@ -2331,9 +2373,9 @@ EfiPxeLoadFile ( // // Check media status before PXE start // - MediaPresent = TRUE; - NetLibDetectMedia (Private->Controller, &MediaPresent); - if (!MediaPresent) { + MediaStatus = EFI_SUCCESS; + NetLibDetectMediaWaitTimeout (Private->Controller, PXEBC_CHECK_MEDIA_WAITING_TIME, &MediaStatus); + if (MediaStatus != EFI_SUCCESS) { return EFI_NO_MEDIA; } @@ -2348,6 +2390,15 @@ EfiPxeLoadFile ( // Start Pxe Base Code to initialize PXE boot. // Status = PxeBc->Start (PxeBc, UsingIpv6); + if (Status == EFI_ALREADY_STARTED && UsingIpv6 != PxeBc->Mode->UsingIpv6) { + // + // PxeBc protocol has already been started but not on the required IP version, restart it. + // + Status = PxeBc->Stop (PxeBc); + if (!EFI_ERROR (Status)) { + Status = PxeBc->Start (PxeBc, UsingIpv6); + } + } if (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED) { Status = PxeBcLoadBootFile (Private, BufferSize, Buffer); } @@ -2362,6 +2413,16 @@ EfiPxeLoadFile ( // 3. unsupported. // PxeBc->Stop (PxeBc); + } else { + // + // The DHCP4 can have only one configured child instance so we need to stop + // reset the DHCP4 child before we return. Otherwise these programs which + // also need to use DHCP4 will be impacted. + // + if (!PxeBc->Mode->UsingIpv6) { + Private->Dhcp4->Stop (Private->Dhcp4); + Private->Dhcp4->Configure (Private->Dhcp4, NULL); + } } return Status;