Ejemplo n.º 1
0
/**
 * @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 */
Ejemplo n.º 2
0
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;
}
/**
 * the *_extract_index routine
 *
 * This routine is called when a set request is received for an index
 * that was not found in the table container. Here, we parse the oid
 * in the the individual index components and copy those indexes to the
 * context. Then we make sure the indexes for the new row are valid.
 */
int
saHpiAutoInsertTimeoutTable_extract_index( saHpiAutoInsertTimeoutTable_context * ctx, netsnmp_index * hdr )
{
        /*
         * temporary local storage for extracting oid index
         *
         * extract index uses varbinds (netsnmp_variable_list) to parse
         * the index OID into the individual components for each index part.
         */
        /** TODO: add storage for external index(s)! */
        netsnmp_variable_list var_saHpiDomainId;
        int err;

        /*
        * copy index, if provided
        */
        if(hdr) {
                netsnmp_assert(ctx->index.oids == NULL);
                if(snmp_clone_mem( (void*)&ctx->index.oids, hdr->oids,
                                  hdr->len * sizeof(oid) )) {
                        return -1;
                }
                ctx->index.len = hdr->len;
        }

        /*
         * initialize variable that will hold each component of the index.
         * If there are multiple indexes for the table, the variable_lists
         * need to be linked together, in order.
         */
        /** TODO: add code for external index(s)! */
        memset( &var_saHpiDomainId, 0x00, sizeof(var_saHpiDomainId) );
        var_saHpiDomainId.type = ASN_UNSIGNED; /* type hint for parse_oid_indexes */
        /** TODO: link this index to the next, or NULL for the last one */
        var_saHpiDomainId.next_variable = NULL;

        /*
         * parse the oid into the individual index components
         */
        err = parse_oid_indexes( hdr->oids, hdr->len, &var_saHpiDomainId );
        if (err == SNMP_ERR_NOERROR) {
                /*
                 * copy index components into the context structure
                 */
                /** skipping external index saHpiDomainId */

                /** skipping external index saHpiResourceId */

                /** skipping external index saHpiResourceIsHistorical */

                err = saHpiDomainId_check_index(*var_saHpiDomainId.val.integer);
        }

        /*
         * parsing may have allocated memory. free it.
         */
        snmp_reset_var_buffers( &var_saHpiDomainId );

        return err;
}
/*
 * the *_extract_index routine. (Mostly auto-generated)
 *
 * This routine is called when a set request is received for an index
 * that was not found in the table container. Here, we parse the oid
 * in the individual index components and copy those indexes to the
 * context. Then we make sure the indexes for the new row are valid.
 *
 * It has been modified from its original form in that if the indexes are
 * invalid, then they aren't returned.  An index is invalid if:
 *
 *   1) It is < 1
 *   2) It doesn't match the global userLookupIndex. (As per MIB specs)
 *
 */
int openserSIPRegUserLookupTable_extract_index(
		openserSIPRegUserLookupTable_context * ctx,
		netsnmp_index * hdr)
{
	/*
	 * temporary local storage for extracting oid index
	 *
	 * extract index uses varbinds (netsnmp_variable_list) to parse
	 * the index OID into the individual components for each index part.
	 */
	netsnmp_variable_list var_openserSIPRegUserLookupIndex;
	int err;

	/* copy index, if provided */
	if(hdr) {
		netsnmp_assert(ctx->index.oids == NULL);
		if((hdr->len > MAX_OID_LEN) ||
		   snmp_clone_mem( (void*)&ctx->index.oids, hdr->oids,
						   hdr->len * sizeof(oid) )) {
			return -1;
		}
		ctx->index.len = hdr->len;
	}

	/* Set up the index */
	memset(&var_openserSIPRegUserLookupIndex, 0x00,
			sizeof(var_openserSIPRegUserLookupIndex));

	var_openserSIPRegUserLookupIndex.type = ASN_UNSIGNED;
	var_openserSIPRegUserLookupIndex.next_variable = NULL;


	/* parse the oid into the individual index components */
	err = parse_oid_indexes( hdr->oids, hdr->len,
			&var_openserSIPRegUserLookupIndex );

	if (err == SNMP_ERR_NOERROR) {

		/* copy index components into the context structure */
		ctx->openserSIPRegUserLookupIndex =
			*var_openserSIPRegUserLookupIndex.val.integer;

		/*
		 * Check to make sure that the index corresponds to the
		 * global_userLookupCounter, as per the MIB specifications.
		 */
		if (*var_openserSIPRegUserLookupIndex.val.integer !=
				global_UserLookupCounter ||
		    *var_openserSIPRegUserLookupIndex.val.integer < 1) {
			err = -1;
		}

	}

	/* parsing may have allocated memory. free it. */
	snmp_reset_var_buffers( &var_openserSIPRegUserLookupIndex );

	return err;
}
Ejemplo n.º 5
0
/*
 * the *_extract_index routine
 */
