Example #1
0
static int
handle_ipAddressSpinLock(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info   *reqinfo,
                          netsnmp_request_info         *requests)
{
    long   value;

    /* We are never called for a GETNEXT if it's registered as a
       "instance", as it's "magically" handled for us.  */

    /* a instance handler also only hands us one request at a time, so
       we don't need to loop over a list of requests; we'll only get one. */

    switch(reqinfo->mode) {

        case MODE_GET:
            snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                     (u_char *)&ipAddressSpinLockValue, 
                                     sizeof(ipAddressSpinLockValue));
            break;

#ifndef NETSNMP_NO_WRITE_SUPPORT
        /*
         * SET REQUEST
         *
         * multiple states in the transaction.  See:
         * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
         */
        case MODE_SET_RESERVE1:
        case MODE_SET_RESERVE2:
            /* just check the value */
            value =  *(requests->requestvb->val.integer);
            if (value != ipAddressSpinLockValue)
                netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_INCONSISTENTVALUE);
            break;

        case MODE_SET_FREE:
            break;

        case MODE_SET_ACTION:
            /* perform the final spinlock check and increase its value */
            value =  *(requests->requestvb->val.integer);
            if (value != ipAddressSpinLockValue) {
                netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_INCONSISTENTVALUE);
            } else {
                ipAddressSpinLockValue++;
                /* and check it for overflow */
                if (ipAddressSpinLockValue > 2147483647 || ipAddressSpinLockValue < 0)
                    ipAddressSpinLockValue = 0;
            }
            break;

        case MODE_SET_COMMIT:
            break;

        case MODE_SET_UNDO:
             break;
#endif /* !NETSNMP_NO_WRITE_SUPPORT */

        default:
            /* we should never get here, so this is a really bad error */
            snmp_log(LOG_ERR, "unknown mode (%d) in handle_ipAddressSpinLock\n", reqinfo->mode );
            return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}
/** handles requests for the mteEventNotificationTable table */
int
mteEventNotificationTable_handler(netsnmp_mib_handler *handler,
                                  netsnmp_handler_registration *reginfo,
                                  netsnmp_agent_request_info *reqinfo,
                                  netsnmp_request_info *requests)
{

    netsnmp_request_info       *request;
    netsnmp_table_request_info *tinfo;
    struct mteEvent            *entry;
    int ret;

    DEBUGMSGTL(("disman:event:mib", "Notification Table handler (%d)\n", reqinfo->mode));

    switch (reqinfo->mode) {
        /*
         * Read-support (also covers GetNext requests)
         */
    case MODE_GET:
        for (request = requests; request; request = request->next) {
            entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
            tinfo = netsnmp_extract_table_info(request);

            /*
             * The mteEventNotificationTable should only contains entries
             *   for rows where the mteEventActions 'notification(0)' bit
             *   is set. So skip entries where this isn't the case.
             */
            if (!entry || !(entry->mteEventActions & MTE_EVENT_NOTIFICATION))
                continue;

            switch (tinfo->colnum) {
            case COLUMN_MTEEVENTNOTIFICATION:
                snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID,
                              (u_char *) entry->mteNotification,
                                         entry->mteNotification_len*sizeof(oid));
                break;
            case COLUMN_MTEEVENTNOTIFICATIONOBJECTSOWNER:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                              (u_char *) entry->mteNotifyOwner,
                                  strlen(entry->mteNotifyOwner));
                break;
            case COLUMN_MTEEVENTNOTIFICATIONOBJECTS:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                              (u_char *) entry->mteNotifyObjects,
                                  strlen(entry->mteNotifyObjects));
                break;
            }
        }
        break;

        /*
         * Write-support
         */
    case MODE_SET_RESERVE1:
        for (request = requests; request; request = request->next) {
            tinfo = netsnmp_extract_table_info(request);

            /*
             * Since the mteEventNotificationTable only contains entries
             *   for rows where the mteEventActions 'notification(0)'
             *   bit is set, strictly speaking we should reject
             *   assignments where this isn't the case.
             * But SET requests that include an assignment of the
             *   'notification(0)' bit at the same time are valid,
             *   so would need to be accepted. Unfortunately, this
             *   assignment is only applied in the COMMIT pass, so
             *   it's difficult to detect whether this holds or not.
             *
             * Let's fudge things for now, by processing assignments
             *   even if the 'notification(0)' bit isn't set.
             */

            switch (tinfo->colnum) {
            case COLUMN_MTEEVENTNOTIFICATION:
                ret = netsnmp_check_vb_oid( request->requestvb );
                if (ret != SNMP_ERR_NOERROR) {
                    netsnmp_set_request_error(reqinfo, request, ret);
                    return SNMP_ERR_NOERROR;
                }
                break;
            case COLUMN_MTEEVENTNOTIFICATIONOBJECTSOWNER:
            case COLUMN_MTEEVENTNOTIFICATIONOBJECTS:
                ret = netsnmp_check_vb_type_and_max_size(
                          request->requestvb, ASN_OCTET_STR, MTE_STR1_LEN);
                if (ret != SNMP_ERR_NOERROR) {
                    netsnmp_set_request_error(reqinfo, request, ret);
                    return SNMP_ERR_NOERROR;
                }
                break;
            default:
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_ERR_NOTWRITABLE);
                return SNMP_ERR_NOERROR;
            }

            /*
             * The Event MIB is somewhat ambiguous as to whether
             *  mteEventNotificationTable (and mteEventSetTable)
             *  entries can be modified once the main mteEventTable
             *  entry has been marked 'active'. 
             * But it's clear from discussion on the DisMan mailing
             *  list is that the intention is not.
             *
             * So check for whether this row is already active,
             *  and reject *all* SET requests if it is.
             */
            entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
            if (entry &&
                entry->flags & MTE_EVENT_FLAG_ACTIVE ) {
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_ERR_INCONSISTENTVALUE);
                return SNMP_ERR_NOERROR;
            }
        }
        break;

    case MODE_SET_RESERVE2:
    case MODE_SET_FREE:
    case MODE_SET_UNDO:
        break;

    case MODE_SET_ACTION:
        for (request = requests; request; request = request->next) {
            entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
            if (!entry) {
                /*
                 * New rows must be created via the RowStatus column
                 *   (in the main mteEventTable)
                 */
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_ERR_NOCREATION);
                                      /* or inconsistentName? */
                return SNMP_ERR_NOERROR;

            }
        }
        break;

    case MODE_SET_COMMIT:
        /*
         * All these assignments are "unfailable", so it's
         *  (reasonably) safe to apply them in the Commit phase
         */
        for (request = requests; request; request = request->next) {
            entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
            tinfo = netsnmp_extract_table_info(request);

            switch (tinfo->colnum) {
            case COLUMN_MTEEVENTNOTIFICATION:
                memset(entry->mteNotification, 0, sizeof(entry->mteNotification));
                memcpy(entry->mteNotification, request->requestvb->val.objid,
                                               request->requestvb->val_len);
                entry->mteNotification_len = request->requestvb->val_len/sizeof(oid);
                break;
            case COLUMN_MTEEVENTNOTIFICATIONOBJECTSOWNER:
                memset(entry->mteNotifyOwner, 0, sizeof(entry->mteNotifyOwner));
                memcpy(entry->mteNotifyOwner, request->requestvb->val.string,
                                              request->requestvb->val_len);
                break;
            case COLUMN_MTEEVENTNOTIFICATIONOBJECTS:
                memset(entry->mteNotifyObjects, 0, sizeof(entry->mteNotifyObjects));
                memcpy(entry->mteNotifyObjects, request->requestvb->val.string,
                                                request->requestvb->val_len);
                break;
            }
        }
        break;
    }
    return SNMP_ERR_NOERROR;
}
Example #3
0
int
handle_BSSIDFilterSwitch(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info   *reqinfo,
                          netsnmp_request_info         *requests)
{
    /* We are never called for a GETNEXT if it's registered as a
       "instance", as it's "magically" handled for us.  */

    /* a instance handler also only hands us one request at a time, so
       we don't need to loop over a list of requests; we'll only get one. */

	snmp_log(LOG_DEBUG, "enter handle_BSSIDFilterSwitch\n");

    switch(reqinfo->mode) {

        case MODE_GET:
		{
			int BSSIDFilterOnOff = 0;
            instance_parameter *paraHead = NULL;
            if(SNMPD_DBUS_SUCCESS == get_slot_dbus_connection(LOCAL_SLOT_NUM, &paraHead, SNMPD_INSTANCE_MASTER_V2))
            {
                int ret = 0;
    			DCLI_AC_API_GROUP_FIVE *wirelessconfig = NULL;
    			wireless_config *head = NULL;

    			snmp_log(LOG_DEBUG, "enter show_wc_config\n");
    			ret = show_wc_config(paraHead->parameter, paraHead->connection,&wirelessconfig);
    			snmp_log(LOG_DEBUG, "exit show_wc_config,ret=%d\n", ret);
    			
    			if((ret == 1)&&(wirelessconfig->wireless_control != NULL))
    			{
    				head = wirelessconfig->wireless_control;
    				BSSIDFilterOnOff = (head->macfiltrflag==1)?1:0;
    			}
			    if(ret == 1)
    			{
    				Free_wc_config(wirelessconfig);
    			}
			}
            free_instance_parameter_list(&paraHead);
            snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                     (u_char *)&BSSIDFilterOnOff,
                                     sizeof(BSSIDFilterOnOff));

			
        }
            break;

        /*
         * SET REQUEST
         *
         * multiple states in the transaction.  See:
         * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
         */
        case MODE_SET_RESERVE1:
			#if 0
            if (/* XXX: check incoming data in requests->requestvb->val.XXX for failures, like an incorrect type or an illegal value or ... */) {
                netsnmp_set_request_error(reqinfo, requests, /* XXX: set error code depending on problem (like SNMP_ERR_WRONGTYPE or SNMP_ERR_WRONGVALUE or ... */);
            }
			#endif
            break;

        case MODE_SET_RESERVE2:
			#if 0
            /* XXX malloc "undo" storage buffer */
            if (/* XXX if malloc, or whatever, failed: */) {
                netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
            }
			#endif
            break;

        case MODE_SET_FREE:
            /* XXX: free resources allocated in RESERVE1 and/or
               RESERVE2.  Something failed somewhere, and the states
               below won't be called. */
            break;

        case MODE_SET_ACTION:
		{			
			int ret = 0;

			if(*requests->requestvb->val.integer==0)
			{
                instance_parameter *paraHead = NULL, *paraNode = NULL;
                list_instance_parameter(&paraHead, SNMPD_INSTANCE_MASTER);
                for(paraNode = paraHead; NULL != paraNode; paraNode = paraNode->next)
                {
    				snmp_log(LOG_DEBUG, "enter set_wid_mac_whitelist_cmd\n");
    				ret = set_wid_mac_whitelist_cmd(paraNode->parameter, paraNode->connection,"disable");
    				snmp_log(LOG_DEBUG, "exit set_wid_mac_whitelist_cmd,ret=%d\n", ret);
    				
    				if(ret != 1)
    				{	
    				    if(SNMPD_CONNECTION_ERROR == ret) {
                            close_slot_dbus_connection(paraNode->parameter.slot_id);
                	    }
    					netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGTYPE);
    				}
    			}	
                free_instance_parameter_list(&paraHead);
			}
			else if(*requests->requestvb->val.integer==1)
			{
                instance_parameter *paraHead = NULL, *paraNode = NULL;
                list_instance_parameter(&paraHead, SNMPD_INSTANCE_MASTER);
                for(paraNode = paraHead; NULL != paraNode; paraNode = paraNode->next)
                {
    				snmp_log(LOG_DEBUG, "enter set_wid_mac_whitelist_cmd\n");
    				ret = set_wid_mac_whitelist_cmd(paraNode->parameter, paraNode->connection,"enable");		
    				snmp_log(LOG_DEBUG, "exit set_wid_mac_whitelist_cmd,ret=%d\n", ret);
    				
    				if(ret != 1)
    				{	
    				    if(SNMPD_CONNECTION_ERROR == ret) {
                            close_slot_dbus_connection(paraNode->parameter.slot_id);
                	    }
    					netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGTYPE);
    				}
    			}	
                free_instance_parameter_list(&paraHead);
			}
			else
			{	
				netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGTYPE);
			}
        }
            break;

        case MODE_SET_COMMIT:
			#if 0
            /* XXX: delete temporary storage */
            if (/* XXX: error? */) {
                /* try _really_really_ hard to never get to this point */
                netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
            }
			#endif
            break;

        case MODE_SET_UNDO:
			#if 0
            /* XXX: UNDO and return to previous value for the object */
            if (/* XXX: error? */) {
                /* try _really_really_ hard to never get to this point */
                netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED);
            }
			#endif
            break;

        default:
            /* we should never get here, so this is a really bad error */
		snmp_log(LOG_ERR, "unknown mode (%d) in handle_BSSIDFilterSwitch\n", reqinfo->mode );
            return SNMP_ERR_GENERR;
    }

	snmp_log(LOG_DEBUG, "exit handle_BSSIDFilterSwitch\n");
    return SNMP_ERR_NOERROR;
}
Example #4
0
int handle_systemStats(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests)
{
	netsnmp_request_info *request = NULL;
	oid subid;
	switch_time_t uptime;
	uint32_t int_val = 0;

	switch(reqinfo->mode) {
	case MODE_GET:
		subid = requests->requestvb->name[reginfo->rootoid_len - 2];
		snmp_log(LOG_DEBUG, "systemStats OID-suffix requested (%d)\n", (int) subid);

		switch (subid) {
		case SS_UPTIME:
			uptime = switch_core_uptime() / 10000;
			snmp_set_var_typed_value(requests->requestvb, ASN_TIMETICKS, (u_char *) &uptime, sizeof(uptime));
			break;
		case SS_SESSIONS_SINCE_STARTUP:
			int_val = switch_core_session_id() - 1;
			snmp_set_var_typed_integer(requests->requestvb, ASN_COUNTER, int_val);
			break;
		case SS_CURRENT_SESSIONS:
			int_val = switch_core_session_count();
			snmp_set_var_typed_integer(requests->requestvb, ASN_GAUGE, int_val);
			break;
		case SS_MAX_SESSIONS:
			switch_core_session_ctl(SCSC_MAX_SESSIONS, &int_val);
			snmp_set_var_typed_integer(requests->requestvb, ASN_GAUGE, int_val);
			break;
		case SS_CURRENT_CALLS:
			{
			switch_cache_db_handle_t *dbh;
			char sql[1024] = "";

			if (switch_core_db_handle(&dbh) != SWITCH_STATUS_SUCCESS) {
				return SNMP_ERR_GENERR;
			}

			sprintf(sql, "SELECT COUNT(*) FROM calls WHERE hostname='%s'", switch_core_get_switchname());
			switch_cache_db_execute_sql_callback(dbh, sql, sql_count_callback, &int_val, NULL);
			snmp_set_var_typed_integer(requests->requestvb, ASN_GAUGE, int_val);
			switch_cache_db_release_db_handle(&dbh);
			}
			break;
		case SS_SESSIONS_PER_SECOND:
			switch_core_session_ctl(SCSC_LAST_SPS, &int_val);
			snmp_set_var_typed_integer(requests->requestvb, ASN_GAUGE, int_val);
			break;
		case SS_MAX_SESSIONS_PER_SECOND:
			switch_core_session_ctl(SCSC_SPS, &int_val);
			snmp_set_var_typed_integer(requests->requestvb, ASN_GAUGE, int_val);
			break;
		case SS_PEAK_SESSIONS_PER_SECOND:
			switch_core_session_ctl(SCSC_SPS_PEAK, &int_val);
			snmp_set_var_typed_integer(requests->requestvb, ASN_GAUGE, int_val);
			break;
		case SS_PEAK_SESSIONS_PER_FIVEMIN:
			switch_core_session_ctl(SCSC_SPS_PEAK_FIVEMIN, &int_val);
			snmp_set_var_typed_integer(requests->requestvb, ASN_GAUGE, int_val);
			break;
		case SS_PEAK_SESSIONS:
			switch_core_session_ctl(SCSC_SESSIONS_PEAK, &int_val);
			snmp_set_var_typed_integer(requests->requestvb, ASN_GAUGE, int_val);
			break;
		case SS_PEAK_SESSIONS_FIVEMIN:
			switch_core_session_ctl(SCSC_SESSIONS_PEAK_FIVEMIN, &int_val);
			snmp_set_var_typed_integer(requests->requestvb, ASN_GAUGE, int_val);
			break;
		default:
			snmp_log(LOG_WARNING, "Unregistered OID-suffix requested (%d)\n", (int) subid);
			netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
		}
		break;

	default:
		/* we should never get here, so this is a really bad error */
		snmp_log(LOG_ERR, "Unknown mode (%d) in handle_systemStats\n", reqinfo->mode);
		return SNMP_ERR_GENERR;
	}

	return SNMP_ERR_NOERROR;
}
/** handles requests for the mteTriggerBooleanTable table */
int
mteTriggerBooleanTable_handler(netsnmp_mib_handler *handler,
                               netsnmp_handler_registration *reginfo,
                               netsnmp_agent_request_info *reqinfo,
                               netsnmp_request_info *requests)
{

    netsnmp_request_info       *request;
    netsnmp_table_request_info *tinfo;
    struct mteTrigger          *entry;
    int ret;

    DEBUGMSGTL(("disman:event:mib", "Boolean Table handler (%d)\n",
                                     reqinfo->mode));

    switch (reqinfo->mode) {
        /*
         * Read-support (also covers GetNext requests)
         */
    case MODE_GET:
        for (request = requests; request; request = request->next) {
            if (request->processed)
                continue;

            entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
            tinfo = netsnmp_extract_table_info(request);

            /*
             * The mteTriggerBooleanTable should only contains entries for
             *   rows where the mteTriggerTest 'boolean(1)' bit is set.
             * So skip entries where this isn't the case.
             */
            if (!entry || !(entry->mteTriggerTest & MTE_TRIGGER_BOOLEAN )) {
                netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE);
                continue;
            }

            switch (tinfo->colnum) {
            case COLUMN_MTETRIGGERBOOLEANCOMPARISON:
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           entry->mteTBoolComparison);
                break;
            case COLUMN_MTETRIGGERBOOLEANVALUE:
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           entry->mteTBoolValue);
                break;
            case COLUMN_MTETRIGGERBOOLEANSTARTUP:
                ret = (entry->flags & MTE_TRIGGER_FLAG_BSTART ) ?
                           TV_TRUE : TV_FALSE;
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret);
                break;
            case COLUMN_MTETRIGGERBOOLEANOBJECTSOWNER:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                              (u_char *) entry->mteTBoolObjOwner,
                                  strlen(entry->mteTBoolObjOwner));
                break;
            case COLUMN_MTETRIGGERBOOLEANOBJECTS:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                              (u_char *) entry->mteTBoolObjects,
                                  strlen(entry->mteTBoolObjects));
                break;
            case COLUMN_MTETRIGGERBOOLEANEVENTOWNER:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                              (u_char *) entry->mteTBoolEvOwner,
                                  strlen(entry->mteTBoolEvOwner));
                break;
            case COLUMN_MTETRIGGERBOOLEANEVENT:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                              (u_char *) entry->mteTBoolEvent,
                                  strlen(entry->mteTBoolEvent));
                break;
            }
        }
        break;

