summaryrefslogtreecommitdiff
path: root/accel-pppd/extra
diff options
context:
space:
mode:
authorDenys Fedoryshchenko <denys.f@collabora.com>2026-04-29 14:40:40 +0300
committerDenys Fedoryshchenko <denys.f@collabora.com>2026-05-04 03:09:49 +0300
commitbfca38f5d71dd552e6379152c5a4ba3b0b42f7a8 (patch)
tree3ecac437c9c2018574f747dc9381303c711742f2 /accel-pppd/extra
parent770550921ae2d084168cb0b9d8d66f783cbdb69d (diff)
downloadaccel-ppp-bfca38f5d71dd552e6379152c5a4ba3b0b42f7a8.tar.gz
accel-ppp-bfca38f5d71dd552e6379152c5a4ba3b0b42f7a8.zip
sstp: encapsulate statistics counters
Group the SSTP starting and active statistics in struct sstp_stat_t and keep the storage under the SSTP server object instead of exposing writable stat_* globals. This keeps ownership inside the SSTP control code while preserving the existing CLI and ACCEL-PPP-MIB counter semantics. Route counter updates through sstp_stat_*() helpers. Connection accept, transition to PPP setup, and disconnect paths no longer open-code individual counter increments/decrements; the update policy now lives beside the SSTP-owned storage and uses relaxed atomic operations for the simple state counters. Make the CLI show-stat path render from a local snapshot and convert the SSTP SNMP starting/active scalars from watched raw pointers to scalar handlers. SNMP now reads through sstp_stat_starting() and sstp_stat_active(), removing the old sstp_get_stat() pointer escape hatch. Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
Diffstat (limited to 'accel-pppd/extra')
-rw-r--r--accel-pppd/extra/net-snmp/statSSTP.c110
1 files changed, 65 insertions, 45 deletions
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;
+}