~ubuntu-branches/ubuntu/gutsy/net-snmp/gutsy-security

« back to all changes in this revision

Viewing changes to agent/mibgroup/Rmon/history.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-09-13 12:06:21 UTC
  • Revision ID: james.westby@ubuntu.com-20040913120621-g952ntonlleihcvm
Tags: upstream-5.1.1
ImportĀ upstreamĀ versionĀ 5.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************
 
2
 * Copyright (C) 2001 Alex Rozin, Optical Access 
 
3
 *
 
4
 *                     All Rights Reserved
 
5
 *
 
6
 * Permission to use, copy, modify and distribute this software and its
 
7
 * documentation for any purpose and without fee is hereby granted,
 
8
 * provided that the above copyright notice appear in all copies and that
 
9
 * both that copyright notice and this permission notice appear in
 
10
 * supporting documentation.
 
11
 * 
 
12
 * ALEX ROZIN DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 
13
 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 
14
 * ALEX ROZIN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
 
15
 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 
16
 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 
17
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 
18
 * SOFTWARE.
 
19
 ******************************************************************/
 
20
 
 
21
#include <net-snmp/net-snmp-config.h>
 
22
 
 
23
#if HAVE_STDLIB_H
 
24
#include <stdlib.h>
 
25
#endif
 
26
#if TIME_WITH_SYS_TIME
 
27
# ifdef WIN32
 
28
#  include <sys/timeb.h>
 
29
# else
 
30
#  include <sys/time.h>
 
31
# endif
 
32
# include <time.h>
 
33
#else
 
34
# if HAVE_SYS_TIME_H
 
35
#  include <sys/time.h>
 
36
# else
 
37
#  include <time.h>
 
38
# endif
 
39
#endif
 
40
#if HAVE_UNISTD_H
 
41
#include <unistd.h>
 
42
#endif
 
43
 
 
44
#include <net-snmp/net-snmp-includes.h>
 
45
#include <net-snmp/agent/net-snmp-agent-includes.h>
 
46
 
 
47
#include "util_funcs.h"
 
48
 
 
49
#include "history.h"
 
50
 
 
51
/*
 
52
 * Implementation headers 
 
53
 */
 
54
#include "agutil_api.h"
 
55
#include "row_api.h"
 
56
 
 
57
/*
 
58
 * File scope definitions section 
 
59
 */
 
60
 
 
61
#define historyControlEntryFirstIndexBegin      11
 
62
 
 
63
#define CTRL_INDEX              3
 
64
#define CTRL_DATASOURCE         4
 
65
#define CTRL_BUCKETSREQUESTED   5
 
66
#define CTRL_BUCKETSGRANTED     6
 
67
#define CTRL_INTERVAL           7
 
68
#define CTRL_OWNER              8
 
69
#define CTRL_STATUS             9
 
70
 
 
71
#define DATA_INDEX              3
 
72
#define DATA_SAMPLEINDEX        4
 
73
#define DATA_INTERVALSTART      5
 
74
#define DATA_DROPEVENTS         6
 
75
#define DATA_OCTETS             7
 
76
#define DATA_PKTS               8
 
77
#define DATA_BROADCASTPKTS      9
 
78
#define DATA_MULTICASTPKTS      10
 
79
#define DATA_CRCALIGNERRORS     11
 
80
#define DATA_UNDERSIZEPKTS      12
 
81
#define DATA_OVERSIZEPKTS       13
 
82
#define DATA_FRAGMENTS          14
 
83
#define DATA_JABBERS            15
 
84
#define DATA_COLLISIONS         16
 
85
#define DATA_UTILIZATION        17
 
86
 
 
87
/*
 
88
 * defaults & limitations 
 
89
 */
 
90
 
 
91
#define MAX_BUCKETS_IN_CRTL_ENTRY       50
 
92
#define HIST_DEF_BUCK_REQ               50
 
93
#define HIST_DEF_INTERVAL               1800
 
94
static VAR_OID_T DEFAULT_DATA_SOURCE = { 11,    /* ifIndex.1 */
 
95
    {1, 3, 6, 1, 2, 1, 2, 2, 1, 1, 1}
 
96
};
 
