Exemple #1
0
int
event_Create(RMON_ENTRY_T * eptr)
{                               /* create the body: alloc it and set defaults */
    CRTL_ENTRY_T   *body;

    eptr->body = AGMALLOC(sizeof(CRTL_ENTRY_T));
    if (!eptr->body)
        return -3;
    body = (CRTL_ENTRY_T *) eptr->body;

    /*
     * set defaults 
     */

    body->event_description = NULL;
    body->event_community = AGSTRDUP("public");
    /*
     * ag_trace ("Dbg: created event_community=<%s>", body->event_community); 
     */
    body->event_type = EVENT_NONE;
    ROWDATAAPI_init(&body->scrlr,
                    MAX_LOG_ENTRIES_PER_CTRL,
                    MAX_LOG_ENTRIES_PER_CTRL,
                    sizeof(DATA_ENTRY_T), &data_destructor);


    return 0;
}
Exemple #2
0
int alarm_Create (RMON_ENTRY_T * eptr)
{                                /* create the body: alloc it and set defaults */
    CRTL_ENTRY_T *body;

    static VAR_OID_T DEFAULT_VAR = { 12,    /* etherStatsPkts.1 */
        {1, 3, 6, 1, 2, 1, 16, 1, 1, 1, 5, 1}
    };


    eptr->body = AGMALLOC (sizeof (CRTL_ENTRY_T));
    if (!eptr->body)
        return -3;
    body = (CRTL_ENTRY_T *) eptr->body;

    /*
     * set defaults 
     */
    body->interval = 1;
    memcpy (&body->var_name, &DEFAULT_VAR, sizeof (VAR_OID_T));
    body->sample_type = SAMPLE_TYPE_ABSOLUTE;
    body->startup_type = ALARM_BOTH;
    body->rising_threshold = MMM_MAX;
    body->falling_threshold = 0;
    body->rising_event_index = body->falling_event_index = 0;

    body->prev_alarm = ALARM_NOTHING;

    return 0;
}
Exemple #3
0
static char    *
create_explanaition(CRTL_ENTRY_T * evptr, u_char is_rising,
                    u_long alarm_index, u_long event_index,
                    oid * alarmed_var,
                    size_t alarmed_var_length,
                    u_long value, u_long the_threshold,
                    u_long sample_type, char *alarm_descr)
{
#define UNEQ_LENGTH	(1 + 11 + 4 + 11 + 1 + 20)
    char            expl[UNEQ_LENGTH];
    static char     c_oid[SPRINT_MAX_LEN];
    size_t          sz;
    char           *descr;
    register char  *pch;
    register char  *tmp;


    snprint_objid(c_oid, sizeof(c_oid)-1, alarmed_var, alarmed_var_length);
    c_oid[sizeof(c_oid)-1] = '\0';
    for (pch = c_oid;;) {
        tmp = strchr(pch, '.');
        if (!tmp)
            break;
        if (isdigit(tmp[1]) || '"' == tmp[1])
            break;
        pch = tmp + 1;
    }

    snprintf(expl, UNEQ_LENGTH, "=%ld %s= %ld :%ld, %ld",
             (unsigned long) value,
             is_rising ? ">" : "<",
             (unsigned long) the_threshold,
             (long) alarm_index, (long) event_index);
    sz = 3 + strlen(expl) + strlen(pch);
    if (alarm_descr)
        sz += strlen(alarm_descr);

    descr = AGMALLOC(sz);
    if (!descr) {
        ag_trace("Can't allocate event description");
        return NULL;
    }

    if (alarm_descr) {
        strcpy(descr, alarm_descr);
        strcat(descr, ":");
    } else
        *descr = '\0';

    strcat(descr, pch);
    strcat(descr, expl);
    return descr;
}
Exemple #4
0
static void realloc_number_of_data (SCROLLER_T * scrlr, long dlong)
{
    void *bptr;                    /* DATA_ENTRY_T */

    NEXTED_PTR_T *prev = NULL;

    void *first = NULL;

    if (dlong > 0)
    {
        for (; dlong; dlong--, prev = bptr, scrlr->data_created++)
        {
            bptr = AGMALLOC (scrlr->data_size);
            if (!bptr)
            {
                ag_trace ("Err: no memory for data");
                break;
            }
            memset (bptr, 0, scrlr->data_size);
            if (prev)
                prev->next = bptr;
            else
                first = bptr;
        }                        /* of loop by malloc bucket */

        if (!scrlr->current_data_ptr)
            scrlr->current_data_ptr = first;
        if (scrlr->last_data_ptr)
        {
            scrlr->last_data_ptr->next = first;
        }
        else
            scrlr->first_data_ptr = first;

        scrlr->last_data_ptr = bptr;

    }
    else
    {
        for (; dlong && scrlr->data_created > 0; dlong++)
        {
            if (scrlr->current_data_ptr)
                delete_data_entry (scrlr, scrlr->current_data_ptr);
            else
                delete_data_entry (scrlr, scrlr->first_data_ptr);
        }
    }
}
Exemple #5
0
RMON_ENTRY_T *ROWAPI_get_clone (TABLE_DEFINTION_T * table_ptr, u_long ctrl_index, size_t body_size)
{
    register RMON_ENTRY_T *eptr;

    if (ctrl_index < 1 || ctrl_index > 0xFFFFu)
    {
        ag_trace ("%s: index %ld out of range (1..65535)", table_ptr->name, (long) ctrl_index);
        return NULL;
    }

    /*
     * get it 
     */
    eptr = ROWAPI_find (table_ptr, ctrl_index);

    if (!eptr)
    {                            /* try to create */
        if (0 != ROWAPI_new (table_ptr, ctrl_index))
        {
            return NULL;
        }

        /*
         * get it 
         */
        eptr = ROWAPI_find (table_ptr, ctrl_index);
        if (!eptr)                /* it is unbelievable, but ... :( */
            return NULL;
    }

    eptr->new_status = eptr->status;

    eptr->tmp = AGMALLOC (body_size);
    if (!eptr->tmp)
    {
        if (eptr->only_just_created)
            rowapi_delete (eptr);
        return NULL;
    }

    memcpy (eptr->tmp, eptr->body, body_size);
    if (table_ptr->ClbkClone)
        table_ptr->ClbkClone (eptr);

    if (eptr->new_owner)
        AGFREE (eptr->new_owner);
    return eptr->tmp;
}
Exemple #6
0
     int
     stat_Create(RMON_ENTRY_T * eptr)
{                               /* create the body: alloc it and set defaults */
    CRTL_ENTRY_T   *body;
    static VAR_OID_T data_src_if_index_1 =
        { 11, {1, 3, 6, 1, 2, 1, 2, 2, 1, 1, 1} };

    eptr->body = AGMALLOC(sizeof(CRTL_ENTRY_T));
    if (!eptr->body)
        return -3;
    body = (CRTL_ENTRY_T *) eptr->body;

    /*
     * set defaults 
     */
    memcpy(&body->data_source, &data_src_if_index_1, sizeof(VAR_OID_T));
    body->data_source.objid[body->data_source.length - 1] =
        eptr->ctrl_index;
    eptr->owner = AGSTRDUP("Startup Mgmt");
    memset(&body->eth, 0, sizeof(ETH_STATS_T));

    return 0;
}
Exemple #7
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;
}
Exemple #8
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;
}
Exemple #9
0
/*
 * creates an entry, locats it in proper sorted order by index
 * Row is initialized to zero,
 * except: 'next', 'table_ptr', 'index',
 * 'timer_id' & 'status'=(RMON1_ENTRY_UNDER_CREATION)
 * Calls (if need) ClbkCreate.
 * Schedules for timeout under entry creation (id of this
 * scheduling is saved in 'timer_id').
 * Returns 0: OK,
 -1:max. number exedes;
 -2:malloc failed;
 -3:ClbkCreate failed */
