36 #include <inet/snmpcom.h>
37 #include <inet/kstatcom.h>
38 #include <inet/udp_impl.h>
39
40 static int udp_kstat_update(kstat_t *, int);
41 static int udp_kstat2_update(kstat_t *, int);
42 static void udp_sum_mib(udp_stack_t *, mib2_udp_t *);
43 static void udp_clr_stats(udp_stat_t *);
44 static void udp_add_stats(udp_stat_counter_t *, udp_stat_t *);
45 static void udp_add_mib(mib2_udp_t *, mib2_udp_t *);
46 /*
47 * return SNMP stuff in buffer in mpdata. We don't hold any lock and report
48 * information that can be changing beneath us.
49 */
50 mblk_t *
51 udp_snmp_get(queue_t *q, mblk_t *mpctl, boolean_t legacy_req)
52 {
53 mblk_t *mpdata;
54 mblk_t *mp_conn_ctl;
55 mblk_t *mp_attr_ctl;
56 mblk_t *mp6_conn_ctl;
57 mblk_t *mp6_attr_ctl;
58 mblk_t *mp_conn_tail;
59 mblk_t *mp_attr_tail;
60 mblk_t *mp6_conn_tail;
61 mblk_t *mp6_attr_tail;
62 struct opthdr *optp;
63 mib2_udpEntry_t ude;
64 mib2_udp6Entry_t ude6;
65 mib2_transportMLPEntry_t mlp;
66 int state;
67 zoneid_t zoneid;
68 int i;
69 connf_t *connfp;
70 conn_t *connp = Q_TO_CONN(q);
71 int v4_conn_idx;
72 int v6_conn_idx;
73 boolean_t needattr;
74 udp_t *udp;
75 ip_stack_t *ipst = connp->conn_netstack->netstack_ip;
76 udp_stack_t *us = connp->conn_netstack->netstack_udp;
77 mblk_t *mp2ctl;
78 mib2_udp_t udp_mib;
79 size_t udp_mib_size, ude_size, ude6_size;
80
81
82 /*
83 * make a copy of the original message
84 */
85 mp2ctl = copymsg(mpctl);
86
87 mp_conn_ctl = mp_attr_ctl = mp6_conn_ctl = NULL;
88 if (mpctl == NULL ||
89 (mpdata = mpctl->b_cont) == NULL ||
90 (mp_conn_ctl = copymsg(mpctl)) == NULL ||
91 (mp_attr_ctl = copymsg(mpctl)) == NULL ||
92 (mp6_conn_ctl = copymsg(mpctl)) == NULL ||
93 (mp6_attr_ctl = copymsg(mpctl)) == NULL) {
94 freemsg(mp_conn_ctl);
95 freemsg(mp_attr_ctl);
96 freemsg(mp6_conn_ctl);
97 freemsg(mpctl);
98 freemsg(mp2ctl);
99 return (0);
100 }
101
102 zoneid = connp->conn_zoneid;
103
104 if (legacy_req) {
105 udp_mib_size = LEGACY_MIB_SIZE(&udp_mib, mib2_udp_t);
106 ude_size = LEGACY_MIB_SIZE(&ude, mib2_udpEntry_t);
107 ude6_size = LEGACY_MIB_SIZE(&ude6, mib2_udp6Entry_t);
108 } else {
109 udp_mib_size = sizeof (mib2_udp_t);
110 ude_size = sizeof (mib2_udpEntry_t);
111 ude6_size = sizeof (mib2_udp6Entry_t);
112 }
113
114 bzero(&udp_mib, sizeof (udp_mib));
115 /* fixed length structure for IPv4 and IPv6 counters */
116 SET_MIB(udp_mib.udpEntrySize, ude_size);
118
119 udp_sum_mib(us, &udp_mib);
120
121 /*
122 * Synchronize 32- and 64-bit counters. Note that udpInDatagrams and
123 * udpOutDatagrams are not updated anywhere in UDP. The new 64 bits
124 * counters are used. Hence the old counters' values in us_sc_mib
125 * are always 0.
126 */
127 SYNC32_MIB(&udp_mib, udpInDatagrams, udpHCInDatagrams);
128 SYNC32_MIB(&udp_mib, udpOutDatagrams, udpHCOutDatagrams);
129
130 optp = (struct opthdr *)&mpctl->b_rptr[sizeof (struct T_optmgmt_ack)];
131 optp->level = MIB2_UDP;
132 optp->name = 0;
133 (void) snmp_append_data(mpdata, (char *)&udp_mib, udp_mib_size);
134 optp->len = msgdsize(mpdata);
135 qreply(q, mpctl);
136
137 mp_conn_tail = mp_attr_tail = mp6_conn_tail = mp6_attr_tail = NULL;
138 v4_conn_idx = v6_conn_idx = 0;
139
140 for (i = 0; i < CONN_G_HASH_SIZE; i++) {
141 connfp = &ipst->ips_ipcl_globalhash_fanout[i];
142 connp = NULL;
143
144 while ((connp = ipcl_get_next_conn(connfp, connp,
145 IPCL_UDPCONN))) {
146 udp = connp->conn_udp;
147 if (zoneid != connp->conn_zoneid)
148 continue;
149
150 /*
151 * Note that the port numbers are sent in
152 * host byte order
153 */
154
155 if (udp->udp_state == TS_UNBND)
156 state = MIB2_UDP_unbound;
157 else if (udp->udp_state == TS_IDLE)
232 ntohs(connp->conn_fport);
233 } else {
234 ude.udpEntryInfo.ue_RemoteAddress = 0;
235 ude.udpEntryInfo.ue_RemotePort = 0;
236 }
237
238 /*
239 * We make the assumption that all udp_t
240 * structs will be created within an address
241 * region no larger than 32-bits.
242 */
243 ude.udpInstance = (uint32_t)(uintptr_t)udp;
244 ude.udpCreationProcess =
245 (connp->conn_cpid < 0) ?
246 MIB2_UNKNOWN_PROCESS :
247 connp->conn_cpid;
248 ude.udpCreationTime = connp->conn_open_time;
249
250 (void) snmp_append_data2(mp_conn_ctl->b_cont,
251 &mp_conn_tail, (char *)&ude, ude_size);
252 mlp.tme_connidx = v4_conn_idx++;
253 if (needattr)
254 (void) snmp_append_data2(
255 mp_attr_ctl->b_cont, &mp_attr_tail,
256 (char *)&mlp, sizeof (mlp));
257 }
258 if (connp->conn_ipversion == IPV6_VERSION) {
259 ude6.udp6EntryInfo.ue_state = state;
260 ude6.udp6LocalAddress = connp->conn_laddr_v6;
261 ude6.udp6LocalPort = ntohs(connp->conn_lport);
262 mutex_enter(&connp->conn_lock);
263 if (connp->conn_ixa->ixa_flags &
264 IXAF_SCOPEID_SET) {
265 ude6.udp6IfIndex =
266 connp->conn_ixa->ixa_scopeid;
267 } else {
268 ude6.udp6IfIndex = connp->conn_bound_if;
269 }
270 mutex_exit(&connp->conn_lock);
271 if (udp->udp_state == TS_DATA_XFER) {
275 ntohs(connp->conn_fport);
276 } else {
277 ude6.udp6EntryInfo.ue_RemoteAddress =
278 sin6_null.sin6_addr;
279 ude6.udp6EntryInfo.ue_RemotePort = 0;
280 }
281 /*
282 * We make the assumption that all udp_t
283 * structs will be created within an address
284 * region no larger than 32-bits.
285 */
286 ude6.udp6Instance = (uint32_t)(uintptr_t)udp;
287 ude6.udp6CreationProcess =
288 (connp->conn_cpid < 0) ?
289 MIB2_UNKNOWN_PROCESS :
290 connp->conn_cpid;
291 ude6.udp6CreationTime = connp->conn_open_time;
292
293 (void) snmp_append_data2(mp6_conn_ctl->b_cont,
294 &mp6_conn_tail, (char *)&ude6, ude6_size);
295 mlp.tme_connidx = v6_conn_idx++;
296 if (needattr)
297 (void) snmp_append_data2(
298 mp6_attr_ctl->b_cont,
299 &mp6_attr_tail, (char *)&mlp,
300 sizeof (mlp));
301 }
302 }
303 }
304
305 /* IPv4 UDP endpoints */
306 optp = (struct opthdr *)&mp_conn_ctl->b_rptr[
307 sizeof (struct T_optmgmt_ack)];
308 optp->level = MIB2_UDP;
309 optp->name = MIB2_UDP_ENTRY;
310 optp->len = msgdsize(mp_conn_ctl->b_cont);
311 qreply(q, mp_conn_ctl);
312
313 /* table of MLP attributes... */
314 optp = (struct opthdr *)&mp_attr_ctl->b_rptr[
315 sizeof (struct T_optmgmt_ack)];
316 optp->level = MIB2_UDP;
317 optp->name = EXPER_XPORT_MLP;
318 optp->len = msgdsize(mp_attr_ctl->b_cont);
319 if (optp->len == 0)
320 freemsg(mp_attr_ctl);
321 else
322 qreply(q, mp_attr_ctl);
323
324 /* IPv6 UDP endpoints */
325 optp = (struct opthdr *)&mp6_conn_ctl->b_rptr[
326 sizeof (struct T_optmgmt_ack)];
327 optp->level = MIB2_UDP6;
328 optp->name = MIB2_UDP6_ENTRY;
329 optp->len = msgdsize(mp6_conn_ctl->b_cont);
330 qreply(q, mp6_conn_ctl);
331
332 /* table of MLP attributes... */
333 optp = (struct opthdr *)&mp6_attr_ctl->b_rptr[
334 sizeof (struct T_optmgmt_ack)];
335 optp->level = MIB2_UDP6;
336 optp->name = EXPER_XPORT_MLP;
337 optp->len = msgdsize(mp6_attr_ctl->b_cont);
338 if (optp->len == 0)
339 freemsg(mp6_attr_ctl);
340 else
341 qreply(q, mp6_attr_ctl);
342
343 return (mp2ctl);
344 }
345
346 /*
347 * Return 0 if invalid set request, 1 otherwise, including non-udp requests.
348 * NOTE: Per MIB-II, UDP has no writable data.
349 * TODO: If this ever actually tries to set anything, it needs to be
350 * to do the appropriate locking.
351 */
352 /* ARGSUSED */
353 int
354 udp_snmp_set(queue_t *q, t_scalar_t level, t_scalar_t name,
355 uchar_t *ptr, int len)
356 {
357 switch (level) {
358 case MIB2_UDP:
359 return (0);
360 default:
361 return (1);
|
36 #include <inet/snmpcom.h>
37 #include <inet/kstatcom.h>
38 #include <inet/udp_impl.h>
39
40 static int udp_kstat_update(kstat_t *, int);
41 static int udp_kstat2_update(kstat_t *, int);
42 static void udp_sum_mib(udp_stack_t *, mib2_udp_t *);
43 static void udp_clr_stats(udp_stat_t *);
44 static void udp_add_stats(udp_stat_counter_t *, udp_stat_t *);
45 static void udp_add_mib(mib2_udp_t *, mib2_udp_t *);
46 /*
47 * return SNMP stuff in buffer in mpdata. We don't hold any lock and report
48 * information that can be changing beneath us.
49 */
50 mblk_t *
51 udp_snmp_get(queue_t *q, mblk_t *mpctl, boolean_t legacy_req)
52 {
53 mblk_t *mpdata;
54 mblk_t *mp_conn_ctl;
55 mblk_t *mp_attr_ctl;
56 mblk_t *mp_pidnode_ctl;
57 mblk_t *mp6_conn_ctl;
58 mblk_t *mp6_attr_ctl;
59 mblk_t *mp6_pidnode_ctl;
60 mblk_t *mp_conn_tail;
61 mblk_t *mp_attr_tail;
62 mblk_t *mp_pidnode_tail;
63 mblk_t *mp6_conn_tail;
64 mblk_t *mp6_attr_tail;
65 mblk_t *mp6_pidnode_tail;
66 struct opthdr *optp;
67 mib2_udpEntry_t ude;
68 mib2_udp6Entry_t ude6;
69 mib2_transportMLPEntry_t mlp;
70 int state;
71 zoneid_t zoneid;
72 int i;
73 connf_t *connfp;
74 conn_t *connp = Q_TO_CONN(q);
75 int v4_conn_idx;
76 int v6_conn_idx;
77 boolean_t needattr;
78 udp_t *udp;
79 ip_stack_t *ipst = connp->conn_netstack->netstack_ip;
80 udp_stack_t *us = connp->conn_netstack->netstack_udp;
81 mblk_t *mp2ctl;
82 mib2_udp_t udp_mib;
83 size_t udp_mib_size, ude_size, ude6_size;
84
85 conn_pid_node_list_hdr_t *cph;
86
87
88 /*
89 * make a copy of the original message
90 */
91 mp2ctl = copymsg(mpctl);
92
93 mp_conn_ctl = mp_attr_ctl = mp6_conn_ctl = NULL;
94 if (mpctl == NULL ||
95 (mpdata = mpctl->b_cont) == NULL ||
96 (mp_conn_ctl = copymsg(mpctl)) == NULL ||
97 (mp_attr_ctl = copymsg(mpctl)) == NULL ||
98 (mp_pidnode_ctl = copymsg(mpctl)) == NULL ||
99 (mp6_conn_ctl = copymsg(mpctl)) == NULL ||
100 (mp6_attr_ctl = copymsg(mpctl)) == NULL ||
101 (mp6_pidnode_ctl = copymsg(mpctl)) == NULL) {
102 freemsg(mp_conn_ctl);
103 freemsg(mp_attr_ctl);
104 freemsg(mp_pidnode_ctl);
105 freemsg(mp6_conn_ctl);
106 freemsg(mp6_attr_ctl);
107 freemsg(mp6_pidnode_ctl);
108 freemsg(mpctl);
109 freemsg(mp2ctl);
110 return (0);
111 }
112
113 zoneid = connp->conn_zoneid;
114
115 if (legacy_req) {
116 udp_mib_size = LEGACY_MIB_SIZE(&udp_mib, mib2_udp_t);
117 ude_size = LEGACY_MIB_SIZE(&ude, mib2_udpEntry_t);
118 ude6_size = LEGACY_MIB_SIZE(&ude6, mib2_udp6Entry_t);
119 } else {
120 udp_mib_size = sizeof (mib2_udp_t);
121 ude_size = sizeof (mib2_udpEntry_t);
122 ude6_size = sizeof (mib2_udp6Entry_t);
123 }
124
125 bzero(&udp_mib, sizeof (udp_mib));
126 /* fixed length structure for IPv4 and IPv6 counters */
127 SET_MIB(udp_mib.udpEntrySize, ude_size);
129
130 udp_sum_mib(us, &udp_mib);
131
132 /*
133 * Synchronize 32- and 64-bit counters. Note that udpInDatagrams and
134 * udpOutDatagrams are not updated anywhere in UDP. The new 64 bits
135 * counters are used. Hence the old counters' values in us_sc_mib
136 * are always 0.
137 */
138 SYNC32_MIB(&udp_mib, udpInDatagrams, udpHCInDatagrams);
139 SYNC32_MIB(&udp_mib, udpOutDatagrams, udpHCOutDatagrams);
140
141 optp = (struct opthdr *)&mpctl->b_rptr[sizeof (struct T_optmgmt_ack)];
142 optp->level = MIB2_UDP;
143 optp->name = 0;
144 (void) snmp_append_data(mpdata, (char *)&udp_mib, udp_mib_size);
145 optp->len = msgdsize(mpdata);
146 qreply(q, mpctl);
147
148 mp_conn_tail = mp_attr_tail = mp6_conn_tail = mp6_attr_tail = NULL;
149 mp_pidnode_tail = mp6_pidnode_tail = NULL;
150 v4_conn_idx = v6_conn_idx = 0;
151
152 for (i = 0; i < CONN_G_HASH_SIZE; i++) {
153 connfp = &ipst->ips_ipcl_globalhash_fanout[i];
154 connp = NULL;
155
156 while ((connp = ipcl_get_next_conn(connfp, connp,
157 IPCL_UDPCONN))) {
158 udp = connp->conn_udp;
159 if (zoneid != connp->conn_zoneid)
160 continue;
161
162 /*
163 * Note that the port numbers are sent in
164 * host byte order
165 */
166
167 if (udp->udp_state == TS_UNBND)
168 state = MIB2_UDP_unbound;
169 else if (udp->udp_state == TS_IDLE)
244 ntohs(connp->conn_fport);
245 } else {
246 ude.udpEntryInfo.ue_RemoteAddress = 0;
247 ude.udpEntryInfo.ue_RemotePort = 0;
248 }
249
250 /*
251 * We make the assumption that all udp_t
252 * structs will be created within an address
253 * region no larger than 32-bits.
254 */
255 ude.udpInstance = (uint32_t)(uintptr_t)udp;
256 ude.udpCreationProcess =
257 (connp->conn_cpid < 0) ?
258 MIB2_UNKNOWN_PROCESS :
259 connp->conn_cpid;
260 ude.udpCreationTime = connp->conn_open_time;
261
262 (void) snmp_append_data2(mp_conn_ctl->b_cont,
263 &mp_conn_tail, (char *)&ude, ude_size);
264 /* my data */
265 (void) snmp_append_data2(mp_pidnode_ctl->b_cont,
266 &mp_pidnode_tail, (char *)&ude, ude_size);
267
268 cph = conn_get_pid_list(connp);
269 (void) snmp_append_data2(mp_pidnode_ctl->b_cont,
270 &mp_pidnode_tail, (char *)cph,
271 cph->cph_tot_size);
272
273 kmem_free(cph, cph->cph_tot_size);
274 /* end of my data */
275
276 mlp.tme_connidx = v4_conn_idx++;
277 if (needattr)
278 (void) snmp_append_data2(
279 mp_attr_ctl->b_cont, &mp_attr_tail,
280 (char *)&mlp, sizeof (mlp));
281 }
282 if (connp->conn_ipversion == IPV6_VERSION) {
283 ude6.udp6EntryInfo.ue_state = state;
284 ude6.udp6LocalAddress = connp->conn_laddr_v6;
285 ude6.udp6LocalPort = ntohs(connp->conn_lport);
286 mutex_enter(&connp->conn_lock);
287 if (connp->conn_ixa->ixa_flags &
288 IXAF_SCOPEID_SET) {
289 ude6.udp6IfIndex =
290 connp->conn_ixa->ixa_scopeid;
291 } else {
292 ude6.udp6IfIndex = connp->conn_bound_if;
293 }
294 mutex_exit(&connp->conn_lock);
295 if (udp->udp_state == TS_DATA_XFER) {
299 ntohs(connp->conn_fport);
300 } else {
301 ude6.udp6EntryInfo.ue_RemoteAddress =
302 sin6_null.sin6_addr;
303 ude6.udp6EntryInfo.ue_RemotePort = 0;
304 }
305 /*
306 * We make the assumption that all udp_t
307 * structs will be created within an address
308 * region no larger than 32-bits.
309 */
310 ude6.udp6Instance = (uint32_t)(uintptr_t)udp;
311 ude6.udp6CreationProcess =
312 (connp->conn_cpid < 0) ?
313 MIB2_UNKNOWN_PROCESS :
314 connp->conn_cpid;
315 ude6.udp6CreationTime = connp->conn_open_time;
316
317 (void) snmp_append_data2(mp6_conn_ctl->b_cont,
318 &mp6_conn_tail, (char *)&ude6, ude6_size);
319 /* my dat */
320 (void) snmp_append_data2(
321 mp6_pidnode_ctl->b_cont, &mp6_pidnode_tail,
322 (char *)&ude6, ude6_size);
323
324 cph = conn_get_pid_list(connp);
325 (void) snmp_append_data2(
326 mp6_pidnode_ctl->b_cont, &mp6_pidnode_tail,
327 (char *)cph, cph->cph_tot_size);
328
329 kmem_free(cph, cph->cph_tot_size);
330 /* end of my data */
331 mlp.tme_connidx = v6_conn_idx++;
332 if (needattr)
333 (void) snmp_append_data2(
334 mp6_attr_ctl->b_cont,
335 &mp6_attr_tail, (char *)&mlp,
336 sizeof (mlp));
337 }
338 }
339 }
340
341 /* IPv4 UDP endpoints */
342 optp = (struct opthdr *)&mp_conn_ctl->b_rptr[
343 sizeof (struct T_optmgmt_ack)];
344 optp->level = MIB2_UDP;
345 optp->name = MIB2_UDP_ENTRY;
346 optp->len = msgdsize(mp_conn_ctl->b_cont);
347 qreply(q, mp_conn_ctl);
348
349 /* table of MLP attributes... */
350 optp = (struct opthdr *)&mp_attr_ctl->b_rptr[
351 sizeof (struct T_optmgmt_ack)];
352 optp->level = MIB2_UDP;
353 optp->name = EXPER_XPORT_MLP;
354 optp->len = msgdsize(mp_attr_ctl->b_cont);
355 if (optp->len == 0)
356 freemsg(mp_attr_ctl);
357 else
358 qreply(q, mp_attr_ctl);
359
360 /* table of EXPER_XPORT_PROC_INFO ipv4 */
361 optp = (struct opthdr *)&mp_pidnode_ctl->b_rptr[
362 sizeof (struct T_optmgmt_ack)];
363 optp->level = MIB2_UDP;
364 optp->name = EXPER_XPORT_PROC_INFO;
365 optp->len = msgdsize(mp_pidnode_ctl->b_cont);
366 if (optp->len == 0)
367 freemsg(mp_pidnode_ctl);
368 else
369 qreply(q, mp_pidnode_ctl);
370
371 /* IPv6 UDP endpoints */
372 optp = (struct opthdr *)&mp6_conn_ctl->b_rptr[
373 sizeof (struct T_optmgmt_ack)];
374 optp->level = MIB2_UDP6;
375 optp->name = MIB2_UDP6_ENTRY;
376 optp->len = msgdsize(mp6_conn_ctl->b_cont);
377 qreply(q, mp6_conn_ctl);
378
379 /* table of MLP attributes... */
380 optp = (struct opthdr *)&mp6_attr_ctl->b_rptr[
381 sizeof (struct T_optmgmt_ack)];
382 optp->level = MIB2_UDP6;
383 optp->name = EXPER_XPORT_MLP;
384 optp->len = msgdsize(mp6_attr_ctl->b_cont);
385 if (optp->len == 0)
386 freemsg(mp6_attr_ctl);
387 else
388 qreply(q, mp6_attr_ctl);
389
390 /* table of EXPER_XPORT_PROC_INFO ipv6 */
391 optp = (struct opthdr *)&mp6_pidnode_ctl->b_rptr[
392 sizeof (struct T_optmgmt_ack)];
393 optp->level = MIB2_UDP6;
394 optp->name = EXPER_XPORT_PROC_INFO;
395 optp->len = msgdsize(mp6_pidnode_ctl->b_cont);
396 if (optp->len == 0)
397 freemsg(mp6_pidnode_ctl);
398 else
399 qreply(q, mp6_pidnode_ctl);
400
401 return (mp2ctl);
402 }
403
404 /*
405 * Return 0 if invalid set request, 1 otherwise, including non-udp requests.
406 * NOTE: Per MIB-II, UDP has no writable data.
407 * TODO: If this ever actually tries to set anything, it needs to be
408 * to do the appropriate locking.
409 */
410 /* ARGSUSED */
411 int
412 udp_snmp_set(queue_t *q, t_scalar_t level, t_scalar_t name,
413 uchar_t *ptr, int len)
414 {
415 switch (level) {
416 case MIB2_UDP:
417 return (0);
418 default:
419 return (1);
|