97
 
 
98
typedef struct data_struct_t {
 
99
    struct data_struct_t *next;
 
100
    u_long          data_index;
 
101
    u_long          start_interval;
 
102
    u_long          utilization;
 
103
    ETH_STATS_T     EthData;
 
104
} DATA_ENTRY_T;
 
105
 
 
106
typedef struct {
 
107
    u_long          interval;
 
108
    u_long          timer_id;
 
109
    VAR_OID_T       data_source;
 
110
 
 
111
    u_long          coeff;
 
112
    DATA_ENTRY_T    previous_bucket;
 
113
    SCROLLER_T      scrlr;
 
114
 
 
115
} CRTL_ENTRY_T;
 
116
 
 
117
static TABLE_DEFINTION_T HistoryCtrlTable;
 
118
static TABLE_DEFINTION_T *table_ptr = &HistoryCtrlTable;
 
119
 
 
120
/*
 
121
 * Main section 
 
122
 */
 
123
 
 
124
#  define Leaf_historyControlDataSource                    2
 
125
#  define Leaf_historyControlBucketsRequested              3
 
126
#  define Leaf_historyControlInterval                      5
 
127
#  define Leaf_historyControlOwner                         6
 
128
#  define Leaf_historyControlStatus                        7
 
129
#  define MIN_historyControlBucketsRequested               1
 
130
#  define MAX_historyControlBucketsRequested               65535
 
131
#  define MIN_historyControlInterval                       1
 
132
#  define MAX_historyControlInterval                       3600
 
133
 
 
134
static int
 
135
write_historyControl(int action, u_char * var_val, u_char var_val_type,
 
136
                     size_t var_val_len, u_char * statP,
 
137
                     oid * name, size_t name_len)
 
