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 /*
86 * make a copy of the original message
87 */
88 mp2ctl = copymsg(mpctl);
89
90 mp_conn_ctl = mp_attr_ctl = mp6_conn_ctl = NULL;
91 if (mpctl == NULL ||
92 (mpdata = mpctl->b_cont) == NULL ||
93 (mp_conn_ctl = copymsg(mpctl)) == NULL ||
94 (mp_attr_ctl = copymsg(mpctl)) == NULL ||
95 (mp_pidnode_ctl = copymsg(mpctl)) == NULL ||
96 (mp6_conn_ctl = copymsg(mpctl)) == NULL ||
97 (mp6_attr_ctl = copymsg(mpctl)) == NULL ||
98 (mp6_pidnode_ctl = copymsg(mpctl)) == NULL) {
99 freemsg(mp_conn_ctl);
100 freemsg(mp_attr_ctl);
101 freemsg(mp_pidnode_ctl);
102 freemsg(mp6_conn_ctl);
103 freemsg(mp6_attr_ctl);
104 freemsg(mp6_pidnode_ctl);
105 freemsg(mpctl);
106 freemsg(mp2ctl);
107 return (0);
108 }
109
110 zoneid = connp->conn_zoneid;
111
112 if (legacy_req) {
113 udp_mib_size = LEGACY_MIB_SIZE(&udp_mib, mib2_udp_t);
114 ude_size = LEGACY_MIB_SIZE(&ude, mib2_udpEntry_t);
115 ude6_size = LEGACY_MIB_SIZE(&ude6, mib2_udp6Entry_t);
116 } else {
117 udp_mib_size = sizeof (mib2_udp_t);
118 ude_size = sizeof (mib2_udpEntry_t);
119 ude6_size = sizeof (mib2_udp6Entry_t);
120 }
121
122 bzero(&udp_mib, sizeof (udp_mib));
123 /* fixed length structure for IPv4 and IPv6 counters */
124 SET_MIB(udp_mib.udpEntrySize, ude_size);
126
127 udp_sum_mib(us, &udp_mib);
128
129 /*
130 * Synchronize 32- and 64-bit counters. Note that udpInDatagrams and
131 * udpOutDatagrams are not updated anywhere in UDP. The new 64 bits
132 * counters are used. Hence the old counters' values in us_sc_mib
133 * are always 0.
134 */
135 SYNC32_MIB(&udp_mib, udpInDatagrams, udpHCInDatagrams);
136 SYNC32_MIB(&udp_mib, udpOutDatagrams, udpHCOutDatagrams);
137
138 optp = (struct opthdr *)&mpctl->b_rptr[sizeof (struct T_optmgmt_ack)];
139 optp->level = MIB2_UDP;
140 optp->name = 0;
141 (void) snmp_append_data(mpdata, (char *)&udp_mib, udp_mib_size);
142 optp->len = msgdsize(mpdata);
143 qreply(q, mpctl);
144
145 mp_conn_tail = mp_attr_tail = mp6_conn_tail = mp6_attr_tail = NULL;
146 mp_pidnode_tail = mp6_pidnode_tail = NULL;
147 v4_conn_idx = v6_conn_idx = 0;
148
149 for (i = 0; i < CONN_G_HASH_SIZE; i++) {
150 connfp = &ipst->ips_ipcl_globalhash_fanout[i];
151 connp = NULL;
152
153 while ((connp = ipcl_get_next_conn(connfp, connp,
154 IPCL_UDPCONN))) {
155 udp = connp->conn_udp;
156 if (zoneid != connp->conn_zoneid)
157 continue;
158
159 /*
160 * Note that the port numbers are sent in
161 * host byte order
162 */
163
164 if (udp->udp_state == TS_UNBND)
165 state = MIB2_UDP_unbound;
166 else if (udp->udp_state == TS_IDLE)
241 ntohs(connp->conn_fport);
242 } else {
243 ude.udpEntryInfo.ue_RemoteAddress = 0;
244 ude.udpEntryInfo.ue_RemotePort = 0;
245 }
246
247 /*
248 * We make the assumption that all udp_t
249 * structs will be created within an address
250 * region no larger than 32-bits.
251 */
252 ude.udpInstance = (uint32_t)(uintptr_t)udp;
253 ude.udpCreationProcess =
254 (connp->conn_cpid < 0) ?
255 MIB2_UNKNOWN_PROCESS :
256 connp->conn_cpid;
257 ude.udpCreationTime = connp->conn_open_time;
258
259 (void) snmp_append_data2(mp_conn_ctl->b_cont,
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
268 mlp.tme_connidx = v4_conn_idx++;
269 if (needattr)
270 (void) snmp_append_data2(
271 mp_attr_ctl->b_cont, &mp_attr_tail,
272 (char *)&mlp, sizeof (mlp));
273 }
274 if (connp->conn_ipversion == IPV6_VERSION) {
275 ude6.udp6EntryInfo.ue_state = state;
276 ude6.udp6LocalAddress = connp->conn_laddr_v6;
277 ude6.udp6LocalPort = ntohs(connp->conn_lport);
278 mutex_enter(&connp->conn_lock);
279 if (connp->conn_ixa->ixa_flags &
280 IXAF_SCOPEID_SET) {
281 ude6.udp6IfIndex =
282 connp->conn_ixa->ixa_scopeid;
283 } else {
284 ude6.udp6IfIndex = connp->conn_bound_if;
285 }
286 mutex_exit(&connp->conn_lock);
287 if (udp->udp_state == TS_DATA_XFER) {
291 ntohs(connp->conn_fport);
292 } else {
293 ude6.udp6EntryInfo.ue_RemoteAddress =
294 sin6_null.sin6_addr;
295 ude6.udp6EntryInfo.ue_RemotePort = 0;
296 }
297 /*
298 * We make the assumption that all udp_t
299 * structs will be created within an address
300 * region no larger than 32-bits.
301 */
302 ude6.udp6Instance = (uint32_t)(uintptr_t)udp;
303 ude6.udp6CreationProcess =
304 (connp->conn_cpid < 0) ?
305 MIB2_UNKNOWN_PROCESS :
306 connp->conn_cpid;
307 ude6.udp6CreationTime = connp->conn_open_time;
308
309 (void) snmp_append_data2(mp6_conn_ctl->b_cont,
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
320 mlp.tme_connidx = v6_conn_idx++;
321 if (needattr)
322 (void) snmp_append_data2(
323 mp6_attr_ctl->b_cont,
324 &mp6_attr_tail, (char *)&mlp,
325 sizeof (mlp));
326 }
327 }
328 }
329
330 /* IPv4 UDP endpoints */
331 optp = (struct opthdr *)&mp_conn_ctl->b_rptr[
332 sizeof (struct T_optmgmt_ack)];
333 optp->level = MIB2_UDP;
334 optp->name = MIB2_UDP_ENTRY;
335 optp->len = msgdsize(mp_conn_ctl->b_cont);
336 qreply(q, mp_conn_ctl);
337
338 /* table of MLP attributes... */
339 optp = (struct opthdr *)&mp_attr_ctl->b_rptr[
340 sizeof (struct T_optmgmt_ack)];
341 optp->level = MIB2_UDP;
342 optp->name = EXPER_XPORT_MLP;
343 optp->len = msgdsize(mp_attr_ctl->b_cont);
344 if (optp->len == 0)
345 freemsg(mp_attr_ctl);
346 else
347 qreply(q, mp_attr_ctl);
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
360 /* IPv6 UDP endpoints */
361 optp = (struct opthdr *)&mp6_conn_ctl->b_rptr[
362 sizeof (struct T_optmgmt_ack)];
363 optp->level = MIB2_UDP6;
364 optp->name = MIB2_UDP6_ENTRY;
365 optp->len = msgdsize(mp6_conn_ctl->b_cont);
366 qreply(q, mp6_conn_ctl);
367
368 /* table of MLP attributes... */
369 optp = (struct opthdr *)&mp6_attr_ctl->b_rptr[
370 sizeof (struct T_optmgmt_ack)];
371 optp->level = MIB2_UDP6;
372 optp->name = EXPER_XPORT_MLP;
373 optp->len = msgdsize(mp6_attr_ctl->b_cont);
374 if (optp->len == 0)
375 freemsg(mp6_attr_ctl);
376 else
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);
389
390 return (mp2ctl);
391 }
392
393 /*
394 * Return 0 if invalid set request, 1 otherwise, including non-udp requests.
395 * NOTE: Per MIB-II, UDP has no writable data.
396 * TODO: If this ever actually tries to set anything, it needs to be
397 * to do the appropriate locking.
398 */
399 /* ARGSUSED */
400 int
401 udp_snmp_set(queue_t *q, t_scalar_t level, t_scalar_t name,
402 uchar_t *ptr, int len)
403 {
404 switch (level) {
405 case MIB2_UDP:
406 return (0);
407 default:
408 return (1);
|