openserSIPServerObjects.c

Go to the documentation of this file.
00001 /*
00002  * $Id: openserSIPServerObjects.c 4518 2008-07-28 15:39:28Z henningw $
00003  *
00004  * SNMPStats Module 
00005  * Copyright (C) 2006 SOMA Networks, INC.
00006  * Written by: Jeffrey Magder (jmagder@somanetworks.com)
00007  *
00008  * This file is part of Kamailio, a free SIP server.
00009  *
00010  * Kamailio is free software; you can redistribute it and/or modify it
00011  * under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * Kamailio is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023  * USA
00024  *
00025  * History:
00026  * --------
00027  * 2006-11-23 initial version (jmagder)
00028  * 2007-02-16 Moved all OID registrations from the experimental branch to 
00029  *            OpenSER's IANA assigned enterprise branch. (jmagder)
00030  * 
00031  * Note: this file originally auto-generated by mib2c using
00032  *        : mib2c.scalar.conf,v 1.9 2005/01/07 09:37:18 dts12 Exp $
00033  *
00034  * This file implements all scalares defines in the OPENSER-SIP-SERVER-MIB.  For
00035  * a full description of the scalars, please see OPENSER-SIP-SERVER-MIB.
00036  *
00037  */
00038 
00039 #include <string.h>
00040 
00041 #include "../../statistics.h"
00042 #include "../../sr_module.h"
00043 #include "../../config.h"
00044 #include "../usrloc/usrloc.h"
00045 
00046 #include <net-snmp/net-snmp-config.h>
00047 #include <net-snmp/net-snmp-includes.h>
00048 #include <net-snmp/agent/net-snmp-agent-includes.h>
00049 #include "openserSIPServerObjects.h"
00050 
00051 #include "snmpstats_globals.h"
00052 #include "utilities.h"
00053 
00054 /* Used for openserSIPRegUserLookupCounter.  (See the MIB file for details) */
00055 unsigned int global_UserLookupCounter;
00056 
00057 
00058 /* Initializes the openserSIPServerObjects module.  This involves: 
00059  *
00060  *  - Registering all OID's
00061  *  - Setting up handlers for all OID's
00062  *
00063  * This function is mostly auto-generated. */
00064 void init_openserSIPServerObjects(void)
00065 {
00066    static oid openserSIPProxyStatefulness_oid[]  =
00067       { OPENSER_OID,3,1,2,1,3,1 };
00068 
00069    static oid openserSIPProxyRecordRoute_oid[]   =
00070       { OPENSER_OID,3,1,2,1,3,3 };
00071 
00072    static oid openserSIPProxyAuthMethod_oid[]    =
00073       { OPENSER_OID,3,1,2,1,3,4 };
00074 
00075    static oid openserSIPNumProxyRequireFailures_oid[]     =
00076       { OPENSER_OID,3,1,2,1,4,1 };
00077 
00078    static oid openserSIPRegMaxContactExpiryDuration_oid[] =
00079       { OPENSER_OID,3,1,2,1,5,2 };
00080 
00081    static oid openserSIPRegMaxUsers_oid[]              =
00082       { OPENSER_OID,3,1,2,1,5,3 };
00083 
00084    static oid openserSIPRegCurrentUsers_oid[]          =
00085       { OPENSER_OID,3,1,2,1,5,4 };
00086 
00087    static oid openserSIPRegDfltRegActiveInterval_oid[] =
00088       { OPENSER_OID,3,1,2,1,5,5 };
00089 
00090    static oid openserSIPRegUserLookupCounter_oid[]     =
00091       { OPENSER_OID,3,1,2,1,5,8 };
00092 
00093    static oid openserSIPRegAcceptedRegistrations_oid[] =
00094       { OPENSER_OID,3,1,2,1,6,1 };
00095 
00096    static oid openserSIPRegRejectedRegistrations_oid[] =
00097       { OPENSER_OID,3,1,2,1,6,2 };
00098 
00099    DEBUGMSGTL(("openserSIPServerObjects", "Initializing\n"));
00100 
00101    netsnmp_register_scalar(
00102       netsnmp_create_handler_registration(
00103          "openserSIPProxyStatefulness",
00104          handle_openserSIPProxyStatefulness,
00105          openserSIPProxyStatefulness_oid,
00106          OID_LENGTH(openserSIPProxyStatefulness_oid),
00107          HANDLER_CAN_RONLY));
00108 
00109    netsnmp_register_scalar(
00110       netsnmp_create_handler_registration(
00111          "openserSIPProxyRecordRoute",
00112          handle_openserSIPProxyRecordRoute,
00113          openserSIPProxyRecordRoute_oid,
00114          OID_LENGTH(openserSIPProxyRecordRoute_oid),
00115          HANDLER_CAN_RONLY));
00116 
00117    netsnmp_register_scalar(
00118       netsnmp_create_handler_registration(
00119          "openserSIPProxyAuthMethod",
00120          handle_openserSIPProxyAuthMethod,
00121          openserSIPProxyAuthMethod_oid,
00122          OID_LENGTH(openserSIPProxyAuthMethod_oid),
00123          HANDLER_CAN_RONLY));
00124 
00125    netsnmp_register_scalar(
00126       netsnmp_create_handler_registration(
00127          "openserSIPNumProxyRequireFailures",
00128          handle_openserSIPNumProxyRequireFailures,
00129          openserSIPNumProxyRequireFailures_oid,
00130          OID_LENGTH(openserSIPNumProxyRequireFailures_oid),
00131          HANDLER_CAN_RONLY));
00132 
00133    netsnmp_register_scalar(
00134       netsnmp_create_handler_registration(
00135          "openserSIPRegMaxContactExpiryDuration",
00136          handle_openserSIPRegMaxContactExpiryDuration,
00137          openserSIPRegMaxContactExpiryDuration_oid,
00138          OID_LENGTH(openserSIPRegMaxContactExpiryDuration_oid),
00139          HANDLER_CAN_RONLY));
00140 
00141    netsnmp_register_scalar(
00142       netsnmp_create_handler_registration(
00143          "openserSIPRegMaxUsers",
00144          handle_openserSIPRegMaxUsers,
00145          openserSIPRegMaxUsers_oid,
00146          OID_LENGTH(openserSIPRegMaxUsers_oid),
00147          HANDLER_CAN_RONLY));
00148 
00149    netsnmp_register_scalar(
00150       netsnmp_create_handler_registration(
00151          "openserSIPRegCurrentUsers",
00152          handle_openserSIPRegCurrentUsers,
00153          openserSIPRegCurrentUsers_oid,
00154          OID_LENGTH(openserSIPRegCurrentUsers_oid),
00155          HANDLER_CAN_RONLY));
00156 
00157    netsnmp_register_scalar(
00158       netsnmp_create_handler_registration(
00159          "openserSIPRegDfltRegActiveInterval",
00160          handle_openserSIPRegDfltRegActiveInterval,
00161          openserSIPRegDfltRegActiveInterval_oid,
00162          OID_LENGTH(openserSIPRegDfltRegActiveInterval_oid),
00163          HANDLER_CAN_RONLY));
00164 
00165    netsnmp_register_scalar(
00166       netsnmp_create_handler_registration(
00167          "openserSIPRegUserLookupCounter",
00168          handle_openserSIPRegUserLookupCounter,
00169          openserSIPRegUserLookupCounter_oid,
00170          OID_LENGTH(openserSIPRegUserLookupCounter_oid),
00171          HANDLER_CAN_RONLY));
00172 
00173    netsnmp_register_scalar(
00174       netsnmp_create_handler_registration(
00175          "openserSIPRegAcceptedRegistrations",
00176          handle_openserSIPRegAcceptedRegistrations,
00177          openserSIPRegAcceptedRegistrations_oid,
00178          OID_LENGTH(openserSIPRegAcceptedRegistrations_oid),
00179          HANDLER_CAN_RONLY));
00180 
00181    netsnmp_register_scalar(
00182       netsnmp_create_handler_registration(
00183          "openserSIPRegRejectedRegistrations",
00184          handle_openserSIPRegRejectedRegistrations,
00185          openserSIPRegRejectedRegistrations_oid,
00186          OID_LENGTH(openserSIPRegRejectedRegistrations_oid),
00187          HANDLER_CAN_RONLY));
00188 }
00189 
00190 /* The following are handlers for the scalars in the OPENSER-SIP-SERVER-MIB. */
00191 
00192 int handle_openserSIPProxyStatefulness(netsnmp_mib_handler *handler,
00193    netsnmp_handler_registration *reginfo,
00194    netsnmp_agent_request_info   *reqinfo,
00195    netsnmp_request_info         *requests)
00196 {
00197    int statefullness;
00198 
00199    if (module_loaded("dialog")) 
00200    {
00201       statefullness = PROXY_STATEFULNESS_CALL_STATEFUL;
00202    }
00203    else if (module_loaded("tm"))
00204    {
00205       statefullness = PROXY_STATEFULNESS_TRANSACTION_STATEFUL;
00206    }
00207    else
00208    {
00209       statefullness = PROXY_STATEFULNESS_STATELESS;
00210    }
00211 
00212    if (reqinfo->mode==MODE_GET) {
00213       snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
00214          (u_char *) &statefullness, sizeof(int));
00215       return SNMP_ERR_NOERROR;
00216    }
00217 
00218    return SNMP_ERR_GENERR;
00219 }
00220 
00221 
00222 int handle_openserSIPProxyRecordRoute(netsnmp_mib_handler *handler,
00223    netsnmp_handler_registration *reginfo,
00224    netsnmp_agent_request_info   *reqinfo,
00225    netsnmp_request_info         *requests)
00226 {
00227    /* If the rr module is loaded, then we support record route.  otherwise,
00228     * we want to return 2, which is false for SNMP TruthValue. */
00229    int supportRecordRoute = TC_FALSE;
00230 
00231    if (module_loaded("rr"))
00232    {
00233       supportRecordRoute = TC_TRUE;
00234    }
00235     
00236    if (reqinfo->mode==MODE_GET) {
00237       snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
00238          (u_char *) &supportRecordRoute, sizeof(int));
00239       return SNMP_ERR_NOERROR;
00240    }
00241 
00242    return SNMP_ERR_GENERR;
00243 }
00244 
00245 int handle_openserSIPProxyAuthMethod(netsnmp_mib_handler *handler,
00246    netsnmp_handler_registration *reginfo,
00247    netsnmp_agent_request_info   *reqinfo,
00248    netsnmp_request_info         *requests)
00249 {
00250 
00251    /* The result needs to be returned as an SNMP bit field. */
00252    unsigned int auth_bitfield = SIP_AUTH_METHOD_NONE;
00253    
00254    if (module_loaded("tls")) {
00255       auth_bitfield |=  SIP_AUTH_METHOD_TLS;
00256       auth_bitfield &= ~SIP_AUTH_METHOD_NONE;
00257    }
00258    
00259    /* We can have both tls and auth loaded simultaneously.  Therefore we
00260     * use an if instead of a else/else-if. */
00261    if (module_loaded("auth")) {
00262       auth_bitfield |= SIP_AUTH_METHOD_DIGEST;
00263       auth_bitfield &= ~SIP_AUTH_METHOD_NONE;
00264    }
00265 
00266    if (reqinfo->mode==MODE_GET) {
00267       snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
00268          (u_char *) &auth_bitfield, 1);
00269       return SNMP_ERR_NOERROR;
00270    }
00271 
00272    return SNMP_ERR_GENERR;
00273 }
00274 
00275 int handle_openserSIPNumProxyRequireFailures(netsnmp_mib_handler *handler,
00276    netsnmp_handler_registration *reginfo,
00277    netsnmp_agent_request_info   *reqinfo,
00278    netsnmp_request_info         *requests)
00279 {
00280    int result = get_statistic("bad_msg_hdr"); 
00281    
00282    if (reqinfo->mode==MODE_GET) {
00283       snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
00284          (u_char *) &result, sizeof(int));
00285       return SNMP_ERR_NOERROR;
00286    }
00287 
00288    return SNMP_ERR_GENERR;
00289 }
00290 
00291 int handle_openserSIPRegMaxContactExpiryDuration(netsnmp_mib_handler *handler,
00292    netsnmp_handler_registration *reginfo,
00293    netsnmp_agent_request_info   *reqinfo,
00294    netsnmp_request_info         *requests)
00295 {
00296    int result = get_statistic("max_expires");
00297     
00298    if (reqinfo->mode==MODE_GET) {
00299       snmp_set_var_typed_value(requests->requestvb, ASN_UNSIGNED,
00300          (u_char *) &result, sizeof(int));
00301       return SNMP_ERR_NOERROR;
00302    }
00303 
00304    return SNMP_ERR_GENERR;
00305 }
00306 
00307 int handle_openserSIPRegMaxUsers(netsnmp_mib_handler *handler,
00308    netsnmp_handler_registration *reginfo,
00309    netsnmp_agent_request_info   *reqinfo,
00310    netsnmp_request_info         *requests)
00311 {
00312 
00313    /* OpenSER doesn't currently have a parameterized maximum number of
00314     * users.  So we return the maximum value an unsigned32 SNMP datatype
00315     * can hold.  */
00316    unsigned int result = 0xffffffff; 
00317    
00318    if (reqinfo->mode==MODE_GET) {
00319       snmp_set_var_typed_value(requests->requestvb, ASN_UNSIGNED,
00320          (u_char *) &result, sizeof(unsigned int));
00321       return SNMP_ERR_NOERROR;
00322    }
00323 
00324    return SNMP_ERR_GENERR;
00325 }
00326 
00327 int handle_openserSIPRegCurrentUsers(netsnmp_mib_handler *handler,
00328    netsnmp_handler_registration *reginfo,
00329    netsnmp_agent_request_info   *reqinfo,
00330    netsnmp_request_info         *requests)
00331 {
00332    int max_users = 0;
00333 
00334    max_users = get_statistic("registered_users");
00335    
00336    if (reqinfo->mode==MODE_GET) {
00337       snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE,
00338          (u_char *) &max_users, sizeof(int));
00339       return SNMP_ERR_NOERROR;
00340    }
00341 
00342    return SNMP_ERR_GENERR;
00343 }
00344 
00345 int handle_openserSIPRegDfltRegActiveInterval(netsnmp_mib_handler *handler,
00346    netsnmp_handler_registration *reginfo,
00347    netsnmp_agent_request_info   *reqinfo,
00348    netsnmp_request_info         *requests)
00349 {
00350    int result = get_statistic("default_expire");
00351    
00352    if (reqinfo->mode==MODE_GET) {
00353       snmp_set_var_typed_value(requests->requestvb, ASN_UNSIGNED,
00354          (u_char *) &result, sizeof(int));
00355       return SNMP_ERR_NOERROR;
00356    }
00357 
00358    return SNMP_ERR_GENERR;
00359 }
00360 
00361 
00362 int handle_openserSIPRegUserLookupCounter(netsnmp_mib_handler *handler,
00363    netsnmp_handler_registration *reginfo,
00364    netsnmp_agent_request_info   *reqinfo,
00365    netsnmp_request_info         *requests)
00366 {
00367    int result = ++global_UserLookupCounter;
00368 
00369    /* If we have had so many requests that we've hit our maximum index,
00370     * then we reset our counter back to 1.  For this not to cause problems,
00371     * it will be required that old rows belonging to the table 
00372     * openserSIPRegUserLookupTable are eventually deleted. */
00373    if (global_UserLookupCounter > MAX_USER_LOOKUP_COUNTER) {
00374       global_UserLookupCounter = 1;
00375    }
00376 
00377    if (reqinfo->mode==MODE_GET) {
00378       snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
00379          (u_char *) &result, sizeof(int));
00380       return SNMP_ERR_NOERROR;
00381    }
00382 
00383    return SNMP_ERR_GENERR;
00384 }
00385 
00386 int handle_openserSIPRegAcceptedRegistrations(netsnmp_mib_handler *handler,
00387    netsnmp_handler_registration *reginfo,
00388    netsnmp_agent_request_info   *reqinfo,
00389    netsnmp_request_info         *requests)
00390 {
00391    int result = get_statistic("accepted_regs");
00392    
00393    if (reqinfo->mode==MODE_GET) {
00394       snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
00395          (u_char *) &result, sizeof(int));
00396       return SNMP_ERR_NOERROR;
00397    }
00398 
00399    return SNMP_ERR_GENERR;
00400 }
00401 
00402 int handle_openserSIPRegRejectedRegistrations(netsnmp_mib_handler *handler,
00403    netsnmp_handler_registration *reginfo,
00404    netsnmp_agent_request_info   *reqinfo,
00405    netsnmp_request_info         *requests)
00406 {
00407    int result = get_statistic("rejected_regs");
00408    
00409    if (reqinfo->mode==MODE_GET) {
00410       snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
00411          (u_char *) &result, sizeof(int));
00412       return SNMP_ERR_NOERROR;
00413    }
00414 
00415    return SNMP_ERR_GENERR;
00416 }
00417 

Generated on Thu May 24 00:00:28 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6