int
ROWAPI_new(TABLE_DEFINTION_T * table_ptr, u_long ctrl_index)
{
    register RMON_ENTRY_T *eptr;
    register RMON_ENTRY_T *prev = NULL;
    register RMON_ENTRY_T *enew;

    /*
     * check on 'max.number'
     */
    if (table_ptr->max_number_of_entries > 0 &&
            table_ptr->current_number_of_entries >=
            table_ptr->max_number_of_entries)
        return -1;

    /*
     * allocate memory for the header
     */
    enew = (RMON_ENTRY_T *) AGMALLOC(sizeof(RMON_ENTRY_T));
    if (!enew)
        return -2;

    /*
     * init the header
     */
    memset(enew, 0, sizeof(RMON_ENTRY_T));
    enew->ctrl_index = ctrl_index;
    enew->table_ptr = (void *) table_ptr;
    enew->status = RMON1_ENTRY_UNDER_CREATION;
    enew->only_just_created = 1;

    /*
     * create the body: alloc it and set defaults
     */
    if (table_ptr->ClbkCreate) {
        if (0 != table_ptr->ClbkCreate(enew)) {
            AGFREE(enew);
            return -3;
        }
    }

    table_ptr->current_number_of_entries++;

    /*
     * find the place : before 'eptr' and after 'prev'
     */
    for (eptr = table_ptr->first; eptr; eptr = eptr->next) {
        if (ctrl_index < eptr->ctrl_index)
            break;
        prev = eptr;
    }

    /*
     * insert it
     */
    enew->next = eptr;
    if (prev)
        prev->next = enew;
    else
        table_ptr->first = enew;

    enew->timer_id = snmp_alarm_register(MAX_CREATION_TIME, 0,
                                         rowapi_too_long_creation_callback,
                                         enew);
    ag_trace("Entry %ld in %s has been created",
             enew->ctrl_index, table_ptr->name);
    return 0;
}
Exemple #10
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;
}