return 0;
}
+DIAG_OFF(format-nonliteral)
+/** Log a message in a canonical format.
+ *
+ * 'fmt' is from our source code, so we don't care about format literals.
+ */
+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, ...)
+{
+ va_list ap;
+ char *msg = NULL;
+
+ if (!DEBUG_ENABLED2) return;
+
+ va_start(ap, fmt);
+ if (*fmt) msg = talloc_asprintf(NULL, fmt, ap);
+ va_end(ap);
+
+ DEBUG2("proto_%s - failed reading socket %s - %s",
+ li->app_io->common.name, name, fr_radius_decode_fail_reason[reason]);
+
+ if (sock) {
+ DEBUG2("proto_%s - from client %pV port %u",
+ li->app_io->common.name, fr_box_ipaddr(sock->inet.src_ipaddr), sock->inet.src_port);
+ }
+
+ if (!msg) return;
+
+ DEBUG2("proto_%s - %s",
+ li->app_io->common.name, name, msg);
+ talloc_free(msg);
+}
+DIAG_ON(format-nonliteral)
+
/** Decode the packet
*
*/
fr_radius_limit_proxy_state_t limit_proxy_state; //!< Limit Proxy-State to packets containing
///< Message-Authenticator.
} proto_radius_t;
+
+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, ...);
break;
}
- PDEBUG2("proto_radius_tcp got read error (%zd) - %s", data_size, fr_syserror(errno));
+ proto_radius_log(li, thread->name, FR_RADIUS_FAIL_IO_ERROR, NULL,
+ "error reading socket - %s", fr_strerror());
return data_size;
}
* TCP read of zero means the socket is dead.
*/
if (!data_size) {
- DEBUG2("proto_radius_tcp - other side closed the socket.");
+ proto_radius_log(li, thread->name, FR_RADIUS_FAIL_IO_ERROR, NULL,
+ "Client closed the connection");
return -1;
}
* We MUST always start with a known RADIUS packet.
*/
if ((buffer[0] == 0) || (buffer[0] >= FR_RADIUS_CODE_MAX)) {
- DEBUG("proto_radius_tcp got invalid packet code %d", buffer[0]);
+ proto_radius_log(li, thread->name, FR_RADIUS_FAIL_UNKNOWN_PACKET_CODE, NULL,
+ "received packet code %u", buffer[0]);
thread->stats.total_unknown_types++;
return -1;
}
* If it's not a RADIUS packet, ignore it.
*/
if (!fr_radius_ok(buffer, &packet_len, inst->max_attributes, false, &reason)) {
- /*
- * @todo - check for F5 load balancer packets. <sigh>
- */
- DEBUG2("proto_radius_tcp got a packet which isn't RADIUS");
+ proto_radius_log(li, thread->name, reason, NULL, "");
thread->stats.total_malformed_requests++;
return -1;
}
SOURCES := proto_radius_tcp.c
-TGT_PREREQS := libfreeradius-radius$(L)
+TGT_PREREQS := libfreeradius-radius$(L) proto_radius$(L)
data_size = udp_recv(thread->sockfd, flags, &address->socket, buffer, buffer_len, recv_time_p);
if (data_size < 0) {
- PDEBUG2("proto_radius_udp got read error");
+ proto_radius_log(li, thread->name, FR_RADIUS_FAIL_IO_ERROR, NULL,
+ "error reading socket - %s", fr_strerror());
return data_size;
}
if (!data_size) {
- DEBUG2("proto_radius_udp got no data: ignoring");
+ proto_radius_log(li, thread->name, FR_RADIUS_FAIL_IO_ERROR, NULL,
+ "no data received");
return 0;
}
packet_len = data_size;
if (data_size < 20) {
- DEBUG2("proto_radius_udp got 'too short' packet size %zd", data_size);
+ proto_radius_log(li, thread->name, FR_RADIUS_FAIL_MIN_LENGTH_PACKET, &address->socket,
+ "received %zu which is smaller than minimum 20", packet_len);
thread->stats.total_malformed_requests++;
return 0;
}
if (packet_len > inst->max_packet_size) {
- DEBUG2("proto_radius_udp got 'too long' packet size %zd > %u", data_size, inst->max_packet_size);
+ proto_radius_log(li, thread->name, FR_RADIUS_FAIL_MIN_LENGTH_PACKET, &address->socket,
+ "received %zu which is larger than maximum %zu", packet_len, inst->max_packet_size);
thread->stats.total_malformed_requests++;
return 0;
}
- if ((buffer[0] == 0) || (buffer[0] > FR_RADIUS_CODE_MAX)) {
- DEBUG("proto_radius_udp got invalid packet code %d", buffer[0]);
+ if ((buffer[0] == 0) || (buffer[0] >= FR_RADIUS_CODE_MAX)) {
+ proto_radius_log(li, thread->name, FR_RADIUS_FAIL_UNKNOWN_PACKET_CODE, &address->socket,
+ "received packet code %u", buffer[0]);
thread->stats.total_unknown_types++;
return 0;
}
/*
- * If it's not a RADIUS packet, ignore it.
+ * If it's not well-formed, discard it.
*/
if (!fr_radius_ok(buffer, &packet_len, inst->max_attributes, false, &reason)) {
- /*
- * @todo - check for F5 load balancer packets. <sigh>
- */
- DEBUG2("proto_radius_udp got a packet which isn't RADIUS: %s", fr_strerror());
+ proto_radius_log(li, thread->name, reason, &address->socket,
+ "");
thread->stats.total_malformed_requests++;
return 0;
}
SOURCES := proto_radius_udp.c
-TGT_PREREQS := libfreeradius-radius$(L)
+TGT_PREREQS := libfreeradius-radius$(L) proto_radius$(L)
[FR_RADIUS_FAIL_VERIFY] = "packet fails verification (shared secret is incorrect)",
[FR_RADIUS_FAIL_NO_MATCHING_REQUEST] = "did not find request which matched response",
+ [FR_RADIUS_FAIL_IO_ERROR] = "IO error",
[FR_RADIUS_FAIL_MAX] = "???",
};
FR_RADIUS_FAIL_VERIFY,
FR_RADIUS_FAIL_NO_MATCHING_REQUEST,
+ FR_RADIUS_FAIL_IO_ERROR,
FR_RADIUS_FAIL_MAX
} fr_radius_decode_fail_t;