]> bbs.cooldavid.org Git - net-next-2.6.git/blob - include/linux/netfilter_ipv6/ip6_tables.h
Merge master.kernel.org:/pub/scm/linux/kernel/git/wim/linux-2.6-watchdog
[net-next-2.6.git] / include / linux / netfilter_ipv6 / ip6_tables.h
1 /*
2  * 25-Jul-1998 Major changes to allow for ip chain table
3  *
4  * 3-Jan-2000 Named tables to allow packet selection for different uses.
5  */
6
7 /*
8  *      Format of an IP6 firewall descriptor
9  *
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.
13  */
14
15 #ifndef _IP6_TABLES_H
16 #define _IP6_TABLES_H
17
18 #ifdef __KERNEL__
19 #include <linux/if.h>
20 #include <linux/types.h>
21 #include <linux/in6.h>
22 #include <linux/ipv6.h>
23 #include <linux/skbuff.h>
24 #endif
25 #include <linux/compiler.h>
26 #include <linux/netfilter_ipv6.h>
27
28 #include <linux/netfilter/x_tables.h>
29
30 #define IP6T_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN
31 #define IP6T_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN
32
33 #define ip6t_match xt_match
34 #define ip6t_target xt_target
35 #define ip6t_table xt_table
36 #define ip6t_get_revision xt_get_revision
37
38 /* Yes, Virginia, you have to zero the padding. */
39 struct ip6t_ip6 {
40         /* Source and destination IP6 addr */
41         struct in6_addr src, dst;               
42         /* Mask for src and dest IP6 addr */
43         struct in6_addr smsk, dmsk;
44         char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
45         unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
46
47         /* ARGH, HopByHop uses 0, so can't do 0 = ANY,
48            instead IP6T_F_NOPROTO must be set */
49         u_int16_t proto;
50         /* TOS to match iff flags & IP6T_F_TOS */
51         u_int8_t tos;
52
53         /* Flags word */
54         u_int8_t flags;
55         /* Inverse flags */
56         u_int8_t invflags;
57 };
58
59 #define ip6t_entry_match xt_entry_match
60 #define ip6t_entry_target xt_entry_target
61 #define ip6t_standard_target xt_standard_target
62
63 #define ip6t_counters   xt_counters
64
65 /* Values for "flag" field in struct ip6t_ip6 (general ip6 structure). */
66 #define IP6T_F_PROTO            0x01    /* Set if rule cares about upper 
67                                            protocols */
68 #define IP6T_F_TOS              0x02    /* Match the TOS. */
69 #define IP6T_F_GOTO             0x04    /* Set if jump is a goto */
70 #define IP6T_F_MASK             0x07    /* All possible flag bits mask. */
71
72 /* Values for "inv" field in struct ip6t_ip6. */
73 #define IP6T_INV_VIA_IN         0x01    /* Invert the sense of IN IFACE. */
74 #define IP6T_INV_VIA_OUT                0x02    /* Invert the sense of OUT IFACE */
75 #define IP6T_INV_TOS            0x04    /* Invert the sense of TOS. */
76 #define IP6T_INV_SRCIP          0x08    /* Invert the sense of SRC IP. */
77 #define IP6T_INV_DSTIP          0x10    /* Invert the sense of DST OP. */
78 #define IP6T_INV_FRAG           0x20    /* Invert the sense of FRAG. */
79 #define IP6T_INV_PROTO          XT_INV_PROTO
80 #define IP6T_INV_MASK           0x7F    /* All possible flag bits mask. */
81
82 /* This structure defines each of the firewall rules.  Consists of 3
83    parts which are 1) general IP header stuff 2) match specific
84    stuff 3) the target to perform if the rule matches */
85 struct ip6t_entry
86 {
87         struct ip6t_ip6 ipv6;
88
89         /* Mark with fields that we care about. */
90         unsigned int nfcache;
91
92         /* Size of ipt_entry + matches */
93         u_int16_t target_offset;
94         /* Size of ipt_entry + matches + target */
95         u_int16_t next_offset;
96
97         /* Back pointer */
98         unsigned int comefrom;
99
100         /* Packet and byte counters. */
101         struct xt_counters counters;
102
103         /* The matches (if any), then the target. */
104         unsigned char elems[0];
105 };
106
107 /* Standard entry */
108 struct ip6t_standard
109 {
110         struct ip6t_entry entry;
111         struct ip6t_standard_target target;
112 };
113
114 struct ip6t_error_target
115 {
116         struct ip6t_entry_target target;
117         char errorname[IP6T_FUNCTION_MAXNAMELEN];
118 };
119
120 struct ip6t_error
121 {
122         struct ip6t_entry entry;
123         struct ip6t_error_target target;
124 };
125
126 /*
127  * New IP firewall options for [gs]etsockopt at the RAW IP level.
128  * Unlike BSD Linux inherits IP options so you don't have to use
129  * a raw socket for this. Instead we check rights in the calls.
130  *
131  * ATTENTION: check linux/in6.h before adding new number here.
132  */
133 #define IP6T_BASE_CTL                   64
134
135 #define IP6T_SO_SET_REPLACE             (IP6T_BASE_CTL)
136 #define IP6T_SO_SET_ADD_COUNTERS        (IP6T_BASE_CTL + 1)
137 #define IP6T_SO_SET_MAX                 IP6T_SO_SET_ADD_COUNTERS
138
139 #define IP6T_SO_GET_INFO                (IP6T_BASE_CTL)
140 #define IP6T_SO_GET_ENTRIES             (IP6T_BASE_CTL + 1)
141 #define IP6T_SO_GET_REVISION_MATCH      (IP6T_BASE_CTL + 4)
142 #define IP6T_SO_GET_REVISION_TARGET     (IP6T_BASE_CTL + 5)
143 #define IP6T_SO_GET_MAX                 IP6T_SO_GET_REVISION_TARGET
144
145 /* CONTINUE verdict for targets */
146 #define IP6T_CONTINUE XT_CONTINUE
147
148 /* For standard target */
149 #define IP6T_RETURN XT_RETURN
150
151 /* TCP/UDP matching stuff */
152 #include <linux/netfilter/xt_tcpudp.h>
153
154 #define ip6t_tcp xt_tcp
155 #define ip6t_udp xt_udp
156
157 /* Values for "inv" field in struct ipt_tcp. */
158 #define IP6T_TCP_INV_SRCPT      XT_TCP_INV_SRCPT
159 #define IP6T_TCP_INV_DSTPT      XT_TCP_INV_DSTPT
160 #define IP6T_TCP_INV_FLAGS      XT_TCP_INV_FLAGS
161 #define IP6T_TCP_INV_OPTION     XT_TCP_INV_OPTION
162 #define IP6T_TCP_INV_MASK       XT_TCP_INV_MASK
163
164 /* Values for "invflags" field in struct ipt_udp. */
165 #define IP6T_UDP_INV_SRCPT      XT_UDP_INV_SRCPT
166 #define IP6T_UDP_INV_DSTPT      XT_UDP_INV_DSTPT
167 #define IP6T_UDP_INV_MASK       XT_UDP_INV_MASK
168
169 /* ICMP matching stuff */
170 struct ip6t_icmp
171 {
172         u_int8_t type;                          /* type to match */
173         u_int8_t code[2];                       /* range of code */
174         u_int8_t invflags;                      /* Inverse flags */
175 };
176
177 /* Values for "inv" field for struct ipt_icmp. */
178 #define IP6T_ICMP_INV   0x01    /* Invert the sense of type/code test */
179
180 /* The argument to IP6T_SO_GET_INFO */
181 struct ip6t_getinfo
182 {
183         /* Which table: caller fills this in. */
184         char name[IP6T_TABLE_MAXNAMELEN];
185
186         /* Kernel fills these in. */
187         /* Which hook entry points are valid: bitmask */
188         unsigned int valid_hooks;
189
190         /* Hook entry points: one per netfilter hook. */
191         unsigned int hook_entry[NF_IP6_NUMHOOKS];
192
193         /* Underflow points. */
194         unsigned int underflow[NF_IP6_NUMHOOKS];
195
196         /* Number of entries */
197         unsigned int num_entries;
198
199         /* Size of entries. */
200         unsigned int size;
201 };
202
203 /* The argument to IP6T_SO_SET_REPLACE. */
204 struct ip6t_replace
205 {
206         /* Which table. */
207         char name[IP6T_TABLE_MAXNAMELEN];
208
209         /* Which hook entry points are valid: bitmask.  You can't
210            change this. */
211         unsigned int valid_hooks;
212
213         /* Number of entries */
214         unsigned int num_entries;
215
216         /* Total size of new entries */
217         unsigned int size;
218
219         /* Hook entry points. */
220         unsigned int hook_entry[NF_IP6_NUMHOOKS];
221
222         /* Underflow points. */
223         unsigned int underflow[NF_IP6_NUMHOOKS];
224
225         /* Information about old entries: */
226         /* Number of counters (must be equal to current number of entries). */
227         unsigned int num_counters;
228         /* The old entries' counters. */
229         struct xt_counters __user *counters;
230
231         /* The entries (hang off end: not really an array). */
232         struct ip6t_entry entries[0];
233 };
234
235 /* The argument to IP6T_SO_ADD_COUNTERS. */
236 #define ip6t_counters_info xt_counters_info
237
238 /* The argument to IP6T_SO_GET_ENTRIES. */
239 struct ip6t_get_entries
240 {
241         /* Which table: user fills this in. */
242         char name[IP6T_TABLE_MAXNAMELEN];
243
244         /* User fills this in: total entry size. */
245         unsigned int size;
246
247         /* The entries. */
248         struct ip6t_entry entrytable[0];
249 };
250
251 /* Standard return verdict, or do jump. */
252 #define IP6T_STANDARD_TARGET XT_STANDARD_TARGET
253 /* Error verdict. */
254 #define IP6T_ERROR_TARGET XT_ERROR_TARGET
255
256 /* Helper functions */
257 static __inline__ struct ip6t_entry_target *
258 ip6t_get_target(struct ip6t_entry *e)
259 {
260         return (void *)e + e->target_offset;
261 }
262
263 /* fn returns 0 to continue iteration */
264 #define IP6T_MATCH_ITERATE(e, fn, args...)      \
265 ({                                              \
266         unsigned int __i;                       \
267         int __ret = 0;                          \
268         struct ip6t_entry_match *__m;           \
269                                                 \
270         for (__i = sizeof(struct ip6t_entry);   \
271              __i < (e)->target_offset;          \
272              __i += __m->u.match_size) {        \
273                 __m = (void *)(e) + __i;        \
274                                                 \
275                 __ret = fn(__m , ## args);      \
276                 if (__ret != 0)                 \
277                         break;                  \
278         }                                       \
279         __ret;                                  \
280 })
281
282 /* fn returns 0 to continue iteration */
283 #define IP6T_ENTRY_ITERATE(entries, size, fn, args...)          \
284 ({                                                              \
285         unsigned int __i;                                       \
286         int __ret = 0;                                          \
287         struct ip6t_entry *__e;                                 \
288                                                                 \
289         for (__i = 0; __i < (size); __i += __e->next_offset) {  \
290                 __e = (void *)(entries) + __i;                  \
291                                                                 \
292                 __ret = fn(__e , ## args);                      \
293                 if (__ret != 0)                                 \
294                         break;                                  \
295         }                                                       \
296         __ret;                                                  \
297 })
298
299 /*
300  *      Main firewall chains definitions and global var's definitions.
301  */
302
303 #ifdef __KERNEL__
304
305 #include <linux/init.h>
306 extern void ip6t_init(void) __init;
307
308 extern int ip6t_register_table(struct xt_table *table,
309                                const struct ip6t_replace *repl);
310 extern void ip6t_unregister_table(struct xt_table *table);
311 extern unsigned int ip6t_do_table(struct sk_buff **pskb,
312                                   unsigned int hook,
313                                   const struct net_device *in,
314                                   const struct net_device *out,
315                                   struct xt_table *table);
316
317 /* Check for an extension */
318 extern int ip6t_ext_hdr(u8 nexthdr);
319 /* find specified header and get offset to it */
320 extern int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
321                          int target, unsigned short *fragoff);
322
323 extern int ip6_masked_addrcmp(const struct in6_addr *addr1,
324                               const struct in6_addr *mask,
325                               const struct in6_addr *addr2);
326
327 #define IP6T_ALIGN(s) (((s) + (__alignof__(struct ip6t_entry)-1)) & ~(__alignof__(struct ip6t_entry)-1))
328
329 #endif /*__KERNEL__*/
330 #endif /* _IP6_TABLES_H */