コード例 #1
0
ファイル: sipProxyCfg.c プロジェクト: BackupTheBerlios/ser
/** 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;
}
コード例 #2
0
/** handles requests for the dot11WtpKeyConfigTable table */
int
dot11WtpKeyConfigTable_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 dot11WtpKeyConfigTable_entry          *table_entry;

    switch (reqinfo->mode) {
        /*
         * Read-support (also covers GetNext requests)
         */
    case MODE_GET:
        for (request=requests; request; request=request->next) {
            table_entry = (struct dot11WtpKeyConfigTable_entry *)
                              netsnmp_extract_iterator_context(request);
            table_info  =     netsnmp_extract_table_info(      request);


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

	
            switch (table_info->colnum) {
            case COLUMN_CIPHERKEYINDEX:
                snmp_set_var_typed_value( request->requestvb, ASN_INTEGER,
                                          (u_char*)&table_entry->CipherKeyIndex,
                                          sizeof(long));
                break;
            case COLUMN_CIPHERKEYVALUE:
                snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
                                          (u_char*)table_entry->CipherKeyValue,
                                          strlen(table_entry->CipherKeyValue));
                break;
            case COLUMN_CIPHERKEYCHARTYPE:
                snmp_set_var_typed_value( request->requestvb, ASN_INTEGER,
                                          (u_char*)&table_entry->CipherKeyCharType,
                                          sizeof(long));
                break;
            }
        }
        break;

        /*
         * Write-support
         */
    case MODE_SET_RESERVE1:
        for (request=requests; request; request=request->next) {
            table_entry = (struct dot11WtpKeyConfigTable_entry *)
                              netsnmp_extract_iterator_context(request);
            table_info  =     netsnmp_extract_table_info(      request);
    
            switch (table_info->colnum) {
            case COLUMN_CIPHERKEYVALUE:
                if ( request->requestvb->type != ASN_OCTET_STR ) {
                    netsnmp_set_request_error( reqinfo, request,
                                               SNMP_ERR_WRONGTYPE );
                    return SNMP_ERR_NOERROR;
                }
                /* Also may need to check size/value */
                break;
            case COLUMN_CIPHERKEYCHARTYPE:
                if ( request->requestvb->type != ASN_INTEGER ) {
                    netsnmp_set_request_error( reqinfo, request,
                                               SNMP_ERR_WRONGTYPE );
                    return SNMP_ERR_NOERROR;
                }
                /* Also may need to check size/value */
                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 dot11WtpKeyConfigTable_entry *)
                              netsnmp_extract_iterator_context(request);
            table_info  =     netsnmp_extract_table_info(      request);
    
            switch (table_info->colnum) {
            case COLUMN_CIPHERKEYVALUE:
                /* Need to save old 'table_entry->CipherKeyValue' value.
                   May need to use 'memcpy' */
                table_entry->old_CipherKeyValue = table_entry->CipherKeyValue;
             //   table_entry->CipherKeyValue     = request->requestvb->val.YYY;
                break;
            case COLUMN_CIPHERKEYCHARTYPE:
                /* Need to save old 'table_entry->CipherKeyCharType' value.
                   May need to use 'memcpy' */
                table_entry->old_CipherKeyCharType = table_entry->CipherKeyCharType;
             //   table_entry->CipherKeyCharType     = request->requestvb->val.YYY;
                break;
            }
        }
        break;

    case MODE_SET_UNDO:
        for (request=requests; request; request=request->next) {
            table_entry = (struct dot11WtpKeyConfigTable_entry *)
                              netsnmp_extract_iterator_context(request);
            table_info  =     netsnmp_extract_table_info(      request);
    
            switch (table_info->colnum) {
            case COLUMN_CIPHERKEYVALUE:
                /* Need to restore old 'table_entry->CipherKeyValue' value.
                   May need to use 'memcpy' */
                table_entry->CipherKeyValue = table_entry->old_CipherKeyValue;
                break;
            case COLUMN_CIPHERKEYCHARTYPE:
                /* Need to restore old 'table_entry->CipherKeyCharType' value.
                   May need to use 'memcpy' */
                table_entry->CipherKeyCharType = table_entry->old_CipherKeyCharType;
                break;
            }
        }
        break;

    case MODE_SET_COMMIT:
        break;
    }
    return SNMP_ERR_NOERROR;
}
コード例 #3
0
ファイル: table_dataset.c プロジェクト: DYFeng/infinidb
/** implements the table data helper.  This is the routine that takes
 *  care of all SNMP requests coming into the table. */
