summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2010-10-26 15:18:56 +0400
committerDmitry Kozlov <xeb@mail.ru>2010-10-26 15:18:56 +0400
commit0d7463621ef7ce5c1df0a427c23d6936f1c43ab7 (patch)
treec804086137c76e7cbfe6c41dacfb8c1de48a24ec
parent098a5112a9e2240fdbac3116173f6735ee13dba8 (diff)
downloadaccel-ppp-0d7463621ef7ce5c1df0a427c23d6936f1c43ab7.tar.gz
accel-ppp-0d7463621ef7ce5c1df0a427c23d6936f1c43ab7.zip
radius: implemented Acct-Delay-Time attribute
radius: accounting start moved to before ip up
-rw-r--r--accel-pptpd/include/events.h1
-rw-r--r--accel-pptpd/ppp/ipcp_opt_ipaddr.c4
-rw-r--r--accel-pptpd/radius/acct.c35
-rw-r--r--accel-pptpd/radius/radius.c8
-rw-r--r--accel-pptpd/radius/radius_p.h1
-rw-r--r--accel-pptpd/radius/req.c6
6 files changed, 41 insertions, 14 deletions
diff --git a/accel-pptpd/include/events.h b/accel-pptpd/include/events.h
index bc1e674..f0b1b8c 100644
--- a/accel-pptpd/include/events.h
+++ b/accel-pptpd/include/events.h
@@ -12,6 +12,7 @@
#define EV_CTRL_STARTED 7
#define EV_CTRL_FINISHED 8
#define EV_PPP_PRE_UP 9
+#define EV_PPP_ACCT_START 10
#define EV_IP_CHANGED 100
#define EV_SHAPE_CHANGED 101
#define EV_MPPE_KEYS 102
diff --git a/accel-pptpd/ppp/ipcp_opt_ipaddr.c b/accel-pptpd/ppp/ipcp_opt_ipaddr.c
index ffba072..b0f662e 100644
--- a/accel-pptpd/ppp/ipcp_opt_ipaddr.c
+++ b/accel-pptpd/ppp/ipcp_opt_ipaddr.c
@@ -122,6 +122,10 @@ ack:
ipcp->ppp->ipaddr = ipaddr_opt->ip->addr;
ipcp->ppp->peer_ipaddr = ipaddr_opt->ip->peer_addr;
+ triton_event_fire(EV_PPP_ACCT_START, ipcp->ppp);
+ if (ipcp->ppp->stop_time)
+ return IPCP_OPT_ACK;
+
triton_event_fire(EV_PPP_PRE_UP, ipcp->ppp);
if (ipcp->ppp->stop_time)
return IPCP_OPT_ACK;
diff --git a/accel-pptpd/radius/acct.c b/accel-pptpd/radius/acct.c
index 0f1b5fd..77f3812 100644
--- a/accel-pptpd/radius/acct.c
+++ b/accel-pptpd/radius/acct.c
@@ -96,7 +96,6 @@ static int rad_acct_read(struct triton_md_handler_t *h)
rad_packet_free(req->reply);
req->reply = NULL;
} else {
- req->pack->id++;
if (req->timeout.tpd)
triton_timer_del(&req->timeout);
}
@@ -108,6 +107,11 @@ static void rad_acct_timeout(struct triton_timer_t *t)
{
struct rad_req_t *req = container_of(t, typeof(*req), timeout);
+ req->rpd->acct_delay_time += conf_timeout;
+ req->pack->id++;
+
+ rad_packet_change_int(req->pack, "Acct-Delay-Time", req->rpd->acct_delay_time);
+ req_set_RA(req, conf_acct_secret);
rad_req_send(req);
}
@@ -122,7 +126,11 @@ static void rad_acct_interim_update(struct triton_timer_t *t)
if (!rpd->acct_interim_interval)
return;
+ rpd->acct_delay_time = 0;
+ rpd->acct_req->pack->id++;
+
rad_packet_change_val(rpd->acct_req->pack, "Acct-Status-Type", "Interim-Update");
+ rad_packet_change_int(rpd->acct_req->pack, "Acct-Delay-Time", 0);
req_set_RA(rpd->acct_req, conf_acct_secret);
rad_req_send(rpd->acct_req);
rpd->acct_req->timeout.period = conf_timeout * 1000;
@@ -149,23 +157,29 @@ int rad_acct_start(struct radius_pd_t *rpd)
//if (rad_req_add_str(rpd->acct_req, "Acct-Session-Id", rpd->ppp->sessionid, PPP_SESSIONID_LEN, 1))
// goto out_err;
- if (req_set_RA(rpd->acct_req, conf_acct_secret))
- goto out_err;
-
if (rpd->acct_req->reply) {
rad_packet_free(rpd->acct_req->reply);
rpd->acct_req->reply = NULL;
}
+ rpd->acct_delay_time = 0;
+
for (i = 0; i < conf_max_try; i++) {
+ rad_packet_change_int(rpd->acct_req->pack, "Acct-Delay-Time", rpd->acct_delay_time);
+ rpd->acct_delay_time += conf_timeout;
+ if (req_set_RA(rpd->acct_req, conf_acct_secret))
+ goto out_err;
if (rad_req_send(rpd->acct_req))
goto out_err;
rad_req_wait(rpd->acct_req, conf_timeout);
- if (!rpd->acct_req->reply)
+ if (!rpd->acct_req->reply) {
+ rpd->acct_req->pack->id++;
continue;
+ }
if (rpd->acct_req->reply->id != rpd->acct_req->pack->id || rpd->acct_req->reply->code != CODE_ACCOUNTING_RESPONSE) {
rad_packet_free(rpd->acct_req->reply);
rpd->acct_req->reply = NULL;
+ rpd->acct_req->pack->id++;
} else
break;
}
@@ -183,10 +197,6 @@ int rad_acct_start(struct radius_pd_t *rpd)
rpd->acct_req->timeout.expire = rad_acct_timeout;
rpd->acct_req->timeout.period = conf_timeout * 1000;
- if (triton_timer_add(rpd->ppp->ctrl->ctx, &rpd->acct_req->timeout, 0)) {
- triton_md_unregister_handler(&rpd->acct_req->hnd);
- goto out_err;
- }
rpd->acct_interim_timer.expire = rad_acct_interim_update;
rpd->acct_interim_timer.period = rpd->acct_interim_interval ? rpd->acct_interim_interval * 1000 : STAT_UPDATE_INTERVAL;
@@ -242,8 +252,15 @@ void rad_acct_stop(struct radius_pd_t *rpd)
rad_packet_free(rpd->acct_req->reply);
rpd->acct_req->reply = NULL;
}
+
+ rpd->acct_delay_time = 0;
for(i = 0; i < conf_max_try; i++) {
+ rad_packet_change_int(rpd->acct_req->pack, "Acct-Delay-Time", rpd->acct_delay_time);
+ rpd->acct_delay_time += conf_timeout;
+ rpd->acct_req->pack->id++;
+ if (req_set_RA(rpd->acct_req, conf_acct_secret))
+ break;
if (rad_req_send(rpd->acct_req))
break;
rad_req_wait(rpd->acct_req, conf_timeout);
diff --git a/accel-pptpd/radius/radius.c b/accel-pptpd/radius/radius.c
index 45f0ba9..f24724f 100644
--- a/accel-pptpd/radius/radius.c
+++ b/accel-pptpd/radius/radius.c
@@ -138,12 +138,14 @@ static void ppp_starting(struct ppp_t *ppp)
pthread_rwlock_unlock(&sessions_lock);
}
-static void ppp_started(struct ppp_t *ppp)
+static void ppp_acct_start(struct ppp_t *ppp)
{
struct radius_pd_t *rpd = find_pd(ppp);
- if (rad_acct_start(rpd))
+ if (rad_acct_start(rpd)) {
ppp_terminate(rpd->ppp, TERM_NAS_ERROR, 0);
+ return;
+ }
if (rpd->session_timeout.expire_tv.tv_sec) {
rpd->session_timeout.expire = session_timeout;
@@ -367,7 +369,7 @@ static void __init radius_init(void)
ipdb_register(&ipdb);
triton_event_register_handler(EV_PPP_STARTING, (triton_event_func)ppp_starting);
- triton_event_register_handler(EV_PPP_STARTED, (triton_event_func)ppp_started);
+ triton_event_register_handler(EV_PPP_ACCT_START, (triton_event_func)ppp_acct_start);
triton_event_register_handler(EV_PPP_FINISHING, (triton_event_func)ppp_finishing);
triton_event_register_handler(EV_PPP_FINISHED, (triton_event_func)ppp_finished);
}
diff --git a/accel-pptpd/radius/radius_p.h b/accel-pptpd/radius/radius_p.h
index e7b6216..d7f009d 100644
--- a/accel-pptpd/radius/radius_p.h
+++ b/accel-pptpd/radius/radius_p.h
@@ -30,6 +30,7 @@ struct radius_pd_t
struct ipdb_item_t ipaddr;
int acct_interim_interval;
+ int acct_delay_time;
};
struct rad_req_t
diff --git a/accel-pptpd/radius/req.c b/accel-pptpd/radius/req.c
index c6687d3..1941321 100644
--- a/accel-pptpd/radius/req.c
+++ b/accel-pptpd/radius/req.c
@@ -85,10 +85,10 @@ int rad_req_acct_fill(struct rad_req_t *req)
memset(req->RA, 0, sizeof(req->RA));
- if (rad_packet_add_val(req->pack, "Acct-Authentic", "RADIUS"))
- return -1;
if (rad_packet_add_val(req->pack, "Acct-Status-Type", "Start"))
return -1;
+ if (rad_packet_add_val(req->pack, "Acct-Authentic", "RADIUS"))
+ return -1;
if (rad_packet_add_str(req->pack, "Acct-Session-Id", req->rpd->ppp->sessionid, PPP_SESSIONID_LEN))
return -1;
if (rad_packet_add_int(req->pack, "Acct-Session-Time", 0))
@@ -105,6 +105,8 @@ int rad_req_acct_fill(struct rad_req_t *req)
return -1;
if (rad_packet_add_int(req->pack, "Acct-Output-Gigawords", 0))
return -1;
+ if (rad_packet_add_int(req->pack, "Acct-Delay-Time", 0))
+ return -1;
if (rad_packet_add_ipaddr(req->pack, "Framed-IP-Address", req->rpd->ppp->peer_ipaddr))
return -1;