]> git.saurik.com Git - apple/xnu.git/blame - bsd/net/ntstat.h
xnu-1699.26.8.tar.gz
[apple/xnu.git] / bsd / net / ntstat.h
CommitLineData
6d2010ae
A
1/*
2 * Copyright (c) 2010-2011 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#ifndef __NTSTAT_H__
29#define __NTSTAT_H__
30#include <netinet/in.h>
31
32#ifdef PRIVATE
33#pragma pack(push, 4)
34#pragma mark -- Common Data Structures --
35
36#define __NSTAT_REVISION__ 1
37
38typedef u_int32_t nstat_provider_id_t;
39typedef u_int32_t nstat_src_ref_t;
40
41typedef struct nstat_counts
42{
43 /* Counters */
44 u_int64_t nstat_rxpackets __attribute__((aligned(8)));
45 u_int64_t nstat_rxbytes __attribute__((aligned(8)));
46 u_int64_t nstat_txpackets __attribute__((aligned(8)));
47 u_int64_t nstat_txbytes __attribute__((aligned(8)));
48
49 u_int32_t nstat_rxduplicatebytes;
50 u_int32_t nstat_rxoutoforderbytes;
51 u_int32_t nstat_txretransmit;
52
53 u_int32_t nstat_connectattempts;
54 u_int32_t nstat_connectsuccesses;
55
56 u_int32_t nstat_min_rtt;
57 u_int32_t nstat_avg_rtt;
58 u_int32_t nstat_var_rtt;
59} nstat_counts;
60
61#pragma mark -- Network Statistics Providers --
62
63enum
64{
65 NSTAT_PROVIDER_ROUTE = 1
66 ,NSTAT_PROVIDER_TCP = 2
67 ,NSTAT_PROVIDER_UDP = 3
68};
69
70typedef struct nstat_route_add_param
71{
72 union
73 {
74 struct sockaddr_in v4;
75 struct sockaddr_in6 v6;
76 } dst;
77 union
78 {
79 struct sockaddr_in v4;
80 struct sockaddr_in6 v6;
81 } mask;
82 u_int32_t ifindex;
83} nstat_route_add_param;
84
85typedef struct nstat_tcp_add_param
86{
87 union
88 {
89 struct sockaddr_in v4;
90 struct sockaddr_in6 v6;
91 } local;
92 union
93 {
94 struct sockaddr_in v4;
95 struct sockaddr_in6 v6;
96 } remote;
97} nstat_tcp_add_param;
98
99typedef struct nstat_tcp_descriptor
100{
101 union
102 {
103 struct sockaddr_in v4;
104 struct sockaddr_in6 v6;
105 } local;
106
107 union
108 {
109 struct sockaddr_in v4;
110 struct sockaddr_in6 v6;
111 } remote;
112
113 u_int32_t ifindex;
114
115 u_int32_t state;
116
117 u_int32_t sndbufsize;
118 u_int32_t sndbufused;
119 u_int32_t rcvbufsize;
120 u_int32_t rcvbufused;
121 u_int32_t txunacked;
122 u_int32_t txwindow;
123 u_int32_t txcwindow;
124
125 u_int64_t upid;
126 u_int32_t pid;
127 char pname[64];
128} nstat_tcp_descriptor;
129
130typedef struct nstat_tcp_add_param nstat_udp_add_param;
131
132typedef struct nstat_udp_descriptor
133{
134 union
135 {
136 struct sockaddr_in v4;
137 struct sockaddr_in6 v6;
138 } local;
139
140 union
141 {
142 struct sockaddr_in v4;
143 struct sockaddr_in6 v6;
144 } remote;
145
146 u_int32_t ifindex;
147
148 u_int32_t rcvbufsize;
149 u_int32_t rcvbufused;
150
151 u_int64_t upid;
152 u_int32_t pid;
153 char pname[64];
154} nstat_udp_descriptor;
155
156typedef struct nstat_route_descriptor
157{
158 u_int64_t id;
159 u_int64_t parent_id;
160 u_int64_t gateway_id;
161
162 union
163 {
164 struct sockaddr_in v4;
165 struct sockaddr_in6 v6;
166 struct sockaddr sa;
167 } dst;
168
169 union
170 {
171 struct sockaddr_in v4;
172 struct sockaddr_in6 v6;
173 struct sockaddr sa;
174 } mask;
175
176 union
177 {
178 struct sockaddr_in v4;
179 struct sockaddr_in6 v6;
180 struct sockaddr sa;
181 } gateway;
182
183 u_int32_t ifindex;
184 u_int32_t flags;
185
186} nstat_route_descriptor;
187
188#pragma mark -- Network Statistics User Client --
189
190#define NET_STAT_CONTROL_NAME "com.apple.network.statistics"
191
192enum
193{
194 // generice respnse messages
195 NSTAT_MSG_TYPE_SUCCESS = 0
196 ,NSTAT_MSG_TYPE_ERROR = 1
197
198 // Requests
199 ,NSTAT_MSG_TYPE_ADD_SRC = 1001
200 ,NSTAT_MSG_TYPE_ADD_ALL_SRCS = 1002
201 ,NSTAT_MSG_TYPE_REM_SRC = 1003
202 ,NSTAT_MSG_TYPE_QUERY_SRC = 1004
203 ,NSTAT_MSG_TYPE_GET_SRC_DESC = 1005
204
205 // Responses/Notfications
206 ,NSTAT_MSG_TYPE_SRC_ADDED = 10001
207 ,NSTAT_MSG_TYPE_SRC_REMOVED = 10002
208 ,NSTAT_MSG_TYPE_SRC_DESC = 10003
209 ,NSTAT_MSG_TYPE_SRC_COUNTS = 10004
210};
211
212enum
213{
214 NSTAT_SRC_REF_ALL = 0xffffffff
215 ,NSTAT_SRC_REF_INVALID = 0
216};
217
218typedef struct nstat_msg_hdr
219{
220 u_int64_t context;
221 u_int32_t type;
222 u_int32_t pad; // unused for now
223} nstat_msg_hdr;
224
225typedef struct nstat_msg_error
226{
227 nstat_msg_hdr hdr;
228 u_int32_t error; // errno error
229} nstat_msg_error;
230
231typedef struct nstat_msg_add_src
232{
233 nstat_msg_hdr hdr;
234 nstat_provider_id_t provider;
235 u_int8_t param[];
236} nstat_msg_add_src_req;
237
238typedef struct nstat_msg_add_all_srcs
239{
240 nstat_msg_hdr hdr;
241 nstat_provider_id_t provider;
242} nstat_msg_add_all_srcs;
243
244typedef struct nstat_msg_src_added
245{
246 nstat_msg_hdr hdr;
247 nstat_provider_id_t provider;
248 nstat_src_ref_t srcref;
249} nstat_msg_src_added;
250
251typedef struct nstat_msg_rem_src
252{
253 nstat_msg_hdr hdr;
254 nstat_src_ref_t srcref;
255} nstat_msg_rem_src_req;
256
257typedef struct nstat_msg_get_src_description
258{
259 nstat_msg_hdr hdr;
260 nstat_src_ref_t srcref;
261} nstat_msg_get_src_description;
262
263typedef struct nstat_msg_src_description
264{
265 nstat_msg_hdr hdr;
266 nstat_src_ref_t srcref;
267 nstat_provider_id_t provider;
268 u_int8_t data[];
269} nstat_msg_src_description;
270
271typedef struct nstat_msg_query_src
272{
273 nstat_msg_hdr hdr;
274 nstat_src_ref_t srcref;
275} nstat_msg_query_src_req;
276
277typedef struct nstat_msg_src_counts
278{
279 nstat_msg_hdr hdr;
280 nstat_src_ref_t srcref;
281 nstat_counts counts;
282} nstat_msg_src_counts;
283
284typedef struct nstat_msg_src_removed
285{
286 nstat_msg_hdr hdr;
287 nstat_src_ref_t srcref;
288} nstat_msg_src_removed;
289
290#pragma pack(pop)
291
292#endif /* PRIVATE */
293
294#ifdef XNU_KERNEL_PRIVATE
295#include <sys/mcache.h>
296
297#pragma mark -- Generic Network Statistics Provider --
298
299typedef void * nstat_provider_cookie_t;
300
301#pragma mark -- Route Statistics Gathering Functions --
302struct rtentry;
303
304enum
305{
306 NSTAT_TX_FLAG_RETRANSMIT = 1
307};
308
309enum
310{
311 NSTAT_RX_FLAG_DUPLICATE = 1,
312 NSTAT_RX_FLAG_OUT_OF_ORDER = 2
313};
314
315// indicates whether or not collection of statistics is enabled
316extern int nstat_collect;
317
318// Route collection routines
319void nstat_route_connect_attempt(struct rtentry *rte);
320void nstat_route_connect_success(struct rtentry *rte);
321void nstat_route_tx(struct rtentry *rte, u_int32_t packets, u_int32_t bytes, u_int32_t flags);
322void nstat_route_rx(struct rtentry *rte, u_int32_t packets, u_int32_t bytes, u_int32_t flags);
323void nstat_route_rtt(struct rtentry *rte, u_int32_t rtt, u_int32_t rtt_var);
324void nstat_route_detach(struct rtentry *rte);
325
326// watcher support
327struct inpcb;
328void nstat_tcp_new_pcb(struct inpcb *inp);
329void nstat_udp_new_pcb(struct inpcb *inp);
330void nstat_route_new_entry(struct rtentry *rt);
331
332// locked_add_64 uses atomic operations on 32bit so the 64bit
333// value can be properly read. The values are only ever incremented
334// while under the socket lock, so on 64bit we don't actually need
335// atomic operations to increment.
336#if defined(__LP64__)
337#define locked_add_64(__addr, __count) do { \
338 *(__addr) += (__count); \
339} while (0)
340#else
341#define locked_add_64(__addr, __count) do { \
342 atomic_add_64((__addr), (__count)); \
343} while (0)
344#endif
345
346#endif /* XNU_KERNEL_PRIVATE */
347
348#endif /* __NTSTAT_H__ */