~ubuntu-branches/ubuntu/trusty/net-snmp/trusty

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-05-10 22:20:23 UTC
  • mto: (1.4.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 11.
  • 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.32 $ of : mfd-top.m2c,v $ 
 
3
 *       version : 1.48 $ of : mfd-top.m2c,v $ 
4
4
 *
5
 
 * $Id: ifTable.c,v 1.17.2.3 2006/01/15 14:07:01 rstory Exp $
 
5
 * $Id: ifTable.c,v 1.22.2.5 2006/02/14 14:40:55 dts12 Exp $
6
6
 */
7
 
/** \mainpage MFD helper for ifTable
 
7
/** \page MFD helper for ifTable
8
8
 *
9
9
 * \section intro Introduction
10
10
 * Introductory text.
26
26
 
27
27
#include "ifTable_interface.h"
28
28
 
 
29
#ifdef USING_IP_MIB_IPV4INTERFACETABLE_IPV4INTERFACETABLE_MODULE
 
30
#   include "ip-mib/ipv4InterfaceTable/ipv4InterfaceTable.h"
 
31
#endif
 
32
#ifdef USING_IP_MIB_IPV6INTERFACETABLE_IPV6INTERFACETABLE_MODULE
 
33
#   include "ip-mib/ipv4InterfaceTable/ipv4InterfaceTable.h"
 
34
#endif
 
35
#ifdef USING_IF_MIB_IFXTABLE_IFXTABLE_MODULE
 
36
#   include "if-mib/ifXTable/ifXTable.h"
 
37
#endif
 
38
 
29
39
oid             ifTable_oid[] = { IFTABLE_OID };
30
40
int             ifTable_oid_size = OID_LENGTH(ifTable_oid);
31
41
 
 
42
ifTable_registration ifTable_user_context;
 
43
 
32
44
void            initialize_table_ifTable(void);
 
45
void            shutdown_table_ifTable(void);
 
46
 
 
47
static int
 
48
_if_number_handler(netsnmp_mib_handler *handler,
 
49
                   netsnmp_handler_registration *reginfo,
 
50
                   netsnmp_agent_request_info *reqinfo,
 
51
                   netsnmp_request_info *requests);
33
52
 
34
53
 
35
54
/**
38
57
void
39
58
init_ifTable(void)
40
59
{
 
60
    static int      ifTable_did_init = 0;
 
61
 
41
62
    DEBUGMSGTL(("verbose:ifTable:init_ifTable", "called\n"));
42
63
 
43
64
    /*
44
65
     * TODO:300:o: Perform ifTable one-time module initialization.
45
66
     */
 
67
    if (++ifTable_did_init != 1) {
 
68
        DEBUGMSGTL(("ifTable:init_ifTable", "ignoring duplicate call\n"));
 
69
        return;
 
70
    }
46
71
 
47
72
    /*
48
73
     * here we initialize all the tables we're planning on supporting
49
74
     */
50
 
    if (should_init("ifTable"))
 
75
    if (should_init("ifTable")) {
 
76
 
 
77
#ifdef USING_IP_MIB_IPV4INTERFACETABLE_IPV4INTERFACETABLE_MODULE
 
78
        if (should_init("ipv4InterfaceTable"))
 
79
            initialize_table_ipv4InterfaceTable();
 
80
#endif
 
81
 
 
82
#ifdef USING_IP_MIB_IPV6INTERFACETABLE_IPV6INTERFACETABLE_MODULE
 
83
        if (should_init("ipv6InterfaceTable"))
 
84
            initialize_table_ipv6InterfaceTable();
 
85
#endif
 
86
 
51
87
        initialize_table_ifTable();
52
88
 
 
89
#ifdef USING_IF_MIB_IFXTABLE_IFXTABLE_MODULE
 
90
        if (should_init("ifXTable"))
 
91
            initialize_table_ifXTable();
 
92
#endif
 
93
    }
53
94
}                               /* init_ifTable */
54
95
 
55
96
/**
 
97
 * Shut-down the ifTable module (agent is exiting)
 
98
 */
 
99
void
 
100
shutdown_ifTable(void)
 
101
{
 
102
    if (should_init("ifTable"))
 
103
        shutdown_table_ifTable();
 
104
 
 
105
}
 
106
 
 
107
/**
56
108
 * Initialize the table ifTable 
57
109
 *    (Define its contents and how it's structured)
58
110
 */
