Revision: 15099
http://sourceforge.net/p/edk2/code/15099
Author: sfu5
Date: 2014-01-13 02:53:50 +0000 (Mon, 13 Jan 2014)
Log Message:
-----------
1. Update the parsing logic of DHCP message in PXE driver.
2. Append null terminated character at the end of option 67.
Signed-off-by: Fu Siyuan <[email protected]>
Reviewed-by: Dong, Guo <[email protected]>
Reviewed-by: Jin, Eric <[email protected]>
Modified Paths:
--------------
trunk/edk2/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c
trunk/edk2/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp4.c
Modified: trunk/edk2/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c
===================================================================
--- trunk/edk2/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c
2014-01-11 03:21:21 UTC (rev 15098)
+++ trunk/edk2/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c
2014-01-13 02:53:50 UTC (rev 15099)
@@ -2,7 +2,7 @@
Support for PxeBc dhcp functions.
Copyright (c) 2013, Red Hat, Inc.
-Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD
License
which accompanies this distribution. The full text of the license may be
found at
@@ -147,14 +147,44 @@
//
// Parse interested dhcp options and store their pointers in
CachedPacket->Dhcp4Option.
+ // First, try to parse DHCPv4 options from the DHCP optional parameters
field.
//
for (Index = 0; Index < PXEBC_DHCP4_TAG_INDEX_MAX; Index++) {
Options[Index] = PxeBcParseExtendOptions (
- Offer->Dhcp4.Option,
- GET_OPTION_BUFFER_LEN (Offer),
- mInterestedDhcp4Tags[Index]
- );
+ Offer->Dhcp4.Option,
+ GET_OPTION_BUFFER_LEN (Offer),
+ 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] = PxeBcParseExtendOptions (
+ (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] = PxeBcParseExtendOptions (
+ (UINT8 *) Offer->Dhcp4.Header.ServerName,
+ sizeof (Offer->Dhcp4.Header.ServerName),
+ mInterestedDhcp4Tags[Index]
+ );
+ }
+ }
+ }
+ }
//
// Check whether is an offer with PXEClient or not.
@@ -177,31 +207,23 @@
}
}
+
//
- // Check whether bootfilename/serverhostname overloaded (See details in dhcp
spec).
- // If overloaded, parse this buffer as nested dhcp options, or just parse
bootfilename/
- // 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] = PxeBcParseExtendOptions (
- (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 dhcp
packet, just parse it.
// And do not count dhcp option header, or else will destroy the
serverhostname.
Modified: trunk/edk2/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp4.c
===================================================================
--- trunk/edk2/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp4.c 2014-01-11 03:21:21 UTC
(rev 15098)
+++ trunk/edk2/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp4.c 2014-01-13 02:53:50 UTC
(rev 15099)
@@ -1,7 +1,7 @@
/** @file
Functions implementation related with DHCPv4 for UefiPxeBc Driver.
- Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD
License
@@ -472,6 +472,7 @@
//
// 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 @@
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,30 +536,21 @@
}
//
- // 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 destroy the
serverhostname.
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits