Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 1 | #ifndef _X_TABLES_H |
| 2 | #define _X_TABLES_H |
| 3 | |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame^] | 4 | #include <linux/types.h> |
| 5 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 6 | #define XT_FUNCTION_MAXNAMELEN 30 |
| 7 | #define XT_TABLE_MAXNAMELEN 32 |
| 8 | |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 9 | struct xt_entry_match |
| 10 | { |
| 11 | union { |
| 12 | struct { |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame^] | 13 | __u16 match_size; |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 14 | |
| 15 | /* Used by userspace */ |
| 16 | char name[XT_FUNCTION_MAXNAMELEN-1]; |
| 17 | |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame^] | 18 | __u8 revision; |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 19 | } user; |
| 20 | struct { |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame^] | 21 | __u16 match_size; |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 22 | |
| 23 | /* Used inside the kernel */ |
| 24 | struct xt_match *match; |
| 25 | } kernel; |
| 26 | |
| 27 | /* Total length */ |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame^] | 28 | __u16 match_size; |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 29 | } u; |
| 30 | |
| 31 | unsigned char data[0]; |
| 32 | }; |
| 33 | |
| 34 | struct xt_entry_target |
| 35 | { |
| 36 | union { |
| 37 | struct { |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame^] | 38 | __u16 target_size; |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 39 | |
| 40 | /* Used by userspace */ |
| 41 | char name[XT_FUNCTION_MAXNAMELEN-1]; |
| 42 | |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame^] | 43 | __u8 revision; |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 44 | } user; |
| 45 | struct { |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame^] | 46 | __u16 target_size; |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 47 | |
| 48 | /* Used inside the kernel */ |
| 49 | struct xt_target *target; |
| 50 | } kernel; |
| 51 | |
| 52 | /* Total length */ |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame^] | 53 | __u16 target_size; |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 54 | } u; |
| 55 | |
| 56 | unsigned char data[0]; |
| 57 | }; |
| 58 | |
Patrick McHardy | 3c2ad46 | 2007-05-10 14:14:16 -0700 | [diff] [blame] | 59 | #define XT_TARGET_INIT(__name, __size) \ |
| 60 | { \ |
| 61 | .target.u.user = { \ |
| 62 | .target_size = XT_ALIGN(__size), \ |
| 63 | .name = __name, \ |
| 64 | }, \ |
| 65 | } |
| 66 | |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 67 | struct xt_standard_target |
| 68 | { |
| 69 | struct xt_entry_target target; |
| 70 | int verdict; |
| 71 | }; |
| 72 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 73 | /* The argument to IPT_SO_GET_REVISION_*. Returns highest revision |
| 74 | * kernel supports, if >= revision. */ |
| 75 | struct xt_get_revision |
| 76 | { |
| 77 | char name[XT_FUNCTION_MAXNAMELEN-1]; |
| 78 | |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame^] | 79 | __u8 revision; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | /* CONTINUE verdict for targets */ |
| 83 | #define XT_CONTINUE 0xFFFFFFFF |
| 84 | |
| 85 | /* For standard target */ |
| 86 | #define XT_RETURN (-NF_REPEAT - 1) |
| 87 | |
David S. Miller | 6fbfc96 | 2006-01-20 11:57:07 -0800 | [diff] [blame] | 88 | /* this is a dummy structure to find out the alignment requirement for a struct |
| 89 | * containing all the fundamental data types that are used in ipt_entry, |
| 90 | * ip6t_entry and arpt_entry. This sucks, and it is a hack. It will be my |
| 91 | * personal pleasure to remove it -HW |
| 92 | */ |
| 93 | struct _xt_align |
| 94 | { |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame^] | 95 | __u8 u8; |
| 96 | __u16 u16; |
| 97 | __u32 u32; |
| 98 | __u64 u64; |
David S. Miller | 6fbfc96 | 2006-01-20 11:57:07 -0800 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | #define XT_ALIGN(s) (((s) + (__alignof__(struct _xt_align)-1)) \ |
| 102 | & ~(__alignof__(struct _xt_align)-1)) |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 103 | |
| 104 | /* Standard return verdict, or do jump. */ |
| 105 | #define XT_STANDARD_TARGET "" |
| 106 | /* Error verdict. */ |
| 107 | #define XT_ERROR_TARGET "ERROR" |
| 108 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 109 | #define SET_COUNTER(c,b,p) do { (c).bcnt = (b); (c).pcnt = (p); } while(0) |
| 110 | #define ADD_COUNTER(c,b,p) do { (c).bcnt += (b); (c).pcnt += (p); } while(0) |
| 111 | |
| 112 | struct xt_counters |
| 113 | { |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame^] | 114 | __u64 pcnt, bcnt; /* Packet and byte counters */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | /* The argument to IPT_SO_ADD_COUNTERS. */ |
| 118 | struct xt_counters_info |
| 119 | { |
| 120 | /* Which table. */ |
| 121 | char name[XT_TABLE_MAXNAMELEN]; |
| 122 | |
| 123 | unsigned int num_counters; |
| 124 | |
| 125 | /* The counters (actually `number' of these). */ |
| 126 | struct xt_counters counters[0]; |
| 127 | }; |
| 128 | |
| 129 | #define XT_INV_PROTO 0x40 /* Invert the sense of PROTO. */ |
| 130 | |
Patrick McHardy | 89c002d | 2007-12-17 21:46:59 -0800 | [diff] [blame] | 131 | /* fn returns 0 to continue iteration */ |
| 132 | #define XT_MATCH_ITERATE(type, e, fn, args...) \ |
| 133 | ({ \ |
| 134 | unsigned int __i; \ |
| 135 | int __ret = 0; \ |
| 136 | struct xt_entry_match *__m; \ |
| 137 | \ |
| 138 | for (__i = sizeof(type); \ |
| 139 | __i < (e)->target_offset; \ |
| 140 | __i += __m->u.match_size) { \ |
| 141 | __m = (void *)e + __i; \ |
| 142 | \ |
| 143 | __ret = fn(__m , ## args); \ |
| 144 | if (__ret != 0) \ |
| 145 | break; \ |
| 146 | } \ |
| 147 | __ret; \ |
| 148 | }) |
| 149 | |
| 150 | /* fn returns 0 to continue iteration */ |
| 151 | #define XT_ENTRY_ITERATE_CONTINUE(type, entries, size, n, fn, args...) \ |
| 152 | ({ \ |
| 153 | unsigned int __i, __n; \ |
| 154 | int __ret = 0; \ |
| 155 | type *__entry; \ |
| 156 | \ |
| 157 | for (__i = 0, __n = 0; __i < (size); \ |
| 158 | __i += __entry->next_offset, __n++) { \ |
| 159 | __entry = (void *)(entries) + __i; \ |
| 160 | if (__n < n) \ |
| 161 | continue; \ |
| 162 | \ |
| 163 | __ret = fn(__entry , ## args); \ |
| 164 | if (__ret != 0) \ |
| 165 | break; \ |
| 166 | } \ |
| 167 | __ret; \ |
| 168 | }) |
| 169 | |
| 170 | /* fn returns 0 to continue iteration */ |
| 171 | #define XT_ENTRY_ITERATE(type, entries, size, fn, args...) \ |
| 172 | XT_ENTRY_ITERATE_CONTINUE(type, entries, size, 0, fn, args) |
| 173 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 174 | #ifdef __KERNEL__ |
| 175 | |
| 176 | #include <linux/netdevice.h> |
| 177 | |
Jan Engelhardt | f7108a2 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 178 | /** |
| 179 | * struct xt_match_param - parameters for match extensions' match functions |
| 180 | * |
| 181 | * @in: input netdevice |
| 182 | * @out: output netdevice |
| 183 | * @match: struct xt_match through which this function was invoked |
| 184 | * @matchinfo: per-match data |
| 185 | * @fragoff: packet is a fragment, this is the data offset |
| 186 | * @thoff: position of transport header relative to skb->data |
| 187 | * @hotdrop: drop packet if we had inspection problems |
Jan Engelhardt | 916a917 | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 188 | * @family: Actual NFPROTO_* through which the function is invoked |
| 189 | * (helpful when match->family == NFPROTO_UNSPEC) |
Jan Engelhardt | f7108a2 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 190 | */ |
| 191 | struct xt_match_param { |
| 192 | const struct net_device *in, *out; |
| 193 | const struct xt_match *match; |
| 194 | const void *matchinfo; |
| 195 | int fragoff; |
| 196 | unsigned int thoff; |
| 197 | bool *hotdrop; |
Jan Engelhardt | 916a917 | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 198 | u_int8_t family; |
Jan Engelhardt | f7108a2 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 199 | }; |
| 200 | |
Jan Engelhardt | 9b4fce7 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 201 | /** |
| 202 | * struct xt_mtchk_param - parameters for match extensions' |
| 203 | * checkentry functions |
| 204 | * |
| 205 | * @table: table the rule is tried to be inserted into |
| 206 | * @entryinfo: the family-specific rule data |
| 207 | * (struct ipt_ip, ip6t_ip, ebt_entry) |
| 208 | * @match: struct xt_match through which this function was invoked |
| 209 | * @matchinfo: per-match data |
| 210 | * @hook_mask: via which hooks the new rule is reachable |
| 211 | */ |
| 212 | struct xt_mtchk_param { |
| 213 | const char *table; |
| 214 | const void *entryinfo; |
| 215 | const struct xt_match *match; |
| 216 | void *matchinfo; |
| 217 | unsigned int hook_mask; |
Jan Engelhardt | 916a917 | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 218 | u_int8_t family; |
Jan Engelhardt | 9b4fce7 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 219 | }; |
| 220 | |
Jan Engelhardt | 6be3d85 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 221 | /* Match destructor parameters */ |
| 222 | struct xt_mtdtor_param { |
| 223 | const struct xt_match *match; |
| 224 | void *matchinfo; |
Jan Engelhardt | 916a917 | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 225 | u_int8_t family; |
Jan Engelhardt | 6be3d85 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 226 | }; |
| 227 | |
Jan Engelhardt | 7eb3558 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 228 | /** |
| 229 | * struct xt_target_param - parameters for target extensions' target functions |
| 230 | * |
| 231 | * @hooknum: hook through which this target was invoked |
| 232 | * @target: struct xt_target through which this function was invoked |
| 233 | * @targinfo: per-target data |
| 234 | * |
| 235 | * Other fields see above. |
| 236 | */ |
| 237 | struct xt_target_param { |
| 238 | const struct net_device *in, *out; |
| 239 | unsigned int hooknum; |
| 240 | const struct xt_target *target; |
| 241 | const void *targinfo; |
Jan Engelhardt | 916a917 | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 242 | u_int8_t family; |
Jan Engelhardt | 7eb3558 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 243 | }; |
| 244 | |
Jan Engelhardt | af5d6dc | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 245 | /** |
| 246 | * struct xt_tgchk_param - parameters for target extensions' |
| 247 | * checkentry functions |
| 248 | * |
| 249 | * @entryinfo: the family-specific rule data |
| 250 | * (struct ipt_entry, ip6t_entry, arpt_entry, ebt_entry) |
| 251 | * |
| 252 | * Other fields see above. |
| 253 | */ |
| 254 | struct xt_tgchk_param { |
| 255 | const char *table; |
Jan Engelhardt | f79fca5 | 2008-11-24 16:06:17 -0800 | [diff] [blame] | 256 | const void *entryinfo; |
Jan Engelhardt | af5d6dc | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 257 | const struct xt_target *target; |
| 258 | void *targinfo; |
| 259 | unsigned int hook_mask; |
Jan Engelhardt | 916a917 | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 260 | u_int8_t family; |
Jan Engelhardt | af5d6dc | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 261 | }; |
| 262 | |
Jan Engelhardt | a2df164 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 263 | /* Target destructor parameters */ |
| 264 | struct xt_tgdtor_param { |
| 265 | const struct xt_target *target; |
| 266 | void *targinfo; |
Jan Engelhardt | 916a917 | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 267 | u_int8_t family; |
Jan Engelhardt | a2df164 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 268 | }; |
| 269 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 270 | struct xt_match |
| 271 | { |
| 272 | struct list_head list; |
| 273 | |
| 274 | const char name[XT_FUNCTION_MAXNAMELEN-1]; |
Richard Kennedy | daaf83d | 2009-01-12 00:06:11 +0000 | [diff] [blame] | 275 | u_int8_t revision; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 276 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 277 | /* Return true or false: return FALSE and set *hotdrop = 1 to |
| 278 | force immediate packet drop. */ |
| 279 | /* Arguments changed since 2.6.9, as this must now handle |
| 280 | non-linear skb, using skb_header_pointer and |
| 281 | skb_ip_make_writable. */ |
Jan Engelhardt | 1d93a9c | 2007-07-07 22:15:35 -0700 | [diff] [blame] | 282 | bool (*match)(const struct sk_buff *skb, |
Jan Engelhardt | f7108a2 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 283 | const struct xt_match_param *); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 284 | |
| 285 | /* Called when user tries to insert an entry of this type. */ |
Jan Engelhardt | 9b4fce7 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 286 | bool (*checkentry)(const struct xt_mtchk_param *); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 287 | |
| 288 | /* Called when entry of this type deleted. */ |
Jan Engelhardt | 6be3d85 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 289 | void (*destroy)(const struct xt_mtdtor_param *); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 290 | |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 291 | /* Called when userspace align differs from kernel space one */ |
Patrick McHardy | 9fa492c | 2006-09-20 12:05:37 -0700 | [diff] [blame] | 292 | void (*compat_from_user)(void *dst, void *src); |
| 293 | int (*compat_to_user)(void __user *dst, void *src); |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 294 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 295 | /* Set this to THIS_MODULE if you are a module, otherwise NULL */ |
| 296 | struct module *me; |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 297 | |
Patrick McHardy | 91270cf | 2006-08-22 00:43:38 -0700 | [diff] [blame] | 298 | /* Free to use by each match */ |
| 299 | unsigned long data; |
| 300 | |
Jan Engelhardt | ecb6f85 | 2008-01-31 03:54:47 -0800 | [diff] [blame] | 301 | const char *table; |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 302 | unsigned int matchsize; |
Patrick McHardy | 9fa492c | 2006-09-20 12:05:37 -0700 | [diff] [blame] | 303 | unsigned int compatsize; |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 304 | unsigned int hooks; |
| 305 | unsigned short proto; |
Patrick McHardy | c4b8851 | 2006-03-20 18:03:40 -0800 | [diff] [blame] | 306 | |
| 307 | unsigned short family; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 308 | }; |
| 309 | |
| 310 | /* Registration hooks for targets. */ |
| 311 | struct xt_target |
| 312 | { |
| 313 | struct list_head list; |
| 314 | |
| 315 | const char name[XT_FUNCTION_MAXNAMELEN-1]; |
| 316 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 317 | /* Returns verdict. Argument order changed since 2.6.9, as this |
| 318 | must now handle non-linear skbs, using skb_copy_bits and |
| 319 | skb_ip_make_writable. */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 320 | unsigned int (*target)(struct sk_buff *skb, |
Jan Engelhardt | 7eb3558 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 321 | const struct xt_target_param *); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 322 | |
| 323 | /* Called when user tries to insert an entry of this type: |
| 324 | hook_mask is a bitmask of hooks from which it can be |
| 325 | called. */ |
| 326 | /* Should return true or false. */ |
Jan Engelhardt | af5d6dc | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 327 | bool (*checkentry)(const struct xt_tgchk_param *); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 328 | |
| 329 | /* Called when entry of this type deleted. */ |
Jan Engelhardt | a2df164 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 330 | void (*destroy)(const struct xt_tgdtor_param *); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 331 | |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 332 | /* Called when userspace align differs from kernel space one */ |
Patrick McHardy | 9fa492c | 2006-09-20 12:05:37 -0700 | [diff] [blame] | 333 | void (*compat_from_user)(void *dst, void *src); |
| 334 | int (*compat_to_user)(void __user *dst, void *src); |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 335 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 336 | /* Set this to THIS_MODULE if you are a module, otherwise NULL */ |
| 337 | struct module *me; |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 338 | |
Jan Engelhardt | ecb6f85 | 2008-01-31 03:54:47 -0800 | [diff] [blame] | 339 | const char *table; |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 340 | unsigned int targetsize; |
Patrick McHardy | 9fa492c | 2006-09-20 12:05:37 -0700 | [diff] [blame] | 341 | unsigned int compatsize; |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 342 | unsigned int hooks; |
| 343 | unsigned short proto; |
Patrick McHardy | c4b8851 | 2006-03-20 18:03:40 -0800 | [diff] [blame] | 344 | |
| 345 | unsigned short family; |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 346 | u_int8_t revision; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 347 | }; |
| 348 | |
| 349 | /* Furniture shopping... */ |
| 350 | struct xt_table |
| 351 | { |
| 352 | struct list_head list; |
| 353 | |
| 354 | /* A unique name... */ |
Jan Engelhardt | ecb6f85 | 2008-01-31 03:54:47 -0800 | [diff] [blame] | 355 | const char name[XT_TABLE_MAXNAMELEN]; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 356 | |
| 357 | /* What hooks you will enter on */ |
| 358 | unsigned int valid_hooks; |
| 359 | |
| 360 | /* Lock for the curtain */ |
| 361 | rwlock_t lock; |
| 362 | |
| 363 | /* Man behind the curtain... */ |
| 364 | //struct ip6t_table_info *private; |
| 365 | void *private; |
| 366 | |
| 367 | /* Set this to THIS_MODULE if you are a module, otherwise NULL */ |
| 368 | struct module *me; |
| 369 | |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 370 | u_int8_t af; /* address/protocol family */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 371 | }; |
| 372 | |
| 373 | #include <linux/netfilter_ipv4.h> |
| 374 | |
| 375 | /* The table itself */ |
| 376 | struct xt_table_info |
| 377 | { |
| 378 | /* Size per table */ |
| 379 | unsigned int size; |
| 380 | /* Number of entries: FIXME. --RR */ |
| 381 | unsigned int number; |
| 382 | /* Initial number of entries. Needed for module usage count */ |
| 383 | unsigned int initial_entries; |
| 384 | |
| 385 | /* Entry points and underflows */ |
Patrick McHardy | 6e23ae2 | 2007-11-19 18:53:30 -0800 | [diff] [blame] | 386 | unsigned int hook_entry[NF_INET_NUMHOOKS]; |
| 387 | unsigned int underflow[NF_INET_NUMHOOKS]; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 388 | |
| 389 | /* ipt_entry tables: one per CPU */ |
Eric Dumazet | 259d4e4 | 2007-12-04 23:24:56 -0800 | [diff] [blame] | 390 | /* Note : this field MUST be the last one, see XT_TABLE_INFO_SZ */ |
| 391 | char *entries[1]; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 392 | }; |
| 393 | |
Eric Dumazet | 259d4e4 | 2007-12-04 23:24:56 -0800 | [diff] [blame] | 394 | #define XT_TABLE_INFO_SZ (offsetof(struct xt_table_info, entries) \ |
| 395 | + nr_cpu_ids * sizeof(char *)) |
Pablo Neira Ayuso | a45049c | 2006-03-22 13:55:40 -0800 | [diff] [blame] | 396 | extern int xt_register_target(struct xt_target *target); |
| 397 | extern void xt_unregister_target(struct xt_target *target); |
Patrick McHardy | 52d9c42 | 2006-08-22 00:33:45 -0700 | [diff] [blame] | 398 | extern int xt_register_targets(struct xt_target *target, unsigned int n); |
| 399 | extern void xt_unregister_targets(struct xt_target *target, unsigned int n); |
| 400 | |
Pablo Neira Ayuso | a45049c | 2006-03-22 13:55:40 -0800 | [diff] [blame] | 401 | extern int xt_register_match(struct xt_match *target); |
| 402 | extern void xt_unregister_match(struct xt_match *target); |
Patrick McHardy | 52d9c42 | 2006-08-22 00:33:45 -0700 | [diff] [blame] | 403 | extern int xt_register_matches(struct xt_match *match, unsigned int n); |
| 404 | extern void xt_unregister_matches(struct xt_match *match, unsigned int n); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 405 | |
Jan Engelhardt | 916a917 | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 406 | extern int xt_check_match(struct xt_mtchk_param *, |
Jan Engelhardt | 9b4fce7 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 407 | unsigned int size, u_int8_t proto, bool inv_proto); |
Jan Engelhardt | 916a917 | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 408 | extern int xt_check_target(struct xt_tgchk_param *, |
Jan Engelhardt | af5d6dc | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 409 | unsigned int size, u_int8_t proto, bool inv_proto); |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 410 | |
Alexey Dobriyan | 8d87005 | 2008-01-31 04:02:13 -0800 | [diff] [blame] | 411 | extern struct xt_table *xt_register_table(struct net *net, |
| 412 | struct xt_table *table, |
Alexey Dobriyan | a98da11 | 2008-01-31 04:01:49 -0800 | [diff] [blame] | 413 | struct xt_table_info *bootstrap, |
| 414 | struct xt_table_info *newinfo); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 415 | extern void *xt_unregister_table(struct xt_table *table); |
| 416 | |
| 417 | extern struct xt_table_info *xt_replace_table(struct xt_table *table, |
| 418 | unsigned int num_counters, |
| 419 | struct xt_table_info *newinfo, |
| 420 | int *error); |
| 421 | |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 422 | extern struct xt_match *xt_find_match(u8 af, const char *name, u8 revision); |
| 423 | extern struct xt_target *xt_find_target(u8 af, const char *name, u8 revision); |
| 424 | extern struct xt_target *xt_request_find_target(u8 af, const char *name, |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 425 | u8 revision); |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 426 | extern int xt_find_revision(u8 af, const char *name, u8 revision, |
| 427 | int target, int *err); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 428 | |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 429 | extern struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af, |
Alexey Dobriyan | 8d87005 | 2008-01-31 04:02:13 -0800 | [diff] [blame] | 430 | const char *name); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 431 | extern void xt_table_unlock(struct xt_table *t); |
| 432 | |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 433 | extern int xt_proto_init(struct net *net, u_int8_t af); |
| 434 | extern void xt_proto_fini(struct net *net, u_int8_t af); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 435 | |
| 436 | extern struct xt_table_info *xt_alloc_table_info(unsigned int size); |
| 437 | extern void xt_free_table_info(struct xt_table_info *info); |
| 438 | |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 439 | #ifdef CONFIG_COMPAT |
| 440 | #include <net/compat.h> |
| 441 | |
| 442 | struct compat_xt_entry_match |
| 443 | { |
| 444 | union { |
| 445 | struct { |
| 446 | u_int16_t match_size; |
| 447 | char name[XT_FUNCTION_MAXNAMELEN - 1]; |
| 448 | u_int8_t revision; |
| 449 | } user; |
Patrick McHardy | 46c5ea3c | 2006-05-02 05:12:22 +0200 | [diff] [blame] | 450 | struct { |
| 451 | u_int16_t match_size; |
| 452 | compat_uptr_t match; |
| 453 | } kernel; |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 454 | u_int16_t match_size; |
| 455 | } u; |
| 456 | unsigned char data[0]; |
| 457 | }; |
| 458 | |
| 459 | struct compat_xt_entry_target |
| 460 | { |
| 461 | union { |
| 462 | struct { |
| 463 | u_int16_t target_size; |
| 464 | char name[XT_FUNCTION_MAXNAMELEN - 1]; |
| 465 | u_int8_t revision; |
| 466 | } user; |
Patrick McHardy | 46c5ea3c | 2006-05-02 05:12:22 +0200 | [diff] [blame] | 467 | struct { |
| 468 | u_int16_t target_size; |
| 469 | compat_uptr_t target; |
| 470 | } kernel; |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 471 | u_int16_t target_size; |
| 472 | } u; |
| 473 | unsigned char data[0]; |
| 474 | }; |
| 475 | |
| 476 | /* FIXME: this works only on 32 bit tasks |
| 477 | * need to change whole approach in order to calculate align as function of |
| 478 | * current task alignment */ |
| 479 | |
| 480 | struct compat_xt_counters |
| 481 | { |
Patrick McHardy | 55fe586 | 2006-04-24 17:16:28 -0700 | [diff] [blame] | 482 | #if defined(CONFIG_X86_64) || defined(CONFIG_IA64) |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 483 | u_int32_t cnt[4]; |
Patrick McHardy | 55fe586 | 2006-04-24 17:16:28 -0700 | [diff] [blame] | 484 | #else |
| 485 | u_int64_t cnt[2]; |
| 486 | #endif |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 487 | }; |
| 488 | |
| 489 | struct compat_xt_counters_info |
| 490 | { |
| 491 | char name[XT_TABLE_MAXNAMELEN]; |
| 492 | compat_uint_t num_counters; |
| 493 | struct compat_xt_counters counters[0]; |
| 494 | }; |
| 495 | |
| 496 | #define COMPAT_XT_ALIGN(s) (((s) + (__alignof__(struct compat_xt_counters)-1)) \ |
| 497 | & ~(__alignof__(struct compat_xt_counters)-1)) |
| 498 | |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 499 | extern void xt_compat_lock(u_int8_t af); |
| 500 | extern void xt_compat_unlock(u_int8_t af); |
Patrick McHardy | 9fa492c | 2006-09-20 12:05:37 -0700 | [diff] [blame] | 501 | |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 502 | extern int xt_compat_add_offset(u_int8_t af, unsigned int offset, short delta); |
| 503 | extern void xt_compat_flush_offsets(u_int8_t af); |
| 504 | extern short xt_compat_calc_jump(u_int8_t af, unsigned int offset); |
Patrick McHardy | b386d9f | 2007-12-17 21:47:48 -0800 | [diff] [blame] | 505 | |
Jan Engelhardt | 5452e42 | 2008-04-14 11:15:35 +0200 | [diff] [blame] | 506 | extern int xt_compat_match_offset(const struct xt_match *match); |
Patrick McHardy | 8956695 | 2007-12-17 21:46:40 -0800 | [diff] [blame] | 507 | extern int xt_compat_match_from_user(struct xt_entry_match *m, |
Patrick McHardy | b0a6363 | 2008-01-31 04:10:18 -0800 | [diff] [blame] | 508 | void **dstptr, unsigned int *size); |
Patrick McHardy | 9fa492c | 2006-09-20 12:05:37 -0700 | [diff] [blame] | 509 | extern int xt_compat_match_to_user(struct xt_entry_match *m, |
Patrick McHardy | b0a6363 | 2008-01-31 04:10:18 -0800 | [diff] [blame] | 510 | void __user **dstptr, unsigned int *size); |
Patrick McHardy | 9fa492c | 2006-09-20 12:05:37 -0700 | [diff] [blame] | 511 | |
Jan Engelhardt | 5452e42 | 2008-04-14 11:15:35 +0200 | [diff] [blame] | 512 | extern int xt_compat_target_offset(const struct xt_target *target); |
Patrick McHardy | 9fa492c | 2006-09-20 12:05:37 -0700 | [diff] [blame] | 513 | extern void xt_compat_target_from_user(struct xt_entry_target *t, |
Patrick McHardy | b0a6363 | 2008-01-31 04:10:18 -0800 | [diff] [blame] | 514 | void **dstptr, unsigned int *size); |
Patrick McHardy | 9fa492c | 2006-09-20 12:05:37 -0700 | [diff] [blame] | 515 | extern int xt_compat_target_to_user(struct xt_entry_target *t, |
Patrick McHardy | b0a6363 | 2008-01-31 04:10:18 -0800 | [diff] [blame] | 516 | void __user **dstptr, unsigned int *size); |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 517 | |
| 518 | #endif /* CONFIG_COMPAT */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 519 | #endif /* __KERNEL__ */ |
| 520 | |
| 521 | #endif /* _X_TABLES_H */ |