Skip to content

Commit 0532a79

Browse files
mrpreMartin KaFai Lau
authored andcommitted
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: Jiayuan Chen <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Reviewed-by: Jakub Sitnicki <[email protected]> Acked-by: John Fastabend <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent bc27c52 commit 0532a79

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Documentation/networking/strparser.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Functions
112112
Callbacks
113113
=========
114114

115-
There are six callbacks:
115+
There are seven callbacks:
116116

117117
::
118118

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

185+
::
186+
187+
int (*read_sock)(struct strparser *strp, read_descriptor_t *desc,
188+
sk_read_actor_t recv_actor);
189+
190+
The read_sock callback is used by strparser instead of
191+
sock->ops->read_sock, if provided.
185192
::
186193

187194
int (*read_sock_done)(struct strparser *strp, int err);

include/net/strparser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ struct strparser;
4343
struct strp_callbacks {
4444
int (*parse_msg)(struct strparser *strp, struct sk_buff *skb);
4545
void (*rcv_msg)(struct strparser *strp, struct sk_buff *skb);
46+
int (*read_sock)(struct strparser *strp, read_descriptor_t *desc,
47+
sk_read_actor_t recv_actor);
4648
int (*read_sock_done)(struct strparser *strp, int err);
4749
void (*abort_parser)(struct strparser *strp, int err);
4850
void (*lock)(struct strparser *strp);

net/strparser/strparser.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,21 @@ static int strp_read_sock(struct strparser *strp)
347347
struct socket *sock = strp->sk->sk_socket;
348348
read_descriptor_t desc;
349349

350-
if (unlikely(!sock || !sock->ops || !sock->ops->read_sock))
350+
if (unlikely(!sock || !sock->ops))
351+
return -EBUSY;
352+
353+
if (unlikely(!strp->cb.read_sock && !sock->ops->read_sock))
351354
return -EBUSY;
352355

353356
desc.arg.data = strp;
354357
desc.error = 0;
355358
desc.count = 1; /* give more than one skb per call */
356359

357360
/* sk should be locked here, so okay to do read_sock */
358-
sock->ops->read_sock(strp->sk, &desc, strp_recv);
361+
if (strp->cb.read_sock)
362+
strp->cb.read_sock(strp, &desc, strp_recv);
363+
else
364+
sock->ops->read_sock(strp->sk, &desc, strp_recv);
359365

360366
desc.error = strp->cb.read_sock_done(strp, desc.error);
361367

@@ -468,6 +474,7 @@ int strp_init(struct strparser *strp, struct sock *sk,
468474
strp->cb.unlock = cb->unlock ? : strp_sock_unlock;
469475
strp->cb.rcv_msg = cb->rcv_msg;
470476
strp->cb.parse_msg = cb->parse_msg;
477+
strp->cb.read_sock = cb->read_sock;
471478
strp->cb.read_sock_done = cb->read_sock_done ? : default_read_sock_done;
472479
strp->cb.abort_parser = cb->abort_parser ? : strp_abort_strp;
473480

0 commit comments

Comments
 (0)