1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** NetX Component */
16 /** */
17 /** Internet Control Message Protocol for IPv6 (ICMPv6) */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define NX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "nx_api.h"
28 #include "nx_icmp.h"
29 #include "nx_icmpv6.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _nxd_icmp_source_ping PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* Yuxin Zhou, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* Depending on the destination IP address, this function performs */
45 /* ICMP ping or ICMPv6 ping. using specified source address. */
46 /* For ICMPv6 ping, the sender address is set to the IPv6 indexed */
47 /* by address_index. The parameter address_index is ignored for */
48 /* IPv4 ping operations. */
49 /* */
50 /* INPUT */
51 /* */
52 /* ip_ptr Pointer to IP instance */
53 /* ip_address IP address to ping */
54 /* address_index Index to the IPv6 address */
55 /* data_ptr User Data pointer */
56 /* data_size Size of User Data */
57 /* response_ptr Pointer to Response Packet */
58 /* wait_option Suspension option */
59 /* */
60 /* OUTPUT */
61 /* */
62 /* NX_SUCCESS Successful completion */
63 /* NX_NOT_SUPPORTED IPv6 or ICMP not enabled */
64 /* status Actual completion status */
65 /* */
66 /* CALLS */
67 /* */
68 /* _nx_ip_route_find Find suitable interface */
69 /* _nx_icmp_interface_ping IPv4 ICMP ping routine. */
70 /* _nx_icmp_interface_ping6 IPv6 ICMP ping routine. */
71 /* */
72 /* CALLED BY */
73 /* */
74 /* Application Code */
75 /* */
76 /* RELEASE HISTORY */
77 /* */
78 /* DATE NAME DESCRIPTION */
79 /* */
80 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
81 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
82 /* resulting in version 6.1 */
83 /* */
84 /**************************************************************************/
_nxd_icmp_source_ping(NX_IP * ip_ptr,NXD_ADDRESS * ip_address,UINT address_index,CHAR * data_ptr,ULONG data_size,NX_PACKET ** response_ptr,ULONG wait_option)85 UINT _nxd_icmp_source_ping(NX_IP *ip_ptr, NXD_ADDRESS *ip_address, UINT address_index,
86 CHAR *data_ptr, ULONG data_size,
87 NX_PACKET **response_ptr, ULONG wait_option)
88 {
89
90 UINT status = NX_NOT_SUPPORTED;
91 #ifndef NX_DISABLE_IPV4
92 ULONG next_hop_address;
93 NX_INTERFACE *interface_ptr;
94 #endif /* !NX_DISABLE_IPV4 */
95
96 #ifndef NX_DISABLE_IPV4
97 if (ip_address -> nxd_ip_version == NX_IP_VERSION_V4)
98 {
99
100 /* Set the outgoing interface. */
101 interface_ptr = &ip_ptr -> nx_ip_interface[address_index];
102
103 /* Find the next hop address. . */
104 _nx_ip_route_find(ip_ptr, ip_address -> nxd_ip_address.v4, &interface_ptr, &next_hop_address);
105
106 /*lint -e{644} suppress variable might not be initialized, since "next_hop_address" was initialized in _nx_ip_route_find. */
107 status = _nx_icmp_interface_ping(ip_ptr, ip_address -> nxd_ip_address.v4, interface_ptr, next_hop_address,
108 data_ptr, data_size, response_ptr, wait_option);
109 }
110 #endif /* !NX_DISABLE_IPV4 */
111
112 #ifdef FEATURE_NX_IPV6
113 if (ip_address -> nxd_ip_version == NX_IP_VERSION_V6)
114 {
115
116 status = _nx_icmp_interface_ping6(ip_ptr, ip_address, data_ptr, data_size,
117 &ip_ptr -> nx_ipv6_address[address_index], response_ptr, wait_option);
118 }
119 #endif /* FEATURE_NX_IPV6 */
120
121 return(status);
122 }
123
124