[CRIU] [PATCH 07/21] soccr: add source and destination addresses to libsoccr_sk_data
Andrei Vagin
avagin at openvz.org
Thu Dec 1 00:32:25 PST 2016
From: Andrei Vagin <avagin at virtuozzo.com>
These addresses will be used to restore half-closed sockets,
we will need to send a fake fin packet for that.
And in the next patch connect() will be moved into soccr.
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
criu/include/sk-inet.h | 4 ++++
criu/sk-inet.c | 13 +++++--------
criu/sk-tcp.c | 9 +++++++++
soccr/soccr.h | 10 ++++++++++
4 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/criu/include/sk-inet.h b/criu/include/sk-inet.h
index a06a8ac..db3317f 100644
--- a/criu/include/sk-inet.h
+++ b/criu/include/sk-inet.h
@@ -85,4 +85,8 @@ struct rst_tcp_sock {
bool reuseaddr;
};
+union libsoccr_addr;
+int restore_sockaddr(union libsoccr_addr *sa,
+ int family, u32 pb_port, u32 *pb_addr, u32 ifindex);
+
#endif /* __CR_SK_INET_H__ */
diff --git a/criu/sk-inet.c b/criu/sk-inet.c
index 084eee7..1336405 100644
--- a/criu/sk-inet.c
+++ b/criu/sk-inet.c
@@ -11,6 +11,8 @@
#include <string.h>
#include <stdlib.h>
+#include "../soccr/soccr.h"
+
#include "libnetlink.h"
#include "cr_options.h"
#include "imgset.h"
@@ -655,12 +657,7 @@ err:
return -1;
}
-union sockaddr_inet {
- struct sockaddr_in v4;
- struct sockaddr_in6 v6;
-};
-
-static int restore_sockaddr(union sockaddr_inet *sa,
+int restore_sockaddr(union libsoccr_addr *sa,
int family, u32 pb_port, u32 *pb_addr, u32 ifindex)
{
BUILD_BUG_ON(sizeof(sa->v4.sin_addr.s_addr) > PB_ALEN_INET * sizeof(u32));
@@ -695,7 +692,7 @@ static int restore_sockaddr(union sockaddr_inet *sa,
int inet_bind(int sk, struct inet_sk_info *ii)
{
bool rst_freebind = false;
- union sockaddr_inet addr;
+ union libsoccr_addr addr;
int addr_size, ifindex = 0;
if (ii->ie->ifname) {
@@ -751,7 +748,7 @@ int inet_bind(int sk, struct inet_sk_info *ii)
int inet_connect(int sk, struct inet_sk_info *ii)
{
- union sockaddr_inet addr;
+ union libsoccr_addr addr;
int addr_size;
addr_size = restore_sockaddr(&addr, ii->ie->family,
diff --git a/criu/sk-tcp.c b/criu/sk-tcp.c
index bd3b0da..3e89848 100644
--- a/criu/sk-tcp.c
+++ b/criu/sk-tcp.c
@@ -338,6 +338,15 @@ static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_
data.rcv_wup = tse->rcv_wup;
}
+ if (restore_sockaddr(&data.src_addr,
+ ii->ie->family, ii->ie->src_port,
+ ii->ie->src_addr, 0) < 0)
+ goto err_c;
+ if (restore_sockaddr(&data.dst_addr,
+ ii->ie->family, ii->ie->dst_port,
+ ii->ie->dst_addr, 0) < 0)
+ goto err_c;
+
(void)data;
if (libsoccr_set_sk_data_unbound(socr, &data, sizeof(data)))
diff --git a/soccr/soccr.h b/soccr/soccr.h
index 4e272d5..c5c3e1b 100644
--- a/soccr/soccr.h
+++ b/soccr/soccr.h
@@ -1,6 +1,7 @@
#ifndef __LIBSOCCR_H__
#define __LIBSOCCR_H__
#include <linux/types.h>
+#include <netinet/in.h>
#include <stdint.h>
#include "config.h"
@@ -57,6 +58,12 @@ void libsoccr_set_log(unsigned int level, void (*fn)(unsigned int level, const c
*/
struct libsoccr_sk;
+union libsoccr_addr {
+ struct sockaddr sa;
+ struct sockaddr_in v4;
+ struct sockaddr_in6 v6;
+};
+
/*
* Connection info that should be saved after fetching from the
* socket and given back into the library in two steps (see below).
@@ -80,6 +87,9 @@ struct libsoccr_sk_data {
__u32 max_window;
__u32 rcv_wnd;
__u32 rcv_wup;
+
+ union libsoccr_addr src_addr;
+ union libsoccr_addr dst_addr;
};
/*
--
2.7.4
More information about the CRIU
mailing list