summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-06-04 14:21:31 +0200
committerDaniel Borkmann <dborkman@redhat.com>2013-06-04 14:21:31 +0200
commit4d3be7be483f92030912e976e4dea24edd723f34 (patch)
treef695f07c924f887357d590ecb8f7ba5fc9c81c89
parent214cb42c626cfe5fe5d9ef1e83e7b23cca1cf02b (diff)
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 <dborkman@redhat.com>
-rw-r--r--bpf.h100
-rw-r--r--bpf_ext.h47
-rw-r--r--bpf_insns.h58
3 files changed, 107 insertions, 98 deletions
diff --git a/bpf.h b/bpf.h
index 4e5fd31..1f6b21c 100644
--- a/bpf.h
+++ b/bpf.h
@@ -6,6 +6,8 @@
#include <stdlib.h>
#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 */