Skip to content

Commit 86f1573

Browse files
committed
rate-limit complaints for injected packets
when we open a new connected UDP socket, the main socket might still have some packets in the inbound kernel queue. We normally read those, and push them to the connected socket. But if the connected socket / message queue is full, then we complain loudly.
1 parent f155323 commit 86f1573

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/lib/io/master.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ typedef struct {
4949
uint64_t client_id; //!< Unique client identifier.
5050
fr_rate_limit_t unknown_client;
5151
fr_rate_limit_t repeat_nak;
52+
fr_rate_limit_t queue_full;
5253
} fr_io_thread_t;
5354

5455
/** A saved packet
@@ -1345,7 +1346,7 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
13451346
*/
13461347
if (fr_time_neq(pending->recv_time, track->timestamp)) {
13471348
DEBUG3("Discarding old packet");
1348-
talloc_free(pending);
1349+
TALLOC_FREE(pending);
13491350
goto redo;
13501351
}
13511352

@@ -1365,7 +1366,7 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
13651366
* Shouldn't be necessary, but what the heck...
13661367
*/
13671368
memcpy(&address, track->address, sizeof(address));
1368-
talloc_free(pending);
1369+
TALLOC_FREE(pending);
13691370

13701371
/*
13711372
* Skip over all kinds of logic to find /
@@ -1719,7 +1720,7 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
17191720
DEBUG("Too many pending packets for dynamic client %pV - discarding packet",
17201721
fr_box_ipaddr(client->src_ipaddr));
17211722

1722-
done:
1723+
discard:
17231724
talloc_free(to_free);
17241725
return 0;
17251726
}
@@ -1732,7 +1733,7 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
17321733
if (!pending) {
17331734
INFO("proto_%s - Failed allocating space for dynamic client %pV - discarding packet",
17341735
inst->app_io->common.name, fr_box_ipaddr(client->src_ipaddr));
1735-
goto done;
1736+
goto discard;
17361737
}
17371738

17381739
if (fr_heap_num_elements(client->pending) > 1) {
@@ -1769,6 +1770,11 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
17691770
return packet_len;
17701771
}
17711772

1773+
/*
1774+
*
1775+
*/
1776+
fr_assert(!pending);
1777+
17721778
/*
17731779
* This must be the main UDP socket which creates
17741780
* connections.
@@ -1834,8 +1840,15 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time
18341840
* We don't need "to_free" after this, as it will be
18351841
* tracked in the connected socket.
18361842
*/
1837-
(void) fr_network_listen_inject(connection->nr, connection->listen,
1838-
buffer, packet_len, recv_time);
1843+
if (fr_network_listen_inject(connection->nr, connection->listen,
1844+
buffer, packet_len, recv_time) < 0) {
1845+
RATE_LIMIT_LOCAL(&thread->queue_full, ERROR, "proto_%s - Discarding packet from dynamic client %pV - cannot push packet to connected socket due to %s",
1846+
inst->app_io->common.name, fr_box_ipaddr(address.socket.inet.src_ipaddr), fr_strerror());
1847+
/*
1848+
* Don't return an error, because that will cause the listener to close its socket.
1849+
*/
1850+
}
1851+
18391852
return 0;
18401853
}
18411854

0 commit comments

Comments
 (0)