int
saHpiSensorTable_extract_index (saHpiSensorTable_context * ctx,
				netsnmp_index * hdr)
{
  /*
   * temporary local storage for extracting oid index
   */
  netsnmp_variable_list var_saHpiDomainID;
  netsnmp_variable_list var_saHpiResourceID;

  netsnmp_variable_list var_saHpiSensorIndex;
  int err;

  /*
   * copy index, if provided
   */
  if (hdr)
    {
      netsnmp_assert (ctx->index.oids == NULL);
      if (snmp_clone_mem ((void *) &ctx->index.oids, hdr->oids,
			  hdr->len * sizeof (oid)))
	{
	  return -1;
	}
      ctx->index.len = hdr->len;
    }

    /**
     * Create variable to hold each component of the index
     */
  memset (&var_saHpiDomainID, 0x00, sizeof (var_saHpiDomainID));
  var_saHpiDomainID.type = ASN_UNSIGNED;
  var_saHpiDomainID.next_variable = &var_saHpiResourceID;

  memset (&var_saHpiResourceID, 0x00, sizeof (var_saHpiResourceID));
  var_saHpiResourceID.type = ASN_UNSIGNED;
  var_saHpiResourceID.next_variable = &var_saHpiSensorIndex;

  memset (&var_saHpiSensorIndex, 0x00, sizeof (var_saHpiSensorIndex));
  var_saHpiSensorIndex.type = ASN_UNSIGNED;
  var_saHpiSensorIndex.next_variable = NULL;

  /*
   * parse the oid into the individual components
   */
  err = parse_oid_indexes (hdr->oids, hdr->len, &var_saHpiDomainID);
  if (err == SNMP_ERR_NOERROR)
    {
      ctx->saHpiSensorIndex = *var_saHpiSensorIndex.val.integer;
    }

  /*
   * parsing may have allocated memory. free it.
   */
  snmp_reset_var_buffers (&var_saHpiDomainID);

  return err;
}
/**
 * extract dot11WtpDataPktsTable indexes from a netsnmp_index
 *
 * @retval SNMP_ERR_NOERROR  : no error
 * @retval SNMP_ERR_GENERR   : error
 */
int
dot11WtpDataPktsTable_index_from_oid(netsnmp_index *oid_idx,
                         dot11WtpDataPktsTable_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;

    /*
     * set up varbinds
     */
    memset( &var_wtpMacAddr, 0x00, sizeof(var_wtpMacAddr) );
    var_wtpMacAddr.type = ASN_OCTET_STR;

    /*
     * chain temp index varbinds together
     */
    var_wtpMacAddr.next_variable =  NULL;


    DEBUGMSGTL(("verbose:dot11WtpDataPktsTable:dot11WtpDataPktsTable_index_from_oid","called\n"));

    /*
     * parse the oid into the individual index components
     */
    err = parse_oid_indexes( oid_idx->oids, oid_idx->len,
                             &var_wtpMacAddr );
    if (err == SNMP_ERR_NOERROR) {
        /*
         * copy out values
         */
    /*
     * NOTE: val_len is in bytes, wtpMacAddr_len might not be
     */
         if(var_wtpMacAddr.val_len > sizeof(mib_idx->wtpMacAddr))
             err = SNMP_ERR_GENERR;
         else {
             memcpy(mib_idx->wtpMacAddr, var_wtpMacAddr.val.string, var_wtpMacAddr.val_len);
             mib_idx->wtpMacAddr_len = var_wtpMacAddr.val_len / sizeof(mib_idx->wtpMacAddr[0]);
         }


    }

    /*
     * parsing may have allocated memory. free it.
     */
    snmp_reset_var_buffers( &var_wtpMacAddr );

    return err;
} /* dot11WtpDataPktsTable_index_from_oid */
Ejemplo n.º 7
0
/**
 * @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 */
Ejemplo n.º 8
0
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;

}
/**
 * extract ipv6ScopeZoneIndexTable indexes from a netsnmp_index
 *
 * @retval SNMP_ERR_NOERROR  : no error
 * @retval SNMP_ERR_GENERR   : error
 */
int
ipv6ScopeZoneIndexTable_index_from_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_from_oid", "called\n"));

    /*
     * parse the oid into the individual index components
     */
    err = parse_oid_indexes(oid_idx->oids, oid_idx->len,
                            &var_ipv6ScopeZoneIndexIfIndex);
    if (err == SNMP_ERR_NOERROR) {
        /*
         * copy out values
         */
        mib_idx->ipv6ScopeZoneIndexIfIndex =
            *((long *) var_ipv6ScopeZoneIndexIfIndex.val.string);


    }

    /*
     * parsing may have allocated memory. free it.
     */
    snmp_reset_var_buffers(&var_ipv6ScopeZoneIndexIfIndex);

    return err;
}                               /* ipv6ScopeZoneIndexTable_index_from_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 */
/**
 * @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 */