138
{
 
139
    long            long_temp;
 
140
    int             leaf_id, snmp_status;
 
141
    static int      prev_action = COMMIT;
 
142
    RMON_ENTRY_T   *hdr;
 
143
    CRTL_ENTRY_T   *cloned_body;
 
144
    CRTL_ENTRY_T   *body;
 
145
 
 
146
    switch (action) {
 
147
    case RESERVE1:
 
148
    case FREE:
 
149
    case UNDO:
 
150
    case ACTION:
 
151
    case COMMIT:
 
152
    default:
 
153
        return ROWAPI_do_another_action(name,
 
154
                                        historyControlEntryFirstIndexBegin,
 
155
                                        action, &prev_action, table_ptr,
 
156
                                        sizeof(CRTL_ENTRY_T));
 
157
    case RESERVE2:
 
158
        /*
 
159
         * get values from PDU, check them and save them in the cloned entry 
 
160
         */
 
161
        long_temp = name[historyControlEntryFirstIndexBegin];
 
162
        leaf_id = (int) name[historyControlEntryFirstIndexBegin - 1];
 
163
        hdr = ROWAPI_find(table_ptr, long_temp);        /* it MUST be OK */
 
164
        cloned_body = (CRTL_ENTRY_T *) hdr->tmp;
 
165
        body = (CRTL_ENTRY_T *) hdr->body;
 
166
        switch (leaf_id) {
 
167
        case Leaf_historyControlDataSource:
 
168
            snmp_status = AGUTIL_get_oid_value(var_val, var_val_type,
 
169
                                               var_val_len,
 
170
                                               &cloned_body->data_source);
 
171
            if (SNMP_ERR_NOERROR != snmp_status) {
 
172
                ag_trace("can't browse historyControlDataSource");
 
173
                return snmp_status;
 
174
            }
 
175
            if (RMON1_ENTRY_UNDER_CREATION != hdr->status &&
 
176
                snmp_oid_compare(cloned_body->data_source.objid,
 
177
                                 cloned_body->data_source.length,
 
178
                                 body->data_source.objid,
 
179
                                 body->data_source.length)) {
 
180
                ag_trace
 
181
                    ("can't change historyControlDataSource - not Creation");
 
182
                return SNMP_ERR_BADVALUE;
 
183
            }
 
184
            break;
 
185
        case Leaf_historyControlBucketsRequested:
 
186
            snmp_status = AGUTIL_get_int_value(var_val, var_val_type,
 
187
                                               var_val_len,
 
188
                                               MIN_historyControlBucketsRequested,
 
189
                                               MAX_historyControlBucketsRequested,
 
190
                                               &cloned_body->scrlr.
 
191
                                               data_requested);
 
192
            if (SNMP_ERR_NOERROR != snmp_status) {
 
193
                return snmp_status;
 
194
            }
 
195
#if 0
 
196
            if (RMON1_ENTRY_UNDER_CREATION != hdr->status &&
 
197
                cloned_body->scrlr.data_requested !=
 
198
                body->scrlr.data_requested)
 
199
                return SNMP_ERR_BADVALUE;
 
200
#endif
 
201
            break;
 
202
        case Leaf_historyControlInterval:
 
203
            snmp_status = AGUTIL_get_int_value(var_val, var_val_type,
 
204
                                               var_val_len,
 
205
                                               MIN_historyControlInterval,
 
206
                                               MAX_historyControlInterval,
 
207
                                               &cloned_body->interval);
 
208
            if (SNMP_ERR_NOERROR != snmp_status) {
 
209
                return snmp_status;
 
210
            }
 
211
#if 0
 
212
            if (RMON1_ENTRY_UNDER_CREATION != hdr->status &&
 
213
                cloned_body->interval != body->interval)
 
214
                return SNMP_ERR_BADVALUE;
 
215
#endif
 
216
            break;
 
217
        case Leaf_historyControlOwner:
 
218
            if (hdr->new_owner)
 
219
                AGFREE(hdr->new_owner);
 
220
            hdr->new_owner = AGMALLOC(MAX_OWNERSTRING);;
 
221
            if (!hdr->new_owner)
 
222
                return SNMP_ERR_TOOBIG;
 
223
            snmp_status = AGUTIL_get_string_value(var_val, var_val_type,
 
224
                                                  var_val_len,
 
225
                                                  MAX_OWNERSTRING,
 
226
                                                  1, NULL, hdr->new_owner);
 
227
            if (SNMP_ERR_NOERROR != snmp_status) {
 
228
                return snmp_status;
 
229
            }
 
230
 
 
231
            break;
 
232
        case Leaf_historyControlStatus:
 
233
            snmp_status = AGUTIL_get_int_value(var_val, var_val_type,
 
234
                                               var_val_len,
 
235
                                               RMON1_ENTRY_VALID,
 
236
                                               RMON1_ENTRY_INVALID,
 
237
                                               &long_temp);
 
238
            if (SNMP_ERR_NOERROR != snmp_status) {
 
239
                return snmp_status;
 
240
            }
 
241
            hdr->new_status = long_temp;
 
242
            break;
 
243
        default:
 
244
            ag_trace("%s:unknown leaf_id=%d\n", table_ptr->name,
 
245
                     (int) leaf_id);
 
246
            return SNMP_ERR_NOSUCHNAME;
 
247
        }                       /* of switch by 'leaf_id' */
 
248
        break;
 
249
 
 
250
    }                           /* of switch by actions */
 
251
 
 
252
    prev_action = action;
 
253
    return SNMP_ERR_NOERROR;
 
254
}
 
255
 
 
256
/*
 
257
 * var_historyControlTable():
 
258
 */
 
259
unsigned char  *
 
260
var_historyControlTable(struct variable *vp,
 
261
                        oid * name,
 
262
                        size_t * length,
 
263
                        int exact,
 
264
                        size_t * var_len, WriteMethod ** write_method)
 
