Commit 0532a79e authored by Jiayuan Chen's avatar Jiayuan Chen Committed by Martin KaFai Lau
Browse files

strparser: Add read_sock callback



Added a new read_sock handler, allowing users to customize read operations
instead of relying on the native socket's read_sock.

Signed-off-by: default avatarJiayuan Chen <mrpre@163.com>
Signed-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
Reviewed-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Link: https://patch.msgid.link/20250122100917.49845-2-mrpre@163.com
parent bc27c52e
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -112,7 +112,7 @@ Functions
Callbacks
=========

There are six callbacks:
There are seven callbacks:

    ::

@@ -182,6 +182,13 @@ There are six callbacks:
    the length of the message. skb->len - offset may be greater
    then full_len since strparser does not trim the skb.

    ::

	int (*read_sock)(struct strparser *strp, read_descriptor_t *desc,
                     sk_read_actor_t recv_actor);

    The read_sock callback is used by strparser instead of
    sock->ops->read_sock, if provided.
    ::

	int (*read_sock_done)(struct strparser *strp, int err);
+2 −0
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ struct strparser;
struct strp_callbacks {
	int (*parse_msg)(struct strparser *strp, struct sk_buff *skb);
	void (*rcv_msg)(struct strparser *strp, struct sk_buff *skb);
	int (*read_sock)(struct strparser *strp, read_descriptor_t *desc,
			 sk_read_actor_t recv_actor);
	int (*read_sock_done)(struct strparser *strp, int err);
	void (*abort_parser)(struct strparser *strp, int err);
	void (*lock)(struct strparser *strp);
+9 −2
Original line number Diff line number Diff line
@@ -347,7 +347,10 @@ static int strp_read_sock(struct strparser *strp)
	struct socket *sock = strp->sk->sk_socket;
	read_descriptor_t desc;

	if (unlikely(!sock || !sock->ops || !sock->ops->read_sock))
	if (unlikely(!sock || !sock->ops))
		return -EBUSY;

	if (unlikely(!strp->cb.read_sock && !sock->ops->read_sock))
		return -EBUSY;

	desc.arg.data = strp;
@@ -355,6 +358,9 @@ static int strp_read_sock(struct strparser *strp)
	desc.count = 1; /* give more than one skb per call */

	/* sk should be locked here, so okay to do read_sock */
	if (strp->cb.read_sock)
		strp->cb.read_sock(strp, &desc, strp_recv);
	else
		sock->ops->read_sock(strp->sk, &desc, strp_recv);

	desc.error = strp->cb.read_sock_done(strp, desc.error);
@@ -468,6 +474,7 @@ int strp_init(struct strparser *strp, struct sock *sk,
	strp->cb.unlock = cb->unlock ? : strp_sock_unlock;
	strp->cb.rcv_msg = cb->rcv_msg;
	strp->cb.parse_msg = cb->parse_msg;
	strp->cb.read_sock = cb->read_sock;
	strp->cb.read_sock_done = cb->read_sock_done ? : default_read_sock_done;
	strp->cb.abort_parser = cb->abort_parser ? : strp_abort_strp;