00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <net-snmp/net-snmp-config.h>
00038 #include <net-snmp/net-snmp-includes.h>
00039 #include <net-snmp/agent/net-snmp-agent-includes.h>
00040 #include <net-snmp/library/snmp_assert.h>
00041
00042 #include "../../statistics.h"
00043 #include "../../mem/mem.h"
00044
00045 #include "snmpstats_globals.h"
00046 #include "openserSIPPortTable.h"
00047
00048 static netsnmp_handler_registration *my_handler = NULL;
00049 static netsnmp_table_array_callbacks cb;
00050
00051 oid openserSIPPortTable_oid[] = { openserSIPPortTable_TABLE_OID };
00052 size_t openserSIPPortTable_oid_len = OID_LENGTH(openserSIPPortTable_oid);
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 oid *createIndex(int ipType, int *ipAddress, int *sizeOfOID)
00065 {
00066 oid *currentOIDIndex;
00067 int i;
00068
00069
00070
00071
00072 *sizeOfOID = NUM_IP_OCTETS + 3;
00073
00074
00075 currentOIDIndex = pkg_malloc((*sizeOfOID) * sizeof(oid));
00076
00077 if (currentOIDIndex == NULL) {
00078 LM_ERR("failed to create a row for openserSIPPortTable\n");
00079 *sizeOfOID = 0;
00080 return NULL;
00081 }
00082
00083
00084 currentOIDIndex[0] = ipType;
00085 currentOIDIndex[1] = NUM_IP_OCTETS;
00086
00087 for (i = 0; i < NUM_IP_OCTETS; i++) {
00088 currentOIDIndex[i+2] = ipAddress[i];
00089 }
00090
00091
00092 currentOIDIndex[NUM_IP_OCTETS+2] = ipAddress[NUM_IP_OCTETS];
00093
00094 return currentOIDIndex;
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104 openserSIPPortTable_context *getRow(int ipType, int *ipAddress)
00105 {
00106 int lengthOfOID;
00107 oid *currentOIDIndex = createIndex(ipType, ipAddress, &lengthOfOID);
00108
00109 if (currentOIDIndex == NULL)
00110 {
00111 return NULL;
00112 }
00113
00114 netsnmp_index theIndex;
00115
00116 theIndex.oids = currentOIDIndex;
00117 theIndex.len = lengthOfOID;
00118
00119 openserSIPPortTable_context *rowToReturn;
00120
00121
00122 rowToReturn = CONTAINER_FIND(cb.container, &theIndex);
00123
00124
00125
00126 if (rowToReturn != NULL)
00127 {
00128
00129
00130 pkg_free(currentOIDIndex);
00131
00132 return rowToReturn;
00133 }
00134
00135
00136 rowToReturn = SNMP_MALLOC_TYPEDEF(openserSIPPortTable_context);
00137
00138
00139 if (rowToReturn == NULL) {
00140 pkg_free(currentOIDIndex);
00141 return NULL;
00142 }
00143
00144
00145 rowToReturn->index.len = lengthOfOID;
00146 rowToReturn->index.oids = currentOIDIndex;
00147
00148 memcpy(rowToReturn->openserSIPStringIndex, currentOIDIndex, NUM_IP_OCTETS + 3);
00149 rowToReturn->openserSIPStringIndex_len = NUM_IP_OCTETS + 3;
00150
00151
00152 CONTAINER_INSERT(cb.container, rowToReturn);
00153
00154 return rowToReturn;
00155 }
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 void createRowsFromIPList(int *theList, int listSize, int protocol,
00166 int *snmpIndex) {
00167
00168 openserSIPPortTable_context *currentRow;
00169
00170 int curIndexOfIP;
00171 int curSocketIdx;
00172 int valueToAssign;
00173
00174 if (protocol == PROTO_UDP)
00175 {
00176 valueToAssign = TC_TRANSPORT_PROTOCOL_UDP;
00177 }
00178 else if (protocol == PROTO_TCP)
00179 {
00180 valueToAssign = TC_TRANSPORT_PROTOCOL_TCP;
00181 }
00182 else if (protocol == PROTO_TLS)
00183 {
00184 valueToAssign = TC_TRANSPORT_PROTOCOL_TLS;
00185 }
00186 else
00187 {
00188 valueToAssign = TC_TRANSPORT_PROTOCOL_OTHER;
00189 }
00190
00191
00192 for (curSocketIdx=0; curSocketIdx < listSize; curSocketIdx++) {
00193
00194 curIndexOfIP = (NUM_IP_OCTETS + 1) * curSocketIdx;
00195
00196
00197
00198 currentRow = getRow(1, &theList[curIndexOfIP]);
00199
00200 if (currentRow == NULL) {
00201 LM_ERR("failed to create all the "
00202 "rows for the openserSIPPortTable\n");
00203 return;
00204 }
00205
00206 currentRow->openserSIPTransportRcv[0] |= valueToAssign;
00207 currentRow->openserSIPTransportRcv_len = 1;
00208 }
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218 void init_openserSIPPortTable(void)
00219 {
00220 int curSNMPIndex = 0;
00221
00222 initialize_table_openserSIPPortTable();
00223
00224 int *UDPList = NULL;
00225 int *TCPList = NULL;
00226 int *TLSList = NULL;
00227
00228 int numUDPSockets;
00229 int numTCPSockets;
00230 int numTLSSockets;
00231
00232
00233 numUDPSockets = get_socket_list_from_proto(&UDPList, PROTO_UDP);
00234 numTCPSockets = get_socket_list_from_proto(&TCPList, PROTO_TCP);
00235 numTLSSockets = get_socket_list_from_proto(&TLSList, PROTO_TLS);
00236
00237
00238 createRowsFromIPList(UDPList, numUDPSockets, PROTO_UDP, &curSNMPIndex);
00239
00240 curSNMPIndex = 0;
00241
00242 createRowsFromIPList(TCPList, numTCPSockets, PROTO_TCP, &curSNMPIndex);
00243
00244 curSNMPIndex = 0;
00245 createRowsFromIPList(TLSList, numTLSSockets, PROTO_TLS, &curSNMPIndex);
00246 }
00247
00248
00249
00250 void initialize_table_openserSIPPortTable(void)
00251 {
00252 netsnmp_table_registration_info *table_info;
00253
00254 if(my_handler) {
00255 snmp_log(LOG_ERR, "initialize_table_openserSIPPortTable_handler"
00256 "called again\n");
00257 return;
00258 }
00259
00260 memset(&cb, 0x00, sizeof(cb));
00261
00262
00263 table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
00264
00265 my_handler = netsnmp_create_handler_registration("openserSIPPortTable",
00266 netsnmp_table_array_helper_handler,
00267 openserSIPPortTable_oid,
00268 openserSIPPortTable_oid_len,
00269 HANDLER_CAN_RONLY);
00270
00271 if (!my_handler || !table_info) {
00272 snmp_log(LOG_ERR, "malloc failed in "
00273 "initialize_table_openserSIPPortTable_handler\n");
00274 return;
00275 }
00276
00277
00278
00279
00280 netsnmp_table_helper_add_index(table_info, ASN_OCTET_STR);
00281
00282 table_info->min_column = openserSIPPortTable_COL_MIN;
00283 table_info->max_column = openserSIPPortTable_COL_MAX;
00284
00285
00286 cb.get_value = openserSIPPortTable_get_value;
00287 cb.container = netsnmp_container_find("openserSIPPortTable_primary:"
00288 "openserSIPPortTable:"
00289 "table_container");
00290
00291
00292 DEBUGMSGTL(("initialize_table_openserSIPPortTable",
00293 "Registering table openserSIPPortTable "
00294 "as a table array\n"));
00295
00296 netsnmp_table_container_register(my_handler, table_info, &cb,
00297 cb.container, 1);
00298 }
00299
00300
00301
00302
00303
00304
00305 int openserSIPPortTable_get_value(netsnmp_request_info *request,
00306 netsnmp_index *item,
00307 netsnmp_table_request_info *table_info )
00308 {
00309 netsnmp_variable_list *var = request->requestvb;
00310
00311 openserSIPPortTable_context *context =
00312 (openserSIPPortTable_context *)item;
00313
00314 switch(table_info->colnum)
00315 {
00316
00317 case COLUMN_OPENSERSIPTRANSPORTRCV:
00318
00319 snmp_set_var_typed_value(var, ASN_OCTET_STR,
00320 (unsigned char *)
00321 &context->openserSIPTransportRcv,
00322 context->openserSIPTransportRcv_len );
00323 break;
00324
00325 default:
00326 snmp_log(LOG_ERR, "unknown column in "
00327 "openserSIPPortTable_get_value\n");
00328 return SNMP_ERR_GENERR;
00329 }
00330
00331 return SNMP_ERR_NOERROR;
00332 }
00333
00334
00335 const openserSIPPortTable_context *
00336 openserSIPPortTable_get_by_idx(netsnmp_index * hdr)
00337 {
00338 return (const openserSIPPortTable_context *)
00339 CONTAINER_FIND(cb.container, hdr );
00340 }
00341
00342