265
{
 
266
    static long     long_ret;
 
267
    static CRTL_ENTRY_T theEntry;
 
268
    RMON_ENTRY_T   *hdr;
 
269
 
 
270
    *write_method = write_historyControl;
 
271
    hdr = ROWAPI_header_ControlEntry(vp, name, length, exact, var_len,
 
272
                                     table_ptr,
 
273
                                     &theEntry, sizeof(CRTL_ENTRY_T));
 
274
    if (!hdr)
 
275
        return NULL;
 
276
 
 
277
    *var_len = sizeof(long);    /* default */
 
278
 
 
279
    switch (vp->magic) {
 
280
    case CTRL_INDEX:
 
281
        long_ret = hdr->ctrl_index;
 
282
        return (unsigned char *) &long_ret;
 
283
 
 
284
    case CTRL_DATASOURCE:
 
285
        *var_len = sizeof(oid) * theEntry.data_source.length;
 
286
        return (unsigned char *) theEntry.data_source.objid;
 
287
 
 
288
    case CTRL_BUCKETSREQUESTED:
 
289
        long_ret = theEntry.scrlr.data_requested;
 
290
        return (unsigned char *) &long_ret;
 
291
 
 
292
    case CTRL_BUCKETSGRANTED:
 
293
 
 
294
        long_ret = theEntry.scrlr.data_granted;
 
295
        return (unsigned char *) &long_ret;
 
296
 
 
297
    case CTRL_INTERVAL:
 
298
        long_ret = theEntry.interval;
 
299
        return (unsigned char *) &long_ret;
 
300
 
 
301
    case CTRL_OWNER:
 
302
        if (hdr->owner) {
 
303
            *var_len = strlen(hdr->owner);
 
304
            return (unsigned char *) hdr->owner;
 
305
        } else {
 
306
            *var_len = 0;
 
307
            return (unsigned char *) "";
 
308
        }
 
309
 
 
310
    case CTRL_STATUS:
 
311
        long_ret = hdr->status;
 
312
        return (unsigned char *) &long_ret;
 
313
 
 
314
    default:
 
315
        ag_trace("HistoryControlTable: unknown vp->magic=%d",
 
316
                 (int) vp->magic);
 
317
        ERROR_MSG("");
 
318
    }
 
319
    return NULL;
 
320
}
 
321
 
 
322
/*
 
323
 * history row management control callbacks 
 
324
 */
 
325
 
 
326
static void
 
327
compute_delta(ETH_STATS_T * delta,
 
328
              ETH_STATS_T * newval, ETH_STATS_T * prevval)
 
329
{
 
330
#define CNT_DIF(X) delta->X = newval->X - prevval->X
 
331
 
 
332
    CNT_DIF(octets);
 
333
    CNT_DIF(packets);
 
334
    CNT_DIF(bcast_pkts);
 
335
    CNT_DIF(mcast_pkts);
 
336
    CNT_DIF(crc_align);
 
337
    CNT_DIF(undersize);
 
338
    CNT_DIF(oversize);
 
339
    CNT_DIF(fragments);
 
340
    CNT_DIF(jabbers);
 
341
    CNT_DIF(collisions);
 
342
}
 
343
 
 
344
static void
 
345
history_get_backet(unsigned int clientreg, void *clientarg)
 
346
{
 
347
    RMON_ENTRY_T   *hdr_ptr;
 
348
    CRTL_ENTRY_T   *body;
 
349
    DATA_ENTRY_T   *bptr;
 
350
    ETH_STATS_T     newSample;
 
351
 
 
352
    /*
 
353
     * ag_trace ("history_get_backet: timer_id=%d", (int) clientreg); 
 
354
     */
 
355
    hdr_ptr = (RMON_ENTRY_T *) clientarg;
 
356
    if (!hdr_ptr) {
 
357
        ag_trace
 
358
            ("Err: history_get_backet: hdr_ptr=NULL ? (Inserted in shock)");
 
359
        return;
 
360
    }
 
361
 
 
362
    body = (CRTL_ENTRY_T *) hdr_ptr->body;
 
363
    if (!body) {
 
364
        ag_trace
 
365
            ("Err: history_get_backet: body=NULL ? (Inserted in shock)");
 
366
        return;
 
367
    }
 
368
 
 
369
    if (RMON1_ENTRY_VALID != hdr_ptr->status) {
 
370
        ag_trace("Err: history_get_backet when entry %d is not valid ?!!",
 
371
                 (int) hdr_ptr->ctrl_index);
 
372
        /*
 
373
         * snmp_alarm_print_list (); 
 
374
         */
 
375
        snmp_alarm_unregister(body->timer_id);
 
376
        ag_trace("Err: unregistered %ld", (long) body->timer_id);
 
377
        return;
 
378
    }
 
379
 
 
380
    SYSTEM_get_eth_statistics(&body->data_source, &newSample);
 
381
 
 
382
    bptr = ROWDATAAPI_locate_new_data(&body->scrlr);
 
383
    if (!bptr) {
 
384
        ag_trace
 
385
            ("Err: history_get_backet for %d: empty bucket's list !??\n",
 
386
             (int) hdr_ptr->ctrl_index);
 
387
        return;
 
388
    }
 
389
 
 
390
    bptr->data_index = ROWDATAAPI_get_total_number(&body->scrlr);
 
391
 
 
392
    bptr->start_interval = body->previous_bucket.start_interval;
 
393
 
 
394
    compute_delta(&bptr->EthData, &newSample,
 
395
                  &body->previous_bucket.EthData);
 
396
 
 
397
    bptr->utilization =
 
398
        bptr->EthData.octets * 8 + bptr->EthData.packets * (96 + 64);
 
399
    bptr->utilization /= body->coeff;
 
400
 
 
401
    /*
 
402
     * update previous_bucket 
 
403
     */
 
404
    body->previous_bucket.start_interval = AGUTIL_sys_up_time();
 
405
    memcpy(&body->previous_bucket.EthData, &newSample,
 
406
           sizeof(ETH_STATS_T));
 
407
}
 
