1195972f6Sopenharmony_ci/**
2195972f6Sopenharmony_ci * @file
3195972f6Sopenharmony_ci * Management Information Base II (RFC1213) ICMP objects and functions.
4195972f6Sopenharmony_ci */
5195972f6Sopenharmony_ci
6195972f6Sopenharmony_ci/*
7195972f6Sopenharmony_ci * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
8195972f6Sopenharmony_ci * All rights reserved.
9195972f6Sopenharmony_ci *
10195972f6Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification,
11195972f6Sopenharmony_ci * are permitted provided that the following conditions are met:
12195972f6Sopenharmony_ci *
13195972f6Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice,
14195972f6Sopenharmony_ci *    this list of conditions and the following disclaimer.
15195972f6Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice,
16195972f6Sopenharmony_ci *    this list of conditions and the following disclaimer in the documentation
17195972f6Sopenharmony_ci *    and/or other materials provided with the distribution.
18195972f6Sopenharmony_ci * 3. The name of the author may not be used to endorse or promote products
19195972f6Sopenharmony_ci *    derived from this software without specific prior written permission.
20195972f6Sopenharmony_ci *
21195972f6Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22195972f6Sopenharmony_ci * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23195972f6Sopenharmony_ci * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24195972f6Sopenharmony_ci * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25195972f6Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26195972f6Sopenharmony_ci * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27195972f6Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28195972f6Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29195972f6Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30195972f6Sopenharmony_ci * OF SUCH DAMAGE.
31195972f6Sopenharmony_ci *
32195972f6Sopenharmony_ci * Author: Dirk Ziegelmeier <dziegel@gmx.de>
33195972f6Sopenharmony_ci *         Christiaan Simons <christiaan.simons@axon.tv>
34195972f6Sopenharmony_ci */
35195972f6Sopenharmony_ci
36195972f6Sopenharmony_ci#include "lwip/snmp.h"
37195972f6Sopenharmony_ci#include "lwip/apps/snmp.h"
38195972f6Sopenharmony_ci#include "lwip/apps/snmp_core.h"
39195972f6Sopenharmony_ci#include "lwip/apps/snmp_mib2.h"
40195972f6Sopenharmony_ci#include "lwip/apps/snmp_table.h"
41195972f6Sopenharmony_ci#include "lwip/apps/snmp_scalar.h"
42195972f6Sopenharmony_ci#include "lwip/icmp.h"
43195972f6Sopenharmony_ci#include "lwip/stats.h"
44195972f6Sopenharmony_ci
45195972f6Sopenharmony_ci#if LWIP_SNMP && SNMP_LWIP_MIB2 && LWIP_ICMP
46195972f6Sopenharmony_ci
47195972f6Sopenharmony_ci#if SNMP_USE_NETCONN
48195972f6Sopenharmony_ci#define SYNC_NODE_NAME(node_name) node_name ## _synced
49195972f6Sopenharmony_ci#define CREATE_LWIP_SYNC_NODE(oid, node_name) \
50195972f6Sopenharmony_ci   static const struct snmp_threadsync_node node_name ## _synced = SNMP_CREATE_THREAD_SYNC_NODE(oid, &node_name.node, &snmp_mib2_lwip_locks);
51195972f6Sopenharmony_ci#else
52195972f6Sopenharmony_ci#define SYNC_NODE_NAME(node_name) node_name
53195972f6Sopenharmony_ci#define CREATE_LWIP_SYNC_NODE(oid, node_name)
54195972f6Sopenharmony_ci#endif
55195972f6Sopenharmony_ci
56195972f6Sopenharmony_ci/* --- icmp .1.3.6.1.2.1.5 ----------------------------------------------------- */
57195972f6Sopenharmony_ci
58195972f6Sopenharmony_cistatic s16_t
59195972f6Sopenharmony_ciicmp_get_value(const struct snmp_scalar_array_node_def *node, void *value)
60195972f6Sopenharmony_ci{
61195972f6Sopenharmony_ci  u32_t *uint_ptr = (u32_t *)value;
62195972f6Sopenharmony_ci
63195972f6Sopenharmony_ci  switch (node->oid) {
64195972f6Sopenharmony_ci    case 1: /* icmpInMsgs */
65195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpinmsgs);
66195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
67195972f6Sopenharmony_ci    case 2: /* icmpInErrors */
68195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpinerrors);
69195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
70195972f6Sopenharmony_ci    case 3: /* icmpInDestUnreachs */
71195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpindestunreachs);
72195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
73195972f6Sopenharmony_ci    case 4: /* icmpInTimeExcds */
74195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpintimeexcds);
75195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
76195972f6Sopenharmony_ci    case 5: /* icmpInParmProbs */
77195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpinparmprobs);
78195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
79195972f6Sopenharmony_ci    case 6: /* icmpInSrcQuenchs */
80195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpinsrcquenchs);
81195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
82195972f6Sopenharmony_ci    case 7: /* icmpInRedirects */
83195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpinredirects);
84195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
85195972f6Sopenharmony_ci    case 8: /* icmpInEchos */
86195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpinechos);
87195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
88195972f6Sopenharmony_ci    case 9: /* icmpInEchoReps */
89195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpinechoreps);
90195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
91195972f6Sopenharmony_ci    case 10: /* icmpInTimestamps */
92195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpintimestamps);
93195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
94195972f6Sopenharmony_ci    case 11: /* icmpInTimestampReps */
95195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpintimestampreps);
96195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
97195972f6Sopenharmony_ci    case 12: /* icmpInAddrMasks */
98195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpinaddrmasks);
99195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
100195972f6Sopenharmony_ci    case 13: /* icmpInAddrMaskReps */
101195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpinaddrmaskreps);
102195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
103195972f6Sopenharmony_ci    case 14: /* icmpOutMsgs */
104195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpoutmsgs);
105195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
106195972f6Sopenharmony_ci    case 15: /* icmpOutErrors */
107195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpouterrors);
108195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
109195972f6Sopenharmony_ci    case 16: /* icmpOutDestUnreachs */
110195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpoutdestunreachs);
111195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
112195972f6Sopenharmony_ci    case 17: /* icmpOutTimeExcds */
113195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpouttimeexcds);
114195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
115195972f6Sopenharmony_ci    case 18: /* icmpOutParmProbs: not supported -> always 0 */
116195972f6Sopenharmony_ci      *uint_ptr = 0;
117195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
118195972f6Sopenharmony_ci    case 19: /* icmpOutSrcQuenchs: not supported -> always 0 */
119195972f6Sopenharmony_ci      *uint_ptr = 0;
120195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
121195972f6Sopenharmony_ci    case 20: /* icmpOutRedirects: not supported -> always 0 */
122195972f6Sopenharmony_ci      *uint_ptr = 0;
123195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
124195972f6Sopenharmony_ci    case 21: /* icmpOutEchos */
125195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpoutechos);
126195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
127195972f6Sopenharmony_ci    case 22: /* icmpOutEchoReps */
128195972f6Sopenharmony_ci      *uint_ptr = STATS_GET(mib2.icmpoutechoreps);
129195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
130195972f6Sopenharmony_ci    case 23: /* icmpOutTimestamps: not supported -> always 0 */
131195972f6Sopenharmony_ci      *uint_ptr = 0;
132195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
133195972f6Sopenharmony_ci    case 24: /* icmpOutTimestampReps: not supported -> always 0 */
134195972f6Sopenharmony_ci      *uint_ptr = 0;
135195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
136195972f6Sopenharmony_ci    case 25: /* icmpOutAddrMasks: not supported -> always 0 */
137195972f6Sopenharmony_ci      *uint_ptr = 0;
138195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
139195972f6Sopenharmony_ci    case 26: /* icmpOutAddrMaskReps: not supported -> always 0 */
140195972f6Sopenharmony_ci      *uint_ptr = 0;
141195972f6Sopenharmony_ci      return sizeof(*uint_ptr);
142195972f6Sopenharmony_ci    default:
143195972f6Sopenharmony_ci      LWIP_DEBUGF(SNMP_MIB_DEBUG, ("icmp_get_value(): unknown id: %"S32_F"\n", node->oid));
144195972f6Sopenharmony_ci      break;
145195972f6Sopenharmony_ci  }
146195972f6Sopenharmony_ci
147195972f6Sopenharmony_ci  return 0;
148195972f6Sopenharmony_ci}
149195972f6Sopenharmony_ci
150195972f6Sopenharmony_ci
151195972f6Sopenharmony_cistatic const struct snmp_scalar_array_node_def icmp_nodes[] = {
152195972f6Sopenharmony_ci  { 1, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
153195972f6Sopenharmony_ci  { 2, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
154195972f6Sopenharmony_ci  { 3, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
155195972f6Sopenharmony_ci  { 4, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
156195972f6Sopenharmony_ci  { 5, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
157195972f6Sopenharmony_ci  { 6, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
158195972f6Sopenharmony_ci  { 7, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
159195972f6Sopenharmony_ci  { 8, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
160195972f6Sopenharmony_ci  { 9, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
161195972f6Sopenharmony_ci  {10, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
162195972f6Sopenharmony_ci  {11, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
163195972f6Sopenharmony_ci  {12, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
164195972f6Sopenharmony_ci  {13, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
165195972f6Sopenharmony_ci  {14, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
166195972f6Sopenharmony_ci  {15, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
167195972f6Sopenharmony_ci  {16, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
168195972f6Sopenharmony_ci  {17, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
169195972f6Sopenharmony_ci  {18, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
170195972f6Sopenharmony_ci  {19, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
171195972f6Sopenharmony_ci  {20, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
172195972f6Sopenharmony_ci  {21, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
173195972f6Sopenharmony_ci  {22, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
174195972f6Sopenharmony_ci  {23, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
175195972f6Sopenharmony_ci  {24, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
176195972f6Sopenharmony_ci  {25, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
177195972f6Sopenharmony_ci  {26, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}
178195972f6Sopenharmony_ci};
179195972f6Sopenharmony_ci
180195972f6Sopenharmony_ciconst struct snmp_scalar_array_node snmp_mib2_icmp_root = SNMP_SCALAR_CREATE_ARRAY_NODE(5, icmp_nodes, icmp_get_value, NULL, NULL);
181195972f6Sopenharmony_ci
182195972f6Sopenharmony_ci#endif /* LWIP_SNMP && SNMP_LWIP_MIB2 && LWIP_ICMP */
183