]> git.proxmox.com Git - mirror_edk2.git/commitdiff
sync tracker:PXE misused the parameter of second since boot in DHCP header.
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 8 Jun 2009 02:13:36 +0000 (02:13 +0000)
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 8 Jun 2009 02:13:36 +0000 (02:13 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8496 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.h
MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c
MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c
MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c

index fa75215dadee71b631226732ec9b40ad25e92a20..36f3ecb81978155b8fffbaf4217497853dbac477 100644 (file)
@@ -6,7 +6,7 @@
   RFC 1534: Interoperation Between DHCP and BOOTP\r
   RFC 3396: Encoding Long Options in DHCP.\r
   \r
-Copyright (c) 2006 - 2008, Intel Corporation.<BR>\r
+Copyright (c) 2006 - 2009, Intel Corporation.<BR>\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -110,7 +110,7 @@ struct _DHCP_SERVICE {
 \r
   UDP_IO_PORT                   *UdpIo;       // Udp child receiving all DHCP message\r
   UDP_IO_PORT                   *LeaseIoPort; // Udp child with lease IP\r
-  NET_BUF                       *LastPacket;  // The last sent packet for retransmission\r
+  EFI_DHCP4_PACKET              *LastPacket;  // The last sent packet for retransmission\r
   EFI_MAC_ADDRESS               Mac;\r
   UINT8                         HwType;\r
   UINT8                         HwLen;\r
@@ -126,6 +126,7 @@ struct _DHCP_SERVICE {
   EFI_EVENT                     Timer;\r
 \r
   UINT32                        PacketToLive; // Retransmission timer for our packets\r
+  UINT32                        LastTimeout;  // Record the init value of PacketToLive every time\r
   INTN                          CurRetry;\r
   INTN                          MaxRetries;\r
   UINT32                        LeaseLife;\r
index 7c48340d8b32751c9132de73fa02f9c7fb609411..dc9b0412a834899a77ccc694cc11a11d3883281c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   EFI DHCP protocol implementation.\r
   \r
-Copyright (c) 2006 - 2008, Intel Corporation.<BR>\r
+Copyright (c) 2006 - 2009, Intel Corporation.<BR>\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -227,7 +227,7 @@ DhcpSetState (
 \r
   DhcpSb->CurRetry      = 0;\r
   DhcpSb->PacketToLive  = 0;\r
-\r
+  DhcpSb->LastTimeout   = 0;\r
   DhcpSb->DhcpState     = State;\r
   return EFI_SUCCESS;\r
 }\r
@@ -260,6 +260,7 @@ DhcpSetTransmitTimer (
   }\r
 \r
   DhcpSb->PacketToLive = Times[DhcpSb->CurRetry];\r
+  DhcpSb->LastTimeout  = DhcpSb->PacketToLive;\r
 \r
   return;\r
 }\r
@@ -470,11 +471,12 @@ DhcpCleanLease (
   }\r
 \r
   if (DhcpSb->LastPacket != NULL) {\r
-    NetbufFree (DhcpSb->LastPacket);\r
+    FreePool (DhcpSb->LastPacket);\r
     DhcpSb->LastPacket = NULL;\r
   }\r
 \r
   DhcpSb->PacketToLive  = 0;\r
+  DhcpSb->LastTimeout   = 0;\r
   DhcpSb->CurRetry      = 0;\r
   DhcpSb->MaxRetries    = 0;\r
   DhcpSb->LeaseLife     = 0;\r
@@ -1353,11 +1355,10 @@ DhcpSendMessage (
   // Save it as the last sent packet for retransmission\r
   //\r
   if (DhcpSb->LastPacket != NULL) {\r
-    NetbufFree (DhcpSb->LastPacket);\r
+    FreePool (DhcpSb->LastPacket);\r
   }\r
 \r
-  NET_GET_REF (Wrap);\r
-  DhcpSb->LastPacket = Wrap;\r
+  DhcpSb->LastPacket = Packet;\r
   DhcpSetTransmitTimer (DhcpSb);\r
 \r
   //\r
@@ -1377,10 +1378,19 @@ DhcpSendMessage (
   }\r
 \r
   ASSERT (UdpIo != NULL);\r
-  Status = UdpIoSendDatagram (UdpIo, Wrap, &EndPoint, 0, DhcpOnPacketSent, DhcpSb);\r
+  NET_GET_REF (Wrap);\r
+  \r
+  Status = UdpIoSendDatagram (\r
+             UdpIo, \r
+             Wrap, \r
+             &EndPoint, \r
+             0, \r
+             DhcpOnPacketSent, \r
+             DhcpSb\r
+             );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    NetbufFree (Wrap);\r
+    NET_PUT_REF (Wrap);\r
     return EFI_ACCESS_DENIED;\r
   }\r
 \r
@@ -1405,10 +1415,25 @@ DhcpRetransmit (
 {\r
   UDP_IO_PORT               *UdpIo;\r
   UDP_POINTS                EndPoint;\r
+  NET_BUF                   *Wrap;\r
+  NET_FRAGMENT              Frag;\r
   EFI_STATUS                Status;\r
 \r
   ASSERT (DhcpSb->LastPacket != NULL);\r
 \r
+  DhcpSb->LastPacket->Dhcp4.Header.Seconds = HTONS (*(UINT16 *)(&DhcpSb->LastTimeout));\r
+\r
+  //\r
+  // Wrap it into a netbuf then send it.\r
+  //\r
+  Frag.Bulk = (UINT8 *) &DhcpSb->LastPacket->Dhcp4.Header;\r
+  Frag.Len  = DhcpSb->LastPacket->Length;\r
+  Wrap      = NetbufFromExt (&Frag, 1, 0, 0, DhcpReleasePacket, DhcpSb->LastPacket);\r
+\r
+  if (Wrap == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  \r
   //\r
   // Broadcast the message, unless we know the server address.\r
   //\r
@@ -1426,10 +1451,10 @@ DhcpRetransmit (
 \r
   ASSERT (UdpIo != NULL);\r
 \r
-  NET_GET_REF (DhcpSb->LastPacket);\r
+  NET_GET_REF (Wrap);\r
   Status = UdpIoSendDatagram (\r
              UdpIo,\r
-             DhcpSb->LastPacket,\r
+             Wrap,\r
              &EndPoint,\r
              0,\r
              DhcpOnPacketSent,\r
@@ -1437,7 +1462,7 @@ DhcpRetransmit (
              );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    NET_PUT_REF (DhcpSb->LastPacket);\r
+    NET_PUT_REF (Wrap);\r
     return EFI_ACCESS_DENIED;\r
   }\r
 \r
index 95f6e9d4df612920e8e462c52873fcdfd99e261d..ad7d139cf71719386fe24de444152f3ab8e0b7cf 100644 (file)
@@ -1117,6 +1117,7 @@ PxeBcDiscvBootService (
   UINT8                               VendorOptLen;\r
   CHAR8                               *SystemSerialNumber;\r
   EFI_DHCP4_HEADER                    *DhcpHeader;\r
+  UINT32                              Xid;\r
 \r
 \r
   Mode      = Private->PxeBc.Mode;\r
@@ -1183,14 +1184,15 @@ PxeBcDiscvBootService (
 \r
     DhcpHeader->HwAddrLen = sizeof (EFI_GUID);\r
   }\r
-\r
-  Token.Packet->Dhcp4.Header.Xid      = NET_RANDOM (NetRandomInitSeed ());\r
-  Token.Packet->Dhcp4.Header.Reserved = (UINT16) ((IsBCast) ? 0xf000 : 0x0);\r
+       \r
+  Xid                                 = NET_RANDOM (NetRandomInitSeed ());\r
+  Token.Packet->Dhcp4.Header.Xid      = HTONL(Xid);\r
+  Token.Packet->Dhcp4.Header.Reserved = HTONS((IsBCast) ? 0x8000 : 0);\r
   CopyMem (&Token.Packet->Dhcp4.Header.ClientAddr, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));\r
 \r
   Token.RemotePort = Sport;\r
 \r
-  if (DestIp == NULL) {\r
+  if (IsBCast) {\r
     SetMem (&Token.RemoteAddress, sizeof (EFI_IPv4_ADDRESS), 0xff);\r
   } else {\r
     CopyMem (&Token.RemoteAddress, DestIp, sizeof (EFI_IPv4_ADDRESS));\r
@@ -1210,7 +1212,8 @@ PxeBcDiscvBootService (
   //\r
   for (TryIndex = 1; TryIndex <= PXEBC_BOOT_REQUEST_RETRIES; TryIndex++) {\r
 \r
-    Token.TimeoutValue  = PXEBC_BOOT_REQUEST_TIMEOUT * TryIndex;\r
+    Token.TimeoutValue                  = (UINT16) (PXEBC_BOOT_REQUEST_TIMEOUT * TryIndex);\r
+    Token.Packet->Dhcp4.Header.Seconds  = (UINT16) (PXEBC_BOOT_REQUEST_TIMEOUT * (TryIndex - 1));\r
 \r
     Status              = Dhcp4->TransmitReceive (Dhcp4, &Token);\r
 \r
index 5a17537b1266b51bf7dbfe74e7a1698219ca8a01..646638674c1c53520f41bd3c6ecdf176f1cc2ef8 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Interface routines for PxeBc.\r
   \r
-Copyright (c) 2007 - 2008, Intel Corporation.<BR>\r
+Copyright (c) 2007 - 2009, Intel Corporation.<BR>\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -15,7 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "PxeBcImpl.h"\r
 \r
-EFI_LOAD_FILE_PROTOCOL  mLoadFileProtocolTemplate = { EfiPxeLoadFile };\r
+UINT32  mPxeDhcpTimeout[4] = { 4, 8, 16, 32 };\r
 \r
 /**\r
   Get and record the arp cache.\r
@@ -502,6 +502,7 @@ EfiPxeBcStop (
 \r
   Private->CurrentUdpSrcPort = 0;\r
   Private->Udp4Write->Configure (Private->Udp4Write, NULL);\r
+  Private->Udp4Read->Groups (Private->Udp4Read, FALSE, NULL);\r
   Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r
 \r
   Private->Dhcp4->Stop (Private->Dhcp4);\r
@@ -560,8 +561,6 @@ EfiPxeBcDhcp (
   EFI_DHCP4_MODE_DATA     Dhcp4Mode;\r
   EFI_DHCP4_PACKET_OPTION *OptList[PXEBC_DHCP4_MAX_OPTION_NUM];\r
   UINT32                  OptCount;\r
-  UINT32                  DiscoverTimeout;\r
-  UINTN                   Index;\r
   EFI_STATUS              Status;\r
   EFI_ARP_CONFIG_DATA     ArpConfigData;\r
 \r
@@ -589,76 +588,62 @@ EfiPxeBcDhcp (
 \r
   //\r
   // Set the DHCP4 config data.\r
+  // The four discovery timeouts are 4, 8, 16, 32 seconds respectively.\r
   //\r
   ZeroMem (&Dhcp4CfgData, sizeof (EFI_DHCP4_CONFIG_DATA));\r
   Dhcp4CfgData.OptionCount      = OptCount;\r
   Dhcp4CfgData.OptionList       = OptList;\r
   Dhcp4CfgData.Dhcp4Callback    = PxeBcDhcpCallBack;\r
   Dhcp4CfgData.CallbackContext  = Private;\r
-  Dhcp4CfgData.DiscoverTryCount = 1;\r
-  Dhcp4CfgData.DiscoverTimeout  = &DiscoverTimeout;\r
-\r
-  for (Index = 0; Index < PXEBC_DHCP4_DISCOVER_RETRIES; Index++) {\r
-    //\r
-    // The four discovery timeouts are 4, 8, 16, 32 seconds respectively.\r
-    //\r
-    DiscoverTimeout = (PXEBC_DHCP4_DISCOVER_INIT_TIMEOUT << Index);\r
+  Dhcp4CfgData.DiscoverTryCount = 4;\r
+  Dhcp4CfgData.DiscoverTimeout  = mPxeDhcpTimeout;\r
 \r
-    Status          = Dhcp4->Configure (Dhcp4, &Dhcp4CfgData);\r
-    if (EFI_ERROR (Status)) {\r
-      break;\r
-    }\r
-    //\r
-    // Zero those arrays to record the varies numbers of DHCP OFFERS.\r
-    //\r
-    Private->GotProxyOffer = FALSE;\r
-    Private->NumOffers     = 0;\r
-    Private->BootpIndex    = 0;\r
-    ZeroMem (Private->ServerCount, sizeof (Private->ServerCount));\r
-    ZeroMem (Private->ProxyIndex, sizeof (Private->ProxyIndex));\r
+  Status          = Dhcp4->Configure (Dhcp4, &Dhcp4CfgData);\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_EXIT;\r
+  }\r
+  \r
+  //\r
+  // Zero those arrays to record the varies numbers of DHCP OFFERS.\r
+  //\r
+  Private->GotProxyOffer = FALSE;\r
+  Private->NumOffers     = 0;\r
+  Private->BootpIndex    = 0;\r
+  ZeroMem (Private->ServerCount, sizeof (Private->ServerCount));\r
+  ZeroMem (Private->ProxyIndex, sizeof (Private->ProxyIndex));\r
 \r
-    Status = Dhcp4->Start (Dhcp4, NULL);\r
-    if (EFI_ERROR (Status)) {\r
-      if (Status == EFI_TIMEOUT) {\r
-        //\r
-        // If no response is received or all received offers don't match\r
-        // the PXE boot requirements, EFI_TIMEOUT will be returned.\r
-        //\r
-        continue;\r
-      }\r
-      if (Status == EFI_ICMP_ERROR) {\r
-        Mode->IcmpErrorReceived = TRUE;\r
-      }\r
-      //\r
-      // Other error status means the DHCP really fails.\r
-      //\r
-      break;\r
+  Status = Dhcp4->Start (Dhcp4, NULL);\r
+  if (EFI_ERROR (Status)) {\r
+    if (Status == EFI_ICMP_ERROR) {\r
+      Mode->IcmpErrorReceived = TRUE;\r
     }\r
+    goto ON_EXIT;\r
+  }\r
 \r
-    Status = Dhcp4->GetModeData (Dhcp4, &Dhcp4Mode);\r
-    if (EFI_ERROR (Status)) {\r
-      break;\r
-    }\r
+  Status = Dhcp4->GetModeData (Dhcp4, &Dhcp4Mode);\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_EXIT;\r
+  }\r
 \r
-    ASSERT (Dhcp4Mode.State == Dhcp4Bound);\r
+  ASSERT (Dhcp4Mode.State == Dhcp4Bound);\r
 \r
-    CopyMem (&Private->StationIp, &Dhcp4Mode.ClientAddress, sizeof (EFI_IPv4_ADDRESS));\r
-    CopyMem (&Private->SubnetMask, &Dhcp4Mode.SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
-    CopyMem (&Private->GatewayIp, &Dhcp4Mode.RouterAddress, sizeof (EFI_IPv4_ADDRESS));\r
+  CopyMem (&Private->StationIp, &Dhcp4Mode.ClientAddress, sizeof (EFI_IPv4_ADDRESS));\r
+  CopyMem (&Private->SubnetMask, &Dhcp4Mode.SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
+  CopyMem (&Private->GatewayIp, &Dhcp4Mode.RouterAddress, sizeof (EFI_IPv4_ADDRESS));\r
 \r
-    CopyMem (&Mode->StationIp, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));\r
-    CopyMem (&Mode->SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
+  CopyMem (&Mode->StationIp, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));\r
+  CopyMem (&Mode->SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
 \r
-    //\r
-    // Check the selected offer to see whether BINL is required, if no or BINL is\r
-    // finished, set the various Mode members.\r
-    //\r
-    Status = PxeBcCheckSelectedOffer (Private);\r
-    if (!EFI_ERROR (Status)) {\r
-      break;\r
-    }\r
+  //\r
+  // Check the selected offer to see whether BINL is required, if no or BINL is\r
+  // finished, set the various Mode members.\r
+  //\r
+  Status = PxeBcCheckSelectedOffer (Private);\r
+  if (!EFI_ERROR (Status)) {\r
+    goto ON_EXIT;\r
   }\r
 \r
+ON_EXIT:\r
   if (EFI_ERROR (Status)) {\r
     Dhcp4->Stop (Dhcp4);\r
     Dhcp4->Configure (Dhcp4, NULL);\r
@@ -2755,3 +2740,5 @@ EfiPxeLoadFile (
   return Status;\r
 }\r
 \r
+EFI_LOAD_FILE_PROTOCOL  mLoadFileProtocolTemplate = { EfiPxeLoadFile };\r
+\r