X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FIp4Dxe%2FIp4Icmp.c;h=052d6b77f79a08186f11c65f79df674049259760;hp=14188851b486336ede200f7970ef6883d54ee245;hb=c0fd7f734e2d33e22215899b40a47b843129541d;hpb=687a2e5f6902fa26c7a1d7a7705e0747c4095125 diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Icmp.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Icmp.c index 14188851b4..052d6b77f7 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Icmp.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Icmp.c @@ -1,21 +1,7 @@ /** @file -Copyright (c) 2005 - 2006, 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 - -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: - +Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -43,36 +29,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 +66,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 +74,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 +94,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 +129,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 +152,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 +187,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,6 +234,7 @@ 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 = (UINT16) (~NetblockChecksum ((UINT8 *) Icmp, Data->TotalSize)); @@ -256,7 +242,7 @@ Ip4IcmpReplyEcho ( 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 +261,9 @@ Ip4IcmpReplyEcho ( Ip4SysPacketSent, NULL ); + if (EFI_ERROR (Status)) { + NetbufFree (Data); + } ON_EXIT: NetbufFree (Packet); @@ -286,13 +275,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 +305,7 @@ Ip4ProcessIcmpQuery ( return Ip4IcmpReplyEcho (IpSb, Head, Packet); } - return Ip4Demultiplex (IpSb, Head, Packet); + return Ip4Demultiplex (IpSb, Head, Packet, NULL, 0); } @@ -324,13 +314,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