408
 
 
409
/*
 
410
 * Control Table RowApi Callbacks 
 
411
 */
 
412
 
 
413
int
 
414
history_Create(RMON_ENTRY_T * eptr)
 
415
{                               /* create the body: alloc it and set defaults */
 
416
    CRTL_ENTRY_T   *body;
 
417
 
 
418
    eptr->body = AGMALLOC(sizeof(CRTL_ENTRY_T));
 
419
    if (!eptr->body)
 
420
        return -3;
 
421
    body = (CRTL_ENTRY_T *) eptr->body;
 
422
 
 
423
    /*
 
424
     * set defaults 
 
425
     */
 
426
    body->interval = HIST_DEF_INTERVAL;
 
427
    body->timer_id = 0;
 
428
    memcpy(&body->data_source, &DEFAULT_DATA_SOURCE, sizeof(VAR_OID_T));
 
429
 
 
430
    ROWDATAAPI_init(&body->scrlr, HIST_DEF_BUCK_REQ,
 
431
                    MAX_BUCKETS_IN_CRTL_ENTRY, sizeof(DATA_ENTRY_T), NULL);
 
432
 
 
433
    return 0;
 
434
}
 
435
 
 
436
int
 
437
history_Validate(RMON_ENTRY_T * eptr)
 
438
{
 
439
    /*
 
440
     * T.B.D. (system dependent) check valid inteface in body->data_source; 
 
441
     */
 
442
    return 0;
 
443
}
 
444
 
 
445
int
 
446
history_Activate(RMON_ENTRY_T * eptr)
 
447
{
 
448
    CRTL_ENTRY_T   *body = (CRTL_ENTRY_T *) eptr->body;
 
449
 
 
450
    body->coeff = 100000L * (long) body->interval;
 
451
 
 
452
    ROWDATAAPI_set_size(&body->scrlr,
 
453
                        body->scrlr.data_requested,
 
454
                        (u_char)(RMON1_ENTRY_VALID == eptr->status) );
 
455
 
 
456
    SYSTEM_get_eth_statistics(&body->data_source,
 
457
                              &body->previous_bucket.EthData);
 
458
    body->previous_bucket.start_interval = AGUTIL_sys_up_time();
 
459
 
 
460
    body->scrlr.current_data_ptr = body->scrlr.first_data_ptr;
 
461
    /*
 
462
     * ag_trace ("Dbg:   registered in history_Activate"); 
 
463
     */
 
464
    body->timer_id = snmp_alarm_register(body->interval, SA_REPEAT,
 
465
                                         history_get_backet, eptr);
 
466
    return 0;
 
467
}
 
468
 
 
469
int
 
470
history_Deactivate(RMON_ENTRY_T * eptr)
 
471
{
 
472
    CRTL_ENTRY_T   *body = (CRTL_ENTRY_T *) eptr->body;
 
473
 
 
474
    snmp_alarm_unregister(body->timer_id);
 
475
    /*
 
476
     * ag_trace ("Dbg: unregistered in history_Deactivate timer_id=%d",
 
477
     * (int) body->timer_id); 
 
478
     */
 
479
 
 
480
    /*
 
481
     * free data list 
 
482
     */
 
483
    ROWDATAAPI_descructor(&body->scrlr);
 
484
 
 
485
    return 0;
 
486
}
 
487
 
 
488
int
 
489
history_Copy(RMON_ENTRY_T * eptr)
 
490
{
 
491
    CRTL_ENTRY_T   *body = (CRTL_ENTRY_T *) eptr->body;
 
492
    CRTL_ENTRY_T   *clone = (CRTL_ENTRY_T *) eptr->tmp;
 
493
 
 
494
    if (body->scrlr.data_requested != clone->scrlr.data_requested) {
 
495
        ROWDATAAPI_set_size(&body->scrlr, clone->scrlr.data_requested,
 
496
                            (u_char)(RMON1_ENTRY_VALID == eptr->status) );
 
497
    }
 
498
 
 
499
    if (body->interval != clone->interval) {
 
500
        if (RMON1_ENTRY_VALID == eptr->status) {
 
501
            snmp_alarm_unregister(body->timer_id);
 
502
            body->timer_id =
 
503
                snmp_alarm_register(clone->interval, SA_REPEAT,
 
504
                                    history_get_backet, eptr);
 
505
        }
 
506
 
 
507
        body->interval = clone->interval;
 
508
    }
 
509
 
 
510
    if (snmp_oid_compare
 
511
        (clone->data_source.objid, clone->data_source.length,
 
512
         body->data_source.objid, body->data_source.length)) {
 
513
        memcpy(&body->data_source, &clone->data_source, sizeof(VAR_OID_T));
 
514
    }
 
515
 
 
516
    return 0;
 
517
}
 
518
 
 
519
static SCROLLER_T *
 
520
history_extract_scroller(void *v_body)
 
521
{
 
522
    CRTL_ENTRY_T   *body = (CRTL_ENTRY_T *) v_body;
 
523
    return &body->scrlr;
 
524
}
 
525
 
 
526
/*
 
527
 * var_etherHistoryTable():
 
528
 */
 
529
unsigned char  *
 
530
var_etherHistoryTable(struct variable *vp,
 
531
                      oid * name,
 
532
                      size_t * length,
 
533
                      int exact,
 
534
                      size_t * var_len, WriteMethod ** write_method)
 
535
{
 
536
    static long     long_ret;
 
537
    static DATA_ENTRY_T theBucket;
 
538
    RMON_ENTRY_T   *hdr;
 
539
    CRTL_ENTRY_T   *ctrl;
 
540
 
 
541
    *write_method = NULL;
 
542
    hdr = ROWDATAAPI_header_DataEntry(vp, name, length, exact, var_len,
 
543
                                      table_ptr,
 
544
                                      &history_extract_scroller,
 
545
                                      sizeof(DATA_ENTRY_T), &theBucket);
 
546
    if (!hdr)
 
547
        return NULL;
 
548
 
 
549
    *var_len = sizeof(long);    /* default */
 
550
 
 
551
    ctrl = (CRTL_ENTRY_T *) hdr->body;
 
552
 
 
553
    switch (vp->magic) {
 
554
    case DATA_INDEX:
 
555
        long_ret = hdr->ctrl_index;
 
556
        return (unsigned char *) &long_ret;
 
557
    case DATA_SAMPLEINDEX:
 
558
        long_ret = theBucket.data_index;
 
559
        return (unsigned char *) &long_ret;
 
560
    case DATA_INTERVALSTART:
 
561
        long_ret = 0;
 
562
        return (unsigned char *) &theBucket.start_interval;
 
563
    case DATA_DROPEVENTS:
 
564
        long_ret = 0;
 
565
        return (unsigned char *) &long_ret;
 
566
    case DATA_OCTETS:
 
567
        long_ret = 0;
 
568
        return (unsigned char *) &theBucket.EthData.octets;
 
569
    case DATA_PKTS:
 
570
        long_ret = 0;
 
571
        return (unsigned char *) &theBucket.EthData.packets;
 
572
    case DATA_BROADCASTPKTS:
 
573
        long_ret = 0;
 
574
        return (unsigned char *) &theBucket.EthData.bcast_pkts;
 
575
    case DATA_MULTICASTPKTS:
 
576
        long_ret = 0;
 
577
        return (unsigned char *) &theBucket.EthData.mcast_pkts;
 
578
    case DATA_CRCALIGNERRORS:
 
579
        long_ret = 0;
 
580
        return (unsigned char *) &theBucket.EthData.crc_align;
 
581
    case DATA_UNDERSIZEPKTS:
 
582
        long_ret = 0;
 
583
        return (unsigned char *) &theBucket.EthData.undersize;
 
584
    case DATA_OVERSIZEPKTS:
 
585
        long_ret = 0;
 
586
        return (unsigned char *) &theBucket.EthData.oversize;
 
587
    case DATA_FRAGMENTS:
 
588
        long_ret = 0;
 
589
        return (unsigned char *) &theBucket.EthData.fragments;
 
590
    case DATA_JABBERS:
 
591
        long_ret = 0;
 
592
        return (unsigned char *) &theBucket.EthData.jabbers;
 
593
    case DATA_COLLISIONS:
 
594
        long_ret = 0;
 
595
        return (unsigned char *) &theBucket.EthData.collisions;
 
596
    case DATA_UTILIZATION:
 
597
        long_ret = 0;
 
598
        return (unsigned char *) &theBucket.utilization;
 
599
    default:
 
600
        ag_trace("etherHistoryTable: unknown vp->magic=%d",
 
601
                 (int) vp->magic);
 
602
        ERROR_MSG("");
 
603
    }
 
604
    return NULL;
 
605
}
 
