提交 5ef49162 编写于 作者: K Kozlov Dmitry

snmp support

上级 fd52e457
......@@ -23,6 +23,7 @@ Features
13. Supported pppd compatible ip-up/ip-down scripts
14. Builtin tbf shaper manager
15. Command line interface via telnet
16. SNMP support (master or subagent via AgentX)
Requirment
......@@ -33,6 +34,7 @@ Requirment
5. libnl-2.0 or probably later (required for builtin shaper)
6. libcrypto-0.9.8 or probably later (openssl-0.9.8)
7. libpcre
8. net-snmp-5.x
Compilation and instalation
......@@ -42,7 +44,7 @@ or specify other location via KDIR.
1. cd /path/to/accel-ppp-1.3.5
2. mkdir build
3. cd build
4. cmake [-DBUILD_DRIVER=FALSE] [-DKDIR=/usr/src/linux] [-DCMAKE_INSTALL_PREFIX=/usr/local] [-DCMAKE_BUILD_TYPE=Release] [-DLOG_PGSQL=FALSE] [-DSHAPER=FALSE] [-DRADIUS=TRUE] ..
4. cmake [-DBUILD_DRIVER=FALSE] [-DKDIR=/usr/src/linux] [-DCMAKE_INSTALL_PREFIX=/usr/local] [-DCMAKE_BUILD_TYPE=Release] [-DLOG_PGSQL=FALSE] [-DSHAPER=FALSE] [-DRADIUS=TRUE] [-DNETSNMP=FALSE] ..
Please note that the double dot record in the end of the command is essential. You'll probably get error or misconfigured sources if you miss it.
BUILD_DRIVER, KDIR, CMAKE_INSTALL_PREFIX, CMAKE_BUILD_TYPE, LOG_PGSQL, SHAPER, RADIUS are optional,
But while pptp is not present in mainline kernel you probably need BUILD_DRIVER.
......@@ -124,6 +126,31 @@ The optional fifth column in chap-secrets file is used to pass rate information
Its format is same as for radius attributes, except you cann't utilize time ranges functionality.
SNMP
----
SNMP is implemented using net-snmp libraries. By default accel-ppp starts in subagent mode,
so make sure that net-snmp configured with subagent control turned on (read net-snmp's README.agentx for more details).
Also you can start accel-ppp as master agent using following configuration:
[snmp]
master=1
Usage:
Place accel-pppd/extra/net-snmp/ACCEL-PPP-MIB.txt to your mibs directory.
Also you can find used numerical oids in this file.
1. Requesting statistics:
snmpwalk -m +ACCEL-PPP-MIB -v 2c -c local 127.0.0.1 ACCEL-PPP-MIB::accelPPPStat
2. Requesting sessions:
snmptable -m +ACCEL-PPP-MIB -v 2c -c local 127.0.0.1 ACCEL-PPP-MIB::sessionsTable
3. Terminate session by session identifier (Acct-Session-ID):
snmpset -m +ACCEL-PPP-MIB -v 2c -c local 127.0.0.1 ACCEL-PPP-MIB::termBySID.0 = 0000000000000001
4. Terminate session by interface name:
snmpset -m +ACCEL-PPP-MIB -v 2c -c local 127.0.0.1 ACCEL-PPP-MIB::termByIfName = ppp2
5. Terminaten session by IP address (Framed-IP-Address):
snmpset -m +ACCEL-PPP-MIB -v 2c -c local 127.0.0.1 ACCEL-PPP-MIB::termByIP = 192.168.10.10
6. Terminate session by username:
snmpset -m +ACCEL-PPP-MIB -v 2c -c local 127.0.0.1 ACCEL-PPP-MIB::termByUsername = user1
Warning !!!
-----------
1. The pptp driver conflicts with ip_gre driver (in kernel), so make sure that ip_gre is not built-in or loaded at run time
......
......@@ -129,3 +129,7 @@ gw-ip-address=192.168.100.1
telnet=127.0.0.1:2000
tcp=127.0.0.1:2001
#password=123
[snmp]
master=0
agent-name=accel-ppp
......@@ -16,6 +16,7 @@
static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt, void *client)
{
struct timespec ts;
time_t dt;
int day,hour;
char statm_fname[128];
......@@ -33,8 +34,8 @@ static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt,
fclose(f);
}
time(&dt);
dt -= triton_stat.start_time;
clock_gettime(CLOCK_MONOTONIC, &ts);
dt = ts.tv_sec - triton_stat.start_time;
day = dt / (60 * 60 * 24);
dt %= 60 * 60 * 24;
hour = dt / (60 * 60);
......
......@@ -301,6 +301,7 @@ static int l2tp_tunnel_alloc(struct l2tp_serv_t *serv, struct l2tp_packet_t *pac
conn->hello_timer.expire = l2tp_send_HELLO;
conn->hello_timer.period = conf_hello_interval * 1000;
conn->ctrl.ctx = &conn->ctx;
conn->ctrl.type = CTRL_TYPE_L2TP;
conn->ctrl.name = "l2tp";
conn->ctrl.started = l2tp_ppp_started;
conn->ctrl.finished = l2tp_ppp_finished;
......@@ -1091,6 +1092,12 @@ static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt,
return CLI_CMD_OK;
}
void __export l2tp_get_stat(unsigned int **starting, unsigned int **active)
{
*starting = &stat_starting;
*active = &stat_active;
}
static void load_config(void)
{
char *opt;
......
......@@ -74,6 +74,7 @@ int conf_tr101 = 1;
static mempool_t conn_pool;
static mempool_t pado_pool;
unsigned int stat_starting;
unsigned int stat_active;
unsigned int stat_delayed_pado;
unsigned long stat_PADI_recv;
......@@ -247,6 +248,7 @@ static struct pppoe_conn_t *allocate_channel(struct pppoe_serv_t *serv, const ui
conn->ctrl.started = ppp_started;
conn->ctrl.finished = ppp_finished;
conn->ctrl.max_mtu = MAX_PPPOE_MTU;
conn->ctrl.type = CTRL_TYPE_PPPOE;
conn->ctrl.name = "pppoe";
conn->ctrl.calling_station_id = _malloc(IFNAMSIZ + 19);
......@@ -1217,6 +1219,12 @@ void pppoe_server_stop(const char *ifname)
pthread_rwlock_unlock(&serv_lock);
}
void __export pppoe_get_stat(unsigned int **starting, unsigned int **active)
{
*starting = &stat_starting;
*active = &stat_active;
}
static int init_secret(struct pppoe_serv_t *serv)
{
int fd;
......
......@@ -656,6 +656,7 @@ static int pptp_connect(struct triton_md_handler_t *h)
conn->ctrl.started = ppp_started;
conn->ctrl.finished = ppp_finished;
conn->ctrl.max_mtu = PPTP_MAX_MTU;
conn->ctrl.type = CTRL_TYPE_PPTP;
conn->ctrl.name = "pptp";
conn->ctrl.calling_station_id = _malloc(17);
......@@ -703,6 +704,12 @@ static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt,
return CLI_CMD_OK;
}
void __export pptp_get_stat(unsigned int **starting, unsigned int **active)
{
*starting = &stat_starting;
*active = &stat_active;
}
static void load_config(void)
{
char *opt;
......
......@@ -17,3 +17,7 @@ IF (SHAPER)
INSTALL(TARGETS shaper_tbf LIBRARY DESTINATION lib/accel-ppp)
ENDIF (SHAPER)
IF (NETSNMP)
ADD_SUBDIRECTORY(net-snmp)
ENDIF (NETSNMP)
ACCEL-PPP-MIB DEFINITIONS ::= BEGIN
IMPORTS
MODULE-IDENTITY, OBJECT-TYPE, Gauge32
NOTIFICATION-TYPE FROM SNMPv2-SMI
netSnmp FROM NET-SNMP-MIB
InetAddressIPv4 FROM INET-ADDRESS-MIB
IANAtunnelType FROM IANAifType-MIB
;
accelPPP MODULE-IDENTITY
LAST-UPDATED "201108180000Z"
ORGANIZATION "accel-ppp.sourceforge.net"
CONTACT-INFO
"email: xeb@mail.ru"
DESCRIPTION
"MIB objects for accel-ppp"
REVISION "201108180000Z"
DESCRIPTION
"First draft"
::= { netSnmp 100 }
--
-- top level structure
--
accelPPPStat OBJECT IDENTIFIER ::= { accelPPP 1 }
accelPPPSessions OBJECT IDENTIFIER ::= { accelPPP 2 }
accelPPPAdmin OBJECT IDENTIFIER ::= { accelPPP 3 }
--accelPPPNotifications OBJECT IDENTIFIER ::= { accelPPP 4 }
statCore OBJECT IDENTIFIER ::= { accelPPPStat 1 }
statPPP OBJECT IDENTIFIER ::= { accelPPPStat 2 }
statPPTP OBJECT IDENTIFIER ::= { accelPPPStat 3 }
statL2TP OBJECT IDENTIFIER ::= { accelPPPStat 4 }
statPPPOE OBJECT IDENTIFIER ::= { accelPPPStat 5 }
--statRadius OBJECT IDENTIFIER ::= { accelPPPStat 6 }
statCoreUpTime OBJECT-TYPE
SYNTAX Gauge32
UNITS "seconds"
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"accel-ppp uptime"
::= { statCore 1 }
statCoreCPU OBJECT-TYPE
SYNTAX INTEGER (0..100)
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"cpu utilization"
::= { statCore 2 }
statCoreMemRss OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"memory rss size"
::= { statCore 3 }
--
-- PPP stats
--
statPPPStarting OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"count of sessions which are
in starting phase"
::= { statPPP 1 }
statPPPActive OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"count of active sessions"
::= { statPPP 2 }
statPPPFinishing OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"count of active which are
in finishing phase"
::= { statPPP 3 }
--
-- PPTP stats
--
statPPTPStarting OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"count of connections which are
in starting phase"
::= { statPPTP 1 }
statPPTPActive OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"count of active connections"
::= { statPPTP 2 }
--
-- L2TP stats
--
statL2TPStarting OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"count of connections which are
in starting phase"
::= { statL2TP 1 }
statL2TPActive OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"count of active connections"
::= { statL2TP 2 }
--
-- PPPOE stats
--
statPPPOEStarting OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"count of connections which are
in starting phase"
::= { statPPPOE 1 }
statPPPOEActive OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"count of active connections"
::= { statPPPOE 2 }
--
-- PPP session table
--
sessionTable OBJECT-TYPE
SYNTAX SEQUENCE OF sessionEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION
"this table contains information about
connected sessions"
::= { accelPPPSessions 1 }
sessionEntry OBJECT-TYPE
SYNTAX sessionEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION
"A row describing a given session"
INDEX { sesSID }
::= { sessionTable 1 }
sessionEntry ::= SEQUENCE {
sesSID OCTET STRING,
sesIfName OCTET STRING,
sesUsername OCTET STRING,
sesIP InetAddress,
sesType IANAtunnelType,
sesState INTEGER,
sesUptime TimeTicks,
sesCallingSID OCTET STRING,
sesCalledSID OCTET STRING
}
sesSID OBJECT-TYPE
SYNTAX OCTET STRING (SIZE(16))
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Acct-Session-ID"
::= { sessionEntry 1 }
sesIfName OBJECT-TYPE
SYNTAX OCTET STRING
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"name of ppp interface"
::= { sessionEntry 2 }
sesUsername OBJECT-TYPE
SYNTAX OCTET STRING
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"session user name"
::= { sessionEntry 3 }
sesIP OBJECT-TYPE
SYNTAX InetAddressIPv4
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"assigned IP address"
::= { sessionEntry 4 }
sesType OBJECT-TYPE
SYNTAX INTEGER {
pptp(1),
l2tp(2),
pppoe(3)
}
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"name of ppp interface"
::= { sessionEntry 5 }
sesState OBJECT-TYPE
SYNTAX INTEGER {
starting(1),
active(2),
finishing(3)
}
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"state of session"
::= { sessionEntry 6 }
sesUptime OBJECT-TYPE
SYNTAX Gauge32
UNITS "seconds"
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"uptime of session"
::= { sessionEntry 7 }
sesCallingSID OBJECT-TYPE
SYNTAX OCTET STRING
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Calling-Station-ID"
::= { sessionEntry 8 }
sesCalledSID OBJECT-TYPE
SYNTAX OCTET STRING
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Called-Station-ID"
::= { sessionEntry 9 }
--
-- Administration
--
terminate OBJECT IDENTIFIER ::= { accelPPPAdmin 1 }
termBySID OBJECT-TYPE
SYNTAX OCTET STRING
MAX-ACCESS write-only
STATUS current
DESCRIPTION
"Terminate session softly identified by Acct-Session-ID"
::= { terminate 1 }
termByIfName OBJECT-TYPE
SYNTAX OCTET STRING
MAX-ACCESS write-only
STATUS current
DESCRIPTION
"Terminate session softly identified by interface name"
::= { terminate 2 }
termByIP OBJECT-TYPE
SYNTAX OCTET STRING
MAX-ACCESS write-only
STATUS current
DESCRIPTION
"Terminate session softly identified by Framed-IP-Address"
::= { terminate 3 }
termByUsername OBJECT-TYPE
SYNTAX OCTET STRING
MAX-ACCESS write-only
STATUS current
DESCRIPTION
"Terminate session softly identified by username"
::= { terminate 4 }
shutdown OBJECT-TYPE
SYNTAX INTEGER {
normal(0),
soft(1),
hard(2),
cancel(3)
}
MAX-ACCESS write-only
STATUS current
DESCRIPTION
"shutdown accel-ppp"
::= { accelPPPAdmin 2 }
END
SET(sources
agent.c
sessionTable.c
sessionTable_data_access.c
sessionTable_data_get.c
sessionTable_data_set.c
sessionTable_interface.c
statCore.c
statL2TP.c
statPPP.c
statPPPOE.c
statPPTP.c
terminate.c
shutdown.c
)
ADD_LIBRARY(net-snmp SHARED ${sources})
TARGET_LINK_LIBRARIES(net-snmp netsnmpagent netsnmphelpers netsnmpmibs
netsnmp)
INSTALL(TARGETS net-snmp
LIBRARY DESTINATION lib/accel-ppp
)
#include <pthread.h>
#include <signal.h>
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "log.h"
#include "triton.h"
#include "statCore.h"
#include "statPPP.h"
#include "statPPTP.h"
#include "statL2TP.h"
#include "statPPPOE.h"
#include "terminate.h"
#include "shutdown.h"
#include "sessionTable.h"
static const char *conf_agent_name = "accel-ppp";
static int conf_master = 0;
/*static const char *conf_oid_prefix = "1.3.6.1.4.1.8072.100";
static oid* oid_prefix;
static size_t oid_prefix_size;*/
static pthread_t snmp_thr;
static int snmp_term = 0;
/*int accel_ppp_alloc_oid(oid tail, size_t size, oid **oid)
{
*oid = malloc(sizeof(oid) * (oid_prefix_size + size));
memcpy(*oid, oid_prefix, oid_prefix_size);
memcpy((*oid) + oid_prefix_size, tail, size);
return oid_prefix_size + size;
}*/
static int agent_log(int major, int minor, void *serv_arg, void *cl_arg)
{
struct snmp_log_message *m = serv_arg;
switch (m->priority) {
case LOG_EMERG:
log_emerg("net-snmp: %s", m->msg);
break;
case LOG_ALERT:
case LOG_CRIT:
case LOG_ERR:
log_error("net-snmp: %s", m->msg);
break;
case LOG_WARNING:
log_warn("net-snmp: %s", m->msg);
break;
case LOG_NOTICE:
log_info1("net-snmp: %s", m->msg);
break;
case LOG_INFO:
log_info2("net-snmp: %s", m->msg);
break;
case LOG_DEBUG:
log_debug("net-snmp: %s", m->msg);
break;
default:
log_msg("net-snmp: %s", m->msg);
}
return 0;
}
static void *snmp_thread(void *a)
{
sigset_t set;
sigfillset(&set);
sigdelset(&set, SIGKILL);
sigdelset(&set, SIGSTOP);
pthread_sigmask(SIG_BLOCK, &set, NULL);
snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_LOGGING, agent_log, NULL);
snmp_disable_log();
snmp_enable_calllog();
//snmp_set_do_debugging(1);
//netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1);
if (!conf_master)
netsnmp_enable_subagent();
init_agent(conf_agent_name);
init_statCore();
init_statPPP();
init_statPPTP();
init_statL2TP();
init_statPPPOE();
init_terminate();
init_shutdown();
init_sessionTable();
init_snmp(conf_agent_name);
if (conf_master)
init_master_agent();
while (!snmp_term) {
agent_check_and_process(1);
}
snmp_shutdown(conf_agent_name);
SOCK_CLEANUP;
return NULL;
}
static void snmp_ctx_close(struct triton_context_t *ctx)
{
snmp_term = 1;
snmp_shutdown(conf_agent_name);
triton_context_unregister(ctx);
}
static struct triton_context_t ctx = {
.close = snmp_ctx_close,
};
static void init(void)
{
const char *opt;
opt = conf_get_opt("snmp", "master");
if (opt)
conf_master = atoi(opt);
opt = conf_get_opt("snmp", "agent-name");
if (opt)
conf_agent_name = opt;
/*opt = conf_get_opt("snmp", "oid-prefix")
if (opt)
conf_oid_prefix = opt;*/
pthread_create(&snmp_thr, NULL, snmp_thread, NULL);
triton_context_register(&ctx, NULL);
triton_context_wakeup(&ctx);
triton_collect_cpu_usage();
}
DEFINE_INIT(100, init);
/*
* Note: this file originally auto-generated by mib2c using
* version : 14170 $ of $
*
* $Id:$
*/
/** \page MFD helper for sessionTable
*
* \section intro Introduction
* Introductory text.
*
*/
/* standard Net-SNMP includes */
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
/* include our parent header */
#include "sessionTable.h"
#include <net-snmp/agent/mib_modules.h>
#include "sessionTable_interface.h"
oid sessionTable_oid[] = { SESSIONTABLE_OID };
int sessionTable_oid_size = OID_LENGTH(sessionTable_oid);
sessionTable_registration sessionTable_user_context;
void initialize_table_sessionTable(void);
void shutdown_table_sessionTable(void);
/**
* Initializes the sessionTable module
*/
void
init_sessionTable(void)
{
DEBUGMSGTL(("verbose:sessionTable:init_sessionTable","called\n"));
/*
* TODO:300:o: Perform sessionTable one-time module initialization.
*/
/*
* here we initialize all the tables we're planning on supporting
*/
if (should_init("sessionTable"))
initialize_table_sessionTable();
} /* init_sessionTable */
/**
* Shut-down the sessionTable module (agent is exiting)
*/
void
shutdown_sessionTable(void)
{
if (should_init("sessionTable"))
shutdown_table_sessionTable();
}
/**
* Initialize the table sessionTable
* (Define its contents and how it's structured)
*/
void
initialize_table_sessionTable(void)
{
sessionTable_registration * user_context;
u_long flags;
DEBUGMSGTL(("verbose:sessionTable:initialize_table_sessionTable","called\n"));
/*
* TODO:301:o: Perform sessionTable one-time table initialization.
*/
/*
* TODO:302:o: |->Initialize sessionTable user context
* if you'd like to pass in a pointer to some data for this
* table, allocate or set it up here.
*/
/*
* a netsnmp_data_list is a simple way to store void pointers. A simple
* string token is used to add, find or remove pointers.
*/
user_context = netsnmp_create_data_list("sessionTable", NULL, NULL);
/*
* No support for any flags yet, but in the future you would
* set any flags here.
*/
flags = 0;
/*
* call interface initialization code
*/
_sessionTable_initialize_interface(user_context, flags);
} /* initialize_table_sessionTable */
/**
* Shutdown the table sessionTable
*/
void
shutdown_table_sessionTable(void)
{
/*
* call interface shutdown code
*/
_sessionTable_shutdown_interface(&sessionTable_user_context);
}
/**
* extra context initialization (eg default values)
*
* @param rowreq_ctx : row request context
* @param user_init_ctx : void pointer for user (parameter to rowreq_ctx_allocate)
*
* @retval MFD_SUCCESS : no errors
* @retval MFD_ERROR : error (context allocate will fail)
*/
int
sessionTable_rowreq_ctx_init(sessionTable_rowreq_ctx *rowreq_ctx,
void *user_init_ctx)
{
DEBUGMSGTL(("verbose:sessionTable:sessionTable_rowreq_ctx_init","called\n"));
netsnmp_assert(NULL != rowreq_ctx);
/*
* TODO:210:o: |-> Perform extra sessionTable rowreq initialization. (eg DEFVALS)
*/
return MFD_SUCCESS;
} /* sessionTable_rowreq_ctx_init */
/**
* extra context cleanup
*
*/
void sessionTable_rowreq_ctx_cleanup(sessionTable_rowreq_ctx *rowreq_ctx)
{
DEBUGMSGTL(("verbose:sessionTable:sessionTable_rowreq_ctx_cleanup","called\n"));
netsnmp_assert(NULL != rowreq_ctx);
/*
* TODO:211:o: |-> Perform extra sessionTable rowreq cleanup.
*/
} /* sessionTable_rowreq_ctx_cleanup */
/**
* pre-request callback
*
*
* @retval MFD_SUCCESS : success.
* @retval MFD_ERROR : other error
*/
int
sessionTable_pre_request(sessionTable_registration * user_context)
{
DEBUGMSGTL(("verbose:sessionTable:sessionTable_pre_request","called\n"));
/*
* TODO:510:o: Perform sessionTable pre-request actions.
*/
return MFD_SUCCESS;
} /* sessionTable_pre_request */
/**
* post-request callback
*
* Note:
* New rows have been inserted into the container, and
* deleted rows have been removed from the container and
* released.
*
* @param user_context
* @param rc : MFD_SUCCESS if all requests succeeded
*
* @retval MFD_SUCCESS : success.
* @retval MFD_ERROR : other error (ignored)
*/
int
sessionTable_post_request(sessionTable_registration * user_context, int rc)
{
DEBUGMSGTL(("verbose:sessionTable:sessionTable_post_request","called\n"));
/*
* TODO:511:o: Perform sessionTable post-request actions.
*/
return MFD_SUCCESS;
} /* sessionTable_post_request */
/** @{ */
/*
* Note: this file originally auto-generated by mib2c using
* version : 14170 $ of $
*
* $Id:$
*/
#ifndef SESSIONTABLE_H
#define SESSIONTABLE_H
#ifdef __cplusplus
extern "C" {
#endif
/** @addtogroup misc misc: Miscellaneous routines
*
* @{
*/
#include <net-snmp/library/asn1.h>
#include "ppp.h"
/* other required module components */
/* *INDENT-OFF* */
config_add_mib(ACCEL-PPP-MIB)
config_require(ACCEL-PPP-MIB/sessionTable/sessionTable_interface)
config_require(ACCEL-PPP-MIB/sessionTable/sessionTable_data_access)
config_require(ACCEL-PPP-MIB/sessionTable/sessionTable_data_get)
config_require(ACCEL-PPP-MIB/sessionTable/sessionTable_data_set)
/* *INDENT-ON* */
/* OID and column number definitions for sessionTable */
#include "sessionTable_oids.h"
/* enum definions */
#include "sessionTable_enums.h"
/* *********************************************************************
* function declarations
*/
void init_sessionTable(void);
void shutdown_sessionTable(void);
/* *********************************************************************
* Table declarations
*/
/**********************************************************************
**********************************************************************
***
*** Table sessionTable
***
**********************************************************************
**********************************************************************/
/*
* ACCEL-PPP-MIB::sessionTable is subid 1 of accelPPPSessions.
* Its status is Current.
* OID: .1.3.6.1.4.1.8072.100.2.1, length: 10
*/
/* *********************************************************************
* When you register your mib, you get to provide a generic
* pointer that will be passed back to you for most of the
* functions calls.
*
* TODO:100:r: Review all context structures
*/
/*
* TODO:101:o: |-> Review sessionTable registration context.
*/
typedef netsnmp_data_list sessionTable_registration;
/**********************************************************************/
/*
* TODO:110:r: |-> Review sessionTable data context structure.
* This structure is used to represent the data for sessionTable.
*/
struct sessionTable_data_s
{
char ifname[PPP_IFNAME_LEN];
char *username;
in_addr_t peer_addr;
int type;
int state;
unsigned long uptime;
char *calling_sid;
char *called_sid;
};
typedef struct sessionTable_data_s sessionTable_data;
/*
* TODO:120:r: |-> Review sessionTable mib index.
* This structure is used to represent the index for sessionTable.
*/
typedef struct sessionTable_mib_index_s {
/*
* sesSID(1)/OCTETSTR/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/h
*/
char sesSID[PPP_SESSIONID_LEN];
size_t sesSID_len;
} sessionTable_mib_index;
/*
* TODO:121:r: | |-> Review sessionTable max index length.
* If you KNOW that your indexes will never exceed a certain
* length, update this macro to that length.
*
* BE VERY CAREFUL TO TAKE INTO ACCOUNT THE MAXIMUM
* POSSIBLE LENGHT FOR EVERY VARIABLE LENGTH INDEX!
* Guessing 128 - col/entry(2) - oid len(10)
*/
#define MAX_sessionTable_IDX_LEN PPP_SESSIONID_LEN + 1
/* *********************************************************************
* TODO:130:o: |-> Review sessionTable Row request (rowreq) context.
* When your functions are called, you will be passed a
* sessionTable_rowreq_ctx pointer.
*/
typedef struct sessionTable_rowreq_ctx_s {
/** this must be first for container compare to work */
netsnmp_index oid_idx;
oid oid_tmp[MAX_sessionTable_IDX_LEN];
sessionTable_mib_index tbl_idx;
sessionTable_data * data;
/*
* flags per row. Currently, the first (lower) 8 bits are reserved
* for the user. See mfd.h for other flags.
*/
u_int rowreq_flags;
/*
* TODO:131:o: | |-> Add useful data to sessionTable rowreq context.
*/
/*
* storage for future expansion
*/
netsnmp_data_list *sessionTable_data_list;
} sessionTable_rowreq_ctx;
typedef struct sessionTable_ref_rowreq_ctx_s {
sessionTable_rowreq_ctx *rowreq_ctx;
} sessionTable_ref_rowreq_ctx;
/* *********************************************************************
* function prototypes
*/
int sessionTable_pre_request(sessionTable_registration * user_context);
int sessionTable_post_request(sessionTable_registration * user_context,
int rc);
int sessionTable_rowreq_ctx_init(sessionTable_rowreq_ctx *rowreq_ctx,
void *user_init_ctx);
void sessionTable_rowreq_ctx_cleanup(sessionTable_rowreq_ctx *rowreq_ctx);
sessionTable_data * sessionTable_allocate_data(void);
void sessionTable_release_data(sessionTable_data *data);
sessionTable_rowreq_ctx *
sessionTable_row_find_by_mib_index(sessionTable_mib_index *mib_idx);
extern oid sessionTable_oid[];
extern int sessionTable_oid_size;
#include "sessionTable_interface.h"
#include "sessionTable_data_access.h"
#include "sessionTable_data_get.h"
#include "sessionTable_data_set.h"
/*
* DUMMY markers, ignore
*
* TODO:099:x: *************************************************************
* TODO:199:x: *************************************************************
* TODO:299:x: *************************************************************
* TODO:399:x: *************************************************************
* TODO:499:x: *************************************************************
*/
#ifdef __cplusplus
}
#endif
#endif /* SESSIONTABLE_H */
/** @} */
/*
* Note: this file originally auto-generated by mib2c using
* version : 14170 $ of $
*
* $Id:$
*/
/* standard Net-SNMP includes */
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
/* include our parent header */
#include "sessionTable.h"
#include "sessionTable_data_access.h"
#include "ppp.h"
/** @ingroup interface
* @addtogroup data_access data_access: Routines to access data
*
* These routines are used to locate the data used to satisfy
* requests.
*
* @{
*/
/**********************************************************************
**********************************************************************
***
*** Table sessionTable
***
**********************************************************************
**********************************************************************/
/*
* ACCEL-PPP-MIB::sessionTable is subid 1 of accelPPPSessions.
* Its status is Current.
* OID: .1.3.6.1.4.1.8072.100.2.1, length: 10
*/
/**
* initialization for sessionTable data access
*
* This function is called during startup to allow you to
* allocate any resources you need for the data table.
*
* @param sessionTable_reg
* Pointer to sessionTable_registration
*
* @retval MFD_SUCCESS : success.
* @retval MFD_ERROR : unrecoverable error.
*/
int
sessionTable_init_data(sessionTable_registration * sessionTable_reg)
{
DEBUGMSGTL(("verbose:sessionTable:sessionTable_init_data","called\n"));
/*
* TODO:303:o: Initialize sessionTable data->
*/
/*
***************************************************
*** START EXAMPLE CODE ***
***---------------------------------------------***/
/*
* if you are the sole writer for the file, you could
* open it here. However, as stated earlier, we are assuming
* the worst case, which in this case means that the file is
* written to by someone else, and might not even exist when
* we start up. So we can't do anything here.
*/
/*
***---------------------------------------------***
*** END EXAMPLE CODE ***
***************************************************/
return MFD_SUCCESS;
} /* sessionTable_init_data */
/**
* container overview
*
*/
/**
* container initialization
*
* @param container_ptr_ptr A pointer to a container pointer. If you
* create a custom container, use this parameter to return it
* to the MFD helper. If set to NULL, the MFD helper will
* allocate a container for you.
*
* This function is called at startup to allow you to customize certain
* aspects of the access method. For the most part, it is for advanced
* users. The default code should suffice for most cases. If no custom
* container is allocated, the MFD code will create one for your.
*
* @remark
* This would also be a good place to do any initialization needed
* for you data source. For example, opening a connection to another
* process that will supply the data, opening a database, etc.
*/
void
sessionTable_container_init(netsnmp_container **container_ptr_ptr,
netsnmp_cache *cache)
{
DEBUGMSGTL(("verbose:sessionTable:sessionTable_container_init","called\n"));
if (NULL == container_ptr_ptr) {
snmp_log(LOG_ERR,"bad container param to sessionTable_container_init\n");
return;
}
/*
* For advanced users, you can use a custom container. If you
* do not create one, one will be created for you.
*/
*container_ptr_ptr = NULL;
if (NULL == cache) {
snmp_log(LOG_ERR,"bad cache param to sessionTable_container_init\n");
return;
}
/*
* TODO:345:A: Set up sessionTable cache properties.
*
* Also for advanced users, you can set parameters for the
* cache. Do not change the magic pointer, as it is used
* by the MFD helper. To completely disable caching, set
* cache->enabled to 0.
*/
cache->timeout = -1; /* seconds */
} /* sessionTable_container_init */
/**
* container shutdown
*
* @param container_ptr A pointer to the container.
*
* This function is called at shutdown to allow you to customize certain
* aspects of the access method. For the most part, it is for advanced
* users. The default code should suffice for most cases.
*
* This function is called before sessionTable_container_free().
*
* @remark
* This would also be a good place to do any cleanup needed
* for you data source. For example, closing a connection to another
* process that supplied the data, closing a database, etc.
*/
void
sessionTable_container_shutdown(netsnmp_container *container_ptr)
{
DEBUGMSGTL(("verbose:sessionTable:sessionTable_container_shutdown","called\n"));
if (NULL == container_ptr) {
snmp_log(LOG_ERR,"bad params to sessionTable_container_shutdown\n");
return;
}
} /* sessionTable_container_shutdown */
/**
* load initial data
*
* TODO:350:M: Implement sessionTable data load
*
* @param container container to which items should be inserted
*
* @retval MFD_SUCCESS : success.
* @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source
* @retval MFD_ERROR : other error.
*
* This function is called to load the index(es) (and data, optionally)
* for the every row in the data set.
*
* @remark
* While loading the data, the only important thing is the indexes.
* If access to your data is cheap/fast (e.g. you have a pointer to a
* structure in memory), it would make sense to update the data here.
* If, however, the accessing the data invovles more work (e.g. parsing
* some other existing data, or peforming calculations to derive the data),
* then you can limit yourself to setting the indexes and saving any
* information you will need later. Then use the saved information in
* sessionTable_row_prep() for populating data->
*
* @note
* If you need consistency between rows (like you want statistics
* for each row to be from the same time frame), you should set all
* data here.
*
*/
int
sessionTable_container_load(netsnmp_container *container)
{
sessionTable_rowreq_ctx *rowreq_ctx;
size_t count = 0;
struct ppp_t *ppp;
time_t t;
time(&t);
DEBUGMSGTL(("verbose:sessionTable:sessionTable_container_load","called\n"));
pthread_rwlock_rdlock(&ppp_lock);
list_for_each_entry(ppp, &ppp_list, entry) {
rowreq_ctx = sessionTable_allocate_rowreq_ctx(NULL, NULL);
if (NULL == rowreq_ctx) {
pthread_rwlock_unlock(&ppp_lock);
snmp_log(LOG_ERR, "memory allocation failed\n");
return MFD_RESOURCE_UNAVAILABLE;
}
if(MFD_SUCCESS != sessionTable_indexes_set(rowreq_ctx
, ppp->sessionid, PPP_SESSIONID_LEN
)) {
snmp_log(LOG_ERR,"error setting index while loading "
"sessionTable data->\n");
sessionTable_release_rowreq_ctx(rowreq_ctx);
continue;
}
strcpy(rowreq_ctx->data->ifname, ppp->ifname);
if (ppp->username)
rowreq_ctx->data->username = strdup(ppp->username);
else
ppp->username = strdup("");
rowreq_ctx->data->peer_addr = ppp->peer_ipaddr;
rowreq_ctx->data->type = ppp->ctrl->type;
rowreq_ctx->data->state = ppp->state;
rowreq_ctx->data->uptime = (ppp->stop_time ? ppp->stop_time : t) - ppp->start_time;
rowreq_ctx->data->calling_sid = strdup(ppp->ctrl->calling_station_id);
rowreq_ctx->data->called_sid = strdup(ppp->ctrl->called_station_id);
CONTAINER_INSERT(container, rowreq_ctx);
++count;
}
pthread_rwlock_unlock(&ppp_lock);
DEBUGMSGT(("verbose:sessionTable:sessionTable_container_load",
"inserted %d records\n", count));
return MFD_SUCCESS;
} /* sessionTable_container_load */
/**
* container clean up
*
* @param container container with all current items
*
* This optional callback is called prior to all
* item's being removed from the container. If you
* need to do any processing before that, do it here.
*
* @note
* The MFD helper will take care of releasing all the row contexts.
* If you did not pass a data context pointer when allocating
* the rowreq context, the one that was allocated will be deleted.
* If you did pass one in, it will not be deleted and that memory
* is your responsibility.
*
*/
void
sessionTable_container_free(netsnmp_container *container)
{
DEBUGMSGTL(("verbose:sessionTable:sessionTable_container_free","called\n"));
/*
* TODO:380:M: Free sessionTable container data->
*/
} /* sessionTable_container_free */
/**
* prepare row for processing.
*
* When the agent has located the row for a request, this function is
* called to prepare the row for processing. If you fully populated
* the data context during the index setup phase, you may not need to
* do anything.
*
* @param rowreq_ctx pointer to a context.
*
* @retval MFD_SUCCESS : success.
* @retval MFD_ERROR : other error.
*/
int
sessionTable_row_prep( sessionTable_rowreq_ctx *rowreq_ctx)
{
DEBUGMSGTL(("verbose:sessionTable:sessionTable_row_prep","called\n"));
netsnmp_assert(NULL != rowreq_ctx);
/*
* TODO:390:o: Prepare row for request.
* If populating row data was delayed, this is the place to
* fill in the row for this request.
*/
return MFD_SUCCESS;
} /* sessionTable_row_prep */
/** @} */
/*
* Note: this file originally auto-generated by mib2c using
* version : 14170 $ of $
*
* $Id:$
*/
#ifndef SESSIONTABLE_DATA_ACCESS_H
#define SESSIONTABLE_DATA_ACCESS_H
#ifdef __cplusplus
extern "C" {
#endif
/* *********************************************************************
* function declarations
*/
/* *********************************************************************
* Table declarations
*/
/**********************************************************************
**********************************************************************
***
*** Table sessionTable
***
**********************************************************************
**********************************************************************/
/*
* ACCEL-PPP-MIB::sessionTable is subid 1 of accelPPPSessions.
* Its status is Current.
* OID: .1.3.6.1.4.1.8072.100.2.1, length: 10
*/
int sessionTable_init_data(sessionTable_registration * sessionTable_reg);
/*
* TODO:180:o: Review sessionTable cache timeout.
* The number of seconds before the cache times out
*/
#define SESSIONTABLE_CACHE_TIMEOUT 60
void sessionTable_container_init(netsnmp_container **container_ptr_ptr,
netsnmp_cache *cache);
void sessionTable_container_shutdown(netsnmp_container *container_ptr);
int sessionTable_container_load(netsnmp_container *container);
void sessionTable_container_free(netsnmp_container *container);
int sessionTable_cache_load(netsnmp_container *container);
void sessionTable_cache_free(netsnmp_container *container);
/*
***************************************************
*** START EXAMPLE CODE ***
***---------------------------------------------***/
/* *********************************************************************
* Since we have no idea how you really access your data, we'll go with
* a worst case example: a flat text file.
*/
#define MAX_LINE_SIZE 256
/*
***---------------------------------------------***
*** END EXAMPLE CODE ***
***************************************************/
int sessionTable_row_prep( sessionTable_rowreq_ctx *rowreq_ctx);
#ifdef __cplusplus
}
#endif
#endif /* SESSIONTABLE_DATA_ACCESS_H */
此差异已折叠。
/*
* Note: this file originally auto-generated by mib2c using
* version : 12088 $ of $
*
* $Id:$
*
* @file sessionTable_data_get.h
*
* @addtogroup get
*
* Prototypes for get functions
*
* @{
*/
#ifndef SESSIONTABLE_DATA_GET_H
#define SESSIONTABLE_DATA_GET_H
#ifdef __cplusplus
extern "C" {
#endif
/* *********************************************************************
* GET function declarations
*/
/* *********************************************************************
* GET Table declarations
*/
/**********************************************************************
**********************************************************************
***
*** Table sessionTable
***
**********************************************************************
**********************************************************************/
/*
* ACCEL-PPP-MIB::sessionTable is subid 1 of accelPPPSessions.
* Its status is Current.
* OID: .1.3.6.1.4.1.8072.100.2.1, length: 10
*/
/*
* indexes
*/
int sesIfName_get( sessionTable_rowreq_ctx *rowreq_ctx, char **sesIfName_val_ptr_ptr, size_t *sesIfName_val_ptr_len_ptr );
int sesUsername_get( sessionTable_rowreq_ctx *rowreq_ctx, char **sesUsername_val_ptr_ptr, size_t *sesUsername_val_ptr_len_ptr );
int sesIP_get( sessionTable_rowreq_ctx *rowreq_ctx, char **sesIP_val_ptr_ptr, size_t *sesIP_val_ptr_len_ptr );
int sesType_get( sessionTable_rowreq_ctx *rowreq_ctx, u_long * sesType_val_ptr );
int sesState_get( sessionTable_rowreq_ctx *rowreq_ctx, u_long * sesState_val_ptr );
int sesUptime_get( sessionTable_rowreq_ctx *rowreq_ctx, u_long * sesUptime_val_ptr );
int sesCallingSID_get( sessionTable_rowreq_ctx *rowreq_ctx, char **sesCallingSID_val_ptr_ptr, size_t *sesCallingSID_val_ptr_len_ptr );
int sesCalledSID_get( sessionTable_rowreq_ctx *rowreq_ctx, char **sesCalledSID_val_ptr_ptr, size_t *sesCalledSID_val_ptr_len_ptr );
int sessionTable_indexes_set_tbl_idx(sessionTable_mib_index *tbl_idx, char *sesSID_val_ptr, size_t sesSID_val_ptr_len);
int sessionTable_indexes_set(sessionTable_rowreq_ctx *rowreq_ctx, char *sesSID_val_ptr, size_t sesSID_val_ptr_len);
#ifdef __cplusplus
}
#endif
#endif /* SESSIONTABLE_DATA_GET_H */
/** @} */
/*
* Note: this file originally auto-generated by mib2c using
* version : 12077 $ of $
*
* $Id:$
*
*/
/* standard Net-SNMP includes */
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
/* include our parent header */
#include "sessionTable.h"
/** @defgroup data_set data_set: Routines to set data
*
* These routines are used to set the value for individual objects. The
* row context is passed, along with the new value.
*
* @{
*/
/** @} */
/*
* Note: this file originally auto-generated by mib2c using
* version : 12077 $ of $
*
* $Id:$
*/
#ifndef SESSIONTABLE_DATA_SET_H
#define SESSIONTABLE_DATA_SET_H
#ifdef __cplusplus
extern "C" {
#endif
/* *********************************************************************
* SET function declarations
*/
/* *********************************************************************
* SET Table declarations
*/
#ifdef __cplusplus
}
#endif
#endif /* SESSIONTABLE_DATA_SET_H */
/*
* Note: this file originally auto-generated by mib2c using
* : generic-table-enums.m2c 12526 2005-07-15 22:41:16Z rstory $
*
* $Id:$
*/
#ifndef SESSIONTABLE_ENUMS_H
#define SESSIONTABLE_ENUMS_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* NOTES on enums
* ==============
*
* Value Mapping
* -------------
* If the values for your data type don't exactly match the
* possible values defined by the mib, you should map them
* below. For example, a boolean flag (1/0) is usually represented
* as a TruthValue in a MIB, which maps to the values (1/2).
*
*/
/*************************************************************************
*************************************************************************
*
* enum definitions for table sessionTable
*
*************************************************************************
*************************************************************************/
/*************************************************************
* constants for enums for the MIB node
* sesType (IANAtunnelType / ASN_INTEGER)
*
* since a Textual Convention may be referenced more than once in a
* MIB, protect againt redefinitions of the enum values.
*/
#ifndef IANATUNNELTYPE_ENUMS
#define IANATUNNELTYPE_ENUMS
#define IANATUNNELTYPE_OTHER 1
#define IANATUNNELTYPE_DIRECT 2
#define IANATUNNELTYPE_GRE 3
#define IANATUNNELTYPE_MINIMAL 4
#define IANATUNNELTYPE_L2TP 5
#define IANATUNNELTYPE_PPTP 6
#define IANATUNNELTYPE_L2F 7
#define IANATUNNELTYPE_UDP 8
#define IANATUNNELTYPE_ATMP 9
#define IANATUNNELTYPE_MSDP 10
#define IANATUNNELTYPE_SIXTOFOUR 11
#define IANATUNNELTYPE_SIXOVERFOUR 12
#define IANATUNNELTYPE_ISATAP 13
#define IANATUNNELTYPE_TEREDO 14
#endif /* IANATUNNELTYPE_ENUMS */
/*************************************************************
* constants for enums for the MIB node
* sesState (INTEGER / ASN_INTEGER)
*
* since a Textual Convention may be referenced more than once in a
* MIB, protect againt redefinitions of the enum values.
*/
#ifndef SESSTATE_ENUMS
#define SESSTATE_ENUMS
#define SESSTATE_STARTING 1
#define SESSTATE_ACTIVE 2
#define SESSTATE_FINISHING 3
#endif /* SESSTATE_ENUMS */
#ifdef __cplusplus
}
#endif
#endif /* SESSIONTABLE_ENUMS_H */
此差异已折叠。
/*
* Note: this file originally auto-generated by mib2c using
* version : 15899 $ of $
*
* $Id:$
*/
/** @ingroup interface: Routines to interface to Net-SNMP
*
* \warning This code should not be modified, called directly,
* or used to interpret functionality. It is subject to
* change at any time.
*
* @{
*/
/*
* *********************************************************************
* *********************************************************************
* *********************************************************************
* *** ***
* *** NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE ***
* *** ***
* *** ***
* *** THIS FILE DOES NOT CONTAIN ANY USER EDITABLE CODE. ***
* *** ***
* *** ***
* *** THE GENERATED CODE IS INTERNAL IMPLEMENTATION, AND ***
* *** ***
* *** ***
* *** IS SUBJECT TO CHANGE WITHOUT WARNING IN FUTURE RELEASES. ***
* *** ***
* *** ***
* *********************************************************************
* *********************************************************************
* *********************************************************************
*/
#ifndef SESSIONTABLE_INTERFACE_H
#define SESSIONTABLE_INTERFACE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "sessionTable.h"
/* ********************************************************************
* Table declarations
*/
/* PUBLIC interface initialization routine */
void _sessionTable_initialize_interface(sessionTable_registration * user_ctx,
u_long flags);
void _sessionTable_shutdown_interface(sessionTable_registration * user_ctx);
sessionTable_registration *
sessionTable_registration_get( void );
sessionTable_registration *
sessionTable_registration_set( sessionTable_registration * newreg );
netsnmp_container *sessionTable_container_get( void );
int sessionTable_container_size( void );
sessionTable_rowreq_ctx * sessionTable_allocate_rowreq_ctx(sessionTable_data *, void *);
void sessionTable_release_rowreq_ctx(sessionTable_rowreq_ctx *rowreq_ctx);
int sessionTable_index_to_oid(netsnmp_index *oid_idx,
sessionTable_mib_index *mib_idx);
int sessionTable_index_from_oid(netsnmp_index *oid_idx,
sessionTable_mib_index *mib_idx);
/*
* access to certain internals. use with caution!
*/
void sessionTable_valid_columns_set(netsnmp_column_info *vc);
#ifdef __cplusplus
}
#endif
#endif /* SESSIONTABLE_INTERFACE_H */
/** @} */
/*
* Note: this file originally auto-generated by mib2c using
* : generic-table-oids.m2c 12855 2005-09-27 15:56:08Z rstory $
*
* $Id:$
*/
#ifndef SESSIONTABLE_OIDS_H
#define SESSIONTABLE_OIDS_H
#ifdef __cplusplus
extern "C" {
#endif
/* column number definitions for table sessionTable */
#define SESSIONTABLE_OID 1,3,6,1,4,1,8072,100,2,1
#define COLUMN_SESSID 1
#define COLUMN_SESIFNAME 2
#define COLUMN_SESUSERNAME 3
#define COLUMN_SESIP 4
#define COLUMN_SESTYPE 5
#define COLUMN_SESSTATE 6
#define COLUMN_SESUPTIME 7
#define COLUMN_SESCALLINGSID 8
#define COLUMN_SESCALLEDSID 9
#define SESSIONTABLE_MIN_COL COLUMN_SESSID
#define SESSIONTABLE_MAX_COL COLUMN_SESCALLEDSID
#ifdef __cplusplus
}
#endif
#endif /* SESSIONTABLE_OIDS_H */
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.scalar.conf 11805 2005-01-07 09:37:18Z dts12 $
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "shutdown.h"
/** Initializes the shutdown module */
void
init_shutdown(void)
{
static oid shutdown_oid[] = { 1,3,6,1,4,1,8072,100,3,2 };
DEBUGMSGTL(("shutdown", "Initializing\n"));
netsnmp_register_scalar(
netsnmp_create_handler_registration("shutdown", handle_shutdown,
shutdown_oid, OID_LENGTH(shutdown_oid),
HANDLER_CAN_RWRITE
));
}
int
handle_shutdown(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
int ret;
/* 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
we don't need to loop over a list of requests; we'll only get one. */
switch(reqinfo->mode) {
case MODE_GET:
netsnmp_set_request_error(reqinfo, requests, SNMP_NOSUCHINSTANCE );
break;
/*
* SET REQUEST
*
* multiple states in the transaction. See:
* http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
*/
case MODE_SET_RESERVE1:
/* or you could use netsnmp_check_vb_type_and_size instead */
ret = netsnmp_check_vb_type(requests->requestvb, ASN_INTEGER);
if ( ret != SNMP_ERR_NOERROR ) {
netsnmp_set_request_error(reqinfo, requests, ret );
}
break;
case MODE_SET_RESERVE2:
/* XXX malloc "undo" storage buffer */
break;
case MODE_SET_FREE:
/* XXX: free resources allocated in RESERVE1 and/or
RESERVE2. Something failed somewhere, and the states
below won't be called. */
break;
case MODE_SET_ACTION:
/* XXX: perform the value change here */
break;
case MODE_SET_COMMIT:
/* XXX: delete temporary storage */
break;
case MODE_SET_UNDO:
/* XXX: UNDO and return to previous value for the object */
break;
default:
/* we should never get here, so this is a really bad error */
snmp_log(LOG_ERR, "unknown mode (%d) in handle_shutdown\n", reqinfo->mode );
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.scalar.conf 11805 2005-01-07 09:37:18Z dts12 $
*/
#ifndef SHUTDOWN_H
#define SHUTDOWN_H
/* function declarations */
void init_shutdown(void);
Netsnmp_Node_Handler handle_shutdown;
#endif /* SHUTDOWN_H */
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.scalar.conf 11805 2005-01-07 09:37:18Z dts12 $
*/
#include <time.h>
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "triton.h"
#include "statCore.h"
/** Initializes the statCore module */
void
init_statCore(void)
{
static oid statCoreUpTime_oid[] = { 1,3,6,1,4,1,8072,100,1,1,1 };
static oid statCoreCPU_oid[] = { 1,3,6,1,4,1,8072,100,1,1,2 };
static oid statCoreMemRss_oid[] = { 1,3,6,1,4,1,8072,100,1,1,3 };
DEBUGMSGTL(("statCore", "Initializing\n"));
netsnmp_register_scalar(
netsnmp_create_handler_registration("statCoreUpTime", handle_statCoreUpTime,
statCoreUpTime_oid, OID_LENGTH(statCoreUpTime_oid),
HANDLER_CAN_RONLY
));
netsnmp_register_scalar(
netsnmp_create_handler_registration("statCoreCPU", handle_statCoreCPU,
statCoreCPU_oid, OID_LENGTH(statCoreCPU_oid),
HANDLER_CAN_RONLY
));
netsnmp_register_scalar(
netsnmp_create_handler_registration("statCoreMemRss", handle_statCoreMemRss,
statCoreMemRss_oid, OID_LENGTH(statCoreMemRss_oid),
HANDLER_CAN_RONLY
));
}
int
handle_statCoreUpTime(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
ts.tv_sec -= triton_stat.start_time;
/* 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
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_GAUGE,
(u_char *)&ts.tv_sec /* XXX: a pointer to the scalar's data */,
sizeof(ts.tv_sec)/* XXX: the length of the data in bytes */);
break;
default:
/* we should never get here, so this is a really bad error */
snmp_log(LOG_ERR, "unknown mode (%d) in handle_statCoreUpTime\n", reqinfo->mode );
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
int
handle_statCoreCPU(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
"instance", as it's "magically" handled for us. */
/* 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 *)&triton_stat.cpu /* XXX: a pointer to the scalar's data */,
sizeof(triton_stat.cpu)/* XXX: the length of the data in bytes */);
break;
default:
/* we should never get here, so this is a really bad error */
snmp_log(LOG_ERR, "unknown mode (%d) in handle_statCoreCPU\n", reqinfo->mode );
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
int
handle_statCoreMemRss(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
char statm_fname[128];
FILE *f;
unsigned long vmsize = 0, vmrss = 0;
unsigned long page_size = sysconf(_SC_PAGE_SIZE);
sprintf(statm_fname, "/proc/%i/statm", getpid());
f = fopen(statm_fname, "r");
if (f) {
fscanf(f, "%lu %lu", &vmsize, &vmrss);
fclose(f);
}
vmrss *= page_size;
/* 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
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 *)&vmrss /* XXX: a pointer to the scalar's data */,
sizeof(vmrss)/* XXX: the length of the data in bytes */);
break;
default:
/* we should never get here, so this is a really bad error */
snmp_log(LOG_ERR, "unknown mode (%d) in handle_statCoreMemRss\n", reqinfo->mode );
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.scalar.conf 11805 2005-01-07 09:37:18Z dts12 $
*/
#ifndef STATCORE_H
#define STATCORE_H
/* function declarations */
void init_statCore(void);
Netsnmp_Node_Handler handle_statCoreUpTime;
Netsnmp_Node_Handler handle_statCoreCPU;
Netsnmp_Node_Handler handle_statCoreMemRss;
#endif /* STATCORE_H */
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.int_watch.conf 13957 2005-12-20 15:33:08Z tanders $
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "triton.h"
#include "statL2TP.h"
/*
* The variables we want to tie the relevant OIDs to.
* The agent will handle all GET and (if applicable) SET requests
* to these variables automatically, changing the values as needed.
*/
void l2tp_get_stat(unsigned int **, unsigned int **);
static unsigned int *stat_starting;
static unsigned int *stat_active;
/*
* Our initialization routine, called automatically by the agent
* (Note that the function name must match init_FILENAME())
*/
void
init_statL2TP(void)
{
netsnmp_handler_registration *reg;
netsnmp_watcher_info *winfo;
static oid statL2TPStarting_oid[] = { 1,3,6,1,4,1,8072,100,1,4,1 };
static oid statL2TPActive_oid[] = { 1,3,6,1,4,1,8072,100,1,4,2 };
/*
* a debugging statement. Run the agent with -DstatL2TP to see
* the output of this debugging statement.
*/
DEBUGMSGTL(("statL2TP", "Initializing the statL2TP module\n"));
if (!triton_module_loaded("l2tp"))
return;
l2tp_get_stat(&stat_starting, &stat_active);
/*
* Register scalar watchers for each of the MIB objects.
* The ASN type and RO/RW status are taken from the MIB definition,
* but can be adjusted if needed.
*
* In most circumstances, the scalar watcher will handle all
* of the necessary processing. But the NULL parameter in the
* netsnmp_create_handler_registration() call can be used to
* supply a user-provided handler if necessary.
*
* This approach can also be used to handle Counter64, string-
* and OID-based watched scalars (although variable-sized writeable
* objects will need some more specialised initialisation).
*/
DEBUGMSGTL(("statL2TP",
"Initializing statL2TPStarting scalar integer. Default value = %d\n",
0));
reg = netsnmp_create_handler_registration(
"statL2TPStarting", NULL,
statL2TPStarting_oid, OID_LENGTH(statL2TPStarting_oid),
HANDLER_CAN_RONLY);
winfo = netsnmp_create_watcher_info(
stat_starting, sizeof(*stat_starting),
ASN_INTEGER, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) {
snmp_log( LOG_ERR, "Failed to register watched statL2TPStarting" );
}
DEBUGMSGTL(("statL2TP",
"Initializing statL2TPActive scalar integer. Default value = %d\n",
0));
reg = netsnmp_create_handler_registration(
"statL2TPActive", NULL,
statL2TPActive_oid, OID_LENGTH(statL2TPActive_oid),
HANDLER_CAN_RONLY);
winfo = netsnmp_create_watcher_info(
stat_active, sizeof(*stat_active),
ASN_INTEGER, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) {
snmp_log( LOG_ERR, "Failed to register watched statL2TPActive" );
}
DEBUGMSGTL(("statL2TP",
"Done initalizing statL2TP module\n"));
}
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.int_watch.conf 13957 2005-12-20 15:33:08Z tanders $
*/
#ifndef STATL2TP_H
#define STATL2TP_H
/* function declarations */
void init_statL2TP(void);
#endif /* STATL2TP_H */
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.int_watch.conf 13957 2005-12-20 15:33:08Z tanders $
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "statPPP.h"
#include "ppp.h"
/*
* Our initialization routine, called automatically by the agent
* (Note that the function name must match init_FILENAME())
*/
void
init_statPPP(void)
{
netsnmp_handler_registration *reg;
netsnmp_watcher_info *winfo;
static oid statPPPStarting_oid[] = { 1,3,6,1,4,1,8072,100,1,2,1 };
static oid statPPPActive_oid[] = { 1,3,6,1,4,1,8072,100,1,2,2 };
static oid statPPPFinishing_oid[] = { 1,3,6,1,4,1,8072,100,1,2,3 };
/*
* a debugging statement. Run the agent with -DstatPPP to see
* the output of this debugging statement.
*/
DEBUGMSGTL(("statPPP", "Initializing the statPPP module\n"));
/*
* Register scalar watchers for each of the MIB objects.
* The ASN type and RO/RW status are taken from the MIB definition,
* but can be adjusted if needed.
*
* In most circumstances, the scalar watcher will handle all
* of the necessary processing. But the NULL parameter in the
* netsnmp_create_handler_registration() call can be used to
* supply a user-provided handler if necessary.
*
* This approach can also be used to handle Counter64, string-
* and OID-based watched scalars (although variable-sized writeable
* objects will need some more specialised initialisation).
*/
DEBUGMSGTL(("statPPP",
"Initializing statPPPStarting scalar integer. Default value = %d\n",
0));
reg = netsnmp_create_handler_registration(
"statPPPStarting", NULL,
statPPPStarting_oid, OID_LENGTH(statPPPStarting_oid),
HANDLER_CAN_RONLY);
winfo = netsnmp_create_watcher_info(
&ppp_stat.starting, sizeof(ppp_stat.starting),
ASN_INTEGER, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) {
snmp_log( LOG_ERR, "Failed to register watched statPPPStarting" );
}
DEBUGMSGTL(("statPPP",
"Initializing statPPPActive scalar integer. Default value = %d\n",
0));
reg = netsnmp_create_handler_registration(
"statPPPActive", NULL,
statPPPActive_oid, OID_LENGTH(statPPPActive_oid),
HANDLER_CAN_RONLY);
winfo = netsnmp_create_watcher_info(
&ppp_stat.active, sizeof(ppp_stat.active),
ASN_INTEGER, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) {
snmp_log( LOG_ERR, "Failed to register watched statPPPActive" );
}
DEBUGMSGTL(("statPPP",
"Initializing statPPPFinishing scalar integer. Default value = %d\n",
0));
reg = netsnmp_create_handler_registration(
"statPPPFinishing", NULL,
statPPPFinishing_oid, OID_LENGTH(statPPPFinishing_oid),
HANDLER_CAN_RONLY);
winfo = netsnmp_create_watcher_info(
&ppp_stat.finishing, sizeof(ppp_stat.finishing),
ASN_INTEGER, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) {
snmp_log( LOG_ERR, "Failed to register watched statPPPFinishing" );
}
DEBUGMSGTL(("statPPP",
"Done initalizing statPPP module\n"));
}
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.int_watch.conf 13957 2005-12-20 15:33:08Z tanders $
*/
#ifndef STATPPP_H
#define STATPPP_H
/* function declarations */
void init_statPPP(void);
#endif /* STATPPP_H */
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.int_watch.conf 13957 2005-12-20 15:33:08Z tanders $
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "triton.h"
#include "statPPPOE.h"
/*
* The variables we want to tie the relevant OIDs to.
* The agent will handle all GET and (if applicable) SET requests
* to these variables automatically, changing the values as needed.
*/
void pppoe_get_stat(unsigned int **, unsigned int **);
static unsigned int *stat_starting;
static unsigned int *stat_active;
/*
* Our initialization routine, called automatically by the agent
* (Note that the function name must match init_FILENAME())
*/
void
init_statPPPOE(void)
{
netsnmp_handler_registration *reg;
netsnmp_watcher_info *winfo;
static oid statPPPOEStarting_oid[] = { 1,3,6,1,4,1,8072,100,1,5,1 };
static oid statPPPOEActive_oid[] = { 1,3,6,1,4,1,8072,100,1,5,2 };
/*
* a debugging statement. Run the agent with -DstatPPPOE to see
* the output of this debugging statement.
*/
DEBUGMSGTL(("statPPPOE", "Initializing the statPPPOE module\n"));
if (!triton_module_loaded("pppoe"))
return;
pppoe_get_stat(&stat_starting, &stat_active);
/*
* Register scalar watchers for each of the MIB objects.
* The ASN type and RO/RW status are taken from the MIB definition,
* but can be adjusted if needed.
*
* In most circumstances, the scalar watcher will handle all
* of the necessary processing. But the NULL parameter in the
* netsnmp_create_handler_registration() call can be used to
* supply a user-provided handler if necessary.
*
* This approach can also be used to handle Counter64, string-
* and OID-based watched scalars (although variable-sized writeable
* objects will need some more specialised initialisation).
*/
DEBUGMSGTL(("statPPPOE",
"Initializing statPPPOEStarting scalar integer. Default value = %d\n",
0));
reg = netsnmp_create_handler_registration(
"statPPPOEStarting", NULL,
statPPPOEStarting_oid, OID_LENGTH(statPPPOEStarting_oid),
HANDLER_CAN_RONLY);
winfo = netsnmp_create_watcher_info(
stat_starting, sizeof(*stat_starting),
ASN_INTEGER, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) {
snmp_log( LOG_ERR, "Failed to register watched statPPPOEStarting" );
}
DEBUGMSGTL(("statPPPOE",
"Initializing statPPPOEActive scalar integer. Default value = %d\n",
0));
reg = netsnmp_create_handler_registration(
"statPPPOEActive", NULL,
statPPPOEActive_oid, OID_LENGTH(statPPPOEActive_oid),
HANDLER_CAN_RONLY);
winfo = netsnmp_create_watcher_info(
stat_active, sizeof(*stat_active),
ASN_INTEGER, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) {
snmp_log( LOG_ERR, "Failed to register watched statPPPOEActive" );
}
DEBUGMSGTL(("statPPPOE",
"Done initalizing statPPPOE module\n"));
}
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.int_watch.conf 13957 2005-12-20 15:33:08Z tanders $
*/
#ifndef STATPPPOE_H
#define STATPPPOE_H
/* function declarations */
void init_statPPPOE(void);
#endif /* STATPPPOE_H */
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.int_watch.conf 13957 2005-12-20 15:33:08Z tanders $
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "statPPTP.h"
#include "triton.h"
/*
* The variables we want to tie the relevant OIDs to.
* The agent will handle all GET and (if applicable) SET requests
* to these variables automatically, changing the values as needed.
*/
void pptp_get_stat(unsigned int **, unsigned int **);
static unsigned int *stat_starting;
static unsigned int *stat_active;
/*
* Our initialization routine, called automatically by the agent
* (Note that the function name must match init_FILENAME())
*/
void
init_statPPTP(void)
{
netsnmp_handler_registration *reg;
netsnmp_watcher_info *winfo;
static oid statPPTPStarting_oid[] = { 1,3,6,1,4,1,8072,100,1,3,1 };
static oid statPPTPActive_oid[] = { 1,3,6,1,4,1,8072,100,1,3,2 };
/*
* a debugging statement. Run the agent with -DstatPPTP to see
* the output of this debugging statement.
*/
DEBUGMSGTL(("statPPTP", "Initializing the statPPTP module\n"));
if (!triton_module_loaded("pptp"))
return;
pptp_get_stat(&stat_starting, &stat_active);
/*
* Register scalar watchers for each of the MIB objects.
* The ASN type and RO/RW status are taken from the MIB definition,
* but can be adjusted if needed.
*
* In most circumstances, the scalar watcher will handle all
* of the necessary processing. But the NULL parameter in the
* netsnmp_create_handler_registration() call can be used to
* supply a user-provided handler if necessary.
*
* This approach can also be used to handle Counter64, string-
* and OID-based watched scalars (although variable-sized writeable
* objects will need some more specialised initialisation).
*/
DEBUGMSGTL(("statPPTP",
"Initializing statPPTPStarting scalar integer. Default value = %d\n",
0));
reg = netsnmp_create_handler_registration(
"statPPTPStarting", NULL,
statPPTPStarting_oid, OID_LENGTH(statPPTPStarting_oid),
HANDLER_CAN_RONLY);
winfo = netsnmp_create_watcher_info(
stat_starting, sizeof(*stat_starting),
ASN_INTEGER, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) {
snmp_log( LOG_ERR, "Failed to register watched statPPTPStarting" );
}
DEBUGMSGTL(("statPPTP",
"Initializing statPPTPActive scalar integer. Default value = %d\n",
0));
reg = netsnmp_create_handler_registration(
"statPPTPActive", NULL,
statPPTPActive_oid, OID_LENGTH(statPPTPActive_oid),
HANDLER_CAN_RONLY);
winfo = netsnmp_create_watcher_info(
stat_active, sizeof(*stat_active),
ASN_INTEGER, WATCHER_FIXED_SIZE);
if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) {
snmp_log( LOG_ERR, "Failed to register watched statPPTPActive" );
}
DEBUGMSGTL(("statPPTP",
"Done initalizing statPPTP module\n"));
}
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.int_watch.conf 13957 2005-12-20 15:33:08Z tanders $
*/
#ifndef STATPPTP_H
#define STATPPTP_H
/* function declarations */
void init_statPPTP(void);
#endif /* STATPPTP_H */
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.scalar.conf 11805 2005-01-07 09:37:18Z dts12 $
*/
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "triton.h"
#include "ppp.h"
#include "terminate.h"
static void __terminate(struct ppp_t *ppp)
{
ppp_terminate(ppp, TERM_ADMIN_RESET, 0);
}
static void terminate_by_sid(const char *val)
{
struct ppp_t *ppp;
pthread_rwlock_rdlock(&ppp_lock);
list_for_each_entry(ppp, &ppp_list, entry) {
if (strncmp(ppp->sessionid, val, PPP_SESSIONID_LEN))
continue;
triton_context_call(ppp->ctrl->ctx, (triton_event_func)__terminate, ppp);
break;
}
pthread_rwlock_unlock(&ppp_lock);
}
static void terminate_by_ifname(const char *val, size_t len)
{
struct ppp_t *ppp;
size_t n;
pthread_rwlock_rdlock(&ppp_lock);
list_for_each_entry(ppp, &ppp_list, entry) {
n = strlen(ppp->ifname);
if (n != len)
continue;
if (strncmp(ppp->ifname, val, len))
continue;
triton_context_call(ppp->ctrl->ctx, (triton_event_func)__terminate, ppp);
break;
}
pthread_rwlock_unlock(&ppp_lock);
}
static void terminate_by_ip(const char *val, size_t len)
{
char str[len + 1];
in_addr_t addr;
struct ppp_t *ppp;
strncpy(str, val, len);
str[len] = 0;
addr = inet_addr(str);
pthread_rwlock_rdlock(&ppp_lock);
list_for_each_entry(ppp, &ppp_list, entry) {
if (ppp->peer_ipaddr != addr)
continue;
triton_context_call(ppp->ctrl->ctx, (triton_event_func)__terminate, ppp);
break;
}
pthread_rwlock_unlock(&ppp_lock);
}
static void terminate_by_username(const char *val, size_t len)
{
struct ppp_t *ppp;
size_t n;
pthread_rwlock_rdlock(&ppp_lock);
list_for_each_entry(ppp, &ppp_list, entry) {
if (!ppp->username)
continue;
n = strlen(ppp->username);
if (n != len)
continue;
if (strncmp(ppp->username, val, len))
continue;
triton_context_call(ppp->ctrl->ctx, (triton_event_func)__terminate, ppp);
}
pthread_rwlock_unlock(&ppp_lock);
}
/** Initializes the terminate module */
void
init_terminate(void)
{
static oid termBySID_oid[] = { 1,3,6,1,4,1,8072,100,3,1,1 };
static oid termByIfName_oid[] = { 1,3,6,1,4,1,8072,100,3,1,2 };
static oid termByIP_oid[] = { 1,3,6,1,4,1,8072,100,3,1,3 };
static oid termByUsername_oid[] = { 1,3,6,1,4,1,8072,100,3,1,4 };
DEBUGMSGTL(("terminate", "Initializing\n"));
netsnmp_register_scalar(
netsnmp_create_handler_registration("termBySID", handle_termBySID,
termBySID_oid, OID_LENGTH(termBySID_oid),
HANDLER_CAN_RWRITE
));
netsnmp_register_scalar(
netsnmp_create_handler_registration("termByIfName", handle_termByIfName,
termByIfName_oid, OID_LENGTH(termByIfName_oid),
HANDLER_CAN_RWRITE
));
netsnmp_register_scalar(
netsnmp_create_handler_registration("termByIP", handle_termByIP,
termByIP_oid, OID_LENGTH(termByIP_oid),
HANDLER_CAN_RWRITE
));
netsnmp_register_scalar(
netsnmp_create_handler_registration("termByUsername", handle_termByUsername,
termByUsername_oid, OID_LENGTH(termByUsername_oid),
HANDLER_CAN_RWRITE
));
}
int
handle_termBySID(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
int ret;
/* 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
we don't need to loop over a list of requests; we'll only get one. */
switch(reqinfo->mode) {
case MODE_GET:
netsnmp_set_request_error(reqinfo, requests, SNMP_NOSUCHINSTANCE );
break;
/*
* SET REQUEST
*
* multiple states in the transaction. See:
* http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
*/
case MODE_SET_RESERVE1:
/* or you could use netsnmp_check_vb_type_and_size instead */
ret = netsnmp_check_vb_type_and_size(requests->requestvb, ASN_OCTET_STR, PPP_SESSIONID_LEN);
if ( ret != SNMP_ERR_NOERROR ) {
netsnmp_set_request_error(reqinfo, requests, ret );
}
break;
case MODE_SET_RESERVE2:
break;
case MODE_SET_FREE:
/* XXX: free resources allocated in RESERVE1 and/or
RESERVE2. Something failed somewhere, and the states
below won't be called. */
break;
case MODE_SET_ACTION:
terminate_by_sid((char *)requests->requestvb->val.string);
/* XXX: perform the value change here */
break;
case MODE_SET_COMMIT:
break;
case MODE_SET_UNDO:
break;
default:
/* we should never get here, so this is a really bad error */
snmp_log(LOG_ERR, "unknown mode (%d) in handle_termBySID\n", reqinfo->mode );
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
int
handle_termByIfName(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
int ret;
/* 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
we don't need to loop over a list of requests; we'll only get one. */
switch(reqinfo->mode) {
case MODE_GET:
netsnmp_set_request_error(reqinfo, requests, SNMP_NOSUCHINSTANCE );
break;
/*
* SET REQUEST
*
* multiple states in the transaction. See:
* http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
*/
case MODE_SET_RESERVE1:
/* or you could use netsnmp_check_vb_type_and_size instead */
ret = netsnmp_check_vb_type(requests->requestvb, ASN_OCTET_STR);
if ( ret != SNMP_ERR_NOERROR ) {
netsnmp_set_request_error(reqinfo, requests, ret );
}
break;
case MODE_SET_RESERVE2:
/* XXX malloc "undo" storage buffer */
break;
case MODE_SET_FREE:
/* XXX: free resources allocated in RESERVE1 and/or
RESERVE2. Something failed somewhere, and the states
below won't be called. */
break;
case MODE_SET_ACTION:
terminate_by_ifname((char *)requests->requestvb->val.string, requests->requestvb->val_len);
/* XXX: perform the value change here */
break;
case MODE_SET_COMMIT:
break;
case MODE_SET_UNDO:
break;
default:
/* we should never get here, so this is a really bad error */
snmp_log(LOG_ERR, "unknown mode (%d) in handle_termByIfName\n", reqinfo->mode );
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
int
handle_termByIP(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
int ret;
/* 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
we don't need to loop over a list of requests; we'll only get one. */
switch(reqinfo->mode) {
case MODE_GET:
netsnmp_set_request_error(reqinfo, requests, SNMP_NOSUCHINSTANCE );
break;
/*
* SET REQUEST
*
* multiple states in the transaction. See:
* http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
*/
case MODE_SET_RESERVE1:
/* or you could use netsnmp_check_vb_type_and_size instead */
ret = netsnmp_check_vb_type(requests->requestvb, ASN_OCTET_STR);
if ( ret != SNMP_ERR_NOERROR ) {
netsnmp_set_request_error(reqinfo, requests, ret );
}
break;
case MODE_SET_RESERVE2:
/* XXX malloc "undo" storage buffer */
break;
case MODE_SET_FREE:
/* XXX: free resources allocated in RESERVE1 and/or
RESERVE2. Something failed somewhere, and the states
below won't be called. */
break;
case MODE_SET_ACTION:
terminate_by_ip((char *)requests->requestvb->val.string, requests->requestvb->val_len);
/* XXX: perform the value change here */
break;
case MODE_SET_COMMIT:
/* XXX: delete temporary storage */
break;
case MODE_SET_UNDO:
/* XXX: UNDO and return to previous value for the object */
break;
default:
/* we should never get here, so this is a really bad error */
snmp_log(LOG_ERR, "unknown mode (%d) in handle_termByIP\n", reqinfo->mode );
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
int
handle_termByUsername(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
int ret;
/* 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
we don't need to loop over a list of requests; we'll only get one. */
switch(reqinfo->mode) {
case MODE_GET:
netsnmp_set_request_error(reqinfo, requests, SNMP_NOSUCHINSTANCE );
break;
/*
* SET REQUEST
*
* multiple states in the transaction. See:
* http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
*/
case MODE_SET_RESERVE1:
/* or you could use netsnmp_check_vb_type_and_size instead */
ret = netsnmp_check_vb_type(requests->requestvb, ASN_OCTET_STR);
if ( ret != SNMP_ERR_NOERROR ) {
netsnmp_set_request_error(reqinfo, requests, ret );
}
break;
case MODE_SET_RESERVE2:
/* XXX malloc "undo" storage buffer */
break;
case MODE_SET_FREE:
/* XXX: free resources allocated in RESERVE1 and/or
RESERVE2. Something failed somewhere, and the states
below won't be called. */
break;
case MODE_SET_ACTION:
terminate_by_username((char *)requests->requestvb->val.string, requests->requestvb->val_len);
/* XXX: perform the value change here */
break;
case MODE_SET_COMMIT:
/* XXX: delete temporary storage */
break;
case MODE_SET_UNDO:
/* XXX: UNDO and return to previous value for the object */
break;
default:
/* we should never get here, so this is a really bad error */
snmp_log(LOG_ERR, "unknown mode (%d) in handle_termByUsername\n", reqinfo->mode );
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.scalar.conf 11805 2005-01-07 09:37:18Z dts12 $
*/
#ifndef TERMINATE_H
#define TERMINATE_H
/* function declarations */
void init_terminate(void);
Netsnmp_Node_Handler handle_termBySID;
Netsnmp_Node_Handler handle_termByIfName;
Netsnmp_Node_Handler handle_termByIP;
Netsnmp_Node_Handler handle_termByUsername;
#endif /* TERMINATE_H */
......@@ -16,6 +16,15 @@
#include "memdebug.h"
#define LOG_MSG 0
#define LOG_ERROR 1
#define LOG_WARN 2
#define LOG_INFO1 3
#define LOG_INFO2 4
#define LOG_DEBUG 5
#define LOG_CHUNK_SIZE 128
struct log_pd_t
{
struct ppp_pd_t pd;
......
......@@ -5,14 +5,6 @@
#include <sys/time.h>
#include "list.h"
#define LOG_MSG 0
#define LOG_ERROR 1
#define LOG_WARN 2
#define LOG_INFO1 3
#define LOG_INFO2 4
#define LOG_DEBUG 5
#define LOG_CHUNK_SIZE 128
#define LOG_MAX_SIZE 4096
struct ppp_t;
......
......@@ -44,7 +44,7 @@ static unsigned long long seq;
static spinlock_t seq_lock;
#endif
struct ppp_stat_t ppp_stat;
__export struct ppp_stat_t ppp_stat;
struct layer_node_t
{
......@@ -400,7 +400,7 @@ void __export ppp_layer_started(struct ppp_t *ppp, struct ppp_layer_data_t *d)
list_for_each_entry(d, &n->items, entry) {
d->starting = 1;
if (d->layer->start(d)) {
ppp_terminate(ppp, TERM_NAS_ERROR, 0);
ppp_terminate(ppp, 1, TERM_NAS_ERROR);
return;
}
}
......
......@@ -56,12 +56,16 @@
#define TERM_AUTH_ERROR 8
#define TERM_LOST_CARRIER 9
#define CTRL_TYPE_PPTP 1
#define CTRL_TYPE_L2TP 2
#define CTRL_TYPE_PPPOE 3
struct ppp_t;
struct ppp_ctrl_t
{
struct triton_context_t *ctx;
int type;
const char *name;
int max_mtu;
char *calling_station_id;
......
......@@ -5,6 +5,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <sched.h>
#include <time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
......@@ -20,9 +21,12 @@ static LIST_HEAD(serv_list);
struct rad_server_t *rad_server_get(int type)
{
struct rad_server_t *s, *s0 = NULL;
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
list_for_each_entry(s, &serv_list, entry) {
if (s->fail_time && time(NULL) < s->fail_time)
if (s->fail_time && ts.tv_sec < s->fail_time)
continue;
if (type == 0 && !s->auth_addr)
......@@ -54,12 +58,16 @@ void rad_server_put(struct rad_server_t *s)
int rad_server_req_enter(struct rad_req_t *req)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
if (!req->serv->max_req_cnt)
return 0;
pthread_mutex_lock(&req->serv->lock);
if (time(NULL) < req->serv->fail_time) {
if (ts.tv_sec < req->serv->fail_time) {
pthread_mutex_unlock(&req->serv->lock);
return -1;
}
......@@ -70,7 +78,7 @@ int rad_server_req_enter(struct rad_req_t *req)
triton_context_schedule();
pthread_mutex_lock(&req->serv->lock);
if (time(NULL) < req->serv->fail_time) {
if (ts.tv_sec < req->serv->fail_time) {
pthread_mutex_unlock(&req->serv->lock);
return -1;
}
......@@ -130,13 +138,14 @@ int rad_server_realloc(struct rad_req_t *req, int type)
void rad_server_fail(struct rad_server_t *s)
{
struct rad_req_t *r;
time_t t;
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
pthread_mutex_lock(&s->lock);
t = time(NULL);
if (t > s->fail_time) {
s->fail_time = t + s->conf_fail_time;
if (ts.tv_sec > s->fail_time) {
s->fail_time = ts.tv_sec + s->conf_fail_time;
log_ppp_warn("radius: server not responding\n");
log_warn("radius: server noy responding\n");
}
......
......@@ -38,11 +38,13 @@ struct stat_accm_t *stat_accm_create(unsigned int time)
static void stat_accm_clean(struct stat_accm_t *s)
{
struct item_t *it;
time_t ts = time(NULL);
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
while (!list_empty(&s->items)) {
it = list_entry(s->items.next, typeof(*it), entry);
if (ts - it->ts > s->time) {
if (ts.tv_sec - it->ts > s->time) {
list_del(&it->entry);
--s->items_cnt;
s->total -= it->val;
......@@ -55,13 +57,16 @@ static void stat_accm_clean(struct stat_accm_t *s)
void stat_accm_add(struct stat_accm_t *s, unsigned int val)
{
struct item_t *it;
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
pthread_mutex_lock(&s->lock);
stat_accm_clean(s);
it = mempool_alloc(item_pool);
it->ts = time(NULL);
it->ts = ts.tv_sec;
it->val = val;
list_add_tail(&it->entry, &s->items);
++s->items_cnt;
......
......@@ -517,8 +517,7 @@ static void ru_update(struct triton_timer_t *t)
val = (double)((rusage.ru_utime.tv_sec - ru_utime.tv_sec) * 1000000 + (rusage.ru_utime.tv_usec - ru_utime.tv_usec) +
(rusage.ru_stime.tv_sec - ru_stime.tv_sec) * 1000000 + (rusage.ru_stime.tv_usec - ru_stime.tv_usec)) / dt * 100;
if (val <= 100)
triton_stat.cpu = val;
triton_stat.cpu = val;
ru_timestamp = ts;
ru_utime = rusage.ru_utime;
......@@ -563,6 +562,8 @@ int __export triton_init(const char *conf_file)
if (event_init())
return -1;
triton_context_register(&default_ctx, NULL);
return 0;
}
......@@ -600,6 +601,7 @@ void __export triton_run()
struct _triton_thread_t *t;
int i;
char *opt;
struct timespec ts;
opt = conf_get_opt("core", "thread-count");
if (opt && atoi(opt) > 0)
......@@ -614,12 +616,12 @@ void __export triton_run()
pthread_mutex_unlock(&t->sleep_lock);
}
time(&triton_stat.start_time);
clock_gettime(CLOCK_MONOTONIC, &ts);
triton_stat.start_time = ts.tv_sec;
md_run();
timer_run();
triton_context_register(&default_ctx, NULL);
triton_context_wakeup(&default_ctx);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册