#ifndef NETSNMP_NO_WRITE_SUPPORT
        /*
         * Write-support
         */
    case MODE_SET_RESERVE1:
        for (request = requests; request; request = request->next) {
            if (request->processed)
                continue;

            entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
            tinfo = netsnmp_extract_table_info(request);

            /*
             * Since the mteTriggerBooleanTable only contains entries for
             *   rows where the mteTriggerTest 'boolean(1)' bit is set,
             *   strictly speaking we should reject assignments where
             *   this isn't the case.
             * But SET requests that include an assignment of the
             *   'boolean(1)' bit at the same time are valid, so would
             *    need to be accepted. Unfortunately, this assignment
             *   is only applied in the COMMIT pass, so it's difficult
             *   to detect whether this holds or not.
             *
             * Let's fudge things for now, by processing assignments
             *   even if the 'boolean(1)' bit isn't set.
             */
            switch (tinfo->colnum) {
            case COLUMN_MTETRIGGERBOOLEANCOMPARISON:
                ret = netsnmp_check_vb_int_range(request->requestvb,
                              MTE_BOOL_UNEQUAL, MTE_BOOL_GREATEREQUAL);
                if (ret != SNMP_ERR_NOERROR) {
                    netsnmp_set_request_error(reqinfo, request, ret);
                    return SNMP_ERR_NOERROR;
                }
                break;
            case COLUMN_MTETRIGGERBOOLEANVALUE:
                ret = netsnmp_check_vb_int(request->requestvb);
                if (ret != SNMP_ERR_NOERROR) {
                    netsnmp_set_request_error(reqinfo, request, ret);
                    return SNMP_ERR_NOERROR;
                }
                break;
            case COLUMN_MTETRIGGERBOOLEANSTARTUP:
                ret = netsnmp_check_vb_truthvalue(request->requestvb);
                if (ret != SNMP_ERR_NOERROR) {
                    netsnmp_set_request_error(reqinfo, request, ret);
                    return SNMP_ERR_NOERROR;
                }
                break;
            case COLUMN_MTETRIGGERBOOLEANOBJECTSOWNER:
            case COLUMN_MTETRIGGERBOOLEANOBJECTS:
            case COLUMN_MTETRIGGERBOOLEANEVENTOWNER:
            case COLUMN_MTETRIGGERBOOLEANEVENT:
                ret = netsnmp_check_vb_type_and_max_size(
                          request->requestvb, ASN_OCTET_STR, MTE_STR1_LEN);
                if (ret != SNMP_ERR_NOERROR) {
                    netsnmp_set_request_error(reqinfo, request, ret);
                    return SNMP_ERR_NOERROR;
                }
                break;
            default:
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_ERR_NOTWRITABLE);
                return SNMP_ERR_NOERROR;
            }

            /*
             * The Event MIB is somewhat ambiguous as to whether the
             *  various trigger table entries can be modified once the
             *  main mteTriggerTable entry has been marked 'active'. 
             * But it's clear from discussion on the DisMan mailing
             *  list is that the intention is not.
             *
             * So check for whether this row is already active,
             *  and reject *all* SET requests if it is.
             */
            entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
            if (entry &&
                entry->flags & MTE_TRIGGER_FLAG_ACTIVE ) {
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_ERR_INCONSISTENTVALUE);
                return SNMP_ERR_NOERROR;
            }
        }
        break;

    case MODE_SET_RESERVE2:
    case MODE_SET_FREE:
    case MODE_SET_UNDO:
        break;

    case MODE_SET_ACTION:
        for (request = requests; request; request = request->next) {
            if (request->processed)
                continue;

            entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
            if (!entry) {
                /*
                 * New rows must be created via the RowStatus column
                 *   (in the main mteTriggerTable)
                 */
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_ERR_NOCREATION);
                                      /* or inconsistentName? */
                return SNMP_ERR_NOERROR;
            }
        }
        break;

    case MODE_SET_COMMIT:
        /*
         * All these assignments are "unfailable", so it's
         *  (reasonably) safe to apply them in the Commit phase
         */
        for (request = requests; request; request = request->next) {
            if (request->processed)
                continue;

            entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
            tinfo = netsnmp_extract_table_info(request);

            switch (tinfo->colnum) {
            case COLUMN_MTETRIGGERBOOLEANCOMPARISON:
                entry->mteTBoolComparison = *request->requestvb->val.integer;
                break;
            case COLUMN_MTETRIGGERBOOLEANVALUE:
                entry->mteTBoolValue      = *request->requestvb->val.integer;
                break;
            case COLUMN_MTETRIGGERBOOLEANSTARTUP:
                if (*request->requestvb->val.integer == TV_TRUE)
                    entry->flags |=  MTE_TRIGGER_FLAG_BSTART;
                else
                    entry->flags &= ~MTE_TRIGGER_FLAG_BSTART;
                break;
            case COLUMN_MTETRIGGERBOOLEANOBJECTSOWNER:
                memset(entry->mteTBoolObjOwner, 0, sizeof(entry->mteTBoolObjOwner));
                memcpy(entry->mteTBoolObjOwner, request->requestvb->val.string,
                                                request->requestvb->val_len);
                break;
            case COLUMN_MTETRIGGERBOOLEANOBJECTS:
                memset(entry->mteTBoolObjects, 0, sizeof(entry->mteTBoolObjects));
                memcpy(entry->mteTBoolObjects, request->requestvb->val.string,
                                               request->requestvb->val_len);
                break;
            case COLUMN_MTETRIGGERBOOLEANEVENTOWNER:
                memset(entry->mteTBoolEvOwner, 0, sizeof(entry->mteTBoolEvOwner));
                memcpy(entry->mteTBoolEvOwner, request->requestvb->val.string,
                                               request->requestvb->val_len);
                break;
            case COLUMN_MTETRIGGERBOOLEANEVENT:
                memset(entry->mteTBoolEvent, 0, sizeof(entry->mteTBoolEvent));
                memcpy(entry->mteTBoolEvent, request->requestvb->val.string,
                                             request->requestvb->val_len);
                break;
            }
        }
        break;
#endif /* !NETSNMP_NO_WRITE_SUPPORT */
    }
    return SNMP_ERR_NOERROR;
}
Example #6
0
/************************************************************
 * saHpiSensorTable_get_value
 *
 * This routine is called for get requests to copy the data
 * from the context to the varbind for the request. If the
 * context has been properly maintained, you don't need to
 * change in code in this fuction.
 */
int saHpiSensorTable_get_value(
            netsnmp_request_info *request,
            netsnmp_index *item,
            netsnmp_table_request_info *table_info )
{
    netsnmp_variable_list *var = request->requestvb;
    saHpiSensorTable_context *context = (saHpiSensorTable_context *)item;

    DEBUGMSGTL ((AGENT, "saHpiSensorTable_get_value, called\n"));

    switch(table_info->colnum) {

        case COLUMN_SAHPISENSORNUM:
            /** SaHpiInstrumentId = ASN_UNSIGNED */
            snmp_set_var_typed_value(var, ASN_UNSIGNED,
                         (char*)&context->saHpiSensorNum,
                         sizeof(context->saHpiSensorNum) );
        break;
    
        case COLUMN_SAHPISENSORTYPE:
            /** SaHpiSensorType = ASN_INTEGER */
            snmp_set_var_typed_value(var, ASN_INTEGER,
                         (char*)&context->saHpiSensorType,
                         sizeof(context->saHpiSensorType) );
        break;
    
        case COLUMN_SAHPISENSORCATEGORY:
            /** SaHpiEventCategory = ASN_INTEGER */
            snmp_set_var_typed_value(var, ASN_INTEGER,
                         (char*)&context->saHpiSensorCategory,
                         sizeof(context->saHpiSensorCategory) );
        break;
    
        case COLUMN_SAHPISENSORENABLECTRL:
            /** TruthValue = ASN_INTEGER */
            snmp_set_var_typed_value(var, ASN_INTEGER,
                         (char*)&context->saHpiSensorEnableCtrl,
                         sizeof(context->saHpiSensorEnableCtrl) );
        break;
    
        case COLUMN_SAHPISENSOREVENTCTRL:
            /** INTEGER = ASN_INTEGER */
            snmp_set_var_typed_value(var, ASN_INTEGER,
                         (char*)&context->saHpiSensorEventCtrl,
                         sizeof(context->saHpiSensorEventCtrl) );
        break;
    
        case COLUMN_SAHPISENSORSUPPORTEDEVENTSTATES:
            /** SaHpiEventState = ASN_OCTET_STR */
            snmp_set_var_typed_value(var, ASN_OCTET_STR,
                         (char*)&context->saHpiSensorSupportedEventStates,
                         context->saHpiSensorSupportedEventStates_len );
        break;
    
        case COLUMN_SAHPISENSORISSUPPORTED:
            /** TruthValue = ASN_INTEGER */
            snmp_set_var_typed_value(var, ASN_INTEGER,
                         (char*)&context->saHpiSensorIsSupported,
                         sizeof(context->saHpiSensorIsSupported) );
        break;
    
        case COLUMN_SAHPISENSORREADINGTYPE:
            /** SaHpiSensorReadingType = ASN_INTEGER */
            snmp_set_var_typed_value(var, ASN_INTEGER,
                         (char*)&context->saHpiSensorReadingType,
                         sizeof(context->saHpiSensorReadingType) );
        break;
    
        case COLUMN_SAHPISENSORBASEUNITS:
            /** SaHpiSensorUnits = ASN_INTEGER */
            snmp_set_var_typed_value(var, ASN_INTEGER,
                         (char*)&context->saHpiSensorBaseUnits,
                         sizeof(context->saHpiSensorBaseUnits) );
        break;
    
        case COLUMN_SAHPISENSORMODIFIERUNITS:
            /** SaHpiSensorUnits = ASN_INTEGER */
            snmp_set_var_typed_value(var, ASN_INTEGER,
                         (char*)&context->saHpiSensorModifierUnits,
                         sizeof(context->saHpiSensorModifierUnits) );
        break;
    
        case COLUMN_SAHPISENSORMODIFIERUSE:
            /** INTEGER = ASN_INTEGER */
            snmp_set_var_typed_value(var, ASN_INTEGER,
                         (char*)&context->saHpiSensorModifierUse,
                         sizeof(context->saHpiSensorModifierUse) );
        break;
    
        case COLUMN_SAHPISENSORPERCENTAGE:
            /** TruthValue = ASN_INTEGER */
            snmp_set_var_typed_value(var, ASN_INTEGER,
                         (char*)&context->saHpiSensorPercentage,
                         sizeof(context->saHpiSensorPercentage) );
        break;
    
        case COLUMN_SAHPISENSORRANGEFLAGS:
            /** OCTETSTR = ASN_OCTET_STR */
            snmp_set_var_typed_value(var, ASN_OCTET_STR,
                         (char*)&context->saHpiSensorRangeFlags,
                         context->saHpiSensorRangeFlags_len );
        break;
    
        case COLUMN_SAHPISENSORACCURACYFACTOR:
            /** Double = ASN_OCTET_STR */
            snmp_set_var_typed_value(var, ASN_OCTET_STR,
                         (char*)&context->saHpiSensorAccuracyFactor,
                         context->saHpiSensorAccuracyFactor_len );
        break;
    
        case COLUMN_SAHPISENSOROEM:
            /** UNSIGNED32 = ASN_UNSIGNED */
            snmp_set_var_typed_value(var, ASN_UNSIGNED,
                         (char*)&context->saHpiSensorOem,
                         sizeof(context->saHpiSensorOem) );
        break;
    
        case COLUMN_SAHPISENSORRDR:
            /** RowPointer = ASN_OBJECT_ID */
            snmp_set_var_typed_value(var, ASN_OBJECT_ID,
                         (char*)&context->saHpiSensorRDR,
                         context->saHpiSensorRDR_len );
        break;
    
    default: /** We shouldn't get here */
        snmp_log(LOG_ERR, "unknown column in "
                 "saHpiSensorTable_get_value\n");
        return SNMP_ERR_GENERR;
    }
    return SNMP_ERR_NOERROR;
}
int
handle_subagent_response(int op, netsnmp_session * session, int reqid,
                         netsnmp_pdu *pdu, void *magic)
{
    ns_subagent_magic *smagic = (ns_subagent_magic *) magic;
    netsnmp_variable_list *u = NULL, *v = NULL;
    int             rc = 0;

    if (op != NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE || magic == NULL) {
        return 1;
    }

    pdu = snmp_clone_pdu(pdu);
    DEBUGMSGTL(("agentx/subagent",
                "handling AgentX response (cmd 0x%02x orig_cmd 0x%02x)\n",
                pdu->command, smagic->original_command));

    if (pdu->command == SNMP_MSG_INTERNAL_SET_FREE ||
        pdu->command == SNMP_MSG_INTERNAL_SET_UNDO ||
        pdu->command == SNMP_MSG_INTERNAL_SET_COMMIT) {
        free_set_vars(smagic->session, pdu);
    }

    if (smagic->original_command == AGENTX_MSG_GETNEXT) {
        DEBUGMSGTL(("agentx/subagent",
                    "do getNext scope processing %p %p\n", smagic->ovars,
                    pdu->variables));
        for (u = smagic->ovars, v = pdu->variables; u != NULL && v != NULL;
             u = u->next_variable, v = v->next_variable) {
            if (snmp_oid_compare
                (u->val.objid, u->val_len / sizeof(oid), nullOid,
                 nullOidLen) != 0) {
                /*
                 * The master agent requested scoping for this variable.  
                 */
                rc = snmp_oid_compare(v->name, v->name_length,
                                      u->val.objid,
                                      u->val_len / sizeof(oid));
                DEBUGMSGTL(("agentx/subagent", "result "));
                DEBUGMSGOID(("agentx/subagent", v->name, v->name_length));
                DEBUGMSG(("agentx/subagent", " scope to "));
                DEBUGMSGOID(("agentx/subagent",
                             u->val.objid, u->val_len / sizeof(oid)));
                DEBUGMSG(("agentx/subagent", " result %d\n", rc));

                if (rc >= 0) {
                    /*
                     * The varbind is out of scope.  From RFC2741, p. 66: "If
                     * the subagent cannot locate an appropriate variable,
                     * v.name is set to the starting OID, and the VarBind is
                     * set to `endOfMibView'".  
                     */
                    snmp_set_var_objid(v, u->name, u->name_length);
                    snmp_set_var_typed_value(v, SNMP_ENDOFMIBVIEW, 0, 0);
                    DEBUGMSGTL(("agentx/subagent",
                                "scope violation -- return endOfMibView\n"));
                }
            } else {
                DEBUGMSGTL(("agentx/subagent", "unscoped var\n"));
            }
        }
    }

    /*
     * XXXJBPN: similar for GETBULK but the varbinds can get re-ordered I
     * think which makes it er more difficult.  
     */

    if (smagic->ovars != NULL) {
        snmp_free_varbind(smagic->ovars);
    }

    pdu->command = AGENTX_MSG_RESPONSE;
    pdu->version = smagic->session->version;

    if (!snmp_send(smagic->session, pdu)) {
        snmp_free_pdu(pdu);
    }
    DEBUGMSGTL(("agentx/subagent", "  FINISHED\n"));
    free(smagic);
    return 1;
}
Example #8
0
/** handles requests for the sipProxyCfgTable table.
 * For every request it checks the specified object to see if it has a
 * handler, and calls it */
