|
1 /* |
|
2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. |
|
3 * |
|
4 * U.S. Government Rights - Commercial software. Government users are subject |
|
5 * to the Sun Microsystems, Inc. standard license agreement and applicable |
|
6 * provisions of the FAR and its supplements. |
|
7 * |
|
8 * |
|
9 * This distribution may include materials developed by third parties. Sun, |
|
10 * Sun Microsystems, the Sun logo and Solaris are trademarks or registered |
|
11 * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. |
|
12 * |
|
13 */ |
|
14 /* |
|
15 * Note: this file originally auto-generated by mib2c using |
|
16 * : mib2c.iterate.conf,v 5.5 2002/12/16 22:50:18 hardaker Exp $ |
|
17 */ |
|
18 |
|
19 #include <net-snmp/net-snmp-config.h> |
|
20 #include <net-snmp/net-snmp-includes.h> |
|
21 #include <net-snmp/agent/net-snmp-agent-includes.h> |
|
22 #include "stdhdr.h" |
|
23 #include "entAliasMappingTable.h" |
|
24 #include "entLogicalTable.h" |
|
25 #include "entPhysicalTable.h" |
|
26 #include "entLastChangeTime.h" |
|
27 |
|
28 entAliasMappingTableEntry_t *gAliasMappingTableHead; |
|
29 int gAliasMappingTableSize; |
|
30 static logicalAlias *gCurAliasEntry; |
|
31 |
|
32 |
|
33 |
|
34 /** Initialize the entAliasMappingTable table by defining its contents and how it's structured */ |
|
35 void |
|
36 initialize_table_entAliasMappingTable(void) |
|
37 { |
|
38 static oid entAliasMappingTable_oid[] = {1,3,6,1,2,1,47,1,3,2}; |
|
39 netsnmp_table_registration_info *table_info; |
|
40 netsnmp_handler_registration *my_handler; |
|
41 netsnmp_iterator_info *iinfo; |
|
42 |
|
43 /* create the table structure itself */ |
|
44 table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); |
|
45 iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info); |
|
46 |
|
47 /* if your table is read only, it's easiest to change the |
|
48 HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY */ |
|
49 /* Fix for 4910624 - changing HANDLER_CAN_RWRITE to HANDLER_CAN_RONLY */ |
|
50 my_handler = netsnmp_create_handler_registration("entAliasMappingTable", |
|
51 entAliasMappingTable_handler, |
|
52 entAliasMappingTable_oid, |
|
53 OID_LENGTH(entAliasMappingTable_oid), |
|
54 HANDLER_CAN_RONLY); |
|
55 /* End of Fix for 4910624 */ |
|
56 |
|
57 if (!my_handler || !table_info || !iinfo) |
|
58 return; /* mallocs failed */ |
|
59 |
|
60 /*************************************************** |
|
61 * Setting up the table's definition |
|
62 */ |
|
63 netsnmp_table_helper_add_indexes(table_info, |
|
64 ASN_INTEGER, /* index: entPhysicalIndex */ |
|
65 ASN_INTEGER, /* index: entAliasLogicalIndexOrZero */ |
|
66 0); |
|
67 |
|
68 table_info->min_column = 2; |
|
69 table_info->max_column = 2; |
|
70 |
|
71 /* iterator access routines */ |
|
72 iinfo->get_first_data_point = entAliasMappingTable_get_first_data_point; |
|
73 iinfo->get_next_data_point = entAliasMappingTable_get_next_data_point; |
|
74 |
|
75 iinfo->table_reginfo = table_info; |
|
76 |
|
77 /*************************************************** |
|
78 * registering the table with the master agent |
|
79 */ |
|
80 DEBUGMSGTL(("initialize_table_entAliasMappingTable", |
|
81 "Registering table entAliasMappingTable as a table iterator\n")); |
|
82 netsnmp_register_table_iterator(my_handler, iinfo); |
|
83 } |
|
84 |
|
85 /** Initializes the entAliasMappingTable module */ |
|
86 void |
|
87 init_entAliasMappingTable(void) |
|
88 { |
|
89 |
|
90 /* here we initialize all the tables we're planning on supporting */ |
|
91 initialize_table_entAliasMappingTable(); |
|
92 gAliasMappingTableSize = 0; |
|
93 gAliasMappingTableHead = NULL; |
|
94 gCurAliasEntry = NULL; |
|
95 } |
|
96 |
|
97 /** returns the first data point within the entAliasMappingTable table data. |
|
98 |
|
99 Set the my_loop_context variable to the first data point structure |
|
100 of your choice (from which you can find the next one). This could |
|
101 be anything from the first node in a linked list, to an integer |
|
102 pointer containing the beginning of an array variable. |
|
103 |
|
104 Set the my_data_context variable to something to be returned to |
|
105 you later that will provide you with the data to return in a given |
|
106 row. This could be the same pointer as what my_loop_context is |
|
107 set to, or something different. |
|
108 |
|
109 The put_index_data variable contains a list of snmp variable |
|
110 bindings, one for each index in your table. Set the values of |
|
111 each appropriately according to the data matching the first row |
|
112 and return the put_index_data variable at the end of the function. |
|
113 */ |
|
114 netsnmp_variable_list * |
|
115 entAliasMappingTable_get_first_data_point(void **my_loop_context, void **my_data_context, |
|
116 netsnmp_variable_list *put_index_data, |
|
117 netsnmp_iterator_info *mydata) |
|
118 { |
|
119 |
|
120 netsnmp_variable_list *vptr; |
|
121 entAliasMappingTableEntry_t *zRunner, *zpValidEntry; |
|
122 logicalAlias *zlogicalAliases, *zValidAlias; |
|
123 int bFound=0; |
|
124 |
|
125 zRunner = gAliasMappingTableHead; |
|
126 zpValidEntry = NULL; |
|
127 gCurAliasEntry = NULL; |
|
128 while (zRunner) { |
|
129 if (zRunner->entPhysicalIndex > 0) { |
|
130 zlogicalAliases = zRunner->entlogicalAliases; |
|
131 while ((zlogicalAliases != NULL) && |
|
132 (zlogicalAliases->entAliasMapIdSize >= 0)){ |
|
133 if (zlogicalAliases->entAliasLogicalIndexorZero >= 0) { |
|
134 bFound = 1; |
|
135 break; |
|
136 } |
|
137 zlogicalAliases++; |
|
138 } |
|
139 if (bFound) { |
|
140 zpValidEntry = zRunner; |
|
141 zValidAlias = zlogicalAliases; |
|
142 break; |
|
143 } |
|
144 } |
|
145 zRunner = zRunner->pNextEntry; |
|
146 } |
|
147 if (zRunner == NULL) return NULL; |
|
148 |
|
149 *my_loop_context = (void *) zpValidEntry; |
|
150 *my_data_context = (void *) zValidAlias; |
|
151 gCurAliasEntry = zValidAlias; |
|
152 |
|
153 vptr = put_index_data; |
|
154 |
|
155 snmp_set_var_value(vptr, (u_char *) &zpValidEntry->entPhysicalIndex, sizeof(zpValidEntry->entPhysicalIndex)); |
|
156 vptr = vptr->next_variable; |
|
157 snmp_set_var_value(vptr, (u_char *) &zValidAlias->entAliasLogicalIndexorZero, sizeof(zValidAlias->entAliasLogicalIndexorZero)); |
|
158 vptr = vptr->next_variable; |
|
159 |
|
160 return put_index_data; |
|
161 } |
|
162 |
|
163 /** functionally the same as entAliasMappingTable_get_first_data_point, but |
|
164 my_loop_context has already been set to a previous value and should |
|
165 be updated to the next in the list. For example, if it was a |
|
166 linked list, you might want to cast it and the return |
|
167 my_loop_context->next. The my_data_context pointer should be set |
|
168 to something you need later and the indexes in put_index_data |
|
169 updated again. */ |
|
170 |
|
171 netsnmp_variable_list * |
|
172 entAliasMappingTable_get_next_data_point(void **my_loop_context, void **my_data_context, |
|
173 netsnmp_variable_list *put_index_data, |
|
174 netsnmp_iterator_info *mydata) |
|
175 { |
|
176 |
|
177 netsnmp_variable_list *vptr; |
|
178 entAliasMappingTableEntry_t *zRunner, *zpValidEntry; |
|
179 logicalAlias *zlogicalAliases, *zValidAlias; |
|
180 int bFound=0; |
|
181 |
|
182 zRunner = (entAliasMappingTableEntry_t *)*my_loop_context; |
|
183 zlogicalAliases = (logicalAlias *) *my_data_context; |
|
184 zlogicalAliases = gCurAliasEntry; |
|
185 |
|
186 if (zlogicalAliases != NULL) |
|
187 zlogicalAliases++; |
|
188 |
|
189 while (zRunner) { |
|
190 if (zRunner->entPhysicalIndex > 0) { |
|
191 while ((zlogicalAliases != NULL) && |
|
192 (zlogicalAliases->entAliasMapIdSize >= 0)){ |
|
193 if (zlogicalAliases->entAliasLogicalIndexorZero >= 0) { |
|
194 bFound = 1; |
|
195 break; |
|
196 } |
|
197 zlogicalAliases++; |
|
198 } |
|
199 if (bFound) { |
|
200 zpValidEntry = zRunner; |
|
201 zValidAlias = zlogicalAliases; |
|
202 break; |
|
203 } |
|
204 } |
|
205 zRunner = zRunner->pNextEntry; |
|
206 if (zRunner) |
|
207 zlogicalAliases = zRunner->entlogicalAliases; |
|
208 } |
|
209 if (zRunner == NULL) return NULL; |
|
210 |
|
211 *my_loop_context = (void *) zpValidEntry; |
|
212 *my_data_context = (void *) zValidAlias; |
|
213 gCurAliasEntry = zValidAlias; |
|
214 |
|
215 vptr = put_index_data; |
|
216 |
|
217 snmp_set_var_value(vptr, (u_char *) &zpValidEntry->entPhysicalIndex, sizeof(zpValidEntry->entPhysicalIndex)); |
|
218 vptr = vptr->next_variable; |
|
219 snmp_set_var_value(vptr, (u_char *) &zValidAlias->entAliasLogicalIndexorZero, sizeof(zValidAlias->entAliasLogicalIndexorZero)); |
|
220 vptr = vptr->next_variable; |
|
221 |
|
222 return put_index_data; |
|
223 } |
|
224 |
|
225 /** handles requests for the entAliasMappingTable table, if anything else needs to be done */ |
|
226 int |
|
227 entAliasMappingTable_handler( |
|
228 netsnmp_mib_handler *handler, |
|
229 netsnmp_handler_registration *reginfo, |
|
230 netsnmp_agent_request_info *reqinfo, |
|
231 netsnmp_request_info *requests) { |
|
232 |
|
233 netsnmp_request_info *request; |
|
234 netsnmp_table_request_info *table_info; |
|
235 netsnmp_variable_list *var; |
|
236 logicalAlias *zAliasEntry; |
|
237 |
|
238 for(request = requests; request; request = request->next) { |
|
239 var = request->requestvb; |
|
240 if (request->processed != 0) |
|
241 continue; |
|
242 |
|
243 /* perform anything here that you need to do before each |
|
244 request is processed. */ |
|
245 |
|
246 /* the following extracts the my_data_context pointer set in |
|
247 the loop functions above. You can then use the results to |
|
248 help return data for the columns of the entAliasMappingTable table in question */ |
|
249 zAliasEntry = (logicalAlias *) netsnmp_extract_iterator_context(request); |
|
250 if (zAliasEntry == NULL) { |
|
251 if (reqinfo->mode == MODE_GET) { |
|
252 netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); |
|
253 continue; |
|
254 } |
|
255 /* XXX: no row existed, if you support creation and this is a |
|
256 set, start dealing with it here, else continue */ |
|
257 } |
|
258 |
|
259 /* extracts the information about the table from the request */ |
|
260 table_info = netsnmp_extract_table_info(request); |
|
261 /* table_info->colnum contains the column number requested */ |
|
262 /* table_info->indexes contains a linked list of snmp variable |
|
263 bindings for the indexes of the table. Values in the list |
|
264 have been set corresponding to the indexes of the |
|
265 request */ |
|
266 if (table_info==NULL) { |
|
267 continue; |
|
268 } |
|
269 |
|
270 switch(reqinfo->mode) { |
|
271 /* the table_iterator helper should change all GETNEXTs |
|
272 into GETs for you automatically, so you don't have to |
|
273 worry about the GETNEXT case. Only GETs and SETs need |
|
274 to be dealt with here */ |
|
275 case MODE_GET: |
|
276 switch(table_info->colnum) { |
|
277 case COLUMN_ENTALIASMAPPINGIDENTIFIER: |
|
278 snmp_set_var_typed_value(var, ASN_OBJECT_ID, (u_char *) zAliasEntry->entAliasMapId, zAliasEntry->entAliasMapIdSize); |
|
279 break; |
|
280 |
|
281 default: |
|
282 /* We shouldn't get here */ |
|
283 snmp_log(LOG_ERR, "problem encountered in entAliasMappingTable_handler: unknown column\n"); |
|
284 } |
|
285 break; |
|
286 |
|
287 case MODE_SET_RESERVE1: |
|
288 /* set handling... */ |
|
289 |
|
290 default: |
|
291 snmp_log(LOG_ERR, "problem encountered in entAliasMappingTable_handler: unsupported mode\n"); |
|
292 } |
|
293 } |
|
294 return SNMP_ERR_NOERROR; |
|
295 } |
|
296 |
|
297 /* Add an entry into the Alias Mapping Table |
|
298 returns 0 for success |
|
299 1 for entry already exist |
|
300 -1 for failure |
|
301 -2 for stale index |
|
302 */ |
|
303 |
|
304 int |
|
305 addAliasMappingTableEntry(int xentPhysicalIndex, int xentLogicalIndex, |
|
306 oid *xAliasMapId, int xAliasMapIdSize) |
|
307 { |
|
308 entAliasMappingTableEntry_t *zAliasTableEntry, *zRunner, *zlastEntry; |
|
309 entPhysicalEntry_t *physentry; |
|
310 entLogicalEntry_t *zLogicalEntry; |
|
311 logicalAlias *zLogicalAliases; |
|
312 |
|
313 /* Fix for 4927412: Rejects NULL xAliasMapId */ |
|
314 if (xAliasMapId == NULL) |
|
315 return -1; |
|
316 /* End of Fix for 4927412 */ |
|
317 |
|
318 /* Fix for 4888088: logical index cannot be smaller than zero, */ |
|
319 /* and physical index cannot be smaller than */ |
|
320 /* or equal to zero. -2 for stale entries */ |
|
321 if (xentPhysicalIndex <= 0 || xentPhysicalIndex > MAX_ENTITY_INDEX || xentLogicalIndex < 0 || xentLogicalIndex > MAX_ENTITY_INDEX) |
|
322 return -1; |
|
323 physentry = getPhysicalTableStaleEntry(xentPhysicalIndex); |
|
324 if (physentry != NULL) |
|
325 return -2; |
|
326 |
|
327 zLogicalEntry = getLogicalTableStaleEntry(xentLogicalIndex); |
|
328 if (zLogicalEntry != NULL) |
|
329 return -2; |
|
330 /* End of Fix for 4888088 */ |
|
331 |
|
332 physentry = getPhysicalTableEntry(xentPhysicalIndex); |
|
333 |
|
334 if (physentry != NULL) { |
|
335 if (physentry->entPhysicalClass != 10) return (-1); |
|
336 } else return (-1); |
|
337 |
|
338 if (xentLogicalIndex != 0) { |
|
339 zLogicalEntry = getLogicalTableEntry(xentLogicalIndex); |
|
340 if (zLogicalEntry == NULL) return (-1); |
|
341 } |
|
342 if (xAliasMapId == NULL) return (-1); |
|
343 |
|
344 zlastEntry = NULL; |
|
345 zRunner = gAliasMappingTableHead; |
|
346 while (zRunner != NULL) { |
|
347 if (zRunner->entPhysicalIndex == xentPhysicalIndex) { |
|
348 break; |
|
349 } |
|
350 zlastEntry = zRunner; |
|
351 zRunner = zRunner->pNextEntry; |
|
352 } |
|
353 if (zRunner != NULL ) {/* Found a entry with physical index */ |
|
354 logicalAlias *p; |
|
355 p = zRunner->entlogicalAliases; |
|
356 if (p == NULL) { |
|
357 zLogicalAliases = (logicalAlias *) malloc(2 * sizeof (logicalAlias)); |
|
358 if (!zLogicalAliases) return -1; |
|
359 zLogicalAliases[0].entAliasLogicalIndexorZero = xentLogicalIndex; |
|
360 zLogicalAliases[0].entAliasMapId = malloc(xAliasMapIdSize); |
|
361 if (!zLogicalAliases[0].entAliasMapId) return -1; |
|
362 memcpy(zLogicalAliases[0].entAliasMapId, xAliasMapId, |
|
363 xAliasMapIdSize); |
|
364 zLogicalAliases[0].entAliasMapIdSize = xAliasMapIdSize; |
|
365 zLogicalAliases[1].entAliasLogicalIndexorZero = 0; |
|
366 zLogicalAliases[1].entAliasMapId = NULL; |
|
367 zLogicalAliases[1].entAliasMapIdSize = -1; |
|
368 zRunner->entlogicalAliases = zLogicalAliases; |
|
369 } else {/* Add phy index to last entry in the array */ |
|
370 int i=0; |
|
371 while (p != NULL && p->entAliasMapIdSize >= 0) { |
|
372 if (p->entAliasLogicalIndexorZero == xentLogicalIndex) return (1); |
|
373 if (p->entAliasMapIdSize < 0 ) { |
|
374 p->entAliasLogicalIndexorZero = xentLogicalIndex; |
|
375 p->entAliasMapId = malloc(xAliasMapIdSize); |
|
376 if (!p->entAliasMapId) return -1; |
|
377 memcpy(p->entAliasMapId, xAliasMapId, xAliasMapIdSize); |
|
378 p->entAliasMapIdSize = xAliasMapIdSize; |
|
379 } |
|
380 p++; |
|
381 i++; |
|
382 } |
|
383 zRunner->entlogicalAliases = |
|
384 (logicalAlias *)realloc(zRunner->entlogicalAliases, (i + 2)*sizeof(logicalAlias)); |
|
385 zRunner->entlogicalAliases[i].entAliasLogicalIndexorZero = |
|
386 xentLogicalIndex; |
|
387 zRunner->entlogicalAliases[i].entAliasMapId = |
|
388 malloc(xAliasMapIdSize); |
|
389 if (!zRunner->entlogicalAliases[i].entAliasMapId) return -1; |
|
390 memcpy(zRunner->entlogicalAliases[i].entAliasMapId, xAliasMapId, |
|
391 xAliasMapIdSize); |
|
392 zRunner->entlogicalAliases[i].entAliasMapIdSize = xAliasMapIdSize; |
|
393 zRunner->entlogicalAliases[i+1].entAliasLogicalIndexorZero = 0; |
|
394 zRunner->entlogicalAliases[i+1].entAliasMapId = NULL; |
|
395 zRunner->entlogicalAliases[i+1].entAliasMapIdSize = -1; |
|
396 } |
|
397 configChanged(); |
|
398 return (0); |
|
399 } |
|
400 |
|
401 /* New entry*/ |
|
402 zAliasTableEntry = (entAliasMappingTableEntry_t *)malloc(sizeof(entAliasMappingTableEntry_t)); |
|
403 if (!zAliasTableEntry) return -1; |
|
404 zAliasTableEntry->entPhysicalIndex = xentPhysicalIndex; |
|
405 zLogicalAliases = (logicalAlias *) malloc(2 * sizeof (logicalAlias)); |
|
406 if (!zLogicalAliases) return -1; |
|
407 zLogicalAliases[0].entAliasLogicalIndexorZero = xentLogicalIndex; |
|
408 zLogicalAliases[0].entAliasMapId = malloc(xAliasMapIdSize); |
|
409 if (!zLogicalAliases[0].entAliasMapId) return -1; |
|
410 memcpy(zLogicalAliases[0].entAliasMapId, xAliasMapId, |
|
411 xAliasMapIdSize); |
|
412 zLogicalAliases[0].entAliasMapIdSize = xAliasMapIdSize; |
|
413 zLogicalAliases[1].entAliasLogicalIndexorZero = 0; |
|
414 zLogicalAliases[1].entAliasMapId = NULL; |
|
415 zLogicalAliases[1].entAliasMapIdSize = -1; |
|
416 zAliasTableEntry->entlogicalAliases = zLogicalAliases; |
|
417 zAliasTableEntry->pNextEntry = NULL; |
|
418 if (gAliasMappingTableHead){ |
|
419 zlastEntry->pNextEntry = zAliasTableEntry; |
|
420 } else { |
|
421 gAliasMappingTableHead = zAliasTableEntry; |
|
422 } |
|
423 gAliasMappingTableSize++; |
|
424 configChanged(); |
|
425 return (0); |
|
426 } |
|
427 |
|
428 /* Returns 0 for successful deletion |
|
429 -1 for entry not found |
|
430 -2 for stale entry |
|
431 */ |
|
432 int |
|
433 deleteAliasMappingTableEntry(int xentPhysicalIndex, int xentLogicalIndex) |
|
434 { |
|
435 entAliasMappingTableEntry_t *zRunner; |
|
436 logicalAlias *zLogicalAliases; |
|
437 int zPhyIndx; |
|
438 entPhysicalEntry_t *zPhysicalEntry; |
|
439 entLogicalEntry_t *zLogicalEntry; |
|
440 |
|
441 /* Fix for 4888088: logical index cannot be smaller than zero, */ |
|
442 /* and physical index cannot be smaller than */ |
|
443 /* or equal to zero. -2 for stale entries */ |
|
444 if (xentPhysicalIndex <= 0 || xentPhysicalIndex > MAX_ENTITY_INDEX || xentLogicalIndex < 0 || xentLogicalIndex > MAX_ENTITY_INDEX) |
|
445 return -1; |
|
446 zPhysicalEntry = getPhysicalTableStaleEntry(xentPhysicalIndex); |
|
447 if (zPhysicalEntry != NULL) |
|
448 return -2; |
|
449 |
|
450 zLogicalEntry = getLogicalTableStaleEntry(xentLogicalIndex); |
|
451 if (zLogicalEntry != NULL) |
|
452 return -2; |
|
453 /* End of Fix for 4888088 */ |
|
454 |
|
455 zRunner = gAliasMappingTableHead; |
|
456 |
|
457 while (zRunner != NULL) { |
|
458 zPhyIndx = zRunner->entPhysicalIndex; |
|
459 |
|
460 if (zPhyIndx > 0) { |
|
461 if (zPhyIndx == xentPhysicalIndex) { |
|
462 zLogicalAliases = zRunner->entlogicalAliases; |
|
463 while (zLogicalAliases != NULL |
|
464 && zLogicalAliases->entAliasMapIdSize >= 0) { |
|
465 int zLogIndx = zLogicalAliases->entAliasLogicalIndexorZero; |
|
466 if (zLogIndx >=0 ) { |
|
467 if (zLogIndx == xentLogicalIndex) { |
|
468 zLogicalAliases->entAliasLogicalIndexorZero = -1; |
|
469 free(zLogicalAliases->entAliasMapId); |
|
470 zLogicalAliases->entAliasMapId = NULL; |
|
471 zLogicalAliases->entAliasMapIdSize = 0; |
|
472 configChanged(); |
|
473 return (0); |
|
474 } |
|
475 } |
|
476 zLogicalAliases++; |
|
477 } |
|
478 return (-1); /* Entry not found */ |
|
479 } |
|
480 } |
|
481 zRunner = zRunner->pNextEntry; |
|
482 } |
|
483 return (-1); |
|
484 } |
|
485 |
|
486 static int |
|
487 FreeAliasMappingTableEntry(entAliasMappingTableEntry_t *xEntry) |
|
488 { |
|
489 logicalAlias *zAliases; |
|
490 int nEntries=0; |
|
491 if (xEntry == NULL) return (-1); |
|
492 zAliases = xEntry->entlogicalAliases; |
|
493 while (zAliases != NULL && zAliases->entAliasMapIdSize >= 0) { |
|
494 /* Fix for 4906853: we only need to free it (and count) if */ |
|
495 /* entAliasMapId != NULL. A better fix is to use a link list */ |
|
496 /* instead of an array for this structure */ |
|
497 if (zAliases->entAliasMapId != NULL) { |
|
498 free(zAliases->entAliasMapId); |
|
499 nEntries++; |
|
500 } |
|
501 /* End of Fix for 4906853 */ |
|
502 zAliases++; |
|
503 } |
|
504 free(xEntry->entlogicalAliases); |
|
505 free(xEntry); |
|
506 xEntry = NULL; |
|
507 return nEntries; |
|
508 } |
|
509 |
|
510 /* Deletes all the entries in the table with primary index as |
|
511 given physical index |
|
512 Return number of entries deleted on success, |
|
513 -1 on failure |
|
514 -2 for a existing stale entry |
|
515 */ |
|
516 |
|
517 int |
|
518 deleteAliasMappingPhysicalIndex(int xentPhysicalIndex) |
|
519 { |
|
520 entAliasMappingTableEntry_t *zRunner, *temp, *prevEntry; |
|
521 int zPhyIndx, nEntries=0; |
|
522 entPhysicalEntry_t *zPhysicalEntry; |
|
523 |
|
524 /* Fix for 4888088: We do not need the check for 4883511 anymore, */ |
|
525 /* because entAliasLogicalIndexorZero will never be set */ |
|
526 /* to negative values. Instead we will check if the */ |
|
527 /* entries are stale (except when xentLogicalIndex = 0) */ |
|
528 if (xentPhysicalIndex <= 0 || xentPhysicalIndex > MAX_ENTITY_INDEX) |
|
529 return -1; |
|
530 zPhysicalEntry = getPhysicalTableStaleEntry(xentPhysicalIndex); |
|
531 if (zPhysicalEntry != NULL) |
|
532 return -2; |
|
533 /* End of Fix for 4888088 */ |
|
534 |
|
535 zRunner = gAliasMappingTableHead; |
|
536 prevEntry = NULL; |
|
537 |
|
538 while (zRunner != NULL) { |
|
539 zPhyIndx = zRunner->entPhysicalIndex; |
|
540 |
|
541 if (zPhyIndx > 0) { |
|
542 if (zPhyIndx == xentPhysicalIndex) { |
|
543 temp = zRunner->pNextEntry; |
|
544 zRunner->pNextEntry = NULL; |
|
545 if (prevEntry) |
|
546 prevEntry->pNextEntry = temp; |
|
547 else |
|
548 gAliasMappingTableHead = temp; |
|
549 nEntries = FreeAliasMappingTableEntry(zRunner); |
|
550 gAliasMappingTableSize--; |
|
551 configChanged(); |
|
552 return nEntries; |
|
553 } |
|
554 } |
|
555 prevEntry = zRunner; |
|
556 zRunner = zRunner->pNextEntry; |
|
557 } |
|
558 return (-1); |
|
559 } |
|
560 |
|
561 /* Deletes all entries of the table for a given logical index. |
|
562 Returns the number if entries deleted |
|
563 -1 if the entry is not found |
|
564 -2 if the logical index is stale |
|
565 The memory allocated is freed when the primary index, physical index |
|
566 is deleted. |
|
567 */ |
|
568 int |
|
569 deleteAliasMappingLogicalIndex(int xentLogicalIndex) |
|
570 { |
|
571 entAliasMappingTableEntry_t *zRunner; |
|
572 logicalAlias *zLogicalAliases; |
|
573 int zPhyIndx, nFound=0; |
|
574 entLogicalEntry_t *zLogicalEntry; |
|
575 |
|
576 /* Fix for 4888088: Here we are not allowing logical index = 0. We are */ |
|
577 /* forcing the user to use deleteAliasMappingTableEntry */ |
|
578 if (xentLogicalIndex <= 0 || xentLogicalIndex > MAX_ENTITY_INDEX) |
|
579 return -1; |
|
580 zLogicalEntry = getLogicalTableStaleEntry(xentLogicalIndex); |
|
581 if (zLogicalEntry != NULL) |
|
582 return -2; |
|
583 /* End of Fix for 4888088 */ |
|
584 |
|
585 zRunner = gAliasMappingTableHead; |
|
586 |
|
587 while (zRunner != NULL) { |
|
588 zPhyIndx = zRunner->entPhysicalIndex; |
|
589 if (zPhyIndx > 0) { |
|
590 zLogicalAliases = zRunner->entlogicalAliases; |
|
591 while (zLogicalAliases != NULL |
|
592 && zLogicalAliases->entAliasMapIdSize >= 0) { |
|
593 int zLogIndx = zLogicalAliases->entAliasLogicalIndexorZero; |
|
594 if (zLogIndx >= 0 ) { |
|
595 if (zLogIndx == xentLogicalIndex) { |
|
596 zLogicalAliases->entAliasLogicalIndexorZero = -1; |
|
597 free(zLogicalAliases->entAliasMapId); |
|
598 zLogicalAliases->entAliasMapId = NULL; |
|
599 zLogicalAliases->entAliasMapIdSize = 0; |
|
600 nFound++; |
|
601 break; |
|
602 } |
|
603 } |
|
604 zLogicalAliases++; |
|
605 } |
|
606 } |
|
607 zRunner = zRunner->pNextEntry; |
|
608 } |
|
609 /* Fix for 4888088 */ |
|
610 if (nFound) { |
|
611 configChanged(); |
|
612 return (nFound); |
|
613 } else { |
|
614 return -1; |
|
615 } |
|
616 /* End of Fix for 4888088 */ |
|
617 } |