source: azure_iot_hub_f767zi/trunk/asp_baseplatform/lwip/lwip-2.1.2/src/apps/snmp/snmp_mib2_tcp.c@ 457

Last change on this file since 457 was 457, checked in by coas-nagasima, 4 years ago

ファイルを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 22.5 KB
Line 
1/**
2 * @file
3 * Management Information Base II (RFC1213) TCP objects and functions.
4 */
5
6/*
7 * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 * OF SUCH DAMAGE.
31 *
32 * Author: Dirk Ziegelmeier <dziegel@gmx.de>
33 * Christiaan Simons <christiaan.simons@axon.tv>
34 */
35
36#include "lwip/snmp.h"
37#include "lwip/apps/snmp.h"
38#include "lwip/apps/snmp_core.h"
39#include "lwip/apps/snmp_mib2.h"
40#include "lwip/apps/snmp_table.h"
41#include "lwip/apps/snmp_scalar.h"
42#include "lwip/tcp.h"
43#include "lwip/priv/tcp_priv.h"
44#include "lwip/stats.h"
45
46#include <string.h>
47
48#if LWIP_SNMP && SNMP_LWIP_MIB2 && LWIP_TCP
49
50#if SNMP_USE_NETCONN
51#define SYNC_NODE_NAME(node_name) node_name ## _synced
52#define CREATE_LWIP_SYNC_NODE(oid, node_name) \
53 static const struct snmp_threadsync_node node_name ## _synced = SNMP_CREATE_THREAD_SYNC_NODE(oid, &node_name.node, &snmp_mib2_lwip_locks);
54#else
55#define SYNC_NODE_NAME(node_name) node_name
56#define CREATE_LWIP_SYNC_NODE(oid, node_name)
57#endif
58
59/* --- tcp .1.3.6.1.2.1.6 ----------------------------------------------------- */
60
61static s16_t
62tcp_get_value(struct snmp_node_instance *instance, void *value)
63{
64 u32_t *uint_ptr = (u32_t *)value;
65 s32_t *sint_ptr = (s32_t *)value;
66
67 switch (instance->node->oid) {
68 case 1: /* tcpRtoAlgorithm, vanj(4) */
69 *sint_ptr = 4;
70 return sizeof(*sint_ptr);
71 case 2: /* tcpRtoMin */
72 /* @todo not the actual value, a guess,
73 needs to be calculated */
74 *sint_ptr = 1000;
75 return sizeof(*sint_ptr);
76 case 3: /* tcpRtoMax */
77 /* @todo not the actual value, a guess,
78 needs to be calculated */
79 *sint_ptr = 60000;
80 return sizeof(*sint_ptr);
81 case 4: /* tcpMaxConn */
82 *sint_ptr = MEMP_NUM_TCP_PCB;
83 return sizeof(*sint_ptr);
84 case 5: /* tcpActiveOpens */
85 *uint_ptr = STATS_GET(mib2.tcpactiveopens);
86 return sizeof(*uint_ptr);
87 case 6: /* tcpPassiveOpens */
88 *uint_ptr = STATS_GET(mib2.tcppassiveopens);
89 return sizeof(*uint_ptr);
90 case 7: /* tcpAttemptFails */
91 *uint_ptr = STATS_GET(mib2.tcpattemptfails);
92 return sizeof(*uint_ptr);
93 case 8: /* tcpEstabResets */
94 *uint_ptr = STATS_GET(mib2.tcpestabresets);
95 return sizeof(*uint_ptr);
96 case 9: { /* tcpCurrEstab */
97 u16_t tcpcurrestab = 0;
98 struct tcp_pcb *pcb = tcp_active_pcbs;
99 while (pcb != NULL) {
100 if ((pcb->state == ESTABLISHED) ||
101 (pcb->state == CLOSE_WAIT)) {
102 tcpcurrestab++;
103 }
104 pcb = pcb->next;
105 }
106 *uint_ptr = tcpcurrestab;
107 }
108 return sizeof(*uint_ptr);
109 case 10: /* tcpInSegs */
110 *uint_ptr = STATS_GET(mib2.tcpinsegs);
111 return sizeof(*uint_ptr);
112 case 11: /* tcpOutSegs */
113 *uint_ptr = STATS_GET(mib2.tcpoutsegs);
114 return sizeof(*uint_ptr);
115 case 12: /* tcpRetransSegs */
116 *uint_ptr = STATS_GET(mib2.tcpretranssegs);
117 return sizeof(*uint_ptr);
118 case 14: /* tcpInErrs */
119 *uint_ptr = STATS_GET(mib2.tcpinerrs);
120 return sizeof(*uint_ptr);
121 case 15: /* tcpOutRsts */
122 *uint_ptr = STATS_GET(mib2.tcpoutrsts);
123 return sizeof(*uint_ptr);
124#if LWIP_HAVE_INT64
125 case 17: { /* tcpHCInSegs */
126 /* use the 32 bit counter for now... */
127 u64_t val64 = STATS_GET(mib2.tcpinsegs);
128 *((u64_t *)value) = val64;
129 }
130 return sizeof(u64_t);
131 case 18: { /* tcpHCOutSegs */
132 /* use the 32 bit counter for now... */
133 u64_t val64 = STATS_GET(mib2.tcpoutsegs);
134 *((u64_t *)value) = val64;
135 }
136 return sizeof(u64_t);
137#endif
138 default:
139 LWIP_DEBUGF(SNMP_MIB_DEBUG, ("tcp_get_value(): unknown id: %"S32_F"\n", instance->node->oid));
140 break;
141 }
142
143 return 0;
144}
145
146/* --- tcpConnTable --- */
147
148#if LWIP_IPV4
149
150/* list of allowed value ranges for incoming OID */
151static const struct snmp_oid_range tcp_ConnTable_oid_ranges[] = {
152 { 0, 0xff }, /* IP A */
153 { 0, 0xff }, /* IP B */
154 { 0, 0xff }, /* IP C */
155 { 0, 0xff }, /* IP D */
156 { 0, 0xffff }, /* Port */
157 { 0, 0xff }, /* IP A */
158 { 0, 0xff }, /* IP B */
159 { 0, 0xff }, /* IP C */
160 { 0, 0xff }, /* IP D */
161 { 0, 0xffff } /* Port */
162};
163
164static snmp_err_t
165tcp_ConnTable_get_cell_value_core(struct tcp_pcb *pcb, const u32_t *column, union snmp_variant_value *value, u32_t *value_len)
166{
167 LWIP_UNUSED_ARG(value_len);
168
169 /* value */
170 switch (*column) {
171 case 1: /* tcpConnState */
172 value->u32 = pcb->state + 1;
173 break;
174 case 2: /* tcpConnLocalAddress */
175 value->u32 = ip_2_ip4(&pcb->local_ip)->addr;
176 break;
177 case 3: /* tcpConnLocalPort */
178 value->u32 = pcb->local_port;
179 break;
180 case 4: /* tcpConnRemAddress */
181 if (pcb->state == LISTEN) {
182 value->u32 = IP4_ADDR_ANY4->addr;
183 } else {
184 value->u32 = ip_2_ip4(&pcb->remote_ip)->addr;
185 }
186 break;
187 case 5: /* tcpConnRemPort */
188 if (pcb->state == LISTEN) {
189 value->u32 = 0;
190 } else {
191 value->u32 = pcb->remote_port;
192 }
193 break;
194 default:
195 LWIP_ASSERT("invalid id", 0);
196 return SNMP_ERR_NOSUCHINSTANCE;
197 }
198
199 return SNMP_ERR_NOERROR;
200}
201
202static snmp_err_t
203tcp_ConnTable_get_cell_value(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, union snmp_variant_value *value, u32_t *value_len)
204{
205 u8_t i;
206 ip4_addr_t local_ip;
207 ip4_addr_t remote_ip;
208 u16_t local_port;
209 u16_t remote_port;
210 struct tcp_pcb *pcb;
211
212 /* check if incoming OID length and if values are in plausible range */
213 if (!snmp_oid_in_range(row_oid, row_oid_len, tcp_ConnTable_oid_ranges, LWIP_ARRAYSIZE(tcp_ConnTable_oid_ranges))) {
214 return SNMP_ERR_NOSUCHINSTANCE;
215 }
216
217 /* get IPs and ports from incoming OID */
218 snmp_oid_to_ip4(&row_oid[0], &local_ip); /* we know it succeeds because of oid_in_range check above */
219 local_port = (u16_t)row_oid[4];
220 snmp_oid_to_ip4(&row_oid[5], &remote_ip); /* we know it succeeds because of oid_in_range check above */
221 remote_port = (u16_t)row_oid[9];
222
223 /* find tcp_pcb with requested ips and ports */
224 for (i = 0; i < LWIP_ARRAYSIZE(tcp_pcb_lists); i++) {
225 pcb = *tcp_pcb_lists[i];
226
227 while (pcb != NULL) {
228 /* do local IP and local port match? */
229 if (IP_IS_V4_VAL(pcb->local_ip) &&
230 ip4_addr_cmp(&local_ip, ip_2_ip4(&pcb->local_ip)) && (local_port == pcb->local_port)) {
231
232 /* PCBs in state LISTEN are not connected and have no remote_ip or remote_port */
233 if (pcb->state == LISTEN) {
234 if (ip4_addr_cmp(&remote_ip, IP4_ADDR_ANY4) && (remote_port == 0)) {
235 /* fill in object properties */
236 return tcp_ConnTable_get_cell_value_core(pcb, column, value, value_len);
237 }
238 } else {
239 if (IP_IS_V4_VAL(pcb->remote_ip) &&
240 ip4_addr_cmp(&remote_ip, ip_2_ip4(&pcb->remote_ip)) && (remote_port == pcb->remote_port)) {
241 /* fill in object properties */
242 return tcp_ConnTable_get_cell_value_core(pcb, column, value, value_len);
243 }
244 }
245 }
246
247 pcb = pcb->next;
248 }
249 }
250
251 /* not found */
252 return SNMP_ERR_NOSUCHINSTANCE;
253}
254
255static snmp_err_t
256tcp_ConnTable_get_next_cell_instance_and_value(const u32_t *column, struct snmp_obj_id *row_oid, union snmp_variant_value *value, u32_t *value_len)
257{
258 u8_t i;
259 struct tcp_pcb *pcb;
260 struct snmp_next_oid_state state;
261 u32_t result_temp[LWIP_ARRAYSIZE(tcp_ConnTable_oid_ranges)];
262
263 /* init struct to search next oid */
264 snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(tcp_ConnTable_oid_ranges));
265
266 /* iterate over all possible OIDs to find the next one */
267 for (i = 0; i < LWIP_ARRAYSIZE(tcp_pcb_lists); i++) {
268 pcb = *tcp_pcb_lists[i];
269 while (pcb != NULL) {
270 u32_t test_oid[LWIP_ARRAYSIZE(tcp_ConnTable_oid_ranges)];
271
272 if (IP_IS_V4_VAL(pcb->local_ip)) {
273 snmp_ip4_to_oid(ip_2_ip4(&pcb->local_ip), &test_oid[0]);
274 test_oid[4] = pcb->local_port;
275
276 /* PCBs in state LISTEN are not connected and have no remote_ip or remote_port */
277 if (pcb->state == LISTEN) {
278 snmp_ip4_to_oid(IP4_ADDR_ANY4, &test_oid[5]);
279 test_oid[9] = 0;
280 } else {
281 if (IP_IS_V6_VAL(pcb->remote_ip)) { /* should never happen */
282 continue;
283 }
284 snmp_ip4_to_oid(ip_2_ip4(&pcb->remote_ip), &test_oid[5]);
285 test_oid[9] = pcb->remote_port;
286 }
287
288 /* check generated OID: is it a candidate for the next one? */
289 snmp_next_oid_check(&state, test_oid, LWIP_ARRAYSIZE(tcp_ConnTable_oid_ranges), pcb);
290 }
291
292 pcb = pcb->next;
293 }
294 }
295
296 /* did we find a next one? */
297 if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {
298 snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len);
299 /* fill in object properties */
300 return tcp_ConnTable_get_cell_value_core((struct tcp_pcb *)state.reference, column, value, value_len);
301 }
302
303 /* not found */
304 return SNMP_ERR_NOSUCHINSTANCE;
305}
306
307#endif /* LWIP_IPV4 */
308
309/* --- tcpConnectionTable --- */
310
311static snmp_err_t
312tcp_ConnectionTable_get_cell_value_core(const u32_t *column, struct tcp_pcb *pcb, union snmp_variant_value *value)
313{
314 /* all items except tcpConnectionState and tcpConnectionProcess are declared as not-accessible */
315 switch (*column) {
316 case 7: /* tcpConnectionState */
317 value->u32 = pcb->state + 1;
318 break;
319 case 8: /* tcpConnectionProcess */
320 value->u32 = 0; /* not supported */
321 break;
322 default:
323 return SNMP_ERR_NOSUCHINSTANCE;
324 }
325
326 return SNMP_ERR_NOERROR;
327}
328
329static snmp_err_t
330tcp_ConnectionTable_get_cell_value(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, union snmp_variant_value *value, u32_t *value_len)
331{
332 ip_addr_t local_ip, remote_ip;
333 u16_t local_port, remote_port;
334 struct tcp_pcb *pcb;
335 u8_t idx = 0;
336 u8_t i;
337 struct tcp_pcb **const tcp_pcb_nonlisten_lists[] = {&tcp_bound_pcbs, &tcp_active_pcbs, &tcp_tw_pcbs};
338
339 LWIP_UNUSED_ARG(value_len);
340
341 /* tcpConnectionLocalAddressType + tcpConnectionLocalAddress + tcpConnectionLocalPort */
342 idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len - idx, &local_ip, &local_port);
343 if (idx == 0) {
344 return SNMP_ERR_NOSUCHINSTANCE;
345 }
346
347 /* tcpConnectionRemAddressType + tcpConnectionRemAddress + tcpConnectionRemPort */
348 idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len - idx, &remote_ip, &remote_port);
349 if (idx == 0) {
350 return SNMP_ERR_NOSUCHINSTANCE;
351 }
352
353 /* find tcp_pcb with requested ip and port*/
354 for (i = 0; i < LWIP_ARRAYSIZE(tcp_pcb_nonlisten_lists); i++) {
355 pcb = *tcp_pcb_nonlisten_lists[i];
356
357 while (pcb != NULL) {
358 if (ip_addr_cmp(&local_ip, &pcb->local_ip) &&
359 (local_port == pcb->local_port) &&
360 ip_addr_cmp(&remote_ip, &pcb->remote_ip) &&
361 (remote_port == pcb->remote_port)) {
362 /* fill in object properties */
363 return tcp_ConnectionTable_get_cell_value_core(column, pcb, value);
364 }
365 pcb = pcb->next;
366 }
367 }
368
369 /* not found */
370 return SNMP_ERR_NOSUCHINSTANCE;
371}
372
373static snmp_err_t
374tcp_ConnectionTable_get_next_cell_instance_and_value(const u32_t *column, struct snmp_obj_id *row_oid, union snmp_variant_value *value, u32_t *value_len)
375{
376 struct tcp_pcb *pcb;
377 struct snmp_next_oid_state state;
378 /* 1x tcpConnectionLocalAddressType + 1x OID len + 16x tcpConnectionLocalAddress + 1x tcpConnectionLocalPort
379 * 1x tcpConnectionRemAddressType + 1x OID len + 16x tcpConnectionRemAddress + 1x tcpConnectionRemPort */
380 u32_t result_temp[38];
381 u8_t i;
382 struct tcp_pcb **const tcp_pcb_nonlisten_lists[] = {&tcp_bound_pcbs, &tcp_active_pcbs, &tcp_tw_pcbs};
383
384 LWIP_UNUSED_ARG(value_len);
385
386 /* init struct to search next oid */
387 snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(result_temp));
388
389 /* iterate over all possible OIDs to find the next one */
390 for (i = 0; i < LWIP_ARRAYSIZE(tcp_pcb_nonlisten_lists); i++) {
391 pcb = *tcp_pcb_nonlisten_lists[i];
392
393 while (pcb != NULL) {
394 u8_t idx = 0;
395 u32_t test_oid[LWIP_ARRAYSIZE(result_temp)];
396
397 /* tcpConnectionLocalAddressType + tcpConnectionLocalAddress + tcpConnectionLocalPort */
398 idx += snmp_ip_port_to_oid(&pcb->local_ip, pcb->local_port, &test_oid[idx]);
399
400 /* tcpConnectionRemAddressType + tcpConnectionRemAddress + tcpConnectionRemPort */
401 idx += snmp_ip_port_to_oid(&pcb->remote_ip, pcb->remote_port, &test_oid[idx]);
402
403 /* check generated OID: is it a candidate for the next one? */
404 snmp_next_oid_check(&state, test_oid, idx, pcb);
405
406 pcb = pcb->next;
407 }
408 }
409
410 /* did we find a next one? */
411 if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {
412 snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len);
413 /* fill in object properties */
414 return tcp_ConnectionTable_get_cell_value_core(column, (struct tcp_pcb *)state.reference, value);
415 } else {
416 /* not found */
417 return SNMP_ERR_NOSUCHINSTANCE;
418 }
419}
420
421/* --- tcpListenerTable --- */
422
423static snmp_err_t
424tcp_ListenerTable_get_cell_value_core(const u32_t *column, union snmp_variant_value *value)
425{
426 /* all items except tcpListenerProcess are declared as not-accessible */
427 switch (*column) {
428 case 4: /* tcpListenerProcess */
429 value->u32 = 0; /* not supported */
430 break;
431 default:
432 return SNMP_ERR_NOSUCHINSTANCE;
433 }
434
435 return SNMP_ERR_NOERROR;
436}
437
438static snmp_err_t
439tcp_ListenerTable_get_cell_value(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, union snmp_variant_value *value, u32_t *value_len)
440{
441 ip_addr_t local_ip;
442 u16_t local_port;
443 struct tcp_pcb_listen *pcb;
444 u8_t idx = 0;
445
446 LWIP_UNUSED_ARG(value_len);
447
448 /* tcpListenerLocalAddressType + tcpListenerLocalAddress + tcpListenerLocalPort */
449 idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len - idx, &local_ip, &local_port);
450 if (idx == 0) {
451 return SNMP_ERR_NOSUCHINSTANCE;
452 }
453
454 /* find tcp_pcb with requested ip and port*/
455 pcb = tcp_listen_pcbs.listen_pcbs;
456 while (pcb != NULL) {
457 if (ip_addr_cmp(&local_ip, &pcb->local_ip) &&
458 (local_port == pcb->local_port)) {
459 /* fill in object properties */
460 return tcp_ListenerTable_get_cell_value_core(column, value);
461 }
462 pcb = pcb->next;
463 }
464
465 /* not found */
466 return SNMP_ERR_NOSUCHINSTANCE;
467}
468
469static snmp_err_t
470tcp_ListenerTable_get_next_cell_instance_and_value(const u32_t *column, struct snmp_obj_id *row_oid, union snmp_variant_value *value, u32_t *value_len)
471{
472 struct tcp_pcb_listen *pcb;
473 struct snmp_next_oid_state state;
474 /* 1x tcpListenerLocalAddressType + 1x OID len + 16x tcpListenerLocalAddress + 1x tcpListenerLocalPort */
475 u32_t result_temp[19];
476
477 LWIP_UNUSED_ARG(value_len);
478
479 /* init struct to search next oid */
480 snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(result_temp));
481
482 /* iterate over all possible OIDs to find the next one */
483 pcb = tcp_listen_pcbs.listen_pcbs;
484 while (pcb != NULL) {
485 u8_t idx = 0;
486 u32_t test_oid[LWIP_ARRAYSIZE(result_temp)];
487
488 /* tcpListenerLocalAddressType + tcpListenerLocalAddress + tcpListenerLocalPort */
489 idx += snmp_ip_port_to_oid(&pcb->local_ip, pcb->local_port, &test_oid[idx]);
490
491 /* check generated OID: is it a candidate for the next one? */
492 snmp_next_oid_check(&state, test_oid, idx, NULL);
493
494 pcb = pcb->next;
495 }
496
497 /* did we find a next one? */
498 if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {
499 snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len);
500 /* fill in object properties */
501 return tcp_ListenerTable_get_cell_value_core(column, value);
502 } else {
503 /* not found */
504 return SNMP_ERR_NOSUCHINSTANCE;
505 }
506}
507
508static const struct snmp_scalar_node tcp_RtoAlgorithm = SNMP_SCALAR_CREATE_NODE_READONLY(1, SNMP_ASN1_TYPE_INTEGER, tcp_get_value);
509static const struct snmp_scalar_node tcp_RtoMin = SNMP_SCALAR_CREATE_NODE_READONLY(2, SNMP_ASN1_TYPE_INTEGER, tcp_get_value);
510static const struct snmp_scalar_node tcp_RtoMax = SNMP_SCALAR_CREATE_NODE_READONLY(3, SNMP_ASN1_TYPE_INTEGER, tcp_get_value);
511static const struct snmp_scalar_node tcp_MaxConn = SNMP_SCALAR_CREATE_NODE_READONLY(4, SNMP_ASN1_TYPE_INTEGER, tcp_get_value);
512static const struct snmp_scalar_node tcp_ActiveOpens = SNMP_SCALAR_CREATE_NODE_READONLY(5, SNMP_ASN1_TYPE_COUNTER, tcp_get_value);
513static const struct snmp_scalar_node tcp_PassiveOpens = SNMP_SCALAR_CREATE_NODE_READONLY(6, SNMP_ASN1_TYPE_COUNTER, tcp_get_value);
514static const struct snmp_scalar_node tcp_AttemptFails = SNMP_SCALAR_CREATE_NODE_READONLY(7, SNMP_ASN1_TYPE_COUNTER, tcp_get_value);
515static const struct snmp_scalar_node tcp_EstabResets = SNMP_SCALAR_CREATE_NODE_READONLY(8, SNMP_ASN1_TYPE_COUNTER, tcp_get_value);
516static const struct snmp_scalar_node tcp_CurrEstab = SNMP_SCALAR_CREATE_NODE_READONLY(9, SNMP_ASN1_TYPE_GAUGE, tcp_get_value);
517static const struct snmp_scalar_node tcp_InSegs = SNMP_SCALAR_CREATE_NODE_READONLY(10, SNMP_ASN1_TYPE_COUNTER, tcp_get_value);
518static const struct snmp_scalar_node tcp_OutSegs = SNMP_SCALAR_CREATE_NODE_READONLY(11, SNMP_ASN1_TYPE_COUNTER, tcp_get_value);
519static const struct snmp_scalar_node tcp_RetransSegs = SNMP_SCALAR_CREATE_NODE_READONLY(12, SNMP_ASN1_TYPE_COUNTER, tcp_get_value);
520static const struct snmp_scalar_node tcp_InErrs = SNMP_SCALAR_CREATE_NODE_READONLY(14, SNMP_ASN1_TYPE_COUNTER, tcp_get_value);
521static const struct snmp_scalar_node tcp_OutRsts = SNMP_SCALAR_CREATE_NODE_READONLY(15, SNMP_ASN1_TYPE_COUNTER, tcp_get_value);
522#if LWIP_HAVE_INT64
523static const struct snmp_scalar_node tcp_HCInSegs = SNMP_SCALAR_CREATE_NODE_READONLY(17, SNMP_ASN1_TYPE_COUNTER64, tcp_get_value);
524static const struct snmp_scalar_node tcp_HCOutSegs = SNMP_SCALAR_CREATE_NODE_READONLY(18, SNMP_ASN1_TYPE_COUNTER64, tcp_get_value);
525#endif
526
527#if LWIP_IPV4
528static const struct snmp_table_simple_col_def tcp_ConnTable_columns[] = {
529 { 1, SNMP_ASN1_TYPE_INTEGER, SNMP_VARIANT_VALUE_TYPE_U32 }, /* tcpConnState */
530 { 2, SNMP_ASN1_TYPE_IPADDR, SNMP_VARIANT_VALUE_TYPE_U32 }, /* tcpConnLocalAddress */
531 { 3, SNMP_ASN1_TYPE_INTEGER, SNMP_VARIANT_VALUE_TYPE_U32 }, /* tcpConnLocalPort */
532 { 4, SNMP_ASN1_TYPE_IPADDR, SNMP_VARIANT_VALUE_TYPE_U32 }, /* tcpConnRemAddress */
533 { 5, SNMP_ASN1_TYPE_INTEGER, SNMP_VARIANT_VALUE_TYPE_U32 } /* tcpConnRemPort */
534};
535
536static const struct snmp_table_simple_node tcp_ConnTable = SNMP_TABLE_CREATE_SIMPLE(13, tcp_ConnTable_columns, tcp_ConnTable_get_cell_value, tcp_ConnTable_get_next_cell_instance_and_value);
537#endif /* LWIP_IPV4 */
538
539static const struct snmp_table_simple_col_def tcp_ConnectionTable_columns[] = {
540 /* all items except tcpConnectionState and tcpConnectionProcess are declared as not-accessible */
541 { 7, SNMP_ASN1_TYPE_INTEGER, SNMP_VARIANT_VALUE_TYPE_U32 }, /* tcpConnectionState */
542 { 8, SNMP_ASN1_TYPE_UNSIGNED32, SNMP_VARIANT_VALUE_TYPE_U32 } /* tcpConnectionProcess */
543};
544
545static const struct snmp_table_simple_node tcp_ConnectionTable = SNMP_TABLE_CREATE_SIMPLE(19, tcp_ConnectionTable_columns, tcp_ConnectionTable_get_cell_value, tcp_ConnectionTable_get_next_cell_instance_and_value);
546
547
548static const struct snmp_table_simple_col_def tcp_ListenerTable_columns[] = {
549 /* all items except tcpListenerProcess are declared as not-accessible */
550 { 4, SNMP_ASN1_TYPE_UNSIGNED32, SNMP_VARIANT_VALUE_TYPE_U32 } /* tcpListenerProcess */
551};
552
553static const struct snmp_table_simple_node tcp_ListenerTable = SNMP_TABLE_CREATE_SIMPLE(20, tcp_ListenerTable_columns, tcp_ListenerTable_get_cell_value, tcp_ListenerTable_get_next_cell_instance_and_value);
554
555/* the following nodes access variables in LWIP stack from SNMP worker thread and must therefore be synced to LWIP (TCPIP) thread */
556CREATE_LWIP_SYNC_NODE( 1, tcp_RtoAlgorithm)
557CREATE_LWIP_SYNC_NODE( 2, tcp_RtoMin)
558CREATE_LWIP_SYNC_NODE( 3, tcp_RtoMax)
559CREATE_LWIP_SYNC_NODE( 4, tcp_MaxConn)
560CREATE_LWIP_SYNC_NODE( 5, tcp_ActiveOpens)
561CREATE_LWIP_SYNC_NODE( 6, tcp_PassiveOpens)
562CREATE_LWIP_SYNC_NODE( 7, tcp_AttemptFails)
563CREATE_LWIP_SYNC_NODE( 8, tcp_EstabResets)
564CREATE_LWIP_SYNC_NODE( 9, tcp_CurrEstab)
565CREATE_LWIP_SYNC_NODE(10, tcp_InSegs)
566CREATE_LWIP_SYNC_NODE(11, tcp_OutSegs)
567CREATE_LWIP_SYNC_NODE(12, tcp_RetransSegs)
568#if LWIP_IPV4
569CREATE_LWIP_SYNC_NODE(13, tcp_ConnTable)
570#endif /* LWIP_IPV4 */
571CREATE_LWIP_SYNC_NODE(14, tcp_InErrs)
572CREATE_LWIP_SYNC_NODE(15, tcp_OutRsts)
573#if LWIP_HAVE_INT64
574CREATE_LWIP_SYNC_NODE(17, tcp_HCInSegs)
575CREATE_LWIP_SYNC_NODE(18, tcp_HCOutSegs)
576#endif
577CREATE_LWIP_SYNC_NODE(19, tcp_ConnectionTable)
578CREATE_LWIP_SYNC_NODE(20, tcp_ListenerTable)
579
580static const struct snmp_node *const tcp_nodes[] = {
581 &SYNC_NODE_NAME(tcp_RtoAlgorithm).node.node,
582 &SYNC_NODE_NAME(tcp_RtoMin).node.node,
583 &SYNC_NODE_NAME(tcp_RtoMax).node.node,
584 &SYNC_NODE_NAME(tcp_MaxConn).node.node,
585 &SYNC_NODE_NAME(tcp_ActiveOpens).node.node,
586 &SYNC_NODE_NAME(tcp_PassiveOpens).node.node,
587 &SYNC_NODE_NAME(tcp_AttemptFails).node.node,
588 &SYNC_NODE_NAME(tcp_EstabResets).node.node,
589 &SYNC_NODE_NAME(tcp_CurrEstab).node.node,
590 &SYNC_NODE_NAME(tcp_InSegs).node.node,
591 &SYNC_NODE_NAME(tcp_OutSegs).node.node,
592 &SYNC_NODE_NAME(tcp_RetransSegs).node.node,
593#if LWIP_IPV4
594 &SYNC_NODE_NAME(tcp_ConnTable).node.node,
595#endif /* LWIP_IPV4 */
596 &SYNC_NODE_NAME(tcp_InErrs).node.node,
597 &SYNC_NODE_NAME(tcp_OutRsts).node.node,
598 &SYNC_NODE_NAME(tcp_HCInSegs).node.node,
599#if LWIP_HAVE_INT64
600 &SYNC_NODE_NAME(tcp_HCOutSegs).node.node,
601 &SYNC_NODE_NAME(tcp_ConnectionTable).node.node,
602#endif
603 &SYNC_NODE_NAME(tcp_ListenerTable).node.node
604};
605
606const struct snmp_tree_node snmp_mib2_tcp_root = SNMP_CREATE_TREE_NODE(6, tcp_nodes);
607#endif /* LWIP_SNMP && SNMP_LWIP_MIB2 && LWIP_TCP */
Note: See TracBrowser for help on using the repository browser.