mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 02:14:37 +00:00
For an established TCP connection, the send queue is restored in two steps: in step (1), we retransmit the data that was sent before but not yet acknowledged, and in step (2), we transmit the data that was never sent outside before. The TCP_REPAIR option is disabled before step (2) and re-enabled after step (2) (without this patch). If the amount of data to be sent in step (2) is large, the TCP_REPAIR flag on the socket can remain off for some time (O(milliseconds)). If a listen() is called on another socket bound to the same port during this time window, it fails. This is because -- turning TCP_REPAIR off clears the SO_REUSEADDR flag on the socket. This patch adds a mutex (reuseaddr_lock) per port number, so that a listen() on a port number does not happen while SO_REUSEADDR for another socket on the same port is off. Thanks to Amey Deshpande <ameyd@google.com> for debugging. Signed-off-by: Saied Kazemi <saied@google.com> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
84 lines
1.9 KiB
C
84 lines
1.9 KiB
C
#ifndef __CR_SK_INET_H__
|
|
#define __CR_SK_INET_H__
|
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#include "sockets.h"
|
|
#include "files.h"
|
|
#include "list.h"
|
|
#include "protobuf.h"
|
|
#include "protobuf/sk-inet.pb-c.h"
|
|
|
|
#define INET_ADDR_LEN 40
|
|
#ifndef TCP_REPAIR
|
|
#define TCP_REPAIR 19 /* TCP sock is under repair right now */
|
|
#define TCP_REPAIR_QUEUE 20
|
|
#define TCP_QUEUE_SEQ 21
|
|
#define TCP_REPAIR_OPTIONS 22
|
|
#endif
|
|
|
|
struct inet_sk_desc {
|
|
struct socket_desc sd;
|
|
unsigned int type;
|
|
unsigned int src_port;
|
|
unsigned int dst_port;
|
|
unsigned int state;
|
|
unsigned int rqlen;
|
|
unsigned int wqlen; /* sent + unsent data */
|
|
unsigned int uwqlen; /* unsent data */
|
|
unsigned int src_addr[4];
|
|
unsigned int dst_addr[4];
|
|
unsigned short shutdown;
|
|
|
|
int rfd;
|
|
int cpt_reuseaddr;
|
|
struct list_head rlist;
|
|
};
|
|
|
|
struct inet_port;
|
|
struct inet_sk_info {
|
|
InetSkEntry *ie;
|
|
struct file_desc d;
|
|
struct inet_port *port;
|
|
struct list_head rlist;
|
|
};
|
|
|
|
extern int inet_bind(int sk, struct inet_sk_info *);
|
|
extern int inet_connect(int sk, struct inet_sk_info *);
|
|
|
|
struct rst_tcp_sock {
|
|
int sk;
|
|
bool reuseaddr;
|
|
};
|
|
|
|
extern struct rst_tcp_sock *rst_tcp_socks;
|
|
extern int rst_tcp_socks_nr;
|
|
|
|
static inline unsigned long rst_tcp_socks_len(void)
|
|
{
|
|
return rst_tcp_socks_nr * sizeof(struct rst_tcp_sock);
|
|
}
|
|
|
|
static inline void tcp_repair_off(int fd)
|
|
{
|
|
int aux = 0, ret;
|
|
|
|
ret = sys_setsockopt(fd, SOL_TCP, TCP_REPAIR, &aux, sizeof(aux));
|
|
if (ret < 0)
|
|
pr_err("Failed to turn off repair mode on socket (%d)", ret);
|
|
}
|
|
|
|
extern void tcp_locked_conn_add(struct inet_sk_info *);
|
|
extern void rst_unlock_tcp_connections(void);
|
|
extern void cpt_unlock_tcp_connections(void);
|
|
|
|
extern int dump_one_tcp(int sk, struct inet_sk_desc *sd);
|
|
extern int restore_one_tcp(int sk, struct inet_sk_info *si);
|
|
|
|
#define SK_EST_PARAM "tcp-established"
|
|
|
|
extern int check_tcp(void);
|
|
extern int rst_tcp_socks_add(int fd, bool reuseaddr);
|
|
extern mutex_t *inet_get_reuseaddr_lock(struct inet_sk_info *ii);
|
|
|
|
#endif /* __CR_SK_INET_H__ */
|