2018-05-22 02:22:30 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2019-01-31 03:15:35 +00:00
|
|
|
#include "../../include/uapi/linux/bpf.h"
|
2018-05-22 02:22:30 +00:00
|
|
|
#include <asm/unistd.h>
|
|
|
|
#include "msgfmt.h"
|
|
|
|
|
2020-03-12 23:08:20 +00:00
|
|
|
FILE *debug_f;
|
2018-05-22 02:22:30 +00:00
|
|
|
|
|
|
|
static int handle_get_cmd(struct mbox_request *cmd)
|
|
|
|
{
|
|
|
|
switch (cmd->cmd) {
|
|
|
|
case 0:
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return -ENOPROTOOPT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int handle_set_cmd(struct mbox_request *cmd)
|
|
|
|
{
|
|
|
|
return -ENOPROTOOPT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void loop(void)
|
|
|
|
{
|
|
|
|
while (1) {
|
|
|
|
struct mbox_request req;
|
|
|
|
struct mbox_reply reply;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
n = read(0, &req, sizeof(req));
|
|
|
|
if (n != sizeof(req)) {
|
2020-03-12 23:08:20 +00:00
|
|
|
fprintf(debug_f, "invalid request %d\n", n);
|
2018-05-22 02:22:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
reply.status = req.is_set ?
|
|
|
|
handle_set_cmd(&req) :
|
|
|
|
handle_get_cmd(&req);
|
|
|
|
|
|
|
|
n = write(1, &reply, sizeof(reply));
|
|
|
|
if (n != sizeof(reply)) {
|
2020-03-12 23:08:20 +00:00
|
|
|
fprintf(debug_f, "reply failed %d\n", n);
|
2018-05-22 02:22:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2020-03-12 23:08:20 +00:00
|
|
|
debug_f = fopen("/dev/kmsg", "w");
|
|
|
|
setvbuf(debug_f, 0, _IOLBF, 0);
|
2021-06-23 04:09:18 +00:00
|
|
|
fprintf(debug_f, "<5>Started bpfilter\n");
|
2018-05-22 02:22:30 +00:00
|
|
|
loop();
|
2020-03-12 23:08:20 +00:00
|
|
|
fclose(debug_f);
|
2018-05-22 02:22:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|