~ubuntu-branches/debian/lenny/net-snmp/lenny

« back to all changes in this revision

Viewing changes to agent/mibgroup/if-mib/ifTable/ifTable_interface.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-05-10 22:20:23 UTC
  • Revision ID: james.westby@ubuntu.com-20070510222023-3fr07xb9i17xvq32
Tags: upstream-5.3.1
ImportĀ upstreamĀ versionĀ 5.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Note: this file originally auto-generated by mib2c using
3
 
 *       version : 1.42 $ of : mfd-interface.m2c,v $ 
 
3
 *       version : 1.67 $ of : mfd-interface.m2c,v $ 
4
4
 *
5
 
 * $Id: ifTable_interface.c,v 1.8.2.5 2006/06/23 12:41:04 tanders Exp $
 
5
 * $Id: ifTable_interface.c,v 1.16.2.2 2006/02/10 22:58:26 rstory Exp $
6
6
 */
7
7
/*
8
8
 * *********************************************************************
39
39
#include "ifTable.h"
40
40
 
41
41
 
 
42
#include <net-snmp/agent/table_container.h>
42
43
#include <net-snmp/library/container.h>
43
44
 
44
45
#include "ifTable_interface.h"
45
46
 
 
47
#include <ctype.h>
 
48
 
46
49
/**********************************************************************
47
50
 **********************************************************************
48
51
 ***
51
54
 **********************************************************************
52
55
 **********************************************************************/
53
56
/*
54
 
 * ifTable is subid 2 of interfaces.
 
57
 * IF-MIB::ifTable is subid 2 of interfaces.
55
58
 * Its status is Current.
56
59
 * OID: .1.3.6.1.2.1.2.2, length: 8
57
60
 */
58
61
typedef struct ifTable_interface_ctx_s {
59
62
 
60
63
    netsnmp_container *container;
61
 
    netsnmp_cache  *cache;      /* optional cache */
 
64
    netsnmp_cache  *cache;
62
65
 
63
 
    ifTable_registration_ptr user_ctx;
 
66
    ifTable_registration *user_ctx;
64
67
 
65
68
    netsnmp_table_registration_info tbl_info;
66
69
 
67
70
    netsnmp_baby_steps_access_methods access_multiplexer;
68
71
 
 
72
    u_int           table_dirty;
 
73
 
 
74
    u_long          last_changed;
 
75
 
69
76
} ifTable_interface_ctx;
70
77
 
71
78
static ifTable_interface_ctx ifTable_if_ctx;
72
79
 
73
80
static void     _ifTable_container_init(ifTable_interface_ctx * if_ctx);
74
 
 
75
 
 
 
81
static void     _ifTable_container_shutdown(ifTable_interface_ctx *
 
82
                                            if_ctx);
 
83
 
 
84
 
 
85
netsnmp_container *
 
86
ifTable_container_get(void)
 
87
{
 
88
    return ifTable_if_ctx.container;
 
89
}
 
90
 
 
91
ifTable_registration *
 
92
ifTable_registration_get(void)
 
93
{
 
94
    return ifTable_if_ctx.user_ctx;
 
95
}
 
96
 
 
97
ifTable_registration *
 
98
ifTable_registration_set(ifTable_registration * newreg)
 
99
{
 
100
    ifTable_registration *old = ifTable_if_ctx.user_ctx;
 
101
    ifTable_if_ctx.user_ctx = newreg;
 
102
    return old;
 
103
}
 
104
 
 
105
int
 
106
ifTable_container_size(void)
 
107
{
 
108
    return CONTAINER_SIZE(ifTable_if_ctx.container);
 
109
}
 
110
 
 
111
u_int
 
112
ifTable_dirty_get(void)
 
113
{
 
114
    return ifTable_if_ctx.table_dirty;
 
115
}
 
116
 
 
117
void
 
118
ifTable_dirty_set(u_int status)
 
119
{
 
120
    DEBUGMSGTL(("ifTable:ifTable_dirty_set",
 
121
                "called. was %d, now %d\n",
 
122
                ifTable_if_ctx.table_dirty, status));
 
123
    ifTable_if_ctx.table_dirty = status;
 
124
}
 
125
 
 
126
/*
 
127
 * ifTableLastChanged, which is not the last time that a row in
 
128
 * the table was changed, but rather is the last time a row was
 
129
 * added/deleted from the table.
 
130
 */
 
131
void
 
132
ifTable_lastChange_set(u_long table_changed)
 
133
{
 
134
    DEBUGMSGTL(("ifTable:ifTable_lastChanged_set",
 
135
                "called. was %ld, now %ld\n",
 
136
                ifTable_if_ctx.last_changed, table_changed));
 
137
    ifTable_if_ctx.last_changed = table_changed;
 
138
}
 
139
 
 
140
/*
 
141
 * mfd multiplexer modes
 
142
 */
76
143
static Netsnmp_Node_Handler _mfd_ifTable_pre_request;
77
144
static Netsnmp_Node_Handler _mfd_ifTable_post_request;
78
145
static Netsnmp_Node_Handler _mfd_ifTable_object_lookup;
84
151
static Netsnmp_Node_Handler _mfd_ifTable_undo_values;
85
152
static Netsnmp_Node_Handler _mfd_ifTable_commit;
86
153
static Netsnmp_Node_Handler _mfd_ifTable_undo_commit;
 
154
static Netsnmp_Node_Handler _mfd_ifTable_irreversible_commit;
87
155
static Netsnmp_Node_Handler _mfd_ifTable_check_dependencies;
88
156
 
