X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=NetworkPkg%2FUefiPxeBcDxe%2FPxeBcDhcp4.c;h=b113505d9758851650b558806b9a59e2933b333c;hb=cd9944d72a2b51004efecdcf024a173721f1b3d1;hp=ecafc86a038780e2e7ac95e6cb7978fe17593dad;hpb=9063c328dff827ef9deb1ce0dde75112c496e072;p=mirror_edk2.git diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp4.c b/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp4.c index ecafc86a03..b113505d97 100644 --- a/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp4.c +++ b/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp4.c @@ -1,7 +1,7 @@ /** @file Functions implementation related with DHCPv4 for UefiPxeBc Driver. - Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2014, 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 @@ -472,6 +472,7 @@ PxeBcParseDhcp4Packet ( // // Parse DHCPv4 options in this offer, and store the pointers. + // First, try to parse DHCPv4 options from the DHCP optional parameters field. // for (Index = 0; Index < PXEBC_DHCP4_TAG_INDEX_MAX; Index++) { Options[Index] = PxeBcParseDhcp4Options ( @@ -480,6 +481,35 @@ PxeBcParseDhcp4Packet ( mInterestedDhcp4Tags[Index] ); } + // + // Second, Check if bootfilename and serverhostname is overloaded to carry DHCP options refers to rfc-2132. + // If yes, try to parse options from the BootFileName field, then ServerName field. + // + Option = Options[PXEBC_DHCP4_TAG_INDEX_OVERLOAD]; + if (Option != NULL) { + if ((Option->Data[0] & PXEBC_DHCP4_OVERLOAD_FILE) != 0) { + for (Index = 0; Index < PXEBC_DHCP4_TAG_INDEX_MAX; Index++) { + if (Options[Index] == NULL) { + Options[Index] = PxeBcParseDhcp4Options ( + (UINT8 *) Offer->Dhcp4.Header.BootFileName, + sizeof (Offer->Dhcp4.Header.BootFileName), + mInterestedDhcp4Tags[Index] + ); + } + } + } + if ((Option->Data[0] & PXEBC_DHCP4_OVERLOAD_SERVER_NAME) != 0) { + for (Index = 0; Index < PXEBC_DHCP4_TAG_INDEX_MAX; Index++) { + if (Options[Index] == NULL) { + Options[Index] = PxeBcParseDhcp4Options ( + (UINT8 *) Offer->Dhcp4.Header.ServerName, + sizeof (Offer->Dhcp4.Header.ServerName), + mInterestedDhcp4Tags[Index] + ); + } + } + } + } // // The offer with "yiaddr" is a proxy offer. @@ -506,33 +536,24 @@ PxeBcParseDhcp4Packet ( } // - // Check whether bootfilename and serverhostname overloaded, refers to rfc-2132 in details. - // If overloaded, parse the buffer as nested DHCPv4 options, or else just parse as bootfilename - // and serverhostname option. + // Parse PXE boot file name: + // According to PXE spec, boot file name should be read from DHCP option 67 (bootfile name) if present. + // Otherwise, read from boot file field in DHCP header. // - Option = Options[PXEBC_DHCP4_TAG_INDEX_OVERLOAD]; - if (Option != NULL && (Option->Data[0] & PXEBC_DHCP4_OVERLOAD_FILE) != 0) { - - Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] = PxeBcParseDhcp4Options ( - (UINT8 *) Offer->Dhcp4.Header.BootFileName, - sizeof (Offer->Dhcp4.Header.BootFileName), - PXEBC_DHCP4_TAG_BOOTFILE - ); + if (Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL) { // // RFC 2132, Section 9.5 does not strictly state Bootfile name (option 67) is null // terminated string. So force to append null terminated character at the end of string. // - if (Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL) { - Ptr8 = (UINT8*)&Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]->Data[0]; - Ptr8 += Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]->Length; - *Ptr8 = '\0'; + Ptr8 = (UINT8*)&Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]->Data[0]; + Ptr8 += Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]->Length; + if (*(Ptr8 - 1) != '\0') { + *Ptr8 = '\0'; } - - } else if ((Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] == NULL) && - (Offer->Dhcp4.Header.BootFileName[0] != 0)) { + } else if (Offer->Dhcp4.Header.BootFileName[0] != 0) { // // If the bootfile is not present and bootfilename is present in DHCPv4 packet, just parse it. - // Do not count dhcp option header here, or else will destory the serverhostname. + // Do not count dhcp option header here, or else will destroy the serverhostname. // Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] = (EFI_DHCP4_PACKET_OPTION *) (&Offer->Dhcp4.Header.BootFileName[0] - @@ -1574,7 +1595,7 @@ PxeBcDhcp4Dora ( CopyMem (&PxeMode->StationIp, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS)); CopyMem (&PxeMode->SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRESS)); - Status = PxeBcFlushStaionIp (Private, &Private->StationIp, &Private->SubnetMask); + Status = PxeBcFlushStationIp (Private, &Private->StationIp, &Private->SubnetMask); if (EFI_ERROR (Status)) { goto ON_EXIT; }