Skip to content

Commit 9bc0009

Browse files
committed
Make more "failed to define client" messages, errors, and write them rate limited to the global log
Print messages about ignoring clients by default ...add toggle to turn this off for servers facing the internet
1 parent 7952f18 commit 9bc0009

File tree

5 files changed

+78
-26
lines changed

5 files changed

+78
-26
lines changed

src/lib/io/master.c

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#include <freeradius-devel/server/base.h>
2828
#include <freeradius-devel/server/module.h>
29+
#include <freeradius-devel/server/log.h>
30+
2931
#include <freeradius-devel/util/debug.h>
3032

3133
#include <freeradius-devel/util/misc.h>
@@ -47,9 +49,19 @@ typedef struct {
4749
uint32_t num_connections; //!< number of dynamic connections
4850
uint32_t num_pending_packets; //!< number of pending packets
4951
uint64_t client_id; //!< Unique client identifier.
50-
fr_rate_limit_t unknown_client;
51-
fr_rate_limit_t repeat_nak;
52-
fr_rate_limit_t queue_full;
52+
53+
struct {
54+
fr_rate_limit_t accept_failed;
55+
fr_rate_limit_t alloc_failed;
56+
fr_rate_limit_t bad_type;
57+
fr_rate_limit_t conn_alloc_failed;
58+
fr_rate_limit_t max_connections;
59+
fr_rate_limit_t queue_full;
60+
fr_rate_limit_t repeat_nak;
61+
fr_rate_limit_t too_many_pending;
62+
fr_rate_limit_t tracking_failed;
63+
fr_rate_limit_t unknown_client;
64+
} rate_limit;
5365
} fr_io_thread_t;
5466

5567
/** A saved packet
@@ -538,8 +550,9 @@ static fr_io_connection_t *fr_io_connection_alloc(fr_io_instance_t const *inst,
538550
(void) fr_trie_walk(thread->trie, &thread->num_connections, count_connections);
539551

540552
if ((thread->num_connections + 1) >= max_connections) {
541-
DEBUG("proto_%s - Ignoring connection from client %s - 'max_connections' limit reached.",
542-
inst->app->common.name, client->radclient->shortname);
553+
RATE_LIMIT_LOCAL(&thread->rate_limit.max_connections, INFO,
554+
"proto_%s - Ignoring connection from client %s - 'max_connections' limit reached.",
555+
inst->app->common.name, client->radclient->shortname);
543556
if (fd >= 0) close(fd);
544557
return NULL;
545558
}
@@ -1305,6 +1318,10 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
13051318
int value, accept_fd = -1;
13061319
uint32_t priority = PRIORITY_NORMAL;
13071320

1321+
/** Log that we ignore clients in debug mode, or when it's enabled for a listener
1322+
*/
1323+
#define LOG_IGNORED_CLIENTS(_inst) ((_inst)->log_ignored_clients || fr_debug_lvl >= 1)
1324+
13081325
get_inst(li, &inst, &thread, &connection, &child);
13091326

13101327
track = NULL;
@@ -1413,8 +1430,9 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
14131430
* OK. So don't return -1.
14141431
*/
14151432
if (accept_fd < 0) {
1416-
INFO("proto_%s - failed to accept new socket: %s",
1417-
inst->app->common.name, fr_syserror(errno));
1433+
RATE_LIMIT_LOCAL(&thread->rate_limit.accept_failed,
1434+
INFO, "proto_%s - failed to accept new socket: %s",
1435+
inst->app->common.name, fr_syserror(errno));
14181436
return 0;
14191437
}
14201438

@@ -1494,8 +1512,11 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
14941512
* the "name" of the socket, in the
14951513
* listener?
14961514
*/
1497-
DEBUG2("proto_%s - ignoring packet from IP %pV. It is not configured as 'type = ...'",
1498-
inst->app_io->common.name, fr_box_ipaddr(address.socket.inet.src_ipaddr));
1515+
if (LOG_IGNORED_CLIENTS(inst)) {
1516+
RATE_LIMIT_LOCAL(&thread->rate_limit.bad_type, INFO,
1517+
"proto_%s - ignoring packet from IP %pV. It is not configured as 'type = ...'",
1518+
inst->app_io->common.name, fr_box_ipaddr(address.socket.inet.src_ipaddr));
1519+
}
14991520
return 0;
15001521
}
15011522
priority = value;
@@ -1616,12 +1637,9 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
16161637
close(accept_fd);
16171638
}
16181639

