[11/12] soccr: Handle connection state

Submitted by Pavel Emelianov on Aug. 5, 2016, 3:02 p.m.

Details

Message ID 57A4AA9A.5070600@virtuozzo.com
State Accepted
Series "Introduce library for socket C/R"
Commit 9c9ad5048bcfa8538db0005257e6f8f839c70436
Headers show

Commit Message

Pavel Emelianov Aug. 5, 2016, 3:02 p.m.
For now we only support ESTABLISHED state, so this is mostly
a preparation for the future extention.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/sk-tcp.c | 1 +
 soccr/soccr.c | 7 ++++++-
 soccr/soccr.h | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/criu/sk-tcp.c b/criu/sk-tcp.c
index 0dd6b77..4399ae4 100644
--- a/criu/sk-tcp.c
+++ b/criu/sk-tcp.c
@@ -341,6 +341,7 @@  static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_
 		goto err_c;
 	}
 
+	data.state = TCP_ESTABLISHED;
 	data.inq_len = tse->inq_len;
 	data.inq_seq = tse->inq_seq;
 	data.outq_len = tse->outq_len;
diff --git a/soccr/soccr.c b/soccr/soccr.c
index 0dfdb5e..c27ba66 100644
--- a/soccr/soccr.c
+++ b/soccr/soccr.c
@@ -109,6 +109,8 @@  static int refresh_sk(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, str
 		return -1;
 	}
 
+	data->state = TCP_ESTABLISHED;
+
 	if (ioctl(sk->fd, SIOCOUTQ, &size) == -1) {
 		loge("Unable to get size of snd queue");
 		return -1;
@@ -265,7 +267,7 @@  err_recv:
 /*
  * This is how much data we've had in the initial libsoccr
  */
-#define SOCR_DATA_MIN_SIZE	(16 * sizeof(__u32))
+#define SOCR_DATA_MIN_SIZE	(17 * sizeof(__u32))
 
 int libsoccr_get_sk_data(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size)
 {
@@ -339,6 +341,9 @@  int libsoccr_set_sk_data_unbound(struct libsoccr_sk *sk,
 	if (!data || data_size < SOCR_DATA_MIN_SIZE)
 		return -1;
 
+	if (data->state != TCP_ESTABLISHED)
+		return -1;
+
 	if (set_queue_seq(sk, TCP_RECV_QUEUE,
 				data->inq_seq - data->inq_len))
 		return -2;
diff --git a/soccr/soccr.h b/soccr/soccr.h
index 2d8b7f3..e6239b7 100644
--- a/soccr/soccr.h
+++ b/soccr/soccr.h
@@ -12,6 +12,7 @@  void libsoccr_set_log(unsigned int level, void (*fn)(unsigned int level, const c
 struct libsoccr_sk;
 
 struct libsoccr_sk_data {
+	__u32	state;
 	__u32	inq_len;
 	__u32	inq_seq;
 	__u32	outq_len;