Debian Codegraph @

agent/mibgroup/sctp-mib/sctpLookupRemPortTable.c

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