summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Eshenko <dmitriy.eshenko@accel-ppp.org>2025-12-13 15:38:16 +0200
committerDenys Fedoryshchenko <denys.f@collabora.com>2025-12-13 15:40:59 +0200
commit8c8ddabc22a523fb129e422baa025d720c3b455b (patch)
treeca832b5f2b099da02e8d3f49a46f8ed297d96d06
parent849b24855ae60fbb20887cfb7e650ea480c36f1f (diff)
downloadaccel-ppp-8c8ddabc22a523fb129e422baa025d720c3b455b.tar.gz
accel-ppp-8c8ddabc22a523fb129e422baa025d720c3b455b.zip
fix(accounting): preserve last counters on disconnect
Ensure accounting values include the most recent traffic sample when a session disconnects, preventing the final interval from being dropped and avoiding under-reported totals in usage/billing. Big thanks Dmitriy Eshenko for patch and testing Author: Dmitriy Eshenko <dmitriy.eshenko@accel-ppp.org> Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
-rw-r--r--accel-pppd/radius/acct.c16
-rw-r--r--accel-pppd/session.c3
2 files changed, 7 insertions, 12 deletions
diff --git a/accel-pppd/radius/acct.c b/accel-pppd/radius/acct.c
index 1cbd9296..15c94107 100644
--- a/accel-pppd/radius/acct.c
+++ b/accel-pppd/radius/acct.c
@@ -41,7 +41,6 @@ static int req_set_RA(struct rad_req_t *req, const char *secret)
static int req_set_stat(struct rad_req_t *req, struct ap_session *ses)
{
- struct rtnl_link_stats64 stats;
struct timespec ts;
int ret = 0;
@@ -50,15 +49,12 @@ static int req_set_stat(struct rad_req_t *req, struct ap_session *ses)
else
clock_gettime(CLOCK_MONOTONIC, &ts);
- if (ap_session_read_stats(ses, &stats) == 0) {
- rad_packet_change_int(req->pack, NULL, "Acct-Input-Octets", (int) (stats.rx_bytes & UINT32_MAX));
- rad_packet_change_int(req->pack, NULL, "Acct-Output-Octets", (int) (stats.tx_bytes & UINT32_MAX));
- rad_packet_change_int(req->pack, NULL, "Acct-Input-Packets", (int) (stats.rx_packets & UINT32_MAX));
- rad_packet_change_int(req->pack, NULL, "Acct-Output-Packets", (int) (stats.tx_packets & UINT32_MAX));
- rad_packet_change_int(req->pack, NULL, "Acct-Input-Gigawords", (int) (stats.rx_bytes >> (sizeof(uint32_t) * 8)));
- rad_packet_change_int(req->pack, NULL, "Acct-Output-Gigawords", (int) (stats.tx_bytes >> (sizeof(uint32_t) * 8)));
- } else
- ret = -1;
+ rad_packet_change_int(req->pack, NULL, "Acct-Input-Octets", (int) (ses->acct_rx_bytes & UINT32_MAX));
+ rad_packet_change_int(req->pack, NULL, "Acct-Output-Octets", (int) (ses->acct_tx_bytes & UINT32_MAX));
+ rad_packet_change_int(req->pack, NULL, "Acct-Input-Packets", (int) (ses->acct_rx_packets & UINT32_MAX));
+ rad_packet_change_int(req->pack, NULL, "Acct-Output-Packets", (int) (ses->acct_tx_packets & UINT32_MAX));
+ rad_packet_change_int(req->pack, NULL, "Acct-Input-Gigawords", (int) (ses->acct_rx_bytes >> (sizeof(uint32_t) * 8)));
+ rad_packet_change_int(req->pack, NULL, "Acct-Output-Gigawords", (int) (ses->acct_tx_bytes >> (sizeof(uint32_t) * 8)));
rad_packet_change_int(req->pack, NULL, "Acct-Session-Time", ts.tv_sec - ses->start_time);
diff --git a/accel-pppd/session.c b/accel-pppd/session.c
index 74b39475..a1b194a3 100644
--- a/accel-pppd/session.c
+++ b/accel-pppd/session.c
@@ -186,7 +186,6 @@ void __export ap_session_finished(struct ap_session *ses)
if (!ses->down) {
ap_session_ifdown(ses);
- ap_session_read_stats(ses, NULL);
triton_event_fire(EV_SES_FINISHING, ses);
}
@@ -309,10 +308,10 @@ void __export ap_session_terminate(struct ap_session *ses, int cause, int hard)
ses->state = AP_STATE_FINISHING;
log_ppp_debug("terminate\n");
+ ap_session_read_stats(ses, NULL);
if (ses->ctrl->terminate(ses, hard)) {
ap_session_ifdown(ses);
- ap_session_read_stats(ses, NULL);
triton_event_fire(EV_SES_FINISHING, ses);