1 // Copyright 2015 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef SANDBOX_LINUX_SYSTEM_HEADERS_LINUX_FILTER_H_ 6 #define SANDBOX_LINUX_SYSTEM_HEADERS_LINUX_FILTER_H_ 7 8 #include <stdint.h> 9 10 // The following structs and macros are taken from linux/filter.h, 11 // as some toolchain does not expose them. 12 struct sock_filter { 13 uint16_t code; 14 uint8_t jt; 15 uint8_t jf; 16 uint32_t k; 17 }; 18 19 struct sock_fprog { 20 uint16_t len; 21 struct sock_filter *filter; 22 }; 23 24 #ifndef BPF_CLASS 25 #define BPF_CLASS(code) ((code) & 0x07) 26 #endif 27 28 #ifndef BPF_LD 29 #define BPF_LD 0x00 30 #endif 31 32 #ifndef BPF_ALU 33 #define BPF_ALU 0x04 34 #endif 35 36 #ifndef BPF_JMP 37 #define BPF_JMP 0x05 38 #endif 39 40 #ifndef BPF_RET 41 #define BPF_RET 0x06 42 #endif 43 44 #ifndef BPF_SIZE 45 #define BPF_SIZE(code) ((code) & 0x18) 46 #endif 47 48 #ifndef BPF_W 49 #define BPF_W 0x00 50 #endif 51 52 #ifndef BPF_MODE 53 #define BPF_MODE(code) ((code) & 0xe0) 54 #endif 55 56 #ifndef BPF_ABS 57 #define BPF_ABS 0x20 58 #endif 59 60 #ifndef BPF_OP 61 #define BPF_OP(code) ((code) & 0xf0) 62 #endif 63 64 #ifndef BPF_ADD 65 #define BPF_ADD 0x00 66 #endif 67 68 #ifndef BPF_SUB 69 #define BPF_SUB 0x10 70 #endif 71 72 #ifndef BPF_MUL 73 #define BPF_MUL 0x20 74 #endif 75 76 #ifndef BPF_DIV 77 #define BPF_DIV 0x30 78 #endif 79 80 #ifndef BPF_OR 81 #define BPF_OR 0x40 82 #endif 83 84 #ifndef BPF_AND 85 #define BPF_AND 0x50 86 #endif 87 88 #ifndef BPF_LSH 89 #define BPF_LSH 0x60 90 #endif 91 92 #ifndef BPF_RSH 93 #define BPF_RSH 0x70 94 #endif 95 96 #ifndef BPF_NEG 97 #define BPF_NEG 0x80 98 #endif 99 100 #ifndef BPF_MOD 101 #define BPF_MOD 0x90 102 #endif 103 104 #ifndef BPF_XOR 105 #define BPF_XOR 0xA0 106 #endif 107 108 #ifndef BPF_JA 109 #define BPF_JA 0x00 110 #endif 111 112 #ifndef BPF_JEQ 113 #define BPF_JEQ 0x10 114 #endif 115 116 #ifndef BPF_JGT 117 #define BPF_JGT 0x20 118 #endif 119 120 #ifndef BPF_JGE 121 #define BPF_JGE 0x30 122 #endif 123 124 #ifndef BPF_JSET 125 #define BPF_JSET 0x40 126 #endif 127 128 #ifndef BPF_SRC 129 #define BPF_SRC(code) ((code) & 0x08) 130 #endif 131 132 #ifndef BPF_K 133 #define BPF_K 0x00 134 #endif 135 136 #ifndef BPF_MAXINSNS 137 #define BPF_MAXINSNS 4096 138 #endif 139 140 #endif // SANDBOX_LINUX_SYSTEM_HEADERS_LINUX_FILTER_H_ 141