From 30bb3086be8ce8d53c382b276a57684ac8b5c9fc Mon Sep 17 00:00:00 2001 From: xucheng5 Date: Fri, 1 Sep 2023 15:02:49 +0800 Subject: [PATCH] socketcan/recv : fixed recv filter not work in special case can recv filter doesn't work when there is any CAN data already buffered in a read-ahead buffer Signed-off-by: xucheng5 --- net/can/can_recvmsg.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/net/can/can_recvmsg.c b/net/can/can_recvmsg.c index 7477734489..e2fcfe78c4 100644 --- a/net/can/can_recvmsg.c +++ b/net/can/can_recvmsg.c @@ -72,6 +72,10 @@ struct can_recvfrom_s * Private Functions ****************************************************************************/ +#ifdef CONFIG_NET_CANPROTO_OPTIONS +static int can_recv_filter(struct can_conn_s *conn, canid_t id); +#endif + /**************************************************************************** * Name: can_add_recvlen * @@ -234,6 +238,31 @@ static inline int can_readahead(struct can_recvfrom_s *pstate) { DEBUGASSERT(iob->io_pktlen > 0); +#ifdef CONFIG_NET_CANPROTO_OPTIONS + /* Check receive filters */ + + canid_t can_id; + iob_copyout((uint8_t *)&can_id, iob, sizeof(canid_t), 0); + + if (can_recv_filter(conn, can_id) == 0) + { + FAR struct iob_s *tmp; + + /* Remove the I/O buffer chain from the head of the read-ahead + * buffer queue. + */ + + tmp = iob_remove_queue(&conn->readahead); + DEBUGASSERT(tmp == iob); + UNUSED(tmp); + + /* And free the I/O buffer chain */ + + iob_free_chain(iob); + return 0; + } +#endif + #ifdef CONFIG_NET_TIMESTAMP if (conn->timestamp && pstate->pr_msglen == sizeof(struct timeval)) {