summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Nault <g.nault@alphalink.fr>2016-11-02 20:34:16 +0100
committerDmitry Kozlov <xeb@mail.ru>2016-11-12 10:34:45 +0300
commit938d3e852f8ef51f9f284e13e3a79c2f501f6d74 (patch)
treee6969f295e4279f46b79dc4a5ec2e53c769bee45
parent1edce7b49f4f522d5b0238e27c3733becc2c0775 (diff)
downloadaccel-ppp-938d3e852f8ef51f9f284e13e3a79c2f501f6d74.tar.gz
accel-ppp-938d3e852f8ef51f9f284e13e3a79c2f501f6d74.zip
pppd-compat: move computation of tx_bytes and rx_bytes
tx_bytes and rx_bytes are only used in the ->stop_time branch, so let's compute them here rather than at the top of the function. Also, let's replace '4294967296llu' by 'UINT32_MAX + 1', to make it clear that a gigaword equals 2^32 bytes and is used to keep track of how many times the 32 bits tx and rx counters have overflowed. Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
-rw-r--r--accel-pppd/extra/pppd_compat.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/accel-pppd/extra/pppd_compat.c b/accel-pppd/extra/pppd_compat.c
index 5518c611..d54743c8 100644
--- a/accel-pppd/extra/pppd_compat.c
+++ b/accel-pppd/extra/pppd_compat.c
@@ -525,14 +525,10 @@ static void build_addr(struct ipv6db_addr_t *a, uint64_t intf_id, struct in6_add
static void fill_env(char **env, char *mem, struct pppd_compat_pd *pd)
{
struct ap_session *ses = pd->ses;
- uint64_t tx_bytes, rx_bytes;
size_t mem_sz = ENV_MEM;
int write_sz;
int n = 0;
- tx_bytes = (uint64_t)ses->acct_tx_bytes + 4294967296llu*ses->acct_output_gigawords;
- rx_bytes = (uint64_t)ses->acct_rx_bytes + 4294967296llu*ses->acct_input_gigawords;
-
env[n] = mem;
write_sz = snprintf(mem, mem_sz, "PEERNAME=%s", pd->ses->username);
if (write_sz < 0 || write_sz >= mem_sz)
@@ -599,6 +595,13 @@ static void fill_env(char **env, char *mem, struct pppd_compat_pd *pd)
}
if (pd->ses->stop_time) {
+ uint64_t gword_sz = (uint64_t)UINT32_MAX + 1;
+ uint64_t tx_bytes;
+ uint64_t rx_bytes;
+
+ tx_bytes = ses->acct_tx_bytes + gword_sz * ses->acct_output_gigawords;
+ rx_bytes = ses->acct_rx_bytes + gword_sz * ses->acct_input_gigawords;
+
env[n] = mem;
write_sz = snprintf(mem, mem_sz, "CONNECT_TIME=%lu",
(unsigned long)(pd->ses->stop_time -