A version of LWIP, provided for backwards compatibility.
Dependents: AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more
mib2.c
00001 /** 00002 * @file 00003 * Management Information Base II (RFC1213) objects and functions. 00004 * 00005 * @note the object identifiers for this MIB-2 and private MIB tree 00006 * must be kept in sorted ascending order. This to ensure correct getnext operation. 00007 */ 00008 00009 /* 00010 * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands. 00011 * All rights reserved. 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 2. Redistributions in binary form must reproduce the above copyright notice, 00019 * this list of conditions and the following disclaimer in the documentation 00020 * and/or other materials provided with the distribution. 00021 * 3. The name of the author may not be used to endorse or promote products 00022 * derived from this software without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00025 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00026 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00027 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00028 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00029 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00030 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00031 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00032 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00033 * OF SUCH DAMAGE. 00034 * 00035 * Author: Christiaan Simons <christiaan.simons@axon.tv> 00036 */ 00037 00038 #include "lwip/opt.h" 00039 00040 #if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */ 00041 00042 #include "lwip/snmp.h" 00043 #include "lwip/netif.h" 00044 #include "lwip/ip.h" 00045 #include "lwip/ip_frag.h" 00046 #include "lwip/tcp.h" 00047 #include "lwip/udp.h" 00048 #include "lwip/snmp_asn1.h" 00049 #include "lwip/snmp_structs.h" 00050 #include "netif/etharp.h" 00051 00052 /** 00053 * IANA assigned enterprise ID for lwIP is 26381 00054 * @see http://www.iana.org/assignments/enterprise-numbers 00055 * 00056 * @note this enterprise ID is assigned to the lwIP project, 00057 * all object identifiers living under this ID are assigned 00058 * by the lwIP maintainers (contact Christiaan Simons)! 00059 * @note don't change this define, use snmp_set_sysobjid() 00060 * 00061 * If you need to create your own private MIB you'll need 00062 * to apply for your own enterprise ID with IANA: 00063 * http://www.iana.org/numbers.html 00064 */ 00065 #define SNMP_ENTERPRISE_ID 26381 00066 #define SNMP_SYSOBJID_LEN 7 00067 #define SNMP_SYSOBJID {1, 3, 6, 1, 4, 1, SNMP_ENTERPRISE_ID} 00068 00069 #ifndef SNMP_SYSSERVICES 00070 #define SNMP_SYSSERVICES ((1 << 6) | (1 << 3) | ((IP_FORWARD) << 2)) 00071 #endif 00072 00073 #ifndef SNMP_GET_SYSUPTIME 00074 #define SNMP_GET_SYSUPTIME(sysuptime) 00075 #endif 00076 00077 static void system_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od); 00078 static void system_get_value(struct obj_def *od, u16_t len, void *value); 00079 static u8_t system_set_test(struct obj_def *od, u16_t len, void *value); 00080 static void system_set_value(struct obj_def *od, u16_t len, void *value); 00081 static void interfaces_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od); 00082 static void interfaces_get_value(struct obj_def *od, u16_t len, void *value); 00083 static void ifentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od); 00084 static void ifentry_get_value(struct obj_def *od, u16_t len, void *value); 00085 #if !SNMP_SAFE_REQUESTS 00086 static u8_t ifentry_set_test (struct obj_def *od, u16_t len, void *value); 00087 static void ifentry_set_value (struct obj_def *od, u16_t len, void *value); 00088 #endif /* SNMP_SAFE_REQUESTS */ 00089 static void atentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od); 00090 static void atentry_get_value(struct obj_def *od, u16_t len, void *value); 00091 static void ip_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od); 00092 static void ip_get_value (struct obj_def *od, u16_t len, void *value); 00093 static u8_t ip_set_test(struct obj_def *od, u16_t len, void *value); 00094 static void ip_addrentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od); 00095 static void ip_addrentry_get_value (struct obj_def *od, u16_t len, void *value); 00096 static void ip_rteentry_get_object_def (u8_t ident_len, s32_t *ident, struct obj_def *od); 00097 static void ip_rteentry_get_value (struct obj_def *od, u16_t len, void *value); 00098 static void ip_ntomentry_get_object_def (u8_t ident_len, s32_t *ident, struct obj_def *od); 00099 static void ip_ntomentry_get_value(struct obj_def *od, u16_t len, void *value); 00100 static void icmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od); 00101 static void icmp_get_value(struct obj_def *od, u16_t len, void *value); 00102 #if LWIP_TCP 00103 static void tcp_get_object_def (u8_t ident_len, s32_t *ident, struct obj_def *od); 00104 static void tcp_get_value(struct obj_def *od, u16_t len, void *value); 00105 #ifdef THIS_SEEMS_UNUSED 00106 static void tcpconnentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od); 00107 static void tcpconnentry_get_value (struct obj_def *od, u16_t len, void *value); 00108 #endif 00109 #endif 00110 static void udp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od); 00111 static void udp_get_value(struct obj_def *od, u16_t len, void *value); 00112 static void udpentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od); 00113 static void udpentry_get_value(struct obj_def *od, u16_t len, void *value); 00114 static void snmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od); 00115 static void snmp_get_value(struct obj_def *od, u16_t len, void *value); 00116 static u8_t snmp_set_test(struct obj_def *od, u16_t len, void *value); 00117 static void snmp_set_value(struct obj_def *od, u16_t len, void *value); 00118 00119 00120 /* snmp .1.3.6.1.2.1.11 */ 00121 const mib_scalar_node snmp_scalar = { 00122 &snmp_get_object_def, 00123 &snmp_get_value, 00124 &snmp_set_test, 00125 &snmp_set_value, 00126 MIB_NODE_SC, 00127 0 00128 }; 00129 const s32_t snmp_ids[28] = { 00130 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 00131 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30 00132 }; 00133 struct mib_node* const snmp_nodes[28] = { 00134 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar, 00135 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar, 00136 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar, 00137 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar, 00138 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar, 00139 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar, 00140 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar, 00141 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar, 00142 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar, 00143 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar, 00144 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar, 00145 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar, 00146 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar, 00147 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar 00148 }; 00149 const struct mib_array_node snmp = { 00150 &noleafs_get_object_def, 00151 &noleafs_get_value, 00152 &noleafs_set_test, 00153 &noleafs_set_value, 00154 MIB_NODE_AR, 00155 28, 00156 snmp_ids, 00157 snmp_nodes 00158 }; 00159 00160 /* dot3 and EtherLike MIB not planned. (transmission .1.3.6.1.2.1.10) */ 00161 /* historical (some say hysterical). (cmot .1.3.6.1.2.1.9) */ 00162 /* lwIP has no EGP, thus may not implement it. (egp .1.3.6.1.2.1.8) */ 00163 00164 /* udp .1.3.6.1.2.1.7 */ 00165 /** index root node for udpTable */ 00166 struct mib_list_rootnode udp_root = { 00167 &noleafs_get_object_def, 00168 &noleafs_get_value, 00169 &noleafs_set_test, 00170 &noleafs_set_value, 00171 MIB_NODE_LR, 00172 0, 00173 NULL, 00174 NULL, 00175 0 00176 }; 00177 const s32_t udpentry_ids[2] = { 1, 2 }; 00178 struct mib_node* const udpentry_nodes[2] = { 00179 (struct mib_node* const)&udp_root, (struct mib_node* const)&udp_root, 00180 }; 00181 const struct mib_array_node udpentry = { 00182 &noleafs_get_object_def, 00183 &noleafs_get_value, 00184 &noleafs_set_test, 00185 &noleafs_set_value, 00186 MIB_NODE_AR, 00187 2, 00188 udpentry_ids, 00189 udpentry_nodes 00190 }; 00191 00192 s32_t udptable_id = 1; 00193 struct mib_node* udptable_node = (struct mib_node* const)&udpentry; 00194 struct mib_ram_array_node udptable = { 00195 &noleafs_get_object_def, 00196 &noleafs_get_value, 00197 &noleafs_set_test, 00198 &noleafs_set_value, 00199 MIB_NODE_RA, 00200 0, 00201 &udptable_id, 00202 &udptable_node 00203 }; 00204 00205 const mib_scalar_node udp_scalar = { 00206 &udp_get_object_def, 00207 &udp_get_value, 00208 &noleafs_set_test, 00209 &noleafs_set_value, 00210 MIB_NODE_SC, 00211 0 00212 }; 00213 const s32_t udp_ids[5] = { 1, 2, 3, 4, 5 }; 00214 struct mib_node* const udp_nodes[5] = { 00215 (struct mib_node* const)&udp_scalar, (struct mib_node* const)&udp_scalar, 00216 (struct mib_node* const)&udp_scalar, (struct mib_node* const)&udp_scalar, 00217 (struct mib_node* const)&udptable 00218 }; 00219 const struct mib_array_node udp = { 00220 &noleafs_get_object_def, 00221 &noleafs_get_value, 00222 &noleafs_set_test, 00223 &noleafs_set_value, 00224 MIB_NODE_AR, 00225 5, 00226 udp_ids, 00227 udp_nodes 00228 }; 00229 00230 /* tcp .1.3.6.1.2.1.6 */ 00231 #if LWIP_TCP 00232 /* only if the TCP protocol is available may implement this group */ 00233 /** index root node for tcpConnTable */ 00234 struct mib_list_rootnode tcpconntree_root = { 00235 &noleafs_get_object_def, 00236 &noleafs_get_value, 00237 &noleafs_set_test, 00238 &noleafs_set_value, 00239 MIB_NODE_LR, 00240 0, 00241 NULL, 00242 NULL, 00243 0 00244 }; 00245 const s32_t tcpconnentry_ids[5] = { 1, 2, 3, 4, 5 }; 00246 struct mib_node* const tcpconnentry_nodes[5] = { 00247 (struct mib_node* const)&tcpconntree_root, (struct mib_node* const)&tcpconntree_root, 00248 (struct mib_node* const)&tcpconntree_root, (struct mib_node* const)&tcpconntree_root, 00249 (struct mib_node* const)&tcpconntree_root 00250 }; 00251 const struct mib_array_node tcpconnentry = { 00252 &noleafs_get_object_def, 00253 &noleafs_get_value, 00254 &noleafs_set_test, 00255 &noleafs_set_value, 00256 MIB_NODE_AR, 00257 5, 00258 tcpconnentry_ids, 00259 tcpconnentry_nodes 00260 }; 00261 00262 s32_t tcpconntable_id = 1; 00263 struct mib_node* tcpconntable_node = (struct mib_node* const)&tcpconnentry; 00264 struct mib_ram_array_node tcpconntable = { 00265 &noleafs_get_object_def, 00266 &noleafs_get_value, 00267 &noleafs_set_test, 00268 &noleafs_set_value, 00269 MIB_NODE_RA, 00270 /** @todo update maxlength when inserting / deleting from table 00271 0 when table is empty, 1 when more than one entry */ 00272 0, 00273 &tcpconntable_id, 00274 &tcpconntable_node 00275 }; 00276 00277 const mib_scalar_node tcp_scalar = { 00278 &tcp_get_object_def , 00279 &tcp_get_value, 00280 &noleafs_set_test, 00281 &noleafs_set_value, 00282 MIB_NODE_SC, 00283 0 00284 }; 00285 const s32_t tcp_ids[15] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; 00286 struct mib_node* const tcp_nodes[15] = { 00287 (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar, 00288 (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar, 00289 (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar, 00290 (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar, 00291 (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar, 00292 (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar, 00293 (struct mib_node* const)&tcpconntable, (struct mib_node* const)&tcp_scalar, 00294 (struct mib_node* const)&tcp_scalar 00295 }; 00296 const struct mib_array_node tcp = { 00297 &noleafs_get_object_def, 00298 &noleafs_get_value, 00299 &noleafs_set_test, 00300 &noleafs_set_value, 00301 MIB_NODE_AR, 00302 15, 00303 tcp_ids, 00304 tcp_nodes 00305 }; 00306 #endif 00307 00308 /* icmp .1.3.6.1.2.1.5 */ 00309 const mib_scalar_node icmp_scalar = { 00310 &icmp_get_object_def, 00311 &icmp_get_value, 00312 &noleafs_set_test, 00313 &noleafs_set_value, 00314 MIB_NODE_SC, 00315 0 00316 }; 00317 const s32_t icmp_ids[26] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 }; 00318 struct mib_node* const icmp_nodes[26] = { 00319 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar, 00320 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar, 00321 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar, 00322 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar, 00323 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar, 00324 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar, 00325 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar, 00326 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar, 00327 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar, 00328 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar, 00329 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar, 00330 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar, 00331 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar 00332 }; 00333 const struct mib_array_node icmp = { 00334 &noleafs_get_object_def, 00335 &noleafs_get_value, 00336 &noleafs_set_test, 00337 &noleafs_set_value, 00338 MIB_NODE_AR, 00339 26, 00340 icmp_ids, 00341 icmp_nodes 00342 }; 00343 00344 /** index root node for ipNetToMediaTable */ 00345 struct mib_list_rootnode ipntomtree_root = { 00346 &noleafs_get_object_def, 00347 &noleafs_get_value, 00348 &noleafs_set_test, 00349 &noleafs_set_value, 00350 MIB_NODE_LR, 00351 0, 00352 NULL, 00353 NULL, 00354 0 00355 }; 00356 const s32_t ipntomentry_ids[4] = { 1, 2, 3, 4 }; 00357 struct mib_node* const ipntomentry_nodes[4] = { 00358 (struct mib_node* const)&ipntomtree_root, (struct mib_node* const)&ipntomtree_root, 00359 (struct mib_node* const)&ipntomtree_root, (struct mib_node* const)&ipntomtree_root 00360 }; 00361 const struct mib_array_node ipntomentry = { 00362 &noleafs_get_object_def, 00363 &noleafs_get_value, 00364 &noleafs_set_test, 00365 &noleafs_set_value, 00366 MIB_NODE_AR, 00367 4, 00368 ipntomentry_ids, 00369 ipntomentry_nodes 00370 }; 00371 00372 s32_t ipntomtable_id = 1; 00373 struct mib_node* ipntomtable_node = (struct mib_node* const)&ipntomentry; 00374 struct mib_ram_array_node ipntomtable = { 00375 &noleafs_get_object_def, 00376 &noleafs_get_value, 00377 &noleafs_set_test, 00378 &noleafs_set_value, 00379 MIB_NODE_RA, 00380 0, 00381 &ipntomtable_id, 00382 &ipntomtable_node 00383 }; 00384 00385 /** index root node for ipRouteTable */ 00386 struct mib_list_rootnode iprtetree_root = { 00387 &noleafs_get_object_def, 00388 &noleafs_get_value, 00389 &noleafs_set_test, 00390 &noleafs_set_value, 00391 MIB_NODE_LR, 00392 0, 00393 NULL, 00394 NULL, 00395 0 00396 }; 00397 const s32_t iprteentry_ids[13] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }; 00398 struct mib_node* const iprteentry_nodes[13] = { 00399 (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root, 00400 (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root, 00401 (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root, 00402 (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root, 00403 (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root, 00404 (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root, 00405 (struct mib_node* const)&iprtetree_root 00406 }; 00407 const struct mib_array_node iprteentry = { 00408 &noleafs_get_object_def, 00409 &noleafs_get_value, 00410 &noleafs_set_test, 00411 &noleafs_set_value, 00412 MIB_NODE_AR, 00413 13, 00414 iprteentry_ids, 00415 iprteentry_nodes 00416 }; 00417 00418 s32_t iprtetable_id = 1; 00419 struct mib_node* iprtetable_node = (struct mib_node* const)&iprteentry; 00420 struct mib_ram_array_node iprtetable = { 00421 &noleafs_get_object_def, 00422 &noleafs_get_value, 00423 &noleafs_set_test, 00424 &noleafs_set_value, 00425 MIB_NODE_RA, 00426 0, 00427 &iprtetable_id, 00428 &iprtetable_node 00429 }; 00430 00431 /** index root node for ipAddrTable */ 00432 struct mib_list_rootnode ipaddrtree_root = { 00433 &noleafs_get_object_def, 00434 &noleafs_get_value, 00435 &noleafs_set_test, 00436 &noleafs_set_value, 00437 MIB_NODE_LR, 00438 0, 00439 NULL, 00440 NULL, 00441 0 00442 }; 00443 const s32_t ipaddrentry_ids[5] = { 1, 2, 3, 4, 5 }; 00444 struct mib_node* const ipaddrentry_nodes[5] = { 00445 (struct mib_node* const)&ipaddrtree_root, 00446 (struct mib_node* const)&ipaddrtree_root, 00447 (struct mib_node* const)&ipaddrtree_root, 00448 (struct mib_node* const)&ipaddrtree_root, 00449 (struct mib_node* const)&ipaddrtree_root 00450 }; 00451 const struct mib_array_node ipaddrentry = { 00452 &noleafs_get_object_def, 00453 &noleafs_get_value, 00454 &noleafs_set_test, 00455 &noleafs_set_value, 00456 MIB_NODE_AR, 00457 5, 00458 ipaddrentry_ids, 00459 ipaddrentry_nodes 00460 }; 00461 00462 s32_t ipaddrtable_id = 1; 00463 struct mib_node* ipaddrtable_node = (struct mib_node* const)&ipaddrentry; 00464 struct mib_ram_array_node ipaddrtable = { 00465 &noleafs_get_object_def, 00466 &noleafs_get_value, 00467 &noleafs_set_test, 00468 &noleafs_set_value, 00469 MIB_NODE_RA, 00470 0, 00471 &ipaddrtable_id, 00472 &ipaddrtable_node 00473 }; 00474 00475 /* ip .1.3.6.1.2.1.4 */ 00476 const mib_scalar_node ip_scalar = { 00477 &ip_get_object_def, 00478 &ip_get_value , 00479 &ip_set_test, 00480 &noleafs_set_value, 00481 MIB_NODE_SC, 00482 0 00483 }; 00484 const s32_t ip_ids[23] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }; 00485 struct mib_node* const ip_nodes[23] = { 00486 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar, 00487 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar, 00488 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar, 00489 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar, 00490 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar, 00491 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar, 00492 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar, 00493 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar, 00494 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar, 00495 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ipaddrtable, 00496 (struct mib_node* const)&iprtetable, (struct mib_node* const)&ipntomtable, 00497 (struct mib_node* const)&ip_scalar 00498 }; 00499 const struct mib_array_node mib2_ip = { 00500 &noleafs_get_object_def, 00501 &noleafs_get_value, 00502 &noleafs_set_test, 00503 &noleafs_set_value, 00504 MIB_NODE_AR, 00505 23, 00506 ip_ids, 00507 ip_nodes 00508 }; 00509 00510 /** index root node for atTable */ 00511 struct mib_list_rootnode arptree_root = { 00512 &noleafs_get_object_def, 00513 &noleafs_get_value, 00514 &noleafs_set_test, 00515 &noleafs_set_value, 00516 MIB_NODE_LR, 00517 0, 00518 NULL, 00519 NULL, 00520 0 00521 }; 00522 const s32_t atentry_ids[3] = { 1, 2, 3 }; 00523 struct mib_node* const atentry_nodes[3] = { 00524 (struct mib_node* const)&arptree_root, 00525 (struct mib_node* const)&arptree_root, 00526 (struct mib_node* const)&arptree_root 00527 }; 00528 const struct mib_array_node atentry = { 00529 &noleafs_get_object_def, 00530 &noleafs_get_value, 00531 &noleafs_set_test, 00532 &noleafs_set_value, 00533 MIB_NODE_AR, 00534 3, 00535 atentry_ids, 00536 atentry_nodes 00537 }; 00538 00539 const s32_t attable_id = 1; 00540 struct mib_node* const attable_node = (struct mib_node* const)&atentry; 00541 const struct mib_array_node attable = { 00542 &noleafs_get_object_def, 00543 &noleafs_get_value, 00544 &noleafs_set_test, 00545 &noleafs_set_value, 00546 MIB_NODE_AR, 00547 1, 00548 &attable_id, 00549 &attable_node 00550 }; 00551 00552 /* at .1.3.6.1.2.1.3 */ 00553 s32_t at_id = 1; 00554 struct mib_node* mib2_at_node = (struct mib_node* const)&attable; 00555 struct mib_ram_array_node at = { 00556 &noleafs_get_object_def, 00557 &noleafs_get_value, 00558 &noleafs_set_test, 00559 &noleafs_set_value, 00560 MIB_NODE_RA, 00561 0, 00562 &at_id, 00563 &mib2_at_node 00564 }; 00565 00566 /** index root node for ifTable */ 00567 struct mib_list_rootnode iflist_root = { 00568 &ifentry_get_object_def, 00569 &ifentry_get_value, 00570 #if SNMP_SAFE_REQUESTS 00571 &noleafs_set_test, 00572 &noleafs_set_value, 00573 #else /* SNMP_SAFE_REQUESTS */ 00574 &ifentry_set_test, 00575 &ifentry_set_value, 00576 #endif /* SNMP_SAFE_REQUESTS */ 00577 MIB_NODE_LR, 00578 0, 00579 NULL, 00580 NULL, 00581 0 00582 }; 00583 const s32_t ifentry_ids[22] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 }; 00584 struct mib_node* const ifentry_nodes[22] = { 00585 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root, 00586 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root, 00587 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root, 00588 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root, 00589 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root, 00590 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root, 00591 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root, 00592 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root, 00593 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root, 00594 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root, 00595 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root 00596 }; 00597 const struct mib_array_node ifentry = { 00598 &noleafs_get_object_def, 00599 &noleafs_get_value, 00600 &noleafs_set_test, 00601 &noleafs_set_value, 00602 MIB_NODE_AR, 00603 22, 00604 ifentry_ids, 00605 ifentry_nodes 00606 }; 00607 00608 s32_t iftable_id = 1; 00609 struct mib_node* iftable_node = (struct mib_node* const)&ifentry; 00610 struct mib_ram_array_node iftable = { 00611 &noleafs_get_object_def, 00612 &noleafs_get_value, 00613 &noleafs_set_test, 00614 &noleafs_set_value, 00615 MIB_NODE_RA, 00616 0, 00617 &iftable_id, 00618 &iftable_node 00619 }; 00620 00621 /* interfaces .1.3.6.1.2.1.2 */ 00622 const mib_scalar_node interfaces_scalar = { 00623 &interfaces_get_object_def, 00624 &interfaces_get_value, 00625 &noleafs_set_test, 00626 &noleafs_set_value, 00627 MIB_NODE_SC, 00628 0 00629 }; 00630 const s32_t interfaces_ids[2] = { 1, 2 }; 00631 struct mib_node* const interfaces_nodes[2] = { 00632 (struct mib_node* const)&interfaces_scalar, (struct mib_node* const)&iftable 00633 }; 00634 const struct mib_array_node interfaces = { 00635 &noleafs_get_object_def, 00636 &noleafs_get_value, 00637 &noleafs_set_test, 00638 &noleafs_set_value, 00639 MIB_NODE_AR, 00640 2, 00641 interfaces_ids, 00642 interfaces_nodes 00643 }; 00644 00645 00646 /* 0 1 2 3 4 5 6 */ 00647 /* system .1.3.6.1.2.1.1 */ 00648 const mib_scalar_node sys_tem_scalar = { 00649 &system_get_object_def, 00650 &system_get_value, 00651 &system_set_test, 00652 &system_set_value, 00653 MIB_NODE_SC, 00654 0 00655 }; 00656 const s32_t sys_tem_ids[7] = { 1, 2, 3, 4, 5, 6, 7 }; 00657 struct mib_node* const sys_tem_nodes[7] = { 00658 (struct mib_node* const)&sys_tem_scalar, (struct mib_node* const)&sys_tem_scalar, 00659 (struct mib_node* const)&sys_tem_scalar, (struct mib_node* const)&sys_tem_scalar, 00660 (struct mib_node* const)&sys_tem_scalar, (struct mib_node* const)&sys_tem_scalar, 00661 (struct mib_node* const)&sys_tem_scalar 00662 }; 00663 /* work around name issue with 'sys_tem', some compiler(s?) seem to reserve 'system' */ 00664 const struct mib_array_node sys_tem = { 00665 &noleafs_get_object_def, 00666 &noleafs_get_value, 00667 &noleafs_set_test, 00668 &noleafs_set_value, 00669 MIB_NODE_AR, 00670 7, 00671 sys_tem_ids, 00672 sys_tem_nodes 00673 }; 00674 00675 /* mib-2 .1.3.6.1.2.1 */ 00676 #if LWIP_TCP 00677 #define MIB2_GROUPS 8 00678 #else 00679 #define MIB2_GROUPS 7 00680 #endif 00681 const s32_t mib2_ids[MIB2_GROUPS] = 00682 { 00683 1, 00684 2, 00685 3, 00686 4, 00687 5, 00688 #if LWIP_TCP 00689 6, 00690 #endif 00691 7, 00692 11 00693 }; 00694 struct mib_node* const mib2_nodes[MIB2_GROUPS] = { 00695 (struct mib_node* const)&sys_tem, 00696 (struct mib_node* const)&interfaces, 00697 (struct mib_node* const)&at, 00698 (struct mib_node* const)&mib2_ip, 00699 (struct mib_node* const)&icmp, 00700 #if LWIP_TCP 00701 (struct mib_node* const)&tcp, 00702 #endif 00703 (struct mib_node* const)&udp, 00704 (struct mib_node* const)&snmp 00705 }; 00706 00707 const struct mib_array_node mib2 = { 00708 &noleafs_get_object_def, 00709 &noleafs_get_value, 00710 &noleafs_set_test, 00711 &noleafs_set_value, 00712 MIB_NODE_AR, 00713 MIB2_GROUPS, 00714 mib2_ids, 00715 mib2_nodes 00716 }; 00717 00718 /* mgmt .1.3.6.1.2 */ 00719 const s32_t mgmt_ids[1] = { 1 }; 00720 struct mib_node* const mgmt_nodes[1] = { (struct mib_node* const)&mib2 }; 00721 const struct mib_array_node mgmt = { 00722 &noleafs_get_object_def, 00723 &noleafs_get_value, 00724 &noleafs_set_test, 00725 &noleafs_set_value, 00726 MIB_NODE_AR, 00727 1, 00728 mgmt_ids, 00729 mgmt_nodes 00730 }; 00731 00732 /* internet .1.3.6.1 */ 00733 #if SNMP_PRIVATE_MIB 00734 s32_t internet_ids[2] = { 2, 4 }; 00735 struct mib_node* const internet_nodes[2] = { (struct mib_node* const)&mgmt, (struct mib_node* const)&private }; 00736 const struct mib_array_node internet = { 00737 &noleafs_get_object_def, 00738 &noleafs_get_value, 00739 &noleafs_set_test, 00740 &noleafs_set_value, 00741 MIB_NODE_AR, 00742 2, 00743 internet_ids, 00744 internet_nodes 00745 }; 00746 #else 00747 const s32_t internet_ids[1] = { 2 }; 00748 struct mib_node* const internet_nodes[1] = { (struct mib_node* const)&mgmt }; 00749 const struct mib_array_node internet = { 00750 &noleafs_get_object_def, 00751 &noleafs_get_value, 00752 &noleafs_set_test, 00753 &noleafs_set_value, 00754 MIB_NODE_AR, 00755 1, 00756 internet_ids, 00757 internet_nodes 00758 }; 00759 #endif 00760 00761 /** mib-2.system.sysObjectID */ 00762 static struct snmp_obj_id sysobjid = {SNMP_SYSOBJID_LEN, SNMP_SYSOBJID}; 00763 /** enterprise ID for generic TRAPs, .iso.org.dod.internet.mgmt.mib-2.snmp */ 00764 static struct snmp_obj_id snmpgrp_id = {7,{1,3,6,1,2,1,11}}; 00765 /** mib-2.system.sysServices */ 00766 static const s32_t sysservices = SNMP_SYSSERVICES; 00767 00768 /** mib-2.system.sysDescr */ 00769 static const u8_t sysdescr_len_default = 4; 00770 static const u8_t sysdescr_default[] = "lwIP"; 00771 static u8_t* sysdescr_len_ptr = (u8_t*)&sysdescr_len_default; 00772 static u8_t* sysdescr_ptr = (u8_t*)&sysdescr_default[0]; 00773 /** mib-2.system.sysContact */ 00774 static const u8_t syscontact_len_default = 0; 00775 static const u8_t syscontact_default[] = ""; 00776 static u8_t* syscontact_len_ptr = (u8_t*)&syscontact_len_default; 00777 static u8_t* syscontact_ptr = (u8_t*)&syscontact_default[0]; 00778 /** mib-2.system.sysName */ 00779 static const u8_t sysname_len_default = 8; 00780 static const u8_t sysname_default[] = "FQDN-unk"; 00781 static u8_t* sysname_len_ptr = (u8_t*)&sysname_len_default; 00782 static u8_t* sysname_ptr = (u8_t*)&sysname_default[0]; 00783 /** mib-2.system.sysLocation */ 00784 static const u8_t syslocation_len_default = 0; 00785 static const u8_t syslocation_default[] = ""; 00786 static u8_t* syslocation_len_ptr = (u8_t*)&syslocation_len_default; 00787 static u8_t* syslocation_ptr = (u8_t*)&syslocation_default[0]; 00788 /** mib-2.snmp.snmpEnableAuthenTraps */ 00789 static const u8_t snmpenableauthentraps_default = 2; /* disabled */ 00790 static u8_t* snmpenableauthentraps_ptr = (u8_t*)&snmpenableauthentraps_default; 00791 00792 /** mib-2.interfaces.ifTable.ifEntry.ifSpecific (zeroDotZero) */ 00793 static const struct snmp_obj_id ifspecific = {2, {0, 0}}; 00794 /** mib-2.ip.ipRouteTable.ipRouteEntry.ipRouteInfo (zeroDotZero) */ 00795 static const struct snmp_obj_id iprouteinfo = {2, {0, 0}}; 00796 00797 00798 00799 /* mib-2.system counter(s) */ 00800 static u32_t sysuptime = 0; 00801 00802 /* mib-2.ip counter(s) */ 00803 static u32_t ipinreceives = 0, 00804 ipinhdrerrors = 0, 00805 ipinaddrerrors = 0, 00806 ipforwdatagrams = 0, 00807 ipinunknownprotos = 0, 00808 ipindiscards = 0, 00809 ipindelivers = 0, 00810 ipoutrequests = 0, 00811 ipoutdiscards = 0, 00812 ipoutnoroutes = 0, 00813 ipreasmreqds = 0, 00814 ipreasmoks = 0, 00815 ipreasmfails = 0, 00816 ipfragoks = 0, 00817 ipfragfails = 0, 00818 ipfragcreates = 0, 00819 iproutingdiscards = 0; 00820 /* mib-2.icmp counter(s) */ 00821 static u32_t icmpinmsgs = 0, 00822 icmpinerrors = 0, 00823 icmpindestunreachs = 0, 00824 icmpintimeexcds = 0, 00825 icmpinparmprobs = 0, 00826 icmpinsrcquenchs = 0, 00827 icmpinredirects = 0, 00828 icmpinechos = 0, 00829 icmpinechoreps = 0, 00830 icmpintimestamps = 0, 00831 icmpintimestampreps = 0, 00832 icmpinaddrmasks = 0, 00833 icmpinaddrmaskreps = 0, 00834 icmpoutmsgs = 0, 00835 icmpouterrors = 0, 00836 icmpoutdestunreachs = 0, 00837 icmpouttimeexcds = 0, 00838 icmpoutparmprobs = 0, 00839 icmpoutsrcquenchs = 0, 00840 icmpoutredirects = 0, 00841 icmpoutechos = 0, 00842 icmpoutechoreps = 0, 00843 icmpouttimestamps = 0, 00844 icmpouttimestampreps = 0, 00845 icmpoutaddrmasks = 0, 00846 icmpoutaddrmaskreps = 0; 00847 /* mib-2.tcp counter(s) */ 00848 static u32_t tcpactiveopens = 0, 00849 tcppassiveopens = 0, 00850 tcpattemptfails = 0, 00851 tcpestabresets = 0, 00852 tcpinsegs = 0, 00853 tcpoutsegs = 0, 00854 tcpretranssegs = 0, 00855 tcpinerrs = 0, 00856 tcpoutrsts = 0; 00857 /* mib-2.udp counter(s) */ 00858 static u32_t udpindatagrams = 0, 00859 udpnoports = 0, 00860 udpinerrors = 0, 00861 udpoutdatagrams = 0; 00862 /* mib-2.snmp counter(s) */ 00863 static u32_t snmpinpkts = 0, 00864 snmpoutpkts = 0, 00865 snmpinbadversions = 0, 00866 snmpinbadcommunitynames = 0, 00867 snmpinbadcommunityuses = 0, 00868 snmpinasnparseerrs = 0, 00869 snmpintoobigs = 0, 00870 snmpinnosuchnames = 0, 00871 snmpinbadvalues = 0, 00872 snmpinreadonlys = 0, 00873 snmpingenerrs = 0, 00874 snmpintotalreqvars = 0, 00875 snmpintotalsetvars = 0, 00876 snmpingetrequests = 0, 00877 snmpingetnexts = 0, 00878 snmpinsetrequests = 0, 00879 snmpingetresponses = 0, 00880 snmpintraps = 0, 00881 snmpouttoobigs = 0, 00882 snmpoutnosuchnames = 0, 00883 snmpoutbadvalues = 0, 00884 snmpoutgenerrs = 0, 00885 snmpoutgetrequests = 0, 00886 snmpoutgetnexts = 0, 00887 snmpoutsetrequests = 0, 00888 snmpoutgetresponses = 0, 00889 snmpouttraps = 0; 00890 00891 00892 00893 /* prototypes of the following functions are in lwip/src/include/lwip/snmp.h */ 00894 /** 00895 * Copy octet string. 00896 * 00897 * @param dst points to destination 00898 * @param src points to source 00899 * @param n number of octets to copy. 00900 */ 00901 void ocstrncpy(u8_t *dst, u8_t *src, u8_t n) 00902 { 00903 while (n > 0) 00904 { 00905 n--; 00906 *dst++ = *src++; 00907 } 00908 } 00909 00910 /** 00911 * Copy object identifier (s32_t) array. 00912 * 00913 * @param dst points to destination 00914 * @param src points to source 00915 * @param n number of sub identifiers to copy. 00916 */ 00917 void objectidncpy(s32_t *dst, s32_t *src, u8_t n) 00918 { 00919 while(n > 0) 00920 { 00921 n--; 00922 *dst++ = *src++; 00923 } 00924 } 00925 00926 /** 00927 * Initializes sysDescr pointers. 00928 * 00929 * @param str if non-NULL then copy str pointer 00930 * @param len points to string length, excluding zero terminator 00931 */ 00932 void snmp_set_sysdesr(u8_t *str, u8_t *len) 00933 { 00934 if (str != NULL) 00935 { 00936 sysdescr_ptr = str; 00937 sysdescr_len_ptr = len; 00938 } 00939 } 00940 00941 void snmp_get_sysobjid_ptr(struct snmp_obj_id **oid) 00942 { 00943 *oid = &sysobjid; 00944 } 00945 00946 /** 00947 * Initializes sysObjectID value. 00948 * 00949 * @param oid points to stuct snmp_obj_id to copy 00950 */ 00951 void snmp_set_sysobjid(struct snmp_obj_id *oid) 00952 { 00953 sysobjid = *oid; 00954 } 00955 00956 /** 00957 * Must be called at regular 10 msec interval from a timer interrupt 00958 * or signal handler depending on your runtime environment. 00959 */ 00960 void snmp_inc_sysuptime(void) 00961 { 00962 sysuptime++; 00963 } 00964 00965 void snmp_add_sysuptime(u32_t value) 00966 { 00967 sysuptime+=value; 00968 } 00969 00970 void snmp_get_sysuptime(u32_t *value) 00971 { 00972 SNMP_GET_SYSUPTIME(sysuptime); 00973 *value = sysuptime; 00974 } 00975 00976 /** 00977 * Initializes sysContact pointers, 00978 * e.g. ptrs to non-volatile memory external to lwIP. 00979 * 00980 * @param ocstr if non-NULL then copy str pointer 00981 * @param ocstrlen points to string length, excluding zero terminator 00982 */ 00983 void snmp_set_syscontact(u8_t *ocstr, u8_t *ocstrlen) 00984 { 00985 if (ocstr != NULL) 00986 { 00987 syscontact_ptr = ocstr; 00988 syscontact_len_ptr = ocstrlen; 00989 } 00990 } 00991 00992 /** 00993 * Initializes sysName pointers, 00994 * e.g. ptrs to non-volatile memory external to lwIP. 00995 * 00996 * @param ocstr if non-NULL then copy str pointer 00997 * @param ocstrlen points to string length, excluding zero terminator 00998 */ 00999 void snmp_set_sysname(u8_t *ocstr, u8_t *ocstrlen) 01000 { 01001 if (ocstr != NULL) 01002 { 01003 sysname_ptr = ocstr; 01004 sysname_len_ptr = ocstrlen; 01005 } 01006 } 01007 01008 /** 01009 * Initializes sysLocation pointers, 01010 * e.g. ptrs to non-volatile memory external to lwIP. 01011 * 01012 * @param ocstr if non-NULL then copy str pointer 01013 * @param ocstrlen points to string length, excluding zero terminator 01014 */ 01015 void snmp_set_syslocation(u8_t *ocstr, u8_t *ocstrlen) 01016 { 01017 if (ocstr != NULL) 01018 { 01019 syslocation_ptr = ocstr; 01020 syslocation_len_ptr = ocstrlen; 01021 } 01022 } 01023 01024 01025 void snmp_add_ifinoctets(struct netif *ni, u32_t value) 01026 { 01027 ni->ifinoctets += value; 01028 } 01029 01030 void snmp_inc_ifinucastpkts(struct netif *ni) 01031 { 01032 (ni->ifinucastpkts)++; 01033 } 01034 01035 void snmp_inc_ifinnucastpkts(struct netif *ni) 01036 { 01037 (ni->ifinnucastpkts)++; 01038 } 01039 01040 void snmp_inc_ifindiscards(struct netif *ni) 01041 { 01042 (ni->ifindiscards)++; 01043 } 01044 01045 void snmp_add_ifoutoctets(struct netif *ni, u32_t value) 01046 { 01047 ni->ifoutoctets += value; 01048 } 01049 01050 void snmp_inc_ifoutucastpkts(struct netif *ni) 01051 { 01052 (ni->ifoutucastpkts)++; 01053 } 01054 01055 void snmp_inc_ifoutnucastpkts(struct netif *ni) 01056 { 01057 (ni->ifoutnucastpkts)++; 01058 } 01059 01060 void snmp_inc_ifoutdiscards(struct netif *ni) 01061 { 01062 (ni->ifoutdiscards)++; 01063 } 01064 01065 void snmp_inc_iflist(void) 01066 { 01067 struct mib_list_node *if_node = NULL; 01068 01069 snmp_mib_node_insert(&iflist_root, iflist_root.count + 1, &if_node); 01070 /* enable getnext traversal on filled table */ 01071 iftable.maxlength = 1; 01072 } 01073 01074 void snmp_dec_iflist(void) 01075 { 01076 snmp_mib_node_delete(&iflist_root, iflist_root.tail); 01077 /* disable getnext traversal on empty table */ 01078 if(iflist_root.count == 0) iftable.maxlength = 0; 01079 } 01080 01081 /** 01082 * Inserts ARP table indexes (.xIfIndex.xNetAddress) 01083 * into arp table index trees (both atTable and ipNetToMediaTable). 01084 */ 01085 void snmp_insert_arpidx_tree(struct netif *ni, struct ip_addr *ip) 01086 { 01087 struct mib_list_rootnode *at_rn; 01088 struct mib_list_node *at_node; 01089 struct ip_addr hip; 01090 s32_t arpidx[5]; 01091 u8_t level, tree; 01092 01093 LWIP_ASSERT("ni != NULL", ni != NULL); 01094 snmp_netiftoifindex(ni, &arpidx[0]); 01095 hip.addr = ntohl(ip->addr); 01096 snmp_iptooid(&hip, &arpidx[1]); 01097 01098 for (tree = 0; tree < 2; tree++) 01099 { 01100 if (tree == 0) 01101 { 01102 at_rn = &arptree_root; 01103 } 01104 else 01105 { 01106 at_rn = &ipntomtree_root; 01107 } 01108 for (level = 0; level < 5; level++) 01109 { 01110 at_node = NULL; 01111 snmp_mib_node_insert(at_rn, arpidx[level], &at_node); 01112 if ((level != 4) && (at_node != NULL)) 01113 { 01114 if (at_node->nptr == NULL) 01115 { 01116 at_rn = snmp_mib_lrn_alloc(); 01117 at_node->nptr = (struct mib_node*)at_rn; 01118 if (at_rn != NULL) 01119 { 01120 if (level == 3) 01121 { 01122 if (tree == 0) 01123 { 01124 at_rn->get_object_def = atentry_get_object_def; 01125 at_rn->get_value = atentry_get_value; 01126 } 01127 else 01128 { 01129 at_rn->get_object_def = ip_ntomentry_get_object_def ; 01130 at_rn->get_value = ip_ntomentry_get_value; 01131 } 01132 at_rn->set_test = noleafs_set_test; 01133 at_rn->set_value = noleafs_set_value; 01134 } 01135 } 01136 else 01137 { 01138 /* at_rn == NULL, malloc failure */ 01139 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_arpidx_tree() insert failed, mem full")); 01140 break; 01141 } 01142 } 01143 else 01144 { 01145 at_rn = (struct mib_list_rootnode*)at_node->nptr; 01146 } 01147 } 01148 } 01149 } 01150 /* enable getnext traversal on filled tables */ 01151 at.maxlength = 1; 01152 ipntomtable.maxlength = 1; 01153 } 01154 01155 /** 01156 * Removes ARP table indexes (.xIfIndex.xNetAddress) 01157 * from arp table index trees. 01158 */ 01159 void snmp_delete_arpidx_tree(struct netif *ni, struct ip_addr *ip) 01160 { 01161 struct mib_list_rootnode *at_rn, *next, *del_rn[5]; 01162 struct mib_list_node *at_n, *del_n[5]; 01163 struct ip_addr hip; 01164 s32_t arpidx[5]; 01165 u8_t fc, tree, level, del_cnt; 01166 01167 snmp_netiftoifindex(ni, &arpidx[0]); 01168 hip.addr = ntohl(ip->addr); 01169 snmp_iptooid(&hip, &arpidx[1]); 01170 01171 for (tree = 0; tree < 2; tree++) 01172 { 01173 /* mark nodes for deletion */ 01174 if (tree == 0) 01175 { 01176 at_rn = &arptree_root; 01177 } 01178 else 01179 { 01180 at_rn = &ipntomtree_root; 01181 } 01182 level = 0; 01183 del_cnt = 0; 01184 while ((level < 5) && (at_rn != NULL)) 01185 { 01186 fc = snmp_mib_node_find(at_rn, arpidx[level], &at_n); 01187 if (fc == 0) 01188 { 01189 /* arpidx[level] does not exist */ 01190 del_cnt = 0; 01191 at_rn = NULL; 01192 } 01193 else if (fc == 1) 01194 { 01195 del_rn[del_cnt] = at_rn; 01196 del_n[del_cnt] = at_n; 01197 del_cnt++; 01198 at_rn = (struct mib_list_rootnode*)(at_n->nptr); 01199 } 01200 else if (fc == 2) 01201 { 01202 /* reset delete (2 or more childs) */ 01203 del_cnt = 0; 01204 at_rn = (struct mib_list_rootnode*)(at_n->nptr); 01205 } 01206 level++; 01207 } 01208 /* delete marked index nodes */ 01209 while (del_cnt > 0) 01210 { 01211 del_cnt--; 01212 01213 at_rn = del_rn[del_cnt]; 01214 at_n = del_n[del_cnt]; 01215 01216 next = snmp_mib_node_delete(at_rn, at_n); 01217 if (next != NULL) 01218 { 01219 LWIP_ASSERT("next_count == 0",next->count == 0); 01220 snmp_mib_lrn_free(next); 01221 } 01222 } 01223 } 01224 /* disable getnext traversal on empty tables */ 01225 if(arptree_root.count == 0) at.maxlength = 0; 01226 if(ipntomtree_root.count == 0) ipntomtable.maxlength = 0; 01227 } 01228 01229 void snmp_inc_ipinreceives(void) 01230 { 01231 ipinreceives++; 01232 } 01233 01234 void snmp_inc_ipinhdrerrors(void) 01235 { 01236 ipinhdrerrors++; 01237 } 01238 01239 void snmp_inc_ipinaddrerrors(void) 01240 { 01241 ipinaddrerrors++; 01242 } 01243 01244 void snmp_inc_ipforwdatagrams(void) 01245 { 01246 ipforwdatagrams++; 01247 } 01248 01249 void snmp_inc_ipinunknownprotos(void) 01250 { 01251 ipinunknownprotos++; 01252 } 01253 01254 void snmp_inc_ipindiscards(void) 01255 { 01256 ipindiscards++; 01257 } 01258 01259 void snmp_inc_ipindelivers(void) 01260 { 01261 ipindelivers++; 01262 } 01263 01264 void snmp_inc_ipoutrequests(void) 01265 { 01266 ipoutrequests++; 01267 } 01268 01269 void snmp_inc_ipoutdiscards(void) 01270 { 01271 ipoutdiscards++; 01272 } 01273 01274 void snmp_inc_ipoutnoroutes(void) 01275 { 01276 ipoutnoroutes++; 01277 } 01278 01279 void snmp_inc_ipreasmreqds(void) 01280 { 01281 ipreasmreqds++; 01282 } 01283 01284 void snmp_inc_ipreasmoks(void) 01285 { 01286 ipreasmoks++; 01287 } 01288 01289 void snmp_inc_ipreasmfails(void) 01290 { 01291 ipreasmfails++; 01292 } 01293 01294 void snmp_inc_ipfragoks(void) 01295 { 01296 ipfragoks++; 01297 } 01298 01299 void snmp_inc_ipfragfails(void) 01300 { 01301 ipfragfails++; 01302 } 01303 01304 void snmp_inc_ipfragcreates(void) 01305 { 01306 ipfragcreates++; 01307 } 01308 01309 void snmp_inc_iproutingdiscards(void) 01310 { 01311 iproutingdiscards++; 01312 } 01313 01314 /** 01315 * Inserts ipAddrTable indexes (.ipAdEntAddr) 01316 * into index tree. 01317 */ 01318 void snmp_insert_ipaddridx_tree(struct netif *ni) 01319 { 01320 struct mib_list_rootnode *ipa_rn; 01321 struct mib_list_node *ipa_node; 01322 struct ip_addr ip; 01323 s32_t ipaddridx[4]; 01324 u8_t level; 01325 01326 LWIP_ASSERT("ni != NULL", ni != NULL); 01327 ip.addr = ntohl(ni->ip_addr.addr); 01328 snmp_iptooid(&ip, &ipaddridx[0]); 01329 01330 level = 0; 01331 ipa_rn = &ipaddrtree_root; 01332 while (level < 4) 01333 { 01334 ipa_node = NULL; 01335 snmp_mib_node_insert(ipa_rn, ipaddridx[level], &ipa_node); 01336 if ((level != 3) && (ipa_node != NULL)) 01337 { 01338 if (ipa_node->nptr == NULL) 01339 { 01340 ipa_rn = snmp_mib_lrn_alloc(); 01341 ipa_node->nptr = (struct mib_node*)ipa_rn; 01342 if (ipa_rn != NULL) 01343 { 01344 if (level == 2) 01345 { 01346 ipa_rn->get_object_def = ip_addrentry_get_object_def; 01347 ipa_rn->get_value = ip_addrentry_get_value ; 01348 ipa_rn->set_test = noleafs_set_test; 01349 ipa_rn->set_value = noleafs_set_value; 01350 } 01351 } 01352 else 01353 { 01354 /* ipa_rn == NULL, malloc failure */ 01355 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_ipaddridx_tree() insert failed, mem full")); 01356 break; 01357 } 01358 } 01359 else 01360 { 01361 ipa_rn = (struct mib_list_rootnode*)ipa_node->nptr; 01362 } 01363 } 01364 level++; 01365 } 01366 /* enable getnext traversal on filled table */ 01367 ipaddrtable.maxlength = 1; 01368 } 01369 01370 /** 01371 * Removes ipAddrTable indexes (.ipAdEntAddr) 01372 * from index tree. 01373 */ 01374 void snmp_delete_ipaddridx_tree(struct netif *ni) 01375 { 01376 struct mib_list_rootnode *ipa_rn, *next, *del_rn[4]; 01377 struct mib_list_node *ipa_n, *del_n[4]; 01378 struct ip_addr ip; 01379 s32_t ipaddridx[4]; 01380 u8_t fc, level, del_cnt; 01381 01382 LWIP_ASSERT("ni != NULL", ni != NULL); 01383 ip.addr = ntohl(ni->ip_addr.addr); 01384 snmp_iptooid(&ip, &ipaddridx[0]); 01385 01386 /* mark nodes for deletion */ 01387 level = 0; 01388 del_cnt = 0; 01389 ipa_rn = &ipaddrtree_root; 01390 while ((level < 4) && (ipa_rn != NULL)) 01391 { 01392 fc = snmp_mib_node_find(ipa_rn, ipaddridx[level], &ipa_n); 01393 if (fc == 0) 01394 { 01395 /* ipaddridx[level] does not exist */ 01396 del_cnt = 0; 01397 ipa_rn = NULL; 01398 } 01399 else if (fc == 1) 01400 { 01401 del_rn[del_cnt] = ipa_rn; 01402 del_n[del_cnt] = ipa_n; 01403 del_cnt++; 01404 ipa_rn = (struct mib_list_rootnode*)(ipa_n->nptr); 01405 } 01406 else if (fc == 2) 01407 { 01408 /* reset delete (2 or more childs) */ 01409 del_cnt = 0; 01410 ipa_rn = (struct mib_list_rootnode*)(ipa_n->nptr); 01411 } 01412 level++; 01413 } 01414 /* delete marked index nodes */ 01415 while (del_cnt > 0) 01416 { 01417 del_cnt--; 01418 01419 ipa_rn = del_rn[del_cnt]; 01420 ipa_n = del_n[del_cnt]; 01421 01422 next = snmp_mib_node_delete(ipa_rn, ipa_n); 01423 if (next != NULL) 01424 { 01425 LWIP_ASSERT("next_count == 0",next->count == 0); 01426 snmp_mib_lrn_free(next); 01427 } 01428 } 01429 /* disable getnext traversal on empty table */ 01430 if (ipaddrtree_root.count == 0) ipaddrtable.maxlength = 0; 01431 } 01432 01433 /** 01434 * Inserts ipRouteTable indexes (.ipRouteDest) 01435 * into index tree. 01436 * 01437 * @param dflt non-zero for the default rte, zero for network rte 01438 * @param ni points to network interface for this rte 01439 * 01440 * @todo record sysuptime for _this_ route when it is installed 01441 * (needed for ipRouteAge) in the netif. 01442 */ 01443 void snmp_insert_iprteidx_tree(u8_t dflt, struct netif *ni) 01444 { 01445 u8_t insert = 0; 01446 struct ip_addr dst; 01447 01448 if (dflt != 0) 01449 { 01450 /* the default route 0.0.0.0 */ 01451 dst.addr = 0; 01452 insert = 1; 01453 } 01454 else 01455 { 01456 /* route to the network address */ 01457 dst.addr = ntohl(ni->ip_addr.addr & ni->netmask.addr); 01458 /* exclude 0.0.0.0 network (reserved for default rte) */ 01459 if (dst.addr != 0) insert = 1; 01460 } 01461 if (insert) 01462 { 01463 struct mib_list_rootnode *iprte_rn; 01464 struct mib_list_node *iprte_node; 01465 s32_t iprteidx[4]; 01466 u8_t level; 01467 01468 snmp_iptooid(&dst, &iprteidx[0]); 01469 level = 0; 01470 iprte_rn = &iprtetree_root; 01471 while (level < 4) 01472 { 01473 iprte_node = NULL; 01474 snmp_mib_node_insert(iprte_rn, iprteidx[level], &iprte_node); 01475 if ((level != 3) && (iprte_node != NULL)) 01476 { 01477 if (iprte_node->nptr == NULL) 01478 { 01479 iprte_rn = snmp_mib_lrn_alloc(); 01480 iprte_node->nptr = (struct mib_node*)iprte_rn; 01481 if (iprte_rn != NULL) 01482 { 01483 if (level == 2) 01484 { 01485 iprte_rn->get_object_def = ip_rteentry_get_object_def ; 01486 iprte_rn->get_value = ip_rteentry_get_value ; 01487 iprte_rn->set_test = noleafs_set_test; 01488 iprte_rn->set_value = noleafs_set_value; 01489 } 01490 } 01491 else 01492 { 01493 /* iprte_rn == NULL, malloc failure */ 01494 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_iprteidx_tree() insert failed, mem full")); 01495 break; 01496 } 01497 } 01498 else 01499 { 01500 iprte_rn = (struct mib_list_rootnode*)iprte_node->nptr; 01501 } 01502 } 01503 level++; 01504 } 01505 } 01506 /* enable getnext traversal on filled table */ 01507 iprtetable.maxlength = 1; 01508 } 01509 01510 /** 01511 * Removes ipRouteTable indexes (.ipRouteDest) 01512 * from index tree. 01513 * 01514 * @param dflt non-zero for the default rte, zero for network rte 01515 * @param ni points to network interface for this rte or NULL 01516 * for default route to be removed. 01517 */ 01518 void snmp_delete_iprteidx_tree(u8_t dflt, struct netif *ni) 01519 { 01520 u8_t delete = 0; 01521 struct ip_addr dst; 01522 01523 if (dflt != 0) 01524 { 01525 /* the default route 0.0.0.0 */ 01526 dst.addr = 0; 01527 delete = 1; 01528 } 01529 else 01530 { 01531 /* route to the network address */ 01532 dst.addr = ntohl(ni->ip_addr.addr & ni->netmask.addr); 01533 /* exclude 0.0.0.0 network (reserved for default rte) */ 01534 if (dst.addr != 0) delete = 1; 01535 } 01536 if (delete) 01537 { 01538 struct mib_list_rootnode *iprte_rn, *next, *del_rn[4]; 01539 struct mib_list_node *iprte_n, *del_n[4]; 01540 s32_t iprteidx[4]; 01541 u8_t fc, level, del_cnt; 01542 01543 snmp_iptooid(&dst, &iprteidx[0]); 01544 /* mark nodes for deletion */ 01545 level = 0; 01546 del_cnt = 0; 01547 iprte_rn = &iprtetree_root; 01548 while ((level < 4) && (iprte_rn != NULL)) 01549 { 01550 fc = snmp_mib_node_find(iprte_rn, iprteidx[level], &iprte_n); 01551 if (fc == 0) 01552 { 01553 /* iprteidx[level] does not exist */ 01554 del_cnt = 0; 01555 iprte_rn = NULL; 01556 } 01557 else if (fc == 1) 01558 { 01559 del_rn[del_cnt] = iprte_rn; 01560 del_n[del_cnt] = iprte_n; 01561 del_cnt++; 01562 iprte_rn = (struct mib_list_rootnode*)(iprte_n->nptr); 01563 } 01564 else if (fc == 2) 01565 { 01566 /* reset delete (2 or more childs) */ 01567 del_cnt = 0; 01568 iprte_rn = (struct mib_list_rootnode*)(iprte_n->nptr); 01569 } 01570 level++; 01571 } 01572 /* delete marked index nodes */ 01573 while (del_cnt > 0) 01574 { 01575 del_cnt--; 01576 01577 iprte_rn = del_rn[del_cnt]; 01578 iprte_n = del_n[del_cnt]; 01579 01580 next = snmp_mib_node_delete(iprte_rn, iprte_n); 01581 if (next != NULL) 01582 { 01583 LWIP_ASSERT("next_count == 0",next->count == 0); 01584 snmp_mib_lrn_free(next); 01585 } 01586 } 01587 } 01588 /* disable getnext traversal on empty table */ 01589 if (iprtetree_root.count == 0) iprtetable.maxlength = 0; 01590 } 01591 01592 01593 void snmp_inc_icmpinmsgs(void) 01594 { 01595 icmpinmsgs++; 01596 } 01597 01598 void snmp_inc_icmpinerrors(void) 01599 { 01600 icmpinerrors++; 01601 } 01602 01603 void snmp_inc_icmpindestunreachs(void) 01604 { 01605 icmpindestunreachs++; 01606 } 01607 01608 void snmp_inc_icmpintimeexcds(void) 01609 { 01610 icmpintimeexcds++; 01611 } 01612 01613 void snmp_inc_icmpinparmprobs(void) 01614 { 01615 icmpinparmprobs++; 01616 } 01617 01618 void snmp_inc_icmpinsrcquenchs(void) 01619 { 01620 icmpinsrcquenchs++; 01621 } 01622 01623 void snmp_inc_icmpinredirects(void) 01624 { 01625 icmpinredirects++; 01626 } 01627 01628 void snmp_inc_icmpinechos(void) 01629 { 01630 icmpinechos++; 01631 } 01632 01633 void snmp_inc_icmpinechoreps(void) 01634 { 01635 icmpinechoreps++; 01636 } 01637 01638 void snmp_inc_icmpintimestamps(void) 01639 { 01640 icmpintimestamps++; 01641 } 01642 01643 void snmp_inc_icmpintimestampreps(void) 01644 { 01645 icmpintimestampreps++; 01646 } 01647 01648 void snmp_inc_icmpinaddrmasks(void) 01649 { 01650 icmpinaddrmasks++; 01651 } 01652 01653 void snmp_inc_icmpinaddrmaskreps(void) 01654 { 01655 icmpinaddrmaskreps++; 01656 } 01657 01658 void snmp_inc_icmpoutmsgs(void) 01659 { 01660 icmpoutmsgs++; 01661 } 01662 01663 void snmp_inc_icmpouterrors(void) 01664 { 01665 icmpouterrors++; 01666 } 01667 01668 void snmp_inc_icmpoutdestunreachs(void) 01669 { 01670 icmpoutdestunreachs++; 01671 } 01672 01673 void snmp_inc_icmpouttimeexcds(void) 01674 { 01675 icmpouttimeexcds++; 01676 } 01677 01678 void snmp_inc_icmpoutparmprobs(void) 01679 { 01680 icmpoutparmprobs++; 01681 } 01682 01683 void snmp_inc_icmpoutsrcquenchs(void) 01684 { 01685 icmpoutsrcquenchs++; 01686 } 01687 01688 void snmp_inc_icmpoutredirects(void) 01689 { 01690 icmpoutredirects++; 01691 } 01692 01693 void snmp_inc_icmpoutechos(void) 01694 { 01695 icmpoutechos++; 01696 } 01697 01698 void snmp_inc_icmpoutechoreps(void) 01699 { 01700 icmpoutechoreps++; 01701 } 01702 01703 void snmp_inc_icmpouttimestamps(void) 01704 { 01705 icmpouttimestamps++; 01706 } 01707 01708 void snmp_inc_icmpouttimestampreps(void) 01709 { 01710 icmpouttimestampreps++; 01711 } 01712 01713 void snmp_inc_icmpoutaddrmasks(void) 01714 { 01715 icmpoutaddrmasks++; 01716 } 01717 01718 void snmp_inc_icmpoutaddrmaskreps(void) 01719 { 01720 icmpoutaddrmaskreps++; 01721 } 01722 01723 void snmp_inc_tcpactiveopens(void) 01724 { 01725 tcpactiveopens++; 01726 } 01727 01728 void snmp_inc_tcppassiveopens(void) 01729 { 01730 tcppassiveopens++; 01731 } 01732 01733 void snmp_inc_tcpattemptfails(void) 01734 { 01735 tcpattemptfails++; 01736 } 01737 01738 void snmp_inc_tcpestabresets(void) 01739 { 01740 tcpestabresets++; 01741 } 01742 01743 void snmp_inc_tcpinsegs(void) 01744 { 01745 tcpinsegs++; 01746 } 01747 01748 void snmp_inc_tcpoutsegs(void) 01749 { 01750 tcpoutsegs++; 01751 } 01752 01753 void snmp_inc_tcpretranssegs(void) 01754 { 01755 tcpretranssegs++; 01756 } 01757 01758 void snmp_inc_tcpinerrs(void) 01759 { 01760 tcpinerrs++; 01761 } 01762 01763 void snmp_inc_tcpoutrsts(void) 01764 { 01765 tcpoutrsts++; 01766 } 01767 01768 void snmp_inc_udpindatagrams(void) 01769 { 01770 udpindatagrams++; 01771 } 01772 01773 void snmp_inc_udpnoports(void) 01774 { 01775 udpnoports++; 01776 } 01777 01778 void snmp_inc_udpinerrors(void) 01779 { 01780 udpinerrors++; 01781 } 01782 01783 void snmp_inc_udpoutdatagrams(void) 01784 { 01785 udpoutdatagrams++; 01786 } 01787 01788 /** 01789 * Inserts udpTable indexes (.udpLocalAddress.udpLocalPort) 01790 * into index tree. 01791 */ 01792 void snmp_insert_udpidx_tree(struct udp_pcb *pcb) 01793 { 01794 struct mib_list_rootnode *udp_rn; 01795 struct mib_list_node *udp_node; 01796 struct ip_addr ip; 01797 s32_t udpidx[5]; 01798 u8_t level; 01799 01800 LWIP_ASSERT("pcb != NULL", pcb != NULL); 01801 ip.addr = ntohl(pcb->local_ip.addr); 01802 snmp_iptooid(&ip, &udpidx[0]); 01803 udpidx[4] = pcb->local_port; 01804 01805 udp_rn = &udp_root; 01806 for (level = 0; level < 5; level++) 01807 { 01808 udp_node = NULL; 01809 snmp_mib_node_insert(udp_rn, udpidx[level], &udp_node); 01810 if ((level != 4) && (udp_node != NULL)) 01811 { 01812 if (udp_node->nptr == NULL) 01813 { 01814 udp_rn = snmp_mib_lrn_alloc(); 01815 udp_node->nptr = (struct mib_node*)udp_rn; 01816 if (udp_rn != NULL) 01817 { 01818 if (level == 3) 01819 { 01820 udp_rn->get_object_def = udpentry_get_object_def; 01821 udp_rn->get_value = udpentry_get_value; 01822 udp_rn->set_test = noleafs_set_test; 01823 udp_rn->set_value = noleafs_set_value; 01824 } 01825 } 01826 else 01827 { 01828 /* udp_rn == NULL, malloc failure */ 01829 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_udpidx_tree() insert failed, mem full")); 01830 break; 01831 } 01832 } 01833 else 01834 { 01835 udp_rn = (struct mib_list_rootnode*)udp_node->nptr; 01836 } 01837 } 01838 } 01839 udptable.maxlength = 1; 01840 } 01841 01842 /** 01843 * Removes udpTable indexes (.udpLocalAddress.udpLocalPort) 01844 * from index tree. 01845 */ 01846 void snmp_delete_udpidx_tree(struct udp_pcb *pcb) 01847 { 01848 struct mib_list_rootnode *udp_rn, *next, *del_rn[5]; 01849 struct mib_list_node *udp_n, *del_n[5]; 01850 struct ip_addr ip; 01851 s32_t udpidx[5]; 01852 u8_t bindings, fc, level, del_cnt; 01853 01854 LWIP_ASSERT("pcb != NULL", pcb != NULL); 01855 ip.addr = ntohl(pcb->local_ip.addr); 01856 snmp_iptooid(&ip, &udpidx[0]); 01857 udpidx[4] = pcb->local_port; 01858 01859 /* count PCBs for a given binding 01860 (e.g. when reusing ports or for temp output PCBs) */ 01861 bindings = 0; 01862 pcb = udp_pcbs; 01863 while ((pcb != NULL)) 01864 { 01865 if ((pcb->local_ip.addr == ip.addr) && 01866 (pcb->local_port == udpidx[4])) 01867 { 01868 bindings++; 01869 } 01870 pcb = pcb->next; 01871 } 01872 if (bindings == 1) 01873 { 01874 /* selectively remove */ 01875 /* mark nodes for deletion */ 01876 level = 0; 01877 del_cnt = 0; 01878 udp_rn = &udp_root; 01879 while ((level < 5) && (udp_rn != NULL)) 01880 { 01881 fc = snmp_mib_node_find(udp_rn, udpidx[level], &udp_n); 01882 if (fc == 0) 01883 { 01884 /* udpidx[level] does not exist */ 01885 del_cnt = 0; 01886 udp_rn = NULL; 01887 } 01888 else if (fc == 1) 01889 { 01890 del_rn[del_cnt] = udp_rn; 01891 del_n[del_cnt] = udp_n; 01892 del_cnt++; 01893 udp_rn = (struct mib_list_rootnode*)(udp_n->nptr); 01894 } 01895 else if (fc == 2) 01896 { 01897 /* reset delete (2 or more childs) */ 01898 del_cnt = 0; 01899 udp_rn = (struct mib_list_rootnode*)(udp_n->nptr); 01900 } 01901 level++; 01902 } 01903 /* delete marked index nodes */ 01904 while (del_cnt > 0) 01905 { 01906 del_cnt--; 01907 01908 udp_rn = del_rn[del_cnt]; 01909 udp_n = del_n[del_cnt]; 01910 01911 next = snmp_mib_node_delete(udp_rn, udp_n); 01912 if (next != NULL) 01913 { 01914 LWIP_ASSERT("next_count == 0",next->count == 0); 01915 snmp_mib_lrn_free(next); 01916 } 01917 } 01918 } 01919 /* disable getnext traversal on empty table */ 01920 if (udp_root.count == 0) udptable.maxlength = 0; 01921 } 01922 01923 01924 void snmp_inc_snmpinpkts(void) 01925 { 01926 snmpinpkts++; 01927 } 01928 01929 void snmp_inc_snmpoutpkts(void) 01930 { 01931 snmpoutpkts++; 01932 } 01933 01934 void snmp_inc_snmpinbadversions(void) 01935 { 01936 snmpinbadversions++; 01937 } 01938 01939 void snmp_inc_snmpinbadcommunitynames(void) 01940 { 01941 snmpinbadcommunitynames++; 01942 } 01943 01944 void snmp_inc_snmpinbadcommunityuses(void) 01945 { 01946 snmpinbadcommunityuses++; 01947 } 01948 01949 void snmp_inc_snmpinasnparseerrs(void) 01950 { 01951 snmpinasnparseerrs++; 01952 } 01953 01954 void snmp_inc_snmpintoobigs(void) 01955 { 01956 snmpintoobigs++; 01957 } 01958 01959 void snmp_inc_snmpinnosuchnames(void) 01960 { 01961 snmpinnosuchnames++; 01962 } 01963 01964 void snmp_inc_snmpinbadvalues(void) 01965 { 01966 snmpinbadvalues++; 01967 } 01968 01969 void snmp_inc_snmpinreadonlys(void) 01970 { 01971 snmpinreadonlys++; 01972 } 01973 01974 void snmp_inc_snmpingenerrs(void) 01975 { 01976 snmpingenerrs++; 01977 } 01978 01979 void snmp_add_snmpintotalreqvars(u8_t value) 01980 { 01981 snmpintotalreqvars += value; 01982 } 01983 01984 void snmp_add_snmpintotalsetvars(u8_t value) 01985 { 01986 snmpintotalsetvars += value; 01987 } 01988 01989 void snmp_inc_snmpingetrequests(void) 01990 { 01991 snmpingetrequests++; 01992 } 01993 01994 void snmp_inc_snmpingetnexts(void) 01995 { 01996 snmpingetnexts++; 01997 } 01998 01999 void snmp_inc_snmpinsetrequests(void) 02000 { 02001 snmpinsetrequests++; 02002 } 02003 02004 void snmp_inc_snmpingetresponses(void) 02005 { 02006 snmpingetresponses++; 02007 } 02008 02009 void snmp_inc_snmpintraps(void) 02010 { 02011 snmpintraps++; 02012 } 02013 02014 void snmp_inc_snmpouttoobigs(void) 02015 { 02016 snmpouttoobigs++; 02017 } 02018 02019 void snmp_inc_snmpoutnosuchnames(void) 02020 { 02021 snmpoutnosuchnames++; 02022 } 02023 02024 void snmp_inc_snmpoutbadvalues(void) 02025 { 02026 snmpoutbadvalues++; 02027 } 02028 02029 void snmp_inc_snmpoutgenerrs(void) 02030 { 02031 snmpoutgenerrs++; 02032 } 02033 02034 void snmp_inc_snmpoutgetrequests(void) 02035 { 02036 snmpoutgetrequests++; 02037 } 02038 02039 void snmp_inc_snmpoutgetnexts(void) 02040 { 02041 snmpoutgetnexts++; 02042 } 02043 02044 void snmp_inc_snmpoutsetrequests(void) 02045 { 02046 snmpoutsetrequests++; 02047 } 02048 02049 void snmp_inc_snmpoutgetresponses(void) 02050 { 02051 snmpoutgetresponses++; 02052 } 02053 02054 void snmp_inc_snmpouttraps(void) 02055 { 02056 snmpouttraps++; 02057 } 02058 02059 void snmp_get_snmpgrpid_ptr(struct snmp_obj_id **oid) 02060 { 02061 *oid = &snmpgrp_id; 02062 } 02063 02064 void snmp_set_snmpenableauthentraps(u8_t *value) 02065 { 02066 if (value != NULL) 02067 { 02068 snmpenableauthentraps_ptr = value; 02069 } 02070 } 02071 02072 void snmp_get_snmpenableauthentraps(u8_t *value) 02073 { 02074 *value = *snmpenableauthentraps_ptr; 02075 } 02076 02077 void 02078 noleafs_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) 02079 { 02080 if (ident_len){} 02081 if (ident){} 02082 od->instance = MIB_OBJECT_NONE; 02083 } 02084 02085 void 02086 noleafs_get_value(struct obj_def *od, u16_t len, void *value) 02087 { 02088 if (od){} 02089 if (len){} 02090 if (value){} 02091 } 02092 02093 u8_t 02094 noleafs_set_test(struct obj_def *od, u16_t len, void *value) 02095 { 02096 if (od){} 02097 if (len){} 02098 if (value){} 02099 /* can't set */ 02100 return 0; 02101 } 02102 02103 void 02104 noleafs_set_value(struct obj_def *od, u16_t len, void *value) 02105 { 02106 if (od){} 02107 if (len){} 02108 if (value){} 02109 } 02110 02111 02112 /** 02113 * Returns systems object definitions. 02114 * 02115 * @param ident_len the address length (2) 02116 * @param ident points to objectname.0 (object id trailer) 02117 * @param od points to object definition. 02118 */ 02119 static void 02120 system_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) 02121 { 02122 u8_t id; 02123 02124 /* return to object name, adding index depth (1) */ 02125 ident_len += 1; 02126 ident -= 1; 02127 if (ident_len == 2) 02128 { 02129 od->id_inst_len = ident_len; 02130 od->id_inst_ptr = ident; 02131 02132 id = ident[0]; 02133 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def system.%"U16_F".0\n",(u16_t)id)); 02134 switch (id) 02135 { 02136 case 1: /* sysDescr */ 02137 od->instance = MIB_OBJECT_SCALAR; 02138 od->access = MIB_OBJECT_READ_ONLY; 02139 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); 02140 od->v_len = *sysdescr_len_ptr; 02141 break; 02142 case 2: /* sysObjectID */ 02143 od->instance = MIB_OBJECT_SCALAR; 02144 od->access = MIB_OBJECT_READ_ONLY; 02145 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID); 02146 od->v_len = sysobjid.len * sizeof(s32_t); 02147 break; 02148 case 3: /* sysUpTime */ 02149 od->instance = MIB_OBJECT_SCALAR; 02150 od->access = MIB_OBJECT_READ_ONLY; 02151 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS); 02152 od->v_len = sizeof(u32_t); 02153 break; 02154 case 4: /* sysContact */ 02155 od->instance = MIB_OBJECT_SCALAR; 02156 od->access = MIB_OBJECT_READ_WRITE; 02157 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); 02158 od->v_len = *syscontact_len_ptr; 02159 break; 02160 case 5: /* sysName */ 02161 od->instance = MIB_OBJECT_SCALAR; 02162 od->access = MIB_OBJECT_READ_WRITE; 02163 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); 02164 od->v_len = *sysname_len_ptr; 02165 break; 02166 case 6: /* sysLocation */ 02167 od->instance = MIB_OBJECT_SCALAR; 02168 od->access = MIB_OBJECT_READ_WRITE; 02169 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); 02170 od->v_len = *syslocation_len_ptr; 02171 break; 02172 case 7: /* sysServices */ 02173 od->instance = MIB_OBJECT_SCALAR; 02174 od->access = MIB_OBJECT_READ_ONLY; 02175 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); 02176 od->v_len = sizeof(s32_t); 02177 break; 02178 default: 02179 LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no such object\n")); 02180 od->instance = MIB_OBJECT_NONE; 02181 break; 02182 }; 02183 } 02184 else 02185 { 02186 LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no scalar\n")); 02187 od->instance = MIB_OBJECT_NONE; 02188 } 02189 } 02190 02191 /** 02192 * Returns system object value. 02193 * 02194 * @param ident_len the address length (2) 02195 * @param ident points to objectname.0 (object id trailer) 02196 * @param len return value space (in bytes) 02197 * @param value points to (varbind) space to copy value into. 02198 */ 02199 static void 02200 system_get_value(struct obj_def *od, u16_t len, void *value) 02201 { 02202 u8_t id; 02203 02204 id = od->id_inst_ptr[0]; 02205 switch (id) 02206 { 02207 case 1: /* sysDescr */ 02208 ocstrncpy(value,sysdescr_ptr, len); 02209 break; 02210 case 2: /* sysObjectID */ 02211 objectidncpy((s32_t*)value, (s32_t*)sysobjid.id, (u8_t)(len / sizeof(s32_t))); 02212 break; 02213 case 3: /* sysUpTime */ 02214 { 02215 snmp_get_sysuptime(value); 02216 } 02217 break; 02218 case 4: /* sysContact */ 02219 ocstrncpy(value,syscontact_ptr,len); 02220 break; 02221 case 5: /* sysName */ 02222 ocstrncpy(value,sysname_ptr,len); 02223 break; 02224 case 6: /* sysLocation */ 02225 ocstrncpy(value,syslocation_ptr,len); 02226 break; 02227 case 7: /* sysServices */ 02228 { 02229 s32_t *sint_ptr = value; 02230 *sint_ptr = sysservices; 02231 } 02232 break; 02233 }; 02234 } 02235 02236 static u8_t 02237 system_set_test(struct obj_def *od, u16_t len, void *value) 02238 { 02239 u8_t id, set_ok; 02240 02241 if (value) {} 02242 set_ok = 0; 02243 id = od->id_inst_ptr[0]; 02244 switch (id) 02245 { 02246 case 4: /* sysContact */ 02247 if ((syscontact_ptr != syscontact_default) && 02248 (len <= 255)) 02249 { 02250 set_ok = 1; 02251 } 02252 break; 02253 case 5: /* sysName */ 02254 if ((sysname_ptr != sysname_default) && 02255 (len <= 255)) 02256 { 02257 set_ok = 1; 02258 } 02259 break; 02260 case 6: /* sysLocation */ 02261 if ((syslocation_ptr != syslocation_default) && 02262 (len <= 255)) 02263 { 02264 set_ok = 1; 02265 } 02266 break; 02267 }; 02268 return set_ok; 02269 } 02270 02271 static void 02272 system_set_value(struct obj_def *od, u16_t len, void *value) 02273 { 02274 u8_t id; 02275 02276 id = od->id_inst_ptr[0]; 02277 switch (id) 02278 { 02279 case 4: /* sysContact */ 02280 ocstrncpy(syscontact_ptr,value,len); 02281 *syscontact_len_ptr = len; 02282 break; 02283 case 5: /* sysName */ 02284 ocstrncpy(sysname_ptr,value,len); 02285 *sysname_len_ptr = len; 02286 break; 02287 case 6: /* sysLocation */ 02288 ocstrncpy(syslocation_ptr,value,len); 02289 *syslocation_len_ptr = len; 02290 break; 02291 }; 02292 } 02293 02294 /** 02295 * Returns interfaces.ifnumber object definition. 02296 * 02297 * @param ident_len the address length (2) 02298 * @param ident points to objectname.index 02299 * @param od points to object definition. 02300 */ 02301 static void 02302 interfaces_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) 02303 { 02304 /* return to object name, adding index depth (1) */ 02305 ident_len += 1; 02306 ident -= 1; 02307 if (ident_len == 2) 02308 { 02309 od->id_inst_len = ident_len; 02310 od->id_inst_ptr = ident; 02311 02312 od->instance = MIB_OBJECT_SCALAR; 02313 od->access = MIB_OBJECT_READ_ONLY; 02314 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); 02315 od->v_len = sizeof(s32_t); 02316 } 02317 else 02318 { 02319 LWIP_DEBUGF(SNMP_MIB_DEBUG,("interfaces_get_object_def: no scalar\n")); 02320 od->instance = MIB_OBJECT_NONE; 02321 } 02322 } 02323 02324 /** 02325 * Returns interfaces.ifnumber object value. 02326 * 02327 * @param ident_len the address length (2) 02328 * @param ident points to objectname.0 (object id trailer) 02329 * @param len return value space (in bytes) 02330 * @param value points to (varbind) space to copy value into. 02331 */ 02332 static void 02333 interfaces_get_value(struct obj_def *od, u16_t len, void *value) 02334 { 02335 if (len){} 02336 if (od->id_inst_ptr[0] == 1) 02337 { 02338 s32_t *sint_ptr = value; 02339 *sint_ptr = iflist_root.count; 02340 } 02341 } 02342 02343 /** 02344 * Returns ifentry object definitions. 02345 * 02346 * @param ident_len the address length (2) 02347 * @param ident points to objectname.index 02348 * @param od points to object definition. 02349 */ 02350 static void 02351 ifentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) 02352 { 02353 u8_t id; 02354 02355 /* return to object name, adding index depth (1) */ 02356 ident_len += 1; 02357 ident -= 1; 02358 if (ident_len == 2) 02359 { 02360 od->id_inst_len = ident_len; 02361 od->id_inst_ptr = ident; 02362 02363 id = ident[0]; 02364 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def ifentry.%"U16_F"\n",(u16_t)id)); 02365 switch (id) 02366 { 02367 case 1: /* ifIndex */ 02368 case 3: /* ifType */ 02369 case 4: /* ifMtu */ 02370 case 8: /* ifOperStatus */ 02371 od->instance = MIB_OBJECT_TAB; 02372 od->access = MIB_OBJECT_READ_ONLY; 02373 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); 02374 od->v_len = sizeof(s32_t); 02375 break; 02376 case 2: /* ifDescr */ 02377 od->instance = MIB_OBJECT_TAB; 02378 od->access = MIB_OBJECT_READ_ONLY; 02379 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); 02380 /** @todo this should be some sort of sizeof(struct netif.name) */ 02381 od->v_len = 2; 02382 break; 02383 case 5: /* ifSpeed */ 02384 case 21: /* ifOutQLen */ 02385 od->instance = MIB_OBJECT_TAB; 02386 od->access = MIB_OBJECT_READ_ONLY; 02387 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE); 02388 od->v_len = sizeof(u32_t); 02389 break; 02390 case 6: /* ifPhysAddress */ 02391 { 02392 struct netif *netif; 02393 02394 snmp_ifindextonetif(ident[1], &netif); 02395 od->instance = MIB_OBJECT_TAB; 02396 od->access = MIB_OBJECT_READ_ONLY; 02397 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); 02398 od->v_len = netif->hwaddr_len; 02399 } 02400 break; 02401 case 7: /* ifAdminStatus */ 02402 od->instance = MIB_OBJECT_TAB; 02403 od->access = MIB_OBJECT_READ_WRITE; 02404 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); 02405 od->v_len = sizeof(s32_t); 02406 break; 02407 case 9: /* ifLastChange */ 02408 od->instance = MIB_OBJECT_TAB; 02409 od->access = MIB_OBJECT_READ_ONLY; 02410 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS); 02411 od->v_len = sizeof(u32_t); 02412 break; 02413 case 10: /* ifInOctets */ 02414 case 11: /* ifInUcastPkts */ 02415 case 12: /* ifInNUcastPkts */ 02416 case 13: /* ifInDiscarts */ 02417 case 14: /* ifInErrors */ 02418 case 15: /* ifInUnkownProtos */ 02419 case 16: /* ifOutOctets */ 02420 case 17: /* ifOutUcastPkts */ 02421 case 18: /* ifOutNUcastPkts */ 02422 case 19: /* ifOutDiscarts */ 02423 case 20: /* ifOutErrors */ 02424 od->instance = MIB_OBJECT_TAB; 02425 od->access = MIB_OBJECT_READ_ONLY; 02426 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER); 02427 od->v_len = sizeof(u32_t); 02428 break; 02429 case 22: /* ifSpecific */ 02430 /** @note returning zeroDotZero (0.0) no media specific MIB support */ 02431 od->instance = MIB_OBJECT_TAB; 02432 od->access = MIB_OBJECT_READ_ONLY; 02433 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID); 02434 od->v_len = ifspecific.len * sizeof(s32_t); 02435 break; 02436 default: 02437 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no such object\n")); 02438 od->instance = MIB_OBJECT_NONE; 02439 break; 02440 }; 02441 } 02442 else 02443 { 02444 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no scalar\n")); 02445 od->instance = MIB_OBJECT_NONE; 02446 } 02447 } 02448 02449 /** 02450 * Returns ifentry object value. 02451 * 02452 * @param ident_len the address length (2) 02453 * @param ident points to objectname.0 (object id trailer) 02454 * @param len return value space (in bytes) 02455 * @param value points to (varbind) space to copy value into. 02456 */ 02457 static void 02458 ifentry_get_value(struct obj_def *od, u16_t len, void *value) 02459 { 02460 struct netif *netif; 02461 u8_t id; 02462 02463 snmp_ifindextonetif(od->id_inst_ptr[1], &netif); 02464 id = od->id_inst_ptr[0]; 02465 switch (id) 02466 { 02467 case 1: /* ifIndex */ 02468 { 02469 s32_t *sint_ptr = value; 02470 *sint_ptr = od->id_inst_ptr[1]; 02471 } 02472 break; 02473 case 2: /* ifDescr */ 02474 ocstrncpy(value,(u8_t*)netif->name,len); 02475 break; 02476 case 3: /* ifType */ 02477 { 02478 s32_t *sint_ptr = value; 02479 *sint_ptr = netif->link_type; 02480 } 02481 break; 02482 case 4: /* ifMtu */ 02483 { 02484 s32_t *sint_ptr = value; 02485 *sint_ptr = netif->mtu; 02486 } 02487 break; 02488 case 5: /* ifSpeed */ 02489 { 02490 u32_t *uint_ptr = value; 02491 *uint_ptr = netif->link_speed; 02492 } 02493 break; 02494 case 6: /* ifPhysAddress */ 02495 ocstrncpy(value,netif->hwaddr,len); 02496 break; 02497 case 7: /* ifAdminStatus */ 02498 #if LWIP_NETIF_LINK_CALLBACK 02499 { 02500 s32_t *sint_ptr = value; 02501 if (netif_is_up(netif)) 02502 { 02503 if (netif_is_link_up(netif)) 02504 { 02505 *sint_ptr = 1; /* up */ 02506 } 02507 else 02508 { 02509 *sint_ptr = 7; /* lowerLayerDown */ 02510 } 02511 } 02512 else 02513 { 02514 *sint_ptr = 2; /* down */ 02515 } 02516 } 02517 break; 02518 #endif 02519 case 8: /* ifOperStatus */ 02520 { 02521 s32_t *sint_ptr = value; 02522 if (netif_is_up(netif)) 02523 { 02524 *sint_ptr = 1; 02525 } 02526 else 02527 { 02528 *sint_ptr = 2; 02529 } 02530 } 02531 break; 02532 case 9: /* ifLastChange */ 02533 { 02534 u32_t *uint_ptr = value; 02535 *uint_ptr = netif->ts; 02536 } 02537 break; 02538 case 10: /* ifInOctets */ 02539 { 02540 u32_t *uint_ptr = value; 02541 *uint_ptr = netif->ifinoctets; 02542 } 02543 break; 02544 case 11: /* ifInUcastPkts */ 02545 { 02546 u32_t *uint_ptr = value; 02547 *uint_ptr = netif->ifinucastpkts; 02548 } 02549 break; 02550 case 12: /* ifInNUcastPkts */ 02551 { 02552 u32_t *uint_ptr = value; 02553 *uint_ptr = netif->ifinnucastpkts; 02554 } 02555 break; 02556 case 13: /* ifInDiscarts */ 02557 { 02558 u32_t *uint_ptr = value; 02559 *uint_ptr = netif->ifindiscards; 02560 } 02561 break; 02562 case 14: /* ifInErrors */ 02563 case 15: /* ifInUnkownProtos */ 02564 /** @todo add these counters! */ 02565 { 02566 u32_t *uint_ptr = value; 02567 *uint_ptr = 0; 02568 } 02569 break; 02570 case 16: /* ifOutOctets */ 02571 { 02572 u32_t *uint_ptr = value; 02573 *uint_ptr = netif->ifoutoctets; 02574 } 02575 break; 02576 case 17: /* ifOutUcastPkts */ 02577 { 02578 u32_t *uint_ptr = value; 02579 *uint_ptr = netif->ifoutucastpkts; 02580 } 02581 break; 02582 case 18: /* ifOutNUcastPkts */ 02583 { 02584 u32_t *uint_ptr = value; 02585 *uint_ptr = netif->ifoutnucastpkts; 02586 } 02587 break; 02588 case 19: /* ifOutDiscarts */ 02589 { 02590 u32_t *uint_ptr = value; 02591 *uint_ptr = netif->ifoutdiscards; 02592 } 02593 break; 02594 case 20: /* ifOutErrors */ 02595 /** @todo add this counter! */ 02596 { 02597 u32_t *uint_ptr = value; 02598 *uint_ptr = 0; 02599 } 02600 break; 02601 case 21: /* ifOutQLen */ 02602 /** @todo figure out if this must be 0 (no queue) or 1? */ 02603 { 02604 u32_t *uint_ptr = value; 02605 *uint_ptr = 0; 02606 } 02607 break; 02608 case 22: /* ifSpecific */ 02609 objectidncpy((s32_t*)value, (s32_t*)ifspecific.id, (u8_t)(len / sizeof(s32_t))); 02610 break; 02611 }; 02612 } 02613 02614 #if !SNMP_SAFE_REQUESTS 02615 static u8_t 02616 ifentry_set_test (struct obj_def *od, u16_t len, void *value) 02617 { 02618 struct netif *netif; 02619 u8_t id, set_ok; 02620 02621 set_ok = 0; 02622 snmp_ifindextonetif(od->id_inst_ptr[1], &netif); 02623 id = od->id_inst_ptr[0]; 02624 switch (id) 02625 { 02626 case 7: /* ifAdminStatus */ 02627 { 02628 s32_t *sint_ptr = value; 02629 if (*sint_ptr == 1 || *sint_ptr == 2) 02630 set_ok = 1; 02631 } 02632 break; 02633 } 02634 return set_ok; 02635 } 02636 02637 static void 02638 ifentry_set_value (struct obj_def *od, u16_t len, void *value) 02639 { 02640 struct netif *netif; 02641 u8_t id; 02642 02643 snmp_ifindextonetif(od->id_inst_ptr[1], &netif); 02644 id = od->id_inst_ptr[0]; 02645 switch (id) 02646 { 02647 case 7: /* ifAdminStatus */ 02648 { 02649 s32_t *sint_ptr = value; 02650 if (*sint_ptr == 1) 02651 { 02652 netif_set_up(netif); 02653 } 02654 else if (*sint_ptr == 2) 02655 { 02656 netif_set_down(netif); 02657 } 02658 } 02659 break; 02660 } 02661 } 02662 #endif /* SNMP_SAFE_REQUESTS */ 02663 02664 /** 02665 * Returns atentry object definitions. 02666 * 02667 * @param ident_len the address length (6) 02668 * @param ident points to objectname.atifindex.atnetaddress 02669 * @param od points to object definition. 02670 */ 02671 static void 02672 atentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) 02673 { 02674 /* return to object name, adding index depth (5) */ 02675 ident_len += 5; 02676 ident -= 5; 02677 02678 if (ident_len == 6) 02679 { 02680 od->id_inst_len = ident_len; 02681 od->id_inst_ptr = ident; 02682 02683 switch (ident[0]) 02684 { 02685 case 1: /* atIfIndex */ 02686 od->instance = MIB_OBJECT_TAB; 02687 od->access = MIB_OBJECT_READ_WRITE; 02688 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); 02689 od->v_len = sizeof(s32_t); 02690 break; 02691 case 2: /* atPhysAddress */ 02692 od->instance = MIB_OBJECT_TAB; 02693 od->access = MIB_OBJECT_READ_WRITE; 02694 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); 02695 od->v_len = 6; /** @todo try to use netif::hwaddr_len */ 02696 break; 02697 case 3: /* atNetAddress */ 02698 od->instance = MIB_OBJECT_TAB; 02699 od->access = MIB_OBJECT_READ_WRITE; 02700 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR); 02701 od->v_len = 4; 02702 break; 02703 default: 02704 LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_object_def: no such object\n")); 02705 od->instance = MIB_OBJECT_NONE; 02706 break; 02707 } 02708 } 02709 else 02710 { 02711 LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_object_def: no scalar\n")); 02712 od->instance = MIB_OBJECT_NONE; 02713 } 02714 } 02715 02716 static void 02717 atentry_get_value(struct obj_def *od, u16_t len, void *value) 02718 { 02719 #if LWIP_ARP 02720 u8_t id; 02721 struct eth_addr* ethaddr_ret; 02722 struct ip_addr* ipaddr_ret; 02723 #endif /* LWIP_ARP */ 02724 struct ip_addr ip; 02725 struct netif *netif; 02726 02727 if (len) {} 02728 02729 snmp_ifindextonetif(od->id_inst_ptr[1], &netif); 02730 snmp_oidtoip(&od->id_inst_ptr[2], &ip); 02731 ip.addr = htonl(ip.addr); 02732 02733 #if LWIP_ARP /** @todo implement a netif_find_addr */ 02734 if (etharp_find_addr(netif, &ip, ðaddr_ret, &ipaddr_ret) > -1) 02735 { 02736 id = od->id_inst_ptr[0]; 02737 switch (id) 02738 { 02739 case 1: /* atIfIndex */ 02740 { 02741 s32_t *sint_ptr = value; 02742 *sint_ptr = od->id_inst_ptr[1]; 02743 } 02744 break; 02745 case 2: /* atPhysAddress */ 02746 { 02747 struct eth_addr *dst = value; 02748 02749 *dst = *ethaddr_ret; 02750 } 02751 break; 02752 case 3: /* atNetAddress */ 02753 { 02754 struct ip_addr *dst = value; 02755 02756 *dst = *ipaddr_ret; 02757 } 02758 break; 02759 } 02760 } 02761 #endif /* LWIP_ARP */ 02762 } 02763 02764 static void 02765 ip_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) 02766 { 02767 u8_t id; 02768 02769 /* return to object name, adding index depth (1) */ 02770 ident_len += 1; 02771 ident -= 1; 02772 if (ident_len == 2) 02773 { 02774 od->id_inst_len = ident_len; 02775 od->id_inst_ptr = ident; 02776 02777 id = ident[0]; 02778 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def ip.%"U16_F".0\n",(u16_t)id)); 02779 switch (id) 02780 { 02781 case 1: /* ipForwarding */ 02782 case 2: /* ipDefaultTTL */ 02783 od->instance = MIB_OBJECT_SCALAR; 02784 od->access = MIB_OBJECT_READ_WRITE; 02785 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); 02786 od->v_len = sizeof(s32_t); 02787 break; 02788 case 3: /* ipInReceives */ 02789 case 4: /* ipInHdrErrors */ 02790 case 5: /* ipInAddrErrors */ 02791 case 6: /* ipForwDatagrams */ 02792 case 7: /* ipInUnknownProtos */ 02793 case 8: /* ipInDiscards */ 02794 case 9: /* ipInDelivers */ 02795 case 10: /* ipOutRequests */ 02796 case 11: /* ipOutDiscards */ 02797 case 12: /* ipOutNoRoutes */ 02798 case 14: /* ipReasmReqds */ 02799 case 15: /* ipReasmOKs */ 02800 case 16: /* ipReasmFails */ 02801 case 17: /* ipFragOKs */ 02802 case 18: /* ipFragFails */ 02803 case 19: /* ipFragCreates */ 02804 case 23: /* ipRoutingDiscards */ 02805 od->instance = MIB_OBJECT_SCALAR; 02806 od->access = MIB_OBJECT_READ_ONLY; 02807 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER); 02808 od->v_len = sizeof(u32_t); 02809 break; 02810 case 13: /* ipReasmTimeout */ 02811 od->instance = MIB_OBJECT_SCALAR; 02812 od->access = MIB_OBJECT_READ_ONLY; 02813 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); 02814 od->v_len = sizeof(s32_t); 02815 break; 02816 default: 02817 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_object_def: no such object\n")); 02818 od->instance = MIB_OBJECT_NONE; 02819 break; 02820 }; 02821 } 02822 else 02823 { 02824 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_object_def: no scalar\n")); 02825 od->instance = MIB_OBJECT_NONE; 02826 } 02827 } 02828 02829 static void 02830 ip_get_value (struct obj_def *od, u16_t len, void *value) 02831 { 02832 u8_t id; 02833 02834 if (len) {} 02835 id = od->id_inst_ptr[0]; 02836 switch (id) 02837 { 02838 case 1: /* ipForwarding */ 02839 { 02840 s32_t *sint_ptr = value; 02841 #if IP_FORWARD 02842 /* forwarding */ 02843 *sint_ptr = 1; 02844 #else 02845 /* not-forwarding */ 02846 *sint_ptr = 2; 02847 #endif 02848 } 02849 break; 02850 case 2: /* ipDefaultTTL */ 02851 { 02852 s32_t *sint_ptr = value; 02853 *sint_ptr = IP_DEFAULT_TTL; 02854 } 02855 break; 02856 case 3: /* ipInReceives */ 02857 { 02858 u32_t *uint_ptr = value; 02859 *uint_ptr = ipinreceives; 02860 } 02861 break; 02862 case 4: /* ipInHdrErrors */ 02863 { 02864 u32_t *uint_ptr = value; 02865 *uint_ptr = ipinhdrerrors; 02866 } 02867 break; 02868 case 5: /* ipInAddrErrors */ 02869 { 02870 u32_t *uint_ptr = value; 02871 *uint_ptr = ipinaddrerrors; 02872 } 02873 break; 02874 case 6: /* ipForwDatagrams */ 02875 { 02876 u32_t *uint_ptr = value; 02877 *uint_ptr = ipforwdatagrams; 02878 } 02879 break; 02880 case 7: /* ipInUnknownProtos */ 02881 { 02882 u32_t *uint_ptr = value; 02883 *uint_ptr = ipinunknownprotos; 02884 } 02885 break; 02886 case 8: /* ipInDiscards */ 02887 { 02888 u32_t *uint_ptr = value; 02889 *uint_ptr = ipindiscards; 02890 } 02891 break; 02892 case 9: /* ipInDelivers */ 02893 { 02894 u32_t *uint_ptr = value; 02895 *uint_ptr = ipindelivers; 02896 } 02897 break; 02898 case 10: /* ipOutRequests */ 02899 { 02900 u32_t *uint_ptr = value; 02901 *uint_ptr = ipoutrequests; 02902 } 02903 break; 02904 case 11: /* ipOutDiscards */ 02905 { 02906 u32_t *uint_ptr = value; 02907 *uint_ptr = ipoutdiscards; 02908 } 02909 break; 02910 case 12: /* ipOutNoRoutes */ 02911 { 02912 u32_t *uint_ptr = value; 02913 *uint_ptr = ipoutnoroutes; 02914 } 02915 break; 02916 case 13: /* ipReasmTimeout */ 02917 { 02918 s32_t *sint_ptr = value; 02919 #if IP_REASSEMBLY 02920 *sint_ptr = IP_REASS_MAXAGE; 02921 #else 02922 *sint_ptr = 0; 02923 #endif 02924 } 02925 break; 02926 case 14: /* ipReasmReqds */ 02927 { 02928 u32_t *uint_ptr = value; 02929 *uint_ptr = ipreasmreqds; 02930 } 02931 break; 02932 case 15: /* ipReasmOKs */ 02933 { 02934 u32_t *uint_ptr = value; 02935 *uint_ptr = ipreasmoks; 02936 } 02937 break; 02938 case 16: /* ipReasmFails */ 02939 { 02940 u32_t *uint_ptr = value; 02941 *uint_ptr = ipreasmfails; 02942 } 02943 break; 02944 case 17: /* ipFragOKs */ 02945 { 02946 u32_t *uint_ptr = value; 02947 *uint_ptr = ipfragoks; 02948 } 02949 break; 02950 case 18: /* ipFragFails */ 02951 { 02952 u32_t *uint_ptr = value; 02953 *uint_ptr = ipfragfails; 02954 } 02955 break; 02956 case 19: /* ipFragCreates */ 02957 { 02958 u32_t *uint_ptr = value; 02959 *uint_ptr = ipfragcreates; 02960 } 02961 break; 02962 case 23: /* ipRoutingDiscards */ 02963 /** @todo can lwIP discard routes at all?? hardwire this to 0?? */ 02964 { 02965 u32_t *uint_ptr = value; 02966 *uint_ptr = iproutingdiscards; 02967 } 02968 break; 02969 }; 02970 } 02971 02972 /** 02973 * Test ip object value before setting. 02974 * 02975 * @param od is the object definition 02976 * @param len return value space (in bytes) 02977 * @param value points to (varbind) space to copy value from. 02978 * 02979 * @note we allow set if the value matches the hardwired value, 02980 * otherwise return badvalue. 02981 */ 02982 static u8_t 02983 ip_set_test(struct obj_def *od, u16_t len, void *value) 02984 { 02985 u8_t id, set_ok; 02986 s32_t *sint_ptr = value; 02987 02988 if (len) {} 02989 set_ok = 0; 02990 id = od->id_inst_ptr[0]; 02991 switch (id) 02992 { 02993 case 1: /* ipForwarding */ 02994 #if IP_FORWARD 02995 /* forwarding */ 02996 if (*sint_ptr == 1) 02997 #else 02998 /* not-forwarding */ 02999 if (*sint_ptr == 2) 03000 #endif 03001 { 03002 set_ok = 1; 03003 } 03004 break; 03005 case 2: /* ipDefaultTTL */ 03006 if (*sint_ptr == IP_DEFAULT_TTL) 03007 { 03008 set_ok = 1; 03009 } 03010 break; 03011 }; 03012 return set_ok; 03013 } 03014 03015 static void 03016 ip_addrentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) 03017 { 03018 /* return to object name, adding index depth (4) */ 03019 ident_len += 4; 03020 ident -= 4; 03021 03022 if (ident_len == 5) 03023 { 03024 u8_t id; 03025 03026 od->id_inst_len = ident_len; 03027 od->id_inst_ptr = ident; 03028 03029 id = ident[0]; 03030 switch (id) 03031 { 03032 case 1: /* ipAdEntAddr */ 03033 case 3: /* ipAdEntNetMask */ 03034 od->instance = MIB_OBJECT_TAB; 03035 od->access = MIB_OBJECT_READ_ONLY; 03036 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR); 03037 od->v_len = 4; 03038 break; 03039 case 2: /* ipAdEntIfIndex */ 03040 case 4: /* ipAdEntBcastAddr */ 03041 case 5: /* ipAdEntReasmMaxSize */ 03042 od->instance = MIB_OBJECT_TAB; 03043 od->access = MIB_OBJECT_READ_ONLY; 03044 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); 03045 od->v_len = sizeof(s32_t); 03046 break; 03047 default: 03048 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_object_def: no such object\n")); 03049 od->instance = MIB_OBJECT_NONE; 03050 break; 03051 } 03052 } 03053 else 03054 { 03055 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_object_def: no scalar\n")); 03056 od->instance = MIB_OBJECT_NONE; 03057 } 03058 } 03059 03060 static void 03061 ip_addrentry_get_value (struct obj_def *od, u16_t len, void *value) 03062 { 03063 u8_t id; 03064 u16_t ifidx; 03065 struct ip_addr ip; 03066 struct netif *netif = netif_list; 03067 03068 if (len) {} 03069 snmp_oidtoip(&od->id_inst_ptr[1], &ip); 03070 ip.addr = htonl(ip.addr); 03071 ifidx = 0; 03072 while ((netif != NULL) && !ip_addr_cmp(&ip, &netif->ip_addr)) 03073 { 03074 netif = netif->next; 03075 ifidx++; 03076 } 03077 03078 if (netif != NULL) 03079 { 03080 id = od->id_inst_ptr[0]; 03081 switch (id) 03082 { 03083 case 1: /* ipAdEntAddr */ 03084 { 03085 struct ip_addr *dst = value; 03086 *dst = netif->ip_addr; 03087 } 03088 break; 03089 case 2: /* ipAdEntIfIndex */ 03090 { 03091 s32_t *sint_ptr = value; 03092 *sint_ptr = ifidx + 1; 03093 } 03094 break; 03095 case 3: /* ipAdEntNetMask */ 03096 { 03097 struct ip_addr *dst = value; 03098 *dst = netif->netmask; 03099 } 03100 break; 03101 case 4: /* ipAdEntBcastAddr */ 03102 { 03103 s32_t *sint_ptr = value; 03104 03105 /* lwIP oddity, there's no broadcast 03106 address in the netif we can rely on */ 03107 *sint_ptr = ip_addr_broadcast.addr & 1; 03108 } 03109 break; 03110 case 5: /* ipAdEntReasmMaxSize */ 03111 { 03112 s32_t *sint_ptr = value; 03113 #if IP_REASSEMBLY 03114 /* @todo The theoretical maximum is IP_REASS_MAX_PBUFS * size of the pbufs, 03115 * but only if receiving one fragmented packet at a time. 03116 * The current solution is to calculate for 2 simultaneous packets... 03117 */ 03118 *sint_ptr = (IP_HLEN + ((IP_REASS_MAX_PBUFS/2) * 03119 (PBUF_POOL_BUFSIZE - PBUF_LINK_HLEN - IP_HLEN))); 03120 #else 03121 /** @todo returning MTU would be a bad thing and 03122 returning a wild guess like '576' isn't good either */ 03123 *sint_ptr = 0; 03124 #endif 03125 } 03126 break; 03127 } 03128 } 03129 } 03130 03131 /** 03132 * @note 03133 * lwIP IP routing is currently using the network addresses in netif_list. 03134 * if no suitable network IP is found in netif_list, the default_netif is used. 03135 */ 03136 static void 03137 ip_rteentry_get_object_def (u8_t ident_len, s32_t *ident, struct obj_def *od) 03138 { 03139 u8_t id; 03140 03141 /* return to object name, adding index depth (4) */ 03142 ident_len += 4; 03143 ident -= 4; 03144 03145 if (ident_len == 5) 03146 { 03147 od->id_inst_len = ident_len; 03148 od->id_inst_ptr = ident; 03149 03150 id = ident[0]; 03151 switch (id) 03152 { 03153 case 1: /* ipRouteDest */ 03154 case 7: /* ipRouteNextHop */ 03155 case 11: /* ipRouteMask */ 03156 od->instance = MIB_OBJECT_TAB; 03157 od->access = MIB_OBJECT_READ_WRITE; 03158 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR); 03159 od->v_len = 4; 03160 break; 03161 case 2: /* ipRouteIfIndex */ 03162 case 3: /* ipRouteMetric1 */ 03163 case 4: /* ipRouteMetric2 */ 03164 case 5: /* ipRouteMetric3 */ 03165 case 6: /* ipRouteMetric4 */ 03166 case 8: /* ipRouteType */ 03167 case 10: /* ipRouteAge */ 03168 case 12: /* ipRouteMetric5 */ 03169 od->instance = MIB_OBJECT_TAB; 03170 od->access = MIB_OBJECT_READ_WRITE; 03171 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); 03172 od->v_len = sizeof(s32_t); 03173 break; 03174 case 9: /* ipRouteProto */ 03175 od->instance = MIB_OBJECT_TAB; 03176 od->access = MIB_OBJECT_READ_ONLY; 03177 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); 03178 od->v_len = sizeof(s32_t); 03179 break; 03180 case 13: /* ipRouteInfo */ 03181 /** @note returning zeroDotZero (0.0) no routing protocol specific MIB */ 03182 od->instance = MIB_OBJECT_TAB; 03183 od->access = MIB_OBJECT_READ_ONLY; 03184 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID); 03185 od->v_len = iprouteinfo.len * sizeof(s32_t); 03186 break; 03187 default: 03188 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_object_def: no such object\n")); 03189 od->instance = MIB_OBJECT_NONE; 03190 break; 03191 } 03192 } 03193 else 03194 { 03195 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_object_def: no scalar\n")); 03196 od->instance = MIB_OBJECT_NONE; 03197 } 03198 } 03199 03200 static void 03201 ip_rteentry_get_value (struct obj_def *od, u16_t len, void *value) 03202 { 03203 struct netif *netif; 03204 struct ip_addr dest; 03205 s32_t *ident; 03206 u8_t id; 03207 03208 ident = od->id_inst_ptr; 03209 snmp_oidtoip(&ident[1], &dest); 03210 dest.addr = htonl(dest.addr); 03211 03212 if (dest.addr == 0) 03213 { 03214 /* ip_route() uses default netif for default route */ 03215 netif = netif_default; 03216 } 03217 else 03218 { 03219 /* not using ip_route(), need exact match! */ 03220 netif = netif_list; 03221 while ((netif != NULL) && 03222 !ip_addr_netcmp(&dest, &(netif->ip_addr), &(netif->netmask)) ) 03223 { 03224 netif = netif->next; 03225 } 03226 } 03227 if (netif != NULL) 03228 { 03229 id = ident[0]; 03230 switch (id) 03231 { 03232 case 1: /* ipRouteDest */ 03233 { 03234 struct ip_addr *dst = value; 03235 03236 if (dest.addr == 0) 03237 { 03238 /* default rte has 0.0.0.0 dest */ 03239 dst->addr = 0; 03240 } 03241 else 03242 { 03243 /* netifs have netaddress dest */ 03244 dst->addr = netif->ip_addr.addr & netif->netmask.addr; 03245 } 03246 } 03247 break; 03248 case 2: /* ipRouteIfIndex */ 03249 { 03250 s32_t *sint_ptr = value; 03251 03252 snmp_netiftoifindex(netif, sint_ptr); 03253 } 03254 break; 03255 case 3: /* ipRouteMetric1 */ 03256 { 03257 s32_t *sint_ptr = value; 03258 03259 if (dest.addr == 0) 03260 { 03261 /* default rte has metric 1 */ 03262 *sint_ptr = 1; 03263 } 03264 else 03265 { 03266 /* other rtes have metric 0 */ 03267 *sint_ptr = 0; 03268 } 03269 } 03270 break; 03271 case 4: /* ipRouteMetric2 */ 03272 case 5: /* ipRouteMetric3 */ 03273 case 6: /* ipRouteMetric4 */ 03274 case 12: /* ipRouteMetric5 */ 03275 { 03276 s32_t *sint_ptr = value; 03277 /* not used */ 03278 *sint_ptr = -1; 03279 } 03280 break; 03281 case 7: /* ipRouteNextHop */ 03282 { 03283 struct ip_addr *dst = value; 03284 03285 if (dest.addr == 0) 03286 { 03287 /* default rte: gateway */ 03288 *dst = netif->gw; 03289 } 03290 else 03291 { 03292 /* other rtes: netif ip_addr */ 03293 *dst = netif->ip_addr; 03294 } 03295 } 03296 break; 03297 case 8: /* ipRouteType */ 03298 { 03299 s32_t *sint_ptr = value; 03300 03301 if (dest.addr == 0) 03302 { 03303 /* default rte is indirect */ 03304 *sint_ptr = 4; 03305 } 03306 else 03307 { 03308 /* other rtes are direct */ 03309 *sint_ptr = 3; 03310 } 03311 } 03312 break; 03313 case 9: /* ipRouteProto */ 03314 { 03315 s32_t *sint_ptr = value; 03316 /* locally defined routes */ 03317 *sint_ptr = 2; 03318 } 03319 break; 03320 case 10: /* ipRouteAge */ 03321 { 03322 s32_t *sint_ptr = value; 03323 /** @todo (sysuptime - timestamp last change) / 100 03324 @see snmp_insert_iprteidx_tree() */ 03325 *sint_ptr = 0; 03326 } 03327 break; 03328 case 11: /* ipRouteMask */ 03329 { 03330 struct ip_addr *dst = value; 03331 03332 if (dest.addr == 0) 03333 { 03334 /* default rte use 0.0.0.0 mask */ 03335 dst->addr = 0; 03336 } 03337 else 03338 { 03339 /* other rtes use netmask */ 03340 *dst = netif->netmask; 03341 } 03342 } 03343 break; 03344 case 13: /* ipRouteInfo */ 03345 objectidncpy((s32_t*)value, (s32_t*)iprouteinfo.id, (u8_t)(len / sizeof(s32_t))); 03346 break; 03347 } 03348 } 03349 } 03350 03351 static void 03352 ip_ntomentry_get_object_def (u8_t ident_len, s32_t *ident, struct obj_def *od) 03353 { 03354 /* return to object name, adding index depth (5) */ 03355 ident_len += 5; 03356 ident -= 5; 03357 03358 if (ident_len == 6) 03359 { 03360 u8_t id; 03361 03362 od->id_inst_len = ident_len; 03363 od->id_inst_ptr = ident; 03364 03365 id = ident[0]; 03366 switch (id) 03367 { 03368 case 1: /* ipNetToMediaIfIndex */ 03369 case 4: /* ipNetToMediaType */ 03370 od->instance = MIB_OBJECT_TAB; 03371 od->access = MIB_OBJECT_READ_WRITE; 03372 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); 03373 od->v_len = sizeof(s32_t); 03374 break; 03375 case 2: /* ipNetToMediaPhysAddress */ 03376 od->instance = MIB_OBJECT_TAB; 03377 od->access = MIB_OBJECT_READ_WRITE; 03378 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); 03379 od->v_len = 6; /** @todo try to use netif::hwaddr_len */ 03380 break; 03381 case 3: /* ipNetToMediaNetAddress */ 03382 od->instance = MIB_OBJECT_TAB; 03383 od->access = MIB_OBJECT_READ_WRITE; 03384 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR); 03385 od->v_len = 4; 03386 break; 03387 default: 03388 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_object_def: no such object\n")); 03389 od->instance = MIB_OBJECT_NONE; 03390 break; 03391 } 03392 } 03393 else 03394 { 03395 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_object_def: no scalar\n")); 03396 od->instance = MIB_OBJECT_NONE; 03397 } 03398 } 03399 03400 static void 03401 ip_ntomentry_get_value(struct obj_def *od, u16_t len, void *value) 03402 { 03403 #if LWIP_ARP 03404 u8_t id; 03405 struct eth_addr* ethaddr_ret; 03406 struct ip_addr* ipaddr_ret; 03407 #endif /* LWIP_ARP */ 03408 struct ip_addr ip; 03409 struct netif *netif; 03410 03411 if (len) {} 03412 03413 snmp_ifindextonetif(od->id_inst_ptr[1], &netif); 03414 snmp_oidtoip(&od->id_inst_ptr[2], &ip); 03415 ip.addr = htonl(ip.addr); 03416 03417 #if LWIP_ARP /** @todo implement a netif_find_addr */ 03418 if (etharp_find_addr(netif, &ip, ðaddr_ret, &ipaddr_ret) > -1) 03419 { 03420 id = od->id_inst_ptr[0]; 03421 switch (id) 03422 { 03423 case 1: /* ipNetToMediaIfIndex */ 03424 { 03425 s32_t *sint_ptr = value; 03426 *sint_ptr = od->id_inst_ptr[1]; 03427 } 03428 break; 03429 case 2: /* ipNetToMediaPhysAddress */ 03430 { 03431 struct eth_addr *dst = value; 03432 03433 *dst = *ethaddr_ret; 03434 } 03435 break; 03436 case 3: /* ipNetToMediaNetAddress */ 03437 { 03438 struct ip_addr *dst = value; 03439 03440 *dst = *ipaddr_ret; 03441 } 03442 break; 03443 case 4: /* ipNetToMediaType */ 03444 { 03445 s32_t *sint_ptr = value; 03446 /* dynamic (?) */ 03447 *sint_ptr = 3; 03448 } 03449 break; 03450 } 03451 } 03452 #endif /* LWIP_ARP */ 03453 } 03454 03455 static void 03456 icmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) 03457 { 03458 /* return to object name, adding index depth (1) */ 03459 ident_len += 1; 03460 ident -= 1; 03461 if ((ident_len == 2) && 03462 (ident[0] > 0) && (ident[0] < 27)) 03463 { 03464 od->id_inst_len = ident_len; 03465 od->id_inst_ptr = ident; 03466 03467 od->instance = MIB_OBJECT_SCALAR; 03468 od->access = MIB_OBJECT_READ_ONLY; 03469 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER); 03470 od->v_len = sizeof(u32_t); 03471 } 03472 else 03473 { 03474 LWIP_DEBUGF(SNMP_MIB_DEBUG,("icmp_get_object_def: no scalar\n")); 03475 od->instance = MIB_OBJECT_NONE; 03476 } 03477 } 03478 03479 static void 03480 icmp_get_value(struct obj_def *od, u16_t len, void *value) 03481 { 03482 u32_t *uint_ptr = value; 03483 u8_t id; 03484 03485 if (len){} 03486 id = od->id_inst_ptr[0]; 03487 switch (id) 03488 { 03489 case 1: /* icmpInMsgs */ 03490 *uint_ptr = icmpinmsgs; 03491 break; 03492 case 2: /* icmpInErrors */ 03493 *uint_ptr = icmpinerrors; 03494 break; 03495 case 3: /* icmpInDestUnreachs */ 03496 *uint_ptr = icmpindestunreachs; 03497 break; 03498 case 4: /* icmpInTimeExcds */ 03499 *uint_ptr = icmpintimeexcds; 03500 break; 03501 case 5: /* icmpInParmProbs */ 03502 *uint_ptr = icmpinparmprobs; 03503 break; 03504 case 6: /* icmpInSrcQuenchs */ 03505 *uint_ptr = icmpinsrcquenchs; 03506 break; 03507 case 7: /* icmpInRedirects */ 03508 *uint_ptr = icmpinredirects; 03509 break; 03510 case 8: /* icmpInEchos */ 03511 *uint_ptr = icmpinechos; 03512 break; 03513 case 9: /* icmpInEchoReps */ 03514 *uint_ptr = icmpinechoreps; 03515 break; 03516 case 10: /* icmpInTimestamps */ 03517 *uint_ptr = icmpintimestamps; 03518 break; 03519 case 11: /* icmpInTimestampReps */ 03520 *uint_ptr = icmpintimestampreps; 03521 break; 03522 case 12: /* icmpInAddrMasks */ 03523 *uint_ptr = icmpinaddrmasks; 03524 break; 03525 case 13: /* icmpInAddrMaskReps */ 03526 *uint_ptr = icmpinaddrmaskreps; 03527 break; 03528 case 14: /* icmpOutMsgs */ 03529 *uint_ptr = icmpoutmsgs; 03530 break; 03531 case 15: /* icmpOutErrors */ 03532 *uint_ptr = icmpouterrors; 03533 break; 03534 case 16: /* icmpOutDestUnreachs */ 03535 *uint_ptr = icmpoutdestunreachs; 03536 break; 03537 case 17: /* icmpOutTimeExcds */ 03538 *uint_ptr = icmpouttimeexcds; 03539 break; 03540 case 18: /* icmpOutParmProbs */ 03541 *uint_ptr = icmpoutparmprobs; 03542 break; 03543 case 19: /* icmpOutSrcQuenchs */ 03544 *uint_ptr = icmpoutsrcquenchs; 03545 break; 03546 case 20: /* icmpOutRedirects */ 03547 *uint_ptr = icmpoutredirects; 03548 break; 03549 case 21: /* icmpOutEchos */ 03550 *uint_ptr = icmpoutechos; 03551 break; 03552 case 22: /* icmpOutEchoReps */ 03553 *uint_ptr = icmpoutechoreps; 03554 break; 03555 case 23: /* icmpOutTimestamps */ 03556 *uint_ptr = icmpouttimestamps; 03557 break; 03558 case 24: /* icmpOutTimestampReps */ 03559 *uint_ptr = icmpouttimestampreps; 03560 break; 03561 case 25: /* icmpOutAddrMasks */ 03562 *uint_ptr = icmpoutaddrmasks; 03563 break; 03564 case 26: /* icmpOutAddrMaskReps */ 03565 *uint_ptr = icmpoutaddrmaskreps; 03566 break; 03567 } 03568 } 03569 03570 #if LWIP_TCP 03571 /** @todo tcp grp */ 03572 static void 03573 tcp_get_object_def (u8_t ident_len, s32_t *ident, struct obj_def *od) 03574 { 03575 u8_t id; 03576 03577 /* return to object name, adding index depth (1) */ 03578 ident_len += 1; 03579 ident -= 1; 03580 if (ident_len == 2) 03581 { 03582 od->id_inst_len = ident_len; 03583 od->id_inst_ptr = ident; 03584 03585 id = ident[0]; 03586 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def tcp.%"U16_F".0\n",(u16_t)id)); 03587 03588 switch (id) 03589 { 03590 case 1: /* tcpRtoAlgorithm */ 03591 case 2: /* tcpRtoMin */ 03592 case 3: /* tcpRtoMax */ 03593 case 4: /* tcpMaxConn */ 03594 od->instance = MIB_OBJECT_SCALAR; 03595 od->access = MIB_OBJECT_READ_ONLY; 03596 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); 03597 od->v_len = sizeof(s32_t); 03598 break; 03599 case 5: /* tcpActiveOpens */ 03600 case 6: /* tcpPassiveOpens */ 03601 case 7: /* tcpAttemptFails */ 03602 case 8: /* tcpEstabResets */ 03603 case 10: /* tcpInSegs */ 03604 case 11: /* tcpOutSegs */ 03605 case 12: /* tcpRetransSegs */ 03606 case 14: /* tcpInErrs */ 03607 case 15: /* tcpOutRsts */ 03608 od->instance = MIB_OBJECT_SCALAR; 03609 od->access = MIB_OBJECT_READ_ONLY; 03610 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER); 03611 od->v_len = sizeof(u32_t); 03612 break; 03613 case 9: /* tcpCurrEstab */ 03614 od->instance = MIB_OBJECT_TAB; 03615 od->access = MIB_OBJECT_READ_ONLY; 03616 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE); 03617 od->v_len = sizeof(u32_t); 03618 break; 03619 default: 03620 LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_object_def: no such object\n")); 03621 od->instance = MIB_OBJECT_NONE; 03622 break; 03623 }; 03624 } 03625 else 03626 { 03627 LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_object_def: no scalar\n")); 03628 od->instance = MIB_OBJECT_NONE; 03629 } 03630 } 03631 03632 static void 03633 tcp_get_value(struct obj_def *od, u16_t len, void *value) 03634 { 03635 u32_t *uint_ptr = value; 03636 s32_t *sint_ptr = value; 03637 u8_t id; 03638 03639 if (len){} 03640 id = od->id_inst_ptr[0]; 03641 switch (id) 03642 { 03643 case 1: /* tcpRtoAlgorithm, vanj(4) */ 03644 *sint_ptr = 4; 03645 break; 03646 case 2: /* tcpRtoMin */ 03647 /* @todo not the actual value, a guess, 03648 needs to be calculated */ 03649 *sint_ptr = 1000; 03650 break; 03651 case 3: /* tcpRtoMax */ 03652 /* @todo not the actual value, a guess, 03653 needs to be calculated */ 03654 *sint_ptr = 60000; 03655 break; 03656 case 4: /* tcpMaxConn */ 03657 *sint_ptr = MEMP_NUM_TCP_PCB; 03658 break; 03659 case 5: /* tcpActiveOpens */ 03660 *uint_ptr = tcpactiveopens; 03661 break; 03662 case 6: /* tcpPassiveOpens */ 03663 *uint_ptr = tcppassiveopens; 03664 break; 03665 case 7: /* tcpAttemptFails */ 03666 *uint_ptr = tcpattemptfails; 03667 break; 03668 case 8: /* tcpEstabResets */ 03669 *uint_ptr = tcpestabresets; 03670 break; 03671 case 9: /* tcpCurrEstab */ 03672 { 03673 u16_t tcpcurrestab = 0; 03674 struct tcp_pcb *pcb = tcp_active_pcbs; 03675 while (pcb != NULL) 03676 { 03677 if ((pcb->state == ESTABLISHED) || 03678 (pcb->state == CLOSE_WAIT)) 03679 { 03680 tcpcurrestab++; 03681 } 03682 pcb = pcb->next; 03683 } 03684 *uint_ptr = tcpcurrestab; 03685 } 03686 break; 03687 case 10: /* tcpInSegs */ 03688 *uint_ptr = tcpinsegs; 03689 break; 03690 case 11: /* tcpOutSegs */ 03691 *uint_ptr = tcpoutsegs; 03692 break; 03693 case 12: /* tcpRetransSegs */ 03694 *uint_ptr = tcpretranssegs; 03695 break; 03696 case 14: /* tcpInErrs */ 03697 *uint_ptr = tcpinerrs; 03698 break; 03699 case 15: /* tcpOutRsts */ 03700 *uint_ptr = tcpoutrsts; 03701 break; 03702 } 03703 } 03704 #ifdef THIS_SEEMS_UNUSED 03705 static void 03706 tcpconnentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) 03707 { 03708 /* return to object name, adding index depth (10) */ 03709 ident_len += 10; 03710 ident -= 10; 03711 03712 if (ident_len == 11) 03713 { 03714 u8_t id; 03715 03716 od->id_inst_len = ident_len; 03717 od->id_inst_ptr = ident; 03718 03719 id = ident[0]; 03720 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def tcp.%"U16_F".0\n",(u16_t)id)); 03721 03722 switch (id) 03723 { 03724 case 1: /* tcpConnState */ 03725 od->instance = MIB_OBJECT_TAB; 03726 od->access = MIB_OBJECT_READ_WRITE; 03727 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); 03728 od->v_len = sizeof(s32_t); 03729 break; 03730 case 2: /* tcpConnLocalAddress */ 03731 case 4: /* tcpConnRemAddress */ 03732 od->instance = MIB_OBJECT_TAB; 03733 od->access = MIB_OBJECT_READ_ONLY; 03734 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR); 03735 od->v_len = 4; 03736 break; 03737 case 3: /* tcpConnLocalPort */ 03738 case 5: /* tcpConnRemPort */ 03739 od->instance = MIB_OBJECT_TAB; 03740 od->access = MIB_OBJECT_READ_ONLY; 03741 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); 03742 od->v_len = sizeof(s32_t); 03743 break; 03744 default: 03745 LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcpconnentry_get_object_def: no such object\n")); 03746 od->instance = MIB_OBJECT_NONE; 03747 break; 03748 }; 03749 } 03750 else 03751 { 03752 LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcpconnentry_get_object_def: no such object\n")); 03753 od->instance = MIB_OBJECT_NONE; 03754 } 03755 } 03756 03757 static void 03758 tcpconnentry_get_value (struct obj_def *od, u16_t len, void *value) 03759 { 03760 struct ip_addr lip, rip; 03761 u16_t lport, rport; 03762 s32_t *ident; 03763 03764 ident = od->id_inst_ptr; 03765 snmp_oidtoip(&ident[1], &lip); 03766 lip.addr = htonl(lip.addr); 03767 lport = ident[5]; 03768 snmp_oidtoip(&ident[6], &rip); 03769 rip.addr = htonl(rip.addr); 03770 rport = ident[10]; 03771 03772 /** @todo find matching PCB */ 03773 } 03774 #endif /* if 0 */ 03775 #endif 03776 03777 static void 03778 udp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) 03779 { 03780 /* return to object name, adding index depth (1) */ 03781 ident_len += 1; 03782 ident -= 1; 03783 if ((ident_len == 2) && 03784 (ident[0] > 0) && (ident[0] < 6)) 03785 { 03786 od->id_inst_len = ident_len; 03787 od->id_inst_ptr = ident; 03788 03789 od->instance = MIB_OBJECT_SCALAR; 03790 od->access = MIB_OBJECT_READ_ONLY; 03791 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER); 03792 od->v_len = sizeof(u32_t); 03793 } 03794 else 03795 { 03796 LWIP_DEBUGF(SNMP_MIB_DEBUG,("udp_get_object_def: no scalar\n")); 03797 od->instance = MIB_OBJECT_NONE; 03798 } 03799 } 03800 03801 static void 03802 udp_get_value(struct obj_def *od, u16_t len, void *value) 03803 { 03804 u32_t *uint_ptr = value; 03805 u8_t id; 03806 03807 if (len){} 03808 id = od->id_inst_ptr[0]; 03809 switch (id) 03810 { 03811 case 1: /* udpInDatagrams */ 03812 *uint_ptr = udpindatagrams; 03813 break; 03814 case 2: /* udpNoPorts */ 03815 *uint_ptr = udpnoports; 03816 break; 03817 case 3: /* udpInErrors */ 03818 *uint_ptr = udpinerrors; 03819 break; 03820 case 4: /* udpOutDatagrams */ 03821 *uint_ptr = udpoutdatagrams; 03822 break; 03823 } 03824 } 03825 03826 static void 03827 udpentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) 03828 { 03829 /* return to object name, adding index depth (5) */ 03830 ident_len += 5; 03831 ident -= 5; 03832 03833 if (ident_len == 6) 03834 { 03835 od->id_inst_len = ident_len; 03836 od->id_inst_ptr = ident; 03837 03838 switch (ident[0]) 03839 { 03840 case 1: /* udpLocalAddress */ 03841 od->instance = MIB_OBJECT_TAB; 03842 od->access = MIB_OBJECT_READ_ONLY; 03843 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR); 03844 od->v_len = 4; 03845 break; 03846 case 2: /* udpLocalPort */ 03847 od->instance = MIB_OBJECT_TAB; 03848 od->access = MIB_OBJECT_READ_ONLY; 03849 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); 03850 od->v_len = sizeof(s32_t); 03851 break; 03852 default: 03853 LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_object_def: no such object\n")); 03854 od->instance = MIB_OBJECT_NONE; 03855 break; 03856 } 03857 } 03858 else 03859 { 03860 LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_object_def: no scalar\n")); 03861 od->instance = MIB_OBJECT_NONE; 03862 } 03863 } 03864 03865 static void 03866 udpentry_get_value(struct obj_def *od, u16_t len, void *value) 03867 { 03868 u8_t id; 03869 struct udp_pcb *pcb; 03870 struct ip_addr ip; 03871 u16_t port; 03872 03873 if (len){} 03874 snmp_oidtoip(&od->id_inst_ptr[1], &ip); 03875 ip.addr = htonl(ip.addr); 03876 port = od->id_inst_ptr[5]; 03877 03878 pcb = udp_pcbs; 03879 while ((pcb != NULL) && 03880 !((pcb->local_ip.addr == ip.addr) && 03881 (pcb->local_port == port))) 03882 { 03883 pcb = pcb->next; 03884 } 03885 03886 if (pcb != NULL) 03887 { 03888 id = od->id_inst_ptr[0]; 03889 switch (id) 03890 { 03891 case 1: /* udpLocalAddress */ 03892 { 03893 struct ip_addr *dst = value; 03894 *dst = pcb->local_ip; 03895 } 03896 break; 03897 case 2: /* udpLocalPort */ 03898 { 03899 s32_t *sint_ptr = value; 03900 *sint_ptr = pcb->local_port; 03901 } 03902 break; 03903 } 03904 } 03905 } 03906 03907 static void 03908 snmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) 03909 { 03910 /* return to object name, adding index depth (1) */ 03911 ident_len += 1; 03912 ident -= 1; 03913 if (ident_len == 2) 03914 { 03915 u8_t id; 03916 03917 od->id_inst_len = ident_len; 03918 od->id_inst_ptr = ident; 03919 03920 id = ident[0]; 03921 switch (id) 03922 { 03923 case 1: /* snmpInPkts */ 03924 case 2: /* snmpOutPkts */ 03925 case 3: /* snmpInBadVersions */ 03926 case 4: /* snmpInBadCommunityNames */ 03927 case 5: /* snmpInBadCommunityUses */ 03928 case 6: /* snmpInASNParseErrs */ 03929 case 8: /* snmpInTooBigs */ 03930 case 9: /* snmpInNoSuchNames */ 03931 case 10: /* snmpInBadValues */ 03932 case 11: /* snmpInReadOnlys */ 03933 case 12: /* snmpInGenErrs */ 03934 case 13: /* snmpInTotalReqVars */ 03935 case 14: /* snmpInTotalSetVars */ 03936 case 15: /* snmpInGetRequests */ 03937 case 16: /* snmpInGetNexts */ 03938 case 17: /* snmpInSetRequests */ 03939 case 18: /* snmpInGetResponses */ 03940 case 19: /* snmpInTraps */ 03941 case 20: /* snmpOutTooBigs */ 03942 case 21: /* snmpOutNoSuchNames */ 03943 case 22: /* snmpOutBadValues */ 03944 case 24: /* snmpOutGenErrs */ 03945 case 25: /* snmpOutGetRequests */ 03946 case 26: /* snmpOutGetNexts */ 03947 case 27: /* snmpOutSetRequests */ 03948 case 28: /* snmpOutGetResponses */ 03949 case 29: /* snmpOutTraps */ 03950 od->instance = MIB_OBJECT_SCALAR; 03951 od->access = MIB_OBJECT_READ_ONLY; 03952 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER); 03953 od->v_len = sizeof(u32_t); 03954 break; 03955 case 30: /* snmpEnableAuthenTraps */ 03956 od->instance = MIB_OBJECT_SCALAR; 03957 od->access = MIB_OBJECT_READ_WRITE; 03958 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); 03959 od->v_len = sizeof(s32_t); 03960 break; 03961 default: 03962 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_object_def: no such object\n")); 03963 od->instance = MIB_OBJECT_NONE; 03964 break; 03965 }; 03966 } 03967 else 03968 { 03969 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_object_def: no scalar\n")); 03970 od->instance = MIB_OBJECT_NONE; 03971 } 03972 } 03973 03974 static void 03975 snmp_get_value(struct obj_def *od, u16_t len, void *value) 03976 { 03977 u32_t *uint_ptr = value; 03978 u8_t id; 03979 03980 if (len){} 03981 id = od->id_inst_ptr[0]; 03982 switch (id) 03983 { 03984 case 1: /* snmpInPkts */ 03985 *uint_ptr = snmpinpkts; 03986 break; 03987 case 2: /* snmpOutPkts */ 03988 *uint_ptr = snmpoutpkts; 03989 break; 03990 case 3: /* snmpInBadVersions */ 03991 *uint_ptr = snmpinbadversions; 03992 break; 03993 case 4: /* snmpInBadCommunityNames */ 03994 *uint_ptr = snmpinbadcommunitynames; 03995 break; 03996 case 5: /* snmpInBadCommunityUses */ 03997 *uint_ptr = snmpinbadcommunityuses; 03998 break; 03999 case 6: /* snmpInASNParseErrs */ 04000 *uint_ptr = snmpinasnparseerrs; 04001 break; 04002 case 8: /* snmpInTooBigs */ 04003 *uint_ptr = snmpintoobigs; 04004 break; 04005 case 9: /* snmpInNoSuchNames */ 04006 *uint_ptr = snmpinnosuchnames; 04007 break; 04008 case 10: /* snmpInBadValues */ 04009 *uint_ptr = snmpinbadvalues; 04010 break; 04011 case 11: /* snmpInReadOnlys */ 04012 *uint_ptr = snmpinreadonlys; 04013 break; 04014 case 12: /* snmpInGenErrs */ 04015 *uint_ptr = snmpingenerrs; 04016 break; 04017 case 13: /* snmpInTotalReqVars */ 04018 *uint_ptr = snmpintotalreqvars; 04019 break; 04020 case 14: /* snmpInTotalSetVars */ 04021 *uint_ptr = snmpintotalsetvars; 04022 break; 04023 case 15: /* snmpInGetRequests */ 04024 *uint_ptr = snmpingetrequests; 04025 break; 04026 case 16: /* snmpInGetNexts */ 04027 *uint_ptr = snmpingetnexts; 04028 break; 04029 case 17: /* snmpInSetRequests */ 04030 *uint_ptr = snmpinsetrequests; 04031 break; 04032 case 18: /* snmpInGetResponses */ 04033 *uint_ptr = snmpingetresponses; 04034 break; 04035 case 19: /* snmpInTraps */ 04036 *uint_ptr = snmpintraps; 04037 break; 04038 case 20: /* snmpOutTooBigs */ 04039 *uint_ptr = snmpouttoobigs; 04040 break; 04041 case 21: /* snmpOutNoSuchNames */ 04042 *uint_ptr = snmpoutnosuchnames; 04043 break; 04044 case 22: /* snmpOutBadValues */ 04045 *uint_ptr = snmpoutbadvalues; 04046 break; 04047 case 24: /* snmpOutGenErrs */ 04048 *uint_ptr = snmpoutgenerrs; 04049 break; 04050 case 25: /* snmpOutGetRequests */ 04051 *uint_ptr = snmpoutgetrequests; 04052 break; 04053 case 26: /* snmpOutGetNexts */ 04054 *uint_ptr = snmpoutgetnexts; 04055 break; 04056 case 27: /* snmpOutSetRequests */ 04057 *uint_ptr = snmpoutsetrequests; 04058 break; 04059 case 28: /* snmpOutGetResponses */ 04060 *uint_ptr = snmpoutgetresponses; 04061 break; 04062 case 29: /* snmpOutTraps */ 04063 *uint_ptr = snmpouttraps; 04064 break; 04065 case 30: /* snmpEnableAuthenTraps */ 04066 *uint_ptr = *snmpenableauthentraps_ptr; 04067 break; 04068 }; 04069 } 04070 04071 /** 04072 * Test snmp object value before setting. 04073 * 04074 * @param od is the object definition 04075 * @param len return value space (in bytes) 04076 * @param value points to (varbind) space to copy value from. 04077 */ 04078 static u8_t 04079 snmp_set_test(struct obj_def *od, u16_t len, void *value) 04080 { 04081 u8_t id, set_ok; 04082 04083 if (len) {} 04084 set_ok = 0; 04085 id = od->id_inst_ptr[0]; 04086 if (id == 30) 04087 { 04088 /* snmpEnableAuthenTraps */ 04089 s32_t *sint_ptr = value; 04090 04091 if (snmpenableauthentraps_ptr != &snmpenableauthentraps_default) 04092 { 04093 /* we should have writable non-volatile mem here */ 04094 if ((*sint_ptr == 1) || (*sint_ptr == 2)) 04095 { 04096 set_ok = 1; 04097 } 04098 } 04099 else 04100 { 04101 /* const or hardwired value */ 04102 if (*sint_ptr == snmpenableauthentraps_default) 04103 { 04104 set_ok = 1; 04105 } 04106 } 04107 } 04108 return set_ok; 04109 } 04110 04111 static void 04112 snmp_set_value(struct obj_def *od, u16_t len, void *value) 04113 { 04114 u8_t id; 04115 04116 if (len) {} 04117 id = od->id_inst_ptr[0]; 04118 if (id == 30) 04119 { 04120 /* snmpEnableAuthenTraps */ 04121 s32_t *sint_ptr = value; 04122 *snmpenableauthentraps_ptr = *sint_ptr; 04123 } 04124 } 04125 04126 #endif /* LWIP_SNMP */
Generated on Tue Jul 12 2022 16:06:17 by 1.7.2