Skip to contentSkip to conversation

net: UDP repair mode for retrieving the send queue of corked UDP socket

PATCH In review Leşe Doru Călin 3 participants 4 messages Apr 16, 2020 – Apr 22, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 net: UDP repair mode for retrieving the send queue of corked UDP socket

In this year's edition of GSoC, there is a project idea for CRIU to add support for checkpoint/restore of cork-ed UDP sockets. But to add it, the kernel API needs to be extended.

This is what this patch does. It adds UDP "repair mode" for UDP sockets in a similar approach to the TCP "repair mode", but only the send queue is necessary to be retrieved. So the patch extends the recv and setsockopt syscalls. Using UDP_REPAIR option in setsockopt, caller can set the socket in repair mode. If it is setted, the recv/recvfrom/recvmsg will receive the write queue and the destination of the data. As in the TCP mode, to change the repair mode requires the CAP_NET_ADMIN capability and to receive data the caller is obliged to use the MSG_PEEK flag.

---
 include/linux/udp.h      |    3 +
 include/net/udp.h        |    3 +
 include/uapi/linux/udp.h |    1 
 net/ipv4/udp.c           |   85 +++++++++++++++++++++++++++++++++++++++--------
 net/ipv6/udp.c           |   64 ++++++++++++++++++++++++-----------
 5 files changed, 122 insertions(+), 34 deletions(-)
include/linux/udp.h +2 -1
index aa84597bdc33..b22bd70118ce 100644
@@ -51,7 +51,8 @@ struct udp_sock {
 					   * different encapsulation layer set
 					   * this
 					   */
-			 gro_enabled:1;	/* Can accept GRO packets */
+			 gro_enabled:1,	/* Can accept GRO packets */
+			 repair:1;/* Receive the send queue */
 	/*
 	 * Following member retains the information to create a UDP header
 	 * when the socket is uncorked.
include/net/udp.h +3 -0
index a8fa6c0c6ded..f7a7fab0712f 100644
@@ -282,8 +282,11 @@ int udp_get_port(struct sock *sk, unsigned short snum,
 int udp_err(struct sk_buff *, u32);
 int udp_abort(struct sock *sk, int err);
 int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len);
+int udp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
+			int noblock, int flags, int *addr_len);
 int udp_push_pending_frames(struct sock *sk);
 void udp_flush_pending_frames(struct sock *sk);
+int udp_peek_sndq(struct sock *sk, struct msghdr *msg, int off, int len);
 int udp_cmsg_send(struct sock *sk, struct msghdr *msg, u16 *gso_size);
 void udp4_hwcsum(struct sk_buff *skb, __be32 src, __be32 dst);
 int udp_rcv(struct sk_buff *skb);
include/uapi/linux/udp.h +1 -0
index 4828794efcf8..2fe78329d6da 100644
@@ -29,6 +29,7 @@ struct udphdr {
 
 /* UDP socket options */
 #define UDP_CORK	1	/* Never send partially complete segments */
+#define UDP_REPAIR  19  /* Receive the send queue */
 #define UDP_ENCAP	100	/* Set the socket to accept encapsulated packets */
 #define UDP_NO_CHECK6_TX 101	/* Disable sending checksum for UDP6X */
 #define UDP_NO_CHECK6_RX 102	/* Disable accpeting checksum for UDP6 */
net/ipv4/udp.c +71 -14

128 lines not on this page · raw message

net/ipv6/udp.c +45 -19

93 lines not on this page · raw message

#1 lore raw

Should I move this functionality in a getsockopt or ioctl syscall, so it does not interfere with other syscalls?

maintainer
#2 lore raw
Quoted 1 line · Leşe Doru Călin

Should I move this functionality in a getsockopt or ioctl syscall, so it does not interfere with other syscalls?

Yes, please. As suggested by Eric, please avoid additional code/conditionals in fast-path.

Thanks,

Paolo

p.s. sorry for the late reply. The current situation does not allow for low latency.

maintainer
#3 lore raw
In reply to Leşe Doru Călin

From: Leşe Doru Călin <[email protected]>
Date: Thu, 16 Apr 2020 16:22:42 +0300

Quoted 13 lines

In this year's edition of GSoC, there is a project idea for CRIU to add support for checkpoint/restore of cork-ed UDP sockets. But to add it, the kernel API needs to be extended.

This is what this patch does. It adds UDP "repair mode" for UDP sockets in a similar approach to the TCP "repair mode", but only the send queue is necessary to be retrieved. So the patch extends the recv and setsockopt syscalls. Using UDP_REPAIR option in setsockopt, caller can set the socket in repair mode. If it is setted, the recv/recvfrom/recvmsg will receive the write queue and the destination of the data. As in the TCP mode, to change the repair mode requires the CAP_NET_ADMIN capability and to receive data the caller is obliged to use the MSG_PEEK flag.

Quoted 1 line

I'm not applying this without any reviews.

So if someone cares about this feature they should review this change.

Thank you.