59
111
void
60
112
initialize_table_ifTable(void)
61
113
{
62
 
    ifTable_registration_ptr user_context;
 
114
    ifTable_registration *user_context;
63
115
    u_long          flags;
64
116
 
65
117
    DEBUGMSGTL(("verbose:ifTable:initialize_table_ifTable", "called\n"));
89
141
     * call interface initialization code
90
142
     */
91
143
    _ifTable_initialize_interface(user_context, flags);
 
144
 
 
145
    /*
 
146
     * register scalar for ifNumber
 
147
     */
 
148
    {
 
149
        oid             reg_oid[] =
 
150
            { IFTABLE_NUMBER };
 
151
        netsnmp_handler_registration *myreg;
 
152
 
 
153
        myreg =
 
154
            netsnmp_create_handler_registration("if number",
 
155
                                                _if_number_handler,
 
156
                                                reg_oid,
 
157
                                                OID_LENGTH(reg_oid),
 
158
                                                HANDLER_CAN_RONLY);
 
159
        netsnmp_register_scalar(myreg);
 
160
    }
 
161
 
92
162
}                               /* initialize_table_ifTable */
93
163
 
94
164
/**
95
 
 * extra context initialization
 
165
 * Shutdown the table ifTable
 
166
 */
 
167
void
 
168
shutdown_table_ifTable(void)
 
169
{
 
170
    /*
 
171
     * call interface shutdown code
 
172
     */
 
173
    _ifTable_shutdown_interface(&ifTable_user_context);
 
174
}
 
175
 
 
176
/**
 
177
 * extra context initialization (eg default values)
96
178
 *
97
179
 * @param rowreq_ctx    : row request context
98
180
 * @param user_init_ctx : void pointer for user (parameter to rowreq_ctx_allocate)
109
191
    netsnmp_assert(NULL != rowreq_ctx);
110
192
 
111
193
    /*
112
 
     * TODO:210:o: |-> Perform extra ifTable rowreq initialization.
 
194
     * TODO:210:o: |-> Perform extra ifTable rowreq initialization. (eg DEFVALS)
113
195
     */
114
196
    if (NULL == user_init_ctx)
115
197
        rowreq_ctx->data.ifentry =
116
 
            netsnmp_access_interface_entry_create(NULL,0);
 
198
            netsnmp_access_interface_entry_create(NULL, 0);
117
199
    else
118
200
        rowreq_ctx->data.ifentry =
119
201
            (netsnmp_interface_entry *) user_init_ctx;
123
205
 
124
206
/**
125
207
 * extra context cleanup
126
 
 *
 
208
 * @param rowreq_ctx
127
209
 */
128
210
void
129
211
ifTable_rowreq_ctx_cleanup(ifTable_rowreq_ctx * rowreq_ctx)
143
225
 
144
226
/**
145
227
 * pre-request callback
 
228
 * @param  user_context
146
229
 *
147
230
 *
148
231
 * @retval MFD_SUCCESS              : success.
149
232
 * @retval MFD_ERROR                : other error
150
233
 */
151
234
int
152
 
ifTable_pre_request(ifTable_registration_ptr user_context)
 
235
ifTable_pre_request(ifTable_registration * user_context)
153
236
{
154
237
    DEBUGMSGTL(("verbose:ifTable:ifTable_pre_request", "called\n"));
155
238
 
163
246
/**
164
247
 * post-request callback
165
248
 *
 
249
 * Note:
 
250
 *   New rows have been inserted into the container, and
 
251
 *   deleted rows have been removed from the container and
 
252
 *   released.
 
253
 *
 
254
 * @param user_context
 
255
 * @param rc : MFD_SUCCESS if all requests succeeded
166
256
 *
167
257
 * @retval MFD_SUCCESS : success.
168
258
 * @retval MFD_ERROR   : other error (ignored)
169
259
 */
170
260
int
171
 
ifTable_post_request(ifTable_registration_ptr user_context)
 
261
ifTable_post_request(ifTable_registration * user_context, int rc)
172
262
{
173
263
    DEBUGMSGTL(("verbose:ifTable:ifTable_post_request", "called\n"));
174
264
 
175
265
    /*
176
 
     * TODO:511:o: Perform ifTable pos-request actions.
177
 
     */
 
266
     * TODO:511:o: Perform ifTable post-request actions.
 
267
     */
 
268
 
 
269
    /*
 
270
     * check to set if any rows were changed.
 
271
     */
 
272
    if (ifTable_dirty_get()) {
 
273
        /*
 
274
         * check if request was successful. If so, this would be
 
275
         * a good place to save data to its persistent store.
 
276
         */
 
277
        if (MFD_SUCCESS == rc) {
 
278
            /*
 
279
             * save changed rows, if you haven't already
 
280
             */
 
281
            snmp_store(netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID,
 
282
                                             NETSNMP_DS_LIB_APPTYPE));
 
283
        }
 
284
 
 
285
        ifTable_dirty_set(0);   /* clear table dirty flag */
 
286
    }
178
287
 
179
288
    return MFD_SUCCESS;
180
289
}                               /* ifTable_post_request */
188
297
 **********************************************************************
189
298
 **********************************************************************/
