blob: bf71efb630075ff4ebeef529cffa32fcd66d8756 [file] [log] [blame]
Harald Welte2e4e6a12006-01-12 13:30:04 -08001#ifndef _X_TABLES_H
2#define _X_TABLES_H
3
4#define XT_FUNCTION_MAXNAMELEN 30
5#define XT_TABLE_MAXNAMELEN 32
6
7/* The argument to IPT_SO_GET_REVISION_*. Returns highest revision
8 * kernel supports, if >= revision. */
9struct xt_get_revision
10{
11 char name[XT_FUNCTION_MAXNAMELEN-1];
12
13 u_int8_t revision;
14};
15
16/* CONTINUE verdict for targets */
17#define XT_CONTINUE 0xFFFFFFFF
18
19/* For standard target */
20#define XT_RETURN (-NF_REPEAT - 1)
21
David S. Miller6fbfc962006-01-20 11:57:07 -080022/* this is a dummy structure to find out the alignment requirement for a struct
23 * containing all the fundamental data types that are used in ipt_entry,
24 * ip6t_entry and arpt_entry. This sucks, and it is a hack. It will be my
25 * personal pleasure to remove it -HW
26 */
27struct _xt_align
28{
29 u_int8_t u8;
30 u_int16_t u16;
31 u_int32_t u32;
32 u_int64_t u64;
33};
34
35#define XT_ALIGN(s) (((s) + (__alignof__(struct _xt_align)-1)) \
36 & ~(__alignof__(struct _xt_align)-1))
Harald Welte2e4e6a12006-01-12 13:30:04 -080037
38/* Standard return verdict, or do jump. */
39#define XT_STANDARD_TARGET ""
40/* Error verdict. */
41#define XT_ERROR_TARGET "ERROR"
42
43/*
44 * New IP firewall options for [gs]etsockopt at the RAW IP level.
45 * Unlike BSD Linux inherits IP options so you don't have to use a raw
46 * socket for this. Instead we check rights in the calls. */
47#define XT_BASE_CTL 64 /* base for firewall socket options */
48
49#define XT_SO_SET_REPLACE (XT_BASE_CTL)
50#define XT_SO_SET_ADD_COUNTERS (XT_BASE_CTL + 1)
51#define XT_SO_SET_MAX XT_SO_SET_ADD_COUNTERS
52
53#define XT_SO_GET_INFO (XT_BASE_CTL)
54#define XT_SO_GET_ENTRIES (XT_BASE_CTL + 1)
55#define XT_SO_GET_REVISION_MATCH (XT_BASE_CTL + 2)
56#define XT_SO_GET_REVISION_TARGET (XT_BASE_CTL + 3)
57#define XT_SO_GET_MAX XT_SO_GET_REVISION_TARGET
58
59#define SET_COUNTER(c,b,p) do { (c).bcnt = (b); (c).pcnt = (p); } while(0)
60#define ADD_COUNTER(c,b,p) do { (c).bcnt += (b); (c).pcnt += (p); } while(0)
61
62struct xt_counters
63{
64 u_int64_t pcnt, bcnt; /* Packet and byte counters */
65};
66
67/* The argument to IPT_SO_ADD_COUNTERS. */
68struct xt_counters_info
69{
70 /* Which table. */
71 char name[XT_TABLE_MAXNAMELEN];
72
73 unsigned int num_counters;
74
75 /* The counters (actually `number' of these). */
76 struct xt_counters counters[0];
77};
78
79#define XT_INV_PROTO 0x40 /* Invert the sense of PROTO. */
80
81#ifdef __KERNEL__
82
83#include <linux/netdevice.h>
84
85#define ASSERT_READ_LOCK(x)
86#define ASSERT_WRITE_LOCK(x)
87#include <linux/netfilter_ipv4/listhelp.h>
88
89struct xt_match
90{
91 struct list_head list;
92
93 const char name[XT_FUNCTION_MAXNAMELEN-1];
94
Harald Welte2e4e6a12006-01-12 13:30:04 -080095 /* Return true or false: return FALSE and set *hotdrop = 1 to
96 force immediate packet drop. */
97 /* Arguments changed since 2.6.9, as this must now handle
98 non-linear skb, using skb_header_pointer and
99 skb_ip_make_writable. */
100 int (*match)(const struct sk_buff *skb,
101 const struct net_device *in,
102 const struct net_device *out,
Patrick McHardy1c524832006-03-20 18:02:15 -0800103 const struct xt_match *match,
Harald Welte2e4e6a12006-01-12 13:30:04 -0800104 const void *matchinfo,
105 int offset,
106 unsigned int protoff,
107 int *hotdrop);
108
109 /* Called when user tries to insert an entry of this type. */
110 /* Should return true or false. */
111 int (*checkentry)(const char *tablename,
112 const void *ip,
Patrick McHardy1c524832006-03-20 18:02:15 -0800113 const struct xt_match *match,
Harald Welte2e4e6a12006-01-12 13:30:04 -0800114 void *matchinfo,
115 unsigned int matchinfosize,
116 unsigned int hook_mask);
117
118 /* Called when entry of this type deleted. */
Patrick McHardy1c524832006-03-20 18:02:15 -0800119 void (*destroy)(const struct xt_match *match, void *matchinfo,
120 unsigned int matchinfosize);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800121
122 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
123 struct module *me;
Patrick McHardy37f9f732006-03-20 17:59:06 -0800124
125 char *table;
126 unsigned int matchsize;
127 unsigned int hooks;
128 unsigned short proto;
Patrick McHardyc4b88512006-03-20 18:03:40 -0800129
130 unsigned short family;
Patrick McHardy37f9f732006-03-20 17:59:06 -0800131 u_int8_t revision;
Harald Welte2e4e6a12006-01-12 13:30:04 -0800132};
133
134/* Registration hooks for targets. */
135struct xt_target
136{
137 struct list_head list;
138
139 const char name[XT_FUNCTION_MAXNAMELEN-1];
140
Harald Welte2e4e6a12006-01-12 13:30:04 -0800141 /* Returns verdict. Argument order changed since 2.6.9, as this
142 must now handle non-linear skbs, using skb_copy_bits and
143 skb_ip_make_writable. */
144 unsigned int (*target)(struct sk_buff **pskb,
145 const struct net_device *in,
146 const struct net_device *out,
147 unsigned int hooknum,
Patrick McHardy1c524832006-03-20 18:02:15 -0800148 const struct xt_target *target,
Harald Welte2e4e6a12006-01-12 13:30:04 -0800149 const void *targinfo,
150 void *userdata);
151
152 /* Called when user tries to insert an entry of this type:
153 hook_mask is a bitmask of hooks from which it can be
154 called. */
155 /* Should return true or false. */
156 int (*checkentry)(const char *tablename,
157 const void *entry,
Patrick McHardy1c524832006-03-20 18:02:15 -0800158 const struct xt_target *target,
Harald Welte2e4e6a12006-01-12 13:30:04 -0800159 void *targinfo,
160 unsigned int targinfosize,
161 unsigned int hook_mask);
162
163 /* Called when entry of this type deleted. */
Patrick McHardy1c524832006-03-20 18:02:15 -0800164 void (*destroy)(const struct xt_target *target, void *targinfo,
165 unsigned int targinfosize);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800166
167 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
168 struct module *me;
Patrick McHardy37f9f732006-03-20 17:59:06 -0800169
170 char *table;
171 unsigned int targetsize;
172 unsigned int hooks;
173 unsigned short proto;
Patrick McHardyc4b88512006-03-20 18:03:40 -0800174
175 unsigned short family;
Patrick McHardy37f9f732006-03-20 17:59:06 -0800176 u_int8_t revision;
Harald Welte2e4e6a12006-01-12 13:30:04 -0800177};
178
179/* Furniture shopping... */
180struct xt_table
181{
182 struct list_head list;
183
184 /* A unique name... */
185 char name[XT_TABLE_MAXNAMELEN];
186
187 /* What hooks you will enter on */
188 unsigned int valid_hooks;
189
190 /* Lock for the curtain */
191 rwlock_t lock;
192
193 /* Man behind the curtain... */
194 //struct ip6t_table_info *private;
195 void *private;
196
197 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
198 struct module *me;
199
200 int af; /* address/protocol family */
201};
202
203#include <linux/netfilter_ipv4.h>
204
205/* The table itself */
206struct xt_table_info
207{
208 /* Size per table */
209 unsigned int size;
210 /* Number of entries: FIXME. --RR */
211 unsigned int number;
212 /* Initial number of entries. Needed for module usage count */
213 unsigned int initial_entries;
214
215 /* Entry points and underflows */
216 unsigned int hook_entry[NF_IP_NUMHOOKS];
217 unsigned int underflow[NF_IP_NUMHOOKS];
218
219 /* ipt_entry tables: one per CPU */
220 char *entries[NR_CPUS];
221};
222
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -0800223extern int xt_register_target(struct xt_target *target);
224extern void xt_unregister_target(struct xt_target *target);
225extern int xt_register_match(struct xt_match *target);
226extern void xt_unregister_match(struct xt_match *target);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800227
Patrick McHardy37f9f732006-03-20 17:59:06 -0800228extern int xt_check_match(const struct xt_match *match, unsigned short family,
229 unsigned int size, const char *table, unsigned int hook,
230 unsigned short proto, int inv_proto);
231extern int xt_check_target(const struct xt_target *target, unsigned short family,
232 unsigned int size, const char *table, unsigned int hook,
233 unsigned short proto, int inv_proto);
234
Harald Welte2e4e6a12006-01-12 13:30:04 -0800235extern int xt_register_table(struct xt_table *table,
236 struct xt_table_info *bootstrap,
237 struct xt_table_info *newinfo);
238extern void *xt_unregister_table(struct xt_table *table);
239
240extern struct xt_table_info *xt_replace_table(struct xt_table *table,
241 unsigned int num_counters,
242 struct xt_table_info *newinfo,
243 int *error);
244
245extern struct xt_match *xt_find_match(int af, const char *name, u8 revision);
246extern struct xt_target *xt_find_target(int af, const char *name, u8 revision);
247extern struct xt_target *xt_request_find_target(int af, const char *name,
248 u8 revision);
249extern int xt_find_revision(int af, const char *name, u8 revision, int target,
250 int *err);
251
252extern struct xt_table *xt_find_table_lock(int af, const char *name);
253extern void xt_table_unlock(struct xt_table *t);
254
255extern int xt_proto_init(int af);
256extern void xt_proto_fini(int af);
257
258extern struct xt_table_info *xt_alloc_table_info(unsigned int size);
259extern void xt_free_table_info(struct xt_table_info *info);
260
261#endif /* __KERNEL__ */
262
263#endif /* _X_TABLES_H */