]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
BaseTools:Change the path of the file that Binary Cache
[mirror_edk2.git] / MdeModulePkg / Library / DxeNetLib / DxeNetLib.c
index 90f17b71b513ea907160c15a5baf0c3753c085b0..8e2f720666eaa3213e179e8e6200e8e3bde4de5e 100644 (file)
@@ -3,13 +3,7 @@
 \r
 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2015 Hewlett Packard Enterprise Development LP<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
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 **/\r
 \r
 #include <Uefi.h>\r
@@ -403,7 +397,6 @@ SyslogBuildPacket (
                     Time.Minute,\r
                     Time.Second\r
                     );\r
-  Len--;\r
 \r
   Len += (UINT32) AsciiSPrint (\r
                     Buf + Len,\r
@@ -414,7 +407,7 @@ SyslogBuildPacket (
                     Line,\r
                     File\r
                     );\r
-  Len--;\r
+  Len ++;\r
 \r
   //\r
   // OK, patch the IP length/checksum and UDP length fields.\r
@@ -649,13 +642,14 @@ NetGetIpClass (
 \r
 /**\r
   Check whether the IP is a valid unicast address according to\r
-  the netmask. \r
+  the netmask.\r
 \r
   ASSERT if NetMask is zero.\r
-  \r
+\r
   If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast address,\r
   except when the originator is one of the endpoints of a point-to-point link with a 31-bit\r
-  mask (RFC3021).\r
+  mask (RFC3021), or a 32bit NetMask (all 0xFF) is used for special network environment (e.g.\r
+  PPP link).\r
 \r
   @param[in]  Ip                    The IP to check against.\r
   @param[in]  NetMask               The mask of the IP.\r
@@ -670,18 +664,20 @@ NetIp4IsUnicast (
   IN IP4_ADDR               NetMask\r
   )\r
 {\r
+  INTN   MaskLength;\r
+\r
   ASSERT (NetMask != 0);\r
-  \r
+\r
   if (Ip == 0 || IP4_IS_LOCAL_BROADCAST (Ip)) {\r
     return FALSE;\r
   }\r
 \r
-  if (NetGetMaskLength (NetMask) != 31) {\r
+  MaskLength = NetGetMaskLength (NetMask);\r
+  ASSERT ((MaskLength >= 0) && (MaskLength <= IP4_MASK_NUM));\r
+  if (MaskLength < 31) {\r
     if (((Ip &~NetMask) == ~NetMask) || ((Ip &~NetMask) == 0)) {\r
       return FALSE;\r
     }\r
-  } else {\r
-    return TRUE;\r
   }\r
 \r
   return TRUE;\r
@@ -805,7 +801,7 @@ NetIp6IsLinkLocalAddr (
   Check whether the Ipv6 address1 and address2 are on the connected network.\r
 \r
   ASSERT if Ip1 or Ip2 is NULL.\r
-  ASSERT if PrefixLength exceeds IP6_PREFIX_MAX.\r
+  ASSERT if PrefixLength exceeds or equals to IP6_PREFIX_MAX.\r
 \r
   @param[in] Ip1          - Ip6 address1, in network order.\r
   @param[in] Ip2          - Ip6 address2, in network order.\r
@@ -827,7 +823,7 @@ NetIp6IsNetEqual (
   UINT8 Bit;\r
   UINT8 Mask;\r
 \r
-  ASSERT ((Ip1 != NULL) && (Ip2 != NULL) && (PrefixLength <= IP6_PREFIX_MAX));\r
+  ASSERT ((Ip1 != NULL) && (Ip2 != NULL) && (PrefixLength < IP6_PREFIX_MAX));\r
 \r
   if (PrefixLength == 0) {\r
     return TRUE;\r
@@ -843,6 +839,10 @@ NetIp6IsNetEqual (
   if (Bit > 0) {\r
     Mask = (UINT8) (0xFF << (8 - Bit));\r
 \r
+    ASSERT (Byte < 16);\r
+    if (Byte >= 16) {\r
+      return FALSE;\r
+    }\r
     if ((Ip1->Addr[Byte] & Mask) != (Ip2->Addr[Byte] & Mask)) {\r
       return FALSE;\r
     }\r
@@ -892,7 +892,7 @@ Ip6Swap128 (
 /**\r
   Initialize a random seed using current time and monotonic count.\r
 \r
-  Get current time and monotonic count first. Then initialize a random seed \r
+  Get current time and monotonic count first. Then initialize a random seed\r
   based on some basic mathematics operation on the hour, day, minute, second,\r
   nanosecond and year of the current time and the monotonic count value.\r
 \r
@@ -1129,7 +1129,7 @@ NetListInsertBefore (
   If it has been removed, then restart the traversal from the head.\r
   If it hasn't been removed, then continue with the next node directly.\r
   This function will end the iterate and return the CallBack's last return value if error happens,\r
-  or retrun EFI_SUCCESS if 2 complete passes are made with no changes in the number of children in the list.  \r
+  or retrun EFI_SUCCESS if 2 complete passes are made with no changes in the number of children in the list.\r
 \r
   @param[in]    List             The head of the list.\r
   @param[in]    CallBack         Pointer to the callback function to destroy one node in the list.\r
@@ -1216,7 +1216,7 @@ NetIsInHandleBuffer (
   )\r
 {\r
   UINTN     Index;\r
-  \r
+\r
   if (NumberOfChildren == 0 || ChildHandleBuffer == NULL) {\r
     return FALSE;\r
   }\r
@@ -1807,7 +1807,7 @@ NetLibDefaultUnload (
     if (DriverBinding->ImageHandle != ImageHandle) {\r
       continue;\r
     }\r
-    \r
+\r
     //\r
     // Disconnect the driver specified by ImageHandle from all\r
     // the devices in the handle database.\r
@@ -1819,16 +1819,16 @@ NetLibDefaultUnload (
                       NULL\r
                       );\r
     }\r
-    \r
+\r
     //\r
     // Uninstall all the protocols installed in the driver entry point\r
-    //    \r
+    //\r
     gBS->UninstallProtocolInterface (\r
           DriverBinding->DriverBindingHandle,\r
           &gEfiDriverBindingProtocolGuid,\r
           DriverBinding\r
           );\r
-    \r
+\r
     Status = gBS->HandleProtocol (\r
                     DeviceHandleBuffer[Index],\r
                     &gEfiComponentNameProtocolGuid,\r
@@ -2573,13 +2573,13 @@ Exit:
 \r
 /**\r
 \r
-  Detect media state for a network device. This routine will wait for a period of time at \r
-  a specified checking interval when a certain network is under connecting until connection \r
+  Detect media state for a network device. This routine will wait for a period of time at\r
+  a specified checking interval when a certain network is under connecting until connection\r
   process finishs or timeout. If Aip protocol is supported by low layer drivers, three kinds\r
   of media states can be detected: EFI_SUCCESS, EFI_NOT_READY and EFI_NO_MEDIA, represents\r
-  connected state, connecting state and no media state respectively. When function detects \r
-  the current state is EFI_NOT_READY, it will loop to wait for next time's check until state \r
-  turns to be EFI_SUCCESS or EFI_NO_MEDIA. If Aip protocol is not supported, function will \r
+  connected state, connecting state and no media state respectively. When function detects\r
+  the current state is EFI_NOT_READY, it will loop to wait for next time's check until state\r
+  turns to be EFI_SUCCESS or EFI_NO_MEDIA. If Aip protocol is not supported, function will\r
   call NetLibDetectMedia() and return state directly.\r
 \r
   @param[in]   ServiceHandle    The handle where network service binding protocols are\r
@@ -2590,7 +2590,7 @@ Exit:
   @param[out]  MediaState       The pointer to the detected media state.\r
 \r
   @retval EFI_SUCCESS           Media detection success.\r
-  @retval EFI_INVALID_PARAMETER ServiceHandle is not a valid network device handle or \r
+  @retval EFI_INVALID_PARAMETER ServiceHandle is not a valid network device handle or\r
                                 MediaState pointer is NULL.\r
   @retval EFI_DEVICE_ERROR      A device error occurred.\r
   @retval EFI_TIMEOUT           Network is connecting but timeout.\r
@@ -2694,7 +2694,7 @@ NetLibDetectMediaWaitTimeout (
   }\r
 \r
   //\r
-  // Loop to check media state \r
+  // Loop to check media state\r
   //\r
 \r
   Timer        = NULL;\r
@@ -2755,10 +2755,10 @@ NetLibDetectMediaWaitTimeout (
   from DHCP).\r
 \r
   If the controller handle does not have the EFI_IP4_CONFIG2_PROTOCOL installed, the\r
-  default address is static. If failed to get the policy from Ip4 Config2 Protocol, \r
+  default address is static. If failed to get the policy from Ip4 Config2 Protocol,\r
   the default address is static. Otherwise, get the result from Ip4 Config2 Protocol.\r
 \r
-  @param[in]   Controller     The controller handle which has the EFI_IP4_CONFIG2_PROTOCOL \r
+  @param[in]   Controller     The controller handle which has the EFI_IP4_CONFIG2_PROTOCOL\r
                               relative with the default address to judge.\r
 \r
   @retval TRUE           If the default address is static.\r
@@ -2772,12 +2772,12 @@ NetLibDefaultAddressIsStatic (
 {\r
   EFI_STATUS                       Status;\r
   EFI_IP4_CONFIG2_PROTOCOL         *Ip4Config2;\r
-  UINTN                            DataSize;  \r
+  UINTN                            DataSize;\r
   EFI_IP4_CONFIG2_POLICY           Policy;\r
   BOOLEAN                          IsStatic;\r
 \r
   Ip4Config2 = NULL;\r
-  \r
+\r
   DataSize = sizeof (EFI_IP4_CONFIG2_POLICY);\r
 \r
   IsStatic   = TRUE;\r
@@ -2794,11 +2794,11 @@ NetLibDefaultAddressIsStatic (
   if (EFI_ERROR (Status)) {\r
     goto ON_EXIT;\r
   }\r
-  \r
+\r
   IsStatic = (BOOLEAN) (Policy == Ip4Config2PolicyStatic);\r
 \r
 ON_EXIT:\r
-  \r
+\r
   return IsStatic;\r
 }\r
 \r
@@ -3129,14 +3129,14 @@ NetLibStrToIp6andPrefix (
 \r
   Convert one EFI_IPv6_ADDRESS to Null-terminated Unicode string.\r
   The text representation of address is defined in RFC 4291.\r
-  \r
+\r
   @param[in]       Ip6Address     The pointer to the IPv6 address.\r
   @param[out]      String         The buffer to return the converted string.\r
   @param[in]       StringSize     The length in bytes of the input String.\r
-                                  \r
+\r
   @retval EFI_SUCCESS             Convert to string successfully.\r
   @retval EFI_INVALID_PARAMETER   The input parameter is invalid.\r
-  @retval EFI_BUFFER_TOO_SMALL    The BufferSize is too small for the result. BufferSize has been \r
+  @retval EFI_BUFFER_TOO_SMALL    The BufferSize is too small for the result. BufferSize has been\r
                                   updated with the size needed to complete the request.\r
 **/\r
 EFI_STATUS\r
@@ -3162,7 +3162,7 @@ NetLibIp6ToStr (
 \r
   //\r
   // Convert the UINT8 array to an UINT16 array for easy handling.\r
-  // \r
+  //\r
   ZeroMem (Ip6Addr, sizeof (Ip6Addr));\r
   for (Index = 0; Index < 16; Index++) {\r
     Ip6Addr[Index / 2] |= (Ip6Address->Addr[Index] << ((1 - (Index % 2)) << 3));\r
@@ -3194,7 +3194,7 @@ NetLibIp6ToStr (
       }\r
     }\r
   }\r
-  \r
+\r
   if (CurrentZerosStart != DEFAULT_ZERO_START && CurrentZerosLength > 2) {\r
     if (LongestZerosStart == DEFAULT_ZERO_START || LongestZerosLength < CurrentZerosLength) {\r
       LongestZerosStart  = CurrentZerosStart;\r
@@ -3215,7 +3215,7 @@ NetLibIp6ToStr (
     }\r
     Ptr += UnicodeSPrint(Ptr, 10, L"%x", Ip6Addr[Index]);\r
   }\r
-  \r
+\r
   if (LongestZerosStart != DEFAULT_ZERO_START && LongestZerosStart + LongestZerosLength == 8) {\r
     *Ptr++ = L':';\r
   }\r
@@ -3278,7 +3278,7 @@ NetLibGetSystemGuid (
         //\r
         return EFI_NOT_FOUND;\r
       }\r
-      \r
+\r
       //\r
       // SMBIOS tables are byte packed so we need to do a byte copy to\r
       // prevend alignment faults on Itanium-based platform.\r
@@ -3292,12 +3292,12 @@ NetLibGetSystemGuid (
     // 1. Formatted section; 2. Unformatted string section. So, 2 steps are needed\r
     // to skip one SMBIOS structure.\r
     //\r
-    \r
+\r
     //\r
     // Step 1: Skip over formatted section.\r
     //\r
     String = (CHAR8 *) (Smbios.Raw + Smbios.Hdr->Length);\r
-  \r
+\r
     //\r
     // Step 2: Skip over unformated string section.\r
     //\r
@@ -3315,7 +3315,7 @@ NetLibGetSystemGuid (
         //\r
         Smbios.Raw = (UINT8 *)++String;\r
         break;\r
-      }    \r
+      }\r
     } while (TRUE);\r
   } while (Smbios.Raw < SmbiosEnd.Raw);\r
   return EFI_NOT_FOUND;\r
@@ -3325,19 +3325,19 @@ NetLibGetSystemGuid (
   Create Dns QName according the queried domain name.\r
 \r
   If DomainName is NULL, then ASSERT().\r
-  \r
-  QName is a domain name represented as a sequence of labels, \r
-  where each label consists of a length octet followed by that \r
-  number of octets. The QName terminates with the zero \r
-  length octet for the null label of the root. Caller should \r
+\r
+  QName is a domain name represented as a sequence of labels,\r
+  where each label consists of a length octet followed by that\r
+  number of octets. The QName terminates with the zero\r
+  length octet for the null label of the root. Caller should\r
   take responsibility to free the buffer in returned pointer.\r
 \r
-  @param  DomainName    The pointer to the queried domain name string.  \r
+  @param  DomainName    The pointer to the queried domain name string.\r
 \r
   @retval NULL          Failed to fill QName.\r
   @return               QName filled successfully.\r
-  \r
-**/ \r
+\r
+**/\r
 CHAR8 *\r
 EFIAPI\r
 NetLibCreateDnsQName (\r
@@ -3359,10 +3359,10 @@ NetLibCreateDnsQName (
   Tail          = NULL;\r
 \r
   //\r
-  // One byte for first label length, one byte for terminated length zero. \r
+  // One byte for first label length, one byte for terminated length zero.\r
   //\r
   QueryNameSize = StrLen (DomainName) + 2;\r
-  \r
+\r
   if (QueryNameSize > DNS_MAX_NAME_SIZE) {\r
     return NULL;\r
   }\r
@@ -3371,7 +3371,7 @@ NetLibCreateDnsQName (
   if (QueryName == NULL) {\r
     return NULL;\r
   }\r
-  \r
+\r
   Header = QueryName;\r
   Tail = Header + 1;\r
   Len = 0;\r