Commit 0f5e2217 authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Andrei Vagin

zdtm: Check that 'tcp-close' option closes sockets

There are 2 test cases:
1. Connected socket should be restored in the closed state
2. Listening socket state should not change after restore
Signed-off-by: 's avatarPavel Begunkov <asml.silence@gmail.com>
Signed-off-by: 's avatarEugene Batalov <eabatalov89@gmail.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 2c370428
...@@ -82,6 +82,8 @@ TST_NOFILE := \ ...@@ -82,6 +82,8 @@ TST_NOFILE := \
socket-tcp-closed \ socket-tcp-closed \
socket-tcp-closed-last-ack \ socket-tcp-closed-last-ack \
socket-tcp6-closed \ socket-tcp6-closed \
socket-tcp-close0 \
socket-tcp-close1 \
socket-tcp-unconn \ socket-tcp-unconn \
socket-tcp6-unconn \ socket-tcp6-unconn \
socket-tcp-syn-sent \ socket-tcp-syn-sent \
......
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
#include "zdtmtst.h"
const char *test_doc = "Check that tcp-close option closes connected tcp socket";
const char *test_author = "Pavel Begunkov <asml.silence@gmail.com>";
static int port = 8880;
static int check_socket_closed(int sk)
{
int err, buffer = 0;
struct tcp_info info;
socklen_t len = sizeof(info);
err = getsockopt(sk, IPPROTO_TCP, TCP_INFO, (void *)&info, &len);
if (err != 0) {
pr_perror("Can't get socket state\n");
return -1;
} else if (info.tcpi_state != TCP_CLOSE) {
pr_err("Invalid socket state (%i)\n", (int)info.tcpi_state);
return -1;
}
err = recv(sk, &buffer, sizeof(buffer), 0);
if (!err || errno != ENOTCONN) {
pr_perror("Invalid recv response\n");
return -1;
}
return 0;
}
int main(int argc, char **argv)
{
int fd, fd_s, clt;
test_init(argc, argv);
fd_s = tcp_init_server(AF_INET, &port);
if (fd_s < 0) {
pr_err("Server initializations failed\n");
return 1;
}
clt = tcp_init_client(AF_INET, "localhost", port);
if (clt < 0)
return 1;
fd = tcp_accept_server(fd_s);
if (fd < 0) {
pr_err("Can't accept client connection\n");
return 1;
}
close(fd_s);
test_daemon();
test_waitsig();
if (check_socket_closed(fd)) {
fail("Server socket isn't closed\n");
return 1;
}
if (check_socket_closed(clt)) {
fail("Client socket isn't closed\n");
return 1;
}
pass();
return 0;
}
{'dopts': '--tcp-established', 'ropts': '--tcp-close'}
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
#include "zdtmtst.h"
const char *test_doc = "Check that tcp-close option doesn't close listening tcp socket";
const char *test_author = "Pavel Begunkov <asml.silence@gmail.com>";
static int port = 8880;
static int check_socket_state(int sk, int state)
{
int err;
struct tcp_info info;
socklen_t len = sizeof(info);
err = getsockopt(sk, IPPROTO_TCP, TCP_INFO, (void *)&info, &len);
if (err != 0) {
pr_perror("Can't get socket state\n");
return -1;
}
return info.tcpi_state == state ? 0 : -1;
}
int main(int argc, char **argv)
{
int fd_s;
test_init(argc, argv);
fd_s = tcp_init_server(AF_INET, &port);
if (fd_s < 0) {
pr_err("Server initializations failed\n");
return 1;
}
test_daemon();
test_waitsig();
if (check_socket_state(fd_s, TCP_LISTEN)) {
fail("Listen socket state is changed\n");
close(fd_s);
return 1;
}
close(fd_s);
pass();
return 0;
}
socket-tcp-close0.desc
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment