mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 10:49:33 +00:00
![Bruno Meneguele](/assets/img/avatar_default.png)
A testing message was brought by13d0f7b814
("net/bpfilter: fix dprintf usage for /dev/kmsg") but should've been deleted before patch submission. Although it doesn't cause any harm to the code or functionality itself, it's totally unpleasant to have it displayed on every loop iteration with no real use case. Thus remove it unconditionally. Fixes:13d0f7b814
("net/bpfilter: fix dprintf usage for /dev/kmsg") Signed-off-by: Bruno Meneguele <bmeneg@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
64 lines
1.1 KiB
C
64 lines
1.1 KiB
C
// 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>
|
|
#include "../../include/uapi/linux/bpf.h"
|
|
#include <asm/unistd.h>
|
|
#include "msgfmt.h"
|
|
|
|
FILE *debug_f;
|
|
|
|
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)) {
|
|
fprintf(debug_f, "invalid request %d\n", n);
|
|
return;
|
|
}
|
|
|
|
reply.status = req.is_set ?
|
|
handle_set_cmd(&req) :
|
|
handle_get_cmd(&req);
|
|
|
|
n = write(1, &reply, sizeof(reply));
|
|
if (n != sizeof(reply)) {
|
|
fprintf(debug_f, "reply failed %d\n", n);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
debug_f = fopen("/dev/kmsg", "w");
|
|
setvbuf(debug_f, 0, _IOLBF, 0);
|
|
fprintf(debug_f, "Started bpfilter\n");
|
|
loop();
|
|
fclose(debug_f);
|
|
return 0;
|
|
}
|