]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/Ip6Dxe/Ip6Icmp.c
NetworkPkg/Ip6Dxe: Fix various typos
[mirror_edk2.git] / NetworkPkg / Ip6Dxe / Ip6Icmp.c
CommitLineData
a3bcde70
HT
1/** @file\r
2 The ICMPv6 handle routines to process the ICMPv6 control messages.\r
3\r
f75a7f56 4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
40696972 5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
f75a7f56 6\r
ecf98fbc 7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
a3bcde70
HT
8\r
9**/\r
10\r
11#include "Ip6Impl.h"\r
12\r
13EFI_IP6_ICMP_TYPE mIp6SupportedIcmp[23] = {\r
14\r
15 {\r
16 ICMP_V6_DEST_UNREACHABLE,\r
17 ICMP_V6_NO_ROUTE_TO_DEST\r
18 },\r
19 {\r
20 ICMP_V6_DEST_UNREACHABLE,\r
21 ICMP_V6_COMM_PROHIBITED\r
22 },\r
23 {\r
24 ICMP_V6_DEST_UNREACHABLE,\r
25 ICMP_V6_BEYOND_SCOPE\r
26 },\r
27 {\r
28 ICMP_V6_DEST_UNREACHABLE,\r
29 ICMP_V6_ADDR_UNREACHABLE\r
30 },\r
31 {\r
32 ICMP_V6_DEST_UNREACHABLE,\r
33 ICMP_V6_PORT_UNREACHABLE\r
34 },\r
35 {\r
36 ICMP_V6_DEST_UNREACHABLE,\r
37 ICMP_V6_SOURCE_ADDR_FAILED\r
38 },\r
39 {\r
40 ICMP_V6_DEST_UNREACHABLE,\r
41 ICMP_V6_ROUTE_REJECTED\r
42 },\r
43\r
44 {\r
45 ICMP_V6_PACKET_TOO_BIG,\r
46 ICMP_V6_DEFAULT_CODE\r
47 },\r
48\r
49 {\r
50 ICMP_V6_TIME_EXCEEDED,\r
51 ICMP_V6_TIMEOUT_HOP_LIMIT\r
52 },\r
53 {\r
54 ICMP_V6_TIME_EXCEEDED,\r
55 ICMP_V6_TIMEOUT_REASSEMBLE\r
56 },\r
57\r
58 {\r
59 ICMP_V6_PARAMETER_PROBLEM,\r
60 ICMP_V6_ERRONEOUS_HEADER\r
61 },\r
62 {\r
63 ICMP_V6_PARAMETER_PROBLEM,\r
64 ICMP_V6_UNRECOGNIZE_NEXT_HDR\r
65 },\r
66 {\r
67 ICMP_V6_PARAMETER_PROBLEM,\r
68 ICMP_V6_UNRECOGNIZE_OPTION\r
69 },\r
70\r
71 {\r
72 ICMP_V6_ECHO_REQUEST,\r
73 ICMP_V6_DEFAULT_CODE\r
74 },\r
75 {\r
76 ICMP_V6_ECHO_REPLY,\r
77 ICMP_V6_DEFAULT_CODE\r
78 },\r
79\r
80 {\r
81 ICMP_V6_LISTENER_QUERY,\r
82 ICMP_V6_DEFAULT_CODE\r
83 },\r
84 {\r
85 ICMP_V6_LISTENER_REPORT,\r
86 ICMP_V6_DEFAULT_CODE\r
87 },\r
88 {\r
89 ICMP_V6_LISTENER_REPORT_2,\r
90 ICMP_V6_DEFAULT_CODE\r
91 },\r
92 {\r
93 ICMP_V6_LISTENER_DONE,\r
94 ICMP_V6_DEFAULT_CODE\r
95 },\r
96\r
97 {\r
98 ICMP_V6_ROUTER_SOLICIT,\r
99 ICMP_V6_DEFAULT_CODE\r
100 },\r
101 {\r
102 ICMP_V6_ROUTER_ADVERTISE,\r
103 ICMP_V6_DEFAULT_CODE\r
104 },\r
105 {\r
106 ICMP_V6_NEIGHBOR_SOLICIT,\r
107 ICMP_V6_DEFAULT_CODE\r
108 },\r
109 {\r
110 ICMP_V6_NEIGHBOR_ADVERTISE,\r
111 ICMP_V6_DEFAULT_CODE\r
112 },\r
113};\r
114\r
115/**\r
116 Reply an ICMPv6 echo request.\r
117\r
118 @param[in] IpSb The IP service that received the packet.\r
119 @param[in] Head The IP head of the ICMPv6 informational message.\r
120 @param[in] Packet The content of the ICMPv6 message with the IP head\r
121 removed.\r
122\r
123 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.\r
124 @retval EFI_SUCCESS Successfully answered the ICMPv6 Echo request.\r
125 @retval Others Failed to answer the ICMPv6 Echo request.\r
126\r
127**/\r
128EFI_STATUS\r
129Ip6IcmpReplyEcho (\r
130 IN IP6_SERVICE *IpSb,\r
131 IN EFI_IP6_HEADER *Head,\r
132 IN NET_BUF *Packet\r
133 )\r
134{\r
135 IP6_ICMP_INFORMATION_HEAD *Icmp;\r
136 NET_BUF *Data;\r
137 EFI_STATUS Status;\r
138 EFI_IP6_HEADER ReplyHead;\r
139\r
140 Status = EFI_OUT_OF_RESOURCES;\r
141 //\r
142 // make a copy the packet, it is really a bad idea to\r
143 // send the MNP's buffer back to MNP.\r
144 //\r
145 Data = NetbufDuplicate (Packet, NULL, IP6_MAX_HEADLEN);\r
146 if (Data == NULL) {\r
147 goto Exit;\r
148 }\r
149\r
150 //\r
151 // Change the ICMP type to echo reply, exchange the source\r
152 // and destination, then send it. The source is updated to\r
153 // use specific destination. See RFC1122. SRR/RR option\r
154 // update is omitted.\r
155 //\r
156 Icmp = (IP6_ICMP_INFORMATION_HEAD *) NetbufGetByte (Data, 0, NULL);\r
157 if (Icmp == NULL) {\r
158 NetbufFree (Data);\r
159 goto Exit;\r
160 }\r
161\r
162 Icmp->Head.Type = ICMP_V6_ECHO_REPLY;\r
163 Icmp->Head.Checksum = 0;\r
164\r
165 //\r
166 // Generate the IPv6 basic header\r
167 // If the Echo Reply is a response to a Echo Request sent to one of the node's unicast address,\r
168 // the Source address of the Echo Reply must be the same address.\r
169 //\r
170 ZeroMem (&ReplyHead, sizeof (EFI_IP6_HEADER));\r
171\r
172 ReplyHead.PayloadLength = HTONS ((UINT16) (Packet->TotalSize));\r
173 ReplyHead.NextHeader = IP6_ICMP;\r
174 ReplyHead.HopLimit = IpSb->CurHopLimit;\r
175 IP6_COPY_ADDRESS (&ReplyHead.DestinationAddress, &Head->SourceAddress);\r
176\r
177 if (Ip6IsOneOfSetAddress (IpSb, &Head->DestinationAddress, NULL, NULL)) {\r
178 IP6_COPY_ADDRESS (&ReplyHead.SourceAddress, &Head->DestinationAddress);\r
179 }\r
180\r
181 //\r
182 // If source is unspecified, Ip6Output will select a source for us\r
183 //\r
184 Status = Ip6Output (\r
185 IpSb,\r
186 NULL,\r
187 NULL,\r
188 Data,\r
189 &ReplyHead,\r
190 NULL,\r
191 0,\r
192 Ip6SysPacketSent,\r
193 NULL\r
194 );\r
195\r
196Exit:\r
197 NetbufFree (Packet);\r
198 return Status;\r
199}\r
200\r
201/**\r
202 Process Packet Too Big message sent by a router in response to a packet that\r
203 it cannot forward because the packet is larger than the MTU of outgoing link.\r
204 Since this driver already uses IPv6 minimum link MTU as the maximum packet size,\r
205 if Packet Too Big message is still received, do not reduce the packet size, but\r
206 rather include a Fragment header in the subsequent packets.\r
207\r
208 @param[in] IpSb The IP service that received the packet.\r
209 @param[in] Head The IP head of the ICMPv6 error packet.\r
210 @param[in] Packet The content of the ICMPv6 error with the IP head\r
211 removed.\r
212\r
213 @retval EFI_SUCCESS The ICMPv6 error processed successfully.\r
214 @retval EFI_OUT_OF_RESOURCES Failed to finish the operation due to lack of\r
215 resource.\r
216 @retval EFI_NOT_FOUND The packet too big message is not sent to us.\r
217\r
218**/\r
219EFI_STATUS\r
220Ip6ProcessPacketTooBig (\r
221 IN IP6_SERVICE *IpSb,\r
222 IN EFI_IP6_HEADER *Head,\r
223 IN NET_BUF *Packet\r
224 )\r
225{\r
226 IP6_ICMP_ERROR_HEAD Icmp;\r
227 UINT32 Mtu;\r
228 IP6_ROUTE_ENTRY *RouteEntry;\r
229 EFI_IPv6_ADDRESS *DestAddress;\r
230\r
231 NetbufCopy (Packet, 0, sizeof (Icmp), (UINT8 *) &Icmp);\r
232 Mtu = NTOHL (Icmp.Fourth);\r
233 DestAddress = &Icmp.IpHead.DestinationAddress;\r
234\r
235 if (Mtu < IP6_MIN_LINK_MTU) {\r
236 //\r
237 // Normally the multicast address is considered to be on-link and not recorded\r
238 // in route table. Here it is added into the table since the MTU information\r
239 // need be recorded.\r
240 //\r
241 if (IP6_IS_MULTICAST (DestAddress)) {\r
242 RouteEntry = Ip6CreateRouteEntry (DestAddress, 128, NULL);\r
243 if (RouteEntry == NULL) {\r
244 NetbufFree (Packet);\r
245 return EFI_OUT_OF_RESOURCES;\r
246 }\r
247\r
248 RouteEntry->Flag = IP6_DIRECT_ROUTE | IP6_PACKET_TOO_BIG;\r
249 InsertHeadList (&IpSb->RouteTable->RouteArea[128], &RouteEntry->Link);\r
250 IpSb->RouteTable->TotalNum++;\r
251 } else {\r
252 RouteEntry = Ip6FindRouteEntry (IpSb->RouteTable, DestAddress, NULL);\r
253 if (RouteEntry == NULL) {\r
254 NetbufFree (Packet);\r
255 return EFI_NOT_FOUND;\r
256 }\r
257\r
258 RouteEntry->Flag = RouteEntry->Flag | IP6_PACKET_TOO_BIG;\r
259\r
260 Ip6FreeRouteEntry (RouteEntry);\r
261 }\r
262 }\r
263\r
264 NetbufFree (Packet);\r
265 return EFI_SUCCESS;\r
266}\r
267\r
268/**\r
269 Process the ICMPv6 error packet, and deliver the packet to upper layer.\r
270\r
271 @param[in] IpSb The IP service that received the packet.\r
272 @param[in] Head The IP head of the ICMPv6 error packet.\r
273 @param[in] Packet The content of the ICMPv6 error with the IP head\r
274 removed.\r
275\r
276 @retval EFI_SUCCESS The ICMPv6 error processed successfully.\r
277 @retval EFI_INVALID_PARAMETER The packet is invalid.\r
278 @retval Others Failed to process the packet.\r
279\r
280**/\r
281EFI_STATUS\r
282Ip6ProcessIcmpError (\r
283 IN IP6_SERVICE *IpSb,\r
284 IN EFI_IP6_HEADER *Head,\r
285 IN NET_BUF *Packet\r
286 )\r
287{\r
288 IP6_ICMP_ERROR_HEAD Icmp;\r
289\r
290 //\r
291 // Check the validity of the packet\r
292 //\r
293 if (Packet->TotalSize < sizeof (Icmp)) {\r
294 goto DROP;\r
295 }\r
296\r
297 NetbufCopy (Packet, 0, sizeof (Icmp), (UINT8 *) &Icmp);\r
298 if (Icmp.Head.Type == ICMP_V6_PACKET_TOO_BIG) {\r
299 return Ip6ProcessPacketTooBig (IpSb, Head, Packet);\r
300 }\r
301\r
302 //\r
7de8045a 303 // Notify the upper-layer process that an ICMPv6 error message is received.\r
a3bcde70
HT
304 //\r
305 IP6_GET_CLIP_INFO (Packet)->Status = EFI_ICMP_ERROR;\r
306 return Ip6Demultiplex (IpSb, Head, Packet);\r
307\r
308DROP:\r
309 NetbufFree (Packet);\r
310 Packet = NULL;\r
311 return EFI_INVALID_PARAMETER;\r
312}\r
313\r
314/**\r
315 Process the ICMPv6 informational messages. If it is an ICMPv6 echo\r
316 request, answer it. If it is a MLD message, trigger MLD routines to\r
317 process it. If it is a ND message, trigger ND routines to process it.\r
318 Otherwise, deliver it to upper layer.\r
319\r
320 @param[in] IpSb The IP service that receivd the packet.\r
321 @param[in] Head The IP head of the ICMPv6 informational packet.\r
322 @param[in] Packet The content of the ICMPv6 informational packet\r
323 with IP head removed.\r
324\r
325 @retval EFI_INVALID_PARAMETER The packet is invalid.\r
326 @retval EFI_SUCCESS The ICMPv6 informational message processed.\r
327 @retval Others Failed to process ICMPv6 informational message.\r
328\r
329**/\r
330EFI_STATUS\r
331Ip6ProcessIcmpInformation (\r
332 IN IP6_SERVICE *IpSb,\r
333 IN EFI_IP6_HEADER *Head,\r
334 IN NET_BUF *Packet\r
335 )\r
336{\r
337 IP6_ICMP_INFORMATION_HEAD Icmp;\r
338 EFI_STATUS Status;\r
339\r
340 NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);\r
341 NET_CHECK_SIGNATURE (Packet, NET_BUF_SIGNATURE);\r
342 ASSERT (Head != NULL);\r
343\r
344 NetbufCopy (Packet, 0, sizeof (Icmp), (UINT8 *) &Icmp);\r
345 Status = EFI_INVALID_PARAMETER;\r
346\r
347 switch (Icmp.Head.Type) {\r
348 case ICMP_V6_ECHO_REQUEST:\r
349 //\r
350 // If ICMPv6 echo, reply it\r
351 //\r
352 if (Icmp.Head.Code == 0) {\r
353 Status = Ip6IcmpReplyEcho (IpSb, Head, Packet);\r
354 }\r
355 break;\r
356 case ICMP_V6_LISTENER_QUERY:\r
357 Status = Ip6ProcessMldQuery (IpSb, Head, Packet);\r
358 break;\r
359 case ICMP_V6_LISTENER_REPORT:\r
360 case ICMP_V6_LISTENER_REPORT_2:\r
361 Status = Ip6ProcessMldReport (IpSb, Head, Packet);\r
362 break;\r
363 case ICMP_V6_NEIGHBOR_SOLICIT:\r
364 Status = Ip6ProcessNeighborSolicit (IpSb, Head, Packet);\r
365 break;\r
366 case ICMP_V6_NEIGHBOR_ADVERTISE:\r
367 Status = Ip6ProcessNeighborAdvertise (IpSb, Head, Packet);\r
368 break;\r
369 case ICMP_V6_ROUTER_ADVERTISE:\r
370 Status = Ip6ProcessRouterAdvertise (IpSb, Head, Packet);\r
371 break;\r
372 case ICMP_V6_REDIRECT:\r
373 Status = Ip6ProcessRedirect (IpSb, Head, Packet);\r
374 break;\r
375 case ICMP_V6_ECHO_REPLY:\r
376 Status = Ip6Demultiplex (IpSb, Head, Packet);\r
377 break;\r
378 default:\r
379 Status = EFI_INVALID_PARAMETER;\r
380 break;\r
381 }\r
382\r
383 return Status;\r
384}\r
385\r
386/**\r
387 Handle the ICMPv6 packet. First validate the message format,\r
388 then, according to the message types, process it as an informational packet or\r
389 an error packet.\r
390\r
391 @param[in] IpSb The IP service that received the packet.\r
392 @param[in] Head The IP head of the ICMPv6 packet.\r
393 @param[in] Packet The content of the ICMPv6 packet with IP head\r
394 removed.\r
395\r
8d774c74 396 @retval EFI_INVALID_PARAMETER The packet is malformatted.\r
a3bcde70
HT
397 @retval EFI_SUCCESS The ICMPv6 message successfully processed.\r
398 @retval Others Failed to handle the ICMPv6 packet.\r
399\r
400**/\r
401EFI_STATUS\r
402Ip6IcmpHandle (\r
403 IN IP6_SERVICE *IpSb,\r
404 IN EFI_IP6_HEADER *Head,\r
405 IN NET_BUF *Packet\r
406 )\r
407{\r
408 IP6_ICMP_HEAD Icmp;\r
409 UINT16 PseudoCheckSum;\r
410 UINT16 CheckSum;\r
411\r
412 //\r
413 // Check the validity of the incoming packet.\r
414 //\r
415 if (Packet->TotalSize < sizeof (Icmp)) {\r
416 goto DROP;\r
417 }\r
418\r
419 NetbufCopy (Packet, 0, sizeof (Icmp), (UINT8 *) &Icmp);\r
420\r
421 //\r
422 // Make sure checksum is valid.\r
423 //\r
424 PseudoCheckSum = NetIp6PseudoHeadChecksum (\r
425 &Head->SourceAddress,\r
426 &Head->DestinationAddress,\r
427 IP6_ICMP,\r
428 Packet->TotalSize\r
429 );\r
430 CheckSum = (UINT16) ~NetAddChecksum (PseudoCheckSum, NetbufChecksum (Packet));\r
431 if (CheckSum != 0) {\r
432 goto DROP;\r
433 }\r
434\r
435 //\r
436 // According to the packet type, call corresponding process\r
437 //\r
438 if (Icmp.Type <= ICMP_V6_ERROR_MAX) {\r
439 return Ip6ProcessIcmpError (IpSb, Head, Packet);\r
440 } else {\r
441 return Ip6ProcessIcmpInformation (IpSb, Head, Packet);\r
442 }\r
443\r
444DROP:\r
445 NetbufFree (Packet);\r
446 return EFI_INVALID_PARAMETER;\r
447}\r
448\r
449/**\r
450 Retrieve the Prefix address according to the PrefixLength by clear the useless\r
451 bits.\r
452\r
453 @param[in] PrefixLength The prefix length of the prefix.\r
454 @param[in, out] Prefix On input, points to the original prefix address\r
455 with dirty bits; on output, points to the updated\r
456 address with useless bit clear.\r
457\r
458**/\r
459VOID\r
460Ip6GetPrefix (\r
461 IN UINT8 PrefixLength,\r
462 IN OUT EFI_IPv6_ADDRESS *Prefix\r
463 )\r
464{\r
465 UINT8 Byte;\r
466 UINT8 Bit;\r
467 UINT8 Mask;\r
468 UINT8 Value;\r
469\r
c720da28 470 ASSERT ((Prefix != NULL) && (PrefixLength < IP6_PREFIX_MAX));\r
a3bcde70
HT
471\r
472 if (PrefixLength == 0) {\r
473 ZeroMem (Prefix, sizeof (EFI_IPv6_ADDRESS));\r
474 return ;\r
475 }\r
476\r
c720da28 477 if (PrefixLength >= IP6_PREFIX_MAX) {\r
a3bcde70
HT
478 return ;\r
479 }\r
480\r
481 Byte = (UINT8) (PrefixLength / 8);\r
482 Bit = (UINT8) (PrefixLength % 8);\r
483 Value = Prefix->Addr[Byte];\r
484\r
40696972 485 if (Byte > 0) {\r
a3bcde70
HT
486 ZeroMem (Prefix->Addr + Byte, 16 - Byte);\r
487 }\r
488\r
489 if (Bit > 0) {\r
490 Mask = (UINT8) (0xFF << (8 - Bit));\r
491 Prefix->Addr[Byte] = (UINT8) (Value & Mask);\r
492 }\r
493\r
494}\r
495\r
496/**\r
497 Check whether the DestinationAddress is an anycast address.\r
498\r
499 @param[in] IpSb The IP service that received the packet.\r
500 @param[in] DestinationAddress Points to the Destination Address of the packet.\r
501\r
502 @retval TRUE The DestinationAddress is anycast address.\r
503 @retval FALSE The DestinationAddress is not anycast address.\r
504\r
505**/\r
506BOOLEAN\r
507Ip6IsAnycast (\r
508 IN IP6_SERVICE *IpSb,\r
509 IN EFI_IPv6_ADDRESS *DestinationAddress\r
510 )\r
511{\r
512 IP6_PREFIX_LIST_ENTRY *PrefixEntry;\r
513 EFI_IPv6_ADDRESS Prefix;\r
514 BOOLEAN Flag;\r
515\r
516 ZeroMem (&Prefix, sizeof (EFI_IPv6_ADDRESS));\r
517\r
518 Flag = FALSE;\r
519\r
520 //\r
521 // If the address is known as on-link or autonomous prefix, record it as\r
522 // anycast address.\r
523 //\r
524 do {\r
525 PrefixEntry = Ip6FindPrefixListEntry (IpSb, Flag, 255, DestinationAddress);\r
526 if (PrefixEntry != NULL) {\r
527 IP6_COPY_ADDRESS (&Prefix, &PrefixEntry->Prefix);\r
528 Ip6GetPrefix (PrefixEntry->PrefixLength, &Prefix);\r
529 if (EFI_IP6_EQUAL (&Prefix, DestinationAddress)) {\r
530 return TRUE;\r
531 }\r
532 }\r
533\r
534 Flag = (BOOLEAN) !Flag;\r
535 } while (Flag);\r
536\r
537 return FALSE;\r
538}\r
539\r
540/**\r
541 Generate ICMPv6 error message and send it out to DestinationAddress. Currently\r
542 Destination Unreachable message, Time Exceeded message and Parameter Problem\r
543 message are supported.\r
544\r
545 @param[in] IpSb The IP service that received the packet.\r
546 @param[in] Packet The packet which invoking ICMPv6 error.\r
547 @param[in] SourceAddress If not NULL, points to the SourceAddress.\r
548 Otherwise, the IP layer will select a source address\r
549 according to the DestinationAddress.\r
550 @param[in] DestinationAddress Points to the Destination Address of the ICMPv6\r
551 error message.\r
552 @param[in] Type The type of the ICMPv6 message.\r
553 @param[in] Code The additional level of the ICMPv6 message.\r
554 @param[in] Pointer If not NULL, identifies the octet offset within\r
555 the invoking packet where the error was detected.\r
556\r
8d774c74 557 @retval EFI_INVALID_PARAMETER The packet is malformatted.\r
a3bcde70
HT
558 @retval EFI_OUT_OF_RESOURCES There is no sufficient resource to complete the\r
559 operation.\r
560 @retval EFI_SUCCESS The ICMPv6 message was successfully sent out.\r
561 @retval Others Failed to generate the ICMPv6 packet.\r
562\r
563**/\r
564EFI_STATUS\r
565Ip6SendIcmpError (\r
566 IN IP6_SERVICE *IpSb,\r
567 IN NET_BUF *Packet,\r
568 IN EFI_IPv6_ADDRESS *SourceAddress OPTIONAL,\r
569 IN EFI_IPv6_ADDRESS *DestinationAddress,\r
570 IN UINT8 Type,\r
571 IN UINT8 Code,\r
572 IN UINT32 *Pointer OPTIONAL\r
573 )\r
574{\r
575 UINT32 PacketLen;\r
576 NET_BUF *ErrorMsg;\r
577 UINT16 PayloadLen;\r
578 EFI_IP6_HEADER Head;\r
579 IP6_ICMP_INFORMATION_HEAD *IcmpHead;\r
580 UINT8 *ErrorBody;\r
581\r
582 if (DestinationAddress == NULL) {\r
583 return EFI_INVALID_PARAMETER;\r
584 }\r
585\r
586 //\r
587 // An ICMPv6 error message must not be originated as a result of receiving\r
588 // a packet whose source address does not uniquely identify a single node --\r
589 // e.g., the IPv6 Unspecified Address, an IPv6 multicast address, or an address\r
590 // known by the ICMP message originator to be an IPv6 anycast address.\r
591 //\r
592 if (NetIp6IsUnspecifiedAddr (DestinationAddress) ||\r
593 IP6_IS_MULTICAST (DestinationAddress) ||\r
594 Ip6IsAnycast (IpSb, DestinationAddress)\r
595 ) {\r
596 return EFI_INVALID_PARAMETER;\r
597 }\r
598\r
599 switch (Type) {\r
600 case ICMP_V6_DEST_UNREACHABLE:\r
601 case ICMP_V6_TIME_EXCEEDED:\r
602 break;\r
603\r
604 case ICMP_V6_PARAMETER_PROBLEM:\r
605 if (Pointer == NULL) {\r
606 return EFI_INVALID_PARAMETER;\r
607 }\r
608\r
609 break;\r
610\r
611 default:\r
612 return EFI_INVALID_PARAMETER;\r
613 }\r
614\r
615 PacketLen = sizeof (IP6_ICMP_ERROR_HEAD) + Packet->TotalSize;\r
616\r
617 if (PacketLen > IpSb->MaxPacketSize) {\r
618 PacketLen = IpSb->MaxPacketSize;\r
619 }\r
620\r
621 ErrorMsg = NetbufAlloc (PacketLen);\r
622 if (ErrorMsg == NULL) {\r
623 return EFI_OUT_OF_RESOURCES;\r
624 }\r
625\r
626 PayloadLen = (UINT16) (PacketLen - sizeof (EFI_IP6_HEADER));\r
627\r
628 //\r
629 // Create the basic IPv6 header.\r
630 //\r
631 ZeroMem (&Head, sizeof (EFI_IP6_HEADER));\r
632\r
633 Head.PayloadLength = HTONS (PayloadLen);\r
634 Head.NextHeader = IP6_ICMP;\r
635 Head.HopLimit = IpSb->CurHopLimit;\r
636\r
637 if (SourceAddress != NULL) {\r
638 IP6_COPY_ADDRESS (&Head.SourceAddress, SourceAddress);\r
639 } else {\r
640 ZeroMem (&Head.SourceAddress, sizeof (EFI_IPv6_ADDRESS));\r
641 }\r
642\r
643 IP6_COPY_ADDRESS (&Head.DestinationAddress, DestinationAddress);\r
644\r
645 NetbufReserve (ErrorMsg, sizeof (EFI_IP6_HEADER));\r
646\r
647 //\r
648 // Fill in the ICMP error message head\r
649 //\r
650 IcmpHead = (IP6_ICMP_INFORMATION_HEAD *) NetbufAllocSpace (ErrorMsg, sizeof (IP6_ICMP_INFORMATION_HEAD), FALSE);\r
651 if (IcmpHead == NULL) {\r
652 NetbufFree (ErrorMsg);\r
653 return EFI_OUT_OF_RESOURCES;\r
654 }\r
655\r
656 ZeroMem (IcmpHead, sizeof (IP6_ICMP_INFORMATION_HEAD));\r
657 IcmpHead->Head.Type = Type;\r
658 IcmpHead->Head.Code = Code;\r
659\r
660 if (Pointer != NULL) {\r
661 IcmpHead->Fourth = HTONL (*Pointer);\r
662 }\r
663\r
664 //\r
665 // Fill in the ICMP error message body\r
666 //\r
667 PayloadLen -= sizeof (IP6_ICMP_INFORMATION_HEAD);\r
668 ErrorBody = NetbufAllocSpace (ErrorMsg, PayloadLen, FALSE);\r
669 if (ErrorBody != NULL) {\r
670 ZeroMem (ErrorBody, PayloadLen);\r
671 NetbufCopy (Packet, 0, PayloadLen, ErrorBody);\r
672 }\r
673\r
674 //\r
675 // Transmit the packet\r
676 //\r
677 return Ip6Output (IpSb, NULL, NULL, ErrorMsg, &Head, NULL, 0, Ip6SysPacketSent, NULL);\r
678}\r
679\r