190
299
/*
191
 
 * ifTable is subid 2 of interfaces.
 
300
 * IF-MIB::ifTable is subid 2 of interfaces.
192
301
 * Its status is Current.
193
302
 * OID: .1.3.6.1.2.1.2.2, length: 8
194
303
 */
195
304
 
 
305
/*
 
306
 * ---------------------------------------------------------------------
 
307
 * * TODO:200:r: Implement ifTable data context functions.
 
308
 */
196
309
 
197
310
 
198
311
/**
199
312
 * set mib index(es)
200
313
 *
201
314
 * @param tbl_idx mib index structure
 
315
 * @param ifIndex_val
202
316
 *
203
317
 * @retval MFD_SUCCESS     : success.
204
318
 * @retval MFD_ERROR       : other error.
228
342
 * set row context indexes
229
343
 *
230
344
 * @param reqreq_ctx the row context that needs updated indexes
 
345
 * @param ifIndex_val
231
346
 *
232
347
 * @retval MFD_SUCCESS     : success.
233
348
 * @retval MFD_ERROR       : other error.
311
426
 */
312
427
int
313
428
ifDescr_get(ifTable_rowreq_ctx * rowreq_ctx, char **ifDescr_val_ptr_ptr,
314
 
            size_t *ifDescr_val_ptr_len_ptr)
 
429
            size_t * ifDescr_val_ptr_len_ptr)
315
430
{
316
431
    char           *tmp_descr = NULL;
317
432
    u_char          tmp_len = 0;
345
460
 
346
461
    /*
347
462
     * TODO:231:o: |-> Extract the current value of the ifDescr data.
348
 
     * set (* ifDescr_val_ptr_ptr ) and (* ifDescr_val_ptr_len_ptr ) from rowreq_ctx->data
 
463
     * copy (* ifDescr_val_ptr_ptr ) data and (* ifDescr_val_ptr_len_ptr ) from rowreq_ctx->data
349
464
     */
350
465
    /*
351
466
     * make sure there is enough space for ifDescr data
352
467
     */
353
 
    if ((NULL == (*ifDescr_val_ptr_ptr))
354
 
        || ((*ifDescr_val_ptr_len_ptr) < tmp_len)) {
 
468
    if ((NULL == (*ifDescr_val_ptr_ptr)) ||
 
469
        ((*ifDescr_val_ptr_len_ptr) < tmp_len)) {
355
470
        /*
356
471
         * allocate space for ifDescr data
357
472
         */
358
473
        (*ifDescr_val_ptr_ptr) =
359
 
            malloc(tmp_len * sizeof((*ifDescr_val_ptr_ptr)[0]));
 
474
            malloc(tmp_len * sizeof(rowreq_ctx->data.ifDescr[0]));
360
475
        if (NULL == (*ifDescr_val_ptr_ptr)) {
361
476
            snmp_log(LOG_ERR, "could not allocate memory\n");
362
477
            return MFD_ERROR;
363
478
        }
364
479
    }
365
 
    (*ifDescr_val_ptr_len_ptr) = tmp_len;
366
 
    memcpy((*ifDescr_val_ptr_ptr), tmp_descr,
367
 
           (*ifDescr_val_ptr_len_ptr) * sizeof((*ifDescr_val_ptr_ptr)[0]));
 
480
    (*ifDescr_val_ptr_len_ptr) =
 
481
        tmp_len * sizeof(rowreq_ctx->data.ifDescr[0]);
 
482
    memcpy((*ifDescr_val_ptr_ptr), tmp_descr, (*ifDescr_val_ptr_len_ptr));
368
483
 
369
484
    return MFD_SUCCESS;
370
485
}                               /* ifDescr_get */
417
532
 
418
533
    /*
419
534
     * TODO:231:o: |-> Extract the current value of the ifType data.
420
 
     * set (* ifType_val_ptr ) from rowreq_ctx->data
 
535
     * copy (* ifType_val_ptr ) from rowreq_ctx->data
421
536
     */
422
537
    (*ifType_val_ptr) = rowreq_ctx->data.ifType;
423
538
 
472
587
 
473
588
    /*
474
589
     * TODO:231:o: |-> Extract the current value of the ifMtu data.
475
 
     * set (* ifMtu_val_ptr ) from rowreq_ctx->data
 
590
     * copy (* ifMtu_val_ptr ) from rowreq_ctx->data
476
591
     */
477
592
    (*ifMtu_val_ptr) = rowreq_ctx->data.ifMtu;
478
593
 
531
646
 
532
647
    /*
533
648
     * TODO:231:o: |-> Extract the current value of the ifSpeed data.
534
 
     * set (* ifSpeed_val_ptr ) from rowreq_ctx->data
 
649
     * copy (* ifSpeed_val_ptr ) from rowreq_ctx->data
535
650
     */
536
651
    (*ifSpeed_val_ptr) = rowreq_ctx->data.ifSpeed;
537
652
 
594
709
int
595
710
ifPhysAddress_get(ifTable_rowreq_ctx * rowreq_ctx,
596
711
                  char **ifPhysAddress_val_ptr_ptr,
597
 
                  size_t *ifPhysAddress_val_ptr_len_ptr)
 
712
                  size_t * ifPhysAddress_val_ptr_len_ptr)
