X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FIp4Dxe%2FIp4Icmp.c;h=511342e786d73d9cfbcecfa10ef0a58aa3830f99;hb=3028d73e5a4073841fdfc94b1e984c92e8e8fa7a;hp=7f29c90869c90b915ba042915930f0fc621f1ce9;hpb=772db4bb33ae66fa20e39f786b5f80d107d450a5;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Icmp.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Icmp.c index 7f29c90869..511342e786 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Icmp.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Icmp.c @@ -1,7 +1,7 @@ /** @file -Copyright (c) 2005 - 2006, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
+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 http://opensource.org/licenses/bsd-license.php @@ -9,14 +9,6 @@ http://opensource.org/licenses/bsd-license.php THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -Module Name: - - Ip4Icmp.c - -Abstract: - - **/ #include "Ip4Impl.h" @@ -43,36 +35,36 @@ mIcmpClass[] = { }; EFI_IP4_ICMP_TYPE -mIp4SupportedIcmp [23] = { - {ICMP_ECHO_REPLY, ICMP_DEFAULT_CODE }, - - {ICMP_DEST_UNREACHABLE, ICMP_NET_UNREACHABLE }, - {ICMP_DEST_UNREACHABLE, ICMP_HOST_UNREACHABLE }, - {ICMP_DEST_UNREACHABLE, ICMP_PROTO_UNREACHABLE }, - {ICMP_DEST_UNREACHABLE, ICMP_PORT_UNREACHABLE }, - {ICMP_DEST_UNREACHABLE, ICMP_FRAGMENT_FAILED }, - {ICMP_DEST_UNREACHABLE, ICMP_SOURCEROUTE_FAILED}, - {ICMP_DEST_UNREACHABLE, ICMP_NET_UNKNOWN }, - {ICMP_DEST_UNREACHABLE, ICMP_HOST_UNKNOWN }, - {ICMP_DEST_UNREACHABLE, ICMP_SOURCE_ISOLATED }, - {ICMP_DEST_UNREACHABLE, ICMP_NET_PROHIBITED }, - {ICMP_DEST_UNREACHABLE, ICMP_HOST_PROHIBITED }, +mIp4SupportedIcmp[23] = { + {ICMP_ECHO_REPLY, ICMP_DEFAULT_CODE }, + + {ICMP_DEST_UNREACHABLE, ICMP_NET_UNREACHABLE }, + {ICMP_DEST_UNREACHABLE, ICMP_HOST_UNREACHABLE }, + {ICMP_DEST_UNREACHABLE, ICMP_PROTO_UNREACHABLE }, + {ICMP_DEST_UNREACHABLE, ICMP_PORT_UNREACHABLE }, + {ICMP_DEST_UNREACHABLE, ICMP_FRAGMENT_FAILED }, + {ICMP_DEST_UNREACHABLE, ICMP_SOURCEROUTE_FAILED }, + {ICMP_DEST_UNREACHABLE, ICMP_NET_UNKNOWN }, + {ICMP_DEST_UNREACHABLE, ICMP_HOST_UNKNOWN }, + {ICMP_DEST_UNREACHABLE, ICMP_SOURCE_ISOLATED }, + {ICMP_DEST_UNREACHABLE, ICMP_NET_PROHIBITED }, + {ICMP_DEST_UNREACHABLE, ICMP_HOST_PROHIBITED }, {ICMP_DEST_UNREACHABLE, ICMP_NET_UNREACHABLE_TOS }, {ICMP_DEST_UNREACHABLE, ICMP_HOST_UNREACHABLE_TOS}, - {ICMP_SOURCE_QUENCH, ICMP_DEFAULT_CODE }, + {ICMP_SOURCE_QUENCH, ICMP_DEFAULT_CODE }, - {ICMP_REDIRECT, ICMP_NET_REDIRECT }, - {ICMP_REDIRECT, ICMP_HOST_REDIRECT }, - {ICMP_REDIRECT, ICMP_NET_TOS_REDIRECT }, - {ICMP_REDIRECT, ICMP_HOST_TOS_REDIRECT }, + {ICMP_REDIRECT, ICMP_NET_REDIRECT }, + {ICMP_REDIRECT, ICMP_HOST_REDIRECT }, + {ICMP_REDIRECT, ICMP_NET_TOS_REDIRECT }, + {ICMP_REDIRECT, ICMP_HOST_TOS_REDIRECT }, - {ICMP_ECHO_REQUEST, ICMP_DEFAULT_CODE }, + {ICMP_ECHO_REQUEST, ICMP_DEFAULT_CODE }, - {ICMP_TIME_EXCEEDED, ICMP_TIMEOUT_IN_TRANSIT}, - {ICMP_TIME_EXCEEDED, ICMp_TIMEOUT_REASSEMBLE}, + {ICMP_TIME_EXCEEDED, ICMP_TIMEOUT_IN_TRANSIT }, + {ICMP_TIME_EXCEEDED, ICMP_TIMEOUT_REASSEMBLE }, - {ICMP_PARAMETER_PROBLEM, ICMP_DEFAULT_CODE }, + {ICMP_PARAMETER_PROBLEM, ICMP_DEFAULT_CODE }, }; @@ -80,6 +72,7 @@ mIp4SupportedIcmp [23] = { /** Process the ICMP redirect. Find the instance then update its route cache. + All kinds of redirect is treated as host redirect as specified by RFC1122 3.3.1.2: "Since the subnet mask appropriate to the destination @@ -87,19 +80,18 @@ mIp4SupportedIcmp [23] = { message SHOULD be treated identically to a Host Redirect message;" - @param IpSb The IP4 service binding instance that received the - packet - @param Head The IP head of the received ICMPpacket. - @param Packet The content of the ICMP redirect packet with IP + @param[in] IpSb The IP4 service binding instance that received + the packet. + @param[in] Head The IP head of the received ICMPpacket. + @param[in] Packet The content of the ICMP redirect packet with IP head removed. - @param Icmp The buffer to store the ICMP error message if + @param[in] Icmp The buffer to store the ICMP error message if something is wrong. @retval EFI_INVALID_PARAMETER The parameter is invalid @retval EFI_SUCCESS Successfully updated the route caches **/ -STATIC EFI_STATUS Ip4ProcessIcmpRedirect ( IN IP4_SERVICE *IpSb, @@ -108,11 +100,13 @@ Ip4ProcessIcmpRedirect ( IN IP4_ICMP_ERROR_HEAD *Icmp ) { - NET_LIST_ENTRY *Entry; + LIST_ENTRY *Entry; IP4_PROTOCOL *Ip4Instance; IP4_ROUTE_CACHE_ENTRY *CacheEntry; IP4_INTERFACE *IpIf; IP4_ADDR Gateway; + IP4_ADDR Src; + IP4_ADDR Dst; // // Find the interface whose IP address is the source of the @@ -141,11 +135,9 @@ Ip4ProcessIcmpRedirect ( continue; } - CacheEntry = Ip4FindRouteCache ( - Ip4Instance->RouteTable, - NTOHL (Icmp->IpHead.Dst), - NTOHL (Icmp->IpHead.Src) - ); + Dst = NTOHL (Icmp->IpHead.Dst); + Src = NTOHL (Icmp->IpHead.Src); + CacheEntry = Ip4FindRouteCache (Ip4Instance->RouteTable, Dst, Src); // // Only update the route cache's gateway if the source of the @@ -166,17 +158,16 @@ Ip4ProcessIcmpRedirect ( update call Ip4ProcessIcmpRedirect to update the IP instance's route cache, otherwise, deliver the packet to upper layer. - @param IpSb The IP service that received the packet. - @param Head The IP head of the ICMP error packet - @param Packet The content of the ICMP error with IP head + @param[in] IpSb The IP4 service that received the packet. + @param[in] Head The IP4 head of the ICMP error packet + @param[in] Packet The content of the ICMP error with IP4 head removed. + @retval EFI_SUCCESS The ICMP error is processed successfully. @retval EFI_INVALID_PARAMETER The packet is invalid @retval Others Failed to process the packet. - @retval EFI_SUCCESS The ICMP error is processed successfully. **/ -STATIC EFI_STATUS Ip4ProcessIcmpError ( IN IP4_SERVICE *IpSb, @@ -202,16 +193,16 @@ Ip4ProcessIcmpError ( } IP4_GET_CLIP_INFO (Packet)->Status = EFI_ICMP_ERROR; - return Ip4Demultiplex (IpSb, Head, Packet); + return Ip4Demultiplex (IpSb, Head, Packet, NULL, 0); } /** Replay an ICMP echo request. - @param IpSb The IP service that receivd the packet - @param Head The IP head of the ICMP error packet - @param Packet The content of the ICMP error with IP head + @param[in] IpSb The IP4 service that receivd the packet + @param[in] Head The IP4 head of the ICMP error packet + @param[in] Packet The content of the ICMP error with IP4 head removed. @retval EFI_OUT_OF_RESOURCES Failed to allocate resource. @@ -249,14 +240,15 @@ Ip4IcmpReplyEcho ( // update is omitted. // Icmp = (IP4_ICMP_QUERY_HEAD *) NetbufGetByte (Data, 0, NULL); + ASSERT (Icmp != NULL); Icmp->Head.Type = ICMP_ECHO_REPLY; Icmp->Head.Checksum = 0; - Icmp->Head.Checksum = ~NetblockChecksum ((UINT8 *) Icmp, Data->TotalSize); + Icmp->Head.Checksum = (UINT16) (~NetblockChecksum ((UINT8 *) Icmp, Data->TotalSize)); ReplyHead.Tos = 0; ReplyHead.Fragment = 0; ReplyHead.Ttl = 64; - ReplyHead.Protocol = IP4_PROTO_ICMP; + ReplyHead.Protocol = EFI_IP_PROTO_ICMP; ReplyHead.Src = 0; // @@ -275,6 +267,9 @@ Ip4IcmpReplyEcho ( Ip4SysPacketSent, NULL ); + if (EFI_ERROR (Status)) { + NetbufFree (Data); + } ON_EXIT: NetbufFree (Packet); @@ -286,13 +281,14 @@ ON_EXIT: Process the ICMP query message. If it is an ICMP echo request, answer it. Otherwise deliver it to upper layer. - @param IpSb The IP service that receivd the packet - @param Head The IP head of the ICMP query packet - @param Packet The content of the ICMP query with IP head + @param[in] IpSb The IP4 service that receivd the packet + @param[in] Head The IP4 head of the ICMP query packet + @param[in] Packet The content of the ICMP query with IP4 head removed. @retval EFI_INVALID_PARAMETER The packet is invalid @retval EFI_SUCCESS The ICMP query message is processed + @retval Others Failed to process ICMP query. **/ EFI_STATUS @@ -315,7 +311,7 @@ Ip4ProcessIcmpQuery ( return Ip4IcmpReplyEcho (IpSb, Head, Packet); } - return Ip4Demultiplex (IpSb, Head, Packet); + return Ip4Demultiplex (IpSb, Head, Packet, NULL, 0); } @@ -324,13 +320,14 @@ Ip4ProcessIcmpQuery ( then according to the message types, process it as query or error packet. - @param IpSb The IP service that receivd the packet - @param Head The IP head of the ICMP query packet - @param Packet The content of the ICMP query with IP head + @param[in] IpSb The IP4 service that receivd the packet. + @param[in] Head The IP4 head of the ICMP query packet. + @param[in] Packet The content of the ICMP query with IP4 head removed. @retval EFI_INVALID_PARAMETER The packet is malformated. @retval EFI_SUCCESS The ICMP message is successfully processed. + @retval Others Failed to handle ICMP packet. **/ EFI_STATUS @@ -353,7 +350,7 @@ Ip4IcmpHandle ( goto DROP; } - Checksum = ~NetbufChecksum (Packet); + Checksum = (UINT16) (~NetbufChecksum (Packet)); if ((Icmp.Checksum != 0) && (Checksum != 0)) { goto DROP; }