X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=udp.c;h=3079a68b629017a3443f5caadeeaeb992b076744;hb=7c62bcd00721941f7c28780266edb3076fc8b9d4;hp=4d274250201a8bdff1d8e87ddd9b3b1b405f581f;hpb=52570225d77be0f9c751ab30e8ec6f98639be827;p=radsecproxy.git 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); }