598
713
{
599
714
   /** we should have a non-NULL pointer and enough storage */
600
715
    netsnmp_assert((NULL != ifPhysAddress_val_ptr_ptr)
621
736
 
622
737
    /*
623
738
     * TODO:231:o: |-> Extract the current value of the ifPhysAddress data.
624
 
     * set (* ifPhysAddress_val_ptr_ptr ) and (* ifPhysAddress_val_ptr_len_ptr ) from rowreq_ctx->data
 
739
     * copy (* ifPhysAddress_val_ptr_ptr ) data and (* ifPhysAddress_val_ptr_len_ptr ) from rowreq_ctx->data
625
740
     */
626
741
    /*
627
742
     * make sure there is enough space for ifPhysAddress data
628
743
     */
629
 
    if ((NULL == (*ifPhysAddress_val_ptr_ptr))
630
 
        || ((*ifPhysAddress_val_ptr_len_ptr) <
631
 
            rowreq_ctx->data.ifPhysAddress_len)) {
 
744
    if ((NULL == (*ifPhysAddress_val_ptr_ptr)) ||
 
745
        ((*ifPhysAddress_val_ptr_len_ptr) <
 
746
         (rowreq_ctx->data.ifPhysAddress_len *
 
747
          sizeof(rowreq_ctx->data.ifPhysAddress[0])))) {
632
748
        /*
633
749
         * allocate space for ifPhysAddress data
634
750
         */
635
751
        (*ifPhysAddress_val_ptr_ptr) =
636
752
            malloc(rowreq_ctx->data.ifPhysAddress_len *
637
 
                   sizeof((*ifPhysAddress_val_ptr_ptr)[0]));
 
753
                   sizeof(rowreq_ctx->data.ifPhysAddress[0]));
638
754
        if (NULL == (*ifPhysAddress_val_ptr_ptr)) {
639
755
            snmp_log(LOG_ERR, "could not allocate memory\n");
640
756
            return MFD_ERROR;
641
757
        }
642
758
    }
643
 
    (*ifPhysAddress_val_ptr_len_ptr) = rowreq_ctx->data.ifPhysAddress_len;
 
759
    (*ifPhysAddress_val_ptr_len_ptr) =
 
760
        rowreq_ctx->data.ifPhysAddress_len *
 
761
        sizeof(rowreq_ctx->data.ifPhysAddress[0]);
644
762
    memcpy((*ifPhysAddress_val_ptr_ptr), rowreq_ctx->data.ifPhysAddress,
645
 
           (*ifPhysAddress_val_ptr_len_ptr) *
646
 
           sizeof((*ifPhysAddress_val_ptr_ptr)[0]));
 
763
           (*ifPhysAddress_val_ptr_len_ptr));
647
764
 
648
765
    return MFD_SUCCESS;
649
766
}                               /* ifPhysAddress_get */
701
818
 
702
819
    /*
703
820
     * TODO:231:o: |-> Extract the current value of the ifAdminStatus data.
704
 
     * set (* ifAdminStatus_val_ptr ) from rowreq_ctx->data
 
821
     * copy (* ifAdminStatus_val_ptr ) from rowreq_ctx->data
705
822
     */
706
823
    (*ifAdminStatus_val_ptr) = rowreq_ctx->data.ifAdminStatus;
707
824
 
766
883
 
767
884
    /*
768
885
     * TODO:231:o: |-> Extract the current value of the ifOperStatus data.
769
 
     * set (* ifOperStatus_val_ptr ) from rowreq_ctx->data
 
886
     * copy (* ifOperStatus_val_ptr ) from rowreq_ctx->data
770
887
     */
771
888
    (*ifOperStatus_val_ptr) = rowreq_ctx->data.ifOperStatus;
772
889
 
822
939
 
823
940
    /*
824
941
     * TODO:231:o: |-> Extract the current value of the ifLastChange data.
825
 
     * set (* ifLastChange_val_ptr ) from rowreq_ctx->data
 
942
     * copy (* ifLastChange_val_ptr ) from rowreq_ctx->data
826
943
     */
827
944
    (*ifLastChange_val_ptr) = rowreq_ctx->data.ifLastChange;
828
945
 
880
997
 
