Debian Codegraph @

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