summaryrefslogtreecommitdiff
path: root/accel-pppd
diff options
context:
space:
mode:
authorDmitriyEshenko <dmitriy.eshenko@vyos.io>2021-12-17 18:32:35 +0300
committerDmitriyEshenko <dmitriy.eshenko@vyos.io>2021-12-17 18:32:35 +0300
commitb8ab27c2254e1668a175a3ae9ad038e5db7d6851 (patch)
treeb33900a3d6e6b28e6c1f88b36f6a9769ee7112ae /accel-pppd
parent385c4038c451f5c181136070846cab0664dae43a (diff)
downloadaccel-ppp-b8ab27c2254e1668a175a3ae9ad038e5db7d6851.tar.gz
accel-ppp-b8ab27c2254e1668a175a3ae9ad038e5db7d6851.zip
T54: Use get_stats function to prevent garbage in counters
Diffstat (limited to 'accel-pppd')
-rw-r--r--accel-pppd/cli/show_sessions.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/accel-pppd/cli/show_sessions.c b/accel-pppd/cli/show_sessions.c
index 73c6a41c..fb3ff527 100644
--- a/accel-pppd/cli/show_sessions.c
+++ b/accel-pppd/cli/show_sessions.c
@@ -565,10 +565,19 @@ static void format_bytes(char *buf, unsigned long long bytes)
sprintf(buf, "%.1f %s", d, suffix);
}
+static void get_stats(struct ap_session *ses) {
+ if(ap_session_read_stats(ses, &stats) == -1) {
+ stats.rx_bytes = 0;
+ stats.tx_bytes = 0;
+ stats.rx_packets = 0;
+ stats.tx_packets = 0;
+ }
+}
+
static void print_rx_bytes(struct ap_session *ses, char *buf)
{
if (!stats_set) {
- ap_session_read_stats(ses, &stats);
+ get_stats(ses);
stats_set = 1;
}
format_bytes(buf, 4294967296ll*ses->acct_input_gigawords + stats.rx_bytes);
@@ -577,7 +586,7 @@ static void print_rx_bytes(struct ap_session *ses, char *buf)
static void print_tx_bytes(struct ap_session *ses, char *buf)
{
if (!stats_set) {
- ap_session_read_stats(ses, &stats);
+ get_stats(ses);
stats_set = 1;
}
format_bytes(buf, 4294967296ll*ses->acct_output_gigawords + stats.tx_bytes);
@@ -586,7 +595,7 @@ static void print_tx_bytes(struct ap_session *ses, char *buf)
static void print_rx_bytes_raw(struct ap_session *ses, char *buf)
{
if (!stats_set) {
- ap_session_read_stats(ses, &stats);
+ get_stats(ses);
stats_set = 1;
}
sprintf(buf, "%llu", 4294967296ll*ses->acct_input_gigawords + stats.rx_bytes);
@@ -595,7 +604,7 @@ static void print_rx_bytes_raw(struct ap_session *ses, char *buf)
static void print_tx_bytes_raw(struct ap_session *ses, char *buf)
{
if (!stats_set) {
- ap_session_read_stats(ses, &stats);
+ get_stats(ses);
stats_set = 1;
}
sprintf(buf, "%llu", 4294967296ll*ses->acct_output_gigawords + stats.tx_bytes);
@@ -604,7 +613,7 @@ static void print_tx_bytes_raw(struct ap_session *ses, char *buf)
static void print_rx_pkts(struct ap_session *ses, char *buf)
{
if (!stats_set) {
- ap_session_read_stats(ses, &stats);
+ get_stats(ses);
stats_set = 1;
}
sprintf(buf, "%u", stats.rx_packets);
@@ -613,7 +622,7 @@ static void print_rx_pkts(struct ap_session *ses, char *buf)
static void print_tx_pkts(struct ap_session *ses, char *buf)
{
if (!stats_set) {
- ap_session_read_stats(ses, &stats);
+ get_stats(ses);
stats_set = 1;
}
sprintf(buf, "%u", stats.tx_packets);