Print this page
XXXX adding PID information to netstat output
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/inet/udp/udp_stats.c
+++ new/usr/src/uts/common/inet/udp/udp_stats.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24 24 */
25 25
26 26 #include <sys/types.h>
27 27 #include <sys/tihdr.h>
28 28 #include <sys/policy.h>
29 29 #include <sys/tsol/tnet.h>
30 30
31 31 #include <inet/common.h>
32 32 #include <inet/kstatcom.h>
33 33 #include <inet/snmpcom.h>
34 34 #include <inet/mib2.h>
35 35 #include <inet/optcom.h>
36 36 #include <inet/snmpcom.h>
37 37 #include <inet/kstatcom.h>
38 38 #include <inet/udp_impl.h>
39 39
40 40 static int udp_kstat_update(kstat_t *, int);
41 41 static int udp_kstat2_update(kstat_t *, int);
42 42 static void udp_sum_mib(udp_stack_t *, mib2_udp_t *);
43 43 static void udp_clr_stats(udp_stat_t *);
44 44 static void udp_add_stats(udp_stat_counter_t *, udp_stat_t *);
45 45 static void udp_add_mib(mib2_udp_t *, mib2_udp_t *);
↓ open down ↓ |
45 lines elided |
↑ open up ↑ |
46 46 /*
47 47 * return SNMP stuff in buffer in mpdata. We don't hold any lock and report
48 48 * information that can be changing beneath us.
49 49 */
50 50 mblk_t *
51 51 udp_snmp_get(queue_t *q, mblk_t *mpctl, boolean_t legacy_req)
52 52 {
53 53 mblk_t *mpdata;
54 54 mblk_t *mp_conn_ctl;
55 55 mblk_t *mp_attr_ctl;
56 + mblk_t *mp_pidnode_ctl;
56 57 mblk_t *mp6_conn_ctl;
57 58 mblk_t *mp6_attr_ctl;
59 + mblk_t *mp6_pidnode_ctl;
58 60 mblk_t *mp_conn_tail;
59 61 mblk_t *mp_attr_tail;
62 + mblk_t *mp_pidnode_tail;
60 63 mblk_t *mp6_conn_tail;
61 64 mblk_t *mp6_attr_tail;
65 + mblk_t *mp6_pidnode_tail;
62 66 struct opthdr *optp;
63 67 mib2_udpEntry_t ude;
64 68 mib2_udp6Entry_t ude6;
65 69 mib2_transportMLPEntry_t mlp;
66 70 int state;
67 71 zoneid_t zoneid;
68 72 int i;
69 73 connf_t *connfp;
70 74 conn_t *connp = Q_TO_CONN(q);
71 75 int v4_conn_idx;
72 76 int v6_conn_idx;
73 77 boolean_t needattr;
74 78 udp_t *udp;
75 79 ip_stack_t *ipst = connp->conn_netstack->netstack_ip;
76 80 udp_stack_t *us = connp->conn_netstack->netstack_udp;
77 81 mblk_t *mp2ctl;
78 82 mib2_udp_t udp_mib;
79 83 size_t udp_mib_size, ude_size, ude6_size;
80 84
81 -
82 85 /*
83 86 * make a copy of the original message
84 87 */
85 88 mp2ctl = copymsg(mpctl);
86 89
87 90 mp_conn_ctl = mp_attr_ctl = mp6_conn_ctl = NULL;
88 91 if (mpctl == NULL ||
89 92 (mpdata = mpctl->b_cont) == NULL ||
90 93 (mp_conn_ctl = copymsg(mpctl)) == NULL ||
91 94 (mp_attr_ctl = copymsg(mpctl)) == NULL ||
95 + (mp_pidnode_ctl = copymsg(mpctl)) == NULL ||
92 96 (mp6_conn_ctl = copymsg(mpctl)) == NULL ||
93 - (mp6_attr_ctl = copymsg(mpctl)) == NULL) {
97 + (mp6_attr_ctl = copymsg(mpctl)) == NULL ||
98 + (mp6_pidnode_ctl = copymsg(mpctl)) == NULL) {
94 99 freemsg(mp_conn_ctl);
95 100 freemsg(mp_attr_ctl);
101 + freemsg(mp_pidnode_ctl);
96 102 freemsg(mp6_conn_ctl);
103 + freemsg(mp6_attr_ctl);
104 + freemsg(mp6_pidnode_ctl);
97 105 freemsg(mpctl);
98 106 freemsg(mp2ctl);
99 107 return (0);
100 108 }
101 109
102 110 zoneid = connp->conn_zoneid;
103 111
104 112 if (legacy_req) {
105 113 udp_mib_size = LEGACY_MIB_SIZE(&udp_mib, mib2_udp_t);
106 114 ude_size = LEGACY_MIB_SIZE(&ude, mib2_udpEntry_t);
107 115 ude6_size = LEGACY_MIB_SIZE(&ude6, mib2_udp6Entry_t);
108 116 } else {
109 117 udp_mib_size = sizeof (mib2_udp_t);
110 118 ude_size = sizeof (mib2_udpEntry_t);
111 119 ude6_size = sizeof (mib2_udp6Entry_t);
112 120 }
113 121
114 122 bzero(&udp_mib, sizeof (udp_mib));
115 123 /* fixed length structure for IPv4 and IPv6 counters */
116 124 SET_MIB(udp_mib.udpEntrySize, ude_size);
117 125 SET_MIB(udp_mib.udp6EntrySize, ude6_size);
118 126
119 127 udp_sum_mib(us, &udp_mib);
120 128
121 129 /*
122 130 * Synchronize 32- and 64-bit counters. Note that udpInDatagrams and
123 131 * udpOutDatagrams are not updated anywhere in UDP. The new 64 bits
124 132 * counters are used. Hence the old counters' values in us_sc_mib
125 133 * are always 0.
126 134 */
127 135 SYNC32_MIB(&udp_mib, udpInDatagrams, udpHCInDatagrams);
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
128 136 SYNC32_MIB(&udp_mib, udpOutDatagrams, udpHCOutDatagrams);
129 137
130 138 optp = (struct opthdr *)&mpctl->b_rptr[sizeof (struct T_optmgmt_ack)];
131 139 optp->level = MIB2_UDP;
132 140 optp->name = 0;
133 141 (void) snmp_append_data(mpdata, (char *)&udp_mib, udp_mib_size);
134 142 optp->len = msgdsize(mpdata);
135 143 qreply(q, mpctl);
136 144
137 145 mp_conn_tail = mp_attr_tail = mp6_conn_tail = mp6_attr_tail = NULL;
146 + mp_pidnode_tail = mp6_pidnode_tail = NULL;
138 147 v4_conn_idx = v6_conn_idx = 0;
139 148
140 149 for (i = 0; i < CONN_G_HASH_SIZE; i++) {
141 150 connfp = &ipst->ips_ipcl_globalhash_fanout[i];
142 151 connp = NULL;
143 152
144 153 while ((connp = ipcl_get_next_conn(connfp, connp,
145 154 IPCL_UDPCONN))) {
146 155 udp = connp->conn_udp;
147 156 if (zoneid != connp->conn_zoneid)
148 157 continue;
149 158
150 159 /*
151 160 * Note that the port numbers are sent in
152 161 * host byte order
153 162 */
154 163
155 164 if (udp->udp_state == TS_UNBND)
156 165 state = MIB2_UDP_unbound;
157 166 else if (udp->udp_state == TS_IDLE)
158 167 state = MIB2_UDP_idle;
159 168 else if (udp->udp_state == TS_DATA_XFER)
160 169 state = MIB2_UDP_connected;
161 170 else
162 171 state = MIB2_UDP_unknown;
163 172
164 173 needattr = B_FALSE;
165 174 bzero(&mlp, sizeof (mlp));
166 175 if (connp->conn_mlp_type != mlptSingle) {
167 176 if (connp->conn_mlp_type == mlptShared ||
168 177 connp->conn_mlp_type == mlptBoth)
169 178 mlp.tme_flags |= MIB2_TMEF_SHARED;
170 179 if (connp->conn_mlp_type == mlptPrivate ||
171 180 connp->conn_mlp_type == mlptBoth)
172 181 mlp.tme_flags |= MIB2_TMEF_PRIVATE;
173 182 needattr = B_TRUE;
174 183 }
175 184 if (connp->conn_anon_mlp) {
176 185 mlp.tme_flags |= MIB2_TMEF_ANONMLP;
177 186 needattr = B_TRUE;
178 187 }
179 188 switch (connp->conn_mac_mode) {
180 189 case CONN_MAC_DEFAULT:
181 190 break;
182 191 case CONN_MAC_AWARE:
183 192 mlp.tme_flags |= MIB2_TMEF_MACEXEMPT;
184 193 needattr = B_TRUE;
185 194 break;
186 195 case CONN_MAC_IMPLICIT:
187 196 mlp.tme_flags |= MIB2_TMEF_MACIMPLICIT;
188 197 needattr = B_TRUE;
189 198 break;
190 199 }
191 200 mutex_enter(&connp->conn_lock);
192 201 if (udp->udp_state == TS_DATA_XFER &&
193 202 connp->conn_ixa->ixa_tsl != NULL) {
194 203 ts_label_t *tsl;
195 204
196 205 tsl = connp->conn_ixa->ixa_tsl;
197 206 mlp.tme_flags |= MIB2_TMEF_IS_LABELED;
198 207 mlp.tme_doi = label2doi(tsl);
199 208 mlp.tme_label = *label2bslabel(tsl);
200 209 needattr = B_TRUE;
201 210 }
202 211 mutex_exit(&connp->conn_lock);
203 212
204 213 /*
205 214 * Create an IPv4 table entry for IPv4 entries and also
206 215 * any IPv6 entries which are bound to in6addr_any
207 216 * (i.e. anything a IPv4 peer could connect/send to).
208 217 */
209 218 if (connp->conn_ipversion == IPV4_VERSION ||
210 219 (udp->udp_state <= TS_IDLE &&
211 220 IN6_IS_ADDR_UNSPECIFIED(&connp->conn_laddr_v6))) {
212 221 ude.udpEntryInfo.ue_state = state;
213 222 /*
214 223 * If in6addr_any this will set it to
215 224 * INADDR_ANY
216 225 */
217 226 ude.udpLocalAddress = connp->conn_laddr_v4;
218 227 ude.udpLocalPort = ntohs(connp->conn_lport);
219 228 if (udp->udp_state == TS_DATA_XFER) {
220 229 /*
221 230 * Can potentially get here for
222 231 * v6 socket if another process
223 232 * (say, ping) has just done a
224 233 * sendto(), changing the state
225 234 * from the TS_IDLE above to
226 235 * TS_DATA_XFER by the time we hit
227 236 * this part of the code.
228 237 */
229 238 ude.udpEntryInfo.ue_RemoteAddress =
230 239 connp->conn_faddr_v4;
231 240 ude.udpEntryInfo.ue_RemotePort =
232 241 ntohs(connp->conn_fport);
233 242 } else {
234 243 ude.udpEntryInfo.ue_RemoteAddress = 0;
235 244 ude.udpEntryInfo.ue_RemotePort = 0;
236 245 }
237 246
238 247 /*
239 248 * We make the assumption that all udp_t
240 249 * structs will be created within an address
241 250 * region no larger than 32-bits.
↓ open down ↓ |
94 lines elided |
↑ open up ↑ |
242 251 */
243 252 ude.udpInstance = (uint32_t)(uintptr_t)udp;
244 253 ude.udpCreationProcess =
245 254 (connp->conn_cpid < 0) ?
246 255 MIB2_UNKNOWN_PROCESS :
247 256 connp->conn_cpid;
248 257 ude.udpCreationTime = connp->conn_open_time;
249 258
250 259 (void) snmp_append_data2(mp_conn_ctl->b_cont,
251 260 &mp_conn_tail, (char *)&ude, ude_size);
261 +
262 + (void) snmp_append_data2(mp_pidnode_ctl->b_cont,
263 + &mp_pidnode_tail, (char *)&ude, ude_size);
264 +
265 + (void) snmp_append_mblk2(mp_pidnode_ctl->b_cont,
266 + &mp_pidnode_tail, conn_get_pid_mblk(connp));
267 +
252 268 mlp.tme_connidx = v4_conn_idx++;
253 269 if (needattr)
254 270 (void) snmp_append_data2(
255 271 mp_attr_ctl->b_cont, &mp_attr_tail,
256 272 (char *)&mlp, sizeof (mlp));
257 273 }
258 274 if (connp->conn_ipversion == IPV6_VERSION) {
259 275 ude6.udp6EntryInfo.ue_state = state;
260 276 ude6.udp6LocalAddress = connp->conn_laddr_v6;
261 277 ude6.udp6LocalPort = ntohs(connp->conn_lport);
262 278 mutex_enter(&connp->conn_lock);
263 279 if (connp->conn_ixa->ixa_flags &
264 280 IXAF_SCOPEID_SET) {
265 281 ude6.udp6IfIndex =
266 282 connp->conn_ixa->ixa_scopeid;
267 283 } else {
268 284 ude6.udp6IfIndex = connp->conn_bound_if;
269 285 }
270 286 mutex_exit(&connp->conn_lock);
271 287 if (udp->udp_state == TS_DATA_XFER) {
272 288 ude6.udp6EntryInfo.ue_RemoteAddress =
273 289 connp->conn_faddr_v6;
274 290 ude6.udp6EntryInfo.ue_RemotePort =
275 291 ntohs(connp->conn_fport);
276 292 } else {
277 293 ude6.udp6EntryInfo.ue_RemoteAddress =
278 294 sin6_null.sin6_addr;
279 295 ude6.udp6EntryInfo.ue_RemotePort = 0;
280 296 }
281 297 /*
282 298 * We make the assumption that all udp_t
283 299 * structs will be created within an address
284 300 * region no larger than 32-bits.
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
285 301 */
286 302 ude6.udp6Instance = (uint32_t)(uintptr_t)udp;
287 303 ude6.udp6CreationProcess =
288 304 (connp->conn_cpid < 0) ?
289 305 MIB2_UNKNOWN_PROCESS :
290 306 connp->conn_cpid;
291 307 ude6.udp6CreationTime = connp->conn_open_time;
292 308
293 309 (void) snmp_append_data2(mp6_conn_ctl->b_cont,
294 310 &mp6_conn_tail, (char *)&ude6, ude6_size);
311 +
312 + (void) snmp_append_data2(
313 + mp6_pidnode_ctl->b_cont, &mp6_pidnode_tail,
314 + (char *)&ude6, ude6_size);
315 +
316 + (void) snmp_append_mblk2(
317 + mp6_pidnode_ctl->b_cont, &mp6_pidnode_tail,
318 + conn_get_pid_mblk(connp));
319 +
295 320 mlp.tme_connidx = v6_conn_idx++;
296 321 if (needattr)
297 322 (void) snmp_append_data2(
298 323 mp6_attr_ctl->b_cont,
299 324 &mp6_attr_tail, (char *)&mlp,
300 325 sizeof (mlp));
301 326 }
302 327 }
303 328 }
304 329
305 330 /* IPv4 UDP endpoints */
306 331 optp = (struct opthdr *)&mp_conn_ctl->b_rptr[
307 332 sizeof (struct T_optmgmt_ack)];
308 333 optp->level = MIB2_UDP;
309 334 optp->name = MIB2_UDP_ENTRY;
310 335 optp->len = msgdsize(mp_conn_ctl->b_cont);
311 336 qreply(q, mp_conn_ctl);
312 337
313 338 /* table of MLP attributes... */
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
314 339 optp = (struct opthdr *)&mp_attr_ctl->b_rptr[
315 340 sizeof (struct T_optmgmt_ack)];
316 341 optp->level = MIB2_UDP;
317 342 optp->name = EXPER_XPORT_MLP;
318 343 optp->len = msgdsize(mp_attr_ctl->b_cont);
319 344 if (optp->len == 0)
320 345 freemsg(mp_attr_ctl);
321 346 else
322 347 qreply(q, mp_attr_ctl);
323 348
349 + /* table of EXPER_XPORT_PROC_INFO ipv4 */
350 + optp = (struct opthdr *)&mp_pidnode_ctl->b_rptr[
351 + sizeof (struct T_optmgmt_ack)];
352 + optp->level = MIB2_UDP;
353 + optp->name = EXPER_XPORT_PROC_INFO;
354 + optp->len = msgdsize(mp_pidnode_ctl->b_cont);
355 + if (optp->len == 0)
356 + freemsg(mp_pidnode_ctl);
357 + else
358 + qreply(q, mp_pidnode_ctl);
359 +
324 360 /* IPv6 UDP endpoints */
325 361 optp = (struct opthdr *)&mp6_conn_ctl->b_rptr[
326 362 sizeof (struct T_optmgmt_ack)];
327 363 optp->level = MIB2_UDP6;
328 364 optp->name = MIB2_UDP6_ENTRY;
329 365 optp->len = msgdsize(mp6_conn_ctl->b_cont);
330 366 qreply(q, mp6_conn_ctl);
331 367
332 368 /* table of MLP attributes... */
333 369 optp = (struct opthdr *)&mp6_attr_ctl->b_rptr[
334 370 sizeof (struct T_optmgmt_ack)];
335 371 optp->level = MIB2_UDP6;
336 372 optp->name = EXPER_XPORT_MLP;
337 373 optp->len = msgdsize(mp6_attr_ctl->b_cont);
338 374 if (optp->len == 0)
339 375 freemsg(mp6_attr_ctl);
340 376 else
341 377 qreply(q, mp6_attr_ctl);
378 +
379 + /* table of EXPER_XPORT_PROC_INFO ipv6 */
380 + optp = (struct opthdr *)&mp6_pidnode_ctl->b_rptr[
381 + sizeof (struct T_optmgmt_ack)];
382 + optp->level = MIB2_UDP6;
383 + optp->name = EXPER_XPORT_PROC_INFO;
384 + optp->len = msgdsize(mp6_pidnode_ctl->b_cont);
385 + if (optp->len == 0)
386 + freemsg(mp6_pidnode_ctl);
387 + else
388 + qreply(q, mp6_pidnode_ctl);
342 389
343 390 return (mp2ctl);
344 391 }
345 392
346 393 /*
347 394 * Return 0 if invalid set request, 1 otherwise, including non-udp requests.
348 395 * NOTE: Per MIB-II, UDP has no writable data.
349 396 * TODO: If this ever actually tries to set anything, it needs to be
350 397 * to do the appropriate locking.
351 398 */
352 399 /* ARGSUSED */
353 400 int
354 401 udp_snmp_set(queue_t *q, t_scalar_t level, t_scalar_t name,
355 402 uchar_t *ptr, int len)
356 403 {
357 404 switch (level) {
358 405 case MIB2_UDP:
359 406 return (0);
360 407 default:
361 408 return (1);
362 409 }
363 410 }
364 411
365 412 void
366 413 udp_kstat_fini(netstackid_t stackid, kstat_t *ksp)
367 414 {
368 415 if (ksp != NULL) {
369 416 ASSERT(stackid == (netstackid_t)(uintptr_t)ksp->ks_private);
370 417 kstat_delete_netstack(ksp, stackid);
371 418 }
372 419 }
373 420
374 421 /*
375 422 * To add stats from one mib2_udp_t to another. Static fields are not added.
376 423 * The caller should set them up propertly.
377 424 */
378 425 static void
379 426 udp_add_mib(mib2_udp_t *from, mib2_udp_t *to)
380 427 {
381 428 to->udpHCInDatagrams += from->udpHCInDatagrams;
382 429 to->udpInErrors += from->udpInErrors;
383 430 to->udpHCOutDatagrams += from->udpHCOutDatagrams;
384 431 to->udpOutErrors += from->udpOutErrors;
385 432 }
386 433
387 434
388 435 void *
389 436 udp_kstat2_init(netstackid_t stackid)
390 437 {
391 438 kstat_t *ksp;
392 439
393 440 udp_stat_t template = {
394 441 { "udp_sock_fallback", KSTAT_DATA_UINT64 },
395 442 { "udp_out_opt", KSTAT_DATA_UINT64 },
396 443 { "udp_out_err_notconn", KSTAT_DATA_UINT64 },
397 444 { "udp_out_err_output", KSTAT_DATA_UINT64 },
398 445 { "udp_out_err_tudr", KSTAT_DATA_UINT64 },
399 446 #ifdef DEBUG
400 447 { "udp_data_conn", KSTAT_DATA_UINT64 },
401 448 { "udp_data_notconn", KSTAT_DATA_UINT64 },
402 449 { "udp_out_lastdst", KSTAT_DATA_UINT64 },
403 450 { "udp_out_diffdst", KSTAT_DATA_UINT64 },
404 451 { "udp_out_ipv6", KSTAT_DATA_UINT64 },
405 452 { "udp_out_mapped", KSTAT_DATA_UINT64 },
406 453 { "udp_out_ipv4", KSTAT_DATA_UINT64 },
407 454 #endif
408 455 };
409 456
410 457 ksp = kstat_create_netstack(UDP_MOD_NAME, 0, "udpstat", "net",
411 458 KSTAT_TYPE_NAMED, sizeof (template) / sizeof (kstat_named_t),
412 459 0, stackid);
413 460
414 461 if (ksp == NULL)
415 462 return (NULL);
416 463
417 464 bcopy(&template, ksp->ks_data, sizeof (template));
418 465 ksp->ks_update = udp_kstat2_update;
419 466 ksp->ks_private = (void *)(uintptr_t)stackid;
420 467
421 468 kstat_install(ksp);
422 469 return (ksp);
423 470 }
424 471
425 472 void
426 473 udp_kstat2_fini(netstackid_t stackid, kstat_t *ksp)
427 474 {
428 475 if (ksp != NULL) {
429 476 ASSERT(stackid == (netstackid_t)(uintptr_t)ksp->ks_private);
430 477 kstat_delete_netstack(ksp, stackid);
431 478 }
432 479 }
433 480
434 481 /*
435 482 * To copy counters from the per CPU udpp_stat_counter_t to the stack
436 483 * udp_stat_t.
437 484 */
438 485 static void
439 486 udp_add_stats(udp_stat_counter_t *from, udp_stat_t *to)
440 487 {
441 488 to->udp_sock_fallback.value.ui64 += from->udp_sock_fallback;
442 489 to->udp_out_opt.value.ui64 += from->udp_out_opt;
443 490 to->udp_out_err_notconn.value.ui64 += from->udp_out_err_notconn;
444 491 to->udp_out_err_output.value.ui64 += from->udp_out_err_output;
445 492 to->udp_out_err_tudr.value.ui64 += from->udp_out_err_tudr;
446 493 #ifdef DEBUG
447 494 to->udp_data_conn.value.ui64 += from->udp_data_conn;
448 495 to->udp_data_notconn.value.ui64 += from->udp_data_notconn;
449 496 to->udp_out_lastdst.value.ui64 += from->udp_out_lastdst;
450 497 to->udp_out_diffdst.value.ui64 += from->udp_out_diffdst;
451 498 to->udp_out_ipv6.value.ui64 += from->udp_out_ipv6;
452 499 to->udp_out_mapped.value.ui64 += from->udp_out_mapped;
453 500 to->udp_out_ipv4.value.ui64 += from->udp_out_ipv4;
454 501 #endif
455 502 }
456 503
457 504 /*
458 505 * To set all udp_stat_t counters to 0.
459 506 */
460 507 static void
461 508 udp_clr_stats(udp_stat_t *stats)
462 509 {
463 510 stats->udp_sock_fallback.value.ui64 = 0;
464 511 stats->udp_out_opt.value.ui64 = 0;
465 512 stats->udp_out_err_notconn.value.ui64 = 0;
466 513 stats->udp_out_err_output.value.ui64 = 0;
467 514 stats->udp_out_err_tudr.value.ui64 = 0;
468 515 #ifdef DEBUG
469 516 stats->udp_data_conn.value.ui64 = 0;
470 517 stats->udp_data_notconn.value.ui64 = 0;
471 518 stats->udp_out_lastdst.value.ui64 = 0;
472 519 stats->udp_out_diffdst.value.ui64 = 0;
473 520 stats->udp_out_ipv6.value.ui64 = 0;
474 521 stats->udp_out_mapped.value.ui64 = 0;
475 522 stats->udp_out_ipv4.value.ui64 = 0;
476 523 #endif
477 524 }
478 525
479 526 int
480 527 udp_kstat2_update(kstat_t *kp, int rw)
481 528 {
482 529 udp_stat_t *stats;
483 530 netstackid_t stackid = (netstackid_t)(uintptr_t)kp->ks_private;
484 531 netstack_t *ns;
485 532 udp_stack_t *us;
486 533 int i;
487 534 int cnt;
488 535
489 536 if (rw == KSTAT_WRITE)
490 537 return (EACCES);
491 538
492 539 ns = netstack_find_by_stackid(stackid);
493 540 if (ns == NULL)
494 541 return (-1);
495 542 us = ns->netstack_udp;
496 543 if (us == NULL) {
497 544 netstack_rele(ns);
498 545 return (-1);
499 546 }
500 547 stats = (udp_stat_t *)kp->ks_data;
501 548 udp_clr_stats(stats);
502 549
503 550 cnt = us->us_sc_cnt;
504 551 for (i = 0; i < cnt; i++)
505 552 udp_add_stats(&us->us_sc[i]->udp_sc_stats, stats);
506 553
507 554 netstack_rele(ns);
508 555 return (0);
509 556 }
510 557
511 558 void *
512 559 udp_kstat_init(netstackid_t stackid)
513 560 {
514 561 kstat_t *ksp;
515 562
516 563 udp_named_kstat_t template = {
517 564 { "inDatagrams", KSTAT_DATA_UINT64, 0 },
518 565 { "inErrors", KSTAT_DATA_UINT32, 0 },
519 566 { "outDatagrams", KSTAT_DATA_UINT64, 0 },
520 567 { "entrySize", KSTAT_DATA_INT32, 0 },
521 568 { "entry6Size", KSTAT_DATA_INT32, 0 },
522 569 { "outErrors", KSTAT_DATA_UINT32, 0 },
523 570 };
524 571
525 572 ksp = kstat_create_netstack(UDP_MOD_NAME, 0, UDP_MOD_NAME, "mib2",
526 573 KSTAT_TYPE_NAMED, NUM_OF_FIELDS(udp_named_kstat_t), 0, stackid);
527 574
528 575 if (ksp == NULL)
529 576 return (NULL);
530 577
531 578 template.entrySize.value.ui32 = sizeof (mib2_udpEntry_t);
532 579 template.entry6Size.value.ui32 = sizeof (mib2_udp6Entry_t);
533 580
534 581 bcopy(&template, ksp->ks_data, sizeof (template));
535 582 ksp->ks_update = udp_kstat_update;
536 583 ksp->ks_private = (void *)(uintptr_t)stackid;
537 584
538 585 kstat_install(ksp);
539 586 return (ksp);
540 587 }
541 588
542 589 /*
543 590 * To sum up all MIB2 stats for a udp_stack_t from all per CPU stats. The
544 591 * caller should initialize the target mib2_udp_t properly as this function
545 592 * just adds up all the per CPU stats.
546 593 */
547 594 static void
548 595 udp_sum_mib(udp_stack_t *us, mib2_udp_t *udp_mib)
549 596 {
550 597 int i;
551 598 int cnt;
552 599
553 600 cnt = us->us_sc_cnt;
554 601 for (i = 0; i < cnt; i++)
555 602 udp_add_mib(&us->us_sc[i]->udp_sc_mib, udp_mib);
556 603 }
557 604
558 605 static int
559 606 udp_kstat_update(kstat_t *kp, int rw)
560 607 {
561 608 udp_named_kstat_t *udpkp;
562 609 netstackid_t stackid = (netstackid_t)(uintptr_t)kp->ks_private;
563 610 netstack_t *ns;
564 611 udp_stack_t *us;
565 612 mib2_udp_t udp_mib;
566 613
567 614 if (rw == KSTAT_WRITE)
568 615 return (EACCES);
569 616
570 617 ns = netstack_find_by_stackid(stackid);
571 618 if (ns == NULL)
572 619 return (-1);
573 620 us = ns->netstack_udp;
574 621 if (us == NULL) {
575 622 netstack_rele(ns);
576 623 return (-1);
577 624 }
578 625 udpkp = (udp_named_kstat_t *)kp->ks_data;
579 626
580 627 bzero(&udp_mib, sizeof (udp_mib));
581 628 udp_sum_mib(us, &udp_mib);
582 629
583 630 udpkp->inDatagrams.value.ui64 = udp_mib.udpHCInDatagrams;
584 631 udpkp->inErrors.value.ui32 = udp_mib.udpInErrors;
585 632 udpkp->outDatagrams.value.ui64 = udp_mib.udpHCOutDatagrams;
586 633 udpkp->outErrors.value.ui32 = udp_mib.udpOutErrors;
587 634 netstack_rele(ns);
588 635 return (0);
589 636 }
↓ open down ↓ |
238 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX