1 /*
2 * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
3 * Copyright (c) 2017-2021 The strace developers.
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9 #include "tests.h"
10 #include <stdio.h>
11 #include <sys/socket.h>
12 #include "netlink.h"
13 #include <linux/netfilter/nfnetlink.h>
14 #include <linux/netfilter/nfnetlink_osf.h>
15
16 static void
17 test_nlmsg_type(const int fd)
18 {
19 long rc;
20 struct nlmsghdr nlh = {
21 .nlmsg_len = sizeof(nlh),
22 .nlmsg_flags = NLM_F_REQUEST,
23 };
24
25 nlh.nlmsg_type = NFNL_SUBSYS_OSF << 8 | OSF_MSG_ADD;
26 rc = sendto(fd, &nlh, nlh.nlmsg_len, MSG_DONTWAIT, NULL, 0);
27 printf("sendto(%d, {nlmsg_len=%u"
28 ", nlmsg_type=NFNL_SUBSYS_OSF<<8|OSF_MSG_ADD"
29 ", nlmsg_flags=NLM_F_REQUEST, nlmsg_seq=0, nlmsg_pid=0}"
30 ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
31 fd, nlh.nlmsg_len, nlh.nlmsg_len, sprintrc(rc));
32
33 nlh.nlmsg_type = NFNL_SUBSYS_OSF << 8 | 0xff;
34 rc = sendto(fd, &nlh, nlh.nlmsg_len, MSG_DONTWAIT, NULL, 0);
35 printf("sendto(%d, {nlmsg_len=%u"
36 ", nlmsg_type=NFNL_SUBSYS_OSF<<8|0xff /* OSF_MSG_??? */"
37 ", nlmsg_flags=NLM_F_REQUEST, nlmsg_seq=0, nlmsg_pid=0}"
38 ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
39 fd, nlh.nlmsg_len, nlh.nlmsg_len, sprintrc(rc));
40 }
41
42 int
43 main(void)
44 {
45 skip_if_unavailable("/proc/self/fd/");
46
47 int fd = create_nl_socket(NETLINK_NETFILTER);
48
49 test_nlmsg_type(fd);
50
51 puts("+++ exited with 0 +++");
52
53 return 0;
54 }