int
netsnmp_table_data_set_helper_handler(netsnmp_mib_handler *handler,
                                      netsnmp_handler_registration
                                      *reginfo,
                                      netsnmp_agent_request_info *reqinfo,
                                      netsnmp_request_info *requests)
{

    netsnmp_table_data_set_storage *data = NULL;
    newrow_stash   *newrowstash = NULL;
    netsnmp_table_row *row, *newrow = NULL;
    netsnmp_table_request_info *table_info;
    netsnmp_request_info *request;
    oid            *suffix;
    size_t          suffix_len;
    netsnmp_oid_stash_node **stashp = NULL;

    if (!handler)
        return SNMPERR_GENERR;
        
    DEBUGMSGTL(("netsnmp_table_data_set", "handler starting\n"));
    for (request = requests; request; request = request->next) {
        netsnmp_table_data_set *datatable =
            (netsnmp_table_data_set *) handler->myvoid;
        if (request->processed)
            continue;

        /*
         * extract our stored data and table info 
         */
        row = netsnmp_extract_table_row(request);
        table_info = netsnmp_extract_table_info(request);
        suffix = requests->requestvb->name + reginfo->rootoid_len + 2;
        suffix_len = requests->requestvb->name_length -
            (reginfo->rootoid_len + 2);

        if (MODE_IS_SET(reqinfo->mode)) {

            char buf[256]; /* is this reasonable size?? */
            int  rc;
            size_t len;

            /*
             * use a cached copy of the row for modification 
             */

            /*
             * cache location: may have been created already by other
             * SET requests in the same master request. 
             */
            rc = snprintf(buf, sizeof(buf), "dataset_row_stash:%s:",
                          datatable->table->name);
            if ((-1 == rc) || (rc >= sizeof(buf))) {
                snmp_log(LOG_ERR,"%s handler name too long\n",
                         datatable->table->name);
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_ERR_GENERR);
                continue;
            }
            len = sizeof(buf) - rc;
            rc = snprint_objid(&buf[rc], len, table_info->index_oid,
                               table_info->index_oid_len);
            if (-1 == rc) {
                snmp_log(LOG_ERR,"%s oid or name too long\n",
                         datatable->table->name);
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_ERR_GENERR);
                continue;
            }
            stashp = (netsnmp_oid_stash_node **)
                netsnmp_table_get_or_create_row_stash(reqinfo, buf);

            newrowstash
                = netsnmp_oid_stash_get_data(*stashp, suffix, suffix_len);

            if (!newrowstash) {
                if (!row) {
                    if (datatable->allow_creation) {
                        /*
                         * entirely new row.  Create the row from the template 
                         */
                        newrowstash =
                             netsnmp_table_data_set_create_newrowstash(
                                                 datatable, table_info);
                        newrow = newrowstash->newrow;
                    } else if (datatable->rowstatus_column == 0) {
                        /*
                         * A RowStatus object may be used to control the
                         *  creation of a new row.  But if this object
                         *  isn't declared (and the table isn't marked as
                         *  'auto-create'), then we can't create a new row.
                         */
                        netsnmp_set_request_error(reqinfo, request,
                                                  SNMP_ERR_NOCREATION);
                        continue;
                    }
                } else {
                    /*
                     * existing row that needs to be modified 
                     */
                    newrowstash = SNMP_MALLOC_TYPEDEF(newrow_stash);
                    newrow = netsnmp_table_data_set_clone_row(row);
                    newrowstash->newrow = newrow;
                }
                netsnmp_oid_stash_add_data(stashp, suffix, suffix_len,
                                           newrowstash);
            } else {
                newrow = newrowstash->newrow;
            }
            /*
             * all future SET data modification operations use this
             * temp pointer 
             */
            if (reqinfo->mode == MODE_SET_RESERVE1 ||
                reqinfo->mode == MODE_SET_RESERVE2)
                row = newrow;
        }

        if (row)
            data = (netsnmp_table_data_set_storage *) row->data;

        if (!row || !table_info || !data) {
            if (!MODE_IS_SET(reqinfo->mode)) {
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_NOSUCHINSTANCE);
                continue;
            }
        }

        data =
            netsnmp_table_data_set_find_column(data, table_info->colnum);

        switch (reqinfo->mode) {
        case MODE_GET:
        case MODE_GETNEXT:
        case MODE_GETBULK:     /* XXXWWW */
            if (data && data->data.voidp)
                netsnmp_table_data_build_result(reginfo, reqinfo, request,
                                                row,
                                                table_info->colnum,
                                                data->type,
                                                data->data.voidp,
                                                data->data_len);
            break;

        case MODE_SET_RESERVE1:
            if (data) {
                /*
                 * Can we modify the existing row?
                 */
                if (!data->writable) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_ERR_NOTWRITABLE);
                } else if (request->requestvb->type != data->type) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_ERR_WRONGTYPE);
                }
            } else if (datatable->rowstatus_column == table_info->colnum) {
                /*
                 * Otherwise, this is where we create a new row using
                 * the RowStatus object (essentially duplicating the
                 * steps followed earlier in the 'allow_creation' case)
                 */
                switch (*(request->requestvb->val.integer)) {
                case RS_CREATEANDGO:
                case RS_CREATEANDWAIT:
                    newrowstash =
                             netsnmp_table_data_set_create_newrowstash(
                                                 datatable, table_info);
                    newrow = newrowstash->newrow;
                    row    = newrow;
                    netsnmp_oid_stash_add_data(stashp, suffix, suffix_len,
                                               newrowstash);
                }
            }
            break;

        case MODE_SET_RESERVE2:
            /*
             * If the agent receives a SET request for an object in a non-existant
             *  row, then the RESERVE1 pass will create the row automatically.
             *
             * But since the row doesn't exist at that point, the test for whether
             *  the object is writable or not will be skipped.  So we need to check
             *  for this possibility again here.
             *
             * Similarly, if row creation is under the control of the RowStatus
             *  object (i.e. allow_creation == 0), but this particular request
             *  doesn't include such an object, then the row won't have been created,
             *  and the writable check will also have been skipped.  Again - check here.
             */
            if (data && data->writable == 0) {
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_ERR_NOTWRITABLE);
                continue;
            }
            if (datatable->rowstatus_column == table_info->colnum) {
                switch (*(request->requestvb->val.integer)) {
                case RS_ACTIVE:
                case RS_NOTINSERVICE:
                    /*
                     * Can only operate on pre-existing rows.
                     */
                    if (!newrowstash || newrowstash->created) {
                        netsnmp_set_request_error(reqinfo, request,
                                                  SNMP_ERR_INCONSISTENTVALUE);
                        continue;
                    }
                    break;

                case RS_CREATEANDGO:
                case RS_CREATEANDWAIT:
                    /*
                     * Can only operate on newly created rows.
                     */
                    if (!(newrowstash && newrowstash->created)) {
                        netsnmp_set_request_error(reqinfo, request,
                                                  SNMP_ERR_INCONSISTENTVALUE);
                        continue;
                    }
                    break;

                case RS_DESTROY:
                    /*
                     * Can operate on new or pre-existing rows.
                     */
                    break;

                case RS_NOTREADY:
                default:
                    /*
                     * Not a valid value to Set 
                     */
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_ERR_WRONGVALUE);
                    continue;
                }
            }
            if (!data ) {
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_ERR_NOCREATION);
                continue;
            }

            /*
             * modify row and set new value 
             */
            SNMP_FREE(data->data.string);
            data->data.string =
                netsnmp_strdup_and_null(request->requestvb->val.string,
                                        request->requestvb->val_len);
            if (!data->data.string) {
                netsnmp_set_request_error(reqinfo, requests,
                                          SNMP_ERR_RESOURCEUNAVAILABLE);
            }
            data->data_len = request->requestvb->val_len;

            if (datatable->rowstatus_column == table_info->colnum) {
                switch (*(request->requestvb->val.integer)) {
                case RS_CREATEANDGO:
                    /*
                     * XXX: check legality 
                     */
                    *(data->data.integer) = RS_ACTIVE;
                    break;

                case RS_CREATEANDWAIT:
                    /*
                     * XXX: check legality 
                     */
                    *(data->data.integer) = RS_NOTINSERVICE;
                    break;

                case RS_DESTROY:
                    newrowstash->deleted = 1;
                    break;
                }
            }
            break;

        case MODE_SET_ACTION:

            /*
             * Install the new row into the stored table.
	     * Do this only *once* per row ....
             */
            if (newrowstash->state != STATE_ACTION) {
                newrowstash->state = STATE_ACTION;
		if (newrowstash->created) {
                    netsnmp_table_dataset_add_row(datatable, newrow);
                } else {
                    netsnmp_table_dataset_replace_row(datatable,
                                                      row, newrow);
                }
            }
            /*
             * ... but every (relevant) varbind in the request will
	     * need to know about this new row, so update the
	     * per-request row information regardless
             */
            if (newrowstash->created) {
		netsnmp_request_add_list_data(request,
			netsnmp_create_data_list(TABLE_DATA_NAME,
						 newrow, NULL));
            }
            break;

        case MODE_SET_UNDO:
            /*
             * extract the new row, replace with the old or delete 
             */
            if (newrowstash->state != STATE_UNDO) {
                newrowstash->state = STATE_UNDO;
                if (newrowstash->created) {
                    netsnmp_table_dataset_remove_and_delete_row(datatable, newrow);
                } else {
                    netsnmp_table_dataset_replace_row(datatable,
                                                      newrow, row);
                    netsnmp_table_dataset_delete_row(newrow);
                }
            }
            break;

        case MODE_SET_COMMIT:
            if (newrowstash->state != STATE_COMMIT) {
                newrowstash->state = STATE_COMMIT;
                if (!newrowstash->created) {
                    netsnmp_table_dataset_delete_row(row);
                }
                if (newrowstash->deleted) {
                    netsnmp_table_dataset_remove_and_delete_row(datatable, newrow);
                }
            }
            break;

        case MODE_SET_FREE:
            if (newrowstash && newrowstash->state != STATE_FREE) {
                newrowstash->state = STATE_FREE;
                netsnmp_table_dataset_delete_row(newrow);
            }
            break;
        }
    }

    /* next handler called automatically - 'AUTO_NEXT' */
    return SNMP_ERR_NOERROR;
}
コード例 #4
0
ファイル: testhandler.c プロジェクト: ClausKlein/net-snmp
int
my_test_table_handler(netsnmp_mib_handler *handler,
                      netsnmp_handler_registration *reginfo,
                      netsnmp_agent_request_info *reqinfo,
                      netsnmp_request_info *requests)
{

    netsnmp_table_registration_info
        *handler_reg_info =
        (netsnmp_table_registration_info *) handler->prev->myvoid;

    netsnmp_table_request_info *table_info;
    u_long          result;
    int             x, y;

    while (requests) {
        netsnmp_variable_list *var = requests->requestvb;

        if (requests->processed != 0)
            continue;

        DEBUGMSGTL(("testhandler_table", "Got request:\n"));
        DEBUGMSGTL(("testhandler_table", "  oid:"));
        DEBUGMSGOID(("testhandler_table", var->name, var->name_length));
        DEBUGMSG(("testhandler_table", "\n"));

        table_info = netsnmp_extract_table_info(requests);
        if (table_info == NULL) {
            requests = requests->next;
            continue;
        }

        switch (reqinfo->mode) {
        case MODE_GETNEXT:
            /*
             * beyond our search range? 
             */
            if (table_info->colnum > RESULT_COLUMN)
                break;

            /*
             * below our minimum column? 
             */
            if (table_info->colnum < RESULT_COLUMN ||
                /*
                 * or no index specified 
                 */
                table_info->indexes->val.integer == 0) {
                table_info->colnum = RESULT_COLUMN;
                x = 0;
                y = 0;
            } else {
                x = *(table_info->indexes->val.integer);
                y = *(table_info->indexes->next_variable->val.integer);
            }

            if (table_info->number_indexes ==
                handler_reg_info->number_indexes) {
                y++;            /* GETNEXT is basically just y+1 for this table */
                if (y > MAX_COLTWO) {   /* (with wrapping) */
                    y = 0;
                    x++;
                }
            }
            if (x <= MAX_COLONE) {
                result = x * y;

                *(table_info->indexes->val.integer) = x;
                *(table_info->indexes->next_variable->val.integer) = y;
                netsnmp_table_build_result(reginfo, requests,
                                           table_info, ASN_INTEGER,
                                           (u_char *) & result,
                                           sizeof(result));
            }

            break;

        case MODE_GET:
            if (var->type == ASN_NULL) {        /* valid request if ASN_NULL */
                /*
                 * is it the right column? 
                 */
                if (table_info->colnum == RESULT_COLUMN &&
                    /*
                     * and within the max boundries? 
                     */
                    *(table_info->indexes->val.integer) <= MAX_COLONE &&
                    *(table_info->indexes->next_variable->val.integer)
                    <= MAX_COLTWO) {

                    /*
                     * then, the result is column1 * column2 
                     */
                    result = *(table_info->indexes->val.integer) *
                        *(table_info->indexes->next_variable->val.integer);
                    snmp_set_var_typed_value(var, ASN_INTEGER,
                                             (u_char *) & result,
                                             sizeof(result));
                }
            }
            break;

        }

        requests = requests->next;
    }

    return SNMP_ERR_NOERROR;
}
コード例 #5
0
/** handles requests for the dot1dBasePortTable table, if anything else needs to be done */
int
dot1dBasePortTable_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;
  netsnmp_variable_list *var;

  void *data_context = NULL;

  (void) reginfo;
  (void) handler;

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

    switch (reqinfo->mode) {
      case MODE_GET:
        data_context =  netsnmp_extract_iterator_context(request);
        if (data_context == NULL) {
          netsnmp_set_request_error(reqinfo, request,
                                    SNMP_NOSUCHINSTANCE);
          continue;
        }
        break;

    }

    /** extracts the information about the table from the request */
    table_info = netsnmp_extract_table_info(request);
    /** table_info->colnum contains the column number requested */
    /** table_info->indexes contains a linked list of snmp variable
        bindings for the indexes of the table.  Values in the list
        have been set corresponding to the indexes of the
        request */
    if (table_info == NULL) {
      continue;
    }

    switch (reqinfo->mode) {
      case MODE_GET:
        switch (table_info->colnum) {
          case COLUMN_DOT1DBASEPORT: {
            int32_t *retval;
            size_t retval_len = 0;
            retval = get_dot1dBasePort(data_context, &retval_len);
            if (retval)
              snmp_set_var_typed_value(var, ASN_INTEGER,
                                       (const u_char *) retval,
                                       retval_len);
          }
          break;

          case COLUMN_DOT1DBASEPORTIFINDEX: {
            int32_t *retval;
            size_t retval_len = 0;
            retval = get_dot1dBasePortIfIndex(data_context, &retval_len);
            if (retval)
              snmp_set_var_typed_value(var, ASN_INTEGER,
                                       (const u_char *) retval,
                                       retval_len);
          }
          break;

          case COLUMN_DOT1DBASEPORTCIRCUIT: {
            oid *retval;
            size_t retval_len = 0;
            retval = get_dot1dBasePortCircuit(data_context, &retval_len);
            if (retval)
              snmp_set_var_typed_value(var, ASN_OBJECT_ID,
                                       (const u_char *) retval,
                                       retval_len);
          }
          break;

          case COLUMN_DOT1DBASEPORTDELAYEXCEEDEDDISCARDS: {
            uint32_t *retval;
            size_t retval_len = 0;
            retval = get_dot1dBasePortDelayExceededDiscards(data_context, &retval_len);
            if (retval)
              snmp_set_var_typed_value(var, ASN_COUNTER,
                                       (const u_char *) retval,
                                       retval_len);
          }
          break;

          case COLUMN_DOT1DBASEPORTMTUEXCEEDEDDISCARDS: {
            uint32_t *retval;
            size_t retval_len = 0;
            retval = get_dot1dBasePortMtuExceededDiscards(data_context, &retval_len);
            if (retval)
              snmp_set_var_typed_value(var, ASN_COUNTER,
                                       (const u_char *) retval,
                                       retval_len);
          }
          break;

          default:
            /** We shouldn't get here */
            snmp_log(LOG_ERR,
                     "problem encountered in dot1dBasePortTable_handler: unknown column\n");
        }
        break;


      default:
        snmp_log(LOG_ERR,
                 "problem encountered in dot1dBasePortTable_handler: unsupported mode\n");
    }
  }


  return SNMP_ERR_NOERROR;
}
コード例 #6
0
ファイル: table_data.c プロジェクト: Undrizzle/apps
/** inserts a newly created table_data row into a request */
NETSNMP_INLINE void
netsnmp_insert_table_row(netsnmp_request_info *request,
                         netsnmp_table_row *row)
{
    netsnmp_request_info       *req;
    netsnmp_table_request_info *table_info = NULL;
    netsnmp_variable_list      *this_index = NULL;
    netsnmp_variable_list      *that_index = NULL;
    oid      base_oid[] = {0, 0};	/* Make sure index OIDs are legal! */
    oid      this_oid[MAX_OID_LEN];
    oid      that_oid[MAX_OID_LEN];
    size_t   this_oid_len, that_oid_len;

    if (!request)
        return;

    /*
     * We'll add the new row information to any request
     * structure with the same index values as the request
     * passed in (which includes that one!).
     *
     * So construct an OID based on these index values.
     */

    table_info = netsnmp_extract_table_info(request);
    this_index = table_info->indexes;
    build_oid_noalloc(this_oid, MAX_OID_LEN, &this_oid_len,
                      base_oid, 2, this_index);

    /*
     * We need to look through the whole of the request list
     * (as received by the current handler), as there's no
     * guarantee that this routine will be called by the first
     * varbind that refers to this row.
     *   In particular, a RowStatus controlled row creation
     * may easily occur later in the variable list.
     *
     * So first, we rewind to the head of the list....
     */
    for (req=request; req->prev; req=req->prev)
        ;

    /*
     * ... and then start looking for matching indexes
     * (by constructing OIDs from these index values)
     */
    for (; req; req=req->next) {
        table_info = netsnmp_extract_table_info(req);
        that_index = table_info->indexes;
        build_oid_noalloc(that_oid, MAX_OID_LEN, &that_oid_len,
                          base_oid, 2, that_index);
      
        /*
         * This request has the same index values,
         * so add the newly-created row information.
         */
        if (snmp_oid_compare(this_oid, this_oid_len,
                             that_oid, that_oid_len) == 0) {
            netsnmp_request_add_list_data(req,
                netsnmp_create_data_list(TABLE_DATA_ROW, row, NULL));
        }
    }
}
コード例 #7
0
ファイル: gpDroneMIB.c プロジェクト: rafaelfonte/gpDrone-SNMP
int
lightingTable_handler(
    netsnmp_mib_handler               *handler,
    netsnmp_handler_registration      *reginfo,
    netsnmp_agent_request_info        *reqinfo,
    netsnmp_request_info              *requests) {
    /* perform anything here that you need to do.  The requests have
       already been processed by the master table_dataset handler, but
       this gives you chance to act on the request in some other way
       if need be. */
//struct tb_entry{
//	int index;
//	char descr[256];
//	int toggle;
//};
    DEBUGMSGTL(("gpDroneMIB","got into the handler...., reqinfo is %d\n",reqinfo->mode));
	//struct light_table_entry *temp;
	netsnmp_table_request_info *table_info = netsnmp_extract_table_info(requests);
	int colnum = table_info->colnum,index = *(table_info->indexes->val.integer);
	char buf_val[32];
	//my_table
	//my_table[i-1].index = i;
	//strncpy(my_table[i-1].descr,l_table[i-1].descr,256);
	//my_table[i-1].toggle = 0;//TODO: initialize
	//temp = (struct light_table_entry*)netsnmp_tdata_extract_entry(requests);
	//for(i = 0; i < 20; i++){
	//DEBUGMSGTL(("gpDroneMIB","This is the column we got: %d\n", table_info->colnum));
	//DEBUGMSGTL(("gpDroneMIB","This is the column we got: %p %p\n", table_info, requests));
	//DEBUGMSGTL(("gpDroneMIB","This is the value of the first index: %d\n", *(table_info->indexes->val.integer)));

	DEBUGMSGTL(("gpDroneMIB","Request was col %d idx %d\n",colnum, index));

	switch(reqinfo->mode){
		case MODE_SET_RESERVE1:
			if(index < 1 || index > 5){
				netsnmp_set_request_error(reqinfo,requests,SNMP_NOSUCHINSTANCE);
				break;
			}
		case MODE_SET_RESERVE2:
		case MODE_SET_FREE:
		case MODE_SET_COMMIT:
			break;
		case MODE_SET_ACTION:
			DEBUGMSGTL(("gpDroneMIB", "tableSetToggle ACTION\n"));
			my_table[index-1].toggle = *(requests->requestvb->val.integer);//Setting the variable
			sprintf(buf_val,"%ld",my_table[index-1].toggle);
			DEBUGMSGTL(("gpDroneMIB", "lgSetPosition val: %ld:\n", buf_val));
			runSetScript(my_table[index-1].descr,buf_val);
			break;
		case MODE_GET:
		case MODE_GETNEXT:
			if(index < 1 || index > 5){
				netsnmp_set_request_error(reqinfo,requests,SNMP_NOSUCHINSTANCE);
				break;
			}
			switch(colnum){
				case 1:
					snmp_set_var_typed_value(requests->requestvb,ASN_INTEGER,&(my_table[index-1].index),sizeof(long));
	DEBUGMSGTL(("gpDroneMIB","Returning INTEGER<idx=%d,col=%d> : %ld\n", index,colnum,my_table[index-1].index));
					break;
				case 2:
					snmp_set_var_typed_value(requests->requestvb,ASN_OCTET_STR,my_table[index-1].descr,strlen(my_table[index-1].descr));
	DEBUGMSGTL(("gpDroneMIB","Returning OCTET_STR<idx=%d,col=%d> : %s\n", index,colnum,my_table[index-1].descr));
					break;
				case 3:
					fetch_integer(my_table[index-1].descr,&(my_table[index-1].toggle));
					snmp_set_var_typed_value(requests->requestvb,ASN_INTEGER,&(my_table[index-1].toggle),sizeof(long));
	DEBUGMSGTL(("gpDroneMIB","Returning INTEGER<idx=%d,col=%d> : %ld\n", index,colnum,my_table[index-1].toggle));
					break;
				default:
					DEBUGMSGTL(("gpDroneMIB","Unknown request...\n"));
			}
			break;
	}

    return SNMP_ERR_NOERROR;
}
コード例 #8
0
ファイル: table_array.c プロジェクト: NieHao/Tomato-RAF
/**********************************************************************
 **********************************************************************
 *                                                                    *
 *                                                                    *
 * GET procession functions                                           *
 *                                                                    *
 *                                                                    *
 **********************************************************************
 **********************************************************************/