881
998
    /*
882
999
     * TODO:231:o: |-> Extract the current value of the ifInOctets data.
883
 
     * set (* ifInOctets_val_ptr ) from rowreq_ctx->data
 
1000
     * copy (* ifInOctets_val_ptr ) from rowreq_ctx->data
884
1001
     */
885
1002
    (*ifInOctets_val_ptr) = rowreq_ctx->data.ifInOctets;
886
1003
 
939
1056
 
940
1057
    /*
941
1058
     * TODO:231:o: |-> Extract the current value of the ifInUcastPkts data.
942
 
     * set (* ifInUcastPkts_val_ptr ) from rowreq_ctx->data
 
1059
     * copy (* ifInUcastPkts_val_ptr ) from rowreq_ctx->data
943
1060
     */
944
1061
    (*ifInUcastPkts_val_ptr) = rowreq_ctx->data.ifInUcastPkts;
945
1062
 
1001
1118
 
1002
1119
    /*
1003
1120
     * TODO:231:o: |-> Extract the current value of the ifInNUcastPkts data.
1004
 
     * set (* ifInNUcastPkts_val_ptr ) from rowreq_ctx->data
 
1121
     * copy (* ifInNUcastPkts_val_ptr ) from rowreq_ctx->data
1005
1122
     */
1006
1123
    (*ifInNUcastPkts_val_ptr) = rowreq_ctx->data.ifInNUcastPkts;
1007
1124
 
1063
1180
 
1064
1181
    /*
1065
1182
     * TODO:231:o: |-> Extract the current value of the ifInDiscards data.
1066
 
     * set (* ifInDiscards_val_ptr ) from rowreq_ctx->data
 
1183
     * copy (* ifInDiscards_val_ptr ) from rowreq_ctx->data
1067
1184
     */
1068
1185
    (*ifInDiscards_val_ptr) = rowreq_ctx->data.ifInDiscards;
1069
1186
 
1125
1242
 
1126
1243
    /*
1127
1244
     * TODO:231:o: |-> Extract the current value of the ifInErrors data.
1128
 
     * set (* ifInErrors_val_ptr ) from rowreq_ctx->data
 
1245
     * copy (* ifInErrors_val_ptr ) from rowreq_ctx->data
1129
1246
     */
1130
1247
    (*ifInErrors_val_ptr) = rowreq_ctx->data.ifInErrors;
1131
1248
 
1190
1307
 
1191
1308
    /*
1192
1309
     * TODO:231:o: |-> Extract the current value of the ifInUnknownProtos data.
1193
 
     * set (* ifInUnknownProtos_val_ptr ) from rowreq_ctx->data
 
1310
     * copy (* ifInUnknownProtos_val_ptr ) from rowreq_ctx->data
1194
1311
     */
1195
1312
    (*ifInUnknownProtos_val_ptr) = rowreq_ctx->data.ifInUnknownProtos;
1196
1313
 
1248
1365
 
1249
1366
    /*
1250
1367
     * TODO:231:o: |-> Extract the current value of the ifOutOctets data.
1251
 
     * set (* ifOutOctets_val_ptr ) from rowreq_ctx->data
 
1368
     * copy (* ifOutOctets_val_ptr ) from rowreq_ctx->data
1252
1369
     */
1253
1370
    (*ifOutOctets_val_ptr) = rowreq_ctx->data.ifOutOctets;
1254
1371
 
1308
1425
 
1309
1426
    /*
1310
1427
     * TODO:231:o: |-> Extract the current value of the ifOutUcastPkts data.
1311
 
     * set (* ifOutUcastPkts_val_ptr ) from rowreq_ctx->data
 
1428
     * copy (* ifOutUcastPkts_val_ptr ) from rowreq_ctx->data
1312
1429
     */
1313
1430
    (*ifOutUcastPkts_val_ptr) = rowreq_ctx->data.ifOutUcastPkts;
1314
1431
 
1371
1488
 
1372
1489
    /*
1373
1490
     * TODO:231:o: |-> Extract the current value of the ifOutNUcastPkts data.
1374
 
     * set (* ifOutNUcastPkts_val_ptr ) from rowreq_ctx->data
 
1491
     * copy (* ifOutNUcastPkts_val_ptr ) from rowreq_ctx->data
1375
1492
     */
1376
 
    (*ifOutNUcastPkts_val_ptr) = rowreq_ctx->data.ifentry->stats.onucast;
 
1493
    (*ifOutNUcastPkts_val_ptr) = rowreq_ctx->data.ifOutNUcastPkts;
1377
1494
 
1378
1495
    return MFD_SUCCESS;
1379
1496
}                               /* ifOutNUcastPkts_get */
1431
1548
 
1432
1549
    /*
1433
1550
     * TODO:231:o: |-> Extract the current value of the ifOutDiscards data.
1434
 
     * set (* ifOutDiscards_val_ptr ) from rowreq_ctx->data
 
1551
     * copy (* ifOutDiscards_val_ptr ) from rowreq_ctx->data
1435
1552
     */