/**
 * extract dot11SsidTeminalTable indexes from a netsnmp_index
 *
 * @retval SNMP_ERR_NOERROR  : no error
 * @retval SNMP_ERR_GENERR   : error
 */
int
dot11SsidTeminalTable_index_from_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_from_oid","called\n"));

    /*
     * parse the oid into the individual index components
     */
    err = parse_oid_indexes( oid_idx->oids, oid_idx->len,
                             &var_wlanCurrID );
    if (err == SNMP_ERR_NOERROR) {
        /*
         * copy out values
         */
    mib_idx->wlanCurrID = *((long *)var_wlanCurrID.val.string);


    }

    /*
     * parsing may have allocated memory. free it.
     */
    snmp_reset_var_buffers( &var_wlanCurrID );

    return err;
} /* dot11SsidTeminalTable_index_from_oid */
/************************************************************
 *
 *  Convert table index components to an oid.
 */
int ituAlarmTable_index_to_oid(char* name,
                               unsigned long index,
                               long severity,
                               netsnmp_index *oid_idx)
{
  int err = SNMP_ERR_NOERROR;

  netsnmp_variable_list var_alarmListName;
  netsnmp_variable_list var_alarmModelIndex;
  netsnmp_variable_list var_alarmModelSeverity;

  /*
   * set up varbinds
   */
  memset(&var_alarmListName, 0x00, sizeof(var_alarmListName));
  var_alarmListName.type = ASN_OCTET_STR;
  memset(&var_alarmModelIndex, 0x00, sizeof(var_alarmModelIndex));
  var_alarmModelIndex.type = ASN_UNSIGNED;
  memset(&var_alarmModelSeverity, 0x00, sizeof(var_alarmModelSeverity));
  var_alarmModelSeverity.type = ASN_INTEGER;

  /*
   * chain index varbinds together
   */
  var_alarmListName.next_variable = &var_alarmModelIndex;
  var_alarmModelIndex.next_variable = &var_alarmModelSeverity;
  var_alarmModelSeverity.next_variable =  NULL;


  DEBUGMSGTL(("verbose:ituAlarmTable:ituAlarmTable_index_to_oid", "called\n"));

  snmp_set_var_value(&var_alarmListName, (u_char*) name, strlen(name));
  snmp_set_var_value(&var_alarmModelIndex, (u_char*) &index, sizeof(index));
  snmp_set_var_value(&var_alarmModelSeverity, (u_char*) &severity, sizeof(severity));

  err = build_oid(&oid_idx->oids, &oid_idx->len, NULL, 0, &var_alarmListName);
  if (err)
  {
    snmp_log(LOG_ERR, "error %d converting index to oid: ituAlarmTable_index_to_oid", err);
  }

  /*
   * parsing may have allocated memory. free it.
   */
  snmp_reset_var_buffers(&var_alarmListName);

  return err;
} 
/**
 * @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 */
/************************************************************
 *
 *  Convert table index components to an oid.
 */