static int sipProxyCfgTable_handler(
		netsnmp_mib_handler               *handler,
		netsnmp_handler_registration      *reginfo,
		netsnmp_agent_request_info        *reqinfo,
		netsnmp_request_info              *requests) 
{
	netsnmp_variable_list *var;
	netsnmp_table_request_info *table_info;
	struct sip_snmp_handler *h;
	struct sip_snmp_obj *o;
	const char *func = "snmp_mod";
	int res;
	void *tmp_val;
	size_t tmp_len;

	while(requests) {
		var = requests->requestvb;
		if(requests->processed != 0)
			goto next;
		table_info = netsnmp_extract_table_info(requests);
		if(!table_info)
			goto next;
		/* this is not an error, since table-walks work by trying to get
		 * things until we run off of it */
		if(table_info->colnum > SIPPROXYCFGTABLE_COLUMNS)
			goto next;

		/* Get the handler and its object */
		if(sipProxyCfgTable_gh) {
			h = sipProxyCfgTable_gh;
			/* sip_obj is valid since we create upon registration */
			h->sip_obj->opaque = (void*)sipProxyCfgTable_replaceRow;
		} else {
			h = sipProxyCfgTable_h[table_info->colnum];
			if(!h) 
				goto next;
		}
		o = h->sip_obj;
		if(!o) {	/* bad bad boy... */
			LOG(L_ERR, "%s: Found handler without an object!!!\n", func);
			goto next;
		}
		o->col = table_info->colnum;
		o->row = var->name[var->name_length-1];
		switch(reqinfo->mode) {
			case MODE_GET:
			case MODE_GETNEXT:
				if(!h->on_get) break;
				res = h->on_get(o, SER_GET);
				if(res == -1) {
					/* since we don't have a way of knowing what went wrong,
					 * just use a generic error code */
					netsnmp_set_request_error(reqinfo, requests,
							SNMP_ERR_RESOURCEUNAVAILABLE);
					break;
				} else if(res == 0)
					/* the handler has new value to pass back up */
					snmp_set_var_typed_value(var, ser_types[o->type],
							(u_char*)o->value.voidp, o->val_len);
				break;
			case MODE_SET_RESERVE1:
				/* NOTE: We don't require the handler for a on_reserve
				 * function since for our cases it seems that just
				 * checking the type is enough */

				/* First make sure handler wants SETs */
				if(!h->on_set) break;
				/* Check the type */
				if(requests->requestvb->type != ser_types[o->type]) {
					LOG(L_ERR, "%s: Wrong type on SET processing\n", func);
					netsnmp_set_request_error(reqinfo, requests,
							SNMP_ERR_WRONGTYPE);
					break;
				}
				break;
			case MODE_SET_ACTION: /* the real deal */
				if(!h->on_set) break;
				/* copy in the new value for the handler */
				tmp_val = o->value.voidp;
				tmp_len = o->val_len;
				o->value.voidp = requests->requestvb->val.string;
				o->val_len = requests->requestvb->val_len;
				if(h->on_set(o, SER_SET) == -1) {
					LOG(L_ERR, "%s: SET Handler for object failed\n", func);
					netsnmp_set_request_error(reqinfo, requests,
						SNMP_ERR_RESOURCEUNAVAILABLE);
					o->value.voidp = tmp_val;
					o->val_len = tmp_len;
					break;
				}
				o->value.voidp = tmp_val;
				o->val_len = tmp_len;
				break;
			case MODE_SET_UNDO:
				if(!h->on_end) {
					if(h->on_set) /*tsk, tsk, bad boy, gonna tell your mamma..*/
						LOG(L_ERR, "%s: Found object without UNDO handler\n",
							func);
					break;
				}
				/* no point in checking for errors since we're already on
				 * an error branch */
				h->on_end(o, SER_UNDO);
				break;
			case MODE_SET_COMMIT:
				/* Tell the handler is all good and it can safely free up
				 * any memory it may have allocated for UNDO */
				if(!h->on_end) 
					break;
				h->on_end(o, SER_COMMIT);
				break;
			case MODE_SET_FREE:
				/* We get here on failure from RESERVE1. Since there we only 
				 * chk for type correctness, there's nothing to do here */
				break;
		}
next:
		requests = requests->next;
	}
	return SNMP_ERR_NOERROR;
}
Example #9
0
int
handle_memory(netsnmp_mib_handler *handler,
                netsnmp_handler_registration *reginfo,
                netsnmp_agent_request_info *reqinfo,
                netsnmp_request_info *requests)
{
    netsnmp_memory_info *mem_info;
    int val;
    char buf[1024];

    /*
     * We just need to handle valid GET requests, as invalid instances
     *   are rejected automatically, and (valid) GETNEXT requests are
     *   converted into the appropriate GET request.
     *
     * We also only ever receive one request at a time.
     */
    switch (reqinfo->mode) {
    case MODE_GET:
        netsnmp_memory_load();
        switch (requests->requestvb->name[ reginfo->rootoid_len - 2 ]) {
        case MEMORY_INDEX:
            val = 0;
            break;
        case MEMORY_ERRNAME:
            sprintf(buf, "swap");
            snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
                                     (u_char *)buf, strlen(buf));
            return SNMP_ERR_NOERROR;
        case MEMORY_SWAP_TOTAL:
            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_SWAP, 0 );
            if (!mem_info)
               goto NOSUCH;
            val  =  mem_info->size;     /* swaptotal */
            val *= (mem_info->units/1024);
            break;
        case MEMORY_SWAP_AVAIL:
            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_SWAP, 0 );
            if (!mem_info)
               goto NOSUCH;
            val  =  mem_info->free;     /* swapfree */
            val *= (mem_info->units/1024);
            break;
        case MEMORY_REAL_TOTAL:
            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_PHYSMEM, 0 );
            if (!mem_info)
               goto NOSUCH;
            val  =  mem_info->size;     /* memtotal */
            val *= (mem_info->units/1024);
            break;
        case MEMORY_REAL_AVAIL:
            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_PHYSMEM, 0 );
            if (!mem_info)
               goto NOSUCH;
            val  =  mem_info->free;     /* memfree */
            val *= (mem_info->units/1024);
            break;
        case MEMORY_STXT_TOTAL:
            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_STEXT, 0 );
            if (!mem_info)
               goto NOSUCH;
            val  =  mem_info->size;
            val *= (mem_info->units/1024);
            break;
        case MEMORY_STXT_AVAIL:    /* Deprecated */
        case MEMORY_STXT_USED:
            /*
             *   The original MIB description of memAvailSwapTXT
             * was inconsistent with that implied by the name.
             *   Retain the actual behaviour for the (sole)
             * implementation of this object, but deprecate it in
             * favour of a more consistently named replacement object.
             */
            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_STEXT, 0 );
            if (!mem_info)
               goto NOSUCH;
            val  = (mem_info->size - mem_info->free);
            val *= (mem_info->units/1024);
            break;
        case MEMORY_RTXT_TOTAL:
            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_RTEXT, 0 );
            if (!mem_info)
               goto NOSUCH;
            val  =  mem_info->size;
            val *= (mem_info->units/1024);
            break;
        case MEMORY_RTXT_AVAIL:    /* Deprecated */
        case MEMORY_RTXT_USED:
            /*
             *   The original MIB description of memAvailRealTXT
             * was inconsistent with that implied by the name.
             *   Retain the actual behaviour for the (sole)
             * implementation of this object, but deprecate it in
             * favour of a more consistently named replacement object.
             */
            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_RTEXT, 0 );
            if (!mem_info)
               goto NOSUCH;
            val  = (mem_info->size - mem_info->free);
            val *= (mem_info->units/1024);
            break;
        case MEMORY_FREE:
            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_VIRTMEM, 0 );
            if (!mem_info)
               goto NOSUCH;
            val  =  mem_info->free;     /* memfree + swapfree */
            val *= (mem_info->units/1024);
            break;
        case MEMORY_SWAP_MIN:
            val = minimum_swap;
            break;
        case MEMORY_SHARED:
            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_SHARED, 0 );
            if (!mem_info)
               goto NOSUCH;
            val  =  mem_info->size;     /* memshared */
            val *= (mem_info->units/1024);
            break;
        case MEMORY_BUFFER:
            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_MBUF, 0 );
            if (!mem_info || mem_info->size == -1)
               goto NOSUCH;
            val  = (mem_info->size - mem_info->free);      /* buffers */
            val *= (mem_info->units/1024);
            break;
        case MEMORY_CACHED:
            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_CACHED, 0 );
            if (!mem_info || mem_info->size== -1)
               goto NOSUCH;
            val  = (mem_info->size - mem_info->free);      /* cached */
            val *= (mem_info->units/1024);
            break;
        case MEMORY_SWAP_ERROR:
            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_SWAP, 0 );
            if (!mem_info)
               goto NOSUCH;
            val = ((mem_info->units / 1024) * mem_info->free > minimum_swap) ? 0 : 1;
            break;
        case MEMORY_SWAP_ERRMSG:
            mem_info = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_SWAP, 0 );
            if (!mem_info)
               goto NOSUCH;
            if ((mem_info->units / 1024) * mem_info->free > minimum_swap)
                buf[0] = 0;
            else
                sprintf(buf, "Running out of swap space (%ld)", mem_info->free);
            snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
                                     (u_char *)buf, strlen(buf));
            return SNMP_ERR_NOERROR;
        default:
            snmp_log(LOG_ERR,
                     "unknown object (%" NETSNMP_PRIo "u) in handle_memory\n",
                     requests->requestvb->name[ reginfo->rootoid_len - 2 ]);
NOSUCH:
            netsnmp_set_request_error( reqinfo, requests, SNMP_NOSUCHOBJECT );
            return SNMP_ERR_NOERROR;
        }
        /*
         * All non-integer objects (and errors) have already been
         * processed.  So return the integer value.
         */
        snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                 (u_char *)&val, sizeof(val));
        break;

    default:
        /*
         * we should never get here, so this is a really bad error 
         */
        snmp_log(LOG_ERR, "unknown mode (%d) in handle_memory\n",
                 reqinfo->mode);
        return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}
/************************************************************
 * saHpiSoftwareEventTable_get_value
 *
 * This routine is called for get requests to copy the data
 * from the context to the varbind for the request. If the
 * context has been properly maintained, you don't need to
 * change in code in this fuction.
 */
int saHpiSoftwareEventTable_get_value(
            netsnmp_request_info *request,
            netsnmp_index *item,
            netsnmp_table_request_info *table_info )
{
    netsnmp_variable_list *var = request->requestvb;
    saHpiSoftwareEventTable_context *context = (saHpiSoftwareEventTable_context *)item;

    switch(table_info->colnum) {

        case COLUMN_SAHPISOFTWAREEVENTENTRYID:
            /** SaHpiEntryId = ASN_UNSIGNED */
            snmp_set_var_typed_value(var, ASN_UNSIGNED,
                         (char*)&context->saHpiSoftwareEventEntryId,
                         sizeof(context->saHpiSoftwareEventEntryId) );
        break;
    
        case COLUMN_SAHPISOFTWAREEVENTTIMESTAMP:
            /** SaHpiTime = ASN_COUNTER64 */
            snmp_set_var_typed_value(var, ASN_COUNTER64,
                         (char*)&context->saHpiSoftwareEventTimestamp,
                         sizeof(context->saHpiSoftwareEventTimestamp) );
        break;
    
        case COLUMN_SAHPISOFTWAREEVENTMANUFACTURERIDT:
            /** SaHpiManufacturerId = ASN_UNSIGNED */
            snmp_set_var_typed_value(var, ASN_UNSIGNED,
                         (char*)&context->saHpiSoftwareEventManufacturerIdT,
                         sizeof(context->saHpiSoftwareEventManufacturerIdT) );
        break;
    
        case COLUMN_SAHPISOFTWAREEVENTTYPE:
            /** INTEGER = ASN_INTEGER */
            snmp_set_var_typed_value(var, ASN_INTEGER,
                         (char*)&context->saHpiSoftwareEventType,
                         sizeof(context->saHpiSoftwareEventType) );
        break;
    
        case COLUMN_SAHPISOFTWAREEVENTTEXTTYPE:
            /** SaHpiTextType = ASN_INTEGER */
            snmp_set_var_typed_value(var, ASN_INTEGER,
                         (char*)&context->saHpiSoftwareEventTextType,
                         sizeof(context->saHpiSoftwareEventTextType) );
        break;
    
        case COLUMN_SAHPISOFTWAREEVENTTEXTLANGUAGE:
            /** SaHpiTextLanguage = ASN_INTEGER */
            snmp_set_var_typed_value(var, ASN_INTEGER,
                         (char*)&context->saHpiSoftwareEventTextLanguage,
                         sizeof(context->saHpiSoftwareEventTextLanguage) );
        break;
    
        case COLUMN_SAHPISOFTWAREEVENTTEXT:
            /** SaHpiText = ASN_OCTET_STR */
            snmp_set_var_typed_value(var, ASN_OCTET_STR,
                         (char*)&context->saHpiSoftwareEventText,
                         context->saHpiSoftwareEventText_len );
        break;
    
    default: /** We shouldn't get here */
        snmp_log(LOG_ERR, "unknown column in "
                 "saHpiSoftwareEventTable_get_value\n");
        return SNMP_ERR_GENERR;
    }
    return SNMP_ERR_NOERROR;
}
Example #11
0
/** handles requests for the raidSetTable table */
int
raidSetTable_handler(
    netsnmp_mib_handler               *handler,
    netsnmp_handler_registration      *reginfo,
    netsnmp_agent_request_info        *reqinfo,
    netsnmp_request_info              *requests) {

    netsnmp_request_info       *request;
    netsnmp_table_request_info *table_info;
    struct raidSetTable_entry          *table_entry;

    switch (reqinfo->mode) {
        /*
         * Read-support (also covers GetNext requests)
         */
    case MODE_GET:
        update_setlist_if_necessary();
        for (request=requests; request; request=request->next) {
            table_entry = (struct raidSetTable_entry *)
                              netsnmp_extract_iterator_context(request);
            table_info  =     netsnmp_extract_table_info(      request);
    
            switch (table_info->colnum) {
            case COLUMN_RAIDSETNAME:
                if ( !table_entry ) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
                                 (u_char*)table_entry->raidSetName,
                                          table_entry->raidSetName_len);
                break;
            case COLUMN_RAIDSETTYPE:
                if ( !table_entry ) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
                                 (u_char*)table_entry->raidSetType,
                                          table_entry->raidSetType_len);
                break;
            case COLUMN_RAIDSETSIZE:
                if ( !table_entry ) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_GAUGE,
                                            table_entry->raidSetSize);
                break;
            case COLUMN_RAIDSETUNUSED:
                if ( !table_entry ) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_GAUGE,
                                            table_entry->raidSetUnused);
                break;
            case COLUMN_RAIDSETCOMMENTS:
                if ( !table_entry ) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
                                 (u_char*)table_entry->raidSetComments,
                                          table_entry->raidSetComments_len);
                break;
            default:
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_NOSUCHOBJECT);
                break;
            }
        }
        break;

    }
    return SNMP_ERR_NOERROR;
}
Example #12
0
        /*
         * Handle the response from an AgentX subagent,
         *   merging the answers back into the original query
         */
int
agentx_got_response(int operation,
                    netsnmp_session * session,
                    int reqid, netsnmp_pdu *pdu, void *magic)
{
    netsnmp_delegated_cache *cache = (netsnmp_delegated_cache *) magic;
    int             i, ret;
    netsnmp_request_info *requests, *request;
    netsnmp_variable_list *var;
    netsnmp_session *ax_session;

    cache = netsnmp_handler_check_cache(cache);
    if (!cache) {
        DEBUGMSGTL(("agentx/master", "response too late on session %08p\n",
                    session));
        return 0;
    }
    requests = cache->requests;

    switch (operation) {
    case NETSNMP_CALLBACK_OP_TIMED_OUT:{
            void           *s = snmp_sess_pointer(session);
            DEBUGMSGTL(("agentx/master", "timeout on session %08p\n",
                        session));

            /*
             * This is a bit sledgehammer because the other sessions on this
             * transport may be okay (e.g. some thread in the subagent has
             * wedged, but the others are alright).  OTOH the overwhelming
             * probability is that the whole agent has died somehow.  
             */

            if (s != NULL) {
                netsnmp_transport *t = snmp_sess_transport(s);
                close_agentx_session(session, -1);

                if (t != NULL) {
                    DEBUGMSGTL(("agentx/master", "close transport\n"));
                    t->f_close(t);
                } else {
                    DEBUGMSGTL(("agentx/master", "NULL transport??\n"));
                }
            } else {
                DEBUGMSGTL(("agentx/master", "NULL sess_pointer??\n"));
            }
            netsnmp_handler_mark_requests_as_delegated(requests,
                                                       REQUEST_IS_NOT_DELEGATED);
            netsnmp_set_request_error(cache->reqinfo, requests, /* XXXWWW: should be index=0 */
                                      SNMP_ERR_GENERR);
            ax_session = (netsnmp_session *) cache->localinfo;
            netsnmp_free_agent_snmp_session_by_session(ax_session, NULL);
            netsnmp_free_delegated_cache(cache);
            return 0;
        }

    case NETSNMP_CALLBACK_OP_DISCONNECT:
    case NETSNMP_CALLBACK_OP_SEND_FAILED:
        if (operation == NETSNMP_CALLBACK_OP_DISCONNECT) {
            DEBUGMSGTL(("agentx/master", "disconnect on session %08p\n",
                        session));
        } else {
            DEBUGMSGTL(("agentx/master", "send failed on session %08p\n",
                        session));
        }
        close_agentx_session(session, -1);
        netsnmp_handler_mark_requests_as_delegated(requests,
                                                   REQUEST_IS_NOT_DELEGATED);
        netsnmp_set_request_error(cache->reqinfo, requests,     /* XXXWWW: should be index=0 */
                                  SNMP_ERR_GENERR);
        netsnmp_free_delegated_cache(cache);
        return 0;

    case NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE:
        /*
         * This session is alive 
         */
        CLEAR_SNMP_STRIKE_FLAGS(session->flags);
        break;
    default:
        snmp_log(LOG_ERR, "Unknown operation %d in agentx_got_response\n",
                 operation);
        netsnmp_free_delegated_cache(cache);
        return 0;
    }

    DEBUGMSGTL(("agentx/master", "got response errstat=%d, (req=0x%x,trans="
                "0x%x,sess=0x%x)\n",
                pdu->errstat,pdu->reqid,pdu->transid, pdu->sessid));

    if (pdu->errstat != AGENTX_ERR_NOERROR) {
        /* [RFC 2471 - 7.2.5.2.]
         *
         *   1) For any received AgentX response PDU, if res.error is
         *      not `noError', the SNMP response PDU's error code is
         *      set to this value.  If res.error contains an AgentX
         *      specific value (e.g.  `parseError'), the SNMP response
         *      PDU's error code is set to a value of genErr instead.
         *      Also, the SNMP response PDU's error index is set to
         *      the index of the variable binding corresponding to the
         *      failed VarBind in the subagent's AgentX response PDU.
         *
         *      All other AgentX response PDUs received due to
         *      processing this SNMP request are ignored.  Processing
         *      is complete; the SNMP Response PDU is ready to be sent
         *      (see section 7.2.6, "Sending the SNMP Response-PDU").
         */
        int err;

        DEBUGMSGTL(("agentx/master",
                    "agentx_got_response() error branch\n"));

        switch (pdu->errstat) {
        case AGENTX_ERR_PARSE_FAILED:
        case AGENTX_ERR_REQUEST_DENIED:
        case AGENTX_ERR_PROCESSING_ERROR:
            err = SNMP_ERR_GENERR;
            break;
        default:
            err = pdu->errstat;
        }

        ret = 0;
        for (request = requests, i = 1; request;
             request = request->next, i++) {
            if (request->index == pdu->errindex) {
                /*
                 * mark this one as the one generating the error
                 */
                netsnmp_set_request_error(cache->reqinfo, request,
                                          err);
                ret = 1;
            }
            request->delegated = REQUEST_IS_NOT_DELEGATED;
        }
        if (!ret) {
            /*
             * ack, unknown, mark the first one
             */
            netsnmp_set_request_error(cache->reqinfo, requests,
                                      SNMP_ERR_GENERR);
        }
        netsnmp_free_delegated_cache(cache);
        DEBUGMSGTL(("agentx/master", "end error branch\n"));
        return 1;
    } else if (cache->reqinfo->mode == MODE_GET ||
               cache->reqinfo->mode == MODE_GETNEXT ||
               cache->reqinfo->mode == MODE_GETBULK) {
        /*
         * Replace varbinds for data request types, but not SETs.  
         */
        DEBUGMSGTL(("agentx/master",
                    "agentx_got_response() beginning...\n"));
        for (var = pdu->variables, request = requests; request && var;
             request = request->next, var = var->next_variable) {
            /*
             * Otherwise, process successful requests
             */
            DEBUGMSGTL(("agentx/master",
                        "  handle_agentx_response: processing: "));
            DEBUGMSGOID(("agentx/master", var->name, var->name_length));
            DEBUGMSG(("agentx/master", "\n"));
            if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_VERBOSE)) {
                DEBUGMSGTL(("snmp_agent", "    >> "));
                DEBUGMSGVAR(("snmp_agent", var));
                DEBUGMSG(("snmp_agent", "\n"));
            }

            /*
             * update the oid in the original request 
             */
            if (var->type != SNMP_ENDOFMIBVIEW) {
                snmp_set_var_typed_value(request->requestvb, var->type,
                                         var->val.string, var->val_len);
                snmp_set_var_objid(request->requestvb, var->name,
                                   var->name_length);
            }
            request->delegated = REQUEST_IS_NOT_DELEGATED;
        }

        if (request || var) {
            /*
             * ack, this is bad.  The # of varbinds don't match and
             * there is no way to fix the problem 
             */
            snmp_log(LOG_ERR,
                     "response to agentx request illegal.  We're screwed.\n");
            netsnmp_set_request_error(cache->reqinfo, requests,
                                      SNMP_ERR_GENERR);
        }

        if (cache->reqinfo->mode == MODE_GETBULK)
            netsnmp_bulk_to_next_fix_requests(requests);
    } else {
        /*
         * mark set requests as handled 
         */
        for (request = requests; request; request = request->next) {
            request->delegated = REQUEST_IS_NOT_DELEGATED;
        }
    }
    DEBUGMSGTL(("agentx/master",
                "handle_agentx_response() finishing...\n"));
    netsnmp_free_delegated_cache(cache);
    return 1;
}
Example #13
0
static int
handle_ipForwarding(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info   *reqinfo,
                          netsnmp_request_info         *requests)
{
    int      rc;
    u_long   value;

    /* We are never called for a GETNEXT if it's registered as a
       "instance", as it's "magically" handled for us.  */

    /* a instance handler also only hands us one request at a time, so
       we don't need to loop over a list of requests; we'll only get one. */

    switch(reqinfo->mode) {

        case MODE_GET:
            rc = netsnmp_arch_ip_scalars_ipForwarding_get(&value);
            if (rc != 0) {
                netsnmp_set_request_error(reqinfo, requests,
                                      SNMP_NOSUCHINSTANCE);
            }
            else {
                value = value ? 1 : 2;
                snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                     (u_char *)&value, sizeof(value));
            }
            break;

#ifndef NETSNMP_NO_WRITE_SUPPORT
        /*
         * SET REQUEST
         *
         * multiple states in the transaction.  See:
         * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
         */
        case MODE_SET_RESERVE1:
            break;

        case MODE_SET_RESERVE2:
            /*
             * store old info for undo later
             */
            rc = netsnmp_arch_ip_scalars_ipForwarding_get(&value);
            if (rc < 0) {
                netsnmp_set_request_error(reqinfo, requests,
                                          SNMP_ERR_NOCREATION);
            } else {
                u_long *value_save;
                memdup((u_char **) & value_save, (u_char *) &value,
                       sizeof(value));
                if ( NULL == value_save )
                    netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
                else
                    netsnmp_request_add_list_data(requests,
                                                  netsnmp_create_data_list
                                                  ("ipfw", value_save,
                                                  free));
	    }
            break;

        case MODE_SET_FREE:
            /* XXX: free resources allocated in RESERVE1 and/or
               RESERVE2.  Something failed somewhere, and the states
               below won't be called. */
            break;

        case MODE_SET_ACTION:
            /* XXX: perform the value change here */
            value =  *(requests->requestvb->val.integer);
            rc = netsnmp_arch_ip_scalars_ipForwarding_set(value);
            if ( 0 != rc ) {
                netsnmp_set_request_error(reqinfo, requests, rc);
            }
            break;

        case MODE_SET_COMMIT:
            break;

        case MODE_SET_UNDO:
             value =
                 *((u_long *) netsnmp_request_get_list_data(requests,
                                                            "ipfw"));
             rc = netsnmp_arch_ip_scalars_ipForwarding_set(value);
             if ( 0 != rc ) {
                 netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED);
             }
             break;
