From: Alan T. DeKok Date: Thu, 9 Mar 2023 22:26:15 +0000 (-0500) Subject: call bfd_session_process() when receiving a packet X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=065e833cd5cd614fd6050e6c9b0fbd2a03453096;p=thirdparty%2Ffreeradius-server.git call bfd_session_process() when receiving a packet for now, we run the unlang sections only when there's a state change on receiving a packet. We don't run unlang when receiving the continual "up" packets. We don't run unlang when sending packets. --- diff --git a/src/listen/bfd/proto_bfd_udp.c b/src/listen/bfd/proto_bfd_udp.c index eee7733bb7e..cf9651038f4 100644 --- a/src/listen/bfd/proto_bfd_udp.c +++ b/src/listen/bfd/proto_bfd_udp.c @@ -104,9 +104,10 @@ static const CONF_PARSER udp_listen_config[] = { static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time_p, uint8_t *buffer, size_t buffer_len, size_t *leftover, UNUSED uint32_t *priority, UNUSED bool *is_dup) { -// proto_bfd_udp_t const *inst = talloc_get_type_abort_const(li->app_io_instance, proto_bfd_udp_t); + proto_bfd_udp_t const *inst = talloc_get_type_abort_const(li->app_io_instance, proto_bfd_udp_t); proto_bfd_udp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_bfd_udp_thread_t); fr_io_address_t *address, **address_p; + fr_client_t *client; int flags; ssize_t data_size; @@ -140,6 +141,17 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time return 0; } + /* + * Try to find the client before looking at any packet data. + */ + client = fr_rb_find(inst->peers, &(fr_client_t) { .ipaddr = address->socket.inet.src_ipaddr, .proto = IPPROTO_UDP }); + if (!client) { + DEBUG2("proto_bfd_udp - Received invalid packet on %s - uknown client %pV:%u", thread->name, + fr_box_ipaddr(address->socket.inet.src_ipaddr), address->socket.inet.src_port); + thread->stats.total_packets_dropped++; + return 0; + } + packet_len = data_size; if (!fr_bfd_packet_ok(&err, buffer, packet_len)) { @@ -160,6 +172,12 @@ static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time (int) packet_len, thread->name, fr_box_ipaddr(address->socket.inet.src_ipaddr), address->socket.inet.src_port); + /* + * Run the BFD state machine. Depending on that result, + * we either send the packet through to unlang, or not. + */ + if (!bfd_session_process((proto_bfd_peer_t *) client, packet)) return 0; + return packet_len; }