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 (ICMP) */
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_ip.h"
29 #include "nx_icmp.h"
30
31
32 /* Bring in externs for caller checking code. */
33
34 NX_CALLER_CHECKING_EXTERNS
35
36
37 /**************************************************************************/
38 /* */
39 /* FUNCTION RELEASE */
40 /* */
41 /* _nxde_icmp_source_ping PORTABLE C */
42 /* 6.1 */
43 /* AUTHOR */
44 /* */
45 /* Yuxin Zhou, Microsoft Corporation */
46 /* */
47 /* DESCRIPTION */
48 /* */
49 /* This function checks for errors in the dual stack (IPv4 or IPv6 */
50 /* ICMP ping service. */
51 /* */
52 /* INPUT */
53 /* */
54 /* ip_ptr Pointer to IP instance */
55 /* ip_address IP address to ping */
56 /* address_index Index of IPv4 or IPv6 address */
57 /* to use as the source address*/
58 /* data_ptr User Data pointer */
59 /* data_size Size of User Data */
60 /* response_ptr Pointer to Response Packet */
61 /* wait_option Suspension option */
62 /* */
63 /* OUTPUT */
64 /* */
65 /* None */
66 /* */
67 /* CALLS */
68 /* */
69 /* _nxd_icmp_source_ping Actual ICMP ping function */
70 /* */
71 /* CALLED BY */
72 /* */
73 /* Application Code */
74 /* */
75 /* RELEASE HISTORY */
76 /* */
77 /* DATE NAME DESCRIPTION */
78 /* */
79 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
80 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
81 /* resulting in version 6.1 */
82 /* */
83 /**************************************************************************/
_nxde_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)84 UINT _nxde_icmp_source_ping(NX_IP *ip_ptr, NXD_ADDRESS *ip_address, UINT address_index,
85 CHAR *data_ptr, ULONG data_size,
86 NX_PACKET **response_ptr, ULONG wait_option)
87 {
88
89 UINT status;
90
91
92 /* Check for invalid input pointers. */
93 if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID) || (response_ptr == NX_NULL))
94 {
95 return(NX_PTR_ERROR);
96 }
97
98 /* Check for invalid IP address. */
99 if (ip_address == NX_NULL)
100 {
101 return(NX_IP_ADDRESS_ERROR);
102 }
103
104 /* Check for invalid version. */
105 if ((ip_address -> nxd_ip_version != NX_IP_VERSION_V4) &&
106 (ip_address -> nxd_ip_version != NX_IP_VERSION_V6))
107 {
108
109 return(NX_IP_ADDRESS_ERROR);
110 }
111
112 #ifndef NX_DISABLE_IPV4
113 /* Check to see if ICMP is enabled. */
114 if (ip_address -> nxd_ip_version == NX_IP_VERSION_V4)
115 {
116 if (address_index >= NX_MAX_IP_INTERFACES)
117 {
118 return(NX_INVALID_INTERFACE);
119 }
120
121
122 /* Cast the function pointer into a ULONG. Since this is exactly what we wish to do, disable the lint warning with the following comment: */
123 /*lint -e{923} suppress cast of pointer to ULONG. */
124 if ((ALIGN_TYPE)ip_ptr -> nx_ip_icmpv4_packet_process == NX_NULL)
125 {
126
127 return(NX_NOT_ENABLED);
128 }
129 }
130 #endif /* NX_DISABLE_IPV4 */
131
132 #ifdef FEATURE_NX_IPV6
133 if (ip_address -> nxd_ip_version == NX_IP_VERSION_V6)
134 {
135 if ((address_index >= (NX_MAX_IPV6_ADDRESSES + NX_LOOPBACK_IPV6_ENABLED)) ||
136 (ip_ptr -> nx_ipv6_address[address_index].nxd_ipv6_address_attached == NX_NULL) ||
137 (ip_ptr -> nx_ipv6_address[address_index].nxd_ipv6_address_valid == NX_FALSE))
138 {
139 return(NX_INVALID_INTERFACE);
140 }
141
142 /* Cast the function pointer into a ULONG. Since this is exactly what we wish to do, disable the lint warning with the following comment: */
143 /*lint -e{923} suppress cast of pointer to ULONG. */
144 if (((ALIGN_TYPE)ip_ptr -> nx_ip_icmpv6_packet_process == NX_NULL) ||
145 ((ALIGN_TYPE)ip_ptr -> nx_ipv6_packet_receive == NX_NULL))
146 {
147
148 return(NX_NOT_ENABLED);
149 }
150 }
151 #endif /* FEATURE_NX_IPV6 */
152
153 /* Check for appropriate caller. */
154 NX_THREADS_ONLY_CALLER_CHECKING
155
156 /* Call actual ICMP ping function. */
157 status = _nxd_icmp_source_ping(ip_ptr, ip_address, address_index, data_ptr, data_size,
158 response_ptr, wait_option);
159
160 /* Return completion status. */
161 return(status);
162 }
163
164