int alarmModelTable_index_to_oid(char* name,
                                 unsigned long index,
                                 unsigned long state,
                                 netsnmp_index *oid_idx)
{
  int err = SNMP_ERR_NOERROR;

  netsnmp_variable_list var_alarmListName;
  netsnmp_variable_list var_alarmModelIndex;
  netsnmp_variable_list var_alarmModelState;

  /*
   * set up varbinds
   */
  memset(&var_alarmListName, 0x00, sizeof(var_alarmListName));
  var_alarmListName.type = ASN_OCTET_STR;
  memset(&var_alarmModelIndex, 0x00, sizeof(var_alarmModelIndex));
  var_alarmModelIndex.type = ASN_UNSIGNED;
  memset(&var_alarmModelState, 0x00, sizeof(var_alarmModelState));
  var_alarmModelState.type = ASN_UNSIGNED;

  /*
   * chain index varbinds together
   */
  var_alarmListName.next_variable = &var_alarmModelIndex;
  var_alarmModelIndex.next_variable = &var_alarmModelState;
  var_alarmModelState.next_variable =  NULL;


  DEBUGMSGTL(("verbose:alarmModelTable:alarmModelTable_index_to_oid", "called\n"));

  snmp_set_var_value(&var_alarmListName, (u_char*) name, strlen(name));
  snmp_set_var_value(&var_alarmModelIndex, (u_char*) &index, sizeof(index));
  snmp_set_var_value(&var_alarmModelState, (u_char*) &state, sizeof(state));

  err = build_oid(&oid_idx->oids, &oid_idx->len, NULL, 0, &var_alarmListName);
  if (err)
  {
    TRC_ERROR("error %d converting index to oid: alarmModelTable_index_to_oid", err); // LCOV_EXCL_LINE
  }

  /*
   * parsing may have allocated memory. free it.
   */
  snmp_reset_var_buffers(&var_alarmListName);

  return err;
} 
void AlarmTrapSender::send_trap(AlarmTableDef& alarm_table_def)
{
  static const oid snmp_trap_oid[] = {1,3,6,1,6,3,1,1,4,1,0};
  static const oid clear_oid[] = {1,3,6,1,2,1,118,0,3};
  static const oid active_oid[] = {1,3,6,1,2,1,118,0,2};

  static const oid model_ptr_oid[] = {1,3,6,1,2,1,118,1,2,2,1,13,0};
  static const oid model_row_oid[] = {1,3,6,1,2,1,118,1,1,2,1,3,0,1,2};

  static const oid resource_id_oid[] = {1,3,6,1,2,1,118,1,2,2,1,10,0};
  static const oid zero_dot_zero[] = {0,0};

  netsnmp_variable_list var_trap;
  netsnmp_variable_list var_model_row;
  netsnmp_variable_list var_resource_id;

  memset(&var_trap, 0x00, sizeof(var_trap));
  memset(&var_model_row, 0x00, sizeof(var_model_row));
  memset(&var_resource_id, 0x00, sizeof(var_resource_id));

  var_trap.next_variable = &var_model_row;
  var_model_row.next_variable = &var_resource_id;
  var_resource_id.next_variable = NULL;

  snmp_set_var_objid(&var_trap, snmp_trap_oid, OID_LENGTH(snmp_trap_oid));
  if (alarm_table_def.severity() == AlarmDef::CLEARED)
  {
    snmp_set_var_typed_value(&var_trap, ASN_OBJECT_ID, (u_char*) clear_oid, sizeof(clear_oid));
  }
  else
  {
    snmp_set_var_typed_value(&var_trap, ASN_OBJECT_ID, (u_char*) active_oid, sizeof(active_oid));
  }

  snmp_set_var_objid(&var_model_row, model_ptr_oid, OID_LENGTH(model_ptr_oid));
  snmp_set_var_typed_value(&var_model_row, ASN_OBJECT_ID, (u_char*) model_row_oid, sizeof(model_row_oid));

  var_model_row.val.objid[ALARMMODELTABLEROW_INDEX] = alarm_table_def.index();
  var_model_row.val.objid[ALARMMODELTABLEROW_STATE] = alarm_table_def.state();

  snmp_set_var_objid(&var_resource_id, resource_id_oid, OID_LENGTH(resource_id_oid));
  snmp_set_var_typed_value(&var_resource_id, ASN_OBJECT_ID, (u_char*) zero_dot_zero, sizeof(zero_dot_zero));

  send_v2trap(&var_trap);

  snmp_reset_var_buffers(&var_trap);
}
Ejemplo n.º 17
0
/**
 * the *_extract_index routine
 *
 * This routine is called when a set request is received for an index
 * that was not found in the table container. Here, we parse the oid
 * in the the individual index components and copy those indexes to the
 * context. Then we make sure the indexes for the new row are valid.
 */
int
saHpiEventTable_extract_index( saHpiEventTable_context * ctx, netsnmp_index * hdr )
{
    /*
     * temporary local storage for extracting oid index
     *
     * extract index uses varbinds (netsnmp_variable_list) to parse
     * the index OID into the individual components for each index part.
     */
    /** TODO: add storage for external index(s)! */
    netsnmp_variable_list var_saHpiEventRowPointer;
    int err;

    /*
     * copy index, if provided
     */
    if(hdr) {
        netsnmp_assert(ctx->index.oids == NULL);
        if(snmp_clone_mem( (void*)&ctx->index.oids, hdr->oids,
                           hdr->len * sizeof(oid) )) {
            return -1;
        }
        ctx->index.len = hdr->len;
    }

    /*
     * initialize variable that will hold each component of the index.
     * If there are multiple indexes for the table, the variable_lists
     * need to be linked together, in order.
     */
       /** TODO: add code for external index(s)! */
       memset( &var_saHpiEventRowPointer, 0x00, sizeof(var_saHpiEventRowPointer) );
       var_saHpiEventRowPointer.type = ASN_OBJECT_ID; /* type hint for parse_oid_indexes */
       /** TODO: link this index to the next, or NULL for the last one */
       var_saHpiEventRowPointer.next_variable = NULL;

       memcpy(ctx->saHpiEventRowPointer, hdr->oids, hdr->len * sizeof(oid));
       ctx->saHpiEventRowPointer_len = hdr->len;
       err = SNMP_ERR_NOERROR;
    
    /*
     * parsing may have allocated memory. free it.
     */
    snmp_reset_var_buffers( &var_saHpiEventRowPointer );

    return err;
}
/**
 * @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 */
Ejemplo n.º 20
0
/**
 * extract pgsqlPgAmTable indexes from a netsnmp_index
 *
 * @retval SNMP_ERR_NOERROR  : no error
 * @retval SNMP_ERR_GENERR   : error
 */
