Debian Codegraph @

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