1436
1553
    (*ifOutDiscards_val_ptr) = rowreq_ctx->data.ifOutDiscards;
1437
1554
 
1492
1609
 
1493
1610
    /*
1494
1611
     * TODO:231:o: |-> Extract the current value of the ifOutErrors data.
1495
 
     * set (* ifOutErrors_val_ptr ) from rowreq_ctx->data
 
1612
     * copy (* ifOutErrors_val_ptr ) from rowreq_ctx->data
1496
1613
     */
1497
1614
    (*ifOutErrors_val_ptr) = rowreq_ctx->data.ifOutErrors;
1498
1615
 
1543
1660
 
1544
1661
    /*
1545
1662
     * TODO:231:o: |-> Extract the current value of the ifOutQLen data.
1546
 
     * set (* ifOutQLen_val_ptr ) from rowreq_ctx->data
 
1663
     * copy (* ifOutQLen_val_ptr ) from rowreq_ctx->data
1547
1664
     */
1548
1665
    (*ifOutQLen_val_ptr) = rowreq_ctx->data.ifOutQLen;
1549
1666
 
1609
1726
int
1610
1727
ifSpecific_get(ifTable_rowreq_ctx * rowreq_ctx,
1611
1728
               oid ** ifSpecific_val_ptr_ptr,
1612
 
               size_t *ifSpecific_val_ptr_len_ptr)
 
1729
               size_t * ifSpecific_val_ptr_len_ptr)
1613
1730
{
1614
1731
   /** we should have a non-NULL pointer and enough storage */
1615
1732
    netsnmp_assert((NULL != ifSpecific_val_ptr_ptr)
1623
1740
 
1624
1741
    /*
1625
1742
     * TODO:231:o: |-> Extract the current value of the ifSpecific data.
1626
 
     * set (* ifSpecific_val_ptr_ptr ) and (* ifSpecific_val_ptr_len_ptr ) from rowreq_ctx->data
 
1743
     * copy (* ifSpecific_val_ptr_ptr ) data and (* ifSpecific_val_ptr_len_ptr ) from rowreq_ctx->data
1627
1744
     */
1628
1745
#ifdef IFTABLE_HAS_IFSPECIFIC
1629
1746
    /*
1630
1747
     * make sure there is enough space for ifSpecific data
1631
1748
     */
1632
 
    if ((NULL == (*ifSpecific_val_ptr_ptr))
1633
 
        || ((*ifSpecific_val_ptr_len_ptr) <
1634
 
            rowreq_ctx->data.ifSpecific_len)) {
 
1749
    if ((NULL == (*ifSpecific_val_ptr_ptr)) ||
 
1750
        ((*ifSpecific_val_ptr_len_ptr) <
 
1751
         (rowreq_ctx->data.ifSpecific_len *
 
1752
          sizeof(rowreq_ctx->data.ifSpecific[0])))) {
1635
1753
        /*
1636
1754
         * allocate space for ifSpecific data
1637
1755
         */
1638
1756
        (*ifSpecific_val_ptr_ptr) =
1639
1757
            malloc(rowreq_ctx->data.ifSpecific_len *
1640
 
                   sizeof((*ifSpecific_val_ptr_ptr)[0]));
 
1758
                   sizeof(rowreq_ctx->data.ifSpecific[0]));
1641
1759
        if (NULL == (*ifSpecific_val_ptr_ptr)) {
1642
1760
            snmp_log(LOG_ERR, "could not allocate memory\n");
1643
1761
            return MFD_ERROR;
1644
1762
        }
1645
1763
    }
1646
 
    (*ifSpecific_val_ptr_len_ptr) = rowreq_ctx->data.ifSpecific_len;
 
1764
    (*ifSpecific_val_ptr_len_ptr) =
 
1765
        rowreq_ctx->data.ifSpecific_len *
 
1766
        sizeof(rowreq_ctx->data.ifSpecific[0]);
1647
1767
    memcpy((*ifSpecific_val_ptr_ptr), rowreq_ctx->data.ifSpecific,
1648
 
           (*ifSpecific_val_ptr_len_ptr) *
1649
 
           sizeof((*ifSpecific_val_ptr_ptr)[0]));
 
1768
           (*ifSpecific_val_ptr_len_ptr));
1650
1769
#else
1651
1770
    /*
1652
1771
     * hard coded
1660
1779
}                               /* ifSpecific_get */
1661
1780
 
1662
1781
 
 
1782
 
1663
1783
/** @} */
1664
1784
/**********************************************************************
1665
1785
 **********************************************************************
1669
1789
 **********************************************************************
1670
1790
 **********************************************************************/
1671
1791
/*
1672
 
 * ifTable is subid 2 of interfaces.
 
1792
 * IF-MIB::ifTable is subid 2 of interfaces.
1673
1793
 * Its status is Current.
1674
1794
 * OID: .1.3.6.1.2.1.2.2, length: 8
1675
1795
 */
1744
1864
/**
1745
1865
 * Setup up context with information needed to undo a set request.
1746
1866
 *
 
1867
     * Undo storage is in (* ifSpecific_val_ptr_ptr )*
1747
1868
 * This function will be called before the individual node undo setup
1748
1869
 * functions are called. If you need to do any undo setup that is not
1749
1870
 * related to a specific column, you can do it here.
1763
1884
 *        Pointer to the table context (ifTable_rowreq_ctx)
1764
1885
 *
1765
1886
 * @retval MFD_SUCCESS : success
 
1887
 * Undo storage is in (* ifSpecific_val_ptr_ptr )*
1766
1888
 * @retval MFD_ERROR   : error. set will fail.
1767
1889
 */
1768
1890
int
1778
1900
    /*
1779
1901
     * TODO:451:M: |-> Setup ifTable undo.
1780
1902
     * set up ifTable undo information, in preparation for a set.
 
1903
     * Undo storage is in (* ifSpecific_val_ptr_ptr )*
 
1904
     */
 
1905
 
 
1906
    return rc;
 
1907
}                               /* ifTable_undo_setup */
 