NETSNMP_INLINE int
process_get_requests(netsnmp_handler_registration *reginfo,
                     netsnmp_agent_request_info *agtreq_info,
                     netsnmp_request_info *requests,
                     table_container_data * tad)
{
    int             rc = SNMP_ERR_NOERROR;
    netsnmp_request_info *current;
    netsnmp_index *row = NULL;
    netsnmp_table_request_info *tblreq_info;
    netsnmp_variable_list *var;

    netsnmp_assert(NULL != tad->table);

    /*
     * Loop through each of the requests, and
     * try to find the appropriate row from the container.
     */
    for (current = requests; current; current = current->next) {

        var = current->requestvb;
        DEBUGMSGTL(("table_array:get",
                    "  process_get_request oid:"));
        DEBUGMSGOID(("table_array:get", var->name,
                     var->name_length));
        DEBUGMSG(("table_array:get", "\n"));

        /*
         * skip anything that doesn't need processing.
         */
        if (current->processed != 0) {
            DEBUGMSGTL(("table_array:get", "already processed\n"));
            continue;
        }

        /*
         * Get pointer to the table information for this request. This
         * information was saved by table_helper_handler. When
         * debugging, we double check a few assumptions. For example,
         * the table_helper_handler should enforce column boundaries.
         */
        tblreq_info = netsnmp_extract_table_info(current);
        netsnmp_assert(tblreq_info->colnum <= tad->tblreg_info->max_column);

        if ((agtreq_info->mode == MODE_GETNEXT) ||
                (agtreq_info->mode == MODE_GETBULK)) {
            /*
             * find the row
             */
            row = find_next_row(tblreq_info, tad);
            if (!row) {
                /*
                 * no results found.
                 *
                 * xxx-rks: how do we skip this entry for the next handler,
                 * but still allow it a chance to hit another handler?
                 */
                DEBUGMSGTL(("table_array:get", "no row found\n"));
                continue;
            }

            /*
             * * if data was found, make sure it has the column we want
             */
            /* xxx-rks: add suport for sparse tables */

            /*
             * build new oid
             */
            build_new_oid(reginfo, tblreq_info, row, current);

        } /** GETNEXT/GETBULK */
        else {
            netsnmp_index index;
            index.oids = tblreq_info->index_oid;
            index.len = tblreq_info->index_oid_len;

            row = CONTAINER_FIND(tad->table, &index);
            if (!row) {
                DEBUGMSGTL(("table_array:get", "no row found\n"));
                netsnmp_set_request_error(agtreq_info, current,
                                          SNMP_NOSUCHINSTANCE);
                continue;
            }
        } /** GET */

        /*
         * get the data
         */
        rc = tad->cb->get_value(current, row, tblreq_info);

    } /** for ( ... requests ... ) */

    return rc;
}
コード例 #9
0
ファイル: table_array.c プロジェクト: NieHao/Tomato-RAF
NETSNMP_INLINE void
group_requests(netsnmp_agent_request_info *agtreq_info,
               netsnmp_request_info *requests,
               netsnmp_container *request_group, table_container_data * tad)
{
    netsnmp_table_request_info *tblreq_info;
    netsnmp_variable_list *var;
    netsnmp_index *row, *tmp, index;
    netsnmp_request_info *current;
    netsnmp_request_group *g;
    netsnmp_request_group_item *i;

    for (current = requests; current; current = current->next) {

        var = current->requestvb;

        /*
         * skip anything that doesn't need processing.
         */
        if (current->processed != 0) {
            DEBUGMSGTL(("table_array:group",
                        "already processed\n"));
            continue;
        }

        /*
         * 3.2.1 Setup and paranoia
         * *
         * * Get pointer to the table information for this request. This
         * * information was saved by table_helper_handler. When
         * * debugging, we double check a few assumptions. For example,
         * * the table_helper_handler should enforce column boundaries.
         */
        row = NULL;
        tblreq_info = netsnmp_extract_table_info(current);
        netsnmp_assert(tblreq_info->colnum <= tad->tblreg_info->max_column);

        /*
         * search for index
         */
        index.oids = tblreq_info->index_oid;
        index.len = tblreq_info->index_oid_len;
        tmp = CONTAINER_FIND(request_group, &index);
        if (tmp) {
            DEBUGMSGTL(("table_array:group",
                        "    existing group:"));
            DEBUGMSGOID(("table_array:group", index.oids,
                         index.len));
            DEBUGMSG(("table_array:group", "\n"));
            g = (netsnmp_request_group *) tmp;
            i = SNMP_MALLOC_TYPEDEF(netsnmp_request_group_item);
            i->ri = current;
            i->tri = tblreq_info;
            i->next = g->list;
            g->list = i;

            /** xxx-rks: store map of colnum to request */
            continue;
        }

        DEBUGMSGTL(("table_array:group", "    new group"));
        DEBUGMSGOID(("table_array:group", index.oids,
                     index.len));
        DEBUGMSG(("table_array:group", "\n"));
        g = SNMP_MALLOC_TYPEDEF(netsnmp_request_group);
        i = SNMP_MALLOC_TYPEDEF(netsnmp_request_group_item);
        g->list = i;
        g->table = tad->table;
        i->ri = current;
        i->tri = tblreq_info;
        /** xxx-rks: store map of colnum to request */

        /*
         * search for row. all changes are made to the original row,
         * later, we'll make a copy in undo_info before we start processing.
         */
        row = g->existing_row = CONTAINER_FIND(tad->table, &index);
        if (!g->existing_row) {
            if (!tad->cb->create_row) {
                if(MODE_IS_SET(agtreq_info->mode))
                    netsnmp_set_request_error(agtreq_info, current,
                                              SNMP_ERR_NOTWRITABLE);
                else
                    netsnmp_set_request_error(agtreq_info, current,
                                              SNMP_NOSUCHINSTANCE);
                free(g);
                free(i);
                continue;
            }
            /** use undo_info temporarily */
            row = g->existing_row = tad->cb->create_row(&index);
            if (!row) {
                /* xxx-rks : parameter to create_row to allow
                 * for better error reporting. */
                netsnmp_set_request_error(agtreq_info, current,
                                          SNMP_ERR_GENERR);
                free(g);
                free(i);
                continue;
            }
            g->row_created = 1;
        }

        g->index.oids = row->oids;
        g->index.len = row->len;

        CONTAINER_INSERT(request_group, g);

    } /** for( current ... ) */
}
コード例 #10
0
ファイル: mib_ipAddrTable.c プロジェクト: millken/zhuxianB30
static int mib_ipAddrTable_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 ipAddrTable_entry *table_entry;

    switch (reqinfo->mode)
    {
    case MODE_GET:
        for (request=requests; request; request=request->next)
        {
            table_entry = (struct ipAddrTable_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_IPADENTADDR:
                if ( !table_entry )
                {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_IPADDRESS,
                                            htonl(table_entry->ipAdEntAddr));
                break;

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

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

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

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

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

            }
        }
        break;

    }
    return SNMP_ERR_NOERROR;
}
コード例 #11
0
ファイル: mib_ipRouteTable.c プロジェクト: millken/zhuxianB30
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;
}
コード例 #12
0
ファイル: tcpTable.c プロジェクト: vincentbernat/net-snmp
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;
}
コード例 #13
0
ファイル: mteEventTable.cpp プロジェクト: duniansampa/SigLog
/** 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;
}
コード例 #14
0
ファイル: nsLogging.cpp プロジェクト: duniansampa/SigLog
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;
}
コード例 #15
0
ファイル: hrSWRunTable.cpp プロジェクト: duniansampa/SigLog
/** handles requests for the hrSWRunTable table */
int
hrSWRunTable_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;
    netsnmp_swrun_entry *table_entry;

    switch (reqinfo->mode) {
        /*
         * Read-support (also covers GetNext requests)
         */
    case MODE_GET:
        for (request = requests; request; request = request->next) {
            if (request->processed)
               continue;
            table_entry = (netsnmp_swrun_entry *)
                netsnmp_container_table_extract_context(request);
            table_info = netsnmp_extract_table_info(request);
            if ((NULL == table_entry) || (NULL == table_info)) {
                snmp_log(LOG_ERR, "could not extract table entry or info for "
                 MYTABLE "\n");
                snmp_set_var_typed_value(request->requestvb,
                                         SNMP_ERR_GENERR, NULL, 0);
                continue;
            }

            switch (table_info->colnum) {
            case COLUMN_HRSWRUNINDEX:
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           table_entry->hrSWRunIndex);
                break;
            case COLUMN_HRSWRUNNAME:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         (u_char *) table_entry->
                                         hrSWRunName,
                                         table_entry->hrSWRunName_len);
                break;
            case COLUMN_HRSWRUNID:
                snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID,
#ifdef NETSNMP_SWRUN_HAVE_ID
                                         (u_char *) table_entry->hrSWRunID,
                                         table_entry->hrSWRunID_len
#else
                                         (u_char *) &nullOid, nullOidLen
#endif
                    );
                break;
            case COLUMN_HRSWRUNPATH:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         (u_char *) table_entry->
                                         hrSWRunPath,
                                         table_entry->hrSWRunPath_len);
                break;
            case COLUMN_HRSWRUNPARAMETERS:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         (u_char *) table_entry->
                                         hrSWRunParameters,
                                         table_entry->
                                         hrSWRunParameters_len);
                break;
            case COLUMN_HRSWRUNTYPE:
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           table_entry->hrSWRunType);
                break;
            case COLUMN_HRSWRUNSTATUS:
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           table_entry->hrSWRunStatus);
                break;
            default:
                /*
                 * An unsupported/unreadable column (if applicable) 
                 */
                snmp_set_var_typed_value(request->requestvb,
                                         SNMP_NOSUCHOBJECT, NULL, 0);
            }
        }
        break;

