diff options
author | Kozlov Dmitry <xeb@mail.ru> | 2012-07-11 18:47:08 +0400 |
---|---|---|
committer | Kozlov Dmitry <xeb@mail.ru> | 2012-07-11 18:47:08 +0400 |
commit | b2e106f8778fd834e0518cc6c0704d7d6b50875e (patch) | |
tree | e6a7dcd7f80b4cb52dd59a2cd087f4c30c357b41 /accel-pppd/radius/acct.c | |
parent | 07c57d04f2c585f4e3ba37bf61c3d14f9d40cd7d (diff) | |
download | accel-ppp-b2e106f8778fd834e0518cc6c0704d7d6b50875e.tar.gz accel-ppp-b2e106f8778fd834e0518cc6c0704d7d6b50875e.zip |
radius: fetch interface statistics via netlink
Diffstat (limited to 'accel-pppd/radius/acct.c')
-rw-r--r-- | accel-pppd/radius/acct.c | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/accel-pppd/radius/acct.c b/accel-pppd/radius/acct.c index b5f7ff76..87ffd83a 100644 --- a/accel-pppd/radius/acct.c +++ b/accel-pppd/radius/acct.c @@ -12,6 +12,8 @@ #include "log.h" #include "backup.h" #include "ap_session_backup.h" +#include "iplink.h" + #include "radius_p.h" #include "memdebug.h" @@ -36,7 +38,9 @@ static int req_set_RA(struct rad_req_t *req, const char *secret) static void req_set_stat(struct rad_req_t *req, struct ap_session *ses) { - struct ifpppstatsreq ifreq; + struct rtnl_link_stats stats; + struct radius_pd_t *rpd = req->rpd; + time_t stop_time; if (ses->stop_time) @@ -44,31 +48,31 @@ static void req_set_stat(struct rad_req_t *req, struct ap_session *ses) else time(&stop_time); - memset(&ifreq, 0, sizeof(ifreq)); - ifreq.stats_ptr = (void *)&ifreq.stats; - strcpy(ifreq.ifr__name, ses->ifname); + if (iplink_get_stats(ses->ifindex, &stats)) { + log_ppp_warn("radius: failed to get interface statistics\n"); + return; + } - if (ses->ctrl->type != CTRL_TYPE_IPOE) { - if (ioctl(sock_fd, SIOCGPPPSTATS, &ifreq)) { - log_ppp_error("radius: failed to get ppp statistics: %s\n", strerror(errno)); - return; - } + 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; - if (ifreq.stats.p.ppp_ibytes < req->rpd->acct_input_octets) - req->rpd->acct_input_gigawords++; - req->rpd->acct_input_octets = ifreq.stats.p.ppp_ibytes; + if (stats.rx_bytes < rpd->acct_rx_bytes) + req->rpd->acct_input_gigawords++; + req->rpd->acct_rx_bytes = stats.rx_packets; - if (ifreq.stats.p.ppp_obytes < req->rpd->acct_output_octets) - req->rpd->acct_output_gigawords++; - req->rpd->acct_output_octets = ifreq.stats.p.ppp_obytes; + if (stats.tx_bytes < rpd->acct_tx_bytes) + req->rpd->acct_output_gigawords++; + req->rpd->acct_tx_bytes = stats.tx_bytes; + + 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-Octets", ifreq.stats.p.ppp_ibytes); - rad_packet_change_int(req->pack, NULL, "Acct-Output-Octets", ifreq.stats.p.ppp_obytes); - rad_packet_change_int(req->pack, NULL, "Acct-Input-Packets", ifreq.stats.p.ppp_ipackets); - rad_packet_change_int(req->pack, NULL, "Acct-Output-Packets", ifreq.stats.p.ppp_opackets); - rad_packet_change_int(req->pack, NULL, "Acct-Input-Gigawords", req->rpd->acct_input_gigawords); - rad_packet_change_int(req->pack, NULL, "Acct-Output-Gigawords", req->rpd->acct_output_gigawords); - } rad_packet_change_int(req->pack, NULL, "Acct-Session-Time", stop_time - ses->start_time); } @@ -233,9 +237,19 @@ 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); |