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

Submitted by Andrei Vagin on Sept. 29, 2017, 10:41 p.m.

Details

Message ID 20170929224145.6764-6-avagin@openvz.org
State Accepted
Series "Series without cover letter"
Commit 1f4086015b9266719303b670085e85631b3ecea6
Headers show

Commit Message

Andrei Vagin Sept. 29, 2017, 10:41 p.m.
From: Andrei Vagin <avagin@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@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(-)

Patch hide | download patch | download mbox

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);