252N/A/*
252N/A * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
252N/A *
252N/A * U.S. Government Rights - Commercial software. Government users are subject
252N/A * to the Sun Microsystems, Inc. standard license agreement and applicable
252N/A * provisions of the FAR and its supplements.
252N/A *
252N/A *
252N/A * This distribution may include materials developed by third parties. Sun,
252N/A * Sun Microsystems, the Sun logo and Solaris are trademarks or registered
252N/A * trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
252N/A *
252N/A */
252N/A/*
252N/A * Note: this file originally auto-generated by mib2c using
252N/A * : mib2c.iterate.conf,v 5.5 2002/12/16 22:50:18 hardaker Exp $
252N/A */
252N/A
252N/A#include <net-snmp/net-snmp-config.h>
252N/A#include <net-snmp/net-snmp-includes.h>
252N/A#include <net-snmp/agent/net-snmp-agent-includes.h>
252N/A#include "stdhdr.h"
252N/A#include "entLogicalTable.h"
252N/A#include "entAliasMappingTable.h"
252N/A#include "entLastChangeTime.h"
252N/A#include "entLPMappingTable.h"
252N/A
252N/Astatic int AddToLogicalTable(entLogicalEntry_t *);
252N/Astatic int FreeLogicalEntry(entLogicalEntry_t *);
252N/A
252N/AentLogicalEntry_t *gLogicalTableHead, *gLogicalTableTail;
252N/Aint gLogicalTableSize;
252N/A
252N/A
252N/A/** Initialize the entLogicalTable table by defining its contents and how it's structured */
252N/Avoid
252N/Ainitialize_table_entLogicalTable(void)
252N/A{
252N/A static oid entLogicalTable_oid[] = {1,3,6,1,2,1,47,1,2,1};
252N/A netsnmp_table_registration_info *table_info;
252N/A netsnmp_handler_registration *my_handler;
252N/A netsnmp_iterator_info *iinfo;
252N/A
252N/A /* create the table structure itself */
252N/A table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
252N/A iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
252N/A
252N/A /* if your table is read only, it's easiest to change the
252N/A HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY */
252N/A /* Fix for 4910624 - changing HANDLER_CAN_RWRITE to HANDLER_CAN_RONLY */
252N/A my_handler = netsnmp_create_handler_registration("entLogicalTable",
252N/A entLogicalTable_handler,
252N/A entLogicalTable_oid,
252N/A OID_LENGTH(entLogicalTable_oid),
252N/A HANDLER_CAN_RONLY);
252N/A /* End of Fix for 4910624 */
252N/A
252N/A if (!my_handler || !table_info || !iinfo)
252N/A return; /* mallocs failed */
252N/A
252N/A /***************************************************
252N/A * Setting up the table's definition
252N/A */
252N/A netsnmp_table_helper_add_indexes(table_info,
252N/A ASN_INTEGER, /* index: entLogicalIndex */
252N/A 0);
252N/A
252N/A table_info->min_column = 2;
252N/A table_info->max_column = 8;
252N/A
252N/A /* iterator access routines */
252N/A iinfo->get_first_data_point = entLogicalTable_get_first_data_point;
252N/A iinfo->get_next_data_point = entLogicalTable_get_next_data_point;
252N/A
252N/A iinfo->table_reginfo = table_info;
252N/A
252N/A /***************************************************
252N/A * registering the table with the master agent
252N/A */
252N/A DEBUGMSGTL(("initialize_table_entLogicalTable",
252N/A "Registering table entLogicalTable as a table iterator\n"));
252N/A netsnmp_register_table_iterator(my_handler, iinfo);
252N/A}
252N/A
252N/A/** Initializes the entLogicalTable module */
252N/Avoid
252N/Ainit_entLogicalTable(void)
252N/A{
252N/A
252N/A /* here we initialize all the tables we're planning on supporting */
252N/A initialize_table_entLogicalTable();
252N/A gLogicalTableHead = NULL;
252N/A gLogicalTableSize = 0;
252N/A gLogicalTableTail = NULL;
252N/A}
252N/A
252N/A/** returns the first data point within the entLogicalTable table data.
252N/A
252N/A Set the my_loop_context variable to the first data point structure
252N/A of your choice (from which you can find the next one). This could
252N/A be anything from the first node in a linked list, to an integer
252N/A pointer containing the beginning of an array variable.
252N/A
252N/A Set the my_data_context variable to something to be returned to
252N/A you later that will provide you with the data to return in a given
252N/A row. This could be the same pointer as what my_loop_context is
252N/A set to, or something different.
252N/A
252N/A The put_index_data variable contains a list of snmp variable
252N/A bindings, one for each index in your table. Set the values of
252N/A each appropriately according to the data matching the first row
252N/A and return the put_index_data variable at the end of the function.
252N/A*/
252N/Anetsnmp_variable_list *
252N/AentLogicalTable_get_first_data_point(void **my_loop_context, void **my_data_context,
252N/A netsnmp_variable_list *put_index_data,
252N/A netsnmp_iterator_info *mydata)
252N/A{
252N/A
252N/A netsnmp_variable_list *vptr;
252N/A entLogicalEntry_t *zRunner;
252N/A zRunner = gLogicalTableHead;
252N/A
252N/A while (zRunner) {
252N/A if (zRunner->entLogicalIndex > 0)
252N/A break;
252N/A zRunner = zRunner->pNextEntry;
252N/A }
252N/A
252N/A if (zRunner == NULL) return NULL;
252N/A
252N/A *my_loop_context = (void *)zRunner;
252N/A *my_data_context = (void *)zRunner;
252N/A
252N/A vptr = put_index_data;
252N/A
252N/A snmp_set_var_value(vptr, (u_char *)&zRunner->entLogicalIndex, sizeof(zRunner->entLogicalIndex));
252N/A vptr = vptr->next_variable;
252N/A
252N/A return put_index_data;
252N/A
252N/A}
252N/A
252N/A/** functionally the same as entLogicalTable_get_first_data_point, but
252N/A my_loop_context has already been set to a previous value and should
252N/A be updated to the next in the list. For example, if it was a
252N/A linked list, you might want to cast it and the return
252N/A my_loop_context->next. The my_data_context pointer should be set
252N/A to something you need later and the indexes in put_index_data
252N/A updated again. */
252N/A
252N/Anetsnmp_variable_list *
252N/AentLogicalTable_get_next_data_point(void **my_loop_context, void **my_data_context,
252N/A netsnmp_variable_list *put_index_data,
252N/A netsnmp_iterator_info *mydata)
252N/A{
252N/A
252N/A entLogicalEntry_t *zRunner;
252N/A netsnmp_variable_list *vptr;
252N/A
252N/A zRunner = (entLogicalEntry_t *) *my_loop_context;
252N/A
252N/A while (zRunner) {
252N/A zRunner = zRunner->pNextEntry;
252N/A if (zRunner && zRunner->entLogicalIndex > 0)
252N/A break;
252N/A }
252N/A
252N/A if (zRunner == NULL) return NULL;
252N/A
252N/A *my_loop_context = (void *)zRunner;
252N/A *my_data_context = (void *)zRunner;
252N/A
252N/A vptr = put_index_data;
252N/A
252N/A snmp_set_var_value(vptr, (u_char *)&zRunner->entLogicalIndex, sizeof(zRunner->entLogicalIndex));
252N/A vptr = vptr->next_variable;
252N/A
252N/A return put_index_data;
252N/A
252N/A}
252N/A
252N/A/** handles requests for the entLogicalTable table, if anything else needs to be done */
252N/Aint
252N/AentLogicalTable_handler(
252N/A netsnmp_mib_handler *handler,
252N/A netsnmp_handler_registration *reginfo,
252N/A netsnmp_agent_request_info *reqinfo,
252N/A netsnmp_request_info *requests) {
252N/A
252N/A netsnmp_request_info *request;
252N/A netsnmp_table_request_info *table_info;
252N/A netsnmp_variable_list *var;
252N/A entLogicalEntry_t *zLogicalEntry;
252N/A
252N/A for(request = requests; request; request = request->next) {
252N/A var = request->requestvb;
252N/A if (request->processed != 0)
252N/A continue;
252N/A
252N/A /* perform anything here that you need to do before each
252N/A request is processed. */
252N/A
252N/A /* the following extracts the my_data_context pointer set in
252N/A the loop functions above. You can then use the results to
252N/A help return data for the columns of the entLogicalTable table in question */
252N/A zLogicalEntry = (entLogicalEntry_t *) netsnmp_extract_iterator_context(request);
252N/A
252N/A if ((zLogicalEntry == NULL) || (zLogicalEntry->entLogicalIndex <= 0) ) {
252N/A if (reqinfo->mode == MODE_GET) {
252N/A netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
252N/A continue;
252N/A }
252N/A /* XXX: no row existed, if you support creation and this is a
252N/A set, start dealing with it here, else continue */
252N/A }
252N/A
252N/A /* extracts the information about the table from the request */
252N/A table_info = netsnmp_extract_table_info(request);
252N/A /* table_info->colnum contains the column number requested */
252N/A /* table_info->indexes contains a linked list of snmp variable
252N/A bindings for the indexes of the table. Values in the list
252N/A have been set corresponding to the indexes of the
252N/A request */
252N/A if (table_info==NULL) {
252N/A continue;
252N/A }
252N/A
252N/A switch(reqinfo->mode) {
252N/A /* the table_iterator helper should change all GETNEXTs
252N/A into GETs for you automatically, so you don't have to
252N/A worry about the GETNEXT case. Only GETs and SETs need
252N/A to be dealt with here */
252N/A case MODE_GET:
252N/A switch(table_info->colnum) {
252N/A case COLUMN_ENTLOGICALDESCR:
252N/A snmp_set_var_typed_value(var, ASN_OCTET_STR, (u_char *) zLogicalEntry->entLogicalDescr, strlen(zLogicalEntry->entLogicalDescr));
252N/A break;
252N/A
252N/A case COLUMN_ENTLOGICALTYPE:
252N/A snmp_set_var_typed_value(var, ASN_OBJECT_ID, (u_char *) zLogicalEntry->entLogicalType, zLogicalEntry->entLogicalTypeSize);
252N/A break;
252N/A
252N/A case COLUMN_ENTLOGICALCOMMUNITY:
252N/A snmp_set_var_typed_value(var, ASN_OCTET_STR, (u_char *) zLogicalEntry->entLogicalCommunity, strlen(zLogicalEntry->entLogicalCommunity));
252N/A break;
252N/A
252N/A case COLUMN_ENTLOGICALTADDRESS:
252N/A snmp_set_var_typed_value(var, ASN_OCTET_STR, (u_char *) zLogicalEntry->entLogicalTAddress, strlen(zLogicalEntry->entLogicalTAddress));
252N/A break;
252N/A
252N/A case COLUMN_ENTLOGICALTDOMAIN:
252N/A snmp_set_var_typed_value(var, ASN_OBJECT_ID, (u_char *) zLogicalEntry->entLogicalTDomain, zLogicalEntry->entLogicalTDomainSize);
252N/A break;
252N/A
252N/A case COLUMN_ENTLOGICALCONTEXTENGINEID:
252N/A snmp_set_var_typed_value(var, ASN_OCTET_STR, (u_char *) zLogicalEntry->entLogicalContextEngineId, strlen(zLogicalEntry->entLogicalContextEngineId));
252N/A break;
252N/A
252N/A case COLUMN_ENTLOGICALCONTEXTNAME:
252N/A snmp_set_var_typed_value(var, ASN_OCTET_STR, (u_char *) zLogicalEntry->entLogicalContextName, strlen(zLogicalEntry->entLogicalContextName));
252N/A break;
252N/A
252N/A default:
252N/A /* We shouldn't get here */
252N/A snmp_log(LOG_ERR, "problem encountered in entLogicalTable_handler: unknown column\n");
252N/A }
252N/A break;
252N/A
252N/A case MODE_SET_RESERVE1:
252N/A /* set handling... */
252N/A
252N/A default:
252N/A snmp_log(LOG_ERR, "problem encountered in entLogicalTable_handler: unsupported mode\n");
252N/A }
252N/A }
252N/A return SNMP_ERR_NOERROR;
252N/A}
252N/A
252N/Avoid populate_entLogicalEntry(entLogicalEntry_t *xLogicalStatic,
252N/A char *entLogicalDescr,
252N/A oid *entLogicalType,
252N/A int entLogicalTypeSize,
252N/A char *entLogicalCommunity,
252N/A char *entLogicalTAddress,
252N/A oid *entLogicalTDomain,
252N/A int entLogicalTDomainSize,
252N/A char *entLogicalContextEngineId,
252N/A char *entLogicalContextName)
252N/A{
252N/A xLogicalStatic->entLogicalDescr = entLogicalDescr;
252N/A xLogicalStatic->entLogicalType = entLogicalType;
252N/A xLogicalStatic->entLogicalTypeSize = entLogicalTypeSize;
252N/A xLogicalStatic->entLogicalCommunity = entLogicalCommunity;
252N/A xLogicalStatic->entLogicalTAddress = entLogicalTAddress;
252N/A xLogicalStatic->entLogicalTDomain = entLogicalTDomain;
252N/A xLogicalStatic->entLogicalTDomainSize = entLogicalTDomainSize;
252N/A xLogicalStatic->entLogicalContextEngineId = entLogicalContextEngineId;
252N/A xLogicalStatic->entLogicalContextName = entLogicalContextName;
252N/A}
252N/A
252N/A
252N/A/*
252N/A * Allocates a Logical entry. if logicidx >0 attempts to reuse an
252N/A * existing entry
252N/A */
252N/A
252N/Aint
252N/AallocLogicalEntry(int xLogicalIdx, entLogicalEntry_t * xnewLogicalEntry)
252N/A{
252N/A entLogicalEntry_t *logicent;
252N/A int index;
252N/A /* Fix for 4893101 */
252N/A static oid mib2oid[] = { 1,3,6,1,2,1 };
252N/A /* End of Fix for 4893101 */
252N/A /* Fix for 4927412 */
252N/A char emptystring[1] = "";
252N/A /* End of Fix for 4927412 */
252N/A
252N/A /* Fix for 4927412: according to RFC 2737, entLogicalDescr has to be */
252N/A /* unique - NULL should be rejected. */
252N/A /* entLogicalTAddress should not accept NULL or "". */
252N/A /* entLogicalTDomain should not accept NULL */
252N/A /* entLogicalType will default to mib-2 for */
252N/A /* NULL. For the rest, we will force NULL = "" */
252N/A /* (zero-length string) */
252N/A if (xnewLogicalEntry->entLogicalDescr == NULL)
252N/A return -1;
252N/A /* Fix for 4893101: We have to check for NULL so that it does not */
252N/A /* crash. Also we need to have mib-2 as the default, */
252N/A /* as outlined in the RFC */
252N/A if (xnewLogicalEntry->entLogicalType == NULL) {
252N/A xnewLogicalEntry->entLogicalType = mib2oid;
252N/A xnewLogicalEntry->entLogicalTypeSize = sizeof(mib2oid);
252N/A }
252N/A /* End of Fix for 4893101 */
252N/A if (xnewLogicalEntry->entLogicalCommunity == NULL)
252N/A xnewLogicalEntry->entLogicalCommunity = emptystring;
252N/A if (xnewLogicalEntry->entLogicalTAddress == NULL)
252N/A return -1;
252N/A else if (strcmp((const char *)xnewLogicalEntry->entLogicalTAddress, "") == 0)
252N/A return -1;
252N/A if (xnewLogicalEntry->entLogicalTDomain == NULL)
252N/A return -1;
252N/A if (xnewLogicalEntry->entLogicalContextEngineId == NULL)
252N/A xnewLogicalEntry->entLogicalContextEngineId = emptystring;
252N/A if (xnewLogicalEntry->entLogicalContextName == NULL)
252N/A xnewLogicalEntry->entLogicalContextName = emptystring;
252N/A /* End of Fix for 4927412 */
252N/A
252N/A /* Fix for 4921309 */
252N/A if (xLogicalIdx < 0 || xLogicalIdx > MAX_ENTITY_INDEX)
252N/A return NULL;
252N/A /* End of Fix for 4921309 */
252N/A
252N/A /* Fix for 4911817: Check for size and boundary limits */
252N/A /* entLogicalDescr 0..255 */
252N/A if (strlen(xnewLogicalEntry->entLogicalDescr) > 255)
252N/A return -1;
252N/A
252N/A /* entLogicalCommunity 0..255 (deprecated) */
252N/A if (strlen(xnewLogicalEntry->entLogicalCommunity) > 255)
252N/A return -1;
252N/A
252N/A /* entLogicalTAddress 1..255 */
252N/A if (strlen(xnewLogicalEntry->entLogicalTAddress) < 1 || strlen(xnewLogicalEntry->entLogicalTAddress) > 255)
252N/A return -1;
252N/A
252N/A /* entLogicalContextEngineId 0..32 */
252N/A if (strlen(xnewLogicalEntry->entLogicalContextEngineId) > 32)
252N/A return -1;
252N/A
252N/A /* entLogicalContextName 0..255 */
252N/A if (strlen(xnewLogicalEntry->entLogicalContextName) > 255)
252N/A return -1;
252N/A /* End of Fix for 4911817 */
252N/A
252N/A logicent = malloc(sizeof (entLogicalEntry_t));
252N/A if (logicent == NULL) {
252N/A return (-1);
252N/A }
252N/A
252N/A logicent->entLogicalIndex = xLogicalIdx;
252N/A
252N/A logicent->entLogicalDescr = strdup(xnewLogicalEntry->entLogicalDescr);
252N/A /* Fix for 4884526 */
252N/A if (logicent->entLogicalDescr == NULL) {
252N/A free (logicent);
252N/A return (-1);
252N/A }
252N/A /* End of Fix for 4884526 */
252N/A
252N/A logicent->entLogicalType = malloc(xnewLogicalEntry->entLogicalTypeSize);
252N/A /* Fix for 4884526 */
252N/A if (logicent->entLogicalType == NULL) {
252N/A free(logicent->entLogicalDescr);
252N/A free (logicent);
252N/A return (-1);
252N/A }
252N/A /* End of Fix for 4884526 */
252N/A
252N/A memcpy(logicent->entLogicalType, xnewLogicalEntry->entLogicalType,
252N/A xnewLogicalEntry->entLogicalTypeSize);
252N/A logicent->entLogicalTypeSize = xnewLogicalEntry->entLogicalTypeSize;
252N/A
252N/A logicent->entLogicalCommunity =
252N/A strdup(xnewLogicalEntry->entLogicalCommunity);
252N/A /* Fix for 4884526 */
252N/A if (logicent->entLogicalCommunity == NULL) {
252N/A free(logicent->entLogicalType);
252N/A free(logicent->entLogicalDescr);
252N/A free (logicent);
252N/A return (-1);
252N/A }
252N/A /* End of Fix for 4884526 */
252N/A logicent->entLogicalTAddress =
252N/A strdup(xnewLogicalEntry->entLogicalTAddress);
252N/A /* Fix for 4884526 */
252N/A if (logicent->entLogicalTAddress == NULL) {
252N/A free(logicent->entLogicalCommunity);
252N/A free(logicent->entLogicalType);
252N/A free(logicent->entLogicalDescr);
252N/A free (logicent);
252N/A return (-1);
252N/A }
252N/A /* End of Fix for 4884526 */
252N/A
252N/A /* Fix for 4926767: We do not want NULL TDomain */
252N/A if (xnewLogicalEntry->entLogicalTDomain == NULL) {
252N/A logicent->entLogicalTDomain = NULL;
252N/A } else {
252N/A logicent->entLogicalTDomain =
252N/A malloc(xnewLogicalEntry->entLogicalTDomainSize);
252N/A }
252N/A /* End of Fix for 4926767 */
252N/A
252N/A /* Fix for 4884526 */
252N/A if (logicent->entLogicalTDomain == NULL) {
252N/A free(logicent->entLogicalTAddress);
252N/A free(logicent->entLogicalCommunity);
252N/A free(logicent->entLogicalType);
252N/A free(logicent->entLogicalDescr);
252N/A free (logicent);
252N/A return (-1);
252N/A }
252N/A /* End of Fix for 4884526 */
252N/A
252N/A memcpy(logicent->entLogicalTDomain, xnewLogicalEntry->entLogicalTDomain,
252N/A xnewLogicalEntry->entLogicalTDomainSize);
252N/A logicent->entLogicalTDomainSize = xnewLogicalEntry->entLogicalTDomainSize;
252N/A
252N/A logicent->entLogicalContextEngineId =
252N/A strdup(xnewLogicalEntry->entLogicalContextEngineId);
252N/A /* Fix for 4884526 */
252N/A if (logicent->entLogicalContextEngineId == NULL) {
252N/A free(logicent->entLogicalTDomain);
252N/A free(logicent->entLogicalTAddress);
252N/A free(logicent->entLogicalCommunity);
252N/A free(logicent->entLogicalType);
252N/A free(logicent->entLogicalDescr);
252N/A free (logicent);
252N/A return (-1);
252N/A }
252N/A /* End of Fix for 4884526 */
252N/A logicent->entLogicalContextName =
252N/A strdup(xnewLogicalEntry->entLogicalContextName);
252N/A /* Fix for 4884526 */
252N/A if (logicent->entLogicalContextName == NULL) {
252N/A free(logicent->entLogicalContextEngineId);
252N/A free(logicent->entLogicalTDomain);
252N/A free(logicent->entLogicalTAddress);
252N/A free(logicent->entLogicalCommunity);
252N/A free(logicent->entLogicalType);
252N/A free(logicent->entLogicalDescr);
252N/A free (logicent);
252N/A return (-1);
252N/A }
252N/A /* End of Fix for 4884526 */
252N/A
252N/A logicent->pNextEntry = NULL;
252N/A
252N/A index = AddToLogicalTable(logicent);
252N/A return (index);
252N/A}
252N/A
252N/Astatic int
252N/AAddToLogicalTable(entLogicalEntry_t * xnewLogicalEntry)
252N/A{
252N/A entLogicalEntry_t *zRunner, *temp;
252N/A int placeFound; /* Fix for 4921309 */
252N/A int zIndex;
252N/A zRunner = gLogicalTableHead;
252N/A
252N/A if (xnewLogicalEntry == NULL) return (-1);
252N/A xnewLogicalEntry->pNextEntry = NULL;
252N/A
252N/A /* Fix for 4921309 */
252N/A /* If index > 0, attempt to insert in appropriate place. */
252N/A if (xnewLogicalEntry->entLogicalIndex > 0) {
252N/A placeFound = 0;
252N/A temp = zRunner;
252N/A while (zRunner != NULL) {
252N/A if (xnewLogicalEntry->entLogicalIndex >
252N/A abs(zRunner->entLogicalIndex)) {
252N/A temp = zRunner;
252N/A zRunner = zRunner->pNextEntry;
252N/A } else {
252N/A break;
252N/A }
252N/A }
252N/A
252N/A /* If the indexes don't match, we can use the specified index */
252N/A if (temp == NULL) {
252N/A /* List is empty, make this the first/last entry */
252N/A gLogicalTableHead = xnewLogicalEntry;
252N/A gLogicalTableTail = xnewLogicalEntry;
252N/A placeFound = 1;
252N/A } else if (zRunner == NULL) {
252N/A /* Index > last value, make this the last entry */
252N/A temp->pNextEntry = xnewLogicalEntry;
252N/A gLogicalTableTail = xnewLogicalEntry;
252N/A placeFound = 1;
252N/A } else if (xnewLogicalEntry->entLogicalIndex !=
252N/A abs(zRunner->entLogicalIndex)) {
252N/A /* Index < zRunner, insert entry before it */
252N/A xnewLogicalEntry->pNextEntry = zRunner;
252N/A if (zRunner == gLogicalTableHead) {
252N/A /* Index fits before list head, insert entry */
252N/A gLogicalTableHead = xnewLogicalEntry;
252N/A } else {
252N/A /* Index fits between two entries, insert entry */
252N/A temp->pNextEntry = xnewLogicalEntry;
252N/A }
252N/A placeFound = 1;
252N/A }
252N/A
252N/A if (placeFound) {
252N/A gLogicalTableSize++;
252N/A configChanged();
252N/A return (xnewLogicalEntry->entLogicalIndex);
252N/A } else {
252N/A /* Re-initialize for code that follows */
252N/A zRunner = gLogicalTableHead;
252N/A }
252N/A }
252N/A
252N/A /* Either index was zero or specified index is already taken */
252N/A /* End of Fix for 4921309 */
252N/A
252N/A if (gLogicalTableSize > LARGE_TABLE) {
252N/A gLogicalTableTail->pNextEntry = xnewLogicalEntry;
252N/A zIndex = abs(gLogicalTableTail->entLogicalIndex) + 1;
252N/A xnewLogicalEntry->entLogicalIndex = zIndex;
252N/A gLogicalTableTail = xnewLogicalEntry;
252N/A gLogicalTableSize++;
252N/A configChanged();
252N/A return (zIndex);
252N/A }
252N/A
252N/A if (gLogicalTableHead) { /* A slightly slower way to add into the list */
252N/A while (zRunner->pNextEntry != NULL) {
252N/A if ((abs(zRunner->pNextEntry->entLogicalIndex)
252N/A - abs(zRunner->entLogicalIndex)) > 1) {
252N/A temp = zRunner->pNextEntry;
252N/A zRunner->pNextEntry = xnewLogicalEntry;
252N/A zIndex = abs(zRunner->entLogicalIndex) + 1;
252N/A xnewLogicalEntry->entLogicalIndex = zIndex;
252N/A xnewLogicalEntry->pNextEntry = temp;
252N/A gLogicalTableSize++;
252N/A configChanged();
252N/A return (zIndex);
252N/A }
252N/A zRunner = zRunner->pNextEntry;
252N/A }
252N/A zIndex = abs(zRunner->entLogicalIndex) + 1;
252N/A xnewLogicalEntry->entLogicalIndex = zIndex;
252N/A zRunner->pNextEntry = xnewLogicalEntry;
252N/A } else {
252N/A zIndex = xnewLogicalEntry->entLogicalIndex = 1;
252N/A gLogicalTableHead = xnewLogicalEntry;
252N/A }
252N/A gLogicalTableTail = xnewLogicalEntry;
252N/A gLogicalTableSize++;
252N/A configChanged();
252N/A return (zIndex);
252N/A}
252N/A
252N/Aint
252N/AmakeLogicalTableEntryStale(int xLogicalIndex)
252N/A{
252N/A
252N/A entLogicalEntry_t *zRunner;
252N/A int zLogicalIndex;
252N/A
252N/A /* Fix for 4888088 */
252N/A if (xLogicalIndex <= 0 || xLogicalIndex > MAX_ENTITY_INDEX)
252N/A return (-1);
252N/A /* End of Fix for 4888088 */
252N/A
252N/A zRunner = gLogicalTableHead;
252N/A
252N/A while (zRunner) {
252N/A zLogicalIndex = zRunner->entLogicalIndex;
252N/A if (zLogicalIndex < 0) {
252N/A if (zLogicalIndex == -(xLogicalIndex))
252N/A return (-2); /* Entry is already stale */
252N/A }
252N/A if (zLogicalIndex == xLogicalIndex) {
252N/A /* Fix for 4918876: We need to delete the related entries first */
252N/A
252N/A/*
252N/A Delete all instances of this logical index in all other
252N/A tables to maintain table integrity. Should we roll-back if a
252N/A deletion fails, perhaps not
252N/A*/
252N/A deleteAliasMappingLogicalIndex( xLogicalIndex); /*Alias mapping*/
252N/A deleteLPMappingLogicalIndex( xLogicalIndex); /* LPTable */
252N/A /* End of Fix for 4918876 */
252N/A
252N/A zRunner->entLogicalIndex = -zLogicalIndex;
252N/A
252N/A configChanged();
252N/A
252N/A return (0);
252N/A }
252N/A zRunner = zRunner->pNextEntry;
252N/A }
252N/A return (-1);
252N/A}
252N/A
252N/Aint
252N/AmakeLogicalTableEntryLive(int xLogicalIndex)
252N/A{
252N/A entLogicalEntry_t *zRunner;
252N/A int zLogicalIndex;
252N/A
252N/A /* Fix for 4888088 */
252N/A if (xLogicalIndex <= 0 || xLogicalIndex > MAX_ENTITY_INDEX)
252N/A return (-1);
252N/A /* End of Fix for 4888088 */
252N/A
252N/A zRunner = gLogicalTableHead;
252N/A
252N/A while (zRunner) {
252N/A zLogicalIndex = zRunner->entLogicalIndex;
252N/A if (zLogicalIndex > 0) {
252N/A if (zLogicalIndex == xLogicalIndex)
252N/A return (-2); /* Entry is already live */
252N/A }
252N/A if (zLogicalIndex == -(xLogicalIndex)) {
252N/A zRunner->entLogicalIndex = xLogicalIndex;
252N/A configChanged();
252N/A return (0);
252N/A }
252N/A zRunner = zRunner->pNextEntry;
252N/A }
252N/A return (-1);
252N/A}
252N/A
252N/AentLogicalEntry_t*
252N/AgetLogicalTableEntry(int xLogicalIndex)
252N/A{
252N/A entLogicalEntry_t *zRunner;
252N/A int zLogicalIndex;
252N/A
252N/A /* Fix for 4888088 */
252N/A if (xLogicalIndex <= 0 || xLogicalIndex > MAX_ENTITY_INDEX)
252N/A return NULL;
252N/A /* End of Fix for 4888088 */
252N/A
252N/A zRunner = gLogicalTableHead;
252N/A while (zRunner) {
252N/A zLogicalIndex = zRunner->entLogicalIndex;
252N/A if (zLogicalIndex > 0) {
252N/A if (zLogicalIndex == xLogicalIndex)
252N/A return zRunner;
252N/A }
252N/A if (zLogicalIndex == -(xLogicalIndex)) {
252N/A return NULL; /* The stale entry exist, we can stop the search*/
252N/A }
252N/A zRunner = zRunner->pNextEntry;
252N/A }
252N/A return NULL;
252N/A}
252N/A
252N/AentLogicalEntry_t*
252N/AgetLogicalTableStaleEntry(int xLogicalIndex)
252N/A{
252N/A entLogicalEntry_t *zRunner;
252N/A int zLogicalIndex;
252N/A
252N/A /* Fix for 4888088 */
252N/A if (xLogicalIndex <= 0 || xLogicalIndex > MAX_ENTITY_INDEX)
252N/A return NULL;
252N/A /* End of Fix for 4888088 */
252N/A
252N/A zRunner = gLogicalTableHead;
252N/A while (zRunner) {
252N/A zLogicalIndex = zRunner->entLogicalIndex;
252N/A if (zLogicalIndex < 0) {
252N/A if (zLogicalIndex == -(xLogicalIndex))
252N/A return zRunner;
252N/A }
252N/A if (zLogicalIndex == xLogicalIndex) {
252N/A return NULL; /* The live entry exist, we can stop the search*/
252N/A }
252N/A zRunner = zRunner->pNextEntry;
252N/A }
252N/A return NULL;
252N/A}
252N/A
252N/A
252N/Aint
252N/AdeleteLogicalTableEntry(int xLogicalIndex)
252N/A{
252N/A entLogicalEntry_t *zRunner, *temp, *prevEntry;
252N/A int zLogicalIndex;
252N/A
252N/A /* Fix for 4888088 */
252N/A if (xLogicalIndex <= 0 || xLogicalIndex > MAX_ENTITY_INDEX)
252N/A return -1;
252N/A /* End of Fix for 4888088 */
252N/A
252N/A zRunner = gLogicalTableHead;
252N/A prevEntry = NULL;
252N/A while (zRunner) {
252N/A zLogicalIndex = zRunner->entLogicalIndex;
252N/A if (zLogicalIndex > 0) {
252N/A if (zLogicalIndex == xLogicalIndex) {
252N/A /* Fix for 4918876: We need to delete the related entries */
252N/A /* first */
252N/A/*
252N/A Delete all instances of this logical index in all other
252N/A tables to maintain table integrity. Should we roll-back if a
252N/A deletion fails, perhaps not
252N/A*/
252N/A deleteAliasMappingLogicalIndex( xLogicalIndex); /*Alias mapping*/
252N/A deleteLPMappingLogicalIndex( xLogicalIndex); /* LPTable */
252N/A /* End of Fix for 4918876 */
252N/A
252N/A temp = zRunner->pNextEntry;
252N/A zRunner->pNextEntry = NULL;
252N/A if (prevEntry)
252N/A prevEntry->pNextEntry = temp;
252N/A else
252N/A gLogicalTableHead = temp;;
252N/A FreeLogicalEntry(zRunner);
252N/A
252N/A configChanged();
252N/A
252N/A gLogicalTableSize--;
252N/A return (0);
252N/A }
252N/A }
252N/A if (zLogicalIndex == -(xLogicalIndex)) {
252N/A return (-2); /* The stale entry exist, we can stop the search*/
252N/A }
252N/A prevEntry = zRunner;
252N/A zRunner = zRunner->pNextEntry;
252N/A }
252N/A return (-1);
252N/A}
252N/A
252N/Aint
252N/AFreeLogicalEntry(entLogicalEntry_t *xEntry)
252N/A{
252N/A if (xEntry == NULL) return (-1);
252N/A free(xEntry->entLogicalDescr);
252N/A free(xEntry->entLogicalType);
252N/A free(xEntry->entLogicalCommunity);
252N/A free(xEntry->entLogicalTAddress);
252N/A free(xEntry->entLogicalTDomain);
252N/A free(xEntry->entLogicalContextEngineId);
252N/A free(xEntry->entLogicalContextName);
252N/A free(xEntry);
252N/A xEntry = NULL;
252N/A return (1);
252N/A}