Skip to contentSkip to conversation

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

PATCH Superseded Leşe Doru Călin 2 participants 6 messages Apr 8, 2020 – Apr 13, 2020

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

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

Hello everyone!

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.

Best regards,
Lese Doru

---
 include/linux/udp.h      |    3 +
 include/uapi/linux/udp.h |    1 
 net/ipv4/udp.c           |   59 +++++++++++++++++++++++++++++++++++++
 net/ipv6/udp.c           |   45 ++++++++++++++++++++++++++++
 4 files changed, 107 insertions(+), 1 deletion(-)
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/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 +59 -0

103 lines not on this page · raw message

net/ipv6/udp.c +45 -0

70 lines not on this page · raw message

maintainer
#1 lore raw

From: Leşe Doru Călin <[email protected]>
Date: Wed, 8 Apr 2020 23:59:54 +0300

Quoted 13 lines

Hello everyone!

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 4 lines

Best regards,
Lese Doru

Why do I feel like I've seen this patch several times before?

#2 lore raw
Quoted 16 lines · David Miller

From: Lese Doru Calin <[email protected]>
Date: Wed, 8 Apr 2020 23:59:54 +0300

Quoted 13 lines

Hello everyone!

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 6 lines
Quoted 4 lines

Best regards,
Lese Doru

Why do I feel like I've seen this patch several times before?

Maybe others contestants in GSoC already sended a patch for this. This is the my first time when try.

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

From: Leşe Doru Călin <[email protected]>
Date: Wed, 8 Apr 2020 23:59:54 +0300

net/ipv4/udp.c struct sk_buff *__skb_recv_udp(struct sock *sk, unsigned int flags, · line 1726

Quoted 4 lines
net/ipv4/udp.c +4 -0
+static int udp_peek_sndq(struct sock *sk, struct msghdr *msg, int off, int len)
+{
+	struct sk_buff *skb;
+	int copied = 0, err = 0, copy;

Please use reverse christmas tree (longest to shortest) ordering for local variables.

net/ipv6/udp.c struct sock *udp6_lib_lookup(struct net *net, const struct in6_addr *saddr, __be · line 256

Quoted 4 lines
net/ipv6/udp.c +4 -0
+static int udp6_peek_sndq(struct sock *sk, struct msghdr *msg, int off, int len)
+{
+	struct sk_buff *skb;
+	int copied = 0, err = 0, copy;

Likewise.

Thank you.

#4 lore raw
Quoted 11 lines · David Miller

From: Lese Doru Calin <[email protected]>
Date: Wed, 8 Apr 2020 23:59:54 +0300

Review

Quoted 4 lines
(quoted diff) +4 -0
+static int udp_peek_sndq(struct sock *sk, struct msghdr *msg, int off, int len)
+{
+	struct sk_buff *skb;
+	int copied = 0, err = 0, copy;

Please use reverse christmas tree (longest to shortest) ordering for local variables.

Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+static int udp6_peek_sndq(struct sock *sk, struct msghdr *msg, int off, int len)
+{
+	struct sk_buff *skb;
+	int copied = 0, err = 0, copy;

Likewise.

Thank you.

I changed it accordingly. I hope it is ok.

Best regards,
Lese Doru

---
 include/linux/udp.h      |    3 +-
 include/uapi/linux/udp.h |    1 
 net/ipv4/udp.c           |   60 +++++++++++++++++++++++++++++++++++++++++++++++
 net/ipv6/udp.c           |   45 +++++++++++++++++++++++++++++++++++
 4 files changed, 108 insertions(+), 1 deletion(-)
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/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 +60 -0

104 lines not on this page · raw message

net/ipv6/udp.c +45 -0

70 lines not on this page · raw message

maintainer
#5 lore raw

From: Leşe Doru Călin <[email protected]>
Date: Mon, 13 Apr 2020 23:09:27 +0300

Quoted 19 lines · David Miller
Quoted 18 lines

From: Lese Doru Calin <[email protected]>
Date: Wed, 8 Apr 2020 23:59:54 +0300

net/ipv4/udp.c struct sk_buff *__skb_recv_udp(struct sock *sk, unsigned int flags,

Quoted 4 lines
net/ipv4/udp.c +4 -0
+static int udp_peek_sndq(struct sock *sk, struct msghdr *msg, int off, int len)
+{
+	struct sk_buff *skb;
+	int copied = 0, err = 0, copy;

Please use reverse christmas tree (longest to shortest) ordering for local variables.

net/ipv6/udp.c struct sock *udp6_lib_lookup(struct net *net, const struct in6_addr *saddr, __be

Quoted 4 lines
net/ipv6/udp.c +4 -0
+static int udp6_peek_sndq(struct sock *sk, struct msghdr *msg, int off, int len)
+{
+	struct sk_buff *skb;
+	int copied = 0, err = 0, copy;

Likewise.

Quoted 3 lines
Quoted 1 line

Thank you.

I changed it accordingly. I hope it is ok.

You have to make a fresh patch posting when you fix feedback given to you, and add appropriate version specifications to your Subject line such as "[PATCH v2]" etc.