#endif /* !NETSNMP_NO_WRITE_SUPPORT */

        default:
            /* we should never get here, so this is a really bad error */
            snmp_log(LOG_ERR, "unknown mode (%d) in handle_ipForwarding\n", reqinfo->mode );
            return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}
Example #14
0
static int
handle_ipv6IpDefaultHopLimit(netsnmp_mib_handler *handler,
                             netsnmp_handler_registration *reginfo,
                             netsnmp_agent_request_info *reqinfo,
                             netsnmp_request_info *requests)
{
    u_long          value;
    int             rc;
    /*
     * We are never called for a GETNEXT if it's registered as a
     * "instance", as it's "magically" handled for us.  
     */

    /*
     * a instance handler also only hands us one request at a time, so
     * we don't need to loop over a list of requests; we'll only get one. 
     */

    switch (reqinfo->mode) {

    case MODE_GET:

        rc = netsnmp_arch_ip_scalars_ipv6IpDefaultHopLimit_get(&value);
        if (rc != 0) {
            netsnmp_set_request_error(reqinfo, requests,
                                  SNMP_NOSUCHINSTANCE);
        }
        else {
            snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                 (u_char *)&value, sizeof(value));
        }

        break;

#ifdef NOTYET
        /*
         * SET REQUEST
         *
         * multiple states in the transaction.  See:
         * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
         */
    case MODE_SET_RESERVE1:
        /*
         * or you could use netsnmp_check_vb_type_and_size instead 
         */
        rc = netsnmp_check_vb_type(requests->requestvb, ASN_INTEGER);
        if (rc != SNMP_ERR_NOERROR) {
            netsnmp_set_request_error(reqinfo, requests, rc);
        }
        break;

    case MODE_SET_RESERVE2:
        /*
         * XXX malloc "undo" storage buffer 
         */
        if ( /* XXX if malloc, or whatever, failed: */ ) {
            netsnmp_set_request_error(reqinfo, requests,
                                      SNMP_ERR_RESOURCEUNAVAILABLE);
        }
        break;

    case MODE_SET_FREE:
        /*
         * XXX: free resources allocated in RESERVE1 and/or
         * RESERVE2.  Something failed somewhere, and the states
         * below won't be called. 
         */
        break;

    case MODE_SET_ACTION:
        /*
         * XXX: perform the value change here 
         */
        if ( /* XXX: error? */ ) {
            netsnmp_set_request_error(reqinfo, requests, /* some error */
                                      );
        }
        break;

    case MODE_SET_COMMIT:
        /*
         * XXX: delete temporary storage 
         */
        if ( /* XXX: error? */ ) {
            /*
             * try _really_really_ hard to never get to this point 
             */
            netsnmp_set_request_error(reqinfo, requests,
                                      SNMP_ERR_COMMITFAILED);
        }
        break;

    case MODE_SET_UNDO:
        /*
         * XXX: UNDO and return to previous value for the object 
         */
        if ( /* XXX: error? */ ) {
            /*
             * try _really_really_ hard to never get to this point 
             */
            netsnmp_set_request_error(reqinfo, requests,
                                      SNMP_ERR_UNDOFAILED);
        }
        break;
#endif

    default:
        /*
         * we should never get here, so this is a really bad error 
         */
        snmp_log(LOG_ERR,
                 "unknown mode (%d) in handle_ipv6IpDefaultHopLimit\n",
                 reqinfo->mode);
        return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}
