Skip to content

Commit

Permalink
improve error reporting for udp sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Mauchle committed May 6, 2018
1 parent ef3b193 commit 024a101
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 4 additions & 3 deletions dtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,15 @@ void *dtlslistener(void *arg) {
continue;

if (getConnectionInfo(s, (struct sockaddr *)&from, sizeof(from), (struct sockaddr *)&to, sizeof(to)) < 0) {
debug(DBG_DBG, "udptlsserverrd: getConnectionInfo failed");
debug(DBG_DBG, "dtlslistener: getConnectionInfo failed");
continue;
}

conf = find_clconf(handle, (struct sockaddr *)&from, NULL);
if (!conf) {
debug(DBG_INFO, "udpdtlsserverrd: got UDP from unknown peer %s, ignoring", addr2string((struct sockaddr *)&from));
recv(s, buf, 1, 0);
debug(DBG_INFO, "dtlslistener: got UDP from unknown peer %s, ignoring", addr2string((struct sockaddr *)&from));
if (recv(s, buf, 4, 0) == -1)
debug(DBG_ERR, "dtlslistener: recv failed - %s", strerror(errno));
continue;
}

Expand Down
12 changes: 8 additions & 4 deletions udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <regex.h>
#include <pthread.h>
#include <assert.h>
#include <errno.h>
#include "radsecproxy.h"
#include "hostport.h"

Expand Down Expand Up @@ -147,7 +148,7 @@ unsigned char *radudpget(int s, struct client **client, struct server **server,

cnt = recvfrom(s, buf, 4, MSG_PEEK | MSG_TRUNC, (struct sockaddr *)&from, &fromlen);
if (cnt == -1) {
debug(DBG_WARN, "radudpget: recv failed");
debug(DBG_ERR, "radudpget: recv failed - %s", strerror(errno));
continue;
}

Expand All @@ -156,21 +157,24 @@ unsigned char *radudpget(int s, struct client **client, struct server **server,
: find_srvconf(handle, (struct sockaddr *)&from, NULL);
if (!p) {
debug(DBG_WARN, "radudpget: got packet from wrong or unknown UDP peer %s, ignoring", addr2string((struct sockaddr *)&from));
recv(s, buf, 4, 0);
if (recv(s, buf, 4, 0) == -1)
debug(DBG_ERR, "radudpget: recv failed - %s", strerror(errno));
continue;
}

len = RADLEN(buf);
if (len < 20) {
debug(DBG_WARN, "radudpget: length too small");
recv(s, buf, 4, 0);
if (recv(s, buf, 4, 0) == -1)
debug(DBG_ERR, "radudpget: recv failed - %s", strerror(errno));
continue;
}

rad = malloc(len);
if (!rad) {
debug(DBG_ERR, "radudpget: malloc failed");
recv(s, buf, 4, 0);
if (recv(s, buf, 4, 0) == -1)
debug(DBG_ERR, "radudpget: recv failed - %s", strerror(errno));
continue;
}

Expand Down

0 comments on commit 024a101

Please sign in to comment.