summaryrefslogtreecommitdiff
path: root/accel-pppd/extra
diff options
context:
space:
mode:
authorDenys Fedoryshchenko <denys.f@collabora.com>2026-05-13 21:43:13 +0300
committerGitHub <noreply@github.com>2026-05-13 21:43:13 +0300
commitd611c3240863f79029ab48d492659a67f82465d9 (patch)
tree8171a65c511849b941fbf492514cb5c89918b4e4 /accel-pppd/extra
parent5b78328068085a8dc530978fd0b51f5c187a6aff (diff)
parente5fe0eaa1fc6b1109db784e818e360159d8dd2ac (diff)
downloadaccel-ppp-d611c3240863f79029ab48d492659a67f82465d9.tar.gz
accel-ppp-d611c3240863f79029ab48d492659a67f82465d9.zip
Merge pull request #308 from nuclearcat/stats-rework
stats: improve how we handle statistics in the code
Diffstat (limited to 'accel-pppd/extra')
-rw-r--r--accel-pppd/extra/net-snmp/statCore.c9
-rw-r--r--accel-pppd/extra/net-snmp/statIPOE.c110
-rw-r--r--accel-pppd/extra/net-snmp/statL2TP.c110
-rw-r--r--accel-pppd/extra/net-snmp/statPPP.c145
-rw-r--r--accel-pppd/extra/net-snmp/statPPPOE.c106
-rw-r--r--accel-pppd/extra/net-snmp/statPPTP.c111
-rw-r--r--accel-pppd/extra/net-snmp/statSSTP.c110
7 files changed, 426 insertions, 275 deletions
diff --git a/accel-pppd/extra/net-snmp/statCore.c b/accel-pppd/extra/net-snmp/statCore.c
index c2e64689..7e9047da 100644
--- a/accel-pppd/extra/net-snmp/statCore.c
+++ b/accel-pppd/extra/net-snmp/statCore.c
@@ -49,7 +49,7 @@ handle_statCoreUpTime(netsnmp_mib_handler *handler,
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
- ts.tv_sec -= triton_stat.start_time;
+ 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. */
@@ -80,6 +80,8 @@ handle_statCoreCPU(netsnmp_mib_handler *handler,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
+ long cpu;
+
/* We are never called for a GETNEXT if it's registered as a
"instance", as it's "magically" handled for us. */
@@ -89,9 +91,10 @@ handle_statCoreCPU(netsnmp_mib_handler *handler,
switch(reqinfo->mode) {
case MODE_GET:
+ cpu = triton_stat_cpu();
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 */);
+ (u_char *)&cpu /* XXX: a pointer to the scalar's data */,
+ sizeof(cpu)/* XXX: the length of the data in bytes */);
break;
diff --git a/accel-pppd/extra/net-snmp/statIPOE.c b/accel-pppd/extra/net-snmp/statIPOE.c
index 24f154fd..33430fe6 100644
--- a/accel-pppd/extra/net-snmp/statIPOE.c
+++ b/accel-pppd/extra/net-snmp/statIPOE.c
@@ -8,18 +8,17 @@
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "triton.h"
+#include "accel-pppd/ctrl/ipoe/ipoe.h"
#include "statIPOE.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 ipoe_get_stat(unsigned int **, unsigned int **);
-
-static unsigned int *stat_starting;
-static unsigned int *stat_active;
+static int handle_statIPOEStarting(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests);
+static int handle_statIPOEActive(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests);
/*
* Our initialization routine, called automatically by the agent
@@ -28,9 +27,6 @@ static unsigned int *stat_active;
void
init_statIPOE(void)
{
- netsnmp_handler_registration *reg;
- netsnmp_watcher_info *winfo;
-
static oid statIPOEStarting_oid[] = { 1,3,6,1,4,1,8072,100,1,6,1 };
static oid statIPOEActive_oid[] = { 1,3,6,1,4,1,8072,100,1,6,2 };
@@ -43,51 +39,75 @@ init_statIPOE(void)
if (!triton_module_loaded("ipoe"))
return;
- ipoe_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(("statIPOE",
"Initializing statIPOEStarting scalar integer. Default value = %d\n",
0));
- reg = netsnmp_create_handler_registration(
- "statIPOEStarting", NULL,
+ if (netsnmp_register_scalar(netsnmp_create_handler_registration(
+ "statIPOEStarting", handle_statIPOEStarting,
statIPOEStarting_oid, OID_LENGTH(statIPOEStarting_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 statIPOEStarting" );
+ HANDLER_CAN_RONLY)) < 0 ) {
+ snmp_log( LOG_ERR, "Failed to register statIPOEStarting" );
}
DEBUGMSGTL(("statIPOE",
"Initializing statIPOEActive scalar integer. Default value = %d\n",
0));
- reg = netsnmp_create_handler_registration(
- "statIPOEActive", NULL,
+ if (netsnmp_register_scalar(netsnmp_create_handler_registration(
+ "statIPOEActive", handle_statIPOEActive,
statIPOEActive_oid, OID_LENGTH(statIPOEActive_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 statIPOEActive" );
+ HANDLER_CAN_RONLY)) < 0 ) {
+ snmp_log( LOG_ERR, "Failed to register statIPOEActive" );
}
DEBUGMSGTL(("statIPOE",
"Done initalizing statIPOE module\n"));
}
+
+static int handle_statIPOEStarting(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
+{
+ long stat;
+
+ (void)handler;
+ (void)reginfo;
+
+ switch (reqinfo->mode) {
+ case MODE_GET:
+ stat = ipoe_stat_starting();
+ snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
+ (u_char *)&stat, sizeof(stat));
+ break;
+ default:
+ snmp_log(LOG_ERR, "unknown mode (%d) in handle_statIPOEStarting\n", reqinfo->mode);
+ return SNMP_ERR_GENERR;
+ }
+
+ return SNMP_ERR_NOERROR;
+}
+
+static int handle_statIPOEActive(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
+{
+ long stat;
+
+ (void)handler;
+ (void)reginfo;
+
+ switch (reqinfo->mode) {
+ case MODE_GET:
+ stat = ipoe_stat_active();
+ snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
+ (u_char *)&stat, sizeof(stat));
+ break;
+ default:
+ snmp_log(LOG_ERR, "unknown mode (%d) in handle_statIPOEActive\n", reqinfo->mode);
+ return SNMP_ERR_GENERR;
+ }
+
+ return SNMP_ERR_NOERROR;
+}
diff --git a/accel-pppd/extra/net-snmp/statL2TP.c b/accel-pppd/extra/net-snmp/statL2TP.c
index 59998386..36e6f90b 100644
--- a/accel-pppd/extra/net-snmp/statL2TP.c
+++ b/accel-pppd/extra/net-snmp/statL2TP.c
@@ -8,19 +8,18 @@
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "triton.h"
+#include "accel-pppd/ctrl/l2tp/l2tp.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;
+static int handle_statL2TPStarting(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests);
+static int handle_statL2TPActive(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests);
/*
* Our initialization routine, called automatically by the agent
@@ -29,9 +28,6 @@ static unsigned int *stat_active;
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 };
@@ -44,51 +40,75 @@ init_statL2TP(void)
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,
+ if (netsnmp_register_scalar(netsnmp_create_handler_registration(
+ "statL2TPStarting", handle_statL2TPStarting,
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" );
+ HANDLER_CAN_RONLY)) < 0 ) {
+ snmp_log( LOG_ERR, "Failed to register statL2TPStarting" );
}
DEBUGMSGTL(("statL2TP",
"Initializing statL2TPActive scalar integer. Default value = %d\n",
0));
- reg = netsnmp_create_handler_registration(
- "statL2TPActive", NULL,
+ if (netsnmp_register_scalar(netsnmp_create_handler_registration(
+ "statL2TPActive", handle_statL2TPActive,
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" );
+ HANDLER_CAN_RONLY)) < 0 ) {
+ snmp_log( LOG_ERR, "Failed to register statL2TPActive" );
}
DEBUGMSGTL(("statL2TP",
"Done initalizing statL2TP module\n"));
}
+
+static int handle_statL2TPStarting(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
+{
+ long stat;
+
+ (void)handler;
+ (void)reginfo;
+
+ switch (reqinfo->mode) {
+ case MODE_GET:
+ stat = l2tp_stat_starting();
+ snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
+ (u_char *)&stat, sizeof(stat));
+ break;
+ default:
+ snmp_log(LOG_ERR, "unknown mode (%d) in handle_statL2TPStarting\n", reqinfo->mode);
+ return SNMP_ERR_GENERR;
+ }
+
+ return SNMP_ERR_NOERROR;
+}
+
+static int handle_statL2TPActive(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
+{
+ long stat;
+
+ (void)handler;
+ (void)reginfo;
+
+ switch (reqinfo->mode) {
+ case MODE_GET:
+ stat = l2tp_stat_active();
+ snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
+ (u_char *)&stat, sizeof(stat));
+ break;
+ default:
+ snmp_log(LOG_ERR, "unknown mode (%d) in handle_statL2TPActive\n", reqinfo->mode);
+ return SNMP_ERR_GENERR;
+ }
+
+ return SNMP_ERR_NOERROR;
+}
diff --git a/accel-pppd/extra/net-snmp/statPPP.c b/accel-pppd/extra/net-snmp/statPPP.c
index 37e4630c..7dc1f659 100644
--- a/accel-pppd/extra/net-snmp/statPPP.c
+++ b/accel-pppd/extra/net-snmp/statPPP.c
@@ -6,9 +6,22 @@
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
+
+#include "ap_session.h"
#include "statPPP.h"
-#include "ppp.h"
+static int handle_statPPPStarting(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests);
+static int handle_statPPPActive(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests);
+static int handle_statPPPFinishing(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests);
/*
* Our initialization routine, called automatically by the agent
@@ -17,77 +30,115 @@
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,
+ if (netsnmp_register_scalar(netsnmp_create_handler_registration(
+ "statPPPStarting", handle_statPPPStarting,
statPPPStarting_oid, OID_LENGTH(statPPPStarting_oid),
- HANDLER_CAN_RONLY);
- winfo = netsnmp_create_watcher_info(
- &ap_session_stat.starting, sizeof(ap_session_stat.starting),
- ASN_INTEGER, WATCHER_FIXED_SIZE);
- if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) {
- snmp_log( LOG_ERR, "Failed to register watched statPPPStarting" );
+ HANDLER_CAN_RONLY)) < 0 ) {
+ snmp_log( LOG_ERR, "Failed to register statPPPStarting" );
}
DEBUGMSGTL(("statPPP",
"Initializing statPPPActive scalar integer. Default value = %d\n",
0));
- reg = netsnmp_create_handler_registration(
- "statPPPActive", NULL,
+ if (netsnmp_register_scalar(netsnmp_create_handler_registration(
+ "statPPPActive", handle_statPPPActive,
statPPPActive_oid, OID_LENGTH(statPPPActive_oid),
- HANDLER_CAN_RONLY);
- winfo = netsnmp_create_watcher_info(
- &ap_session_stat.active, sizeof(ap_session_stat.active),
- ASN_INTEGER, WATCHER_FIXED_SIZE);
- if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) {
- snmp_log( LOG_ERR, "Failed to register watched statPPPActive" );
+ HANDLER_CAN_RONLY)) < 0 ) {
+ snmp_log( LOG_ERR, "Failed to register statPPPActive" );
}
DEBUGMSGTL(("statPPP",
"Initializing statPPPFinishing scalar integer. Default value = %d\n",
0));
- reg = netsnmp_create_handler_registration(
- "statPPPFinishing", NULL,
+ if (netsnmp_register_scalar(netsnmp_create_handler_registration(
+ "statPPPFinishing", handle_statPPPFinishing,
statPPPFinishing_oid, OID_LENGTH(statPPPFinishing_oid),
- HANDLER_CAN_RONLY);
- winfo = netsnmp_create_watcher_info(
- &ap_session_stat.finishing, sizeof(ap_session_stat.finishing),
- ASN_INTEGER, WATCHER_FIXED_SIZE);
- if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) {
- snmp_log( LOG_ERR, "Failed to register watched statPPPFinishing" );
+ HANDLER_CAN_RONLY)) < 0 ) {
+ snmp_log( LOG_ERR, "Failed to register statPPPFinishing" );
}
DEBUGMSGTL(("statPPP",
"Done initalizing statPPP module\n"));
}
+
+static int handle_statPPPStarting(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
+{
+ long stat;
+
+ (void)handler;
+ (void)reginfo;
+
+ switch (reqinfo->mode) {
+ case MODE_GET:
+ stat = ap_session_stat_starting();
+ snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
+ (u_char *)&stat, sizeof(stat));
+ break;
+ default:
+ snmp_log(LOG_ERR, "unknown mode (%d) in handle_statPPPStarting\n", reqinfo->mode);
+ return SNMP_ERR_GENERR;
+ }
+
+ return SNMP_ERR_NOERROR;
+}
+
+static int handle_statPPPActive(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
+{
+ long stat;
+
+ (void)handler;
+ (void)reginfo;
+
+ switch (reqinfo->mode) {
+ case MODE_GET:
+ stat = ap_session_stat_active();
+ snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
+ (u_char *)&stat, sizeof(stat));
+ break;
+ default:
+ snmp_log(LOG_ERR, "unknown mode (%d) in handle_statPPPActive\n", reqinfo->mode);
+ return SNMP_ERR_GENERR;
+ }
+
+ return SNMP_ERR_NOERROR;
+}
+
+static int handle_statPPPFinishing(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
+{
+ long stat;
+
+ (void)handler;
+ (void)reginfo;
+
+ switch (reqinfo->mode) {
+ case MODE_GET:
+ stat = ap_session_stat_finishing();
+ snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
+ (u_char *)&stat, sizeof(stat));
+ break;
+ default:
+ snmp_log(LOG_ERR, "unknown mode (%d) in handle_statPPPFinishing\n", reqinfo->mode);
+ return SNMP_ERR_GENERR;
+ }
+
+ return SNMP_ERR_NOERROR;
+}
diff --git a/accel-pppd/extra/net-snmp/statPPPOE.c b/accel-pppd/extra/net-snmp/statPPPOE.c
index 6042dc5b..64e61c3c 100644
--- a/accel-pppd/extra/net-snmp/statPPPOE.c
+++ b/accel-pppd/extra/net-snmp/statPPPOE.c
@@ -10,16 +10,17 @@
#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.
- */
+unsigned int pppoe_stat_starting(void);
+unsigned int pppoe_stat_active(void);
-void pppoe_get_stat(unsigned int **, unsigned int **);
-
-static unsigned int *stat_starting;
-static unsigned int *stat_active;
+static int handle_statPPPOEStarting(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests);
+static int handle_statPPPOEActive(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests);
/*
* Our initialization routine, called automatically by the agent
@@ -28,9 +29,6 @@ static unsigned int *stat_active;
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 };
@@ -43,51 +41,69 @@ init_statPPPOE(void)
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,
+ if (netsnmp_register_scalar(netsnmp_create_handler_registration(
+ "statPPPOEStarting", handle_statPPPOEStarting,
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" );
+ HANDLER_CAN_RONLY)) < 0 ) {
+ snmp_log( LOG_ERR, "Failed to register statPPPOEStarting" );
}
DEBUGMSGTL(("statPPPOE",
"Initializing statPPPOEActive scalar integer. Default value = %d\n",
0));
- reg = netsnmp_create_handler_registration(
- "statPPPOEActive", NULL,
+ if (netsnmp_register_scalar(netsnmp_create_handler_registration(
+ "statPPPOEActive", handle_statPPPOEActive,
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" );
+ HANDLER_CAN_RONLY)) < 0 ) {
+ snmp_log( LOG_ERR, "Failed to register statPPPOEActive" );
}
DEBUGMSGTL(("statPPPOE",
- "Done initalizing statPPPOE module\n"));
+ "Done initalizing statPPPOE module\n"));
+}
+
+static int handle_statPPPOEStarting(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
+{
+ long stat;
+
+ switch (reqinfo->mode) {
+ case MODE_GET:
+ stat = pppoe_stat_starting();
+ snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
+ (u_char *)&stat, sizeof(stat));
+ break;
+ default:
+ snmp_log(LOG_ERR, "unknown mode (%d) in handle_statPPPOEStarting\n", reqinfo->mode);
+ return SNMP_ERR_GENERR;
+ }
+
+ return SNMP_ERR_NOERROR;
+}
+
+static int handle_statPPPOEActive(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
+{
+ long stat;
+
+ switch (reqinfo->mode) {
+ case MODE_GET:
+ stat = pppoe_stat_active();
+ snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
+ (u_char *)&stat, sizeof(stat));
+ break;
+ default:
+ snmp_log(LOG_ERR, "unknown mode (%d) in handle_statPPPOEActive\n", reqinfo->mode);
+ return SNMP_ERR_GENERR;
+ }
+
+ return SNMP_ERR_NOERROR;
}
diff --git a/accel-pppd/extra/net-snmp/statPPTP.c b/accel-pppd/extra/net-snmp/statPPTP.c
index 48642202..8a633da3 100644
--- a/accel-pppd/extra/net-snmp/statPPTP.c
+++ b/accel-pppd/extra/net-snmp/statPPTP.c
@@ -6,20 +6,19 @@
#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"
+#include "accel-pppd/ctrl/pptp/pptp.h"
+#include "statPPTP.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;
+static int handle_statPPTPStarting(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests);
+static int handle_statPPTPActive(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests);
/*
* Our initialization routine, called automatically by the agent
@@ -28,9 +27,6 @@ static unsigned int *stat_active;
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 };
@@ -43,50 +39,75 @@ init_statPPTP(void)
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,
+ if (netsnmp_register_scalar(netsnmp_create_handler_registration(
+ "statPPTPStarting", handle_statPPTPStarting,
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" );
+ HANDLER_CAN_RONLY)) < 0 ) {
+ snmp_log( LOG_ERR, "Failed to register statPPTPStarting" );
}
DEBUGMSGTL(("statPPTP",
"Initializing statPPTPActive scalar integer. Default value = %d\n",
0));
- reg = netsnmp_create_handler_registration(
- "statPPTPActive", NULL,
+ if (netsnmp_register_scalar(netsnmp_create_handler_registration(
+ "statPPTPActive", handle_statPPTPActive,
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" );
+ HANDLER_CAN_RONLY)) < 0 ) {
+ snmp_log( LOG_ERR, "Failed to register statPPTPActive" );
}
DEBUGMSGTL(("statPPTP",
"Done initalizing statPPTP module\n"));
}
+
+static int handle_statPPTPStarting(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
+{
+ long stat;
+
+ (void)handler;
+ (void)reginfo;
+
+ switch (reqinfo->mode) {
+ case MODE_GET:
+ stat = pptp_stat_starting();
+ snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
+ (u_char *)&stat, sizeof(stat));
+ break;
+ default:
+ snmp_log(LOG_ERR, "unknown mode (%d) in handle_statPPTPStarting\n", reqinfo->mode);
+ return SNMP_ERR_GENERR;
+ }
+
+ return SNMP_ERR_NOERROR;
+}
+
+static int handle_statPPTPActive(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
+{
+ long stat;
+
+ (void)handler;
+ (void)reginfo;
+
+ switch (reqinfo->mode) {
+ case MODE_GET:
+ stat = pptp_stat_active();
+ snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
+ (u_char *)&stat, sizeof(stat));
+ break;
+ default:
+ snmp_log(LOG_ERR, "unknown mode (%d) in handle_statPPTPActive\n", reqinfo->mode);
+ return SNMP_ERR_GENERR;
+ }
+
+ return SNMP_ERR_NOERROR;
+}
diff --git a/accel-pppd/extra/net-snmp/statSSTP.c b/accel-pppd/extra/net-snmp/statSSTP.c
index 06ba6aa1..62948acd 100644
--- a/accel-pppd/extra/net-snmp/statSSTP.c
+++ b/accel-pppd/extra/net-snmp/statSSTP.c
@@ -8,18 +8,17 @@
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "triton.h"
+#include "accel-pppd/ctrl/sstp/sstp.h"
#include "statSSTP.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 sstp_get_stat(unsigned int **, unsigned int **);
-
-static unsigned int *stat_starting;
-static unsigned int *stat_active;
+static int handle_statSSTPStarting(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests);
+static int handle_statSSTPActive(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests);
/*
* Our initialization routine, called automatically by the agent
@@ -28,9 +27,6 @@ static unsigned int *stat_active;
void
init_statSSTP(void)
{
- netsnmp_handler_registration *reg;
- netsnmp_watcher_info *winfo;
-
static oid statSSTPStarting_oid[] = { 1,3,6,1,4,1,8072,100,1,7,1 };
static oid statSSTPActive_oid[] = { 1,3,6,1,4,1,8072,100,1,7,2 };
@@ -43,51 +39,75 @@ init_statSSTP(void)
if (!triton_module_loaded("sstp"))
return;
- sstp_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(("statSSTP",
"Initializing statSSTPStarting scalar integer. Default value = %d\n",
0));
- reg = netsnmp_create_handler_registration(
- "statSSTPStarting", NULL,
+ if (netsnmp_register_scalar(netsnmp_create_handler_registration(
+ "statSSTPStarting", handle_statSSTPStarting,
statSSTPStarting_oid, OID_LENGTH(statSSTPStarting_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 statSSTPStarting" );
+ HANDLER_CAN_RONLY)) < 0 ) {
+ snmp_log( LOG_ERR, "Failed to register statSSTPStarting" );
}
DEBUGMSGTL(("statSSTP",
"Initializing statSSTPActive scalar integer. Default value = %d\n",
0));
- reg = netsnmp_create_handler_registration(
- "statSSTPActive", NULL,
+ if (netsnmp_register_scalar(netsnmp_create_handler_registration(
+ "statSSTPActive", handle_statSSTPActive,
statSSTPActive_oid, OID_LENGTH(statSSTPActive_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 statSSTPActive" );
+ HANDLER_CAN_RONLY)) < 0 ) {
+ snmp_log( LOG_ERR, "Failed to register statSSTPActive" );
}
DEBUGMSGTL(("statSSTP",
"Done initalizing statSSTP module\n"));
}
+
+static int handle_statSSTPStarting(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
+{
+ long stat;
+
+ (void)handler;
+ (void)reginfo;
+
+ switch (reqinfo->mode) {
+ case MODE_GET:
+ stat = sstp_stat_starting();
+ snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
+ (u_char *)&stat, sizeof(stat));
+ break;
+ default:
+ snmp_log(LOG_ERR, "unknown mode (%d) in handle_statSSTPStarting\n", reqinfo->mode);
+ return SNMP_ERR_GENERR;
+ }
+
+ return SNMP_ERR_NOERROR;
+}
+
+static int handle_statSSTPActive(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
+{
+ long stat;
+
+ (void)handler;
+ (void)reginfo;
+
+ switch (reqinfo->mode) {
+ case MODE_GET:
+ stat = sstp_stat_active();
+ snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
+ (u_char *)&stat, sizeof(stat));
+ break;
+ default:
+ snmp_log(LOG_ERR, "unknown mode (%d) in handle_statSSTPActive\n", reqinfo->mode);
+ return SNMP_ERR_GENERR;
+ }
+
+ return SNMP_ERR_NOERROR;
+}