Alexei Starovoitov | d2ba09c | 2018-05-21 19:22:30 -0700 | [diff] [blame] | 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> |
Masahiro Yamada | 303a339 | 2019-01-31 12:15:35 +0900 | [diff] [blame] | 9 | #include "../../include/uapi/linux/bpf.h" |
Alexei Starovoitov | d2ba09c | 2018-05-21 19:22:30 -0700 | [diff] [blame] | 10 | #include <asm/unistd.h> |
| 11 | #include "msgfmt.h" |
| 12 | |
Bruno Meneguele | 13d0f7b | 2020-03-12 20:08:20 -0300 | [diff] [blame] | 13 | FILE *debug_f; |
Alexei Starovoitov | d2ba09c | 2018-05-21 19:22:30 -0700 | [diff] [blame] | 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 | |
| 38 | n = read(0, &req, sizeof(req)); |
| 39 | if (n != sizeof(req)) { |
Bruno Meneguele | 13d0f7b | 2020-03-12 20:08:20 -0300 | [diff] [blame] | 40 | fprintf(debug_f, "invalid request %d\n", n); |
Alexei Starovoitov | d2ba09c | 2018-05-21 19:22:30 -0700 | [diff] [blame] | 41 | return; |
| 42 | } |
| 43 | |
| 44 | reply.status = req.is_set ? |
| 45 | handle_set_cmd(&req) : |
| 46 | handle_get_cmd(&req); |
| 47 | |
| 48 | n = write(1, &reply, sizeof(reply)); |
| 49 | if (n != sizeof(reply)) { |
Bruno Meneguele | 13d0f7b | 2020-03-12 20:08:20 -0300 | [diff] [blame] | 50 | fprintf(debug_f, "reply failed %d\n", n); |
Alexei Starovoitov | d2ba09c | 2018-05-21 19:22:30 -0700 | [diff] [blame] | 51 | return; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | int main(void) |
| 57 | { |
Bruno Meneguele | 13d0f7b | 2020-03-12 20:08:20 -0300 | [diff] [blame] | 58 | debug_f = fopen("/dev/kmsg", "w"); |
| 59 | setvbuf(debug_f, 0, _IOLBF, 0); |
Gary Lin | a196fa7 | 2021-06-23 12:09:18 +0800 | [diff] [blame] | 60 | fprintf(debug_f, "<5>Started bpfilter\n"); |
Alexei Starovoitov | d2ba09c | 2018-05-21 19:22:30 -0700 | [diff] [blame] | 61 | loop(); |
Bruno Meneguele | 13d0f7b | 2020-03-12 20:08:20 -0300 | [diff] [blame] | 62 | fclose(debug_f); |
Alexei Starovoitov | d2ba09c | 2018-05-21 19:22:30 -0700 | [diff] [blame] | 63 | return 0; |
| 64 | } |