2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-22 09:58:09 +00:00

zdtm: add ipv6 variants of net_lock_socket_* tests

v2: remove unnecessary elif and else after return in
    wait_server_addr()
v3: use IOError instead of FileNotFoundError for python2
    compatibility

Signed-off-by: Zeyad Yasser <zeyady98@gmail.com>
This commit is contained in:
Zeyad Yasser 2021-07-29 20:18:21 +02:00 committed by Andrei Vagin
parent 212db1d9a6
commit cd1570b15e
9 changed files with 55 additions and 11 deletions

View File

@ -220,7 +220,9 @@ TST_NOFILE := \
netns_lock_iptables \
netns_lock_nftables \
net_lock_socket_iptables \
net_lock_socket_iptables6 \
net_lock_socket_nftables \
net_lock_socket_nftables6 \
netns_sub \
netns_sub_veth \
netns_sub_sysctl \
@ -583,6 +585,8 @@ clone_fs: LDLIBS += -pthread
# we have to explicitly specify both .o and .d for this case:
netns_sub_veth.o netns_sub_veth.d: CPPFLAGS += $(call pkg-cflags, libnl-3.0)
netns_sub_veth: LDLIBS += $(call pkg-libs, libnl-route-3.0 libnl-3.0)
net_lock_socket_iptables6: CFLAGS += -D ZDTM_IPV6
net_lock_socket_nftables6: CFLAGS += -D ZDTM_IPV6
symlink01: CFLAGS += -DZDTM_UNLINK_SYMLINK
socket-tcp-fin-wait1: CFLAGS += -D ZDTM_TCP_FIN_WAIT1

View File

@ -1,5 +1,11 @@
#include "zdtmtst.h"
#if defined(ZDTM_IPV6)
#define ZDTM_FAMILY AF_INET6
#else
#define ZDTM_FAMILY AF_INET
#endif
const char *test_doc = "Check that sockets are locked between dump and restore\n";
const char *test_author = "Zeyad Yasser <zeyady98@gmail.com>";
@ -14,22 +20,31 @@ static int port = 8880;
int main(int argc, char **argv)
{
char buf[5];
int fd_s, fd_sock, fd_sync, buf_len;
int fd_s, fd_sock, buf_len;
FILE *f_sync;
test_init(argc, argv);
if ((fd_s = tcp_init_server(AF_INET, &port)) < 0) {
if ((fd_s = tcp_init_server(ZDTM_FAMILY, &port)) < 0) {
pr_err("initializing server failed\n");
return 1;
}
// Server is ready to accept sockets
fd_sync = open(SYNCFILE_PATH, O_CREAT, 0444);
if (fd_sync == -1) {
f_sync = fopen(SYNCFILE_PATH, "w");
if (f_sync == NULL) {
pr_perror("cannot create sync file");
return 1;
}
close(fd_sync);
#if defined(ZDTM_IPV6)
if (fprintf(f_sync, "ipv6") < 0) {
#else
if (fprintf(f_sync, "ipv4") < 0) {
#endif
pr_perror("cannot write to sync file");
return 1;
}
fclose(f_sync);
fd_sock = tcp_accept_server(fd_s);

View File

@ -10,11 +10,21 @@ TIMEOUT = 0.1
INTERNAL_SERVER = "\0internal_server"
SYNCFILE = "zdtm/static/socket_lock.sync"
def wait_sync_file():
def wait_server_addr():
for _ignore in range(3):
if os.path.exists(SYNCFILE):
try:
with open(SYNCFILE, "r") as f:
addr = f.read(4)
os.remove(SYNCFILE)
return
if addr == "ipv4":
return "127.0.0.1"
if addr == "ipv6":
return "::1"
raise Exception("Invalid address type")
except IOError:
time.sleep(1)
raise TimeoutError("Sync timeout: file ({}) not found".format(SYNCFILE))
@ -25,13 +35,13 @@ if sys.argv[1] == "--post-start":
internal_sock.listen(1)
# Wait for test server to be ready
wait_sync_file()
server_addr = wait_server_addr()
pid = os.fork()
if pid == 0:
os.setsid() # Detach from parent
test_sock = socket.create_connection(("127.0.0.1", PORT), TIMEOUT)
test_sock = socket.create_connection((server_addr, PORT), TIMEOUT)
while True:
internal_conn, _ignore = internal_sock.accept()

View File

@ -0,0 +1 @@
net_lock_socket_iptables.c

View File

@ -0,0 +1,5 @@
{
'flavor': 'h',
'flags': 'suid excl',
'opts': '--tcp-established --network-lock iptables',
}

View File

@ -0,0 +1 @@
net_lock_socket_iptables.hook

View File

@ -0,0 +1 @@
net_lock_socket_iptables.c

View File

@ -0,0 +1,6 @@
{
'flavor': 'h',
'flags': 'suid excl',
'feature': 'network_lock_nftables',
'opts': '--tcp-established --network-lock nftables',
}

View File

@ -0,0 +1 @@
net_lock_socket_iptables.hook