mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-28 21:07:43 +00:00
zdtm: Add tests for IP_PKTINFO and IP_FREEBIND sock options
Just creates ipv4/ipv6 raw/dgram sockets with IP_PKTINFO and IP_FREEBIND socket options enabled/disabled and checks that these options persist. Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
This commit is contained in:
parent
bd9b66c8c0
commit
4a8c02d636
@ -123,6 +123,8 @@ TST_NOFILE := \
|
||||
sock_opts00 \
|
||||
sock_opts01 \
|
||||
sock_opts02 \
|
||||
sock_ip_opts00 \
|
||||
sock_ip_opts01 \
|
||||
sk-unix-unconn \
|
||||
sk-unix-unconn-seqpacket \
|
||||
ipc_namespace \
|
||||
@ -598,6 +600,7 @@ socket-tcp6-closed: CFLAGS += -D ZDTM_IPV6
|
||||
socket-tcp6-closed: CFLAGS += -D ZDTM_IPV4V6
|
||||
socket-tcp-closed-last-ack: CFLAGS += -D ZDTM_TCP_LAST_ACK
|
||||
socket-tcp-skip-in-flight: CFLAGS += -D ZDTM_IPV4V6
|
||||
sock_ip_opts01: CFLAGS += -DZDTM_VAL_ZERO
|
||||
tun_ns: CFLAGS += -DTUN_NS
|
||||
mnt_ext_manual: CFLAGS += -D ZDTM_EXTMAP_MANUAL
|
||||
mntns_pivot_root_ro: CFLAGS += -DMNTNS_PIVOT_ROOT_RO
|
||||
|
110
test/zdtm/static/sock_ip_opts00.c
Normal file
110
test/zdtm/static/sock_ip_opts00.c
Normal file
@ -0,0 +1,110 @@
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <linux/in.h>
|
||||
#include <linux/in6.h>
|
||||
|
||||
#include "zdtmtst.h"
|
||||
|
||||
const char *test_doc = "Check that different ip socket options are restored";
|
||||
const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>";
|
||||
|
||||
#ifdef ZDTM_VAL_ZERO
|
||||
#define IP_OPT_VAL 0
|
||||
#else
|
||||
#define IP_OPT_VAL 1
|
||||
#endif
|
||||
|
||||
struct sk_opt {
|
||||
int level;
|
||||
int opt;
|
||||
};
|
||||
|
||||
struct sk_opt sk_opts_v4[] = {
|
||||
{ SOL_IP, IP_FREEBIND },
|
||||
{ SOL_IP, IP_PKTINFO },
|
||||
};
|
||||
|
||||
#ifndef IPV6_FREEBIND
|
||||
#define IPV6_FREEBIND 78
|
||||
#endif
|
||||
|
||||
struct sk_opt sk_opts_v6[] = {
|
||||
{ SOL_IPV6, IPV6_FREEBIND },
|
||||
{ SOL_IPV6, IPV6_RECVPKTINFO },
|
||||
};
|
||||
|
||||
struct sk_conf {
|
||||
int domain;
|
||||
int type;
|
||||
int protocol;
|
||||
int sk;
|
||||
} sk_confs[] = {
|
||||
{ AF_INET, SOCK_DGRAM, IPPROTO_UDP },
|
||||
{ AF_INET, SOCK_RAW, IPPROTO_UDP },
|
||||
{ AF_INET6, SOCK_DGRAM, IPPROTO_UDP },
|
||||
{ AF_INET6, SOCK_RAW, IPPROTO_UDP },
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct sk_opt *opts;
|
||||
int exit_code = 1;
|
||||
int i, j, val;
|
||||
socklen_t len;
|
||||
int n_opts;
|
||||
|
||||
test_init(argc, argv);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(sk_confs); i++) {
|
||||
sk_confs[i].sk = socket(sk_confs[i].domain, sk_confs[i].type, sk_confs[i].protocol);
|
||||
if (sk_confs[i].sk == -1) {
|
||||
pr_perror("socket(%d,%d,%d) failed", sk_confs[i].domain, sk_confs[i].type,
|
||||
sk_confs[i].protocol);
|
||||
goto close;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(sk_confs); i++) {
|
||||
opts = sk_confs[i].domain == AF_INET ? sk_opts_v4 : sk_opts_v6;
|
||||
n_opts = sk_confs[i].domain == AF_INET ? ARRAY_SIZE(sk_opts_v4) : ARRAY_SIZE(sk_opts_v6);
|
||||
|
||||
for (j = 0; j < n_opts; j++) {
|
||||
val = IP_OPT_VAL;
|
||||
if (setsockopt(sk_confs[i].sk, opts[j].level, opts[j].opt, &val, sizeof(int)) == -1) {
|
||||
pr_perror("setsockopt(%d, %d) failed", opts[j].level, opts[j].opt);
|
||||
goto close;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test_daemon();
|
||||
test_waitsig();
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(sk_confs); i++) {
|
||||
opts = sk_confs[i].domain == AF_INET ? sk_opts_v4 : sk_opts_v6;
|
||||
n_opts = sk_confs[i].domain == AF_INET ? ARRAY_SIZE(sk_opts_v4) : ARRAY_SIZE(sk_opts_v6);
|
||||
|
||||
for (j = 0; j < n_opts; j++) {
|
||||
len = sizeof(int);
|
||||
if (getsockopt(sk_confs[i].sk, opts[j].level, opts[j].opt, &val, &len) == -1) {
|
||||
pr_perror("getsockopt(%d, %d) failed", opts[j].level, opts[j].opt);
|
||||
goto close;
|
||||
}
|
||||
|
||||
if (val != IP_OPT_VAL) {
|
||||
fail("Unexpected value socket(%d,%d,%d) opts(%d,%d)", sk_confs[i].domain,
|
||||
sk_confs[i].type, sk_confs[i].protocol, opts[j].level, opts[j].opt);
|
||||
goto close;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pass();
|
||||
exit_code = 0;
|
||||
close:
|
||||
for (i = 0; i < ARRAY_SIZE(sk_confs); i++)
|
||||
close(sk_confs[i].sk);
|
||||
return exit_code;
|
||||
}
|
1
test/zdtm/static/sock_ip_opts00.desc
Normal file
1
test/zdtm/static/sock_ip_opts00.desc
Normal file
@ -0,0 +1 @@
|
||||
{'flags': 'suid', 'feature': 'ipv6_freebind'}
|
1
test/zdtm/static/sock_ip_opts01.c
Symbolic link
1
test/zdtm/static/sock_ip_opts01.c
Symbolic link
@ -0,0 +1 @@
|
||||
sock_ip_opts00.c
|
1
test/zdtm/static/sock_ip_opts01.desc
Symbolic link
1
test/zdtm/static/sock_ip_opts01.desc
Symbolic link
@ -0,0 +1 @@
|
||||
sock_ip_opts00.desc
|
Loading…
x
Reference in New Issue
Block a user