summaryrefslogtreecommitdiff
path: root/accel-pppd
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2023-01-27 11:05:26 +0300
committerDmitry Kozlov <xeb@mail.ru>2023-01-27 11:05:26 +0300
commitcc8f2bada5635768d425e2fa2bafb095acda8ca9 (patch)
tree94241195b30e21c1b2fd20af70adcc4c6a083e51 /accel-pppd
parentb120b0d83e2145d1681f10003b13274dec6dc412 (diff)
downloadaccel-ppp-cc8f2bada5635768d425e2fa2bafb095acda8ca9.tar.gz
accel-ppp-cc8f2bada5635768d425e2fa2bafb095acda8ca9.zip
radius: implemented accounting delay option (acct-delay-start)
Diffstat (limited to 'accel-pppd')
-rw-r--r--accel-pppd/accel-ppp.conf1
-rw-r--r--accel-pppd/accel-ppp.conf.53
-rw-r--r--accel-pppd/radius/acct.c27
-rw-r--r--accel-pppd/radius/radius.c11
-rw-r--r--accel-pppd/radius/radius_p.h1
5 files changed, 41 insertions, 2 deletions
diff --git a/accel-pppd/accel-ppp.conf b/accel-pppd/accel-ppp.conf
index d5c69bf8..1b14b9b0 100644
--- a/accel-pppd/accel-ppp.conf
+++ b/accel-pppd/accel-ppp.conf
@@ -217,6 +217,7 @@ verbose=1
#max-try=3
#acct-timeout=120
#acct-delay-time=0
+#acct-delay-start=0
#acct-on=0
#acct-interim-interval=0
#acct-interim-jitter=0
diff --git a/accel-pppd/accel-ppp.conf.5 b/accel-pppd/accel-ppp.conf.5
index f951325c..09c4597e 100644
--- a/accel-pppd/accel-ppp.conf.5
+++ b/accel-pppd/accel-ppp.conf.5
@@ -933,6 +933,9 @@ Specifies timeout of accounting interim update.
.BI "acct-delay-time=" 0|1
Specifies whether radius client should include Acct-Delay-Time attribute to accounting requests (default 0).
.TP
+.BI "acct-delay-start=" n
+Specifies delay to send accounting start packet (defaul 0).
+.TP
.BI "acct-on=" 0|1
Specifies whether radius client should send Account-Request with Acct-Status-Type=Accounting-On on startup and Acct-Status-Type=Accounting-Off on shutdown.
.TP
diff --git a/accel-pppd/radius/acct.c b/accel-pppd/radius/acct.c
index d8488592..1cbd9296 100644
--- a/accel-pppd/radius/acct.c
+++ b/accel-pppd/radius/acct.c
@@ -214,7 +214,7 @@ static int rad_acct_before_send(struct rad_req_t *req)
clock_gettime(CLOCK_MONOTONIC, &ts);
- rad_packet_change_int(req->pack, NULL, "Acct-Delay-Time", ts.tv_sec - req->ts);
+ rad_packet_change_int(req->pack, NULL, "Acct-Delay-Time", ts.tv_sec - req->ts + conf_acct_delay_start);
req_set_RA(req, req->serv->secret);
return 0;
@@ -300,7 +300,7 @@ static void rad_acct_start_timeout(struct triton_timer_t *t)
ap_session_terminate(req->rpd->ses, TERM_NAS_ERROR, 0);
}
-int rad_acct_start(struct radius_pd_t *rpd)
+static int __rad_acct_start(struct radius_pd_t *rpd)
{
struct rad_req_t *req = rad_req_alloc(rpd, CODE_ACCOUNTING_REQUEST, rpd->ses->username, 0);
@@ -335,6 +335,29 @@ out_err:
return -1;
}
+static void rad_acct_start_delay(struct triton_timer_t *t)
+{
+ struct radius_pd_t *rpd = container_of(t, typeof(*rpd), acct_interim_timer);
+
+ triton_timer_del(&rpd->acct_interim_timer);
+
+ if (__rad_acct_start(rpd))
+ ap_session_terminate(rpd->ses, TERM_NAS_ERROR, 0);
+}
+
+int rad_acct_start(struct radius_pd_t *rpd)
+{
+ if (conf_acct_delay_start) {
+ log_ppp_debug("radius: acct delay start %i\n", conf_acct_delay_start);
+ rpd->acct_interim_timer.expire = rad_acct_start_delay;
+ rpd->acct_interim_timer.expire_tv.tv_sec = conf_acct_delay_start;
+ triton_timer_add(rpd->ses->ctrl->ctx, &rpd->acct_interim_timer, 0);
+ return 0;
+ }
+
+ return __rad_acct_start(rpd);
+}
+
static void rad_acct_stop_sent(struct rad_req_t *req, int res)
{
if (res) {
diff --git a/accel-pppd/radius/radius.c b/accel-pppd/radius/radius.c
index 786faa56..2406ba04 100644
--- a/accel-pppd/radius/radius.c
+++ b/accel-pppd/radius/radius.c
@@ -57,6 +57,8 @@ static int conf_strip_realm;
const char *conf_attr_tunnel_type;
+int conf_acct_delay_start;
+
static LIST_HEAD(sessions);
static pthread_rwlock_t sessions_lock = PTHREAD_RWLOCK_INITIALIZER;
@@ -697,6 +699,9 @@ static void ses_finishing(struct ap_session *ses)
if (rpd->acct_started || rpd->acct_req)
rad_acct_stop(rpd);
+
+ if (rpd->acct_interim_timer.tpd)
+ triton_timer_del(&rpd->acct_interim_timer);
}
static void ses_finished(struct ap_session *ses)
@@ -1075,6 +1080,12 @@ static int load_config(void)
if (opt)
conf_nas_port_id_in_req = atoi(opt);
+ opt = conf_get_opt("radius", "acct-delay-start");
+ if (opt)
+ conf_acct_delay_start = atoi(opt);
+ else
+ conf_acct_delay_start = 0;
+
return 0;
}
diff --git a/accel-pppd/radius/radius_p.h b/accel-pppd/radius/radius_p.h
index 988f154f..cd9a0ab4 100644
--- a/accel-pppd/radius/radius_p.h
+++ b/accel-pppd/radius/radius_p.h
@@ -193,6 +193,7 @@ extern int conf_acct_interim_interval;
extern int conf_acct_interim_jitter;
extern int conf_accounting;
extern const char *conf_attr_tunnel_type;
+extern int conf_acct_delay_start;
int rad_check_nas_pack(struct rad_packet_t *pack);
struct radius_pd_t *rad_find_session(const char *sessionid, const char *username, const char *port_id, int port, in_addr_t ipaddr, const char *csid);