]> granicus.if.org Git - strace/blob - tests/nfnetlink_acct.c
Update copyright headers
[strace] / tests / nfnetlink_acct.c
1 /*
2  * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
3  * Copyright (c) 2017-2018 The strace developers.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  */
8
9 #include "tests.h"
10
11 #ifdef HAVE_LINUX_NETFILTER_NFNETLINK_ACCT_H
12
13 # include <stdio.h>
14 # include <sys/socket.h>
15 # include "netlink.h"
16 # include <linux/netfilter/nfnetlink.h>
17 # include <linux/netfilter/nfnetlink_acct.h>
18
19 static void
20 test_nlmsg_type(const int fd)
21 {
22         long rc;
23         struct nlmsghdr nlh = {
24                 .nlmsg_len = sizeof(nlh),
25                 .nlmsg_flags = NLM_F_REQUEST,
26         };
27
28         nlh.nlmsg_type = NFNL_SUBSYS_ACCT << 8 | NFNL_MSG_ACCT_NEW;
29         rc = sendto(fd, &nlh, nlh.nlmsg_len, MSG_DONTWAIT, NULL, 0);
30         printf("sendto(%d, {len=%u"
31                ", type=NFNL_SUBSYS_ACCT<<8|NFNL_MSG_ACCT_NEW"
32                ", flags=NLM_F_REQUEST, seq=0, pid=0}"
33                ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
34                fd, nlh.nlmsg_len, nlh.nlmsg_len, sprintrc(rc));
35
36         nlh.nlmsg_type = NFNL_SUBSYS_ACCT << 8 | 0xff;
37         rc = sendto(fd, &nlh, nlh.nlmsg_len, MSG_DONTWAIT, NULL, 0);
38         printf("sendto(%d, {len=%u"
39                ", type=NFNL_SUBSYS_ACCT<<8|0xff /* NFNL_MSG_ACCT_??? */"
40                ", flags=NLM_F_REQUEST, seq=0, pid=0}"
41                ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
42                fd, nlh.nlmsg_len, nlh.nlmsg_len, sprintrc(rc));
43 }
44
45 static void
46 test_nlmsg_flags(const int fd)
47 {
48         long rc;
49         struct nlmsghdr nlh = {
50                 .nlmsg_len = sizeof(nlh),
51         };
52
53         nlh.nlmsg_type = NFNL_SUBSYS_ACCT << 8 | NFNL_MSG_ACCT_NEW;
54         nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE;
55         rc = sendto(fd, &nlh, nlh.nlmsg_len, MSG_DONTWAIT, NULL, 0);
56         printf("sendto(%d, {len=%u"
57                ", type=NFNL_SUBSYS_ACCT<<8|NFNL_MSG_ACCT_NEW"
58                ", flags=NLM_F_REQUEST|NLM_F_CREATE, seq=0, pid=0}"
59                ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
60                fd, nlh.nlmsg_len, nlh.nlmsg_len, sprintrc(rc));
61
62         nlh.nlmsg_type = NFNL_SUBSYS_ACCT << 8 | NFNL_MSG_ACCT_GET;
63         nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_MATCH;
64         rc = sendto(fd, &nlh, nlh.nlmsg_len, MSG_DONTWAIT, NULL, 0);
65         printf("sendto(%d, {len=%u"
66                ", type=NFNL_SUBSYS_ACCT<<8|NFNL_MSG_ACCT_GET"
67                ", flags=NLM_F_REQUEST|NLM_F_MATCH, seq=0, pid=0}"
68                ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
69                fd, nlh.nlmsg_len, nlh.nlmsg_len, sprintrc(rc));
70
71         nlh.nlmsg_type = NFNL_SUBSYS_ACCT << 8 | NFNL_MSG_ACCT_DEL;
72         nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_NONREC;
73         rc = sendto(fd, &nlh, nlh.nlmsg_len, MSG_DONTWAIT, NULL, 0);
74         printf("sendto(%d, {len=%u"
75                ", type=NFNL_SUBSYS_ACCT<<8|NFNL_MSG_ACCT_DEL"
76                ", flags=NLM_F_REQUEST|NLM_F_NONREC, seq=0, pid=0}"
77                ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
78                fd, nlh.nlmsg_len, nlh.nlmsg_len, sprintrc(rc));
79 }
80
81 int
82 main(void)
83 {
84         skip_if_unavailable("/proc/self/fd/");
85
86         int fd = create_nl_socket(NETLINK_NETFILTER);
87
88         test_nlmsg_type(fd);
89         test_nlmsg_flags(fd);
90
91         puts("+++ exited with 0 +++");
92
93         return 0;
94 }
95
96 #else
97
98 SKIP_MAIN_UNDEFINED("HAVE_LINUX_NETFILTER_NFNETLINK_ACCT_H")
99
100 #endif