#ifndef NETSNMP_NO_WRITE_SUPPORT
#ifdef NETSNMP_INCLUDE_HRSWRUN_WRITE_SUPPORT
        /*
         * Write-support
         */
    case MODE_SET_RESERVE1:
        for (request = requests; request; request = request->next) {
            int pid;
            if (request->processed)
               continue;
            table_entry = (netsnmp_swrun_entry *)
                netsnmp_container_table_extract_context(request);
            table_info = netsnmp_extract_table_info(request);
            if ((NULL == table_entry) || (NULL == table_info)) {
                snmp_log(LOG_ERR, "could not extract table entry or info for "
                 MYTABLE "\n");
                snmp_set_var_typed_value(request->requestvb,
                                         SNMP_ERR_GENERR, NULL, 0);
                continue;
            }

            switch (table_info->colnum) {
            case COLUMN_HRSWRUNSTATUS:
                if (*request->requestvb->val.integer != HRSWRUNSTATUS_INVALID) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_ERR_WRONGVALUE);
                    return SNMP_ERR_NOERROR;
                }
                pid = request->requestvb->name[request->requestvb->name_length-1];
                if (1 == pid) {
                    snmp_log(LOG_WARNING,"refusing to kill pid 1\n");
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_ERR_NOACCESS);
                    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) {
            if (request->processed)
               continue;
            table_entry = (netsnmp_swrun_entry *)
                netsnmp_container_table_extract_context(request);
            table_info = netsnmp_extract_table_info(request);
            if ((NULL == table_entry) || (NULL == table_info)) {
                snmp_log(LOG_ERR, "could not extract table entry or info for "
                 MYTABLE "\n");
                snmp_set_var_typed_value(request->requestvb,
                                         SNMP_ERR_GENERR, NULL, 0);
                continue;
            }

            switch (table_info->colnum) {
            case COLUMN_HRSWRUNSTATUS:
                table_entry->old_hrSWRunStatus =
                    table_entry->hrSWRunStatus;
                table_entry->hrSWRunStatus =
                    *request->requestvb->val.integer;
                break;
            }
        }
        break;

    case MODE_SET_UNDO:
        for (request = requests; request; request = request->next) {
            if (request->processed)
               continue;
            container = netsnmp_container_table_extract_context(request);
            table_entry = (netsnmp_swrun_entry *)
                netsnmp_container_table_extract_context(request);
            table_info = netsnmp_extract_table_info(request);
            if ((NULL == table_entry) || (NULL == table_info)) {
                snmp_log(LOG_ERR, "could not extract table entry or info for "
                 MYTABLE "\n");
                snmp_set_var_typed_value(request->requestvb,
                                         SNMP_ERR_GENERR, NULL, 0);
                continue;
            }

            switch (table_info->colnum) {
            case COLUMN_HRSWRUNSTATUS:
                table_entry->hrSWRunStatus =
                    table_entry->old_hrSWRunStatus;
                table_entry->old_hrSWRunStatus = 0;
                break;
            }
        }
        break;

    case MODE_SET_COMMIT:
        for (request = requests; request; request = request->next) {
            int pid;
            if (request->processed)
               continue;
            pid = request->requestvb->name[request->requestvb->name_length-1];
            DEBUGMSGTL(("hrSWRunTable:commit", "kill(%d,TERM)\n", pid));
            kill(pid, SIGTERM);
        }
        break;
#endif /* NETSNMP_INCLUDE_HRSWRUN_WRITE_SUPPORT */
#endif /* !NETSNMP_NO_WRITE_SUPPORT */
    }
    return SNMP_ERR_NOERROR;
}
コード例 #16
0
static
int
tableGroupSetReserve2
	(
        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;
	PCCSP_MIB_MAPPING				pMapping        = NULL;
    oid                             subid			= 0;
	int								i               = 0;
	ULONG							uCount          = 0;
	parameterValStruct_t*			pValueArray	    = NULL;
	BOOL							bResult         = FALSE;
	PCCSP_TABLE_ENTRY				pEntry          = (PCCSP_TABLE_ENTRY)NULL;
	netsnmp_table_request_info*     table_info      = NULL;
	netsnmp_tdata*					table_data      = NULL;
	netsnmp_tdata_row*			    table_row       = NULL;
	ULONG                           indexes[8]      = { 0 };

	/* first round check how many parameters will be set */
	for (request = requests; request != NULL; request = request->next) 
	{
		if( request->processed != 0) { continue;}

		pEntry = (PCCSP_TABLE_ENTRY)netsnmp_tdata_extract_entry(request);
		table_info = netsnmp_extract_table_info(request);

		requestvb = request->requestvb;
		subid     = table_info->colnum;
		pMapping  = CcspUtilLookforMibMapWithOid(&pThisObject->MibObjQueue, subid);

		if( pMapping && pMapping->bHasMapping)
		{
			uCount ++;
		}
	}

	if( uCount == 0)
	{
		/* the mibs maybe be handled by callback apis. We return success here. */
		return SNMP_ERR_NOERROR;
	}

	/* allocate memory and get ready to set */
	pValueArray = (parameterValStruct_t*)AnscAllocateMemory(sizeof(parameterValStruct_t)* uCount);

	if( pValueArray == NULL)
	{
		return SNMP_ERR_GENERR;
	}

	/* Second round to transfer mib value to DM value */
	uCount = 0;
	for (request = requests; request != NULL; request = request->next) 
	{
		if( request->processed != 0) { continue;}

		pEntry = (PCCSP_TABLE_ENTRY)netsnmp_tdata_extract_entry(request);
		table_info = netsnmp_extract_table_info(request);

		if( pEntry == NULL)
		{
			AnscFreeMemory(pValueArray);/*RDKB-6909, CID-33559, free unused resource before exit*/
			return SNMP_ERR_NOERROR;
		}

		requestvb = request->requestvb;
		subid     = table_info->colnum;
		pMapping  = CcspUtilLookforMibMapWithOid(&pThisObject->MibObjQueue, subid);
		pMibValueObj = CcspUtilLookforMibValueObjWithOid(&pEntry->MibValueQueue, subid);

		for( i = 0; i < pEntry->IndexCount; i ++)
		{
			indexes[i] = pEntry->IndexValue[i].Value.uValue;
		}

		if( pMapping && pMapping->bHasMapping)
		{
			pValueArray[uCount].parameterName = CcspUtilGetDMParamName(&pThisObject->IndexMapQueue, indexes, pEntry->IndexCount, pMapping->Mapping.pDMName);
			pValueArray[uCount].type          = (enum dataType_e)pMapping->Mapping.uDataType;

			if( pMibValueObj != NULL)
			{
				if( pMapping->MibInfo.uType == ASN_OCTET_STR)
				{
					pMibValueObj->BackValue.pBuffer = pMibValueObj->Value.pBuffer;
					pMibValueObj->uBackSize         = pMibValueObj->uSize;

					pMibValueObj->Value.pBuffer     = AnscCloneString((char*)requestvb->val.string);
					pMibValueObj->uSize             = requestvb->val_len;
				}
				else if( pMapping->MibInfo.uType == ASN_BIT_STR)
				{
					pMibValueObj->BackValue.puBuffer  = pMibValueObj->Value.puBuffer;
					pMibValueObj->uBackSize           = pMibValueObj->uSize;

					pMibValueObj->Value.puBuffer      = (u_char*)AnscAllocateMemory(requestvb->val_len);
					if( pMibValueObj->Value.puBuffer != NULL) AnscCopyMemory(pMibValueObj->Value.puBuffer, requestvb->val.bitstring, requestvb->val_len);
					pMibValueObj->uSize               = requestvb->val_len;
				}
				else
				{
					pMibValueObj->BackValue.uValue  = pMibValueObj->Value.uValue;
					pMibValueObj->uBackSize         = pMibValueObj->uSize;

					pMibValueObj->Value.uValue     = *requestvb->val.integer;
					pMibValueObj->uSize             = requestvb->val_len;
				}
			}

			/* parse MIB value to DM value */
			CcspUtilMIBValueToDM(pMapping, (void*)&pValueArray[uCount], request->requestvb);
			pThisObject->bBackground |= pMapping->Mapping.backgroundCommit;
			CcspTraceDebug(("!!!!!Background commit %d (table)\n",pThisObject->bBackground));
			uCount ++;
		}
	}

	/* call SetParamValue */
	bResult = 
		Cosa_SetParamValuesNoCommit
			(
				pThisObject->pCcspComp,
				pThisObject->pCcspPath,
				pValueArray,
				uCount
				);

	/* free the memory */
	if( pValueArray != NULL)
	{
		for( i = 0; i < uCount; i ++)
		{
			if( pValueArray[i].parameterValue != NULL) AnscFreeMemory(pValueArray[i].parameterValue);
		}

		AnscFreeMemory(pValueArray);
	}

	if( bResult)
	{
		return SNMP_ERR_NOERROR;
	}
	else
	{
		return SNMP_ERR_GENERR;
	}
}
コード例 #17
0
ファイル: table_data.c プロジェクト: Undrizzle/apps
/*
 * The helper handler that takes care of passing a specific row of
 * data down to the lower handler(s).  It sets request->processed if
 * the request should not be handled.
 */
