main.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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>
  9. #include "include/uapi/linux/bpf.h"
  10. #include <asm/unistd.h>
  11. #include "msgfmt.h"
  12. int debug_fd;
  13. static int handle_get_cmd(struct mbox_request *cmd)
  14. {
  15. switch (cmd->cmd) {
  16. case 0:
  17. return 0;
  18. default:
  19. break;
  20. }
  21. return -ENOPROTOOPT;
  22. }
  23. static int handle_set_cmd(struct mbox_request *cmd)
  24. {
  25. return -ENOPROTOOPT;
  26. }
  27. static void loop(void)
  28. {
  29. while (1) {
  30. struct mbox_request req;
  31. struct mbox_reply reply;
  32. int n;
  33. n = read(0, &req, sizeof(req));
  34. if (n != sizeof(req)) {
  35. dprintf(debug_fd, "invalid request %d\n", n);
  36. return;
  37. }
  38. reply.status = req.is_set ?
  39. handle_set_cmd(&req) :
  40. handle_get_cmd(&req);
  41. n = write(1, &reply, sizeof(reply));
  42. if (n != sizeof(reply)) {
  43. dprintf(debug_fd, "reply failed %d\n", n);
  44. return;
  45. }
  46. }
  47. }
  48. int main(void)
  49. {
  50. debug_fd = open("/dev/console", 00000002);
  51. dprintf(debug_fd, "Started bpfilter\n");
  52. loop();
  53. close(debug_fd);
  54. return 0;
  55. }