89
157
NETSNMP_STATIC_INLINE int _ifTable_undo_column(ifTable_rowreq_ctx *
99
167
void
100
168
if_mib_container_init(void)
101
169
{
102
 
    static int done = 0;
 
170
    static int      done = 0;
103
171
 
104
172
    if (done)
105
173
        return;
121
189
 *    (Define its contents and how it's structured)
122
190
 */
123
191
void
124
 
_ifTable_initialize_interface(ifTable_registration_ptr reg_ptr,
125
 
                              u_long flags)
 
192
_ifTable_initialize_interface(ifTable_registration * reg_ptr, u_long flags)
126
193
{
127
194
    netsnmp_baby_steps_access_methods *access_multiplexer =
128
195
        &ifTable_if_ctx.access_multiplexer;
136
203
 
137
204
    (void) if_mib_container_init();
138
205
    if (NULL == ifTable_if_ctx.container)
139
 
        return; /* msg already logged */
 
206
        return;                 /* msg already logged */
140
207
 
141
 
#ifdef NETSNMP_ENABLE_MFD_REWRITES
 
208
#ifndef USING_MIBII_INTERFACES_MODULE
142
209
    /*************************************************
143
210
     *
144
211
     * save interface context for ifTable
194
261
     */
195
262
    access_multiplexer->commit = _mfd_ifTable_commit;
196
263
    access_multiplexer->undo_commit = _mfd_ifTable_undo_commit;
 
264
    access_multiplexer->irreversible_commit =
 
265
        _mfd_ifTable_irreversible_commit;
197
266
 
198
267
    /*
199
268
     * REQUIRED for tables with dependencies
287
356
     * register table
288
357
     */
289
358
    netsnmp_register_table(reginfo, tbl_info);
290
 
#endif                          /* NETSNMP_ENABLE_MFD_REWRITES */
 
359
 
 
360
 
 
361
    /*
 
362
     * register ifTableLastChanged
 
363
     */
 
364
    {
 
365
        oid             iftlc_oid[] = { IFTABLE_LAST_CHANGE };
 
366
        netsnmp_register_watched_scalar(netsnmp_create_handler_registration
 
367
                                        ("ifTableLastChanged", NULL,
 
368
                                         iftlc_oid, OID_LENGTH(iftlc_oid),
 
369
                                         HANDLER_CAN_RONLY),
 
370
                                        netsnmp_create_watcher_info((void
 
371
                                                                     *)
 
372
                                                                    &ifTable_if_ctx.
 
373
                                                                    last_changed,
 
374
                                                                    sizeof
 
375
                                                                    (u_long),
 
376
                                                                    ASN_TIMETICKS,
 
377
                                                                    WATCHER_FIXED_SIZE));
 
378
    }
 
379
#endif                          /* USING_MIBII_INTERFACES_MODULE */
 
380
 
291
381
}                               /* _ifTable_initialize_interface */
292
382
 
 
383
/**
 
384
 * @internal
 
385
 * Shutdown the table ifTable
 
386
 */
 
387
void
 
388
_ifTable_shutdown_interface(ifTable_registration * reg_ptr)
 
389
{
 
390
    /*
 
391
     * shutdown the container
 
392
     */
 
393
    _ifTable_container_shutdown(&ifTable_if_ctx);
 
394
}
 
395
 
293
396
void
294
397
ifTable_valid_columns_set(netsnmp_column_info *vc)
295
398
{
402
505
 
403
506
 
404
507
/*
405
 
 * ---------------------------------------------------------------------
406
 
 * * TODO:200:r: Implement ifTable data context functions.
407
 
 */
408
 
/*
409
508
 * ifTable_allocate_data
410
509
 *
411
510
 * Purpose: create new ifTable_data.
413
512
ifTable_data   *
414
513
ifTable_allocate_data(void)
415
514
{
416
 
    /*
417
 
     * TODO:201:r: |-> allocate memory for the ifTable data context.
418
 
     */
419
515
    ifTable_data   *rtn = SNMP_MALLOC_TYPEDEF(ifTable_data);
420
516
 
421
517
    DEBUGMSGTL(("verbose:ifTable:ifTable_allocate_data", "called\n"));
438
534
{
439
535
    DEBUGMSGTL(("verbose:ifTable:ifTable_release_data", "called\n"));
440
536
 
441
 
    /*
442
 
     * TODO:202:r: |-> release memory for the ifTable data context.
443
 
     */
444
537
    free(data);
445
538
}                               /* ifTable_release_data */
446
539
 
466
559
    rowreq_ctx->oid_idx.oids = rowreq_ctx->oid_tmp;
467
560
 
468
561
    rowreq_ctx->ifTable_data_list = NULL;
469
 
    rowreq_ctx->ifTable_reg = ifTable_if_ctx.user_ctx;
470
562
 
471
 
    if (SNMPERR_SUCCESS !=
472
 
        ifTable_rowreq_ctx_init(rowreq_ctx, user_init_ctx)) {
473
 
        ifTable_release_rowreq_ctx(rowreq_ctx);
474
 
        rowreq_ctx = NULL;
 
563
    /*
 
564
     * if we allocated data, call init routine
 
565
     */
 
566
    if (!(rowreq_ctx->rowreq_flags & MFD_ROW_DATA_FROM_USER)) {
 
567
        if (SNMPERR_SUCCESS !=
 
568
            ifTable_rowreq_ctx_init(rowreq_ctx, user_init_ctx)) {
 
569
            ifTable_release_rowreq_ctx(rowreq_ctx);
 
570
            rowreq_ctx = NULL;
 
571
        }
475
572
    }
476
573
 
477
574
    return rowreq_ctx;
515
612
                         netsnmp_agent_request_info *agtreq_info,
516
613
                         netsnmp_request_info *requests)
517
614
{
518
 
    int             rc = ifTable_pre_request(ifTable_if_ctx.user_ctx);
 
615
    int             rc;
 
616
 
 
617
    DEBUGMSGTL(("internal:ifTable:_mfd_ifTable_pre_request", "called\n"));
 
618
 
 
619
    if (1 != netsnmp_row_merge_status_first(reginfo, agtreq_info)) {
 
620
        DEBUGMSGTL(("internal:ifTable",
 
621
                    "skipping additional pre_request\n"));
 
622
        return SNMP_ERR_NOERROR;
 
623
    }
 
624
 
 
625
    rc = ifTable_pre_request(ifTable_if_ctx.user_ctx);
519
626
    if (MFD_SUCCESS != rc) {
520
627
        /*
521
628
         * nothing we can do about it but log it
522
629
         */
523
 
        DEBUGMSGTL(("internal:ifTable", "error %d from "
 
630
        DEBUGMSGTL(("ifTable", "error %d from "
524
631
                    "ifTable_pre_request\n", rc));
525
632
        netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));
526
633
    }
538
645
                          netsnmp_agent_request_info *agtreq_info,
539
646
                          netsnmp_request_info *requests)
540
647
{
541
 
    ifTable_rowreq_ctx *rowreq_ctx;
542
 
    int             rc = ifTable_post_request(ifTable_if_ctx.user_ctx);
 
648
    ifTable_rowreq_ctx *rowreq_ctx =
 
649
        netsnmp_container_table_row_extract(requests);
 
650
    int             rc, packet_rc;
 
651
 
 
652
    DEBUGMSGTL(("internal:ifTable:_mfd_ifTable_post_request", "called\n"));
 
653
 
 
654
    /*
 
655
     * release row context, if deleted
 
656
     */
 
657
    if (rowreq_ctx && (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED))
 
658
        ifTable_release_rowreq_ctx(rowreq_ctx);
 
659
 
 
660
    /*
 
661
     * wait for last call before calling user
 
662
     */
 
663
    if (1 != netsnmp_row_merge_status_last(reginfo, agtreq_info)) {
 
664
        DEBUGMSGTL(("internal:ifTable",
 
665
                    "waiting for last post_request\n"));
 
666
        return SNMP_ERR_NOERROR;
 
667
    }
 
668
 
 
669
    packet_rc = netsnmp_check_all_requests_error(agtreq_info->asp, 0);
 
670
    if ((MFD_SUCCESS != packet_rc) && ifTable_dirty_get()) {
 
671
        /*
 
672
         * we shouldn't get here. the undo steps should also clear
 
673
         * the dirty flags.
 
674
         */
 
675
        snmp_log(LOG_WARNING, "ifTable dirty flag set in post_request "
 
676
                 "but status != SUCCESS.\n");
 
677
    }
 
678
 
 
679
    rc = ifTable_post_request(ifTable_if_ctx.user_ctx, packet_rc);
543
680
    if (MFD_SUCCESS != rc) {
544
681
        /*
545
682
         * nothing we can do about it but log it
546
683
         */
547
 
        DEBUGMSGTL(("internal:ifTable", "error %d from "
 
684
        DEBUGMSGTL(("ifTable", "error %d from "
548
685
                    "ifTable_post_request\n", rc));
549
686
    }
550
687
 
551
 
    /*
552
 
     * if it was set, clear row created flag.
553
 
     */
554
 
    rowreq_ctx = netsnmp_container_table_row_extract(requests);
555
 
    if ((NULL != rowreq_ctx)
556
 
        && (rowreq_ctx->rowreq_flags & MFD_ROW_CREATED))
557
 
        rowreq_ctx->rowreq_flags &= ~MFD_ROW_CREATED;
558
 
 
559
688
    return SNMP_ERR_NOERROR;
560
689
}                               /* _mfd_ifTable_post_request */
561
690
 
569
698
                           netsnmp_agent_request_info *agtreq_info,
570
699
                           netsnmp_request_info *requests)
571
700
{
 
701
    int             rc = SNMP_ERR_NOERROR;
572
702
    ifTable_rowreq_ctx *rowreq_ctx =
573
703
        netsnmp_container_table_row_extract(requests);
574
704
 
582
712
     */
583
713
 
584
714
    if (NULL == rowreq_ctx) {
585
 
        netsnmp_request_set_error_all(requests, SNMP_ERR_NOCREATION);
586
 
    } else {
 
715
        rc = SNMP_ERR_NOCREATION;
 
716
    }
 
717
 
 
718
    if (MFD_SUCCESS != rc)
 
719
        netsnmp_request_set_error_all(requests, rc);
 
720
    else
587
721
        ifTable_row_prep(rowreq_ctx);
588
 
    }
589
722
 
590
 
    return SNMP_ERR_NOERROR;
 
723
    return SNMP_VALIDATE_ERR(rc);
591
724
}                               /* _mfd_ifTable_object_lookup */
592
725
 
593
726
/***********************************************************************
605
738
{
606
739
    int             rc = SNMPERR_SUCCESS;
607
740
 
608
 
    DEBUGMSGTL(("internal:ifTable:_mfd_ifTable_get_column", "called\n"));
 
741
    DEBUGMSGTL(("internal:ifTable:_mfd_ifTable_get_column",
 
742
                "called for %d\n", column));
609
743
 
610
744
 
611
745
    netsnmp_assert(NULL != rowreq_ctx);
865
999
                                 tri->colnum);
866
1000
        if (rc) {
867
1001
            if (MFD_SKIP == rc) {
868
 
                requests->requestvb->type = ASN_PRIV_RETRY;
 
1002
                requests->requestvb->type = SNMP_NOSUCHINSTANCE;
869
1003
                rc = SNMP_ERR_NOERROR;
870
1004
            }
871
1005
        } else if (NULL == requests->requestvb->val.string) {
892
1026
    return SNMP_ERR_NOERROR;
893
1027
}                               /* _mfd_ifTable_get_values */
894
1028
 
 
1029
 
 
1030
 
 
1031
 
895
1032
/***********************************************************************
896
1033
 *
897
1034
 * SET processing
913
1050
{
914
1051
    int             rc = SNMPERR_SUCCESS;
915
1052
 
916
 
    DEBUGMSGTL(("internal:ifTable:_ifTable_check_column", "called\n"));
 
1053
    DEBUGMSGTL(("internal:ifTable:_ifTable_check_column",
 
1054
                "called for %d\n", column));
917
1055
 
918
1056
    netsnmp_assert(NULL != rowreq_ctx);
919
1057
 
920
1058
    switch (column) {
 
1059
        /*
 
1060
         * (INDEX) ifIndex(1)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/w/e/R/d/H 
 
1061
         */
 
1062
    case COLUMN_IFINDEX:
 
1063
        rc = SNMP_ERR_NOTWRITABLE;      /* can not change index of active row */
 
1064
        break;
 
1065
 
 
1066
        /*
 
1067
         * ifDescr(2)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H 
 
1068
         */
 
1069
    case COLUMN_IFDESCR:
 
1070
        rc = SNMP_ERR_NOTWRITABLE;
 
1071
        break;
 
1072
 
 
1073
        /*
 
1074
         * ifType(3)/IANAifType/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h 
 
1075
         */
 
1076
    case COLUMN_IFTYPE:
 
1077
        rc = SNMP_ERR_NOTWRITABLE;
 
1078
        break;
 
1079
 
 
1080
        /*
 
1081
         * ifMtu(4)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h 
 
1082
         */
 
1083
    case COLUMN_IFMTU:
 
1084
        rc = SNMP_ERR_NOTWRITABLE;
 
1085
        break;
 
1086
 
 
1087
        /*
 
1088
         * ifSpeed(5)/GAUGE/ASN_GAUGE/u_long(u_long)//l/A/w/e/r/d/h 
 
1089
         */
 
1090
    case COLUMN_IFSPEED:
 
1091
        rc = SNMP_ERR_NOTWRITABLE;
 
1092
        break;
 
1093
 
 
1094
        /*
 
1095
         * ifPhysAddress(6)/PhysAddress/ASN_OCTET_STR/char(char)//L/A/w/e/r/d/H 
 
1096
         */
 
1097
    case COLUMN_IFPHYSADDRESS:
 
1098
        rc = SNMP_ERR_NOTWRITABLE;
 
1099
        break;
921
1100
 
922
1101
        /*
923
1102
         * ifAdminStatus(7)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h 
929
1108
         ** will ensure that there is no data overflow. */
930
1109
        rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER,
931
1110
                                            sizeof(u_long));
932
 
        if (SNMPERR_SUCCESS == rc) {
933
 
 
934
 
            /*
935
 
             * check that the value is one of defined enums 
936
 
             */
937
 
            if (1 && (*var->val.integer != IFADMINSTATUS_UP)
938
 
                && (*var->val.integer != IFADMINSTATUS_DOWN)
939
 
                && (*var->val.integer != IFADMINSTATUS_TESTING)
940
 
                ) {
941
 
                rc = SNMP_ERR_WRONGVALUE;
942
 
            }
 
1111
        /*
 
1112
         * check that the value is one of defined enums 
 
1113
         */
 
1114
        if ((SNMPERR_SUCCESS == rc)
 
1115
            && (*var->val.integer != IFADMINSTATUS_UP)
 
1116
            && (*var->val.integer != IFADMINSTATUS_DOWN)
 
1117
            && (*var->val.integer != IFADMINSTATUS_TESTING)
 
1118
            ) {
 
1119
            rc = SNMP_ERR_WRONGVALUE;
943
1120
        }
944
 
        if (SNMPERR_SUCCESS == rc) {
 
1121
        if (SNMPERR_SUCCESS != rc) {
 
1122
            DEBUGMSGTL(("ifTable:_ifTable_check_column:ifAdminStatus",
 
1123
                        "varbind validation failed (eg bad type or size)\n"));
 
1124
        } else {
945
1125
            rc = ifAdminStatus_check_value(rowreq_ctx,
946
1126
                                           *((u_long *) var->val.string));
947
1127
            if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc)
953
1133
        }
954
1134
        break;
955
1135
 
956
 
    default: /** We shouldn't get here */
 
1136
        /*
 
1137
         * ifOperStatus(8)/INTEGER/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h 
 
1138
         */
 
1139
    case COLUMN_IFOPERSTATUS:
 
1140
        rc = SNMP_ERR_NOTWRITABLE;
 
1141
        break;
 
1142
 
 
1143
        /*
 
1144
         * ifLastChange(9)/TICKS/ASN_TIMETICKS/u_long(u_long)//l/A/w/e/r/d/h 
 
1145
         */
 
1146
    case COLUMN_IFLASTCHANGE:
 
1147
        rc = SNMP_ERR_NOTWRITABLE;
 
1148
        break;
 
1149
 
 
1150
        /*
 
1151
         * ifInOctets(10)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h 
 
1152
         */
 
1153
    case COLUMN_IFINOCTETS:
 
1154
        rc = SNMP_ERR_NOTWRITABLE;
 
1155
        break;
 
1156
 
 
1157
        /*
 
1158
         * ifInUcastPkts(11)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h 
 
1159
         */
 
1160
    case COLUMN_IFINUCASTPKTS:
 
1161
        rc = SNMP_ERR_NOTWRITABLE;
 
1162
        break;
 
1163
 
 
1164
        /*
 
1165
         * ifInNUcastPkts(12)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h 
 
1166
         */
 
1167
    case COLUMN_IFINNUCASTPKTS:
 
1168
        rc = SNMP_ERR_NOTWRITABLE;
 
1169
        break;
 
1170
 
 
1171
        /*
 
1172
         * ifInDiscards(13)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h 
 
1173
         */
 
1174
    case COLUMN_IFINDISCARDS:
 
1175
        rc = SNMP_ERR_NOTWRITABLE;
 
1176
        break;
 
1177
 
 
1178
        /*
 
1179
         * ifInErrors(14)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h 
 
1180
         */
 
1181
    case COLUMN_IFINERRORS:
 
1182
        rc = SNMP_ERR_NOTWRITABLE;
 
1183
        break;
 
1184
 
 
1185
        /*
 
1186
         * ifInUnknownProtos(15)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h 
 
1187
         */
 
1188
    case COLUMN_IFINUNKNOWNPROTOS:
 
1189
        rc = SNMP_ERR_NOTWRITABLE;
 
1190
        break;
 
1191
 
 
1192
        /*
 
1193
         * ifOutOctets(16)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h 
 
1194
         */
 
1195
    case COLUMN_IFOUTOCTETS:
 
1196
        rc = SNMP_ERR_NOTWRITABLE;
 
1197
        break;
 
1198
 
 
1199
        /*
 
1200
         * ifOutUcastPkts(17)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h 
 
1201
         */
 
1202
    case COLUMN_IFOUTUCASTPKTS:
 
1203
        rc = SNMP_ERR_NOTWRITABLE;
 
1204
        break;
 
1205
 
 
1206
        /*
 
1207
         * ifOutNUcastPkts(18)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h 
 
1208
         */
 
1209
    case COLUMN_IFOUTNUCASTPKTS:
 
1210
        rc = SNMP_ERR_NOTWRITABLE;
 
1211
        break;
 
1212
 
 
1213
        /*
 
1214
         * ifOutDiscards(19)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h 
 
1215
         */
 
1216
    case COLUMN_IFOUTDISCARDS:
 
1217
        rc = SNMP_ERR_NOTWRITABLE;
 
1218
        break;
 
1219
 
 
1220
        /*
 
1221
         * ifOutErrors(20)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h 
 
1222
         */
 
1223
    case COLUMN_IFOUTERRORS:
 
1224
        rc = SNMP_ERR_NOTWRITABLE;
 
1225
        break;
 
1226
 
 
1227
        /*
 
1228
         * ifOutQLen(21)/GAUGE/ASN_GAUGE/u_long(u_long)//l/A/w/e/r/d/h 
 
1229
         */
 
1230
    case COLUMN_IFOUTQLEN:
 
1231
        rc = SNMP_ERR_NOTWRITABLE;
 
1232
        break;
 
1233
 
 
1234
        /*
 
1235
         * ifSpecific(22)/OBJECTID/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/d/h 
 
1236
         */
 
1237
    case COLUMN_IFSPECIFIC:
 
1238
        rc = SNMP_ERR_NOTWRITABLE;
 
1239
        break;
 
1240
 
 
1241
    default:   /** We shouldn't get here */
957
1242
        rc = SNMP_ERR_GENERR;
958
1243
        snmp_log(LOG_ERR, "unknown column %d in _ifTable_check_column\n",
959
1244
                 column);
999
1284
    return SNMP_ERR_NOERROR;
1000
1285
}                               /* _mfd_ifTable_check_objects */
1001
1286
 
1002
 
 
1003
 
 
1004
1287
/*----------------------------------------------------------------------
1005
1288
 *
1006
1289
 * SET: check dependencies
1026
1309
 
1027
1310
    rc = ifTable_check_dependencies(rowreq_ctx);
1028
1311
    if (rc) {
1029
 
        DEBUGMSGTL(("verbose:ifTable:mfd", "error %d from "
 
1312
        DEBUGMSGTL(("ifTable:mfd", "error %d from "
1030
1313
                    "ifTable_check_dependencies\n", rc));
1031
1314
        netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));
1032
1315
    }
1049
1332
    int             rc = SNMPERR_SUCCESS;
1050
1333
 
1051
1334
    DEBUGMSGTL(("internal:ifTable:_ifTable_undo_setup_column",
1052
 
                "called\n"));
 
1335
                "called for %d\n", column));
1053
1336
 
1054
1337
    netsnmp_assert(NULL != rowreq_ctx);
1055
1338
 
1059
1342
         * ifAdminStatus(7)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h 
1060
1343
         */
1061
1344
    case COLUMN_IFADMINSTATUS:
1062
 
        rowreq_ctx->column_set_flags |= FLAG_IFADMINSTATUS;
 
1345
        rowreq_ctx->column_set_flags |= COLUMN_IFADMINSTATUS_FLAG;
1063
1346
        rc = ifAdminStatus_undo_setup(rowreq_ctx);
1064
1347
        break;
1065
1348
 
1164
1447
     */
1165
1448
    rc = ifTable_undo_setup(rowreq_ctx);
1166
1449
    if (MFD_SUCCESS != rc) {
1167
 
        DEBUGMSGTL(("verbose:ifTable:mfd", "error %d from "
 
1450
        DEBUGMSGTL(("ifTable:mfd", "error %d from "
1168
1451
                    "ifTable_undo_setup\n", rc));
1169
1452
        netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));
1170
1453
    } else {
1182
1465
 
1183
1466
            rc = _ifTable_undo_setup_column(rowreq_ctx, tri->colnum);
1184
1467
            if (MFD_SUCCESS != rc) {
1185
 
                DEBUGMSGTL(("verbose:ifTable:mfd", "error %d from "
 
1468
                DEBUGMSGTL(("ifTable:mfd", "error %d from "
1186
1469
                            "ifTable_undo_setup_column\n", rc));
1187
1470
                netsnmp_set_request_error(agtreq_info, requests,
1188
1471
                                          SNMP_VALIDATE_ERR(rc));
1244
1527
        /*
1245
1528
         * nothing we can do about it but log it
1246
1529
         */
1247
 
        DEBUGMSGTL(("verbose:ifTable:mfd", "error %d from "
 
1530
        DEBUGMSGTL(("ifTable:mfd", "error %d from "
1248
1531
                    "ifTable_undo_cleanup\n", rc));
1249
1532
    }
1250
1533
 
1253
1536
     */
1254
1537
    _mfd_ifTable_undo_setup_release(rowreq_ctx);
1255
1538
 
1256
 
    /*
1257
 
     * clear set flags
1258
 
     */
1259
 
    rowreq_ctx->column_set_flags = 0;
1260
1539
 
1261
1540
    return SNMP_ERR_NOERROR;
1262
1541
}                               /* _mfd_ifTable_undo_cleanup */
1276
1555
{
1277
1556
    int             rc = SNMPERR_SUCCESS;
1278
1557
 
1279
 
    DEBUGMSGTL(("internal:ifTable:_ifTable_set_column", "called\n"));
 
1558
    DEBUGMSGTL(("internal:ifTable:_ifTable_set_column",
 
1559
                "called for %d\n", column));
1280
1560
 
1281
1561
    netsnmp_assert(NULL != rowreq_ctx);
1282
1562
 
1286
1566
         * ifAdminStatus(7)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h 
1287
1567
         */
1288
1568
    case COLUMN_IFADMINSTATUS:
1289
 
        if (var->val_len != sizeof(u_long)) {
1290
 
            rc = SNMP_ERR_WRONGLENGTH;
1291
 
            snmp_log(LOG_ERR,
1292
 
                     "varbind size of %d does not match expected size %d\n",
1293
 
                     var->val_len, sizeof(u_long));
1294
 
            break;
1295
 
        }
1296
 
        rowreq_ctx->column_set_flags |= FLAG_IFADMINSTATUS;
 
1569
        rowreq_ctx->column_set_flags |= COLUMN_IFADMINSTATUS_FLAG;
1297
1570
        rc = ifAdminStatus_set(rowreq_ctx, *((u_long *) var->val.string));
1298
1571
        break;
1299
1572
 
1300
1573
    default:
1301
1574
        snmp_log(LOG_ERR, "unknown column %d in _ifTable_set_column\n",
1302
1575
                 column);
 
1576
        rc = SNMP_ERR_GENERR;
1303
1577
        break;
1304
1578
    }
1305
1579
 
1333
1607
        rc = _ifTable_set_column(rowreq_ctx,
1334
1608
                                 requests->requestvb, tri->colnum);
1335
1609
        if (MFD_SUCCESS != rc) {
1336
 
            DEBUGMSGTL(("verbose:ifTable:mfd", "error %d from "
 
1610
            DEBUGMSGTL(("ifTable:mfd", "error %d from "
1337
1611
                        "ifTable_set_column\n", rc));
1338
1612
            netsnmp_set_request_error(agtreq_info, requests,
1339
1613
                                      SNMP_VALIDATE_ERR(rc));
1368
1642
 
1369
1643
    rc = ifTable_commit(rowreq_ctx);
1370
1644
    if (MFD_SUCCESS != rc) {
1371
 
        DEBUGMSGTL(("verbose:ifTable:mfd", "error %d from "
 
1645
        DEBUGMSGTL(("ifTable:mfd", "error %d from "
1372
1646
                    "ifTable_commit\n", rc));
1373
1647
        netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));
1374
1648
    }
1375
1649
 
 
1650
    if (rowreq_ctx->rowreq_flags & MFD_ROW_DIRTY) {
 
1651
        /*
 
1652
         * if we successfully commited this row, set the dirty flag. Use the
 
1653
         * current value + 1 (i.e. dirty = # rows changed).
 
1654
         * this is checked in post_request...
 
1655
         */
 
1656
        ifTable_dirty_set(ifTable_dirty_get() + 1);     /* set table dirty flag */
 
1657
    }
 
1658
 
 
1659
    if (rowreq_ctx->rowreq_flags & MFD_ROW_DIRTY) {
 
1660
        /*
 
1661
         * if we successfully commited this row, set the dirty flag. Use the
 
1662
         * current value + 1 (i.e. dirty = # rows changed).
 
1663
         * this is checked in post_request...
 
1664
         */
 
1665
        ifTable_dirty_set(ifTable_dirty_get() + 1);     /* set table dirty flag */
 
1666
    }
 
1667
 
1376
1668
    return SNMP_ERR_NOERROR;
1377
1669
}
1378
1670
 
1390
1682
 
1391
1683
    netsnmp_assert(NULL != rowreq_ctx);
1392
1684
 
 
1685
    if (rowreq_ctx->rowreq_flags & MFD_ROW_DIRTY) {
 
1686
        u_int           d = ifTable_dirty_get();
 
1687
 
 
1688
        netsnmp_assert(d != 0);
 
1689
        if (d)
 
1690
            ifTable_dirty_set(d - 1);
 
1691
    }
 
1692
 
1393
1693
    rc = ifTable_undo_commit(rowreq_ctx);
1394
1694
    if (MFD_SUCCESS != rc) {
1395
1695
        /*
1396
1696
         * nothing we can do about it but log it
1397
1697
         */
1398
 
        DEBUGMSGTL(("verbose:ifTable:mfd", "error %d from "
 
1698
        DEBUGMSGTL(("ifTable:mfd", "error %d from "
1399
1699
                    "ifTable_undo_commit\n", rc));
1400
1700
    }
1401
1701
 
 
1702
    if (rowreq_ctx->rowreq_flags & MFD_ROW_DIRTY) {
 
1703
        snmp_log(LOG_WARNING,
 
1704
                 "ifTable row dirty flag still set after undo_commit\n");
 
1705
        rowreq_ctx->rowreq_flags &= ~MFD_ROW_DIRTY;
 
1706
    }
 
1707
 
1402
1708
    return SNMP_ERR_NOERROR;
1403
1709
}                               /* _mfd_ifTable_commit */
1404
1710
 
1417
1723
{
1418
1724
    int             rc = SNMPERR_SUCCESS;
1419
1725
 
1420
 
    DEBUGMSGTL(("internal:ifTable:_ifTable_undo_column", "called\n"));
 
1726
    DEBUGMSGTL(("internal:ifTable:_ifTable_undo_column",
 
1727
                "called for %d\n", column));
1421
1728
 
1422
1729
    netsnmp_assert(NULL != rowreq_ctx);
1423
1730
 
1454
1761
 
1455
1762
    netsnmp_assert(NULL != rowreq_ctx);
1456
1763
 
 
1764
    rc = ifTable_undo(rowreq_ctx);
 
1765
    if (MFD_SUCCESS != rc) {
 
1766
        /*
 
1767
         * nothing we can do about it but log it
 
1768
         */
 
1769
        DEBUGMSGTL(("ifTable:mfd", "error %d from " "ifTable_undo\n", rc));
 
1770
    }
 
1771
 
1457
1772
    for (; requests; requests = requests->next) {
1458
1773
        /*
1459
1774
         * set column data
1468
1783
            /*
1469
1784
             * nothing we can do about it but log it
1470
1785
             */
1471
 
            DEBUGMSGTL(("verbose:ifTable:mfd", "error %d from "
 
1786
            DEBUGMSGTL(("ifTable:mfd", "error %d from "
1472
1787
                        "ifTable_undo_column\n", rc));
1473
1788
        }
1474
1789
    }                           /* for results */
1476
1791
    return SNMP_ERR_NOERROR;
1477
1792
}                               /* _mfd_ifTable_undo_values */
1478
1793
 
 
1794
/*----------------------------------------------------------------------
 
1795
 *
 
1796
 * SET: irreversible commit
 
1797
 *
 
1798
 *---------------------------------------------------------------------*/
 
1799
/**
 
1800
 * @internal
 
1801
 * commit irreversible actions
 
1802
 */
 
1803
int
 
1804
_mfd_ifTable_irreversible_commit(netsnmp_mib_handler *handler,
 
1805
                                 netsnmp_handler_registration *reginfo,
 
1806
                                 netsnmp_agent_request_info *agtreq_info,
 
1807
                                 netsnmp_request_info *requests)
 
1808
{
 
1809
    ifTable_rowreq_ctx *rowreq_ctx =
 
1810
        netsnmp_container_table_row_extract(requests);
 
1811
 
 
1812
    DEBUGMSGTL(("internal:ifTable:_mfd_ifTable_irreversible:commit",
 
1813
                "called\n"));
 
1814
 
 
1815
    netsnmp_assert(NULL != rowreq_ctx);
 
1816
 
 
1817
    /*
 
1818
     * check for and handle row creation/deletion
 
1819
     * and update column exist flags...
 
1820
     */
 
1821
    if (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED) {
 
1822
        CONTAINER_REMOVE(ifTable_if_ctx.container, rowreq_ctx);
 
1823
    } else {
 
1824
        if (rowreq_ctx->column_set_flags) {
 
1825
            rowreq_ctx->column_set_flags = 0;
 
1826
        }
 
1827
    }
 
1828
 
 
1829
    return SNMP_ERR_NOERROR;
 
1830
}                               /* _mfd_ifTable_irreversible_commit */
 
1831
 
1479
1832
/***********************************************************************
1480
1833
 *
1481
1834
 * DATA ACCESS
1482
1835
 *
1483
1836
 ***********************************************************************/
 
1837
static void     _container_free(netsnmp_container *container);
 
1838
 
1484
1839
/**
1485
1840
 * @internal
1486
1841
 */
1500
1855
    /*
1501
1856
     * call user code
1502
1857
     */
1503
 
    return ifTable_cache_load((netsnmp_container *) cache->magic);
 
1858
    return ifTable_container_load((netsnmp_container *) cache->magic);
1504
1859
}                               /* _cache_load */
1505
1860
 
1506
1861
/**
1507
1862
 * @internal
1508
1863
 */
1509
1864
static void
1510
 
_cache_item_free(ifTable_rowreq_ctx * rowreq_ctx, void *context)
1511
 
{
1512
 
    DEBUGMSGTL(("internal:ifTable:_cache_item_free", "called\n"));
1513
 
 
1514
 
    if (NULL == rowreq_ctx)
1515
 
        return;
1516
 
 
1517
 
    ifTable_release_rowreq_ctx(rowreq_ctx);
1518
 
}                               /* _cache_item_free */
1519
 
 
1520
 
/**
1521
 
 * @internal
1522
 
 */
1523
 
static void
1524
1865
_cache_free(netsnmp_cache * cache, void *magic)
1525
1866
{
1526
1867
    netsnmp_container *container;
1534
1875
 
1535
1876
    container = (netsnmp_container *) cache->magic;
1536
1877
 
 
1878
    _container_free(container);
 
1879
}                               /* _cache_free */
 
1880
 
 
1881
/**
 
1882
 * @internal
 
1883
 */
 
1884
static void
 
1885
_container_item_free(ifTable_rowreq_ctx * rowreq_ctx, void *context)
 
1886
{
 
1887
    DEBUGMSGTL(("internal:ifTable:_container_item_free", "called\n"));
 
1888
 
 
1889
    if (NULL == rowreq_ctx)
 
1890
        return;
 
1891
 
 
1892
    ifTable_release_rowreq_ctx(rowreq_ctx);
 
1893
}                               /* _container_item_free */
 
1894
 
 
1895
/**
 
1896
 * @internal
 
1897
 */
 
1898
static void
 
1899
_container_free(netsnmp_container *container)
 
1900
{
 
1901
    DEBUGMSGTL(("internal:ifTable:_container_free", "called\n"));
 
1902
 
 
1903
    if (NULL == container) {
 
1904
        snmp_log(LOG_ERR, "invalid container in ifTable_container_free\n");
 
1905
        return;
 
1906
    }
 
1907
 
1537
1908
    /*
1538
1909
     * call user code
1539
1910
     */
1540
 
    ifTable_cache_free(container);
 
1911
    ifTable_container_free(container);
1541
1912
 
1542
1913
    /*
1543
1914
     * free all items. inefficient, but easy.
1544
1915
     */
1545
1916
    CONTAINER_CLEAR(container,
1546
 
                    (netsnmp_container_obj_func *) _cache_item_free, NULL);
1547
 
}                               /* _cache_free */
 
1917
                    (netsnmp_container_obj_func *) _container_item_free,
 
1918
                    NULL);
 
1919
}                               /* _container_free */
1548
1920
 
1549
1921
/**
1550
1922
 * @internal
1551
 
 * initialize the iterator container with functions or wrappers
 
1923
 * initialize the container with functions or wrappers
1552
1924
 */
1553
1925
void
1554
1926
_ifTable_container_init(ifTable_interface_ctx * if_ctx)
1556
1928
    DEBUGMSGTL(("internal:ifTable:_ifTable_container_init", "called\n"));
1557
1929
 
1558
1930
    /*
1559
 
     * set up the cache
 
1931
     * cache init
1560
1932
     */
1561
1933
    if_ctx->cache = netsnmp_cache_create(30,    /* timeout in seconds */
1562
1934
                                         _cache_load, _cache_free,
1578
1950
                 "ifTable_container_init\n");
1579
1951
        return;
1580
1952
    }
1581
 
    if_ctx->cache->magic = (void *) if_ctx->container;
 
1953
 
 
1954
    if (NULL != if_ctx->cache)
 
1955
        if_ctx->cache->magic = (void *) if_ctx->container;
1582
1956
}                               /* _ifTable_container_init */
 
1957
 
 
1958
/**
 
1959
 * @internal
 
1960
 * shutdown the container with functions or wrappers
 
1961
 */
 
1962
void
 
1963
_ifTable_container_shutdown(ifTable_interface_ctx * if_ctx)
 
1964
{
 
1965
    DEBUGMSGTL(("internal:ifTable:_ifTable_container_shutdown",
 
1966
                "called\n"));
 
1967
 
 
1968
    ifTable_container_shutdown(if_ctx->container);
 
1969
 
 
1970
    _container_free(if_ctx->container);
 
1971
 
 
1972
}                               /* _ifTable_container_shutdown */
 
1973
 
 
1974
 
 
1975
ifTable_rowreq_ctx *
 
1976
ifTable_row_find_by_mib_index(ifTable_mib_index * mib_idx)
 
1977
{
 
1978
    ifTable_rowreq_ctx *rowreq_ctx;
 
1979
    oid             oid_tmp[MAX_OID_LEN];
 
1980
    netsnmp_index   oid_idx;
 
1981
    int             rc;
 
1982
 
 
1983
    /*
 
1984
     * set up storage for OID
 
1985
     */
 
1986
    oid_idx.oids = oid_tmp;
 
1987
    oid_idx.len = sizeof(oid_tmp) / sizeof(oid);
 
1988
 
 
1989
    /*
 
1990
     * convert
 
1991
     */
 
1992
    rc = ifTable_index_to_oid(&oid_idx, mib_idx);
 
1993
    if (MFD_SUCCESS != rc)
 
1994
        return NULL;
 
1995
 
 
1996
    rowreq_ctx = CONTAINER_FIND(ifTable_if_ctx.container, &oid_idx);
 
1997
 
 
1998
    return rowreq_ctx;
 
1999
}