int
pgsqlPgAmTable_index_from_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_from_oid","called\n"));

    /*
     * parse the oid into the individual index components
     */
    err = parse_oid_indexes( oid_idx->oids, oid_idx->len,
                             &var_pgsnmpdConnID );
    if (err == SNMP_ERR_NOERROR) {
        /*
         * copy out values
         */
    /*
     * NOTE: val_len is in bytes, pgsnmpdConnID_len might not be
     */
         if(var_pgsnmpdConnID.val_len > sizeof(mib_idx->pgsnmpdConnID))
             err = SNMP_ERR_GENERR;
         else {
             memcpy(mib_idx->pgsnmpdConnID, var_pgsnmpdConnID.val.string, var_pgsnmpdConnID.val_len);
             mib_idx->pgsnmpdConnID_len = var_pgsnmpdConnID.val_len / sizeof(mib_idx->pgsnmpdConnID[0]);
         }
    mib_idx->rdbmsDbIndex = *((long *)var_rdbmsDbIndex.val.string);
    mib_idx->pgsqlPgAmEntryOID = *((long *)var_pgsqlPgAmEntryOID.val.string);


    }

    /*
     * parsing may have allocated memory. free it.
     */
    snmp_reset_var_buffers( &var_pgsnmpdConnID );

    return err;
} /* pgsqlPgAmTable_index_from_oid */
/**
 * @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 */
/**
 * extract ipDefaultRouterTable indexes from a netsnmp_index
 *
 * @retval SNMP_ERR_NOERROR  : no error
 * @retval SNMP_ERR_GENERR   : error
 */
int
ipDefaultRouterTable_index_from_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_from_oid", "called\n"));

    /*
     * parse the oid into the individual index components
     */
    err = parse_oid_indexes(oid_idx->oids, oid_idx->len,
                            &var_ipDefaultRouterAddressType);
    if (err == SNMP_ERR_NOERROR) {
        /*
         * copy out values
         */
        mib_idx->ipDefaultRouterAddressType =
            *((u_long *) var_ipDefaultRouterAddressType.val.string);
        /*
         * NOTE: val_len is in bytes, ipDefaultRouterAddress_len might not be
         */
        if (var_ipDefaultRouterAddress.val_len >
            sizeof(mib_idx->ipDefaultRouterAddress))
            err = SNMP_ERR_GENERR;
        else {
            memcpy(mib_idx->ipDefaultRouterAddress,
                   var_ipDefaultRouterAddress.val.string,
                   var_ipDefaultRouterAddress.val_len);
            mib_idx->ipDefaultRouterAddress_len =
                var_ipDefaultRouterAddress.val_len /
                sizeof(mib_idx->ipDefaultRouterAddress[0]);
        }
        mib_idx->ipDefaultRouterIfIndex =
            *((long *) var_ipDefaultRouterIfIndex.val.string);


    }

    /*
     * parsing may have allocated memory. free it.
     */
    snmp_reset_var_buffers(&var_ipDefaultRouterAddressType);

    return err;
}                               /* ipDefaultRouterTable_index_from_oid */
Ejemplo n.º 23
0
/**
 * the *_extract_index routine
 *
 * This routine is called when a set request is received for an index
 * that was not found in the table container. Here, we parse the oid
 * in the the individual index components and copy those indexes to the
 * context. Then we make sure the indexes for the new row are valid.
 */
