~ubuntu-branches/ubuntu/precise/net-snmp/precise

« back to all changes in this revision

Viewing changes to agent/mibgroup/sctp-mib/sctpLookupLocalPortTable.c

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-11-26 01:27:00 UTC
  • mfrom: (1.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20091126012700-pox7w0a5j2x305h9
Tags: 5.4.2.1~dfsg-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - Set Ubuntu maintainer address.
  - net-snmp-config: Use bash. (LP: #104738)
  - Removed multiuser option when calling update-rc.d. (LP: #254261)
  - debian/snmpd.init: LSBify the init script.
  - debian/patches/52_fix_snmpcmd_1_typo.patch: Adjust a typo in snmpcmd.1
    (LP: #250459)
  - debian/patches/99-fix-ubuntu-div0.patch: Fix dvision by zero.
    (LP: #426813).
 * Dropped patches:
   - debian/patches/101-fix-ipalias.patch: Applied upstream.
   - debian/patches/99-fix-net-snmp-syslog.patch: Applied upstream.
   - debian/patches/99-fix-perl-counter-in-subagent.patch: Applied upstream.
   - ebian/patches/103-fix-ubuntu-lmsensors.patch: No longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Note: this file originally auto-generated by mib2c using
 
3
 *  $
 
4
 */
 
5
 
 
6
#include <net-snmp/net-snmp-config.h>
 
7
#include <net-snmp/net-snmp-includes.h>
 
8
#include <net-snmp/agent/net-snmp-agent-includes.h>
 
9
#include <net-snmp/agent/net-snmp-agent-includes.h>
 
10
#include <net-snmp/agent/table_container.h>
 
11
#include "sctpLookupLocalPortTable.h"
 
12
 
 
13
static netsnmp_container *sctpLookupLocalPortTable_container;
 
14
 
 
15
/** Initializes the sctpLookupLocalPortTable module */
 
16
void
 
17
init_sctpLookupLocalPortTable(void)
 
18
{
 
19
    /*
 
20
     * here we initialize all the tables we're planning on supporting 
 
21
     */
 
22
    initialize_table_sctpLookupLocalPortTable();
 
23
}
 
24
 
 
25
void
 
26
shutdown_sctpLookupLocalPortTable(void)
 
27
{
 
28
    sctpLookupLocalPortTable_container_clear
 
29
        (sctpLookupLocalPortTable_container);
 
30
}
 
31
 
 
32
/** Initialize the sctpLookupLocalPortTable table by defining its contents and how it's structured */
 
33
void
 
34
initialize_table_sctpLookupLocalPortTable(void)
 
35
{
 
36
    static oid      sctpLookupLocalPortTable_oid[] =
 
37
        { 1, 3, 6, 1, 2, 1, 104, 1, 6 };
 
38
    size_t          sctpLookupLocalPortTable_oid_len =
 
39
        OID_LENGTH(sctpLookupLocalPortTable_oid);
 
40
    netsnmp_handler_registration *reg = NULL;
 
41
    netsnmp_mib_handler *handler = NULL;
 
42
    netsnmp_container *container = NULL;
 
43
    netsnmp_table_registration_info *table_info = NULL;
 
44
 
 
45
    reg =
 
46
        netsnmp_create_handler_registration("sctpLookupLocalPortTable",
 
47
                                            sctpLookupLocalPortTable_handler,
 
48
                                            sctpLookupLocalPortTable_oid,
 
49
                                            sctpLookupLocalPortTable_oid_len,
 
50
                                            HANDLER_CAN_RONLY);
 
51
    if (NULL == reg) {
 
52
        snmp_log(LOG_ERR,
 
53
                 "error creating handler registration for sctpLookupLocalPortTable\n");
 
54
        goto bail;
 
55
    }
 
56
 
 
57
    container =
 
58
        netsnmp_container_find("sctpLookupLocalPortTable:table_container");
 
59
    if (NULL == container) {
 
60
        snmp_log(LOG_ERR,
 
61
                 "error creating container for sctpLookupLocalPortTable\n");
 
62
        goto bail;
 
63
    }
 
64
    sctpLookupLocalPortTable_container = container;
 
65
 
 
66
    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
 
67
    if (NULL == table_info) {
 
68
        snmp_log(LOG_ERR,
 
69
                 "error allocating table registration for sctpLookupLocalPortTable\n");
 
70
        goto bail;
 
71
    }
 
72
    netsnmp_table_helper_add_indexes(table_info, ASN_UNSIGNED,  /* index: sctpAssocLocalPort */
 
73
                                     ASN_UNSIGNED,      /* index: sctpAssocId */
 
74
                                     0);
 
75
    table_info->min_column = COLUMN_SCTPLOOKUPLOCALPORTSTARTTIME;
 
76
    table_info->max_column = COLUMN_SCTPLOOKUPLOCALPORTSTARTTIME;
 
77
 
 
78
    /*************************************************
 
79
     *
 
80
     * inject container_table helper
 
81
     */
 
82
    handler = netsnmp_container_table_handler_get(table_info, container,
 
83
                                                  TABLE_CONTAINER_KEY_NETSNMP_INDEX);
 
84
    if (NULL == handler) {
 
85
        snmp_log(LOG_ERR,
 
86
                 "error allocating table registration for sctpLookupLocalPortTable\n");
 
87
        goto bail;
 
88
    }
 
89
    if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
 
90
        snmp_log(LOG_ERR,
 
91
                 "error injecting container_table handler for sctpLookupLocalPortTable\n");
 
92
        goto bail;
 
93
    }
 
94
    handler = NULL;             /* reg has it, will reuse below */
 
95
 
 
96
    /*
 
97
     * register the table
 
98
     */
 
99
    if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
 
100
        snmp_log(LOG_ERR,
 
101
                 "error registering table handler for sctpLookupLocalPortTable\n");
 
102
        goto bail;
 
103
    }
 
104
 
 
105
    /*
 
106
     * Initialise the contents of the table here
 
107
     */
 
108
 
 
109
 
 
110
    return;                     /* ok */
 
111
 
 
112
    /*
 
113
     * Some error occurred during registration. Clean up and bail.
 
114
     */
 
115
  bail:                        /* not ok */
 
116
 
 
117
    if (handler)
 
118
        netsnmp_handler_free(handler);
 
119
 
 
120
    if (table_info)
 
121
        netsnmp_table_registration_info_free(table_info);
 
122
 
 
123
    if (container)
 
124
        CONTAINER_FREE(container);
 
125
 
 
126
    if (reg)
 
127
        netsnmp_handler_registration_free(reg);
 
128
}
 
129
 
 
130
 
 
131
/** handles requests for the sctpLookupLocalPortTable table */
 
132
int
 
133
sctpLookupLocalPortTable_handler(netsnmp_mib_handler *handler,
 
134
                                 netsnmp_handler_registration *reginfo,
 
135
                                 netsnmp_agent_request_info *reqinfo,
 
136
                                 netsnmp_request_info *requests)
 
137
{
 
138
 
 
139
    netsnmp_request_info *request;
 
140
    netsnmp_table_request_info *table_info;
 
141
    sctpLookupLocalPortTable_entry *table_entry;
 
142
 
 
143
    switch (reqinfo->mode) {
 
144
        /*
 
145
         * Read-support (also covers GetNext requests)
 
146
         */
 
147
    case MODE_GET:
 
148
        for (request = requests; request; request = request->next) {
 
149
            if (request->processed)
 
150
                continue;
 
151
            table_entry = (sctpLookupLocalPortTable_entry *)
 
152
                netsnmp_container_table_extract_context(request);
 
153
            table_info = netsnmp_extract_table_info(request);
 
154
            if ((NULL == table_entry) || (NULL == table_info)) {
 
155
                snmp_log(LOG_ERR,
 
156
                         "could not extract table entry or info for sctpLookupLocalPortTable\n");
 
157
                snmp_set_var_typed_value(request->requestvb,
 
158
                                         SNMP_ERR_GENERR, NULL, 0);
 
159
                continue;
 
160
            }
 
161
 
 
162
            switch (table_info->colnum) {
 
163
            case COLUMN_SCTPLOOKUPLOCALPORTSTARTTIME:
 
164
                if (!table_entry) {
 
165
                    netsnmp_set_request_error(reqinfo, request,
 
166
                                              SNMP_NOSUCHINSTANCE);
 
167
                    continue;
 
168
                }
 
169
                snmp_set_var_typed_integer(request->requestvb,
 
170
                                           ASN_TIMETICKS,
 
171
                                           table_entry->sctpLookupLocalPortStartTime);
 
172
                break;
 
173
            default:
 
174
                netsnmp_set_request_error(reqinfo, request,
 
175
                                          SNMP_NOSUCHOBJECT);
 
176
                break;
 
177
            }
 
178
        }
 
179
        break;
 
180
 
 
181
    }
 
182
    return SNMP_ERR_NOERROR;
 
183
}
 
184
 
 
185
sctpLookupLocalPortTable_entry *
 
186
sctpLookupLocalPortTable_entry_create(void)
 
187
{
 
188
    sctpLookupLocalPortTable_entry *entry =
 
189
        SNMP_MALLOC_TYPEDEF(sctpLookupLocalPortTable_entry);
 
190
    if (entry != NULL) {
 
191
        entry->oid_index.len = SCTP_LOOKUP_LOCAL_PORT_TABLE_INDEX_SIZE;
 
192
        entry->oid_index.oids = entry->oid_tmp;
 
193
    }
 
194
 
 
195
    return entry;
 
196
}
 
197
 
 
198
int
 
199
sctpLookupLocalPortTable_entry_update_index(sctpLookupLocalPortTable_entry
 
200
                                            * entry)
 
201
{
 
202
    netsnmp_variable_list var_sctpAssocLocalPort;
 
203
    netsnmp_variable_list var_sctpAssocId;
 
204
    int             err = 0;
 
205
 
 
206
    /*
 
207
     * prepare the value to be converted 
 
208
     */
 
209
    memset(&var_sctpAssocLocalPort, 0, sizeof(var_sctpAssocLocalPort));
 
210
    var_sctpAssocLocalPort.type = ASN_UNSIGNED;
 
211
    var_sctpAssocLocalPort.next_variable = &var_sctpAssocId;
 
212
    snmp_set_var_value(&var_sctpAssocLocalPort,
 
213
                       (u_char *) & entry->sctpAssocLocalPort,
 
214
                       sizeof(entry->sctpAssocLocalPort));
 
215
 
 
216
    memset(&var_sctpAssocId, 0, sizeof(var_sctpAssocId));
 
217
    var_sctpAssocId.type = ASN_UNSIGNED;
 
218
    var_sctpAssocId.next_variable = NULL;
 
219
    snmp_set_var_value(&var_sctpAssocId, (u_char *) & entry->sctpAssocId,
 
220
                       sizeof(entry->sctpAssocId));
 
221
 
 
222
    /*
 
223
     * convert it 
 
224
     */
 
225
    err =
 
226
        build_oid_noalloc(entry->oid_index.oids, entry->oid_index.len,
 
227
                          &entry->oid_index.len, NULL, 0,
 
228
                          &var_sctpAssocLocalPort);
 
229
    if (err)
 
230
        snmp_log(LOG_ERR, "error %d converting index to oid\n", err);
 
231
 
 
232
    /*
 
233
     * release any memory allocated during the conversion 
 
234
     */
 
235
    snmp_reset_var_buffers(&var_sctpAssocLocalPort);
 
236
 
 
237
    return err;
 
238
}
 
239
 
 
240
void
 
241
sctpLookupLocalPortTable_entry_copy(sctpLookupLocalPortTable_entry * from,
 
242
                                    sctpLookupLocalPortTable_entry * to)
 
243
{
 
244
    memcpy(to, from, sizeof(sctpLookupLocalPortTable_entry));
 
245
    to->oid_index.oids = to->oid_tmp;
 
246
}
 
247
 
 
248
 
 
249
void
 
250
sctpLookupLocalPortTable_entry_free(sctpLookupLocalPortTable_entry * entry)
 
251
{
 
252
    if (entry != NULL)
 
253
        SNMP_FREE(entry);
 
254
}
 
255
 
 
256
netsnmp_container *
 
257
sctpLookupLocalPortTable_get_container(void)
 
258
{
 
259
    return sctpLookupLocalPortTable_container;
 
260
}
 
261
 
 
262
 
 
263
static void
 
264
sctpLookupLocalPortTable_entry_clear(void *what, void *magic)
 
265
{
 
266
    sctpLookupLocalPortTable_entry_free(what);
 
267
}
 
268
 
 
269
void
 
270
sctpLookupLocalPortTable_container_clear(netsnmp_container *container)
 
271
{
 
272
    CONTAINER_CLEAR(container, sctpLookupLocalPortTable_entry_clear, NULL);
 
273
}