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_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 ICMP*/
50 /* ping function call. */
51 /* */
52 /* INPUT */
53 /* */
54 /* ip_ptr Pointer to IP instance */
55 /* ip_address IP address to ping */
56 /* data_ptr User Data pointer */
57 /* data_size Size of User Data */
58 /* response_ptr Pointer to Response Packet */
59 /* wait_option Suspension option */
60 /* */
61 /* OUTPUT */
62 /* */
63 /* None */
64 /* */
65 /* CALLS */
66 /* */
67 /* _nxd_icmp_ping Actual ICMP ping function */
68 /* */
69 /* CALLED BY */
70 /* */
71 /* Application Code */
72 /* */
73 /* RELEASE HISTORY */
74 /* */
75 /* DATE NAME DESCRIPTION */
76 /* */
77 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
78 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
79 /* resulting in version 6.1 */
80 /* */
81 /**************************************************************************/
_nxde_icmp_ping(NX_IP * ip_ptr,NXD_ADDRESS * ip_address,CHAR * data_ptr,ULONG data_size,NX_PACKET ** response_ptr,ULONG wait_option)82 UINT _nxde_icmp_ping(NX_IP *ip_ptr, NXD_ADDRESS *ip_address,
83 CHAR *data_ptr, ULONG data_size,
84 NX_PACKET **response_ptr, ULONG wait_option)
85 {
86
87 UINT status;
88
89
90 /* Check for invalid input pointers. */
91 if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID) || (response_ptr == NX_NULL))
92 {
93 return(NX_PTR_ERROR);
94 }
95
96 /* Check for invalid IP address. */
97 if (ip_address == NX_NULL)
98 {
99 return(NX_IP_ADDRESS_ERROR);
100 }
101
102 /* Check for invalid version. */
103 if ((ip_address -> nxd_ip_version != NX_IP_VERSION_V4) &&
104 (ip_address -> nxd_ip_version != NX_IP_VERSION_V6))
105 {
106
107 return(NX_IP_ADDRESS_ERROR);
108 }
109
110 #ifndef NX_DISABLE_IPV4
111 /* Check to see if ICMP is enabled. */
112 /* Cast the function pointer into a ULONG. Since this is exactly what we wish to do, disable the lint warning with the following comment: */
113 /*lint -e{923} suppress cast of pointer to ULONG. */
114 if ((ip_address -> nxd_ip_version == NX_IP_VERSION_V4) &&
115 ((ALIGN_TYPE)ip_ptr -> nx_ip_icmpv4_packet_process == NX_NULL))
116 {
117
118 return(NX_NOT_ENABLED);
119 }
120 #endif /* !NX_DISABLE_IPV4 */
121
122 #ifdef FEATURE_NX_IPV6
123
124 if (ip_address -> nxd_ip_version == NX_IP_VERSION_V6)
125 {
126
127 /* Cast the function pointer into a ULONG. Since this is exactly what we wish to do, disable the lint warning with the following comment: */
128 /*lint -e{923} suppress cast of pointer to ULONG. */
129 if (((ALIGN_TYPE)ip_ptr -> nx_ip_icmpv6_packet_process == NX_NULL) ||
130 ((ALIGN_TYPE)ip_ptr -> nx_ipv6_packet_receive == NX_NULL))
131 {
132
133 return(NX_NOT_ENABLED);
134 }
135 }
136
137 #endif /* FEATURE_NX_IPV6 */
138
139 /* Check for appropriate caller. */
140 NX_THREADS_ONLY_CALLER_CHECKING
141
142 /* Call actual ICMP ping function. */
143 status = _nxd_icmp_ping(ip_ptr, ip_address, data_ptr, data_size,
144 response_ptr, wait_option);
145
146 /* Return completion status. */
147 return(status);
148 }
149
150