Skip to content

Commit 06add39

Browse files
committed
print out the full socket information when decoding fails
1 parent 6e1f52c commit 06add39

File tree

4 files changed

+18
-24
lines changed

4 files changed

+18
-24
lines changed

src/listen/radius/proto_radius.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ DIAG_OFF(format-nonliteral)
225225
*
226226
* 'fmt' is from our source code, so we don't care about format literals.
227227
*/
228-
void proto_radius_log(fr_listen_t *li, char const *name, fr_radius_decode_fail_t reason,
228+
void proto_radius_log(fr_listen_t const *li, fr_radius_decode_fail_t reason,
229229
fr_socket_t const *sock, char const *fmt, ...)
230230
{
231231
va_list ap;
@@ -238,14 +238,14 @@ void proto_radius_log(fr_listen_t *li, char const *name, fr_radius_decode_fail_t
238238
va_end(ap);
239239

240240
if (sock) {
241-
EDEBUG2("proto_%s - discarding packet on socket %s from client %pV port %u - %s (%s)",
242-
li->app_io->common.name, name,
241+
EDEBUG2("proto_radius - discarding packet on socket %s from client %pV port %u - %s (%s)",
242+
li->name,
243243
fr_box_ipaddr(sock->inet.src_ipaddr), sock->inet.src_port,
244244
msg,
245245
fr_radius_decode_fail_reason[reason]);
246246
} else {
247-
EDEBUG2("proto_%s - discarding packet on socket %s - %s (%s)",
248-
li->app_io->common.name, name, msg, fr_radius_decode_fail_reason[reason]);
247+
EDEBUG2("proto_radius - discarding packet on socket %s - %s (%s)",
248+
li->name, msg, fr_radius_decode_fail_reason[reason]);
249249
}
250250

251251
EDEBUG2("For more information, please see " DOC_ROOT_URL "/troubleshooting/network/%s.html", url[reason]);
@@ -327,14 +327,8 @@ static int mod_decode(void const *instance, request_t *request, uint8_t *const d
327327
data, data_len, &decode_ctx) < 0) {
328328
talloc_free(decode_ctx.tmp_ctx);
329329

330-
/*
331-
* @todo - print out socket name, too.
332-
*/
333-
EDEBUG2("proto_%s - discarding packet - failed decode (%s)",
334-
inst->io.app_io->common.name, fr_radius_decode_fail_reason[decode_ctx.reason]);
335-
EDEBUG2("For more information, please see " DOC_ROOT_URL "/troubleshooting/network/%s.html",
336-
url[decode_ctx.reason]);
337-
330+
proto_radius_log(track->li, decode_ctx.reason, &address->socket,
331+
"decoding failed");
338332
return -1;
339333
}
340334
talloc_free(decode_ctx.tmp_ctx);

src/listen/radius/proto_radius.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ struct proto_radius_io_thread_s {
5656

5757
};
5858

59-
void proto_radius_log(fr_listen_t *li, char const *name, fr_radius_decode_fail_t reason, fr_socket_t const *sock, char const *fmt, ...);
59+
void proto_radius_log(fr_listen_t const *li, fr_radius_decode_fail_t reason, fr_socket_t const *sock, char const *fmt, ...);

src/listen/radius/proto_radius_tcp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static ssize_t mod_read(fr_listen_t *li, UNUSED void **packet_ctx, fr_time_t *re
145145
break;
146146
}
147147

148-
proto_radius_log(li, thread->name, FR_RADIUS_FAIL_IO_ERROR, NULL,
148+
proto_radius_log(li, FR_RADIUS_FAIL_IO_ERROR, NULL,
149149
"%s", fr_strerror());
150150
return data_size;
151151
}
@@ -160,7 +160,7 @@ static ssize_t mod_read(fr_listen_t *li, UNUSED void **packet_ctx, fr_time_t *re
160160
* TCP read of zero means the socket is dead.
161161
*/
162162
if (!data_size) {
163-
proto_radius_log(li, thread->name, FR_RADIUS_FAIL_IO_ERROR, NULL,
163+
proto_radius_log(li, FR_RADIUS_FAIL_IO_ERROR, NULL,
164164
"Client closed the connection");
165165
return -1;
166166
}
@@ -170,7 +170,7 @@ static ssize_t mod_read(fr_listen_t *li, UNUSED void **packet_ctx, fr_time_t *re
170170
* We MUST always start with a known RADIUS packet.
171171
*/
172172
if ((buffer[0] == 0) || (buffer[0] >= FR_RADIUS_CODE_MAX)) {
173-
proto_radius_log(li, thread->name, FR_RADIUS_FAIL_UNKNOWN_PACKET_CODE, NULL,
173+
proto_radius_log(li, FR_RADIUS_FAIL_UNKNOWN_PACKET_CODE, NULL,
174174
"Received packet code %u", buffer[0]);
175175
thread->stats.total_unknown_types++;
176176
return -1;
@@ -210,7 +210,7 @@ static ssize_t mod_read(fr_listen_t *li, UNUSED void **packet_ctx, fr_time_t *re
210210
* If it's not a RADIUS packet, ignore it.
211211
*/
212212
if (!fr_radius_ok(buffer, &packet_len, inst->max_attributes, false, &reason)) {
213-
proto_radius_log(li, thread->name, reason, NULL, "Received invalid packet");
213+
proto_radius_log(li, reason, NULL, "Received invalid packet");
214214
thread->stats.total_malformed_requests++;
215215
return -1;
216216
}

src/listen/radius/proto_radius_udp.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,35 +136,35 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
136136

137137
data_size = udp_recv(thread->sockfd, flags, &address->socket, buffer, buffer_len, recv_time_p);
138138
if (data_size < 0) {
139-
proto_radius_log(li, thread->name, FR_RADIUS_FAIL_IO_ERROR, NULL,
139+
proto_radius_log(li, FR_RADIUS_FAIL_IO_ERROR, NULL,
140140
"%s", fr_strerror());
141141
return data_size;
142142
}
143143

144144
if (!data_size) {
145-
proto_radius_log(li, thread->name, FR_RADIUS_FAIL_IO_ERROR, NULL,
145+
proto_radius_log(li, FR_RADIUS_FAIL_IO_ERROR, NULL,
146146
"Received no data");
147147
return 0;
148148
}
149149

150150
packet_len = data_size;
151151

152152
if (data_size < 20) {
153-
proto_radius_log(li, thread->name, FR_RADIUS_FAIL_MIN_LENGTH_PACKET, &address->socket,
153+
proto_radius_log(li, FR_RADIUS_FAIL_MIN_LENGTH_PACKET, &address->socket,
154154
"Received packet length %zu", packet_len);
155155
thread->stats.total_malformed_requests++;
156156
return 0;
157157
}
158158

159159
if (packet_len > inst->max_packet_size) {
160-
proto_radius_log(li, thread->name, FR_RADIUS_FAIL_MIN_LENGTH_PACKET, &address->socket,
160+
proto_radius_log(li, FR_RADIUS_FAIL_MIN_LENGTH_PACKET, &address->socket,
161161
"Received packet length %zu");
162162
thread->stats.total_malformed_requests++;
163163
return 0;
164164
}
165165

166166
if ((buffer[0] == 0) || (buffer[0] >= FR_RADIUS_CODE_MAX)) {
167-
proto_radius_log(li, thread->name, FR_RADIUS_FAIL_UNKNOWN_PACKET_CODE, &address->socket,
167+
proto_radius_log(li, FR_RADIUS_FAIL_UNKNOWN_PACKET_CODE, &address->socket,
168168
"Received packet code %u", buffer[0]);
169169
thread->stats.total_unknown_types++;
170170
return 0;
@@ -174,7 +174,7 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
174174
* If it's not well-formed, discard it.
175175
*/
176176
if (!fr_radius_ok(buffer, &packet_len, inst->max_attributes, false, &reason)) {
177-
proto_radius_log(li, thread->name, reason, &address->socket,
177+
proto_radius_log(li, reason, &address->socket,
178178
"Received invalid packet");
179179
thread->stats.total_malformed_requests++;
180180
return 0;

0 commit comments

Comments
 (0)