]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - include/linux/netfilter_arp/arp_tables.h
Merge master.kernel.org:/pub/scm/linux/kernel/git/acme/net-2.6
[linux-2.6-omap-h63xx.git] / include / linux / netfilter_arp / arp_tables.h
1 /*
2  *      Format of an ARP firewall descriptor
3  *
4  *      src, tgt, src_mask, tgt_mask, arpop, arpop_mask are always stored in
5  *      network byte order.
6  *      flags are stored in host byte order (of course).
7  */
8
9 #ifndef _ARPTABLES_H
10 #define _ARPTABLES_H
11
12 #ifdef __KERNEL__
13 #include <linux/if.h>
14 #include <linux/types.h>
15 #include <linux/in.h>
16 #include <linux/if_arp.h>
17 #include <linux/skbuff.h>
18 #endif
19 #include <linux/compiler.h>
20 #include <linux/netfilter_arp.h>
21
22 #define ARPT_FUNCTION_MAXNAMELEN 30
23 #define ARPT_TABLE_MAXNAMELEN 32
24
25 #define ARPT_DEV_ADDR_LEN_MAX 16
26
27 struct arpt_devaddr_info {
28         char addr[ARPT_DEV_ADDR_LEN_MAX];
29         char mask[ARPT_DEV_ADDR_LEN_MAX];
30 };
31
32 /* Yes, Virginia, you have to zero the padding. */
33 struct arpt_arp {
34         /* Source and target IP addr */
35         struct in_addr src, tgt;
36         /* Mask for src and target IP addr */
37         struct in_addr smsk, tmsk;
38
39         /* Device hw address length, src+target device addresses */
40         u_int8_t arhln, arhln_mask;
41         struct arpt_devaddr_info src_devaddr;
42         struct arpt_devaddr_info tgt_devaddr;
43
44         /* ARP operation code. */
45         u_int16_t arpop, arpop_mask;
46
47         /* ARP hardware address and protocol address format. */
48         u_int16_t arhrd, arhrd_mask;
49         u_int16_t arpro, arpro_mask;
50
51         /* The protocol address length is only accepted if it is 4
52          * so there is no use in offering a way to do filtering on it.
53          */
54
55         char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
56         unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
57
58         /* Flags word */
59         u_int8_t flags;
60         /* Inverse flags */
61         u_int16_t invflags;
62 };
63
64 struct arpt_entry_target
65 {
66         union {
67                 struct {
68                         u_int16_t target_size;
69
70                         /* Used by userspace */
71                         char name[ARPT_FUNCTION_MAXNAMELEN-1];
72                         u_int8_t revision;
73                 } user;
74                 struct {
75                         u_int16_t target_size;
76
77                         /* Used inside the kernel */
78                         struct arpt_target *target;
79                 } kernel;
80
81                 /* Total length */
82                 u_int16_t target_size;
83         } u;
84
85         unsigned char data[0];
86 };
87
88 struct arpt_standard_target
89 {
90         struct arpt_entry_target target;
91         int verdict;
92 };
93
94 struct arpt_counters
95 {
96         u_int64_t pcnt, bcnt;                   /* Packet and byte counters */
97 };
98
99 /* Values for "flag" field in struct arpt_ip (general arp structure).
100  * No flags defined yet.
101  */
102 #define ARPT_F_MASK             0x00    /* All possible flag bits mask. */
103
104 /* Values for "inv" field in struct arpt_arp. */
105 #define ARPT_INV_VIA_IN         0x0001  /* Invert the sense of IN IFACE. */
106 #define ARPT_INV_VIA_OUT        0x0002  /* Invert the sense of OUT IFACE */
107 #define ARPT_INV_SRCIP          0x0004  /* Invert the sense of SRC IP. */
108 #define ARPT_INV_TGTIP          0x0008  /* Invert the sense of TGT IP. */
109 #define ARPT_INV_SRCDEVADDR     0x0010  /* Invert the sense of SRC DEV ADDR. */
110 #define ARPT_INV_TGTDEVADDR     0x0020  /* Invert the sense of TGT DEV ADDR. */
111 #define ARPT_INV_ARPOP          0x0040  /* Invert the sense of ARP OP. */
112 #define ARPT_INV_ARPHRD         0x0080  /* Invert the sense of ARP HRD. */
113 #define ARPT_INV_ARPPRO         0x0100  /* Invert the sense of ARP PRO. */
114 #define ARPT_INV_ARPHLN         0x0200  /* Invert the sense of ARP HLN. */
115 #define ARPT_INV_MASK           0x03FF  /* All possible flag bits mask. */
116
117 /* This structure defines each of the firewall rules.  Consists of 3
118    parts which are 1) general ARP header stuff 2) match specific
119    stuff 3) the target to perform if the rule matches */
120 struct arpt_entry
121 {
122         struct arpt_arp arp;
123
124         /* Size of arpt_entry + matches */
125         u_int16_t target_offset;
126         /* Size of arpt_entry + matches + target */
127         u_int16_t next_offset;
128
129         /* Back pointer */
130         unsigned int comefrom;
131
132         /* Packet and byte counters. */
133         struct arpt_counters counters;
134
135         /* The matches (if any), then the target. */
136         unsigned char elems[0];
137 };
138
139 /*
140  * New IP firewall options for [gs]etsockopt at the RAW IP level.
141  * Unlike BSD Linux inherits IP options so you don't have to use a raw
142  * socket for this. Instead we check rights in the calls.
143  */
144 #define ARPT_BASE_CTL           96      /* base for firewall socket options */
145
146 #define ARPT_SO_SET_REPLACE             (ARPT_BASE_CTL)
147 #define ARPT_SO_SET_ADD_COUNTERS        (ARPT_BASE_CTL + 1)
148 #define ARPT_SO_SET_MAX                 ARPT_SO_SET_ADD_COUNTERS
149
150 #define ARPT_SO_GET_INFO                (ARPT_BASE_CTL)
151 #define ARPT_SO_GET_ENTRIES             (ARPT_BASE_CTL + 1)
152 /* #define ARPT_SO_GET_REVISION_MATCH   (ARPT_BASE_CTL + 2)*/
153 #define ARPT_SO_GET_REVISION_TARGET     (ARPT_BASE_CTL + 3)
154 #define ARPT_SO_GET_MAX                 ARPT_SO_GET_REVISION_TARGET
155
156 /* CONTINUE verdict for targets */
157 #define ARPT_CONTINUE 0xFFFFFFFF
158
159 /* For standard target */
160 #define ARPT_RETURN (-NF_REPEAT - 1)
161
162 /* The argument to ARPT_SO_GET_INFO */
163 struct arpt_getinfo
164 {
165         /* Which table: caller fills this in. */
166         char name[ARPT_TABLE_MAXNAMELEN];
167
168         /* Kernel fills these in. */
169         /* Which hook entry points are valid: bitmask */
170         unsigned int valid_hooks;
171
172         /* Hook entry points: one per netfilter hook. */
173         unsigned int hook_entry[NF_ARP_NUMHOOKS];
174
175         /* Underflow points. */
176         unsigned int underflow[NF_ARP_NUMHOOKS];
177
178         /* Number of entries */
179         unsigned int num_entries;
180
181         /* Size of entries. */
182         unsigned int size;
183 };
184
185 /* The argument to ARPT_SO_SET_REPLACE. */
186 struct arpt_replace
187 {
188         /* Which table. */
189         char name[ARPT_TABLE_MAXNAMELEN];
190
191         /* Which hook entry points are valid: bitmask.  You can't
192            change this. */
193         unsigned int valid_hooks;
194
195         /* Number of entries */
196         unsigned int num_entries;
197
198         /* Total size of new entries */
199         unsigned int size;
200
201         /* Hook entry points. */
202         unsigned int hook_entry[NF_ARP_NUMHOOKS];
203
204         /* Underflow points. */
205         unsigned int underflow[NF_ARP_NUMHOOKS];
206
207         /* Information about old entries: */
208         /* Number of counters (must be equal to current number of entries). */
209         unsigned int num_counters;
210         /* The old entries' counters. */
211         struct arpt_counters __user *counters;
212
213         /* The entries (hang off end: not really an array). */
214         struct arpt_entry entries[0];
215 };
216
217 /* The argument to ARPT_SO_ADD_COUNTERS. */
218 struct arpt_counters_info
219 {
220         /* Which table. */
221         char name[ARPT_TABLE_MAXNAMELEN];
222
223         unsigned int num_counters;
224
225         /* The counters (actually `number' of these). */
226         struct arpt_counters counters[0];
227 };
228
229 /* The argument to ARPT_SO_GET_ENTRIES. */
230 struct arpt_get_entries
231 {
232         /* Which table: user fills this in. */
233         char name[ARPT_TABLE_MAXNAMELEN];
234
235         /* User fills this in: total entry size. */
236         unsigned int size;
237
238         /* The entries. */
239         struct arpt_entry entrytable[0];
240 };
241
242 /* The argument to ARPT_SO_GET_REVISION_*.  Returns highest revision
243  * kernel supports, if >= revision. */
244 struct arpt_get_revision
245 {
246         char name[ARPT_FUNCTION_MAXNAMELEN-1];
247
248         u_int8_t revision;
249 };
250
251 /* Standard return verdict, or do jump. */
252 #define ARPT_STANDARD_TARGET ""
253 /* Error verdict. */
254 #define ARPT_ERROR_TARGET "ERROR"
255
256 /* Helper functions */
257 static __inline__ struct arpt_entry_target *arpt_get_target(struct arpt_entry *e)
258 {
259         return (void *)e + e->target_offset;
260 }
261
262 /* fn returns 0 to continue iteration */
263 #define ARPT_ENTRY_ITERATE(entries, size, fn, args...)          \
264 ({                                                              \
265         unsigned int __i;                                       \
266         int __ret = 0;                                          \
267         struct arpt_entry *__entry;                             \
268                                                                 \
269         for (__i = 0; __i < (size); __i += __entry->next_offset) { \
270                 __entry = (void *)(entries) + __i;              \
271                                                                 \
272                 __ret = fn(__entry , ## args);                  \
273                 if (__ret != 0)                                 \
274                         break;                                  \
275         }                                                       \
276         __ret;                                                  \
277 })
278
279 /*
280  *      Main firewall chains definitions and global var's definitions.
281  */
282 #ifdef __KERNEL__
283
284 /* Registration hooks for targets. */
285 struct arpt_target
286 {
287         struct list_head list;
288
289         const char name[ARPT_FUNCTION_MAXNAMELEN-1];
290
291         u_int8_t revision;
292
293         /* Returns verdict. */
294         unsigned int (*target)(struct sk_buff **pskb,
295                                unsigned int hooknum,
296                                const struct net_device *in,
297                                const struct net_device *out,
298                                const void *targinfo,
299                                void *userdata);
300
301         /* Called when user tries to insert an entry of this type:
302            hook_mask is a bitmask of hooks from which it can be
303            called. */
304         /* Should return true or false. */
305         int (*checkentry)(const char *tablename,
306                           const struct arpt_entry *e,
307                           void *targinfo,
308                           unsigned int targinfosize,
309                           unsigned int hook_mask);
310
311         /* Called when entry of this type deleted. */
312         void (*destroy)(void *targinfo, unsigned int targinfosize);
313
314         /* Set this to THIS_MODULE if you are a module, otherwise NULL */
315         struct module *me;
316 };
317
318 extern int arpt_register_target(struct arpt_target *target);
319 extern void arpt_unregister_target(struct arpt_target *target);
320
321 /* Furniture shopping... */
322 struct arpt_table
323 {
324         struct list_head list;
325
326         /* A unique name... */
327         char name[ARPT_TABLE_MAXNAMELEN];
328
329         /* What hooks you will enter on */
330         unsigned int valid_hooks;
331
332         /* Lock for the curtain */
333         rwlock_t lock;
334
335         /* Man behind the curtain... */
336         struct arpt_table_info *private;
337
338         /* Set this to THIS_MODULE if you are a module, otherwise NULL */
339         struct module *me;
340 };
341
342 extern int arpt_register_table(struct arpt_table *table,
343                                const struct arpt_replace *repl);
344 extern void arpt_unregister_table(struct arpt_table *table);
345 extern unsigned int arpt_do_table(struct sk_buff **pskb,
346                                   unsigned int hook,
347                                   const struct net_device *in,
348                                   const struct net_device *out,
349                                   struct arpt_table *table,
350                                   void *userdata);
351
352 #define ARPT_ALIGN(s) (((s) + (__alignof__(struct arpt_entry)-1)) & ~(__alignof__(struct arpt_entry)-1))
353 #endif /*__KERNEL__*/
354 #endif /* _ARPTABLES_H */