summaryrefslogtreecommitdiff
path: root/accel-pppd/radius
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2011-08-24 18:43:02 +0400
committerKozlov Dmitry <dima@server>2011-08-24 18:43:02 +0400
commit9d4a4daad3221efefbdb2a6b98c301d75d9b23bc (patch)
tree32d3c206e2ee0b159f9589e327737c2f773665b3 /accel-pppd/radius
parent52223ac31751a5ec0bd8be3beb3fdd0559353b54 (diff)
downloadaccel-ppp-9d4a4daad3221efefbdb2a6b98c301d75d9b23bc.tar.gz
accel-ppp-9d4a4daad3221efefbdb2a6b98c301d75d9b23bc.zip
radius: load balancing improvement
Diffstat (limited to 'accel-pppd/radius')
-rw-r--r--accel-pppd/radius/acct.c12
-rw-r--r--accel-pppd/radius/auth.c4
-rw-r--r--accel-pppd/radius/radius_p.h7
-rw-r--r--accel-pppd/radius/req.c6
-rw-r--r--accel-pppd/radius/serv.c16
5 files changed, 24 insertions, 21 deletions
diff --git a/accel-pppd/radius/acct.c b/accel-pppd/radius/acct.c
index 04b21fa7..dcf2efe1 100644
--- a/accel-pppd/radius/acct.c
+++ b/accel-pppd/radius/acct.c
@@ -121,7 +121,7 @@ static void __rad_req_send(struct rad_req_t *req)
{
while (1) {
if (rad_server_req_enter(req)) {
- if (rad_server_realloc(req, RAD_SERV_ACCT)) {
+ if (rad_server_realloc(req)) {
if (conf_acct_timeout) {
log_ppp_warn("radius:acct: no servers available, terminating session...\n");
ppp_terminate(req->rpd->ppp, TERM_NAS_ERROR, 0);
@@ -164,7 +164,7 @@ static void rad_acct_timeout(struct triton_timer_t *t)
if (dt > conf_acct_timeout) {
rad_server_fail(req->serv);
- if (rad_server_realloc(req, RAD_SERV_ACCT)) {
+ if (rad_server_realloc(req)) {
log_ppp_warn("radius:acct: no servers available, terminating session...\n");
ppp_terminate(req->rpd->ppp, TERM_NAS_ERROR, 0);
return;
@@ -260,7 +260,7 @@ int rad_acct_start(struct radius_pd_t *rpd)
while (1) {
if (rad_server_req_enter(rpd->acct_req)) {
- if (rad_server_realloc(rpd->acct_req, RAD_SERV_ACCT)) {
+ if (rad_server_realloc(rpd->acct_req)) {
log_ppp_warn("radius:acct_start: no servers available\n");
goto out_err;
}
@@ -315,7 +315,7 @@ int rad_acct_start(struct radius_pd_t *rpd)
break;
rad_server_fail(rpd->acct_req->serv);
- if (rad_server_realloc(rpd->acct_req, RAD_SERV_ACCT)) {
+ if (rad_server_realloc(rpd->acct_req)) {
log_ppp_warn("radius:acct_start: no servers available\n");
goto out_err;
}
@@ -406,7 +406,7 @@ void rad_acct_stop(struct radius_pd_t *rpd)
while (1) {
if (rad_server_req_enter(rpd->acct_req)) {
- if (rad_server_realloc(rpd->acct_req, RAD_SERV_ACCT)) {
+ if (rad_server_realloc(rpd->acct_req)) {
log_ppp_warn("radius:acct_stop: no servers available\n");
break;
}
@@ -454,7 +454,7 @@ void rad_acct_stop(struct radius_pd_t *rpd)
break;
rad_server_fail(rpd->acct_req->serv);
- if (rad_server_realloc(rpd->acct_req, RAD_SERV_ACCT)) {
+ if (rad_server_realloc(rpd->acct_req)) {
log_ppp_warn("radius:acct_stop: no servers available\n");
break;
}
diff --git a/accel-pppd/radius/auth.c b/accel-pppd/radius/auth.c
index 639284a5..11557a64 100644
--- a/accel-pppd/radius/auth.c
+++ b/accel-pppd/radius/auth.c
@@ -151,7 +151,7 @@ static int rad_auth_send(struct rad_req_t *req)
while (1) {
if (rad_server_req_enter(req)) {
- if (rad_server_realloc(req, RAD_SERV_AUTH)) {
+ if (rad_server_realloc(req)) {
log_ppp_warn("radius: no available servers\n");
break;
}
@@ -198,7 +198,7 @@ static int rad_auth_send(struct rad_req_t *req)
if (!req->reply) {
rad_server_fail(req->serv);
- if (rad_server_realloc(req, RAD_SERV_AUTH)) {
+ if (rad_server_realloc(req)) {
log_ppp_warn("radius: no available servers\n");
break;
}
diff --git a/accel-pppd/radius/radius_p.h b/accel-pppd/radius/radius_p.h
index 1fecd881..f3f28e27 100644
--- a/accel-pppd/radius/radius_p.h
+++ b/accel-pppd/radius/radius_p.h
@@ -62,6 +62,7 @@ struct rad_req_t
in_addr_t server_addr;
int server_port;
+ int type;
};
struct rad_server_t
@@ -77,7 +78,7 @@ struct rad_server_t
int max_req_cnt;
int req_cnt;
struct list_head req_queue;
- int client_cnt;
+ int client_cnt[2];
time_t fail_time;
int conf_fail_time;
int timeout_cnt;
@@ -148,10 +149,10 @@ int rad_packet_send(struct rad_packet_t *pck, int fd, struct sockaddr_in *addr);
void dm_coa_cancel(struct radius_pd_t *pd);
struct rad_server_t *rad_server_get(int);
-void rad_server_put(struct rad_server_t *);
+void rad_server_put(struct rad_server_t *, int);
int rad_server_req_enter(struct rad_req_t *);
void rad_server_req_exit(struct rad_req_t *);
-int rad_server_realloc(struct rad_req_t *, int);
+int rad_server_realloc(struct rad_req_t *);
void rad_server_fail(struct rad_server_t *);
void rad_server_timeout(struct rad_server_t *);
void rad_server_reply(struct rad_server_t *);
diff --git a/accel-pppd/radius/req.c b/accel-pppd/radius/req.c
index 1f956bf2..c9b91494 100644
--- a/accel-pppd/radius/req.c
+++ b/accel-pppd/radius/req.c
@@ -32,7 +32,9 @@ struct rad_req_t *rad_req_alloc(struct radius_pd_t *rpd, int code, const char *u
req->hnd.fd = -1;
req->ctx.before_switch = log_switch;
- req->serv = rad_server_get(code == CODE_ACCESS_REQUEST ? RAD_SERV_AUTH : RAD_SERV_ACCT);
+ req->type = code == CODE_ACCESS_REQUEST ? RAD_SERV_AUTH : RAD_SERV_ACCT;
+
+ req->serv = rad_server_get(req->type);
if (!req->serv)
goto out_err;
@@ -151,7 +153,7 @@ int rad_req_acct_fill(struct rad_req_t *req)
void rad_req_free(struct rad_req_t *req)
{
if (req->serv)
- rad_server_put(req->serv);
+ rad_server_put(req->serv, req->type);
if (req->hnd.fd >= 0 )
close(req->hnd.fd);
if (req->pack)
diff --git a/accel-pppd/radius/serv.c b/accel-pppd/radius/serv.c
index 880268bf..4aaaef00 100644
--- a/accel-pppd/radius/serv.c
+++ b/accel-pppd/radius/serv.c
@@ -43,14 +43,14 @@ static struct rad_server_t *__rad_server_get(int type, struct rad_server_t *excl
continue;
}
- if (s->client_cnt < s0->client_cnt)
+ if (s->client_cnt[type] < s0->client_cnt[type])
s0 = s;
}
if (!s0)
return NULL;
- __sync_add_and_fetch(&s0->client_cnt, 1);
+ __sync_add_and_fetch(&s0->client_cnt[type], 1);
return s0;
}
@@ -60,9 +60,9 @@ struct rad_server_t *rad_server_get(int type)
return __rad_server_get(type, NULL);
}
-void rad_server_put(struct rad_server_t *s)
+void rad_server_put(struct rad_server_t *s, int type)
{
- __sync_sub_and_fetch(&s->client_cnt, 1);
+ __sync_sub_and_fetch(&s->client_cnt[type], 1);
}
int rad_server_req_enter(struct rad_req_t *req)
@@ -121,15 +121,15 @@ void rad_server_req_exit(struct rad_req_t *req)
triton_context_wakeup(r->rpd->ppp->ctrl->ctx);
}
-int rad_server_realloc(struct rad_req_t *req, int type)
+int rad_server_realloc(struct rad_req_t *req)
{
- struct rad_server_t *s = __rad_server_get(type, req->serv);
+ struct rad_server_t *s = __rad_server_get(req->type, req->serv);
if (!s)
return -1;
if (req->serv)
- rad_server_put(req->serv);
+ rad_server_put(req->serv, req->type);
req->serv = s;
@@ -140,7 +140,7 @@ int rad_server_realloc(struct rad_req_t *req, int type)
req->hnd.fd = -1;
}
- if (type) {
+ if (req->type == RAD_SERV_ACCT) {
req->server_addr = req->serv->acct_addr;
req->server_port = req->serv->acct_port;
} else {