Iptables: ignore IPT_F_NO_DEF_MATCH flag when comparing rules
[tomato.git] / release / src / linux / linux / include / linux / netfilter_ipv4 / ip_tables.h
blobd4f5ec5dc931be0e48e2ad066a44c9becb46096d
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/netfilter_ipv4.h>
27 #define IPT_FUNCTION_MAXNAMELEN 30
28 #define IPT_TABLE_MAXNAMELEN 32
30 /* Yes, Virginia, you have to zero the padding. */
31 struct ipt_ip {
32 /* Source and destination IP addr */
33 struct in_addr src, dst;
34 /* Mask for src and dest IP addr */
35 struct in_addr smsk, dmsk;
36 char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
37 unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
39 /* Protocol, 0 = ANY */
40 u_int16_t proto;
42 /* Flags word */
43 u_int8_t flags;
44 /* Inverse flags */
45 u_int8_t invflags;
48 struct ipt_entry_match
50 union {
51 struct {
52 u_int16_t match_size;
54 /* Used by userspace */
55 char name[IPT_FUNCTION_MAXNAMELEN];
56 } user;
57 struct {
58 u_int16_t match_size;
60 /* Used inside the kernel */
61 struct ipt_match *match;
62 } kernel;
64 /* Total length */
65 u_int16_t match_size;
66 } u;
68 unsigned char data[0];
71 struct ipt_entry_target
73 union {
74 struct {
75 u_int16_t target_size;
77 /* Used by userspace */
78 char name[IPT_FUNCTION_MAXNAMELEN];
79 } user;
80 struct {
81 u_int16_t target_size;
83 /* Used inside the kernel */
84 struct ipt_target *target;
85 } kernel;
87 /* Total length */
88 u_int16_t target_size;
89 } u;
91 unsigned char data[0];
94 struct ipt_standard_target
96 struct ipt_entry_target target;
97 int verdict;
100 struct ipt_counters
102 u_int64_t pcnt, bcnt; /* Packet and byte counters */
105 /* Values for "flag" field in struct ipt_ip (general ip structure). */
106 #define IPT_F_FRAG 0x01 /* Set if rule is a fragment rule */
107 #define IPT_F_GOTO 0x02 /* Set if jump is a goto */
108 #define IPT_F_MASK 0x03 /* All possible flag bits mask. */
109 #define IPT_F_NO_DEF_MATCH 0x80 /* Internal: no default match rules present */
111 /* Values for "inv" field in struct ipt_ip. */
112 #define IPT_INV_VIA_IN 0x01 /* Invert the sense of IN IFACE. */
113 #define IPT_INV_VIA_OUT 0x02 /* Invert the sense of OUT IFACE */
114 #define IPT_INV_TOS 0x04 /* Invert the sense of TOS. */
115 #define IPT_INV_SRCIP 0x08 /* Invert the sense of SRC IP. */
116 #define IPT_INV_DSTIP 0x10 /* Invert the sense of DST OP. */
117 #define IPT_INV_FRAG 0x20 /* Invert the sense of FRAG. */
118 #define IPT_INV_PROTO 0x40 /* Invert the sense of PROTO. */
119 #define IPT_INV_MASK 0x7F /* All possible flag bits mask. */
121 /* This structure defines each of the firewall rules. Consists of 3
122 parts which are 1) general IP header stuff 2) match specific
123 stuff 3) the target to perform if the rule matches */
124 struct ipt_entry
126 struct ipt_ip ip;
128 /* Mark with fields that we care about. */
129 unsigned int nfcache;
131 /* Size of ipt_entry + matches */
132 u_int16_t target_offset;
133 /* Size of ipt_entry + matches + target */
134 u_int16_t next_offset;
136 /* Back pointer */
137 unsigned int comefrom;
139 /* Packet and byte counters. */
140 struct ipt_counters counters;
142 /* The matches (if any), then the target. */
143 unsigned char elems[0];
147 * New IP firewall options for [gs]etsockopt at the RAW IP level.
148 * Unlike BSD Linux inherits IP options so you don't have to use a raw
149 * socket for this. Instead we check rights in the calls. */
150 #define IPT_BASE_CTL 64 /* base for firewall socket options */
152 #define IPT_SO_SET_REPLACE (IPT_BASE_CTL)
153 #define IPT_SO_SET_ADD_COUNTERS (IPT_BASE_CTL + 1)
154 #define IPT_SO_SET_MAX IPT_SO_SET_ADD_COUNTERS
156 #define IPT_SO_GET_INFO (IPT_BASE_CTL)
157 #define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1)
158 #define IPT_SO_GET_MAX IPT_SO_GET_ENTRIES
160 /* CONTINUE verdict for targets */
161 #define IPT_CONTINUE 0xFFFFFFFF
163 /* For standard target */
164 #define IPT_RETURN (-NF_MAX_VERDICT - 1)
166 /* TCP matching stuff */
167 struct ipt_tcp
169 u_int16_t spts[2]; /* Source port range. */
170 u_int16_t dpts[2]; /* Destination port range. */
171 u_int8_t option; /* TCP Option iff non-zero*/
172 u_int8_t flg_mask; /* TCP flags mask byte */
173 u_int8_t flg_cmp; /* TCP flags compare byte */
174 u_int8_t invflags; /* Inverse flags */
177 /* Values for "inv" field in struct ipt_tcp. */
178 #define IPT_TCP_INV_SRCPT 0x01 /* Invert the sense of source ports. */
179 #define IPT_TCP_INV_DSTPT 0x02 /* Invert the sense of dest ports. */
180 #define IPT_TCP_INV_FLAGS 0x04 /* Invert the sense of TCP flags. */
181 #define IPT_TCP_INV_OPTION 0x08 /* Invert the sense of option test. */
182 #define IPT_TCP_INV_MASK 0x0F /* All possible flags. */
184 /* UDP matching stuff */
185 struct ipt_udp
187 u_int16_t spts[2]; /* Source port range. */
188 u_int16_t dpts[2]; /* Destination port range. */
189 u_int8_t invflags; /* Inverse flags */
192 /* Values for "invflags" field in struct ipt_udp. */
193 #define IPT_UDP_INV_SRCPT 0x01 /* Invert the sense of source ports. */
194 #define IPT_UDP_INV_DSTPT 0x02 /* Invert the sense of dest ports. */
195 #define IPT_UDP_INV_MASK 0x03 /* All possible flags. */
197 /* ICMP matching stuff */
198 struct ipt_icmp
200 u_int8_t type; /* type to match */
201 u_int8_t code[2]; /* range of code */
202 u_int8_t invflags; /* Inverse flags */
205 /* Values for "inv" field for struct ipt_icmp. */
206 #define IPT_ICMP_INV 0x01 /* Invert the sense of type/code test */
208 /* The argument to IPT_SO_GET_INFO */
209 struct ipt_getinfo
211 /* Which table: caller fills this in. */
212 char name[IPT_TABLE_MAXNAMELEN];
214 /* Kernel fills these in. */
215 /* Which hook entry points are valid: bitmask */
216 unsigned int valid_hooks;
218 /* Hook entry points: one per netfilter hook. */
219 unsigned int hook_entry[NF_IP_NUMHOOKS];
221 /* Underflow points. */
222 unsigned int underflow[NF_IP_NUMHOOKS];
224 /* Number of entries */
225 unsigned int num_entries;
227 /* Size of entries. */
228 unsigned int size;
231 /* The argument to IPT_SO_SET_REPLACE. */
232 struct ipt_replace
234 /* Which table. */
235 char name[IPT_TABLE_MAXNAMELEN];
237 /* Which hook entry points are valid: bitmask. You can't
238 change this. */
239 unsigned int valid_hooks;
241 /* Number of entries */
242 unsigned int num_entries;
244 /* Total size of new entries */
245 unsigned int size;
247 /* Hook entry points. */
248 unsigned int hook_entry[NF_IP_NUMHOOKS];
250 /* Underflow points. */
251 unsigned int underflow[NF_IP_NUMHOOKS];
253 /* Information about old entries: */
254 /* Number of counters (must be equal to current number of entries). */
255 unsigned int num_counters;
256 /* The old entries' counters. */
257 struct ipt_counters *counters;
259 /* The entries (hang off end: not really an array). */
260 struct ipt_entry entries[0];
263 /* The argument to IPT_SO_ADD_COUNTERS. */
264 struct ipt_counters_info
266 /* Which table. */
267 char name[IPT_TABLE_MAXNAMELEN];
269 unsigned int num_counters;
271 /* The counters (actually `number' of these). */
272 struct ipt_counters counters[0];
275 /* The argument to IPT_SO_GET_ENTRIES. */
276 struct ipt_get_entries
278 /* Which table: user fills this in. */
279 char name[IPT_TABLE_MAXNAMELEN];
281 /* User fills this in: total entry size. */
282 unsigned int size;
284 /* The entries. */
285 struct ipt_entry entrytable[0];
288 /* Standard return verdict, or do jump. */
289 #define IPT_STANDARD_TARGET ""
290 /* Error verdict. */
291 #define IPT_ERROR_TARGET "ERROR"
293 /* Helper functions */
294 static __inline__ struct ipt_entry_target *
295 ipt_get_target(struct ipt_entry *e)
297 return (void *)e + e->target_offset;
300 /* fn returns 0 to continue iteration */
301 #define IPT_MATCH_ITERATE(e, fn, args...) \
302 ({ \
303 unsigned int __i; \
304 int __ret = 0; \
305 struct ipt_entry_match *__match; \
307 for (__i = sizeof(struct ipt_entry); \
308 __i < (e)->target_offset; \
309 __i += __match->u.match_size) { \
310 __match = (void *)(e) + __i; \
312 __ret = fn(__match , ## args); \
313 if (__ret != 0) \
314 break; \
316 __ret; \
319 /* fn returns 0 to continue iteration */
320 #define IPT_ENTRY_ITERATE(entries, size, fn, args...) \
321 ({ \
322 unsigned int __i; \
323 int __ret = 0; \
324 struct ipt_entry *__entry; \
326 for (__i = 0; __i < (size); __i += __entry->next_offset) { \
327 __entry = (void *)(entries) + __i; \
329 __ret = fn(__entry , ## args); \
330 if (__ret != 0) \
331 break; \
333 __ret; \
337 * Main firewall chains definitions and global var's definitions.
339 #ifdef __KERNEL__
341 #include <linux/init.h>
342 extern void ipt_init(void) __init;
344 struct ipt_match
346 struct list_head list;
348 const char name[IPT_FUNCTION_MAXNAMELEN];
350 /* Return true or false: return FALSE and set *hotdrop = 1 to
351 force immediate packet drop. */
352 int (*match)(const struct sk_buff *skb,
353 const struct net_device *in,
354 const struct net_device *out,
355 const void *matchinfo,
356 int offset,
357 const void *hdr,
358 u_int16_t datalen,
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 if you are a module, otherwise NULL */
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 /* Returns verdict. */
384 unsigned int (*target)(struct sk_buff **pskb,
385 unsigned int hooknum,
386 const struct net_device *in,
387 const struct net_device *out,
388 const void *targinfo,
389 void *userdata);
391 /* Called when user tries to insert an entry of this type:
392 hook_mask is a bitmask of hooks from which it can be
393 called. */
394 /* Should return true or false. */
395 int (*checkentry)(const char *tablename,
396 const struct ipt_entry *e,
397 void *targinfo,
398 unsigned int targinfosize,
399 unsigned int hook_mask);
401 /* Called when entry of this type deleted. */
402 void (*destroy)(void *targinfo, unsigned int targinfosize);
404 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
405 struct module *me;
408 extern struct ipt_target *
409 ipt_find_target_lock(const char *name, int *error, struct semaphore *mutex);
410 extern struct arpt_target *
411 arpt_find_target_lock(const char *name, int *error, struct semaphore *mutex);
413 extern int ipt_register_target(struct ipt_target *target);
414 extern void ipt_unregister_target(struct ipt_target *target);
416 extern int ipt_register_match(struct ipt_match *match);
417 extern void ipt_unregister_match(struct ipt_match *match);
419 /* Furniture shopping... */
420 struct ipt_table
422 struct list_head list;
424 /* A unique name... */
425 char name[IPT_TABLE_MAXNAMELEN];
427 /* Seed table: copied in register_table */
428 struct ipt_replace *table;
430 /* What hooks you will enter on */
431 unsigned int valid_hooks;
433 /* Lock for the curtain */
434 rwlock_t lock;
436 /* Man behind the curtain... */
437 struct ipt_table_info *private;
439 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
440 struct module *me;
443 extern int ipt_register_table(struct ipt_table *table);
444 extern void ipt_unregister_table(struct ipt_table *table);
445 extern unsigned int ipt_do_table(struct sk_buff **pskb,
446 unsigned int hook,
447 const struct net_device *in,
448 const struct net_device *out,
449 struct ipt_table *table,
450 void *userdata);
452 #define IPT_ALIGN(s) (((s) + (__alignof__(struct ipt_entry)-1)) & ~(__alignof__(struct ipt_entry)-1))
453 #endif /*__KERNEL__*/
454 #endif /* _IPTABLES_H */