Example #15
0
int instance_get_set_handler(netsnmp_mib_handler * handler,
                             netsnmp_handler_registration * reginfo,
                             netsnmp_agent_request_info * reqinfo,
                             netsnmp_request_info * requests)
{

  snmp_adm_type_union var;
  unsigned char type;
  register_info *info = NULL;
  int branch, num_stat_conf, err = 0, err_fct;
  char str[256];
  unsigned int tmp_it;

        /** XXX
	 *  Yet another tree structure specific computation
	 */
  /* what node do you want? */
  num_stat_conf = reginfo->rootoid[reginfo->rootoid_len - 3];
  branch = reginfo->rootoid[reginfo->rootoid_len - 4];

  /* look for our get_set */
  for(info = register_info_list; info; info = info->next)
    if(info->type == GET_SET &&
       info->function_info.get_set->num == num_stat_conf &&
       info->function_info.get_set->branch == branch)
      break;

  if(!info)
    {                           /* not found */
      netsnmp_request_set_error(requests, SNMP_ERR_GENERR);
      return SNMP_ERR_GENERR;
    }

  type = info->function_info.get_set->type;

  switch (reqinfo->mode)
    {
    case MODE_GET:
      /*
       * data requests
       */
      /* call the function */
      err =
          info->function_info.get_set->getter(&var, info->function_info.get_set->opt_arg);
      if(err)
        {
          snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
                                   (u_char *) "SNMP_ADM_ERROR", strlen("SNMP_ADM_ERROR"));

          return SNMP_ERR_NOERROR;
        }
      switch (type)
        {
        case SNMP_ADM_INTEGER:
          snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                   (u_char *) & (var.integer), sizeof(var.integer));
          break;
        case SNMP_ADM_STRING:
          snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
                                   (u_char *) var.string, strlen((char *)var.string));
          break;
        case SNMP_ADM_REAL:
          err = real2str(str, var.real);
          if(!err)
            snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
                                     (u_char *) str, strlen(str));
          else
            netsnmp_request_set_error(requests, SNMP_ERR_BADVALUE);
          break;
        case SNMP_ADM_BIGINT:
          err = big2str(str, var.bigint);
          if(!err)
            snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
                                     (u_char *) str, strlen(str));
          else
            netsnmp_request_set_error(requests, SNMP_ERR_BADVALUE);
          break;
        case SNMP_ADM_TIMETICKS:
          tmp_it = (var.time) * 100;

          snmp_set_var_typed_value(requests->requestvb, ASN_TIMETICKS,
                                   (u_char *) & (tmp_it), sizeof(tmp_it));
          break;

        default:
          netsnmp_request_set_error(requests, SNMP_ERR_BADVALUE);
        }

      break;
    case MODE_SET_ACTION:
      switch (type)
        {
        case SNMP_ADM_INTEGER:
          var.integer = *(int *)requests->requestvb->val.integer;
          break;
        case SNMP_ADM_STRING:
          strncpy(var.string, (char *)(requests->requestvb->val.string),
                  sizeof(var.string));
          break;
        case SNMP_ADM_REAL:
          err = str2real(&(var.real), (char *)(requests->requestvb->val.string));
          break;
        case SNMP_ADM_BIGINT:
          err = str2big(&(var.bigint), (char *)(requests->requestvb->val.string));
          break;
        case SNMP_ADM_TIMETICKS:
          tmp_it = *(unsigned int *)requests->requestvb->val.integer;
          var.time = tmp_it / 100;
          break;
        default:
          netsnmp_request_set_error(requests, SNMP_ERR_BADVALUE);
        }

      if(!err)
        {
          /* call the function */
          err_fct =
              info->function_info.get_set->setter(&var,
                                                  info->function_info.get_set->opt_arg);

          if(err_fct)
            netsnmp_request_set_error(requests, SNMP_ERR_BADVALUE);
        }
      else
        netsnmp_request_set_error(requests, SNMP_ERR_BADVALUE);
      break;
    }

  return SNMP_ERR_NOERROR;
}
Example #16
0
/** @internal Implements the stash_cache handler */
int
netsnmp_stash_cache_helper(netsnmp_mib_handler *handler,
                           netsnmp_handler_registration *reginfo,
                           netsnmp_agent_request_info *reqinfo,
                           netsnmp_request_info *requests)
{
    netsnmp_cache            *cache;
    netsnmp_stash_cache_info *cinfo;
    netsnmp_oid_stash_node   *cnode;
    netsnmp_variable_list    *cdata;
    netsnmp_request_info     *request;

    DEBUGMSGTL(("helper:stash_cache", "Got request\n"));

    cache = netsnmp_cache_reqinfo_extract( reqinfo, reginfo->handlerName );
    if (!cache) {
        DEBUGMSGTL(("helper:stash_cache", "No cache structure\n"));
        return SNMP_ERR_GENERR;
    }
    cinfo = (netsnmp_stash_cache_info *) cache->magic;

    switch (reqinfo->mode) {

    case MODE_GET:
        DEBUGMSGTL(("helper:stash_cache", "Processing GET request\n"));
        for(request = requests; request; request = request->next) {
            cdata =
                netsnmp_oid_stash_get_data(cinfo->cache,
                                           requests->requestvb->name,
                                           requests->requestvb->name_length);
            if (cdata && cdata->val.string && cdata->val_len) {
                DEBUGMSGTL(("helper:stash_cache", "Found cached GET varbind\n"));
                DEBUGMSGOID(("helper:stash_cache", cdata->name, cdata->name_length));
                DEBUGMSG(("helper:stash_cache", "\n"));
                snmp_set_var_typed_value(request->requestvb, cdata->type,
                                         cdata->val.string, cdata->val_len);
            }
        }
        return SNMP_ERR_NOERROR;
        break;

    case MODE_GETNEXT:
        DEBUGMSGTL(("helper:stash_cache", "Processing GETNEXT request\n"));
        for(request = requests; request; request = request->next) {
            cnode =
                netsnmp_oid_stash_getnext_node(cinfo->cache,
                                               requests->requestvb->name,
                                               requests->requestvb->name_length);
            if (cnode && cnode->thedata) {
                cdata = cnode->thedata;
                if (cdata->val.string && cdata->name && cdata->name_length) {
                    DEBUGMSGTL(("helper:stash_cache", "Found cached GETNEXT varbind\n"));
                    DEBUGMSGOID(("helper:stash_cache", cdata->name, cdata->name_length));
                    DEBUGMSG(("helper:stash_cache", "\n"));
                    snmp_set_var_typed_value(request->requestvb, cdata->type,
                                             cdata->val.string, cdata->val_len);
                    snmp_set_var_objid(request->requestvb, cdata->name,
                                       cdata->name_length);
                }
            }
        }
        return SNMP_ERR_NOERROR;
        break;

    default:
        cinfo->cache_valid = 0;
        return netsnmp_call_next_handler(handler, reginfo, reqinfo,
                                         requests);
    }
    return SNMP_ERR_GENERR;     /* should never get here */
}
Example #17
0
static int mib_ipRouteTable_handler(netsnmp_mib_handler *handler,
                    netsnmp_handler_registration *reginfo,
                    netsnmp_agent_request_info *reqinfo,
                    netsnmp_request_info *requests)
{
    netsnmp_request_info       *request;
    netsnmp_table_request_info *table_req_info;
    struct ipRouteTable_entry *table_entry;
    int                         ret;
    switch (reqinfo->mode)
    {
    case MODE_GET:
        for (request=requests; request; request=request->next)
        {
            table_entry = (struct ipRouteTable_entry *)
                              netsnmp_extract_iterator_context(request);
            table_req_info  = netsnmp_extract_table_info(request);
            if(NULL == table_req_info)
            {
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_ERR_NOACCESS);
                continue;
            }

            switch (table_req_info->colnum)
            {
            case COLUMN_IPROUTEDEST:
                if ( !table_entry )
                {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_IPADDRESS,
                                            htonl(table_entry->ipRouteDest));
                break;

            case COLUMN_IPROUTEIFINDEX:
                if ( !table_entry )
                {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
                                            table_entry->ipRouteIfIndex);
                break;

            case COLUMN_IPROUTEMETRIC1:
                if ( !table_entry )
                {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
                                            table_entry->ipRouteMetric1);
                break;

            case COLUMN_IPROUTEMETRIC2:
                if ( !table_entry )
                {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
                                            table_entry->ipRouteMetric2);
                break;

            case COLUMN_IPROUTEMETRIC3:
                if ( !table_entry )
                {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
                                            table_entry->ipRouteMetric3);
                break;

            case COLUMN_IPROUTEMETRIC4:
                if ( !table_entry )
                {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
                                            table_entry->ipRouteMetric4);
                break;

            case COLUMN_IPROUTENEXTHOP:
                if ( !table_entry )
                {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_IPADDRESS,
                                            htonl(table_entry->ipRouteNextHop));
                break;

            case COLUMN_IPROUTETYPE:
                if ( !table_entry )
                {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
                                            table_entry->ipRouteType);
                break;

            case COLUMN_IPROUTEPROTO:
                if ( !table_entry )
                {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
                                            table_entry->ipRouteProto);
                break;

            case COLUMN_IPROUTEAGE:
                if ( !table_entry )
                {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
                                            table_entry->ipRouteAge);
                break;

            case COLUMN_IPROUTEMASK:
                if ( !table_entry )
                {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_IPADDRESS,
                                            htonl(table_entry->ipRouteMask));
                break;

            case COLUMN_IPROUTEMETRIC5:
                if ( !table_entry )
                {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
                                            table_entry->ipRouteMetric5);
                break;

            case COLUMN_IPROUTEINFO:
                if ( !table_entry )
                {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_value( request->requestvb, ASN_OBJECT_ID,
                                 (u_char*)table_entry->ipRouteInfo,
                                          table_entry->ipRouteInfo_len);
                break;

            default:
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_NOSUCHOBJECT);
                break;

            }
        }
        break;
    case MODE_SET_RESERVE1:
        for (request=requests; request; request=request->next)
        {
            table_entry = (struct ipRouteTable_entry *)
                              netsnmp_extract_iterator_context(request);
            table_req_info  = netsnmp_extract_table_info(request);
            if(NULL == table_req_info)
            {
                netsnmp_set_request_error( reqinfo, request,
                                           SNMP_ERR_NOACCESS );
                return SNMP_ERR_NOERROR;
            }

            switch (table_req_info->colnum)
            {
            case COLUMN_IPROUTEDEST:
                ret = netsnmp_check_vb_type_and_size(
                          request->requestvb, ASN_IPADDRESS, sizeof(table_entry->ipRouteDest));
                if ( ret != SNMP_ERR_NOERROR )
                {
                    netsnmp_set_request_error( reqinfo, request, ret );
                    return SNMP_ERR_NOERROR;
                }
                break;

            case COLUMN_IPROUTEIFINDEX:
                ret = netsnmp_check_vb_int( request->requestvb );
                if ( ret != SNMP_ERR_NOERROR )
                {
                    netsnmp_set_request_error( reqinfo, request, ret );
                    return SNMP_ERR_NOERROR;
                }
                break;

            case COLUMN_IPROUTEMETRIC1:
                ret = netsnmp_check_vb_int( request->requestvb );
                if ( ret != SNMP_ERR_NOERROR )
                {
                    netsnmp_set_request_error( reqinfo, request, ret );
                    return SNMP_ERR_NOERROR;
                }
                break;

            case COLUMN_IPROUTEMETRIC2:
                ret = netsnmp_check_vb_int( request->requestvb );
                if ( ret != SNMP_ERR_NOERROR )
                {
                    netsnmp_set_request_error( reqinfo, request, ret );
                    return SNMP_ERR_NOERROR;
                }
                break;

            case COLUMN_IPROUTEMETRIC3:
                ret = netsnmp_check_vb_int( request->requestvb );
                if ( ret != SNMP_ERR_NOERROR )
                {
                    netsnmp_set_request_error( reqinfo, request, ret );
                    return SNMP_ERR_NOERROR;
                }
                break;

            case COLUMN_IPROUTEMETRIC4:
                ret = netsnmp_check_vb_int( request->requestvb );
                if ( ret != SNMP_ERR_NOERROR )
                {
                    netsnmp_set_request_error( reqinfo, request, ret );
                    return SNMP_ERR_NOERROR;
                }
                break;

            case COLUMN_IPROUTENEXTHOP:
                ret = netsnmp_check_vb_type_and_size(
                          request->requestvb, ASN_IPADDRESS, sizeof(table_entry->ipRouteNextHop));
                if ( ret != SNMP_ERR_NOERROR )
                {
                    netsnmp_set_request_error( reqinfo, request, ret );
                    return SNMP_ERR_NOERROR;
                }
                break;

            case COLUMN_IPROUTETYPE:
                ret = netsnmp_check_vb_int( request->requestvb );
                if ( ret != SNMP_ERR_NOERROR )
                {
                    netsnmp_set_request_error( reqinfo, request, ret );
                    return SNMP_ERR_NOERROR;
                }
                break;

            case COLUMN_IPROUTEAGE:
                ret = netsnmp_check_vb_int( request->requestvb );
                if ( ret != SNMP_ERR_NOERROR )
                {
                    netsnmp_set_request_error( reqinfo, request, ret );
                    return SNMP_ERR_NOERROR;
                }
                break;

            case COLUMN_IPROUTEMASK:
                ret = netsnmp_check_vb_type_and_size(
                          request->requestvb, ASN_IPADDRESS, sizeof(table_entry->ipRouteMask));
                if ( ret != SNMP_ERR_NOERROR )
                {
                    netsnmp_set_request_error( reqinfo, request, ret );
                    return SNMP_ERR_NOERROR;
                }
                break;

            case COLUMN_IPROUTEMETRIC5:
                ret = netsnmp_check_vb_int( request->requestvb );
                if ( ret != SNMP_ERR_NOERROR )
                {
                    netsnmp_set_request_error( reqinfo, request, ret );
                    return SNMP_ERR_NOERROR;
                }
                break;

            default:
                netsnmp_set_request_error( reqinfo, request,
                                           SNMP_ERR_NOTWRITABLE );
                return SNMP_ERR_NOERROR;
            }
        }
        break;

    case MODE_SET_RESERVE2:
        break;

    case MODE_SET_FREE:
        break;

    case MODE_SET_ACTION:
        for (request=requests; request; request=request->next)
        {
            table_entry = (struct ipRouteTable_entry *)
                              netsnmp_extract_iterator_context(request);
            table_req_info  = netsnmp_extract_table_info(request);

            switch (table_req_info->colnum)
            {
            case COLUMN_IPROUTEDEST:
                table_entry->old_ipRouteDest = table_entry->ipRouteDest;
                table_entry->ipRouteDest     = *request->requestvb->val.integer;
                break;

            case COLUMN_IPROUTEIFINDEX:
                table_entry->old_ipRouteIfIndex = table_entry->ipRouteIfIndex;
                table_entry->ipRouteIfIndex     = *request->requestvb->val.integer;
                break;

            case COLUMN_IPROUTEMETRIC1:
                table_entry->old_ipRouteMetric1 = table_entry->ipRouteMetric1;
                table_entry->ipRouteMetric1     = *request->requestvb->val.integer;
                break;

            case COLUMN_IPROUTEMETRIC2:
                table_entry->old_ipRouteMetric2 = table_entry->ipRouteMetric2;
                table_entry->ipRouteMetric2     = *request->requestvb->val.integer;
                break;

            case COLUMN_IPROUTEMETRIC3:
                table_entry->old_ipRouteMetric3 = table_entry->ipRouteMetric3;
                table_entry->ipRouteMetric3     = *request->requestvb->val.integer;
                break;

            case COLUMN_IPROUTEMETRIC4:
                table_entry->old_ipRouteMetric4 = table_entry->ipRouteMetric4;
                table_entry->ipRouteMetric4     = *request->requestvb->val.integer;
                break;

            case COLUMN_IPROUTENEXTHOP:
                table_entry->old_ipRouteNextHop = table_entry->ipRouteNextHop;
                table_entry->ipRouteNextHop     = *request->requestvb->val.integer;
                break;

            case COLUMN_IPROUTETYPE:
                table_entry->old_ipRouteType = table_entry->ipRouteType;
                table_entry->ipRouteType     = *request->requestvb->val.integer;
                break;

            case COLUMN_IPROUTEAGE:
                table_entry->old_ipRouteAge = table_entry->ipRouteAge;
                table_entry->ipRouteAge     = *request->requestvb->val.integer;
                break;

            case COLUMN_IPROUTEMASK:
                table_entry->old_ipRouteMask = table_entry->ipRouteMask;
                table_entry->ipRouteMask     = *request->requestvb->val.integer;
                break;

            case COLUMN_IPROUTEMETRIC5:
                table_entry->old_ipRouteMetric5 = table_entry->ipRouteMetric5;
                table_entry->ipRouteMetric5     = *request->requestvb->val.integer;
                break;

            }
        }
        break;

    case MODE_SET_COMMIT:
        break;

    case MODE_SET_UNDO:
        for (request=requests; request; request=request->next)
        {
            table_entry = (struct ipRouteTable_entry *)
                              netsnmp_extract_iterator_context(request);
            table_req_info  = netsnmp_extract_table_info( request);

            switch (table_req_info->colnum)
            {
            case COLUMN_IPROUTEDEST:
                table_entry->ipRouteDest     = table_entry->old_ipRouteDest;
                table_entry->old_ipRouteDest = 0;
                break;

            case COLUMN_IPROUTEIFINDEX:
                table_entry->ipRouteIfIndex     = table_entry->old_ipRouteIfIndex;
                table_entry->old_ipRouteIfIndex = 0;
                break;

            case COLUMN_IPROUTEMETRIC1:
                table_entry->ipRouteMetric1     = table_entry->old_ipRouteMetric1;
                table_entry->old_ipRouteMetric1 = 0;
                break;

            case COLUMN_IPROUTEMETRIC2:
                table_entry->ipRouteMetric2     = table_entry->old_ipRouteMetric2;
                table_entry->old_ipRouteMetric2 = 0;
                break;

            case COLUMN_IPROUTEMETRIC3:
                table_entry->ipRouteMetric3     = table_entry->old_ipRouteMetric3;
                table_entry->old_ipRouteMetric3 = 0;
                break;

            case COLUMN_IPROUTEMETRIC4:
                table_entry->ipRouteMetric4     = table_entry->old_ipRouteMetric4;
                table_entry->old_ipRouteMetric4 = 0;
                break;

            case COLUMN_IPROUTENEXTHOP:
                table_entry->ipRouteNextHop     = table_entry->old_ipRouteNextHop;
                table_entry->old_ipRouteNextHop = 0;
                break;

            case COLUMN_IPROUTETYPE:
                table_entry->ipRouteType     = table_entry->old_ipRouteType;
                table_entry->old_ipRouteType = 0;
                break;

            case COLUMN_IPROUTEAGE:
                table_entry->ipRouteAge     = table_entry->old_ipRouteAge;
                table_entry->old_ipRouteAge = 0;
                break;

            case COLUMN_IPROUTEMASK:
                table_entry->ipRouteMask     = table_entry->old_ipRouteMask;
                table_entry->old_ipRouteMask = 0;
                break;

            case COLUMN_IPROUTEMETRIC5:
                table_entry->ipRouteMetric5     = table_entry->old_ipRouteMetric5;
                table_entry->old_ipRouteMetric5 = 0;
                break;

            }
        }
        break;

    }
    return SNMP_ERR_NOERROR;
}
Example #18
0
int
handle_usmDHParameters (netsnmp_mib_handler * handler,
                        netsnmp_handler_registration * reginfo,
                        netsnmp_agent_request_info * reqinfo, netsnmp_request_info * requests)
{
    /*
     * We are never called for a GETNEXT if it's registered as a
     * "instance", as it's "magically" handled for us.  
     */

    static unsigned char *cp = NULL;

    static DH *dh_tmpp = NULL;

    int cp_len;

    /*
     * a instance handler also only hands us one request at a time, so
     * we don't need to loop over a list of requests; we'll only get one. 
     */

    switch (reqinfo->mode)
    {

        case MODE_GET:
            if (cp)
            {
                free (cp);
                cp = NULL;
            }
            cp_len = i2d_DHparams (dh_params, &cp);
            if (cp_len > 0)
                snmp_set_var_typed_value (requests->requestvb, ASN_OCTET_STR, (u_char *) cp, cp_len);
            break;

            /*
             * SET REQUEST
             *
             * multiple states in the transaction.  See:
             * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
             */
        case MODE_SET_RESERVE1:
            break;

        case MODE_SET_RESERVE2:
            cp = requests->requestvb->val.string;
            dh_tmpp = d2i_DHparams (NULL, (const unsigned char **) (void *) &cp, requests->requestvb->val_len);
            if (!dh_tmpp)
            {
                netsnmp_set_request_error (reqinfo, requests, SNMP_ERR_WRONGVALUE);
            }
            if (cp - requests->requestvb->val.string != requests->requestvb->val_len)
            {
                /* value too long; we didn't parse the whole thing */
                netsnmp_set_request_error (reqinfo, requests, SNMP_ERR_WRONGVALUE);
                DH_free (dh_tmpp);
                dh_tmpp = NULL;
            }
            break;

        case MODE_SET_FREE:
        case MODE_SET_COMMIT:
            DH_free (dh_tmpp);
            dh_tmpp = NULL;
            break;

        case MODE_SET_ACTION:
            {
                DH *tmpp;

                tmpp = dh_params;
                dh_params = dh_tmpp;
                dh_tmpp = tmpp;
                break;
            }

        case MODE_SET_UNDO:
            {
                DH_free (dh_params);    /* free new value */
                dh_params = dh_tmpp;    /* restore old value */
                dh_tmpp = NULL;
                break;
            }

        default:
            /*
             * we should never get here, so this is a really bad error 
             */
            return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}
Example #19
0
/************************************************************
 * saHpiWatchdogTable_get_value
 */
int
saHpiWatchdogTable_get_value(netsnmp_request_info *request,
                             netsnmp_index * item,
                             netsnmp_table_request_info *table_info)
{
    netsnmp_variable_list *var = request->requestvb;
    saHpiWatchdogTable_context *context =
        (saHpiWatchdogTable_context *) item;

    switch (table_info->colnum) {

    case COLUMN_SAHPIWATCHDOGNUM:
            /** UNSIGNED32 = ASN_UNSIGNED */
        snmp_set_var_typed_value(var, ASN_UNSIGNED,
                                 (char *) &context->saHpiWatchdogNum,
                                 sizeof(context->saHpiWatchdogNum));
        break;

    case COLUMN_SAHPIWATCHDOGLOG:
            /** TruthValue = ASN_INTEGER */
        snmp_set_var_typed_value(var, ASN_INTEGER,
                                 (char *) &context->saHpiWatchdogLog,
                                 sizeof(context->saHpiWatchdogLog));
        break;

    case COLUMN_SAHPIWATCHDOGRUNNING:
            /** TruthValue = ASN_INTEGER */
        snmp_set_var_typed_value(var, ASN_INTEGER,
                                 (char *) &context->saHpiWatchdogRunning,
                                 sizeof(context->saHpiWatchdogRunning));
        break;

    case COLUMN_SAHPIWATCHDOGTIMERUSE:
            /** INTEGER = ASN_INTEGER */
        snmp_set_var_typed_value(var, ASN_INTEGER,
                                 (char *) &context->saHpiWatchdogTimerUse,
                                 sizeof(context->saHpiWatchdogTimerUse));
        break;

    case COLUMN_SAHPIWATCHDOGTIMERACTION:
            /** INTEGER = ASN_INTEGER */
        snmp_set_var_typed_value(var, ASN_INTEGER,
                                 (char *) &context->
                                 saHpiWatchdogTimerAction,
                                 sizeof(context->
                                        saHpiWatchdogTimerAction));
        break;

    case COLUMN_SAHPIWATCHDOGPRETIMERINTERRUPT:
            /** INTEGER = ASN_INTEGER */
        snmp_set_var_typed_value(var, ASN_INTEGER,
                                 (char *) &context->
                                 saHpiWatchdogPretimerInterrupt,
                                 sizeof(context->
                                        saHpiWatchdogPretimerInterrupt));
        break;

    case COLUMN_SAHPIWATCHDOGPRETIMEOUTINTERVAL:
            /** UNSIGNED32 = ASN_UNSIGNED */
        snmp_set_var_typed_value(var, ASN_UNSIGNED,
                                 (char *) &context->
                                 saHpiWatchdogPreTimeoutInterval,
                                 sizeof(context->
                                        saHpiWatchdogPreTimeoutInterval));
        break;

    case COLUMN_SAHPIWATCHDOGTIMERUSEEXPFLAGS:
            /** UNSIGNED32 = ASN_UNSIGNED */
        snmp_set_var_typed_value(var, ASN_UNSIGNED,
                                 (char *) &context->
                                 saHpiWatchdogTimerUseExpFlags,
                                 sizeof(context->
                                        saHpiWatchdogTimerUseExpFlags));
        break;

    case COLUMN_SAHPIWATCHDOGTIMERINITIALCOUNT:
            /** UNSIGNED32 = ASN_UNSIGNED */
        snmp_set_var_typed_value(var, ASN_UNSIGNED,
                                 (char *) &context->
                                 saHpiWatchdogTimerInitialCount,
                                 sizeof(context->
                                        saHpiWatchdogTimerInitialCount));
        break;

    case COLUMN_SAHPIWATCHDOGTIMERPRESENTCOUNT:
            /** UNSIGNED32 = ASN_UNSIGNED */
        snmp_set_var_typed_value(var, ASN_UNSIGNED,
                                 (char *) &context->
                                 saHpiWatchdogTimerPresentCount,
                                 sizeof(context->
                                        saHpiWatchdogTimerPresentCount));
        break;

    case COLUMN_SAHPIWATCHDOGOEM:
            /** UNSIGNED32 = ASN_UNSIGNED */
        snmp_set_var_typed_value(var, ASN_UNSIGNED,
                                 (char *) &context->saHpiWatchdogOem,
                                 sizeof(context->saHpiWatchdogOem));
        break;
    case COLUMN_SAHPIWATCHDOGRDR:
      /** RowPointer = ASN_OBJECT_ID */
      snmp_set_var_typed_value(var, ASN_OBJECT_ID,
			       (char *) &context->saHpiWatchdogRDR,
                                 context->saHpiWatchdogRDR_len);
        break;
    default:/** We shouldn't get here */
        snmp_log(LOG_ERR, "unknown column in "
                 "saHpiWatchdogTable_get_value\n");
        return SNMP_ERR_GENERR;
    }
    return SNMP_ERR_NOERROR;
}
Example #20
0
int
handle_nsLoggingTable(netsnmp_mib_handler *handler,
                netsnmp_handler_registration *reginfo,
                netsnmp_agent_request_info *reqinfo,
                netsnmp_request_info *requests)
{
    long temp;
    netsnmp_request_info       *request     = NULL;
    netsnmp_table_request_info *table_info  = NULL;
    netsnmp_log_handler        *logh        = NULL;
    netsnmp_variable_list      *idx         = NULL;

    switch (reqinfo->mode) {

    case MODE_GET:
        for (request=requests; request; request=request->next) {
            if (request->processed != 0)
                continue;
            logh = (netsnmp_log_handler*)netsnmp_extract_iterator_context(request);
            table_info  =                netsnmp_extract_table_info(request);

            switch (table_info->colnum) {
            case NSLOGGING_TYPE:
                if (!logh) {
                    netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
                    continue;
		}
		temp = logh->type;
	        snmp_set_var_typed_value(request->requestvb, ASN_INTEGER,
                                         (u_char*)&temp,
                                            sizeof(temp));
	        break;

            case NSLOGGING_MAXLEVEL:
                if (!logh) {
                    netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
                    continue;
		}
		temp = logh->pri_max;
	        snmp_set_var_typed_value(request->requestvb, ASN_INTEGER,
                                         (u_char*)&temp,
                                            sizeof(temp));
	        break;

            case NSLOGGING_STATUS:
                if (!logh) {
                    netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
                    continue;
		}
		temp = (logh->type ?
	                   (logh->enabled ?
	                      RS_ACTIVE:
	                      RS_NOTINSERVICE) :
	                    RS_NOTREADY);
	        snmp_set_var_typed_value(request->requestvb, ASN_INTEGER,
                                         (u_char*)&temp, sizeof(temp));
	        break;

            default:
                netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
                continue;
	    }
	}
	break;


#ifndef NETSNMP_NO_WRITE_SUPPORT
    case MODE_SET_RESERVE1:
        for (request=requests; request; request=request->next) {
            if ( request->status != 0 ) {
                return SNMP_ERR_NOERROR;	/* Already got an error */
            }
            logh = (netsnmp_log_handler*)netsnmp_extract_iterator_context(request);
            table_info  =                 netsnmp_extract_table_info(request);

            switch (table_info->colnum) {
            case NSLOGGING_TYPE:
                if ( request->requestvb->type != ASN_INTEGER ) {
                    netsnmp_set_request_error(reqinfo, request, SNMP_ERR_WRONGTYPE);
                    return SNMP_ERR_WRONGTYPE;
                }
                if (*request->requestvb->val.integer < 0 ) {
                    netsnmp_set_request_error(reqinfo, request, SNMP_ERR_WRONGVALUE);
                    return SNMP_ERR_WRONGVALUE;
                }
		/*
		 * It's OK to create a new logging entry
		 *  (either in one go, or built up using createAndWait)
		 *  but it's not possible to change the type of an entry
		 *  once it's been created.
		 */
                if (logh && logh->type) {
                    netsnmp_set_request_error(reqinfo, request, SNMP_ERR_NOTWRITABLE);
                    return SNMP_ERR_NOTWRITABLE;
		}
	        break;

            case NSLOGGING_MAXLEVEL:
                if ( request->requestvb->type != ASN_INTEGER ) {
                    netsnmp_set_request_error(reqinfo, request, SNMP_ERR_WRONGTYPE);
                    return SNMP_ERR_WRONGTYPE;
                }
                if (*request->requestvb->val.integer < 0 ||
                    *request->requestvb->val.integer > 7 ) {
                    netsnmp_set_request_error(reqinfo, request, SNMP_ERR_WRONGVALUE);
                    return SNMP_ERR_WRONGVALUE;
                }
	        break;

            case NSLOGGING_STATUS:
                if ( request->requestvb->type != ASN_INTEGER ) {
                    netsnmp_set_request_error(reqinfo, request, SNMP_ERR_WRONGTYPE);
                    return SNMP_ERR_WRONGTYPE;
                }
		switch ( *request->requestvb->val.integer ) {
                case RS_ACTIVE:
                case RS_NOTINSERVICE:
                    /*
		     * Can only work on existing rows
		     */
                    if (!logh) {
                        netsnmp_set_request_error(reqinfo, request,
                                                  SNMP_ERR_INCONSISTENTVALUE);
                        return SNMP_ERR_INCONSISTENTVALUE;
                    }
	            break;

                case RS_CREATEANDWAIT:
                case RS_CREATEANDGO:
                    /*
		     * Can only work with new rows
		     */
                    if (logh) {
                        netsnmp_set_request_error(reqinfo, request,
                                                  SNMP_ERR_INCONSISTENTVALUE);
                        return SNMP_ERR_INCONSISTENTVALUE;
                    }

                    /*
                     *  Normally, we'd create the row at a later stage
                     *   (probably during the RESERVE2 or ACTION passes)
                     *
                     *  But we need to check that the values are
                     *   consistent during the ACTION pass (which is the
                     *   latest that an error can be safely handled),
                     *   so the values all need to be set up before this
                     *      (i.e. during the RESERVE2 pass)
                     *  So the new row needs to be created before that
                     *   in order to have somewhere to put them.
                     *
                     *  That's why we're doing this here.
                     */
                    idx = table_info->indexes;
	            logh = netsnmp_register_loghandler(
				    /* not really, but we need a valid type */
				    NETSNMP_LOGHANDLER_STDOUT,
				    *idx->val.integer);
                    if (!logh) {
                        netsnmp_set_request_error(reqinfo, request,
                                                  SNMP_ERR_GENERR); /* ??? */
                        return SNMP_ERR_GENERR;
                    }
                    idx = idx->next_variable;
	            logh->type  = 0;
	            logh->token = strdup((char *) idx->val.string);
                    netsnmp_insert_iterator_context(request, (void*)logh);
	            break;

                case RS_DESTROY:
                    /*
		     * Can work with new or existing rows
		     */
                    break;

                case RS_NOTREADY:
		default:
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_ERR_WRONGVALUE);
                    return SNMP_ERR_WRONGVALUE;
                }
                break;

            default:
                netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
                return SNMP_NOSUCHOBJECT;
	    }
	}
	break;


    case MODE_SET_RESERVE2:
        for (request=requests; request; request=request->next) {
            if ( request->status != 0 ) {
                return SNMP_ERR_NOERROR;	/* Already got an error */
            }
            logh = (netsnmp_log_handler*)netsnmp_extract_iterator_context(request);
            table_info  =                 netsnmp_extract_table_info(request);

            switch (table_info->colnum) {
            case NSLOGGING_TYPE:
                /*
		 * If we're creating a row using createAndGo,
		 * we need to set the type early, so that we
		 * can validate it in the ACTION pass.
		 *
		 * Remember that we need to be able to reverse this
		 */
                if ( logh )
                    logh->type = *request->requestvb->val.integer;
	        break;
            /*
	     * Don't need to handle nsLogToken or nsLogStatus in this pass
	     */
	    }
	}
	break;

    case MODE_SET_ACTION:
        for (request=requests; request; request=request->next) {
            if (request->processed != 0)
                continue;
            if ( request->status != 0 ) {
                return SNMP_ERR_NOERROR;	/* Already got an error */
            }
            logh = (netsnmp_log_handler*)netsnmp_extract_iterator_context(request);
            table_info  =                 netsnmp_extract_table_info(request);

            switch (table_info->colnum) {
            case NSLOGGING_STATUS:
                /*
		 * This is where we can check the internal consistency
		 * of the request.  Basically, for a row to be marked
		 * 'active', then there needs to be a valid type value.
		 */
		switch ( *request->requestvb->val.integer ) {
                case RS_ACTIVE:
                case RS_CREATEANDGO:
                    if ( !logh || !logh->type ) {
                        netsnmp_set_request_error(reqinfo, request,
                                                  SNMP_ERR_INCONSISTENTVALUE);
                        return SNMP_ERR_INCONSISTENTVALUE;
		    }
	            break;
		}
	        break;
            /*
	     * Don't need to handle nsLogToken or nsLogType in this pass
	     */
	    }
	}
	break;

    case MODE_SET_FREE:
    case MODE_SET_UNDO:
        /*
         * If any resources were allocated in either of the
         *  two RESERVE passes, they need to be released here,
         *  and any assignments (in RESERVE2) reversed.
         *
         * Nothing additional will have been done during ACTION
         *  so this same code can do for UNDO as well.
         */
        for (request=requests; request; request=request->next) {
            if (request->processed != 0)
                continue;
            logh = (netsnmp_log_handler*)netsnmp_extract_iterator_context(request);
            table_info  =                 netsnmp_extract_table_info(request);

            switch (table_info->colnum) {
            case NSLOGGING_TYPE:
                /*
		 * If we've been setting the type, and the request
		 * has failed, then revert to an unset type.
		 *
		 * We need to be careful here - if the reason it failed is
		 *  that the type was already set, then we shouldn't "undo"
		 *  the assignment (since it won't actually have been made).
		 *
		 * Check the current value against the 'new' one.  If they're
		 * the same, then this is probably a successful assignment,
		 * and the failure was elsewhere, so we need to undo it.
		 *  (Or else there was an attempt to write the same value!)
		 */
                if ( logh && logh->type == *request->requestvb->val.integer )
                    logh->type = 0;
	        break;

            case NSLOGGING_STATUS:
                temp = *request->requestvb->val.integer;
                if ( logh && ( temp == RS_CREATEANDGO ||
                               temp == RS_CREATEANDWAIT)) {
		    netsnmp_remove_loghandler( logh );
		}
	        break;
            /*
	     * Don't need to handle nsLogToken in this pass
	     */
	    }
	}
	break;


    case MODE_SET_COMMIT:
        for (request=requests; request; request=request->next) {
            if (request->processed != 0)
                continue;
            if ( request->status != 0 ) {
                return SNMP_ERR_NOERROR;	/* Already got an error */
            }
            logh = (netsnmp_log_handler*)netsnmp_extract_iterator_context(request);
            if (!logh) {
                netsnmp_set_request_error(reqinfo, request, SNMP_ERR_COMMITFAILED);
                return SNMP_ERR_COMMITFAILED;	/* Shouldn't happen! */
            }
            table_info  =                 netsnmp_extract_table_info(request);

            switch (table_info->colnum) {
            case NSLOGGING_MAXLEVEL:
                logh->pri_max = *request->requestvb->val.integer;
	        break;

            case NSLOGGING_STATUS:
                switch (*request->requestvb->val.integer) {
                    case RS_ACTIVE:
                    case RS_CREATEANDGO:
                        netsnmp_enable_this_loghandler(logh);
                        break;
                    case RS_NOTINSERVICE:
                    case RS_CREATEANDWAIT:
                        netsnmp_disable_this_loghandler(logh);
                        break;
		    case RS_DESTROY:
		        netsnmp_remove_loghandler( logh );
                        break;
		}
	        break;
	    }
	}
	break;
#endif /* !NETSNMP_NO_WRITE_SUPPORT */
    }

    return SNMP_ERR_NOERROR;
}
/**********************************************************************

    prototype:

		int
		CcspTableHelperGetMibValues
			(
				ANSC_HANDLE                 hThisObject,
				netsnmp_agent_request_info  *reqinfo,
				netsnmp_request_info		*requests
			);

    description:

        This function is called to retrieve MIB values.

    argument:   ANSC_HANDLE				hThisObject
	            The handle of the object;

				netsnmp_agent_request_info  *reqinfo,
				The request info

				netsnmp_request_info		*requests
				The requests;

	return:     The error code

**********************************************************************/
int
CcspTableHelperGetMibValues
	(
        ANSC_HANDLE                 hThisObject,
        netsnmp_agent_request_info  *reqinfo,
        netsnmp_request_info		*requests
	)
{
	PCCSP_TABLE_HELPER_OBJECT       pThisObject     = (PCCSP_TABLE_HELPER_OBJECT)hThisObject;
	PCCSP_MIB_VALUE                 pMibValueObj    = (PCCSP_MIB_VALUE)NULL;
    netsnmp_request_info            *request		= NULL;
    netsnmp_variable_list           *requestvb		= NULL;
    oid                             subid			= 0;
    netsnmp_table_request_info*		table_info      = NULL;
    netsnmp_tdata*					table_data      = NULL;
    netsnmp_tdata_row*				table_row       = NULL;
    PCCSP_TABLE_ENTRY				table_entry     = NULL;


    for (request = requests; request != NULL; request = request->next) 
	{
		if( request->processed != 0) { continue;}

            table_entry = (PCCSP_TABLE_ENTRY)netsnmp_tdata_extract_entry(request);
            table_info = netsnmp_extract_table_info(request);
			subid = table_info->colnum;

			if(!table_entry)
			{
				netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
				continue;
			}

			requestvb = request->requestvb;
			pMibValueObj = CcspUtilLookforMibValueObjWithOid(&table_entry->MibValueQueue, subid);

			if( pMibValueObj != NULL)
			{
				if( pMibValueObj->uType == ASN_INTEGER || pMibValueObj->uType == ASN_BOOLEAN ||
					(pMibValueObj->uType >= ASN_IPADDRESS && pMibValueObj->uType <= ASN_OPAQUE))
				{
					pMibValueObj->uSize = 4;
					snmp_set_var_typed_value(request->requestvb, (u_char)pMibValueObj->uType,
						(u_char *)&pMibValueObj->Value.uValue, pMibValueObj->uSize);

				}
				else if( pMibValueObj->uType == ASN_BIT_STR || pMibValueObj->uType == ASN_OCTET_STR)
				{
					snmp_set_var_typed_value(request->requestvb, (u_char)pMibValueObj->uType,
						(u_char *)pMibValueObj->Value.pBuffer, pMibValueObj->uSize);
				}
				else if( pMibValueObj->uType == ASN_COUNTER64)
				{
					snmp_set_var_typed_value(request->requestvb, (u_char)pMibValueObj->uType,
						(u_char *)&pMibValueObj->Value.u64Value, pMibValueObj->uSize);
				}
				else
				{
					AnscTraceWarning(("Unknown MIB type '%lu'\n", pMibValueObj->uType));
				}
			}	
			else
			{
				netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
			}
 	}

    return SNMP_ERR_NOERROR;
}
Example #22
0
/** handles requests for the mteEventTable table */
int
mteEventTable_handler(netsnmp_mib_handler *handler,
                      netsnmp_handler_registration *reginfo,
                      netsnmp_agent_request_info *reqinfo,
                      netsnmp_request_info *requests)
{

    netsnmp_request_info       *request;
    netsnmp_table_request_info *tinfo;
    netsnmp_tdata_row          *row;
    struct mteEvent            *entry;
    char mteOwner[MTE_STR1_LEN+1];
    char mteEName[MTE_STR1_LEN+1];
    long ret;

    DEBUGMSGTL(("disman:event:mib", "Event Table handler (%d)\n",
                                     reqinfo->mode));

    switch (reqinfo->mode) {
        /*
         * Read-support (also covers GetNext requests)
         */
    case MODE_GET:
        for (request = requests; request; request = request->next) {
            if (request->processed)
                continue;

            entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
            tinfo = netsnmp_extract_table_info(request);
            if (!entry || !(entry->flags & MTE_EVENT_FLAG_VALID))
                continue;

            switch (tinfo->colnum) {
            case COLUMN_MTEEVENTCOMMENT:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         entry->mteEventComment,
                                  strlen(entry->mteEventComment));
                break;
            case COLUMN_MTEEVENTACTIONS:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                        &entry->mteEventActions, 1);
                break;
            case COLUMN_MTEEVENTENABLED:
                ret = (entry->flags & MTE_EVENT_FLAG_ENABLED ) ?
                           TV_TRUE : TV_FALSE;
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret);
                break;
            case COLUMN_MTEEVENTENTRYSTATUS:
                ret = (entry->flags & MTE_EVENT_FLAG_ACTIVE ) ?
                           RS_ACTIVE : RS_NOTINSERVICE;
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret);
                break;
            }
        }
        break;


