]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Icmp.c
MdeModulePkg: Update IP4 stack drivers for classless address unicast check.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Icmp.c
index 397296d03b15a7a28dbcbea9bb872a02e4d20c2c..b4b086496cf048873a1ad3b5f6c6f4e9a6c58cad 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 \r
-Copyright (c) 2005 - 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2005 - 2015, 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
 http://opensource.org/licenses/bsd-license.php\r
@@ -9,14 +9,6 @@ http://opensource.org/licenses/bsd-license.php
 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
 \r
-\r
-Module Name:\r
-\r
-  Ip4Icmp.c\r
-\r
-Abstract:\r
-\r
-\r
 **/\r
 \r
 #include "Ip4Impl.h"\r
@@ -70,7 +62,7 @@ mIp4SupportedIcmp[23] = {
   {ICMP_ECHO_REQUEST,      ICMP_DEFAULT_CODE        },\r
 \r
   {ICMP_TIME_EXCEEDED,     ICMP_TIMEOUT_IN_TRANSIT  },\r
-  {ICMP_TIME_EXCEEDED,     ICMp_TIMEOUT_REASSEMBLE  },\r
+  {ICMP_TIME_EXCEEDED,     ICMP_TIMEOUT_REASSEMBLE  },\r
 \r
   {ICMP_PARAMETER_PROBLEM, ICMP_DEFAULT_CODE        },\r
 };\r
