int snmp_input(int op, struct snmp_session *session, int reqid, struct snmp_pdu *pdu, void *magic) { struct sockaddr_in *src_ip; uint32_t specific; struct variable_list *var; #ifdef HAVE_NETSNMP if (op != NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE) goto out; #else if (op != RECEIVED_MESSAGE) goto out; #endif if (pdu->command != SNMP_MSG_TRAP) goto out; if (snmp_oid_compare(ipmi_oid, IPMI_OID_SIZE, pdu->enterprise, pdu->enterprise_length) != 0) { goto out; } if (pdu->trap_type != SNMP_TRAP_ENTERPRISESPECIFIC) goto out; src_ip = (struct sockaddr_in *) &pdu->agent_addr; specific = pdu->specific_type; var = pdu->variables; if (var == NULL) goto out; if (var->type != ASN_OCTET_STR) goto out; if (snmp_oid_compare(ipmi_oid, IPMI_OID_SIZE, var->name, var->name_length) != 0) { goto out; } if (var->val_len < 46) goto out; ipmi_handle_snmp_trap_data(src_ip, sizeof(*src_ip), IPMI_EXTERN_ADDR_IP, specific, var->val.string, var->val_len); out: return 1; }
int agentx_notify(netsnmp_session * session, netsnmp_pdu *pdu) { netsnmp_session *sp; netsnmp_variable_list *var; extern const oid sysuptime_oid[], snmptrap_oid[]; extern const size_t sysuptime_oid_len, snmptrap_oid_len; sp = find_agentx_session(session, pdu->sessid); if (sp == NULL) return AGENTX_ERR_NOT_OPEN; var = pdu->variables; if (!var) return AGENTX_ERR_PROCESSING_ERROR; if (snmp_oid_compare(var->name, var->name_length, sysuptime_oid, sysuptime_oid_len) == 0) { var = var->next_variable; } if (!var || snmp_oid_compare(var->name, var->name_length, snmptrap_oid, snmptrap_oid_len) != 0) return AGENTX_ERR_PROCESSING_ERROR; /* * If sysUptime isn't the first varbind, don't worry. * send_trap_vars() will add it if necessary. * * Note that if this behaviour is altered, it will * be necessary to add sysUptime here, * as this is valid AgentX syntax. */ /* If a context name was specified, send the trap using that context. * Otherwise, send the trap without the context using the old method */ if (pdu->contextName != NULL) { send_trap_vars_with_context(-1, -1, pdu->variables, pdu->contextName); } else { send_trap_vars(-1, -1, pdu->variables); } return AGENTX_ERR_NOERROR; }
int header_hrswinst(struct variable *vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method) { #define HRSWINST_NAME_LENGTH 9 oid newname[MAX_OID_LEN]; int result; DEBUGMSGTL(("host/hr_swinst", "var_hrswinst: ")); DEBUGMSGOID(("host/hr_swinst", name, *length)); DEBUGMSG(("host/hr_swinst", " %d\n", exact)); memcpy((char *) newname, (char *) vp->name, vp->namelen * sizeof(oid)); newname[HRSWINST_NAME_LENGTH] = 0; result = snmp_oid_compare(name, *length, newname, vp->namelen + 1); if ((exact && (result != 0)) || (!exact && (result >= 0))) return (MATCH_FAILED); memcpy((char *) name, (char *) newname, (vp->namelen + 1) * sizeof(oid)); *length = vp->namelen + 1; *write_method = 0; *var_len = sizeof(long); /* default to 'long' results */ return (MATCH_SUCCEEDED); }
int header_system(struct variable *vp, oid *name, int *length, int exact, int *var_len, WriteMethod **write_method) { #define SYSTEM_NAME_LENGTH 8 oid newname[MAX_OID_LEN]; int result; char c_oid[SPRINT_MAX_LEN]; if (snmp_get_do_debugging()) { sprint_objid (c_oid, name, *length); DEBUGMSGTL(("mibII/system", "var_system: %s %d\n", c_oid, exact)); DEBUGMSGTL(("mibII/system", "vp len: %d / %d\n", vp->namelen, 8)); } memcpy((char *)newname, (char *)vp->name, (int)vp->namelen * sizeof(oid)); newname[SYSTEM_NAME_LENGTH] = 0; result = snmp_oid_compare(name, *length, newname, (int)vp->namelen + 1); if ((exact && (result != 0)) || (!exact && (result >= 0))) return(MATCH_FAILED); memcpy( (char *)name,(char *)newname, ((int)vp->namelen + 1) * sizeof(oid)); *length = vp->namelen + 1; *write_method = 0; *var_len = sizeof(long); /* default to 'long' results */ return(MATCH_SUCCEEDED); }
/* header_dummy(... Arguments: vp IN - pointer to variable entry that points here name IN/OUT - IN/name requested, OUT/name found length IN/OUT - length of input and output oid's exact IN - TRUE if an exact match was requested. var_len OUT - length of variable or 0 if function returned. write_method OUT - pointer to function to set variable, otherwise 0 */ int header_dummy(struct variable *vp, oid *name, int *length, int exact, int *var_len, WriteMethod **write_method) { #define DUMMY_NAME_LENGTH 8 oid newname[MAX_OID_LEN]; int result; /* just do trace and token print */ DEBUGMSGTL(("dummy/dummy:var_dummy", "")); DEBUGMSGOID(("dummy/dummy:var_dummy", name, *length)); DEBUGMSG(("dummy/dummy:var_dummy", " %d\n", exact)); memcpy(newname, vp->name, (int)vp->namelen * sizeof(oid)); newname[DUMMY_NAME_LENGTH] = 0; result = snmp_oid_compare(name, *length, newname, (int)vp->namelen + 1); if ((exact && (result != 0)) || (!exact && (result >= 0))) return(MATCH_FAILED); memcpy(name, newname, ((int)vp->namelen + 1) * sizeof(oid)); *length = vp->namelen + 1; *write_method = 0; *var_len = sizeof(long); /* default to 'long' results */ return(MATCH_SUCCEEDED); }
u_char * agentx_var(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { int result; AddVarMethod *add_method; DEBUGMSGTL(("agentx/master","request to pass to client: ")); DEBUGMSGOID(("agentx/master", name, *length)); DEBUGMSG(("agentx/master","\n")); /* * If the requested OID precedes the area of responsibility * of this subagent (and hence it's presumable a non-exact match), * then update the "matched" name to be the starting point */ /* XXX shouldn't we check exact in this case? */ result = snmp_oid_compare(name, *length, vp->name, vp->namelen); if ( result < 0 ) { memcpy((char *)name,(char *)vp->name, vp->namelen*sizeof(oid)); *length = vp->namelen; } /* Return a pointer to an appropriate method */ add_method = agentx_add_request; return (u_char*)add_method; }
struct header_complex_index * header_complex_maybe_add_data_by_oid(struct header_complex_index **thedata, oid * newoid, size_t newoid_len, void *data, int dont_allow_duplicates) { struct header_complex_index *hciptrn, *hciptrp; int rc; if (thedata == NULL || newoid == NULL || data == NULL) return NULL; for (hciptrn = *thedata, hciptrp = NULL; hciptrn != NULL; hciptrp = hciptrn, hciptrn = hciptrn->next) { /* * XXX: check for == and error (overlapping table entries) * 8/2005 rks Ok, I added duplicate entry check, but only log * warning and continue, because it seems that nobody * that calls this fucntion does error checking!. */ rc = snmp_oid_compare(hciptrn->name, hciptrn->namelen, newoid, newoid_len); if (rc > 0) break; else if (0 == rc) { snmp_log(LOG_WARNING, "header_complex_add_data_by_oid with " "duplicate index.\n"); if (dont_allow_duplicates) return NULL; } } return _header_complex_add_between(thedata, hciptrp, hciptrn, newoid, newoid_len, data); }
int header_hrdevice (struct variable *vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method) { #define HRDEV_ENTRY_NAME_LENGTH 11 oid newname[MAX_OID_LEN]; int dev_idx, LowIndex = -1, LowType = -1; int result; DEBUGMSGTL (("host/hr_device", "var_hrdevice: ")); DEBUGMSGOID (("host/hr_device", name, *length)); DEBUGMSG (("host/hr_device", " %d\n", exact)); memcpy ((char *) newname, (char *) vp->name, (int) vp->namelen * sizeof (oid)); /* * Find the "next" device entry. * If we're in the middle of the table, then there's * no point in examining earlier types of devices, * so set the starting type to that of the variable * being queried. * If we've moved from one column of the table to another, * then we need to start at the beginning again. * (i.e. the 'compare' fails to match) * Similarly if we're at the start of the table * (i.e. *length is too short to be a full instance) */ if ((snmp_oid_compare (vp->name, vp->namelen, name, vp->namelen) == 0) && (*length > HRDEV_ENTRY_NAME_LENGTH)) current_type = (name[HRDEV_ENTRY_NAME_LENGTH] >> HRDEV_TYPE_SHIFT); else
static int header_dlmod(struct variable *vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method) { #define DLMOD_NAME_LENGTH 10 oid newname[MAX_OID_LEN]; int result; memcpy((char *) newname, (char *) vp->name, (int) vp->namelen * sizeof(oid)); newname[DLMOD_NAME_LENGTH] = 0; result = snmp_oid_compare(name, *length, newname, (int) vp->namelen + 1); if ((exact && (result != 0)) || (!exact && (result >= 0))) { return MATCH_FAILED; } memcpy((char *) name, (char *) newname, ((int) vp->namelen + 1) * sizeof(oid)); *length = vp->namelen + 1; *write_method = 0; *var_len = sizeof(long); /* default to 'long' results */ return MATCH_SUCCEEDED; }
static int expValueTable_set(struct expExpressionTable_data *expression_data, const char *owner, size_t owner_len, const char *name, size_t name_len, oid *index, size_t index_len) { netsnmp_variable_list *vars = NULL; struct expValueTable_data *thedata; struct header_complex_index *hcindex; int found = 0; for (hcindex = expValueTableStorage; hcindex; hcindex = hcindex->next) { thedata = hcindex->data; if (strcmp(thedata->expExpressionOwner, owner) == 0 && thedata->expExpressionOwnerLen == owner_len && strcmp(thedata->expExpressionName, name) == 0 && thedata->expExpressionNameLen == name_len) { found = 1; break; } } if (found) { if (snmp_oid_compare(thedata->expValueInstance, thedata->expValueInstanceLen, index, index_len) != 0) { SNMP_FREE(thedata->expValueInstance); thedata->expValueInstance = netsnmp_memdup(index, index_len); thedata->expValueInstanceLen = index_len; } else { SNMP_FREE(index); } } else if ((thedata = calloc(1, sizeof(*thedata)))) { thedata->expExpressionOwner = owner; thedata->expExpressionOwnerLen = owner_len; thedata->expExpressionName = name; thedata->expExpressionNameLen = name_len; thedata->expValueInstance = index; thedata->expValueInstanceLen = index_len; thedata->expression_data = expression_data; snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (const char *) thedata->expExpressionOwner, thedata->expExpressionOwnerLen); snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (const char *) thedata->expExpressionName, thedata->expExpressionNameLen); snmp_varlist_add_variable(&vars, NULL, 0, ASN_PRIV_IMPLIED_OBJECT_ID, (u_char *) thedata->expValueInstance, thedata->expValueInstanceLen * sizeof(oid)); header_complex_add_data(&expValueTableStorage, vars, thedata); } else { return SNMPERR_GENERR; } thedata->set = 1; return SNMPERR_SUCCESS; }
struct vacm_viewEntry * vacm_getViewEntry(const char *viewName, oid * viewSubtree, size_t viewSubtreeLen, int mode) { struct vacm_viewEntry *vp, *vpret = NULL; char view[VACMSTRINGLEN]; int found, glen; int count=0; glen = (int) strlen(viewName); if (glen < 0 || glen >= VACM_MAX_STRING) return NULL; view[0] = glen; strcpy(view + 1, viewName); for (vp = viewList; vp; vp = vp->next) { if (!memcmp(view, vp->viewName, glen + 1) && viewSubtreeLen >= (vp->viewSubtreeLen - 1)) { int mask = 0x80, maskpos = 0; int oidpos; found = 1; if (mode != VACM_MODE_IGNORE_MASK) { /* check the mask */ for (oidpos = 0; found && oidpos < (int) vp->viewSubtreeLen - 1; oidpos++) { if ((vp->viewMask[maskpos] & mask) != 0) { if (viewSubtree[oidpos] != vp->viewSubtree[oidpos + 1]) found = 0; } if (mask == 1) { mask = 0x80; maskpos++; } else mask >>= 1; } } if (found) { /* * match successful, keep this node if its longer than * the previous or (equal and lexicographically greater * than the previous). */ count++; if (mode == VACM_MODE_CHECK_SUBTREE) { vpret = vp; } else if (vpret == NULL || vp->viewSubtreeLen > vpret->viewSubtreeLen || (vp->viewSubtreeLen == vpret->viewSubtreeLen && snmp_oid_compare(vp->viewSubtree + 1, vp->viewSubtreeLen - 1, vpret->viewSubtree + 1, vpret->viewSubtreeLen - 1) > 0)) { vpret = vp; } } } }
int header_hrdisk(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { #define HRDISK_ENTRY_NAME_LENGTH 11 oid newname[MAX_OID_LEN]; int disk_idx, LowIndex = -1; int result; DEBUGMSGTL(("host/hr_disk", "var_hrdisk: ")); DEBUGMSGOID(("host/hr_disk", name, *length)); DEBUGMSG(("host/hr_disk"," %d\n", exact)); memcpy( (char *)newname,(char *)vp->name, (int)vp->namelen * sizeof(oid)); /* Find "next" disk entry */ Init_HR_Disk(); for ( ;; ) { disk_idx = Get_Next_HR_Disk(); if ( disk_idx == -1 ) break; newname[HRDISK_ENTRY_NAME_LENGTH] = disk_idx; result = snmp_oid_compare(name, *length, newname, (int)vp->namelen + 1); if (exact && (result == 0)) { LowIndex = disk_idx; Save_HR_Disk_Specific(); break; } if ((!exact && (result < 0)) && ( LowIndex == -1 || disk_idx < LowIndex )) { LowIndex = disk_idx; Save_HR_Disk_Specific(); #ifdef HRD_MONOTONICALLY_INCREASING break; #endif } } if ( LowIndex == -1 ) { DEBUGMSGTL(("host/hr_disk", "... index out of range\n")); return(MATCH_FAILED); } newname[HRDISK_ENTRY_NAME_LENGTH] = LowIndex; memcpy( (char *)name,(char *)newname, ((int)vp->namelen + 1) * sizeof(oid)); *length = vp->namelen + 1; *write_method = 0; *var_len = sizeof(long); /* default to 'long' results */ DEBUGMSGTL(("host/hr_disk", "... get disk stats ")); DEBUGMSGOID(("host/hr_disk", name, *length)); DEBUGMSG(("host/hr_disk","\n")); return LowIndex; }
/** compare a row with the given index OID */ int netsnmp_tdata_compare_oid(netsnmp_tdata_row *row, oid * compareto, size_t compareto_len) { netsnmp_index *index = (netsnmp_index *)row; return snmp_oid_compare( index->oids, index->len, compareto, compareto_len); }
int header_hrnet(struct variable *vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method) { #define HRNET_ENTRY_NAME_LENGTH 11 oid newname[MAX_OID_LEN]; int net_idx; int result; int LowIndex = -1; DEBUGMSGTL(("host/hr_network", "var_hrnet: ")); DEBUGMSGOID(("host/hr_network", name, *length)); DEBUGMSG(("host/hr_network", " %d\n", exact)); memcpy((char *) newname, (char *) vp->name, vp->namelen * sizeof(oid)); /* * Find "next" net entry */ Init_HR_Network(); for (;;) { net_idx = Get_Next_HR_Network(); if (net_idx == -1) break; newname[HRNET_ENTRY_NAME_LENGTH] = net_idx; result = snmp_oid_compare(name, *length, newname, vp->namelen + 1); if (exact && (result == 0)) { LowIndex = net_idx; break; } if (!exact && (result < 0) && (LowIndex == -1 || net_idx < LowIndex)) { LowIndex = net_idx; #ifdef HRN_MONOTONICALLY_INCREASING break; #endif } } if (LowIndex == -1) { DEBUGMSGTL(("host/hr_network", "... index out of range\n")); return (MATCH_FAILED); } newname[HRNET_ENTRY_NAME_LENGTH] = LowIndex; memcpy((char *) name, (char *) newname, (vp->namelen + 1) * sizeof(oid)); *length = vp->namelen + 1; *write_method = 0; *var_len = sizeof(long); /* default to 'long' results */ DEBUGMSGTL(("host/hr_network", "... get net stats ")); DEBUGMSGOID(("host/hr_network", name, *length)); DEBUGMSG(("host/hr_network", "\n")); return LowIndex; }
int header_hrfilesys(struct variable *vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method) { #define HRFSYS_ENTRY_NAME_LENGTH 11 oid newname[MAX_OID_LEN]; int fsys_idx, LowIndex = -1; int result; DEBUGMSGTL(("host/hr_filesys", "var_hrfilesys: ")); DEBUGMSGOID(("host/hr_filesys", name, *length)); DEBUGMSG(("host/hr_filesys", " %d\n", exact)); memcpy((char *) newname, (char *) vp->name, vp->namelen * sizeof(oid)); /* * Find "next" file system entry */ Init_HR_FileSys(); for (;;) { fsys_idx = Get_Next_HR_FileSys(); if (fsys_idx == -1) break; newname[HRFSYS_ENTRY_NAME_LENGTH] = fsys_idx; result = snmp_oid_compare(name, *length, newname, vp->namelen + 1); if (exact && (result == 0)) { LowIndex = fsys_idx; break; } if ((!exact && (result < 0)) && (LowIndex == -1 || fsys_idx < LowIndex)) { LowIndex = fsys_idx; #ifdef HRFS_MONOTONICALLY_INCREASING break; #endif } } if (LowIndex == -1) { DEBUGMSGTL(("host/hr_filesys", "... index out of range\n")); return (MATCH_FAILED); } memcpy((char *) name, (char *) newname, (vp->namelen + 1) * sizeof(oid)); *length = vp->namelen + 1; *write_method = (WriteMethod*)0; *var_len = sizeof(long); /* default to 'long' results */ DEBUGMSGTL(("host/hr_filesys", "... get filesys stats ")); DEBUGMSGOID(("host/hr_filesys", name, *length)); DEBUGMSG(("host/hr_filesys", "\n")); return LowIndex; }
int pass_persist_compare(const void *a, const void *b) { const struct extensible *const *ap, *const *bp; ap = (const struct extensible * const *) a; bp = (const struct extensible * const *) b; return snmp_oid_compare((*ap)->miboid, (*ap)->miblen, (*bp)->miboid, (*bp)->miblen); }
static struct tunnel * getNextTunnelByConfigOid(oid * name, size_t * length) { struct tunnel *tunnel, *last_tunnel; oid tname[10], last_tname[10]; DEBUGMSG(("tunnel", "getNextTunnelByConfigOid(")); DEBUGMSGOID(("tunnel", name, *length)); DEBUGMSG(("tunnel", "): ")); last_tunnel = NULL; for (tunnel = tunnels; tunnel; tunnel = tunnel->next) { if (!tunnel->active) continue; fillConfigOid(tname, tunnel); if (snmp_oid_compare(tname, 10, &name[tunnel_len + 3], (*length) - tunnel_len - 3) > 0) { if (!last_tunnel) { last_tunnel = tunnel; memcpy((char *) last_tname, (char *) tname, 10 * sizeof(oid)); } else { if (snmp_oid_compare(tname, 10, last_tname, 10) < 0) { last_tunnel = tunnel; memcpy((char *) last_tname, (char *) tname, 10 * sizeof(oid)); } } } } if (last_tunnel) { DEBUGMSG(("tunnel", "%s (index=%" NETSNMP_PRIo "u)\n", last_tunnel->ifname, last_tunnel->ifindex)); } else { DEBUGMSG(("tunnel", "NONE\n")); } return last_tunnel; }
struct subtree *find_subtree(oid *name, size_t len, struct subtree *subtree) { struct subtree *myptr; myptr = find_subtree_previous(name, len, subtree); if (myptr && snmp_oid_compare(name, len, myptr->end, myptr->end_len) < 0) return myptr; return NULL; }
struct subtree * free_subtree(struct subtree *st) { struct subtree *ret = NULL; if ((snmp_oid_compare(st->name, st->namelen, st->start, st->start_len) == 0) && (st->variables != NULL)) free(st->variables); if (st->next != NULL) ret = st->next; free(st); return ret; }
netsnmp_variable_list * collect(netsnmp_session * ss, netsnmp_pdu *pdu, oid * base, size_t base_length) { netsnmp_pdu *response; int running = 1; netsnmp_variable_list *saved = NULL, **vlpp = &saved; int status; while (running) { /* * gotta catch em all, gotta catch em all! */ status = snmp_synch_response(ss, pdu, &response); if (status != STAT_SUCCESS || !response) { snmp_sess_perror("snmpdf", ss); exit(1); } if (response->errstat != SNMP_ERR_NOERROR) { fprintf(stderr, "snmpdf: Error in packet: %s\n", snmp_errstring(response->errstat)); exit(1); } if (response && snmp_oid_compare(response->variables->name, SNMP_MIN(base_length, response->variables-> name_length), base, base_length) != 0) running = 0; else { /* * get response */ *vlpp = response->variables; (*vlpp)->next_variable = NULL; /* shouldn't be any, but just in case */ /* * create the next request */ pdu = snmp_pdu_create(SNMP_MSG_GETNEXT); snmp_add_null_var(pdu, (*vlpp)->name, (*vlpp)->name_length); /* * finish loop setup */ vlpp = &((*vlpp)->next_variable); response->variables = NULL; /* ahh, forget about it */ } snmp_free_pdu(response); } return saved; }
int my_test_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { oid myoid1[] = { 1, 2, 3, 4, 5, 6 }; static u_long accesses = 0; DEBUGMSGTL(("testhandler", "Got request:\n")); /* * loop through requests */ while (requests) { netsnmp_variable_list *var = requests->requestvb; DEBUGMSGTL(("testhandler", " oid:")); DEBUGMSGOID(("testhandler", var->name, var->name_length)); DEBUGMSG(("testhandler", "\n")); switch (reqinfo->mode) { case MODE_GET: if (netsnmp_oid_equals(var->name, var->name_length, myoid1, 6) == 0) { snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *) & accesses, sizeof(accesses)); return SNMP_ERR_NOERROR; } break; case MODE_GETNEXT: if (snmp_oid_compare(var->name, var->name_length, myoid1, 6) < 0) { snmp_set_var_objid(var, myoid1, 6); snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *) & accesses, sizeof(accesses)); return SNMP_ERR_NOERROR; } break; default: netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_GENERR); break; } requests = requests->next; } return SNMP_ERR_NOERROR; }
netsnmp_variable_list* find_varbind_in_list( netsnmp_variable_list *vblist, oid *name, size_t len) { netsnmp_variable_list *v; for (v=vblist; v; v=v->next_variable) if (!snmp_oid_compare(v->name, v->name_length, name, len)) return v; return NULL; }
int agentx_notify(netsnmp_session * session, netsnmp_pdu *pdu) { netsnmp_session *sp; netsnmp_variable_list *var; int got_sysuptime = 0; extern oid sysuptime_oid[], snmptrap_oid[]; extern size_t sysuptime_oid_len, snmptrap_oid_len; sp = find_agentx_session(session, pdu->sessid); if (sp == NULL) return AGENTX_ERR_NOT_OPEN; var = pdu->variables; if (!var) return AGENTX_ERR_PROCESSING_ERROR; if (snmp_oid_compare(var->name, var->name_length, sysuptime_oid, sysuptime_oid_len) == 0) { got_sysuptime = 1; var = var->next_variable; } if (!var || snmp_oid_compare(var->name, var->name_length, snmptrap_oid, snmptrap_oid_len) != 0) return AGENTX_ERR_PROCESSING_ERROR; /* * If sysUptime isn't the first varbind, don't worry. * send_trap_vars() will add it if necessary. * * Note that if this behaviour is altered, it will * be necessary to add sysUptime here, * as this is valid AgentX syntax. */ send_trap_vars(-1, -1, pdu->variables); return AGENTX_ERR_NOERROR; }
int stat_Copy(RMON_ENTRY_T * eptr) { CRTL_ENTRY_T *body = (CRTL_ENTRY_T *) eptr->body; CRTL_ENTRY_T *clone = (CRTL_ENTRY_T *) eptr->tmp; if (snmp_oid_compare (clone->data_source.objid, clone->data_source.length, body->data_source.objid, body->data_source.length)) { memcpy(&body->data_source, &clone->data_source, sizeof(VAR_OID_T)); } return 0; }
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 ); }
/** finds the data in "datalist" stored at the searchfor oid */ netsnmp_table_row * netsnmp_table_data_get_from_oid(netsnmp_table_data *table, oid * searchfor, size_t searchfor_len) { netsnmp_table_row *row; if (!table) return NULL; for (row = table->first_row; row != NULL; row = row->next) { if (row->index_oid && snmp_oid_compare(searchfor, searchfor_len, row->index_oid, row->index_oid_len) == 0) return row; } return NULL; }
netsnmp_table_row * netsnmp_table_data_row_next_byoid(netsnmp_table_data *table, oid *instance, size_t len) { netsnmp_table_row *row; if (!table || !instance) return NULL; for (row = table->first_row; row; row = row->next) { if (snmp_oid_compare(row->index_oid, row->index_oid_len, instance, len) > 0) return row; } return NULL; }
struct subtree *find_subtree_previous(oid *name, size_t len, struct subtree *subtree) { struct subtree *myptr, *previous = NULL; if ( subtree ) myptr = subtree; else myptr = subtrees; /* look through everything */ for( ; myptr != NULL; previous = myptr, myptr = myptr->next) { if (snmp_oid_compare(name, len, myptr->start, myptr->start_len) < 0) return previous; } return previous; }
static struct dlmod * header_dlmodEntry(struct variable *vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method) { #define DLMODENTRY_NAME_LENGTH 12 oid newname[MAX_OID_LEN]; int result; struct dlmod *dlm = NULL; unsigned int dlmod_index; memcpy((char *) newname, (char *) vp->name, (int) vp->namelen * sizeof(oid)); *write_method = 0; for (dlmod_index = 1; dlmod_index < dlmod_next_index; dlmod_index++) { dlm = dlmod_get_by_index(dlmod_index); DEBUGMSGTL(("dlmod", "dlmodEntry dlm: %p dlmod_index: %d\n", dlm, dlmod_index)); if (dlm) { newname[12] = dlmod_index; result = snmp_oid_compare(name, *length, newname, (int) vp->namelen + 1); if ((exact && (result == 0)) || (!exact && (result < 0))) break; } } if (dlmod_index >= dlmod_next_index) { if (dlmod_index == dlmod_next_index && exact && vp->magic == DLMODSTATUS) *write_method = write_dlmodStatus; return NULL; } memcpy((char *) name, (char *) newname, ((int) vp->namelen + 1) * sizeof(oid)); *length = vp->namelen + 1; *var_len = sizeof(long); return dlm; }
struct subtree *find_subtree_next(oid *name, size_t len, struct subtree *subtree) { struct subtree *myptr = NULL; myptr = find_subtree_previous(name, len, subtree); if ( myptr != NULL ) { myptr = myptr->next; while ( myptr && (myptr->variables == NULL || myptr->variables_len == 0) ) myptr = myptr->next; return myptr; } else if (subtree && snmp_oid_compare(name, len, subtree->start, subtree->start_len) < 0) return subtree; else return NULL; }