static void sctpAssocTable_collect_invalid(void *what, void *magic) { sctpAssocTable_entry *entry = what; netsnmp_container *to_delete = magic; if (entry->valid) entry->valid = 0; else CONTAINER_INSERT(to_delete, entry); }
/* Creates a row and inserts it. * * Returns: The rows userIndex on success, and 0 otherwise. */ int createRegUserRow(char *stringToRegister) { int static index = 0; index++; openserSIPRegUserTable_context *theRow; oid *OIDIndex; int stringLength; theRow = SNMP_MALLOC_TYPEDEF(openserSIPRegUserTable_context); if (theRow == NULL) { LM_ERR("failed to create a row for openserSIPRegUserTable\n"); return 0; } OIDIndex = pkg_malloc(sizeof(oid)); if (OIDIndex == NULL) { free(theRow); LM_ERR("failed to create a row for openserSIPRegUserTable\n"); return 0; } stringLength = strlen(stringToRegister); OIDIndex[0] = index; theRow->index.len = 1; theRow->index.oids = OIDIndex; theRow->openserSIPUserIndex = index; theRow->openserSIPUserUri = (unsigned char*)pkg_malloc(stringLength* sizeof(char)); if(theRow->openserSIPUserUri== NULL) { pkg_free(OIDIndex); free(theRow); LM_ERR("failed to create a row for openserSIPRegUserTable\n"); return 0; } memcpy(theRow->openserSIPUserUri, stringToRegister, stringLength); theRow->openserSIPUserUri_len = stringLength; theRow->openserSIPUserAuthenticationFailures = 0; CONTAINER_INSERT(cb.container, theRow); return index; }
int populate_hotswap (SaHpiRptEntryT * rpt_entry, oid * rpt_oid, size_t rpt_oid_len) { SaHpiSessionIdT session_id; int rc = AGENT_ERR_NOERROR; oid index_oid[HOTSWAP_INDEX_NR]; netsnmp_index hotswap_index; saHpiHotSwapTable_context *hotswap_context; DEBUGMSGTL ((AGENT, "\n\t--- populate_hotswap. Entry\n")); if ((rc = getSaHpiSession (&session_id)) == AGENT_ERR_NOERROR) { index_oid[0] = rpt_entry->DomainId; index_oid[1] = rpt_entry->ResourceId; hotswap_index.oids = (oid *) & index_oid; hotswap_index.len = HOTSWAP_INDEX_NR; hotswap_context = CONTAINER_FIND (cb.container, &hotswap_index); if (!hotswap_context) { // Couldn't find it. Add new entry. hotswap_context = saHpiHotSwapTable_create_row (&hotswap_index); } if (!hotswap_context) { snmp_log (LOG_ERR, "Not enough memory for a HotSwap row!\n"); return AGENT_ERR_MEMORY_FAULT; } if (saHpiHotSwapTable_modify_context (rpt_entry, rpt_oid, rpt_oid_len, hotswap_context) == AGENT_NEW_ENTRY) { CONTAINER_INSERT (cb.container, hotswap_context); } } DEBUGMSGTL ((AGENT, "\n\t--- populate_hotswap: Exit (rc: %d).\n", rc)); return rc; }
static int _load_tcpconn_table_v6(netsnmp_container *container, int flag) { mib2_tcp6ConnEntry_t tc6; netsnmp_tcpconn_entry *ep; req_e req = GET_FIRST; DEBUGMSGT(("access:tcpconn:container", "load v6\n")); while (getMibstat(MIB_TCP6_CONN, &tc6, sizeof(tc6), req, &Get_everything, 0)==0) { req = GET_NEXT; if ((flag & NETSNMP_ACCESS_TCPCONN_LOAD_ONLYLISTEN && tc6.tcp6ConnState != MIB2_TCP_listen) || (flag & NETSNMP_ACCESS_TCPCONN_LOAD_NOLISTEN && tc6.tcp6ConnState == MIB2_TCP_listen)) { continue; } ep = netsnmp_access_tcpconn_entry_create(); if (ep == NULL) return (-1); DEBUGMSGT(("access:tcpconn:container", "add entry\n")); /* * local address/port. */ ep->loc_addr_len = sizeof(tc6.tcp6ConnLocalAddress); if (sizeof(ep->loc_addr) < ep->loc_addr_len) { netsnmp_access_tcpconn_entry_free(ep); return (-1); } (void)memcpy(&ep->loc_addr, &tc6.tcp6ConnLocalAddress, ep->loc_addr_len); ep->loc_port = tc6.tcp6ConnLocalPort; /* remote address/port */ ep->rmt_addr_len = sizeof(tc6.tcp6ConnRemAddress); (void)memcpy(&ep->rmt_addr, &tc6.tcp6ConnRemAddress, ep->rmt_addr_len); ep->rmt_port = tc6.tcp6ConnRemPort; /* state/pid */ ep->tcpConnState = tc6.tcp6ConnState; ep->pid = 0; ep->arch_data = NULL; /* index */ ep->arbitrary_index = CONTAINER_SIZE(container) + 1; CONTAINER_INSERT(container, (void *)ep); } return (0); }
/* Will return an existing row indexed by the parameter list if one exists, and * return a new one otherwise. If the row is new, then the provided index will be * assigned to the new row. * * Note: NULL will be returned on an error */ openserSIPPortTable_context *getRow(int ipType, int *ipAddress) { int lengthOfOID; oid *currentOIDIndex = createIndex(ipType, ipAddress, &lengthOfOID); if (currentOIDIndex == NULL) { return NULL; } netsnmp_index theIndex; theIndex.oids = currentOIDIndex; theIndex.len = lengthOfOID; openserSIPPortTable_context *rowToReturn; /* Lets check to see if there is an existing row. */ rowToReturn = CONTAINER_FIND(cb.container, &theIndex); /* We found an existing row, so there is no need to create a new one. * Let's return it to the caller. */ if (rowToReturn != NULL) { /* We don't need the index we allocated anymore, because the * existing row already has its own copy, so free the memory */ pkg_free(currentOIDIndex); return rowToReturn; } /* If we are here then the row doesn't exist yet. So lets create it. */ rowToReturn = SNMP_MALLOC_TYPEDEF(openserSIPPortTable_context); /* Not enough memory to create the new row. */ if (rowToReturn == NULL) { pkg_free(currentOIDIndex); return NULL; } /* Assign the Container Index. */ rowToReturn->index.len = lengthOfOID; rowToReturn->index.oids = currentOIDIndex; memcpy(rowToReturn->openserSIPStringIndex, currentOIDIndex, NUM_IP_OCTETS + 3); rowToReturn->openserSIPStringIndex_len = NUM_IP_OCTETS + 3; /* Insert the new row into the table */ CONTAINER_INSERT(cb.container, rowToReturn); return rowToReturn; }
/** create a new row in the table */ static void register_foreach(const struct sysORTable* data, void* dummy) { sysORTable_entry *entry; sysORLastChange = data->OR_uptime; entry = SNMP_MALLOC_TYPEDEF(sysORTable_entry); if (!entry) { snmp_log(LOG_ERR, "could not allocate storage, sysORTable is inconsistent\n"); } else { const oid firstNext = sysORNextIndex; netsnmp_iterator* it = CONTAINER_ITERATOR(table); do { const sysORTable_entry* value; const oid cur = sysORNextIndex; if (sysORNextIndex == SNMP_MIN(MAX_SUBID, 2147483647UL)) sysORNextIndex = 1; else ++sysORNextIndex; for (value = (sysORTable_entry*)it->curr(it); value && value->sysORIndex < cur; value = (sysORTable_entry*)ITERATOR_NEXT(it)) { } if (value && value->sysORIndex == cur) { if (sysORNextIndex < cur) it->reset(it); } else { entry->sysORIndex = cur; break; } } while (firstNext != sysORNextIndex); ITERATOR_RELEASE(it); if(firstNext == sysORNextIndex) { snmp_log(LOG_ERR, "Failed to locate a free index in sysORTable\n"); free(entry); } else { entry->data = data; entry->oid_index.len = 1; entry->oid_index.oids = &entry->sysORIndex; CONTAINER_INSERT(table, entry); } } }
/** * @internal * parse mode: */ void _pm_save_index_string_string(FILE *f, netsnmp_container *cin, int flags) { char line[STRINGMAX], *ptr; netsnmp_token_value_index *tvi; size_t count = 0, len; netsnmp_assert(NULL != f); netsnmp_assert(NULL != cin); while (fgets(line, sizeof(line), f) != NULL) { ++count; ptr = line; len = strlen(line) - 1; if (line[len] == '\n') line[len] = 0; /* * save blank line or comment? */ if (flags & PM_FLAG_SKIP_WHITESPACE) { if (NULL == (ptr = skip_white(ptr))) continue; } tvi = SNMP_MALLOC_TYPEDEF(netsnmp_token_value_index); if (NULL == tvi) { snmp_log(LOG_ERR,"malloc failed\n"); break; } /* * copy whole line, then set second pointer to * after token. One malloc, 2 strings! */ tvi->index = count; tvi->token = strdup(line); if (NULL == tvi->token) { snmp_log(LOG_ERR,"malloc failed\n"); free(tvi); break; } tvi->value.cp = skip_not_white(tvi->token); if (NULL != tvi->value.cp) { *(tvi->value.cp) = 0; ++(tvi->value.cp); } CONTAINER_INSERT(cin, tvi); } }
/** * check entry for update * */ static void _snarf_arp_entry(netsnmp_arp_entry *arp_entry, netsnmp_container *container) { inetNetToMediaTable_rowreq_ctx *rowreq_ctx; int inetAddressType; DEBUGTRACE; netsnmp_assert(NULL != arp_entry); netsnmp_assert(NULL != container); /* * convert the addr len to an inetAddressType */ switch (arp_entry->arp_ipaddress_len) { case 4: inetAddressType = INETADDRESSTYPE_IPV4; break; case 6: inetAddressType = INETADDRESSTYPE_IPV6; break; default: netsnmp_access_arp_entry_free(arp_entry); snmp_log(LOG_ERR, "unsupported address type\n"); return; } /* * allocate an row context and set the index(es), then add it to * the container */ rowreq_ctx = inetNetToMediaTable_allocate_rowreq_ctx(arp_entry, NULL); if ((NULL != rowreq_ctx) && (MFD_SUCCESS == inetNetToMediaTable_indexes_set (rowreq_ctx, rowreq_ctx->data->if_index, inetAddressType, rowreq_ctx->data->arp_ipaddress, rowreq_ctx->data->arp_ipaddress_len))) { rowreq_ctx->inetNetToMediaRowStatus = ROWSTATUS_ACTIVE; CONTAINER_INSERT(container, rowreq_ctx); } else { if (rowreq_ctx) { snmp_log(LOG_ERR, "error setting index while loading " "inetNetToMediaTable cache.\n"); inetNetToMediaTable_release_rowreq_ctx(rowreq_ctx); } else netsnmp_access_arp_entry_free(arp_entry); } }
/* * Retrieve a sensor entry by name, * or (optionally) insert a new one into the container */ netsnmp_sensor_info * sensor_by_name( char *name, int create_type ) { netsnmp_sensor_info *sp; DEBUGMSGTL(("sensors:name", "Get sensor entry (%s)\n", name)); /* * Look through the list for a matching entry */ /* .. or use a secondary index container ?? */ for (sp = CONTAINER_FIRST( _sensor_container ); sp; sp = CONTAINER_NEXT( _sensor_container, sp )) { if ( !strcmp( name, sp->name )) return sp; } /* * Not found... */ if ( create_type == NETSNMP_SENSOR_FIND_EXIST ) { DEBUGMSGTL(("sensors:name", "No such sensor entry\n")); return NULL; } /* * ... so let's create a new one, using the type supplied */ sp = SNMP_MALLOC_TYPEDEF( netsnmp_sensor_info ); if ( sp ) { strcpy( sp->name, name ); sp->type = create_type; /* * Set up the index value. * * All this trouble, just for a simple integer. * Surely there must be a better way? */ sp->idx.len = 1; sp->idx.oids = SNMP_MALLOC_TYPEDEF( oid ); sp->idx.oids[0] = ++_sensor_idx; } DEBUGMSGTL(("sensors:name", "Create sensor entry (type = %d, index = %d\n", create_type, _sensor_idx)); CONTAINER_INSERT( _sensor_container, sp ); return sp; }
/************************************************************ * * Retreives all the alarm definitions */ void alarmModelTable_insert_defs(AlarmTableDefs& defs) { for (AlarmTableDefsIterator it = defs.begin(); it != defs.end(); it++) { alarmModelTable_context* ctx = alarmModelTable_create_row_context((char*) "", it->alarm_index(), it->state()); if (ctx) { ctx->_alarm_table_def = &(*it); CONTAINER_INSERT(cb.container, ctx); } } }
/** * add new entry */ static void _add_new_interface(netsnmp_interface_entry *ifentry, netsnmp_container *container) { ifTable_rowreq_ctx *rowreq_ctx; DEBUGMSGTL(("ifTable:access", "creating new entry\n")); /* * allocate an row context and set the index(es), then add it to * the container and set ifTableLastChanged. */ rowreq_ctx = ifTable_allocate_rowreq_ctx(ifentry); if ((NULL != rowreq_ctx) && (MFD_SUCCESS == ifTable_indexes_set(rowreq_ctx, ifentry->index))) { CONTAINER_INSERT(container, rowreq_ctx); /* * fix this when we hit an arch that reports its own last change */ netsnmp_assert(0 == (ifentry->ns_flags & NETSNMP_INTERFACE_FLAGS_HAS_LASTCHANGE)); if (0 == _first_load) { rowreq_ctx->data.ifLastChange = netsnmp_get_agent_uptime(); ifTable_lastChange_set(rowreq_ctx->data.ifLastChange); } #ifdef USING_IP_MIB_IPV4INTERFACETABLE_IPV4INTERFACETABLE_MODULE /* * give ipv4If table a crack at the entry */ ipv4InterfaceTable_check_entry_for_updates(rowreq_ctx, ifentry); #endif #ifdef USING_IP_MIB_IPV6INTERFACETABLE_IPV6INTERFACETABLE_MODULE /* * give ipv6If table a crack at the entry */ ipv6InterfaceTable_check_entry_for_updates(rowreq_ctx, ifentry); #endif } else { if (rowreq_ctx) { snmp_log(LOG_ERR, "error setting index while loading " "ifTable cache.\n"); ifTable_release_rowreq_ctx(rowreq_ctx); } else { snmp_log(LOG_ERR, "memory allocation failed while loading " "ifTable cache.\n"); netsnmp_access_interface_entry_free(ifentry); } } }
/* --------------------------------------------------------------------- */ int netsnmp_swinst_arch_load( netsnmp_container *container, u_int flags) { FILE *p = popen("dpkg-query --show --showformat '${Package}#${Version}#${Section}#${Priority}#${Essential}#${Status}\n'", "r"); char package[SNMP_MAXBUF]; char version[SNMP_MAXBUF]; char section[SNMP_MAXBUF]; char priority[SNMP_MAXBUF]; char essential[SNMP_MAXBUF]; char status[SNMP_MAXBUF]; char buf[BUFSIZ]; netsnmp_swinst_entry *entry; int i = 0; if (p == NULL) { snmp_perror("dpkg-list"); return 1; } while (fgets(buf, BUFSIZ, p)) { DEBUGMSG(("swinst_apt", "entry: %s\n", buf)); entry = netsnmp_swinst_entry_create( i++ ); if (NULL == entry) continue; /* error already logged by function */ CONTAINER_INSERT(container, entry); sscanf(buf, apt_fmt, package, version, section, priority, essential, status); if (strstr(status, "not-installed")) continue; entry->swName_len = snprintf( entry->swName, sizeof(entry->swName), "%s-%s", package, version); if (entry->swName_len >= sizeof(entry->swName)) entry->swName_len = sizeof(entry->swName)-1; entry->swType = (strcmp(essential, "yes") == 0) ? 2 /* operatingSystem */ : 4; /* application */ entry->swDate_len = 8; memcpy(entry->swDate, "\0\0\1\1\0\0\0\0", 8); } pclose(p); DEBUGMSGTL(("swinst:load:arch"," loaded %d entries\n", (int) CONTAINER_SIZE(container))); return 0; }
/** * add new entry */ static void _add_new_entry(netsnmp_ipaddress_entry *ipaddress_entry, netsnmp_container *container) { ipAddressTable_rowreq_ctx *rowreq_ctx; DEBUGMSGTL(("ipAddressTable:access", "creating new entry\n")); netsnmp_assert(NULL != ipaddress_entry); netsnmp_assert(NULL != container); /* * allocate an row context and set the index(es) */ rowreq_ctx = ipAddressTable_allocate_rowreq_ctx(ipaddress_entry, NULL); if ((NULL != rowreq_ctx) && (MFD_SUCCESS == ipAddressTable_indexes_set(rowreq_ctx, ipaddress_entry->ia_address_len, ipaddress_entry->ia_address, ipaddress_entry->ia_address_len))) { if (CONTAINER_INSERT(container, rowreq_ctx) < 0) { DEBUGMSGTL (("ipAddressTable:access","container insert failed for new entry\n")); ipAddressTable_release_rowreq_ctx(rowreq_ctx); return; } rowreq_ctx->ipAddressLastChanged = rowreq_ctx->ipAddressCreated = netsnmp_get_agent_uptime(); } else { if (NULL != rowreq_ctx) { snmp_log(LOG_ERR, "error setting index while loading " "ipAddressTable cache.\n"); ipAddressTable_release_rowreq_ctx(rowreq_ctx); } else { snmp_log(LOG_ERR, "memory allocation failed while loading " "ipAddressTable cache.\n"); netsnmp_access_ipaddress_entry_free(ipaddress_entry); } return; } /*------------------------------------------------------------------- * handle data that isn't part of the data_access ipaddress structure */ rowreq_ctx->ipAddressRowStatus = ROWSTATUS_ACTIVE; }
/* * sql trap handler */ int mysql_handler(netsnmp_pdu *pdu, netsnmp_transport *transport, netsnmp_trapd_handler *handler) { sql_buf *sqlb; int old_format, rc; DEBUGMSGTL(("sql:handler", "called\n")); /** allocate a buffer to save data */ sqlb = _sql_buf_get(); if (NULL == sqlb) { snmp_log(LOG_ERR, "Could not allocate trap sql buffer\n"); return syslog_handler( pdu, transport, handler ); } /** save OID output format and change to numeric */ old_format = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT); netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, NETSNMP_OID_OUTPUT_NUMERIC); rc = _sql_save_trap_info(sqlb, pdu, transport); rc = _sql_save_varbind_info(sqlb, pdu); /** restore previous OID output format */ netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, old_format); /** insert into queue */ rc = CONTAINER_INSERT(_sql.queue, sqlb); if(rc) { snmp_log(LOG_ERR, "Could not log queue sql trap buffer\n"); _sql_log(sqlb, NULL); _sql_buf_free(sqlb, 0); return -1; } /** save queue if size is > max */ if (CONTAINER_SIZE(_sql.queue) >= _sql.queue_max) _sql_process_queue(0,NULL); return 0; }
/* Create a row at the given index, containing stringToRegister, and insert it * into the table. Note that stringToRegister will be copied, so it is not * necessary to pre-allocate this string anywhere. */ void createRow(int index, char *stringToRegister) { openserSIPMethodSupportedTable_context *theRow; oid *OIDIndex; char *copiedString; int stringLength; theRow = SNMP_MALLOC_TYPEDEF(openserSIPMethodSupportedTable_context); if (theRow == NULL) { LM_ERR("failed to create a row for openserSIPMethodSupportedTable\n"); return; } OIDIndex = pkg_malloc(sizeof(oid)); if (OIDIndex == NULL) { free(theRow); LM_ERR("failed to create a row for openserSIPMethodSupportedTable\n"); return; } stringLength = strlen(stringToRegister); copiedString = pkg_malloc((stringLength + 1) * sizeof(char)); if (copiedString == NULL) { SNMP_FREE(theRow); LM_ERR("failed to create a row for openserSIPMethodSupportedTable\n"); return; } strcpy(copiedString, stringToRegister); OIDIndex[0] = index; theRow->index.len = 1; theRow->index.oids = OIDIndex; theRow->openserSIPMethodSupportedIndex = index; theRow->openserSIPMethodName = (unsigned char*) copiedString; theRow->openserSIPMethodName_len = stringLength; CONTAINER_INSERT(cb.container, theRow); }
/** * check entry for update */ static void _snarf_route_entry(netsnmp_route_entry *route_entry, netsnmp_container *container) { inetCidrRouteTable_rowreq_ctx *rowreq_ctx; netsnmp_assert(NULL != route_entry); netsnmp_assert(NULL != container); /* * per inetCidrRouteType: * * Routes which do not result in traffic forwarding or * rejection should not be displayed even if the * implementation keeps them stored internally. */ if (route_entry->rt_type == 0) { /* set when route not up */ DEBUGMSGT(("verbose:inetCidrRouteTable:inetCidrRouteTable_cache_load", "skipping route\n")); netsnmp_access_route_entry_free(route_entry); return; } /* * allocate an row context and set the index(es), then add it to * the container */ rowreq_ctx = inetCidrRouteTable_allocate_rowreq_ctx(route_entry, NULL); if ((NULL != rowreq_ctx) && (MFD_SUCCESS == inetCidrRouteTable_indexes_set (rowreq_ctx, route_entry->rt_dest_type, (char *) route_entry->rt_dest, route_entry->rt_dest_len, route_entry->rt_pfx_len, route_entry->rt_policy, route_entry->rt_policy_len, route_entry->rt_nexthop_type, (char *) route_entry->rt_nexthop, route_entry->rt_nexthop_len))) { CONTAINER_INSERT(container, rowreq_ctx); rowreq_ctx->row_status = ROWSTATUS_ACTIVE; } else { if (rowreq_ctx) { snmp_log(LOG_ERR, "error setting index while loading " "inetCidrRoute cache.\n"); inetCidrRouteTable_release_rowreq_ctx(rowreq_ctx); } else netsnmp_access_route_entry_free(route_entry); } }
/** * add new entry */ static void _add_new_entry(netsnmp_defaultrouter_entry *defaultrouter_entry, netsnmp_container *container) { ipDefaultRouterTable_rowreq_ctx *rowreq_ctx; DEBUGMSGTL(("ipDefaultRouterTable:access", "creating new entry\n")); netsnmp_assert(NULL != defaultrouter_entry); netsnmp_assert(NULL != container); /* * allocate an row context and set the index(es) */ rowreq_ctx = ipDefaultRouterTable_allocate_rowreq_ctx(defaultrouter_entry, NULL); if ((NULL != rowreq_ctx) && (MFD_SUCCESS == ipDefaultRouterTable_indexes_set(rowreq_ctx, defaultrouter_entry->dr_addresstype, defaultrouter_entry->dr_address, defaultrouter_entry->dr_address_len, defaultrouter_entry->dr_if_index))) { if (CONTAINER_INSERT(container, rowreq_ctx) < 0) { DEBUGMSGTL(("ipAddressTable:access", "container insert failed for new entry\n")); ipDefaultRouterTable_release_rowreq_ctx(rowreq_ctx); return; } } else { if (NULL != rowreq_ctx) { snmp_log(LOG_ERR, "error setting index while loading " "ipDefaultRouterTable cache.\n"); ipDefaultRouterTable_release_rowreq_ctx(rowreq_ctx); } else { snmp_log(LOG_ERR, "memory allocation failed while loading " "ipDefaultRouterTable cache.\n"); netsnmp_access_defaultrouter_entry_free(defaultrouter_entry); } return; } }
static void sctpTables_add_rem_port(sctpAssocTable_entry * assoc, sctpTables_containers * containers) { sctpLookupRemPortTable_entry *entry; entry = sctpLookupRemPortTable_entry_create(); if (entry == NULL) { DEBUGMSGTL(("sctp:tables:fill_lookup", "cannot create sctpLookupRemPortTable_entry")); return; } entry->sctpAssocId = assoc->sctpAssocId; entry->sctpAssocRemPort = assoc->sctpAssocRemPort; entry->sctpLookupRemPortStartTime = assoc->sctpAssocStartTime; sctpLookupRemPortTable_entry_update_index(entry); CONTAINER_INSERT(containers->sctpLookupRemPortTable, entry); }
int sctpAssocTable_add_or_update(netsnmp_container *assocTable, sctpAssocTable_entry * entry) { /* * we have full sctpAssocTable entry, update or add it in the container */ sctpAssocTable_entry *old; entry->valid = 1; /* * try to find it in the container */ sctpAssocTable_entry_update_index(entry); old = CONTAINER_FIND(assocTable, entry); if (old != NULL) { /* * update existing entry, don't overwrite the timestamp */ time_t timestamp = old->sctpAssocStartTime; if (timestamp == 0 && entry->sctpAssocStartTime == 0 && entry->sctpAssocState >= SCTPASSOCSTATE_ESTABLISHED) timestamp = netsnmp_get_agent_uptime(); /* set the timestamp if it was not set before and entry reaches the right state */ sctpAssocTable_entry_copy(entry, old); old->sctpAssocStartTime = timestamp; sctpAssocTable_entry_free(entry); } else { /* * the entry is new, add it there */ if (entry->sctpAssocStartTime == 0 && entry->sctpAssocState >= SCTPASSOCSTATE_ESTABLISHED) { entry->sctpAssocStartTime = netsnmp_get_agent_uptime(); } CONTAINER_INSERT(assocTable, entry); } return SNMP_ERR_NOERROR; }
/************************************************************ * * Initializes the ituAlarmTable module */ void init_ituAlarmTable(void) { AlarmTableDefs& defs = AlarmTableDefs::get_instance(); if (initialize_table_ituAlarmTable() == SNMP_ERR_NOERROR) { for (AlarmTableDefsIterator it = defs.begin(); it != defs.end(); it++) { ituAlarmTable_context* ctx = ituAlarmTable_create_row_context((char*) "", it->index(), it->severity()); if (ctx) { ctx->_alarm_table_def = &(*it); CONTAINER_INSERT(cb.container, ctx); } } } }
/** * Adds a row to the given table (stored in proper lexographical order). * * returns SNMPERR_SUCCESS on successful addition. * or SNMPERR_GENERR on failure (E.G., indexes already existed) */ int netsnmp_tdata_add_row(netsnmp_tdata *table, netsnmp_tdata_row *row) { if (!row || !table) return SNMPERR_GENERR; if (row->indexes) _netsnmp_tdata_generate_index_oid(row); if (!row->oid_index.oids) { snmp_log(LOG_ERR, "illegal data attempted to be added to table %s (no index)\n", table->name); return SNMPERR_GENERR; } /* * The individual index values probably won't be needed, * so this memory can be released. * Note that this is purely internal to the helper. * The calling application can set this flag as * a hint to the helper that these values aren't * required, but it's up to the helper as to * whether it takes any notice or not! */ if (table->flags & TDATA_FLAG_NO_STORE_INDEXES) { snmp_free_varbind(row->indexes); row->indexes = NULL; } /* * add this row to the stored table */ if (CONTAINER_INSERT( table->container, row ) != 0) return SNMPERR_GENERR; DEBUGMSGTL(("tdata_add_row", "added row (%p)\n", row)); return SNMPERR_SUCCESS; }
/** * check entry for update */ static void _check_entry_for_updates (ipDefaultRouterTable_rowreq_ctx * rowreq_ctx, void **magic) { netsnmp_container *defaultrouter_container = magic[0]; netsnmp_container *to_delete = (netsnmp_container *) magic[1]; /* * check for matching entry using secondary index. */ netsnmp_defaultrouter_entry *defaultrouter_entry = CONTAINER_FIND (defaultrouter_container, rowreq_ctx->data); if (NULL == defaultrouter_entry) { DEBUGMSGTL (("ipDefaultRouterTable:access", "removing missing entry\n")); if (NULL == to_delete) { magic[1] = to_delete = netsnmp_container_find ("lifo"); if (NULL == to_delete) snmp_log (LOG_ERR, "couldn't create delete container\n"); } if (NULL != to_delete) CONTAINER_INSERT (to_delete, rowreq_ctx); } else { DEBUGMSGTL (("ipDefaultRouterTable:access", "updating existing entry\n")); /* * Check for changes & update */ netsnmp_access_defaultrouter_entry_update (rowreq_ctx->data, defaultrouter_entry); /* * remove entry from ifcontainer */ CONTAINER_REMOVE (defaultrouter_container, defaultrouter_entry); netsnmp_access_defaultrouter_entry_free (defaultrouter_entry); } }
/** * check entry for update */ static void _check_entry_for_updates(ipAddressTable_rowreq_ctx * rowreq_ctx, void **magic) { netsnmp_container *ipaddress_container = (netsnmp_container*)magic[0]; netsnmp_container *to_delete = (netsnmp_container*)magic[1]; /* * check for matching entry using secondary index. */ netsnmp_ipaddress_entry *ipaddress_entry = (netsnmp_ipaddress_entry*) CONTAINER_FIND(ipaddress_container, rowreq_ctx->data); if (NULL == ipaddress_entry) { DEBUGMSGTL(("ipAddressTable:access", "removing missing entry\n")); if (NULL == to_delete) { magic[1] = to_delete = netsnmp_container_find("lifo"); if (NULL == to_delete) snmp_log(LOG_ERR, "couldn't create delete container\n"); } if (NULL != to_delete) CONTAINER_INSERT(to_delete, rowreq_ctx); } else { DEBUGMSGTL(("ipAddressTable:access", "updating existing entry\n")); /* * Check for changes & update */ if (netsnmp_access_ipaddress_entry_update(rowreq_ctx->data, ipaddress_entry) > 0) rowreq_ctx->ipAddressLastChanged = netsnmp_get_agent_uptime(); /* * remove entry from ifcontainer */ CONTAINER_REMOVE(ipaddress_container, ipaddress_entry); netsnmp_access_ipaddress_entry_free(ipaddress_entry); } }
netsnmp_fsys_info * _fsys_create_entry( void ) { netsnmp_fsys_info *sp; sp = SNMP_MALLOC_TYPEDEF( netsnmp_fsys_info ); if ( sp ) { /* * Set up the index value. * * All this trouble, just for a simple integer. * Surely there must be a better way? */ sp->idx.len = 1; sp->idx.oids = SNMP_MALLOC_TYPEDEF( oid ); sp->idx.oids[0] = ++_fsys_idx; } DEBUGMSGTL(("fsys:new", "Create filesystem entry (index = %d\n", _fsys_idx)); CONTAINER_INSERT( _fsys_container, sp ); return sp; }
static int _insert_nsfile (netsnmp_container * c, const char *name, struct stat *stats, u_int flags) { int rc; netsnmp_file *ns_file = netsnmp_file_new (name, 0, 0, 0); if (NULL == ns_file) { snmp_log (LOG_ERR, "error creating ns_file\n"); return -1; } if (flags & NETSNMP_DIR_NSFILE_STATS) { ns_file->stats = (struct stat *) calloc (1, sizeof (*(ns_file->stats))); if (NULL == ns_file->stats) { snmp_log (LOG_ERR, "error creating stats for ns_file\n"); netsnmp_file_release (ns_file); return -1; } /** use stats from earlier if we have them */ if (stats) memcpy (ns_file->stats, stats, sizeof (*stats)); else stat (ns_file->name, ns_file->stats); } rc = CONTAINER_INSERT (c, ns_file); if (-1 == rc) { DEBUGMSGTL (("directory:container", " err adding %s\n", name)); netsnmp_file_release (ns_file); } return 0; }
static void sctpTables_add_rem_prim_ip_addr(sctpAssocTable_entry * assoc, sctpTables_containers * containers) { sctpLookupRemPrimIPAddrTable_entry *entry; entry = sctpLookupRemPrimIPAddrTable_entry_create(); if (entry == NULL) { DEBUGMSGTL(("sctp:tables:fill_lookup", "cannot create sctpLookupRemPrimIPAddrTable_entry")); return; } entry->sctpAssocId = assoc->sctpAssocId; entry->sctpAssocRemPrimAddrType = assoc->sctpAssocRemPrimAddrType; entry->sctpAssocRemPrimAddr_len = assoc->sctpAssocRemPrimAddr_len; memcpy(entry->sctpAssocRemPrimAddr, assoc->sctpAssocRemPrimAddr, assoc->sctpAssocRemPrimAddr_len); entry->sctpLookupRemPrimIPAddrStartTime = assoc->sctpAssocStartTime; sctpLookupRemPrimIPAddrTable_entry_update_index(entry); CONTAINER_INSERT(containers->sctpLookupRemPrimIPAddrTable, entry); }
/** * add new entry */ static void _add_new(netsnmp_systemstats_entry *ifstats_entry, netsnmp_container *container) { ipIfStatsTable_rowreq_ctx *rowreq_ctx; DEBUGMSGTL(("ipIfStatsTable:access", "creating new entry\n")); netsnmp_assert(NULL != ifstats_entry); netsnmp_assert(NULL != container); /* * allocate an row context and set the index(es) */ rowreq_ctx = ipIfStatsTable_allocate_rowreq_ctx(ifstats_entry, NULL); if ((NULL != rowreq_ctx) && (MFD_SUCCESS == ipIfStatsTable_indexes_set(rowreq_ctx, ifstats_entry->index[0], ifstats_entry->index[1]))) { rowreq_ctx->ipIfStatsRefreshRate = ipis_cache_refresh * 1000; /* milli-seconds */ CONTAINER_INSERT(container, rowreq_ctx); ipIfStatsTable_lastChange_set(netsnmp_get_agent_uptime()); } else { if (NULL != rowreq_ctx) { snmp_log(LOG_ERR, "error setting index while loading " "ipIfStatsTable cache.\n"); ipIfStatsTable_release_rowreq_ctx(rowreq_ctx); } else { snmp_log(LOG_ERR, "memory allocation failed while loading " "ipIfStatsTable cache.\n"); netsnmp_access_systemstats_entry_free(ifstats_entry); } } }
void put_pwrTable(int idx, char* name, int id, int status) { netsnmp_index index; oid myoid; pwrTable_context* myrow; int makeit=0; myoid = idx; index.oids = &myoid; index.len = 1; if(!(myrow = (pwrTable_context*)CONTAINER_FIND(cb.container, &index))) { myrow = pwrTable_create_row(&index); makeit=1; } myrow->pwrIndex = idx; strcpy(myrow->pwrSystem, name); myrow->pwrSystem_len = strlen(name); myrow->pwrId = id; myrow->pwrStatus = status; if(makeit) CONTAINER_INSERT(cb.container,myrow); }
SaErrorT populate_saHpiDomainEventTable(SaHpiSessionIdT sessionid, SaHpiEventT *event, oid * this_child_oid, size_t *this_child_oid_len) { SaErrorT rv = SA_OK; int new_row = MIB_FALSE; oid domain_evt_oid[DOMAIN_EVENT_INDEX_NR]; netsnmp_index domain_evt_idx; saHpiDomainEventTable_context *domain_evt_ctx; oid column[2]; int column_len = 2; DR_XREF *dr_entry; SaHpiDomainIdResourceIdArrayT dr_pair; DEBUGMSGTL ((AGENT, "populate_saHpiDomainEventTable, called\n")); /* check for NULL pointers */ if (!event) { DEBUGMSGTL ((AGENT, "ERROR: populate_saHpiDomainEventTable() passed NULL event pointer\n")); return AGENT_ERR_INTERNAL_ERROR; } /* BUILD oid for new row */ /* assign the number of indices */ domain_evt_idx.len = DOMAIN_EVENT_INDEX_NR; /** Index saHpiDomainId is external */ domain_evt_oid[0] = get_domain_id(sessionid); /** Index saHpiDomainEventEntryId is internal */ dr_pair.domainId_resourceId_arry[0] = get_domain_id(sessionid); dr_pair.domainId_resourceId_arry[1] = event->Source; dr_entry = domain_resource_pair_get(&dr_pair, &dr_table); if (dr_entry == NULL) { DEBUGMSGTL ((AGENT, "ERROR: populate_saHpiDomainEventTable() domain_resource_pair_get returned NULL\n")); return AGENT_ERR_INTERNAL_ERROR; } domain_evt_oid[1] = dr_entry->entry_id++; /** Index saHpiEventSeverity is external */ domain_evt_oid[2] = event->Severity + 1; /* assign the indices to the index */ domain_evt_idx.oids = (oid *) & domain_evt_oid; /* See if Row exists. */ domain_evt_ctx = NULL; domain_evt_ctx = CONTAINER_FIND(cb.container, &domain_evt_idx); if (!domain_evt_ctx) { // New entry. Add it domain_evt_ctx = saHpiDomainEventTable_create_row(&domain_evt_idx); new_row = MIB_TRUE; } if (!domain_evt_ctx) { snmp_log (LOG_ERR, "Not enough memory for a Domain Event row!"); rv = AGENT_ERR_INTERNAL_ERROR; } /** SaHpiEntryId = ASN_UNSIGNED */ domain_evt_ctx->saHpiDomainEventEntryId = domain_evt_oid[2]; /** SaHpiTime = ASN_COUNTER64 */ assign_timestamp(&event->Timestamp, &domain_evt_ctx->saHpiDomainEventTimestamp); /** INTEGER = ASN_INTEGER */ domain_evt_ctx->saHpiDomainEventType = event->EventDataUnion.DomainEvent.Type + 1; if (new_row == MIB_TRUE) CONTAINER_INSERT (cb.container, domain_evt_ctx); domain_event_entry_count = CONTAINER_SIZE (cb.container); /* create full oid on This row for parent RowPointer */ column[0] = 1; column[1] = COLUMN_SAHPIDOMAINEVENTTIMESTAMP; memset(this_child_oid, 0, sizeof(this_child_oid)); build_full_oid(saHpiDomainEventTable_oid, saHpiDomainEventTable_oid_len, column, column_len, &domain_evt_idx, this_child_oid, MAX_OID_LEN, this_child_oid_len); return SA_OK; }
/** * load initial data * * TODO:350:M: Implement ipv6InterfaceTable data load * * @param container container to which items should be inserted * * @retval MFD_SUCCESS : success. * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source * @retval MFD_ERROR : other error. * * This function is called to load the index(es) (and data, optionally) * for the every row in the data set. * * @remark * While loading the data, the only important thing is the indexes. * If access to your data is cheap/fast (e.g. you have a pointer to a * structure in memory), it would make sense to update the data here. * If, however, the accessing the data invovles more work (e.g. parsing * some other existing data, or peforming calculations to derive the data), * then you can limit yourself to setting the indexes and saving any * information you will need later. Then use the saved information in * ipv6InterfaceTable_row_prep() for populating data. * * @note * If you need consistency between rows (like you want statistics * for each row to be from the same time frame), you should set all * data here. * */ int ipv6InterfaceTable_container_load(netsnmp_container *container) { ipv6InterfaceTable_rowreq_ctx *rowreq_ctx; size_t count = 0; /* * temporary storage for index values */ /* * ipv6InterfaceIfIndex(1)/InterfaceIndex/ASN_INTEGER/long(long)//l/a/w/e/R/d/H */ long ipv6InterfaceIfIndex; DEBUGMSGTL(("verbose:ipv6InterfaceTable:ipv6InterfaceTable_container_load", "called\n")); /* * TODO:351:M: |-> Load/update data in the ipv6InterfaceTable container. * loop over your ipv6InterfaceTable data, allocate a rowreq context, * set the index(es) [and data, optionally] and insert into * the container. */ while (1) { /* * check for end of data; bail out if there is no more data */ if (1) break; /* * TODO:352:M: | |-> set indexes in new ipv6InterfaceTable rowreq context. * data context will be set from the param (unless NULL, * in which case a new data context will be allocated) */ rowreq_ctx = ipv6InterfaceTable_allocate_rowreq_ctx(NULL); if (NULL == rowreq_ctx) { snmp_log(LOG_ERR, "memory allocation failed\n"); return MFD_RESOURCE_UNAVAILABLE; } if (MFD_SUCCESS != ipv6InterfaceTable_indexes_set(rowreq_ctx, ipv6InterfaceIfIndex)) { snmp_log(LOG_ERR, "error setting index while loading " "ipv6InterfaceTable data.\n"); ipv6InterfaceTable_release_rowreq_ctx(rowreq_ctx); continue; } /* * TODO:352:r: | |-> populate ipv6InterfaceTable data context. * Populate data context here. (optionally, delay until row prep) */ /* * non-TRANSIENT data: no need to copy. set pointer to data */ /* * insert into table container */ CONTAINER_INSERT(container, rowreq_ctx); ++count; } DEBUGMSGT(("verbose:ipv6InterfaceTable:ipv6InterfaceTable_container_load", "inserted %d records\n", count)); return MFD_SUCCESS; } /* ipv6InterfaceTable_container_load */