2 * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
3 * Copyright (c) 2017-2018 The strace developers.
6 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include <sys/socket.h>
16 #include <linux/xfrm.h>
19 test_nlmsg_type(const int fd)
22 struct nlmsghdr nlh = {
23 .nlmsg_len = sizeof(nlh),
24 .nlmsg_type = XFRM_MSG_NEWSA,
25 .nlmsg_flags = NLM_F_REQUEST,
28 rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
29 printf("sendto(%d, {len=%u, type=XFRM_MSG_NEWSA"
30 ", flags=NLM_F_REQUEST, seq=0, pid=0}"
31 ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
32 fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
36 test_nlmsg_flags(const int fd)
39 struct nlmsghdr nlh = {
40 .nlmsg_len = sizeof(nlh),
43 nlh.nlmsg_type = XFRM_MSG_GETSA;
44 nlh.nlmsg_flags = NLM_F_DUMP;
45 rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
46 printf("sendto(%d, {len=%u, type=XFRM_MSG_GETSA"
47 ", flags=NLM_F_DUMP, seq=0, pid=0}"
48 ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
49 fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
51 nlh.nlmsg_type = XFRM_MSG_NEWSA;
52 nlh.nlmsg_flags = NLM_F_REPLACE;
53 rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
54 printf("sendto(%d, {len=%u, type=XFRM_MSG_NEWSA"
55 ", flags=NLM_F_REPLACE, seq=0, pid=0}"
56 ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
57 fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
59 nlh.nlmsg_type = XFRM_MSG_DELSA;
60 nlh.nlmsg_flags = NLM_F_ECHO | NLM_F_NONREC;
61 rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
62 printf("sendto(%d, {len=%u, type=XFRM_MSG_DELSA"
63 ", flags=NLM_F_ECHO|NLM_F_NONREC, seq=0, pid=0}"
64 ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
65 fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
67 nlh.nlmsg_type = XFRM_MSG_ALLOCSPI;
68 nlh.nlmsg_flags = NLM_F_ECHO | NLM_F_REPLACE;
69 rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
70 printf("sendto(%d, {len=%u, type=XFRM_MSG_ALLOCSPI"
71 ", flags=NLM_F_ECHO|%#x, seq=0, pid=0}"
72 ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
73 fd, nlh.nlmsg_len, NLM_F_REPLACE,
74 (unsigned) sizeof(nlh), sprintrc(rc));
79 skip_if_unavailable("/proc/self/fd/");
81 int fd = create_nl_socket(NETLINK_XFRM);
86 printf("+++ exited with 0 +++\n");