This is a discussion on Error building ASN.1 representation within the SNMP Coders forums, part of the Networking and Network Related category; hi all: I am working on net-snmp agent, and I create a table with two indexes, when I start ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
hi all:
I am working on net-snmp agent, and I create a table with two indexes, when I start the agent and get value from the table using snmpv3 protocol, I get the following error: netsnmp_assert pss->s_snmp_errno != (-11) failed snmp_api.c:3119 snmp_build() send response: Error building ASN.1 representation (build objid: bad first subidentifier) -- DLINK-LLDP-MIB::lldpLocManAddrIfSubtype.ipV4."229.339.277.12" -- DLINK-LLDP-MIB::lldpLocManAddrIfId.ipV4."229.339.277.12" -- DLINK-LLDP-MIB::lldpLocManAddrOID.ipV4."229.339.277.12" -- SNMPv2-MIB::sysDescr.0 -- SNMPv2-MIB::sysObjectID.0 -- DISMAN-EVENT-MIB::sysUpTimeInstance -- SNMPv2-MIB::sysContact.0 -- SNMPv2-MIB::sysName.0 -- SNMPv2-MIB::sysLocation.0 -- SNMPv2-MIB::sysORLastChange.0 the mib browser I use is MG-SOFT mib browser, when I use snmpv1, I can get the integer value but if I use snmpv2 or snmpv3, I get nothing, the browse display " Index discovery running...", and the agent give the errors above. I have no any idea about this, would anyone can help me, I paste the code and the mib file below, Thanks a lot. code: #include <net-snmp/net-snmp-config.h> #include <net-snmp/net-snmp-includes.h> #include <net-snmp/agent/net-snmp-agent-includes.h> #include "lldpLocManAddrTable.h" /** Initializes the lldpLocManAddrTable module */ void init_lldpLocManAddrTable(void) { /* * here we initialize all the tables we're planning on supporting */ initialize_table_lldpLocManAddrTable(); } /** Initialize the lldpLocManAddrTable table by defining its contents and how it's structured */ void initialize_table_lldpLocManAddrTable(void) { static oid lldpLocManAddrTable_oid[] = { 1, 0, 8802, 1, 1, 2, 1, 3, 8 }; size_t lldpLocManAddrTable_oid_len = OID_LENGTH(lldpLocManAddrTable_oid); netsnmp_handler_registration *reg; netsnmp_iterator_info *iinfo; netsnmp_table_registration_info *table_info; reg = netsnmp_create_handler_registration("lldpLocManAdd rTable", lldpLocManAddrTable_handler, lldpLocManAddrTable_oid, lldpLocManAddrTable_oid_len, HANDLER_CAN_RONLY); table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_inf o); netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: lldpLocManAddrSubtype */ ASN_OCTET_STR, /* index: lldpLocManAddr */ 0); table_info->min_column = 1; table_info->max_column = 10; iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info); iinfo->get_first_data_point = lldpLocManAddrTable_get_first_data_point; iinfo->get_next_data_point = lldpLocManAddrTable_get_next_data_point; iinfo->table_reginfo = table_info; netsnmp_register_table_iterator(reg, iinfo); /* * Initialise the contents of the table here */ } /* * Typical data structure for a row entry */ struct lldpLocManAddrTable_entry { /* * Index values */ long lldpLocManAddrSubtype; char lldpLocManAddr[30]; /* * Column values */ long lldpLocManAddrLen; long lldpLocManAddrIfSubtype; long lldpLocManAddrIfId; oid lldpLocManAddrOID[255]; /* * Illustrate using a simple linked list */ int valid; struct lldpLocManAddrTable_entry *next; }; struct lldpLocManAddrTable_entry *lldpLocManAddrTable_head = NULL; /* * create a new row in the (unsorted) table */ struct lldpLocManAddrTable_entry * lldpLocManAddrTable_createEntry(long lldpLocManAddrSubtype, char* lldpLocManAddr, long lldpLocManAddrLen, long lldpLocManAddrIfSubType, long lldpLocManAddrIfId, oid* lldpLocManAddrOID) { struct lldpLocManAddrTable_entry *entry; entry = SNMP_MALLOC_TYPEDEF(struct lldpLocManAddrTable_entry); if (!entry) return NULL; entry->lldpLocManAddrSubtype = lldpLocManAddrSubtype; strcpy(entry->lldpLocManAddr, lldpLocManAddr); entry->lldpLocManAddrLen = lldpLocManAddrLen; entry->lldpLocManAddrIfSubtype = lldpLocManAddrIfSubType; entry->lldpLocManAddrIfId = lldpLocManAddrIfId; strcpy((u_char *)entry->lldpLocManAddrOID, (u_char *)lldpLocManAddrOID); entry->next = lldpLocManAddrTable_head; lldpLocManAddrTable_head = entry; return entry; } /* * remove a row from the table */ void lldpLocManAddrTable_removeEntry(struct lldpLocManAddrTable_entry *entry) { struct lldpLocManAddrTable_entry *ptr, *prev; if (!entry) return; /* Nothing to remove */ for (ptr = lldpLocManAddrTable_head, prev = NULL; ptr != NULL; prev = ptr, ptr = ptr->next) { if (ptr == entry) break; } if (!ptr) return; /* Can't find it */ if (prev == NULL) lldpLocManAddrTable_head = ptr->next; else prev->next = ptr->next; SNMP_FREE(entry); /* XXX - release any other internal resources */ } /* * Example iterator hook routines - using 'get_next' to do most of the work */ netsnmp_variable_list * lldpLocManAddrTable_get_first_data_point(void **my_loop_context, void **my_data_context, netsnmp_variable_list * put_index_data, netsnmp_iterator_info *mydata) { lldpLocManAddrTable_createEntry(1, "229.339.277.12", 7, 4, 8,"6"); *my_loop_context = lldpLocManAddrTable_head; return lldpLocManAddrTable_get_next_data_point(my_loop_co ntext, my_data_context, put_index_data, mydata); } netsnmp_variable_list * lldpLocManAddrTable_get_next_data_point(void **my_loop_context, void **my_data_context, netsnmp_variable_list * put_index_data, netsnmp_iterator_info *mydata) { struct lldpLocManAddrTable_entry *entry = (struct lldpLocManAddrTable_entry *) *my_loop_context; netsnmp_variable_list *idx = put_index_data; if (entry) { snmp_set_var_value(idx, (u_char *)&entry->lldpLocManAddrSubtype, sizeof(entry->lldpLocManAddrSubtype)); idx = idx->next_variable; snmp_set_var_value(idx, (u_char *)entry->lldpLocManAddr, strlen(entry->lldpLocManAddr)); idx = idx->next_variable; *my_data_context = (void *) entry; *my_loop_context = (void *) entry->next; } else { return NULL; } return put_index_data; } /** handles requests for the lldpLocManAddrTable table */ int lldpLocManAddrTable_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_request_info *request; netsnmp_table_request_info *table_info; struct lldpLocManAddrTable_entry *table_entry; switch (reqinfo->mode) { /* * Read-support (also covers GetNext requests) */ case MODE_GET: for (request = requests; request; request = request->next) { table_entry = (struct lldpLocManAddrTable_entry *) netsnmp_extract_iterator_context(request); if(!table_entry) continue; table_info = netsnmp_extract_table_info(request); switch (table_info->colnum) { case COLUMN_LLDPLOCMANADDRLEN: snmp_set_var_typed_value(request->requestvb, ASN_INTEGER, (u_char *)&table_entry->lldpLocManAddrLen, sizeof(table_entry-> lldpLocManAddrLen)); break; case COLUMN_LLDPLOCMANADDRIFSUBTYPE: snmp_set_var_typed_value(request->requestvb, ASN_INTEGER, (u_char *)&table_entry-> lldpLocManAddrIfSubtype, sizeof(table_entry-> lldpLocManAddrIfSubtype)); break; case COLUMN_LLDPLOCMANADDRIFID: snmp_set_var_typed_value(request->requestvb, ASN_INTEGER, (u_char *)&table_entry->lldpLocManAddrIfId, sizeof(table_entry-> lldpLocManAddrIfId)); break; case COLUMN_LLDPLOCMANADDROID: snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID, (u_char *)table_entry->lldpLocManAddrOID, sizeof(table_entry->lldpLocManAddrOID)); break; } } break; } return SNMP_ERR_NOERROR; } -------------------------------------------------------------------------------------- mib: lldpLocManAddrTable OBJECT-TYPE SYNTAX SEQUENCE OF LldpLocManAddrEntry MAX-ACCESS not-accessible STATUS current DESCRIPTION "This table contains management address information on the local system known to this agent." ::= { lldpLocalSystemData 8 } lldpLocManAddrEntry OBJECT-TYPE SYNTAX LldpLocManAddrEntry MAX-ACCESS not-accessible STATUS current DESCRIPTION "Management address information about a particular chassis component. There may be multiple management addresses configured on the system identified by a particular lldpLocChassisId. Each management address should have distinct 'management address type' (lldpLocManAddrSubtype) and 'management address' (lldpLocManAddr.) Entries may be created and deleted in this table by the agent." INDEX { lldpLocManAddrSubtype, lldpLocManAddr } ::= { lldpLocManAddrTable 1 } LldpLocManAddrEntry ::= SEQUENCE { lldpLocManAddrSubtype AddressFamilyNumbers, lldpLocManAddr LldpManAddress, lldpLocManAddrLen Integer32, lldpLocManAddrIfSubtype LldpManAddrIfSubtype, lldpLocManAddrIfId Integer32, lldpLocManAddrOID OBJECT IDENTIFIER } lldpLocManAddrSubtype OBJECT-TYPE SYNTAX AddressFamilyNumbers MAX-ACCESS not-accessible STATUS current DESCRIPTION "The type of management address identifier encoding used in the associated 'lldpLocManagmentAddr' object." REFERENCE "IEEE Std 802.1AB-2005 9.5.9.3" ::= { lldpLocManAddrEntry 1 } lldpLocManAddr OBJECT-TYPE SYNTAX LldpManAddress MAX-ACCESS not-accessible STATUS current DESCRIPTION "The string value used to identify the management address component associated with the local system. The purpose of this address is to contact the management entity." REFERENCE "IEEE Std 802.1AB-2005 9.5.9.4" ::= { lldpLocManAddrEntry 2 } lldpLocManAddrLen OBJECT-TYPE SYNTAX Integer32 MAX-ACCESS read-only STATUS current DESCRIPTION "The total length of the management address subtype and the management address fields in LLDPDUs transmitted by the local LLDP agent. The management address length field is needed so that the receiving systems that do not implement SNMP will not be required to implement an iana family numbers/address length equivalency table in order to decode the management address." REFERENCE "IEEE Std 802.1AB-2005 9.5.9.2" ::= { lldpLocManAddrEntry 3 } lldpLocManAddrIfSubtype OBJECT-TYPE SYNTAX LldpManAddrIfSubtype MAX-ACCESS read-only STATUS current DESCRIPTION "The enumeration value that identifies the interface numbering method used for defining the interface number, associated with the local system." REFERENCE "IEEE Std 802.1AB-2005 9.5.9.5" ::= { lldpLocManAddrEntry 4 } lldpLocManAddrIfId OBJECT-TYPE SYNTAX Integer32 MAX-ACCESS read-only STATUS current DESCRIPTION "The integer value used to identify the interface number regarding the management address component associated with the local system." REFERENCE "IEEE Std 802.1AB-2005 9.5.9.6" ::= { lldpLocManAddrEntry 5 } lldpLocManAddrOID OBJECT-TYPE SYNTAX OBJECT IDENTIFIER MAX-ACCESS read-only STATUS current DESCRIPTION "The OID value used to identify the type of hardware component or protocol entity associated with the management address advertised by the local system agent." REFERENCE "IEEE Std 802.1AB-2005 9.5.9.8" ::= { lldpLocManAddrEntry 6 } |