int
saHpiHotSwapTable_extract_index( saHpiHotSwapTable_context * ctx, netsnmp_index * hdr )
{
    /*
     * temporary local storage for extracting oid index
     *
     * extract index uses varbinds (netsnmp_variable_list) to parse
     * the index OID into the individual components for each index part.
     */
    /** TODO: add storage for external index(s)! */
    netsnmp_variable_list var_saHpiDomainId;
    netsnmp_variable_list var_saHpiResourceId;
    netsnmp_variable_list var_saHpiResourceIsHistorical;
    int err;

    /*
     * copy index, if provided
     */
    if(hdr) {
        netsnmp_assert(ctx->index.oids == NULL);
        if(snmp_clone_mem( (void*)&ctx->index.oids, hdr->oids,
                           hdr->len * sizeof(oid) )) {
            return -1;
        }
        ctx->index.len = hdr->len;
    }

    /*
     * initialize variable that will hold each component of the index.
     * If there are multiple indexes for the table, the variable_lists
     * need to be linked together, in order.
     */
       /** TODO: add code for external index(s)! */
       memset( &var_saHpiDomainId, 0x00, sizeof(var_saHpiDomainId) );
       var_saHpiDomainId.type = ASN_UNSIGNED; /* type hint for parse_oid_indexes */
       /** TODO: link this index to the next, or NULL for the last one */
#ifdef TABLE_CONTAINER_TODO
    snmp_log(LOG_ERR, "saHpiHotSwapTable_extract_index index list not implemented!\n" );
    return 0;
#else
       var_saHpiDomainId.next_variable = &var_XX;
#endif

       memset( &var_saHpiResourceId, 0x00, sizeof(var_saHpiResourceId) );
       var_saHpiResourceId.type = ASN_UNSIGNED; /* type hint for parse_oid_indexes */
       /** TODO: link this index to the next, or NULL for the last one */
#ifdef TABLE_CONTAINER_TODO
    snmp_log(LOG_ERR, "saHpiHotSwapTable_extract_index index list not implemented!\n" );
    return 0;
#else
       var_saHpiResourceId.next_variable = &var_XX;
#endif

       memset( &var_saHpiResourceIsHistorical, 0x00, sizeof(var_saHpiResourceIsHistorical) );
       var_saHpiResourceIsHistorical.type = ASN_INTEGER; /* type hint for parse_oid_indexes */
       /** TODO: link this index to the next, or NULL for the last one */
#ifdef TABLE_CONTAINER_TODO
    snmp_log(LOG_ERR, "saHpiHotSwapTable_extract_index index list not implemented!\n" );
    return 0;
#else
       var_saHpiResourceIsHistorical.next_variable = &var_XX;
#endif


    /*
     * parse the oid into the individual index components
     */
    err = parse_oid_indexes( hdr->oids, hdr->len, &var_saHpiDomainId );
    if (err == SNMP_ERR_NOERROR) {
       /*
        * copy index components into the context structure
        */
              /** skipping external index saHpiDomainId */
   
              /** skipping external index saHpiResourceId */
   
              /** skipping external index saHpiResourceIsHistorical */
   
   
           /*
            * TODO: check index for valid values. For EXAMPLE:
            *
              * if ( *var_saHpiDomainId.val.integer != XXX ) {
          *    err = -1;
          * }
          */
           /*
            * TODO: check index for valid values. For EXAMPLE:
            *
              * if ( *var_saHpiResourceId.val.integer != XXX ) {
          *    err = -1;
          * }
          */
           /*
            * TODO: check index for valid values. For EXAMPLE:
            *
              * if ( *var_saHpiResourceIsHistorical.val.integer != XXX ) {
          *    err = -1;
          * }
          */
    }

    /*
     * parsing may have allocated memory. free it.
     */
    snmp_reset_var_buffers( &var_saHpiDomainId );

    return err;
}
/**
 * @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 */
Ejemplo n.º 25
0
/*
 * the *_extract_index routine (Mostly auto-generated)
 *
 * This routine is called when a set request is received for an index that 
 * was not found in the table container. Here, we parse the oid in the
 * individual index components and copy those indexes to the context. Then 
 * we make sure the indexes for the new row are valid.
 *
 * It has been modified from its original form in that the indexes aren't
 * returned if they are invalid.  An index is invalid if it is not between 
 * 100 and 699 (Inclusive).
 */
int openserSIPStatusCodesTable_extract_index( 
		openserSIPStatusCodesTable_context * ctx, netsnmp_index * hdr)
{

	/*
	 * temporary local storage for extracting oid index
	 *
	 * extract index uses varbinds (netsnmp_variable_list) to parse
	 * the index OID into the individual components for each index part.
	 */
	netsnmp_variable_list var_openserSIPStatusCodeMethod;
	netsnmp_variable_list var_openserSIPStatusCodeValue;
	int err;

	/*
	 * copy index, if provided
	 */
	if(hdr) {
		netsnmp_assert(ctx->index.oids == NULL);
		if((hdr->len > MAX_OID_LEN) || 
				snmp_clone_mem( 
					(void*)&ctx->index.oids,
					hdr->oids,
					hdr->len * sizeof(oid))) 
		{
			return -1;
		}

		ctx->index.len = hdr->len;
	}

 	/* Initialize the two variables responsible for holding our two indices.
	 */
	memset(&var_openserSIPStatusCodeMethod, 0x00, 
			 sizeof(var_openserSIPStatusCodeMethod));

	memset( &var_openserSIPStatusCodeValue, 0x00, 
			sizeof(var_openserSIPStatusCodeValue) );

	var_openserSIPStatusCodeMethod.type = ASN_UNSIGNED; 
	var_openserSIPStatusCodeValue.type  = ASN_UNSIGNED;

	var_openserSIPStatusCodeMethod.next_variable = 
		&var_openserSIPStatusCodeValue;

	var_openserSIPStatusCodeValue.next_variable = NULL;

	/* parse the oid into the individual index components */
	err = parse_oid_indexes( hdr->oids, hdr->len, 
			&var_openserSIPStatusCodeMethod );

	if (err == SNMP_ERR_NOERROR) {

		/* copy index components into the context structure */
		ctx->openserSIPStatusCodeMethod = 
			*var_openserSIPStatusCodeMethod.val.integer;
		ctx->openserSIPStatusCodeValue  = 
			*var_openserSIPStatusCodeValue.val.integer;
   
   
		if (*var_openserSIPStatusCodeMethod.val.integer < 1)
		{
			err = -1;
		}

		if (*var_openserSIPStatusCodeValue.val.integer < 100 ||
		    *var_openserSIPStatusCodeValue.val.integer > 699) {
			err = -1;
		}

	}

	
	/* parsing may have allocated memory. free it. */
	snmp_reset_var_buffers( &var_openserSIPStatusCodeMethod );

	return err;
}
Ejemplo n.º 26
0
/**
 * @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 */
