[CRIU] [PATCH 2/5] zdtm: check that a sender address is restored
Andrey Vagin
avagin at openvz.org
Sun Aug 2 22:27:42 PDT 2015
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
test/zdtm/live/static/Makefile | 1 +
test/zdtm/live/static/socket_snd_addr.c | 101 ++++++++++++++++++++++++++++++++
2 files changed, 102 insertions(+)
create mode 100644 test/zdtm/live/static/socket_snd_addr.c
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 7575f7d..d894971 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -34,6 +34,7 @@ TST_NOFILE = \
socket_udplite \
socket_aio \
socket_close_data \
+ socket_snd_addr \
packet_sock \
packet_sock_mmap \
sock_filter \
diff --git a/test/zdtm/live/static/socket_snd_addr.c b/test/zdtm/live/static/socket_snd_addr.c
new file mode 100644
index 0000000..906abae
--- /dev/null
+++ b/test/zdtm/live/static/socket_snd_addr.c
@@ -0,0 +1,101 @@
+#define _GNU_SOURCE
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc = "Check that sender addresses are restored";
+const char *test_author = "Andrew Vagin <avagin at openvz.org";
+
+#define SK_SRV "\0socket_snd_srv"
+#define SK_NAME "\0A-socket_snd_clnt"
+
+char sk_names[2][128] = {
+ SK_NAME,
+ SK_NAME,
+ };
+
+#define MSG "hello"
+int main(int argc, char **argv)
+{
+ struct sockaddr_un addr;
+ unsigned int addrlen;
+ int srv, clnt = -1, ret, i;
+ char buf[1024];
+ struct iovec iov = {
+ .iov_base = &buf,
+ .iov_len = sizeof(buf),
+ };
+ struct msghdr hdr = {
+ .msg_name = &addr,
+ .msg_namelen = sizeof(addr),
+ .msg_iov = &iov,
+ .msg_iovlen = 1,
+ };
+
+ test_init(argc, argv);
+
+ srv = socket(PF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0);
+
+ addr.sun_family = AF_UNIX;
+ memcpy(addr.sun_path, SK_SRV, sizeof(SK_SRV));
+ addrlen = sizeof(addr.sun_family) + sizeof(SK_SRV);
+
+ if (bind(srv, &addr, addrlen)) {
+ fail("bind\n");
+ exit(1);
+ }
+
+ for (i = 0; i < 2; i++) {
+ close(clnt);
+ clnt = socket(PF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0);
+
+ sk_names[i][1] += i;
+ addr.sun_family = AF_UNIX;
+ memcpy(addr.sun_path, sk_names[i], sizeof(SK_NAME));
+ addrlen = sizeof(addr.sun_family) + sizeof(SK_NAME);
+
+ if (bind(clnt, &addr, addrlen)) {
+ fail("bind\n");
+ exit(1);
+ }
+
+ memcpy(addr.sun_path, SK_SRV, sizeof(SK_SRV));
+ addrlen = sizeof(addr.sun_family) + sizeof(SK_SRV);
+ if (connect(clnt, &addr, addrlen)) {
+ fail("connect\n");
+ exit(1);
+ }
+
+ if (send(clnt, MSG, sizeof(MSG), 0) != sizeof(MSG)) {
+ err("write");
+ return 1;
+ }
+ }
+
+ test_daemon();
+ test_waitsig();
+
+ for (i = 0; i < 2; i++) {
+ memset(addr.sun_path, 0, sizeof(addr.sun_path));
+ ret = recvmsg(srv, &hdr, MSG_DONTWAIT);
+ buf[ret > 0 ? ret : 0] = 0;
+ if (ret != sizeof(MSG)) {
+ fail("%d: %s", ret, buf);
+ return 1;
+ }
+ if (hdr.msg_namelen > sizeof(addr.sun_family) + 1)
+ err("%d, %s", hdr.msg_namelen, addr.sun_path + 1);
+ if (memcmp(addr.sun_path, sk_names[i], sizeof(SK_NAME))) {
+ fail("A sender address is mismatch");
+ return 1;
+ }
+ }
+
+ pass();
+ return 0;
+}
--
2.1.0
More information about the CRIU
mailing list