summaryrefslogtreecommitdiff
path: root/radsecproxy.c
diff options
context:
space:
mode:
authorvenaas <venaas>2008-09-22 15:20:38 +0000
committervenaas <venaas@e88ac4ed-0b26-0410-9574-a7f39faa03bf>2008-09-22 15:20:38 +0000
commit3a2b6fa277c26222b2dbb235dbd802a72ad46f32 (patch)
tree764ff299055299a9b34679018f7338fb1aa88b1f /radsecproxy.c
parent9989a0a7b4f52da41334a11ae28dc232aa7bac0b (diff)
reserving id 0 for status server when enabled
git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@396 e88ac4ed-0b26-0410-9574-a7f39faa03bf
Diffstat (limited to 'radsecproxy.c')
-rw-r--r--radsecproxy.c58
1 files changed, 36 insertions, 22 deletions
diff --git a/radsecproxy.c b/radsecproxy.c
index 80f6a47..91a6676 100644
--- a/radsecproxy.c
+++ b/radsecproxy.c
@@ -956,20 +956,23 @@ void freerqoutdata(struct rqout *rqout) {
}
void sendrq(struct server *to, struct request *rq) {
- int i;
+ int i, start;
+ start = to->conf->statusserver ? 1 : 0;
pthread_mutex_lock(&to->newrq_mutex);
- /* might simplify if only try nextid, might be ok */
- for (i = to->nextid; i < MAX_REQUESTS; i++) {
- if (!to->requests[i].rq) {
- pthread_mutex_lock(to->requests[i].lock);
- if (!to->requests[i].rq)
- break;
- pthread_mutex_unlock(to->requests[i].lock);
+ if (start && rq->msg->code == RAD_Status_Server) {
+ pthread_mutex_lock(to->requests[0].lock);
+ if (to->requests[0].rq) {
+ pthread_mutex_unlock(to->requests[0].lock);
+ debug(DBG_WARN, "sendrq: status server already in queue, dropping request");
+ goto errexit;
}
- }
- if (i == MAX_REQUESTS) {
- for (i = 0; i < to->nextid; i++) {
+ i = 0;
+ } else {
+ if (!to->nextid)
+ to->nextid = start;
+ /* might simplify if only try nextid, might be ok */
+ for (i = to->nextid; i < MAX_REQUESTS; i++) {
if (!to->requests[i].rq) {
pthread_mutex_lock(to->requests[i].lock);
if (!to->requests[i].rq)
@@ -977,28 +980,34 @@ void sendrq(struct server *to, struct request *rq) {
pthread_mutex_unlock(to->requests[i].lock);
}
}
- if (i == to->nextid) {
- debug(DBG_WARN, "sendrq: no room in queue, dropping request");
- rmclientrq(rq, rq->msg->id);
- freerq(rq);
- goto exit;
+ if (i == MAX_REQUESTS) {
+ for (i = start; i < to->nextid; i++) {
+ if (!to->requests[i].rq) {
+ pthread_mutex_lock(to->requests[i].lock);
+ if (!to->requests[i].rq)
+ break;
+ pthread_mutex_unlock(to->requests[i].lock);
+ }
+ }
+ if (i == to->nextid) {
+ debug(DBG_WARN, "sendrq: no room in queue, dropping request");
+ goto errexit;
+ }
}
}
-
rq->msg->id = (uint8_t)i;
rq->buf = radmsg2buf(rq->msg, (uint8_t *)to->conf->secret);
if (!rq->buf) {
pthread_mutex_unlock(to->requests[i].lock);
debug(DBG_ERR, "sendrq: radmsg2buf failed");
- rmclientrq(rq, rq->msg->id);
- freerq(rq);
- goto exit;
+ goto errexit;
}
debug(DBG_DBG, "sendrq: inserting packet with id %d in queue for %s", i, to->conf->host);
to->requests[i].rq = rq;
pthread_mutex_unlock(to->requests[i].lock);
- to->nextid = i + 1;
+ if (i >= start) /* i is not reserved for statusserver */
+ to->nextid = i + 1;
if (!to->newrq) {
to->newrq = 1;
@@ -1006,7 +1015,12 @@ void sendrq(struct server *to, struct request *rq) {
pthread_cond_signal(&to->newrq_cond);
}
- exit:
+ pthread_mutex_unlock(&to->newrq_mutex);
+ return;
+
+ errexit:
+ rmclientrq(rq, rq->msg->id);
+ freerq(rq);
pthread_mutex_unlock(&to->newrq_mutex);
}