1619-
if (DEBUG_ENABLED) {
1620-
DEBUG("proto_%s - Ignoring %s from IP address %pV - %s",
1621-
inst->app_io->common.name, msg, fr_box_ipaddr(address.socket.inet.src_ipaddr),
1622-
error);
1623-
} else {
1624-
RATE_LIMIT_LOCAL(&thread->unknown_client, ERROR, "proto_%s - Ignoring %s from IP address %pV - %s",
1640+
if (LOG_IGNORED_CLIENTS(inst)) {
1641+
RATE_LIMIT_LOCAL(&thread->rate_limit.unknown_client,
1642+
ERROR, "proto_%s - Ignoring %s from IP address %pV - %s",
16251643
inst->app_io->common.name, msg, fr_box_ipaddr(address.socket.inet.src_ipaddr),
16261644
error);
16271645
}
@@ -1642,7 +1660,8 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
16421660
*/
16431661
if (accept_fd >= 0) {
16441662
if (!fr_io_connection_alloc(inst, thread, client, accept_fd, &address, NULL)) {
1645-
DEBUG("Failed to allocate connection from client %s.", client->radclient->shortname);
1663+
RATE_LIMIT_LOCAL(&thread->rate_limit.conn_alloc_failed,
1664+
ERROR, "Failed to allocate connection from client %s", client->radclient->shortname);
16461665
}
16471666

16481667
return 0;
@@ -1667,8 +1686,9 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
16671686

16681687
track = fr_io_track_add(client, &address, buffer, packet_len, recv_time, &is_dup);
16691688
if (!track) {
1670-
DEBUG("Failed tracking packet from client %s - discarding it",
1671-
client->radclient->shortname);
1689+
RATE_LIMIT_LOCAL(&thread->rate_limit.tracking_failed,
1690+
ERROR, "Failed tracking packet from client %s - discarding it",
1691+
client->radclient->shortname);
16721692
return 0;
16731693
}
16741694

@@ -1736,8 +1756,9 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
17361756
* to track pending packets.
17371757
*/
17381758
if (!connection && inst->max_pending_packets && (thread->num_pending_packets >= inst->max_pending_packets)) {
1739-
DEBUG("Too many pending packets from dynamic client %pV - discarding packet",
1740-
fr_box_ipaddr(client->src_ipaddr));
1759+
RATE_LIMIT_LOCAL(&thread->rate_limit.too_many_pending,
1760+
ERROR, "Too many pending dynamic client packets for listener - discarding packet from %pV",
1761+
fr_box_ipaddr(client->src_ipaddr));
17411762

17421763
discard:
17431764
talloc_free(to_free);
@@ -1750,8 +1771,9 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
17501771
pending = fr_io_pending_alloc(connection, client, buffer, packet_len,
17511772
track, priority);
17521773
if (!pending) {
1753-
INFO("proto_%s - Failed allocating space for dynamic client %pV - discarding packet",
1754-
inst->app_io->common.name, fr_box_ipaddr(client->src_ipaddr));
1774+
RATE_LIMIT_LOCAL(&thread->rate_limit.alloc_failed,
1775+
ERROR, "proto_%s - Failed allocating space for dynamic client %pV - discarding packet",
1776+
inst->app_io->common.name, fr_box_ipaddr(client->src_ipaddr));
17551777
goto discard;
17561778
}
17571779

@@ -1822,7 +1844,7 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
18221844
* for it.
18231845
*/
18241846
if (nak) {
1825-
RATE_LIMIT_LOCAL(&thread->repeat_nak, ERROR, "proto_%s - Discarding repeated packet from NAK'd dynamic client %pV",
1847+
RATE_LIMIT_LOCAL(&thread->rate_limit.repeat_nak, ERROR, "proto_%s - Discarding repeated packet from NAK'd dynamic client %pV",
18261848
inst->app_io->common.name, fr_box_ipaddr(address.socket.inet.src_ipaddr));
18271849

18281850
DEBUG("Discarding packet to NAKed connection %s", connection->name);
@@ -1836,7 +1858,8 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
18361858
if (!connection) {
18371859
connection = fr_io_connection_alloc(inst, thread, client, -1, &address, NULL);
18381860
if (!connection) {
1839-
DEBUG("Failed to allocate connection from client %s. Discarding packet.", client->radclient->shortname);
1861+
RATE_LIMIT_LOCAL(&thread->rate_limit.conn_alloc_failed,
1862+
ERROR, "Failed to allocate connection from client %s. Discarding packet.", client->radclient->shortname);
18401863
return 0;
18411864
}
18421865
}
@@ -1861,8 +1884,9 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
18611884
*/
18621885
if (fr_network_listen_inject(connection->nr, connection->listen,
18631886
buffer, packet_len, recv_time) < 0) {
1864-
RATE_LIMIT_LOCAL(&thread->queue_full, ERROR, "proto_%s - Discarding packet from dynamic client %pV - cannot push packet to connected socket due to %s",
1865-
inst->app_io->common.name, fr_box_ipaddr(address.socket.inet.src_ipaddr), fr_strerror());
1887+
RATE_LIMIT_LOCAL(&thread->rate_limit.queue_full, PERROR,
1888+
"proto_%s - Discarding packet from dynamic client %pV - cannot push packet to connected socket",
1889+
inst->app_io->common.name, fr_box_ipaddr(address.socket.inet.src_ipaddr));
18661890
/*
18671891
* Don't return an error, because that will cause the listener to close its socket.
18681892
*/

src/lib/io/master.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ typedef struct {
8585
fr_time_delta_t check_interval; //!< polling for closed sockets
8686

8787
bool dynamic_clients; //!< do we have dynamic clients.
88+
bool log_ignored_clients; //!< Whether we emit log messages when we ignore
89+
///< a client because it's unknown, or outside
90+
///< of the allowed networks. This is here for
91+
///< people who expose their RADIUS servers to
92+
///< the internet, and don't want their logs filling
93+
///< up with random connection attempts.
8894

8995
CONF_SECTION *server_cs; //!< server CS for this listener
9096

src/listen/dhcpv4/proto_dhcpv4.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ static conf_parser_t const limit_config[] = {
7070
CONF_PARSER_TERMINATOR
7171
};
7272

73+
static conf_parser_t const log_config[] = {
74+
{ FR_CONF_OFFSET("ignored_clients", proto_dhcpv4_t, io.log_ignored_clients), .dflt = "yes" } ,
75+
76+
CONF_PARSER_TERMINATOR
77+
};
78+
7379
/** How to parse a DHCPV4 listen section
7480
*
7581
*/
@@ -78,6 +84,7 @@ static conf_parser_t const proto_dhcpv4_config[] = {
7884
{ FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_dhcpv4_t, io.submodule),
7985
.func = transport_parse },
8086

87+
{ FR_CONF_POINTER("log", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) log_config },
8188
{ FR_CONF_POINTER("limit", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) limit_config },
8289

8390
CONF_PARSER_TERMINATOR

src/listen/dhcpv6/proto_dhcpv6.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ static conf_parser_t const limit_config[] = {
7171
CONF_PARSER_TERMINATOR
7272
};
7373

74+
static conf_parser_t const log_config[] = {
75+
{ FR_CONF_OFFSET("ignored_clients", proto_dhcpv6_t, io.log_ignored_clients), .dflt = "yes" } ,
76+
77+
CONF_PARSER_TERMINATOR
78+
};
79+
7480
/** How to parse a DHCPV6 listen section
7581
*
7682
*/
@@ -79,6 +85,7 @@ static conf_parser_t const proto_dhcpv6_config[] = {
7985
{ FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_dhcpv6_t, io.submodule),
8086
.func = transport_parse },
8187

88+
{ FR_CONF_POINTER("log", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) log_config },
8289
{ FR_CONF_POINTER("limit", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) limit_config },
8390

8491
CONF_PARSER_TERMINATOR

src/listen/radius/proto_radius.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ static const conf_parser_t priority_config[] = {
6767
CONF_PARSER_TERMINATOR
6868
};
6969

70+
static conf_parser_t const log_config[] = {
71+
{ FR_CONF_OFFSET("ignored_clients", proto_radius_t, io.log_ignored_clients), .dflt = "yes" } ,
72+
73+
CONF_PARSER_TERMINATOR
74+
};
75+
7076
/** How to parse a RADIUS listen section
7177
*
7278
*/
@@ -84,6 +90,8 @@ static conf_parser_t const proto_radius_config[] = {
8490
{ FR_CONF_POINTER("limit", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) limit_config },
8591
{ FR_CONF_POINTER("priority", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) priority_config },
8692

93+
{ FR_CONF_POINTER("log", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) log_config },
94+
8795
{ FR_CONF_OFFSET("require_message_authenticator", proto_radius_t, require_message_authenticator),
8896
.func = cf_table_parse_int,
8997
.uctx = &(cf_table_parse_ctx_t){ .table = fr_radius_require_ma_table, .len = &fr_radius_require_ma_table_len },

0 commit comments

Comments
 (0)