summaryrefslogtreecommitdiff
path: root/udp.c
diff options
context:
space:
mode:
authorvenaas <venaas>2008-09-16 09:29:11 +0000
committervenaas <venaas@e88ac4ed-0b26-0410-9574-a7f39faa03bf>2008-09-16 09:29:11 +0000
commit7c62bcd00721941f7c28780266edb3076fc8b9d4 (patch)
tree938ea86d108a737859758d69b5baa6644ee6fc42 /udp.c
parent52570225d77be0f9c751ab30e8ec6f98639be827 (diff)
renamed some stuff, added client state for received rqs etc
git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@379 e88ac4ed-0b26-0410-9574-a7f39faa03bf
Diffstat (limited to 'udp.c')
-rw-r--r--udp.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/udp.c b/udp.c
index 4d27425..3079a68 100644
--- a/udp.c
+++ b/udp.c
@@ -102,22 +102,28 @@ unsigned char *radudpget(int s, struct client **client, struct server **server,
debug(DBG_DBG, "radudpget: packet was padded with %d bytes", cnt - len);
if (client) {
+ pthread_mutex_lock(p->lock);
for (node = list_first(p->clients); node; node = list_next(node))
if (addr_equal((struct sockaddr *)&from, ((struct client *)node->data)->addr))
break;
if (node) {
*client = (struct client *)node->data;
+ pthread_mutex_unlock(p->lock);
break;
}
fromcopy = addr_copy((struct sockaddr *)&from);
- if (!fromcopy)
+ if (!fromcopy) {
+ pthread_mutex_unlock(p->lock);
continue;
- *client = addclient(p);
+ }
+ *client = addclient(p, 0);
if (!*client) {
free(fromcopy);
+ pthread_mutex_unlock(p->lock);
continue;
}
(*client)->addr = fromcopy;
+ pthread_mutex_unlock(p->lock);
} else if (server)
*server = p->servers;
break;
@@ -178,14 +184,19 @@ void *udpclientrd(void *arg) {
}
void *udpserverrd(void *arg) {
- struct request rq;
+ struct request *rq;
int *sp = (int *)arg;
for (;;) {
- memset(&rq, 0, sizeof(struct request));
- rq.buf = radudpget(*sp, &rq.from, NULL, &rq.fromsa);
- rq.fromudpsock = *sp;
- radsrv(&rq);
+ rq = newrequest();
+ if (!rq) {
+ sleep(5); /* malloc failed */
+ continue;
+ }
+ rq->buf = radudpget(*sp, &rq->from, NULL, &rq->fromsa);
+ rq->fromudpsock = *sp;
+ radsrv(rq);
+ freerq(rq);
}
free(sp);
}