Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Ralf Lici and committed by
Paolo Abeni
f6ceec64 10843e14

+37 -10
+3
include/linux/skbuff.h
··· 4204 4204 struct sk_buff_head *sk_queue, 4205 4205 unsigned int flags, int *off, int *err); 4206 4206 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); 4207 4210 __poll_t datagram_poll(struct file *file, struct socket *sock, 4208 4211 struct poll_table_struct *wait); 4209 4212 int skb_copy_datagram_iter(const struct sk_buff *from, int offset,
+34 -10
net/core/datagram.c
··· 920 920 EXPORT_SYMBOL(skb_copy_and_csum_datagram_msg); 921 921 922 922 /** 923 - * datagram_poll - generic datagram poll 923 + * datagram_poll_queue - same as datagram_poll, but on a specific receive 924 + * queue 924 925 * @file: file struct 925 926 * @sock: socket 926 927 * @wait: poll table 928 + * @rcv_queue: receive queue to poll 927 929 * 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. 931 934 * 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 935 936 */ 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) 938 939 { 939 940 struct sock *sk = sock->sk; 940 941 __poll_t mask; ··· 957 956 mask |= EPOLLHUP; 958 957 959 958 /* readable? */ 960 - if (!skb_queue_empty_lockless(&sk->sk_receive_queue)) 959 + if (!skb_queue_empty_lockless(rcv_queue)) 961 960 mask |= EPOLLIN | EPOLLRDNORM; 962 961 963 962 /* Connection-based need to check for termination and startup */ ··· 978 977 sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk); 979 978 980 979 return mask; 980 + } 981 + EXPORT_SYMBOL(datagram_poll_queue); 982 + 983 + /** 984 + * datagram_poll - generic datagram poll 985 + * @file: file struct 986 + * @sock: socket 987 + * @wait: poll table 988 + * 989 + * Datagram poll: Again totally generic. This also handles 990 + * sequenced packet sockets providing the socket receive queue 991 + * is only ever holding data ready to receive. 992 + * 993 + * Note: when you *don't* use this routine for this protocol, 994 + * and you use a different write policy from sock_writeable() 995 + * then please supply your own write_space callback. 996 + * 997 + * Return: poll bitmask indicating the socket's current state 998 + */ 999 + __poll_t datagram_poll(struct file *file, struct socket *sock, poll_table *wait) 1000 + { 1001 + return datagram_poll_queue(file, sock, wait, 1002 + &sock->sk->sk_receive_queue); 981 1003 } 982 1004 EXPORT_SYMBOL(datagram_poll);