initial commit with v2.6.9
[linux-2.6.9-moxart.git] / include / linux / netfilter_ipv4 / ip_tables.h
blob02a006f17ac40b846eeb40488f89479e93a476b0
1 /*
2 * 25-Jul-1998 Major changes to allow for ip chain table
4 * 3-Jan-2000 Named tables to allow packet selection for different uses.
5 */
7 /*
8 * Format of an IP firewall descriptor
10 * src, dst, src_mask, dst_mask are always stored in network byte order.
11 * flags are stored in host byte order (of course).
12 * Port numbers are stored in HOST byte order.
15 #ifndef _IPTABLES_H
16 #define _IPTABLES_H
18 #ifdef __KERNEL__
19 #include <linux/if.h>
20 #include <linux/types.h>
21 #include <linux/in.h>
22 #include <linux/ip.h>
23 #include <linux/skbuff.h>
24 #endif
25 #include <linux/compiler.h>
26 #include <linux/netfilter_ipv4.h>
28 #define IPT_FUNCTION_MAXNAMELEN 30
29 #define IPT_TABLE_MAXNAMELEN 32
31 /* Yes, Virginia, you have to zero the padding. */
32 struct ipt_ip {
33 /* Source and destination IP addr */
34 struct in_addr src, dst;
35 /* Mask for src and dest IP addr */
36 struct in_addr smsk, dmsk;
37 char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
38 unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
40 /* Protocol, 0 = ANY */
41 u_int16_t proto;
43 /* Flags word */
44 u_int8_t flags;
45 /* Inverse flags */
46 u_int8_t invflags;
49 struct ipt_entry_match
51 union {
52 struct {
53 u_int16_t match_size;
55 /* Used by userspace */
56 char name[IPT_FUNCTION_MAXNAMELEN];
57 } user;
58 struct {
59 u_int16_t match_size;
61 /* Used inside the kernel */
62 struct ipt_match *match;
63 } kernel;
65 /* Total length */
66 u_int16_t match_size;
67 } u;
69 unsigned char data[0];
72 struct ipt_entry_target
74 union {
75 struct {
76 u_int16_t target_size;
78 /* Used by userspace */
79 char name[IPT_FUNCTION_MAXNAMELEN];
80 } user;
81 struct {
82 u_int16_t target_size;
84 /* Used inside the kernel */
85 struct ipt_target *target;
86 } kernel;
88 /* Total length */
89 u_int16_t target_size;
90 } u;
92 unsigned char data[0];
95 struct ipt_standard_target
97 struct ipt_entry_target target;
98 int verdict;
101 struct ipt_counters
103 u_int64_t pcnt, bcnt; /* Packet and byte counters */
106 /* Values for "flag" field in struct ipt_ip (general ip structure). */
107 #define IPT_F_FRAG 0x01 /* Set if rule is a fragment rule */
108 #define IPT_F_MASK 0x01 /* All possible flag bits mask. */
110 /* Values for "inv" field in struct ipt_ip. */
111 #define IPT_INV_VIA_IN 0x01 /* Invert the sense of IN IFACE. */
112 #define IPT_INV_VIA_OUT 0x02 /* Invert the sense of OUT IFACE */
113 #define IPT_INV_TOS 0x04 /* Invert the sense of TOS. */
114 #define IPT_INV_SRCIP 0x08 /* Invert the sense of SRC IP. */
115 #define IPT_INV_DSTIP 0x10 /* Invert the sense of DST OP. */
116 #define IPT_INV_FRAG 0x20 /* Invert the sense of FRAG. */
117 #define IPT_INV_PROTO 0x40 /* Invert the sense of PROTO. */
118 #define IPT_INV_MASK 0x7F /* All possible flag bits mask. */
120 /* This structure defines each of the firewall rules. Consists of 3
121 parts which are 1) general IP header stuff 2) match specific
122 stuff 3) the target to perform if the rule matches */
123 struct ipt_entry
125 struct ipt_ip ip;
127 /* Mark with fields that we care about. */
128 unsigned int nfcache;
130 /* Size of ipt_entry + matches */
131 u_int16_t target_offset;
132 /* Size of ipt_entry + matches + target */
133 u_int16_t next_offset;
135 /* Back pointer */
136 unsigned int comefrom;
138 /* Packet and byte counters. */
139 struct ipt_counters counters;
141 /* The matches (if any), then the target. */
142 unsigned char elems[0];
146 * New IP firewall options for [gs]etsockopt at the RAW IP level.
147 * Unlike BSD Linux inherits IP options so you don't have to use a raw
148 * socket for this. Instead we check rights in the calls. */
149 #define IPT_BASE_CTL 64 /* base for firewall socket options */
151 #define IPT_SO_SET_REPLACE (IPT_BASE_CTL)
152 #define IPT_SO_SET_ADD_COUNTERS (IPT_BASE_CTL + 1)
153 #define IPT_SO_SET_MAX IPT_SO_SET_ADD_COUNTERS
155 #define IPT_SO_GET_INFO (IPT_BASE_CTL)
156 #define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1)
157 #define IPT_SO_GET_MAX IPT_SO_GET_ENTRIES
159 /* CONTINUE verdict for targets */
160 #define IPT_CONTINUE 0xFFFFFFFF
162 /* For standard target */
163 #define IPT_RETURN (-NF_MAX_VERDICT - 1)
165 /* TCP matching stuff */
166 struct ipt_tcp
168 u_int16_t spts[2]; /* Source port range. */
169 u_int16_t dpts[2]; /* Destination port range. */
170 u_int8_t option; /* TCP Option iff non-zero*/
171 u_int8_t flg_mask; /* TCP flags mask byte */
172 u_int8_t flg_cmp; /* TCP flags compare byte */
173 u_int8_t invflags; /* Inverse flags */
176 /* Values for "inv" field in struct ipt_tcp. */
177 #define IPT_TCP_INV_SRCPT 0x01 /* Invert the sense of source ports. */
178 #define IPT_TCP_INV_DSTPT 0x02 /* Invert the sense of dest ports. */
179 #define IPT_TCP_INV_FLAGS 0x04 /* Invert the sense of TCP flags. */
180 #define IPT_TCP_INV_OPTION 0x08 /* Invert the sense of option test. */
181 #define IPT_TCP_INV_MASK 0x0F /* All possible flags. */
183 /* UDP matching stuff */
184 struct ipt_udp
186 u_int16_t spts[2]; /* Source port range. */
187 u_int16_t dpts[2]; /* Destination port range. */
188 u_int8_t invflags; /* Inverse flags */
191 /* Values for "invflags" field in struct ipt_udp. */
192 #define IPT_UDP_INV_SRCPT 0x01 /* Invert the sense of source ports. */
193 #define IPT_UDP_INV_DSTPT 0x02 /* Invert the sense of dest ports. */
194 #define IPT_UDP_INV_MASK 0x03 /* All possible flags. */
196 /* ICMP matching stuff */
197 struct ipt_icmp
199 u_int8_t type; /* type to match */
200 u_int8_t code[2]; /* range of code */
201 u_int8_t invflags; /* Inverse flags */
204 /* Values for "inv" field for struct ipt_icmp. */
205 #define IPT_ICMP_INV 0x01 /* Invert the sense of type/code test */
207 /* The argument to IPT_SO_GET_INFO */
208 struct ipt_getinfo
210 /* Which table: caller fills this in. */
211 char name[IPT_TABLE_MAXNAMELEN];
213 /* Kernel fills these in. */
214 /* Which hook entry points are valid: bitmask */
215 unsigned int valid_hooks;
217 /* Hook entry points: one per netfilter hook. */
218 unsigned int hook_entry[NF_IP_NUMHOOKS];
220 /* Underflow points. */
221 unsigned int underflow[NF_IP_NUMHOOKS];
223 /* Number of entries */
224 unsigned int num_entries;
226 /* Size of entries. */
227 unsigned int size;
230 /* The argument to IPT_SO_SET_REPLACE. */
231 struct ipt_replace
233 /* Which table. */
234 char name[IPT_TABLE_MAXNAMELEN];
236 /* Which hook entry points are valid: bitmask. You can't
237 change this. */
238 unsigned int valid_hooks;
240 /* Number of entries */
241 unsigned int num_entries;
243 /* Total size of new entries */
244 unsigned int size;
246 /* Hook entry points. */
247 unsigned int hook_entry[NF_IP_NUMHOOKS];
249 /* Underflow points. */
250 unsigned int underflow[NF_IP_NUMHOOKS];
252 /* Information about old entries: */
253 /* Number of counters (must be equal to current number of entries). */
254 unsigned int num_counters;
255 /* The old entries' counters. */
256 struct ipt_counters __user *counters;
258 /* The entries (hang off end: not really an array). */
259 struct ipt_entry entries[0];
262 /* The argument to IPT_SO_ADD_COUNTERS. */
263 struct ipt_counters_info
265 /* Which table. */
266 char name[IPT_TABLE_MAXNAMELEN];
268 unsigned int num_counters;
270 /* The counters (actually `number' of these). */
271 struct ipt_counters counters[0];
274 /* The argument to IPT_SO_GET_ENTRIES. */
275 struct ipt_get_entries
277 /* Which table: user fills this in. */
278 char name[IPT_TABLE_MAXNAMELEN];
280 /* User fills this in: total entry size. */
281 unsigned int size;
283 /* The entries. */
284 struct ipt_entry entrytable[0];
287 /* Standard return verdict, or do jump. */
288 #define IPT_STANDARD_TARGET ""
289 /* Error verdict. */
290 #define IPT_ERROR_TARGET "ERROR"
292 /* Helper functions */
293 static __inline__ struct ipt_entry_target *
294 ipt_get_target(struct ipt_entry *e)
296 return (void *)e + e->target_offset;
299 /* fn returns 0 to continue iteration */
300 #define IPT_MATCH_ITERATE(e, fn, args...) \
301 ({ \
302 unsigned int __i; \
303 int __ret = 0; \
304 struct ipt_entry_match *__match; \
306 for (__i = sizeof(struct ipt_entry); \
307 __i < (e)->target_offset; \
308 __i += __match->u.match_size) { \
309 __match = (void *)(e) + __i; \
311 __ret = fn(__match , ## args); \
312 if (__ret != 0) \
313 break; \
315 __ret; \
318 /* fn returns 0 to continue iteration */
319 #define IPT_ENTRY_ITERATE(entries, size, fn, args...) \
320 ({ \
321 unsigned int __i; \
322 int __ret = 0; \
323 struct ipt_entry *__entry; \
325 for (__i = 0; __i < (size); __i += __entry->next_offset) { \
326 __entry = (void *)(entries) + __i; \
328 __ret = fn(__entry , ## args); \
329 if (__ret != 0) \
330 break; \
332 __ret; \
336 * Main firewall chains definitions and global var's definitions.
338 #ifdef __KERNEL__
340 #include <linux/init.h>
341 extern void ipt_init(void) __init;
343 struct ipt_match
345 struct list_head list;
347 const char name[IPT_FUNCTION_MAXNAMELEN];
349 /* Return true or false: return FALSE and set *hotdrop = 1 to
350 force immediate packet drop. */
351 /* Arguments changed since 2.4, as this must now handle
352 non-linear skbs, using skb_copy_bits and
353 skb_ip_make_writable. */
354 int (*match)(const struct sk_buff *skb,
355 const struct net_device *in,
356 const struct net_device *out,
357 const void *matchinfo,
358 int offset,
359 int *hotdrop);
361 /* Called when user tries to insert an entry of this type. */
362 /* Should return true or false. */
363 int (*checkentry)(const char *tablename,
364 const struct ipt_ip *ip,
365 void *matchinfo,
366 unsigned int matchinfosize,
367 unsigned int hook_mask);
369 /* Called when entry of this type deleted. */
370 void (*destroy)(void *matchinfo, unsigned int matchinfosize);
372 /* Set this to THIS_MODULE. */
373 struct module *me;
376 /* Registration hooks for targets. */
377 struct ipt_target
379 struct list_head list;
381 const char name[IPT_FUNCTION_MAXNAMELEN];
383 /* Called when user tries to insert an entry of this type:
384 hook_mask is a bitmask of hooks from which it can be
385 called. */
386 /* Should return true or false. */
387 int (*checkentry)(const char *tablename,
388 const struct ipt_entry *e,
389 void *targinfo,
390 unsigned int targinfosize,
391 unsigned int hook_mask);
393 /* Called when entry of this type deleted. */
394 void (*destroy)(void *targinfo, unsigned int targinfosize);
396 /* Returns verdict. Argument order changed since 2.4, as this
397 must now handle non-linear skbs, using skb_copy_bits and
398 skb_ip_make_writable. */
399 unsigned int (*target)(struct sk_buff **pskb,
400 const struct net_device *in,
401 const struct net_device *out,
402 unsigned int hooknum,
403 const void *targinfo,
404 void *userdata);
406 /* Set this to THIS_MODULE. */
407 struct module *me;
410 extern struct ipt_target *
411 ipt_find_target_lock(const char *name, int *error, struct semaphore *mutex);
412 extern struct arpt_target *
413 arpt_find_target_lock(const char *name, int *error, struct semaphore *mutex);
415 extern int ipt_register_target(struct ipt_target *target);
416 extern void ipt_unregister_target(struct ipt_target *target);
418 extern int ipt_register_match(struct ipt_match *match);
419 extern void ipt_unregister_match(struct ipt_match *match);
421 /* Furniture shopping... */
422 struct ipt_table
424 struct list_head list;
426 /* A unique name... */
427 char name[IPT_TABLE_MAXNAMELEN];
429 /* Seed table: copied in register_table */
430 struct ipt_replace *table;
432 /* What hooks you will enter on */
433 unsigned int valid_hooks;
435 /* Lock for the curtain */
436 rwlock_t lock;
438 /* Man behind the curtain... */
439 struct ipt_table_info *private;
441 /* Set to THIS_MODULE. */
442 struct module *me;
445 extern int ipt_register_table(struct ipt_table *table);
446 extern void ipt_unregister_table(struct ipt_table *table);
447 extern unsigned int ipt_do_table(struct sk_buff **pskb,
448 unsigned int hook,
449 const struct net_device *in,
450 const struct net_device *out,
451 struct ipt_table *table,
452 void *userdata);
454 #define IPT_ALIGN(s) (((s) + (__alignof__(struct ipt_entry)-1)) & ~(__alignof__(struct ipt_entry)-1))
455 #endif /*__KERNEL__*/
456 #endif /* _IPTABLES_H */