#ifndef NETSNMP_NO_WRITE_SUPPORT
        /*
         * Write-support
         */
    case MODE_SET_RESERVE1:
        for (request = requests; request; request = request->next) {
            if (request->processed)
                continue;

            entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
            tinfo = netsnmp_extract_table_info(request);

            switch (tinfo->colnum) {
            case COLUMN_MTEEVENTCOMMENT:
                ret = netsnmp_check_vb_type_and_max_size(
                          request->requestvb, ASN_OCTET_STR, MTE_STR1_LEN);
                if (ret != SNMP_ERR_NOERROR) {
                    netsnmp_set_request_error(reqinfo, request, ret);
                    return SNMP_ERR_NOERROR;
                }
                /*
                 * Can't modify the comment of an active row
                 *   (No good reason for this, but that's what the MIB says!)
                 */
                if (entry &&
                    entry->flags & MTE_EVENT_FLAG_ACTIVE ) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_ERR_INCONSISTENTVALUE);
                    return SNMP_ERR_NOERROR;
                }
                break;
            case COLUMN_MTEEVENTACTIONS:
                ret = netsnmp_check_vb_type_and_size(
                          request->requestvb, ASN_OCTET_STR, 1);
                if (ret != SNMP_ERR_NOERROR) {
                    netsnmp_set_request_error(reqinfo, request, ret);
                    return SNMP_ERR_NOERROR;
                }
                /*
                 * Can't modify the event types of an active row
                 *   (A little more understandable perhaps,
                 *    but still an unnecessary restriction IMO)
                 */
                if (entry &&
                    entry->flags & MTE_EVENT_FLAG_ACTIVE ) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_ERR_INCONSISTENTVALUE);
                    return SNMP_ERR_NOERROR;
                }
                break;
            case COLUMN_MTEEVENTENABLED:
                ret = netsnmp_check_vb_truthvalue(request->requestvb);
                if (ret != SNMP_ERR_NOERROR) {
                    netsnmp_set_request_error(reqinfo, request, ret);
                    return SNMP_ERR_NOERROR;
                }
                /*
                 * The published version of the Event MIB forbids
                 *   enabling (or disabling) an active row, which
                 *   would make this object completely pointless!
                 * Fortunately this ludicrous decision has since been corrected.
                 */
                break;

            case COLUMN_MTEEVENTENTRYSTATUS:
                ret = netsnmp_check_vb_rowstatus(request->requestvb,
                          (entry ? RS_ACTIVE : RS_NONEXISTENT));
                if (ret != SNMP_ERR_NOERROR) {
                    netsnmp_set_request_error(reqinfo, request, ret);
                    return SNMP_ERR_NOERROR;
                }
                /* An active row can only be deleted */
                if (entry &&
                    entry->flags & MTE_EVENT_FLAG_ACTIVE &&
                    *request->requestvb->val.integer == RS_NOTINSERVICE ) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_ERR_INCONSISTENTVALUE);
                    return SNMP_ERR_NOERROR;
                }
                break;
            default:
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_ERR_NOTWRITABLE);
                return SNMP_ERR_NOERROR;
            }
        }
        break;

    case MODE_SET_RESERVE2:
        for (request = requests; request; request = request->next) {
            if (request->processed)
                continue;

            tinfo = netsnmp_extract_table_info(request);

            switch (tinfo->colnum) {
            case COLUMN_MTEEVENTENTRYSTATUS:
                switch (*request->requestvb->val.integer) {
                case RS_CREATEANDGO:
                case RS_CREATEANDWAIT:
                    /*
                     * Create an (empty) new row structure
                     */
                    memset(mteOwner, 0, sizeof(mteOwner));
                    memcpy(mteOwner, tinfo->indexes->val.string,
                                     tinfo->indexes->val_len);
                    memset(mteEName, 0, sizeof(mteEName));
                    memcpy(mteEName,
                           tinfo->indexes->next_variable->val.string,
                           tinfo->indexes->next_variable->val_len);

                    row = mteEvent_createEntry(mteOwner, mteEName, 0);
                    if (!row) {
                        netsnmp_set_request_error(reqinfo, request,
                                                  SNMP_ERR_RESOURCEUNAVAILABLE);
                        return SNMP_ERR_NOERROR;
                    }
                    netsnmp_insert_tdata_row( request, row );
                }
            }
        }
        break;

    case MODE_SET_FREE:
        for (request = requests; request; request = request->next) {
            if (request->processed)
                continue;

            tinfo = netsnmp_extract_table_info(request);

            switch (tinfo->colnum) {
            case COLUMN_MTEEVENTENTRYSTATUS:
                switch (*request->requestvb->val.integer) {
                case RS_CREATEANDGO:
                case RS_CREATEANDWAIT:
                    /*
                     * Tidy up after a failed row creation request
                     */ 
                    entry = (struct mteEvent *)
                                netsnmp_tdata_extract_entry(request);
                    if (entry &&
                      !(entry->flags & MTE_EVENT_FLAG_VALID)) {
                        row = (netsnmp_tdata_row *)
                                netsnmp_tdata_extract_row(request);
                        mteEvent_removeEntry( row );
                    }
                }
            }
        }
        break;

    case MODE_SET_ACTION:
        for (request = requests; request; request = request->next) {
            if (request->processed)
                continue;

            tinfo = netsnmp_extract_table_info(request);
            entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
            if (!entry) {
                /*
                 * New rows must be created via the RowStatus column
                 */
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_ERR_NOCREATION);
                                      /* or inconsistentName? */
                return SNMP_ERR_NOERROR;

            }
        }
        break;

    case MODE_SET_UNDO:
        break;

    case MODE_SET_COMMIT:
        /*
         * All these assignments are "unfailable", so it's
         *  (reasonably) safe to apply them in the Commit phase
         */
        for (request = requests; request; request = request->next) {
            if (request->processed)
                continue;

            entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request);
            tinfo = netsnmp_extract_table_info(request);

            switch (tinfo->colnum) {
            case COLUMN_MTEEVENTCOMMENT:
                memset(entry->mteEventComment, 0,
                       sizeof(entry->mteEventComment));
                memcpy(entry->mteEventComment,
                       request->requestvb->val.string,
                       request->requestvb->val_len);
                break;

            case COLUMN_MTEEVENTACTIONS:
                entry->mteEventActions = request->requestvb->val.string[0];
                break;

            case COLUMN_MTEEVENTENABLED:
                if (*request->requestvb->val.integer == TV_TRUE)
                    entry->flags |=  MTE_EVENT_FLAG_ENABLED;
                else
                    entry->flags &= ~MTE_EVENT_FLAG_ENABLED;
                break;

            case COLUMN_MTEEVENTENTRYSTATUS:
                switch (*request->requestvb->val.integer) {
                case RS_ACTIVE:
                    entry->flags |= MTE_EVENT_FLAG_ACTIVE;
                    break;
                case RS_CREATEANDGO:
                    entry->flags |= MTE_EVENT_FLAG_ACTIVE;
                    /* fall-through */
                case RS_CREATEANDWAIT:
                    entry->flags |= MTE_EVENT_FLAG_VALID;
                    entry->session =
                        netsnmp_iquery_pdu_session(reqinfo->asp->pdu);
                    break;

                case RS_DESTROY:
                    row = (netsnmp_tdata_row *)
                               netsnmp_tdata_extract_row(request);
                    mteEvent_removeEntry(row);
                }
            }
        }
        break;
