• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2 
3 #ifndef __LINUX_FILTER_H
4 #define __LINUX_FILTER_H
5 
6 #include <linux/bpf.h>
7 
8 #define BPF_ALU64_IMM(OP, DST, IMM)				\
9 	((struct bpf_insn) {					\
10 		.code  = BPF_ALU64 | BPF_OP(OP) | BPF_K,	\
11 		.dst_reg = DST,					\
12 		.src_reg = 0,					\
13 		.off   = 0,					\
14 		.imm   = IMM })
15 
16 #define BPF_MOV64_IMM(DST, IMM)					\
17 	((struct bpf_insn) {					\
18 		.code  = BPF_ALU64 | BPF_MOV | BPF_K,		\
19 		.dst_reg = DST,					\
20 		.src_reg = 0,					\
21 		.off   = 0,					\
22 		.imm   = IMM })
23 
24 #define BPF_EXIT_INSN()						\
25 	((struct bpf_insn) {					\
26 		.code  = BPF_JMP | BPF_EXIT,			\
27 		.dst_reg = 0,					\
28 		.src_reg = 0,					\
29 		.off   = 0,					\
30 		.imm   = 0 })
31 
32 #define BPF_JMP_IMM(OP, DST, IMM, OFF)				\
33 	((struct bpf_insn) {					\
34 		.code = BPF_JMP | BPF_OP(OP) | BPF_K,		\
35 		.dst_reg = DST,					\
36 		.src_reg = 0,					\
37 		.off  = OFF,					\
38 		.imm  = IMM })
39 
40 #define BPF_JMP32_IMM(OP, DST, IMM, OFF)			\
41 	((struct bpf_insn) {					\
42 		.code = BPF_JMP32 | BPF_OP(OP) | BPF_K,		\
43 		.dst_reg = DST,					\
44 		.src_reg = 0,					\
45 		.off  = OFF,					\
46 		.imm  = IMM })
47 
48 #endif
49