/** * @internal * convert the index component stored in the context to an oid */ int dmfTable_index_to_oid(netsnmp_index * oid_idx, dmfTable_mib_index * mib_idx) { int err = SNMP_ERR_NOERROR; /* * temp storage for parsing indexes */ /* * server(1)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H */ netsnmp_variable_list var_server; /* * pagesize(2)/INTEGER/ASN_INTEGER/long(long)//l/A/w/e/r/d/h */ netsnmp_variable_list var_pagesize; /* * set up varbinds */ memset(&var_server, 0x00, sizeof(var_server)); var_server.type = ASN_OCTET_STR; memset(&var_pagesize, 0x00, sizeof(var_pagesize)); var_pagesize.type = ASN_INTEGER; /* * chain temp index varbinds together */ var_server.next_variable = &var_pagesize; var_pagesize.next_variable = NULL; DEBUGMSGTL(("verbose:dmfTable:dmfTable_index_to_oid", "called\n")); /* * server(1)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H */ snmp_set_var_value(&var_server, (u_char *) & mib_idx->server, mib_idx->server_len * sizeof(mib_idx->server[0])); /* * pagesize(2)/INTEGER/ASN_INTEGER/long(long)//l/A/w/e/r/d/h */ snmp_set_var_value(&var_pagesize, (u_char *) & mib_idx->pagesize, sizeof(mib_idx->pagesize)); err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len, NULL, 0, &var_server); if (err) snmp_log(LOG_ERR, "error %d converting index to oid\n", err); /* * parsing may have allocated memory. free it. */ snmp_reset_var_buffers(&var_server); return err; } /* dmfTable_index_to_oid */
int sctpAssocTable_entry_update_index(sctpAssocTable_entry * entry) { netsnmp_variable_list var_sctpAssocId; int err = 0; /* * prepare the value to be converted */ memset(&var_sctpAssocId, 0, sizeof(var_sctpAssocId)); var_sctpAssocId.type = ASN_UNSIGNED; var_sctpAssocId.next_variable = NULL; snmp_set_var_value(&var_sctpAssocId, (u_char *) & entry->sctpAssocId, sizeof(entry->sctpAssocId)); /* * convert it */ err = build_oid_noalloc(entry->oid_index.oids, entry->oid_index.len, &entry->oid_index.len, NULL, 0, &var_sctpAssocId); if (err) snmp_log(LOG_ERR, "error %d converting index to oid\n", err); /* * release any memory allocated during the conversion */ snmp_reset_var_buffers(&var_sctpAssocId); return err; }
/** finds the lexically next row in the 'tdata' table given the index values */ netsnmp_tdata_row *netsnmp_tdata_row_next_byidx (netsnmp_tdata * table, netsnmp_variable_list * indexes) { oid searchfor[MAX_OID_LEN]; size_t searchfor_len = MAX_OID_LEN; build_oid_noalloc (searchfor, MAX_OID_LEN, &searchfor_len, NULL, 0, indexes); return netsnmp_tdata_row_next_byoid (table, searchfor, searchfor_len); }
int netsnmp_tdata_compare_subtree_idx (netsnmp_tdata_row * row, netsnmp_variable_list * indexes) { oid searchfor[MAX_OID_LEN]; size_t searchfor_len = MAX_OID_LEN; build_oid_noalloc (searchfor, MAX_OID_LEN, &searchfor_len, NULL, 0, indexes); return netsnmp_tdata_compare_subtree_oid (row, searchfor, searchfor_len); }
/** * @internal * convert the index component stored in the context to an oid */ int dot11WtpIfTable_index_to_oid(netsnmp_index *oid_idx, dot11WtpIfTable_mib_index *mib_idx) { int err = SNMP_ERR_NOERROR; /* * temp storage for parsing indexes */ /* * wtpMacAddr(1)/Dot11BaseWtpIdTC/ASN_OCTET_STR/char(char)//L/A/w/e/r/d/h */ netsnmp_variable_list var_wtpMacAddr; /* * wtpIfIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/A/w/e/r/d/h */ netsnmp_variable_list var_wtpIfIndex; /* * set up varbinds */ memset( &var_wtpMacAddr, 0x00, sizeof(var_wtpMacAddr) ); var_wtpMacAddr.type = ASN_OCTET_STR; memset( &var_wtpIfIndex, 0x00, sizeof(var_wtpIfIndex) ); var_wtpIfIndex.type = ASN_INTEGER; /* * chain temp index varbinds together */ var_wtpMacAddr.next_variable = &var_wtpIfIndex; var_wtpIfIndex.next_variable = NULL; DEBUGMSGTL(("verbose:dot11WtpIfTable:dot11WtpIfTable_index_to_oid","called\n")); /* wtpMacAddr(1)/Dot11BaseWtpIdTC/ASN_OCTET_STR/char(char)//L/A/w/e/r/d/h */ snmp_set_var_value(&var_wtpMacAddr, (u_char*)&mib_idx->wtpMacAddr, mib_idx->wtpMacAddr_len * sizeof(mib_idx->wtpMacAddr[0])); /* wtpIfIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/A/w/e/r/d/h */ snmp_set_var_value(&var_wtpIfIndex, (u_char*)&mib_idx->wtpIfIndex, sizeof(mib_idx->wtpIfIndex)); err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len, NULL, 0, &var_wtpMacAddr); if(err) snmp_log(LOG_ERR,"error %d converting index to oid\n", err); /* * parsing may have allocated memory. free it. */ snmp_reset_var_buffers( &var_wtpMacAddr ); return err; } /* dot11WtpIfTable_index_to_oid */
int sctpAssocLocalAddrTable_entry_update_index(sctpAssocLocalAddrTable_entry * entry) { int err = 0; netsnmp_variable_list var_sctpAssocId; netsnmp_variable_list var_sctpAssocLocalAddrType; netsnmp_variable_list var_sctpAssocLocalAddr; /* * prepare the values to be converted */ memset(&var_sctpAssocId, 0, sizeof(var_sctpAssocId)); var_sctpAssocId.type = ASN_UNSIGNED; memset(&var_sctpAssocLocalAddrType, 0, sizeof(var_sctpAssocLocalAddrType)); var_sctpAssocLocalAddrType.type = ASN_INTEGER; memset(&var_sctpAssocLocalAddr, 0, sizeof(var_sctpAssocLocalAddr)); var_sctpAssocLocalAddr.type = ASN_OCTET_STR; var_sctpAssocId.next_variable = &var_sctpAssocLocalAddrType; var_sctpAssocLocalAddrType.next_variable = &var_sctpAssocLocalAddr; var_sctpAssocLocalAddr.next_variable = NULL; snmp_set_var_value(&var_sctpAssocId, (u_char *) & entry->sctpAssocId, sizeof(entry->sctpAssocId)); snmp_set_var_value(&var_sctpAssocLocalAddrType, (u_char *) & entry->sctpAssocLocalAddrType, sizeof(entry->sctpAssocLocalAddrType)); snmp_set_var_value(&var_sctpAssocLocalAddr, (u_char *) & entry->sctpAssocLocalAddr, entry->sctpAssocLocalAddr_len * sizeof(entry->sctpAssocLocalAddr[0])); /* * convert it */ err = build_oid_noalloc(entry->oid_index.oids, entry->oid_index.len, &entry->oid_index.len, NULL, 0, &var_sctpAssocId); if (err) snmp_log(LOG_ERR, "error %d converting index to oid\n", err); /* * release any memory allocated during the conversion */ snmp_reset_var_buffers(&var_sctpAssocId); return err; }
void *netsnmp_iterator_row_next_byidx (netsnmp_iterator_info * iinfo, netsnmp_variable_list * indexes) { oid dummy[] = { 0, 0 }; oid instance[MAX_OID_LEN]; size_t len = MAX_OID_LEN; if (!iinfo || !indexes) return NULL; build_oid_noalloc (instance, MAX_OID_LEN, &len, dummy, 2, indexes); return netsnmp_iterator_row_next_byoid (iinfo, instance + 2, len - 2); }
netsnmp_table_row * netsnmp_table_data_row_next_byidx(netsnmp_table_data *table, netsnmp_variable_list *indexes) { oid instance[MAX_OID_LEN]; size_t len = MAX_OID_LEN; if (!table || !indexes) return NULL; build_oid_noalloc(instance, MAX_OID_LEN, &len, NULL, 0, indexes); return netsnmp_table_data_row_next_byoid(table, instance, len); }
/** * @internal * convert the index component stored in the context to an oid */ int ipv6ScopeZoneIndexTable_index_to_oid(netsnmp_index * oid_idx, ipv6ScopeZoneIndexTable_mib_index * mib_idx) { int err = SNMP_ERR_NOERROR; /* * temp storage for parsing indexes */ /* * ipv6ScopeZoneIndexIfIndex(1)/InterfaceIndex/ASN_INTEGER/long(long)//l/a/w/e/R/d/H */ netsnmp_variable_list var_ipv6ScopeZoneIndexIfIndex; /* * set up varbinds */ memset(&var_ipv6ScopeZoneIndexIfIndex, 0x00, sizeof(var_ipv6ScopeZoneIndexIfIndex)); var_ipv6ScopeZoneIndexIfIndex.type = ASN_INTEGER; /* * chain temp index varbinds together */ var_ipv6ScopeZoneIndexIfIndex.next_variable = NULL; DEBUGMSGTL(("verbose:ipv6ScopeZoneIndexTable:ipv6ScopeZoneIndexTable_index_to_oid", "called\n")); /* * ipv6ScopeZoneIndexIfIndex(1)/InterfaceIndex/ASN_INTEGER/long(long)//l/a/w/e/R/d/H */ snmp_set_var_value(&var_ipv6ScopeZoneIndexIfIndex, (u_char *) & mib_idx->ipv6ScopeZoneIndexIfIndex, sizeof(mib_idx->ipv6ScopeZoneIndexIfIndex)); err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len, NULL, 0, &var_ipv6ScopeZoneIndexIfIndex); if (err) snmp_log(LOG_ERR, "error %d converting index to oid\n", err); /* * parsing may have allocated memory. free it. */ snmp_reset_var_buffers(&var_ipv6ScopeZoneIndexIfIndex); return err; } /* ipv6ScopeZoneIndexTable_index_to_oid */
/** * @internal * convert the index component stored in the context to an oid */ int jmfcNamespaceHttpServerTable_index_to_oid(netsnmp_index *oid_idx, jmfcNamespaceHttpServerTable_mib_index * mib_idx) { int err = SNMP_ERR_NOERROR; /* * temp storage for parsing indexes */ /* * jmfcNamespaceName(2)/OCTETSTR/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/h */ netsnmp_variable_list var_jmfcNamespaceName; /* * set up varbinds */ memset( &var_jmfcNamespaceName, 0x00, sizeof(var_jmfcNamespaceName) ); var_jmfcNamespaceName.type = ASN_OCTET_STR; /* * chain temp index varbinds together */ var_jmfcNamespaceName.next_variable = NULL; DEBUGMSGTL(("verbose:jmfcNamespaceHttpServerTable:jmfcNamespaceHttpServerTable_index_to_oid","called\n")); /* * jmfcNamespaceName(2)/OCTETSTR/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/h */ snmp_set_var_value(&var_jmfcNamespaceName, (u_char *) & mib_idx->jmfcNamespaceName, mib_idx->jmfcNamespaceName_len * sizeof(mib_idx->jmfcNamespaceName[0])); err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len, NULL, 0, &var_jmfcNamespaceName); if(err) snmp_log(LOG_ERR,"error %d converting index to oid\n", err); /* * parsing may have allocated memory. free it. */ snmp_reset_var_buffers( &var_jmfcNamespaceName ); return err; } /* jmfcNamespaceHttpServerTable_index_to_oid */
void * netsnmp_iterator_row_get_byoid( netsnmp_iterator_info *iinfo, oid *instance, size_t len ) { oid dummy[] = {0,0}; oid this_inst[ MAX_OID_LEN]; size_t this_len; netsnmp_variable_list *vp1, *vp2; void *ctx1, *ctx2; int n; if (!iinfo || !iinfo->get_first_data_point || !iinfo->get_next_data_point ) return NULL; if ( !instance || !len ) return NULL; vp1 = snmp_clone_varbind(iinfo->indexes); vp2 = iinfo->get_first_data_point( &ctx1, &ctx2, vp1, iinfo ); DEBUGMSGTL(("table:iterator:get", "first DP: %x %x %x\n", ctx1, ctx2, vp2)); /* XXX - free context ? */ while ( vp2 ) { this_len = MAX_OID_LEN; build_oid_noalloc(this_inst, MAX_OID_LEN, &this_len, dummy, 2, vp2); n = snmp_oid_compare( instance, len, this_inst+2, this_len-2 ); if ( n == 0 ) break; /* Found matching row */ if (( n > 0) && (iinfo->flags & NETSNMP_ITERATOR_FLAG_SORTED)) { vp2 = NULL; /* Row not present */ break; } vp2 = iinfo->get_next_data_point( &ctx1, &ctx2, vp2, iinfo ); DEBUGMSGTL(("table:iterator:get", "next DP: %x %x %x\n", ctx1, ctx2, vp2)); /* XXX - free context ? */ } /* XXX - final free context ? */ snmp_free_varbind( vp1 ); return ( vp2 ? ctx2 : NULL ); }
/** * @internal * convert the index component stored in the context to an oid */ int dessertAppStatsTable_index_to_oid(netsnmp_index * oid_idx, dessertAppStatsTable_mib_index * mib_idx) { int err = SNMP_ERR_NOERROR; /* * temp storage for parsing indexes */ /* * appStatsIndex(1)///()//L/a/w/e/r/d/h */ netsnmp_variable_list var_appStatsIndex; /* * set up varbinds */ memset(&var_appStatsIndex, 0x00, sizeof(var_appStatsIndex)); var_appStatsIndex.type = ASN_INTEGER; /* * chain temp index varbinds together */ var_appStatsIndex.next_variable = NULL; DEBUGMSGTL(("verbose:dessertAppStatsTable:dessertAppStatsTable_index_to_oid", "called\n")); /* * appStatsIndex(1)///()//L/a/w/e/r/d/h */ snmp_set_var_value(&var_appStatsIndex, (u_char *) & mib_idx->appStatsIndex, sizeof(mib_idx->appStatsIndex)); err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len, NULL, 0, &var_appStatsIndex); if (err) snmp_log(LOG_ERR, "error %d converting index to oid\n", err); /* * parsing may have allocated memory. free it. */ snmp_reset_var_buffers(&var_appStatsIndex); return err; } /* dessertAppStatsTable_index_to_oid */
/** * @internal * convert the index component stored in the context to an oid */ int dot11SsidTeminalTable_index_to_oid(netsnmp_index *oid_idx, dot11SsidTeminalTable_mib_index *mib_idx) { int err = SNMP_ERR_NOERROR; /* * temp storage for parsing indexes */ /* * wlanCurrID(1)/INTEGER/ASN_INTEGER/long(long)//l/A/w/e/r/d/h */ netsnmp_variable_list var_wlanCurrID; /* * set up varbinds */ memset( &var_wlanCurrID, 0x00, sizeof(var_wlanCurrID) ); var_wlanCurrID.type = ASN_INTEGER; /* * chain temp index varbinds together */ var_wlanCurrID.next_variable = NULL; DEBUGMSGTL(("verbose:dot11SsidTeminalTable:dot11SsidTeminalTable_index_to_oid","called\n")); /* wlanCurrID(1)/INTEGER/ASN_INTEGER/long(long)//l/A/w/e/r/d/h */ snmp_set_var_value(&var_wlanCurrID, (u_char*)&mib_idx->wlanCurrID, sizeof(mib_idx->wlanCurrID)); err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len, NULL, 0, &var_wlanCurrID); if(err) snmp_log(LOG_ERR,"error %d converting index to oid\n", err); /* * parsing may have allocated memory. free it. */ snmp_reset_var_buffers( &var_wlanCurrID ); return err; } /* dot11SsidTeminalTable_index_to_oid */
/** * @internal * convert the index component stored in the context to an oid */ int dot11WtpWAPIPerformanceStatsTable_index_to_oid(netsnmp_index *oid_idx, dot11WtpWAPIPerformanceStatsTable_mib_index *mib_idx) { int err = SNMP_ERR_NOERROR; /* * temp storage for parsing indexes */ /* * staMacAddr(1)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H */ netsnmp_variable_list var_staMacAddr; /* * set up varbinds */ memset( &var_staMacAddr, 0x00, sizeof(var_staMacAddr) ); var_staMacAddr.type = ASN_OCTET_STR; /* * chain temp index varbinds together */ var_staMacAddr.next_variable = NULL; DEBUGMSGTL(("verbose:dot11WtpWAPIPerformanceStatsTable:dot11WtpWAPIPerformanceStatsTable_index_to_oid","called\n")); /* staMacAddr(1)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H */ snmp_set_var_value(&var_staMacAddr, (u_char*)&mib_idx->staMacAddr, mib_idx->staMacAddr_len * sizeof(mib_idx->staMacAddr[0])); err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len, NULL, 0, &var_staMacAddr); if(err) snmp_log(LOG_ERR,"error %d converting index to oid\n", err); /* * parsing may have allocated memory. free it. */ snmp_reset_var_buffers( &var_staMacAddr ); return err; } /* dot11WtpWAPIPerformanceStatsTable_index_to_oid */
/* implements the table_iterator helper */ int netsnmp_table_iterator_helper_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_table_registration_info *tbl_info; netsnmp_table_request_info *table_info = NULL; oid coloid[MAX_OID_LEN]; size_t coloid_len; int ret; static oid myname[MAX_OID_LEN]; size_t myname_len; int oldmode = 0; netsnmp_iterator_info *iinfo; int notdone; netsnmp_request_info *request, *reqtmp = NULL; netsnmp_variable_list *index_search = NULL; netsnmp_variable_list *free_this_index_search = NULL; void *callback_loop_context = NULL, *last_loop_context; void *callback_data_context = NULL; ti_cache_info *ti_info = NULL; int request_count = 0; netsnmp_oid_stash_node **cinfo = NULL; netsnmp_variable_list *old_indexes = NULL, *vb; netsnmp_table_registration_info *table_reg_info = NULL; int i; netsnmp_data_list *ldata = NULL; iinfo = (netsnmp_iterator_info *) handler->myvoid; if (!iinfo || !reginfo || !reqinfo) return SNMPERR_GENERR; tbl_info = iinfo->table_reginfo; /* * copy in the table registration oid for later use */ coloid_len = reginfo->rootoid_len + 2; memcpy(coloid, reginfo->rootoid, reginfo->rootoid_len * sizeof(oid)); coloid[reginfo->rootoid_len] = 1; /* table.entry node */ /* * illegally got here if these functions aren't defined */ if (iinfo->get_first_data_point == NULL || iinfo->get_next_data_point == NULL) { snmp_log(LOG_ERR, "table_iterator helper called without data accessor functions\n"); return SNMP_ERR_GENERR; } /* preliminary analysis */ switch (reqinfo->mode) { case MODE_GET_STASH: cinfo = netsnmp_extract_stash_cache(reqinfo); table_reg_info = netsnmp_find_table_registration_info(reginfo); /* XXX: move this malloc to stash_cache handler? */ reqtmp = SNMP_MALLOC_TYPEDEF(netsnmp_request_info); reqtmp->subtree = requests->subtree; table_info = netsnmp_extract_table_info(requests); netsnmp_request_add_list_data(reqtmp, netsnmp_create_data_list (TABLE_HANDLER_NAME, (void *) table_info, NULL)); /* remember the indexes that were originally parsed. */ old_indexes = table_info->indexes; break; case MODE_GETNEXT: for(request = requests ; request; request = request->next) { if (request->processed) continue; table_info = netsnmp_extract_table_info(request); if (table_info->colnum < tbl_info->min_column - 1) { /* XXX: optimize better than this */ /* for now, just increase to colnum-1 */ /* we need to jump to the lowest result of the min_column and take it, comparing to nothing from the request */ table_info->colnum = tbl_info->min_column - 1; } else if (table_info->colnum > tbl_info->max_column) { request->processed = TABLE_ITERATOR_NOTAGAIN; } ti_info = netsnmp_request_get_list_data(request, TI_REQUEST_CACHE); if (!ti_info) { ti_info = SNMP_MALLOC_TYPEDEF(ti_cache_info); netsnmp_request_add_list_data(request, netsnmp_create_data_list (TI_REQUEST_CACHE, ti_info, netsnmp_free_ti_cache)); } /* XXX: if no valid requests, don't even loop below */ } break; } /* * collect all information for each needed row */ if (reqinfo->mode == MODE_GET || reqinfo->mode == MODE_GETNEXT || reqinfo->mode == MODE_GET_STASH || reqinfo->mode == MODE_SET_RESERVE1) { /* * Count the number of request in the list, * so that we'll know when we're finished */ for(request = requests ; request; request = request->next) if (!request->processed) request_count++; notdone = 1; while(notdone) { notdone = 0; /* find first data point */ if (!index_search) { if (free_this_index_search) { /* previously done */ index_search = free_this_index_search; } else { for(request=requests ; request; request=request->next) { table_info = netsnmp_extract_table_info(request); if (table_info) break; } if (!table_info) { snmp_log(LOG_WARNING, "no valid requests for iterator table %s\n", reginfo->handlerName); netsnmp_free_request_data_sets(reqtmp); SNMP_FREE(reqtmp); return SNMP_ERR_NOERROR; } index_search = snmp_clone_varbind(table_info->indexes); free_this_index_search = index_search; /* setup, malloc search data: */ if (!index_search) { /* * hmmm.... invalid table? */ snmp_log(LOG_WARNING, "invalid index list or failed malloc for table %s\n", reginfo->handlerName); netsnmp_free_request_data_sets(reqtmp); SNMP_FREE(reqtmp); return SNMP_ERR_NOERROR; } } } /* if sorted, pass in a hint */ if (iinfo->flags & NETSNMP_ITERATOR_FLAG_SORTED) { callback_loop_context = table_info; } index_search = (iinfo->get_first_data_point) (&callback_loop_context, &callback_data_context, index_search, iinfo); /* loop over each data point */ while(index_search) { /* remember to free this later */ free_this_index_search = index_search; /* compare against each request*/ for(request = requests ; request; request = request->next) { if (request->processed) continue; /* XXX: store in an array for faster retrival */ table_info = netsnmp_extract_table_info(request); coloid[reginfo->rootoid_len + 1] = table_info->colnum; ti_info = netsnmp_request_get_list_data(request, TI_REQUEST_CACHE); switch(reqinfo->mode) { case MODE_GET: case MODE_SET_RESERVE1: /* looking for exact matches */ build_oid_noalloc(myname, MAX_OID_LEN, &myname_len, coloid, coloid_len, index_search); if (snmp_oid_compare(myname, myname_len, request->requestvb->name, request->requestvb->name_length) == 0) { /* keep this */ netsnmp_iterator_remember(request, myname, myname_len, callback_data_context, callback_loop_context, iinfo); request_count--; /* One less to look for */ } else { if (iinfo->free_data_context && callback_data_context) { (iinfo->free_data_context)(callback_data_context, iinfo); } } break; case MODE_GET_STASH: /* collect data for each column for every row */ build_oid_noalloc(myname, MAX_OID_LEN, &myname_len, coloid, coloid_len, index_search); reqinfo->mode = MODE_GET; if (reqtmp) ldata = netsnmp_get_list_node(reqtmp->parent_data, TABLE_ITERATOR_NAME); if (!ldata) { netsnmp_request_add_list_data(reqtmp, netsnmp_create_data_list (TABLE_ITERATOR_NAME, callback_data_context, NULL)); } else { /* may have changed */ ldata->data = callback_data_context; } table_info->indexes = index_search; for(i = table_reg_info->min_column; i <= (int)table_reg_info->max_column; i++) { myname[reginfo->rootoid_len + 1] = i; table_info->colnum = i; vb = reqtmp->requestvb = SNMP_MALLOC_TYPEDEF(netsnmp_variable_list); vb->type = ASN_NULL; snmp_set_var_objid(vb, myname, myname_len); netsnmp_call_next_handler(handler, reginfo, reqinfo, reqtmp); reqtmp->requestvb = NULL; reqtmp->processed = 0; if (vb->type != ASN_NULL) { /* XXX, not all */ netsnmp_oid_stash_add_data(cinfo, myname, myname_len, vb); } else { snmp_free_var(vb); } } reqinfo->mode = MODE_GET_STASH; break; case MODE_GETNEXT: /* looking for "next" matches */ if (netsnmp_check_getnext_reply (request, coloid, coloid_len, index_search, &ti_info->results)) { netsnmp_iterator_remember(request, ti_info->results->name, ti_info->results->name_length, callback_data_context, callback_loop_context, iinfo); /* * If we've been told that the rows are sorted, * then the first valid one we find * must be the right one. */ if (iinfo->flags & NETSNMP_ITERATOR_FLAG_SORTED) request_count--; } else { if (iinfo->free_data_context && callback_data_context) { (iinfo->free_data_context)(callback_data_context, iinfo); } } break; case MODE_SET_RESERVE2: case MODE_SET_FREE: case MODE_SET_UNDO: case MODE_SET_COMMIT: /* needed processing already done in RESERVE1 */ break; default: snmp_log(LOG_ERR, "table_iterator called with unsupported mode\n"); break; /* XXX return */ } } /* Is there any point in carrying on? */ if (!request_count) break; /* get the next search possibility */ last_loop_context = callback_loop_context; index_search = (iinfo->get_next_data_point) (&callback_loop_context, &callback_data_context, index_search, iinfo); if (iinfo->free_loop_context && last_loop_context && callback_data_context != last_loop_context) { (iinfo->free_loop_context) (last_loop_context, iinfo); last_loop_context = NULL; } } /* free loop context before going on */ if (callback_loop_context && iinfo->free_loop_context_at_end) { (iinfo->free_loop_context_at_end) (callback_loop_context, iinfo); callback_loop_context = NULL; } /* decide which (GETNEXT) requests are not yet filled */ if (reqinfo->mode == MODE_GETNEXT) { for(request = requests ; request; request = request->next) { if (request->processed) continue; ti_info = netsnmp_request_get_list_data(request, TI_REQUEST_CACHE); if (!ti_info->results) { int nc; table_info = netsnmp_extract_table_info(request); nc = netsnmp_table_next_column(table_info); if (0 == nc) { coloid[reginfo->rootoid_len+1] = table_info->colnum+1; snmp_set_var_objid(request->requestvb, coloid, reginfo->rootoid_len+2); request->processed = TABLE_ITERATOR_NOTAGAIN; break; } else { table_info->colnum = nc; notdone = 1; } } } } } } if (reqinfo->mode == MODE_GET || reqinfo->mode == MODE_GETNEXT || reqinfo->mode == MODE_SET_RESERVE1) { /* per request last minute processing */ for(request = requests ; request; request = request->next) { if (request->processed) continue; ti_info = netsnmp_request_get_list_data(request, TI_REQUEST_CACHE); table_info = netsnmp_extract_table_info(request); if (!ti_info) continue; switch(reqinfo->mode) { case MODE_GETNEXT: if (ti_info->best_match_len) snmp_set_var_objid(request->requestvb, ti_info->best_match, ti_info->best_match_len); else { coloid[reginfo->rootoid_len+1] = netsnmp_table_next_column(table_info); if (0 == coloid[reginfo->rootoid_len+1]) { /* out of range. */ coloid[reginfo->rootoid_len+1] = tbl_info->max_column + 1; request->processed = TABLE_ITERATOR_NOTAGAIN; } snmp_set_var_objid(request->requestvb, coloid, reginfo->rootoid_len+2); request->processed = 1; } snmp_free_varbind(table_info->indexes); table_info->indexes = snmp_clone_varbind(ti_info->results); /* FALL THROUGH */ case MODE_GET: case MODE_SET_RESERVE1: if (ti_info->data_context) /* we don't add a free pointer, since it's in the TI_REQUEST_CACHE instead */ netsnmp_request_add_list_data(request, netsnmp_create_data_list (TABLE_ITERATOR_NAME, ti_info->data_context, NULL)); break; default: break; } } /* we change all GETNEXT operations into GET operations. why? because we're just so nice to the lower levels. maybe someday they'll pay us for it. doubtful though. */ oldmode = reqinfo->mode; if (reqinfo->mode == MODE_GETNEXT) { reqinfo->mode = MODE_GET; } } else if (reqinfo->mode == MODE_GET_STASH) { netsnmp_free_request_data_sets(reqtmp); SNMP_FREE(reqtmp); table_info->indexes = old_indexes; } /* Finally, we get to call the next handler below us. Boy, wasn't all that simple? They better be glad they don't have to do it! */ if (reqinfo->mode != MODE_GET_STASH) { DEBUGMSGTL(("table_iterator", "call subhandler for mode: %s\n", se_find_label_in_slist("agent_mode", oldmode))); ret = netsnmp_call_next_handler(handler, reginfo, reqinfo, requests); } /* reverse the previously saved mode if we were a getnext */ if (oldmode == MODE_GETNEXT) { reqinfo->mode = oldmode; } /* cleanup */ if (free_this_index_search) snmp_free_varbind(free_this_index_search); return SNMP_ERR_NOERROR; }
/** inserts table_iterator specific data for a newly * created row into a request */ NETSNMP_INLINE void netsnmp_insert_iterator_context(netsnmp_request_info *request, void *data) { netsnmp_request_info *req; netsnmp_table_request_info *table_info = NULL; netsnmp_variable_list *this_index = NULL; netsnmp_variable_list *that_index = NULL; oid base_oid[] = {0, 0}; /* Make sure index OIDs are legal! */ oid this_oid[MAX_OID_LEN]; oid that_oid[MAX_OID_LEN]; size_t this_oid_len, that_oid_len; if (!request) return; /* * We'll add the new row information to any request * structure with the same index values as the request * passed in (which includes that one!). * * So construct an OID based on these index values. */ table_info = netsnmp_extract_table_info(request); this_index = table_info->indexes; build_oid_noalloc(this_oid, MAX_OID_LEN, &this_oid_len, base_oid, 2, this_index); /* * We need to look through the whole of the request list * (as received by the current handler), as there's no * guarantee that this routine will be called by the first * varbind that refers to this row. * In particular, a RowStatus controlled row creation * may easily occur later in the variable list. * * So first, we rewind to the head of the list.... */ for (req=request; req->prev; req=req->prev) ; /* * ... and then start looking for matching indexes * (by constructing OIDs from these index values) */ for (; req; req=req->next) { table_info = netsnmp_extract_table_info(req); that_index = table_info->indexes; build_oid_noalloc(that_oid, MAX_OID_LEN, &that_oid_len, base_oid, 2, that_index); /* * This request has the same index values, * so add the newly-created row information. */ if (snmp_oid_compare(this_oid, this_oid_len, that_oid, that_oid_len) == 0) { netsnmp_request_add_list_data(req, netsnmp_create_data_list(TABLE_ITERATOR_NAME, data, NULL)); } } }
/** handles requests for the expValueTable table */ int expValueTable_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 *tinfo; netsnmp_variable_list *value; oid expValueOID[] = { 1, 3, 6, 1, 2, 1, 90, 1, 3, 1, 1, 99 }; size_t expValueOID_len = OID_LENGTH(expValueOID); oid name_buf[ MAX_OID_LEN ]; oid *name_ptr = name_buf; size_t name_buf_len = MAX_OID_LEN; DEBUGMSGTL(("disman:expr:mib", "Expression Value Table handler (%d)\n", reqinfo->mode)); switch (reqinfo->mode) { case MODE_GET: case MODE_GETNEXT: for (request = requests; request; request = request->next) { tinfo = netsnmp_extract_table_info(request); value = expValueTable_getEntry(tinfo->indexes, reqinfo->mode, tinfo->colnum); if (!value || !value->val.integer) { netsnmp_set_request_error(reqinfo, request, (reqinfo->mode == MODE_GET) ? SNMP_NOSUCHINSTANCE : SNMP_ENDOFMIBVIEW); continue; } if ( reqinfo->mode == MODE_GETNEXT ) { /* * Need to update the request varbind OID * to match the instance just evaluated. * (XXX - Is this the appropriate mechanism?) */ build_oid_noalloc( name_buf, MAX_OID_LEN, &name_buf_len, expValueOID, expValueOID_len, tinfo->indexes ); name_buf[ expValueOID_len -1 ] = tinfo->colnum; snmp_set_var_objid(request->requestvb, name_buf, name_buf_len); } switch (tinfo->colnum) { case COLUMN_EXPVALUECOUNTER32VAL: snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, *value->val.integer); break; case COLUMN_EXPVALUEUNSIGNED32VAL: snmp_set_var_typed_integer(request->requestvb, ASN_UNSIGNED, *value->val.integer); break; case COLUMN_EXPVALUETIMETICKSVAL: snmp_set_var_typed_integer(request->requestvb, ASN_TIMETICKS, *value->val.integer); break; case COLUMN_EXPVALUEINTEGER32VAL: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, *value->val.integer); break; case COLUMN_EXPVALUEIPADDRESSVAL: snmp_set_var_typed_integer(request->requestvb, ASN_IPADDRESS, *value->val.integer); break; case COLUMN_EXPVALUEOCTETSTRINGVAL: snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR, value->val.string, value->val_len); break; case COLUMN_EXPVALUEOIDVAL: snmp_set_var_typed_value( request->requestvb, ASN_OBJECT_ID, (u_char *)value->val.objid, value->val_len); break; case COLUMN_EXPVALUECOUNTER64VAL: snmp_set_var_typed_value( request->requestvb, ASN_COUNTER64, (u_char *)value->val.counter64, value->val_len); break; } } break; } DEBUGMSGTL(("disman:expr:mib", "Expression Value handler - done \n")); return SNMP_ERR_NOERROR; }
/** * @internal * convert the index component stored in the context to an oid */ int pgsqlPgAmTable_index_to_oid(netsnmp_index *oid_idx, pgsqlPgAmTable_mib_index *mib_idx) { int err = SNMP_ERR_NOERROR; /* * temp storage for parsing indexes */ /* * pgsnmpdConnID(1)/DisplayString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H */ netsnmp_variable_list var_pgsnmpdConnID; /* * rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ netsnmp_variable_list var_rdbmsDbIndex; /* * pgsqlPgAmEntryOID(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/r/d/h */ netsnmp_variable_list var_pgsqlPgAmEntryOID; /* * set up varbinds */ memset( &var_pgsnmpdConnID, 0x00, sizeof(var_pgsnmpdConnID) ); var_pgsnmpdConnID.type = ASN_OCTET_STR; memset( &var_rdbmsDbIndex, 0x00, sizeof(var_rdbmsDbIndex) ); var_rdbmsDbIndex.type = ASN_INTEGER; memset( &var_pgsqlPgAmEntryOID, 0x00, sizeof(var_pgsqlPgAmEntryOID) ); var_pgsqlPgAmEntryOID.type = ASN_INTEGER; /* * chain temp index varbinds together */ var_pgsnmpdConnID.next_variable = &var_rdbmsDbIndex; var_rdbmsDbIndex.next_variable = &var_pgsqlPgAmEntryOID; var_pgsqlPgAmEntryOID.next_variable = NULL; DEBUGMSGTL(("verbose:pgsqlPgAmTable:pgsqlPgAmTable_index_to_oid","called\n")); /* pgsnmpdConnID(1)/DisplayString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H */ snmp_set_var_value(&var_pgsnmpdConnID, (u_char*)&mib_idx->pgsnmpdConnID, mib_idx->pgsnmpdConnID_len * sizeof(mib_idx->pgsnmpdConnID[0])); /* rdbmsDbIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/R/d/h */ snmp_set_var_value(&var_rdbmsDbIndex, (u_char*)&mib_idx->rdbmsDbIndex, sizeof(mib_idx->rdbmsDbIndex)); /* pgsqlPgAmEntryOID(1)/INTEGER/ASN_INTEGER/long(long)//l/a/w/e/r/d/h */ snmp_set_var_value(&var_pgsqlPgAmEntryOID, (u_char*)&mib_idx->pgsqlPgAmEntryOID, sizeof(mib_idx->pgsqlPgAmEntryOID)); err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len, NULL, 0, &var_pgsnmpdConnID); if(err) snmp_log(LOG_ERR,"error %d converting index to oid\n", err); /* * parsing may have allocated memory. free it. */ snmp_reset_var_buffers( &var_pgsnmpdConnID ); return err; } /* pgsqlPgAmTable_index_to_oid */
/** implements the table_iterator helper */ int netsnmp_table_iterator_helper_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_table_registration_info *tbl_info; oid coloid[MAX_OID_LEN]; size_t coloid_len; int ret; static oid myname[MAX_OID_LEN]; size_t myname_len; int oldmode; netsnmp_iterator_info *iinfo; iinfo = (netsnmp_iterator_info *) handler->myvoid; if (!iinfo || !reginfo || !reqinfo) return SNMPERR_GENERR; tbl_info = iinfo->table_reginfo; /* * copy in the table registration oid for later use */ coloid_len = reginfo->rootoid_len + 2; memcpy(coloid, reginfo->rootoid, reginfo->rootoid_len * sizeof(oid)); coloid[reginfo->rootoid_len] = 1; /* table.entry node */ /* * illegally got here if these functions aren't defined */ if (iinfo->get_first_data_point == NULL || iinfo->get_next_data_point == NULL) { snmp_log(LOG_ERR, "table_iterator helper called without data accessor functions\n"); return SNMP_ERR_GENERR; } /* * XXXWWW: deal with SET caching */ #ifdef NOT_SERIALIZED while (requests) /* XXX: currently only serialized */ #endif { /* * XXXWWW: optimize by reversing loops (look through data only once) */ netsnmp_variable_list *results = NULL; netsnmp_variable_list *index_search = NULL; /* WWW: move up? */ netsnmp_variable_list *free_this_index_search = NULL; netsnmp_table_request_info *table_info = netsnmp_extract_table_info(requests); void *callback_loop_context = NULL; void *callback_data_context = NULL; void *callback_data_keep = NULL; if (requests->processed != 0) { #ifdef NOT_SERIALIZED continue; #else return SNMP_ERR_NOERROR; #endif } if (reqinfo->mode != MODE_GET && reqinfo->mode != MODE_GETNEXT && reqinfo->mode != MODE_GETBULK && /* XXX */ reqinfo->mode != MODE_SET_RESERVE1) { goto skip_processing; } if (table_info->colnum > tbl_info->max_column) { requests->processed = 1; #ifdef NOT_SERIALIZED break; #else return SNMP_ERR_NOERROR; #endif } /* * XXX: if loop through everything, these are never free'd * since iterator returns NULL and thus we forget about * these */ index_search = snmp_clone_varbind(table_info->indexes); if (!index_search) { /* * hmmm.... invalid table? */ snmp_log(LOG_WARNING, "invalid index list or failed malloc for table %s\n", reginfo->handlerName); return SNMP_ERR_NOERROR; } free_this_index_search = index_search; /* * below our minimum column? */ if (table_info->colnum < tbl_info->min_column) { results = (iinfo->get_first_data_point) (&callback_loop_context, &callback_data_context, index_search, iinfo); if (iinfo->free_loop_context) { (iinfo->free_loop_context) (callback_loop_context, iinfo); callback_loop_context = NULL; } goto got_results; } /* * XXX: do "only got some indexes" */ /* * find the next legal result to return */ /* * find the first node */ index_search = (iinfo->get_first_data_point) (&callback_loop_context, &callback_data_context, index_search, iinfo); /* * table.entry.column node */ coloid[reginfo->rootoid_len + 1] = table_info->colnum; switch (reqinfo->mode) { case MODE_GETNEXT: case MODE_GETBULK: /* XXXWWW */ /* * loop through all data and find next one */ while (index_search) { /* * compare the node with previous results */ if (netsnmp_check_getnext_reply (requests, coloid, coloid_len, index_search, &results)) { /* * result is our current choice, so keep a pointer to * the data that the lower handler wants us to * remember (possibly freeing the last known "good" * result data pointer) */ if (callback_data_keep && iinfo->free_data_context) { (iinfo->free_data_context) (callback_data_keep, iinfo); callback_data_keep = NULL; } if (iinfo->make_data_context && !callback_data_context) { callback_data_context = (iinfo-> make_data_context) (callback_loop_context, iinfo); } callback_data_keep = callback_data_context; callback_data_context = NULL; } else { if (callback_data_context && iinfo->free_data_context) (iinfo->free_data_context) (callback_data_context, iinfo); callback_data_context = NULL; } /* * get the next node in the data chain */ index_search = (iinfo->get_next_data_point) (&callback_loop_context, &callback_data_context, index_search, iinfo); if (!index_search && !results && tbl_info->max_column > table_info->colnum) { /* * restart loop. XXX: Should cache this better */ table_info->colnum++; coloid[reginfo->rootoid_len + 1] = table_info->colnum; if (free_this_index_search != NULL) snmp_free_varbind(free_this_index_search); index_search = snmp_clone_varbind(table_info->indexes); free_this_index_search = index_search; if (callback_loop_context && iinfo->free_loop_context_at_end) { (iinfo->free_loop_context_at_end)(callback_loop_context, iinfo); callback_loop_context = NULL; } if (iinfo->free_loop_context && callback_loop_context) { (iinfo->free_loop_context) (callback_loop_context, iinfo); callback_loop_context = NULL; } if (callback_data_context && iinfo->free_data_context) { (iinfo->free_data_context) (callback_data_context, iinfo); callback_data_context = NULL; } index_search = (iinfo-> get_first_data_point) (&callback_loop_context, &callback_data_context, index_search, iinfo); } } break; case MODE_GET: case MODE_SET_RESERVE1: /* * loop through all data till exact results are found */ while (index_search) { build_oid_noalloc(myname, MAX_OID_LEN, &myname_len, coloid, coloid_len, index_search); if (snmp_oid_compare(myname, myname_len, requests->requestvb->name, requests->requestvb->name_length) == 0) { /* * found the exact match, so we're done */ if (iinfo->make_data_context && !callback_data_context) { callback_data_context = (iinfo-> make_data_context) (callback_loop_context, iinfo); } callback_data_keep = callback_data_context; callback_data_context = NULL; results = snmp_clone_varbind(index_search); snmp_set_var_objid(results, myname, myname_len); goto got_results; } else { /* * free not-needed data context */ if (callback_data_context && iinfo->free_data_context) { (iinfo->free_data_context) (callback_data_context, iinfo); callback_data_context = NULL; } } /* * get the next node in the data chain */ index_search = (iinfo->get_next_data_point) (&callback_loop_context, &callback_data_context, index_search, iinfo); } break; default: /* * the rest of the set states have been dealt with already */ goto got_results; } /* * XXX: free index_search? */ if (callback_loop_context && iinfo->free_loop_context) { (iinfo->free_loop_context) (callback_loop_context, iinfo); callback_loop_context = NULL; } got_results: /* not milk */ /* * This free_data_context call is required in the event that your * get_next_data_point method allocates new memory, even during the * calls where it eventually returns a NULL */ if (callback_data_context && iinfo->free_data_context) { (iinfo->free_data_context) (callback_data_context, iinfo); callback_data_context = NULL; } if (!results && !MODE_IS_SET(reqinfo->mode)) { /* * no results found. */ /* * XXX: check for at least one entry at the very top */ #ifdef NOT_SERIALIZED break; #else if (callback_loop_context && iinfo->free_loop_context_at_end) { (iinfo->free_loop_context_at_end) (callback_loop_context, iinfo); callback_loop_context = NULL; } if (free_this_index_search != NULL) { snmp_free_varbind(free_this_index_search); } return SNMP_ERR_NOERROR; #endif } skip_processing: /* * OK, here results should be a pointer to the data that we * actually need to GET */ oldmode = reqinfo->mode; if (reqinfo->mode == MODE_GETNEXT || reqinfo->mode == MODE_GETBULK) { /* XXX */ snmp_set_var_objid(requests->requestvb, results->name, results->name_length); reqinfo->mode = MODE_GET; } if (reqinfo->mode == MODE_GET || reqinfo->mode == MODE_GETNEXT || reqinfo->mode == MODE_GETBULK || /* XXX */ reqinfo->mode == MODE_SET_RESERVE1) { /* * first (or only) pass stuff */ /* * let set requsets use previously constructed data */ snmp_free_varbind(results); if (callback_data_keep) netsnmp_request_add_list_data(requests, netsnmp_create_data_list (TABLE_ITERATOR_NAME, callback_data_keep, NULL)); netsnmp_request_add_list_data(requests, netsnmp_create_data_list (TABLE_ITERATOR_LAST_CONTEXT, callback_loop_context, NULL)); } DEBUGMSGTL(("table_iterator", "doing mode: %s\n", se_find_label_in_slist("agent_mode", oldmode))); ret = netsnmp_call_next_handler(handler, reginfo, reqinfo, requests); if (oldmode == MODE_GETNEXT || oldmode == MODE_GETBULK) { /* XXX */ if (requests->requestvb->type == ASN_NULL || requests->requestvb->type == SNMP_NOSUCHINSTANCE) { /* * get next skipped this value for this column, we * need to keep searching forward */ requests->requestvb->type = ASN_PRIV_RETRY; } reqinfo->mode = oldmode; } callback_data_keep = netsnmp_request_get_list_data(requests, TABLE_ITERATOR_NAME); callback_loop_context = netsnmp_request_get_list_data(requests, TABLE_ITERATOR_LAST_CONTEXT); /* * This has to be done to prevent a memory leak. Notice that on * SET_RESERVE1 we're assigning something to * 'free_this_index_search' at the beginning of this handler (right * above the line that says 'below our minimum column?'), * but we're not given a chance to free it below with the other * SET modes, hence our doing it here. */ if (reqinfo->mode == MODE_SET_RESERVE1) { if (free_this_index_search) { snmp_free_varbind(free_this_index_search); free_this_index_search = NULL; } } if (reqinfo->mode == MODE_GET || reqinfo->mode == MODE_GETNEXT || reqinfo->mode == MODE_GETBULK || /* XXX */ reqinfo->mode == MODE_SET_FREE || reqinfo->mode == MODE_SET_UNDO || reqinfo->mode == MODE_SET_COMMIT) { if (callback_data_keep && iinfo->free_data_context) { (iinfo->free_data_context) (callback_data_keep, iinfo); callback_data_keep = NULL; } if (free_this_index_search) { snmp_free_varbind(free_this_index_search); free_this_index_search = NULL; } #ifndef NOT_SERIALIZED if (callback_loop_context && iinfo->free_loop_context_at_end) { (iinfo->free_loop_context_at_end) (callback_loop_context, iinfo); callback_loop_context = NULL; } #endif } #ifdef NOT_SERIALIZED return ret; #else requests = requests->next; #endif } #ifdef NOT_SERIALIZED if (reqinfo->mode == MODE_GET || reqinfo->mode == MODE_GETNEXT || reqinfo->mode == MODE_GETBULK || /* XXX */ reqinfo->mode == MODE_SET_FREE || reqinfo->mode == MODE_SET_UNDO || reqinfo->mode == MODE_SET_COMMIT) { if (callback_loop_context && iinfo->free_loop_context_at_end) { (iinfo->free_loop_context_at_end) (callback_loop_context, iinfo); callback_loop_context = NULL; } } #endif return SNMP_ERR_NOERROR; }
/** * @internal * convert the index component stored in the context to an oid */ int ipDefaultRouterTable_index_to_oid(netsnmp_index * oid_idx, ipDefaultRouterTable_mib_index * mib_idx) { int err = SNMP_ERR_NOERROR; /* * temp storage for parsing indexes */ /* * ipDefaultRouterAddressType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h */ netsnmp_variable_list var_ipDefaultRouterAddressType; /* * ipDefaultRouterAddress(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h */ netsnmp_variable_list var_ipDefaultRouterAddress; /* * ipDefaultRouterIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/a/w/e/R/d/H */ netsnmp_variable_list var_ipDefaultRouterIfIndex; /* * set up varbinds */ memset(&var_ipDefaultRouterAddressType, 0x00, sizeof(var_ipDefaultRouterAddressType)); var_ipDefaultRouterAddressType.type = ASN_INTEGER; memset(&var_ipDefaultRouterAddress, 0x00, sizeof(var_ipDefaultRouterAddress)); var_ipDefaultRouterAddress.type = ASN_OCTET_STR; memset(&var_ipDefaultRouterIfIndex, 0x00, sizeof(var_ipDefaultRouterIfIndex)); var_ipDefaultRouterIfIndex.type = ASN_INTEGER; /* * chain temp index varbinds together */ var_ipDefaultRouterAddressType.next_variable = &var_ipDefaultRouterAddress; var_ipDefaultRouterAddress.next_variable = &var_ipDefaultRouterIfIndex; var_ipDefaultRouterIfIndex.next_variable = NULL; DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_index_to_oid", "called\n")); /* * ipDefaultRouterAddressType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h */ snmp_set_var_value(&var_ipDefaultRouterAddressType, (u_char *) & mib_idx->ipDefaultRouterAddressType, sizeof(mib_idx->ipDefaultRouterAddressType)); /* * ipDefaultRouterAddress(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h */ snmp_set_var_value(&var_ipDefaultRouterAddress, (u_char *) & mib_idx->ipDefaultRouterAddress, mib_idx->ipDefaultRouterAddress_len * sizeof(mib_idx->ipDefaultRouterAddress[0])); /* * ipDefaultRouterIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/a/w/e/R/d/H */ snmp_set_var_value(&var_ipDefaultRouterIfIndex, (u_char *) & mib_idx->ipDefaultRouterIfIndex, sizeof(mib_idx->ipDefaultRouterIfIndex)); err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len, NULL, 0, &var_ipDefaultRouterAddressType); if (err) snmp_log(LOG_ERR, "error %d converting index to oid\n", err); /* * parsing may have allocated memory. free it. */ snmp_reset_var_buffers(&var_ipDefaultRouterAddressType); return err; } /* ipDefaultRouterTable_index_to_oid */
void fill_query_container(pgsnmpd_query *query) { /* TODO: Make this work */ cust_query_row *row; int i, j, string_idx_count, string_idx_len; netsnmp_variable_list var_rdbmsDbIndex, var_pgsnmpdConnID, *var_otherIndexes; int err = SNMP_ERR_NOERROR; char *val; memset( &var_pgsnmpdConnID, 0x00, sizeof(var_pgsnmpdConnID) ); var_pgsnmpdConnID.type = ASN_INTEGER; memset( &var_rdbmsDbIndex, 0x00, sizeof(var_rdbmsDbIndex) ); var_rdbmsDbIndex.type = ASN_INTEGER; var_otherIndexes = malloc(sizeof(netsnmp_variable_list) * query->num_indexes); if (var_otherIndexes == NULL) { snmp_log(LOG_ERR, "Memory allocation error\n"); return; } memset(var_otherIndexes, 0, sizeof(netsnmp_variable_list) * query->num_indexes); string_idx_count = 0; for (i = 0; i < query->num_indexes; i++) { if (i < query->num_indexes - 1) var_otherIndexes[i].next_variable = &var_otherIndexes[i+1]; var_otherIndexes[i].type = query->types[i]; if (query->types[i] == ASN_OCTET_STR) string_idx_count++; } var_pgsnmpdConnID.next_variable = &var_rdbmsDbIndex; var_rdbmsDbIndex.next_variable = var_otherIndexes; snmp_set_var_typed_value(&var_rdbmsDbIndex, ASN_INTEGER, (u_char *) &rdbmsDbIndex, sizeof(int)); snmp_set_var_typed_value(&var_pgsnmpdConnID, ASN_INTEGER, (u_char *) &pgsnmpdConnID, sizeof(int)); for (i = 0; i < query->rowcount; i++) { string_idx_len = 0; for (j = 0; j < query->num_indexes; j++) { val = PQgetvalue(query->result, i, j); /* TODO: Floats and OIDs also need more than the usual memory. * Learn to handle them. Until then we can expect problems using * OIDs and Floats as indexes */ if (query->types[j] == ASN_OCTET_STR) string_idx_len += strlen(val); set_val_from_string(&var_otherIndexes[j], query->types[j], val); } row = SNMP_MALLOC_TYPEDEF(cust_query_row); row->myoids = malloc(sizeof(oid) * (query->num_indexes + extra_idx_count + string_idx_count + string_idx_len)); if (row->myoids == NULL) { snmp_log(LOG_ERR, "memory allocation problem \n"); return; } row->row_index.len = query->num_indexes + extra_idx_count + string_idx_len + string_idx_count; row->row_index.oids = row->myoids; err = build_oid_noalloc(row->row_index.oids, row->row_index.len, (size_t *) &(row->row_index.len), NULL, 0, &var_pgsnmpdConnID); if (err) snmp_log(LOG_ERR,"error %d converting index to oid, query %s\n", err, query->table_name); row->query = query; row->rownum = i; CONTAINER_INSERT(query->cb.container, row); } }
int netsnmp_table_row_register(netsnmp_handler_registration *reginfo, netsnmp_table_registration_info *tabreg, void *row, netsnmp_variable_list *index) { netsnmp_handler_registration *reg2; netsnmp_mib_handler *handler; oid row_oid[MAX_OID_LEN]; size_t row_oid_len, len; char tmp[SNMP_MAXBUF_MEDIUM]; if ((NULL == reginfo) || (NULL == reginfo->handler) || (NULL == tabreg)) { snmp_log(LOG_ERR, "bad param in netsnmp_table_row_register\n"); return SNMPERR_GENERR; } /* * The first table_row invoked for a particular table should * register the full table as well, with a default handler to * process requests for non-existent (or incomplete) rows. * * Subsequent table_row registrations attempting to set up * this default handler would fail - preferably silently! */ snprintf(tmp, sizeof(tmp), "%s_table", reginfo->handlerName); reg2 = netsnmp_create_handler_registration( tmp, _table_row_default_handler, reginfo->rootoid, reginfo->rootoid_len, reginfo->modes); netsnmp_register_table(reg2, tabreg); /* Ignore return value */ /* * Adjust the OID being registered, to take account * of the indexes and column range provided.... */ row_oid_len = reginfo->rootoid_len; memcpy( row_oid, (u_char *) reginfo->rootoid, row_oid_len * sizeof(oid)); row_oid[row_oid_len++] = 1; /* tableEntry */ row_oid[row_oid_len++] = tabreg->min_column; reginfo->range_ubound = tabreg->max_column; reginfo->range_subid = row_oid_len-1; build_oid_noalloc(&row_oid[row_oid_len], MAX_OID_LEN-row_oid_len, &len, NULL, 0, index); row_oid_len += len; free(reginfo->rootoid); memdup((u_char **) & reginfo->rootoid, (const u_char *) row_oid, row_oid_len * sizeof(oid)); reginfo->rootoid_len = row_oid_len; /* * ... insert a minimal handler ... */ handler = netsnmp_table_row_handler_get(row); netsnmp_inject_handler(reginfo, handler ); /* * ... and register the row */ return netsnmp_register_handler(reginfo); }
void * netsnmp_iterator_row_next_byoid( netsnmp_iterator_info *iinfo, oid *instance, size_t len ) { oid dummy[] = {0,0}; oid this_inst[ MAX_OID_LEN]; size_t this_len; oid best_inst[ MAX_OID_LEN]; size_t best_len = 0; netsnmp_variable_list *vp1, *vp2; void *ctx1, *ctx2; int n; if (!iinfo || !iinfo->get_first_data_point || !iinfo->get_next_data_point ) return NULL; vp1 = snmp_clone_varbind(iinfo->indexes); vp2 = iinfo->get_first_data_point( &ctx1, &ctx2, vp1, iinfo ); DEBUGMSGTL(("table:iterator:get", "first DP: %x %x %x\n", ctx1, ctx2, vp2)); if ( !instance || !len ) { snmp_free_varbind( vp1 ); return ( vp2 ? ctx2 : NULL ); /* First entry */ } /* XXX - free context ? */ while ( vp2 ) { this_len = MAX_OID_LEN; build_oid_noalloc(this_inst, MAX_OID_LEN, &this_len, dummy, 2, vp2); n = snmp_oid_compare( instance, len, this_inst+2, this_len-2 ); /* * Look for the best-fit candidate for the next row * (bearing in mind the rows may not be ordered "correctly") */ if ( n > 0 ) { if ( best_len == 0 ) { memcpy( best_inst, this_inst, sizeof( this_inst )); best_len = this_len; if (iinfo->flags & NETSNMP_ITERATOR_FLAG_SORTED) break; } else { n = snmp_oid_compare( best_inst, best_len, this_inst, this_len ); if ( n < 0 ) { memcpy( best_inst, this_inst, sizeof( this_inst )); best_len = this_len; if (iinfo->flags & NETSNMP_ITERATOR_FLAG_SORTED) break; } } } vp2 = iinfo->get_next_data_point( &ctx1, &ctx2, vp2, iinfo ); DEBUGMSGTL(("table:iterator:get", "next DP: %x %x %x\n", ctx1, ctx2, vp2)); /* XXX - free context ? */ } /* XXX - final free context ? */ snmp_free_varbind( vp1 ); return ( vp2 ? ctx2 : NULL ); }
/** * @internal * convert the index component stored in the context to an oid */ int usmDHUserKeyTable_index_to_oid(netsnmp_index * oid_idx, usmDHUserKeyTable_mib_index * mib_idx) { int err = SNMP_ERR_NOERROR; /* * temp storage for parsing indexes */ /* * usmUserEngineID(1)/SnmpEngineID/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h */ netsnmp_variable_list var_usmUserEngineID; /* * usmUserName(2)/SnmpAdminString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H */ netsnmp_variable_list var_usmUserName; /* * set up varbinds */ memset(&var_usmUserEngineID, 0x00, sizeof(var_usmUserEngineID)); var_usmUserEngineID.type = ASN_OCTET_STR; memset(&var_usmUserName, 0x00, sizeof(var_usmUserName)); var_usmUserName.type = ASN_OCTET_STR; /* * chain temp index varbinds together */ var_usmUserEngineID.next_variable = &var_usmUserName; var_usmUserName.next_variable = NULL; DEBUGMSGTL(("verbose:usmDHUserKeyTable:usmDHUserKeyTable_index_to_oid", "called\n")); /* * usmUserEngineID(1)/SnmpEngineID/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h */ snmp_set_var_value(&var_usmUserEngineID, (u_char *) & mib_idx->usmUserEngineID, mib_idx->usmUserEngineID_len * sizeof(mib_idx->usmUserEngineID[0])); /* * usmUserName(2)/SnmpAdminString/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/H */ snmp_set_var_value(&var_usmUserName, (u_char *) & mib_idx->usmUserName, mib_idx->usmUserName_len * sizeof(mib_idx->usmUserName[0])); err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len, NULL, 0, &var_usmUserEngineID); if (err) snmp_log(LOG_ERR, "error %d converting index to oid\n", err); /* * parsing may have allocated memory. free it. */ snmp_reset_var_buffers(&var_usmUserEngineID); return err; } /* usmDHUserKeyTable_index_to_oid */