Module: sip-router Branch: master Commit: dbde9b609c2a3538fca1e7db72e518f97b3f018a URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=dbde9b60...
Author: Olle E. Johansson oej@edvina.net Committer: Olle E. Johansson oej@edvina.net Date: Sat Apr 6 22:06:47 2013 +0200
snmpstats Add IPv6 support in list of active interfaces
Output from SNMPwalk after this patch: KAMAILIO-SIP-COMMON-MIB::kamailioSIPTransportRcv.ipv6."20:01:DB:80:21:2e:00:00:00:00:00:00:00:00:00:22".5080 = BITS: 40 udp(1)
---
modules/snmpstats/snmpSIPPortTable.c | 87 ++++++++++++++++++++-------------- modules/snmpstats/snmpSIPPortTable.h | 11 ++-- 2 files changed, 57 insertions(+), 41 deletions(-)
diff --git a/modules/snmpstats/snmpSIPPortTable.c b/modules/snmpstats/snmpSIPPortTable.c index 5d57c2e..04a2b80 100644 --- a/modules/snmpstats/snmpSIPPortTable.c +++ b/modules/snmpstats/snmpSIPPortTable.c @@ -28,7 +28,7 @@ * History: * -------- * 2006-11-23 initial version (jmagder) - * 2013-02-24 Added WS, WSS and SCTP support (oej) + * 2013-02-24 Added SCTP support (oej) * * Originally Generated with mib2c using mib2c.array-user.conf * @@ -65,18 +65,21 @@ 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. */ -oid *createIndex(int ipType, int *ipAddress, int *sizeOfOID) +static oid *createIndex(int ipType, int *ipAddress, int *sizeOfOID) { oid *currentOIDIndex; int i; + int family = ipType == 1 ? AF_INET : AF_INET6; + int num_octets = family == AF_INET ? NUM_IP_OCTETS : NUM_IPV6_OCTETS;
/* The size needs to be large enough such that it can store the ipType * (one octet), the prefixed length (one octet), the number of * octets to the IP Address (NUM_IP_OCTETS), and the port. */ - *sizeOfOID = NUM_IP_OCTETS + 3; + *sizeOfOID = num_octets + 3;
/* Allocate space for the OID Index. */ currentOIDIndex = pkg_malloc((*sizeOfOID) * sizeof(oid)); + LM_DBG("----> Size of OID %d \n", *sizeOfOID);
if (currentOIDIndex == NULL) { LM_ERR("failed to create a row for kamailioSIPPortTable\n"); @@ -86,14 +89,15 @@ oid *createIndex(int ipType, int *ipAddress, int *sizeOfOID)
/* Assign the OID Index */ currentOIDIndex[0] = ipType; - currentOIDIndex[1] = NUM_IP_OCTETS; + currentOIDIndex[1] = num_octets; - for (i = 0; i < NUM_IP_OCTETS; i++) { + for (i = 0; i < num_octets; i++) { currentOIDIndex[i+2] = ipAddress[i]; }
/* Extract out the port number */ - currentOIDIndex[NUM_IP_OCTETS+2] = ipAddress[NUM_IP_OCTETS]; + currentOIDIndex[num_octets + 2] = ipAddress[num_octets]; + LM_DBG("----> Port number %d Family %s \n", ipAddress[num_octets], ipType == 1 ? "IPv4" : "IPv6");
return currentOIDIndex; } @@ -105,23 +109,22 @@ oid *createIndex(int ipType, int *ipAddress, int *sizeOfOID) * * Note: NULL will be returned on an error */ -kamailioSIPPortTable_context *getRow(int ipType, int *ipAddress) +kamailioSIPPortTable_context *getRow(int ipType, int *ipAddress) { int lengthOfOID; oid *currentOIDIndex = createIndex(ipType, ipAddress, &lengthOfOID); + netsnmp_index theIndex; + kamailioSIPPortTable_context *rowToReturn; + int num_octets = ipType == 1 ? NUM_IP_OCTETS : NUM_IPV6_OCTETS;
if (currentOIDIndex == NULL) { return NULL; }
- netsnmp_index theIndex; - theIndex.oids = currentOIDIndex; theIndex.len = lengthOfOID;
- kamailioSIPPortTable_context *rowToReturn; - /* Lets check to see if there is an existing row. */ rowToReturn = CONTAINER_FIND(cb.container, &theIndex); @@ -149,8 +152,8 @@ kamailioSIPPortTable_context *getRow(int ipType, int *ipAddress) rowToReturn->index.len = lengthOfOID; rowToReturn->index.oids = currentOIDIndex;
- memcpy(rowToReturn->kamailioSIPStringIndex, currentOIDIndex, NUM_IP_OCTETS + 3); - rowToReturn->kamailioSIPStringIndex_len = NUM_IP_OCTETS + 3; + memcpy(rowToReturn->kamailioSIPStringIndex, currentOIDIndex, num_octets + 3); + rowToReturn->kamailioSIPStringIndex_len = num_octets + 3;
/* Insert the new row into the table */ CONTAINER_INSERT(cb.container, rowToReturn); @@ -167,7 +170,7 @@ kamailioSIPPortTable_context *getRow(int ipType, int *ipAddress) * 'protocol', we can continue from the last index. */ void createRowsFromIPList(int *theList, int listSize, int protocol, - int *snmpIndex) { + int *snmpIndex, int family) {
kamailioSIPPortTable_context *currentRow; @@ -210,8 +213,10 @@ void createRowsFromIPList(int *theList, int listSize, int protocol, curIndexOfIP = (NUM_IP_OCTETS + 1) * curSocketIdx; /* Retrieve an existing row, or a new row if one doesn't - * allready exist. */ - currentRow = getRow(1, &theList[curIndexOfIP]); + * already exist. + * RFC 4001 defined IPv4 as 1, IPv6 as 2 + */ + currentRow = getRow(family == AF_INET? 1 : 2, &theList[curIndexOfIP]);
if (currentRow == NULL) { LM_ERR("failed to create all the " @@ -240,43 +245,55 @@ void init_kamailioSIPPortTable(void) int *UDPList = NULL; int *TCPList = NULL; int *TLSList = NULL; - int *WSList = NULL; - int *WSSList = NULL; int *SCTPList = NULL;
+ int *UDP6List = NULL; + int *TCP6List = NULL; + int *TLS6List = NULL; + int *SCTP6List = NULL; + int numUDPSockets; int numTCPSockets; int numTLSSockets; - int numWSSockets; - int numWSSSockets; int numSCTPSockets; + + int numUDP6Sockets; + int numTCP6Sockets; + int numTLS6Sockets; + int numSCTP6Sockets; /* Retrieve the list of the number of UDP and TCP sockets. */ - 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); - numWSSockets = get_socket_list_from_proto(&WSList, PROTO_WS); - numWSSSockets = get_socket_list_from_proto(&WSSList, PROTO_WSS); - numSCTPSockets = get_socket_list_from_proto(&SCTPList, PROTO_SCTP); + numUDPSockets = get_socket_list_from_proto_and_family(&UDPList, PROTO_UDP, AF_INET); + numUDP6Sockets = get_socket_list_from_proto_and_family(&UDP6List, PROTO_UDP, AF_INET6); + numTCPSockets = get_socket_list_from_proto_and_family(&TCPList, PROTO_TCP, AF_INET); + numTCP6Sockets = get_socket_list_from_proto_and_family(&TCP6List, PROTO_TCP, AF_INET6); + numTLSSockets = get_socket_list_from_proto_and_family(&TLSList, PROTO_TLS, AF_INET); + numTLS6Sockets = get_socket_list_from_proto_and_family(&TLS6List, PROTO_TLS, AF_INET6); + numSCTPSockets = get_socket_list_from_proto_and_family(&SCTPList, PROTO_SCTP, AF_INET); + numSCTP6Sockets = get_socket_list_from_proto_and_family(&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(UDPList, numUDPSockets, PROTO_UDP, &curSNMPIndex); - + createRowsFromIPList(UDPList, numUDPSockets, PROTO_UDP, &curSNMPIndex, AF_INET); curSNMPIndex = 0; - - createRowsFromIPList(TCPList, numTCPSockets, PROTO_TCP, &curSNMPIndex); + createRowsFromIPList(UDP6List, numUDP6Sockets, PROTO_UDP, &curSNMPIndex, AF_INET6);
curSNMPIndex = 0; - createRowsFromIPList(TLSList, numTLSSockets, PROTO_TLS, &curSNMPIndex); - + createRowsFromIPList(TCPList, numTCPSockets, PROTO_TCP, &curSNMPIndex, AF_INET); curSNMPIndex = 0; - createRowsFromIPList(WSList, numWSSockets, PROTO_WS, &curSNMPIndex); + createRowsFromIPList(TCP6List, numTCP6Sockets, PROTO_TCP, &curSNMPIndex, AF_INET6);
curSNMPIndex = 0; - createRowsFromIPList(WSSList, numWSSSockets, PROTO_WSS, &curSNMPIndex); + createRowsFromIPList(TLSList, numTLSSockets, PROTO_TLS, &curSNMPIndex, AF_INET); + curSNMPIndex = 0; + createRowsFromIPList(TLS6List, numTLS6Sockets, PROTO_TLS, &curSNMPIndex, AF_INET6);
curSNMPIndex = 0; - createRowsFromIPList(SCTPList, numSCTPSockets, PROTO_SCTP, &curSNMPIndex); + createRowsFromIPList(SCTPList, numSCTPSockets, PROTO_SCTP, &curSNMPIndex, AF_INET); + curSNMPIndex = 0; + createRowsFromIPList(SCTP6List, numSCTP6Sockets, PROTO_SCTP, &curSNMPIndex, AF_INET6); }
diff --git a/modules/snmpstats/snmpSIPPortTable.h b/modules/snmpstats/snmpSIPPortTable.h index 8165b3e..4032672 100644 --- a/modules/snmpstats/snmpSIPPortTable.h +++ b/modules/snmpstats/snmpSIPPortTable.h @@ -47,7 +47,8 @@ extern "C" {
#include "../../config.h"
-#define SIP_PORT_TABLE_STR_INDEX_SIZE 10 +// OLD #define SIP_PORT_TABLE_STR_INDEX_SIZE 10 +#define SIP_PORT_TABLE_STR_INDEX_SIZE 50
/* This strucutre represents a single row in the table. */ typedef struct kamailioSIPPortTable_context_s @@ -87,11 +88,9 @@ void initialize_table_kamailioSIPPortTable(void); 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 @@ -108,7 +107,7 @@ extern size_t kamailioSIPPortTable_oid_len; #define COLUMN_KAMAILIOSIPTRANSPORTRCV 4
#define kamailioSIPPortTable_COL_MIN 4 -#define kamailioSIPPortTable_COL_MAX 4 +#define kamailioSIPPortTable_COL_MAX 12
#ifdef __cplusplus