int
netsnmp_table_data_helper_handler(netsnmp_mib_handler *handler,
                                  netsnmp_handler_registration *reginfo,
                                  netsnmp_agent_request_info *reqinfo,
                                  netsnmp_request_info *requests)
{
    netsnmp_table_data *table = (netsnmp_table_data *) handler->myvoid;
    netsnmp_request_info *request;
    int             valid_request = 0;
    netsnmp_table_row *row;
    netsnmp_table_request_info *table_info;
    netsnmp_table_registration_info *table_reg_info =
        netsnmp_find_table_registration_info(reginfo);
    int             result, regresult;
    int             oldmode;

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

        table_info = netsnmp_extract_table_info(request);
        if (!table_info)
            continue;           /* ack */
        switch (reqinfo->mode) {
        case MODE_GET:
        case MODE_GETNEXT:
        case MODE_SET_RESERVE1:
            netsnmp_request_add_list_data(request,
                                      netsnmp_create_data_list(
                                          TABLE_DATA_TABLE, table, NULL));
        }

        /*
         * find the row in question 
         */
        switch (reqinfo->mode) {
        case MODE_GETNEXT:
        case MODE_GETBULK:     /* XXXWWW */
            if (request->requestvb->type != ASN_NULL)
                continue;
            /*
             * loop through data till we find the next row 
             */
            result = snmp_oid_compare(request->requestvb->name,
                                      request->requestvb->name_length,
                                      reginfo->rootoid,
                                      reginfo->rootoid_len);
            regresult = snmp_oid_compare(request->requestvb->name,
                                         SNMP_MIN(request->requestvb->
                                                  name_length,
                                                  reginfo->rootoid_len),
                                         reginfo->rootoid,
                                         reginfo->rootoid_len);
            if (regresult == 0
                && request->requestvb->name_length < reginfo->rootoid_len)
                regresult = -1;

            if (result < 0 || 0 == result) {
                /*
                 * before us entirely, return the first 
                 */
                row = table->first_row;
                table_info->colnum = table_reg_info->min_column;
            } else if (regresult == 0 && request->requestvb->name_length ==
                       reginfo->rootoid_len + 1 &&
                       /* entry node must be 1, but any column is ok */
                       request->requestvb->name[reginfo->rootoid_len] == 1) {
                /*
                 * exactly to the entry 
                 */
                row = table->first_row;
                table_info->colnum = table_reg_info->min_column;
            } else if (regresult == 0 && request->requestvb->name_length ==
                       reginfo->rootoid_len + 2 &&
                       /* entry node must be 1, but any column is ok */
                       request->requestvb->name[reginfo->rootoid_len] == 1) {
                /*
                 * exactly to the column 
                 */
                row = table->first_row;
            } else {
                /*
                 * loop through all rows looking for the first one
                 * that is equal to the request or greater than it 
                 */
                for (row = table->first_row; row; row = row->next) {
                    /*
                     * compare the index of the request to the row 
                     */
                    result =
                        snmp_oid_compare(row->index_oid,
                                         row->index_oid_len,
                                         request->requestvb->name + 2 +
                                         reginfo->rootoid_len,
                                         request->requestvb->name_length -
                                         2 - reginfo->rootoid_len);
                    if (result == 0) {
                        /*
                         * equal match, return the next row 
                         */
                        if (row) {
                            row = row->next;
                        }
                        break;
                    } else if (result > 0) {
                        /*
                         * the current row is greater than the
                         * request, use it 
                         */
                        break;
                    }
                }
            }
            if (!row) {
                table_info->colnum++;
                if (table_info->colnum <= table_reg_info->max_column) {
                    row = table->first_row;
                }
            }
            if (row) {
                valid_request = 1;
                netsnmp_request_add_list_data(request,
                                              netsnmp_create_data_list
                                              (TABLE_DATA_ROW, row,
                                               NULL));
                /*
                 * Set the name appropriately, so we can pass this
                 *  request on as a simple GET request
                 */
                netsnmp_table_data_build_result(reginfo, reqinfo, request,
                                                row,
                                                table_info->colnum,
                                                ASN_NULL, NULL, 0);
            } else {            /* no decent result found.  Give up. It's beyond us. */
                request->processed = 1;
            }
            break;

        case MODE_GET:
            if (request->requestvb->type != ASN_NULL)
                continue;
            /*
             * find the row in question 
             */
            if (request->requestvb->name_length < (reginfo->rootoid_len + 3)) { /* table.entry.column... */
                /*
                 * request too short 
                 */
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_NOSUCHINSTANCE);
                break;
            } else if (NULL ==
                       (row =
                        netsnmp_table_data_get_from_oid(table,
                                                        request->
                                                        requestvb->name +
                                                        reginfo->
                                                        rootoid_len + 2,
                                                        request->
                                                        requestvb->
                                                        name_length -
                                                        reginfo->
                                                        rootoid_len -
                                                        2))) {
                /*
                 * no such row 
                 */
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_NOSUCHINSTANCE);
                break;
            } else {
                valid_request = 1;
                netsnmp_request_add_list_data(request,
                                              netsnmp_create_data_list
                                              (TABLE_DATA_ROW, row,
                                               NULL));
            }
            break;

        case MODE_SET_RESERVE1:
            valid_request = 1;
            if (NULL !=
                (row =
                 netsnmp_table_data_get_from_oid(table,
                                                 request->requestvb->name +
                                                 reginfo->rootoid_len + 2,
                                                 request->requestvb->
                                                 name_length -
                                                 reginfo->rootoid_len -
                                                 2))) {
                netsnmp_request_add_list_data(request,
                                              netsnmp_create_data_list
                                              (TABLE_DATA_ROW, row,
                                               NULL));
            }
            break;

        case MODE_SET_RESERVE2:
        case MODE_SET_ACTION:
        case MODE_SET_COMMIT:
        case MODE_SET_FREE:
        case MODE_SET_UNDO:
            valid_request = 1;

        }
    }

    if (valid_request &&
       (reqinfo->mode == MODE_GETNEXT || reqinfo->mode == MODE_GETBULK)) {
        /*
         * If this is a GetNext or GetBulk request, then we've identified
         *  the row that ought to include the appropriate next instance.
         *  Convert the request into a Get request, so that the lower-level
         *  handlers don't need to worry about skipping on, and call these
         *  handlers ourselves (so we can undo this again afterwards).
         */
        oldmode = reqinfo->mode;
        reqinfo->mode = MODE_GET;
        result = netsnmp_call_next_handler(handler, reginfo, reqinfo,
                                         requests);
        reqinfo->mode = oldmode;
        handler->flags |= MIB_HANDLER_AUTO_NEXT_OVERRIDE_ONCE;
        return result;
    }
    else
        /* next handler called automatically - 'AUTO_NEXT' */
        return SNMP_ERR_NOERROR;
}
コード例 #18
0
static
int
tableGroupSetFree
	(
        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;
	PCCSP_TABLE_ENTRY				pEntry          = (PCCSP_TABLE_ENTRY)NULL;
	netsnmp_table_request_info*     table_info      = NULL;
	netsnmp_tdata*					table_data      = NULL;
	netsnmp_tdata_row*			    table_row       = NULL;
	ULONG                           indexes[8]      = { 0 };
	ULONG							i				= 0;

	AnscTraceInfo(("Enter 'tableGroupSetFree'\n"));

#if 0
	/* check whether Rowstatus is involved */
	for (request = requests; request != NULL; request = request->next) 
	{
		if( request->processed != 0) { continue;}

		pEntry = (PCCSP_TABLE_ENTRY)netsnmp_tdata_extract_entry(request);
		table_info = netsnmp_extract_table_info(request);
		table_data = netsnmp_tdata_extract_table(request);
		table_row  = netsnmp_tdata_extract_row(request);

		requestvb = request->requestvb;
		subid     = table_info->colnum;

		if( subid == pThisObject->uRowStatus)
		{
			if( RS_CREATEANDGO == *requestvb->val.integer || RS_CREATEANDWAIT == *requestvb->val.integer)
			{
				if( pEntry != NULL && !pEntry->valid)
				{
					for( i = 0; i < pEntry->IndexCount; i ++)
					{
						indexes[i] = pEntry->IndexValue[i].Value.uValue;
					}

					/* remove the entry at the back-end */
					if(!CcspUtilDeleteCosaEntry((ANSC_HANDLE)pThisObject, indexes, pEntry->IndexCount))
					{
						AnscTraceWarning(("Failed to delete DM entry.\n"));
					}
					CcspUtilRemoveMibEntry(table_data,table_row);

				}
			}

		}
	}
#endif

	/* Copy back the saved values */
	for (request = requests; request != NULL; request = request->next) 
	{
		if( request->processed != 0) { continue;}

		pEntry = (PCCSP_TABLE_ENTRY)netsnmp_tdata_extract_entry(request);
		table_info = netsnmp_extract_table_info(request);

		requestvb = request->requestvb;
		subid     = table_info->colnum;

		if( pEntry == NULL) return SNMP_ERR_NOERROR;

		pMibValueObj = CcspUtilLookforMibValueObjWithOid(&pEntry->MibValueQueue, subid);

		if( pMibValueObj != NULL)
		{
			if( pMibValueObj->uType == ASN_OCTET_STR)
			{
				if( pMibValueObj->Value.pBuffer != NULL)  AnscFreeMemory(pMibValueObj->Value.pBuffer);

				pMibValueObj->Value.pBuffer     = pMibValueObj->BackValue.pBuffer;
				pMibValueObj->uSize             = pMibValueObj->uBackSize;

				pMibValueObj->BackValue.pBuffer = NULL;
				pMibValueObj->uBackSize         = 0;
			}
			else if( pMibValueObj->uType == ASN_BIT_STR)
			{
				if( pMibValueObj->Value.puBuffer != NULL)  AnscFreeMemory(pMibValueObj->Value.puBuffer);

				pMibValueObj->Value.puBuffer     = pMibValueObj->BackValue.puBuffer;
				pMibValueObj->uSize              = pMibValueObj->uBackSize;

				pMibValueObj->BackValue.puBuffer = NULL;
				pMibValueObj->uBackSize          = 0;
			}
			else
			{
				pMibValueObj->Value.uValue      = pMibValueObj->BackValue.uValue;
				pMibValueObj->uSize             = pMibValueObj->uBackSize;

				pMibValueObj->BackValue.uValue  = 0;
				pMibValueObj->uBackSize         = pMibValueObj->uSize;
			}
		}
	}

	return SNMP_ERR_NOERROR;
}
コード例 #19
0
ファイル: udpTable.c プロジェクト: gittestusername/uClinux
int
udpTable_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;
    UDPTABLE_ENTRY_TYPE	  *entry;
    oid      subid;
    long     port;
    in_addr_t addr;

    DEBUGMSGTL(("mibII/udpTable", "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/udpTable", "oid: "));
            DEBUGMSGOID(("mibII/udpTable", requestvb->name,
                                           requestvb->name_length));
            DEBUGMSG((   "mibII/udpTable", "\n"));

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

            switch (subid) {
            case UDPLOCALADDRESS:
#if defined(osf5) && defined(IN6_EXTRACT_V4ADDR)
                addr = ntohl(IN6_EXTRACT_V4ADDR(&entry->pcb.inp_laddr));
	        snmp_set_var_typed_value(requestvb, ASN_IPADDRESS,
                                         (u_char*)&addr,
                                         sizeof(uint32_t));
#else
                addr = UDP_ADDRESS_TO_HOST_ORDER(entry->UDPTABLE_LOCALADDRESS);
	        snmp_set_var_typed_value(requestvb, ASN_IPADDRESS,
                                         (u_char *)&addr,
                                         sizeof(uint32_t));
#endif
                break;
            case UDPLOCALPORT:
                port = UDP_PORT_TO_HOST_ORDER((u_short)entry->UDPTABLE_LOCALPORT);
	        snmp_set_var_typed_value(requestvb, ASN_INTEGER,
                                 (u_char *)&port, sizeof(port));
                break;
	    }
	}
        break;

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

    return SNMP_ERR_NOERROR;
}
コード例 #20
0
int
CcspTableHelperSetMibValues
	(
        ANSC_HANDLE                 hThisObject,
        netsnmp_agent_request_info  *reqinfo,
        netsnmp_request_info		*requests
	)
{
	PCCSP_TABLE_HELPER_OBJECT       pThisObject     = (PCCSP_TABLE_HELPER_OBJECT)hThisObject;
	PCCSP_TABLE_ENTRY				pEntry          = (PCCSP_TABLE_ENTRY)NULL;
	PCCSP_MIB_VALUE                 pMibValueObj    = (PCCSP_MIB_VALUE)NULL;
    netsnmp_request_info            *request		= NULL;
	netsnmp_table_request_info*     table_info      = NULL;
	netsnmp_tdata*					table_data      = NULL;
	netsnmp_tdata_row*			    table_row       = NULL;
    netsnmp_variable_list           *requestvb		= NULL;
    netsnmp_variable_list           *next    		= NULL;
	PCCSP_MIB_MAPPING				pMapping        = NULL;
    oid                             subid			= 0;
	int								ret             = 0;
	int                             i               = 0;
	ULONG                           indexes[8]      = { 0 };

	AnscTraceInfo(("Enter 'CcspTableHelperSetMibValues' with mode = %d\n", reqinfo->mode));

	switch( reqinfo->mode)
	{
		case MODE_SET_RESERVE1:

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

				pEntry = (PCCSP_TABLE_ENTRY)netsnmp_tdata_extract_entry(request);
				table_info = netsnmp_extract_table_info(request);

				requestvb = request->requestvb;
				subid     = table_info->colnum;

				pMapping  = CcspUtilLookforMibMapWithOid(&pThisObject->MibObjQueue, subid);

				if( subid == pThisObject->uRowStatus)
				{
					ret = netsnmp_check_vb_rowstatus( requestvb, (pEntry? RS_ACTIVE: RS_NONEXISTENT));

					if( ret != SNMP_ERR_NOERROR)
					{
						netsnmp_set_request_error(reqinfo, request, ret);

						return SNMP_ERR_NOERROR;
					}

					/* somehow the Destroy was not checked correctly above */
					if( pEntry == NULL && *requestvb->val.integer == RS_DESTROY)
					{
						netsnmp_set_request_error(reqinfo, request, SNMP_ERR_BADVALUE);

						return SNMP_ERR_NOERROR;
					}
				}
				else if( pMapping)
				{
					ret = verifyTypeAndValueInSetReserved1(request->requestvb, pMapping);

					if( ret != SNMP_ERR_NOERROR)
					{
						netsnmp_set_request_error(reqinfo, request, ret);

						return SNMP_ERR_NOERROR;
					}
				}
				else
				{
					netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
					return SNMP_ERR_NOERROR;
				}
			}

			break;

		case MODE_SET_RESERVE2:

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

				pEntry = (PCCSP_TABLE_ENTRY)netsnmp_tdata_extract_entry(request);
				table_info = netsnmp_extract_table_info(request);
				table_data = netsnmp_tdata_extract_table(request);

				requestvb = request->requestvb;
				subid     = table_info->colnum;

				if( subid == pThisObject->uRowStatus)
				{
					if( RS_CREATEANDGO == *requestvb->val.integer || RS_CREATEANDWAIT == *requestvb->val.integer)
					{
						next = table_info->indexes;

						for( i = 0; i < table_info->number_indexes; i ++)
						{
							indexes[i] = *next->val.integer;
							next = next->next_variable;

							if( next == NULL) break;
						}

						table_row = CcspUtilCreateMibEntry( table_data, indexes, table_info->number_indexes, FALSE);

						if( table_row)
						{
							/* create entry at CCSP back-end */
							if(!CcspUtilCreateCosaEntry((ANSC_HANDLE)pThisObject, indexes, table_info->number_indexes))
							{
								AnscTraceError(("Failed to Add COSA Entry at back-end.\n"));
							}

							pEntry = (PCCSP_TABLE_ENTRY)table_row->data;

							/* the indexes array is the array of CCSP instance numbers */
							for( i = 0; i < table_info->number_indexes; i ++)
							{
								pEntry->IndexValue[i].Value.iValue = indexes[i];
							}

							pEntry->IndexCount = table_info->number_indexes;

							/* init the value array */
							CcspUtilInitMibValueArray(&pThisObject->MibObjQueue, &pEntry->MibValueQueue);

							netsnmp_insert_tdata_row(request, table_row);
						}
						else
						{
							netsnmp_set_request_error(reqinfo, request, SNMP_ERR_RESOURCEUNAVAILABLE);

							return SNMP_ERR_NOERROR;
						}
					}
				}
			}

			/* collect all the updated values and call Cosa_SetParamValues with Commit = FALSE */
			return tableGroupSetReserve2(hThisObject, reqinfo, requests);

			break;

		case MODE_SET_ACTION:

			if( pThisObject->pCcspComp != NULL && pThisObject->pCcspPath)
			{
				/* commit the update */
				if (pThisObject->bBackground) 
				{
					Cosa_BackgroundCommit(pThisObject->pCcspComp, pThisObject->pCcspPath, TRUE);
					pThisObject->bBackground = 0;
                                        struct timespec delay = {0, 80000000};
                                        nanosleep(&delay, NULL);
				}
				else
				{
					Cosa_SetCommit(pThisObject->pCcspComp, pThisObject->pCcspPath, TRUE);
				}
			}

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

				pEntry = (PCCSP_TABLE_ENTRY)netsnmp_tdata_extract_entry(request);

				if(pEntry)
				{
					table_info = netsnmp_extract_table_info(request);
					table_row  = netsnmp_tdata_extract_row(request);
					table_data = netsnmp_tdata_extract_table(request);

					requestvb = request->requestvb;
					subid     = table_info->colnum;

					if( subid == pThisObject->uRowStatus)
					{
						pMibValueObj = CcspUtilLookforMibValueObjWithOid(&pEntry->MibValueQueue, subid);

						switch(*requestvb->val.integer)
						{
							case RS_CREATEANDGO:
								pEntry->valid = 1;
							case RS_ACTIVE:
								if( pMibValueObj) pMibValueObj->Value.uValue = RS_ACTIVE;
									break;
							case RS_CREATEANDWAIT:
								pEntry->valid = 1;
							case RS_NOTINSERVICE:
								if( pMibValueObj) pMibValueObj->Value.uValue = RS_NOTINSERVICE;
								break;
							case RS_DESTROY:

								for( i = 0; i < pEntry->IndexCount; i ++)
								{
									indexes[i] = pEntry->IndexValue[i].Value.uValue;
								}

								/* remove the entry at the back-end */
								if(!CcspUtilDeleteCosaEntry((ANSC_HANDLE)pThisObject, indexes, pEntry->IndexCount))
								{
									AnscTraceWarning(("Failed to delete DM entry.\n"));
								}

								CcspUtilRemoveMibEntry(table_data,table_row);

								break;
						}
					}
				}
			}

			return SNMP_ERR_NOERROR;

		case MODE_SET_FREE:

			if( pThisObject->pCcspComp != NULL && pThisObject->pCcspPath)
			{
				/* don't commit the update */
				Cosa_SetCommit(pThisObject->pCcspComp, pThisObject->pCcspPath, FALSE);
			}

		   return tableGroupSetFree(hThisObject, reqinfo, requests); 

		case MODE_SET_COMMIT:
		case MODE_SET_UNDO:
		default:

			/* we don't care about them */
			return SNMP_ERR_NOERROR;
	}

    return SNMP_ERR_NOERROR;
}
コード例 #21
0
/*******************************************************************************
 函数名称  : mib_etherHistoryTable_handler
 功能描述  : handles requests for the etherHistoryTable table
 输入参数  :
 输出参数  :
 返 回 值  :
 --------------------------------------------------------------------------------
 最近一次修改记录 :
 修改作者   :
 修改目的   :
 修改日期   :
*******************************************************************************/
static int
mib_etherHistoryTable_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 etherHistoryTable_entry *table_entry;

    switch (reqinfo->mode) {
        /*
         * 这里的GET操作已经覆盖了GET_NEXT操作
         */
    case MODE_GET:
        for (request = requests; request; request = request->next) {
            table_entry = (struct etherHistoryTable_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_ETHERHISTORYINDEX:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           htonl(table_entry->
                                                 etherHistoryIndex));
                break;
            case COLUMN_ETHERHISTORYSAMPLEINDEX:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           htonl(table_entry->
                                                 etherHistorySampleIndex));
                break;
            case COLUMN_ETHERHISTORYINTERVALSTART:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb,
                                           ASN_TIMETICKS,
                                           htonl(table_entry->
                                                 etherHistoryIntervalStart));
                break;
            case COLUMN_ETHERHISTORYDROPEVENTS:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
                                           htonl(table_entry->
                                                 etherHistoryDropEvents));
                break;
            case COLUMN_ETHERHISTORYOCTETS:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
                                           htonl(table_entry->
                                                 etherHistoryOctets));
                break;
            case COLUMN_ETHERHISTORYPKTS:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
                                           htonl(table_entry->
                                                 etherHistoryPkts));
                break;
            case COLUMN_ETHERHISTORYBROADCASTPKTS:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
                                           htonl(table_entry->
                                                 etherHistoryBroadcastPkts));
                break;
            case COLUMN_ETHERHISTORYMULTICASTPKTS:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
                                           htonl(table_entry->
                                                 etherHistoryMulticastPkts));
                break;
            case COLUMN_ETHERHISTORYCRCALIGNERRORS:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
                                           htonl(table_entry->
                                                 etherHistoryCRCAlignErrors));
                break;
            case COLUMN_ETHERHISTORYUNDERSIZEPKTS:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
                                           htonl(table_entry->
                                                 etherHistoryUndersizePkts));
                break;
            case COLUMN_ETHERHISTORYOVERSIZEPKTS:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
                                           htonl(table_entry->
                                                 etherHistoryOversizePkts));
                break;
            case COLUMN_ETHERHISTORYFRAGMENTS:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
                                           htonl(table_entry->
                                                 etherHistoryFragments));
                break;
            case COLUMN_ETHERHISTORYJABBERS:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
                                           htonl(table_entry->
                                                 etherHistoryJabbers));
                break;
            case COLUMN_ETHERHISTORYCOLLISIONS:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
                                           htonl(table_entry->
                                                 etherHistoryCollisions));
                break;
            case COLUMN_ETHERHISTORYUTILIZATION:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           htonl(table_entry->
                                                 etherHistoryUtilization));
                break;
            default:
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_NOSUCHOBJECT);
                break;
            }
        }
        break;

    }
    return SNMP_ERR_NOERROR;
}
コード例 #22
0
/**********************************************************************

    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;
}
コード例 #23
0
/** handles requests for the cpqLinOsProcessorTable table */
int
cpqLinOsProcessorTable_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;
    cpqLinOsProcessorTable_entry *table_entry;

    DEBUGMSGTL(("cpqLinOsProcessorTable:handler",
                "Processing request (%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;
            table_entry = (cpqLinOsProcessorTable_entry *)
                netsnmp_container_table_extract_context(request);
            table_info = netsnmp_extract_table_info(request);
            if ((NULL == table_entry) || (NULL == table_info)) {
                snmp_log(LOG_ERR,
                         "could not extract table entry or info for cpqLinOsProcessorTable\n");
                snmp_set_var_typed_value(request->requestvb,
                                         SNMP_ERR_GENERR, NULL, 0);
                continue;
            }

            switch (table_info->colnum) {
            case COLUMN_CPQLINOSCPUINDEX:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           table_entry->cpqLinOsCpuIndex);
                break;
            case COLUMN_CPQLINOSCPUINSTANCE:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         table_entry->cpqLinOsCpuInstance,
                                         table_entry->
                                         cpqLinOsCpuInstance_len);
                break;
            case COLUMN_CPQLINOSCPUINTERRUPTSPERSEC:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           table_entry->
                                           cpqLinOsCpuInterruptsPerSec);
                break;
            case COLUMN_CPQLINOSCPUTIMEPERCENT:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           table_entry->
                                           cpqLinOsCpuTimePercent);
                break;
            case COLUMN_CPQLINOSCPUUSERTIMEPERCENT:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           table_entry->
                                           cpqLinOsCpuUserTimePercent);
                break;
            case COLUMN_CPQLINOSCPUPRIVILEGEDTIMEPERCENT:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           table_entry->
                                           cpqLinOsCpuPrivilegedTimePercent);
                break;
            default:
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_NOSUCHOBJECT);
                break;
            }
        }
        break;

    }
    return SNMP_ERR_NOERROR;
}
コード例 #24
0
ファイル: subagent.c プロジェクト: PauloFer1/FreeSWITCH
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;
}
コード例 #25
0
int
_mfd_ipv6InterfaceTable_get_values(netsnmp_mib_handler *handler,
                                   netsnmp_handler_registration *reginfo,
                                   netsnmp_agent_request_info *agtreq_info,
                                   netsnmp_request_info *requests)
{
    ipv6InterfaceTable_rowreq_ctx *rowreq_ctx =
        netsnmp_container_table_row_extract(requests);
    netsnmp_table_request_info *tri;
    u_char         *old_string;
    void            (*dataFreeHook) (void *);
    int             rc;

    DEBUGMSGTL(("internal:ipv6InterfaceTable:_mfd_ipv6InterfaceTable_get_values", "called\n"));

    netsnmp_assert(NULL != rowreq_ctx);

    for (; requests; requests = requests->next) {
        /*
         * save old pointer, so we can free it if replaced
         */
        old_string = requests->requestvb->val.string;
        dataFreeHook = requests->requestvb->dataFreeHook;
        if (NULL == requests->requestvb->val.string) {
            requests->requestvb->val.string = requests->requestvb->buf;
            requests->requestvb->val_len =
                sizeof(requests->requestvb->buf);
        } else if (requests->requestvb->buf ==
                   requests->requestvb->val.string) {
            if (requests->requestvb->val_len !=
                sizeof(requests->requestvb->buf))
                requests->requestvb->val_len =
                    sizeof(requests->requestvb->buf);
        }

        /*
         * get column data
         */
        tri = netsnmp_extract_table_info(requests);
        if (NULL == tri)
            continue;

        rc = _ipv6InterfaceTable_get_column(rowreq_ctx,
                                            requests->requestvb,
                                            tri->colnum);
        if (rc) {
            if (MFD_SKIP == rc) {
                requests->requestvb->type = SNMP_NOSUCHINSTANCE;
                rc = SNMP_ERR_NOERROR;
            }
        } else if (NULL == requests->requestvb->val.string) {
            snmp_log(LOG_ERR, "NULL varbind data pointer!\n");
            rc = SNMP_ERR_GENERR;
        }
        if (rc)
            netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc));

        /*
         * if the buffer wasn't used previously for the old data (i.e. it
         * was allcoated memory)  and the get routine replaced the pointer,
         * we need to free the previous pointer.
         */
        if (old_string && (old_string != requests->requestvb->buf) &&
            (requests->requestvb->val.string != old_string)) {
            if (dataFreeHook)
                (*dataFreeHook) (old_string);
            else
                free(old_string);
        }
    }                           /* for results */

    return SNMP_ERR_NOERROR;
}                               /* _mfd_ipv6InterfaceTable_get_values */
/** 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;
}
コード例 #27
0
/** handles requests for the LHANodeTable table, if anything else needs to be done */
int
LHANodeTable_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;
    netsnmp_variable_list *var;

    struct hb_nodeinfo * entry;

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

        /** perform anything here that you need to do before each
           request is processed. */
	entry = (struct hb_nodeinfo *) 
	    netsnmp_extract_iterator_context(request);

        if (entry == NULL) {
            if (reqinfo->mode == MODE_GET) {
                netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
                continue;
            }
            /** XXX: no row existed, if you support creation and this is a
               set, start dealing with it here, else continue */
        }

        /** extracts the information about the table from the request */
        table_info = netsnmp_extract_table_info(request);
        /** table_info->colnum contains the column number requested */
        /** table_info->indexes contains a linked list of snmp variable
           bindings for the indexes of the table.  Values in the list
           have been set corresponding to the indexes of the
           request */
        if (table_info==NULL) {
            continue;
        }

        switch(reqinfo->mode) {
            /** the table_iterator helper should change all GETNEXTs
               into GETs for you automatically, so you don't have to
               worry about the GETNEXT case.  Only GETs and SETs need
               to be dealt with here */
            case MODE_GET:
                switch(table_info->colnum) {
		    case COLUMN_LHANODEINDEX:
			snmp_set_var_typed_value(var,
				ASN_INTEGER,
				(u_char*)&entry->id,
				sizeof(entry->id));
			break;

                    case COLUMN_LHANODENAME:
                        snmp_set_var_typed_value(var, 
				ASN_OCTET_STR, 
				(u_char *) (entry->name), 
				strlen(entry->name) + 1);
                        break;

                    case COLUMN_LHANODETYPE:
                        snmp_set_var_typed_value(var, 
				ASN_INTEGER, 
				(u_char *) & entry->type, 
				sizeof(entry->type));
                        break;

                    case COLUMN_LHANODESTATUS:
                        snmp_set_var_typed_value(var, 
				ASN_INTEGER, 
				(u_char *) & entry->status, 
				sizeof(entry->status));
                        break;

#ifdef HAVE_NEW_HB_API
                    case COLUMN_LHANODEUUID:
                        snmp_set_var_typed_value(var, 
				ASN_OCTET_STR, 
				(u_char *) &entry->uuid, 
				sizeof(entry->uuid));
                        break;
#endif /* HAVE_NEW_HB_API */

                    case COLUMN_LHANODEIFCOUNT:
                        snmp_set_var_typed_value(var, 
				ASN_COUNTER, 
				(u_char *) & entry->ifcount, 
				sizeof(entry->ifcount));
                        break;


                    default:
                        /** We shouldn't get here */
                        snmp_log(LOG_ERR, "problem encountered in LHANodeTable_handler: unknown column\n");
                }
                break;

            case MODE_SET_RESERVE1:
                /** set handling... */

            default:
                snmp_log(LOG_ERR, "problem encountered in LHANodeTable_handler: unsupported mode\n");
        }
    }
    return SNMP_ERR_NOERROR;
}
コード例 #28
0
ファイル: sctpAssocTable.c プロジェクト: Undrizzle/apps
/** handles requests for the sctpAssocTable table */
int
sctpAssocTable_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;
    sctpAssocTable_entry *table_entry;

    switch (reqinfo->mode) {
        /*
         * Read-support (also covers GetNext requests)
         */
    case MODE_GET:
        for (request = requests; request; request = request->next) {
            if (request->processed)
                continue;
            table_entry = (sctpAssocTable_entry *)
                netsnmp_container_table_extract_context(request);
            table_info = netsnmp_extract_table_info(request);
            if ((NULL == table_entry) || (NULL == table_info)) {
                snmp_log(LOG_ERR,
                         "could not extract table entry or info for sctpAssocTable\n");
                snmp_set_var_typed_value(request->requestvb,
                                         SNMP_ERR_GENERR, NULL, 0);
                continue;
            }

            switch (table_info->colnum) {
            case COLUMN_SCTPASSOCREMHOSTNAME:
                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->sctpAssocRemHostName,
                                         table_entry->sctpAssocRemHostName_len);
                break;
            case COLUMN_SCTPASSOCLOCALPORT:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb,
                                           ASN_UNSIGNED,
                                           table_entry->sctpAssocLocalPort);
                break;
            case COLUMN_SCTPASSOCREMPORT:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb,
                                           ASN_UNSIGNED,
                                           table_entry->sctpAssocRemPort);
                break;
            case COLUMN_SCTPASSOCREMPRIMADDRTYPE:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           table_entry->sctpAssocRemPrimAddrType);
                break;
            case COLUMN_SCTPASSOCREMPRIMADDR:
                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->sctpAssocRemPrimAddr,
                                         table_entry->sctpAssocRemPrimAddr_len);
                break;
            case COLUMN_SCTPASSOCHEARTBEATINTERVAL:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb,
                                           ASN_UNSIGNED,
                                           table_entry->sctpAssocHeartBeatInterval);
                break;
            case COLUMN_SCTPASSOCSTATE:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           table_entry->sctpAssocState);
                break;
            case COLUMN_SCTPASSOCINSTREAMS:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb,
                                           ASN_UNSIGNED,
                                           table_entry->sctpAssocInStreams);
                break;
            case COLUMN_SCTPASSOCOUTSTREAMS:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb,
                                           ASN_UNSIGNED,
                                           table_entry->sctpAssocOutStreams);
                break;
            case COLUMN_SCTPASSOCMAXRETR:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb,
                                           ASN_UNSIGNED,
                                           table_entry->sctpAssocMaxRetr);
                break;
            case COLUMN_SCTPASSOCPRIMPROCESS:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb,
                                           ASN_UNSIGNED,
                                           table_entry->sctpAssocPrimProcess);
                break;
            case COLUMN_SCTPASSOCT1EXPIREDS:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
                                           table_entry->sctpAssocT1expireds);
                break;
            case COLUMN_SCTPASSOCT2EXPIREDS:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
                                           table_entry->sctpAssocT2expireds);
                break;
            case COLUMN_SCTPASSOCRTXCHUNKS:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
                                           table_entry->sctpAssocRtxChunks);
                break;
            case COLUMN_SCTPASSOCSTARTTIME:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb,
                                           ASN_TIMETICKS,
                                           table_entry->sctpAssocStartTime);
                break;
            case COLUMN_SCTPASSOCDISCONTINUITYTIME:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb,
                                           ASN_TIMETICKS,
                                           table_entry->sctpAssocDiscontinuityTime);
                break;
            default:
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_NOSUCHOBJECT);
                break;
            }
        }
        break;

        /*
         * Write-support
         */
    case MODE_SET_RESERVE1:
        for (request = requests; request; request = request->next) {
            if (request->processed)
                continue;
            netsnmp_set_request_error(reqinfo, request,
                                      SNMP_ERR_NOTWRITABLE);
        }
        break;

    case MODE_SET_RESERVE2:
    case MODE_SET_FREE:
    case MODE_SET_ACTION:
    case MODE_SET_UNDO:
    case MODE_SET_COMMIT:
        break;
    }
    return SNMP_ERR_NOERROR;
}
コード例 #29
0
/** handles requests for the mteTriggerThresholdTable table */
int
mteTriggerThresholdTable_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", "Threshold 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 mteTriggerThresholdTable should only contains entries for
             *   rows where the mteTriggerTest 'threshold(2)' bit is set.
             * So skip entries where this isn't the case.
             */
            if (!entry || !(entry->mteTriggerTest & MTE_TRIGGER_THRESHOLD )) {
                netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE);
                continue;
            }

            switch (tinfo->colnum) {
            case COLUMN_MTETRIGGERTHRESHOLDSTARTUP:
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           entry->mteTThStartup);
                break;
            case COLUMN_MTETRIGGERTHRESHOLDRISING:
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           entry->mteTThRiseValue);
                break;
            case COLUMN_MTETRIGGERTHRESHOLDFALLING:
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           entry->mteTThFallValue);
                break;
            case COLUMN_MTETRIGGERTHRESHOLDDELTARISING:
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           entry->mteTThDRiseValue);
                break;
            case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLING:
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           entry->mteTThDFallValue);
                break;
            case COLUMN_MTETRIGGERTHRESHOLDOBJECTSOWNER:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         (u_char *) entry->mteTThObjOwner,
                                         strlen(entry->mteTThObjOwner));
                break;
            case COLUMN_MTETRIGGERTHRESHOLDOBJECTS:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         (u_char *) entry->mteTThObjects,
                                         strlen(entry->mteTThObjects));
                break;
            case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENTOWNER:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         (u_char *) entry->mteTThRiseOwner,
                                         strlen(entry->mteTThRiseOwner));
                break;
            case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENT:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         (u_char *) entry->mteTThRiseEvent,
                                         strlen(entry->mteTThRiseEvent));
                break;
            case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENTOWNER:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         (u_char *) entry->mteTThFallOwner,
                                         strlen(entry->mteTThFallOwner));
                break;
            case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENT:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         (u_char *) entry->mteTThFallEvent,
                                         strlen(entry->mteTThFallEvent));
                break;
            case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENTOWNER:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         (u_char *) entry->mteTThDRiseOwner,
                                         strlen(entry->mteTThDRiseOwner));
                break;
            case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENT:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         (u_char *) entry->mteTThDRiseEvent,
                                         strlen(entry->mteTThDRiseEvent));
                break;
            case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENTOWNER:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         (u_char *) entry->mteTThDFallOwner,
                                         strlen(entry->mteTThDFallOwner));
                break;
            case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENT:
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         (u_char *) entry->mteTThDFallEvent,
                                         strlen(entry->mteTThDFallEvent));
                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 mteTriggerThresholdTable only contains entries for
             *   rows where the mteTriggerTest 'threshold(2)' bit is set,
             *   strictly speaking we should reject assignments where
             *   this isn't the case.
             * But SET requests that include an assignment of the
             *   'threshold(2)' 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 'threshold(2)' bit isn't set.
             */
            switch (tinfo->colnum) {
            case COLUMN_MTETRIGGERTHRESHOLDSTARTUP:
                ret = netsnmp_check_vb_int_range(request->requestvb,
                                                 MTE_THRESH_START_RISE,
                                                 MTE_THRESH_START_RISEFALL );
                if (ret != SNMP_ERR_NOERROR) {
                    netsnmp_set_request_error(reqinfo, request, ret);
                    return SNMP_ERR_NOERROR;
                }
                break;
            case COLUMN_MTETRIGGERTHRESHOLDRISING:
            case COLUMN_MTETRIGGERTHRESHOLDFALLING:
            case COLUMN_MTETRIGGERTHRESHOLDDELTARISING:
            case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLING:
                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_MTETRIGGERTHRESHOLDOBJECTSOWNER:
            case COLUMN_MTETRIGGERTHRESHOLDOBJECTS:
            case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENTOWNER:
            case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENT:
            case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENTOWNER:
            case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENT:
            case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENTOWNER:
            case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENT:
            case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENTOWNER:
            case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENT:
                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_MTETRIGGERTHRESHOLDSTARTUP:
                entry->mteTThStartup    = *request->requestvb->val.integer;
                break;
            case COLUMN_MTETRIGGERTHRESHOLDRISING:
                entry->mteTThRiseValue  = *request->requestvb->val.integer;
                break;
            case COLUMN_MTETRIGGERTHRESHOLDFALLING:
                entry->mteTThFallValue  = *request->requestvb->val.integer;
                break;
            case COLUMN_MTETRIGGERTHRESHOLDDELTARISING:
                entry->mteTThDRiseValue = *request->requestvb->val.integer;
                break;
            case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLING:
                entry->mteTThDFallValue = *request->requestvb->val.integer;
                break;
            case COLUMN_MTETRIGGERTHRESHOLDOBJECTSOWNER:
                memset(entry->mteTThObjOwner, 0, sizeof(entry->mteTThObjOwner));
                memcpy(entry->mteTThObjOwner, request->requestvb->val.string,
                       request->requestvb->val_len);
                break;
            case COLUMN_MTETRIGGERTHRESHOLDOBJECTS:
                memset(entry->mteTThObjects,  0, sizeof(entry->mteTThObjects));
                memcpy(entry->mteTThObjects,  request->requestvb->val.string,
                       request->requestvb->val_len);
                break;
            case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENTOWNER:
                memset(entry->mteTThRiseOwner, 0, sizeof(entry->mteTThRiseOwner));
                memcpy(entry->mteTThRiseOwner, request->requestvb->val.string,
                       request->requestvb->val_len);
                break;
            case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENT:
                memset(entry->mteTThRiseEvent, 0, sizeof(entry->mteTThRiseEvent));
                memcpy(entry->mteTThRiseEvent, request->requestvb->val.string,
                       request->requestvb->val_len);
                break;
            case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENTOWNER:
                memset(entry->mteTThFallOwner, 0, sizeof(entry->mteTThFallOwner));
                memcpy(entry->mteTThFallOwner, request->requestvb->val.string,
                       request->requestvb->val_len);
                break;
            case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENT:
                memset(entry->mteTThFallEvent, 0, sizeof(entry->mteTThFallEvent));
                memcpy(entry->mteTThFallEvent, request->requestvb->val.string,
                       request->requestvb->val_len);
                break;
            case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENTOWNER:
                memset(entry->mteTThDRiseOwner, 0, sizeof(entry->mteTThDRiseOwner));
                memcpy(entry->mteTThDRiseOwner, request->requestvb->val.string,
                       request->requestvb->val_len);
                break;
            case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENT:
                memset(entry->mteTThDRiseEvent, 0, sizeof(entry->mteTThDRiseEvent));
                memcpy(entry->mteTThDRiseEvent, request->requestvb->val.string,
                       request->requestvb->val_len);
                break;
            case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENTOWNER:
                memset(entry->mteTThDFallOwner, 0, sizeof(entry->mteTThDFallOwner));
                memcpy(entry->mteTThDFallOwner, request->requestvb->val.string,
                       request->requestvb->val_len);
                break;
            case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENT:
                memset(entry->mteTThDFallEvent, 0, sizeof(entry->mteTThDFallEvent));
                memcpy(entry->mteTThDFallEvent, request->requestvb->val.string,
                       request->requestvb->val_len);
                break;
            }
        }
        break;
#endif /* !NETSNMP_NO_WRITE_SUPPORT */

    }
    return SNMP_ERR_NOERROR;
}
コード例 #30
0
ファイル: raidSetTable.c プロジェクト: Jaharmi/Xsnmp
/** 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;
}