Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #define _GNU_SOURCE
0003 #include <sys/uio.h>
0004 #include <errno.h>
0005 #include <stdio.h>
0006 #include <sys/socket.h>
0007 #include <fcntl.h>
0008 #include <unistd.h>
0009 #include "../../include/uapi/linux/bpf.h"
0010 #include <asm/unistd.h>
0011 #include "msgfmt.h"
0012 
0013 FILE *debug_f;
0014 
0015 static int handle_get_cmd(struct mbox_request *cmd)
0016 {
0017     switch (cmd->cmd) {
0018     case 0:
0019         return 0;
0020     default:
0021         break;
0022     }
0023     return -ENOPROTOOPT;
0024 }
0025 
0026 static int handle_set_cmd(struct mbox_request *cmd)
0027 {
0028     return -ENOPROTOOPT;
0029 }
0030 
0031 static void loop(void)
0032 {
0033     while (1) {
0034         struct mbox_request req;
0035         struct mbox_reply reply;
0036         int n;
0037 
0038         n = read(0, &req, sizeof(req));
0039         if (n != sizeof(req)) {
0040             fprintf(debug_f, "invalid request %d\n", n);
0041             return;
0042         }
0043 
0044         reply.status = req.is_set ?
0045             handle_set_cmd(&req) :
0046             handle_get_cmd(&req);
0047 
0048         n = write(1, &reply, sizeof(reply));
0049         if (n != sizeof(reply)) {
0050             fprintf(debug_f, "reply failed %d\n", n);
0051             return;
0052         }
0053     }
0054 }
0055 
0056 int main(void)
0057 {
0058     debug_f = fopen("/dev/kmsg", "w");
0059     setvbuf(debug_f, 0, _IOLBF, 0);
0060     fprintf(debug_f, "<5>Started bpfilter\n");
0061     loop();
0062     fclose(debug_f);
0063     return 0;
0064 }