606
 
 
607
#if 1                           /* debug, but may be used for init. TBD: may be token snmpd.conf ? */
 
608
int
 
609
add_hist_entry(int ctrl_index, int ifIndex,
 
610
               u_long interval, u_long requested)
 
611
{
 
612
    register RMON_ENTRY_T *eptr;
 
613
    register CRTL_ENTRY_T *body;
 
614
    int             ierr;
 
615
 
 
616
    ierr = ROWAPI_new(table_ptr, ctrl_index);
 
617
    if (ierr) {
 
618
        ag_trace("ROWAPI_new failed with %d", ierr);
 
619
        return ierr;
 
620
    }
 
621
 
 
622
    eptr = ROWAPI_find(table_ptr, ctrl_index);
 
623
    if (!eptr) {
 
624
        ag_trace("ROWAPI_find failed");
 
625
        return -4;
 
626
    }
 
627
 
 
628
    body = (CRTL_ENTRY_T *) eptr->body;
 
629
 
 
630
    /*
 
631
     * set parameters 
 
632
     */
 
633
 
 
634
    body->data_source.objid[body->data_source.length - 1] = ifIndex;
 
635
    body->interval = interval;
 
636
    body->scrlr.data_requested = requested;
 
637
 
 
638
    eptr->new_status = RMON1_ENTRY_VALID;
 
639
    ierr = ROWAPI_commit(table_ptr, ctrl_index);
 
640
    if (ierr) {
 
641
        ag_trace("ROWAPI_commit failed with %d", ierr);
 
642
    }
 
643
 
 
644
    return ierr;
 
645
 
 
646
}
 
647
 
 
648
#endif
 
649
 
 
650
/*
 
651
 * Registration & Initializatio section 
 
652
 */
 
653
 
 
654
oid             historyControlTable_variables_oid[] =
 
655
    { 1, 3, 6, 1, 2, 1, 16, 2, 1 };
 
656
 
 
657
struct variable2 historyControlTable_variables[] = {
 
658
    /*
 
659
     * magic number        , variable type, ro/rw , callback fn  ,           L, oidsuffix 
 
660
     */
 
661
    {CTRL_INDEX, ASN_INTEGER, RONLY, var_historyControlTable, 2, {1, 1}},
 
662
    {CTRL_DATASOURCE, ASN_OBJECT_ID, RWRITE, var_historyControlTable, 2,
 
663
     {1, 2}},
 
664
    {CTRL_BUCKETSREQUESTED, ASN_INTEGER, RWRITE, var_historyControlTable,
 
665
     2, {1, 3}},
 
666
    {CTRL_BUCKETSGRANTED, ASN_INTEGER, RONLY, var_historyControlTable, 2,
 
667
     {1, 4}},
 
668
    {CTRL_INTERVAL, ASN_INTEGER, RWRITE, var_historyControlTable, 2,
 
669
     {1, 5}},
 
670
    {CTRL_OWNER, ASN_OCTET_STR, RWRITE, var_historyControlTable, 2,
 
671
     {1, 6}},
 
672
    {CTRL_STATUS, ASN_INTEGER, RWRITE, var_historyControlTable, 2, {1, 7}},
 
673
 
 
674
};
 