@@ -88,12 +80,12 @@ mIp4SupportedIcmp[23] = {
   message SHOULD be treated identically to a Host Redirect\r
   message;"\r
 \r
-  @param  IpSb                   The IP4 service binding instance that received the\r
-                                 packet\r
-  @param  Head                   The IP head of the received ICMPpacket.\r
-  @param  Packet                 The content of the ICMP redirect packet with IP\r
+  @param[in]  IpSb               The IP4 service binding instance that received \r
+                                 the packet.\r
+  @param[in]  Head               The IP head of the received ICMPpacket.\r
+  @param[in]  Packet             The content of the ICMP redirect packet with IP\r
                                  head removed.\r
-  @param  Icmp                   The buffer to store the ICMP error message if\r
+  @param[in]  Icmp               The buffer to store the ICMP error message if\r
                                  something is wrong.\r
 \r
   @retval EFI_INVALID_PARAMETER  The parameter is invalid\r
@@ -113,6 +105,8 @@ Ip4ProcessIcmpRedirect (
   IP4_ROUTE_CACHE_ENTRY     *CacheEntry;\r
   IP4_INTERFACE             *IpIf;\r
   IP4_ADDR                  Gateway;\r
+  IP4_ADDR                  Src;\r
+  IP4_ADDR                  Dst;\r
 \r
   //\r
   // Find the interface whose IP address is the source of the\r
@@ -141,11 +135,9 @@ Ip4ProcessIcmpRedirect (
       continue;\r
     }\r
 \r
-    CacheEntry = Ip4FindRouteCache (\r
-                   Ip4Instance->RouteTable,\r
-                   NTOHL (Icmp->IpHead.Dst),\r
-                   NTOHL (Icmp->IpHead.Src)\r
-                   );\r
+    Dst = NTOHL (Icmp->IpHead.Dst);\r
+    Src = NTOHL (Icmp->IpHead.Src);\r
+    CacheEntry = Ip4FindRouteCache (Ip4Instance->RouteTable, Dst, Src);\r
 \r
     //\r
     // Only update the route cache's gateway if the source of the\r
@@ -166,9 +158,9 @@ Ip4ProcessIcmpRedirect (
   update call Ip4ProcessIcmpRedirect to update the IP instance's\r
   route cache, otherwise, deliver the packet to upper layer.\r
 \r
-  @param  IpSb                   The IP service that received the packet.\r
-  @param  Head                   The IP head of the ICMP error packet\r
-  @param  Packet                 The content of the ICMP error with IP head\r
+  @param[in]  IpSb               The IP4 service that received the packet.\r
+  @param[in]  Head               The IP4 head of the ICMP error packet\r
+  @param[in]  Packet             The content of the ICMP error with IP4 head\r
                                  removed.\r
 \r
   @retval EFI_SUCCESS            The ICMP error is processed successfully.\r
@@ -201,16 +193,16 @@ Ip4ProcessIcmpError (
   }\r
 \r
   IP4_GET_CLIP_INFO (Packet)->Status = EFI_ICMP_ERROR;\r
-  return Ip4Demultiplex (IpSb, Head, Packet);\r
+  return Ip4Demultiplex (IpSb, Head, Packet, NULL, 0);\r
 }\r
 \r
 \r
 /**\r
   Replay an ICMP echo request.\r
 \r
-  @param  IpSb                   The IP service that receivd the packet\r
-  @param  Head                   The IP head of the ICMP error packet\r
-  @param  Packet                 The content of the ICMP error with IP head\r
+  @param[in]  IpSb               The IP4 service that receivd the packet\r
+  @param[in]  Head               The IP4 head of the ICMP error packet\r
+  @param[in]  Packet             The content of the ICMP error with IP4 head\r
                                  removed.\r
 \r
   @retval EFI_OUT_OF_RESOURCES   Failed to allocate resource.\r
@@ -248,6 +240,7 @@ Ip4IcmpReplyEcho (
   // update is omitted.\r
   //\r
   Icmp                = (IP4_ICMP_QUERY_HEAD *) NetbufGetByte (Data, 0, NULL);\r
+  ASSERT (Icmp != NULL);\r
   Icmp->Head.Type     = ICMP_ECHO_REPLY;\r
   Icmp->Head.Checksum = 0;\r
   Icmp->Head.Checksum = (UINT16) (~NetblockChecksum ((UINT8 *) Icmp, Data->TotalSize));\r
@@ -255,7 +248,7 @@ Ip4IcmpReplyEcho (
   ReplyHead.Tos       = 0;\r
   ReplyHead.Fragment  = 0;\r
   ReplyHead.Ttl       = 64;\r
-  ReplyHead.Protocol  = IP4_PROTO_ICMP;\r
+  ReplyHead.Protocol  = EFI_IP_PROTO_ICMP;\r
   ReplyHead.Src       = 0;\r
 \r
   //\r
@@ -285,9 +278,9 @@ ON_EXIT:
   Process the ICMP query message. If it is an ICMP echo\r
   request, answer it. Otherwise deliver it to upper layer.\r
 \r
-  @param  IpSb                   The IP service that receivd the packet\r
-  @param  Head                   The IP head of the ICMP query packet\r
-  @param  Packet                 The content of the ICMP query with IP head\r
+  @param[in]  IpSb               The IP4 service that receivd the packet\r
+  @param[in]  Head               The IP4 head of the ICMP query packet\r
+  @param[in]  Packet             The content of the ICMP query with IP4 head\r
                                  removed.\r
 \r
   @retval EFI_INVALID_PARAMETER  The packet is invalid\r
@@ -315,7 +308,7 @@ Ip4ProcessIcmpQuery (
     return Ip4IcmpReplyEcho (IpSb, Head, Packet);\r
   }\r
 \r
-  return Ip4Demultiplex (IpSb, Head, Packet);\r
+  return Ip4Demultiplex (IpSb, Head, Packet, NULL, 0);\r
 }\r
 \r
 \r
@@ -324,9 +317,9 @@ Ip4ProcessIcmpQuery (
   then according to the message types, process it as query or\r
   error packet.\r
 \r
-  @param  IpSb                   The IP service that receivd the packet\r
-  @param  Head                   The IP head of the ICMP query packet\r
-  @param  Packet                 The content of the ICMP query with IP head\r
+  @param[in]  IpSb               The IP4 service that receivd the packet.\r
+  @param[in]  Head               The IP4 head of the ICMP query packet.\r
+  @param[in]  Packet             The content of the ICMP query with IP4 head\r
                                  removed.\r
 \r
   @retval EFI_INVALID_PARAMETER  The packet is malformated.\r