snmplib.c revision a1c5472562e714fe175eb2fbfcde0ccba7385a6c
1N/A * The contents of this file are subject to the terms of the 1N/A * Common Development and Distribution License (the "License"). 1N/A * You may not use this file except in compliance with the License. 1N/A * See the License for the specific language governing permissions 1N/A * and limitations under the License. 1N/A * When distributing Covered Code, include this CDDL HEADER in each 1N/A * If applicable, add the following below this CDDL HEADER, with the 1N/A * fields enclosed by brackets "[]" replaced with your own identifying 1N/A * information: Portions Copyright [yyyy] [name of copyright owner] 1N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 1N/A * Use is subject to license terms. 1N/A#
pragma ident "%Z%%M% %I% %E% SMI" 1N/A * The snmp library helps to prepare the PDUs and communicate with 1N/A * the snmp agent on the SP side via the ds_snmp driver. 1N/A * Data from the MIB is fetched based on the hints about object 1N/A * groups received from (possibly many threads in) the application. 1N/A * However, the fetched data is kept in a common cache for use across 1N/A * all threads, so even a GETBULK is issued only when absolutely 1N/A * Note that locking is not fine grained (there's no locking per row) 1N/A * since we don't expect too many MT consumers right away. 1N/A * Static function declarations * Allocate a new oidgroup_t * Determine how much space is required to register this group for (i = 0; i <
n_oids; i++) {
* Link it to the tail of the list of oid groups * snmp_get_int() takes in an OID and returns the integer value * of the object referenced in the passed arg. It returns 0 on * success and -1 on failure. * If this item should not be cached, fetch it directly from * the agent using fetch_single_xxx() * fetch it from the agent and populate the cache * look it up again and return it * snmp_get_str() takes in an OID and returns the string value * of the object referenced in the passed arg. Memory for the string * is allocated within snmp_get_str() and is expected to be freed by * the caller when it is no longer needed. The function returns 0 * on success and -1 on failure. * Check if this item is cacheable or not. If not, call * fetch_single_* to get it directly from the agent * See if it's in the cache already * Fetch it from the agent and populate cache * snmp_get_bitstr() takes in an OID and returns the bit string value * of the object referenced in the passed args. Memory for the bitstring * is allocated within the function and is expected to be freed by * the caller when it is no longer needed. The function returns 0 * on success and -1 on failure. * Check if this item is cacheable or not. If not, call * fetch_single_* to get it directly from the agent * See if it's in the cache already * Fetch it from the agent and populate cache * snmp_get_nextrow() is similar in operation to SNMP_GETNEXT, but * only just. In particular, this is only expected to return the next * valid row number for the same object, not its value. Since we don't * have any other means, we use this to determine the number of rows * in the table (and the valid ones). This function returns 0 on success * The get_nextrow results should *never* go into any cache, * since these relationships are dynamically discovered each time. * We are not concerned about the "value" of the lexicographically * next object; we only care about the name of that object and * its row number (and whether such an object exists or not). * This indicates that we're at the end of the MIB view. * need to be able to convert the OID * We're on to the next table. * Ok, so we've got an oid that's simply the next valid row of the * passed on object, return this row number. * Request ids for snmp messages to the agent are sequenced here. * If this is a volatile property, we should be searching * for an integer-timestamp pair * If this is a volatile property, we should be searching * for a string-timestamp pair * We don't support volatile bit string values yet. The nvlist * functions don't support bitstring arrays like they do charstring * arrays, so we would need to do things in a convoluted way, * probably by attaching the timestamp as part of the byte array * itself. However, the need for volatile bitstrings isn't there * yet, to justify the effort. for (i = 0; i <
n_oids; i++) {
* Note that we don't make any distinction between unsigned int * value and signed int value at this point, since we provide * only snmp_get_int() at the higher level. While it is possible * to provide an entirely separate interface such as snmp_get_uint(), * that's quite unnecessary, because we don't do any interpretation * of the received value. Besides, the sizes of int and uint are * the same and the sizes of all pointers are the same (so val.iptr * would be the same as val.uiptr in pdu_varlist_t). If/when we * violate any of these assumptions, it will be time to add * If we're fetching volatile properties using BULKGET, don't * venture to get multiple rows (passing max_reps=0 will make * snmp_create_pdu() fetch SNMP_DEF_MAX_REPETITIONS rows) * Make an ASN.1 encoded packet from the PDU information * Send the request packet to the agent * Receive response from the agent into the reply packet buffer * Parse the reply, validate the response and create a * reply-PDU out of the information. Populate the mibcache * with the received values. * The ioctl will block until we have snmp data available * Scan each variable in the returned PDU's bindings and populate * the cache appropriately * If we're populating volatile properties, we also store a * timestamp with each property value. When we lookup, we * check the current time against this timestamp to determine * if we need to refetch the value or not (refetch if it has * been in for far too long). * Convert the standard OID form into an oid string that * we can use as the key to lookup. Since we only search * by the prefix (mibcache is really an array of nvlist_t * pointers), ignore the leaf subid. * We don't support yet bit string objects that are * ugly, but for now this will have to do.