xref: /xnu-12377.81.4/bsd/net/net_api_stats.h (revision 043036a2b3718f7f0be807e2870f8f47d3fa0796) !
1*043036a2SApple OSS Distributions /*
2*043036a2SApple OSS Distributions  * Copyright (c) 2017-2021 Apple Inc. All rights reserved.
3*043036a2SApple OSS Distributions  *
4*043036a2SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*043036a2SApple OSS Distributions  *
6*043036a2SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*043036a2SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*043036a2SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*043036a2SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*043036a2SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*043036a2SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*043036a2SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*043036a2SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*043036a2SApple OSS Distributions  *
15*043036a2SApple OSS Distributions  * Please obtain a copy of the License at
16*043036a2SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*043036a2SApple OSS Distributions  *
18*043036a2SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*043036a2SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*043036a2SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*043036a2SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*043036a2SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*043036a2SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*043036a2SApple OSS Distributions  * limitations under the License.
25*043036a2SApple OSS Distributions  *
26*043036a2SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*043036a2SApple OSS Distributions  */
28*043036a2SApple OSS Distributions 
29*043036a2SApple OSS Distributions #ifndef __NET_API_STATS__
30*043036a2SApple OSS Distributions #define __NET_API_STATS__
31*043036a2SApple OSS Distributions 
32*043036a2SApple OSS Distributions #ifdef PRIVATE
33*043036a2SApple OSS Distributions #include <stdint.h>
34*043036a2SApple OSS Distributions 
35*043036a2SApple OSS Distributions #define NAS_HAS_FLTR_OS_COUNTS 1
36*043036a2SApple OSS Distributions 
37*043036a2SApple OSS Distributions /*
38*043036a2SApple OSS Distributions  * net_api_stats counts the usage of the networking APIs
39*043036a2SApple OSS Distributions  *
40*043036a2SApple OSS Distributions  * Note: we are using signed 64 bit values to detect and prevent wrap around
41*043036a2SApple OSS Distributions  */
42*043036a2SApple OSS Distributions struct net_api_stats {
43*043036a2SApple OSS Distributions 	/*
44*043036a2SApple OSS Distributions 	 * Interface Filters
45*043036a2SApple OSS Distributions 	 */
46*043036a2SApple OSS Distributions 	int64_t nas_iflt_attach_count;  // Currently attached
47*043036a2SApple OSS Distributions 	int64_t nas_iflt_attach_os_count;
48*043036a2SApple OSS Distributions 	int64_t nas_iflt_attach_total;  // Total number of attachments
49*043036a2SApple OSS Distributions 	int64_t nas_iflt_attach_os_total;
50*043036a2SApple OSS Distributions 
51*043036a2SApple OSS Distributions 	/*
52*043036a2SApple OSS Distributions 	 * IP Filters
53*043036a2SApple OSS Distributions 	 */
54*043036a2SApple OSS Distributions 	int64_t nas_ipf_add_count;      // Currently attached
55*043036a2SApple OSS Distributions 	int64_t nas_ipf_add_os_count;
56*043036a2SApple OSS Distributions 	int64_t nas_ipf_add_total;      // Total number of attachments
57*043036a2SApple OSS Distributions 	int64_t nas_ipf_add_os_total;
58*043036a2SApple OSS Distributions 
59*043036a2SApple OSS Distributions 	/*
60*043036a2SApple OSS Distributions 	 * Socket Filters
61*043036a2SApple OSS Distributions 	 */
62*043036a2SApple OSS Distributions 	int64_t nas_sfltr_register_count;       // Currently attached
63*043036a2SApple OSS Distributions 	int64_t nas_sfltr_register_os_count;
64*043036a2SApple OSS Distributions 	int64_t nas_sfltr_register_total;       // Total number of attachments
65*043036a2SApple OSS Distributions 	int64_t nas_sfltr_register_os_total;
66*043036a2SApple OSS Distributions 
67*043036a2SApple OSS Distributions 	/*
68*043036a2SApple OSS Distributions 	 * Sockets
69*043036a2SApple OSS Distributions 	 */
70*043036a2SApple OSS Distributions 	int64_t nas_socket_alloc_total;
71*043036a2SApple OSS Distributions 	int64_t nas_socket_in_kernel_total;
72*043036a2SApple OSS Distributions 	int64_t nas_socket_in_kernel_os_total;
73*043036a2SApple OSS Distributions 	int64_t nas_socket_necp_clientuuid_total;
74*043036a2SApple OSS Distributions 
75*043036a2SApple OSS Distributions 	/*
76*043036a2SApple OSS Distributions 	 * Sockets per protocol domains
77*043036a2SApple OSS Distributions 	 */
78*043036a2SApple OSS Distributions 	int64_t nas_socket_domain_local_total;
79*043036a2SApple OSS Distributions 	int64_t nas_socket_domain_route_total;
80*043036a2SApple OSS Distributions 	int64_t nas_socket_domain_inet_total;
81*043036a2SApple OSS Distributions 	int64_t nas_socket_domain_inet6_total;
82*043036a2SApple OSS Distributions 	int64_t nas_socket_domain_system_total;
83*043036a2SApple OSS Distributions 	int64_t nas_socket_domain_multipath_total;
84*043036a2SApple OSS Distributions 	int64_t nas_socket_domain_key_total;
85*043036a2SApple OSS Distributions 	int64_t nas_socket_domain_ndrv_total;
86*043036a2SApple OSS Distributions 	int64_t nas_socket_domain_other_total;
87*043036a2SApple OSS Distributions 
88*043036a2SApple OSS Distributions 	/*
89*043036a2SApple OSS Distributions 	 * Sockets per domain and type
90*043036a2SApple OSS Distributions 	 */
91*043036a2SApple OSS Distributions 	int64_t nas_socket_inet_stream_total;
92*043036a2SApple OSS Distributions 	int64_t nas_socket_inet_dgram_total;
93*043036a2SApple OSS Distributions 	int64_t nas_socket_inet_dgram_connected;
94*043036a2SApple OSS Distributions 	int64_t nas_socket_inet_dgram_dns;      // port 53
95*043036a2SApple OSS Distributions 	int64_t nas_socket_inet_dgram_no_data;  // typically for interface ioctl
96*043036a2SApple OSS Distributions 
97*043036a2SApple OSS Distributions 	int64_t nas_socket_inet6_stream_total;
98*043036a2SApple OSS Distributions 	int64_t nas_socket_inet6_dgram_total;
99*043036a2SApple OSS Distributions 	int64_t nas_socket_inet6_dgram_connected;
100*043036a2SApple OSS Distributions 	int64_t nas_socket_inet6_dgram_dns;     // port 53
101*043036a2SApple OSS Distributions 	int64_t nas_socket_inet6_dgram_no_data; // typically for interface ioctl
102*043036a2SApple OSS Distributions 
103*043036a2SApple OSS Distributions 	/*
104*043036a2SApple OSS Distributions 	 * Multicast join
105*043036a2SApple OSS Distributions 	 */
106*043036a2SApple OSS Distributions 	int64_t nas_socket_mcast_join_total;
107*043036a2SApple OSS Distributions 	int64_t nas_socket_mcast_join_os_total;
108*043036a2SApple OSS Distributions 
109*043036a2SApple OSS Distributions 	/*
110*043036a2SApple OSS Distributions 	 * IPv6 Extension Header Socket API
111*043036a2SApple OSS Distributions 	 */
112*043036a2SApple OSS Distributions 	int64_t nas_sock_inet6_stream_exthdr_in;
113*043036a2SApple OSS Distributions 	int64_t nas_sock_inet6_stream_exthdr_out;
114*043036a2SApple OSS Distributions 	int64_t nas_sock_inet6_dgram_exthdr_in;
115*043036a2SApple OSS Distributions 	int64_t nas_sock_inet6_dgram_exthdr_out;
116*043036a2SApple OSS Distributions 
117*043036a2SApple OSS Distributions 	/*
118*043036a2SApple OSS Distributions 	 * Nexus flows
119*043036a2SApple OSS Distributions 	 */
120*043036a2SApple OSS Distributions 	int64_t nas_nx_flow_inet_stream_total;
121*043036a2SApple OSS Distributions 	int64_t nas_nx_flow_inet_dgram_total;
122*043036a2SApple OSS Distributions 
123*043036a2SApple OSS Distributions 	int64_t nas_nx_flow_inet6_stream_total;
124*043036a2SApple OSS Distributions 	int64_t nas_nx_flow_inet6_dgram_total;
125*043036a2SApple OSS Distributions 
126*043036a2SApple OSS Distributions 	/*
127*043036a2SApple OSS Distributions 	 * Interfaces
128*043036a2SApple OSS Distributions 	 */
129*043036a2SApple OSS Distributions 	int64_t nas_ifnet_alloc_count;
130*043036a2SApple OSS Distributions 	int64_t nas_ifnet_alloc_total;
131*043036a2SApple OSS Distributions 	int64_t nas_ifnet_alloc_os_count;
132*043036a2SApple OSS Distributions 	int64_t nas_ifnet_alloc_os_total;
133*043036a2SApple OSS Distributions 
134*043036a2SApple OSS Distributions 	/*
135*043036a2SApple OSS Distributions 	 * PF
136*043036a2SApple OSS Distributions 	 */
137*043036a2SApple OSS Distributions 	int64_t nas_pf_addrule_total;
138*043036a2SApple OSS Distributions 	int64_t nas_pf_addrule_os;
139*043036a2SApple OSS Distributions 
140*043036a2SApple OSS Distributions 	/*
141*043036a2SApple OSS Distributions 	 * vmnet API
142*043036a2SApple OSS Distributions 	 */
143*043036a2SApple OSS Distributions 	int64_t nas_vmnet_total;
144*043036a2SApple OSS Distributions };
145*043036a2SApple OSS Distributions 
146*043036a2SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
147*043036a2SApple OSS Distributions extern struct net_api_stats net_api_stats;
148*043036a2SApple OSS Distributions 
149*043036a2SApple OSS Distributions /*
150*043036a2SApple OSS Distributions  * Increment up to the max value of int64_t
151*043036a2SApple OSS Distributions  */
152*043036a2SApple OSS Distributions #define INC_ATOMIC_INT64_LIM(counter) {                                 \
153*043036a2SApple OSS Distributions 	int64_t val;                                                    \
154*043036a2SApple OSS Distributions 	do {                                                            \
155*043036a2SApple OSS Distributions 	        val = counter;                                          \
156*043036a2SApple OSS Distributions 	        if (val >= INT64_MAX) {                                 \
157*043036a2SApple OSS Distributions 	                break;                                          \
158*043036a2SApple OSS Distributions 	        }                                                       \
159*043036a2SApple OSS Distributions 	} while (!OSCompareAndSwap64(val, val + 1, &(counter)));        \
160*043036a2SApple OSS Distributions }
161*043036a2SApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */
162*043036a2SApple OSS Distributions 
163*043036a2SApple OSS Distributions #endif /* PRIVATE */
164*043036a2SApple OSS Distributions 
165*043036a2SApple OSS Distributions #endif /* __NET_API_STATS__ */
166