#endif /* !NETSNMP_NO_WRITE_SUPPORT */

    }
    DEBUGMSGTL(("disman:event:mib", "Table handler, done\n"));
    return SNMP_ERR_NOERROR;
}
Example #23
0
int handle_channelList(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests)
{
	netsnmp_request_info *request;
	netsnmp_table_request_info *table_info;
	chan_entry_t *entry;
	char dt_str[12];

	switch (reqinfo->mode) {
	case MODE_GET:
		for (request = requests; request; request = request->next) {
			if (request->processed)
				continue;

			table_info = netsnmp_extract_table_info(request);
			entry = (chan_entry_t *) netsnmp_tdata_extract_entry(request);

			switch (table_info->colnum) {
			case CH_INDEX:
				snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->idx);
				break;
			case CH_UUID:
				snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->uuid, strlen(entry->uuid));
				break;
			case CH_DIRECTION:
				snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->direction, strlen(entry->direction));
				break;
			case CH_CREATED:
				time_t_to_datetime(entry->created_epoch, (char *) &dt_str, sizeof(dt_str));
				snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) &dt_str, sizeof(dt_str));
				break;
			case CH_NAME:
				snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->name, strlen(entry->name));
				break;
			case CH_STATE:
				snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->state, strlen(entry->state));
				break;
			case CH_CID_NAME:
				snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->cid_name, strlen(entry->cid_name));
				break;
			case CH_CID_NUM:
				snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->cid_num, strlen(entry->cid_num));
				break;
			case CH_IP_ADDR_TYPE:
				if (entry->addr_family == AF_INET6) {
					snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, INETADDRESSTYPE_IPV6);
				} else {
					snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, INETADDRESSTYPE_IPV4);
				}
				break;
			case CH_IP_ADDR:
				if (entry->addr_family == AF_INET6) {
					snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) &entry->ip_addr.v6, sizeof(entry->ip_addr.v6));
				} else {
					snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) &entry->ip_addr.v4, sizeof(entry->ip_addr.v4));
				}
				break;
			case CH_DEST:
				snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->dest, strlen(entry->dest));
				break;
			case CH_APPLICATION:
				snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->application, strlen(entry->application));
				break;
			case CH_APPLICATION_DATA:
				snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->application_data, strlen(entry->application_data));
				break;
			case CH_DIALPLAN:
				snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->dialplan, strlen(entry->dialplan));
				break;
			case CH_CONTEXT:
				snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->context, strlen(entry->context));
				break;
			case CH_READ_CODEC:
				snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->read_codec, strlen(entry->read_codec));
				break;
			case CH_READ_RATE:
				snmp_set_var_typed_value(request->requestvb, ASN_GAUGE, (u_char *) &entry->read_rate, sizeof(entry->read_rate));
				break;
			case CH_READ_BITRATE:
				snmp_set_var_typed_value(request->requestvb, ASN_GAUGE, (u_char *) &entry->read_bitrate, sizeof(entry->read_bitrate));
				break;
			case CH_WRITE_CODEC:
				snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->write_codec, strlen(entry->write_codec));
				break;
			case CH_WRITE_RATE:
				snmp_set_var_typed_value(request->requestvb, ASN_GAUGE, (u_char *) &entry->write_rate, sizeof(entry->write_rate));
				break;
			case CH_WRITE_BITRATE:
				snmp_set_var_typed_value(request->requestvb, ASN_GAUGE, (u_char *) &entry->write_bitrate, sizeof(entry->write_bitrate));
				break;
			default:
				snmp_log(LOG_WARNING, "Unregistered OID-suffix requested (%d)\n", table_info->colnum);
				netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
			}
		}
		break;
	default:
		/* we should never get here, so this is a really bad error */
		snmp_log(LOG_ERR, "Unknown mode (%d) in handle_channelList\n", reqinfo->mode );
		return SNMP_ERR_GENERR;
	}

	return SNMP_ERR_NOERROR;
}
Example #24
0
int
tcpTable_handler(netsnmp_mib_handler          *handler,
                 netsnmp_handler_registration *reginfo,
                 netsnmp_agent_request_info   *reqinfo,
                 netsnmp_request_info         *requests)
{
    netsnmp_request_info  *request;
    netsnmp_variable_list *requestvb;
    netsnmp_table_request_info *table_info;
    TCPTABLE_ENTRY_TYPE	  *entry;
    oid      subid;
    long     port;
    long     state;

    DEBUGMSGTL(("mibII/tcpTable", "Handler - mode %s\n",
                se_find_label_in_slist("agent_mode", reqinfo->mode)));
    switch (reqinfo->mode) {
    case MODE_GET:
        for (request=requests; request; request=request->next) {
            requestvb = request->requestvb;
            DEBUGMSGTL(( "mibII/tcpTable", "oid: "));
            DEBUGMSGOID(("mibII/tcpTable", requestvb->name,
                         requestvb->name_length));
            DEBUGMSG((   "mibII/tcpTable", "\n"));

            entry = (TCPTABLE_ENTRY_TYPE *)netsnmp_extract_iterator_context(request);
            if (!entry)
                continue;
            table_info = netsnmp_extract_table_info(request);
            subid      = table_info->colnum;

            switch (subid) {
            case TCPCONNSTATE:
                state = entry->TCPTABLE_STATE;
                snmp_set_var_typed_value(requestvb, ASN_INTEGER,
                                         (u_char *)&state, sizeof(state));
                break;
            case TCPCONNLOCALADDRESS:
#if defined(osf5) && defined(IN6_EXTRACT_V4ADDR)
                snmp_set_var_typed_value(requestvb, ASN_IPADDRESS,
                                         (u_char*)IN6_EXTRACT_V4ADDR(&entry->pcb.inp_laddr),
                                         sizeof(IN6_EXTRACT_V4ADDR(&entry->pcb.inp_laddr)));
#else
                snmp_set_var_typed_value(requestvb, ASN_IPADDRESS,
                                         (u_char *)&entry->TCPTABLE_LOCALADDRESS,
                                         sizeof(entry->TCPTABLE_LOCALADDRESS));
#endif
                break;
            case TCPCONNLOCALPORT:
                port = TCP_PORT_TO_HOST_ORDER((u_short)entry->TCPTABLE_LOCALPORT);
                snmp_set_var_typed_value(requestvb, ASN_INTEGER,
                                         (u_char *)&port, sizeof(port));
                break;
            case TCPCONNREMOTEADDRESS:
#if defined(osf5) && defined(IN6_EXTRACT_V4ADDR)
                snmp_set_var_typed_value(requestvb, ASN_IPADDRESS,
                                         (u_char*)IN6_EXTRACT_V4ADDR(&entry->pcb.inp_laddr),
                                         sizeof(IN6_EXTRACT_V4ADDR(&entry->pcb.inp_laddr)));
#else
                snmp_set_var_typed_value(requestvb, ASN_IPADDRESS,
                                         (u_char *)&entry->TCPTABLE_REMOTEADDRESS,
                                         sizeof(entry->TCPTABLE_REMOTEADDRESS));
#endif
                break;
            case TCPCONNREMOTEPORT:
                port = TCP_PORT_TO_HOST_ORDER((u_short)entry->TCPTABLE_REMOTEPORT);
                snmp_set_var_typed_value(requestvb, ASN_INTEGER,
                                         (u_char *)&port, sizeof(port));
                break;
            }
        }
        break;

    case MODE_GETNEXT:
    case MODE_GETBULK:
#ifndef NETSNMP_NO_WRITE_SUPPORT
    case MODE_SET_RESERVE1:
    case MODE_SET_RESERVE2:
    case MODE_SET_ACTION:
    case MODE_SET_COMMIT:
    case MODE_SET_FREE:
    case MODE_SET_UNDO:
#endif /* !NETSNMP_NO_WRITE_SUPPORT */
        snmp_log(LOG_WARNING, "mibII/tcpTable: Unsupported mode (%d)\n",
                 reqinfo->mode);
        break;
    default:
        snmp_log(LOG_WARNING, "mibII/tcpTable: Unrecognised mode (%d)\n",
                 reqinfo->mode);
        break;
    }

    return SNMP_ERR_NOERROR;
}
Example #25
0
int
handle_acIfPortNum(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info   *reqinfo,
                          netsnmp_request_info         *requests)
{
	snmp_log(LOG_DEBUG, "enter handle_acIfPortNum\n");

	switch(reqinfo->mode) {

	case MODE_GET:
	{
		#if 0
		int number = 0,ret1=0,port_count = 0;
		ETH_SLOT_LIST  head,*p;
		memset(&head,0,sizeof(ETH_SLOT_LIST));
		ETH_PORT_LIST *pp;
		ret1=show_ethport_list(&head,&number);
		p=head.next;
		if(p!=NULL)
		{
			while(p!=NULL)
			{
				port_count +=p->port_num;
				pp=p->port.next;
				p=p->next;
			}
		#endif
		unsigned int ret = 0, num = 0;
		struct flow_data_list *alldata = NULL;
		struct flow_data_list *temp = NULL;

		
		snmp_log(LOG_DEBUG, "enter intflib_getdata\n");
		ret = intflib_getdata(&alldata);
		snmp_log(LOG_DEBUG, "exit intflib_getdata,ret=%d\n", ret);
		
		if(ret < 0)
		{
			printf("intflib get data error! ret %d.<br>",ret);
		}
		temp = alldata;
		for(temp; NULL != temp; temp = temp->next)
		{
			
			if(strncmp(temp->ltdata.ifname,"r",1)==0 
			|| strncmp(temp->ltdata.ifname,"pimreg",6)==0 
			|| strncmp(temp->ltdata.ifname,"sit0",4)==0)
			{
				continue;
			}
	
			num++;
		}
		snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
								(u_char *)&num,
								sizeof(num));
		intflib_memfree(&alldata);
		#if 0
		if((ret1==0)&&(number>0))
		{
			Free_ethslot_head(&head);
		}
		#endif
	}
	break;


	default:
	/* we should never get here, so this is a really bad error */
	snmp_log(LOG_ERR, "unknown mode (%d) in handle_acIfPortNum\n", reqinfo->mode );

	return SNMP_ERR_GENERR;
	}

	snmp_log(LOG_DEBUG, "exit handle_acIfPortNum\n");
	return SNMP_ERR_NOERROR;
}

int
handle_acPhyPortNum(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info   *reqinfo,
                          netsnmp_request_info         *requests)
{
	snmp_log(LOG_DEBUG, "enter handle_acPhyPortNum\n");

	switch(reqinfo->mode) {

	case MODE_GET:
	{
		int acPhyPortNum = 0;

		snmp_log(LOG_DEBUG, "enter count_eth_port_num\n");
		acPhyPortNum=count_eth_port_num();
		snmp_log(LOG_DEBUG, "exit count_eth_port_num,acPhyPortNum=%d\n", acPhyPortNum);
		
		snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
								(u_char *)&acPhyPortNum,
								sizeof(acPhyPortNum));
	}
	break;


	default:
	/* we should never get here, so this is a really bad error */
	snmp_log(LOG_ERR, "unknown mode (%d) in handle_acPhyPortNum\n", reqinfo->mode );

	return SNMP_ERR_GENERR;
	}

	snmp_log(LOG_DEBUG, "exit handle_acPhyPortNum\n");
	return SNMP_ERR_NOERROR;
}
/*
 * This function is called to handle SNMP GET requests.  
 *
 * The row which this function is called with, will store a message code.  The
 * function will retrieve the 'number of messages in' and 'number of messages
 * out' statistic for this particular message code from the statistics
 * framework.  
 *
 * The function will then subtract from this value the value it was initialized
 * with when the row was first created.  In this sense, the row shows how many
 * ins and how many outs have been received (With respect to the message code)
 * since this row was created. 
 */
