From 7fd4346bbbf03622abf0e09d4f1efb32169a7cf0 Mon Sep 17 00:00:00 2001 From: fendo Date: Wed, 24 Apr 2013 22:29:36 +0200 Subject: [PATCH 1/1] add accounting parameter account_all_origin --- Docs/manual.html | 9 +++++++-- l2tpns.c | 30 ++++++++++++++++++++++++++++++ l2tpns.h | 1 + 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Docs/manual.html b/Docs/manual.html index 95e3afe..8894599 100644 --- a/Docs/manual.html +++ b/Docs/manual.html @@ -316,8 +316,13 @@ every connected use will be dumped to a file in this directory. Each file dumped begins with a header, where each line is prefixed by #. Following the header is a single line for every connected user, fields separated by a space.
The fields are username, ip, qos, -uptxoctets, downrxoctets. The qos field is 1 if a standard user, and -2 if the user is throttled. +uptxoctets, downrxoctets, origin (optional). The qos field is 1 if a standard user, and +2 if the user is throttled. The origin field is dump if account_all_origin is set to true +(origin value: L=LAC data, R=Remote LNS data, P=PPPOE data). + + +
  • account_all_origin (boolean)
    +If set to true, all origin of the usage is dumped to the accounting file (LAC+Remote LNS+PPPOE)(default false).
  • setuid (int)
    diff --git a/l2tpns.c b/l2tpns.c index 8f1ace5..55621a5 100644 --- a/l2tpns.c +++ b/l2tpns.c @@ -152,6 +152,7 @@ config_descriptt config_values[] = { CONFIG("throttle_speed", rl_rate, UNSIGNED_LONG), CONFIG("throttle_buckets", num_tbfs, INT), CONFIG("accounting_dir", accounting_dir, STRING), + CONFIG("account_all_origin", account_all_origin, BOOL), CONFIG("dump_speed", dump_speed, BOOL), CONFIG("multi_read_count", multi_read_count, INT), CONFIG("scheduler_fifo", scheduler_fifo, BOOL), @@ -4939,6 +4940,21 @@ static int dump_session(FILE **f, sessiont *s) } LOG(3, 0, 0, "Dumping accounting information to %s\n", filename); + if(config->account_all_origin) + { + fprintf(*f, "# dslwatch.pl dump file V1.01\n" + "# host: %s\n" + "# endpoint: %s\n" + "# time: %ld\n" + "# uptime: %ld\n" + "# format: username ip qos uptxoctets downrxoctets origin(L=LAC, R=Remote LNS, P=PPPOE)\n", + hostname, + fmtaddr(config->iftun_n_address[tunnel[s->tunnel].indexudp] ? config->iftun_n_address[tunnel[s->tunnel].indexudp] : my_address, 0), + now, + now - basetime); + } + else + { fprintf(*f, "# dslwatch.pl dump file V1.01\n" "# host: %s\n" "# endpoint: %s\n" @@ -4949,15 +4965,29 @@ static int dump_session(FILE **f, sessiont *s) fmtaddr(config->iftun_n_address[tunnel[s->tunnel].indexudp] ? config->iftun_n_address[tunnel[s->tunnel].indexudp] : my_address, 0), now, now - basetime); + } } LOG(4, 0, 0, "Dumping accounting information for %s\n", s->user); + if(config->account_all_origin) + { + fprintf(*f, "%s %s %d %u %u %s\n", + s->user, // username + fmtaddr(htonl(s->ip), 0), // ip + (s->throttle_in || s->throttle_out) ? 2 : 1, // qos + (uint32_t) s->cin_delta, // uptxoctets + (uint32_t) s->cout_delta, // downrxoctets + (s->tunnel == TUNNEL_ID_PPPOE)?"P":(tunnel[s->tunnel].isremotelns?"R":"L")); // Origin + } + else if (!tunnel[s->tunnel].isremotelns && (s->tunnel != TUNNEL_ID_PPPOE)) + { fprintf(*f, "%s %s %d %u %u\n", s->user, // username fmtaddr(htonl(s->ip), 0), // ip (s->throttle_in || s->throttle_out) ? 2 : 1, // qos (uint32_t) s->cin_delta, // uptxoctets (uint32_t) s->cout_delta); // downrxoctets + } s->cin_delta = s->cout_delta = 0; diff --git a/l2tpns.h b/l2tpns.h index 89f49dd..8c306d3 100644 --- a/l2tpns.h +++ b/l2tpns.h @@ -696,6 +696,7 @@ typedef struct int num_tbfs; // number of throttle buckets char accounting_dir[128]; + int account_all_origin; // Accouting all origin (LAC data + Remote LNS Data + PPPOE data) in_addr_t bind_address; in_addr_t peer_address; int send_garp; // Set to true to garp for vip address on startup -- 2.20.1