]>
Commit | Line | Data |
---|---|---|
2e4e6a17 HW |
1 | #ifndef _X_TABLES_H |
2 | #define _X_TABLES_H | |
3 | ||
4 | #define XT_FUNCTION_MAXNAMELEN 30 | |
5 | #define XT_TABLE_MAXNAMELEN 32 | |
6 | ||
1e30a014 DM |
7 | struct xt_entry_match |
8 | { | |
9 | union { | |
10 | struct { | |
11 | u_int16_t match_size; | |
12 | ||
13 | /* Used by userspace */ | |
14 | char name[XT_FUNCTION_MAXNAMELEN-1]; | |
15 | ||
16 | u_int8_t revision; | |
17 | } user; | |
18 | struct { | |
19 | u_int16_t match_size; | |
20 | ||
21 | /* Used inside the kernel */ | |
22 | struct xt_match *match; | |
23 | } kernel; | |
24 | ||
25 | /* Total length */ | |
26 | u_int16_t match_size; | |
27 | } u; | |
28 | ||
29 | unsigned char data[0]; | |
30 | }; | |
31 | ||
32 | struct xt_entry_target | |
33 | { | |
34 | union { | |
35 | struct { | |
36 | u_int16_t target_size; | |
37 | ||
38 | /* Used by userspace */ | |
39 | char name[XT_FUNCTION_MAXNAMELEN-1]; | |
40 | ||
41 | u_int8_t revision; | |
42 | } user; | |
43 | struct { | |
44 | u_int16_t target_size; | |
45 | ||
46 | /* Used inside the kernel */ | |
47 | struct xt_target *target; | |
48 | } kernel; | |
49 | ||
50 | /* Total length */ | |
51 | u_int16_t target_size; | |
52 | } u; | |
53 | ||
54 | unsigned char data[0]; | |
55 | }; | |
56 | ||
57 | struct xt_standard_target | |
58 | { | |
59 | struct xt_entry_target target; | |
60 | int verdict; | |
61 | }; | |
62 | ||
2e4e6a17 HW |
63 | /* The argument to IPT_SO_GET_REVISION_*. Returns highest revision |
64 | * kernel supports, if >= revision. */ | |
65 | struct xt_get_revision | |
66 | { | |
67 | char name[XT_FUNCTION_MAXNAMELEN-1]; | |
68 | ||
69 | u_int8_t revision; | |
70 | }; | |
71 | ||
72 | /* CONTINUE verdict for targets */ | |
73 | #define XT_CONTINUE 0xFFFFFFFF | |
74 | ||
75 | /* For standard target */ | |
76 | #define XT_RETURN (-NF_REPEAT - 1) | |
77 | ||
6fbfc968 DM |
78 | /* this is a dummy structure to find out the alignment requirement for a struct |
79 | * containing all the fundamental data types that are used in ipt_entry, | |
80 | * ip6t_entry and arpt_entry. This sucks, and it is a hack. It will be my | |
81 | * personal pleasure to remove it -HW | |
82 | */ | |
83 | struct _xt_align | |
84 | { | |
85 | u_int8_t u8; | |
86 | u_int16_t u16; | |
87 | u_int32_t u32; | |
88 | u_int64_t u64; | |
89 | }; | |
90 | ||
91 | #define XT_ALIGN(s) (((s) + (__alignof__(struct _xt_align)-1)) \ | |
92 | & ~(__alignof__(struct _xt_align)-1)) | |
2e4e6a17 HW |
93 | |
94 | /* Standard return verdict, or do jump. */ | |
95 | #define XT_STANDARD_TARGET "" | |
96 | /* Error verdict. */ | |
97 | #define XT_ERROR_TARGET "ERROR" | |
98 | ||
99 | /* | |
100 | * New IP firewall options for [gs]etsockopt at the RAW IP level. | |
101 | * Unlike BSD Linux inherits IP options so you don't have to use a raw | |
102 | * socket for this. Instead we check rights in the calls. */ | |
103 | #define XT_BASE_CTL 64 /* base for firewall socket options */ | |
104 | ||
105 | #define XT_SO_SET_REPLACE (XT_BASE_CTL) | |
106 | #define XT_SO_SET_ADD_COUNTERS (XT_BASE_CTL + 1) | |
107 | #define XT_SO_SET_MAX XT_SO_SET_ADD_COUNTERS | |
108 | ||
109 | #define XT_SO_GET_INFO (XT_BASE_CTL) | |
110 | #define XT_SO_GET_ENTRIES (XT_BASE_CTL + 1) | |
111 | #define XT_SO_GET_REVISION_MATCH (XT_BASE_CTL + 2) | |
112 | #define XT_SO_GET_REVISION_TARGET (XT_BASE_CTL + 3) | |
113 | #define XT_SO_GET_MAX XT_SO_GET_REVISION_TARGET | |
114 | ||
115 | #define SET_COUNTER(c,b,p) do { (c).bcnt = (b); (c).pcnt = (p); } while(0) | |
116 | #define ADD_COUNTER(c,b,p) do { (c).bcnt += (b); (c).pcnt += (p); } while(0) | |
117 | ||
118 | struct xt_counters | |
119 | { | |
120 | u_int64_t pcnt, bcnt; /* Packet and byte counters */ | |
121 | }; | |
122 | ||
123 | /* The argument to IPT_SO_ADD_COUNTERS. */ | |
124 | struct xt_counters_info | |
125 | { | |
126 | /* Which table. */ | |
127 | char name[XT_TABLE_MAXNAMELEN]; | |
128 | ||
129 | unsigned int num_counters; | |
130 | ||
131 | /* The counters (actually `number' of these). */ | |
132 | struct xt_counters counters[0]; | |
133 | }; | |
134 | ||
135 | #define XT_INV_PROTO 0x40 /* Invert the sense of PROTO. */ | |
136 | ||
137 | #ifdef __KERNEL__ | |
138 | ||
139 | #include <linux/netdevice.h> | |
140 | ||
2722971c DM |
141 | #ifdef CONFIG_COMPAT |
142 | #define COMPAT_TO_USER 1 | |
143 | #define COMPAT_FROM_USER -1 | |
144 | #define COMPAT_CALC_SIZE 0 | |
145 | #endif | |
146 | ||
2e4e6a17 HW |
147 | struct xt_match |
148 | { | |
149 | struct list_head list; | |
150 | ||
151 | const char name[XT_FUNCTION_MAXNAMELEN-1]; | |
152 | ||
2e4e6a17 HW |
153 | /* Return true or false: return FALSE and set *hotdrop = 1 to |
154 | force immediate packet drop. */ | |
155 | /* Arguments changed since 2.6.9, as this must now handle | |
156 | non-linear skb, using skb_header_pointer and | |
157 | skb_ip_make_writable. */ | |
158 | int (*match)(const struct sk_buff *skb, | |
159 | const struct net_device *in, | |
160 | const struct net_device *out, | |
1c524830 | 161 | const struct xt_match *match, |
2e4e6a17 HW |
162 | const void *matchinfo, |
163 | int offset, | |
164 | unsigned int protoff, | |
165 | int *hotdrop); | |
166 | ||
167 | /* Called when user tries to insert an entry of this type. */ | |
168 | /* Should return true or false. */ | |
169 | int (*checkentry)(const char *tablename, | |
170 | const void *ip, | |
1c524830 | 171 | const struct xt_match *match, |
2e4e6a17 | 172 | void *matchinfo, |
2e4e6a17 HW |
173 | unsigned int hook_mask); |
174 | ||
175 | /* Called when entry of this type deleted. */ | |
efa74165 | 176 | void (*destroy)(const struct xt_match *match, void *matchinfo); |
2e4e6a17 | 177 | |
2722971c DM |
178 | /* Called when userspace align differs from kernel space one */ |
179 | int (*compat)(void *match, void **dstptr, int *size, int convert); | |
180 | ||
2e4e6a17 HW |
181 | /* Set this to THIS_MODULE if you are a module, otherwise NULL */ |
182 | struct module *me; | |
37f9f733 | 183 | |
91270cf8 PM |
184 | /* Free to use by each match */ |
185 | unsigned long data; | |
186 | ||
37f9f733 PM |
187 | char *table; |
188 | unsigned int matchsize; | |
189 | unsigned int hooks; | |
190 | unsigned short proto; | |
c4b88513 PM |
191 | |
192 | unsigned short family; | |
37f9f733 | 193 | u_int8_t revision; |
2e4e6a17 HW |
194 | }; |
195 | ||
196 | /* Registration hooks for targets. */ | |
197 | struct xt_target | |
198 | { | |
199 | struct list_head list; | |
200 | ||
201 | const char name[XT_FUNCTION_MAXNAMELEN-1]; | |
202 | ||
2e4e6a17 HW |
203 | /* Returns verdict. Argument order changed since 2.6.9, as this |
204 | must now handle non-linear skbs, using skb_copy_bits and | |
205 | skb_ip_make_writable. */ | |
206 | unsigned int (*target)(struct sk_buff **pskb, | |
207 | const struct net_device *in, | |
208 | const struct net_device *out, | |
209 | unsigned int hooknum, | |
1c524830 | 210 | const struct xt_target *target, |
fe1cb108 | 211 | const void *targinfo); |
2e4e6a17 HW |
212 | |
213 | /* Called when user tries to insert an entry of this type: | |
214 | hook_mask is a bitmask of hooks from which it can be | |
215 | called. */ | |
216 | /* Should return true or false. */ | |
217 | int (*checkentry)(const char *tablename, | |
218 | const void *entry, | |
1c524830 | 219 | const struct xt_target *target, |
2e4e6a17 | 220 | void *targinfo, |
2e4e6a17 HW |
221 | unsigned int hook_mask); |
222 | ||
223 | /* Called when entry of this type deleted. */ | |
efa74165 | 224 | void (*destroy)(const struct xt_target *target, void *targinfo); |
2e4e6a17 | 225 | |
2722971c DM |
226 | /* Called when userspace align differs from kernel space one */ |
227 | int (*compat)(void *target, void **dstptr, int *size, int convert); | |
228 | ||
2e4e6a17 HW |
229 | /* Set this to THIS_MODULE if you are a module, otherwise NULL */ |
230 | struct module *me; | |
37f9f733 PM |
231 | |
232 | char *table; | |
233 | unsigned int targetsize; | |
234 | unsigned int hooks; | |
235 | unsigned short proto; | |
c4b88513 PM |
236 | |
237 | unsigned short family; | |
37f9f733 | 238 | u_int8_t revision; |
2e4e6a17 HW |
239 | }; |
240 | ||
241 | /* Furniture shopping... */ | |
242 | struct xt_table | |
243 | { | |
244 | struct list_head list; | |
245 | ||
246 | /* A unique name... */ | |
247 | char name[XT_TABLE_MAXNAMELEN]; | |
248 | ||
249 | /* What hooks you will enter on */ | |
250 | unsigned int valid_hooks; | |
251 | ||
252 | /* Lock for the curtain */ | |
253 | rwlock_t lock; | |
254 | ||
255 | /* Man behind the curtain... */ | |
256 | //struct ip6t_table_info *private; | |
257 | void *private; | |
258 | ||
259 | /* Set this to THIS_MODULE if you are a module, otherwise NULL */ | |
260 | struct module *me; | |
261 | ||
262 | int af; /* address/protocol family */ | |
263 | }; | |
264 | ||
265 | #include <linux/netfilter_ipv4.h> | |
266 | ||
267 | /* The table itself */ | |
268 | struct xt_table_info | |
269 | { | |
270 | /* Size per table */ | |
271 | unsigned int size; | |
272 | /* Number of entries: FIXME. --RR */ | |
273 | unsigned int number; | |
274 | /* Initial number of entries. Needed for module usage count */ | |
275 | unsigned int initial_entries; | |
276 | ||
277 | /* Entry points and underflows */ | |
278 | unsigned int hook_entry[NF_IP_NUMHOOKS]; | |
279 | unsigned int underflow[NF_IP_NUMHOOKS]; | |
280 | ||
281 | /* ipt_entry tables: one per CPU */ | |
282 | char *entries[NR_CPUS]; | |
283 | }; | |
284 | ||
a45049c5 PNA |
285 | extern int xt_register_target(struct xt_target *target); |
286 | extern void xt_unregister_target(struct xt_target *target); | |
52d9c42e PM |
287 | extern int xt_register_targets(struct xt_target *target, unsigned int n); |
288 | extern void xt_unregister_targets(struct xt_target *target, unsigned int n); | |
289 | ||
a45049c5 PNA |
290 | extern int xt_register_match(struct xt_match *target); |
291 | extern void xt_unregister_match(struct xt_match *target); | |
52d9c42e PM |
292 | extern int xt_register_matches(struct xt_match *match, unsigned int n); |
293 | extern void xt_unregister_matches(struct xt_match *match, unsigned int n); | |
2e4e6a17 | 294 | |
37f9f733 PM |
295 | extern int xt_check_match(const struct xt_match *match, unsigned short family, |
296 | unsigned int size, const char *table, unsigned int hook, | |
297 | unsigned short proto, int inv_proto); | |
298 | extern int xt_check_target(const struct xt_target *target, unsigned short family, | |
299 | unsigned int size, const char *table, unsigned int hook, | |
300 | unsigned short proto, int inv_proto); | |
301 | ||
2e4e6a17 HW |
302 | extern int xt_register_table(struct xt_table *table, |
303 | struct xt_table_info *bootstrap, | |
304 | struct xt_table_info *newinfo); | |
305 | extern void *xt_unregister_table(struct xt_table *table); | |
306 | ||
307 | extern struct xt_table_info *xt_replace_table(struct xt_table *table, | |
308 | unsigned int num_counters, | |
309 | struct xt_table_info *newinfo, | |
310 | int *error); | |
311 | ||
312 | extern struct xt_match *xt_find_match(int af, const char *name, u8 revision); | |
313 | extern struct xt_target *xt_find_target(int af, const char *name, u8 revision); | |
314 | extern struct xt_target *xt_request_find_target(int af, const char *name, | |
315 | u8 revision); | |
316 | extern int xt_find_revision(int af, const char *name, u8 revision, int target, | |
317 | int *err); | |
318 | ||
319 | extern struct xt_table *xt_find_table_lock(int af, const char *name); | |
320 | extern void xt_table_unlock(struct xt_table *t); | |
321 | ||
322 | extern int xt_proto_init(int af); | |
323 | extern void xt_proto_fini(int af); | |
324 | ||
325 | extern struct xt_table_info *xt_alloc_table_info(unsigned int size); | |
326 | extern void xt_free_table_info(struct xt_table_info *info); | |
327 | ||
2722971c DM |
328 | #ifdef CONFIG_COMPAT |
329 | #include <net/compat.h> | |
330 | ||
331 | struct compat_xt_entry_match | |
332 | { | |
333 | union { | |
334 | struct { | |
335 | u_int16_t match_size; | |
336 | char name[XT_FUNCTION_MAXNAMELEN - 1]; | |
337 | u_int8_t revision; | |
338 | } user; | |
46c5ea3c PM |
339 | struct { |
340 | u_int16_t match_size; | |
341 | compat_uptr_t match; | |
342 | } kernel; | |
2722971c DM |
343 | u_int16_t match_size; |
344 | } u; | |
345 | unsigned char data[0]; | |
346 | }; | |
347 | ||
348 | struct compat_xt_entry_target | |
349 | { | |
350 | union { | |
351 | struct { | |
352 | u_int16_t target_size; | |
353 | char name[XT_FUNCTION_MAXNAMELEN - 1]; | |
354 | u_int8_t revision; | |
355 | } user; | |
46c5ea3c PM |
356 | struct { |
357 | u_int16_t target_size; | |
358 | compat_uptr_t target; | |
359 | } kernel; | |
2722971c DM |
360 | u_int16_t target_size; |
361 | } u; | |
362 | unsigned char data[0]; | |
363 | }; | |
364 | ||
365 | /* FIXME: this works only on 32 bit tasks | |
366 | * need to change whole approach in order to calculate align as function of | |
367 | * current task alignment */ | |
368 | ||
369 | struct compat_xt_counters | |
370 | { | |
55fe5866 | 371 | #if defined(CONFIG_X86_64) || defined(CONFIG_IA64) |
2722971c | 372 | u_int32_t cnt[4]; |
55fe5866 PM |
373 | #else |
374 | u_int64_t cnt[2]; | |
375 | #endif | |
2722971c DM |
376 | }; |
377 | ||
378 | struct compat_xt_counters_info | |
379 | { | |
380 | char name[XT_TABLE_MAXNAMELEN]; | |
381 | compat_uint_t num_counters; | |
382 | struct compat_xt_counters counters[0]; | |
383 | }; | |
384 | ||
385 | #define COMPAT_XT_ALIGN(s) (((s) + (__alignof__(struct compat_xt_counters)-1)) \ | |
386 | & ~(__alignof__(struct compat_xt_counters)-1)) | |
387 | ||
388 | extern void xt_compat_lock(int af); | |
389 | extern void xt_compat_unlock(int af); | |
390 | extern int xt_compat_match(void *match, void **dstptr, int *size, int convert); | |
391 | extern int xt_compat_target(void *target, void **dstptr, int *size, | |
392 | int convert); | |
393 | ||
394 | #endif /* CONFIG_COMPAT */ | |
2e4e6a17 HW |
395 | #endif /* __KERNEL__ */ |
396 | ||
397 | #endif /* _X_TABLES_H */ |