int kamailioSIPStatusCodesTable_get_value(
			netsnmp_request_info *request,
			netsnmp_index *item,
			netsnmp_table_request_info *table_info )
{
	stat_var *the_stat;

	netsnmp_variable_list *var = request->requestvb;

	kamailioSIPStatusCodesTable_context *context = 
		(kamailioSIPStatusCodesTable_context *)item;

	/* Retrieve the statusCodeIdx so we can calculate deltas between current
	 * values and previous values. */
	int statusCodeIdx = context->kamailioSIPStatusCodeValue;

	switch(table_info->colnum) 
	{
		case COLUMN_KAMAILIOSIPSTATUSCODEINS:

			context->kamailioSIPStatusCodeIns = 0;

			the_stat = get_stat_var_from_num_code(statusCodeIdx, 0);

			if (the_stat != NULL)  
			{
				/* Calculate the Delta */
				context->kamailioSIPStatusCodeIns = get_stat_val(the_stat) -
					context->startingInStatusCodeValue;
			}

			snmp_set_var_typed_value(var, ASN_COUNTER,
					(unsigned char*)
					&context->kamailioSIPStatusCodeIns,
					sizeof(context->kamailioSIPStatusCodeIns));
			break;
	
		case COLUMN_KAMAILIOSIPSTATUSCODEOUTS:
			
			context->kamailioSIPStatusCodeOuts = 0;

			the_stat = get_stat_var_from_num_code(statusCodeIdx, 1);

			if (the_stat != NULL)
			{
				/* Calculate the Delta */
				context->kamailioSIPStatusCodeOuts =
					get_stat_val(the_stat) -
					context->startingOutStatusCodeValue;
			}
			snmp_set_var_typed_value(var, ASN_COUNTER,
					 (unsigned char*)
					 &context->kamailioSIPStatusCodeOuts,
					 sizeof(context->kamailioSIPStatusCodeOuts) );
		break;
	
		case COLUMN_KAMAILIOSIPSTATUSCODEROWSTATUS:
			/** RowStatus = ASN_INTEGER */
			snmp_set_var_typed_value(var, ASN_INTEGER,
					 (unsigned char*)
					 &context->kamailioSIPStatusCodeRowStatus,
					 sizeof(context->kamailioSIPStatusCodeRowStatus) );
		break;
	
	default: /** We shouldn't get here */
		snmp_log(LOG_ERR, "unknown column in "
				 "kamailioSIPStatusCodesTable_get_value\n");
		return SNMP_ERR_GENERR;
	}
	return SNMP_ERR_NOERROR;
}
Example #27
0
int
handle_widsFloodDetectOnOff(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info   *reqinfo,
                          netsnmp_request_info         *requests)
{
    /* We are never called for a GETNEXT if it's registered as a
       "instance", as it's "magically" handled for us.  */

    /* a instance handler also only hands us one request at a time, so
       we don't need to loop over a list of requests; we'll only get one. */

	snmp_log(LOG_DEBUG, "enter handle_widsFloodDetectOnOff\n");

    switch(reqinfo->mode) {

        case MODE_GET:
		{
			#if 0
			int widsFloodDetectOnOff = 0;
            instance_parameter *paraHead = NULL;
            if(SNMPD_DBUS_SUCCESS == get_slot_dbus_connection(LOCAL_SLOT_NUM, &paraHead, SNMPD_INSTANCE_MASTER_V2))
            {
			    int ret = 0;
    			DCLI_WTP_API_GROUP_THREE *WTPINFO = NULL;   
    			
    			snmp_log(LOG_DEBUG, "enter show_ap_wids_set_cmd_func\n");
    			ret=show_ap_wids_set_cmd_func(paraHead->parameter, paraHead->connection,&WTPINFO);
    			snmp_log(LOG_DEBUG, "exit show_ap_wids_set_cmd_func,ret=%d\n", ret);
    			
    			if(ret==1)
    			{
    				if(WTPINFO->wids.flooding==1)
    					widsFloodDetectOnOff = 1;
    				else
    					widsFloodDetectOnOff = 0;
    				free_show_ap_wids_set_cmd(WTPINFO);	
    			}
    		}				
			free_instance_parameter_list(&paraHead);
			#endif

			update_data_for_show_ap_wids_set_cmd_func();
            snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                     (u_char *)&widsFloodDetectOnOff,
                                     sizeof(widsFloodDetectOnOff));
        }
            break;

        /*
         * SET REQUEST
         *
         * multiple states in the transaction.  See:
         * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
         */
        case MODE_SET_RESERVE1:
			#if 0
            if (/* XXX: check incoming data in requests->requestvb->val.XXX for failures, like an incorrect type or an illegal value or ... */) {
                netsnmp_set_request_error(reqinfo, requests, /* XXX: set error code depending on problem (like SNMP_ERR_WRONGTYPE or SNMP_ERR_WRONGVALUE or ... */);
            }
			#endif
            break;

        case MODE_SET_RESERVE2:
			#if 0
            /* XXX malloc "undo" storage buffer */
            if (/* XXX if malloc, or whatever, failed: */) {
                netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
            }
			#endif
            break;

        case MODE_SET_FREE:
            /* XXX: free resources allocated in RESERVE1 and/or
               RESERVE2.  Something failed somewhere, and the states
               below won't be called. */
            break;

        case MODE_SET_ACTION:
		{	
		    
            instance_parameter *paraHead = NULL, *paraNode = NULL;
            list_instance_parameter(&paraHead, SNMPD_INSTANCE_MASTER);
            for(paraNode = paraHead; NULL != paraNode; paraNode = paraNode->next)
            {
    			int ret = 0,flag = 1;
				char state[10] = { 0 };
    			memset(state,0,10);

    			if(*requests->requestvb->val.integer==0)
					strncpy(state,"disable",sizeof(state)-1);
    			else if(*requests->requestvb->val.integer==1)
					strncpy(state,"enable",sizeof(state)-1);
    			else
    			{
    				flag = 0;
    				netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGTYPE);
    			}
    			
    			if(flag==1)
    			{
    				snmp_log(LOG_DEBUG, "enter set_ap_wids_set_cmd_func\n");
    				ret=set_ap_wids_set_cmd_func(paraNode->parameter, paraNode->connection,"flooding","","",state);
    				snmp_log(LOG_DEBUG, "exit set_ap_wids_set_cmd_func,ret=%d\n", ret);

					if(1 == ret)
					{
						widsFloodDetectOnOff = *requests->requestvb->val.integer;
					}
					else
    				{	
    				    if(SNMPD_CONNECTION_ERROR == ret) {
                            close_slot_dbus_connection(paraNode->parameter.slot_id);
                	    }
    					netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGTYPE);
    				}
    			}
    		}	
			free_instance_parameter_list(&paraHead);

        }
            break;

        case MODE_SET_COMMIT:
			#if 0
            /* XXX: delete temporary storage */
            if (/* XXX: error? */) {
                /* try _really_really_ hard to never get to this point */
                netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
            }
			#endif
            break;

        case MODE_SET_UNDO:
			#if 0
            /* XXX: UNDO and return to previous value for the object */
            if (/* XXX: error? */) {
                /* try _really_really_ hard to never get to this point */
                netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED);
            }
			#endif
            break;

        default:
            /* we should never get here, so this is a really bad error */
            snmp_log(LOG_ERR, "unknown mode (%d) in handle_widsFloodDetectOnOff\n", reqinfo->mode );
            return SNMP_ERR_GENERR;
    }

	snmp_log(LOG_DEBUG, "exit handle_widsFloodDetectOnOff\n");
    return SNMP_ERR_NOERROR;
}
Example #28
0
File: vmstat.c Project: 274914765/C
int
vmstat_handler (netsnmp_mib_handler * handler,
                netsnmp_handler_registration * reginfo,
                netsnmp_agent_request_info * reqinfo, netsnmp_request_info * requests)
{
    oid obj;

    unsigned long long value = 0;

    char cp[300];

    netsnmp_cpu_info *info = netsnmp_cpu_get_byIdx (-1, 0);

    switch (reqinfo->mode)
    {
        case MODE_GET:
            obj = requests->requestvb->name[requests->requestvb->name_length - 2];

            switch (obj)
            {
                case MIBINDEX:    /* dummy value */
                    snmp_set_var_typed_integer (requests->requestvb, ASN_INTEGER, 1);
                    break;

                case ERRORNAME:    /* dummy name */
                    sprintf (cp, "systemStats");
                    snmp_set_var_typed_value (requests->requestvb, ASN_OCTET_STR, cp, strlen (cp));
                    break;

/*
        case IOSENT:
            long_ret = vmstat(iosent);
            return ((u_char *) (&long_ret));
        case IORECEIVE:
            long_ret = vmstat(ioreceive);
            return ((u_char *) (&long_ret));
        case IORAWSENT:
            long_ret = vmstat(rawiosent);
            return ((u_char *) (&long_ret));
        case IORAWRECEIVE:
            long_ret = vmstat(rawioreceive);
            return ((u_char *) (&long_ret));
*/

                    /*
                     *  Raw CPU statistics
                     *  Taken directly from the (overall) cpu_info structure.
                     *
                     *  XXX - Need some form of flag to skip objects that
                     *        aren't supported on a given architecture.
                     */
                case CPURAWUSER:
                    snmp_set_var_typed_integer (requests->requestvb, ASN_COUNTER, info->user_ticks & 0xffffffff);
                    break;
                case CPURAWNICE:
                    snmp_set_var_typed_integer (requests->requestvb, ASN_COUNTER, info->nice_ticks & 0xffffffff);
                    break;
                case CPURAWSYSTEM:
                    /*
                     * Some architecture have traditionally reported a
                     *   combination of CPU statistics for this object.
                     * The CPU HAL module uses 'sys2_ticks' for this,
                     *   so use this value in preference to 'sys_ticks'
                     *   if it has a non-zero value.
                     */
                    snmp_set_var_typed_integer (requests->requestvb, ASN_COUNTER,
                                                (info->sys2_ticks ? info->sys2_ticks : info->sys_ticks) & 0xffffffff);
                    break;
                case CPURAWIDLE:
                    snmp_set_var_typed_integer (requests->requestvb, ASN_COUNTER, info->idle_ticks & 0xffffffff);
                    break;
                case CPURAWWAIT:
                    snmp_set_var_typed_integer (requests->requestvb, ASN_COUNTER, info->wait_ticks & 0xffffffff);
                    break;
                case CPURAWKERNEL:
                    snmp_set_var_typed_integer (requests->requestvb, ASN_COUNTER, info->kern_ticks & 0xffffffff);
                    break;
                case CPURAWINTR:
                    snmp_set_var_typed_integer (requests->requestvb, ASN_COUNTER, info->intrpt_ticks & 0xffffffff);
                    break;
                case CPURAWSOFTIRQ:
                    snmp_set_var_typed_integer (requests->requestvb, ASN_COUNTER, info->sirq_ticks & 0xffffffff);
                    break;
                case CPURAWSTEAL:
                    snmp_set_var_typed_integer (requests->requestvb, ASN_COUNTER, info->steal_ticks & 0xffffffff);
                    break;
                case CPURAWGUEST:
                    snmp_set_var_typed_integer (requests->requestvb, ASN_COUNTER, info->guest_ticks & 0xffffffff);
                    break;
                case CPURAWGUESTNICE:
                    snmp_set_var_typed_integer (requests->requestvb, ASN_COUNTER, info->guestnice_ticks & 0xffffffff);
                    break;

                    /*
                     *  'Cooked' CPU statistics
                     *     Percentage usage of the specified statistic calculated
                     *     over the period (1 min) that history is being kept for.
                     *
                     *   This is actually a change of behaviour for some architectures,
                     *     but:
                     *        a)  It ensures consistency across all systems
                     *        a)  It matches the definition of the MIB objects
                     *
                     *   Note that this value will only be reported once the agent
                     *     has a full minute's history collected.
                     */
                case CPUUSER:
                    if (info->history && info->history[0].total_hist)
                    {
                        value = (info->user_ticks - info->history[0].user_hist) * 100;
                        if (info->total_ticks - info->history[0].total_hist)
                            value /= (info->total_ticks - info->history[0].total_hist);
                        else
                            value = 0;    /* or skip this entry */
                        snmp_set_var_typed_integer (requests->requestvb, ASN_INTEGER, value & 0x7fffffff);
                    }
                    break;
                case CPUSYSTEM:
                    if (info->history && info->history[0].total_hist)
                    {
                        /* or sys2_ticks ??? */
                        value = (info->sys_ticks - info->history[0].sys_hist) * 100;
                        if (info->total_ticks - info->history[0].total_hist)
                            value /= (info->total_ticks - info->history[0].total_hist);
                        else
                            value = 0;    /* or skip this entry */
                        snmp_set_var_typed_integer (requests->requestvb, ASN_INTEGER, value & 0x7fffffff);
                    }
                    break;
                case CPUIDLE:
                    if (info->history && info->history[0].total_hist)
                    {
                        value = (info->idle_ticks - info->history[0].idle_hist) * 100;
                        if (info->total_ticks - info->history[0].total_hist)
                            value /= (info->total_ticks - info->history[0].total_hist);
                        else
                            value = 0;    /* or skip this entry */
                        snmp_set_var_typed_integer (requests->requestvb, ASN_INTEGER, value & 0x7fffffff);
                    }
                    break;

                    /*
                     * Similarly for the Interrupt and Context switch statistics
                     *   (raw and per-second, calculated over the last minute)
                     */
                case SYSRAWINTERRUPTS:
                    snmp_set_var_typed_integer (requests->requestvb, ASN_COUNTER, info->nInterrupts & 0xffffffff);
                    break;
                case SYSRAWCONTEXT:
                    snmp_set_var_typed_integer (requests->requestvb, ASN_COUNTER, info->nCtxSwitches & 0xffffffff);
                    break;
                case SYSINTERRUPTS:
                    if (info->history && info->history[0].total_hist)
                    {
                        value = (info->nInterrupts - info->history[0].intr_hist) / 60;
                        snmp_set_var_typed_integer (requests->requestvb, ASN_INTEGER, value & 0x7fffffff);
                    }
                    break;
                case SYSCONTEXT:
                    if (info->history && info->history[0].total_hist)
                    {
                        value = (info->nCtxSwitches - info->history[0].ctx_hist) / 60;
                        snmp_set_var_typed_integer (requests->requestvb, ASN_INTEGER, value & 0x7fffffff);
                    }
                    break;

                    /*
                     * Similarly for the Swap statistics...
                     */
                case RAWSWAPIN:
                    snmp_set_var_typed_integer (requests->requestvb, ASN_COUNTER, info->swapIn & 0xffffffff);
                    break;
                case RAWSWAPOUT:
                    snmp_set_var_typed_integer (requests->requestvb, ASN_COUNTER, info->swapOut & 0xffffffff);
                    break;
                case SWAPIN:
                    if (info->history && info->history[0].total_hist)
                    {
                        value = (info->swapIn - info->history[0].swpi_hist) / 60;
                        /* ??? value *= PAGE_SIZE;  */
                        snmp_set_var_typed_integer (requests->requestvb, ASN_INTEGER, value & 0x7fffffff);
                    }
                    break;
                case SWAPOUT:
                    if (info->history && info->history[0].total_hist)
                    {
                        value = (info->swapOut - info->history[0].swpo_hist) / 60;
                        /* ??? value *= PAGE_SIZE;  */
                        snmp_set_var_typed_integer (requests->requestvb, ASN_INTEGER, value & 0x7fffffff);
                    }
                    break;

                    /*
                     * ... and the I/O statistics.
                     */
                case IORAWSENT:
                    snmp_set_var_typed_integer (requests->requestvb, ASN_COUNTER, info->pageOut & 0xffffffff);
                    break;
                case IORAWRECEIVE:
                    snmp_set_var_typed_integer (requests->requestvb, ASN_COUNTER, info->pageIn & 0xffffffff);
                    break;
                case IOSENT:
                    if (info->history && info->history[0].total_hist)
                    {
                        value = (info->pageOut - info->history[0].pageo_hist) / 60;
                        snmp_set_var_typed_integer (requests->requestvb, ASN_INTEGER, value & 0x7fffffff);
                    }
                    break;
                case IORECEIVE:
                    if (info->history && info->history[0].total_hist)
                    {
                        value = (info->pageIn - info->history[0].pagei_hist) / 60;
                        snmp_set_var_typed_integer (requests->requestvb, ASN_INTEGER, value & 0x7fffffff);
                    }
                    break;

                default:

/*
   XXX - The systemStats group is "holely", so walking it would
         trigger this message repeatedly.  We really need a form
         of the table column registration mechanism, that would
         work with scalar groups.
               snmp_log(LOG_ERR,
                   "unknown object (%d) in vmstat_handler\n", (int)obj);
 */
                    break;
            }
            break;

        default:
            snmp_log (LOG_ERR, "unknown mode (%d) in vmstat_handler\n", reqinfo->mode);
            return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}
Example #29
0
/************************************************************
 * saHpiRdrTable_get_value
 *
 * This routine is called for get requests to copy the data
 * from the context to the varbind for the request. If the
 * context has been properly maintained, you don't need to
 * change in code in this fuction.
 */
int saHpiRdrTable_get_value(
            netsnmp_request_info *request,
            netsnmp_index *item,
            netsnmp_table_request_info *table_info )
{
	netsnmp_variable_list *var = request->requestvb;
	saHpiRdrTable_context *context = (saHpiRdrTable_context *)item;

	DEBUGMSGTL ((AGENT, "saHpiRdrTable_get_value, called\n"));

	switch(table_info->colnum) {
	
	    case COLUMN_SAHPIRDRENTRYID:
		/** COUNTER = ASN_COUNTER */
		snmp_set_var_typed_value(var, ASN_COUNTER,
			 (char*)&context->saHpiRdrEntryId,
			 sizeof(context->saHpiRdrEntryId) );
	    break;
	
	    case COLUMN_SAHPIRDRNEXTENTRYID:
		/** COUNTER = ASN_COUNTER */
		snmp_set_var_typed_value(var, ASN_COUNTER,
			 (char*)&context->saHpiRdrNextEntryId,
			 sizeof(context->saHpiRdrNextEntryId) );
	    break;
	
	    case COLUMN_SAHPIRDRTYPE:
		/** INTEGER = ASN_INTEGER */
		snmp_set_var_typed_value(var, ASN_INTEGER,
			 (char*)&context->saHpiRdrType,
			 sizeof(context->saHpiRdrType) );
	    break;
	
	    case COLUMN_SAHPIRDRENTITYPATH:
		/** SaHpiEntityPath = ASN_OCTET_STR */
		snmp_set_var_typed_value(var, ASN_OCTET_STR,
			 (char*)&context->saHpiRdrEntityPath,
			 context->saHpiRdrEntityPath_len );
	    break;
	
	    case COLUMN_SAHPIRDRISFRU:
		/** TruthValue = ASN_INTEGER */
		snmp_set_var_typed_value(var, ASN_INTEGER,
			 (char*)&context->saHpiRdrIsFru,
			 sizeof(context->saHpiRdrIsFru) );
	    break;
	
	    case COLUMN_SAHPIRDRROWPOINTER:
		/** RowPointer = ASN_OBJECT_ID */
		snmp_set_var_typed_value(var, ASN_OBJECT_ID,
			 (char*)&context->saHpiRdrRowPointer,
			 context->saHpiRdrRowPointer_len );
	    break;
	
	    case COLUMN_SAHPIRDRRPT:
		/** RowPointer = ASN_OBJECT_ID */
		snmp_set_var_typed_value(var, ASN_OBJECT_ID,
			 (char*)&context->saHpiRdrRPT,
			 context->saHpiRdrRPT_len );
	    break;
	
	    case COLUMN_SAHPIRDRTEXTTYPE:
		/** SaHpiTextType = ASN_INTEGER */
		snmp_set_var_typed_value(var, ASN_INTEGER,
			 (char*)&context->saHpiRdrTextType,
			 sizeof(context->saHpiRdrTextType) );
	    break;
	
	    case COLUMN_SAHPIRDRTEXTLANGUAGE:
		/** SaHpiTextLanguage = ASN_INTEGER */
		snmp_set_var_typed_value(var, ASN_INTEGER,
			 (char*)&context->saHpiRdrTextLanguage,
			 sizeof(context->saHpiRdrTextLanguage) );
	    break;
	
	    case COLUMN_SAHPIRDRIDSTRING:
		/** OCTETSTR = ASN_OCTET_STR */
		snmp_set_var_typed_value(var, ASN_OCTET_STR,
			 (char*)&context->saHpiRdrIdString,
			 context->saHpiRdrIdString_len );
	    break;
	
	default: /** We shouldn't get here */
	    snmp_log(LOG_ERR, "unknown column in "
		 "saHpiRdrTable_get_value\n");
	    return SNMP_ERR_GENERR;
	}
	return SNMP_ERR_NOERROR;
}
Example #30
0
int
handle_nsDebugTable(netsnmp_mib_handler *handler,
                netsnmp_handler_registration *reginfo,
                netsnmp_agent_request_info *reqinfo,
                netsnmp_request_info *requests)
{
    long status;
    netsnmp_request_info       *request    =NULL;
    netsnmp_table_request_info *table_info    =NULL;
    netsnmp_token_descr        *debug_entry=NULL;

    switch (reqinfo->mode) {

    case MODE_GET:
        for (request=requests; request; request=request->next) {
            if (request->processed != 0)
                continue;
            debug_entry = (netsnmp_token_descr*)
                           netsnmp_extract_iterator_context(request);
            if (!debug_entry)
                continue;
	    status = (debug_entry->enabled ? RS_ACTIVE : RS_NOTINSERVICE);
	    snmp_set_var_typed_value(request->requestvb, ASN_INTEGER,
                                     (u_char*)&status, sizeof(status));
	}
	break;


    case MODE_SET_RESERVE1:
	for (request = requests; request; request=request->next) {
            if (request->processed != 0)
                continue;
            if ( request->status != 0 ) {
                return SNMP_ERR_NOERROR;	/* Already got an error */
            }
            if ( request->requestvb->type != ASN_INTEGER ) {
                netsnmp_set_request_error(reqinfo, request, SNMP_ERR_WRONGTYPE);
                return SNMP_ERR_WRONGTYPE;
            }

            debug_entry = (netsnmp_token_descr*)
                           netsnmp_extract_iterator_context(request);
            switch (*request->requestvb->val.integer) {
            case RS_ACTIVE:
            case RS_NOTINSERVICE:
                /*
		 * These operations require an existing row
		 */
                if (!debug_entry) {
		    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_ERR_INCONSISTENTVALUE);
                    return SNMP_ERR_INCONSISTENTVALUE;
		}
		break;

            case RS_CREATEANDWAIT:
            case RS_CREATEANDGO:
                /*
		 * These operations assume the row doesn't already exist
		 */
                if (debug_entry) {
		    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_ERR_INCONSISTENTVALUE);
                    return SNMP_ERR_INCONSISTENTVALUE;
		}
		break;

            case RS_DESTROY:
                /*
		 * This operation can work regardless
		 */
		break;

            case RS_NOTREADY:
            default:
		netsnmp_set_request_error(reqinfo, request,
                                          SNMP_ERR_WRONGVALUE);
                return SNMP_ERR_WRONGVALUE;
	    }
        }
        break;


    case MODE_SET_COMMIT:
	for (request = requests; request; request=request->next) {
            if (request->processed != 0)
                continue;
            if ( request->status != 0 ) {
                return SNMP_ERR_NOERROR;	/* Already got an error */
            }

            switch (*request->requestvb->val.integer) {
            case RS_ACTIVE:
            case RS_NOTINSERVICE:
                /*
		 * Update the enabled field appropriately
		 */
                debug_entry = (netsnmp_token_descr*)
                               netsnmp_extract_iterator_context(request);
                debug_entry->enabled =
                    (*request->requestvb->val.integer == RS_ACTIVE);
		break;

            case RS_CREATEANDWAIT:
            case RS_CREATEANDGO:
                /*
		 * Create the entry, and set the enabled field appropriately
		 */
                table_info = netsnmp_extract_table_info(request);
                debug_register_tokens(table_info->indexes->val.string);
#ifdef UMMMMM
                if (*request->requestvb->val.integer == RS_CREATEANDWAIT) {
		    /* XXX - how to locate the entry ??  */
		    debug_entry->enabled = 0;
		}
#endif
		break;

            case RS_DESTROY:
                /*
		 * XXX - there's no "remove" API  :-(
		 */
                debug_entry = (netsnmp_token_descr*)
                               netsnmp_extract_iterator_context(request);
                if (debug_entry) {
		    debug_entry->enabled = 0;
		    free(debug_entry->token_name);
		    debug_entry->token_name = NULL;
		}
		break;
	    }
        }
        break;
    }

    return SNMP_ERR_NOERROR;
}