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