Blame view

net/bpfilter/main.c 1.06 KB
d2ba09c17   Alexei Starovoitov   net: add skeleton...
1
2
3
4
5
6
7
8
  // 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>
303a339f3   Masahiro Yamada   bpfilter: remove ...
9
  #include "../../include/uapi/linux/bpf.h"
d2ba09c17   Alexei Starovoitov   net: add skeleton...
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  #include <asm/unistd.h>
  #include "msgfmt.h"
  
  int debug_fd;
  
  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)) {
  			dprintf(debug_fd, "invalid request %d
  ", 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)) {
  			dprintf(debug_fd, "reply failed %d
  ", n);
  			return;
  		}
  	}
  }
  
  int main(void)
  {
36c4357c6   Gary Lin   net: bpfilter: pr...
60
  	debug_fd = open("/dev/kmsg", 00000002);
d2ba09c17   Alexei Starovoitov   net: add skeleton...
61
62
63
64
65
66
  	dprintf(debug_fd, "Started bpfilter
  ");
  	loop();
  	close(debug_fd);
  	return 0;
  }