/**
 * the *_extract_index routine
 *
 * This routine is called when a set request is received for an index
 * that was not found in the table container. Here, we parse the oid
 * in the the individual index components and copy those indexes to the
 * context. Then we make sure the indexes for the new row are valid.
 */
int
  saHpiSensorThdPosHysteresisTable_extract_index
  (saHpiSensorThdPosHysteresisTable_context * ctx, netsnmp_index * hdr)
{
  /*
   * temporary local storage for extracting oid index
   *
   * extract index uses varbinds (netsnmp_variable_list) to parse
   * the index OID into the individual components for each index part.
   */
  netsnmp_variable_list var_saHpiDomainID;
  netsnmp_variable_list var_saHpiResourceID;
  netsnmp_variable_list var_saHpiSensorIndex;
  int err;

  /*
   * copy index, if provided
   */
  if (hdr)
    {
      netsnmp_assert (ctx->index.oids == NULL);
      if (snmp_clone_mem ((void *) &ctx->index.oids, hdr->oids,
			  hdr->len * sizeof (oid)))
	{
	  return -1;
	}
      ctx->index.len = hdr->len;
    }

  /*
   * initialize variable that will hold each component of the index.
   * If there are multiple indexes for the table, the variable_lists
   * need to be linked together, in order.
   */
  memset (&var_saHpiDomainID, 0x00, sizeof (var_saHpiDomainID));
  var_saHpiDomainID.type = ASN_UNSIGNED;	/* type hint for parse_oid_indexes */

  var_saHpiDomainID.next_variable = &var_saHpiResourceID;

  memset (&var_saHpiResourceID, 0x00, sizeof (var_saHpiResourceID));
  var_saHpiResourceID.type = ASN_UNSIGNED;	/* type hint for parse_oid_indexes */

  var_saHpiResourceID.next_variable = &var_saHpiSensorIndex;

  memset (&var_saHpiSensorIndex, 0x00, sizeof (var_saHpiSensorIndex));
  var_saHpiSensorIndex.type = ASN_UNSIGNED;	/* type hint for parse_oid_indexes */

  var_saHpiSensorIndex.next_variable = NULL;

  /*
   * parse the oid into the individual index components
   */
  err = parse_oid_indexes (hdr->oids, hdr->len, &var_saHpiDomainID);
  if (err == SNMP_ERR_NOERROR)
    {
      /*
       * copy index components into the context structure
       */
	ctx->domain_id  = *var_saHpiDomainID.val.integer;
	ctx->resource_id = *var_saHpiResourceID.val.integer;
	ctx->sensor_id = *var_saHpiSensorIndex.val.integer;
    }

  /*
   * parsing may have allocated memory. free it.
   */
  snmp_reset_var_buffers (&var_saHpiDomainID);

  return err;
}
/**
 * extract dot11NewNeighborAPTable indexes from a netsnmp_index
 *
 * @retval SNMP_ERR_NOERROR  : no error
 * @retval SNMP_ERR_GENERR   : error
 */
int
dot11NewNeighborAPTable_index_from_oid(netsnmp_index *oid_idx,
                         dot11NewNeighborAPTable_mib_index *mib_idx)
{
    int err = SNMP_ERR_NOERROR;
    
    /*
     * temp storage for parsing indexes
     */
    /*
     * wtpMacAddr(1)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H
     */
    netsnmp_variable_list var_wtpMacAddr;
    /*
     * wtpWirelessIfIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
     */
    netsnmp_variable_list var_wtpWirelessIfIndex;
    /*
     * neighborAPIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
     */
    netsnmp_variable_list var_neighborAPIndex;

    /*
     * set up varbinds
     */
    memset( &var_wtpMacAddr, 0x00, sizeof(var_wtpMacAddr) );
    var_wtpMacAddr.type = ASN_OCTET_STR;
    memset( &var_wtpWirelessIfIndex, 0x00, sizeof(var_wtpWirelessIfIndex) );
    var_wtpWirelessIfIndex.type = ASN_INTEGER;
    memset( &var_neighborAPIndex, 0x00, sizeof(var_neighborAPIndex) );
    var_neighborAPIndex.type = ASN_INTEGER;

    /*
     * chain temp index varbinds together
     */
    var_wtpMacAddr.next_variable =  &var_wtpWirelessIfIndex; var_wtpWirelessIfIndex.next_variable =  &var_neighborAPIndex; var_neighborAPIndex.next_variable =  NULL;


    DEBUGMSGTL(("verbose:dot11NewNeighborAPTable:dot11NewNeighborAPTable_index_from_oid","called\n"));

    /*
     * parse the oid into the individual index components
     */
    err = parse_oid_indexes( oid_idx->oids, oid_idx->len,
                             &var_wtpMacAddr );
    if (err == SNMP_ERR_NOERROR) {
        /*
         * copy out values
         */
    /*
     * NOTE: val_len is in bytes, wtpMacAddr_len might not be
     */
         if(var_wtpMacAddr.val_len > sizeof(mib_idx->wtpMacAddr))
             err = SNMP_ERR_GENERR;
         else {
             memcpy(mib_idx->wtpMacAddr, var_wtpMacAddr.val.string, var_wtpMacAddr.val_len);
             mib_idx->wtpMacAddr_len = var_wtpMacAddr.val_len / sizeof(mib_idx->wtpMacAddr[0]);
         }
    mib_idx->wtpWirelessIfIndex = *((long *)var_wtpWirelessIfIndex.val.string);
    mib_idx->neighborAPIndex = *((long *)var_neighborAPIndex.val.string);


    }

    /*
     * parsing may have allocated memory. free it.
     */
    snmp_reset_var_buffers( &var_wtpMacAddr );

    return err;
} /* dot11NewNeighborAPTable_index_from_oid */
Ejemplo n.º 29
0
/**
 * the *_extract_index routine
 *
 * This routine is called when a set request is received for an index
 * that was not found in the table container. Here, we parse the oid
 * in the the individual index components and copy those indexes to the
 * context. Then we make sure the indexes for the new row are valid.
 */
