[CRIU] [PATCH 11/14] soccr/tcp: Restore socket's info after binding it
Pavel Emelyanov
xemul at virtuozzo.com
Mon Apr 18 06:06:16 PDT 2016
And this is p2 of the previous patch.
Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
criu/sk-tcp.c | 57 +--------------------------------------------------------
soccr/soccr.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
soccr/soccr.h | 1 +
3 files changed, 60 insertions(+), 56 deletions(-)
diff --git a/criu/sk-tcp.c b/criu/sk-tcp.c
index a9f2c6d..510c327 100644
--- a/criu/sk-tcp.c
+++ b/criu/sk-tcp.c
@@ -52,10 +52,6 @@ enum {
#define TCP_TIMESTAMP 24
#endif
-#ifndef TCPOPT_SACK_PERM
-#define TCPOPT_SACK_PERM TCPOPT_SACK_PERMITTED
-#endif
-
static LIST_HEAD(cpt_tcp_repair_sockets);
static LIST_HEAD(rst_tcp_repair_sockets);
@@ -360,57 +356,6 @@ static int restore_tcp_queues(int sk, TcpStreamEntry *tse, struct cr_img *img)
return 0;
}
-static int restore_tcp_opts(int sk, TcpStreamEntry *tse)
-{
- struct tcp_repair_opt opts[4];
- int onr = 0;
-
- pr_debug("\tRestoring TCP options\n");
-
- if (tse->opt_mask & TCPI_OPT_SACK) {
- pr_debug("\t\tWill turn SAK on\n");
- opts[onr].opt_code = TCPOPT_SACK_PERM;
- opts[onr].opt_val = 0;
- onr++;
- }
-
- if (tse->opt_mask & TCPI_OPT_WSCALE) {
- pr_debug("\t\tWill set snd_wscale to %u\n", tse->snd_wscale);
- pr_debug("\t\tWill set rcv_wscale to %u\n", tse->rcv_wscale);
- opts[onr].opt_code = TCPOPT_WINDOW;
- opts[onr].opt_val = tse->snd_wscale + (tse->rcv_wscale << 16);
- onr++;
- }
-
- if (tse->opt_mask & TCPI_OPT_TIMESTAMPS) {
- pr_debug("\t\tWill turn timestamps on\n");
- opts[onr].opt_code = TCPOPT_TIMESTAMP;
- opts[onr].opt_val = 0;
- onr++;
- }
-
- pr_debug("Will set mss clamp to %u\n", tse->mss_clamp);
- opts[onr].opt_code = TCPOPT_MAXSEG;
- opts[onr].opt_val = tse->mss_clamp;
- onr++;
-
- if (setsockopt(sk, SOL_TCP, TCP_REPAIR_OPTIONS,
- opts, onr * sizeof(struct tcp_repair_opt)) < 0) {
- pr_perror("Can't repair options");
- return -1;
- }
-
- if (tse->has_timestamp) {
- if (setsockopt(sk, SOL_TCP, TCP_TIMESTAMP,
- &tse->timestamp, sizeof(tse->timestamp)) < 0) {
- pr_perror("Can't set timestamp");
- return -1;
- }
- }
-
- return 0;
-}
-
static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_sk_info *ii)
{
int aux;
@@ -468,7 +413,7 @@ static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_
if (inet_connect(sk, ii))
goto err_c;
- if (restore_tcp_opts(sk, tse))
+ if (libsoccr_set_sk_data(socr, &data, sizeof(data)))
goto err_c;
if (restore_prepare_socket(sk))
diff --git a/soccr/soccr.c b/soccr/soccr.c
index 5da2066..e127342 100644
--- a/soccr/soccr.c
+++ b/soccr/soccr.c
@@ -307,3 +307,61 @@ int libsoccr_set_sk_data_unbound(struct libsoccr_sk *sk,
return 0;
}
+#ifndef TCPOPT_SACK_PERM
+#define TCPOPT_SACK_PERM TCPOPT_SACK_PERMITTED
+#endif
+
+int libsoccr_set_sk_data(struct libsoccr_sk *sk,
+ struct libsoccr_sk_data *data, unsigned data_size)
+{
+ struct tcp_repair_opt opts[4];
+ int onr = 0;
+
+ if (!data || data_size < SOCR_DATA_MIN_SIZE)
+ return -1;
+
+ logd("\tRestoring TCP options\n");
+
+ if (data->opt_mask & TCPI_OPT_SACK) {
+ logd("\t\tWill turn SAK on\n");
+ opts[onr].opt_code = TCPOPT_SACK_PERM;
+ opts[onr].opt_val = 0;
+ onr++;
+ }
+
+ if (data->opt_mask & TCPI_OPT_WSCALE) {
+ logd("\t\tWill set snd_wscale to %u\n", data->snd_wscale);
+ logd("\t\tWill set rcv_wscale to %u\n", data->rcv_wscale);
+ opts[onr].opt_code = TCPOPT_WINDOW;
+ opts[onr].opt_val = data->snd_wscale + (data->rcv_wscale << 16);
+ onr++;
+ }
+
+ if (data->opt_mask & TCPI_OPT_TIMESTAMPS) {
+ logd("\t\tWill turn timestamps on\n");
+ opts[onr].opt_code = TCPOPT_TIMESTAMP;
+ opts[onr].opt_val = 0;
+ onr++;
+ }
+
+ logd("Will set mss clamp to %u\n", data->mss_clamp);
+ opts[onr].opt_code = TCPOPT_MAXSEG;
+ opts[onr].opt_val = data->mss_clamp;
+ onr++;
+
+ if (setsockopt(sk->fd, SOL_TCP, TCP_REPAIR_OPTIONS,
+ opts, onr * sizeof(struct tcp_repair_opt)) < 0) {
+ loge("Can't repair options");
+ return -2;
+ }
+
+ if (data->opt_mask & TCPI_OPT_TIMESTAMPS) {
+ if (setsockopt(sk->fd, SOL_TCP, TCP_TIMESTAMP,
+ &data->timestamp, sizeof(data->timestamp)) < 0) {
+ loge("Can't set timestamp");
+ return -3;
+ }
+ }
+
+ return 0;
+}
diff --git a/soccr/soccr.h b/soccr/soccr.h
index 569d5df..0dd19ee 100644
--- a/soccr/soccr.h
+++ b/soccr/soccr.h
@@ -31,4 +31,5 @@ int libsoccr_get_sk_data(struct libsoccr_sk *sk, struct libsoccr_sk_data *data,
char *libsoccr_get_queue_bytes(struct libsoccr_sk *sk, int queue_id, int steal);
int libsoccr_set_sk_data_unbound(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size);
+int libsoccr_set_sk_data(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size);
#endif
--
2.5.0
More information about the CRIU
mailing list