This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 30bb3086be socketcan/recv : fixed recv filter not work in special case
30bb3086be is described below
commit 30bb3086be8ce8d53c382b276a57684ac8b5c9fc
Author: xucheng5 <[email protected]>
AuthorDate: Fri Sep 1 15:02:49 2023 +0800
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 <[email protected]>
---
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))
{