2 * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
5 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include <sys/socket.h>
15 #include <linux/xfrm.h>
18 test_nlmsg_type(const int fd)
21 struct nlmsghdr nlh = {
22 .nlmsg_len = sizeof(nlh),
23 .nlmsg_type = XFRM_MSG_NEWSA,
24 .nlmsg_flags = NLM_F_REQUEST,
27 rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
28 printf("sendto(%d, {len=%u, type=XFRM_MSG_NEWSA"
29 ", flags=NLM_F_REQUEST, seq=0, pid=0}"
30 ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
31 fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
35 test_nlmsg_flags(const int fd)
38 struct nlmsghdr nlh = {
39 .nlmsg_len = sizeof(nlh),
42 nlh.nlmsg_type = XFRM_MSG_GETSA;
43 nlh.nlmsg_flags = NLM_F_DUMP;
44 rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
45 printf("sendto(%d, {len=%u, type=XFRM_MSG_GETSA"
46 ", flags=NLM_F_DUMP, seq=0, pid=0}"
47 ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
48 fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
50 nlh.nlmsg_type = XFRM_MSG_NEWSA;
51 nlh.nlmsg_flags = NLM_F_REPLACE;
52 rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
53 printf("sendto(%d, {len=%u, type=XFRM_MSG_NEWSA"
54 ", flags=NLM_F_REPLACE, seq=0, pid=0}"
55 ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
56 fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
58 nlh.nlmsg_type = XFRM_MSG_DELSA;
59 nlh.nlmsg_flags = NLM_F_ECHO | NLM_F_NONREC;
60 rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
61 printf("sendto(%d, {len=%u, type=XFRM_MSG_DELSA"
62 ", flags=NLM_F_ECHO|NLM_F_NONREC, seq=0, pid=0}"
63 ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
64 fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
66 nlh.nlmsg_type = XFRM_MSG_ALLOCSPI;
67 nlh.nlmsg_flags = NLM_F_ECHO | NLM_F_REPLACE;
68 rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
69 printf("sendto(%d, {len=%u, type=XFRM_MSG_ALLOCSPI"
70 ", flags=NLM_F_ECHO|%#x, seq=0, pid=0}"
71 ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
72 fd, nlh.nlmsg_len, NLM_F_REPLACE,
73 (unsigned) sizeof(nlh), sprintrc(rc));
78 skip_if_unavailable("/proc/self/fd/");
80 int fd = create_nl_socket(NETLINK_XFRM);
85 printf("+++ exited with 0 +++\n");