From 4d3be7be483f92030912e976e4dea24edd723f34 Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Tue, 4 Jun 2013 14:21:31 +0200 Subject: bpf: split up instructions and extensions from header Move them into a separate header file, so that it is more clean. Signed-off-by: Daniel Borkmann --- bpf.h | 100 ++---------------------------------------------------------- bpf_ext.h | 47 ++++++++++++++++++++++++++++ bpf_insns.h | 58 +++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 98 deletions(-) create mode 100644 bpf_ext.h create mode 100644 bpf_insns.h diff --git a/bpf.h b/bpf.h index 4e5fd31..1f6b21c 100644 --- a/bpf.h +++ b/bpf.h @@ -6,6 +6,8 @@ #include #include "xmalloc.h" +#include "bpf_insns.h" +#include "bpf_ext.h" extern void bpf_dump_op_table(void); extern void bpf_dump_all(struct sock_fprog *bpf); @@ -27,107 +29,9 @@ static inline void bpf_try_compile(const char *rulefile, panic("Cannot open file %s!\n", rulefile); } #endif - static inline void bpf_release(struct sock_fprog *bpf) { free(bpf->filter); } -#define BPF_CLASS(code) ((code) & 0x07) -#define BPF_LD 0x00 -#define BPF_LDX 0x01 -#define BPF_ST 0x02 -#define BPF_STX 0x03 -#define BPF_ALU 0x04 -#define BPF_JMP 0x05 -#define BPF_RET 0x06 -#define BPF_MISC 0x07 - -#define BPF_SIZE(code) ((code) & 0x18) -#define BPF_W 0x00 -#define BPF_H 0x08 -#define BPF_B 0x10 - -#define BPF_MODE(code) ((code) & 0xe0) -#define BPF_IMM 0x00 -#define BPF_ABS 0x20 -#define BPF_IND 0x40 -#define BPF_MEM 0x60 -#define BPF_LEN 0x80 -#define BPF_MSH 0xa0 - -#define BPF_OP(code) ((code) & 0xf0) -#define BPF_ADD 0x00 -#define BPF_SUB 0x10 -#define BPF_MUL 0x20 -#define BPF_DIV 0x30 -#define BPF_OR 0x40 -#define BPF_AND 0x50 -#define BPF_LSH 0x60 -#define BPF_RSH 0x70 -#define BPF_NEG 0x80 -#define BPF_MOD 0x90 -#define BPF_XOR 0xa0 - -#define BPF_JA 0x00 -#define BPF_JEQ 0x10 -#define BPF_JGT 0x20 -#define BPF_JGE 0x30 -#define BPF_JSET 0x40 - -#define BPF_SRC(code) ((code) & 0x08) -#define BPF_K 0x00 -#define BPF_X 0x08 - -/* ret - BPF_K and BPF_X also apply */ -#define BPF_RVAL(code) ((code) & 0x18) -#define BPF_A 0x10 - -#define BPF_MISCOP(code) ((code) & 0xf8) -#define BPF_TAX 0x00 -#define BPF_TXA 0x80 - -#ifndef SKF_AD_OFF -# define SKF_AD_OFF (-0x1000) -#endif -#ifndef SKF_AD_PROTOCOL -# define SKF_AD_PROTOCOL 0 -#endif -#ifndef SKF_AD_PKTTYPE -# define SKF_AD_PKTTYPE 4 -#endif -#ifndef SKF_AD_IFINDEX -# define SKF_AD_IFINDEX 8 -#endif -#ifndef SKF_AD_NLATTR -# define SKF_AD_NLATTR 12 -#endif -#ifndef SKF_AD_NLATTR_NEST -# define SKF_AD_NLATTR_NEST 16 -#endif -#ifndef SKF_AD_MARK -# define SKF_AD_MARK 20 -#endif -#ifndef SKF_AD_QUEUE -# define SKF_AD_QUEUE 24 -#endif -#ifndef SKF_AD_HATYPE -# define SKF_AD_HATYPE 28 -#endif -#ifndef SKF_AD_RXHASH -# define SKF_AD_RXHASH 32 -#endif -#ifndef SKF_AD_CPU -# define SKF_AD_CPU 36 -#endif -#ifndef SKF_AD_VLAN_TAG -# define SKF_AD_VLAN_TAG 44 -#endif -#ifndef SKF_AD_VLAN_TAG_PRESENT -# define SKF_AD_VLAN_TAG_PRESENT 48 -#endif -#ifndef SKF_AD_PAY_OFFSET -# define SKF_AD_PAY_OFFSET 52 -#endif - #endif /* BPF_I_H */ diff --git a/bpf_ext.h b/bpf_ext.h new file mode 100644 index 0000000..f9892ed --- /dev/null +++ b/bpf_ext.h @@ -0,0 +1,47 @@ +#ifndef BPF_EXT +#define BPF_EXT + +#ifndef SKF_AD_OFF +# define SKF_AD_OFF (-0x1000) +#endif +#ifndef SKF_AD_PROTOCOL +# define SKF_AD_PROTOCOL 0 +#endif +#ifndef SKF_AD_PKTTYPE +# define SKF_AD_PKTTYPE 4 +#endif +#ifndef SKF_AD_IFINDEX +# define SKF_AD_IFINDEX 8 +#endif +#ifndef SKF_AD_NLATTR +# define SKF_AD_NLATTR 12 +#endif +#ifndef SKF_AD_NLATTR_NEST +# define SKF_AD_NLATTR_NEST 16 +#endif +#ifndef SKF_AD_MARK +# define SKF_AD_MARK 20 +#endif +#ifndef SKF_AD_QUEUE +# define SKF_AD_QUEUE 24 +#endif +#ifndef SKF_AD_HATYPE +# define SKF_AD_HATYPE 28 +#endif +#ifndef SKF_AD_RXHASH +# define SKF_AD_RXHASH 32 +#endif +#ifndef SKF_AD_CPU +# define SKF_AD_CPU 36 +#endif +#ifndef SKF_AD_VLAN_TAG +# define SKF_AD_VLAN_TAG 44 +#endif +#ifndef SKF_AD_VLAN_TAG_PRESENT +# define SKF_AD_VLAN_TAG_PRESENT 48 +#endif +#ifndef SKF_AD_PAY_OFFSET +# define SKF_AD_PAY_OFFSET 52 +#endif + +#endif /* BPF_EXT */ diff --git a/bpf_insns.h b/bpf_insns.h new file mode 100644 index 0000000..193f0b7 --- /dev/null +++ b/bpf_insns.h @@ -0,0 +1,58 @@ +#ifndef BPF_INSNS_H +#define BPF_INSNS_H + +#define BPF_CLASS(code) ((code) & 0x07) +#define BPF_LD 0x00 +#define BPF_LDX 0x01 +#define BPF_ST 0x02 +#define BPF_STX 0x03 +#define BPF_ALU 0x04 +#define BPF_JMP 0x05 +#define BPF_RET 0x06 +#define BPF_MISC 0x07 + +#define BPF_SIZE(code) ((code) & 0x18) +#define BPF_W 0x00 +#define BPF_H 0x08 +#define BPF_B 0x10 + +#define BPF_MODE(code) ((code) & 0xe0) +#define BPF_IMM 0x00 +#define BPF_ABS 0x20 +#define BPF_IND 0x40 +#define BPF_MEM 0x60 +#define BPF_LEN 0x80 +#define BPF_MSH 0xa0 + +#define BPF_OP(code) ((code) & 0xf0) +#define BPF_ADD 0x00 +#define BPF_SUB 0x10 +#define BPF_MUL 0x20 +#define BPF_DIV 0x30 +#define BPF_OR 0x40 +#define BPF_AND 0x50 +#define BPF_LSH 0x60 +#define BPF_RSH 0x70 +#define BPF_NEG 0x80 +#define BPF_MOD 0x90 +#define BPF_XOR 0xa0 + +#define BPF_JA 0x00 +#define BPF_JEQ 0x10 +#define BPF_JGT 0x20 +#define BPF_JGE 0x30 +#define BPF_JSET 0x40 + +#define BPF_SRC(code) ((code) & 0x08) +#define BPF_K 0x00 +#define BPF_X 0x08 + +/* ret - BPF_K and BPF_X also apply */ +#define BPF_RVAL(code) ((code) & 0x18) +#define BPF_A 0x10 + +#define BPF_MISCOP(code) ((code) & 0xf8) +#define BPF_TAX 0x00 +#define BPF_TXA 0x80 + +#endif /* BPF_INSNS_H */ -- cgit v1.2.3-54-g00ecf