Skip to content

Commit f6ceec6

Browse files
ralfliciPaolo Abeni
authored andcommitted
net: datagram: introduce datagram_poll_queue for custom receive queues
Some protocols using TCP encapsulation (e.g., espintcp, openvpn) deliver userspace-bound packets through a custom skb queue rather than the standard sk_receive_queue. Introduce datagram_poll_queue that accepts an explicit receive queue, and convert datagram_poll into a wrapper around datagram_poll_queue. This allows protocols with custom skb queues to reuse the core polling logic without relying on sk_receive_queue. Cc: Sabrina Dubroca <sd@queasysnail.net> Cc: Antonio Quartulli <antonio@openvpn.net> Signed-off-by: Ralf Lici <ralf@mandelbit.com> Reviewed-by: Sabrina Dubroca <sd@queasysnail.net> Reviewed-by: Antonio Quartulli <antonio@openvpn.net> Link: https://patch.msgid.link/20251021100942.195010-2-ralf@mandelbit.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 10843e1 commit f6ceec6

2 files changed

Lines changed: 37 additions & 10 deletions

File tree

include/linux/skbuff.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4204,6 +4204,9 @@ struct sk_buff *__skb_recv_datagram(struct sock *sk,
42044204
struct sk_buff_head *sk_queue,
42054205
unsigned int flags, int *off, int *err);
42064206
struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned int flags, int *err);
4207+
__poll_t datagram_poll_queue(struct file *file, struct socket *sock,
4208+
struct poll_table_struct *wait,
4209+
struct sk_buff_head *rcv_queue);
42074210
__poll_t datagram_poll(struct file *file, struct socket *sock,
42084211
struct poll_table_struct *wait);
42094212
int skb_copy_datagram_iter(const struct sk_buff *from, int offset,

net/core/datagram.c

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -920,21 +920,22 @@ int skb_copy_and_csum_datagram_msg(struct sk_buff *skb,
920920
EXPORT_SYMBOL(skb_copy_and_csum_datagram_msg);
921921

922922
/**
923-
* datagram_poll - generic datagram poll
923+
* datagram_poll_queue - same as datagram_poll, but on a specific receive
924+
* queue
924925
* @file: file struct
925926
* @sock: socket
926927
* @wait: poll table
928+
* @rcv_queue: receive queue to poll
927929
*
928-
* Datagram poll: Again totally generic. This also handles
929-
* sequenced packet sockets providing the socket receive queue
930-
* is only ever holding data ready to receive.
930+
* Performs polling on the given receive queue, handling shutdown, error,
931+
* and connection state. This is useful for protocols that deliver
932+
* userspace-bound packets through a custom queue instead of
933+
* sk->sk_receive_queue.
931934
*
932-
* Note: when you *don't* use this routine for this protocol,
933-
* and you use a different write policy from sock_writeable()
934-
* then please supply your own write_space callback.
935+
* Return: poll bitmask indicating the socket's current state
935936
*/
936-
__poll_t datagram_poll(struct file *file, struct socket *sock,
937-
poll_table *wait)
937+
__poll_t datagram_poll_queue(struct file *file, struct socket *sock,
938+
poll_table *wait, struct sk_buff_head *rcv_queue)
938939
{
939940
struct sock *sk = sock->sk;
940941
__poll_t mask;
@@ -956,7 +957,7 @@ __poll_t datagram_poll(struct file *file, struct socket *sock,
956957
mask |= EPOLLHUP;
957958

958959
/* readable? */
959-
if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
960+
if (!skb_queue_empty_lockless(rcv_queue))
960961
mask |= EPOLLIN | EPOLLRDNORM;
961962

962963
/* Connection-based need to check for termination and startup */
@@ -978,4 +979,27 @@ __poll_t datagram_poll(struct file *file, struct socket *sock,
978979

979980
return mask;
980981
}
982+
EXPORT_SYMBOL(datagram_poll_queue);
983+
984+
/**
985+
* datagram_poll - generic datagram poll
986+
* @file: file struct
987+
* @sock: socket
988+
* @wait: poll table
989+
*
990+
* Datagram poll: Again totally generic. This also handles
991+
* sequenced packet sockets providing the socket receive queue
992+
* is only ever holding data ready to receive.
993+
*
994+
* Note: when you *don't* use this routine for this protocol,
995+
* and you use a different write policy from sock_writeable()
996+
* then please supply your own write_space callback.
997+
*
998+
* Return: poll bitmask indicating the socket's current state
999+
*/
1000+
__poll_t datagram_poll(struct file *file, struct socket *sock, poll_table *wait)
1001+
{
1002+
return datagram_poll_queue(file, sock, wait,
1003+
&sock->sk->sk_receive_queue);
1004+
}
9811005
EXPORT_SYMBOL(datagram_poll);

0 commit comments

Comments
 (0)