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_icmp.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _nx_icmp_info_get                                   PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Yuxin Zhou, Microsoft Corporation                                   */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function retrieves the selected ICMP information for the       */
44 /*    caller.                                                             */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    ip_ptr                                Pointer to IP instance        */
49 /*    pings_sent                            Destination for number of     */
50 /*                                            pings sent                  */
51 /*    ping_timeouts                         Destination for number of     */
52 /*                                            ping timeouts               */
53 /*    ping_threads_suspended                Destination for number of     */
54 /*                                            threads suspended on pings  */
55 /*    ping_responses_received               Destination for number of     */
56 /*                                            ping responses received     */
57 /*    icmp_checksum_errors                  Destination for number of     */
58 /*                                            ICMP checksum errors        */
59 /*    icmp_unhandled_messages               Destination for number of     */
60 /*                                            unhandled ICMP messages     */
61 /*                                                                        */
62 /*  OUTPUT                                                                */
63 /*                                                                        */
64 /*    None                                                                */
65 /*                                                                        */
66 /*  CALLS                                                                 */
67 /*                                                                        */
68 /*    tx_mutex_get                          Obtain protection mutex       */
69 /*    tx_mutex_put                          Release protection mutex      */
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 /**************************************************************************/
_nx_icmp_info_get(NX_IP * ip_ptr,ULONG * pings_sent,ULONG * ping_timeouts,ULONG * ping_threads_suspended,ULONG * ping_responses_received,ULONG * icmp_checksum_errors,ULONG * icmp_unhandled_messages)84 UINT  _nx_icmp_info_get(NX_IP *ip_ptr, ULONG *pings_sent, ULONG *ping_timeouts,
85                         ULONG *ping_threads_suspended, ULONG *ping_responses_received,
86                         ULONG *icmp_checksum_errors, ULONG *icmp_unhandled_messages)
87 {
88 
89     /* Obtain protection on this IP instance.  */
90     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
91 
92     /* Determine if pings sent is wanted.  */
93     if (pings_sent)
94     {
95 
96         /* Return the number of pings sent by this IP instance.  */
97         *pings_sent =  ip_ptr -> nx_ip_pings_sent;
98     }
99 
100     /* Determine if ping timeouts is wanted.  */
101     if (ping_timeouts)
102     {
103 
104         /* Return the number of ping timeouts by this IP instance.  */
105         *ping_timeouts =  ip_ptr -> nx_ip_ping_timeouts;
106     }
107 
108     /* Determine if ping threads suspended is wanted.  */
109     if (ping_threads_suspended)
110     {
111 
112         /* Return the number of ping threads suspended by this IP instance.  */
113         *ping_threads_suspended =  ip_ptr -> nx_ip_ping_threads_suspended;
114     }
115 
116     /* Determine if ping responses received is wanted.  */
117     if (ping_responses_received)
118     {
119 
120         /* Return the number of ping responses received by this IP instance.  */
121         *ping_responses_received =  ip_ptr -> nx_ip_ping_responses_received;
122     }
123 
124     /* Determine if ICMP checksum errors is wanted.  */
125     if (icmp_checksum_errors)
126     {
127 
128         /* Return the number of ICMP checksum errors detected by this IP instance.  */
129         *icmp_checksum_errors =  ip_ptr -> nx_ip_icmp_checksum_errors;
130     }
131 
132     /* Determine if ICMP unhandled messages is wanted.  */
133     if (icmp_unhandled_messages)
134     {
135 
136         /* Return the number of ICMP unhandled messages by this IP instance.  */
137         *icmp_unhandled_messages =  ip_ptr -> nx_ip_icmp_unhandled_messages;
138     }
139 
140     /* Release protection.  */
141     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
142 
143     /* Return a successful status.  */
144     return(NX_SUCCESS);
145 }
146 
147