int
memTable_extract_index(memTable_context * ctx, netsnmp_index * hdr)
{
    /*
     * temporary local storage for extracting oid index
     *
     * extract index uses varbinds (netsnmp_variable_list) to parse
     * the index OID into the individual components for each index part.
     */
    netsnmp_variable_list var_memIndex;
    int             err;

    /*
     * copy index, if provided
     */
    if (hdr) {
        netsnmp_assert(ctx->index.oids == NULL);
        if (snmp_clone_mem((void *) &ctx->index.oids, hdr->oids,
                           hdr->len * sizeof(oid))) {
            return -1;
        }
        ctx->index.len = hdr->len;
    }

    /*
     * initialize variable that will hold each component of the index.
     * If there are multiple indexes for the table, the variable_lists
     * need to be linked together, in order.
     */
    memset(&var_memIndex, 0x00, sizeof(var_memIndex));
    var_memIndex.type = ASN_INTEGER;    /* type hint for parse_oid_indexes */
       /** TODO: link this index to the next, or NULL for the last one */
#ifdef TABLE_CONTAINER_TODO
    log_print(LOGN_CRI,
             "memTable_extract_index index list not implemented!\n");
    return 0;
#else
    //var_memIndex.next_variable = &var_XX;
    var_memIndex.next_variable = NULL;
#endif


    /*
     * parse the oid into the individual index components
     */
    err = parse_oid_indexes(hdr->oids, hdr->len, &var_memIndex);
    if (err == SNMP_ERR_NOERROR) {
        /*
         * copy index components into the context structure
         */
        ctx->memIndex = *var_memIndex.val.integer;


        /*
         * TODO: check index for valid values. For EXAMPLE:
         *
         * if ( *var_memIndex.val.integer != XXX ) {
         *    err = -1;
         * }
         */
    }

    /*
     * parsing may have allocated memory. free it.
     */
    snmp_reset_var_buffers(&var_memIndex);

    return err;
}
/**
 * extract usmDHUserKeyTable indexes from a netsnmp_index
 *
 * @retval SNMP_ERR_NOERROR  : no error
 * @retval SNMP_ERR_GENERR   : error
 */
int
usmDHUserKeyTable_index_from_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_from_oid", "called\n"));

    /*
     * parse the oid into the individual index components
     */
    err = parse_oid_indexes(oid_idx->oids, oid_idx->len,
                            &var_usmUserEngineID);
    if (err == SNMP_ERR_NOERROR) {
        /*
         * copy out values
         */
        /*
         * NOTE: val_len is in bytes, usmUserEngineID_len might not be
         */
        if (var_usmUserEngineID.val_len > sizeof(mib_idx->usmUserEngineID))
            err = SNMP_ERR_GENERR;
        else {
            memcpy(mib_idx->usmUserEngineID,
                   var_usmUserEngineID.val.string,
                   var_usmUserEngineID.val_len);
            mib_idx->usmUserEngineID_len =
                var_usmUserEngineID.val_len /
                sizeof(mib_idx->usmUserEngineID[0]);
        }
        /*
         * NOTE: val_len is in bytes, usmUserName_len might not be
         */
        if (var_usmUserName.val_len > sizeof(mib_idx->usmUserName))
            err = SNMP_ERR_GENERR;
        else {
            memcpy(mib_idx->usmUserName, var_usmUserName.val.string,
                   var_usmUserName.val_len);
            mib_idx->usmUserName_len =
                var_usmUserName.val_len / sizeof(mib_idx->usmUserName[0]);
        }


    }

    /*
     * parsing may have allocated memory. free it.
     */
    snmp_reset_var_buffers(&var_usmUserEngineID);

    return err;
}                               /* usmDHUserKeyTable_index_from_oid */