diff options
author | Kozlov Dmitry <xeb@mail.ru> | 2012-09-05 23:24:51 +0400 |
---|---|---|
committer | Kozlov Dmitry <xeb@mail.ru> | 2012-09-05 23:24:51 +0400 |
commit | 490f6384f6a54e388587329c0309a6602d5544e8 (patch) | |
tree | 5e70a9e4e7a8f6714a4694826ec68f293d1e55a8 /accel-pppd/radius | |
parent | a10ec0f4636cd559209659304709924daad96340 (diff) | |
download | accel-ppp-490f6384f6a54e388587329c0309a6602d5544e8.tar.gz accel-ppp-490f6384f6a54e388587329c0309a6602d5544e8.zip |
generalize interface statistics gathering
Diffstat (limited to 'accel-pppd/radius')
-rw-r--r-- | accel-pppd/radius/acct.c | 45 | ||||
-rw-r--r-- | accel-pppd/radius/radius.c | 11 | ||||
-rw-r--r-- | accel-pppd/radius/radius_p.h | 11 |
3 files changed, 9 insertions, 58 deletions
diff --git a/accel-pppd/radius/acct.c b/accel-pppd/radius/acct.c index ab71c453..81145cd1 100644 --- a/accel-pppd/radius/acct.c +++ b/accel-pppd/radius/acct.c @@ -12,7 +12,7 @@ #include "log.h" #include "backup.h" #include "ap_session_backup.h" -#include "iplink.h" +#include "iputils.h" #include "radius_p.h" @@ -21,33 +21,6 @@ #define STAT_UPDATE_INTERVAL (10 * 60 * 1000) #define INTERIM_SAFE_TIME 10 -int rad_read_stats(struct radius_pd_t *rpd, struct rtnl_link_stats *stats) -{ - int r; - - if (iplink_get_stats(rpd->ses->ifindex, stats)) { - log_ppp_warn("radius: failed to get interface statistics\n"); - return -1; - } - - stats->rx_packets -= rpd->acct_rx_packets_i; - stats->tx_packets -= rpd->acct_tx_packets_i; - stats->rx_bytes -= rpd->acct_rx_bytes_i; - stats->tx_bytes -= rpd->acct_tx_bytes_i; - - r = stats->rx_bytes != rpd->acct_rx_bytes || stats->tx_bytes < rpd->acct_tx_bytes; - - if (stats->rx_bytes < rpd->acct_rx_bytes) - rpd->acct_input_gigawords++; - rpd->acct_rx_bytes = stats->rx_packets; - - if (stats->tx_bytes < rpd->acct_tx_bytes) - rpd->acct_output_gigawords++; - rpd->acct_tx_bytes = stats->tx_bytes; - - return r; -} - static int req_set_RA(struct rad_req_t *req, const char *secret) { MD5_CTX ctx; @@ -75,13 +48,13 @@ static void req_set_stat(struct rad_req_t *req, struct ap_session *ses) else time(&stop_time); - if (rad_read_stats(rpd, &stats) > 0) { + if (ap_session_read_stats(ses, &stats) == 0) { rad_packet_change_int(req->pack, NULL, "Acct-Input-Octets", stats.rx_bytes); rad_packet_change_int(req->pack, NULL, "Acct-Output-Octets", stats.tx_bytes); rad_packet_change_int(req->pack, NULL, "Acct-Input-Packets", stats.rx_packets); rad_packet_change_int(req->pack, NULL, "Acct-Output-Packets", stats.tx_packets); - rad_packet_change_int(req->pack, NULL, "Acct-Input-Gigawords", rpd->acct_input_gigawords); - rad_packet_change_int(req->pack, NULL, "Acct-Output-Gigawords", rpd->acct_output_gigawords); + rad_packet_change_int(req->pack, NULL, "Acct-Input-Gigawords", rpd->ses->acct_input_gigawords); + rad_packet_change_int(req->pack, NULL, "Acct-Output-Gigawords", rpd->ses->acct_output_gigawords); } rad_packet_change_int(req->pack, NULL, "Acct-Session-Time", stop_time - ses->start_time); @@ -248,20 +221,10 @@ int rad_acct_start(struct radius_pd_t *rpd) int i; time_t ts; unsigned int dt; - struct rtnl_link_stats stats; if (!conf_accounting) return 0; - if (iplink_get_stats(rpd->ses->ifindex, &stats)) - log_ppp_warn("radius: failed to get interface statistics\n"); - else { - rpd->acct_rx_packets_i = stats.rx_packets; - rpd->acct_tx_packets_i = stats.tx_packets; - rpd->acct_rx_bytes_i = stats.rx_bytes; - rpd->acct_tx_bytes_i = stats.tx_bytes; - } - if (!rpd->acct_req) rpd->acct_req = rad_req_alloc(rpd, CODE_ACCOUNTING_REQUEST, rpd->ses->username); diff --git a/accel-pppd/radius/radius.c b/accel-pppd/radius/radius.c index 5f5d0ba4..67c18e6d 100644 --- a/accel-pppd/radius/radius.c +++ b/accel-pppd/radius/radius.c @@ -235,19 +235,18 @@ static void session_timeout(struct triton_timer_t *t) static void idle_timeout(struct triton_timer_t *t) { struct radius_pd_t *rpd = container_of(t, typeof(*rpd), idle_timeout); - struct rtnl_link_stats stats; + time_t tt; if (rpd->ses->stop_time) return; - rad_read_stats(rpd, &stats); + time(&tt); - if (stats.rx_packets == rpd->acct_rx_packets && stats.tx_packets == rpd->acct_tx_packets) { + ap_session_read_stats(rpd->ses, NULL); + + if (tt - rpd->ses->idle_time > t->period / 1000) { log_ppp_msg("radius: idle timed out\n"); ap_session_terminate(rpd->ses, TERM_IDLE_TIMEOUT, 0); - } else { - rpd->acct_rx_packets = stats.rx_packets; - rpd->acct_tx_packets = stats.tx_packets; } } diff --git a/accel-pppd/radius/radius_p.h b/accel-pppd/radius/radius_p.h index 8a4d27a9..4a17202f 100644 --- a/accel-pppd/radius/radius_p.h +++ b/accel-pppd/radius/radius_p.h @@ -25,17 +25,6 @@ struct radius_pd_t struct rad_req_t *acct_req; struct triton_timer_t acct_interim_timer; - uint32_t acct_rx_bytes; - uint32_t acct_tx_bytes; - uint32_t acct_rx_packets; - uint32_t acct_tx_packets; - uint32_t acct_input_gigawords; - uint32_t acct_output_gigawords; - uint32_t acct_rx_packets_i; - uint32_t acct_tx_packets_i; - uint32_t acct_rx_bytes_i; - uint32_t acct_tx_bytes_i; - struct triton_timer_t session_timeout; struct triton_timer_t idle_timeout; |