1908
 
 
1909
/**
 
1910
 * Undo a set request.
 
1911
 *
 
1912
 * This function will be called before the individual node undo
 
1913
 * functions are called. If you need to do any undo that is not
 
1914
 * related to a specific column, you can do it here.
 
1915
 *
 
1916
 * Note that an individual node's undo function will only be called
 
1917
 * if that node is being set to a new value.
 
1918
 *
 
1919
 * If there is anything  specific to a particular column (e.g. releasing
 
1920
 * memory for a string), you should do that setup in the node's undo
 
1921
 * function, so it won't be done unless it is necessary.
 
1922
 *
 
1923
 * @param rowreq_ctx
 
1924
 *        Pointer to the table context (ifTable_rowreq_ctx)
 
1925
 *
 
1926
 * @retval MFD_SUCCESS : success
 
1927
 * @retval MFD_ERROR   : error. set will fail.
 
1928
 */
 
1929
int
 
1930
ifTable_undo(ifTable_rowreq_ctx * rowreq_ctx)
 
1931
{
 
1932
    int             rc = MFD_SUCCESS;
 
1933
 
 
1934
    DEBUGMSGTL(("verbose:ifTable:ifTable_undo", "called\n"));
 
1935
 
 
1936
    /** we should have a non-NULL pointer */
 
1937
    netsnmp_assert(NULL != rowreq_ctx);
 
1938
 
 
1939
    /*
 
1940
     * TODO:451:M: |-> ifTable undo.
 
1941
     * ifTable undo information, in response to a failed set.
 
1942
     * Undo storage is in (* ifSpecific_val_ptr_ptr )*
1781
1943
     */
1782
1944
 
1783
1945
    return rc;
1812
1974
 
1813
1975
    /*
1814
1976
     * TODO:452:M: |-> Cleanup ifTable undo.
 
1977
     * Undo storage is in (* ifSpecific_val_ptr_ptr )*
1815
1978
     */
1816
1979
 
1817
1980
    return rc;
1825
1988
 *
1826
1989
 * Should you need different behavior depending on which columns were
1827
1990
 * set, rowreq_ctx->column_set_flags will indicate which writeable columns were
1828
 
 * set. The definitions for the FLAG_* bits can be found in
 
1991
 * set. The definitions for the COLUMN_*_FLAG bits can be found in
1829
1992
 * ifTable.h.
1830
1993
 * A new row will have the MFD_ROW_CREATED bit set in rowreq_flags.
1831
1994
 *
1832
 
 * @param ifTable_rowreq_ctx
1833
 
 *        Pointer to the users context.
 
1995
 * @param rowreq_ctx Pointer to the users context.
1834
1996
 *
1835
1997
 * @retval MFD_SUCCESS : success
1836
1998
 * @retval MFD_ERROR   : error
1859
2021
     * 3) set the column's flag in column_set_flags if it needs undo
1860
2022
     *    processing in case of a failure.
1861
2023
     */
1862
 
    if (save_flags & FLAG_IFADMINSTATUS) {
1863
 
        save_flags &= ~FLAG_IFADMINSTATUS;      /* clear ifAdminStatus */
 
2024
    if (save_flags & COLUMN_IFADMINSTATUS_FLAG) {
 
2025
        save_flags &= ~COLUMN_IFADMINSTATUS_FLAG;       /* clear ifAdminStatus */
1864
2026
        /*
1865
2027
         * TODO:482:o: |-> commit column ifAdminStatus.
1866
2028
         */
1876
2038
            /*
1877
2039
             * set flag, in case we need to undo ifAdminStatus
1878
2040
             */
1879
 
            rowreq_ctx->column_set_flags |= FLAG_IFADMINSTATUS;
 
2041
            rowreq_ctx->column_set_flags |= COLUMN_IFADMINSTATUS_FLAG;
1880
2042
        }
1881
2043
    }
