Commit | Line | Data |
---|---|---|
d2ba09c1 AS |
1 | // SPDX-License-Identifier: GPL-2.0 |
2 | #define _GNU_SOURCE | |
3 | #include <sys/uio.h> | |
4 | #include <errno.h> | |
5 | #include <stdio.h> | |
6 | #include <sys/socket.h> | |
7 | #include <fcntl.h> | |
8 | #include <unistd.h> | |
303a339f | 9 | #include "../../include/uapi/linux/bpf.h" |
d2ba09c1 AS |
10 | #include <asm/unistd.h> |
11 | #include "msgfmt.h" | |
12 | ||
13d0f7b8 | 13 | FILE *debug_f; |
d2ba09c1 AS |
14 | |
15 | static int handle_get_cmd(struct mbox_request *cmd) | |
16 | { | |
17 | switch (cmd->cmd) { | |
18 | case 0: | |
19 | return 0; | |
20 | default: | |
21 | break; | |
22 | } | |
23 | return -ENOPROTOOPT; | |
24 | } | |
25 | ||
26 | static int handle_set_cmd(struct mbox_request *cmd) | |
27 | { | |
28 | return -ENOPROTOOPT; | |
29 | } | |
30 | ||
31 | static void loop(void) | |
32 | { | |
33 | while (1) { | |
34 | struct mbox_request req; | |
35 | struct mbox_reply reply; | |
36 | int n; | |
37 | ||
13d0f7b8 | 38 | fprintf(debug_f, "testing the buffer\n"); |
d2ba09c1 AS |
39 | n = read(0, &req, sizeof(req)); |
40 | if (n != sizeof(req)) { | |
13d0f7b8 | 41 | fprintf(debug_f, "invalid request %d\n", n); |
d2ba09c1 AS |
42 | return; |
43 | } | |
44 | ||
45 | reply.status = req.is_set ? | |
46 | handle_set_cmd(&req) : | |
47 | handle_get_cmd(&req); | |
48 | ||
49 | n = write(1, &reply, sizeof(reply)); | |
50 | if (n != sizeof(reply)) { | |
13d0f7b8 | 51 | fprintf(debug_f, "reply failed %d\n", n); |
d2ba09c1 AS |
52 | return; |
53 | } | |
54 | } | |
55 | } | |
56 | ||
57 | int main(void) | |
58 | { | |
13d0f7b8 BM |
59 | debug_f = fopen("/dev/kmsg", "w"); |
60 | setvbuf(debug_f, 0, _IOLBF, 0); | |
61 | fprintf(debug_f, "Started bpfilter\n"); | |
d2ba09c1 | 62 | loop(); |
13d0f7b8 | 63 | fclose(debug_f); |
d2ba09c1 AS |
64 | return 0; |
65 | } |