diff --git a/src/modules/snmpstats/alarm_checks.c b/src/modules/snmpstats/alarm_checks.c index b062b287dab..06e391a4ad0 100644 --- a/src/modules/snmpstats/alarm_checks.c +++ b/src/modules/snmpstats/alarm_checks.c @@ -44,19 +44,17 @@ /*! Returns the number of bytes currently waiting in the msg queue if they exceed * the threshold, and zero otherwise. If threshold_to_compare_to is < 0, then * no check will be performed and zero always returned. */ -int check_msg_queue_alarm(int threshold_to_compare_to) +int check_msg_queue_alarm(int threshold_to_compare_to) { int bytesWaiting = 0; - if (threshold_to_compare_to < 0) - { + if(threshold_to_compare_to < 0) { return 0; } - - bytesWaiting = get_total_bytes_waiting(); - if (bytesWaiting > threshold_to_compare_to) - { + bytesWaiting = get_total_bytes_waiting(); + + if(bytesWaiting > threshold_to_compare_to) { return bytesWaiting; } @@ -66,19 +64,17 @@ int check_msg_queue_alarm(int threshold_to_compare_to) /*! Returns the number of active dialogs if they exceed the threshold, and zero * otherwise. */ -int check_dialog_alarm(int threshold_to_compare_to) +int check_dialog_alarm(int threshold_to_compare_to) { int num_dialogs; - if (threshold_to_compare_to < 0) - { + if(threshold_to_compare_to < 0) { return 0; } num_dialogs = get_statistic("active_dialogs"); - if (num_dialogs > threshold_to_compare_to) - { + if(num_dialogs > threshold_to_compare_to) { return num_dialogs; } @@ -88,22 +84,21 @@ int check_dialog_alarm(int threshold_to_compare_to) /*! This function will be called periodically from an Kamailio timer. The first * time it is called, it will query KAMAILIO-MIB for configured thresholds. */ -void run_alarm_check(unsigned int ticks, void * attr) +void run_alarm_check(unsigned int ticks, void *attr) { static int msg_queue_minor_threshold; - static int msg_queue_major_threshold; + static int msg_queue_major_threshold; static int dialog_minor_threshold; static int dialog_major_threshold; static char firstRun = 1; - + int bytesInMsgQueue; int numActiveDialogs; /* We only need to retrieve our thresholds the first time around */ - if (firstRun) - { + if(firstRun) { register_with_master_agent(ALARM_AGENT_NAME); msg_queue_minor_threshold = get_msg_queue_minor_threshold(); @@ -114,11 +109,11 @@ void run_alarm_check(unsigned int ticks, void * attr) firstRun = 0; } - + /* We need to have this here in case the master agent fails and is * restarted. Without it, we won't be able to re-establish or AgentX * connection */ - agent_check_and_process(0); + agent_check_and_process(0); /* Check for MsgQueue alarm conditions */ @@ -127,36 +122,32 @@ void run_alarm_check(unsigned int ticks, void * attr) * of bytes will be returned. */ bytesInMsgQueue = check_msg_queue_alarm(msg_queue_minor_threshold); - if (bytesInMsgQueue != 0) - { - send_kamailioMsgQueueDepthMinorEvent_trap(bytesInMsgQueue, - msg_queue_minor_threshold); + if(bytesInMsgQueue != 0) { + send_kamailioMsgQueueDepthMinorEvent_trap( + bytesInMsgQueue, msg_queue_minor_threshold); } bytesInMsgQueue = check_msg_queue_alarm(msg_queue_major_threshold); - if (bytesInMsgQueue != 0) - { - send_kamailioMsgQueueDepthMajorEvent_trap(bytesInMsgQueue, - msg_queue_major_threshold); + if(bytesInMsgQueue != 0) { + send_kamailioMsgQueueDepthMajorEvent_trap( + bytesInMsgQueue, msg_queue_major_threshold); } /* Check for Dialog alarm conditions: */ - numActiveDialogs = check_dialog_alarm(dialog_minor_threshold); + numActiveDialogs = check_dialog_alarm(dialog_minor_threshold); - if (numActiveDialogs != 0) - { - send_kamailioDialogLimitMinorEvent_trap(numActiveDialogs, - dialog_minor_threshold); + if(numActiveDialogs != 0) { + send_kamailioDialogLimitMinorEvent_trap( + numActiveDialogs, dialog_minor_threshold); } - + numActiveDialogs = check_dialog_alarm(dialog_major_threshold); - if (numActiveDialogs != 0) - { - send_kamailioDialogLimitMajorEvent_trap(numActiveDialogs, - dialog_major_threshold); + if(numActiveDialogs != 0) { + send_kamailioDialogLimitMajorEvent_trap( + numActiveDialogs, dialog_major_threshold); } -} +} \ No newline at end of file diff --git a/src/modules/snmpstats/alarm_checks.h b/src/modules/snmpstats/alarm_checks.h index fa69292d68c..76e12019cb8 100644 --- a/src/modules/snmpstats/alarm_checks.h +++ b/src/modules/snmpstats/alarm_checks.h @@ -34,7 +34,7 @@ #define _SNMPSTATS_ALARM_AGENT_ #define ALARM_AGENT_FREQUENCY_IN_SECONDS 5 -#define ALARM_AGENT_NAME "snmpstats_alarm_agent" +#define ALARM_AGENT_NAME "snmpstats_alarm_agent" /*! Returns the number of bytes currently waiting in the msg queue if they exceed * the threshold, and zero otherwise. If threshold_to_compare_to is < 0, then @@ -48,6 +48,6 @@ int check_dialog_alarm(int threshold_to_compare_to); /*! This function will be called periodically from an Kamailio timer. The first * time it is called, it will query KAMAILIO-MIB for configured thresholds. */ -void run_alarm_check(unsigned int ticks, void * attr); +void run_alarm_check(unsigned int ticks, void *attr); #endif diff --git a/src/modules/snmpstats/hashTable.c b/src/modules/snmpstats/hashTable.c index 24a4e79e69b..1fa6afeb26f 100644 --- a/src/modules/snmpstats/hashTable.c +++ b/src/modules/snmpstats/hashTable.c @@ -52,12 +52,12 @@ /*! Calculates and returns a hash index to a hash table. The index is calculated * by summing up all the characters specified with theString, and using the * hashTableSize as the modulus. */ -int calculateHashSlot(char *theString, int hashTableSize) +int calculateHashSlot(char *theString, int hashTableSize) { char *currentCharacter = theString; - int runningTotal = 0; + int runningTotal = 0; - while (*currentCharacter != '\0') { + while(*currentCharacter != '\0') { runningTotal += *currentCharacter; currentCharacter++; } @@ -83,12 +83,12 @@ aorToIndexStruct_t *findHashRecord(hashSlot_t *theTable, char *aor, int size) aorToIndexStruct_t *currentRecord = theTable[hashIndex].first; - while (currentRecord != NULL) { - + while(currentRecord != NULL) { + /* If the strings are the same length and the same in every * other way, then return the given record. */ - if (currentRecord->aorLength == aorStringLength && - memcmp(currentRecord->aor, aor, aorStringLength)==0) { + if(currentRecord->aorLength == aorStringLength + && memcmp(currentRecord->aor, aor, aorStringLength) == 0) { return currentRecord; } @@ -102,15 +102,14 @@ aorToIndexStruct_t *findHashRecord(hashSlot_t *theTable, char *aor, int size) /*! Returns a chunk of memory large enough to store 'size' hashSlot's. The * table will contain mappings between Kamailio's "aor" user/contact indexing * scheme, and SNMPStats integer indexing scheme */ -hashSlot_t *createHashTable(int size) +hashSlot_t *createHashTable(int size) { - hashSlot_t *hashTable = NULL; - int numberOfBytes = sizeof(hashSlot_t)*size; + hashSlot_t *hashTable = NULL; + int numberOfBytes = sizeof(hashSlot_t) * size; hashTable = pkg_malloc(numberOfBytes); - if (!hashTable) - { + if(!hashTable) { LM_ERR("no more pkg memory"); return NULL; } @@ -122,8 +121,8 @@ hashSlot_t *createHashTable(int size) /*! Inserts the record specified with 'theRecord' into our hash table. */ -void insertHashRecord(hashSlot_t *theTable, aorToIndexStruct_t *theRecord, - int size) +void insertHashRecord( + hashSlot_t *theTable, aorToIndexStruct_t *theRecord, int size) { int hashIndex = calculateHashSlot(theRecord->aor, size); @@ -133,22 +132,20 @@ void insertHashRecord(hashSlot_t *theTable, aorToIndexStruct_t *theRecord, /* This is the first record in the hash table, so assign the first and * last pointers to this record. */ - if (theTable[hashIndex].last == NULL) { - - theTable[hashIndex].last = theRecord; + if(theTable[hashIndex].last == NULL) { + + theTable[hashIndex].last = theRecord; theTable[hashIndex].first = theRecord; } else { - + /* Make the element that was previously the last element point * to this new record, as its next element. */ theTable[hashIndex].last->next = theRecord; /* Reassign the 'final element' pointer to this new record. */ theTable[hashIndex].last = theRecord; - } - } /*! @@ -165,22 +162,21 @@ void deleteUser(hashSlot_t *theTable, char *aor, int hashTableSize) int hashIndex = calculateHashSlot(aor, hashTableSize); int searchStringLength = strlen(aor); - aorToIndexStruct_t *currentRecord = theTable[hashIndex].first; + aorToIndexStruct_t *currentRecord = theTable[hashIndex].first; - while (currentRecord != NULL) { + while(currentRecord != NULL) { /* First make sure both strings are the same length. If so, * then compare all bytes. If this succeeds, then we need to * link up the previous and next element together. */ - if (currentRecord->aorLength == searchStringLength && - memcmp(currentRecord->aor, aor, searchStringLength) == 0) { + if(currentRecord->aorLength == searchStringLength + && memcmp(currentRecord->aor, aor, searchStringLength) == 0) { currentRecord->numContacts--; /* There are still contacts relying on this user, so * don't delete anything. */ - if (currentRecord->numContacts > 0) - { + if(currentRecord->numContacts > 0) { return; } @@ -191,32 +187,26 @@ void deleteUser(hashSlot_t *theTable, char *aor, int hashTableSize) /* Maintenance of the hash table */ - if (currentRecord->prev == NULL) - { - /* Edge Case: First element in list was just deleted, so set + if(currentRecord->prev == NULL) { + /* Edge Case: First element in list was just deleted, so set * up the first element to point to the one after the one * just deleted */ - theTable[hashIndex].first = currentRecord->next; - } - else - { - /* Not the first element, so hook up the previous node to + theTable[hashIndex].first = currentRecord->next; + } else { + /* Not the first element, so hook up the previous node to * the node after the one just deleted. */ - currentRecord->prev->next = currentRecord->next; + currentRecord->prev->next = currentRecord->next; } - if (currentRecord->next == NULL) - { - /* Edge Case: The last element has been targetted for + if(currentRecord->next == NULL) { + /* Edge Case: The last element has been targetted for * deletion. So move the pointer to the node just before * this one. */ - theTable[hashIndex].last = currentRecord->prev; - } - else - { - /* Not the last element, so hook up next nodes previous + theTable[hashIndex].last = currentRecord->prev; + } else { + /* Not the last element, so hook up next nodes previous * element to this nodes previous. */ - currentRecord->next->prev = currentRecord->prev; + currentRecord->next->prev = currentRecord->prev; } pkg_free(currentRecord); @@ -228,7 +218,6 @@ void deleteUser(hashSlot_t *theTable, char *aor, int hashTableSize) /* Advance to the next records. */ currentRecord = currentRecord->next; } - } @@ -240,24 +229,23 @@ void deleteUser(hashSlot_t *theTable, char *aor, int hashTableSize) * directly to the parameter. Therefore make sure that aor is not on the stack, * and is not going to disappear before this record is deleted. */ -aorToIndexStruct_t *createHashRecord(int userIndex, char *aor) +aorToIndexStruct_t *createHashRecord(int userIndex, char *aor) { - int aorLength =strlen(aor); + int aorLength = strlen(aor); - aorToIndexStruct_t *theRecord = pkg_malloc(sizeof(aorToIndexStruct_t)+ - (aorLength+1)* sizeof(char)); - if (theRecord == NULL) - { + aorToIndexStruct_t *theRecord = pkg_malloc( + sizeof(aorToIndexStruct_t) + (aorLength + 1) * sizeof(char)); + if(theRecord == NULL) { LM_ERR("failed to create a mapping record for %s", aor); return NULL; } memset(theRecord, 0, sizeof(aorToIndexStruct_t)); - theRecord->aor = (char*)theRecord + sizeof(aorToIndexStruct_t); - memcpy(theRecord->aor, aor, aorLength ); + theRecord->aor = (char *)theRecord + sizeof(aorToIndexStruct_t); + memcpy(theRecord->aor, aor, aorLength); theRecord->aor[aorLength] = '\0'; - theRecord->aorLength = aorLength; + theRecord->aorLength = aorLength; theRecord->userIndex = userIndex; theRecord->numContacts = 1; @@ -265,18 +253,16 @@ aorToIndexStruct_t *createHashRecord(int userIndex, char *aor) } - - /*! Debugging function. Prints off an entire hash slot. */ -void printHashSlot(hashSlot_t *theTable, int index) +void printHashSlot(hashSlot_t *theTable, int index) { aorToIndexStruct_t *currentRecord = theTable[index].first; LM_ERR("dumping Hash Slot #%d\n", index); - while (currentRecord != NULL) { - LM_ERR( "\tString: %s - Index: %d\n", - currentRecord->aor, currentRecord->userIndex); + while(currentRecord != NULL) { + LM_ERR("\tString: %s - Index: %d\n", currentRecord->aor, + currentRecord->userIndex); currentRecord = currentRecord->next; } -} +} \ No newline at end of file diff --git a/src/modules/snmpstats/hashTable.h b/src/modules/snmpstats/hashTable.h index 0389c4c5b22..8fb9ff55857 100644 --- a/src/modules/snmpstats/hashTable.h +++ b/src/modules/snmpstats/hashTable.h @@ -56,7 +56,7 @@ * Used to map between a 'contact' name (Kamailio's index) and a contact index. * (SNMPStats Index) */ -typedef struct contactToIndexStruct +typedef struct contactToIndexStruct { char *contactName; @@ -72,11 +72,11 @@ typedef struct contactToIndexStruct * index). Since each user can have multiple contacts, the structure also has a * 'contactIndex', and a reference to the contactToIndexStruct list. */ -typedef struct aorToIndexStruct +typedef struct aorToIndexStruct { /* Pointer to the actual address record in the given SNMP row. */ char *aor; - int aorLength; + int aorLength; /* Points to the user index, which is used to uniquely identify each * SNMP row in a table. */ @@ -105,20 +105,20 @@ typedef struct aorToIndexStruct } aorToIndexStruct_t; -typedef struct hashSlot +typedef struct hashSlot { /*! Number of elements in this list. */ int numberOfElements; /*! First element in the list. */ - struct aorToIndexStruct* first; + struct aorToIndexStruct *first; /*! Last element in the list. This is here for optimization purposes. * It stands to reason that things added later will need to be deleted * later. So they should be added to the end of the list. This way, * things that are to be deleted sooner will be at the front of the * list. */ - struct aorToIndexStruct* last; + struct aorToIndexStruct *last; } hashSlot_t; @@ -140,7 +140,7 @@ aorToIndexStruct_t *createHashRecord(int userIndex, char *aor); /*! Returns a chunk of memory large enough to store 'size' hashSlot's. The * table will contain mappings between Kamailio's "aor" user/contact indexing * scheme, and SNMPStats integer indexing scheme */ -hashSlot_t *createHashTable(int size); +hashSlot_t *createHashTable(int size); /*! Calculates and returns a hash index to a hash table. The index is calculated @@ -164,7 +164,8 @@ aorToIndexStruct_t *findHashRecord(hashSlot_t *theTable, char *aor, int size); /*! Inserts theRecord into an appropriate place in theTable, when size is given. */ -void insertHashRecord(hashSlot_t *theTable, aorToIndexStruct_t *theRecord, int size); +void insertHashRecord( + hashSlot_t *theTable, aorToIndexStruct_t *theRecord, int size); /*! Debugging function. Prints off an entire hash slot. */ @@ -173,7 +174,7 @@ void printHashSlot(hashSlot_t *theTable, int index); /*! If a record is found with string aor in theTable, it is deleted and its * SNMPStats user integer index is returned. */ -int deleteHashRecord(hashSlot_t *theTable, char *aor, int hashTableSize); +int deleteHashRecord(hashSlot_t *theTable, char *aor, int hashTableSize); /*! * This function will search the provided hash table for an entry indexed by @@ -186,4 +187,4 @@ int deleteHashRecord(hashSlot_t *theTable, char *aor, int hashTableSize); */ void deleteUser(hashSlot_t *theTable, char *aor, int hashTableSize); -#endif +#endif \ No newline at end of file diff --git a/src/modules/snmpstats/interprocess_buffer.c b/src/modules/snmpstats/interprocess_buffer.c index 8edc0ea548d..2c31db3fe4e 100644 --- a/src/modules/snmpstats/interprocess_buffer.c +++ b/src/modules/snmpstats/interprocess_buffer.c @@ -65,7 +65,7 @@ interprocessBuffer_t *endRegUserTableBuffer = NULL; /*! This is to protect the potential racecondition in which a command is added to * the buffer while it is being consumed */ -gen_lock_t *interprocessCBLock = NULL; +gen_lock_t *interprocessCBLock = NULL; /*! * This function takes an element of the interprocess buffer passed to it, and @@ -78,29 +78,27 @@ static void executeInterprocessBufferCmd(interprocessBuffer_t *currentBuffer); * Initialize shared memory used to buffer communication between the usrloc * module and the SNMPStats module. (Specifically, the user and contact tables) */ -int initInterprocessBuffers(void) +int initInterprocessBuffers(void) { /* Initialize the shared memory that will be used to buffer messages * over the usrloc module to RegUserTable callback. */ - frontRegUserTableBuffer = shm_malloc(sizeof(interprocessBuffer_t)); - endRegUserTableBuffer = shm_malloc(sizeof(interprocessBuffer_t)); + frontRegUserTableBuffer = shm_malloc(sizeof(interprocessBuffer_t)); + endRegUserTableBuffer = shm_malloc(sizeof(interprocessBuffer_t)); - if(frontRegUserTableBuffer == NULL || endRegUserTableBuffer == NULL) - { + if(frontRegUserTableBuffer == NULL || endRegUserTableBuffer == NULL) { LM_ERR("no more shared memory\n"); return -1; } memset(frontRegUserTableBuffer, 0x00, sizeof(interprocessBuffer_t)); - memset(endRegUserTableBuffer, 0x00, sizeof(interprocessBuffer_t)); + memset(endRegUserTableBuffer, 0x00, sizeof(interprocessBuffer_t)); /* Initialize a lock to the interprocess buffer. The lock will be used * to control race-conditions that would otherwise occur if an snmp * command was received while the interprocess buffer was being consumed. */ interprocessCBLock = lock_alloc(); - if(interprocessCBLock==NULL) - { + if(interprocessCBLock == NULL) { LM_ERR("cannot allocate the lock\n"); shm_free(frontRegUserTableBuffer); frontRegUserTableBuffer = NULL; @@ -111,8 +109,7 @@ int initInterprocessBuffers(void) lock_init(interprocessCBLock); hashTable = createHashTable(HASH_SIZE); - if(hashTable == NULL) - { + if(hashTable == NULL) { LM_ERR("no more shared memory\n"); lock_destroy(interprocessCBLock); lock_dealloc(interprocessCBLock); @@ -140,7 +137,7 @@ int initInterprocessBuffers(void) * any race conditions between this function and the consumeInterprocessBuffer() * function. */ -void handleContactCallbacks(ucontact_t *contactInfo, int type, void *param) +void handleContactCallbacks(ucontact_t *contactInfo, int type, void *param) { char *addressOfRecord; char *contact; @@ -149,8 +146,7 @@ void handleContactCallbacks(ucontact_t *contactInfo, int type, void *param) currentBufferElement = shm_malloc(sizeof(interprocessBuffer_t)); - if (currentBufferElement == NULL) - { + if(currentBufferElement == NULL) { goto error; } @@ -160,14 +156,14 @@ void handleContactCallbacks(ucontact_t *contactInfo, int type, void *param) * If we do not maintain our own copies, then the AOR and contact adress * pointed to could be removed and reallocated to another thread before * we get a chance to consume our interprocess buffer. */ - convertStrToCharString(contactInfo->aor, &addressOfRecord); + convertStrToCharString(contactInfo->aor, &addressOfRecord); convertStrToCharString(&(contactInfo->c), &contact); - currentBufferElement->stringName = addressOfRecord; + currentBufferElement->stringName = addressOfRecord; currentBufferElement->stringContact = contact; - currentBufferElement->contactInfo = contactInfo; - currentBufferElement->callbackType = type; - currentBufferElement->next = NULL; + currentBufferElement->contactInfo = contactInfo; + currentBufferElement->callbackType = type; + currentBufferElement->next = NULL; /* A lock is necessary to prevent a race condition. Specifically, it @@ -177,21 +173,22 @@ void handleContactCallbacks(ucontact_t *contactInfo, int type, void *param) lock_get(interprocessCBLock); /* This is the first element to be added. */ - if (frontRegUserTableBuffer->next == NULL) { + if(frontRegUserTableBuffer->next == NULL) { frontRegUserTableBuffer->next = currentBufferElement; } else { endRegUserTableBuffer->next->next = currentBufferElement; } - - endRegUserTableBuffer->next = currentBufferElement; + + endRegUserTableBuffer->next = currentBufferElement; lock_release(interprocessCBLock); - + return; error: LM_ERR("Not enough shared memory for kamailioSIPRegUserTable insert." - " (%s)\n", contactInfo->c.s); + " (%s)\n", + contactInfo->c.s); } @@ -212,14 +209,13 @@ void handleContactCallbacks(ucontact_t *contactInfo, int type, void *param) * This is made possible by simply changing the head of the interprocess * buffer, and then releasing the lock. */ -void consumeInterprocessBuffer(void) +void consumeInterprocessBuffer(void) { interprocessBuffer_t *previousBuffer; interprocessBuffer_t *currentBuffer; - + /* There is nothing to consume, so just exit. */ - if (frontRegUserTableBuffer->next == NULL) - { + if(frontRegUserTableBuffer->next == NULL) { return; } @@ -231,13 +227,13 @@ void consumeInterprocessBuffer(void) lock_get(interprocessCBLock); currentBuffer = frontRegUserTableBuffer->next; - + frontRegUserTableBuffer->next = NULL; - endRegUserTableBuffer->next = NULL; + endRegUserTableBuffer->next = NULL; lock_release(interprocessCBLock); - while (currentBuffer != NULL) { + while(currentBuffer != NULL) { executeInterprocessBufferCmd(currentBuffer); @@ -250,9 +246,7 @@ void consumeInterprocessBuffer(void) shm_free(previousBuffer->stringName); shm_free(previousBuffer->stringContact); shm_free(previousBuffer); - } - } @@ -261,92 +255,82 @@ void consumeInterprocessBuffer(void) * handles populating the respective user and contact tables with its contained * data. */ -static void executeInterprocessBufferCmd(interprocessBuffer_t *currentBuffer) +static void executeInterprocessBufferCmd(interprocessBuffer_t *currentBuffer) { int delContactIndex; aorToIndexStruct_t *currentUser; - if (currentBuffer->callbackType == UL_CONTACT_INSERT) - { + if(currentBuffer->callbackType == UL_CONTACT_INSERT) { /* Add the user if the user doesn't exist, or increment its * contact index otherwise. */ updateUser(currentBuffer->stringName); - } - else if (currentBuffer->callbackType != UL_CONTACT_EXPIRE) - { + } else if(currentBuffer->callbackType != UL_CONTACT_EXPIRE) { /* Currently we only support UL_CONTACT_INSERT and * UL_CONTACT_EXPIRE. If we receive another callback type, this * is a bug. */ LM_ERR("found a command on the interprocess buffer that" - " was not an INSERT or EXPIRE"); + " was not an INSERT or EXPIRE"); return; } currentUser = - findHashRecord(hashTable, currentBuffer->stringName, HASH_SIZE); + findHashRecord(hashTable, currentBuffer->stringName, HASH_SIZE); /* This should never happen. This is more of a sanity check. */ - if (currentUser == NULL) { + if(currentUser == NULL) { LM_ERR("Received a request for contact: %s for user: %s who doesn't " - "exists\n", currentBuffer->stringName, - currentBuffer->stringContact); + "exists\n", + currentBuffer->stringName, currentBuffer->stringContact); return; - } + } /* This buffer element specified that we need to add a contact. So lets * add them */ - if (currentBuffer->callbackType == UL_CONTACT_INSERT) { + if(currentBuffer->callbackType == UL_CONTACT_INSERT) { /* Increment the contact index, which will be used to generate - * our new row. */ + * our new row. */ currentUser->contactIndex++; /* We should do this after we create the row in the snmptable. * Its easier to delete the SNMP Row than the contact record. */ - if(!insertContactRecord(&(currentUser->contactList), - currentUser->contactIndex, - currentBuffer->stringContact)) { + if(!insertContactRecord(&(currentUser->contactList), + currentUser->contactIndex, currentBuffer->stringContact)) { LM_ERR("kamailioSIPRegUserTable was unable to allocate memory for " - "adding contact: %s to user %s.\n", + "adding contact: %s to user %s.\n", currentBuffer->stringName, currentBuffer->stringContact); /* We didn't use the index, so decrement it so we can * use it next time around. */ currentUser->contactIndex--; - + return; } - - if (!createContactRow(currentUser->userIndex, - currentUser->contactIndex, - currentBuffer->stringContact, - currentBuffer->contactInfo)) { - - deleteContactRecord(&(currentUser->contactList), - currentBuffer->stringContact); + if(!createContactRow(currentUser->userIndex, currentUser->contactIndex, + currentBuffer->stringContact, currentBuffer->contactInfo)) { + + deleteContactRecord( + &(currentUser->contactList), currentBuffer->stringContact); } - } - else { + } else { - delContactIndex = - deleteContactRecord(&(currentUser->contactList), - currentBuffer->stringContact); + delContactIndex = deleteContactRecord( + &(currentUser->contactList), currentBuffer->stringContact); /* This should never happen. But its probably wise to check and * to print out debug messages in case there is a hidden bug. */ if(delContactIndex == 0) { - + LM_ERR("Received a request to delete contact: %s for user: %s" - " who doesn't exist\n", currentBuffer->stringName, - currentBuffer->stringContact); + " who doesn't exist\n", + currentBuffer->stringName, currentBuffer->stringContact); return; - - } + } deleteContactRow(currentUser->userIndex, delContactIndex); @@ -358,27 +342,25 @@ void freeInterprocessBuffer(void) { interprocessBuffer_t *currentBuffer, *previousBuffer; - if (frontRegUserTableBuffer==NULL - || frontRegUserTableBuffer->next == NULL - || endRegUserTableBuffer==NULL) { + if(frontRegUserTableBuffer == NULL || frontRegUserTableBuffer->next == NULL + || endRegUserTableBuffer == NULL) { LM_DBG("Nothing to clean\n"); return; } currentBuffer = frontRegUserTableBuffer->next; - + frontRegUserTableBuffer->next = NULL; - endRegUserTableBuffer->next = NULL; + endRegUserTableBuffer->next = NULL; - while (currentBuffer != NULL) { + while(currentBuffer != NULL) { previousBuffer = currentBuffer; currentBuffer = currentBuffer->next; shm_free(previousBuffer->stringName); shm_free(previousBuffer->stringContact); shm_free(previousBuffer); - } if(frontRegUserTableBuffer) @@ -386,5 +368,4 @@ void freeInterprocessBuffer(void) if(endRegUserTableBuffer) shm_free(endRegUserTableBuffer); - -} +} \ No newline at end of file diff --git a/src/modules/snmpstats/interprocess_buffer.h b/src/modules/snmpstats/interprocess_buffer.h index dfdf81e307d..36298b5fc39 100644 --- a/src/modules/snmpstats/interprocess_buffer.h +++ b/src/modules/snmpstats/interprocess_buffer.h @@ -59,15 +59,14 @@ #include "../usrloc/ucontact.h" /* Represents an element of the interprocess buffer. */ -typedef struct interprocessBuffer +typedef struct interprocessBuffer { - char *stringName; - char *stringContact; - int callbackType; + char *stringName; + char *stringContact; + int callbackType; struct interprocessBuffer *next; ucontact_t *contactInfo; - } interprocessBuffer_t; /* Both of these will be used to reference in the interprocess buffer */ @@ -77,14 +76,14 @@ extern interprocessBuffer_t *endRegUserTableBuffer; /* A request to consume the interprocess buffer could occur at the same time * there is a request to add to the interprocess buffer. (Or vice-versa). This * lock is used to prevent these race conditions. */ -extern gen_lock_t *interprocessCBLock; -extern hashSlot_t *hashTable; +extern gen_lock_t *interprocessCBLock; +extern hashSlot_t *hashTable; /* * Initialize shared memory used to buffer communication between the usrloc * module and the SNMPStats module. (Specifically, the user and contact tables) */ -int initInterprocessBuffers(void); +int initInterprocessBuffers(void); /* USRLOC Callback Handler: * @@ -124,4 +123,4 @@ void consumeInterprocessBuffer(void); void freeInterprocessBuffer(void); -#endif +#endif \ No newline at end of file diff --git a/src/modules/snmpstats/kamailioNet.c b/src/modules/snmpstats/kamailioNet.c index 276f9fc1580..282c15e4b7a 100644 --- a/src/modules/snmpstats/kamailioNet.c +++ b/src/modules/snmpstats/kamailioNet.c @@ -45,1308 +45,1314 @@ #include "../../core/tcp_options.h" /** Initializes the kamailioNet module */ -void -init_kamailioNet(void) +void init_kamailioNet(void) { - oid kamailioNetTcpConnEstablished_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,2,1 }; - oid kamailioNetTcpConnFailed_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,2,2 }; - oid kamailioNetTcpConnReset_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,2,3 }; - oid kamailioNetTcpConnSuccess_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,2,4 }; - oid kamailioNetTcpConnOpen_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,2,5 }; - oid kamailioNetTcpConnPassiveOpen_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,2,6 }; - oid kamailioNetTcpConnReject_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,2,8 }; - oid kamailioNetTcpEnabled_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,1 }; - oid kamailioNetTcpMaxConns_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,2 }; - oid kamailioNetTcpConnTimeout_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,3 }; - oid kamailioNetTcpSendTimeout_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,4 }; - oid kamailioNetTcpConnLifetime_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,5 }; - oid kamailioNetTcpNoConnect_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,7 }; - oid kamailioNetTcpFdCache_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,8 }; - oid kamailioNetTcpAsync_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,9 }; - oid kamailioNetTcpAsyncConnWait_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,10 }; - oid kamailioNetTcpAsyncConnWqMax_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,11 }; - oid kamailioNetTcpAsyncWqMax_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,12 }; - oid kamailioNetTcpRdBufSize_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,13 }; - oid kamailioNetTcpDeferAccept_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,14 }; - oid kamailioNetTcpDelayedAck_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,15 }; - oid kamailioNetTcpSynCnt_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,16 }; - oid kamailioNetTcpLinger_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,17 }; - oid kamailioNetTcpKeepAlive_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,18 }; - oid kamailioNetTcpKeepIdle_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,19 }; - oid kamailioNetTcpKeepIntvl_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,20 }; - oid kamailioNetTcpKeepCnt_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,21 }; - oid kamailioNetTcpCrlfPing_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,22 }; - oid kamailioNetTcpAcceptAliases_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,23 }; - oid kamailioNetTcpAcceptNoCl_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,24 }; - - /* WebSockets */ - oid kamailioNetWsConnsActive_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,2,1,1 }; - oid kamailioNetWsConnsActiveMax_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,2,1,2 }; - oid kamailioNetWsConnsFailed_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,2,1,3 }; - oid kamailioNetWsConnsClosedLocal_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,2,1,4 }; - oid kamailioNetWsConnsClosedRemote_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,2,1,5 }; - oid kamailioNetWsFramesRx_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,2,1,6 }; - oid kamailioNetWsFramesTx_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,2,1,7 }; - oid kamailioNetWsHandshakeSuccess_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,2,1,8 }; - oid kamailioNetWsHandshakeFailed_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,2,1,9 }; - - DEBUGMSGTL(("kamailioNet", "Initializing\n")); - - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpConnEstablished", handle_kamailioNetTcpConnEstablished, - kamailioNetTcpConnEstablished_oid, OID_LENGTH(kamailioNetTcpConnEstablished_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpConnFailed", handle_kamailioNetTcpConnFailed, - kamailioNetTcpConnFailed_oid, OID_LENGTH(kamailioNetTcpConnFailed_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpConnReset", handle_kamailioNetTcpConnReset, - kamailioNetTcpConnReset_oid, OID_LENGTH(kamailioNetTcpConnReset_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpConnSuccess", handle_kamailioNetTcpConnSuccess, - kamailioNetTcpConnSuccess_oid, OID_LENGTH(kamailioNetTcpConnSuccess_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpConnOped", handle_kamailioNetTcpConnOpen, - kamailioNetTcpConnOpen_oid, OID_LENGTH(kamailioNetTcpConnOpen_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpConnPassiveOpen", handle_kamailioNetTcpConnPassiveOpen, - kamailioNetTcpConnPassiveOpen_oid, OID_LENGTH(kamailioNetTcpConnPassiveOpen_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpConnReject", handle_kamailioNetTcpConnReject, - kamailioNetTcpConnReject_oid, OID_LENGTH(kamailioNetTcpConnReject_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpEnabled", handle_kamailioNetTcpEnabled, - kamailioNetTcpEnabled_oid, OID_LENGTH(kamailioNetTcpEnabled_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpMaxConns", handle_kamailioNetTcpMaxConns, - kamailioNetTcpMaxConns_oid, OID_LENGTH(kamailioNetTcpMaxConns_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpConnTimeout", handle_kamailioNetTcpConnTimeout, - kamailioNetTcpConnTimeout_oid, OID_LENGTH(kamailioNetTcpConnTimeout_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpSendTimeout", handle_kamailioNetTcpSendTimeout, - kamailioNetTcpSendTimeout_oid, OID_LENGTH(kamailioNetTcpSendTimeout_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpConnLifetime", handle_kamailioNetTcpConnLifetime, - kamailioNetTcpConnLifetime_oid, OID_LENGTH(kamailioNetTcpConnLifetime_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpNoConnect", handle_kamailioNetTcpNoConnect, - kamailioNetTcpNoConnect_oid, OID_LENGTH(kamailioNetTcpNoConnect_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpFdCache", handle_kamailioNetTcpFdCache, - kamailioNetTcpFdCache_oid, OID_LENGTH(kamailioNetTcpFdCache_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpAsync", handle_kamailioNetTcpAsync, - kamailioNetTcpAsync_oid, OID_LENGTH(kamailioNetTcpAsync_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpAsyncConnWait", handle_kamailioNetTcpAsyncConnWait, - kamailioNetTcpAsyncConnWait_oid, OID_LENGTH(kamailioNetTcpAsyncConnWait_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpAsyncConnWqMax", handle_kamailioNetTcpAsyncConnWqMax, - kamailioNetTcpAsyncConnWqMax_oid, OID_LENGTH(kamailioNetTcpAsyncConnWqMax_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpAsyncWqMax", handle_kamailioNetTcpAsyncWqMax, - kamailioNetTcpAsyncWqMax_oid, OID_LENGTH(kamailioNetTcpAsyncWqMax_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpRdBufSize", handle_kamailioNetTcpRdBufSize, - kamailioNetTcpRdBufSize_oid, OID_LENGTH(kamailioNetTcpRdBufSize_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpDeferAccept", handle_kamailioNetTcpDeferAccept, - kamailioNetTcpDeferAccept_oid, OID_LENGTH(kamailioNetTcpDeferAccept_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpDelayedAck", handle_kamailioNetTcpDelayedAck, - kamailioNetTcpDelayedAck_oid, OID_LENGTH(kamailioNetTcpDelayedAck_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpSynCnt", handle_kamailioNetTcpSynCnt, - kamailioNetTcpSynCnt_oid, OID_LENGTH(kamailioNetTcpSynCnt_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpLinger", handle_kamailioNetTcpLinger, - kamailioNetTcpLinger_oid, OID_LENGTH(kamailioNetTcpLinger_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpKeepAlive", handle_kamailioNetTcpKeepAlive, - kamailioNetTcpKeepAlive_oid, OID_LENGTH(kamailioNetTcpKeepAlive_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpKeepIdle", handle_kamailioNetTcpKeepIdle, - kamailioNetTcpKeepIdle_oid, OID_LENGTH(kamailioNetTcpKeepIdle_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpKeepIntvl", handle_kamailioNetTcpKeepIntvl, - kamailioNetTcpKeepIntvl_oid, OID_LENGTH(kamailioNetTcpKeepIntvl_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpKeepCnt", handle_kamailioNetTcpKeepCnt, - kamailioNetTcpKeepCnt_oid, OID_LENGTH(kamailioNetTcpKeepCnt_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpCrlfPing", handle_kamailioNetTcpCrlfPing, - kamailioNetTcpCrlfPing_oid, OID_LENGTH(kamailioNetTcpCrlfPing_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpAcceptAliases", handle_kamailioNetTcpAcceptAliases, - kamailioNetTcpAcceptAliases_oid, OID_LENGTH(kamailioNetTcpAcceptAliases_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetTcpAcceptNoCl", handle_kamailioNetTcpAcceptNoCl, - kamailioNetTcpAcceptNoCl_oid, OID_LENGTH(kamailioNetTcpAcceptNoCl_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetWsConnsActive", handle_kamailioNetWsConnsActive, - kamailioNetWsConnsActive_oid, OID_LENGTH(kamailioNetWsConnsActive_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetWsConnsActiveMax", handle_kamailioNetWsConnsActiveMax, - kamailioNetWsConnsActiveMax_oid, OID_LENGTH(kamailioNetWsConnsActiveMax_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetWsConnsFailed", handle_kamailioNetWsConnsFailed, - kamailioNetWsConnsFailed_oid, OID_LENGTH(kamailioNetWsConnsFailed_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetWsConnsClosedLocal", handle_kamailioNetWsConnsClosedLocal, - kamailioNetWsConnsClosedLocal_oid, OID_LENGTH(kamailioNetWsConnsClosedLocal_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetWsConnsClosedRemote", handle_kamailioNetWsConnsClosedRemote, - kamailioNetWsConnsClosedRemote_oid, OID_LENGTH(kamailioNetWsConnsClosedRemote_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetWsFramesRx", handle_kamailioNetWsFramesRx, - kamailioNetWsFramesRx_oid, OID_LENGTH(kamailioNetWsFramesRx_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetWsFramesTx", handle_kamailioNetWsFramesTx, - kamailioNetWsFramesTx_oid, OID_LENGTH(kamailioNetWsFramesTx_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetWsHandshakeSuccess", handle_kamailioNetWsHandshakeSuccess, - kamailioNetWsHandshakeSuccess_oid, OID_LENGTH(kamailioNetWsHandshakeSuccess_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetWsHandshakeFailed", handle_kamailioNetWsHandshakeFailed, - kamailioNetWsHandshakeFailed_oid, OID_LENGTH(kamailioNetWsHandshakeFailed_oid), - HANDLER_CAN_RONLY - )); + oid kamailioNetTcpConnEstablished_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 2, 1}; + oid kamailioNetTcpConnFailed_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 2, 2}; + oid kamailioNetTcpConnReset_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 2, 3}; + oid kamailioNetTcpConnSuccess_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 2, 4}; + oid kamailioNetTcpConnOpen_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 2, 5}; + oid kamailioNetTcpConnPassiveOpen_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 2, 6}; + oid kamailioNetTcpConnReject_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 2, 8}; + oid kamailioNetTcpEnabled_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 1}; + oid kamailioNetTcpMaxConns_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 2}; + oid kamailioNetTcpConnTimeout_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 3}; + oid kamailioNetTcpSendTimeout_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 4}; + oid kamailioNetTcpConnLifetime_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 5}; + oid kamailioNetTcpNoConnect_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 7}; + oid kamailioNetTcpFdCache_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 8}; + oid kamailioNetTcpAsync_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 9}; + oid kamailioNetTcpAsyncConnWait_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 10}; + oid kamailioNetTcpAsyncConnWqMax_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 11}; + oid kamailioNetTcpAsyncWqMax_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 12}; + oid kamailioNetTcpRdBufSize_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 13}; + oid kamailioNetTcpDeferAccept_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 14}; + oid kamailioNetTcpDelayedAck_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 15}; + oid kamailioNetTcpSynCnt_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 16}; + oid kamailioNetTcpLinger_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 17}; + oid kamailioNetTcpKeepAlive_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 18}; + oid kamailioNetTcpKeepIdle_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 19}; + oid kamailioNetTcpKeepIntvl_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 20}; + oid kamailioNetTcpKeepCnt_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 21}; + oid kamailioNetTcpCrlfPing_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 22}; + oid kamailioNetTcpAcceptAliases_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 23}; + oid kamailioNetTcpAcceptNoCl_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 1, 3, 24}; + + /* WebSockets */ + oid kamailioNetWsConnsActive_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 2, 1, 1}; + oid kamailioNetWsConnsActiveMax_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 2, 1, 2}; + oid kamailioNetWsConnsFailed_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 2, 1, 3}; + oid kamailioNetWsConnsClosedLocal_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 2, 1, 4}; + oid kamailioNetWsConnsClosedRemote_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 2, 1, 5}; + oid kamailioNetWsFramesRx_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 2, 1, 6}; + oid kamailioNetWsFramesTx_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 2, 1, 7}; + oid kamailioNetWsHandshakeSuccess_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 2, 1, 8}; + oid kamailioNetWsHandshakeFailed_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 2, 1, 9}; + + DEBUGMSGTL(("kamailioNet", "Initializing\n")); + + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpConnEstablished", + handle_kamailioNetTcpConnEstablished, + kamailioNetTcpConnEstablished_oid, + OID_LENGTH(kamailioNetTcpConnEstablished_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpConnFailed", handle_kamailioNetTcpConnFailed, + kamailioNetTcpConnFailed_oid, + OID_LENGTH(kamailioNetTcpConnFailed_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpConnReset", handle_kamailioNetTcpConnReset, + kamailioNetTcpConnReset_oid, + OID_LENGTH(kamailioNetTcpConnReset_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpConnSuccess", handle_kamailioNetTcpConnSuccess, + kamailioNetTcpConnSuccess_oid, + OID_LENGTH(kamailioNetTcpConnSuccess_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioNetTcpConnOped", + handle_kamailioNetTcpConnOpen, kamailioNetTcpConnOpen_oid, + OID_LENGTH(kamailioNetTcpConnOpen_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpConnPassiveOpen", + handle_kamailioNetTcpConnPassiveOpen, + kamailioNetTcpConnPassiveOpen_oid, + OID_LENGTH(kamailioNetTcpConnPassiveOpen_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpConnReject", handle_kamailioNetTcpConnReject, + kamailioNetTcpConnReject_oid, + OID_LENGTH(kamailioNetTcpConnReject_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioNetTcpEnabled", + handle_kamailioNetTcpEnabled, kamailioNetTcpEnabled_oid, + OID_LENGTH(kamailioNetTcpEnabled_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioNetTcpMaxConns", + handle_kamailioNetTcpMaxConns, kamailioNetTcpMaxConns_oid, + OID_LENGTH(kamailioNetTcpMaxConns_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpConnTimeout", handle_kamailioNetTcpConnTimeout, + kamailioNetTcpConnTimeout_oid, + OID_LENGTH(kamailioNetTcpConnTimeout_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpSendTimeout", handle_kamailioNetTcpSendTimeout, + kamailioNetTcpSendTimeout_oid, + OID_LENGTH(kamailioNetTcpSendTimeout_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpConnLifetime", handle_kamailioNetTcpConnLifetime, + kamailioNetTcpConnLifetime_oid, + OID_LENGTH(kamailioNetTcpConnLifetime_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpNoConnect", handle_kamailioNetTcpNoConnect, + kamailioNetTcpNoConnect_oid, + OID_LENGTH(kamailioNetTcpNoConnect_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioNetTcpFdCache", + handle_kamailioNetTcpFdCache, kamailioNetTcpFdCache_oid, + OID_LENGTH(kamailioNetTcpFdCache_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioNetTcpAsync", + handle_kamailioNetTcpAsync, kamailioNetTcpAsync_oid, + OID_LENGTH(kamailioNetTcpAsync_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpAsyncConnWait", handle_kamailioNetTcpAsyncConnWait, + kamailioNetTcpAsyncConnWait_oid, + OID_LENGTH(kamailioNetTcpAsyncConnWait_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpAsyncConnWqMax", handle_kamailioNetTcpAsyncConnWqMax, + kamailioNetTcpAsyncConnWqMax_oid, + OID_LENGTH(kamailioNetTcpAsyncConnWqMax_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpAsyncWqMax", handle_kamailioNetTcpAsyncWqMax, + kamailioNetTcpAsyncWqMax_oid, + OID_LENGTH(kamailioNetTcpAsyncWqMax_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpRdBufSize", handle_kamailioNetTcpRdBufSize, + kamailioNetTcpRdBufSize_oid, + OID_LENGTH(kamailioNetTcpRdBufSize_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpDeferAccept", handle_kamailioNetTcpDeferAccept, + kamailioNetTcpDeferAccept_oid, + OID_LENGTH(kamailioNetTcpDeferAccept_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpDelayedAck", handle_kamailioNetTcpDelayedAck, + kamailioNetTcpDelayedAck_oid, + OID_LENGTH(kamailioNetTcpDelayedAck_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioNetTcpSynCnt", + handle_kamailioNetTcpSynCnt, kamailioNetTcpSynCnt_oid, + OID_LENGTH(kamailioNetTcpSynCnt_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioNetTcpLinger", + handle_kamailioNetTcpLinger, kamailioNetTcpLinger_oid, + OID_LENGTH(kamailioNetTcpLinger_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpKeepAlive", handle_kamailioNetTcpKeepAlive, + kamailioNetTcpKeepAlive_oid, + OID_LENGTH(kamailioNetTcpKeepAlive_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioNetTcpKeepIdle", + handle_kamailioNetTcpKeepIdle, kamailioNetTcpKeepIdle_oid, + OID_LENGTH(kamailioNetTcpKeepIdle_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpKeepIntvl", handle_kamailioNetTcpKeepIntvl, + kamailioNetTcpKeepIntvl_oid, + OID_LENGTH(kamailioNetTcpKeepIntvl_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioNetTcpKeepCnt", + handle_kamailioNetTcpKeepCnt, kamailioNetTcpKeepCnt_oid, + OID_LENGTH(kamailioNetTcpKeepCnt_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioNetTcpCrlfPing", + handle_kamailioNetTcpCrlfPing, kamailioNetTcpCrlfPing_oid, + OID_LENGTH(kamailioNetTcpCrlfPing_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpAcceptAliases", handle_kamailioNetTcpAcceptAliases, + kamailioNetTcpAcceptAliases_oid, + OID_LENGTH(kamailioNetTcpAcceptAliases_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetTcpAcceptNoCl", handle_kamailioNetTcpAcceptNoCl, + kamailioNetTcpAcceptNoCl_oid, + OID_LENGTH(kamailioNetTcpAcceptNoCl_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetWsConnsActive", handle_kamailioNetWsConnsActive, + kamailioNetWsConnsActive_oid, + OID_LENGTH(kamailioNetWsConnsActive_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetWsConnsActiveMax", handle_kamailioNetWsConnsActiveMax, + kamailioNetWsConnsActiveMax_oid, + OID_LENGTH(kamailioNetWsConnsActiveMax_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetWsConnsFailed", handle_kamailioNetWsConnsFailed, + kamailioNetWsConnsFailed_oid, + OID_LENGTH(kamailioNetWsConnsFailed_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetWsConnsClosedLocal", + handle_kamailioNetWsConnsClosedLocal, + kamailioNetWsConnsClosedLocal_oid, + OID_LENGTH(kamailioNetWsConnsClosedLocal_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetWsConnsClosedRemote", + handle_kamailioNetWsConnsClosedRemote, + kamailioNetWsConnsClosedRemote_oid, + OID_LENGTH(kamailioNetWsConnsClosedRemote_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioNetWsFramesRx", + handle_kamailioNetWsFramesRx, kamailioNetWsFramesRx_oid, + OID_LENGTH(kamailioNetWsFramesRx_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioNetWsFramesTx", + handle_kamailioNetWsFramesTx, kamailioNetWsFramesTx_oid, + OID_LENGTH(kamailioNetWsFramesTx_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetWsHandshakeSuccess", + handle_kamailioNetWsHandshakeSuccess, + kamailioNetWsHandshakeSuccess_oid, + OID_LENGTH(kamailioNetWsHandshakeSuccess_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetWsHandshakeFailed", handle_kamailioNetWsHandshakeFailed, + kamailioNetWsHandshakeFailed_oid, + OID_LENGTH(kamailioNetWsHandshakeFailed_oid), HANDLER_CAN_RONLY)); } -int -handle_kamailioNetTcpConnEstablished(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpConnEstablished(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - /* We are never called for a GETNEXT if it's registered as a + /* We are never called for a GETNEXT if it's registered as a "instance", as it's "magically" handled for us. */ - /* a instance handler also only hands us one request at a time, so + /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ int datafield = get_statistic("established"); - - switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &datafield, sizeof(int)); - break; + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, + (u_char *)&datafield, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpConnEstablished\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - return SNMP_ERR_NOERROR; + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, "unknown mode (%d) in " + "handle_kamailioNetTcpConnEstablished\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpConnFailed(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpConnFailed(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int datafield = get_statistic("connect_failed"); - - switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &datafield, sizeof(int)); - break; + switch(reqinfo->mode) { + + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, + (u_char *)&datafield, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpConnFailed\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpConnFailed\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpConnReset(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpConnReset(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int datafield = get_statistic("con_reset"); - - switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &datafield, sizeof(int)); - break; + switch(reqinfo->mode) { + + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, + (u_char *)&datafield, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpConnReset\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpConnReset\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpConnSuccess(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpConnSuccess(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int datafield = get_statistic("connect_success"); - - switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &datafield, sizeof(int)); - break; + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, + (u_char *)&datafield, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpConnSuccess\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - return SNMP_ERR_NOERROR; + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpConnSuccess\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpConnOpen(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpConnOpen(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int datafield = get_statistic("current_opened_connections"); - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, - (u_char *) &datafield, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, + (u_char *)&datafield, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpConnOpen\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpConnOpen\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpConnPassiveOpen(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpConnPassiveOpen(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int datafield = get_statistic("passive_open"); - - switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &datafield, sizeof(int)); - break; + switch(reqinfo->mode) { + + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, + (u_char *)&datafield, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpConnPassiveOpen\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, "unknown mode (%d) in " + "handle_kamailioNetTcpConnPassiveOpen\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpConnReject(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpConnReject(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - /* We are never called for a GETNEXT if it's registered as a + /* We are never called for a GETNEXT if it's registered as a "instance", as it's "magically" handled for us. */ - /* a instance handler also only hands us one request at a time, so + /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ int datafield = get_statistic("local_reject"); - - switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &datafield, sizeof(int)); - break; + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, + (u_char *)&datafield, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpConnReject\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - return SNMP_ERR_NOERROR; + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpConnReject\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpEnabled(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpEnabled(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - /* We are never called for a GETNEXT if it's registered as a + /* We are never called for a GETNEXT if it's registered as a "instance", as it's "magically" handled for us. */ - /* a instance handler also only hands us one request at a time, so + /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ int enabled = (tcp_disable == 0); - - switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &enabled, sizeof(int)); - break; + switch(reqinfo->mode) { + + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&enabled, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpEnabled\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpEnabled\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpMaxConns(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpMaxConns(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int maxconn; + struct cfg_group_tcp t; + unsigned int maxconn; - tcp_options_get(&t); - maxconn = t.max_connections; + tcp_options_get(&t); + maxconn = t.max_connections; - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &maxconn, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&maxconn, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpMaxConns\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpMaxConns\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpAsync(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpAsync(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; - tcp_options_get(&t); - value = t.async; - /* We are never called for a GETNEXT if it's registered as a + tcp_options_get(&t); + value = t.async; + /* We are never called for a GETNEXT if it's registered as a "instance", as it's "magically" handled for us. */ - /* a instance handler also only hands us one request at a time, so + /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ - - switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { + + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpAsync\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpAsync\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpConnTimeout(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpConnTimeout(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; - tcp_options_get(&t); - value = t.connect_timeout_s; - - switch(reqinfo->mode) { + tcp_options_get(&t); + value = t.connect_timeout_s; - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpConnTimeout\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - return SNMP_ERR_NOERROR; + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpConnTimeout\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpSendTimeout(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpSendTimeout(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; + + tcp_options_get(&t); + value = t.send_timeout; - tcp_options_get(&t); - value = t.send_timeout; - - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpSendTimeout\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpSendTimeout\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpConnLifetime(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpConnLifetime(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; - tcp_options_get(&t); - value = t.con_lifetime; - - switch(reqinfo->mode) { + tcp_options_get(&t); + value = t.con_lifetime; - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpConnLifetime\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - return SNMP_ERR_NOERROR; + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpConnLifetime\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpNoConnect(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpNoConnect(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value ; + struct cfg_group_tcp t; + unsigned int value; + + tcp_options_get(&t); + value = t.no_connect; - tcp_options_get(&t); - value = t.no_connect; - - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpNoConnect\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpNoConnect\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpFdCache(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpFdCache(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; + + tcp_options_get(&t); + value = t.con_lifetime; - tcp_options_get(&t); - value = t.con_lifetime; - - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpFdCache\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpFdCache\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpAsyncConnWait(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpAsyncConnWait(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; - tcp_options_get(&t); - value = t.tcp_connect_wait; - - switch(reqinfo->mode) { + tcp_options_get(&t); + value = t.tcp_connect_wait; - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpAsyncConnWait\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - return SNMP_ERR_NOERROR; + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpAsyncConnWait\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpAsyncConnWqMax(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpAsyncConnWqMax(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; + + tcp_options_get(&t); + value = t.tcpconn_wq_max; - tcp_options_get(&t); - value = t.tcpconn_wq_max; - - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpAsyncConnWqMax\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, "unknown mode (%d) in " + "handle_kamailioNetTcpAsyncConnWqMax\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpAsyncWqMax(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpAsyncWqMax(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; - tcp_options_get(&t); - value = t.tcp_wq_max; - - switch(reqinfo->mode) { + tcp_options_get(&t); + value = t.tcp_wq_max; - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpAsyncWqMax\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - return SNMP_ERR_NOERROR; + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpAsyncWqMax\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpRdBufSize(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpRdBufSize(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; + + tcp_options_get(&t); + value = t.rd_buf_size; - tcp_options_get(&t); - value = t.rd_buf_size; - - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpRdBufSize\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpRdBufSize\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpDeferAccept(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpDeferAccept(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; - tcp_options_get(&t); - value = t.defer_accept; + tcp_options_get(&t); + value = t.defer_accept; - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpDeferAccept\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpDeferAccept\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpDelayedAck(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpDelayedAck(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; - tcp_options_get(&t); - value = t.delayed_ack; - - switch(reqinfo->mode) { + tcp_options_get(&t); + value = t.delayed_ack; - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpDelayedAck\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - return SNMP_ERR_NOERROR; + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpDelayedAck\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpSynCnt(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpSynCnt(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; + + tcp_options_get(&t); + value = t.syncnt; - tcp_options_get(&t); - value = t.syncnt; - - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpSynCnt\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpSynCnt\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpLinger(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpLinger(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; - tcp_options_get(&t); - value = t.linger2; - - switch(reqinfo->mode) { + tcp_options_get(&t); + value = t.linger2; - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpLinger\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - return SNMP_ERR_NOERROR; + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpLinger\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpKeepAlive(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpKeepAlive(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; + + tcp_options_get(&t); + value = t.keepalive; - tcp_options_get(&t); - value = t.keepalive; - - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpKeepAlive\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpKeepAlive\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpKeepIdle(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpKeepIdle(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; + + tcp_options_get(&t); + value = t.keepidle; - tcp_options_get(&t); - value = t.keepidle; - - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpKeepIdle\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpKeepIdle\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpKeepIntvl(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpKeepIntvl(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; - tcp_options_get(&t); - value = t.keepintvl; - - switch(reqinfo->mode) { + tcp_options_get(&t); + value = t.keepintvl; - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpKeepIntvl\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - return SNMP_ERR_NOERROR; + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpKeepIntvl\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpKeepCnt(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpKeepCnt(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; - tcp_options_get(&t); - value = t.keepcnt; + tcp_options_get(&t); + value = t.keepcnt; - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpKeepCnt\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpKeepCnt\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpCrlfPing(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpCrlfPing(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; + + tcp_options_get(&t); + value = t.crlf_ping; - tcp_options_get(&t); - value = t.crlf_ping; - - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpCrlfPing\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpCrlfPing\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetTcpAcceptAliases(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetTcpAcceptAliases(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; - tcp_options_get(&t); - value = t.accept_aliases; - - switch(reqinfo->mode) { + tcp_options_get(&t); + value = t.accept_aliases; - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpAcceptAliases\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - return SNMP_ERR_NOERROR; + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpAcceptAliases\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } int handle_kamailioNetTcpAcceptNoCl(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - struct cfg_group_tcp t; - unsigned int value; + struct cfg_group_tcp t; + unsigned int value; + + tcp_options_get(&t); + value = t.accept_no_cl; - tcp_options_get(&t); - value = t.accept_no_cl; - - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetTcpAcceptNoCl\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetTcpAcceptNoCl\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioNetWsConnsActive(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int datafield = get_statistic("ws_current_connections"); - - switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, - (u_char *) &datafield, sizeof(int)); - break; - - - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetWsConnsActive\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - - return SNMP_ERR_NOERROR; + int datafield = get_statistic("ws_current_connections"); + + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, + (u_char *)&datafield, sizeof(int)); + break; + + + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetWsConnsActive\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetWsConnsActiveMax(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetWsConnsActiveMax(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int datafield = get_statistic("ws_max_concurrent_connections"); - - switch(reqinfo->mode) { + int datafield = get_statistic("ws_max_concurrent_connections"); + + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, - (u_char *) &datafield, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, + (u_char *)&datafield, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetWsConnsActiveMax\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetWsConnsActiveMax\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetWsConnsFailed(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetWsConnsFailed(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int datafield = get_statistic("ws_failed_connections"); - - switch(reqinfo->mode) { + int datafield = get_statistic("ws_failed_connections"); + + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &datafield, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, + (u_char *)&datafield, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetWsConnsFailed\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetWsConnsFailed\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetWsConnsClosedLocal(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetWsConnsClosedLocal(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int datafield = get_statistic("ws_local_closed_connections"); - - switch(reqinfo->mode) { + int datafield = get_statistic("ws_local_closed_connections"); - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &datafield, sizeof(int)); - break; + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, + (u_char *)&datafield, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetWsConnsClosedLocal\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - return SNMP_ERR_NOERROR; + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, "unknown mode (%d) in " + "handle_kamailioNetWsConnsClosedLocal\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetWsConnsClosedRemote(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetWsConnsClosedRemote(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int datafield = get_statistic("ws_remote_closed_connections"); - - switch(reqinfo->mode) { + int datafield = get_statistic("ws_remote_closed_connections"); + + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &datafield, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, + (u_char *)&datafield, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetWsConnsClosedRemote\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, "unknown mode (%d) in " + "handle_kamailioNetWsConnsClosedRemote\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetWsFramesRx(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetWsFramesRx(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int datafield = get_statistic("ws_received_frames"); - - switch(reqinfo->mode) { + int datafield = get_statistic("ws_received_frames"); - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &datafield, sizeof(int)); - break; + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, + (u_char *)&datafield, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetWsFramesRx\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - return SNMP_ERR_NOERROR; + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetWsFramesRx\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetWsFramesTx(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetWsFramesTx(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int datafield = get_statistic("ws_transmitted_frames"); - - switch(reqinfo->mode) { + int datafield = get_statistic("ws_transmitted_frames"); + + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &datafield, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, + (u_char *)&datafield, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetWsFramesTx\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetWsFramesTx\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetWsHandshakeSuccess(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetWsHandshakeSuccess(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int datafield = get_statistic("ws_successful_handshakes"); - - switch(reqinfo->mode) { + int datafield = get_statistic("ws_successful_handshakes"); - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &datafield, sizeof(int)); - break; + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, + (u_char *)&datafield, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetWsHandshakeSuccess\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - return SNMP_ERR_NOERROR; + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, "unknown mode (%d) in " + "handle_kamailioNetWsHandshakeSuccess\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } -int -handle_kamailioNetWsHandshakeFailed(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) +int handle_kamailioNetWsHandshakeFailed(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int datafield = get_statistic("ws_failed_handshakes"); - - switch(reqinfo->mode) { + int datafield = get_statistic("ws_failed_handshakes"); + + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &datafield, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, + (u_char *)&datafield, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetWsHandshakeFailed\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, "unknown mode (%d) in " + "handle_kamailioNetWsHandshakeFailed\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } diff --git a/src/modules/snmpstats/kamailioNetConfig.c b/src/modules/snmpstats/kamailioNetConfig.c index de99b9697ef..99c2628dd10 100644 --- a/src/modules/snmpstats/kamailioNetConfig.c +++ b/src/modules/snmpstats/kamailioNetConfig.c @@ -49,402 +49,429 @@ #define CONST /** Initializes the kamailioNetConfig module */ -void -init_kamailioNetConfig(void) +void init_kamailioNetConfig(void) { - CONST oid kamailioNetConfUdpTransport_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,4,1 }; - CONST oid kamailioNetConfUdpDtlsTransport_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,4,2 }; - CONST oid kamailioNetConfTcpTransport_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,4,3 }; - CONST oid kamailioNetConfTcpTlsTransport_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,4,4 }; - CONST oid kamailioNetConfSctpTransport_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,4,5 }; - CONST oid kamailioNetConfSctpTlsTransport_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,4,6 }; - CONST oid kamailioNetConfWsTransport_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,4,7 }; - CONST oid kamailioNetConfWsTlsTransport_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,4,8 }; - CONST oid kamailioNetConfHttpServer_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,4,9 }; - CONST oid kamailioNetConfMsrpRelay_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,4,10 }; - CONST oid kamailioNetConfStunServer_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,4,11 }; - CONST oid kamailioNetConfOutbound_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,4,12 }; - - DEBUGMSGTL(("kamailioNetConfig", "Initializing\n")); - - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetConfUdpTransport", handle_kamailioNetConfUdpTransport, - kamailioNetConfUdpTransport_oid, OID_LENGTH(kamailioNetConfUdpTransport_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetConfUdpDtlsTransport", handle_kamailioNetConfUdpDtlsTransport, - kamailioNetConfUdpDtlsTransport_oid, OID_LENGTH(kamailioNetConfUdpDtlsTransport_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetConfTcpTransport", handle_kamailioNetConfTcpTransport, - kamailioNetConfTcpTransport_oid, OID_LENGTH(kamailioNetConfTcpTransport_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetConfTcpTlsTransport", handle_kamailioNetConfTcpTlsTransport, - kamailioNetConfTcpTlsTransport_oid, OID_LENGTH(kamailioNetConfTcpTlsTransport_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetConfSctpTransport", handle_kamailioNetConfSctpTransport, - kamailioNetConfSctpTransport_oid, OID_LENGTH(kamailioNetConfSctpTransport_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetConfSctpTlsTransport", handle_kamailioNetConfSctpTlsTransport, - kamailioNetConfSctpTlsTransport_oid, OID_LENGTH(kamailioNetConfSctpTlsTransport_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetConfWsTransport", handle_kamailioNetConfWsTransport, - kamailioNetConfWsTransport_oid, OID_LENGTH(kamailioNetConfWsTransport_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetConfWsTlsTransport", handle_kamailioNetConfWsTlsTransport, - kamailioNetConfWsTlsTransport_oid, OID_LENGTH(kamailioNetConfWsTlsTransport_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetConfHttpServer", handle_kamailioNetConfHttpServer, - kamailioNetConfHttpServer_oid, OID_LENGTH(kamailioNetConfHttpServer_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetConfMsrpRelay", handle_kamailioNetConfMsrpRelay, - kamailioNetConfMsrpRelay_oid, OID_LENGTH(kamailioNetConfMsrpRelay_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetConfStunServer", handle_kamailioNetConfStunServer, - kamailioNetConfStunServer_oid, OID_LENGTH(kamailioNetConfStunServer_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioNetConfOutbound", handle_kamailioNetConfOutbound, - kamailioNetConfOutbound_oid, OID_LENGTH(kamailioNetConfOutbound_oid), - HANDLER_CAN_RONLY - )); + CONST oid kamailioNetConfUdpTransport_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 4, 1}; + CONST oid kamailioNetConfUdpDtlsTransport_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 4, 2}; + CONST oid kamailioNetConfTcpTransport_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 4, 3}; + CONST oid kamailioNetConfTcpTlsTransport_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 4, 4}; + CONST oid kamailioNetConfSctpTransport_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 4, 5}; + CONST oid kamailioNetConfSctpTlsTransport_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 4, 6}; + CONST oid kamailioNetConfWsTransport_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 4, 7}; + CONST oid kamailioNetConfWsTlsTransport_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 4, 8}; + CONST oid kamailioNetConfHttpServer_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 4, 9}; + CONST oid kamailioNetConfMsrpRelay_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 4, 10}; + CONST oid kamailioNetConfStunServer_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 4, 11}; + CONST oid kamailioNetConfOutbound_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 4, 4, 12}; + + DEBUGMSGTL(("kamailioNetConfig", "Initializing\n")); + + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetConfUdpTransport", handle_kamailioNetConfUdpTransport, + kamailioNetConfUdpTransport_oid, + OID_LENGTH(kamailioNetConfUdpTransport_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetConfUdpDtlsTransport", + handle_kamailioNetConfUdpDtlsTransport, + kamailioNetConfUdpDtlsTransport_oid, + OID_LENGTH(kamailioNetConfUdpDtlsTransport_oid), + HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetConfTcpTransport", handle_kamailioNetConfTcpTransport, + kamailioNetConfTcpTransport_oid, + OID_LENGTH(kamailioNetConfTcpTransport_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetConfTcpTlsTransport", + handle_kamailioNetConfTcpTlsTransport, + kamailioNetConfTcpTlsTransport_oid, + OID_LENGTH(kamailioNetConfTcpTlsTransport_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetConfSctpTransport", handle_kamailioNetConfSctpTransport, + kamailioNetConfSctpTransport_oid, + OID_LENGTH(kamailioNetConfSctpTransport_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetConfSctpTlsTransport", + handle_kamailioNetConfSctpTlsTransport, + kamailioNetConfSctpTlsTransport_oid, + OID_LENGTH(kamailioNetConfSctpTlsTransport_oid), + HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetConfWsTransport", handle_kamailioNetConfWsTransport, + kamailioNetConfWsTransport_oid, + OID_LENGTH(kamailioNetConfWsTransport_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetConfWsTlsTransport", + handle_kamailioNetConfWsTlsTransport, + kamailioNetConfWsTlsTransport_oid, + OID_LENGTH(kamailioNetConfWsTlsTransport_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetConfHttpServer", handle_kamailioNetConfHttpServer, + kamailioNetConfHttpServer_oid, + OID_LENGTH(kamailioNetConfHttpServer_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetConfMsrpRelay", handle_kamailioNetConfMsrpRelay, + kamailioNetConfMsrpRelay_oid, + OID_LENGTH(kamailioNetConfMsrpRelay_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetConfStunServer", handle_kamailioNetConfStunServer, + kamailioNetConfStunServer_oid, + OID_LENGTH(kamailioNetConfStunServer_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioNetConfOutbound", handle_kamailioNetConfOutbound, + kamailioNetConfOutbound_oid, + OID_LENGTH(kamailioNetConfOutbound_oid), HANDLER_CAN_RONLY)); } int handle_kamailioNetConfUdpTransport(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int value = 1; /* By default, implemented */ + int value = 1; /* By default, implemented */ - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetConfUdpTransport\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetConfUdpTransport\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioNetConfUdpDtlsTransport(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { /* Note: This transport is not supported in Kamailio. This OID is just a place holder for future work. */ - int value = -1; /* Not implemented */ - - switch(reqinfo->mode) { + int value = -1; /* Not implemented */ - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetConfUdpDtlsTransport\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; + + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, "unknown mode (%d) in " + "handle_kamailioNetConfUdpDtlsTransport\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioNetConfTcpTransport(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int value = 0; /* Not implemented */ + int value = 0; /* Not implemented */ #ifdef USE_TCP - if (!tcp_disable) { + if(!tcp_disable) { value = 1; } #endif - switch(reqinfo->mode) { - - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetConfTcpTransport\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; + + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetConfTcpTransport\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioNetConfTcpTlsTransport(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int value = 0; + int value = 0; #ifdef USE_TCP - if (!tcp_disable) { + if(!tcp_disable) { #ifdef USE_TLS - if (module_loaded("tls")) { + if(module_loaded("tls")) { value = 1; } #endif - ; /* Empty statement needed here */ + ; /* Empty statement needed here */ } #endif - switch(reqinfo->mode) { - - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetConfTcpTlsTransport\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; + + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, "unknown mode (%d) in " + "handle_kamailioNetConfTcpTlsTransport\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioNetConfSctpTransport(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int value = 0; - /* At this point I'm lazy and just check if the transport is compiled. */ + int value = 0; +/* At this point I'm lazy and just check if the transport is compiled. */ #ifdef USE_SCTP value = 1; #endif - switch(reqinfo->mode) { - - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetConfSctpTransport\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; + + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, "unknown mode (%d) in " + "handle_kamailioNetConfSctpTransport\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioNetConfSctpTlsTransport(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int value = -1; /* Not implemented */ + int value = -1; /* Not implemented */ - switch(reqinfo->mode) { - - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetConfSctpTlsTransport\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; + + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, "unknown mode (%d) in " + "handle_kamailioNetConfSctpTlsTransport\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioNetConfWsTransport(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int value = -1; /* Not implemented */ - if (module_loaded("tls")) { - value = 1; - } - - switch(reqinfo->mode) { + int value = -1; /* Not implemented */ + if(module_loaded("tls")) { + value = 1; + } - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetConfWsTransport\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; + + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetConfWsTransport\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioNetConfWsTlsTransport(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int value = 0; + int value = 0; unsigned int type; - if (module_loaded("websocket")) { + if(module_loaded("websocket")) { value = snmp_cfg_get_int("websocket", "enabled", &type); - if (type != CFG_VAR_INT) { + if(type != CFG_VAR_INT) { value = 0; } } - switch(reqinfo->mode) { - - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetConfWsTlsTransport\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; + + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, "unknown mode (%d) in " + "handle_kamailioNetConfWsTlsTransport\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioNetConfHttpServer(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int value = 0; - if (module_loaded("xhttp")) { - value = 1; - } - - switch(reqinfo->mode) { + int value = 0; + if(module_loaded("xhttp")) { + value = 1; + } - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetConfHttpServer\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; + + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetConfHttpServer\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioNetConfMsrpRelay(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int value = 0; - if (module_loaded("msrp")) { - value = 1; - } - - switch(reqinfo->mode) { + int value = 0; + if(module_loaded("msrp")) { + value = 1; + } - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetConfMsrpRelay\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; + + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetConfMsrpRelay\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioNetConfStunServer(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int value = 0; - if (module_loaded("stun")) { - value = 1; - } - - switch(reqinfo->mode) { + int value = 0; + if(module_loaded("stun")) { + value = 1; + } - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetConfStunServer\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; + + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetConfStunServer\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioNetConfOutbound(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int value = 0; /* Not implemented */ + int value = 0; /* Not implemented */ unsigned int type; - - if (module_loaded("outbound")) { + + if(module_loaded("outbound")) { value = snmp_cfg_get_int("outbound", "outbound_enabled", &type); - if (type != CFG_VAR_INT) { + if(type != CFG_VAR_INT) { value = 0; } } switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, (u_char *) &value, sizeof(int)); - break; - - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioNetConfOutbound\n", reqinfo->mode ); - return SNMP_ERR_GENERR; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, + (u_char *)&value, sizeof(int)); + break; + + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioNetConfOutbound\n", + reqinfo->mode); + return SNMP_ERR_GENERR; } return SNMP_ERR_NOERROR; -} +} \ No newline at end of file diff --git a/src/modules/snmpstats/kamailioNetConfig.h b/src/modules/snmpstats/kamailioNetConfig.h index 6399d97965c..46f4d12ac6d 100644 --- a/src/modules/snmpstats/kamailioNetConfig.h +++ b/src/modules/snmpstats/kamailioNetConfig.h @@ -20,4 +20,4 @@ Netsnmp_Node_Handler handle_kamailioNetConfMsrpRelay; Netsnmp_Node_Handler handle_kamailioNetConfStunServer; Netsnmp_Node_Handler handle_kamailioNetConfOutbound; -#endif /* KAMAILIONETCONFIG_H */ +#endif /* KAMAILIONETCONFIG_H */ \ No newline at end of file diff --git a/src/modules/snmpstats/kamailioServer.c b/src/modules/snmpstats/kamailioServer.c index 51dd8d44181..1bd7e70854a 100644 --- a/src/modules/snmpstats/kamailioServer.c +++ b/src/modules/snmpstats/kamailioServer.c @@ -50,98 +50,97 @@ #include "../../core/mem/shm_mem.h" /** Initializes the kamailioServer module */ -void -init_kamailioServer(void) +void init_kamailioServer(void) { - oid kamailioSrvMaxMemory_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,1,1,1 }; - oid kamailioSrvFreeMemory_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,1,1,2 }; - oid kamailioSrvMaxUsed_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,1,1,3 }; - oid kamailioSrvRealUsed_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,1,1,4 }; - oid kamailioSrvMemFragments_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,1,1,5 }; - - oid kamailioSrvCnfFullVersion_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,1,2,1 }; - oid kamailioSrvCnfVerName_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,1,2,2 }; - oid kamailioSrvCnfVerVersion_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,1,2,3 }; - oid kamailioSrvCnfVerArch_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,1,2,4 }; - oid kamailioSrvCnfVerOs_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,1,2,5 }; - oid kamailioSrvCnfVerId_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,1,2,6 }; - oid kamailioSrvCnfVerCompTime_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,1,2,7 }; - oid kamailioSrvCnfVerCompiler_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,1,2,8 }; - oid kamailioSrvCnfVerFlags_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,1,2,9 }; - - DEBUGMSGTL(("kamailioServer", "Initializing\n")); - LM_DBG("initializing Kamailio Server OID's X\n"); - - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioSrvMaxMemory", handle_kamailioSrvMaxMemory, - kamailioSrvMaxMemory_oid, OID_LENGTH(kamailioSrvMaxMemory_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioSrvFreeMemory", handle_kamailioSrvFreeMemory, - kamailioSrvFreeMemory_oid, OID_LENGTH(kamailioSrvFreeMemory_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioSrvMaxUsed", handle_kamailioSrvMaxUsed, - kamailioSrvMaxUsed_oid, OID_LENGTH(kamailioSrvMaxUsed_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioSrvRealUsed", handle_kamailioSrvRealUsed, - kamailioSrvRealUsed_oid, OID_LENGTH(kamailioSrvRealUsed_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioSrvMemFragments", handle_kamailioSrvMemFragments, - kamailioSrvMemFragments_oid, OID_LENGTH(kamailioSrvMemFragments_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioSrvCnfFullVersion", handle_kamailioSrvCnfFullVersion, - kamailioSrvCnfFullVersion_oid, OID_LENGTH(kamailioSrvCnfFullVersion_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioSrvCnfVerName", handle_kamailioSrvCnfVerName, - kamailioSrvCnfVerName_oid, OID_LENGTH(kamailioSrvCnfVerName_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioSrvCnfVerVersion", handle_kamailioSrvCnfVerVersion, - kamailioSrvCnfVerVersion_oid, OID_LENGTH(kamailioSrvCnfVerVersion_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioSrvCnfVerArch", handle_kamailioSrvCnfVerArch, - kamailioSrvCnfVerArch_oid, OID_LENGTH(kamailioSrvCnfVerArch_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioSrvCnfVerOs", handle_kamailioSrvCnfVerOs, - kamailioSrvCnfVerOs_oid, OID_LENGTH(kamailioSrvCnfVerOs_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioSrvCnfVerId", handle_kamailioSrvCnfVerId, - kamailioSrvCnfVerId_oid, OID_LENGTH(kamailioSrvCnfVerId_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioSrvCnfVerCompTime", handle_kamailioSrvCnfVerCompTime, - kamailioSrvCnfVerCompTime_oid, OID_LENGTH(kamailioSrvCnfVerCompTime_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioSrvCnfVerCompiler", handle_kamailioSrvCnfVerCompiler, - kamailioSrvCnfVerCompiler_oid, OID_LENGTH(kamailioSrvCnfVerCompiler_oid), - HANDLER_CAN_RONLY - )); - netsnmp_register_scalar( - netsnmp_create_handler_registration("kamailioSrvCnfVerFlags", handle_kamailioSrvCnfVerFlags, - kamailioSrvCnfVerFlags_oid, OID_LENGTH(kamailioSrvCnfVerFlags_oid), - HANDLER_CAN_RONLY - )); + oid kamailioSrvMaxMemory_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 1, 1, 1}; + oid kamailioSrvFreeMemory_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 1, 1, 2}; + oid kamailioSrvMaxUsed_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 1, 1, 3}; + oid kamailioSrvRealUsed_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 1, 1, 4}; + oid kamailioSrvMemFragments_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 1, 1, 5}; + + oid kamailioSrvCnfFullVersion_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 1, 2, 1}; + oid kamailioSrvCnfVerName_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 1, 2, 2}; + oid kamailioSrvCnfVerVersion_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 1, 2, 3}; + oid kamailioSrvCnfVerArch_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 1, 2, 4}; + oid kamailioSrvCnfVerOs_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 1, 2, 5}; + oid kamailioSrvCnfVerId_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 1, 2, 6}; + oid kamailioSrvCnfVerCompTime_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 1, 2, 7}; + oid kamailioSrvCnfVerCompiler_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 1, 2, 8}; + oid kamailioSrvCnfVerFlags_oid[] = { + 1, 3, 6, 1, 4, 1, 34352, 3, 1, 3, 1, 1, 2, 9}; + + DEBUGMSGTL(("kamailioServer", "Initializing\n")); + LM_DBG("initializing Kamailio Server OID's X\n"); + + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioSrvMaxMemory", + handle_kamailioSrvMaxMemory, kamailioSrvMaxMemory_oid, + OID_LENGTH(kamailioSrvMaxMemory_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioSrvFreeMemory", + handle_kamailioSrvFreeMemory, kamailioSrvFreeMemory_oid, + OID_LENGTH(kamailioSrvFreeMemory_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioSrvMaxUsed", + handle_kamailioSrvMaxUsed, kamailioSrvMaxUsed_oid, + OID_LENGTH(kamailioSrvMaxUsed_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioSrvRealUsed", + handle_kamailioSrvRealUsed, kamailioSrvRealUsed_oid, + OID_LENGTH(kamailioSrvRealUsed_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioSrvMemFragments", handle_kamailioSrvMemFragments, + kamailioSrvMemFragments_oid, + OID_LENGTH(kamailioSrvMemFragments_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioSrvCnfFullVersion", handle_kamailioSrvCnfFullVersion, + kamailioSrvCnfFullVersion_oid, + OID_LENGTH(kamailioSrvCnfFullVersion_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioSrvCnfVerName", + handle_kamailioSrvCnfVerName, kamailioSrvCnfVerName_oid, + OID_LENGTH(kamailioSrvCnfVerName_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioSrvCnfVerVersion", handle_kamailioSrvCnfVerVersion, + kamailioSrvCnfVerVersion_oid, + OID_LENGTH(kamailioSrvCnfVerVersion_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioSrvCnfVerArch", + handle_kamailioSrvCnfVerArch, kamailioSrvCnfVerArch_oid, + OID_LENGTH(kamailioSrvCnfVerArch_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioSrvCnfVerOs", + handle_kamailioSrvCnfVerOs, kamailioSrvCnfVerOs_oid, + OID_LENGTH(kamailioSrvCnfVerOs_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioSrvCnfVerId", + handle_kamailioSrvCnfVerId, kamailioSrvCnfVerId_oid, + OID_LENGTH(kamailioSrvCnfVerId_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioSrvCnfVerCompTime", handle_kamailioSrvCnfVerCompTime, + kamailioSrvCnfVerCompTime_oid, + OID_LENGTH(kamailioSrvCnfVerCompTime_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioSrvCnfVerCompiler", handle_kamailioSrvCnfVerCompiler, + kamailioSrvCnfVerCompiler_oid, + OID_LENGTH(kamailioSrvCnfVerCompiler_oid), HANDLER_CAN_RONLY)); + netsnmp_register_scalar( + netsnmp_create_handler_registration("kamailioSrvCnfVerFlags", + handle_kamailioSrvCnfVerFlags, kamailioSrvCnfVerFlags_oid, + OID_LENGTH(kamailioSrvCnfVerFlags_oid), HANDLER_CAN_RONLY)); } @@ -153,333 +152,347 @@ void stats_shm_update(void) { ticks_t t; t = get_ticks(); - if(t!=_stats_shm_tm) { + if(t != _stats_shm_tm) { shm_info(&_stats_shm_mi); _stats_shm_tm = t; } } int handle_kamailioSrvMaxMemory(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - stats_shm_update(); - int maxmemory = (int) _stats_shm_mi.total_size; - - switch(reqinfo->mode) { + stats_shm_update(); + int maxmemory = (int)_stats_shm_mi.total_size; - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, - (u_char *) &maxmemory, sizeof(int)); - break; + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, + (u_char *)&maxmemory, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioSrvMaxMemory\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - return SNMP_ERR_NOERROR; + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioSrvMaxMemory\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } int handle_kamailioSrvFreeMemory(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - stats_shm_update(); - int freememory = (int) _stats_shm_mi.free; + stats_shm_update(); + int freememory = (int)_stats_shm_mi.free; - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, - (u_char *) &freememory, sizeof(int)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, + (u_char *)&freememory, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioSrvFreeMemory\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioSrvFreeMemory\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioSrvMaxUsed(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - stats_shm_update(); - int value = (int) _stats_shm_mi.max_used; - - switch(reqinfo->mode) { + stats_shm_update(); + int value = (int)_stats_shm_mi.max_used; - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, - (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioSrvMaxUsed\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - return SNMP_ERR_NOERROR; + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioSrvMaxUsed\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } int handle_kamailioSrvRealUsed(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - stats_shm_update(); - int value = (int) _stats_shm_mi.real_used; - - switch(reqinfo->mode) { + stats_shm_update(); + int value = (int)_stats_shm_mi.real_used; - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, - (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioSrvRealUsed\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - return SNMP_ERR_NOERROR; + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioSrvRealUsed\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } int handle_kamailioSrvMemFragments(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - stats_shm_update(); - int value = (int) _stats_shm_mi.total_frags; - - switch(reqinfo->mode) { + stats_shm_update(); + int value = (int)_stats_shm_mi.total_frags; - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, - (u_char *) &value, sizeof(int)); - break; + switch(reqinfo->mode) { + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, + (u_char *)&value, sizeof(int)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioSrvMemFragments\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } - return SNMP_ERR_NOERROR; + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioSrvMemFragments\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } + + return SNMP_ERR_NOERROR; } int handle_kamailioSrvCnfFullVersion(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, - (u_char *) full_version, strlen(full_version)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, + (u_char *)full_version, strlen(full_version)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioSrvCnfFullVersion\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioSrvCnfFullVersion\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioSrvCnfVerName(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, - (u_char *) ver_name, strlen(ver_name)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, + (u_char *)ver_name, strlen(ver_name)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioSrvCnfVerName\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioSrvCnfVerName\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioSrvCnfVerVersion(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, - (u_char *) ver_version, strlen(ver_version)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, + (u_char *)ver_version, strlen(ver_version)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioSrvCnfVerVersion\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioSrvCnfVerVersion\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioSrvCnfVerArch(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, - (u_char *) ver_arch, strlen(ver_arch)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, + (u_char *)ver_arch, strlen(ver_arch)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioSrvCnfVerArch\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioSrvCnfVerArch\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioSrvCnfVerOs(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, - (u_char *) ver_os, strlen(ver_os)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, + (u_char *)ver_os, strlen(ver_os)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioSrvCnfVerOs\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioSrvCnfVerOs\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioSrvCnfVerId(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, - (u_char *) ver_id, strlen(ver_id)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, + (u_char *)ver_id, strlen(ver_id)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioSrvCnfVerId\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioSrvCnfVerId\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioSrvCnfVerCompTime(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, - (u_char *) ver_compiled_time, strlen(ver_compiled_time)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, + (u_char *)ver_compiled_time, strlen(ver_compiled_time)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioSrvCnfVerCompTime\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioSrvCnfVerCompTime\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioSrvCnfVerCompiler(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, - (u_char *) ver_compiler, strlen(ver_compiler)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, + (u_char *)ver_compiler, strlen(ver_compiler)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioSrvCnfVerCompiler\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioSrvCnfVerCompiler\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; + return SNMP_ERR_NOERROR; } int handle_kamailioSrvCnfVerFlags(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - switch(reqinfo->mode) { + switch(reqinfo->mode) { - case MODE_GET: - snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, - (u_char *) ver_flags, strlen(ver_flags)); - break; + case MODE_GET: + snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, + (u_char *)ver_flags, strlen(ver_flags)); + break; - default: - /* we should never get here, so this is a really bad error */ - snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioSrvCnfVerFlags\n", reqinfo->mode ); - return SNMP_ERR_GENERR; - } + default: + /* we should never get here, so this is a really bad error */ + snmp_log(LOG_ERR, + "unknown mode (%d) in handle_kamailioSrvCnfVerFlags\n", + reqinfo->mode); + return SNMP_ERR_GENERR; + } - return SNMP_ERR_NOERROR; -} + return SNMP_ERR_NOERROR; +} \ No newline at end of file diff --git a/src/modules/snmpstats/kamailioServer.h b/src/modules/snmpstats/kamailioServer.h index 83d17989039..ba3ec3ec81f 100644 --- a/src/modules/snmpstats/kamailioServer.h +++ b/src/modules/snmpstats/kamailioServer.h @@ -48,4 +48,4 @@ Netsnmp_Node_Handler handle_kamailioSrvCnfVerCompTime; Netsnmp_Node_Handler handle_kamailioSrvCnfVerCompiler; Netsnmp_Node_Handler handle_kamailioSrvCnfVerFlags; -#endif /* KAMAILIOSERVER_H */ +#endif /* KAMAILIOSERVER_H */ \ No newline at end of file diff --git a/src/modules/snmpstats/snmpMIBNotifications.c b/src/modules/snmpstats/snmpMIBNotifications.c index 711d7f97d9f..6b65cc02756 100644 --- a/src/modules/snmpstats/snmpMIBNotifications.c +++ b/src/modules/snmpstats/snmpMIBNotifications.c @@ -46,43 +46,33 @@ static oid snmptrap_oid[] = {1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0}; * - kamailioMsgQueueMinorThreshold = minorThreshold * */ -int send_kamailioMsgQueueDepthMinorEvent_trap(int msgQueueDepth, - int minorThreshold) +int send_kamailioMsgQueueDepthMinorEvent_trap( + int msgQueueDepth, int minorThreshold) { - netsnmp_variable_list *var_list = NULL; - - oid kamailioMsgQueueDepthMinorEvent_oid[] = { - KAMAILIO_OID,3,1,3,2,0,1 }; - - oid kamailioMsgQueueDepth_oid[] = { - KAMAILIO_OID,3,1,3,1,2,3,1,0 }; - - oid kamailioMsgQueueMinorThreshold_oid[] = { - KAMAILIO_OID,3,1,3,1,2,3,2,0 }; - - snmp_varlist_add_variable(&var_list, - snmptrap_oid, - OID_LENGTH(snmptrap_oid), - ASN_OBJECT_ID, - (u_char *)kamailioMsgQueueDepthMinorEvent_oid, + netsnmp_variable_list *var_list = NULL; + + oid kamailioMsgQueueDepthMinorEvent_oid[] = { + KAMAILIO_OID, 3, 1, 3, 2, 0, 1}; + + oid kamailioMsgQueueDepth_oid[] = {KAMAILIO_OID, 3, 1, 3, 1, 2, 3, 1, 0}; + + oid kamailioMsgQueueMinorThreshold_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 2, 3, 2, 0}; + + snmp_varlist_add_variable(&var_list, snmptrap_oid, OID_LENGTH(snmptrap_oid), + ASN_OBJECT_ID, (u_char *)kamailioMsgQueueDepthMinorEvent_oid, (int)sizeof(kamailioMsgQueueDepthMinorEvent_oid)); - - snmp_varlist_add_variable(&var_list, - kamailioMsgQueueDepth_oid, - OID_LENGTH(kamailioMsgQueueDepth_oid), - ASN_GAUGE, - (u_char *)&msgQueueDepth, - sizeof(msgQueueDepth)); - - snmp_varlist_add_variable(&var_list, - kamailioMsgQueueMinorThreshold_oid, - OID_LENGTH(kamailioMsgQueueMinorThreshold_oid), - ASN_INTEGER, - (u_char *)&minorThreshold, - sizeof(minorThreshold)); - - send_v2trap( var_list ); - snmp_free_varbind( var_list ); + + snmp_varlist_add_variable(&var_list, kamailioMsgQueueDepth_oid, + OID_LENGTH(kamailioMsgQueueDepth_oid), ASN_GAUGE, + (u_char *)&msgQueueDepth, sizeof(msgQueueDepth)); + + snmp_varlist_add_variable(&var_list, kamailioMsgQueueMinorThreshold_oid, + OID_LENGTH(kamailioMsgQueueMinorThreshold_oid), ASN_INTEGER, + (u_char *)&minorThreshold, sizeof(minorThreshold)); + + send_v2trap(var_list); + snmp_free_varbind(var_list); return SNMP_ERR_NOERROR; } @@ -95,43 +85,33 @@ int send_kamailioMsgQueueDepthMinorEvent_trap(int msgQueueDepth, * - kamailioMsgQueueMajorThreshold = majorThreshold * */ -int send_kamailioMsgQueueDepthMajorEvent_trap(int msgQueueDepth, - int majorThreshold) +int send_kamailioMsgQueueDepthMajorEvent_trap( + int msgQueueDepth, int majorThreshold) { - netsnmp_variable_list *var_list = NULL; - - oid kamailioMsgQueueDepthMajorEvent_oid[] = { - KAMAILIO_OID,3,1,3,2,0,2 }; - - oid kamailioMsgQueueDepth_oid[] = { - KAMAILIO_OID,3,1,3,1,2,3,1,0 }; - - oid kamailioMsgQueueMajorThreshold_oid[] = { - KAMAILIO_OID,3,1,3,1,2,3,3,0 }; - - snmp_varlist_add_variable(&var_list, - snmptrap_oid, - OID_LENGTH(snmptrap_oid), - ASN_OBJECT_ID, - (u_char *)kamailioMsgQueueDepthMajorEvent_oid, - (int)sizeof(kamailioMsgQueueDepthMajorEvent_oid)); - - snmp_varlist_add_variable(&var_list, - kamailioMsgQueueDepth_oid, - OID_LENGTH(kamailioMsgQueueDepth_oid), - ASN_GAUGE, - (u_char *)&msgQueueDepth, - sizeof(msgQueueDepth)); - - snmp_varlist_add_variable(&var_list, - kamailioMsgQueueMajorThreshold_oid, - OID_LENGTH(kamailioMsgQueueMajorThreshold_oid), - ASN_INTEGER, - (u_char *)&majorThreshold, - sizeof(majorThreshold)); - - send_v2trap( var_list ); - snmp_free_varbind( var_list ); + netsnmp_variable_list *var_list = NULL; + + oid kamailioMsgQueueDepthMajorEvent_oid[] = { + KAMAILIO_OID, 3, 1, 3, 2, 0, 2}; + + oid kamailioMsgQueueDepth_oid[] = {KAMAILIO_OID, 3, 1, 3, 1, 2, 3, 1, 0}; + + oid kamailioMsgQueueMajorThreshold_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 2, 3, 3, 0}; + + snmp_varlist_add_variable(&var_list, snmptrap_oid, OID_LENGTH(snmptrap_oid), + ASN_OBJECT_ID, (u_char *)kamailioMsgQueueDepthMajorEvent_oid, + (int)sizeof(kamailioMsgQueueDepthMajorEvent_oid)); + + snmp_varlist_add_variable(&var_list, kamailioMsgQueueDepth_oid, + OID_LENGTH(kamailioMsgQueueDepth_oid), ASN_GAUGE, + (u_char *)&msgQueueDepth, sizeof(msgQueueDepth)); + + snmp_varlist_add_variable(&var_list, kamailioMsgQueueMajorThreshold_oid, + OID_LENGTH(kamailioMsgQueueMajorThreshold_oid), ASN_INTEGER, + (u_char *)&majorThreshold, sizeof(majorThreshold)); + + send_v2trap(var_list); + snmp_free_varbind(var_list); return SNMP_ERR_NOERROR; } @@ -147,40 +127,29 @@ int send_kamailioMsgQueueDepthMajorEvent_trap(int msgQueueDepth, */ int send_kamailioDialogLimitMinorEvent_trap(int numDialogs, int threshold) { - netsnmp_variable_list *var_list = NULL; - - oid kamailioDialogLimitMinorEvent_oid[] = { - KAMAILIO_OID,3,1,3,2,0,3 }; - - oid kamailioCurNumDialogs_oid[] = { - KAMAILIO_OID,3,1,3,1,3,2,1, 0 }; - - oid kamailioDialogLimitMinorThreshold_oid[] = { - KAMAILIO_OID,3,1,3,1,3,2,5, 0 }; - - snmp_varlist_add_variable(&var_list, - snmptrap_oid, - OID_LENGTH(snmptrap_oid), - ASN_OBJECT_ID, - (u_char *)kamailioDialogLimitMinorEvent_oid, - (int)sizeof(kamailioDialogLimitMinorEvent_oid)); - - snmp_varlist_add_variable(&var_list, - kamailioCurNumDialogs_oid, - OID_LENGTH(kamailioCurNumDialogs_oid), - ASN_GAUGE, - (u_char *)&numDialogs, - sizeof(numDialogs)); - - snmp_varlist_add_variable(&var_list, - kamailioDialogLimitMinorThreshold_oid, - OID_LENGTH(kamailioDialogLimitMinorThreshold_oid), - ASN_INTEGER, - (u_char *)&threshold, - sizeof(threshold)); - - send_v2trap( var_list ); - snmp_free_varbind( var_list ); + netsnmp_variable_list *var_list = NULL; + + oid kamailioDialogLimitMinorEvent_oid[] = {KAMAILIO_OID, 3, 1, 3, 2, 0, 3}; + + oid kamailioCurNumDialogs_oid[] = {KAMAILIO_OID, 3, 1, 3, 1, 3, 2, 1, 0}; + + oid kamailioDialogLimitMinorThreshold_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 3, 2, 5, 0}; + + snmp_varlist_add_variable(&var_list, snmptrap_oid, OID_LENGTH(snmptrap_oid), + ASN_OBJECT_ID, (u_char *)kamailioDialogLimitMinorEvent_oid, + (int)sizeof(kamailioDialogLimitMinorEvent_oid)); + + snmp_varlist_add_variable(&var_list, kamailioCurNumDialogs_oid, + OID_LENGTH(kamailioCurNumDialogs_oid), ASN_GAUGE, + (u_char *)&numDialogs, sizeof(numDialogs)); + + snmp_varlist_add_variable(&var_list, kamailioDialogLimitMinorThreshold_oid, + OID_LENGTH(kamailioDialogLimitMinorThreshold_oid), ASN_INTEGER, + (u_char *)&threshold, sizeof(threshold)); + + send_v2trap(var_list); + snmp_free_varbind(var_list); return SNMP_ERR_NOERROR; } @@ -196,40 +165,29 @@ int send_kamailioDialogLimitMinorEvent_trap(int numDialogs, int threshold) */ int send_kamailioDialogLimitMajorEvent_trap(int numDialogs, int threshold) { - netsnmp_variable_list *var_list = NULL; - - oid kamailioDialogLimitMajorEvent_oid[] = { - KAMAILIO_OID,3,1,3,2,0,4 }; - - oid kamailioCurNumDialogs_oid[] = { - KAMAILIO_OID,3,1,3,1,3,2,1, 0 }; - - oid kamailioDialogLimitMajorThreshold_oid[] = { - KAMAILIO_OID,3,1,3,1,3,2,6, 0 }; - - snmp_varlist_add_variable(&var_list, - snmptrap_oid, - OID_LENGTH(snmptrap_oid), - ASN_OBJECT_ID, - (u_char *)kamailioDialogLimitMajorEvent_oid, - (int)sizeof(kamailioDialogLimitMajorEvent_oid)); - - snmp_varlist_add_variable(&var_list, - kamailioCurNumDialogs_oid, - OID_LENGTH(kamailioCurNumDialogs_oid), - ASN_GAUGE, - (u_char *)&numDialogs, - sizeof(numDialogs)); - - snmp_varlist_add_variable(&var_list, - kamailioDialogLimitMajorThreshold_oid, - OID_LENGTH(kamailioDialogLimitMajorThreshold_oid), - ASN_INTEGER, - (u_char *)&threshold, - sizeof(threshold)); - - send_v2trap( var_list ); - snmp_free_varbind( var_list ); + netsnmp_variable_list *var_list = NULL; + + oid kamailioDialogLimitMajorEvent_oid[] = {KAMAILIO_OID, 3, 1, 3, 2, 0, 4}; + + oid kamailioCurNumDialogs_oid[] = {KAMAILIO_OID, 3, 1, 3, 1, 3, 2, 1, 0}; + + oid kamailioDialogLimitMajorThreshold_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 3, 2, 6, 0}; + + snmp_varlist_add_variable(&var_list, snmptrap_oid, OID_LENGTH(snmptrap_oid), + ASN_OBJECT_ID, (u_char *)kamailioDialogLimitMajorEvent_oid, + (int)sizeof(kamailioDialogLimitMajorEvent_oid)); + + snmp_varlist_add_variable(&var_list, kamailioCurNumDialogs_oid, + OID_LENGTH(kamailioCurNumDialogs_oid), ASN_GAUGE, + (u_char *)&numDialogs, sizeof(numDialogs)); + + snmp_varlist_add_variable(&var_list, kamailioDialogLimitMajorThreshold_oid, + OID_LENGTH(kamailioDialogLimitMajorThreshold_oid), ASN_INTEGER, + (u_char *)&threshold, sizeof(threshold)); + + send_v2trap(var_list); + snmp_free_varbind(var_list); return SNMP_ERR_NOERROR; -} +} \ No newline at end of file diff --git a/src/modules/snmpstats/snmpMIBNotifications.h b/src/modules/snmpstats/snmpMIBNotifications.h index bbe08381427..cea2817f8fd 100644 --- a/src/modules/snmpstats/snmpMIBNotifications.h +++ b/src/modules/snmpstats/snmpMIBNotifications.h @@ -41,8 +41,8 @@ * - kamailioMsgQueueMinorThreshold = minorThreshold * */ -int send_kamailioMsgQueueDepthMinorEvent_trap(int msgQueueDepth, - int minorThreshold); +int send_kamailioMsgQueueDepthMinorEvent_trap( + int msgQueueDepth, int minorThreshold); /* * Sends off an kamailioMsgQueueDepthMajorEvent trap to the master agent, @@ -52,8 +52,8 @@ int send_kamailioMsgQueueDepthMinorEvent_trap(int msgQueueDepth, * - kamailioMsgQueueMajorThreshold = majorThreshold * */ -int send_kamailioMsgQueueDepthMajorEvent_trap(int msgQueueDepth, - int majorThreshold); +int send_kamailioMsgQueueDepthMajorEvent_trap( + int msgQueueDepth, int majorThreshold); /* * Sends off an kamailioDialogLimitMinorEvent trap to the master agent, @@ -75,4 +75,4 @@ int send_kamailioDialogLimitMinorEvent_trap(int numDialogs, int threshold); */ int send_kamailioDialogLimitMajorEvent_trap(int numDialogs, int threshold); -#endif /* KAMAILIOMIBNOTIFICATIONS_H */ +#endif /* KAMAILIOMIBNOTIFICATIONS_H */ \ No newline at end of file diff --git a/src/modules/snmpstats/snmpObjects.c b/src/modules/snmpstats/snmpObjects.c index 9dc9449e481..a0894609fd6 100644 --- a/src/modules/snmpstats/snmpObjects.c +++ b/src/modules/snmpstats/snmpObjects.c @@ -50,212 +50,163 @@ */ void init_kamailioObjects(void) { - static oid kamailioMsgQueueDepth_oid[] = - { KAMAILIO_OID,3,1,3,1,2,3,1 }; + static oid kamailioMsgQueueDepth_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 2, 3, 1}; - static oid kamailioMsgQueueMinorThreshold_oid[] = - { KAMAILIO_OID,3,1,3,1,2,3,2 }; + static oid kamailioMsgQueueMinorThreshold_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 2, 3, 2}; - static oid kamailioMsgQueueMajorThreshold_oid[] = - { KAMAILIO_OID,3,1,3,1,2,3,3 }; + static oid kamailioMsgQueueMajorThreshold_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 2, 3, 3}; - static oid kamailioMsgQueueDepthAlarmStatus_oid[] = - { KAMAILIO_OID,3,1,3,1,2,4,1 }; - - static oid kamailioMsgQueueDepthMinorAlarm_oid[] = - { KAMAILIO_OID,3,1,3,1,2,4,2 }; + static oid kamailioMsgQueueDepthAlarmStatus_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 2, 4, 1}; - static oid kamailioMsgQueueDepthMajorAlarm_oid[] = - { KAMAILIO_OID,3,1,3,1,2,4,3 }; + static oid kamailioMsgQueueDepthMinorAlarm_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 2, 4, 2}; - static oid kamailioCurNumDialogs_oid[] = - { KAMAILIO_OID,3,1,3,1,3,2,1 }; + static oid kamailioMsgQueueDepthMajorAlarm_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 2, 4, 3}; - static oid kamailioCurNumDialogsInProgress_oid[] = - { KAMAILIO_OID,3,1,3,1,3,2,2 }; + static oid kamailioCurNumDialogs_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 3, 2, 1}; - static oid kamailioCurNumDialogsInSetup_oid[] = - { KAMAILIO_OID,3,1,3,1,3,2,3 }; + static oid kamailioCurNumDialogsInProgress_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 3, 2, 2}; - static oid kamailioTotalNumFailedDialogSetups_oid[] = - { KAMAILIO_OID,3,1,3,1,3,2,4 }; + static oid kamailioCurNumDialogsInSetup_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 3, 2, 3}; - static oid kamailioDialogLimitMinorThreshold_oid[] = - { KAMAILIO_OID,3,1,3,1,3,2,5 }; + static oid kamailioTotalNumFailedDialogSetups_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 3, 2, 4}; - static oid kamailioDialogLimitMajorThreshold_oid[] = - { KAMAILIO_OID,3,1,3,1,3,2,6 }; + static oid kamailioDialogLimitMinorThreshold_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 3, 2, 5}; - static oid kamailioTotalNumDialogSetups_oid[] = - { KAMAILIO_OID,3,1,3,1,3,2,7 }; + static oid kamailioDialogLimitMajorThreshold_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 3, 2, 6}; - static oid kamailioDialogUsageState_oid[] = - { KAMAILIO_OID,3,1,3,1,3,3,1 }; + static oid kamailioTotalNumDialogSetups_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 3, 2, 7}; - static oid kamailioDialogLimitAlarmStatus_oid[] = - { KAMAILIO_OID,3,1,3,1,3,4,1 }; + static oid kamailioDialogUsageState_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 3, 3, 1}; - static oid kamailioDialogLimitMinorAlarm_oid[] = - { KAMAILIO_OID,3,1,3,1,3,4,2 }; + static oid kamailioDialogLimitAlarmStatus_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 3, 4, 1}; - static oid kamailioDialogLimitMajorAlarm_oid[] = - { KAMAILIO_OID,3,1,3,1,3,4,3 }; + static oid kamailioDialogLimitMinorAlarm_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 3, 4, 2}; + static oid kamailioDialogLimitMajorAlarm_oid[] = { + KAMAILIO_OID, 3, 1, 3, 1, 3, 4, 3}; - DEBUGMSGTL(("kamailioObjects", "Initializing\n")); - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioMsgQueueDepth", - handle_kamailioMsgQueueDepth, - kamailioMsgQueueDepth_oid, - OID_LENGTH(kamailioMsgQueueDepth_oid), - HANDLER_CAN_RONLY) - ); + DEBUGMSGTL(("kamailioObjects", "Initializing\n")); netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioMsgQueueMinorThreshold", + netsnmp_create_handler_registration("kamailioMsgQueueDepth", + handle_kamailioMsgQueueDepth, kamailioMsgQueueDepth_oid, + OID_LENGTH(kamailioMsgQueueDepth_oid), HANDLER_CAN_RONLY)); + + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioMsgQueueMinorThreshold", handle_kamailioMsgQueueMinorThreshold, - kamailioMsgQueueMinorThreshold_oid, - OID_LENGTH(kamailioMsgQueueMinorThreshold_oid), - HANDLER_CAN_RONLY) - ); + kamailioMsgQueueMinorThreshold_oid, + OID_LENGTH(kamailioMsgQueueMinorThreshold_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioMsgQueueMajorThreshold", + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioMsgQueueMajorThreshold", handle_kamailioMsgQueueMajorThreshold, - kamailioMsgQueueMajorThreshold_oid, - OID_LENGTH(kamailioMsgQueueMajorThreshold_oid), - HANDLER_CAN_RONLY) - ); + kamailioMsgQueueMajorThreshold_oid, + OID_LENGTH(kamailioMsgQueueMajorThreshold_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioMsgQueueDepthAlarmStatus", + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioMsgQueueDepthAlarmStatus", handle_kamailioMsgQueueDepthAlarmStatus, - kamailioMsgQueueDepthAlarmStatus_oid, + kamailioMsgQueueDepthAlarmStatus_oid, OID_LENGTH(kamailioMsgQueueDepthAlarmStatus_oid), - HANDLER_CAN_RONLY) - ); + HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioMsgQueueDepthMinorAlarm", + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioMsgQueueDepthMinorAlarm", handle_kamailioMsgQueueDepthMinorAlarm, - kamailioMsgQueueDepthMinorAlarm_oid, + kamailioMsgQueueDepthMinorAlarm_oid, OID_LENGTH(kamailioMsgQueueDepthMinorAlarm_oid), - HANDLER_CAN_RONLY) - ); - - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioMsgQueueDepthMajorAlarm", + HANDLER_CAN_RONLY)); + + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioMsgQueueDepthMajorAlarm", handle_kamailioMsgQueueDepthMajorAlarm, - kamailioMsgQueueDepthMajorAlarm_oid, + kamailioMsgQueueDepthMajorAlarm_oid, OID_LENGTH(kamailioMsgQueueDepthMajorAlarm_oid), - HANDLER_CAN_RONLY) - ); + HANDLER_CAN_RONLY)); netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioCurNumDialogs", - handle_kamailioCurNumDialogs, - kamailioCurNumDialogs_oid, - OID_LENGTH(kamailioCurNumDialogs_oid), - HANDLER_CAN_RONLY) - ); - - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioCurNumDialogsInProgress", + netsnmp_create_handler_registration("kamailioCurNumDialogs", + handle_kamailioCurNumDialogs, kamailioCurNumDialogs_oid, + OID_LENGTH(kamailioCurNumDialogs_oid), HANDLER_CAN_RONLY)); + + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioCurNumDialogsInProgress", handle_kamailioCurNumDialogsInProgress, - kamailioCurNumDialogsInProgress_oid, + kamailioCurNumDialogsInProgress_oid, OID_LENGTH(kamailioCurNumDialogsInProgress_oid), - HANDLER_CAN_RONLY) - ); - - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioCurNumDialogsInSetup", - handle_kamailioCurNumDialogsInSetup, - kamailioCurNumDialogsInSetup_oid, - OID_LENGTH(kamailioCurNumDialogsInSetup_oid), - HANDLER_CAN_RONLY) - ); - - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioTotalNumFailedDialogSetups", - handle_kamailioTotalNumFailedDialogSetups, - kamailioTotalNumFailedDialogSetups_oid, - OID_LENGTH(kamailioTotalNumFailedDialogSetups_oid), - HANDLER_CAN_RONLY) - ); - - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioDialogLimitMinorThreshold", + HANDLER_CAN_RONLY)); + + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioCurNumDialogsInSetup", handle_kamailioCurNumDialogsInSetup, + kamailioCurNumDialogsInSetup_oid, + OID_LENGTH(kamailioCurNumDialogsInSetup_oid), HANDLER_CAN_RONLY)); + + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioTotalNumFailedDialogSetups", + handle_kamailioTotalNumFailedDialogSetups, + kamailioTotalNumFailedDialogSetups_oid, + OID_LENGTH(kamailioTotalNumFailedDialogSetups_oid), + HANDLER_CAN_RONLY)); + + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioDialogLimitMinorThreshold", handle_kamailioDialogLimitMinorThreshold, - kamailioDialogLimitMinorThreshold_oid, + kamailioDialogLimitMinorThreshold_oid, OID_LENGTH(kamailioDialogLimitMinorThreshold_oid), - HANDLER_CAN_RONLY) - ); + HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioDialogLimitMajorThreshold", + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioDialogLimitMajorThreshold", handle_kamailioDialogLimitMajorThreshold, - kamailioDialogLimitMajorThreshold_oid, + kamailioDialogLimitMajorThreshold_oid, OID_LENGTH(kamailioDialogLimitMajorThreshold_oid), - HANDLER_CAN_RONLY) - ); + HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioTotalNumDialogSetups", - handle_kamailioTotalNumDialogSetups, - kamailioTotalNumDialogSetups_oid, - OID_LENGTH(kamailioTotalNumDialogSetups_oid), - HANDLER_CAN_RONLY) - ); + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioTotalNumDialogSetups", handle_kamailioTotalNumDialogSetups, + kamailioTotalNumDialogSetups_oid, + OID_LENGTH(kamailioTotalNumDialogSetups_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioDialogUsageState", - handle_kamailioDialogUsageState, - kamailioDialogUsageState_oid, - OID_LENGTH(kamailioDialogUsageState_oid), - HANDLER_CAN_RONLY) - ); - - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioDialogLimitAlarmStatus", + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioDialogUsageState", handle_kamailioDialogUsageState, + kamailioDialogUsageState_oid, + OID_LENGTH(kamailioDialogUsageState_oid), HANDLER_CAN_RONLY)); + + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioDialogLimitAlarmStatus", handle_kamailioDialogLimitAlarmStatus, - kamailioDialogLimitAlarmStatus_oid, - OID_LENGTH(kamailioDialogLimitAlarmStatus_oid), - HANDLER_CAN_RONLY) - ); - - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioDialogLimitMinorAlarm", + kamailioDialogLimitAlarmStatus_oid, + OID_LENGTH(kamailioDialogLimitAlarmStatus_oid), HANDLER_CAN_RONLY)); + + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioDialogLimitMinorAlarm", handle_kamailioDialogLimitMinorAlarm, - kamailioDialogLimitMinorAlarm_oid, - OID_LENGTH(kamailioDialogLimitMinorAlarm_oid), - HANDLER_CAN_RONLY) - ); - - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioDialogLimitMajorAlarm", + kamailioDialogLimitMinorAlarm_oid, + OID_LENGTH(kamailioDialogLimitMinorAlarm_oid), HANDLER_CAN_RONLY)); + + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioDialogLimitMajorAlarm", handle_kamailioDialogLimitMajorAlarm, - kamailioDialogLimitMajorAlarm_oid, - OID_LENGTH(kamailioDialogLimitMajorAlarm_oid), - HANDLER_CAN_RONLY) - ); + kamailioDialogLimitMajorAlarm_oid, + OID_LENGTH(kamailioDialogLimitMajorAlarm_oid), HANDLER_CAN_RONLY)); } @@ -284,17 +235,16 @@ static int msgQueueMajorThreshold = -1; int handle_kamailioMsgQueueDepth(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int bytesWaiting; - + bytesWaiting = get_total_bytes_waiting(); - if (reqinfo->mode == MODE_GET) { + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, - (u_char *) &bytesWaiting, sizeof(int)); + (u_char *)&bytesWaiting, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -303,26 +253,24 @@ int handle_kamailioMsgQueueDepth(netsnmp_mib_handler *handler, int handle_kamailioMsgQueueMinorThreshold(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - if (reqinfo->mode == MODE_GET) { + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &msgQueueMinorThreshold, sizeof(int)); + (u_char *)&msgQueueMinorThreshold, sizeof(int)); return SNMP_ERR_NOERROR; - } + } return SNMP_ERR_GENERR; } int handle_kamailioMsgQueueMajorThreshold(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - if (reqinfo->mode == MODE_GET) { + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &msgQueueMajorThreshold, sizeof(int)); + (u_char *)&msgQueueMajorThreshold, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -331,8 +279,7 @@ int handle_kamailioMsgQueueMajorThreshold(netsnmp_mib_handler *handler, int handle_kamailioMsgQueueDepthAlarmStatus(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { /* The MIB specifications say the scalar should be set to 'clear' if @@ -340,18 +287,18 @@ int handle_kamailioMsgQueueDepthAlarmStatus(netsnmp_mib_handler *handler, * this means that no bits are toggled. So we set the state to zero by * default */ unsigned int state = 0; - - if (check_msg_queue_alarm(msgQueueMinorThreshold)) { - state |= TC_ALARM_STATUS_MINOR; + + if(check_msg_queue_alarm(msgQueueMinorThreshold)) { + state |= TC_ALARM_STATUS_MINOR; } - if (check_msg_queue_alarm(msgQueueMajorThreshold)) { - state |= TC_ALARM_STATUS_MAJOR; + if(check_msg_queue_alarm(msgQueueMajorThreshold)) { + state |= TC_ALARM_STATUS_MAJOR; } - if (reqinfo->mode == MODE_GET) { - snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, - (u_char *)&state, 1); + if(reqinfo->mode == MODE_GET) { + snmp_set_var_typed_value( + requests->requestvb, ASN_OCTET_STR, (u_char *)&state, 1); return SNMP_ERR_NOERROR; } @@ -360,18 +307,17 @@ int handle_kamailioMsgQueueDepthAlarmStatus(netsnmp_mib_handler *handler, int handle_kamailioMsgQueueDepthMinorAlarm(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int x731AlarmState = TC_ALARM_STATE_CLEAR; - if (check_msg_queue_alarm(msgQueueMinorThreshold)) { + if(check_msg_queue_alarm(msgQueueMinorThreshold)) { x731AlarmState = TC_ALARM_STATE_MINOR; } - if (reqinfo->mode == MODE_GET) { + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &x731AlarmState, sizeof(int)); + (u_char *)&x731AlarmState, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -380,18 +326,17 @@ int handle_kamailioMsgQueueDepthMinorAlarm(netsnmp_mib_handler *handler, int handle_kamailioMsgQueueDepthMajorAlarm(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int x731AlarmState = TC_ALARM_STATE_CLEAR; - if (check_msg_queue_alarm(msgQueueMajorThreshold)) { + if(check_msg_queue_alarm(msgQueueMajorThreshold)) { x731AlarmState = TC_ALARM_STATE_MAJOR; } - - if (reqinfo->mode == MODE_GET) { + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &x731AlarmState, sizeof(int)); + (u_char *)&x731AlarmState, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -400,16 +345,15 @@ int handle_kamailioMsgQueueDepthMajorAlarm(netsnmp_mib_handler *handler, int handle_kamailioCurNumDialogs(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { /* This scalar is defined as the number of dialogs in both the EARLY and * the CONFIRMED state. */ int result = get_statistic("active_dialogs"); - if (reqinfo->mode == MODE_GET) { - snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, - (u_char *) &result, sizeof(int)); + if(reqinfo->mode == MODE_GET) { + snmp_set_var_typed_value( + requests->requestvb, ASN_GAUGE, (u_char *)&result, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -418,19 +362,17 @@ int handle_kamailioCurNumDialogs(netsnmp_mib_handler *handler, int handle_kamailioCurNumDialogsInProgress(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { /* This scalar is defined as the number of dialogs in the CONFIRMED * state only. active_dialogs includes both confirmed and early, so * we subtract out early_dialogs from active_dialogs. */ - int result = - get_statistic("active_dialogs") - - get_statistic("early_dialogs"); - - if (reqinfo->mode == MODE_GET) { - snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, - (u_char *) &result, sizeof(int)); + int result = + get_statistic("active_dialogs") - get_statistic("early_dialogs"); + + if(reqinfo->mode == MODE_GET) { + snmp_set_var_typed_value( + requests->requestvb, ASN_GAUGE, (u_char *)&result, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -439,16 +381,15 @@ int handle_kamailioCurNumDialogsInProgress(netsnmp_mib_handler *handler, int handle_kamailioCurNumDialogsInSetup(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { /* This scalar is defined as the number of dialogs in the EARLY state. * */ int result = get_statistic("early_dialogs"); - - if (reqinfo->mode == MODE_GET) { - snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, - (u_char *) &result, sizeof(int)); + + if(reqinfo->mode == MODE_GET) { + snmp_set_var_typed_value( + requests->requestvb, ASN_GAUGE, (u_char *)&result, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -457,14 +398,13 @@ int handle_kamailioCurNumDialogsInSetup(netsnmp_mib_handler *handler, int handle_kamailioTotalNumFailedDialogSetups(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int result = get_statistic("failed_dialogs"); - - if (reqinfo->mode == MODE_GET) { + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &result, sizeof(int)); + (u_char *)&result, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -473,14 +413,13 @@ int handle_kamailioTotalNumFailedDialogSetups(netsnmp_mib_handler *handler, int handle_kamailioTotalNumDialogSetups(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int result = get_statistic("processed_dialogs"); - if (reqinfo->mode == MODE_GET) { + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &result, sizeof(int)); + (u_char *)&result, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -489,12 +428,11 @@ int handle_kamailioTotalNumDialogSetups(netsnmp_mib_handler *handler, int handle_kamailioDialogLimitMinorThreshold(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - if (reqinfo->mode == MODE_GET) { + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &dialog_minor_threshold, sizeof(int)); + (u_char *)&dialog_minor_threshold, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -503,12 +441,11 @@ int handle_kamailioDialogLimitMinorThreshold(netsnmp_mib_handler *handler, int handle_kamailioDialogLimitMajorThreshold(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - if (reqinfo->mode == MODE_GET) { + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &dialog_major_threshold, sizeof(int)); + (u_char *)&dialog_major_threshold, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -517,8 +454,7 @@ int handle_kamailioDialogLimitMajorThreshold(netsnmp_mib_handler *handler, int handle_kamailioDialogUsageState(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { /* Return value follows the X731UsageState Textual Convention * @@ -527,20 +463,20 @@ int handle_kamailioDialogUsageState(netsnmp_mib_handler *handler, int num_dialogs = get_statistic("active_dialogs"); - if (num_dialogs==0) { + if(num_dialogs == 0) { usage_state = TC_USAGE_STATE_IDLE; } else { usage_state = TC_USAGE_STATE_ACTIVE; } - if ((dialog_major_threshold > -1) && (num_dialogs > - dialog_major_threshold)) { + if((dialog_major_threshold > -1) + && (num_dialogs > dialog_major_threshold)) { usage_state = TC_USAGE_STATE_BUSY; } - - if (reqinfo->mode == MODE_GET) { + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &usage_state, sizeof(int)); + (u_char *)&usage_state, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -550,27 +486,26 @@ int handle_kamailioDialogUsageState(netsnmp_mib_handler *handler, int handle_kamailioDialogLimitAlarmStatus(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { /* The MIB specifications say the scalar should be set to 'clear' if * everything is ok. According the X731AlarmStatus specification, * this means that no bits are toggled. So we set the state to zero by * default */ unsigned int state = 0; - - if (check_dialog_alarm(dialog_minor_threshold)) { - state |= TC_ALARM_STATUS_MINOR; + + if(check_dialog_alarm(dialog_minor_threshold)) { + state |= TC_ALARM_STATUS_MINOR; } - if (check_dialog_alarm(dialog_major_threshold)) { - state |= TC_ALARM_STATUS_MAJOR; + if(check_dialog_alarm(dialog_major_threshold)) { + state |= TC_ALARM_STATUS_MAJOR; } - - if (reqinfo->mode == MODE_GET) { - snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, - (u_char *) &state, 1); + + if(reqinfo->mode == MODE_GET) { + snmp_set_var_typed_value( + requests->requestvb, ASN_OCTET_STR, (u_char *)&state, 1); return SNMP_ERR_NOERROR; } @@ -578,22 +513,19 @@ int handle_kamailioDialogLimitAlarmStatus(netsnmp_mib_handler *handler, } - int handle_kamailioDialogLimitMinorAlarm(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int x731AlarmState = TC_ALARM_STATE_CLEAR; - if (check_dialog_alarm(dialog_minor_threshold)) - { + if(check_dialog_alarm(dialog_minor_threshold)) { x731AlarmState = TC_ALARM_STATE_MINOR; } - - if (reqinfo->mode == MODE_GET) { + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &x731AlarmState, sizeof(int)); + (u_char *)&x731AlarmState, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -602,19 +534,17 @@ int handle_kamailioDialogLimitMinorAlarm(netsnmp_mib_handler *handler, int handle_kamailioDialogLimitMajorAlarm(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int x731AlarmState = TC_ALARM_STATE_CLEAR; - if (check_dialog_alarm(dialog_major_threshold)) - { + if(check_dialog_alarm(dialog_major_threshold)) { x731AlarmState = TC_ALARM_STATE_MAJOR; } - - if (reqinfo->mode == MODE_GET) { + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &x731AlarmState, sizeof(int)); + (u_char *)&x731AlarmState, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -623,28 +553,28 @@ int handle_kamailioDialogLimitMajorAlarm(netsnmp_mib_handler *handler, /* If a proper integer is passed that is >= -1, then newValue will be set to * val, and 0 returned. Otherwise -1 is returned. */ -static int set_if_valid_threshold(modparam_t type, void *val, char *varStr, - int *newVal) +static int set_if_valid_threshold( + modparam_t type, void *val, char *varStr, int *newVal) { - if (val==0) { + if(val == 0) { LM_ERR("%s called with a null value!\n", varStr); return -1; } - if (PARAM_TYPE_MASK(type) != INT_PARAM) { - LM_ERR("%s called with type %d instead of %d!\n", - varStr, type, INT_PARAM); + if(PARAM_TYPE_MASK(type) != INT_PARAM) { + LM_ERR("%s called with type %d instead of %d!\n", varStr, type, + INT_PARAM); return -1; } - + int new_threshold = (int)(long)(int *)val; - if (new_threshold < -1) { - LM_ERR("%s called with an invalid threshold=%d!\n", - varStr, new_threshold); + if(new_threshold < -1) { + LM_ERR("%s called with an invalid threshold=%d!\n", varStr, + new_threshold); return -1; } - + *newVal = new_threshold; return 0; @@ -655,38 +585,42 @@ static int set_if_valid_threshold(modparam_t type, void *val, char *varStr, */ /* Handles setting of the message queue minor alarm threshold */ -int set_queue_minor_threshold(modparam_t type, void *val) { - return set_if_valid_threshold(type, val, "MsgQueueMinorThreshold", - &msgQueueMinorThreshold); +int set_queue_minor_threshold(modparam_t type, void *val) +{ + return set_if_valid_threshold( + type, val, "MsgQueueMinorThreshold", &msgQueueMinorThreshold); } /* Handles setting of the message queue major alarm threshold */ -int set_queue_major_threshold(modparam_t type, void *val) { - return set_if_valid_threshold(type, val, "MsgQueueMajorThreshold", - &msgQueueMajorThreshold); +int set_queue_major_threshold(modparam_t type, void *val) +{ + return set_if_valid_threshold( + type, val, "MsgQueueMajorThreshold", &msgQueueMajorThreshold); } /* Handles setting of the dialog minor threshold */ -int set_dlg_minor_threshold(modparam_t type, void *val) { - return set_if_valid_threshold(type, val, "set_dlg_minor_threshold", - &dialog_minor_threshold); +int set_dlg_minor_threshold(modparam_t type, void *val) +{ + return set_if_valid_threshold( + type, val, "set_dlg_minor_threshold", &dialog_minor_threshold); } /* Handles setting of the dialog major threshold */ -int set_dlg_major_threshold(modparam_t type, void *val) { - return set_if_valid_threshold(type, val, "set_dlg_major_threshold", - &dialog_major_threshold); +int set_dlg_major_threshold(modparam_t type, void *val) +{ + return set_if_valid_threshold( + type, val, "set_dlg_major_threshold", &dialog_major_threshold); } -int get_msg_queue_minor_threshold(void) +int get_msg_queue_minor_threshold(void) { return msgQueueMinorThreshold; } -int get_msg_queue_major_threshold(void) +int get_msg_queue_major_threshold(void) { return msgQueueMajorThreshold; } @@ -699,4 +633,4 @@ int get_dialog_minor_threshold(void) int get_dialog_major_threshold(void) { return dialog_major_threshold; -} +} \ No newline at end of file diff --git a/src/modules/snmpstats/snmpObjects.h b/src/modules/snmpstats/snmpObjects.h index f896ecc484c..bc2c94c932a 100644 --- a/src/modules/snmpstats/snmpObjects.h +++ b/src/modules/snmpstats/snmpObjects.h @@ -64,4 +64,4 @@ int get_msg_queue_major_threshold(void); int get_dialog_minor_threshold(void); int get_dialog_major_threshold(void); -#endif /* KAMAILIOOBJECTS_H */ +#endif /* KAMAILIOOBJECTS_H */ \ No newline at end of file diff --git a/src/modules/snmpstats/snmpSIPCommonObjects.c b/src/modules/snmpstats/snmpSIPCommonObjects.c index 002b02e1ebf..3ddf6465b14 100644 --- a/src/modules/snmpstats/snmpSIPCommonObjects.c +++ b/src/modules/snmpstats/snmpSIPCommonObjects.c @@ -40,7 +40,7 @@ #include "snmpstats_globals.h" #include "utilities.h" -static char *kamailioVersion = "SIP/2.0"; +static char *kamailioVersion = "SIP/2.0"; static unsigned int kamailioEntityType = TC_SIP_ENTITY_ROLE_OTHER; /* @@ -53,154 +53,126 @@ static unsigned int kamailioEntityType = TC_SIP_ENTITY_ROLE_OTHER; */ void init_kamailioSIPCommonObjects(void) { - static oid kamailioSIPProtocolVersion_oid[] = - { KAMAILIO_OID,3,1,1,1,1,1 }; + static oid kamailioSIPProtocolVersion_oid[] = { + KAMAILIO_OID, 3, 1, 1, 1, 1, 1}; - static oid kamailioSIPServiceStartTime_oid[] = - { KAMAILIO_OID,3,1,1,1,1,2 }; + static oid kamailioSIPServiceStartTime_oid[] = { + KAMAILIO_OID, 3, 1, 1, 1, 1, 2}; - static oid kamailioSIPEntityType_oid[] = - { KAMAILIO_OID,3,1,1,1,1,4 }; + static oid kamailioSIPEntityType_oid[] = {KAMAILIO_OID, 3, 1, 1, 1, 1, 4}; - static oid kamailioSIPSummaryInRequests_oid[] = - { KAMAILIO_OID,3,1,1,1,3,1 }; + static oid kamailioSIPSummaryInRequests_oid[] = { + KAMAILIO_OID, 3, 1, 1, 1, 3, 1}; - static oid kamailioSIPSummaryOutRequests_oid[] = - { KAMAILIO_OID,3,1,1,1,3,2 }; + static oid kamailioSIPSummaryOutRequests_oid[] = { + KAMAILIO_OID, 3, 1, 1, 1, 3, 2}; - static oid kamailioSIPSummaryInResponses_oid[] = - { KAMAILIO_OID,3,1,1,1,3,3 }; + static oid kamailioSIPSummaryInResponses_oid[] = { + KAMAILIO_OID, 3, 1, 1, 1, 3, 3}; - static oid kamailioSIPSummaryOutResponses_oid[] = - { KAMAILIO_OID,3,1,1,1,3,4 }; + static oid kamailioSIPSummaryOutResponses_oid[] = { + KAMAILIO_OID, 3, 1, 1, 1, 3, 4}; - static oid kamailioSIPSummaryTotalTransactions_oid[] = - { KAMAILIO_OID,3,1,1,1,3,5 }; + static oid kamailioSIPSummaryTotalTransactions_oid[] = { + KAMAILIO_OID, 3, 1, 1, 1, 3, 5}; - static oid kamailioSIPCurrentTransactions_oid[] = - { KAMAILIO_OID,3,1,1,1,6,1 }; + static oid kamailioSIPCurrentTransactions_oid[] = { + KAMAILIO_OID, 3, 1, 1, 1, 6, 1}; - static oid kamailioSIPNumUnsupportedUris_oid[] = - { KAMAILIO_OID,3,1,1,1,8,1 }; + static oid kamailioSIPNumUnsupportedUris_oid[] = { + KAMAILIO_OID, 3, 1, 1, 1, 8, 1}; - static oid kamailioSIPNumUnsupportedMethods_oid[] = - { KAMAILIO_OID,3,1,1,1,8,2 }; + static oid kamailioSIPNumUnsupportedMethods_oid[] = { + KAMAILIO_OID, 3, 1, 1, 1, 8, 2}; - static oid kamailioSIPOtherwiseDiscardedMsgs_oid[] = - { KAMAILIO_OID,3,1,1,1,8,3 }; + static oid kamailioSIPOtherwiseDiscardedMsgs_oid[] = { + KAMAILIO_OID, 3, 1, 1, 1, 8, 3}; DEBUGMSGTL(("kamailioSIPCommonObjects", "Initializing\n")); - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioSIPProtocolVersion", - handle_kamailioSIPProtocolVersion, + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioSIPProtocolVersion", handle_kamailioSIPProtocolVersion, kamailioSIPProtocolVersion_oid, - OID_LENGTH(kamailioSIPProtocolVersion_oid), - HANDLER_CAN_RONLY)); + OID_LENGTH(kamailioSIPProtocolVersion_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioSIPServiceStartTime", - handle_kamailioSIPServiceStartTime, + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioSIPServiceStartTime", handle_kamailioSIPServiceStartTime, kamailioSIPServiceStartTime_oid, - OID_LENGTH(kamailioSIPServiceStartTime_oid), - HANDLER_CAN_RONLY)); + OID_LENGTH(kamailioSIPServiceStartTime_oid), HANDLER_CAN_RONLY)); netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioSIPEntityType", - handle_kamailioSIPEntityType, - kamailioSIPEntityType_oid, - OID_LENGTH(kamailioSIPEntityType_oid), - HANDLER_CAN_RONLY)); + netsnmp_create_handler_registration("kamailioSIPEntityType", + handle_kamailioSIPEntityType, kamailioSIPEntityType_oid, + OID_LENGTH(kamailioSIPEntityType_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioSIPSummaryInRequests", - handle_kamailioSIPSummaryInRequests, + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioSIPSummaryInRequests", handle_kamailioSIPSummaryInRequests, kamailioSIPSummaryInRequests_oid, - OID_LENGTH(kamailioSIPSummaryInRequests_oid), - HANDLER_CAN_RONLY)); + OID_LENGTH(kamailioSIPSummaryInRequests_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( + netsnmp_register_scalar(netsnmp_create_handler_registration( "kamailioSIPSummaryOutRequests", handle_kamailioSIPSummaryOutRequests, kamailioSIPSummaryOutRequests_oid, - OID_LENGTH(kamailioSIPSummaryOutRequests_oid), - HANDLER_CAN_RONLY)); + OID_LENGTH(kamailioSIPSummaryOutRequests_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( + netsnmp_register_scalar(netsnmp_create_handler_registration( "kamailioSIPSummaryInResponses", handle_kamailioSIPSummaryInResponses, kamailioSIPSummaryInResponses_oid, - OID_LENGTH(kamailioSIPSummaryInResponses_oid), - HANDLER_CAN_RONLY)); + OID_LENGTH(kamailioSIPSummaryInResponses_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( + netsnmp_register_scalar(netsnmp_create_handler_registration( "kamailioSIPSummaryOutResponses", handle_kamailioSIPSummaryOutResponses, kamailioSIPSummaryOutResponses_oid, - OID_LENGTH(kamailioSIPSummaryOutResponses_oid), - HANDLER_CAN_RONLY)); + OID_LENGTH(kamailioSIPSummaryOutResponses_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( + netsnmp_register_scalar(netsnmp_create_handler_registration( "kamailioSIPSummaryTotalTransactions", handle_kamailioSIPSummaryTotalTransactions, kamailioSIPSummaryTotalTransactions_oid, OID_LENGTH(kamailioSIPSummaryTotalTransactions_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( + netsnmp_register_scalar(netsnmp_create_handler_registration( "kamailioSIPCurrentTransactions", handle_kamailioSIPCurrentTransactions, kamailioSIPCurrentTransactions_oid, - OID_LENGTH(kamailioSIPCurrentTransactions_oid), - HANDLER_CAN_RONLY)); + OID_LENGTH(kamailioSIPCurrentTransactions_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( + netsnmp_register_scalar(netsnmp_create_handler_registration( "kamailioSIPNumUnsupportedUris", handle_kamailioSIPNumUnsupportedUris, kamailioSIPNumUnsupportedUris_oid, - OID_LENGTH(kamailioSIPNumUnsupportedUris_oid), - HANDLER_CAN_RONLY)); + OID_LENGTH(kamailioSIPNumUnsupportedUris_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( + netsnmp_register_scalar(netsnmp_create_handler_registration( "kamailioSIPNumUnsupportedMethods", handle_kamailioSIPNumUnsupportedMethods, kamailioSIPNumUnsupportedMethods_oid, OID_LENGTH(kamailioSIPNumUnsupportedMethods_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( + netsnmp_register_scalar(netsnmp_create_handler_registration( "kamailioSIPOtherwiseDiscardedMsgs", handle_kamailioSIPOtherwiseDiscardedMsgs, kamailioSIPOtherwiseDiscardedMsgs_oid, OID_LENGTH(kamailioSIPOtherwiseDiscardedMsgs_oid), - HANDLER_CAN_RONLY)); - + HANDLER_CAN_RONLY)); } int handle_kamailioSIPProtocolVersion(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) -{ - if (reqinfo->mode==MODE_GET) { + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) +{ + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, - (u_char *) kamailioVersion, 7); + (u_char *)kamailioVersion, 7); return SNMP_ERR_NOERROR; } - return SNMP_ERR_GENERR; + return SNMP_ERR_GENERR; } /* @@ -210,8 +182,7 @@ int handle_kamailioSIPProtocolVersion(netsnmp_mib_handler *handler, */ int handle_kamailioSIPServiceStartTime(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int elapsedTime = 0; @@ -221,49 +192,47 @@ int handle_kamailioSIPServiceStartTime(netsnmp_mib_handler *handler, /* Open the file created by spawn_sysUpTime_child(), and parse our the * required data. */ - if (theFile == NULL) { - LM_ERR("failed to read sysUpTime file at %s\n", - SNMPGET_TEMP_FILE); + if(theFile == NULL) { + LM_ERR("failed to read sysUpTime file at %s\n", SNMPGET_TEMP_FILE); } else { - if(fgets(buffer, SNMPGET_MAX_BUFFER, theFile)==NULL) + if(fgets(buffer, SNMPGET_MAX_BUFFER, theFile) == NULL) LM_ERR("failed to read from sysUpTime file at %s\n", SNMPGET_TEMP_FILE); /* Find the positions of '(' and ')' so we can extract out the * timeticks value. */ - char *openBracePosition = strchr(buffer, '('); + char *openBracePosition = strchr(buffer, '('); char *closedBracePosition = strchr(buffer, ')'); /* Make sure that both the '(' and ')' exist in the file, and * that '(' occurs earlier than the ')'. If all these * conditions are true, then attempt to convert the string into * an integer. */ - if (openBracePosition != NULL && closedBracePosition != NULL && - openBracePosition < closedBracePosition) { - elapsedTime = (int) strtol(++openBracePosition, NULL, 10); + if(openBracePosition != NULL && closedBracePosition != NULL + && openBracePosition < closedBracePosition) { + elapsedTime = (int)strtol(++openBracePosition, NULL, 10); } fclose(theFile); } - if (reqinfo->mode == MODE_GET) { + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_TIMETICKS, - (u_char *) &elapsedTime, sizeof(elapsedTime)); + (u_char *)&elapsedTime, sizeof(elapsedTime)); return SNMP_ERR_NOERROR; } - + return SNMP_ERR_GENERR; } int handle_kamailioSIPEntityType(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - if (reqinfo->mode==MODE_GET) { + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, - (u_char *) &kamailioEntityType, 1); + (u_char *)&kamailioEntityType, 1); return SNMP_ERR_NOERROR; } @@ -273,14 +242,13 @@ int handle_kamailioSIPEntityType(netsnmp_mib_handler *handler, int handle_kamailioSIPSummaryInRequests(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int numRequests = get_statistic("rcv_requests"); - - if (reqinfo->mode==MODE_GET) { + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &numRequests, sizeof(int)); + (u_char *)&numRequests, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -289,14 +257,13 @@ int handle_kamailioSIPSummaryInRequests(netsnmp_mib_handler *handler, int handle_kamailioSIPSummaryOutRequests(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int out_requests = get_statistic("fwd_requests"); - - if (reqinfo->mode==MODE_GET) { + int out_requests = get_statistic("fwd_requests"); + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &out_requests, sizeof(int)); + (u_char *)&out_requests, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -305,14 +272,13 @@ int handle_kamailioSIPSummaryOutRequests(netsnmp_mib_handler *handler, int handle_kamailioSIPSummaryInResponses(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int result = get_statistic("rcv_replies"); - - if (reqinfo->mode==MODE_GET) { + int result = get_statistic("rcv_replies"); + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &result, sizeof(int)); + (u_char *)&result, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -321,8 +287,7 @@ int handle_kamailioSIPSummaryInResponses(netsnmp_mib_handler *handler, int handle_kamailioSIPSummaryOutResponses(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { /* We can find the number of outbound responses sent by adding three * sources @@ -331,18 +296,17 @@ int handle_kamailioSIPSummaryOutResponses(netsnmp_mib_handler *handler, * 2) local_replies and relayed_replies from the tm module * 3) sent_replies from the sl module. */ - - int fwd_replies = get_statistic("fwd_replies"); - int local_replies = get_statistic("local_replies"); + + int fwd_replies = get_statistic("fwd_replies"); + int local_replies = get_statistic("local_replies"); int relayed_replies = get_statistic("relayed_replies"); - int sent_replies = get_statistic("sent_replies"); + int sent_replies = get_statistic("sent_replies"); - int result = - fwd_replies + local_replies + relayed_replies + sent_replies; - - if (reqinfo->mode==MODE_GET) { + int result = fwd_replies + local_replies + relayed_replies + sent_replies; + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &result, sizeof(int)); + (u_char *)&result, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -351,20 +315,18 @@ int handle_kamailioSIPSummaryOutResponses(netsnmp_mib_handler *handler, int handle_kamailioSIPSummaryTotalTransactions(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { /* We can find the total number of transactions by summing * UAC_transactions and UAS_transactions. We don't need to add * inuse_transactions because this will already be accounted for in the * two other statistics. */ - int result = - get_statistic("UAS_transactions") + - get_statistic("UAC_transactions"); + int result = get_statistic("UAS_transactions") + + get_statistic("UAC_transactions"); - if (reqinfo->mode==MODE_GET) { + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &result, sizeof(int)); + (u_char *)&result, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -373,14 +335,13 @@ int handle_kamailioSIPSummaryTotalTransactions(netsnmp_mib_handler *handler, int handle_kamailioSIPCurrentTransactions(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int result = get_statistic("inuse_transactions"); - - if (reqinfo->mode==MODE_GET) { - snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, - (u_char *) &result, sizeof(int)); + + if(reqinfo->mode == MODE_GET) { + snmp_set_var_typed_value( + requests->requestvb, ASN_GAUGE, (u_char *)&result, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -389,14 +350,13 @@ int handle_kamailioSIPCurrentTransactions(netsnmp_mib_handler *handler, int handle_kamailioSIPNumUnsupportedUris(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int result = get_statistic("bad_URIs_rcvd"); - - if (reqinfo->mode==MODE_GET) { + int result = get_statistic("bad_URIs_rcvd"); + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &result, sizeof(int)); + (u_char *)&result, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -405,14 +365,13 @@ int handle_kamailioSIPNumUnsupportedUris(netsnmp_mib_handler *handler, int handle_kamailioSIPNumUnsupportedMethods(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int result = get_statistic("unsupported_methods"); - - if (reqinfo->mode==MODE_GET) { + int result = get_statistic("unsupported_methods"); + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &result, sizeof(int)); + (u_char *)&result, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -421,20 +380,17 @@ int handle_kamailioSIPNumUnsupportedMethods(netsnmp_mib_handler *handler, int handle_kamailioSIPOtherwiseDiscardedMsgs(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { /* We should be able to get this number from existing stats layed out in * the following equation: */ - int result = - get_statistic("err_requests") + - get_statistic("err_replies") + - get_statistic("drop_requests") + - get_statistic("drop_replies"); - - if (reqinfo->mode==MODE_GET) { + int result = get_statistic("err_requests") + get_statistic("err_replies") + + get_statistic("drop_requests") + + get_statistic("drop_replies"); + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &result, sizeof(int)); + (u_char *)&result, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -452,13 +408,13 @@ int handle_kamailioSIPOtherwiseDiscardedMsgs(netsnmp_mib_handler *handler, * * Returns 0 on success, -1 on failure. */ -int handleSipEntityType( modparam_t type, void* val) +int handleSipEntityType(modparam_t type, void *val) { - + /* By default we start off as "other". */ static char firstTime = 1; - if (!stringHandlerSanityCheck(type, val, "sipEntityType")) { + if(!stringHandlerSanityCheck(type, val, "sipEntityType")) { return -1; } @@ -467,41 +423,35 @@ int handleSipEntityType( modparam_t type, void* val) /* This is our first time through this function, so we need to change * kamailioEntityType from its default to 0, allowing our bitmasks below * to work as expected. */ - if (firstTime) { + if(firstTime) { firstTime = 0; kamailioEntityType = 0; - } + } /* Begin our string comparison. This isn't the most efficient approach, * but we don't expect this function to be called anywhere other than at * startup. So our inefficiency is outweiged by simplicity */ - if (strcasecmp(strEntityType, "other") == 0) { + if(strcasecmp(strEntityType, "other") == 0) { kamailioEntityType |= TC_SIP_ENTITY_ROLE_OTHER; - } - else if (strcasecmp(strEntityType, "userAgent") == 0) { - kamailioEntityType |= TC_SIP_ENTITY_ROLE_USER_AGENT; - } - else if (strcasecmp(strEntityType, "proxyServer") == 0) { - kamailioEntityType |= TC_SIP_ENTITY_ROLE_PROXY_SERVER; - } - else if (strcasecmp(strEntityType, "redirectServer") == 0) { + } else if(strcasecmp(strEntityType, "userAgent") == 0) { + kamailioEntityType |= TC_SIP_ENTITY_ROLE_USER_AGENT; + } else if(strcasecmp(strEntityType, "proxyServer") == 0) { + kamailioEntityType |= TC_SIP_ENTITY_ROLE_PROXY_SERVER; + } else if(strcasecmp(strEntityType, "redirectServer") == 0) { kamailioEntityType |= TC_SIP_ENTITY_ROLE_REDIRECT_SERVER; - } - else if (strcasecmp(strEntityType, "registrarServer") == 0) { + } else if(strcasecmp(strEntityType, "registrarServer") == 0) { kamailioEntityType |= TC_SIP_ENTITY_ROLE_REGISTRAR_SERVER; - } - else if (strcasecmp(strEntityType, "edgeproxyServer") == 0) { + } else if(strcasecmp(strEntityType, "edgeproxyServer") == 0) { kamailioEntityType |= TC_SIP_ENTITY_ROLE_EDGEPROXY_SERVER; - } - else if (strcasecmp(strEntityType, "sipcaptureServer") == 0) { + } else if(strcasecmp(strEntityType, "sipcaptureServer") == 0) { kamailioEntityType |= TC_SIP_ENTITY_ROLE_SIPCAPTURE_SERVER; - } - else { + } else { LM_ERR("The configuration file specified sipEntityType=%s," - " an unknown type\n", strEntityType); + " an unknown type\n", + strEntityType); return -1; } return 0; -} +} \ No newline at end of file diff --git a/src/modules/snmpstats/snmpSIPCommonObjects.h b/src/modules/snmpstats/snmpSIPCommonObjects.h index 8779c8a6681..4fc03f05d2d 100644 --- a/src/modules/snmpstats/snmpSIPCommonObjects.h +++ b/src/modules/snmpstats/snmpSIPCommonObjects.h @@ -45,4 +45,4 @@ Netsnmp_Node_Handler handle_kamailioSIPNumUnsupportedUris; Netsnmp_Node_Handler handle_kamailioSIPNumUnsupportedMethods; Netsnmp_Node_Handler handle_kamailioSIPOtherwiseDiscardedMsgs; -#endif /* KAMAILIOSIPCOMMONOBJECTS_H */ +#endif /* KAMAILIOSIPCOMMONOBJECTS_H */ \ No newline at end of file diff --git a/src/modules/snmpstats/snmpSIPContactTable.c b/src/modules/snmpstats/snmpSIPContactTable.c index ccd786e02f9..582d5d6634b 100644 --- a/src/modules/snmpstats/snmpSIPContactTable.c +++ b/src/modules/snmpstats/snmpSIPContactTable.c @@ -84,8 +84,9 @@ static netsnmp_handler_registration *my_handler = NULL; static netsnmp_table_array_callbacks cb; -oid kamailioSIPContactTable_oid[] = { kamailioSIPContactTable_TABLE_OID }; -size_t kamailioSIPContactTable_oid_len = OID_LENGTH(kamailioSIPContactTable_oid); +oid kamailioSIPContactTable_oid[] = {kamailioSIPContactTable_TABLE_OID}; +size_t kamailioSIPContactTable_oid_len = + OID_LENGTH(kamailioSIPContactTable_oid); /* * This function adds a new contactToIndexStruct_t record to the front of @@ -96,23 +97,25 @@ size_t kamailioSIPContactTable_oid_len = OID_LENGTH(kamailioSIPContactTable_oid) * we need to find out which SNMP row the information is stored under. */ int insertContactRecord( - contactToIndexStruct_t **contactRecord, int index, char *name) + contactToIndexStruct_t **contactRecord, int index, char *name) { - int nameLength =strlen(name); - - contactToIndexStruct_t *newContactRecord = (contactToIndexStruct_t *) - pkg_malloc(sizeof(contactToIndexStruct_t) +(nameLength+1)* sizeof(char)); - - if (newContactRecord == NULL) - { - LM_ERR("no more pkg memory\n"); + int nameLength = strlen(name); + + contactToIndexStruct_t *newContactRecord = + (contactToIndexStruct_t *)pkg_malloc( + sizeof(contactToIndexStruct_t) + + (nameLength + 1) * sizeof(char)); + + if(newContactRecord == NULL) { + LM_ERR("no more pkg memory\n"); return 0; } - newContactRecord->next = *contactRecord; - newContactRecord->contactName = (char*)newContactRecord + sizeof(contactToIndexStruct_t); - memcpy(newContactRecord->contactName, name, nameLength); - newContactRecord->contactName[nameLength]= '\0'; + newContactRecord->next = *contactRecord; + newContactRecord->contactName = + (char *)newContactRecord + sizeof(contactToIndexStruct_t); + memcpy(newContactRecord->contactName, name, nameLength); + newContactRecord->contactName[nameLength] = '\0'; newContactRecord->contactIndex = index; *contactRecord = newContactRecord; @@ -127,32 +130,31 @@ int insertContactRecord( * the records index. In the event that the record could not be found, 0 will * be returned. */ -int deleteContactRecord(contactToIndexStruct_t **contactRecord,char *contactName) +int deleteContactRecord( + contactToIndexStruct_t **contactRecord, char *contactName) { int contactIndexToReturn; - contactToIndexStruct_t *currentContact = *contactRecord; + contactToIndexStruct_t *currentContact = *contactRecord; contactToIndexStruct_t *previousContact = *contactRecord; - while (currentContact != NULL) { + while(currentContact != NULL) { - if (strcmp(currentContact->contactName, contactName) == 0) - { + if(strcmp(currentContact->contactName, contactName) == 0) { /* This means that this is the first element. Link up * the pointer to the next element */ - if (currentContact == previousContact) { + if(currentContact == previousContact) { *contactRecord = currentContact->next; } else { previousContact->next = currentContact->next; } contactIndexToReturn = currentContact->contactIndex; - pkg_free(currentContact); + pkg_free(currentContact); return contactIndexToReturn; } previousContact = currentContact; - currentContact = currentContact->next; - + currentContact = currentContact->next; } return 0; @@ -165,25 +167,25 @@ int deleteContactRecord(contactToIndexStruct_t **contactRecord,char *contactName * * Returns: 1 on success, and 0 otherwise. */ -int createContactRow(int userIndex, int contactIndex, char *contactName, - ucontact_t *contactInfo) +int createContactRow(int userIndex, int contactIndex, char *contactName, + ucontact_t *contactInfo) { kamailioSIPContactTable_context *theRow; - oid *OIDIndex; - int stringLength; + oid *OIDIndex; + int stringLength; theRow = SNMP_MALLOC_TYPEDEF(kamailioSIPContactTable_context); - if (theRow == NULL) { + if(theRow == NULL) { LM_ERR("failed to create a row for kamailioSIPContactTable\n"); return 0; } /* We need enough memory for both the user index and contact index. */ - OIDIndex = pkg_malloc(sizeof(oid)*2); + OIDIndex = pkg_malloc(sizeof(oid) * 2); - if (OIDIndex == NULL) { + if(OIDIndex == NULL) { free(theRow); LM_ERR("failed to create a row for kamailioSIPContactTable\n"); return 0; @@ -195,24 +197,23 @@ int createContactRow(int userIndex, int contactIndex, char *contactName, OIDIndex[0] = userIndex; OIDIndex[1] = contactIndex; - theRow->index.len = 2; + theRow->index.len = 2; theRow->index.oids = OIDIndex; theRow->kamailioSIPContactIndex = contactIndex; /* Fill in the rest of the rows columns */ - theRow->kamailioSIPContactURI = (unsigned char*) - pkg_malloc((stringLength+ 1)* sizeof(char)); - if(theRow->kamailioSIPContactURI == NULL) - { - pkg_free(OIDIndex); + theRow->kamailioSIPContactURI = + (unsigned char *)pkg_malloc((stringLength + 1) * sizeof(char)); + if(theRow->kamailioSIPContactURI == NULL) { + pkg_free(OIDIndex); free(theRow); LM_ERR("failed to allocate memory for contact name\n"); return 0; - } - memcpy(theRow->kamailioSIPContactURI, contactName, stringLength); - theRow->kamailioSIPContactURI[stringLength] = '\0'; + } + memcpy(theRow->kamailioSIPContactURI, contactName, stringLength); + theRow->kamailioSIPContactURI[stringLength] = '\0'; - theRow->kamailioSIPContactURI_len = stringLength; + theRow->kamailioSIPContactURI_len = stringLength; theRow->contactInfo = contactInfo; CONTAINER_INSERT(cb.container, theRow); @@ -225,7 +226,7 @@ int createContactRow(int userIndex, int contactIndex, char *contactName, * Removes the row indexed by userIndex and contactIndex, and free's up the * memory allocated to it. If the row could not be found, then nothing is done. */ -void deleteContactRow(int userIndex, int contactIndex) +void deleteContactRow(int userIndex, int contactIndex) { kamailioSIPContactTable_context *theRow; @@ -235,20 +236,20 @@ void deleteContactRow(int userIndex, int contactIndex) /* Form the OID Index of the row so we can search for it */ indexToRemoveOID[0] = userIndex; indexToRemoveOID[1] = contactIndex; - indexToRemove.oids = indexToRemoveOID; - indexToRemove.len = 2; + indexToRemove.oids = indexToRemoveOID; + indexToRemove.len = 2; theRow = CONTAINER_FIND(cb.container, &indexToRemove); /* The ContactURI is shared memory, the index.oids was allocated from * pkg_malloc(), and theRow was made with the NetSNMP API which uses * malloc() */ - if (theRow != NULL) { + if(theRow != NULL) { CONTAINER_REMOVE(cb.container, &indexToRemove); pkg_free(theRow->kamailioSIPContactURI); pkg_free(theRow->index.oids); free(theRow); - } + } } /* @@ -269,7 +270,6 @@ void init_kamailioSIPContactTable(void) } - /* * Initialize the kamailioSIPContactTable table by defining its contents and how * it's structured. @@ -282,7 +282,7 @@ void initialize_table_kamailioSIPContactTable(void) if(my_handler) { snmp_log(LOG_ERR, "initialize_table_kamailioSIPContactTable_" - "handler called again\n"); + "handler called again\n"); return; } @@ -291,16 +291,13 @@ void initialize_table_kamailioSIPContactTable(void) /** create the table structure itself */ table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); - my_handler = netsnmp_create_handler_registration( - "kamailioSIPContactTable", - netsnmp_table_array_helper_handler, - kamailioSIPContactTable_oid, - kamailioSIPContactTable_oid_len, - HANDLER_CAN_RONLY); - - if (!my_handler || !table_info) { + my_handler = netsnmp_create_handler_registration("kamailioSIPContactTable", + netsnmp_table_array_helper_handler, kamailioSIPContactTable_oid, + kamailioSIPContactTable_oid_len, HANDLER_CAN_RONLY); + + if(!my_handler || !table_info) { snmp_log(LOG_ERR, "malloc failed in initialize_table_kamailio" - "SIPContactTable_handler\n"); + "SIPContactTable_handler\n"); return; /** mallocs failed */ } @@ -317,14 +314,15 @@ void initialize_table_kamailioSIPContactTable(void) */ cb.get_value = kamailioSIPContactTable_get_value; cb.container = netsnmp_container_find("kamailioSIPContactTable_primary:" - "kamailioSIPContactTable:" "table_container"); - + "kamailioSIPContactTable:" + "table_container"); + DEBUGMSGTL(("initialize_table_kamailioSIPContactTable", - "Registering table kamailioSIPContactTable " - "as a table array\n")); - - netsnmp_table_container_register(my_handler, table_info, &cb, - cb.container, 1); + "Registering table kamailioSIPContactTable " + "as a table array\n")); + + netsnmp_table_container_register( + my_handler, table_info, &cb, cb.container, 1); } @@ -337,20 +335,18 @@ void initialize_table_kamailioSIPContactTable(void) * may have changed since the row was first created. Therefore, this data is * retrieved when it is requested for. */ -int kamailioSIPContactTable_get_value( - netsnmp_request_info *request, - netsnmp_index *item, - netsnmp_table_request_info *table_info ) +int kamailioSIPContactTable_get_value(netsnmp_request_info *request, + netsnmp_index *item, netsnmp_table_request_info *table_info) { - static char defaultExpiry[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + static char defaultExpiry[8] = {0, 0, 0, 0, 0, 0, 0, 0}; /* Needs to be large enough to hold the null terminated string "-0.01". */ - char contactPreference[6]; - float preferenceAsFloat = -1; + char contactPreference[6]; + float preferenceAsFloat = -1; - char *retrievedExpiry; - struct tm *timeValue; + char *retrievedExpiry; + struct tm *timeValue; /* First things first, we need to consume the interprocess buffer, in * case something has changed. We want to return the freshest data. */ @@ -358,69 +354,56 @@ int kamailioSIPContactTable_get_value( netsnmp_variable_list *var = request->requestvb; - kamailioSIPContactTable_context *context = - (kamailioSIPContactTable_context *)item; + kamailioSIPContactTable_context *context = + (kamailioSIPContactTable_context *)item; - switch(table_info->colnum) - { + switch(table_info->colnum) { case COLUMN_KAMAILIOSIPCONTACTDISPLAYNAME: /* FIXME: WHERE DO WE FIND THIS?? Setting to the same * thing as contact uri for now. */ - snmp_set_var_typed_value(var, ASN_OCTET_STR, - (unsigned char*) - context->kamailioSIPContactURI, + snmp_set_var_typed_value(var, ASN_OCTET_STR, + (unsigned char *)context->kamailioSIPContactURI, context->kamailioSIPContactURI_len); break; case COLUMN_KAMAILIOSIPCONTACTURI: snmp_set_var_typed_value(var, ASN_OCTET_STR, - (unsigned char*) - context->kamailioSIPContactURI, - context->kamailioSIPContactURI_len); + (unsigned char *)context->kamailioSIPContactURI, + context->kamailioSIPContactURI_len); break; - + case COLUMN_KAMAILIOSIPCONTACTLASTUPDATED: - - if (context->contactInfo != NULL) - { - timeValue = - localtime(&(context->contactInfo->last_modified)); - retrievedExpiry = - convertTMToSNMPDateAndTime(timeValue); + + if(context->contactInfo != NULL) { + timeValue = localtime(&(context->contactInfo->last_modified)); + retrievedExpiry = convertTMToSNMPDateAndTime(timeValue); } else { retrievedExpiry = defaultExpiry; } - snmp_set_var_typed_value(var, ASN_OCTET_STR, - (unsigned char*) - retrievedExpiry, - 8); + snmp_set_var_typed_value( + var, ASN_OCTET_STR, (unsigned char *)retrievedExpiry, 8); break; - + case COLUMN_KAMAILIOSIPCONTACTEXPIRY: - if (context->contactInfo != NULL) - { - timeValue = - localtime(&(context->contactInfo->expires)); + if(context->contactInfo != NULL) { + timeValue = localtime(&(context->contactInfo->expires)); - retrievedExpiry = - convertTMToSNMPDateAndTime(timeValue); + retrievedExpiry = convertTMToSNMPDateAndTime(timeValue); } else { retrievedExpiry = defaultExpiry; } - snmp_set_var_typed_value(var, ASN_OCTET_STR, - (unsigned char*) - retrievedExpiry, - 8); + snmp_set_var_typed_value( + var, ASN_OCTET_STR, (unsigned char *)retrievedExpiry, 8); break; - + case COLUMN_KAMAILIOSIPCONTACTPREFERENCE: - if (context->contactInfo != NULL) { + if(context->contactInfo != NULL) { preferenceAsFloat = context->contactInfo->q; } @@ -434,15 +417,13 @@ int kamailioSIPContactTable_get_value( * MIB. */ sprintf(contactPreference, "%5.2f", preferenceAsFloat); - snmp_set_var_typed_value(var, ASN_OCTET_STR, - (unsigned char*) - contactPreference, - 5); + snmp_set_var_typed_value( + var, ASN_OCTET_STR, (unsigned char *)contactPreference, 5); break; - + default: /** We shouldn't get here */ snmp_log(LOG_ERR, "unknown column in " - "kamailioSIPContactTable_get_value\n"); + "kamailioSIPContactTable_get_value\n"); return SNMP_ERR_GENERR; } @@ -452,11 +433,9 @@ int kamailioSIPContactTable_get_value( /* * kamailioSIPContactTable_get_by_idx is an auto-generated function. */ -const kamailioSIPContactTable_context * -kamailioSIPContactTable_get_by_idx(netsnmp_index * hdr) +const kamailioSIPContactTable_context *kamailioSIPContactTable_get_by_idx( + netsnmp_index *hdr) { - return (const kamailioSIPContactTable_context *) - CONTAINER_FIND(cb.container, hdr ); -} - - + return (const kamailioSIPContactTable_context *)CONTAINER_FIND( + cb.container, hdr); +} \ No newline at end of file diff --git a/src/modules/snmpstats/snmpSIPContactTable.h b/src/modules/snmpstats/snmpSIPContactTable.h index fb8845539e9..0992e7a2459 100644 --- a/src/modules/snmpstats/snmpSIPContactTable.h +++ b/src/modules/snmpstats/snmpSIPContactTable.h @@ -61,7 +61,7 @@ extern "C" { #endif - + #include #include #include @@ -77,21 +77,21 @@ extern "C" { * was done because the values change over time. Therefore we retrieve the data * only when it is requested for, instead of storing stale data. */ -typedef struct kamailioSIPContactTable_context_s +typedef struct kamailioSIPContactTable_context_s { netsnmp_index index; /** THIS MUST BE FIRST!!! */ unsigned long kamailioSIPContactIndex; unsigned char *kamailioSIPContactURI; - long kamailioSIPContactURI_len; + long kamailioSIPContactURI_len; /* A pointer to the rest of the contact structure, giving us access to * kamailioSIPContactURI, kamailioSIPContactExpirty, and * kamailioSIPContactPreference. */ ucontact_t *contactInfo; - void * data; + void *data; } kamailioSIPContactTable_context; @@ -105,7 +105,7 @@ typedef struct kamailioSIPContactTable_context_s * * Returns: 1 on success, and 0 otherwise. */ -int createContactRow(int userIndex, int contactIndex, char *contactName, +int createContactRow(int userIndex, int contactIndex, char *contactName, ucontact_t *contactInfo); /* @@ -123,8 +123,8 @@ void deleteContactRow(int userIndex, int contactIndex); * indexing scheme. It will be used later when a delete command comes in, and * we need to find out which SNMP row the information is stored under. */ -int insertContactRecord(contactToIndexStruct_t **contactRecord, int index, - char *name); +int insertContactRecord( + contactToIndexStruct_t **contactRecord, int index, char *name); /* * This function will remove the contactToIndexStruct_T record matching @@ -132,8 +132,8 @@ int insertContactRecord(contactToIndexStruct_t **contactRecord, int index, * the records index. In the event that the record could not be found, 0 will * be returned. */ -int deleteContactRecord(contactToIndexStruct_t **contactRecord, - char *contactName); +int deleteContactRecord( + contactToIndexStruct_t **contactRecord, char *contactName); /********************************/ @@ -148,7 +148,7 @@ int deleteContactRecord(contactToIndexStruct_t **contactRecord, * 2) Creating a default row, so that there is a row to query to trigger the * consumption of the interprocess buffer. */ -void init_kamailioSIPContactTable(void); +void init_kamailioSIPContactTable(void); /* @@ -157,34 +157,34 @@ void init_kamailioSIPContactTable(void); * * This function is mostly auto-generated. */ -void initialize_table_kamailioSIPContactTable(void); +void initialize_table_kamailioSIPContactTable(void); -const kamailioSIPContactTable_context * kamailioSIPContactTable_get_by_idx( +const kamailioSIPContactTable_context *kamailioSIPContactTable_get_by_idx( netsnmp_index *); -const kamailioSIPContactTable_context * kamailioSIPContactTable_get_by_idx_rs( +const kamailioSIPContactTable_context *kamailioSIPContactTable_get_by_idx_rs( netsnmp_index *, int row_status); /* This routine is called to process get requests for elements of the table. */ -int kamailioSIPContactTable_get_value(netsnmp_request_info *, netsnmp_index *, - netsnmp_table_request_info *); +int kamailioSIPContactTable_get_value( + netsnmp_request_info *, netsnmp_index *, netsnmp_table_request_info *); /* oid declarations */ -extern oid kamailioSIPContactTable_oid[]; +extern oid kamailioSIPContactTable_oid[]; extern size_t kamailioSIPContactTable_oid_len; -#define kamailioSIPContactTable_TABLE_OID KAMAILIO_OID,3,1,2,1,5,7 - +#define kamailioSIPContactTable_TABLE_OID KAMAILIO_OID, 3, 1, 2, 1, 5, 7 + /************************************************************* * column number definitions for table kamailioSIPContactTable */ -#define COLUMN_KAMAILIOSIPCONTACTINDEX 1 +#define COLUMN_KAMAILIOSIPCONTACTINDEX 1 #define COLUMN_KAMAILIOSIPCONTACTDISPLAYNAME 2 -#define COLUMN_KAMAILIOSIPCONTACTURI 3 +#define COLUMN_KAMAILIOSIPCONTACTURI 3 #define COLUMN_KAMAILIOSIPCONTACTLASTUPDATED 4 -#define COLUMN_KAMAILIOSIPCONTACTEXPIRY 5 -#define COLUMN_KAMAILIOSIPCONTACTPREFERENCE 6 +#define COLUMN_KAMAILIOSIPCONTACTEXPIRY 5 +#define COLUMN_KAMAILIOSIPCONTACTPREFERENCE 6 #define kamailioSIPContactTable_COL_MIN 2 #define kamailioSIPContactTable_COL_MAX 6 @@ -193,4 +193,4 @@ extern size_t kamailioSIPContactTable_oid_len; } #endif -#endif /** KAMAILIOSIPCONTACTTABLE_H */ +#endif /** KAMAILIOSIPCONTACTTABLE_H */ \ No newline at end of file diff --git a/src/modules/snmpstats/snmpSIPMethodSupportedTable.c b/src/modules/snmpstats/snmpSIPMethodSupportedTable.c index 58e82f1593e..4dc3394dbee 100644 --- a/src/modules/snmpstats/snmpSIPMethodSupportedTable.c +++ b/src/modules/snmpstats/snmpSIPMethodSupportedTable.c @@ -45,34 +45,35 @@ static netsnmp_handler_registration *my_handler = NULL; static netsnmp_table_array_callbacks cb; -oid kamailioSIPMethodSupportedTable_oid[] = - { kamailioSIPMethodSupportedTable_TABLE_OID }; +oid kamailioSIPMethodSupportedTable_oid[] = { + kamailioSIPMethodSupportedTable_TABLE_OID}; -size_t kamailioSIPMethodSupportedTable_oid_len = - OID_LENGTH(kamailioSIPMethodSupportedTable_oid); +size_t kamailioSIPMethodSupportedTable_oid_len = + OID_LENGTH(kamailioSIPMethodSupportedTable_oid); /* Create a row at the given index, containing stringToRegister, and insert it * into the table. Note that stringToRegister will be copied, so it is not * necessary to pre-allocate this string anywhere. */ -void createRow(int index, char *stringToRegister) { +void createRow(int index, char *stringToRegister) +{ kamailioSIPMethodSupportedTable_context *theRow; - oid *OIDIndex; + oid *OIDIndex; char *copiedString; - int stringLength; + int stringLength; theRow = SNMP_MALLOC_TYPEDEF(kamailioSIPMethodSupportedTable_context); - if (theRow == NULL) { + if(theRow == NULL) { LM_ERR("failed to create a row for kamailioSIPMethodSupportedTable\n"); return; } OIDIndex = pkg_malloc(sizeof(oid)); - if (OIDIndex == NULL) { + if(OIDIndex == NULL) { free(theRow); LM_ERR("failed to create a row for kamailioSIPMethodSupportedTable\n"); return; @@ -82,7 +83,7 @@ void createRow(int index, char *stringToRegister) { copiedString = pkg_malloc((stringLength + 1) * sizeof(char)); - if (copiedString == NULL) { + if(copiedString == NULL) { free(theRow); free(OIDIndex); LM_ERR("failed to create a row for kamailioSIPMethodSupportedTable\n"); @@ -93,11 +94,11 @@ void createRow(int index, char *stringToRegister) { OIDIndex[0] = index; - theRow->index.len = 1; + theRow->index.len = 1; theRow->index.oids = OIDIndex; theRow->kamailioSIPMethodSupportedIndex = index; - theRow->kamailioSIPMethodName = (unsigned char*) copiedString; + theRow->kamailioSIPMethodName = (unsigned char *)copiedString; theRow->kamailioSIPMethodName_len = stringLength; CONTAINER_INSERT(cb.container, theRow); @@ -133,26 +134,26 @@ void init_kamailioSIPMethodSupportedTable(void) * * NOTE: My way of checking what METHODS we support is probably wrong. * Please feel free to correct it! */ - + createRow(1, "METHOD_INVITE"); createRow(2, "METHOD_CANCEL"); createRow(3, "METHOD_ACK"); createRow(4, "METHOD_BYE"); - if (module_loaded("options") || module_loaded("siputils")) { + if(module_loaded("options") || module_loaded("siputils")) { createRow(6, "METHOD_OPTIONS"); } createRow(7, "METHOD_UPDATE"); - if (module_loaded("registrar")) { + if(module_loaded("registrar")) { createRow(8, "METHOD_REGISTER"); createRow(10, "METHOD_SUBSCRIBE"); createRow(11, "METHOD_NOTIFY"); } - createRow(5, "METHOD_INFO"); - createRow(9, "METHOD_MESSAGE"); + createRow(5, "METHOD_INFO"); + createRow(9, "METHOD_MESSAGE"); createRow(12, "METHOD_PRACK"); createRow(13, "METHOD_REFER"); createRow(14, "METHOD_PUBLISH"); @@ -167,7 +168,7 @@ void initialize_table_kamailioSIPMethodSupportedTable(void) if(my_handler) { snmp_log(LOG_ERR, "initialize_table_kamailioSIPMethodSupported" - "Table_handler called again\n"); + "Table_handler called again\n"); return; } @@ -176,18 +177,16 @@ void initialize_table_kamailioSIPMethodSupportedTable(void) /** create the table structure itself */ table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); - my_handler = - netsnmp_create_handler_registration( + my_handler = netsnmp_create_handler_registration( "kamailioSIPMethodSupportedTable", netsnmp_table_array_helper_handler, kamailioSIPMethodSupportedTable_oid, - kamailioSIPMethodSupportedTable_oid_len, - HANDLER_CAN_RONLY); - - if (!my_handler || !table_info) { + kamailioSIPMethodSupportedTable_oid_len, HANDLER_CAN_RONLY); + + if(!my_handler || !table_info) { snmp_log(LOG_ERR, "malloc failed in initialize_table_kamailio" - "SIPMethodSupportedTable_handler\n"); - return; + "SIPMethodSupportedTable_handler\n"); + return; } netsnmp_table_helper_add_index(table_info, ASN_UNSIGNED); @@ -199,17 +198,17 @@ void initialize_table_kamailioSIPMethodSupportedTable(void) * registering the table with the master agent */ cb.get_value = kamailioSIPMethodSupportedTable_get_value; - cb.container = - netsnmp_container_find("kamailioSIPMethodSupportedTable_primary:" - "kamailioSIPMethodSupportedTable:" "table_container"); - - DEBUGMSGTL(("initialize_table_kamailioSIPMethodSupportedTable", - "Registering table kamailioSIPMethodSupportedTable" - "as a table array\n")); + cb.container = + netsnmp_container_find("kamailioSIPMethodSupportedTable_primary:" + "kamailioSIPMethodSupportedTable:" + "table_container"); - netsnmp_table_container_register(my_handler, table_info, &cb, - cb.container, 1); + DEBUGMSGTL(("initialize_table_kamailioSIPMethodSupportedTable", + "Registering table kamailioSIPMethodSupportedTable" + "as a table array\n")); + netsnmp_table_container_register( + my_handler, table_info, &cb, cb.container, 1); } /* @@ -217,30 +216,26 @@ void initialize_table_kamailioSIPMethodSupportedTable(void) * * The function is pretty much left as is from the auto-generated code. */ -int kamailioSIPMethodSupportedTable_get_value( - netsnmp_request_info *request, - netsnmp_index *item, - netsnmp_table_request_info *table_info ) +int kamailioSIPMethodSupportedTable_get_value(netsnmp_request_info *request, + netsnmp_index *item, netsnmp_table_request_info *table_info) { netsnmp_variable_list *var = request->requestvb; - kamailioSIPMethodSupportedTable_context *context = - (kamailioSIPMethodSupportedTable_context *)item; + kamailioSIPMethodSupportedTable_context *context = + (kamailioSIPMethodSupportedTable_context *)item; - switch(table_info->colnum) - { + switch(table_info->colnum) { case COLUMN_KAMAILIOSIPMETHODNAME: /** SnmpAdminString = ASN_OCTET_STR */ snmp_set_var_typed_value(var, ASN_OCTET_STR, - (unsigned char*) - context->kamailioSIPMethodName, - context->kamailioSIPMethodName_len ); + (unsigned char *)context->kamailioSIPMethodName, + context->kamailioSIPMethodName_len); break; - + default: /** We shouldn't get here */ snmp_log(LOG_ERR, "unknown column in kamailioSIPMethod" - "SupportedTable_get_value\n"); + "SupportedTable_get_value\n"); return SNMP_ERR_GENERR; } @@ -251,10 +246,8 @@ int kamailioSIPMethodSupportedTable_get_value( * kamailioSIPMethodSupportedTable_get_by_idx is an auto-generated function. */ const kamailioSIPMethodSupportedTable_context * - kamailioSIPMethodSupportedTable_get_by_idx(netsnmp_index * hdr) +kamailioSIPMethodSupportedTable_get_by_idx(netsnmp_index *hdr) { - return (const kamailioSIPMethodSupportedTable_context *) - CONTAINER_FIND(cb.container, hdr ); -} - - + return (const kamailioSIPMethodSupportedTable_context *)CONTAINER_FIND( + cb.container, hdr); +} \ No newline at end of file diff --git a/src/modules/snmpstats/snmpSIPMethodSupportedTable.h b/src/modules/snmpstats/snmpSIPMethodSupportedTable.h index 242f6ebeaa4..db96fadfde8 100644 --- a/src/modules/snmpstats/snmpSIPMethodSupportedTable.h +++ b/src/modules/snmpstats/snmpSIPMethodSupportedTable.h @@ -32,7 +32,7 @@ extern "C" { #endif - + #include #include #include @@ -43,7 +43,8 @@ extern "C" { * This strucutre represents a single row in the SNMP table, and is mostly * auto-generated. */ -typedef struct kamailioSIPMethodSupportedTable_context_s { +typedef struct kamailioSIPMethodSupportedTable_context_s +{ netsnmp_index index; @@ -52,10 +53,10 @@ typedef struct kamailioSIPMethodSupportedTable_context_s { /** SnmpAdminString = ASN_OCTET_STR */ unsigned char *kamailioSIPMethodName; - + long kamailioSIPMethodName_len; - void * data; + void *data; } kamailioSIPMethodSupportedTable_context; @@ -73,29 +74,28 @@ void initialize_table_kamailioSIPMethodSupportedTable(void); * * The function is pretty much left as is from the auto-generated code. */ -int kamailioSIPMethodSupportedTable_get_value(netsnmp_request_info *, - netsnmp_index *, netsnmp_table_request_info *); +int kamailioSIPMethodSupportedTable_get_value( + netsnmp_request_info *, netsnmp_index *, netsnmp_table_request_info *); -const kamailioSIPMethodSupportedTable_context * - kamailioSIPMethodSupportedTable_get_by_idx(netsnmp_index *); +const kamailioSIPMethodSupportedTable_context * +kamailioSIPMethodSupportedTable_get_by_idx(netsnmp_index *); -const kamailioSIPMethodSupportedTable_context * - kamailioSIPMethodSupportedTable_get_by_idx_rs(netsnmp_index *, - int row_status); +const kamailioSIPMethodSupportedTable_context * +kamailioSIPMethodSupportedTable_get_by_idx_rs(netsnmp_index *, int row_status); /* * oid declarations */ -extern oid kamailioSIPMethodSupportedTable_oid[]; +extern oid kamailioSIPMethodSupportedTable_oid[]; extern size_t kamailioSIPMethodSupportedTable_oid_len; -#define kamailioSIPMethodSupportedTable_TABLE_OID KAMAILIO_OID,3,1,1,1,1,7 - +#define kamailioSIPMethodSupportedTable_TABLE_OID KAMAILIO_OID, 3, 1, 1, 1, 1, 7 + /* * column number definitions for table kamailioSIPMethodSupportedTable */ -#define COLUMN_KAMAILIOSIPMETHODSUPPORTEDINDEX 1 -#define COLUMN_KAMAILIOSIPMETHODNAME 2 +#define COLUMN_KAMAILIOSIPMETHODSUPPORTEDINDEX 1 +#define COLUMN_KAMAILIOSIPMETHODNAME 2 #define kamailioSIPMethodSupportedTable_COL_MIN 2 #define kamailioSIPMethodSupportedTable_COL_MAX 2 @@ -105,4 +105,4 @@ extern size_t kamailioSIPMethodSupportedTable_oid_len; } #endif -#endif /** KAMAILIOSIPMETHODSUPPORTEDTABLE_H */ +#endif /** KAMAILIOSIPMETHODSUPPORTEDTABLE_H */ \ No newline at end of file diff --git a/src/modules/snmpstats/snmpSIPPortTable.c b/src/modules/snmpstats/snmpSIPPortTable.c index 5b7e536e672..3dcdf7ff93d 100644 --- a/src/modules/snmpstats/snmpSIPPortTable.c +++ b/src/modules/snmpstats/snmpSIPPortTable.c @@ -42,10 +42,10 @@ #include "snmpstats_globals.h" #include "snmpSIPPortTable.h" -static netsnmp_handler_registration *my_handler = NULL; -static netsnmp_table_array_callbacks cb; +static netsnmp_handler_registration *my_handler = NULL; +static netsnmp_table_array_callbacks cb; -oid kamailioSIPPortTable_oid[] = { kamailioSIPPortTable_TABLE_OID }; +oid kamailioSIPPortTable_oid[] = {kamailioSIPPortTable_TABLE_OID}; size_t kamailioSIPPortTable_oid_len = OID_LENGTH(kamailioSIPPortTable_oid); @@ -58,7 +58,7 @@ size_t kamailioSIPPortTable_oid_len = OID_LENGTH(kamailioSIPPortTable_oid); * Note: This function returns a newly allocated block of memory. Make sure to * deallocate the memory when you no longer need it. */ -static oid *createIndex(int ipType, int *ipAddress, int *sizeOfOID) +static oid *createIndex(int ipType, int *ipAddress, int *sizeOfOID) { oid *currentOIDIndex; int i; @@ -74,7 +74,7 @@ static oid *createIndex(int ipType, int *ipAddress, int *sizeOfOID) currentOIDIndex = pkg_malloc((*sizeOfOID) * sizeof(oid)); LM_DBG("----> Size of OID %d \n", *sizeOfOID); - if (currentOIDIndex == NULL) { + if(currentOIDIndex == NULL) { LM_ERR("failed to create a row for kamailioSIPPortTable\n"); *sizeOfOID = 0; return NULL; @@ -83,14 +83,15 @@ static oid *createIndex(int ipType, int *ipAddress, int *sizeOfOID) /* Assign the OID Index */ currentOIDIndex[0] = ipType; currentOIDIndex[1] = num_octets; - - for (i = 0; i < num_octets; i++) { - currentOIDIndex[i+2] = ipAddress[i]; + + for(i = 0; i < num_octets; i++) { + currentOIDIndex[i + 2] = ipAddress[i]; } /* Extract out the port number */ currentOIDIndex[num_octets + 2] = ipAddress[num_octets]; - LM_DBG("----> Port number %d Family %s \n", ipAddress[num_octets], ipType == 1 ? "IPv4" : "IPv6"); + LM_DBG("----> Port number %d Family %s \n", ipAddress[num_octets], + ipType == 1 ? "IPv4" : "IPv6"); return currentOIDIndex; } @@ -110,42 +111,41 @@ kamailioSIPPortTable_context *getRow(int ipType, int *ipAddress) kamailioSIPPortTable_context *rowToReturn; int num_octets = ipType == 1 ? NUM_IP_OCTETS : NUM_IPV6_OCTETS; - if (currentOIDIndex == NULL) - { + if(currentOIDIndex == NULL) { return NULL; } theIndex.oids = currentOIDIndex; - theIndex.len = lengthOfOID; + theIndex.len = lengthOfOID; /* Lets check to see if there is an existing row. */ rowToReturn = CONTAINER_FIND(cb.container, &theIndex); - + /* We found an existing row, so there is no need to create a new one. * Let's return it to the caller. */ - if (rowToReturn != NULL) - { + if(rowToReturn != NULL) { /* We don't need the index we allocated anymore, because the * existing row already has its own copy, so free the memory */ pkg_free(currentOIDIndex); return rowToReturn; } - + /* If we are here then the row doesn't exist yet. So lets create it. */ rowToReturn = SNMP_MALLOC_TYPEDEF(kamailioSIPPortTable_context); /* Not enough memory to create the new row. */ - if (rowToReturn == NULL) { + if(rowToReturn == NULL) { pkg_free(currentOIDIndex); return NULL; } /* Assign the Container Index. */ - rowToReturn->index.len = lengthOfOID; + rowToReturn->index.len = lengthOfOID; rowToReturn->index.oids = currentOIDIndex; - memcpy(rowToReturn->kamailioSIPStringIndex, currentOIDIndex, num_octets + 3); + memcpy(rowToReturn->kamailioSIPStringIndex, currentOIDIndex, + num_octets + 3); rowToReturn->kamailioSIPStringIndex_len = num_octets + 3; /* Insert the new row into the table */ @@ -162,8 +162,9 @@ kamailioSIPPortTable_context *getRow(int ipType, int *ipAddress) * to an integer so that if the function is called again with another * 'protocol', we can continue from the last index. */ -static void createRowsFromIPList(int *theList, int listSize, int protocol, - int *snmpIndex, int family) { +static void createRowsFromIPList( + int *theList, int listSize, int protocol, int *snmpIndex, int family) +{ kamailioSIPPortTable_context *currentRow; int num_octets = family == AF_INET ? NUM_IP_OCTETS : NUM_IPV6_OCTETS; @@ -171,45 +172,36 @@ static void createRowsFromIPList(int *theList, int listSize, int protocol, int curSocketIdx; int valueToAssign; - if (protocol == PROTO_UDP) - { + if(protocol == PROTO_UDP) { valueToAssign = TC_TRANSPORT_PROTOCOL_UDP; - } - else if (protocol == PROTO_TCP) - { + } else if(protocol == PROTO_TCP) { valueToAssign = TC_TRANSPORT_PROTOCOL_TCP; - } - else if (protocol == PROTO_TLS) - { + } else if(protocol == PROTO_TLS) { valueToAssign = TC_TRANSPORT_PROTOCOL_TLS; - } - else if (protocol == PROTO_SCTP) - { + } else if(protocol == PROTO_SCTP) { valueToAssign = TC_SIP_TRANSPORT_PROTOCOL_SCTP; - } - else - { + } else { valueToAssign = TC_TRANSPORT_PROTOCOL_OTHER; } - + /* Create all rows with respect to the given protocol */ - for (curSocketIdx=0; curSocketIdx < listSize; curSocketIdx++) { + for(curSocketIdx = 0; curSocketIdx < listSize; curSocketIdx++) { + + curIndexOfIP = (num_octets + 1) * curSocketIdx; - curIndexOfIP = (num_octets + 1) * curSocketIdx; - /* Retrieve an existing row, or a new row if one doesn't * already exist. * RFC 4001 defined IPv4 as 1, IPv6 as 2 */ - currentRow = getRow(family == AF_INET? 1 : 2, &theList[curIndexOfIP]); + currentRow = getRow(family == AF_INET ? 1 : 2, &theList[curIndexOfIP]); - if (currentRow == NULL) { + if(currentRow == NULL) { LM_ERR("failed to create all the " - "rows for the kamailioSIPPortTable\n"); + "rows for the kamailioSIPPortTable\n"); return; } - currentRow->kamailioSIPTransportRcv[0] |= valueToAssign; + currentRow->kamailioSIPTransportRcv[0] |= valueToAssign; currentRow->kamailioSIPTransportRcv_len = 1; } } @@ -238,50 +230,68 @@ void init_kamailioSIPPortTable(void) initialize_table_kamailioSIPPortTable(); int numUDPSockets; - int numTCPSockets; + int numTCPSockets; int numTLSSockets; int numSCTPSockets; int numUDP6Sockets; - int numTCP6Sockets; + int numTCP6Sockets; int numTLS6Sockets; int numSCTP6Sockets; - + /* Retrieve the list of the number of UDP and TCP sockets. */ - numUDPSockets = get_socket_list_from_proto_and_family(&_sr_snmp_UDPList, PROTO_UDP, AF_INET); - numUDP6Sockets = get_socket_list_from_proto_and_family(&_sr_snmp_UDP6List, PROTO_UDP, AF_INET6); - numTCPSockets = get_socket_list_from_proto_and_family(&_sr_snmp_TCPList, PROTO_TCP, AF_INET); - numTCP6Sockets = get_socket_list_from_proto_and_family(&_sr_snmp_TCP6List, PROTO_TCP, AF_INET6); - numTLSSockets = get_socket_list_from_proto_and_family(&_sr_snmp_TLSList, PROTO_TLS, AF_INET); - numTLS6Sockets = get_socket_list_from_proto_and_family(&_sr_snmp_TLS6List, PROTO_TLS, AF_INET6); - numSCTPSockets = get_socket_list_from_proto_and_family(&_sr_snmp_SCTPList, PROTO_SCTP, AF_INET); - numSCTP6Sockets = get_socket_list_from_proto_and_family(&_sr_snmp_SCTP6List, PROTO_SCTP, AF_INET6); - - LM_DBG("-----> Sockets UDP %d UDP6 %d TCP %d TCP6 %d TLS %d TLS6 %d SCTP %d SCTP6 %d\n", - numUDPSockets, numUDP6Sockets, numTCPSockets, numTCP6Sockets, numTLSSockets, numTLS6Sockets, numSCTPSockets, numSCTP6Sockets); + numUDPSockets = get_socket_list_from_proto_and_family( + &_sr_snmp_UDPList, PROTO_UDP, AF_INET); + numUDP6Sockets = get_socket_list_from_proto_and_family( + &_sr_snmp_UDP6List, PROTO_UDP, AF_INET6); + numTCPSockets = get_socket_list_from_proto_and_family( + &_sr_snmp_TCPList, PROTO_TCP, AF_INET); + numTCP6Sockets = get_socket_list_from_proto_and_family( + &_sr_snmp_TCP6List, PROTO_TCP, AF_INET6); + numTLSSockets = get_socket_list_from_proto_and_family( + &_sr_snmp_TLSList, PROTO_TLS, AF_INET); + numTLS6Sockets = get_socket_list_from_proto_and_family( + &_sr_snmp_TLS6List, PROTO_TLS, AF_INET6); + numSCTPSockets = get_socket_list_from_proto_and_family( + &_sr_snmp_SCTPList, PROTO_SCTP, AF_INET); + numSCTP6Sockets = get_socket_list_from_proto_and_family( + &_sr_snmp_SCTP6List, PROTO_SCTP, AF_INET6); + + LM_DBG("-----> Sockets UDP %d UDP6 %d TCP %d TCP6 %d TLS %d TLS6 %d SCTP " + "%d SCTP6 %d\n", + numUDPSockets, numUDP6Sockets, numTCPSockets, numTCP6Sockets, + numTLSSockets, numTLS6Sockets, numSCTPSockets, numSCTP6Sockets); /* Generate all rows, using all retrieved interfaces. */ - createRowsFromIPList(_sr_snmp_UDPList, numUDPSockets, PROTO_UDP, &curSNMPIndex, AF_INET); + createRowsFromIPList( + _sr_snmp_UDPList, numUDPSockets, PROTO_UDP, &curSNMPIndex, AF_INET); curSNMPIndex = 0; - createRowsFromIPList(_sr_snmp_UDP6List, numUDP6Sockets, PROTO_UDP, &curSNMPIndex, AF_INET6); + createRowsFromIPList(_sr_snmp_UDP6List, numUDP6Sockets, PROTO_UDP, + &curSNMPIndex, AF_INET6); curSNMPIndex = 0; - createRowsFromIPList(_sr_snmp_TCPList, numTCPSockets, PROTO_TCP, &curSNMPIndex, AF_INET); + createRowsFromIPList( + _sr_snmp_TCPList, numTCPSockets, PROTO_TCP, &curSNMPIndex, AF_INET); curSNMPIndex = 0; - createRowsFromIPList(_sr_snmp_TCP6List, numTCP6Sockets, PROTO_TCP, &curSNMPIndex, AF_INET6); + createRowsFromIPList(_sr_snmp_TCP6List, numTCP6Sockets, PROTO_TCP, + &curSNMPIndex, AF_INET6); curSNMPIndex = 0; - createRowsFromIPList(_sr_snmp_TLSList, numTLSSockets, PROTO_TLS, &curSNMPIndex, AF_INET); + createRowsFromIPList( + _sr_snmp_TLSList, numTLSSockets, PROTO_TLS, &curSNMPIndex, AF_INET); curSNMPIndex = 0; - createRowsFromIPList(_sr_snmp_TLS6List, numTLS6Sockets, PROTO_TLS, &curSNMPIndex, AF_INET6); + createRowsFromIPList(_sr_snmp_TLS6List, numTLS6Sockets, PROTO_TLS, + &curSNMPIndex, AF_INET6); curSNMPIndex = 0; - createRowsFromIPList(_sr_snmp_SCTPList, numSCTPSockets, PROTO_SCTP, &curSNMPIndex, AF_INET); + createRowsFromIPList(_sr_snmp_SCTPList, numSCTPSockets, PROTO_SCTP, + &curSNMPIndex, AF_INET); curSNMPIndex = 0; - createRowsFromIPList(_sr_snmp_SCTP6List, numSCTP6Sockets, PROTO_SCTP, &curSNMPIndex, AF_INET6); + createRowsFromIPList(_sr_snmp_SCTP6List, numSCTP6Sockets, PROTO_SCTP, + &curSNMPIndex, AF_INET6); } - + /* Initialize the kamailioSIPPortTable table by defining how it is structured */ void initialize_table_kamailioSIPPortTable(void) { @@ -289,7 +299,7 @@ void initialize_table_kamailioSIPPortTable(void) if(my_handler) { snmp_log(LOG_ERR, "initialize_table_kamailioSIPPortTable_handler" - "called again\n"); + "called again\n"); return; } @@ -299,19 +309,17 @@ void initialize_table_kamailioSIPPortTable(void) table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); my_handler = netsnmp_create_handler_registration("kamailioSIPPortTable", - netsnmp_table_array_helper_handler, - kamailioSIPPortTable_oid, - kamailioSIPPortTable_oid_len, - HANDLER_CAN_RONLY); - - if (!my_handler || !table_info) { + netsnmp_table_array_helper_handler, kamailioSIPPortTable_oid, + kamailioSIPPortTable_oid_len, HANDLER_CAN_RONLY); + + if(!my_handler || !table_info) { snmp_log(LOG_ERR, "malloc failed in " - "initialize_table_kamailioSIPPortTable_handler\n"); + "initialize_table_kamailioSIPPortTable_handler\n"); return; /** mallocs failed */ } /* Set up the table's structural definition */ - + /* index: kamailioSIPPortIndex */ netsnmp_table_helper_add_index(table_info, ASN_OCTET_STR); @@ -321,16 +329,16 @@ void initialize_table_kamailioSIPPortTable(void) /* register the table with the master agent */ cb.get_value = kamailioSIPPortTable_get_value; cb.container = netsnmp_container_find("kamailioSIPPortTable_primary:" - "kamailioSIPPortTable:" - "table_container"); + "kamailioSIPPortTable:" + "table_container"); + - DEBUGMSGTL(("initialize_table_kamailioSIPPortTable", - "Registering table kamailioSIPPortTable " - "as a table array\n")); - - netsnmp_table_container_register(my_handler, table_info, &cb, - cb.container, 1); + "Registering table kamailioSIPPortTable " + "as a table array\n")); + + netsnmp_table_container_register( + my_handler, table_info, &cb, cb.container, 1); } /* @@ -338,29 +346,26 @@ void initialize_table_kamailioSIPPortTable(void) * * The function is mostly left in its auto-generated form */ -int kamailioSIPPortTable_get_value(netsnmp_request_info *request, - netsnmp_index *item, - netsnmp_table_request_info *table_info ) +int kamailioSIPPortTable_get_value(netsnmp_request_info *request, + netsnmp_index *item, netsnmp_table_request_info *table_info) { netsnmp_variable_list *var = request->requestvb; - kamailioSIPPortTable_context *context = - (kamailioSIPPortTable_context *)item; + kamailioSIPPortTable_context *context = + (kamailioSIPPortTable_context *)item; + + switch(table_info->colnum) { - switch(table_info->colnum) - { - case COLUMN_KAMAILIOSIPTRANSPORTRCV: /** KamailioSIPTransportProtocol = ASN_OCTET_STR */ snmp_set_var_typed_value(var, ASN_OCTET_STR, - (unsigned char *) - &context->kamailioSIPTransportRcv, - context->kamailioSIPTransportRcv_len ); + (unsigned char *)&context->kamailioSIPTransportRcv, + context->kamailioSIPTransportRcv_len); break; default: /** We shouldn't get here */ snmp_log(LOG_ERR, "unknown column in " - "kamailioSIPPortTable_get_value\n"); + "kamailioSIPPortTable_get_value\n"); return SNMP_ERR_GENERR; } @@ -368,11 +373,9 @@ int kamailioSIPPortTable_get_value(netsnmp_request_info *request, } /* Auto-generated function */ -const kamailioSIPPortTable_context * -kamailioSIPPortTable_get_by_idx(netsnmp_index * hdr) +const kamailioSIPPortTable_context *kamailioSIPPortTable_get_by_idx( + netsnmp_index *hdr) { - return (const kamailioSIPPortTable_context *) - CONTAINER_FIND(cb.container, hdr ); -} - - + return (const kamailioSIPPortTable_context *)CONTAINER_FIND( + cb.container, hdr); +} \ No newline at end of file diff --git a/src/modules/snmpstats/snmpSIPPortTable.h b/src/modules/snmpstats/snmpSIPPortTable.h index 3d40a76594a..b71370b8217 100644 --- a/src/modules/snmpstats/snmpSIPPortTable.h +++ b/src/modules/snmpstats/snmpSIPPortTable.h @@ -42,18 +42,18 @@ extern "C" { #define SIP_PORT_TABLE_STR_INDEX_SIZE 22 /* This structure represents a single row in the table. */ -typedef struct kamailioSIPPortTable_context_s +typedef struct kamailioSIPPortTable_context_s { - netsnmp_index index; - + netsnmp_index index; + unsigned char kamailioSIPStringIndex[SIP_PORT_TABLE_STR_INDEX_SIZE]; unsigned long kamailioSIPStringIndex_len; unsigned char kamailioSIPTransportRcv[2]; long kamailioSIPTransportRcv_len; - void * data; + void *data; } kamailioSIPPortTable_context; @@ -65,32 +65,34 @@ typedef struct kamailioSIPPortTable_context_s * populate it with the ports and transports that Kamailio is listening on. * */ -void init_kamailioSIPPortTable(void); +void init_kamailioSIPPortTable(void); /* Initialize the kamailioSIPPortTable table by defining how it is structured */ -void initialize_table_kamailioSIPPortTable(void); +void initialize_table_kamailioSIPPortTable(void); /* * This routine is called to process get requests for elements of the table. * The function is mostly left in its auto-generated form */ -int kamailioSIPPortTable_get_value(netsnmp_request_info *, netsnmp_index *, - netsnmp_table_request_info *); +int kamailioSIPPortTable_get_value( + netsnmp_request_info *, netsnmp_index *, netsnmp_table_request_info *); -const kamailioSIPPortTable_context *kamailioSIPPortTable_get_by_idx(netsnmp_index *); +const kamailioSIPPortTable_context *kamailioSIPPortTable_get_by_idx( + netsnmp_index *); -const kamailioSIPPortTable_context * kamailioSIPPortTable_get_by_idx_rs(netsnmp_index *, int row_status); +const kamailioSIPPortTable_context *kamailioSIPPortTable_get_by_idx_rs( + netsnmp_index *, int row_status); /* * oid declarations */ -extern oid kamailioSIPPortTable_oid[]; +extern oid kamailioSIPPortTable_oid[]; extern size_t kamailioSIPPortTable_oid_len; -#define kamailioSIPPortTable_TABLE_OID KAMAILIO_OID,3,1,1,1,1,5 - +#define kamailioSIPPortTable_TABLE_OID KAMAILIO_OID, 3, 1, 1, 1, 1, 5 + /* * column number definitions for table kamailioSIPPortTable */ @@ -104,4 +106,4 @@ extern size_t kamailioSIPPortTable_oid_len; #ifdef __cplusplus } #endif -#endif /** KAMAILIOSIPPORTTABLE_H */ +#endif /** KAMAILIOSIPPORTTABLE_H */ \ No newline at end of file diff --git a/src/modules/snmpstats/snmpSIPRegUserLookupTable.c b/src/modules/snmpstats/snmpSIPRegUserLookupTable.c index 1f0281daf4b..d25392f35ba 100644 --- a/src/modules/snmpstats/snmpSIPRegUserLookupTable.c +++ b/src/modules/snmpstats/snmpSIPRegUserLookupTable.c @@ -74,11 +74,11 @@ static netsnmp_handler_registration *my_handler = NULL; static netsnmp_table_array_callbacks cb; -oid kamailioSIPRegUserLookupTable_oid[] = { - kamailioSIPRegUserLookupTable_TABLE_OID }; +oid kamailioSIPRegUserLookupTable_oid[] = { + kamailioSIPRegUserLookupTable_TABLE_OID}; -size_t kamailioSIPRegUserLookupTable_oid_len = - OID_LENGTH(kamailioSIPRegUserLookupTable_oid); +size_t kamailioSIPRegUserLookupTable_oid_len = + OID_LENGTH(kamailioSIPRegUserLookupTable_oid); /* @@ -93,35 +93,33 @@ void init_kamailioSIPRegUserLookupTable(void) /* the *_row_copy routine */ static int kamailioSIPRegUserLookupTable_row_copy( - kamailioSIPRegUserLookupTable_context * dst, - kamailioSIPRegUserLookupTable_context * src) + kamailioSIPRegUserLookupTable_context *dst, + kamailioSIPRegUserLookupTable_context *src) { - if(!dst||!src) - { + if(!dst || !src) { return 1; } - - + + /* copy index, if provided */ - if(dst->index.oids) - { + if(dst->index.oids) { free(dst->index.oids); } - if(snmp_clone_mem( (void*)&dst->index.oids, src->index.oids, - src->index.len * sizeof(oid) )) { + if(snmp_clone_mem((void *)&dst->index.oids, src->index.oids, + src->index.len * sizeof(oid))) { dst->index.oids = NULL; return 1; } dst->index.len = src->index.len; - + /* Copy out almost all components of the structure. We don't copy out * the kamailioSIPRegUSerLookupURI (or its length). */ - dst->kamailioSIPRegUserLookupIndex = src->kamailioSIPRegUserLookupIndex; - dst->kamailioSIPRegUserIndex = src->kamailioSIPRegUserIndex; - dst->kamailioSIPRegUserLookupRowStatus = - src->kamailioSIPRegUserLookupRowStatus; + dst->kamailioSIPRegUserLookupIndex = src->kamailioSIPRegUserLookupIndex; + dst->kamailioSIPRegUserIndex = src->kamailioSIPRegUserIndex; + dst->kamailioSIPRegUserLookupRowStatus = + src->kamailioSIPRegUserLookupRowStatus; return 0; } @@ -142,8 +140,7 @@ static int kamailioSIPRegUserLookupTable_row_copy( * */ int kamailioSIPRegUserLookupTable_extract_index( - kamailioSIPRegUserLookupTable_context * ctx, - netsnmp_index * hdr) + kamailioSIPRegUserLookupTable_context *ctx, netsnmp_index *hdr) { /* * temporary local storage for extracting oid index @@ -157,16 +154,16 @@ int kamailioSIPRegUserLookupTable_extract_index( /* copy index, if provided */ if(hdr) { netsnmp_assert(ctx->index.oids == NULL); - if((hdr->len > MAX_OID_LEN) || - snmp_clone_mem( (void*)&ctx->index.oids, hdr->oids, - hdr->len * sizeof(oid) )) { + if((hdr->len > MAX_OID_LEN) + || snmp_clone_mem((void *)&ctx->index.oids, hdr->oids, + hdr->len * sizeof(oid))) { return -1; } ctx->index.len = hdr->len; } /* Set up the index */ - memset(&var_kamailioSIPRegUserLookupIndex, 0x00, + memset(&var_kamailioSIPRegUserLookupIndex, 0x00, sizeof(var_kamailioSIPRegUserLookupIndex)); var_kamailioSIPRegUserLookupIndex.type = ASN_UNSIGNED; @@ -174,29 +171,28 @@ int kamailioSIPRegUserLookupTable_extract_index( /* parse the oid into the individual index components */ - err = parse_oid_indexes( hdr->oids, hdr->len, - &var_kamailioSIPRegUserLookupIndex ); + err = parse_oid_indexes( + hdr->oids, hdr->len, &var_kamailioSIPRegUserLookupIndex); + + if(err == SNMP_ERR_NOERROR) { - if (err == SNMP_ERR_NOERROR) { - /* copy index components into the context structure */ - ctx->kamailioSIPRegUserLookupIndex = - *var_kamailioSIPRegUserLookupIndex.val.integer; + ctx->kamailioSIPRegUserLookupIndex = + *var_kamailioSIPRegUserLookupIndex.val.integer; /* * Check to make sure that the index corresponds to the * global_userLookupCounter, as per the MIB specifications. */ - if (*var_kamailioSIPRegUserLookupIndex.val.integer != - global_UserLookupCounter || - *var_kamailioSIPRegUserLookupIndex.val.integer < 1) { + if(*var_kamailioSIPRegUserLookupIndex.val.integer + != global_UserLookupCounter + || *var_kamailioSIPRegUserLookupIndex.val.integer < 1) { err = -1; } - } /* parsing may have allocated memory. free it. */ - snmp_reset_var_buffers( &var_kamailioSIPRegUserLookupIndex ); + snmp_reset_var_buffers(&var_kamailioSIPRegUserLookupIndex); return err; } @@ -212,7 +208,7 @@ int kamailioSIPRegUserLookupTable_extract_index( int kamailioSIPRegUserLookupTable_can_activate( kamailioSIPRegUserLookupTable_context *undo_ctx, kamailioSIPRegUserLookupTable_context *row_ctx, - netsnmp_request_group * rg) + netsnmp_request_group *rg) { return 1; } @@ -230,7 +226,7 @@ int kamailioSIPRegUserLookupTable_can_activate( int kamailioSIPRegUserLookupTable_can_deactivate( kamailioSIPRegUserLookupTable_context *undo_ctx, kamailioSIPRegUserLookupTable_context *row_ctx, - netsnmp_request_group * rg) + netsnmp_request_group *rg) { return 1; } @@ -247,11 +243,11 @@ int kamailioSIPRegUserLookupTable_can_deactivate( int kamailioSIPRegUserLookupTable_can_delete( kamailioSIPRegUserLookupTable_context *undo_ctx, kamailioSIPRegUserLookupTable_context *row_ctx, - netsnmp_request_group * rg) + netsnmp_request_group *rg) { - if(kamailioSIPRegUserLookupTable_can_deactivate(undo_ctx,row_ctx,rg) != 1) + if(kamailioSIPRegUserLookupTable_can_deactivate(undo_ctx, row_ctx, rg) != 1) return 0; - + return 1; } @@ -266,27 +262,24 @@ int kamailioSIPRegUserLookupTable_can_delete( * Returns a newly allocated kamailioSIPRegUserLookupTable_context structure (a * row in the table) if the indexes are legal. NULL will be returned otherwise. */ -kamailioSIPRegUserLookupTable_context * -kamailioSIPRegUserLookupTable_create_row( netsnmp_index* hdr) +kamailioSIPRegUserLookupTable_context *kamailioSIPRegUserLookupTable_create_row( + netsnmp_index *hdr) { - kamailioSIPRegUserLookupTable_context * ctx = - SNMP_MALLOC_TYPEDEF(kamailioSIPRegUserLookupTable_context); + kamailioSIPRegUserLookupTable_context *ctx = + SNMP_MALLOC_TYPEDEF(kamailioSIPRegUserLookupTable_context); - if (!ctx) - { + if(!ctx) { return NULL; } - + /* * Extract the index. The function has been modified from its original * auto-generated version in that the function will fail if index is * somehow invalid. */ - if(kamailioSIPRegUserLookupTable_extract_index( ctx, hdr )) - { + if(kamailioSIPRegUserLookupTable_extract_index(ctx, hdr)) { - if (NULL != ctx->index.oids) - { + if(NULL != ctx->index.oids) { free(ctx->index.oids); } @@ -295,9 +288,9 @@ kamailioSIPRegUserLookupTable_create_row( netsnmp_index* hdr) return NULL; } - ctx->kamailioSIPRegUserLookupURI = NULL; - ctx->kamailioSIPRegUserLookupURI_len = 0; - ctx->kamailioSIPRegUserIndex = 0; + ctx->kamailioSIPRegUserLookupURI = NULL; + ctx->kamailioSIPRegUserLookupURI_len = 0; + ctx->kamailioSIPRegUserIndex = 0; ctx->kamailioSIPRegUserLookupRowStatus = 0; return ctx; @@ -307,10 +300,10 @@ kamailioSIPRegUserLookupTable_create_row( netsnmp_index* hdr) * Auto-generated function. The *_duplicate row routine */ kamailioSIPRegUserLookupTable_context * -kamailioSIPRegUserLookupTable_duplicate_row( - kamailioSIPRegUserLookupTable_context * row_ctx) +kamailioSIPRegUserLookupTable_duplicate_row( + kamailioSIPRegUserLookupTable_context *row_ctx) { - kamailioSIPRegUserLookupTable_context * dup; + kamailioSIPRegUserLookupTable_context *dup; if(!row_ctx) return NULL; @@ -318,8 +311,8 @@ kamailioSIPRegUserLookupTable_duplicate_row( dup = SNMP_MALLOC_TYPEDEF(kamailioSIPRegUserLookupTable_context); if(!dup) return NULL; - - if(kamailioSIPRegUserLookupTable_row_copy(dup,row_ctx)) { + + if(kamailioSIPRegUserLookupTable_row_copy(dup, row_ctx)) { free(dup); dup = NULL; } @@ -334,21 +327,19 @@ kamailioSIPRegUserLookupTable_duplicate_row( * deleted. However, in our implementation there is never a reason why this * function can't be called. */ -netsnmp_index * kamailioSIPRegUserLookupTable_delete_row( - kamailioSIPRegUserLookupTable_context * ctx ) +netsnmp_index *kamailioSIPRegUserLookupTable_delete_row( + kamailioSIPRegUserLookupTable_context *ctx) { - if(ctx->index.oids) - { + if(ctx->index.oids) { free(ctx->index.oids); } - if (ctx->kamailioSIPRegUserLookupURI != NULL) - { + if(ctx->kamailioSIPRegUserLookupURI != NULL) { pkg_free(ctx->kamailioSIPRegUserLookupURI); } - free( ctx ); + free(ctx); return NULL; } @@ -373,10 +364,10 @@ netsnmp_index * kamailioSIPRegUserLookupTable_delete_row( * any other condition is considered illegal, and will result in an SNMP error * being returned. */ -void kamailioSIPRegUserLookupTable_set_reserve1( netsnmp_request_group *rg ) +void kamailioSIPRegUserLookupTable_set_reserve1(netsnmp_request_group *rg) { kamailioSIPRegUserLookupTable_context *row_ctx = - (kamailioSIPRegUserLookupTable_context *)rg->existing_row; + (kamailioSIPRegUserLookupTable_context *)rg->existing_row; netsnmp_variable_list *var; @@ -384,67 +375,59 @@ void kamailioSIPRegUserLookupTable_set_reserve1( netsnmp_request_group *rg ) int rc; - for( current = rg->list; current; current = current->next ) { + for(current = rg->list; current; current = current->next) { var = current->ri->requestvb; rc = SNMP_ERR_NOERROR; - switch(current->tri->colnum) - { + switch(current->tri->colnum) { case COLUMN_KAMAILIOSIPREGUSERLOOKUPURI: - if (row_ctx->kamailioSIPRegUserLookupRowStatus == 0 || - row_ctx->kamailioSIPRegUserLookupRowStatus == - TC_ROWSTATUS_NOTREADY) { + if(row_ctx->kamailioSIPRegUserLookupRowStatus == 0 + || row_ctx->kamailioSIPRegUserLookupRowStatus + == TC_ROWSTATUS_NOTREADY) { } else { rc = SNMP_ERR_BADVALUE; } - + break; case COLUMN_KAMAILIOSIPREGUSERLOOKUPROWSTATUS: /** RowStatus = ASN_INTEGER */ rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER, - sizeof( - row_ctx->kamailioSIPRegUserLookupRowStatus)); - + sizeof(row_ctx->kamailioSIPRegUserLookupRowStatus)); + /* Want to make sure that if it already exists that it * is setting it to 'destroy', or if it doesn't exist, * that it is setting it to 'createAndGo' */ - if (row_ctx->kamailioSIPRegUserLookupRowStatus == 0 && - *var->val.integer != TC_ROWSTATUS_CREATEANDGO) - { + if(row_ctx->kamailioSIPRegUserLookupRowStatus == 0 + && *var->val.integer != TC_ROWSTATUS_CREATEANDGO) { rc = SNMP_ERR_BADVALUE; - } - - else if (row_ctx->kamailioSIPRegUserLookupRowStatus == - TC_ROWSTATUS_ACTIVE && - *var->val.integer != - TC_ROWSTATUS_DESTROY) - { + } + + else if(row_ctx->kamailioSIPRegUserLookupRowStatus + == TC_ROWSTATUS_ACTIVE + && *var->val.integer != TC_ROWSTATUS_DESTROY) { rc = SNMP_ERR_BADVALUE; } - - break; + + break; default: /** We shouldn't get here */ rc = SNMP_ERR_GENERR; snmp_log(LOG_ERR, "unknown column in kamailioSIPReg" - "UserLookupTable_set_reserve1\n"); + "UserLookupTable_set_reserve1\n"); } - if (rc) - { - netsnmp_set_mode_request_error( - MODE_SET_BEGIN, current->ri, rc ); + if(rc) { + netsnmp_set_mode_request_error(MODE_SET_BEGIN, current->ri, rc); } - rg->status = SNMP_MAX( rg->status, current->ri->status ); + rg->status = SNMP_MAX(rg->status, current->ri->status); } - } /* @@ -452,10 +435,10 @@ void kamailioSIPRegUserLookupTable_set_reserve1( netsnmp_request_group *rg ) * last-minute conditions not being met. However, we don't have any such * conditions, so we leave the default function as is. */ -void kamailioSIPRegUserLookupTable_set_reserve2( netsnmp_request_group *rg ) +void kamailioSIPRegUserLookupTable_set_reserve2(netsnmp_request_group *rg) { - kamailioSIPRegUserLookupTable_context *undo_ctx = - (kamailioSIPRegUserLookupTable_context *)rg->undo_info; + kamailioSIPRegUserLookupTable_context *undo_ctx = + (kamailioSIPRegUserLookupTable_context *)rg->undo_info; netsnmp_request_group_item *current; @@ -463,36 +446,33 @@ void kamailioSIPRegUserLookupTable_set_reserve2( netsnmp_request_group *rg ) rg->rg_void = rg->list->ri; - for( current = rg->list; current; current = current->next ) { + for(current = rg->list; current; current = current->next) { rc = SNMP_ERR_NOERROR; - switch(current->tri->colnum) - { + switch(current->tri->colnum) { case COLUMN_KAMAILIOSIPREGUSERLOOKUPURI: break; case COLUMN_KAMAILIOSIPREGUSERLOOKUPROWSTATUS: - + /** RowStatus = ASN_INTEGER */ rc = netsnmp_check_vb_rowstatus(current->ri->requestvb, - undo_ctx ? - undo_ctx->kamailioSIPRegUserLookupRowStatus:0); + undo_ctx ? undo_ctx->kamailioSIPRegUserLookupRowStatus + : 0); rg->rg_void = current->ri; - + break; - default: /** We shouldn't get here */ + default: /** We shouldn't get here */ netsnmp_assert(0); /** why wasn't this caught in reserve1? */ } - if (rc) - { + if(rc) { netsnmp_set_mode_request_error(MODE_SET_BEGIN, current->ri, rc); } } - } /* @@ -507,8 +487,8 @@ void kamailioSIPRegUserLookupTable_set_reserve2( netsnmp_request_group *rg ) * * All other handling is auto-generated. */ -void kamailioSIPRegUserLookupTable_set_action( netsnmp_request_group *rg ) -{ +void kamailioSIPRegUserLookupTable_set_action(netsnmp_request_group *rg) +{ /* First things first, we need to consume the interprocess buffer, in * case something has changed. We want to return the freshest data. */ consumeInterprocessBuffer(); @@ -517,107 +497,95 @@ void kamailioSIPRegUserLookupTable_set_action( netsnmp_request_group *rg ) netsnmp_variable_list *var; - kamailioSIPRegUserLookupTable_context *row_ctx = - (kamailioSIPRegUserLookupTable_context *)rg->existing_row; + kamailioSIPRegUserLookupTable_context *row_ctx = + (kamailioSIPRegUserLookupTable_context *)rg->existing_row; - kamailioSIPRegUserLookupTable_context *undo_ctx = - (kamailioSIPRegUserLookupTable_context *)rg->undo_info; + kamailioSIPRegUserLookupTable_context *undo_ctx = + (kamailioSIPRegUserLookupTable_context *)rg->undo_info; netsnmp_request_group_item *current; - int row_err = 0; + int row_err = 0; /* Copy the actual data to the row. */ - for( current = rg->list; current; current = current->next ) { + for(current = rg->list; current; current = current->next) { var = current->ri->requestvb; - switch(current->tri->colnum) - { + switch(current->tri->colnum) { case COLUMN_KAMAILIOSIPREGUSERLOOKUPURI: - row_ctx->kamailioSIPRegUserLookupURI = - pkg_malloc(sizeof(char)*(var->val_len + 1)); + row_ctx->kamailioSIPRegUserLookupURI = + pkg_malloc(sizeof(char) * (var->val_len + 1)); - memcpy(row_ctx->kamailioSIPRegUserLookupURI, - var->val.string, + memcpy(row_ctx->kamailioSIPRegUserLookupURI, var->val.string, var->val_len); - + /* Usually NetSNMP won't terminate strings with '\0'. * The hash function expect them to be terminated * though, so we have to add this on to the end. The +1 * in the malloc makes sure of the extra space for us. - */ + */ row_ctx->kamailioSIPRegUserLookupURI[var->val_len] = '\0'; row_ctx->kamailioSIPRegUserLookupURI_len = var->val_len; - + /* Do the lookup. If we could find the record, then set * the index and the row status to active. Otherwise, * set the row to notInService */ - hashRecord = - findHashRecord(hashTable, - (char *) - row_ctx->kamailioSIPRegUserLookupURI, + hashRecord = findHashRecord(hashTable, + (char *)row_ctx->kamailioSIPRegUserLookupURI, HASH_SIZE); - if (hashRecord == NULL) - { - row_ctx->kamailioSIPRegUserIndex = 0; - row_ctx->kamailioSIPRegUserLookupRowStatus = - TC_ROWSTATUS_NOTINSERVICE; - } - else - { - row_ctx->kamailioSIPRegUserIndex = - hashRecord->userIndex; - row_ctx->kamailioSIPRegUserLookupRowStatus = - TC_ROWSTATUS_ACTIVE; + if(hashRecord == NULL) { + row_ctx->kamailioSIPRegUserIndex = 0; + row_ctx->kamailioSIPRegUserLookupRowStatus = + TC_ROWSTATUS_NOTINSERVICE; + } else { + row_ctx->kamailioSIPRegUserIndex = hashRecord->userIndex; + row_ctx->kamailioSIPRegUserLookupRowStatus = + TC_ROWSTATUS_ACTIVE; } break; case COLUMN_KAMAILIOSIPREGUSERLOOKUPROWSTATUS: - row_ctx->kamailioSIPRegUserLookupRowStatus = - *var->val.integer; + row_ctx->kamailioSIPRegUserLookupRowStatus = *var->val.integer; - if (*var->val.integer == TC_ROWSTATUS_CREATEANDGO) - { + if(*var->val.integer == TC_ROWSTATUS_CREATEANDGO) { rg->row_created = 1; /* Set to NOT READY until the lookup URI has * been supplied. */ row_ctx->kamailioSIPRegUserLookupRowStatus = - TC_ROWSTATUS_NOTREADY; - } - else if (*var->val.integer == TC_ROWSTATUS_DESTROY) - { + TC_ROWSTATUS_NOTREADY; + } else if(*var->val.integer == TC_ROWSTATUS_DESTROY) { rg->row_deleted = 1; - } - else - { + } else { /* We should never be here, because the RESERVE * functions should have taken care of all other * values. */ - LM_ERR("invalid RowStatus in kamailioSIPStatusCodesTable\n"); + LM_ERR("invalid RowStatus in " + "kamailioSIPStatusCodesTable\n"); } break; - default: /** We shouldn't get here */ + default: /** We shouldn't get here */ netsnmp_assert(0); /** why wasn't this caught in reserve1? */ } } - /* +/* * done with all the columns. Could check row related * requirements here. */ #ifndef kamailioSIPRegUserLookupTable_CAN_MODIFY_ACTIVE_ROW - if( undo_ctx && RS_IS_ACTIVE(undo_ctx->kamailioSIPRegUserLookupRowStatus) && - row_ctx && RS_IS_ACTIVE(row_ctx->kamailioSIPRegUserLookupRowStatus) ) { - row_err = 1; + if(undo_ctx && RS_IS_ACTIVE(undo_ctx->kamailioSIPRegUserLookupRowStatus) + && row_ctx + && RS_IS_ACTIVE(row_ctx->kamailioSIPRegUserLookupRowStatus)) { + row_err = 1; } #endif @@ -629,20 +597,18 @@ void kamailioSIPRegUserLookupTable_set_action( netsnmp_request_group *rg ) undo_ctx ? &undo_ctx->kamailioSIPRegUserLookupRowStatus : NULL); if(row_err) { - netsnmp_set_mode_request_error(MODE_SET_BEGIN, - (netsnmp_request_info*)rg->rg_void, row_err); + netsnmp_set_mode_request_error( + MODE_SET_BEGIN, (netsnmp_request_info *)rg->rg_void, row_err); return; } - } /* * The COMMIT phase is used to do any extra processing after the ACTION phase. * In our table, there is nothing to do, so the function body is empty. */ -void kamailioSIPRegUserLookupTable_set_commit( netsnmp_request_group *rg ) +void kamailioSIPRegUserLookupTable_set_commit(netsnmp_request_group *rg) { - } @@ -652,9 +618,8 @@ void kamailioSIPRegUserLookupTable_set_commit( netsnmp_request_group *rg ) * all these resources in earlier functions. So for our purposes, the function * body is empty. */ -void kamailioSIPRegUserLookupTable_set_free( netsnmp_request_group *rg ) +void kamailioSIPRegUserLookupTable_set_free(netsnmp_request_group *rg) { - } @@ -663,9 +628,8 @@ void kamailioSIPRegUserLookupTable_set_free( netsnmp_request_group *rg ) * We don't have anything complicated enough to warrant putting anything in this * function. Therefore, its just left with an empty function body. */ -void kamailioSIPRegUserLookupTable_set_undo( netsnmp_request_group *rg ) +void kamailioSIPRegUserLookupTable_set_undo(netsnmp_request_group *rg) { - } @@ -681,7 +645,7 @@ void initialize_table_kamailioSIPRegUserLookupTable(void) if(my_handler) { snmp_log(LOG_ERR, "initialize_table_kamailioSIPRegUserLookup" - "Table_handler called again\n"); + "Table_handler called again\n"); return; } @@ -691,16 +655,14 @@ void initialize_table_kamailioSIPRegUserLookupTable(void) table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); my_handler = netsnmp_create_handler_registration( - "kamailioSIPRegUserLookupTable", - netsnmp_table_array_helper_handler, + "kamailioSIPRegUserLookupTable", netsnmp_table_array_helper_handler, kamailioSIPRegUserLookupTable_oid, - kamailioSIPRegUserLookupTable_oid_len, - HANDLER_CAN_RWRITE); - - if (!my_handler || !table_info) { + kamailioSIPRegUserLookupTable_oid_len, HANDLER_CAN_RWRITE); + + if(!my_handler || !table_info) { snmp_log(LOG_ERR, "malloc failed in " - "initialize_table_kamailioSIPRegUserLookup" - "Table_handler\n"); + "initialize_table_kamailioSIPRegUserLookup" + "Table_handler\n"); return; /** mallocs failed */ } @@ -717,89 +679,80 @@ void initialize_table_kamailioSIPRegUserLookupTable(void) * registering the table with the master agent */ cb.get_value = kamailioSIPRegUserLookupTable_get_value; - cb.container = netsnmp_container_find( - "kamailioSIPRegUserLookupTable_primary:" - "kamailioSIPRegUserLookupTable:" - "table_container"); + cb.container = + netsnmp_container_find("kamailioSIPRegUserLookupTable_primary:" + "kamailioSIPRegUserLookupTable:" + "table_container"); cb.can_set = 1; - cb.create_row = - (UserRowMethod*)kamailioSIPRegUserLookupTable_create_row; - cb.duplicate_row = - (UserRowMethod*)kamailioSIPRegUserLookupTable_duplicate_row; - cb.delete_row = - (UserRowMethod*)kamailioSIPRegUserLookupTable_delete_row; - cb.row_copy = - (Netsnmp_User_Row_Operation *) + cb.create_row = (UserRowMethod *)kamailioSIPRegUserLookupTable_create_row; + cb.duplicate_row = + (UserRowMethod *)kamailioSIPRegUserLookupTable_duplicate_row; + cb.delete_row = (UserRowMethod *)kamailioSIPRegUserLookupTable_delete_row; + cb.row_copy = (Netsnmp_User_Row_Operation *) kamailioSIPRegUserLookupTable_row_copy; - cb.can_activate = (Netsnmp_User_Row_Action *) - kamailioSIPRegUserLookupTable_can_activate; + cb.can_activate = (Netsnmp_User_Row_Action *) + kamailioSIPRegUserLookupTable_can_activate; cb.can_deactivate = (Netsnmp_User_Row_Action *) - kamailioSIPRegUserLookupTable_can_deactivate; - cb.can_delete = (Netsnmp_User_Row_Action *) - kamailioSIPRegUserLookupTable_can_delete; + kamailioSIPRegUserLookupTable_can_deactivate; + cb.can_delete = + (Netsnmp_User_Row_Action *)kamailioSIPRegUserLookupTable_can_delete; cb.set_reserve1 = kamailioSIPRegUserLookupTable_set_reserve1; cb.set_reserve2 = kamailioSIPRegUserLookupTable_set_reserve2; - cb.set_action = kamailioSIPRegUserLookupTable_set_action; - cb.set_commit = kamailioSIPRegUserLookupTable_set_commit; - cb.set_free = kamailioSIPRegUserLookupTable_set_free; - cb.set_undo = kamailioSIPRegUserLookupTable_set_undo; + cb.set_action = kamailioSIPRegUserLookupTable_set_action; + cb.set_commit = kamailioSIPRegUserLookupTable_set_commit; + cb.set_free = kamailioSIPRegUserLookupTable_set_free; + cb.set_undo = kamailioSIPRegUserLookupTable_set_undo; DEBUGMSGTL(("initialize_table_kamailioSIPRegUserLookupTable", - "Registering table kamailioSIPRegUserLookupTable " - "as a table array\n")); - - netsnmp_table_container_register(my_handler, table_info, &cb, - cb.container, 1); + "Registering table kamailioSIPRegUserLookupTable " + "as a table array\n")); + + netsnmp_table_container_register( + my_handler, table_info, &cb, cb.container, 1); } /* * This function was auto-generated and didn't need modifications from its * auto-generation. It is called to handle an SNMP GET request. */ -int kamailioSIPRegUserLookupTable_get_value( - netsnmp_request_info *request, - netsnmp_index *item, - netsnmp_table_request_info *table_info ) +int kamailioSIPRegUserLookupTable_get_value(netsnmp_request_info *request, + netsnmp_index *item, netsnmp_table_request_info *table_info) { netsnmp_variable_list *var = request->requestvb; kamailioSIPRegUserLookupTable_context *context = - (kamailioSIPRegUserLookupTable_context *)item; + (kamailioSIPRegUserLookupTable_context *)item; - switch(table_info->colnum) - { + switch(table_info->colnum) { case COLUMN_KAMAILIOSIPREGUSERLOOKUPURI: /** SnmpAdminString = ASN_OCTET_STR */ - snmp_set_var_typed_value(var, ASN_OCTET_STR, - (unsigned char*) - context->kamailioSIPRegUserLookupURI, + snmp_set_var_typed_value(var, ASN_OCTET_STR, + (unsigned char *)context->kamailioSIPRegUserLookupURI, context->kamailioSIPRegUserLookupURI_len); - break; - + break; + case COLUMN_KAMAILIOSIPREGUSERINDEX: /** UNSIGNED32 = ASN_UNSIGNED */ snmp_set_var_typed_value(var, ASN_UNSIGNED, - (unsigned char*) - &context->kamailioSIPRegUserIndex, - sizeof(context->kamailioSIPRegUserIndex)); - break; - + (unsigned char *)&context->kamailioSIPRegUserIndex, + sizeof(context->kamailioSIPRegUserIndex)); + break; + case COLUMN_KAMAILIOSIPREGUSERLOOKUPROWSTATUS: /** RowStatus = ASN_INTEGER */ snmp_set_var_typed_value(var, ASN_INTEGER, - (unsigned char*) - &context->kamailioSIPRegUserLookupRowStatus, - sizeof( - context->kamailioSIPRegUserLookupRowStatus)); - break; - - default: /** We shouldn't get here */ - snmp_log(LOG_ERR, "unknown column in " - "kamailioSIPRegUserLookupTable_get_value\n"); - return SNMP_ERR_GENERR; + (unsigned char *)&context + ->kamailioSIPRegUserLookupRowStatus, + sizeof(context->kamailioSIPRegUserLookupRowStatus)); + break; + + default: /** We shouldn't get here */ + snmp_log(LOG_ERR, "unknown column in " + "kamailioSIPRegUserLookupTable_get_value\n"); + return SNMP_ERR_GENERR; } return SNMP_ERR_NOERROR; @@ -809,10 +762,8 @@ int kamailioSIPRegUserLookupTable_get_value( * kamailioSIPRegUserLookupTable_get_by_idx */ const kamailioSIPRegUserLookupTable_context * -kamailioSIPRegUserLookupTable_get_by_idx(netsnmp_index * hdr) +kamailioSIPRegUserLookupTable_get_by_idx(netsnmp_index *hdr) { - return (const kamailioSIPRegUserLookupTable_context *) - CONTAINER_FIND(cb.container, hdr ); -} - - + return (const kamailioSIPRegUserLookupTable_context *)CONTAINER_FIND( + cb.container, hdr); +} \ No newline at end of file diff --git a/src/modules/snmpstats/snmpSIPRegUserLookupTable.h b/src/modules/snmpstats/snmpSIPRegUserLookupTable.h index e645a18082e..f94b1f0cef7 100644 --- a/src/modules/snmpstats/snmpSIPRegUserLookupTable.h +++ b/src/modules/snmpstats/snmpSIPRegUserLookupTable.h @@ -48,7 +48,7 @@ extern "C" { #endif - + #include #include #include @@ -57,24 +57,24 @@ extern "C" { /* This structure represnts a row in the table */ -typedef struct kamailioSIPRegUserLookupTable_context_s +typedef struct kamailioSIPRegUserLookupTable_context_s { - netsnmp_index index; + netsnmp_index index; /** UNSIGNED32 = ASN_UNSIGNED */ - unsigned long kamailioSIPRegUserLookupIndex; + unsigned long kamailioSIPRegUserLookupIndex; /** SnmpAdminString = ASN_OCTET_STR */ unsigned char *kamailioSIPRegUserLookupURI; - long kamailioSIPRegUserLookupURI_len; + long kamailioSIPRegUserLookupURI_len; /** UNSIGNED32 = ASN_UNSIGNED */ - unsigned long kamailioSIPRegUserIndex; + unsigned long kamailioSIPRegUserIndex; /** RowStatus = ASN_INTEGER */ long kamailioSIPRegUserLookupRowStatus; - void * data; + void *data; } kamailioSIPRegUserLookupTable_context; @@ -98,29 +98,27 @@ void initialize_table_kamailioSIPRegUserLookupTable(void); * This function was auto-generated and didn't need modifications from its * auto-generation. It is called to handle an SNMP GET request. */ -int kamailioSIPRegUserLookupTable_get_value(netsnmp_request_info *, - netsnmp_index *, netsnmp_table_request_info *); +int kamailioSIPRegUserLookupTable_get_value( + netsnmp_request_info *, netsnmp_index *, netsnmp_table_request_info *); -const kamailioSIPRegUserLookupTable_context * - kamailioSIPRegUserLookupTable_get_by_idx(netsnmp_index *); +const kamailioSIPRegUserLookupTable_context * +kamailioSIPRegUserLookupTable_get_by_idx(netsnmp_index *); -const kamailioSIPRegUserLookupTable_context * - kamailioSIPRegUserLookupTable_get_by_idx_rs( - netsnmp_index *, - int row_status); +const kamailioSIPRegUserLookupTable_context * +kamailioSIPRegUserLookupTable_get_by_idx_rs(netsnmp_index *, int row_status); /* oid declarations */ -extern oid kamailioSIPRegUserLookupTable_oid[]; +extern oid kamailioSIPRegUserLookupTable_oid[]; extern size_t kamailioSIPRegUserLookupTable_oid_len; -#define kamailioSIPRegUserLookupTable_TABLE_OID KAMAILIO_OID,3,1,2,1,5,9 +#define kamailioSIPRegUserLookupTable_TABLE_OID KAMAILIO_OID, 3, 1, 2, 1, 5, 9 /* column number definitions for table kamailioSIPRegUserLookupTable */ -#define COLUMN_KAMAILIOSIPREGUSERLOOKUPINDEX 1 -#define COLUMN_KAMAILIOSIPREGUSERLOOKUPURI 2 -#define COLUMN_KAMAILIOSIPREGUSERINDEX 3 +#define COLUMN_KAMAILIOSIPREGUSERLOOKUPINDEX 1 +#define COLUMN_KAMAILIOSIPREGUSERLOOKUPURI 2 +#define COLUMN_KAMAILIOSIPREGUSERINDEX 3 #define COLUMN_KAMAILIOSIPREGUSERLOOKUPROWSTATUS 4 #define kamailioSIPRegUserLookupTable_COL_MIN 2 @@ -128,7 +126,7 @@ extern size_t kamailioSIPRegUserLookupTable_oid_len; /* Handles index extraction for row creation */ -int kamailioSIPRegUserLookupTable_extract_index( +int kamailioSIPRegUserLookupTable_extract_index( kamailioSIPRegUserLookupTable_context *ctx, netsnmp_index *hdr); /* Handle RESERVE1 and RESERVE2 phases of an SNMP SET */ @@ -144,12 +142,12 @@ void kamailioSIPRegUserLookupTable_set_commit(netsnmp_request_group *); void kamailioSIPRegUserLookupTable_set_free(netsnmp_request_group *); void kamailioSIPRegUserLookupTable_set_undo(netsnmp_request_group *); -kamailioSIPRegUserLookupTable_context * - kamailioSIPRegUserLookupTable_duplicate_row( - kamailioSIPRegUserLookupTable_context*); +kamailioSIPRegUserLookupTable_context * +kamailioSIPRegUserLookupTable_duplicate_row( + kamailioSIPRegUserLookupTable_context *); -netsnmp_index * kamailioSIPRegUserLookupTable_delete_row( - kamailioSIPRegUserLookupTable_context*); +netsnmp_index *kamailioSIPRegUserLookupTable_delete_row( + kamailioSIPRegUserLookupTable_context *); /* Used to check if there is a reason why a row can't be activated * (There is no reason in our implementation) @@ -157,7 +155,7 @@ netsnmp_index * kamailioSIPRegUserLookupTable_delete_row( int kamailioSIPRegUserLookupTable_can_activate( kamailioSIPRegUserLookupTable_context *undo_ctx, kamailioSIPRegUserLookupTable_context *row_ctx, - netsnmp_request_group * rg); + netsnmp_request_group *rg); /* Used to check if there is a reason why a row can't be deactivated * (There is no reason in our implementation) @@ -165,7 +163,7 @@ int kamailioSIPRegUserLookupTable_can_activate( int kamailioSIPRegUserLookupTable_can_deactivate( kamailioSIPRegUserLookupTable_context *undo_ctx, kamailioSIPRegUserLookupTable_context *row_ctx, - netsnmp_request_group * rg); + netsnmp_request_group *rg); /* Used to check if there is a reason why a row can't be deleted * (There is no reason in our implementation) @@ -173,15 +171,15 @@ int kamailioSIPRegUserLookupTable_can_deactivate( int kamailioSIPRegUserLookupTable_can_delete( kamailioSIPRegUserLookupTable_context *undo_ctx, kamailioSIPRegUserLookupTable_context *row_ctx, - netsnmp_request_group * rg); - + netsnmp_request_group *rg); + /* Basic structural setups of the new row */ -kamailioSIPRegUserLookupTable_context * kamailioSIPRegUserLookupTable_create_row( - netsnmp_index*); +kamailioSIPRegUserLookupTable_context *kamailioSIPRegUserLookupTable_create_row( + netsnmp_index *); #ifdef __cplusplus } #endif -#endif /** KAMAILIOSIPREGUSERLOOKUPTABLE_H */ +#endif /** KAMAILIOSIPREGUSERLOOKUPTABLE_H */ \ No newline at end of file diff --git a/src/modules/snmpstats/snmpSIPRegUserTable.c b/src/modules/snmpstats/snmpSIPRegUserTable.c index 7218a66add8..63cf2f40ff4 100644 --- a/src/modules/snmpstats/snmpSIPRegUserTable.c +++ b/src/modules/snmpstats/snmpSIPRegUserTable.c @@ -86,8 +86,9 @@ static netsnmp_handler_registration *my_handler = NULL; static netsnmp_table_array_callbacks cb; -oid kamailioSIPRegUserTable_oid[] = { kamailioSIPRegUserTable_TABLE_OID }; -size_t kamailioSIPRegUserTable_oid_len = OID_LENGTH(kamailioSIPRegUserTable_oid); +oid kamailioSIPRegUserTable_oid[] = {kamailioSIPRegUserTable_TABLE_OID}; +size_t kamailioSIPRegUserTable_oid_len = + OID_LENGTH(kamailioSIPRegUserTable_oid); /* If the usrloc module is loaded, this function will grab hooks into its @@ -95,25 +96,23 @@ size_t kamailioSIPRegUserTable_oid_len = OID_LENGTH(kamailioSIPRegUserTable_oid) * callback for UL_CONTACT_INSERT and UL_CONTACT_EXPIRE. * * Returns 1 on success, and zero otherwise. */ -int registerForUSRLOCCallbacks(void) +int registerForUSRLOCCallbacks(void) { bind_usrloc_t bind_usrloc; usrloc_api_t ul; bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0); - if (!bind_usrloc) - { + if(!bind_usrloc) { LM_ERR("Can't find ul_bind_usrloc\n"); goto error; } - if (bind_usrloc(&ul) < 0 || ul.register_ulcb == NULL) - { + if(bind_usrloc(&ul) < 0 || ul.register_ulcb == NULL) { LM_ERR("Can't bind usrloc\n"); goto error; } ul.register_ulcb(UL_CONTACT_INSERT, handleContactCallbacks, NULL); - + ul.register_ulcb(UL_CONTACT_EXPIRE, handleContactCallbacks, NULL); return 1; @@ -128,30 +127,29 @@ int registerForUSRLOCCallbacks(void) /* Removes an SNMP row indexed by userIndex, and frees the string and index it * pointed to. */ -void deleteRegUserRow(int userIndex) +void deleteRegUserRow(int userIndex) { - + kamailioSIPRegUserTable_context *theRow; netsnmp_index indexToRemove; oid indexToRemoveOID; - - indexToRemoveOID = userIndex; + + indexToRemoveOID = userIndex; indexToRemove.oids = &indexToRemoveOID; - indexToRemove.len = 1; + indexToRemove.len = 1; theRow = CONTAINER_FIND(cb.container, &indexToRemove); /* The userURI is shared memory, the index.oids was allocated from * pkg_malloc(), and theRow was made with the NetSNMP API which uses * malloc() */ - if (theRow != NULL) { + if(theRow != NULL) { CONTAINER_REMOVE(cb.container, &indexToRemove); pkg_free(theRow->kamailioSIPUserUri); pkg_free(theRow->index.oids); free(theRow); } - } /* @@ -162,19 +160,18 @@ void deleteRegUserRow(int userIndex) * - If the user doesn't exist, the user will be added to the table, and its * number of contacts' count set to 1. */ -void updateUser(char *userName) +void updateUser(char *userName) { - int userIndex; + int userIndex; aorToIndexStruct_t *newRecord; - aorToIndexStruct_t *existingRecord = - findHashRecord(hashTable, userName, HASH_SIZE); + aorToIndexStruct_t *existingRecord = + findHashRecord(hashTable, userName, HASH_SIZE); /* We found an existing record, so we need to update its 'number of * contacts' count. */ - if (existingRecord != NULL) - { + if(existingRecord != NULL) { existingRecord->numContacts++; return; } @@ -183,61 +180,60 @@ void updateUser(char *userName) * structures */ userIndex = createRegUserRow(userName); - if (userIndex == 0) - { + if(userIndex == 0) { LM_ERR("kamailioSIPRegUserTable ran out of memory." - " Not able to add user: %s", userName); + " Not able to add user: %s", + userName); return; } newRecord = createHashRecord(userIndex, userName); - + /* If we couldn't create a record in the hash table, then we won't be * able to access this row properly later. So remove the row from the * table and fail. */ - if (newRecord == NULL) { + if(newRecord == NULL) { deleteRegUserRow(userIndex); LM_ERR("kamailioSIPRegUserTable was not able to push %s into the hash." - " User not added to this table\n", userName); + " User not added to this table\n", + userName); return; } - + /* Insert the new record of the mapping data structure into the hash * table */ /*insertHashRecord(hashTable, createHashRecord(userIndex, userName), HASH_SIZE);*/ - - insertHashRecord(hashTable, - newRecord, - HASH_SIZE); + + insertHashRecord(hashTable, newRecord, HASH_SIZE); } /* Creates a row and inserts it. * * Returns: The rows userIndex on success, and 0 otherwise. */ -int createRegUserRow(char *stringToRegister) +int createRegUserRow(char *stringToRegister) { int static index = 0; - + index++; kamailioSIPRegUserTable_context *theRow; - oid *OIDIndex; - int stringLength; + oid *OIDIndex; + int stringLength; theRow = SNMP_MALLOC_TYPEDEF(kamailioSIPRegUserTable_context); - if (theRow == NULL) { + if(theRow == NULL) { LM_ERR("failed to create a row for kamailioSIPRegUserTable\n"); return 0; } OIDIndex = pkg_malloc(sizeof(oid)); - if (OIDIndex == NULL) { + if(OIDIndex == NULL) { free(theRow); LM_ERR("failed to create a row for kamailioSIPRegUserTable\n"); return 0; @@ -247,22 +243,21 @@ int createRegUserRow(char *stringToRegister) OIDIndex[0] = index; - theRow->index.len = 1; + theRow->index.len = 1; theRow->index.oids = OIDIndex; theRow->kamailioSIPUserIndex = index; - theRow->kamailioSIPUserUri = (unsigned char*)pkg_malloc(stringLength* sizeof(char)); - if(theRow->kamailioSIPUserUri== NULL) - { - pkg_free(OIDIndex); + theRow->kamailioSIPUserUri = + (unsigned char *)pkg_malloc(stringLength * sizeof(char)); + if(theRow->kamailioSIPUserUri == NULL) { + pkg_free(OIDIndex); free(theRow); LM_ERR("failed to create a row for kamailioSIPRegUserTable\n"); return 0; + } + memcpy(theRow->kamailioSIPUserUri, stringToRegister, stringLength); - } - memcpy(theRow->kamailioSIPUserUri, stringToRegister, stringLength); - - theRow->kamailioSIPUserUri_len = stringLength; + theRow->kamailioSIPUserUri_len = stringLength; theRow->kamailioSIPUserAuthenticationFailures = 0; @@ -279,12 +274,11 @@ void init_kamailioSIPRegUserTable(void) /* We need to create a default row, so create DefaultUser */ static char *defaultUser = "DefaultUser"; - + createRegUserRow(defaultUser); } - /* * Initialize the kamailioSIPRegUserTable table by defining its contents and how * it's structured @@ -295,7 +289,7 @@ void initialize_table_kamailioSIPRegUserTable(void) if(my_handler) { snmp_log(LOG_ERR, "initialize_table_kamailioSIPRegUserTable_hand" - "ler called again\n"); + "ler called again\n"); return; } @@ -304,17 +298,13 @@ void initialize_table_kamailioSIPRegUserTable(void) /* create the table structure itself */ table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); - my_handler = - netsnmp_create_handler_registration( - "kamailioSIPRegUserTable", - netsnmp_table_array_helper_handler, - kamailioSIPRegUserTable_oid, - kamailioSIPRegUserTable_oid_len, - HANDLER_CAN_RONLY); + my_handler = netsnmp_create_handler_registration("kamailioSIPRegUserTable", + netsnmp_table_array_helper_handler, kamailioSIPRegUserTable_oid, + kamailioSIPRegUserTable_oid_len, HANDLER_CAN_RONLY); - if (!my_handler || !table_info) { + if(!my_handler || !table_info) { snmp_log(LOG_ERR, "malloc failed in initialize_table_kamailio" - "SIPRegUserTable_handler\n"); + "SIPRegUserTable_handler\n"); return; /** mallocs failed */ } @@ -325,22 +315,21 @@ void initialize_table_kamailioSIPRegUserTable(void) cb.get_value = kamailioSIPRegUserTable_get_value; cb.container = netsnmp_container_find("kamailioSIPRegUserTable_primary:" - "kamailioSIPRegUserTable:" "table_container"); + "kamailioSIPRegUserTable:" + "table_container"); DEBUGMSGTL(("initialize_table_kamailioSIPRegUserTable", - "Registering table kamailioSIPRegUserTable " - "as a table array\n")); + "Registering table kamailioSIPRegUserTable " + "as a table array\n")); - netsnmp_table_container_register(my_handler, table_info, &cb, - cb.container, 1); + netsnmp_table_container_register( + my_handler, table_info, &cb, cb.container, 1); } /* Handles SNMP GET requests. */ -int kamailioSIPRegUserTable_get_value( - netsnmp_request_info *request, - netsnmp_index *item, - netsnmp_table_request_info *table_info ) +int kamailioSIPRegUserTable_get_value(netsnmp_request_info *request, + netsnmp_index *item, netsnmp_table_request_info *table_info) { /* First things first, we need to consume the interprocess buffer, in * case something has changed. We want to return the freshest data. */ @@ -348,31 +337,29 @@ int kamailioSIPRegUserTable_get_value( netsnmp_variable_list *var = request->requestvb; - kamailioSIPRegUserTable_context *context = - (kamailioSIPRegUserTable_context *)item; + kamailioSIPRegUserTable_context *context = + (kamailioSIPRegUserTable_context *)item; - switch(table_info->colnum) - { + switch(table_info->colnum) { case COLUMN_KAMAILIOSIPUSERURI: /** SnmpAdminString = ASN_OCTET_STR */ snmp_set_var_typed_value(var, ASN_OCTET_STR, - (unsigned char*)context->kamailioSIPUserUri, - context->kamailioSIPUserUri_len ); + (unsigned char *)context->kamailioSIPUserUri, + context->kamailioSIPUserUri_len); break; - + case COLUMN_KAMAILIOSIPUSERAUTHENTICATIONFAILURES: /** COUNTER = ASN_COUNTER */ snmp_set_var_typed_value(var, ASN_COUNTER, - (unsigned char*) - &context->kamailioSIPUserAuthenticationFailures, - sizeof( - context->kamailioSIPUserAuthenticationFailures)); - break; - + (unsigned char *)&context + ->kamailioSIPUserAuthenticationFailures, + sizeof(context->kamailioSIPUserAuthenticationFailures)); + break; + default: /** We shouldn't get here */ snmp_log(LOG_ERR, "unknown column in " - "kamailioSIPRegUserTable_get_value\n"); + "kamailioSIPRegUserTable_get_value\n"); return SNMP_ERR_GENERR; } @@ -381,11 +368,9 @@ int kamailioSIPRegUserTable_get_value( } -const kamailioSIPRegUserTable_context * -kamailioSIPRegUserTable_get_by_idx(netsnmp_index * hdr) +const kamailioSIPRegUserTable_context *kamailioSIPRegUserTable_get_by_idx( + netsnmp_index *hdr) { - return (const kamailioSIPRegUserTable_context *) - CONTAINER_FIND(cb.container, hdr ); -} - - + return (const kamailioSIPRegUserTable_context *)CONTAINER_FIND( + cb.container, hdr); +} \ No newline at end of file diff --git a/src/modules/snmpstats/snmpSIPRegUserTable.h b/src/modules/snmpstats/snmpSIPRegUserTable.h index 791a835c7fe..c8036c1a59b 100644 --- a/src/modules/snmpstats/snmpSIPRegUserTable.h +++ b/src/modules/snmpstats/snmpSIPRegUserTable.h @@ -78,9 +78,9 @@ extern "C" { #include "../../core/config.h" /* Defines what each SNMP Row is made of. */ -typedef struct kamailioSIPRegUserTable_context_s +typedef struct kamailioSIPRegUserTable_context_s { - netsnmp_index index; + netsnmp_index index; unsigned long kamailioSIPUserIndex; @@ -93,7 +93,7 @@ typedef struct kamailioSIPRegUserTable_context_s unsigned long kamailioSIPUserAuthenticationFailures; - void * data; + void *data; } kamailioSIPRegUserTable_context; @@ -113,16 +113,16 @@ int registerForUSRLOCCallbacks(void); * * Returns: The rows userIndex on success, and 0 otherwise. */ -int createRegUserRow(char *stringToRegister); +int createRegUserRow(char *stringToRegister); /* Removes an SNMP row indexed by userIndex, and frees the string and index it * pointed to. */ -void deleteRegUserRow(int userIndex); +void deleteRegUserRow(int userIndex); /* Creates an 'aor to userindex' record from stringName and userIndex, and pushes * them onto the hash table. */ -void pushUserIntoHashTable(int userIndex, char *stringName); +void pushUserIntoHashTable(int userIndex, char *stringName); /* * Adds or updates a user: @@ -139,35 +139,33 @@ void updateUser(char *userName); /*******************************/ /* Initializes the kamailioSIPRegUserTable module. */ -void init_kamailioSIPRegUserTable(void); +void init_kamailioSIPRegUserTable(void); /* * Initialize the kamailioSIPRegUserTable table by defining its contents and how * it's structured */ -void initialize_table_kamailioSIPRegUserTable(void); +void initialize_table_kamailioSIPRegUserTable(void); -const kamailioSIPRegUserTable_context * kamailioSIPRegUserTable_get_by_idx( +const kamailioSIPRegUserTable_context *kamailioSIPRegUserTable_get_by_idx( netsnmp_index *); -const kamailioSIPRegUserTable_context * kamailioSIPRegUserTable_get_by_idx_rs( +const kamailioSIPRegUserTable_context *kamailioSIPRegUserTable_get_by_idx_rs( netsnmp_index *, int row_status); /* Handles SNMP GET requests. */ -int kamailioSIPRegUserTable_get_value( - netsnmp_request_info *, - netsnmp_index *, - netsnmp_table_request_info *); +int kamailioSIPRegUserTable_get_value( + netsnmp_request_info *, netsnmp_index *, netsnmp_table_request_info *); /* OID Declarations. */ extern oid kamailioSIPRegUserTable_oid[]; extern size_t kamailioSIPRegUserTable_oid_len; -#define kamailioSIPRegUserTable_TABLE_OID KAMAILIO_OID,3,1,2,1,5,6 - +#define kamailioSIPRegUserTable_TABLE_OID KAMAILIO_OID, 3, 1, 2, 1, 5, 6 + /* Column Definitions */ -#define COLUMN_KAMAILIOSIPUSERINDEX 1 -#define COLUMN_KAMAILIOSIPUSERURI 2 +#define COLUMN_KAMAILIOSIPUSERINDEX 1 +#define COLUMN_KAMAILIOSIPUSERURI 2 #define COLUMN_KAMAILIOSIPUSERAUTHENTICATIONFAILURES 3 #define kamailioSIPRegUserTable_COL_MIN 2 @@ -177,4 +175,4 @@ extern size_t kamailioSIPRegUserTable_oid_len; } #endif -#endif /** KAMAILIOSIPREGUSERTABLE_H */ +#endif /** KAMAILIOSIPREGUSERTABLE_H */ \ No newline at end of file diff --git a/src/modules/snmpstats/snmpSIPServerObjects.c b/src/modules/snmpstats/snmpSIPServerObjects.c index d5d8d2abcd4..ca793e42427 100644 --- a/src/modules/snmpstats/snmpSIPServerObjects.c +++ b/src/modules/snmpstats/snmpSIPServerObjects.c @@ -52,75 +52,63 @@ unsigned int global_UserLookupCounter; * This function is mostly auto-generated. */ void init_kamailioSIPServerObjects(void) { - static oid kamailioSIPProxyStatefulness_oid[] = - { KAMAILIO_OID,3,1,2,1,3,1 }; + static oid kamailioSIPProxyStatefulness_oid[] = { + KAMAILIO_OID, 3, 1, 2, 1, 3, 1}; - static oid kamailioSIPProxyRecordRoute_oid[] = - { KAMAILIO_OID,3,1,2,1,3,3 }; + static oid kamailioSIPProxyRecordRoute_oid[] = { + KAMAILIO_OID, 3, 1, 2, 1, 3, 3}; - static oid kamailioSIPProxyAuthMethod_oid[] = - { KAMAILIO_OID,3,1,2,1,3,4 }; + static oid kamailioSIPProxyAuthMethod_oid[] = { + KAMAILIO_OID, 3, 1, 2, 1, 3, 4}; - static oid kamailioSIPNumProxyRequireFailures_oid[] = - { KAMAILIO_OID,3,1,2,1,4,1 }; + static oid kamailioSIPNumProxyRequireFailures_oid[] = { + KAMAILIO_OID, 3, 1, 2, 1, 4, 1}; - static oid kamailioSIPRegMaxContactExpiryDuration_oid[] = - { KAMAILIO_OID,3,1,2,1,5,2 }; + static oid kamailioSIPRegMaxContactExpiryDuration_oid[] = { + KAMAILIO_OID, 3, 1, 2, 1, 5, 2}; - static oid kamailioSIPRegMaxUsers_oid[] = - { KAMAILIO_OID,3,1,2,1,5,3 }; + static oid kamailioSIPRegMaxUsers_oid[] = {KAMAILIO_OID, 3, 1, 2, 1, 5, 3}; - static oid kamailioSIPRegCurrentUsers_oid[] = - { KAMAILIO_OID,3,1,2,1,5,4 }; + static oid kamailioSIPRegCurrentUsers_oid[] = { + KAMAILIO_OID, 3, 1, 2, 1, 5, 4}; - static oid kamailioSIPRegDfltRegActiveInterval_oid[] = - { KAMAILIO_OID,3,1,2,1,5,5 }; + static oid kamailioSIPRegDfltRegActiveInterval_oid[] = { + KAMAILIO_OID, 3, 1, 2, 1, 5, 5}; - static oid kamailioSIPRegUserLookupCounter_oid[] = - { KAMAILIO_OID,3,1,2,1,5,8 }; + static oid kamailioSIPRegUserLookupCounter_oid[] = { + KAMAILIO_OID, 3, 1, 2, 1, 5, 8}; - static oid kamailioSIPRegAcceptedRegistrations_oid[] = - { KAMAILIO_OID,3,1,2,1,6,1 }; + static oid kamailioSIPRegAcceptedRegistrations_oid[] = { + KAMAILIO_OID, 3, 1, 2, 1, 6, 1}; - static oid kamailioSIPRegRejectedRegistrations_oid[] = - { KAMAILIO_OID,3,1,2,1,6,2 }; + static oid kamailioSIPRegRejectedRegistrations_oid[] = { + KAMAILIO_OID, 3, 1, 2, 1, 6, 2}; DEBUGMSGTL(("kamailioSIPServerObjects", "Initializing\n")); - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioSIPProxyStatefulness", - handle_kamailioSIPProxyStatefulness, + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioSIPProxyStatefulness", handle_kamailioSIPProxyStatefulness, kamailioSIPProxyStatefulness_oid, - OID_LENGTH(kamailioSIPProxyStatefulness_oid), - HANDLER_CAN_RONLY)); + OID_LENGTH(kamailioSIPProxyStatefulness_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioSIPProxyRecordRoute", - handle_kamailioSIPProxyRecordRoute, + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioSIPProxyRecordRoute", handle_kamailioSIPProxyRecordRoute, kamailioSIPProxyRecordRoute_oid, - OID_LENGTH(kamailioSIPProxyRecordRoute_oid), - HANDLER_CAN_RONLY)); + OID_LENGTH(kamailioSIPProxyRecordRoute_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioSIPProxyAuthMethod", - handle_kamailioSIPProxyAuthMethod, + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioSIPProxyAuthMethod", handle_kamailioSIPProxyAuthMethod, kamailioSIPProxyAuthMethod_oid, - OID_LENGTH(kamailioSIPProxyAuthMethod_oid), - HANDLER_CAN_RONLY)); + OID_LENGTH(kamailioSIPProxyAuthMethod_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( + netsnmp_register_scalar(netsnmp_create_handler_registration( "kamailioSIPNumProxyRequireFailures", handle_kamailioSIPNumProxyRequireFailures, kamailioSIPNumProxyRequireFailures_oid, OID_LENGTH(kamailioSIPNumProxyRequireFailures_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( + netsnmp_register_scalar(netsnmp_create_handler_registration( "kamailioSIPRegMaxContactExpiryDuration", handle_kamailioSIPRegMaxContactExpiryDuration, kamailioSIPRegMaxContactExpiryDuration_oid, @@ -128,47 +116,37 @@ void init_kamailioSIPServerObjects(void) HANDLER_CAN_RONLY)); netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioSIPRegMaxUsers", - handle_kamailioSIPRegMaxUsers, - kamailioSIPRegMaxUsers_oid, - OID_LENGTH(kamailioSIPRegMaxUsers_oid), - HANDLER_CAN_RONLY)); + netsnmp_create_handler_registration("kamailioSIPRegMaxUsers", + handle_kamailioSIPRegMaxUsers, kamailioSIPRegMaxUsers_oid, + OID_LENGTH(kamailioSIPRegMaxUsers_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( - "kamailioSIPRegCurrentUsers", - handle_kamailioSIPRegCurrentUsers, + netsnmp_register_scalar(netsnmp_create_handler_registration( + "kamailioSIPRegCurrentUsers", handle_kamailioSIPRegCurrentUsers, kamailioSIPRegCurrentUsers_oid, - OID_LENGTH(kamailioSIPRegCurrentUsers_oid), - HANDLER_CAN_RONLY)); + OID_LENGTH(kamailioSIPRegCurrentUsers_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( + netsnmp_register_scalar(netsnmp_create_handler_registration( "kamailioSIPRegDfltRegActiveInterval", handle_kamailioSIPRegDfltRegActiveInterval, kamailioSIPRegDfltRegActiveInterval_oid, OID_LENGTH(kamailioSIPRegDfltRegActiveInterval_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( + netsnmp_register_scalar(netsnmp_create_handler_registration( "kamailioSIPRegUserLookupCounter", handle_kamailioSIPRegUserLookupCounter, kamailioSIPRegUserLookupCounter_oid, OID_LENGTH(kamailioSIPRegUserLookupCounter_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( + netsnmp_register_scalar(netsnmp_create_handler_registration( "kamailioSIPRegAcceptedRegistrations", handle_kamailioSIPRegAcceptedRegistrations, kamailioSIPRegAcceptedRegistrations_oid, OID_LENGTH(kamailioSIPRegAcceptedRegistrations_oid), HANDLER_CAN_RONLY)); - netsnmp_register_scalar( - netsnmp_create_handler_registration( + netsnmp_register_scalar(netsnmp_create_handler_registration( "kamailioSIPRegRejectedRegistrations", handle_kamailioSIPRegRejectedRegistrations, kamailioSIPRegRejectedRegistrations_oid, @@ -179,28 +157,22 @@ void init_kamailioSIPServerObjects(void) /* The following are handlers for the scalars in the KAMAILIO-SIP-SERVER-MIB. */ int handle_kamailioSIPProxyStatefulness(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int statefullness; - if (module_loaded("dialog") || module_loaded("ims_dialog")) - { + if(module_loaded("dialog") || module_loaded("ims_dialog")) { statefullness = PROXY_STATEFULNESS_CALL_STATEFUL; - } - else if (module_loaded("tm")) - { + } else if(module_loaded("tm")) { statefullness = PROXY_STATEFULNESS_TRANSACTION_STATEFUL; - } - else - { + } else { statefullness = PROXY_STATEFULNESS_STATELESS; } - if (reqinfo->mode==MODE_GET) { + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &statefullness, sizeof(int)); + (u_char *)&statefullness, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -209,22 +181,20 @@ int handle_kamailioSIPProxyStatefulness(netsnmp_mib_handler *handler, int handle_kamailioSIPProxyRecordRoute(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { /* If the rr module is loaded, then we support record route. otherwise, * we want to return 2, which is false for SNMP TruthValue. */ int supportRecordRoute = TC_FALSE; - if (module_loaded("rr")) - { + if(module_loaded("rr")) { supportRecordRoute = TC_TRUE; } - - if (reqinfo->mode==MODE_GET) { + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, - (u_char *) &supportRecordRoute, sizeof(int)); + (u_char *)&supportRecordRoute, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -232,29 +202,28 @@ int handle_kamailioSIPProxyRecordRoute(netsnmp_mib_handler *handler, } int handle_kamailioSIPProxyAuthMethod(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { /* The result needs to be returned as an SNMP bit field. */ unsigned int auth_bitfield = SIP_AUTH_METHOD_NONE; - - if (module_loaded("tls")) { - auth_bitfield |= SIP_AUTH_METHOD_TLS; + + if(module_loaded("tls")) { + auth_bitfield |= SIP_AUTH_METHOD_TLS; auth_bitfield &= ~SIP_AUTH_METHOD_NONE; } - + /* We can have both tls and auth loaded simultaneously. Therefore we * use an if instead of a else/else-if. */ - if (module_loaded("auth")) { + if(module_loaded("auth")) { auth_bitfield |= SIP_AUTH_METHOD_DIGEST; auth_bitfield &= ~SIP_AUTH_METHOD_NONE; } - if (reqinfo->mode==MODE_GET) { + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, - (u_char *) &auth_bitfield, 1); + (u_char *)&auth_bitfield, 1); return SNMP_ERR_NOERROR; } @@ -262,15 +231,14 @@ int handle_kamailioSIPProxyAuthMethod(netsnmp_mib_handler *handler, } int handle_kamailioSIPNumProxyRequireFailures(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { - int result = get_statistic("bad_msg_hdr"); - - if (reqinfo->mode==MODE_GET) { + int result = get_statistic("bad_msg_hdr"); + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &result, sizeof(int)); + (u_char *)&result, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -278,15 +246,14 @@ int handle_kamailioSIPNumProxyRequireFailures(netsnmp_mib_handler *handler, } int handle_kamailioSIPRegMaxContactExpiryDuration(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int result = get_statistic("max_expires"); - - if (reqinfo->mode==MODE_GET) { + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_UNSIGNED, - (u_char *) &result, sizeof(int)); + (u_char *)&result, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -294,19 +261,18 @@ int handle_kamailioSIPRegMaxContactExpiryDuration(netsnmp_mib_handler *handler, } int handle_kamailioSIPRegMaxUsers(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { /* Kamailio doesn't currently have a parameterized maximum number of * users. So we return the maximum value an unsigned32 SNMP datatype * can hold. */ - unsigned int result = 0xffffffff; - - if (reqinfo->mode==MODE_GET) { + unsigned int result = 0xffffffff; + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_UNSIGNED, - (u_char *) &result, sizeof(unsigned int)); + (u_char *)&result, sizeof(unsigned int)); return SNMP_ERR_NOERROR; } @@ -314,17 +280,16 @@ int handle_kamailioSIPRegMaxUsers(netsnmp_mib_handler *handler, } int handle_kamailioSIPRegCurrentUsers(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int max_users = 0; max_users = get_statistic("registered_users"); - - if (reqinfo->mode==MODE_GET) { + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, - (u_char *) &max_users, sizeof(int)); + (u_char *)&max_users, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -332,15 +297,14 @@ int handle_kamailioSIPRegCurrentUsers(netsnmp_mib_handler *handler, } int handle_kamailioSIPRegDfltRegActiveInterval(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int result = get_statistic("default_expire"); - - if (reqinfo->mode==MODE_GET) { + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_UNSIGNED, - (u_char *) &result, sizeof(int)); + (u_char *)&result, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -349,9 +313,8 @@ int handle_kamailioSIPRegDfltRegActiveInterval(netsnmp_mib_handler *handler, int handle_kamailioSIPRegUserLookupCounter(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int result = ++global_UserLookupCounter; @@ -359,13 +322,13 @@ int handle_kamailioSIPRegUserLookupCounter(netsnmp_mib_handler *handler, * then we reset our counter back to 1. For this not to cause problems, * it will be required that old rows belonging to the table * kamailioSIPRegUserLookupTable are eventually deleted. */ - if (global_UserLookupCounter > MAX_USER_LOOKUP_COUNTER) { + if(global_UserLookupCounter > MAX_USER_LOOKUP_COUNTER) { global_UserLookupCounter = 1; } - if (reqinfo->mode==MODE_GET) { + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &result, sizeof(int)); + (u_char *)&result, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -373,15 +336,14 @@ int handle_kamailioSIPRegUserLookupCounter(netsnmp_mib_handler *handler, } int handle_kamailioSIPRegAcceptedRegistrations(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int result = get_statistic("accepted_regs"); - - if (reqinfo->mode==MODE_GET) { + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &result, sizeof(int)); + (u_char *)&result, sizeof(int)); return SNMP_ERR_NOERROR; } @@ -389,18 +351,16 @@ int handle_kamailioSIPRegAcceptedRegistrations(netsnmp_mib_handler *handler, } int handle_kamailioSIPRegRejectedRegistrations(netsnmp_mib_handler *handler, - netsnmp_handler_registration *reginfo, - netsnmp_agent_request_info *reqinfo, - netsnmp_request_info *requests) + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { int result = get_statistic("rejected_regs"); - - if (reqinfo->mode==MODE_GET) { + + if(reqinfo->mode == MODE_GET) { snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, - (u_char *) &result, sizeof(int)); + (u_char *)&result, sizeof(int)); return SNMP_ERR_NOERROR; } return SNMP_ERR_GENERR; -} - +} \ No newline at end of file diff --git a/src/modules/snmpstats/snmpSIPServerObjects.h b/src/modules/snmpstats/snmpSIPServerObjects.h index 5b8a0ee78e2..3e7c2dd72f6 100644 --- a/src/modules/snmpstats/snmpSIPServerObjects.h +++ b/src/modules/snmpstats/snmpSIPServerObjects.h @@ -41,12 +41,12 @@ Netsnmp_Node_Handler handle_kamailioSIPRegUserLookupCounter; Netsnmp_Node_Handler handle_kamailioSIPRegAcceptedRegistrations; Netsnmp_Node_Handler handle_kamailioSIPRegRejectedRegistrations; -#define PROXY_STATEFULNESS_STATELESS 1 +#define PROXY_STATEFULNESS_STATELESS 1 #define PROXY_STATEFULNESS_TRANSACTION_STATEFUL 2 -#define PROXY_STATEFULNESS_CALL_STATEFUL 3 +#define PROXY_STATEFULNESS_CALL_STATEFUL 3 -#define SIP_AUTH_METHOD_NONE (128 >> 0) -#define SIP_AUTH_METHOD_TLS (128 >> 1) +#define SIP_AUTH_METHOD_NONE (128 >> 0) +#define SIP_AUTH_METHOD_TLS (128 >> 1) #define SIP_AUTH_METHOD_DIGEST (128 >> 2) -#endif /* KAMAILIOSIPSERVEROBJECTS_H */ +#endif /* KAMAILIOSIPSERVEROBJECTS_H */ \ No newline at end of file diff --git a/src/modules/snmpstats/snmpSIPStatusCodesTable.c b/src/modules/snmpstats/snmpSIPStatusCodesTable.c index 5c4401174e7..0bd5ba11feb 100644 --- a/src/modules/snmpstats/snmpSIPStatusCodesTable.c +++ b/src/modules/snmpstats/snmpSIPStatusCodesTable.c @@ -80,11 +80,10 @@ static netsnmp_handler_registration *my_handler = NULL; static netsnmp_table_array_callbacks cb; -oid kamailioSIPStatusCodesTable_oid[] = { - kamailioSIPStatusCodesTable_TABLE_OID }; +oid kamailioSIPStatusCodesTable_oid[] = {kamailioSIPStatusCodesTable_TABLE_OID}; size_t kamailioSIPStatusCodesTable_oid_len = -OID_LENGTH(kamailioSIPStatusCodesTable_oid); + OID_LENGTH(kamailioSIPStatusCodesTable_oid); /* @@ -100,34 +99,32 @@ void init_kamailioSIPStatusCodesTable(void) /* the *_row_copy routine */ static int kamailioSIPStatusCodesTable_row_copy( - kamailioSIPStatusCodesTable_context * dst, - kamailioSIPStatusCodesTable_context * src) + kamailioSIPStatusCodesTable_context *dst, + kamailioSIPStatusCodesTable_context *src) { - if(!dst||!src) + if(!dst || !src) return 1; - - + + /* copy index, if provided */ - if(dst->index.oids) - { + if(dst->index.oids) { free(dst->index.oids); } - if(snmp_clone_mem( (void*)&dst->index.oids, src->index.oids, - src->index.len * sizeof(oid) )) - { + if(snmp_clone_mem((void *)&dst->index.oids, src->index.oids, + src->index.len * sizeof(oid))) { dst->index.oids = NULL; return 1; } dst->index.len = src->index.len; - + /* copy components into the context structure */ - dst->kamailioSIPStatusCodeMethod = src->kamailioSIPStatusCodeMethod; - dst->kamailioSIPStatusCodeValue = src->kamailioSIPStatusCodeValue; - dst->kamailioSIPStatusCodeIns = src->kamailioSIPStatusCodeIns; - dst->kamailioSIPStatusCodeOuts = src->kamailioSIPStatusCodeOuts; + dst->kamailioSIPStatusCodeMethod = src->kamailioSIPStatusCodeMethod; + dst->kamailioSIPStatusCodeValue = src->kamailioSIPStatusCodeValue; + dst->kamailioSIPStatusCodeIns = src->kamailioSIPStatusCodeIns; + dst->kamailioSIPStatusCodeOuts = src->kamailioSIPStatusCodeOuts; dst->kamailioSIPStatusCodeRowStatus = src->kamailioSIPStatusCodeRowStatus; return 0; @@ -145,8 +142,8 @@ static int kamailioSIPStatusCodesTable_row_copy( * returned if they are invalid. An index is invalid if it is not between * 100 and 699 (Inclusive). */ -int kamailioSIPStatusCodesTable_extract_index( - kamailioSIPStatusCodesTable_context * ctx, netsnmp_index * hdr) +int kamailioSIPStatusCodesTable_extract_index( + kamailioSIPStatusCodesTable_context *ctx, netsnmp_index *hdr) { /* @@ -164,62 +161,57 @@ int kamailioSIPStatusCodesTable_extract_index( */ if(hdr) { netsnmp_assert(ctx->index.oids == NULL); - if((hdr->len > MAX_OID_LEN) || - snmp_clone_mem( - (void*)&ctx->index.oids, - hdr->oids, - hdr->len * sizeof(oid))) - { + if((hdr->len > MAX_OID_LEN) + || snmp_clone_mem((void *)&ctx->index.oids, hdr->oids, + hdr->len * sizeof(oid))) { return -1; } ctx->index.len = hdr->len; } - /* Initialize the two variables responsible for holding our two indices. + /* Initialize the two variables responsible for holding our two indices. */ - memset(&var_kamailioSIPStatusCodeMethod, 0x00, - sizeof(var_kamailioSIPStatusCodeMethod)); + memset(&var_kamailioSIPStatusCodeMethod, 0x00, + sizeof(var_kamailioSIPStatusCodeMethod)); - memset( &var_kamailioSIPStatusCodeValue, 0x00, - sizeof(var_kamailioSIPStatusCodeValue) ); + memset(&var_kamailioSIPStatusCodeValue, 0x00, + sizeof(var_kamailioSIPStatusCodeValue)); - var_kamailioSIPStatusCodeMethod.type = ASN_UNSIGNED; - var_kamailioSIPStatusCodeValue.type = ASN_UNSIGNED; + var_kamailioSIPStatusCodeMethod.type = ASN_UNSIGNED; + var_kamailioSIPStatusCodeValue.type = ASN_UNSIGNED; - var_kamailioSIPStatusCodeMethod.next_variable = - &var_kamailioSIPStatusCodeValue; + var_kamailioSIPStatusCodeMethod.next_variable = + &var_kamailioSIPStatusCodeValue; var_kamailioSIPStatusCodeValue.next_variable = NULL; /* parse the oid into the individual index components */ - err = parse_oid_indexes( hdr->oids, hdr->len, - &var_kamailioSIPStatusCodeMethod ); + err = parse_oid_indexes( + hdr->oids, hdr->len, &var_kamailioSIPStatusCodeMethod); - if (err == SNMP_ERR_NOERROR) { + if(err == SNMP_ERR_NOERROR) { /* copy index components into the context structure */ - ctx->kamailioSIPStatusCodeMethod = - *var_kamailioSIPStatusCodeMethod.val.integer; - ctx->kamailioSIPStatusCodeValue = - *var_kamailioSIPStatusCodeValue.val.integer; - - - if (*var_kamailioSIPStatusCodeMethod.val.integer < 1) - { + ctx->kamailioSIPStatusCodeMethod = + *var_kamailioSIPStatusCodeMethod.val.integer; + ctx->kamailioSIPStatusCodeValue = + *var_kamailioSIPStatusCodeValue.val.integer; + + + if(*var_kamailioSIPStatusCodeMethod.val.integer < 1) { err = -1; } - if (*var_kamailioSIPStatusCodeValue.val.integer < 100 || - *var_kamailioSIPStatusCodeValue.val.integer > 699) { + if(*var_kamailioSIPStatusCodeValue.val.integer < 100 + || *var_kamailioSIPStatusCodeValue.val.integer > 699) { err = -1; } - } - + /* parsing may have allocated memory. free it. */ - snmp_reset_var_buffers( &var_kamailioSIPStatusCodeMethod ); + snmp_reset_var_buffers(&var_kamailioSIPStatusCodeMethod); return err; } @@ -235,8 +227,7 @@ int kamailioSIPStatusCodesTable_extract_index( */ int kamailioSIPStatusCodesTable_can_activate( kamailioSIPStatusCodesTable_context *undo_ctx, - kamailioSIPStatusCodesTable_context *row_ctx, - netsnmp_request_group * rg) + kamailioSIPStatusCodesTable_context *row_ctx, netsnmp_request_group *rg) { return 1; } @@ -254,8 +245,7 @@ int kamailioSIPStatusCodesTable_can_activate( */ int kamailioSIPStatusCodesTable_can_deactivate( kamailioSIPStatusCodesTable_context *undo_ctx, - kamailioSIPStatusCodesTable_context *row_ctx, - netsnmp_request_group * rg) + kamailioSIPStatusCodesTable_context *row_ctx, netsnmp_request_group *rg) { return 1; } @@ -272,12 +262,11 @@ int kamailioSIPStatusCodesTable_can_deactivate( */ int kamailioSIPStatusCodesTable_can_delete( kamailioSIPStatusCodesTable_context *undo_ctx, - kamailioSIPStatusCodesTable_context *row_ctx, - netsnmp_request_group * rg) + kamailioSIPStatusCodesTable_context *row_ctx, netsnmp_request_group *rg) { - if(kamailioSIPStatusCodesTable_can_deactivate(undo_ctx,row_ctx,rg) != 1) + if(kamailioSIPStatusCodesTable_can_deactivate(undo_ctx, row_ctx, rg) != 1) return 0; - + return 1; } @@ -300,21 +289,21 @@ int kamailioSIPStatusCodesTable_can_delete( * This value will be used in the future to calculate the delta between now and * the time this row has been read. * */ -kamailioSIPStatusCodesTable_context * -kamailioSIPStatusCodesTable_create_row( netsnmp_index* hdr) +kamailioSIPStatusCodesTable_context *kamailioSIPStatusCodesTable_create_row( + netsnmp_index *hdr) { stat_var *in_status_code; stat_var *out_status_code; - kamailioSIPStatusCodesTable_context * ctx = - SNMP_MALLOC_TYPEDEF(kamailioSIPStatusCodesTable_context); + kamailioSIPStatusCodesTable_context *ctx = + SNMP_MALLOC_TYPEDEF(kamailioSIPStatusCodesTable_context); if(!ctx) return NULL; - + /* The *_extract_index funtion already validates the indices, so we * don't need to do any further evaluations here. */ - if(kamailioSIPStatusCodesTable_extract_index( ctx, hdr )) { - if (NULL != ctx->index.oids) + if(kamailioSIPStatusCodesTable_extract_index(ctx, hdr)) { + if(NULL != ctx->index.oids) free(ctx->index.oids); free(ctx); return NULL; @@ -323,8 +312,8 @@ kamailioSIPStatusCodesTable_create_row( netsnmp_index* hdr) /* The indices were already set up in the extract_index function * above. */ - ctx->kamailioSIPStatusCodeIns = 0; - ctx->kamailioSIPStatusCodeOuts = 0; + ctx->kamailioSIPStatusCodeIns = 0; + ctx->kamailioSIPStatusCodeOuts = 0; ctx->kamailioSIPStatusCodeRowStatus = 0; /* Retrieve the index for the status code, and then assign the starting @@ -332,19 +321,17 @@ kamailioSIPStatusCodesTable_create_row( netsnmp_index* hdr) * the next snmpget/snmpwalk/snmptable/etc. */ int codeIndex = ctx->kamailioSIPStatusCodeValue; - ctx->startingInStatusCodeValue = 0; + ctx->startingInStatusCodeValue = 0; ctx->startingOutStatusCodeValue = 0; - in_status_code = get_stat_var_from_num_code(codeIndex, 0); + in_status_code = get_stat_var_from_num_code(codeIndex, 0); out_status_code = get_stat_var_from_num_code(codeIndex, 1); - if (in_status_code != NULL) - { - ctx->startingInStatusCodeValue = get_stat_val(in_status_code); + if(in_status_code != NULL) { + ctx->startingInStatusCodeValue = get_stat_val(in_status_code); } - if (out_status_code != NULL) - { + if(out_status_code != NULL) { ctx->startingOutStatusCodeValue = get_stat_val(out_status_code); } @@ -355,11 +342,10 @@ kamailioSIPStatusCodesTable_create_row( netsnmp_index* hdr) /* * Auto-generated function. The *_duplicate row routine */ -kamailioSIPStatusCodesTable_context * -kamailioSIPStatusCodesTable_duplicate_row( - kamailioSIPStatusCodesTable_context * row_ctx) +kamailioSIPStatusCodesTable_context *kamailioSIPStatusCodesTable_duplicate_row( + kamailioSIPStatusCodesTable_context *row_ctx) { - kamailioSIPStatusCodesTable_context * dup; + kamailioSIPStatusCodesTable_context *dup; if(!row_ctx) return NULL; @@ -367,8 +353,8 @@ kamailioSIPStatusCodesTable_duplicate_row( dup = SNMP_MALLOC_TYPEDEF(kamailioSIPStatusCodesTable_context); if(!dup) return NULL; - - if(kamailioSIPStatusCodesTable_row_copy(dup,row_ctx)) { + + if(kamailioSIPStatusCodesTable_row_copy(dup, row_ctx)) { free(dup); dup = NULL; } @@ -384,13 +370,13 @@ kamailioSIPStatusCodesTable_duplicate_row( * deleted. However, in our implementation there is never a reason why this * function can't be called. */ -netsnmp_index * kamailioSIPStatusCodesTable_delete_row( - kamailioSIPStatusCodesTable_context * ctx ) +netsnmp_index *kamailioSIPStatusCodesTable_delete_row( + kamailioSIPStatusCodesTable_context *ctx) { if(ctx->index.oids) free(ctx->index.oids); - free( ctx ); + free(ctx); return NULL; } @@ -415,68 +401,59 @@ netsnmp_index * kamailioSIPStatusCodesTable_delete_row( * any other condition is considered illegal, and will result in an SNMP error * being returned. */ -void kamailioSIPStatusCodesTable_set_reserve1( netsnmp_request_group *rg ) +void kamailioSIPStatusCodesTable_set_reserve1(netsnmp_request_group *rg) { kamailioSIPStatusCodesTable_context *row_ctx = - (kamailioSIPStatusCodesTable_context *)rg->existing_row; + (kamailioSIPStatusCodesTable_context *)rg->existing_row; - netsnmp_variable_list *var; + netsnmp_variable_list *var; netsnmp_request_group_item *current; int rc; /* Loop through the specified columns, and make sure that all values are * valid. */ - for( current = rg->list; current; current = current->next ) { + for(current = rg->list; current; current = current->next) { var = current->ri->requestvb; rc = SNMP_ERR_NOERROR; - switch(current->tri->colnum) - { + switch(current->tri->colnum) { case COLUMN_KAMAILIOSIPSTATUSCODEROWSTATUS: /** RowStatus = ASN_INTEGER */ - rc = netsnmp_check_vb_type_and_size(var, - ASN_INTEGER, - sizeof( - row_ctx->kamailioSIPStatusCodeRowStatus)); - + rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER, + sizeof(row_ctx->kamailioSIPStatusCodeRowStatus)); + /* Want to make sure that if it already exists that it * is setting it to 'destroy', or if it doesn't exist, * that it is setting it to 'createAndGo' */ - if (row_ctx->kamailioSIPStatusCodeRowStatus == 0 && - *var->val.integer != TC_ROWSTATUS_CREATEANDGO) - { + if(row_ctx->kamailioSIPStatusCodeRowStatus == 0 + && *var->val.integer != TC_ROWSTATUS_CREATEANDGO) { rc = SNMP_ERR_BADVALUE; - } + } - else if (row_ctx->kamailioSIPStatusCodeRowStatus == - TC_ROWSTATUS_ACTIVE && - *var->val.integer != - TC_ROWSTATUS_DESTROY) - { + else if(row_ctx->kamailioSIPStatusCodeRowStatus + == TC_ROWSTATUS_ACTIVE + && *var->val.integer != TC_ROWSTATUS_DESTROY) { rc = SNMP_ERR_BADVALUE; } - + break; default: /** We shouldn't get here */ rc = SNMP_ERR_GENERR; snmp_log(LOG_ERR, "unknown column in kamailioSIP" - "StatusCodesTable_set_reserve1\n"); + "StatusCodesTable_set_reserve1\n"); } - if (rc) - { - netsnmp_set_mode_request_error(MODE_SET_BEGIN, - current->ri, rc ); + if(rc) { + netsnmp_set_mode_request_error(MODE_SET_BEGIN, current->ri, rc); } rg->status = SNMP_MAX(rg->status, current->ri->status); } - } /* @@ -484,10 +461,10 @@ void kamailioSIPStatusCodesTable_set_reserve1( netsnmp_request_group *rg ) * last-minute conditions not being met. However, we don't have any such * conditions, so we leave the default function as is. */ -void kamailioSIPStatusCodesTable_set_reserve2( netsnmp_request_group *rg ) +void kamailioSIPStatusCodesTable_set_reserve2(netsnmp_request_group *rg) { - kamailioSIPStatusCodesTable_context *undo_ctx = - (kamailioSIPStatusCodesTable_context *)rg->undo_info; + kamailioSIPStatusCodesTable_context *undo_ctx = + (kamailioSIPStatusCodesTable_context *)rg->undo_info; netsnmp_request_group_item *current; @@ -495,33 +472,29 @@ void kamailioSIPStatusCodesTable_set_reserve2( netsnmp_request_group *rg ) rg->rg_void = rg->list->ri; - for( current = rg->list; current; current = current->next ) { + for(current = rg->list; current; current = current->next) { rc = SNMP_ERR_NOERROR; - switch(current->tri->colnum) - { + switch(current->tri->colnum) { case COLUMN_KAMAILIOSIPSTATUSCODEROWSTATUS: /** RowStatus = ASN_INTEGER */ rc = netsnmp_check_vb_rowstatus(current->ri->requestvb, - undo_ctx ? - undo_ctx->kamailioSIPStatusCodeRowStatus:0); + undo_ctx ? undo_ctx->kamailioSIPStatusCodeRowStatus + : 0); rg->rg_void = current->ri; break; - default: /** We shouldn't get here */ + default: /** We shouldn't get here */ netsnmp_assert(0); /** why wasn't this caught in reserve1? */ } - if (rc) - { - netsnmp_set_mode_request_error(MODE_SET_BEGIN, - current->ri, rc); + if(rc) { + netsnmp_set_mode_request_error(MODE_SET_BEGIN, current->ri, rc); } } - } /* @@ -532,15 +505,15 @@ void kamailioSIPStatusCodesTable_set_reserve2( netsnmp_request_group *rg ) * In our case, we don't require any changes. So we leave the original * auto-generated code as is. */ -void kamailioSIPStatusCodesTable_set_action( netsnmp_request_group *rg ) +void kamailioSIPStatusCodesTable_set_action(netsnmp_request_group *rg) { netsnmp_variable_list *var; - kamailioSIPStatusCodesTable_context *row_ctx = - (kamailioSIPStatusCodesTable_context *)rg->existing_row; + kamailioSIPStatusCodesTable_context *row_ctx = + (kamailioSIPStatusCodesTable_context *)rg->existing_row; - kamailioSIPStatusCodesTable_context *undo_ctx = - (kamailioSIPStatusCodesTable_context *)rg->undo_info; + kamailioSIPStatusCodesTable_context *undo_ctx = + (kamailioSIPStatusCodesTable_context *)rg->undo_info; netsnmp_request_group_item *current; @@ -548,66 +521,57 @@ void kamailioSIPStatusCodesTable_set_action( netsnmp_request_group *rg ) /* Depending on what the snmpset was, set the row to be created or * deleted. */ - for( current = rg->list; current; current = current->next ) - { + for(current = rg->list; current; current = current->next) { var = current->ri->requestvb; - switch(current->tri->colnum) - { + switch(current->tri->colnum) { case COLUMN_KAMAILIOSIPSTATUSCODEROWSTATUS: - + /** RowStatus = ASN_INTEGER */ - row_ctx->kamailioSIPStatusCodeRowStatus = - *var->val.integer; + row_ctx->kamailioSIPStatusCodeRowStatus = *var->val.integer; - if (*var->val.integer == TC_ROWSTATUS_CREATEANDGO) - { + if(*var->val.integer == TC_ROWSTATUS_CREATEANDGO) { rg->row_created = 1; - } - else if (*var->val.integer == TC_ROWSTATUS_DESTROY) - { + } else if(*var->val.integer == TC_ROWSTATUS_DESTROY) { rg->row_deleted = 1; - } - else { + } else { /* We should never be here, because the RESERVE * functions should have taken care of all other * values. */ - LM_ERR("Invalid RowStatus in kamailioSIPStatusCodesTable\n"); + LM_ERR("Invalid RowStatus in " + "kamailioSIPStatusCodesTable\n"); } break; - default: /** We shouldn't get here */ + default: /** We shouldn't get here */ netsnmp_assert(0); /** why wasn't this caught in reserve1? */ } } - /* +/* * done with all the columns. Could check row related * requirements here. */ #ifndef kamailioSIPStatusCodesTable_CAN_MODIFY_ACTIVE_ROW - if( undo_ctx && RS_IS_ACTIVE(undo_ctx->kamailioSIPStatusCodeRowStatus) && - row_ctx && RS_IS_ACTIVE(row_ctx->kamailioSIPStatusCodeRowStatus)) - { - row_err = 1; + if(undo_ctx && RS_IS_ACTIVE(undo_ctx->kamailioSIPStatusCodeRowStatus) + && row_ctx + && RS_IS_ACTIVE(row_ctx->kamailioSIPStatusCodeRowStatus)) { + row_err = 1; } #endif /* * check activation/deactivation */ - row_err = netsnmp_table_array_check_row_status(&cb, rg, - row_ctx ? - &row_ctx->kamailioSIPStatusCodeRowStatus : NULL, - undo_ctx ? - &undo_ctx->kamailioSIPStatusCodeRowStatus : NULL); + row_err = netsnmp_table_array_check_row_status(&cb, rg, + row_ctx ? &row_ctx->kamailioSIPStatusCodeRowStatus : NULL, + undo_ctx ? &undo_ctx->kamailioSIPStatusCodeRowStatus : NULL); if(row_err) { - netsnmp_set_mode_request_error(MODE_SET_BEGIN, - (netsnmp_request_info*)rg->rg_void, row_err); + netsnmp_set_mode_request_error( + MODE_SET_BEGIN, (netsnmp_request_info *)rg->rg_void, row_err); return; } - } @@ -615,9 +579,8 @@ void kamailioSIPStatusCodesTable_set_action( netsnmp_request_group *rg ) * The COMMIT phase is used to do any extra processing after the ACTION phase. * In our table, there is nothing to do, so the function body is empty. */ -void kamailioSIPStatusCodesTable_set_commit( netsnmp_request_group *rg ) +void kamailioSIPStatusCodesTable_set_commit(netsnmp_request_group *rg) { - } @@ -627,9 +590,8 @@ void kamailioSIPStatusCodesTable_set_commit( netsnmp_request_group *rg ) * all these resources in earlier functions. So for our purposes, the function * body is empty. */ -void kamailioSIPStatusCodesTable_set_free( netsnmp_request_group *rg ) +void kamailioSIPStatusCodesTable_set_free(netsnmp_request_group *rg) { - } @@ -638,13 +600,11 @@ void kamailioSIPStatusCodesTable_set_free( netsnmp_request_group *rg ) * We don't have anything complicated enough to warrant putting anything in this * function. Therefore, its just left with an empty function body. */ -void kamailioSIPStatusCodesTable_set_undo( netsnmp_request_group *rg ) +void kamailioSIPStatusCodesTable_set_undo(netsnmp_request_group *rg) { - } - /* * Initialize the kamailioSIPStatusCodesTable table by defining how it is * structured. @@ -657,7 +617,7 @@ void initialize_table_kamailioSIPStatusCodesTable(void) if(my_handler) { snmp_log(LOG_ERR, "initialize_table_kamailioSIPStatusCodes" - "Table_handler called again\n"); + "Table_handler called again\n"); return; } @@ -667,15 +627,13 @@ void initialize_table_kamailioSIPStatusCodesTable(void) table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); my_handler = netsnmp_create_handler_registration( - "kamailioSIPStatusCodesTable", - netsnmp_table_array_helper_handler, + "kamailioSIPStatusCodesTable", netsnmp_table_array_helper_handler, kamailioSIPStatusCodesTable_oid, - kamailioSIPStatusCodesTable_oid_len, - HANDLER_CAN_RWRITE); - - if (!my_handler || !table_info) { + kamailioSIPStatusCodesTable_oid_len, HANDLER_CAN_RWRITE); + + if(!my_handler || !table_info) { snmp_log(LOG_ERR, "malloc failed in initialize_table_kamailioSIP" - "StatusCodesTable_handler\n"); + "StatusCodesTable_handler\n"); return; /** mallocs failed */ } @@ -692,58 +650,54 @@ void initialize_table_kamailioSIPStatusCodesTable(void) */ cb.get_value = kamailioSIPStatusCodesTable_get_value; - cb.container = - netsnmp_container_find("kamailioSIPStatusCodesTable_primary:" - "kamailioSIPStatusCodesTable:" - "table_container"); + cb.container = netsnmp_container_find("kamailioSIPStatusCodesTable_primary:" + "kamailioSIPStatusCodesTable:" + "table_container"); #ifdef kamailioSIPStatusCodesTable_CUSTOM_SORT netsnmp_container_add_index(cb.container, - netsnmp_container_find( - "kamailioSIPStatusCodesTable_custom:" - "kamailioSIPStatusCodesTable:" - "table_container")); + netsnmp_container_find("kamailioSIPStatusCodesTable_custom:" + "kamailioSIPStatusCodesTable:" + "table_container")); cb.container->next->compare = kamailioSIPStatusCodesTable_cmp; #endif cb.can_set = 1; - cb.create_row = - (UserRowMethod*)kamailioSIPStatusCodesTable_create_row; + cb.create_row = (UserRowMethod *)kamailioSIPStatusCodesTable_create_row; - cb.duplicate_row = - (UserRowMethod*)kamailioSIPStatusCodesTable_duplicate_row; + cb.duplicate_row = + (UserRowMethod *)kamailioSIPStatusCodesTable_duplicate_row; - cb.delete_row = - (UserRowMethod*)kamailioSIPStatusCodesTable_delete_row; + cb.delete_row = (UserRowMethod *)kamailioSIPStatusCodesTable_delete_row; - cb.row_copy = (Netsnmp_User_Row_Operation *) - kamailioSIPStatusCodesTable_row_copy; + cb.row_copy = + (Netsnmp_User_Row_Operation *)kamailioSIPStatusCodesTable_row_copy; - cb.can_activate = (Netsnmp_User_Row_Action *) - kamailioSIPStatusCodesTable_can_activate; + cb.can_activate = + (Netsnmp_User_Row_Action *)kamailioSIPStatusCodesTable_can_activate; cb.can_deactivate = (Netsnmp_User_Row_Action *) - kamailioSIPStatusCodesTable_can_deactivate; + kamailioSIPStatusCodesTable_can_deactivate; + + cb.can_delete = + (Netsnmp_User_Row_Action *)kamailioSIPStatusCodesTable_can_delete; - cb.can_delete = - (Netsnmp_User_Row_Action *)kamailioSIPStatusCodesTable_can_delete; + cb.set_reserve1 = kamailioSIPStatusCodesTable_set_reserve1; + cb.set_reserve2 = kamailioSIPStatusCodesTable_set_reserve2; - cb.set_reserve1 = kamailioSIPStatusCodesTable_set_reserve1; - cb.set_reserve2 = kamailioSIPStatusCodesTable_set_reserve2; - cb.set_action = kamailioSIPStatusCodesTable_set_action; cb.set_commit = kamailioSIPStatusCodesTable_set_commit; - + cb.set_free = kamailioSIPStatusCodesTable_set_free; cb.set_undo = kamailioSIPStatusCodesTable_set_undo; - + DEBUGMSGTL(("initialize_table_kamailioSIPStatusCodesTable", - "Registering table kamailioSIPStatusCodesTable " - "as a table array\n")); - - netsnmp_table_container_register(my_handler, table_info, &cb, - cb.container, 1); + "Registering table kamailioSIPStatusCodesTable " + "as a table array\n")); + + netsnmp_table_container_register( + my_handler, table_info, &cb, cb.container, 1); } /* @@ -759,74 +713,67 @@ void initialize_table_kamailioSIPStatusCodesTable(void) * ins and how many outs have been received (With respect to the message code) * since this row was created. */ -int kamailioSIPStatusCodesTable_get_value( - netsnmp_request_info *request, - netsnmp_index *item, - netsnmp_table_request_info *table_info ) +int kamailioSIPStatusCodesTable_get_value(netsnmp_request_info *request, + netsnmp_index *item, netsnmp_table_request_info *table_info) { stat_var *the_stat; netsnmp_variable_list *var = request->requestvb; - kamailioSIPStatusCodesTable_context *context = - (kamailioSIPStatusCodesTable_context *)item; + kamailioSIPStatusCodesTable_context *context = + (kamailioSIPStatusCodesTable_context *)item; /* Retrieve the statusCodeIdx so we can calculate deltas between current * values and previous values. */ int statusCodeIdx = context->kamailioSIPStatusCodeValue; - switch(table_info->colnum) - { + switch(table_info->colnum) { case COLUMN_KAMAILIOSIPSTATUSCODEINS: context->kamailioSIPStatusCodeIns = 0; the_stat = get_stat_var_from_num_code(statusCodeIdx, 0); - if (the_stat != NULL) - { + if(the_stat != NULL) { /* Calculate the Delta */ - context->kamailioSIPStatusCodeIns = get_stat_val(the_stat) - - context->startingInStatusCodeValue; + context->kamailioSIPStatusCodeIns = + get_stat_val(the_stat) + - context->startingInStatusCodeValue; } snmp_set_var_typed_value(var, ASN_COUNTER, - (unsigned char*) - &context->kamailioSIPStatusCodeIns, + (unsigned char *)&context->kamailioSIPStatusCodeIns, sizeof(context->kamailioSIPStatusCodeIns)); break; - + case COLUMN_KAMAILIOSIPSTATUSCODEOUTS: - + context->kamailioSIPStatusCodeOuts = 0; the_stat = get_stat_var_from_num_code(statusCodeIdx, 1); - if (the_stat != NULL) - { + if(the_stat != NULL) { /* Calculate the Delta */ context->kamailioSIPStatusCodeOuts = - get_stat_val(the_stat) - - context->startingOutStatusCodeValue; + get_stat_val(the_stat) + - context->startingOutStatusCodeValue; } snmp_set_var_typed_value(var, ASN_COUNTER, - (unsigned char*) - &context->kamailioSIPStatusCodeOuts, - sizeof(context->kamailioSIPStatusCodeOuts) ); - break; - + (unsigned char *)&context->kamailioSIPStatusCodeOuts, + sizeof(context->kamailioSIPStatusCodeOuts)); + break; + case COLUMN_KAMAILIOSIPSTATUSCODEROWSTATUS: /** RowStatus = ASN_INTEGER */ snmp_set_var_typed_value(var, ASN_INTEGER, - (unsigned char*) - &context->kamailioSIPStatusCodeRowStatus, - sizeof(context->kamailioSIPStatusCodeRowStatus) ); - break; - - default: /** We shouldn't get here */ - snmp_log(LOG_ERR, "unknown column in " - "kamailioSIPStatusCodesTable_get_value\n"); - return SNMP_ERR_GENERR; + (unsigned char *)&context->kamailioSIPStatusCodeRowStatus, + sizeof(context->kamailioSIPStatusCodeRowStatus)); + break; + + default: /** We shouldn't get here */ + snmp_log(LOG_ERR, "unknown column in " + "kamailioSIPStatusCodesTable_get_value\n"); + return SNMP_ERR_GENERR; } return SNMP_ERR_NOERROR; } @@ -835,10 +782,8 @@ int kamailioSIPStatusCodesTable_get_value( * kamailioSIPRegUserLookupTable_get_by_idx */ const kamailioSIPStatusCodesTable_context * -kamailioSIPStatusCodesTable_get_by_idx(netsnmp_index * hdr) +kamailioSIPStatusCodesTable_get_by_idx(netsnmp_index *hdr) { - return (const kamailioSIPStatusCodesTable_context *) - CONTAINER_FIND(cb.container, hdr ); -} - - + return (const kamailioSIPStatusCodesTable_context *)CONTAINER_FIND( + cb.container, hdr); +} \ No newline at end of file diff --git a/src/modules/snmpstats/snmpSIPStatusCodesTable.h b/src/modules/snmpstats/snmpSIPStatusCodesTable.h index 8b4a7362d90..f23b7b9ae5a 100644 --- a/src/modules/snmpstats/snmpSIPStatusCodesTable.h +++ b/src/modules/snmpstats/snmpSIPStatusCodesTable.h @@ -54,7 +54,7 @@ extern "C" { #endif - + #include #include #include @@ -76,14 +76,15 @@ extern "C" { * many of the given message codes have occurred since the creation of the row, * insead of since Kamailio first loaded up. */ -typedef struct kamailioSIPStatusCodesTable_context_s { - +typedef struct kamailioSIPStatusCodesTable_context_s +{ + /* The container interface requires that this be first. */ - netsnmp_index index; + netsnmp_index index; /* The first index. */ unsigned long kamailioSIPStatusCodeMethod; - + /* The second index, specifying which status code to monitor */ unsigned long kamailioSIPStatusCodeValue; @@ -102,7 +103,7 @@ typedef struct kamailioSIPStatusCodesTable_context_s { long kamailioSIPStatusCodeRowStatus; /* Added automatically, but not really used by us. */ - void * data; + void *data; long startingInStatusCodeValue; long startingOutStatusCodeValue; @@ -137,55 +138,54 @@ void initialize_table_kamailioSIPStatusCodesTable(void); * ins and how many outs have been received (With respect to the message code) * since this row was created. */ -int kamailioSIPStatusCodesTable_get_value(netsnmp_request_info *, - netsnmp_index *, netsnmp_table_request_info *); +int kamailioSIPStatusCodesTable_get_value( + netsnmp_request_info *, netsnmp_index *, netsnmp_table_request_info *); -const kamailioSIPStatusCodesTable_context * - kamailioSIPStatusCodesTable_get_by_idx(netsnmp_index *); +const kamailioSIPStatusCodesTable_context * +kamailioSIPStatusCodesTable_get_by_idx(netsnmp_index *); -const kamailioSIPStatusCodesTable_context * - kamailioSIPStatusCodesTable_get_by_idx_rs(netsnmp_index *, - int row_status); +const kamailioSIPStatusCodesTable_context * +kamailioSIPStatusCodesTable_get_by_idx_rs(netsnmp_index *, int row_status); /* oid declarations */ extern oid kamailioSIPStatusCodesTable_oid[]; extern size_t kamailioSIPStatusCodesTable_oid_len; -#define kamailioSIPStatusCodesTable_TABLE_OID KAMAILIO_OID,3,1,1,1,5,1 - +#define kamailioSIPStatusCodesTable_TABLE_OID KAMAILIO_OID, 3, 1, 1, 1, 5, 1 + /* column number definitions for table kamailioSIPStatusCodesTable */ -#define COLUMN_KAMAILIOSIPSTATUSCODEMETHOD 1 -#define COLUMN_KAMAILIOSIPSTATUSCODEVALUE 2 -#define COLUMN_KAMAILIOSIPSTATUSCODEINS 3 -#define COLUMN_KAMAILIOSIPSTATUSCODEOUTS 4 +#define COLUMN_KAMAILIOSIPSTATUSCODEMETHOD 1 +#define COLUMN_KAMAILIOSIPSTATUSCODEVALUE 2 +#define COLUMN_KAMAILIOSIPSTATUSCODEINS 3 +#define COLUMN_KAMAILIOSIPSTATUSCODEOUTS 4 #define COLUMN_KAMAILIOSIPSTATUSCODEROWSTATUS 5 #define kamailioSIPStatusCodesTable_COL_MIN 3 #define kamailioSIPStatusCodesTable_COL_MAX 5 /* Handles index extraction for row creation */ -int kamailioSIPStatusCodesTable_extract_index( - kamailioSIPStatusCodesTable_context * ctx, netsnmp_index * hdr ); +int kamailioSIPStatusCodesTable_extract_index( + kamailioSIPStatusCodesTable_context *ctx, netsnmp_index *hdr); /* Handle RESERVE1 and RESERVE2 phases of an SNMP SET */ -void kamailioSIPStatusCodesTable_set_reserve1( netsnmp_request_group * ); -void kamailioSIPStatusCodesTable_set_reserve2( netsnmp_request_group * ); +void kamailioSIPStatusCodesTable_set_reserve1(netsnmp_request_group *); +void kamailioSIPStatusCodesTable_set_reserve2(netsnmp_request_group *); /* Handle the SET and ACTION phases of an SNMP SET */ -void kamailioSIPStatusCodesTable_set_action( netsnmp_request_group * ); -void kamailioSIPStatusCodesTable_set_commit( netsnmp_request_group * ); +void kamailioSIPStatusCodesTable_set_action(netsnmp_request_group *); +void kamailioSIPStatusCodesTable_set_commit(netsnmp_request_group *); /* Handle Resource cleanup if the ACTION or RESERVE1/RESERVE2 phases of an * SNMPSET fail */ -void kamailioSIPStatusCodesTable_set_free( netsnmp_request_group * ); -void kamailioSIPStatusCodesTable_set_undo( netsnmp_request_group * ); +void kamailioSIPStatusCodesTable_set_free(netsnmp_request_group *); +void kamailioSIPStatusCodesTable_set_undo(netsnmp_request_group *); -kamailioSIPStatusCodesTable_context * kamailioSIPStatusCodesTable_duplicate_row( - kamailioSIPStatusCodesTable_context* ); +kamailioSIPStatusCodesTable_context *kamailioSIPStatusCodesTable_duplicate_row( + kamailioSIPStatusCodesTable_context *); -netsnmp_index * kamailioSIPStatusCodesTable_delete_row( - kamailioSIPStatusCodesTable_context* ); +netsnmp_index *kamailioSIPStatusCodesTable_delete_row( + kamailioSIPStatusCodesTable_context *); /* Used to check if there is a reason why a row can't be activated * (There is no reason in our implementation) @@ -193,7 +193,7 @@ netsnmp_index * kamailioSIPStatusCodesTable_delete_row( int kamailioSIPStatusCodesTable_can_activate( kamailioSIPStatusCodesTable_context *undo_ctx, kamailioSIPStatusCodesTable_context *row_ctx, - netsnmp_request_group * rg); + netsnmp_request_group *rg); /* Used to check if there is a reason why a row can't be deactivated * (There is no reason in our implementation) @@ -201,7 +201,7 @@ int kamailioSIPStatusCodesTable_can_activate( int kamailioSIPStatusCodesTable_can_deactivate( kamailioSIPStatusCodesTable_context *undo_ctx, kamailioSIPStatusCodesTable_context *row_ctx, - netsnmp_request_group * rg); + netsnmp_request_group *rg); /* Used to check if there is a reason why a row can't be deleted * (There is no reason in our implementation) @@ -209,15 +209,15 @@ int kamailioSIPStatusCodesTable_can_deactivate( int kamailioSIPStatusCodesTable_can_delete( kamailioSIPStatusCodesTable_context *undo_ctx, kamailioSIPStatusCodesTable_context *row_ctx, - netsnmp_request_group * rg); - - -kamailioSIPStatusCodesTable_context * - kamailioSIPStatusCodesTable_create_row( netsnmp_index* ); + netsnmp_request_group *rg); + + +kamailioSIPStatusCodesTable_context *kamailioSIPStatusCodesTable_create_row( + netsnmp_index *); #ifdef __cplusplus } #endif -#endif /** KAMAILIOSIPSTATUSCODESTABLE_H */ +#endif /** KAMAILIOSIPSTATUSCODESTABLE_H */ \ No newline at end of file diff --git a/src/modules/snmpstats/snmp_statistics.c b/src/modules/snmpstats/snmp_statistics.c index 6d1c3f859c1..ffba4a1bb94 100644 --- a/src/modules/snmpstats/snmp_statistics.c +++ b/src/modules/snmpstats/snmp_statistics.c @@ -51,14 +51,14 @@ */ stat_var *get_stat_var_from_num_code(unsigned int numerical_code, int out_codes) { - static char msg_code[INT2STR_MAX_LEN+4]; + static char msg_code[INT2STR_MAX_LEN + 4]; str stat_name; - stat_name.s = int2bstr( (unsigned long)numerical_code, msg_code, - &stat_name.len); + stat_name.s = + int2bstr((unsigned long)numerical_code, msg_code, &stat_name.len); stat_name.s[stat_name.len++] = '_'; - if (out_codes) { + if(out_codes) { stat_name.s[stat_name.len++] = 'o'; stat_name.s[stat_name.len++] = 'u'; stat_name.s[stat_name.len++] = 't'; @@ -106,7 +106,8 @@ stat_var *get_stat_var_from_num_code(unsigned int numerical_code, int out_codes) * Therefore it is CRUCIAL that you free ipList when you are done with its * contents, to avoid a nasty memory leak. */ -int get_socket_list_from_proto(int **ipList, int protocol) { +int get_socket_list_from_proto(int **ipList, int protocol) +{ return get_socket_list_from_proto_and_family(ipList, protocol, AF_INET); } @@ -132,54 +133,52 @@ int get_socket_list_from_proto(int **ipList, int protocol) { * - iplist[5] will be the first octet of the first ip address, * - and so on. */ -int get_socket_list_from_proto_and_family(int **ipList, int protocol, int family) { +int get_socket_list_from_proto_and_family( + int **ipList, int protocol, int family) +{ - struct socket_info *si; - struct socket_info** list; + struct socket_info *si; + struct socket_info **list; - int num_ip_octets = family == AF_INET ? NUM_IP_OCTETS : NUM_IPV6_OCTETS; + int num_ip_octets = family == AF_INET ? NUM_IP_OCTETS : NUM_IPV6_OCTETS; int numberOfSockets = 0; - int currentRow = 0; + int currentRow = 0; - /* I hate to use #ifdefs, but this is necessary because of the way +/* I hate to use #ifdefs, but this is necessary because of the way * get_sock_info_list() is defined. */ #ifndef USE_TCP - if (protocol == PROTO_TCP) - { + if(protocol == PROTO_TCP) { return 0; } #endif #ifndef USE_TLS - if (protocol == PROTO_TLS) - { + if(protocol == PROTO_TLS) { return 0; } #endif #ifndef USE_SCTP - if (protocol == PROTO_SCTP) - { + if(protocol == PROTO_SCTP) { return 0; } #endif /* We have no "interfaces" for websockets */ - if (protocol == PROTO_WS || protocol == PROTO_WSS) + if(protocol == PROTO_WS || protocol == PROTO_WSS) return 0; /* Retrieve the list of sockets with respect to the given protocol. */ - list=get_sock_info_list(protocol); + list = get_sock_info_list(protocol); /* Find out how many sockets are in the list. We need to know this so * we can malloc an array to assign to ipList. */ - for(si=list?*list:0; si; si=si->next){ - if (si->address.af == family) { + for(si = list ? *list : 0; si; si = si->next) { + if(si->address.af == family) { numberOfSockets++; } } /* There are no open sockets with respect to the given protocol. */ - if (numberOfSockets == 0) - { + if(numberOfSockets == 0) { return 0; } @@ -187,30 +186,29 @@ int get_socket_list_from_proto_and_family(int **ipList, int protocol, int family /* We couldn't allocate memory for the IP List. So all we can do is * fail. */ - if (*ipList == NULL) { + if(*ipList == NULL) { LM_ERR("no more pkg memory"); return 0; } /* We need to search the list again. So find the front of the list. */ - list=get_sock_info_list(protocol); + list = get_sock_info_list(protocol); /* Extract out the IP Addresses and ports. */ - for(si=list?*list:0; si; si=si->next){ + for(si = list ? *list : 0; si; si = si->next) { int i; /* We currently only support IPV4. */ - if (si->address.af != family) { + if(si->address.af != family) { continue; } - for (i = 0; i < num_ip_octets; i++) { - (*ipList)[currentRow*(num_ip_octets + 1) + i ] = - si->address.u.addr[i]; + for(i = 0; i < num_ip_octets; i++) { + (*ipList)[currentRow * (num_ip_octets + 1) + i] = + si->address.u.addr[i]; } - (*ipList)[currentRow*(num_ip_octets + 1) + i] = - si->port_no; + (*ipList)[currentRow * (num_ip_octets + 1) + i] = si->port_no; currentRow++; } @@ -255,25 +253,24 @@ static int parse_proc_net_line(char *line, int *ipAddress, int *rx_queue) * 6) Parse out the rx_queue. */ - for (i = 0; i < 4; i++) { + for(i = 0; i < 4; i++) { currColonLocation = strchr(currentLocationInLine, ':'); /* We didn't find all the needed ':', so fail. */ - if (currColonLocation == NULL) { + if(currColonLocation == NULL) { return 0; } /* Parse out the integer, keeping the location of the next * non-numerical character. */ parsedInteger[i] = - (int) strtol(++currColonLocation, &nextNonNumericalChar, - 16); + (int)strtol(++currColonLocation, &nextNonNumericalChar, 16); /* strtol()'s specifications specify that the second parameter * is set to the first parameter when a number couldn't be * parsed out. This means the parse was unsuccesful. */ - if (nextNonNumericalChar == currColonLocation) { + if(nextNonNumericalChar == currColonLocation) { return 0; } @@ -281,18 +278,15 @@ static int parse_proc_net_line(char *line, int *ipAddress, int *rx_queue) * character, so that next iteration of this loop, we can find * the next colon location. */ currentLocationInLine = nextNonNumericalChar; - } /* Extract out the segments of the IP Address. They are stored in * reverse network byte order. */ - for (i = 0; i < NUM_IP_OCTETS; i++) { + for(i = 0; i < NUM_IP_OCTETS; i++) { - ipAddress[i] = - parsedInteger[0] & (ipOctetExtractionMask << i*8); - - ipAddress[i] >>= i*8; + ipAddress[i] = parsedInteger[0] & (ipOctetExtractionMask << i * 8); + ipAddress[i] >>= i * 8; } ipAddress[NUM_IP_OCTETS] = parsedInteger[1]; @@ -317,18 +311,17 @@ static int match_ip_and_port(int *ipOne, int *ipArray, int sizeOf_ipArray) int ipArrayIndex; /* Loop over every IP Address */ - for (curIPAddrIdx = 0; curIPAddrIdx < sizeOf_ipArray; curIPAddrIdx++) { + for(curIPAddrIdx = 0; curIPAddrIdx < sizeOf_ipArray; curIPAddrIdx++) { /* Check for octets that don't match. If one is found, skip the * rest. */ - for (curOctetIdx = 0; curOctetIdx < NUM_IP_OCTETS + 1; curOctetIdx++) { + for(curOctetIdx = 0; curOctetIdx < NUM_IP_OCTETS + 1; curOctetIdx++) { /* We've encoded a 2D array as a 1D array. So find out * our position in the 1D array. */ - ipArrayIndex = - curIPAddrIdx * (NUM_IP_OCTETS + 1) + curOctetIdx; + ipArrayIndex = curIPAddrIdx * (NUM_IP_OCTETS + 1) + curOctetIdx; - if (ipOne[curOctetIdx] != ipArray[ipArrayIndex]) { + if(ipOne[curOctetIdx] != ipArray[ipArrayIndex]) { break; } } @@ -336,10 +329,9 @@ static int match_ip_and_port(int *ipOne, int *ipArray, int sizeOf_ipArray) /* If the index from the inner loop is equal to NUM_IP_OCTETS * + 1, then that means that every octet (and the port with the * + 1) matched. */ - if (curOctetIdx == NUM_IP_OCTETS + 1) { + if(curOctetIdx == NUM_IP_OCTETS + 1) { return 1; } - } return 0; @@ -357,17 +349,16 @@ static int match_ip_and_port(int *ipOne, int *ipArray, int sizeOf_ipArray) * Note: This only works on linux systems supporting the /proc/net/[tcp|udp] * interface. On other systems, zero will always be returned. */ -static int get_used_waiting_queue( - int forTCP, int *interfaceList, int listSize) +static int get_used_waiting_queue(int forTCP, int *interfaceList, int listSize) { FILE *fp; char *fileToOpen; char lineBuffer[MAX_PROC_BUFFER]; - int ipAddress[NUM_IP_OCTETS+1]; - int rx_queue; + int ipAddress[NUM_IP_OCTETS + 1]; + int rx_queue; - int waitingQueueSize = 0; + int waitingQueueSize = 0; #ifndef __OS_linux /* /proc/net/tcp and /proc/net/udp only exists on Linux systems, so don't bother with @@ -376,7 +367,7 @@ static int get_used_waiting_queue( #endif /* Set up the file we want to open. */ - if (forTCP) { + if(forTCP) { fileToOpen = "/proc/net/tcp"; } else { fileToOpen = "/proc/net/udp"; @@ -384,16 +375,17 @@ static int get_used_waiting_queue( fp = fopen(fileToOpen, "r"); - if (fp == NULL) { + if(fp == NULL) { LM_ERR("Could not open %s. kamailioMsgQueueDepth and its related" - " alarms will not be available.\n", fileToOpen); + " alarms will not be available.\n", + fileToOpen); return 0; } /* Read in every line of the file, parse out the ip address, port, and * rx_queue, and compare to our list of interfaces we are listening on. * Add up rx_queue for those lines which match our known interfaces. */ - while (fgets(lineBuffer, MAX_PROC_BUFFER, fp)!=NULL) { + while(fgets(lineBuffer, MAX_PROC_BUFFER, fp) != NULL) { /* Parse out the ip address, port, and rx_queue. */ if(parse_proc_net_line(lineBuffer, ipAddress, &rx_queue)) { @@ -403,7 +395,7 @@ static int get_used_waiting_queue( * check because it is possible that this system has * other network interfaces that Kamailio has been told * to ignore. */ - if (match_ip_and_port(ipAddress, interfaceList, listSize)) { + if(match_ip_and_port(ipAddress, interfaceList, listSize)) { waitingQueueSize += rx_queue; } } @@ -426,71 +418,68 @@ int get_total_bytes_waiting(void) { int bytesWaiting = 0; - int *UDPList = NULL; - int *TCPList = NULL; - int *TLSList = NULL; - int *UDP6List = NULL; - int *TCP6List = NULL; - int *TLS6List = NULL; + int *UDPList = NULL; + int *TCPList = NULL; + int *TLSList = NULL; + int *UDP6List = NULL; + int *TCP6List = NULL; + int *TLS6List = NULL; - int numUDPSockets = 0; - int numTCPSockets = 0; - int numTLSSockets = 0; - int numUDP6Sockets = 0; - int numTCP6Sockets = 0; - int numTLS6Sockets = 0; + int numUDPSockets = 0; + int numTCPSockets = 0; + int numTLSSockets = 0; + int numUDP6Sockets = 0; + int numTCP6Sockets = 0; + int numTLS6Sockets = 0; /* Extract out the IP address address for UDP, TCP, and TLS, keeping * track of the number of IP addresses from each transport */ - numUDPSockets = get_socket_list_from_proto(&UDPList, PROTO_UDP); - numTCPSockets = get_socket_list_from_proto(&TCPList, PROTO_TCP); - numTLSSockets = get_socket_list_from_proto(&TLSList, PROTO_TLS); + numUDPSockets = get_socket_list_from_proto(&UDPList, PROTO_UDP); + numTCPSockets = get_socket_list_from_proto(&TCPList, PROTO_TCP); + numTLSSockets = get_socket_list_from_proto(&TLSList, PROTO_TLS); - numUDP6Sockets = get_socket_list_from_proto_and_family(&UDP6List, PROTO_UDP, AF_INET6); - numTCP6Sockets = get_socket_list_from_proto_and_family(&TCP6List, PROTO_TCP, AF_INET6); - numTLS6Sockets = get_socket_list_from_proto_and_family(&TLS6List, PROTO_TLS, AF_INET6); + numUDP6Sockets = get_socket_list_from_proto_and_family( + &UDP6List, PROTO_UDP, AF_INET6); + numTCP6Sockets = get_socket_list_from_proto_and_family( + &TCP6List, PROTO_TCP, AF_INET6); + numTLS6Sockets = get_socket_list_from_proto_and_family( + &TLS6List, PROTO_TLS, AF_INET6); /* Deliberately not looking at PROTO_WS or PROTO_WSS here as they are just upgraded TCP/TLS connections */ /* Find out the number of bytes waiting on our interface list over all * UDP and TCP transports. */ - bytesWaiting += get_used_waiting_queue(0, UDPList, numUDPSockets); - bytesWaiting += get_used_waiting_queue(1, TCPList, numTCPSockets); - bytesWaiting += get_used_waiting_queue(1, TLSList, numTLSSockets); + bytesWaiting += get_used_waiting_queue(0, UDPList, numUDPSockets); + bytesWaiting += get_used_waiting_queue(1, TCPList, numTCPSockets); + bytesWaiting += get_used_waiting_queue(1, TLSList, numTLSSockets); - bytesWaiting += get_used_waiting_queue(0, UDP6List, numUDP6Sockets); - bytesWaiting += get_used_waiting_queue(1, TCP6List, numTCP6Sockets); - bytesWaiting += get_used_waiting_queue(1, TLS6List, numTLS6Sockets); + bytesWaiting += get_used_waiting_queue(0, UDP6List, numUDP6Sockets); + bytesWaiting += get_used_waiting_queue(1, TCP6List, numTCP6Sockets); + bytesWaiting += get_used_waiting_queue(1, TLS6List, numTLS6Sockets); /* get_socket_list_from_proto() allocated a chunk of memory, so we need * to free it. */ - if (numUDPSockets > 0) - { + if(numUDPSockets > 0) { pkg_free(UDPList); } - if (numUDP6Sockets > 0) - { + if(numUDP6Sockets > 0) { pkg_free(UDP6List); } - if (numTCPSockets > 0) - { + if(numTCPSockets > 0) { pkg_free(TCPList); } - if (numTCP6Sockets > 0) - { + if(numTCP6Sockets > 0) { pkg_free(TCP6List); } - if (numTLSSockets > 0) - { + if(numTLSSockets > 0) { pkg_free(TLSList); } - if (numTLS6Sockets > 0) - { + if(numTLS6Sockets > 0) { pkg_free(TLS6List); } return bytesWaiting; -} +} \ No newline at end of file diff --git a/src/modules/snmpstats/snmp_statistics.h b/src/modules/snmpstats/snmp_statistics.h index dab7a4f375c..3ab4c4a98dd 100644 --- a/src/modules/snmpstats/snmp_statistics.h +++ b/src/modules/snmpstats/snmp_statistics.h @@ -50,11 +50,10 @@ stat_var *get_stat_var_from_num_code(unsigned int numerical_code, int in_codes); #else - #define get_stat_var_from_num_code( _n_code, _in_code) NULL +#define get_stat_var_from_num_code(_n_code, _in_code) NULL #endif - /*! * This function will retrieve a list of all ip addresses and ports that Kamailio * is listening on, with respect to the transport protocol specified with @@ -93,7 +92,8 @@ int get_socket_list_from_proto(int **ipList, int protocol); * * For documentation see \ref get_socket_list_from_proto() */ -int get_socket_list_from_proto_and_family(int **ipList, int protocol, int family); +int get_socket_list_from_proto_and_family( + int **ipList, int protocol, int family); /*! @@ -106,4 +106,4 @@ int get_socket_list_from_proto_and_family(int **ipList, int protocol, int family */ int get_total_bytes_waiting(void); -#endif +#endif \ No newline at end of file diff --git a/src/modules/snmpstats/snmpstats.c b/src/modules/snmpstats/snmpstats.c index a3cb2d072b8..b2224ba47e5 100644 --- a/src/modules/snmpstats/snmpstats.c +++ b/src/modules/snmpstats/snmpstats.c @@ -114,12 +114,12 @@ static int snmp_export_registrar = 0; * This call must always return a value as soon as possible. If it were not to * return, then Kamailio would not be able to initialize any of the other * modules. */ -static int mod_init(void); +static int mod_init(void); /*! This function is called when Kamailio has finished creating all instances of * itself. It is at this point that we want to create our AgentX sub-agent * process, and register a handler for any state changes of our child. */ -static int mod_child_init(int rank); +static int mod_child_init(int rank); /*! This function is called when Kamailio is shutting down. When this happens, we @@ -127,8 +127,8 @@ static int mod_child_init(int rank); static void mod_destroy(void); static proc_export_t mod_procs[] = { - {"SNMP AgentX", 0, 0, agentx_child, 1 }, - {0,0,0,0,0} + {"SNMP AgentX", 0, 0, agentx_child, 1}, + {0, 0, 0, 0, 0} }; @@ -136,42 +136,39 @@ static proc_export_t mod_procs[] = { * This structure defines the SNMPStats parameters that can be configured * through the kamailio.cfg configuration file. */ -static param_export_t mod_params[] = -{ - { "sipEntityType", PARAM_STRING|USE_FUNC_PARAM, - (void *)handleSipEntityType }, - { "MsgQueueMinorThreshold", INT_PARAM|USE_FUNC_PARAM, - (void *)set_queue_minor_threshold }, - { "MsgQueueMajorThreshold", INT_PARAM|USE_FUNC_PARAM, - (void *)set_queue_major_threshold }, - { "dlg_minor_threshold", INT_PARAM|USE_FUNC_PARAM, - (void *)set_dlg_minor_threshold }, - { "dlg_major_threshold", INT_PARAM|USE_FUNC_PARAM, - (void *)set_dlg_major_threshold }, - { "snmpgetPath", PARAM_STRING|USE_FUNC_PARAM, - (void *)set_snmpget_path }, - { "snmpCommunity", PARAM_STRING|USE_FUNC_PARAM, - (void *)set_snmp_community }, - { "export_registrar", INT_PARAM, - &snmp_export_registrar }, - { 0,0,0 } +static param_export_t mod_params[] = { + {"sipEntityType", PARAM_STRING | USE_FUNC_PARAM, + (void *)handleSipEntityType}, + {"MsgQueueMinorThreshold", INT_PARAM | USE_FUNC_PARAM, + (void *)set_queue_minor_threshold}, + {"MsgQueueMajorThreshold", INT_PARAM | USE_FUNC_PARAM, + (void *)set_queue_major_threshold}, + {"dlg_minor_threshold", INT_PARAM | USE_FUNC_PARAM, + (void *)set_dlg_minor_threshold}, + {"dlg_major_threshold", INT_PARAM | USE_FUNC_PARAM, + (void *)set_dlg_major_threshold}, + {"snmpgetPath", PARAM_STRING | USE_FUNC_PARAM, + (void *)set_snmpget_path}, + {"snmpCommunity", PARAM_STRING | USE_FUNC_PARAM, + (void *)set_snmp_community}, + {"export_registrar", INT_PARAM, &snmp_export_registrar}, + {0, 0, 0} }; -struct module_exports exports = -{ - SNMPSTATS_MODULE_NAME, /* module's name */ - DEFAULT_DLFLAGS, /* dlopen flags */ - 0, /* exported functions */ - mod_params, /* param exports */ - 0, /* exported statistics */ - 0, /* MI Functions */ - 0, /* pseudo-variables */ - mod_procs, /* extra processes */ - mod_init, /* module initialization function */ - 0, /* reply processing function */ - mod_destroy, /* Destroy function */ - mod_child_init /* per-child init function */ +struct module_exports exports = { + SNMPSTATS_MODULE_NAME, /* module's name */ + DEFAULT_DLFLAGS, /* dlopen flags */ + 0, /* exported functions */ + mod_params, /* param exports */ + 0, /* exported statistics */ + 0, /* MI Functions */ + 0, /* pseudo-variables */ + mod_procs, /* extra processes */ + mod_init, /* module initialization function */ + 0, /* reply processing function */ + mod_destroy, /* Destroy function */ + mod_child_init /* per-child init function */ }; /*! @@ -191,7 +188,7 @@ static int spawn_sysUpTime_child(); /*! Storage for the "snmpgetPath" and "snmpCommunity" kamailio.cfg parameters. * The parameters are used to define what happens with the sysUpTime child. */ -char *snmpget_path = NULL; +char *snmpget_path = NULL; char *snmp_community = NULL; /*! @@ -215,22 +212,21 @@ static struct sigaction old_sigchld_handler; * messages received with the response code X. * */ -char *in_message_code_names[] = -{ +char *in_message_code_names[] = { "100_in", "180_in", "181_in", "182_in", "183_in", "199_in", - + "200_in", "202_in", "204_in", - + "300_in", "301_in", "302_in", "305_in", "380_in", - - "400_in", "401_in", "402_in", "403_in", "404_in", "405_in", "406_in", - "407_in", "408_in", "410_in", "412_in", "413_in", "414_in", "415_in", + + "400_in", "401_in", "402_in", "403_in", "404_in", "405_in", "406_in", + "407_in", "408_in", "410_in", "412_in", "413_in", "414_in", "415_in", "416_in", "417_in", "420_in", "421_in", "422_in", "423_in", "424_in", "428_in", "429_in", "430_in", "433_in", "436_in", "437_in", "438_in", "439_in", "440_in", "469_in", "470_in", "480_in", "481_in", "482_in", "483_in", "484_in", "485_in", "486_in", "487_in", "488_in", "489_in", - "491_in", "492_in", "493_in", "494_in", - + "491_in", "492_in", "493_in", "494_in", + "500_in", "501_in", "502_in", "503_in", "504_in", "505_in", "513_in", "580_in", @@ -250,24 +246,24 @@ char *in_message_code_names[] = * The array is used to register the statistics keeping track of the number of * messages send out with the response code X. */ -char *out_message_code_names[] = -{ +char *out_message_code_names[] = { "100_out", "180_out", "181_out", "182_out", "183_out", "199_out", - + "200_out", "202_out", "204_out", - + "300_out", "301_out", "302_out", "305_out", "380_out", - - "400_out", "401_out", "402_out", "403_out", "404_out", "405_out", "406_out", - "407_out", "408_out", "410_out", "412_out", "413_out", "414_out", "415_out", - "416_out", "417_out", "420_out", "421_out", "422_out", "423_out", "424_out", - "428_out", "429_out", "430_out", "433_out", "436_out", "437_out", "438_out", - "439_out", "440_out", "469_out", "470_out", "480_out", "481_out", "482_out", - "483_out", "484_out", "485_out", "486_out", "487_out", "488_out", "489_out", - "491_out", "492_out", "493_out", "494_out", - - "500_out", "501_out", "502_out", "503_out", "504_out", "505_out", "513_out", - "580_out", + + "400_out", "401_out", "402_out", "403_out", "404_out", "405_out", + "406_out", "407_out", "408_out", "410_out", "412_out", "413_out", + "414_out", "415_out", "416_out", "417_out", "420_out", "421_out", + "422_out", "423_out", "424_out", "428_out", "429_out", "430_out", + "433_out", "436_out", "437_out", "438_out", "439_out", "440_out", + "469_out", "470_out", "480_out", "481_out", "482_out", "483_out", + "484_out", "485_out", "486_out", "487_out", "488_out", "489_out", + "491_out", "492_out", "493_out", "494_out", + + "500_out", "501_out", "502_out", "503_out", "504_out", "505_out", + "513_out", "580_out", "600_out", "603_out", "604_out", "606_out" }; @@ -275,41 +271,40 @@ char *out_message_code_names[] = /*! message_code_stat_array[0] will be the data source for message_code_array[0] * message_code_stat_array[3] will be the data source for message_code_array[3] * and so on. */ -stat_var **in_message_code_stats = NULL; +stat_var **in_message_code_stats = NULL; stat_var **out_message_code_stats = NULL; /*! Adds the message code statistics to the statistics framework */ -static int register_message_code_statistics(void) +static int register_message_code_statistics(void) { int i; - int number_of_message_codes = - sizeof(in_message_code_names) / sizeof(char *); + int number_of_message_codes = + sizeof(in_message_code_names) / sizeof(char *); - in_message_code_stats = - shm_malloc(sizeof(stat_var*) * number_of_message_codes); + in_message_code_stats = + shm_malloc(sizeof(stat_var *) * number_of_message_codes); - out_message_code_stats = - shm_malloc(sizeof(stat_var*) * number_of_message_codes); + out_message_code_stats = + shm_malloc(sizeof(stat_var *) * number_of_message_codes); /* We can only proceed if we had enough memory to allocate the * statistics. Note that we don't free the memory, but we don't care * because the system is going to shut down */ - if (in_message_code_stats == NULL || - out_message_code_stats == NULL) - { + if(in_message_code_stats == NULL || out_message_code_stats == NULL) { return -1; } /* Make sure everything is zeroed out */ - memset(in_message_code_stats, 0, sizeof(stat_var*) * number_of_message_codes); - memset(out_message_code_stats, 0, sizeof(stat_var*) * number_of_message_codes); + memset(in_message_code_stats, 0, + sizeof(stat_var *) * number_of_message_codes); + memset(out_message_code_stats, 0, + sizeof(stat_var *) * number_of_message_codes); - for (i = 0; i < number_of_message_codes; i++) - { - register_stat(SNMPSTATS_MODULE_NAME, in_message_code_names[i], + for(i = 0; i < number_of_message_codes; i++) { + register_stat(SNMPSTATS_MODULE_NAME, in_message_code_names[i], &in_message_code_stats[i], 0); - register_stat(SNMPSTATS_MODULE_NAME, out_message_code_names[i], + register_stat(SNMPSTATS_MODULE_NAME, out_message_code_names[i], &out_message_code_stats[i], 0); } @@ -320,32 +315,29 @@ static int register_message_code_statistics(void) * This call must always return a value as soon as possible. If it were not to * return, then Kamailio would not be able to initialize any of the other * modules. */ -static int mod_init(void) +static int mod_init(void) { - if (register_message_code_statistics() < 0) - { + if(register_message_code_statistics() < 0) { return -1; } /* Initialize shared memory used to buffer communication between the * usrloc module and the snmpstats module. */ initInterprocessBuffers(); - + /* We need to register for callbacks with usrloc module, for whenever a * contact is added or removed from the system. We need to do it now * before Kamailio's functions get a chance to load up old user data from * the database. That load will happen if a lookup() function is come * across in kamailio.cfg. */ - if (snmp_export_registrar!=0) - { - if(!registerForUSRLOCCallbacks()) - { + if(snmp_export_registrar != 0) { + if(!registerForUSRLOCCallbacks()) { /* Originally there were descriptive error messages here to help * the operator debug problems. Turns out this may instead * alarm them about problems they don't need to worry about. So * the messages are commented out for now */ - + /* LM_ERR("snmpstats module was unable to register callbacks" " with the usrloc module\n"); @@ -374,23 +366,23 @@ static int mod_init(void) /*! This function is called when Kamailio has finished creating all instances of * itself. It is at this point that we want to create our AgentX sub-agent * process, and register a handler for any state changes of our child. */ -static int mod_child_init(int rank) +static int mod_child_init(int rank) { int pid; /* We only want to setup a single process, under the main attendant. */ - if (rank != PROC_MAIN) { + if(rank != PROC_MAIN) { return 0; } /* Spawn SNMP AgentX process */ - pid=fork_process(PROC_NOCHLDINIT, "SNMP AgentX", 1); - if (pid<0) + pid = fork_process(PROC_NOCHLDINIT, "SNMP AgentX", 1); + if(pid < 0) return -1; /* error */ - if(pid==0){ + if(pid == 0) { /* child */ /* initialize the config framework */ - if (cfg_child_init()) + if(cfg_child_init()) return -1; agentx_child(1); @@ -405,10 +397,10 @@ static int mod_child_init(int rank) /*! This function is called when Kamailio is shutting down. When this happens, we * log a useful message and kill the AgentX Sub-Agent child process */ -static void mod_destroy(void) +static void mod_destroy(void) { LM_INFO("The SNMPStats module got the kill signal\n"); - + freeInterprocessBuffer(); LM_INFO("Shutting down the AgentX Sub-Agent!\n"); @@ -429,18 +421,16 @@ static void sigchld_handler(int signal) * sysUpTime child process, and ignore it. If the SIGCHLD is * from another process, we need to call Kamailio's usual * handlers */ - pid_of_signalled_process = + pid_of_signalled_process = waitpid(-1, &pid_of_signalled_process_status, WNOHANG); - if (pid_of_signalled_process == sysUpTime_pid) - { + if(pid_of_signalled_process == sysUpTime_pid) { /* It was the sysUpTime process which died, which was expected. * At this point we will never see any SIGCHLDs from any other * SNMPStats process. This means that we can restore Kamailio's * original handlers. */ sigaction(SIGCHLD, &old_sigchld_handler, NULL); - } else - { + } else { /* We need this 'else-block' in case another Kamailio process dies * unexpectantly before the sysUpTime process dies. If this @@ -448,13 +438,11 @@ static void sigchld_handler(int signal) * the block above re-assigns Kamailio's original SIGCHLD * handler. If it does happen, then we make sure to call the * default signal handlers. */ - if (old_sigchld_handler.sa_handler != SIG_IGN && - old_sigchld_handler.sa_handler != SIG_DFL) - { + if(old_sigchld_handler.sa_handler != SIG_IGN + && old_sigchld_handler.sa_handler != SIG_DFL) { (*(old_sigchld_handler.sa_handler))(signal); } } - } /*! @@ -469,13 +457,13 @@ static void sigchld_handler(int signal) * a normal system uptime. Support for this has been provided to try to * match the IETF Draft SIP MIBs as closely as possible. */ -static int spawn_sysUpTime_child(void) +static int spawn_sysUpTime_child(void) { struct sigaction new_sigchld_handler; char *local_path_to_snmpget = "/usr/local/bin/"; - char *snmpget_binary_name = "/snmpget"; - char *full_path_to_snmpget = NULL; + char *snmpget_binary_name = "/snmpget"; + char *full_path_to_snmpget = NULL; char *snmp_community_string = "public"; @@ -483,16 +471,16 @@ static int spawn_sysUpTime_child(void) * ignoring SIGCHLDs generated by our sysUpTime child process. Every * other SIGCHLD will be redirected to the old SIGCHLD handler. */ sigfillset(&new_sigchld_handler.sa_mask); - new_sigchld_handler.sa_flags = SA_RESTART; + new_sigchld_handler.sa_flags = SA_RESTART; new_sigchld_handler.sa_handler = sigchld_handler; sigaction(SIGCHLD, &new_sigchld_handler, &old_sigchld_handler); pid_t result_pid = fork(); - if (result_pid < 0) { + if(result_pid < 0) { LM_ERR("failed to not spawn an agent to check sysUpTime\n"); return -1; - } else if (result_pid != 0) { + } else if(result_pid != 0) { /* Keep around the PID of the sysUpTime process so that the * customized SIGCHLD handler knows to ignore the SIGCHLD we @@ -500,82 +488,75 @@ static int spawn_sysUpTime_child(void) sysUpTime_pid = result_pid; return 0; - } /* If we are here, then we are the child process. Lets set up the file * descriptors so we can capture the output of snmpget. */ - int snmpget_fd = - open(SNMPGET_TEMP_FILE, O_CREAT|O_TRUNC|O_RDWR, - S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); + int snmpget_fd = open(SNMPGET_TEMP_FILE, O_CREAT | O_TRUNC | O_RDWR, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - if (snmpget_fd == -1) { + if(snmpget_fd == -1) { LM_ERR("failed to open a temporary file " - "for snmpget to write to\n"); + "for snmpget to write to\n"); return -1; } /* Redirect Standard Output to our temporary file. */ - dup2(snmpget_fd, 1); + dup2(snmpget_fd, 1); - if (snmp_community != NULL) { + if(snmp_community != NULL) { snmp_community_string = snmp_community; } else { LM_INFO("An snmpCommunity parameter was not provided." - " Defaulting to %s\n", snmp_community_string); + " Defaulting to %s\n", + snmp_community_string); } - char *args[] = {"-Ov", "-c", snmp_community_string, "localhost", - SYSUPTIME_OID, (char *) 0}; + char *args[] = {"-Ov", "-c", snmp_community_string, "localhost", + SYSUPTIME_OID, (char *)0}; /* Make sure we have a path to snmpget, so we can retrieve the * sysUpTime. */ - if (snmpget_path == NULL) - { + if(snmpget_path == NULL) { LM_INFO("An snmpgetPath parameter was not specified." - " Defaulting to %s\n", local_path_to_snmpget); - } - else - { + " Defaulting to %s\n", + local_path_to_snmpget); + } else { local_path_to_snmpget = snmpget_path; } int local_path_to_snmpget_length = strlen(local_path_to_snmpget); - int snmpget_binary_name_length = strlen(snmpget_binary_name); - + int snmpget_binary_name_length = strlen(snmpget_binary_name); + /* Allocate enough memory to hold the path, the binary name, and the * null character. We don't use pkg_memory here. */ - full_path_to_snmpget = - malloc(sizeof(char) * - (local_path_to_snmpget_length + - snmpget_binary_name_length + 1)); + full_path_to_snmpget = malloc( + sizeof(char) + * (local_path_to_snmpget_length + snmpget_binary_name_length + 1)); - if (full_path_to_snmpget == NULL) - { + if(full_path_to_snmpget == NULL) { LM_ERR("Ran out of memory while trying to retrieve sysUpTime. "); - LM_ERR( " kamailioSIPServiceStartTime is " - "defaulting to zero\n"); + LM_ERR(" kamailioSIPServiceStartTime is " + "defaulting to zero\n"); return -1; - } - else - { + } else { /* Make a new string containing the full path to the binary. */ strcpy(full_path_to_snmpget, local_path_to_snmpget); - strcpy(&full_path_to_snmpget[local_path_to_snmpget_length], + strcpy(&full_path_to_snmpget[local_path_to_snmpget_length], snmpget_binary_name); } /* snmpget -Ov -c public localhost .1.3.6.1.2.1.1.3.0 */ - if (execve(full_path_to_snmpget, args, NULL) == -1) { - LM_ERR( "snmpget failed to run. Did you supply the snmpstats module" - " with a proper snmpgetPath parameter? The " - "kamailioSIPServiceStartTime is defaulting to zero\n"); + if(execve(full_path_to_snmpget, args, NULL) == -1) { + LM_ERR("snmpget failed to run. Did you supply the snmpstats module" + " with a proper snmpgetPath parameter? The " + "kamailioSIPServiceStartTime is defaulting to zero\n"); close(snmpget_fd); free(full_path_to_snmpget); exit(-1); } - + /* We should never be able to get here, because execve() is never * supposed to return. */ free(full_path_to_snmpget); @@ -585,9 +566,9 @@ static int spawn_sysUpTime_child(void) /*! This function is called whenever the kamailio.cfg file specifies the * snmpgetPath parameter. The function will set the snmpget_path parameter. */ -int set_snmpget_path( modparam_t type, void *val) +int set_snmpget_path(modparam_t type, void *val) { - if (!stringHandlerSanityCheck(type, val, "snmpgetPath" )) { + if(!stringHandlerSanityCheck(type, val, "snmpgetPath")) { return -1; } @@ -597,13 +578,13 @@ int set_snmpget_path( modparam_t type, void *val) } /* Handles setting of the snmp community string. */ -int set_snmp_community( modparam_t type, void *val) +int set_snmp_community(modparam_t type, void *val) { - if (!stringHandlerSanityCheck(type, val, "snmpCommunity")) { + if(!stringHandlerSanityCheck(type, val, "snmpCommunity")) { return -1; } snmp_community = (char *)val; return 0; -} +} \ No newline at end of file diff --git a/src/modules/snmpstats/snmpstats.h b/src/modules/snmpstats/snmpstats.h index ff9fbb25dd8..dfd79017f1a 100644 --- a/src/modules/snmpstats/snmpstats.h +++ b/src/modules/snmpstats/snmpstats.h @@ -60,7 +60,6 @@ #define _SNMP_STATS_ #define SNMPSTATS_MODULE_NAME "snmpstats" -#define SYSUPTIME_OID ".1.3.6.1.2.1.1.3.0" +#define SYSUPTIME_OID ".1.3.6.1.2.1.1.3.0" - -#endif +#endif \ No newline at end of file diff --git a/src/modules/snmpstats/snmpstats_globals.h b/src/modules/snmpstats/snmpstats_globals.h index bad47bd25c0..f40e65d42b8 100644 --- a/src/modules/snmpstats/snmpstats_globals.h +++ b/src/modules/snmpstats/snmpstats_globals.h @@ -35,7 +35,7 @@ #include "../../core/sr_module.h" -#define KAMAILIO_OID 1,3,6,1,4,1,34352 +#define KAMAILIO_OID 1, 3, 6, 1, 4, 1, 34352 /*************************************************************** * Textual Conventions for BITS types - begins @@ -53,81 +53,80 @@ * * currentAlarmStatus &= ~TC_ALARM_STATUS_MINOR */ -#define TC_SIP_TRANSPORT_PROTOCOL_OTHER (128>>0) -#define TC_SIP_TRANSPORT_PROTOCOL_UDP (128>>1) -#define TC_SIP_TRANSPORT_PROTOCOL_TCP (128>>2) -#define TC_SIP_TRANSPORT_PROTOCOL_SCTP (128>>3) -#define TC_SIP_TRANSPORT_PROTOCOL_TLS (128>>4) -#define TC_SIP_TRANSPORT_PROTOCOL_SCTP_TLS (128>>5) -#define TC_SIP_TRANSPORT_PROTOCOL_WS (128 >> 6) -#define TC_SIP_TRANSPORT_PROTOCOL_WSS (128 >> 7) - -#define TC_SIP_ENTITY_ROLE_OTHER (128 >> 0) -#define TC_SIP_ENTITY_ROLE_USER_AGENT (128 >> 1) -#define TC_SIP_ENTITY_ROLE_PROXY_SERVER (128 >> 2) -#define TC_SIP_ENTITY_ROLE_REDIRECT_SERVER (128 >> 3) +#define TC_SIP_TRANSPORT_PROTOCOL_OTHER (128 >> 0) +#define TC_SIP_TRANSPORT_PROTOCOL_UDP (128 >> 1) +#define TC_SIP_TRANSPORT_PROTOCOL_TCP (128 >> 2) +#define TC_SIP_TRANSPORT_PROTOCOL_SCTP (128 >> 3) +#define TC_SIP_TRANSPORT_PROTOCOL_TLS (128 >> 4) +#define TC_SIP_TRANSPORT_PROTOCOL_SCTP_TLS (128 >> 5) +#define TC_SIP_TRANSPORT_PROTOCOL_WS (128 >> 6) +#define TC_SIP_TRANSPORT_PROTOCOL_WSS (128 >> 7) + +#define TC_SIP_ENTITY_ROLE_OTHER (128 >> 0) +#define TC_SIP_ENTITY_ROLE_USER_AGENT (128 >> 1) +#define TC_SIP_ENTITY_ROLE_PROXY_SERVER (128 >> 2) +#define TC_SIP_ENTITY_ROLE_REDIRECT_SERVER (128 >> 3) #define TC_SIP_ENTITY_ROLE_REGISTRAR_SERVER (128 >> 4) #define TC_SIP_ENTITY_ROLE_EDGEPROXY_SERVER (128 >> 5) #define TC_SIP_ENTITY_ROLE_SIPCAPTURE_SERVER (128 >> 6) -#define TC_SIP_OPTION_TAG_REQUIRE (128 >> 0) +#define TC_SIP_OPTION_TAG_REQUIRE (128 >> 0) #define TC_SIP_OPTION_TAG_PROXY_REQUIRE (128 >> 1) -#define TC_SIP_OPTION_TAG_SUPPORTED (128 >> 2) -#define TC_SIP_OPTION_TAG_UNSUPPORTED (128 >> 3) +#define TC_SIP_OPTION_TAG_SUPPORTED (128 >> 2) +#define TC_SIP_OPTION_TAG_UNSUPPORTED (128 >> 3) -#define TC_ALARM_STATUS_UNDER_REPAIR (128 >> 0) -#define TC_ALARM_STATUS_CRITICAL (128 >> 1) -#define TC_ALARM_STATUS_MAJOR (128 >> 2) -#define TC_ALARM_STATUS_MINOR (128 >> 3) +#define TC_ALARM_STATUS_UNDER_REPAIR (128 >> 0) +#define TC_ALARM_STATUS_CRITICAL (128 >> 1) +#define TC_ALARM_STATUS_MAJOR (128 >> 2) +#define TC_ALARM_STATUS_MINOR (128 >> 3) #define TC_ALARM_STATUS_ALARM_OUTSTANDING (128 >> 4) -#define TC_ALARM_STATUS_UNKNOWN (128 >> 5) +#define TC_ALARM_STATUS_UNKNOWN (128 >> 5) #define TC_TRANSPORT_PROTOCOL_OTHER (128 >> 0) -#define TC_TRANSPORT_PROTOCOL_UDP (128 >> 1) -#define TC_TRANSPORT_PROTOCOL_TCP (128 >> 2) -#define TC_TRANSPORT_PROTOCOL_SCTP (128 >> 3) -#define TC_TRANSPORT_PROTOCOL_TLS (128 >> 4) -#define TC_TRANSPORT_PROTOCOL_SCRTP_TLS (128 >> 5) -#define TC_TRANSPORT_PROTOCOL_WS (128 >> 6) -#define TC_TRANSPORT_PROTOCOL_WSS (128 >> 7) +#define TC_TRANSPORT_PROTOCOL_UDP (128 >> 1) +#define TC_TRANSPORT_PROTOCOL_TCP (128 >> 2) +#define TC_TRANSPORT_PROTOCOL_SCTP (128 >> 3) +#define TC_TRANSPORT_PROTOCOL_TLS (128 >> 4) +#define TC_TRANSPORT_PROTOCOL_SCRTP_TLS (128 >> 5) +#define TC_TRANSPORT_PROTOCOL_WS (128 >> 6) +#define TC_TRANSPORT_PROTOCOL_WSS (128 >> 7) /* * Textual Conventions for BITS types - ends *************************************************************/ - /*************************************************************** * Textual Conventions for INTEGER types - begins */ -#define TC_ALARM_STATE_CLEAR 0 +#define TC_ALARM_STATE_CLEAR 0 #define TC_ALARM_STATE_CRITICAL 1 -#define TC_ALARM_STATE_MAJOR 2 -#define TC_ALARM_STATE_MINOR 3 -#define TC_ALARM_STATE_UNKNOWN 4 +#define TC_ALARM_STATE_MAJOR 2 +#define TC_ALARM_STATE_MINOR 3 +#define TC_ALARM_STATE_UNKNOWN 4 -#define TC_USAGE_STATE_IDLE 0 -#define TC_USAGE_STATE_ACTIVE 1 -#define TC_USAGE_STATE_BUSY 2 +#define TC_USAGE_STATE_IDLE 0 +#define TC_USAGE_STATE_ACTIVE 1 +#define TC_USAGE_STATE_BUSY 2 #define TC_USAGE_STATE_UNKNOWN 3 -#define TC_ROWSTATUS_ACTIVE 1 -#define TC_ROWSTATUS_NOTINSERVICE 2 -#define TC_ROWSTATUS_NOTREADY 3 -#define TC_ROWSTATUS_CREATEANDGO 4 -#define TC_ROWSTATUS_CREATEANDWAIT 5 -#define TC_ROWSTATUS_DESTROY 6 +#define TC_ROWSTATUS_ACTIVE 1 +#define TC_ROWSTATUS_NOTINSERVICE 2 +#define TC_ROWSTATUS_NOTREADY 3 +#define TC_ROWSTATUS_CREATEANDGO 4 +#define TC_ROWSTATUS_CREATEANDWAIT 5 +#define TC_ROWSTATUS_DESTROY 6 /* * Textual Conventions for INTEGER types - ends *************************************************************/ -#define TC_TRUE 1 +#define TC_TRUE 1 #define TC_FALSE 2 #define SNMPGET_TEMP_FILE "/tmp/kamailio_SNMPAgent.txt" #define SNMPGET_MAX_BUFFER 80 -#define MAX_PROC_BUFFER 256 +#define MAX_PROC_BUFFER 256 #define MAX_USER_LOOKUP_COUNTER 255 @@ -140,7 +139,7 @@ extern unsigned int global_UserLookupCounter; */ /*! Handles setting of the sip entity type parameter. */ -int handleSipEntityType( modparam_t type, void* val); +int handleSipEntityType(modparam_t type, void *val); /*! Handles setting of the Msg Queue Depth Minor Threshold */ int set_queue_minor_threshold(modparam_t type, void *val); @@ -155,10 +154,9 @@ int set_dlg_minor_threshold(modparam_t type, void *val); int set_dlg_major_threshold(modparam_t type, void *val); /*! Handles setting of the path to the snmpget binary. */ -int set_snmpget_path( modparam_t type, void *val); +int set_snmpget_path(modparam_t type, void *val); /*! Handles setting of the snmp community string. */ -int set_snmp_community( modparam_t type, void *val); - +int set_snmp_community(modparam_t type, void *val); -#endif +#endif \ No newline at end of file diff --git a/src/modules/snmpstats/sub_agent.c b/src/modules/snmpstats/sub_agent.c index 1857ee790cc..fc938d0f2cd 100644 --- a/src/modules/snmpstats/sub_agent.c +++ b/src/modules/snmpstats/sub_agent.c @@ -69,7 +69,7 @@ static int keep_running; /*! The function handles Handles shutting down of the sub_agent process. */ -static void sigterm_handler(int signal) +static void sigterm_handler(int signal) { /* Just exit. The master agent will clean everything up for us */ exit(0); @@ -86,13 +86,13 @@ static void sigterm_handler(int signal) * \note This function never returns, so it should always be called from a * sub-process. */ -static int initialize_agentx(void) +static int initialize_agentx(void) { /* We register with a master agent */ register_with_master_agent(AGENT_PROCESS_NAME); LM_DBG("Initializing Kamailio OID's for SNMPD MasterX\n"); - + /* Initialize all scalars, and let the master agent know we want to * handle all OID's pertaining to these scalars. */ init_kamailioSIPCommonObjects(); @@ -125,7 +125,7 @@ static int initialize_agentx(void) LM_DBG("Shutting down Kamailio SNMPD MasterX sub agent.\n"); snmp_shutdown(AGENT_PROCESS_NAME); SOCK_CLEANUP; - exit (0); + exit(0); return 0; } @@ -141,7 +141,7 @@ void agentx_child(int rank) /* Setup a SIGTERM handler */ sigfillset(&new_sigterm_handler.sa_mask); - new_sigterm_handler.sa_flags = 0; + new_sigterm_handler.sa_flags = 0; new_sigterm_handler.sa_handler = sigterm_handler; sigaction(SIGTERM, &new_sigterm_handler, NULL); @@ -153,8 +153,8 @@ void agentx_child(int rank) default_handlers.sa_handler = SIG_DFL; sigaction(SIGCHLD, &default_handlers, NULL); - sigaction(SIGINT, &default_handlers, NULL); - sigaction(SIGHUP, &default_handlers, NULL); + sigaction(SIGINT, &default_handlers, NULL); + sigaction(SIGHUP, &default_handlers, NULL); sigaction(SIGUSR1, &default_handlers, NULL); sigaction(SIGUSR2, &default_handlers, NULL); @@ -176,10 +176,9 @@ void agentx_child(int rank) } - /*! This function opens up a connection with the master agent specified in * the snmpstats modules configuration file */ -void register_with_master_agent(char *name_to_register_under) +void register_with_master_agent(char *name_to_register_under) { /* Set ourselves up as an AgentX Client. */ netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1); @@ -195,4 +194,4 @@ void register_with_master_agent(char *name_to_register_under) /* Use a name we can register our agent under. */ init_snmp(name_to_register_under); LM_DBG("** Connected to SNMPD MasterX\n"); -} +} \ No newline at end of file diff --git a/src/modules/snmpstats/sub_agent.h b/src/modules/snmpstats/sub_agent.h index f93ac444945..7f1c3318783 100644 --- a/src/modules/snmpstats/sub_agent.h +++ b/src/modules/snmpstats/sub_agent.h @@ -35,7 +35,7 @@ #ifndef _SNMPSTATS_SUB_AGENT_ #define _SNMPSTATS_SUB_AGENT_ -#define AGENT_PROCESS_NAME "snmpstats_sub_agent" +#define AGENT_PROCESS_NAME "snmpstats_sub_agent" /*! Run the AgentX sub-agent as a separate process. The child will * insulate itself from the rest of Kamailio by overriding most of signal @@ -46,4 +46,4 @@ void agentx_child(int rank); * the snmpstats modules configuration file */ void register_with_master_agent(char *name_to_register_under); -#endif +#endif \ No newline at end of file diff --git a/src/modules/snmpstats/utilities.c b/src/modules/snmpstats/utilities.c index afbca544d83..e5ebfc64b65 100644 --- a/src/modules/snmpstats/utilities.c +++ b/src/modules/snmpstats/utilities.c @@ -46,7 +46,7 @@ #include "../../core/counters.h" -static cfg_ctx_t *ctx = NULL; +static cfg_ctx_t *ctx = NULL; /*! * This function copies an Kamailio "str" datatype into a '\\0' terminated char* @@ -61,8 +61,7 @@ int convertStrToCharString(str *strToConvert, char **copiedString) /* We want enough space for the string, plus 1 for the '\0' character. */ *copiedString = shm_malloc(sizeof(char) * (strToConvert->len + 1)); - if (*copiedString == NULL) - { + if(*copiedString == NULL) { return 0; } @@ -75,19 +74,19 @@ int convertStrToCharString(str *strToConvert, char **copiedString) /*! Silently returns 1 if the supplied parameters are sane. Otherwise, an error * message is logged for parameterName, and 0 returned. */ -int stringHandlerSanityCheck( modparam_t type, void *val, char *parameterName) +int stringHandlerSanityCheck(modparam_t type, void *val, char *parameterName) { char *theString = (char *)val; /* Make sure the function was called correctly. */ - if (PARAM_TYPE_MASK(type) != PARAM_STRING) { + if(PARAM_TYPE_MASK(type) != PARAM_STRING) { LM_ERR("the %s parameter was assigned a type %d instead of %d\n", parameterName, type, PARAM_STRING); return 0; } /* An empty string was supplied. We consider this illegal */ - if (theString==0 || (theString[0])==0) { + if(theString == 0 || (theString[0]) == 0) { LM_ERR("the %s parameter was specified with an empty string\n", parameterName); return 0; @@ -97,7 +96,6 @@ int stringHandlerSanityCheck( modparam_t type, void *val, char *parameterName) } - /*! * This function is a wrapper around the standard statistic framework. It will * return the value of the statistic denoted with statName, or zero if the @@ -109,12 +107,12 @@ int get_statistic(char *statName) str theStr; - theStr.s = statName; + theStr.s = statName; theStr.len = strlen(statName); stat_var *theVar = get_stat(&theStr); - if (theVar==0) { + if(theVar == 0) { LM_INFO("failed to retrieve statistics for %s\n", statName); } else { result = get_stat_val(theVar); @@ -126,7 +124,7 @@ int get_statistic(char *statName) /*! Returns a pointer to an SNMP DateAndTime OCTET STRING representation of the * time structure. Note that the pointer is to static data, so it shouldn't be * counted on to be around if this function is called again. */ -char * convertTMToSNMPDateAndTime(struct tm *timeStructure) +char *convertTMToSNMPDateAndTime(struct tm *timeStructure) { static char dateAndTime[8]; @@ -135,13 +133,13 @@ char * convertTMToSNMPDateAndTime(struct tm *timeStructure) int currentYear = timeStructure->tm_year + 1900; /* See SNMPv2-TC for the conversion details */ - dateAndTime[0] = (char) ((currentYear & 0xFF00) >> 8); - dateAndTime[1] = (char) currentYear & 0xFF; - dateAndTime[2] = (char) timeStructure->tm_mon + 1; - dateAndTime[3] = (char) timeStructure->tm_mday; - dateAndTime[4] = (char) timeStructure->tm_hour; - dateAndTime[5] = (char) timeStructure->tm_min; - dateAndTime[6] = (char) timeStructure->tm_sec; + dateAndTime[0] = (char)((currentYear & 0xFF00) >> 8); + dateAndTime[1] = (char)currentYear & 0xFF; + dateAndTime[2] = (char)timeStructure->tm_mon + 1; + dateAndTime[3] = (char)timeStructure->tm_mday; + dateAndTime[4] = (char)timeStructure->tm_hour; + dateAndTime[5] = (char)timeStructure->tm_min; + dateAndTime[6] = (char)timeStructure->tm_sec; dateAndTime[7] = 0; return dateAndTime; @@ -150,7 +148,7 @@ char * convertTMToSNMPDateAndTime(struct tm *timeStructure) /* module initialization function */ int config_context_init(void) { - if (cfg_register_ctx(&ctx, NULL)) { + if(cfg_register_ctx(&ctx, NULL)) { LM_ERR("failed to register cfg context\n"); return -1; } @@ -164,8 +162,8 @@ int config_context_init(void) */ int snmp_cfg_get_int(char *arg_group, char *arg_name, unsigned int *type) { - void *val; - unsigned int val_type; + void *val; + unsigned int val_type; int res; str group, name; @@ -178,15 +176,15 @@ int snmp_cfg_get_int(char *arg_group, char *arg_name, unsigned int *type) *type = CFG_VAR_UNSET; res = cfg_get_by_name(ctx, &group, NULL, &name, &val, &val_type); - if (res < 0) { + if(res < 0) { LM_ERR("failed to get the variable\n"); return -1; - } else if (res > 0) { + } else if(res > 0) { LM_ERR("fariable exists, but it is not readable via RPC interface\n"); return -1; } - LM_DBG("xonfig framework variable %s:%s retrieved %d\n", - arg_group, arg_name, (int)(long) val); + LM_DBG("xonfig framework variable %s:%s retrieved %d\n", arg_group, + arg_name, (int)(long)val); *type = val_type; - return (int) (long) val; -} + return (int)(long)val; +} \ No newline at end of file diff --git a/src/modules/snmpstats/utilities.h b/src/modules/snmpstats/utilities.h index 0642b3ec0bc..176e9f63e9a 100644 --- a/src/modules/snmpstats/utilities.h +++ b/src/modules/snmpstats/utilities.h @@ -53,7 +53,7 @@ int convertStrToCharString(str *strToConvert, char **copiedString); /*! Performs sanity checks on the parameters passed to a string configuration * file parameter handler. */ -int stringHandlerSanityCheck( modparam_t type, void *val, char *parameterName); +int stringHandlerSanityCheck(modparam_t type, void *val, char *parameterName); /*! * This function is a wrapper around the standard statistic framework. It will @@ -65,7 +65,7 @@ int get_statistic(char *statName); /*! Returns a pointer to an SNMP DateAndTime OCTET STRING representation of the * time structure. Note that the pointer is to static data, so it shouldn't be * counted on to be around if this function is called again. */ -char * convertTMToSNMPDateAndTime(struct tm *timeStructure); +char *convertTMToSNMPDateAndTime(struct tm *timeStructure); /*! \brief Get config framework variable * type will return cfg_type - CFG_VAR_INT, CFG_VAR_STRING, CFG_VAR_STR @@ -76,5 +76,4 @@ int snmp_cfg_get_int(char *arg_group, char *arg_name, unsigned int *type); /*! Initialize config framework */ int config_context_init(void); - -#endif +#endif \ No newline at end of file