675
 
 
676
oid             etherHistoryTable_variables_oid[] =
 
677
    { 1, 3, 6, 1, 2, 1, 16, 2, 2 };
 
678
 
 
679
struct variable2 etherHistoryTable_variables[] = {
 
680
    /*
 
681
     * magic number     , variable type , ro/rw , callback fn  ,        L, oidsuffix 
 
682
     */
 
683
    {DATA_INDEX, ASN_INTEGER, RONLY, var_etherHistoryTable, 2, {1, 1}},
 
684
    {DATA_SAMPLEINDEX, ASN_INTEGER, RONLY, var_etherHistoryTable, 2,
 
685
     {1, 2}},
 
686
    {DATA_INTERVALSTART, ASN_TIMETICKS, RONLY, var_etherHistoryTable, 2,
 
687
     {1, 3}},
 
688
    {DATA_DROPEVENTS, ASN_COUNTER, RONLY, var_etherHistoryTable, 2,
 
689
     {1, 4}},
 
690
    {DATA_OCTETS, ASN_COUNTER, RONLY, var_etherHistoryTable, 2, {1, 5}},
 
691
    {DATA_PKTS, ASN_COUNTER, RONLY, var_etherHistoryTable, 2, {1, 6}},
 
692
    {DATA_BROADCASTPKTS, ASN_COUNTER, RONLY, var_etherHistoryTable, 2,
 
693
     {1, 7}},
 
694
    {DATA_MULTICASTPKTS, ASN_COUNTER, RONLY, var_etherHistoryTable, 2,
 
695
     {1, 8}},
 
696
    {DATA_CRCALIGNERRORS, ASN_COUNTER, RONLY, var_etherHistoryTable, 2,
 
697
     {1, 9}},
 
698
    {DATA_UNDERSIZEPKTS, ASN_COUNTER, RONLY, var_etherHistoryTable, 2,
 
699
     {1, 10}},
 
700
    {DATA_OVERSIZEPKTS, ASN_COUNTER, RONLY, var_etherHistoryTable, 2,
 
701
     {1, 11}},
 
702
    {DATA_FRAGMENTS, ASN_COUNTER, RONLY, var_etherHistoryTable, 2,
 
703
     {1, 12}},
 
704
    {DATA_JABBERS, ASN_COUNTER, RONLY, var_etherHistoryTable, 2, {1, 13}},
 
705
    {DATA_COLLISIONS, ASN_COUNTER, RONLY, var_etherHistoryTable, 2,
 
706
     {1, 14}},
 
707
    {DATA_UTILIZATION, ASN_INTEGER, RONLY, var_etherHistoryTable, 2,
 
708
     {1, 15}},
 
709
 
 
710
};
 
711
 
 
712
void
 
713
init_history(void)
 
714
{
 
715
    REGISTER_MIB("historyControlTable", historyControlTable_variables,
 
716
                 variable2, historyControlTable_variables_oid);
 
717
    REGISTER_MIB("etherHistoryTable", etherHistoryTable_variables,
 
718
                 variable2, etherHistoryTable_variables_oid);
 
719
 
 
720
    ROWAPI_init_table(&HistoryCtrlTable, "History", 0, &history_Create, NULL,   /* &history_Clone, */
 
721
                      NULL,     /* &history_Delete, */
 
722
                      &history_Validate,
 
723
                      &history_Activate,
 
724
                      &history_Deactivate, &history_Copy);
 
725
 
 
726
    /*
 
727
     * add_hist_entry (2, 3, 4, 2); 
 
728
     */
 
729
}