1882
2044
 
 
2045
    /*
 
2046
     * if we successfully commited this row, set the dirty flag.
 
2047
     */
 
2048
    if (MFD_SUCCESS == rc) {
 
2049
        rowreq_ctx->rowreq_flags |= MFD_ROW_DIRTY;
 
2050
    }
 
2051
 
1883
2052
    if (save_flags) {
1884
2053
        snmp_log(LOG_ERR, "unhandled columns (0x%x) in commit\n",
1885
2054
                 save_flags);
1894
2063
 *
1895
2064
 * Should you need different behavior depending on which columns were
1896
2065
 * set, rowreq_ctx->column_set_flags will indicate which writeable columns were
1897
 
 * set. The definitions for the FLAG_* bits can be found in
 
2066
 * set. The definitions for the COLUMN_*_FLAG bits can be found in
1898
2067
 * ifTable.h.
1899
2068
 * A new row will have the MFD_ROW_CREATED bit set in rowreq_flags.
1900
2069
 *
1901
 
 * @param ifTable_rowreq_ctx
 
2070
 * @param rowreq_ctx
1902
2071
 *        Pointer to the users context.
1903
2072
 *
1904
2073
 * @retval MFD_SUCCESS : success
1919
2088
     * check the column's flag in rowreq_ctx->column_set_flags to see
1920
2089
     * if it was set during commit, then undo it.
1921
2090
     *
1922
 
     * eg: if (rowreq_ctx->column_set_flags & FLAG_) {}
 
2091
     * eg: if (rowreq_ctx->column_set_flags & COLUMN__FLAG) {}
1923
2092
     */
1924
2093
    /*
1925
2094
     * no undo cleanup, undo entry simply freed
1926
2095
     */
1927
2096
 
 
2097
 
 
2098
    /*
 
2099
     * if we successfully un-commited this row, clear the dirty flag.
 
2100
     */
 
2101
    if (MFD_SUCCESS == rc) {
 
2102
        rowreq_ctx->rowreq_flags &= ~MFD_ROW_DIRTY;
 
2103
    }
 
2104
 
1928
2105
    return rc;
1929
2106
}                               /* ifTable_undo_commit */
1930
2107
 
1931
2108
/*
1932
 
 * TODO:420:r: Implement ifTable index validation.
1933
 
 */
1934
 
/*
1935
2109
 * TODO:440:M: Implement ifTable node value checks.
1936
2110
 * TODO:450:M: Implement ifTable undo functions.
1937
2111
 * TODO:460:M: Implement ifTable set functions.
2124
2298
 *
2125
2299
 * Should you need different behavior depending on which columns were
2126
2300
 * set, rowreq_ctx->column_set_flags will indicate which writeable columns were
2127
 
 * set. The definitions for the FLAG_* bits can be found in
 
2301
 * set. The definitions for the COLUMN_*_FLAG bits can be found in
2128
2302
 * ifTable.h.
2129
2303
 * A new row will have the MFD_ROW_CREATED bit set in rowreq_flags.
2130
2304
 *
 
2305
 * @param rowreq_ctx
 
2306
 *
2131
2307
 * @retval MFD_SUCCESS all the changes to the row are legal
2132
2308
 * @retval MFD_ERROR   one or more changes are not legal
2133
2309
 *
2150
2326
    return rc;
2151
2327
}                               /* ifTable_check_dependencies */
2152
2328
 
 
2329
 
 
2330
static int
 
2331
_if_number_handler(netsnmp_mib_handler *handler,
 
2332
                      netsnmp_handler_registration *reginfo,
 
2333
                      netsnmp_agent_request_info *reqinfo,
 
2334
                      netsnmp_request_info *requests)
 
2335
{
 
2336
    if (MODE_GET == reqinfo->mode) {
 
2337
        int val = ifTable_container_size();
 
2338
        snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
 
2339
                                 (u_char *) &val, sizeof(val));
 
2340
    } else
 
2341
        netsnmp_assert("bad mode in RO handler");
 
2342
    
 
2343
    if (handler->next && handler->next->access_method)
 
2344
        return netsnmp_call_next_handler(handler, reginfo, reqinfo,
 
2345
                                         requests);
 
2346
    
 
2347
    return SNMP_ERR_NOERROR;
 
2348
}
 
2349
 
2153
2350
/** @} */
2154
2351
/** @{ */