1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef _IP6_TABLES_H
16#define _IP6_TABLES_H
17
18#ifdef __KERNEL__
19#include <linux/if.h>
20#include <linux/in6.h>
21#include <linux/ipv6.h>
22#include <linux/skbuff.h>
23#endif
24#include <linux/types.h>
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
39struct ip6t_ip6 {
40
41 struct in6_addr src, dst;
42
43 struct in6_addr smsk, dmsk;
44 char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
45 unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
46
47
48
49
50
51
52
53
54
55 u_int16_t proto;
56
57 u_int8_t tos;
58
59
60 u_int8_t flags;
61
62 u_int8_t invflags;
63};
64
65#define ip6t_entry_match xt_entry_match
66#define ip6t_entry_target xt_entry_target
67#define ip6t_standard_target xt_standard_target
68
69#define ip6t_counters xt_counters
70
71
72#define IP6T_F_PROTO 0x01
73
74#define IP6T_F_TOS 0x02
75#define IP6T_F_GOTO 0x04
76#define IP6T_F_MASK 0x07
77
78
79#define IP6T_INV_VIA_IN 0x01
80#define IP6T_INV_VIA_OUT 0x02
81#define IP6T_INV_TOS 0x04
82#define IP6T_INV_SRCIP 0x08
83#define IP6T_INV_DSTIP 0x10
84#define IP6T_INV_FRAG 0x20
85#define IP6T_INV_PROTO XT_INV_PROTO
86#define IP6T_INV_MASK 0x7F
87
88
89
90
91struct ip6t_entry
92{
93 struct ip6t_ip6 ipv6;
94
95
96 unsigned int nfcache;
97
98
99 u_int16_t target_offset;
100
101 u_int16_t next_offset;
102
103
104 unsigned int comefrom;
105
106
107 struct xt_counters counters;
108
109
110 unsigned char elems[0];
111};
112
113
114struct ip6t_standard
115{
116 struct ip6t_entry entry;
117 struct ip6t_standard_target target;
118};
119
120struct ip6t_error_target
121{
122 struct ip6t_entry_target target;
123 char errorname[IP6T_FUNCTION_MAXNAMELEN];
124};
125
126struct ip6t_error
127{
128 struct ip6t_entry entry;
129 struct ip6t_error_target target;
130};
131
132#define IP6T_ENTRY_INIT(__size) \
133{ \
134 .target_offset = sizeof(struct ip6t_entry), \
135 .next_offset = (__size), \
136}
137
138#define IP6T_STANDARD_INIT(__verdict) \
139{ \
140 .entry = IP6T_ENTRY_INIT(sizeof(struct ip6t_standard)), \
141 .target = XT_TARGET_INIT(IP6T_STANDARD_TARGET, \
142 sizeof(struct ip6t_standard_target)), \
143 .target.verdict = -(__verdict) - 1, \
144}
145
146#define IP6T_ERROR_INIT \
147{ \
148 .entry = IP6T_ENTRY_INIT(sizeof(struct ip6t_error)), \
149 .target = XT_TARGET_INIT(IP6T_ERROR_TARGET, \
150 sizeof(struct ip6t_error_target)), \
151 .target.errorname = "ERROR", \
152}
153
154
155
156
157
158
159
160
161#define IP6T_BASE_CTL 64
162
163#define IP6T_SO_SET_REPLACE (IP6T_BASE_CTL)
164#define IP6T_SO_SET_ADD_COUNTERS (IP6T_BASE_CTL + 1)
165#define IP6T_SO_SET_MAX IP6T_SO_SET_ADD_COUNTERS
166
167#define IP6T_SO_GET_INFO (IP6T_BASE_CTL)
168#define IP6T_SO_GET_ENTRIES (IP6T_BASE_CTL + 1)
169#define IP6T_SO_GET_REVISION_MATCH (IP6T_BASE_CTL + 4)
170#define IP6T_SO_GET_REVISION_TARGET (IP6T_BASE_CTL + 5)
171#define IP6T_SO_GET_MAX IP6T_SO_GET_REVISION_TARGET
172
173
174#define IP6T_CONTINUE XT_CONTINUE
175
176
177#define IP6T_RETURN XT_RETURN
178
179
180#include <linux/netfilter/xt_tcpudp.h>
181
182#define ip6t_tcp xt_tcp
183#define ip6t_udp xt_udp
184
185
186#define IP6T_TCP_INV_SRCPT XT_TCP_INV_SRCPT
187#define IP6T_TCP_INV_DSTPT XT_TCP_INV_DSTPT
188#define IP6T_TCP_INV_FLAGS XT_TCP_INV_FLAGS
189#define IP6T_TCP_INV_OPTION XT_TCP_INV_OPTION
190#define IP6T_TCP_INV_MASK XT_TCP_INV_MASK
191
192
193#define IP6T_UDP_INV_SRCPT XT_UDP_INV_SRCPT
194#define IP6T_UDP_INV_DSTPT XT_UDP_INV_DSTPT
195#define IP6T_UDP_INV_MASK XT_UDP_INV_MASK
196
197
198struct ip6t_icmp
199{
200 u_int8_t type;
201 u_int8_t code[2];
202 u_int8_t invflags;
203};
204
205
206#define IP6T_ICMP_INV 0x01
207
208
209struct ip6t_getinfo
210{
211
212 char name[IP6T_TABLE_MAXNAMELEN];
213
214
215
216 unsigned int valid_hooks;
217
218
219 unsigned int hook_entry[NF_INET_NUMHOOKS];
220
221
222 unsigned int underflow[NF_INET_NUMHOOKS];
223
224
225 unsigned int num_entries;
226
227
228 unsigned int size;
229};
230
231
232struct ip6t_replace
233{
234
235 char name[IP6T_TABLE_MAXNAMELEN];
236
237
238
239 unsigned int valid_hooks;
240
241
242 unsigned int num_entries;
243
244
245 unsigned int size;
246
247
248 unsigned int hook_entry[NF_INET_NUMHOOKS];
249
250
251 unsigned int underflow[NF_INET_NUMHOOKS];
252
253
254
255 unsigned int num_counters;
256
257 struct xt_counters __user *counters;
258
259
260 struct ip6t_entry entries[0];
261};
262
263
264#define ip6t_counters_info xt_counters_info
265
266
267struct ip6t_get_entries
268{
269
270 char name[IP6T_TABLE_MAXNAMELEN];
271
272
273 unsigned int size;
274
275
276 struct ip6t_entry entrytable[0];
277};
278
279
280#define IP6T_STANDARD_TARGET XT_STANDARD_TARGET
281
282#define IP6T_ERROR_TARGET XT_ERROR_TARGET
283
284
285static __inline__ struct ip6t_entry_target *
286ip6t_get_target(struct ip6t_entry *e)
287{
288 return (void *)e + e->target_offset;
289}
290
291
292#define IP6T_MATCH_ITERATE(e, fn, args...) \
293 XT_MATCH_ITERATE(struct ip6t_entry, e, fn, ## args)
294
295
296#define IP6T_ENTRY_ITERATE(entries, size, fn, args...) \
297 XT_ENTRY_ITERATE(struct ip6t_entry, entries, size, fn, ## args)
298
299
300
301
302
303#ifdef __KERNEL__
304
305#include <linux/init.h>
306extern void ip6t_init(void) __init;
307
308extern struct xt_table *ip6t_register_table(struct net *net,
309 const struct xt_table *table,
310 const struct ip6t_replace *repl);
311extern void ip6t_unregister_table(struct xt_table *table);
312extern unsigned int ip6t_do_table(struct sk_buff *skb,
313 unsigned int hook,
314 const struct net_device *in,
315 const struct net_device *out,
316 struct xt_table *table);
317
318
319extern int ip6t_ext_hdr(u8 nexthdr);
320
321extern int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
322 int target, unsigned short *fragoff);
323
324extern int ip6_masked_addrcmp(const struct in6_addr *addr1,
325 const struct in6_addr *mask,
326 const struct in6_addr *addr2);
327
328#define IP6T_ALIGN(s) XT_ALIGN(s)
329
330#ifdef CONFIG_COMPAT
331#include <net/compat.h>
332
333struct compat_ip6t_entry
334{
335 struct ip6t_ip6 ipv6;
336 compat_uint_t nfcache;
337 u_int16_t target_offset;
338 u_int16_t next_offset;
339 compat_uint_t comefrom;
340 struct compat_xt_counters counters;
341 unsigned char elems[0];
342};
343
344static inline struct ip6t_entry_target *
345compat_ip6t_get_target(struct compat_ip6t_entry *e)
346{
347 return (void *)e + e->target_offset;
348}
349
350#define COMPAT_IP6T_ALIGN(s) COMPAT_XT_ALIGN(s)
351
352
353#define COMPAT_IP6T_MATCH_ITERATE(e, fn, args...) \
354 XT_MATCH_ITERATE(struct compat_ip6t_entry, e, fn, ## args)
355
356
357#define COMPAT_IP6T_ENTRY_ITERATE(entries, size, fn, args...) \
358 XT_ENTRY_ITERATE(struct compat_ip6t_entry, entries, size, fn, ## args)
359
360#define COMPAT_IP6T_ENTRY_ITERATE_CONTINUE(entries, size, n, fn, args...) \
361 XT_ENTRY_ITERATE_CONTINUE(struct compat_ip6t_entry, entries, size, n, \
362 fn, ## args)
363
364#endif
365#endif
366#endif
367