[CRIU] [crtools-bot for Pavel Emelyanov ] udp: Restore UDP sockets

Cyrill Gorcunov gorcunov at openvz.org
Fri Mar 2 06:54:43 EST 2012


The commit is pushed to "master" and will appear on git://github.com/cyrillos/crtools.git
------>
commit 1c12a31893d410cc32caf7712600305bf1e70819
Author: Pavel Emelyanov <xemul at parallels.com>
Date:   Fri Mar 2 15:51:30 2012 +0400

    udp: Restore UDP sockets
    
    Reuse the TCP socket restore, just add connect() and sanity checks
    for protocol.
    
    This is OK, since UDP connect doesn't go to network for connection
    and (unlike unix sockets) doesn't require peer to be "online". It
    just puts the peer's creds on socket and returns.
    
    Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
    Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 sockets.c |   32 ++++++++++++++++++++++++++++----
 1 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/sockets.c b/sockets.c
index 60f60e6..7d0e887 100644
--- a/sockets.c
+++ b/sockets.c
@@ -1188,7 +1188,7 @@ static int open_inet_sk(const struct inet_sk_entry *ie, int *img_fd)
 		return -1;
 	}
 
-	if (ie->type != SOCK_STREAM) {
+	if ((ie->type != SOCK_STREAM) && (ie->type != SOCK_DGRAM)) {
 		pr_err("Unsupported socket type: %d\n", ie->type);
 		return -1;
 	}
@@ -1213,9 +1213,33 @@ static int open_inet_sk(const struct inet_sk_entry *ie, int *img_fd)
 		goto err;
 	}
 
-	if (listen(sk, ie->backlog) == -1) {
-		pr_perror("Can't listen on a socket");
-		goto err;
+	if (ie->state == TCP_LISTEN) {
+		if (ie->proto != IPPROTO_TCP) {
+			pr_err("Wrong socket in listen state %d\n", ie->proto);
+			goto err;
+		}
+
+		if (listen(sk, ie->backlog) == -1) {
+			pr_perror("Can't listen on a socket");
+			goto err;
+		}
+	}
+
+	if (ie->state == TCP_ESTABLISHED) {
+		if (ie->proto != IPPROTO_UDP) {
+			pr_err("Connected TCP socket in image\n");
+			goto err;
+		}
+
+		memset(&addr, 0, sizeof(addr));
+		addr.sin_family = ie->family;
+		addr.sin_port = htons(ie->dst_port);
+		memcpy(&addr.sin_addr.s_addr, ie->dst_addr, sizeof(ie->dst_addr));
+
+		if (connect(sk, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
+			pr_perror("Can't connect UDP socket back");
+			goto err;
+		}
 	}
 
 	if (move_img_fd(img_fd, ie->fd))


More information about the CRIU mailing list