[CRIU] [PATCH 6/9] tcp: be ready that a size of tcp_info can be changed

Andrei Vagin avagin at openvz.org
Sat Sep 30 01:41:42 MSK 2017


From: Andrei Vagin <avagin at virtuozzo.com>

(00.052683) Error (soccr/soccr.c:166): Failed to obtain TCP_INFO: No error information

We don't need a whole tcp info, so get only a part
what we are going to use.

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/sk-inet.c                       |  9 ++++++++-
 soccr/soccr.c                        | 18 +++++++++++++++---
 test/zdtm/static/socket-tcp-close0.c |  5 ++++-
 test/zdtm/static/socket-tcp-close1.c |  5 ++++-
 4 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/criu/sk-inet.c b/criu/sk-inet.c
index 94170cb93..93de1e2ee 100644
--- a/criu/sk-inet.c
+++ b/criu/sk-inet.c
@@ -246,7 +246,14 @@ static struct inet_sk_desc *gen_uncon_sk(int lfd, const struct fd_parms *p, int
 	sk->sd.ino = p->stat.st_ino;
 
 	if (proto == IPPROTO_TCP) {
-		struct tcp_info info;
+		struct {
+			__u8    tcpi_state;
+			__u8    tcpi_ca_state;
+			__u8    tcpi_retransmits;
+			__u8    tcpi_probes;
+			__u8    tcpi_backoff;
+			__u8    tcpi_options;
+		} info;
 
 		aux = sizeof(info);
 		ret = getsockopt(lfd, SOL_TCP, TCP_INFO, &info, &aux);
diff --git a/soccr/soccr.c b/soccr/soccr.c
index 48469aaab..1a1aaa35d 100644
--- a/soccr/soccr.c
+++ b/soccr/soccr.c
@@ -157,7 +157,18 @@ void libsoccr_release(struct libsoccr_sk *sk)
 	free(sk);
 }
 
-static int refresh_sk(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, struct tcp_info *ti)
+struct soccr_tcp_info {
+        __u8    tcpi_state;
+        __u8    tcpi_ca_state;
+        __u8    tcpi_retransmits;
+        __u8    tcpi_probes;
+        __u8    tcpi_backoff;
+        __u8    tcpi_options;
+        __u8    tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
+};
+
+static int refresh_sk(struct libsoccr_sk *sk,
+			struct libsoccr_sk_data *data, struct soccr_tcp_info *ti)
 {
 	int size;
 	socklen_t olen = sizeof(*ti);
@@ -215,7 +226,8 @@ static int refresh_sk(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, str
 	return 0;
 }
 
-static int get_stream_options(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, struct tcp_info *ti)
+static int get_stream_options(struct libsoccr_sk *sk,
+		struct libsoccr_sk_data *data, struct soccr_tcp_info *ti)
 {
 	int ret;
 	socklen_t auxl;
@@ -353,7 +365,7 @@ err_recv:
 
 int libsoccr_save(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size)
 {
-	struct tcp_info ti;
+	struct soccr_tcp_info ti;
 
 	if (!data || data_size < SOCR_DATA_MIN_SIZE) {
 		loge("Invalid input parameters\n");
diff --git a/test/zdtm/static/socket-tcp-close0.c b/test/zdtm/static/socket-tcp-close0.c
index 2bc0f64f9..6043cebb8 100644
--- a/test/zdtm/static/socket-tcp-close0.c
+++ b/test/zdtm/static/socket-tcp-close0.c
@@ -3,6 +3,7 @@
 #include <sys/socket.h>
 #include <netinet/tcp.h>
 #include <netinet/in.h>
+#include <linux/types.h>
 
 #include "zdtmtst.h"
 
@@ -14,7 +15,9 @@ static int port = 8880;
 static int check_socket_closed(int sk)
 {
 	int err, buffer = 0;
-	struct tcp_info info;
+	struct {
+		__u8    tcpi_state;
+	} info;
 	socklen_t len = sizeof(info);
 
 	err = getsockopt(sk, IPPROTO_TCP, TCP_INFO, (void *)&info, &len);
diff --git a/test/zdtm/static/socket-tcp-close1.c b/test/zdtm/static/socket-tcp-close1.c
index 54511a341..3dba4e54d 100644
--- a/test/zdtm/static/socket-tcp-close1.c
+++ b/test/zdtm/static/socket-tcp-close1.c
@@ -2,6 +2,7 @@
 #include <sys/socket.h>
 #include <netinet/tcp.h>
 #include <netinet/in.h>
+#include <linux/types.h>
 
 #include "zdtmtst.h"
 
@@ -13,7 +14,9 @@ static int port = 8880;
 static int check_socket_state(int sk, int state)
 {
 	int err;
-	struct tcp_info info;
+	struct {
+		__u8    tcpi_state;
+	} info;
 	socklen_t len = sizeof(info);
 
 	err = getsockopt(sk, IPPROTO_TCP, TCP_INFO, (void *)&info, &len);
-- 
2.13.3



More information about the CRIU mailing list