Debian Codegraph @

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