1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef _IPTABLES_H
16#define _IPTABLES_H
17
18#ifdef __KERNEL__
19#include <linux/if.h>
20#include <linux/in.h>
21#include <linux/ip.h>
22#include <linux/skbuff.h>
23#endif
24#include <linux/types.h>
25#include <linux/compiler.h>
26#include <linux/netfilter_ipv4.h>
27
28#include <linux/netfilter/x_tables.h>
29
30#define IPT_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN
31#define IPT_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN
32#define ipt_match xt_match
33#define ipt_target xt_target
34#define ipt_table xt_table
35#define ipt_get_revision xt_get_revision
36
37
38struct ipt_ip {
39
40 struct in_addr src, dst;
41
42 struct in_addr smsk, dmsk;
43 char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
44 unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
45
46
47 u_int16_t proto;
48
49
50 u_int8_t flags;
51
52 u_int8_t invflags;
53};
54
55#define ipt_entry_match xt_entry_match
56#define ipt_entry_target xt_entry_target
57#define ipt_standard_target xt_standard_target
58
59#define ipt_counters xt_counters
60
61
62#define IPT_F_FRAG 0x01
63#define IPT_F_GOTO 0x02
64#define IPT_F_MASK 0x03
65
66
67#define IPT_INV_VIA_IN 0x01
68#define IPT_INV_VIA_OUT 0x02
69#define IPT_INV_TOS 0x04
70#define IPT_INV_SRCIP 0x08
71#define IPT_INV_DSTIP 0x10
72#define IPT_INV_FRAG 0x20
73#define IPT_INV_PROTO XT_INV_PROTO
74#define IPT_INV_MASK 0x7F
75
76
77
78
79struct ipt_entry
80{
81 struct ipt_ip ip;
82
83
84 unsigned int nfcache;
85
86
87 u_int16_t target_offset;
88
89 u_int16_t next_offset;
90
91
92 unsigned int comefrom;
93
94
95 struct xt_counters counters;
96
97
98 unsigned char elems[0];
99};
100
101
102
103
104
105
106
107
108#define IPT_BASE_CTL 64
109
110#define IPT_SO_SET_REPLACE (IPT_BASE_CTL)
111#define IPT_SO_SET_ADD_COUNTERS (IPT_BASE_CTL + 1)
112#define IPT_SO_SET_MAX IPT_SO_SET_ADD_COUNTERS
113
114#define IPT_SO_GET_INFO (IPT_BASE_CTL)
115#define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1)
116#define IPT_SO_GET_REVISION_MATCH (IPT_BASE_CTL + 2)
117#define IPT_SO_GET_REVISION_TARGET (IPT_BASE_CTL + 3)
118#define IPT_SO_GET_MAX IPT_SO_GET_REVISION_TARGET
119
120#define IPT_CONTINUE XT_CONTINUE
121#define IPT_RETURN XT_RETURN
122
123#include <linux/netfilter/xt_tcpudp.h>
124#define ipt_udp xt_udp
125#define ipt_tcp xt_tcp
126
127#define IPT_TCP_INV_SRCPT XT_TCP_INV_SRCPT
128#define IPT_TCP_INV_DSTPT XT_TCP_INV_DSTPT
129#define IPT_TCP_INV_FLAGS XT_TCP_INV_FLAGS
130#define IPT_TCP_INV_OPTION XT_TCP_INV_OPTION
131#define IPT_TCP_INV_MASK XT_TCP_INV_MASK
132
133#define IPT_UDP_INV_SRCPT XT_UDP_INV_SRCPT
134#define IPT_UDP_INV_DSTPT XT_UDP_INV_DSTPT
135#define IPT_UDP_INV_MASK XT_UDP_INV_MASK
136
137
138struct ipt_icmp
139{
140 u_int8_t type;
141 u_int8_t code[2];
142 u_int8_t invflags;
143};
144
145
146#define IPT_ICMP_INV 0x01
147
148
149struct ipt_getinfo
150{
151
152 char name[IPT_TABLE_MAXNAMELEN];
153
154
155
156 unsigned int valid_hooks;
157
158
159 unsigned int hook_entry[NF_INET_NUMHOOKS];
160
161
162 unsigned int underflow[NF_INET_NUMHOOKS];
163
164
165 unsigned int num_entries;
166
167
168 unsigned int size;
169};
170
171
172struct ipt_replace
173{
174
175 char name[IPT_TABLE_MAXNAMELEN];
176
177
178
179 unsigned int valid_hooks;
180
181
182 unsigned int num_entries;
183
184
185 unsigned int size;
186
187
188 unsigned int hook_entry[NF_INET_NUMHOOKS];
189
190
191 unsigned int underflow[NF_INET_NUMHOOKS];
192
193
194
195 unsigned int num_counters;
196
197 struct xt_counters __user *counters;
198
199
200 struct ipt_entry entries[0];
201};
202
203
204#define ipt_counters_info xt_counters_info
205
206
207struct ipt_get_entries
208{
209
210 char name[IPT_TABLE_MAXNAMELEN];
211
212
213 unsigned int size;
214
215
216 struct ipt_entry entrytable[0];
217};
218
219
220#define IPT_STANDARD_TARGET XT_STANDARD_TARGET
221
222#define IPT_ERROR_TARGET XT_ERROR_TARGET
223
224
225static __inline__ struct ipt_entry_target *
226ipt_get_target(struct ipt_entry *e)
227{
228 return (void *)e + e->target_offset;
229}
230
231
232#define IPT_MATCH_ITERATE(e, fn, args...) \
233 XT_MATCH_ITERATE(struct ipt_entry, e, fn, ## args)
234
235
236#define IPT_ENTRY_ITERATE(entries, size, fn, args...) \
237 XT_ENTRY_ITERATE(struct ipt_entry, entries, size, fn, ## args)
238
239
240
241
242#ifdef __KERNEL__
243
244#include <linux/init.h>
245extern void ipt_init(void) __init;
246
247extern struct xt_table *ipt_register_table(struct net *net,
248 const struct xt_table *table,
249 const struct ipt_replace *repl);
250extern void ipt_unregister_table(struct xt_table *table);
251
252
253struct ipt_standard
254{
255 struct ipt_entry entry;
256 struct ipt_standard_target target;
257};
258
259struct ipt_error_target
260{
261 struct ipt_entry_target target;
262 char errorname[IPT_FUNCTION_MAXNAMELEN];
263};
264
265struct ipt_error
266{
267 struct ipt_entry entry;
268 struct ipt_error_target target;
269};
270
271#define IPT_ENTRY_INIT(__size) \
272{ \
273 .target_offset = sizeof(struct ipt_entry), \
274 .next_offset = (__size), \
275}
276
277#define IPT_STANDARD_INIT(__verdict) \
278{ \
279 .entry = IPT_ENTRY_INIT(sizeof(struct ipt_standard)), \
280 .target = XT_TARGET_INIT(IPT_STANDARD_TARGET, \
281 sizeof(struct xt_standard_target)), \
282 .target.verdict = -(__verdict) - 1, \
283}
284
285#define IPT_ERROR_INIT \
286{ \
287 .entry = IPT_ENTRY_INIT(sizeof(struct ipt_error)), \
288 .target = XT_TARGET_INIT(IPT_ERROR_TARGET, \
289 sizeof(struct ipt_error_target)), \
290 .target.errorname = "ERROR", \
291}
292
293extern unsigned int ipt_do_table(struct sk_buff *skb,
294 unsigned int hook,
295 const struct net_device *in,
296 const struct net_device *out,
297 struct xt_table *table);
298
299#define IPT_ALIGN(s) XT_ALIGN(s)
300
301#ifdef CONFIG_COMPAT
302#include <net/compat.h>
303
304struct compat_ipt_entry
305{
306 struct ipt_ip ip;
307 compat_uint_t nfcache;
308 u_int16_t target_offset;
309 u_int16_t next_offset;
310 compat_uint_t comefrom;
311 struct compat_xt_counters counters;
312 unsigned char elems[0];
313};
314
315
316static inline struct ipt_entry_target *
317compat_ipt_get_target(struct compat_ipt_entry *e)
318{
319 return (void *)e + e->target_offset;
320}
321
322#define COMPAT_IPT_ALIGN(s) COMPAT_XT_ALIGN(s)
323
324
325#define COMPAT_IPT_MATCH_ITERATE(e, fn, args...) \
326 XT_MATCH_ITERATE(struct compat_ipt_entry, e, fn, ## args)
327
328
329#define COMPAT_IPT_ENTRY_ITERATE(entries, size, fn, args...) \
330 XT_ENTRY_ITERATE(struct compat_ipt_entry, entries, size, fn, ## args)
331
332
333#define COMPAT_IPT_ENTRY_ITERATE_CONTINUE(entries, size, n, fn, args...) \
334 XT_ENTRY_ITERATE_CONTINUE(struct compat_ipt_entry, entries, size, n, \
335 fn, ## args)
336
337#endif
338#endif
339#endif
340