]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c
MdeModulePkg/Dhcp4Dxe: Remove unnecessary NULL pointer check.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / Dhcp4Io.c
index 4bc991557a1750089abb9463de6e4a0bdcb6bea1..360365ecc3ad51a5b7339611e5f1b8f8b3327b3d 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   EFI DHCP protocol implementation.\r
-  \r
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+\r
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
 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
@@ -41,7 +41,7 @@ DhcpInitRequest (
   // Clear initial time to make sure that elapsed-time is set to 0 for first Discover or REQUEST message.\r
   //\r
   DhcpSb->ActiveChild->ElaspedTime= 0;\r
-  \r
+\r
   if (DhcpSb->DhcpState == Dhcp4Init) {\r
     DhcpSetState (DhcpSb, Dhcp4Selecting, FALSE);\r
     Status = DhcpSendMessage (DhcpSb, NULL, NULL, DHCP_MSG_DISCOVER, NULL);\r
@@ -393,8 +393,6 @@ DhcpLeaseAcquired (
   IN OUT DHCP_SERVICE           *DhcpSb\r
   )\r
 {\r
-  INTN                      Class;\r
-\r
   DhcpSb->ClientAddr = EFI_NTOHL (DhcpSb->Selected->Dhcp4.Header.YourAddr);\r
 \r
   if (DhcpSb->Para != NULL) {\r
@@ -403,9 +401,7 @@ DhcpLeaseAcquired (
   }\r
 \r
   if (DhcpSb->Netmask == 0) {\r
-    Class           = NetGetIpClass (DhcpSb->ClientAddr);\r
-    ASSERT (Class < IP4_ADDR_CLASSE);\r
-    DhcpSb->Netmask = gIp4AllMasks[Class << 3];\r
+    return EFI_ABORTED;\r
   }\r
 \r
   if (DhcpSb->LeaseIoPort != NULL) {\r
@@ -1100,23 +1096,6 @@ RESTART:
   }\r
 }\r
 \r
-\r
-/**\r
-  Release the packet.\r
-\r
-  @param[in]  Arg                   The packet to release\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-DhcpReleasePacket (\r
-  IN VOID                   *Arg\r
-  )\r
-{\r
-  FreePool (Arg);\r
-}\r
-\r
-\r
 /**\r
   Release the net buffer when packet is sent.\r
 \r
@@ -1240,7 +1219,7 @@ DhcpSendMessage (
   //\r
   Packet->Dhcp4.Magik = DHCP_OPTION_MAGIC;\r
   Buf                 = Packet->Dhcp4.Option;\r
-  Buf                 = DhcpAppendOption (Buf, DHCP_TAG_TYPE, 1, &Type);\r
+  Buf                 = DhcpAppendOption (Buf, DHCP4_TAG_MSG_TYPE, 1, &Type);\r
 \r
   //\r
   // Append the serverid option if necessary:\r
@@ -1255,7 +1234,7 @@ DhcpSendMessage (
     ASSERT ((Para != NULL) && (Para->ServerId != 0));\r
 \r
     IpAddr  = HTONL (Para->ServerId);\r
-    Buf     = DhcpAppendOption (Buf, DHCP_TAG_SERVER_ID, 4, (UINT8 *) &IpAddr);\r
+    Buf     = DhcpAppendOption (Buf, DHCP4_TAG_SERVER_ID, 4, (UINT8 *) &IpAddr);\r
   }\r
 \r
   //\r
@@ -1281,7 +1260,7 @@ DhcpSendMessage (
   }\r
 \r
   if (IpAddr != 0) {\r
-    Buf = DhcpAppendOption (Buf, DHCP_TAG_REQUEST_IP, 4, (UINT8 *) &IpAddr);\r
+    Buf = DhcpAppendOption (Buf, DHCP4_TAG_REQUEST_IP, 4, (UINT8 *) &IpAddr);\r
   }\r
 \r
   //\r
@@ -1291,7 +1270,7 @@ DhcpSendMessage (
   //\r
   if ((Type != DHCP_MSG_DECLINE) && (Type != DHCP_MSG_RELEASE)) {\r
     MaxMsg  = HTONS (0xFF00);\r
-    Buf     = DhcpAppendOption (Buf, DHCP_TAG_MAXMSG, 2, (UINT8 *) &MaxMsg);\r
+    Buf     = DhcpAppendOption (Buf, DHCP4_TAG_MAXMSG, 2, (UINT8 *) &MaxMsg);\r
   }\r
 \r
   //\r
@@ -1299,7 +1278,7 @@ DhcpSendMessage (
   //\r
   if (Msg != NULL) {\r
     Len     = MIN ((UINT32) AsciiStrLen ((CHAR8 *) Msg), 255);\r
-    Buf     = DhcpAppendOption (Buf, DHCP_TAG_MESSAGE, (UINT16) Len, Msg);\r
+    Buf     = DhcpAppendOption (Buf, DHCP4_TAG_MESSAGE, (UINT16) Len, Msg);\r
   }\r
 \r
   //\r
@@ -1312,7 +1291,7 @@ DhcpSendMessage (
       // if it is a DHCP decline or DHCP release .\r
       //\r
       if (((Type == DHCP_MSG_DECLINE) || (Type == DHCP_MSG_RELEASE)) &&\r
-          (Config->OptionList[Index]->OpCode != DHCP_TAG_CLIENT_ID)) {\r
+          (Config->OptionList[Index]->OpCode != DHCP4_TAG_CLIENT_ID)) {\r
         continue;\r
       }\r
 \r
@@ -1325,7 +1304,7 @@ DhcpSendMessage (
     }\r
   }\r
 \r
-  *(Buf++) = DHCP_TAG_EOP;\r
+  *(Buf++) = DHCP4_TAG_EOP;\r
   Packet->Length += (UINT32) (Buf - Packet->Dhcp4.Option);\r
 \r
   //\r
@@ -1363,13 +1342,12 @@ DhcpSendMessage (
     Packet->Dhcp4.Header.HwAddrLen\r
     );\r
 \r
-\r
   //\r
   // Wrap it into a netbuf then send it.\r
   //\r
   Frag.Bulk = (UINT8 *) &Packet->Dhcp4.Header;\r
   Frag.Len  = Packet->Length;\r
-  Wrap      = NetbufFromExt (&Frag, 1, 0, 0, DhcpReleasePacket, Packet);\r
+  Wrap      = NetbufFromExt (&Frag, 1, 0, 0, DhcpDummyExtFree, NULL);\r
 \r
   if (Wrap == NULL) {\r
     FreePool (Packet);\r
@@ -1403,19 +1381,18 @@ DhcpSendMessage (
   }\r
 \r
   ASSERT (UdpIo != NULL);\r
-  NET_GET_REF (Wrap);\r
-  \r
+\r
   Status = UdpIoSendDatagram (\r
-             UdpIo, \r
-             Wrap, \r
-             &EndPoint, \r
-             NULL, \r
-             DhcpOnPacketSent, \r
+             UdpIo,\r
+             Wrap,\r
+             &EndPoint,\r
+             NULL,\r
+             DhcpOnPacketSent,\r
              DhcpSb\r
              );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    NET_PUT_REF (Wrap);\r
+    NetbufFree (Wrap);\r
     return EFI_ACCESS_DENIED;\r
   }\r
 \r
@@ -1458,12 +1435,12 @@ DhcpRetransmit (
   //\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
+  Wrap      = NetbufFromExt (&Frag, 1, 0, 0, DhcpDummyExtFree, NULL);\r
 \r
   if (Wrap == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  \r
+\r
   //\r
   // Broadcast the message, unless we know the server address.\r
   //\r
@@ -1481,7 +1458,6 @@ DhcpRetransmit (
 \r
   ASSERT (UdpIo != NULL);\r
 \r
-  NET_GET_REF (Wrap);\r
   Status = UdpIoSendDatagram (\r
              UdpIo,\r
              Wrap,\r
@@ -1492,7 +1468,7 @@ DhcpRetransmit (
              );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    NET_PUT_REF (Wrap);\r
+    NetbufFree (Wrap);\r
     return EFI_ACCESS_DENIED;\r
   }\r
 \r
@@ -1533,7 +1509,7 @@ DhcpOnTimerTick (
   if (Instance != NULL && Instance->ElaspedTime < 0xffff) {\r
     Instance->ElaspedTime++;\r
   }\r
-  \r
+\r
   //\r
   // Check the retransmit timer\r
   //\r
@@ -1555,7 +1531,7 @@ DhcpOnTimerTick (
         goto ON_EXIT;\r
       }\r
     }\r
-    \r
+\r
     if (++DhcpSb->CurRetry < DhcpSb->MaxRetries) {\r
       //\r
       // Still has another try\r
@@ -1594,7 +1570,7 @@ DhcpOnTimerTick (
       goto END_SESSION;\r
     }\r
   }\r
-  \r
+\r
   //\r
   // If an address has been acquired, check whether need to\r
   // refresh or whether it has expired.\r
@@ -1626,8 +1602,8 @@ DhcpOnTimerTick (
 \r
       if (Instance != NULL) {\r
         Instance->ElaspedTime= 0;\r
-      }      \r
-      \r
+      }\r
+\r
       Status = DhcpSendMessage (\r
                  DhcpSb,\r
                  DhcpSb->Selected,\r
@@ -1650,7 +1626,7 @@ DhcpOnTimerTick (
 \r
       if (Instance != NULL) {\r
         Instance->ElaspedTime= 0;\r
-      }    \r
+      }\r
 \r
       Status = DhcpSendMessage (\r
                  DhcpSb,\r
@@ -1672,12 +1648,9 @@ ON_EXIT:
   //\r
   NET_LIST_FOR_EACH_SAFE (Entry, Next, &DhcpSb->Children) {\r
     Instance = NET_LIST_USER_STRUCT (Entry, DHCP_PROTOCOL, Link);\r
-    \r
-    if ((Instance != NULL) && (Instance->Token != NULL)) {\r
-      Instance->Timeout--;\r
-      if (Instance->Timeout == 0) {\r
-        PxeDhcpDone (Instance);\r
-      }\r
+    Instance->Timeout--;\r
+    if (Instance->Timeout == 0 && Instance->Token != NULL) {\r
+      PxeDhcpDone (Instance);\r
     }\r
   }\r
 \r