Пример #1
0
/***************************************************
 * Function:write_etherStatsEntry 
 ***************************************************/
static int
write_etherStatsEntry(int action, u_char * var_val, u_char var_val_type,
                      size_t var_val_len, u_char * statP,
                      oid * name, size_t name_len)
{
    long            long_temp;
    int             leaf_id, snmp_status;
    static int      prev_action = COMMIT;
    RMON_ENTRY_T   *hdr;
    CRTL_ENTRY_T   *cloned_body;
    CRTL_ENTRY_T   *body;

    switch (action) {
    case RESERVE1:
    case FREE:
    case UNDO:
    case ACTION:
    case COMMIT:
    default:
        snmp_status =
            ROWAPI_do_another_action(name, etherStatsEntryFirstIndexBegin,
                                     action, &prev_action, table_ptr,
                                     sizeof(CRTL_ENTRY_T));
        if (SNMP_ERR_NOERROR != snmp_status) {
            ag_trace("failed action %d with %d", action, snmp_status);
        }
        break;

    case RESERVE2:
        /*
         * get values from PDU, check them and save them in the cloned entry 
         */
        long_temp = name[etherStatsEntryFirstIndexBegin];
        leaf_id = (int) name[etherStatsEntryFirstIndexBegin - 1];
        hdr = ROWAPI_find(table_ptr, long_temp);        /* it MUST be OK */
        cloned_body = (CRTL_ENTRY_T *) hdr->tmp;
        body = (CRTL_ENTRY_T *) hdr->body;
        switch (leaf_id) {
        case Leaf_etherStatsDataSource:
            snmp_status = AGUTIL_get_oid_value(var_val, var_val_type,
                                               var_val_len,
                                               &cloned_body->data_source);
            if (SNMP_ERR_NOERROR != snmp_status) {
                return snmp_status;
            }
            if (RMON1_ENTRY_UNDER_CREATION != hdr->status &&
                snmp_oid_compare(cloned_body->data_source.objid,
                                 cloned_body->data_source.length,
                                 body->data_source.objid,
                                 body->data_source.length))
                return SNMP_ERR_BADVALUE;
            break;

            break;
        case Leaf_etherStatsOwner:
            if (hdr->new_owner)
                AGFREE(hdr->new_owner);
            hdr->new_owner = AGMALLOC(MAX_OWNERSTRING);;
            if (!hdr->new_owner)
                return SNMP_ERR_TOOBIG;
            snmp_status = AGUTIL_get_string_value(var_val, var_val_type,
                                                  var_val_len,
                                                  MAX_OWNERSTRING,
                                                  1, NULL, hdr->new_owner);
            if (SNMP_ERR_NOERROR != snmp_status) {
                return snmp_status;
            }
            break;
        case Leaf_etherStatsStatus:
            snmp_status = AGUTIL_get_int_value(var_val, var_val_type,
                                               var_val_len,
                                               RMON1_ENTRY_VALID,
                                               RMON1_ENTRY_INVALID,
                                               &long_temp);
            if (SNMP_ERR_NOERROR != snmp_status) {
                ag_trace("cannot browse etherStatsStatus");
                return snmp_status;
            }
            hdr->new_status = long_temp;
            break;
            break;
        default:
            ag_trace("%s:unknown leaf_id=%d\n", table_ptr->name,
                     (int) leaf_id);
            return SNMP_ERR_NOSUCHNAME;
        }                       /* of switch by 'leaf_id' */
        break;
    }                           /* of switch by 'action' */

    prev_action = action;
    return SNMP_ERR_NOERROR;
}
Пример #2
0
static int
write_eventControl(int action, u_char * var_val, u_char var_val_type,
                   size_t var_val_len, u_char * statP,
                   oid * name, size_t name_len)
{
    long            long_temp;
    char           *char_temp;
    int             leaf_id, snmp_status;
    static int      prev_action = COMMIT;
    RMON_ENTRY_T   *hdr;
    CRTL_ENTRY_T   *cloned_body;

    switch (action) {
    case RESERVE1:
    case FREE:
    case UNDO:
    case ACTION:
    case COMMIT:
    default:
        return ROWAPI_do_another_action(name, eventEntryFirstIndexBegin,
                                        action, &prev_action,
                                        table_ptr, sizeof(CRTL_ENTRY_T));

    case RESERVE2:
        /*
         * get values from PDU, check them and save them in the cloned entry 
         */
        long_temp = name[eventEntryFirstIndexBegin];
        leaf_id = (int) name[eventEntryFirstIndexBegin - 1];
        hdr = ROWAPI_find(table_ptr, long_temp);        /* it MUST be OK */
        cloned_body = (CRTL_ENTRY_T *) hdr->tmp;
        switch (leaf_id) {
        case Leaf_event_index:
            return SNMP_ERR_NOTWRITABLE;
        case Leaf_event_description:
            char_temp = AGMALLOC(1 + MAX_event_description);
            if (!char_temp)
                return SNMP_ERR_TOOBIG;
            snmp_status = AGUTIL_get_string_value(var_val, var_val_type,
                                                  var_val_len,
                                                  MAX_event_description,
                                                  1, NULL, char_temp);
            if (SNMP_ERR_NOERROR != snmp_status) {
                AGFREE(char_temp);
                return snmp_status;
            }

            if (cloned_body->event_description)
                AGFREE(cloned_body->event_description);

            cloned_body->event_description = AGSTRDUP(char_temp);
            /*
             * ag_trace ("rx: event_description=<%s>", cloned_body->event_description); 
             */
            AGFREE(char_temp);

            break;
        case Leaf_event_type:
            snmp_status = AGUTIL_get_int_value(var_val, var_val_type,
                                               var_val_len,
                                               EVENT_NONE,
                                               EVENT_LOG_AND_TRAP,
                                               &long_temp);
            if (SNMP_ERR_NOERROR != snmp_status) {
                return snmp_status;
            }
            cloned_body->event_type = long_temp;
            break;
        case Leaf_event_last_time_sent:
            return SNMP_ERR_NOTWRITABLE;
        case Leaf_event_community:
            char_temp = AGMALLOC(1 + MAX_event_community);
            if (!char_temp)
                return SNMP_ERR_TOOBIG;
            snmp_status = AGUTIL_get_string_value(var_val, var_val_type,
                                                  var_val_len,
                                                  MAX_event_community,
                                                  1, NULL, char_temp);
            if (SNMP_ERR_NOERROR != snmp_status) {
                AGFREE(char_temp);
                return snmp_status;
            }

            if (cloned_body->event_community)
                AGFREE(cloned_body->event_community);

            cloned_body->event_community = AGSTRDUP(char_temp);
            AGFREE(char_temp);

            break;
        case Leaf_eventOwner:
            if (hdr->new_owner)
                AGFREE(hdr->new_owner);
            hdr->new_owner = AGMALLOC(MAX_OWNERSTRING);;
            if (!hdr->new_owner)
                return SNMP_ERR_TOOBIG;
            snmp_status = AGUTIL_get_string_value(var_val, var_val_type,
                                                  var_val_len,
                                                  MAX_OWNERSTRING,
                                                  1, NULL, hdr->new_owner);
            if (SNMP_ERR_NOERROR != snmp_status) {
                return snmp_status;
            }

            break;
        case Leaf_eventStatus:
            snmp_status = AGUTIL_get_int_value(var_val, var_val_type,
                                               var_val_len,
                                               RMON1_ENTRY_VALID,
                                               RMON1_ENTRY_INVALID,
                                               &long_temp);
            if (SNMP_ERR_NOERROR != snmp_status) {
                return snmp_status;
            }
            hdr->new_status = long_temp;
            break;
        default:
            ag_trace("%s:unknown leaf_id=%d\n", table_ptr->name,
                     (int) leaf_id);
            return SNMP_ERR_NOSUCHNAME;
        }                       /* of switch by 'leaf_id' */
        break;
    }                           /* of switch by actions */

    prev_action = action;
    return SNMP_ERR_NOERROR;
}
Пример #3
0
static int
write_alarmEntry (int action, u_char * var_val, u_char var_val_type,
                  size_t var_val_len, u_char * statP, oid * name, size_t name_len)
{
    long long_tmp;

    int leaf_id, snmp_status;

    static int prev_action = COMMIT;

    RMON_ENTRY_T *hdr;

    CRTL_ENTRY_T *cloned_body;

    CRTL_ENTRY_T *body;

    switch (action)
    {
        case RESERVE1:
        case FREE:
        case UNDO:
        case ACTION:
        case COMMIT:
        default:
            return ROWAPI_do_another_action (name, alarmEntryFirstIndexBegin,
                                             action, &prev_action, table_ptr, sizeof (CRTL_ENTRY_T));
        case RESERVE2:
            /*
             * get values from PDU, check them and save them in the cloned entry 
             */
            long_tmp = name[alarmEntryFirstIndexBegin];
            leaf_id = (int) name[alarmEntryFirstIndexBegin - 1];
            hdr = ROWAPI_find (table_ptr, long_tmp);    /* it MUST be OK */
            cloned_body = (CRTL_ENTRY_T *) hdr->tmp;
            body = (CRTL_ENTRY_T *) hdr->body;
            switch (leaf_id)
            {
                case IDalarmInterval:
                    snmp_status = AGUTIL_get_int_value (var_val, var_val_type, var_val_len, 0, MMM_MAX, &long_tmp);
                    if (SNMP_ERR_NOERROR != snmp_status)
                    {
                        return snmp_status;
                    }
                    cloned_body->interval = long_tmp;
                    break;
                case IDalarmVariable:
                    snmp_status = AGUTIL_get_oid_value (var_val, var_val_type, var_val_len, &cloned_body->var_name);
                    if (SNMP_ERR_NOERROR != snmp_status)
                    {
                        return snmp_status;
                    }
                    if (RMON1_ENTRY_UNDER_CREATION != hdr->status &&
                        snmp_oid_compare (cloned_body->var_name.objid,
                                          cloned_body->var_name.length, body->var_name.objid, body->var_name.length))
                        return SNMP_ERR_BADVALUE;
                    break;

                    break;
                case IDalarmSampleType:
                    snmp_status = AGUTIL_get_int_value (var_val, var_val_type,
                                                        var_val_len,
                                                        SAMPLE_TYPE_ABSOLUTE, SAMPLE_TYPE_DELTE, &long_tmp);
                    if (SNMP_ERR_NOERROR != snmp_status)
                    {
                        return snmp_status;
                    }
                    cloned_body->sample_type = long_tmp;
                    break;
                case IDalarmStartupAlarm:
                    snmp_status = AGUTIL_get_int_value (var_val, var_val_type,
                                                        var_val_len, ALARM_RISING, ALARM_BOTH, &long_tmp);
                    if (SNMP_ERR_NOERROR != snmp_status)
                    {
                        return snmp_status;
                    }
                    cloned_body->startup_type = long_tmp;
                    break;
                case IDalarmRisingThreshold:
                    snmp_status = AGUTIL_get_int_value (var_val, var_val_type, var_val_len, 0, MMM_MAX, &long_tmp);
                    if (SNMP_ERR_NOERROR != snmp_status)
                    {
                        return snmp_status;
                    }
                    cloned_body->rising_threshold = long_tmp;
                    break;
                case IDalarmFallingThreshold:
                    snmp_status = AGUTIL_get_int_value (var_val, var_val_type, var_val_len, 0, 0xFFFFFFFFl, &long_tmp);
                    if (SNMP_ERR_NOERROR != snmp_status)
                    {
                        return snmp_status;
                    }
                    cloned_body->falling_threshold = long_tmp;
                    break;
                case IDalarmRisingEventIndex:
                    snmp_status = AGUTIL_get_int_value (var_val, var_val_type, var_val_len, 0,    /* min. value */
                                                        0,    /* max. value */
                                                        &long_tmp);
                    if (SNMP_ERR_NOERROR != snmp_status)
                    {
                        return snmp_status;
                    }
                    cloned_body->rising_event_index = long_tmp;
                    break;
                case IDalarmFallingEventIndex:
                    snmp_status = AGUTIL_get_int_value (var_val, var_val_type, var_val_len, 0,    /* min. value */
                                                        0,    /* max. value */
                                                        &long_tmp);
                    if (SNMP_ERR_NOERROR != snmp_status)
                    {
                        return snmp_status;
                    }
                    cloned_body->falling_event_index = long_tmp;
                    break;
                case IDalarmOwner:
                    if (hdr->new_owner)
                        AGFREE (hdr->new_owner);
                    hdr->new_owner = AGMALLOC (MAX_OWNERSTRING);;
                    if (!hdr->new_owner)
                        return SNMP_ERR_TOOBIG;
                    snmp_status = AGUTIL_get_string_value (var_val, var_val_type,
                                                           var_val_len, MAX_OWNERSTRING, 1, NULL, hdr->new_owner);
                    if (SNMP_ERR_NOERROR != snmp_status)
                    {
                        return snmp_status;
                    }

                    break;
                case IDalarmStatus:
                    snmp_status = AGUTIL_get_int_value (var_val, var_val_type,
                                                        var_val_len, RMON1_ENTRY_VALID, RMON1_ENTRY_INVALID, &long_tmp);
                    if (SNMP_ERR_NOERROR != snmp_status)
                    {
                        return snmp_status;
                    }
                    hdr->new_status = long_tmp;
                    break;
                default:
                    ag_trace ("%s:unknown leaf_id=%d\n", table_ptr->name, (int) leaf_id);
                    return SNMP_ERR_NOSUCHNAME;
            }                    /* of switch by 'leaf_id' */

            break;
    }                            /* of switch by actions */

    prev_action = action;
    return SNMP_ERR_NOERROR;
}