Merge branch 'fix/asoc' into for-linus
[pandora-kernel.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/in.h>
15 #include <linux/if_arp.h>
16 #include <linux/skbuff.h>
17 #endif
18 #include <linux/types.h>
19 #include <linux/compiler.h>
20 #include <linux/netfilter_arp.h>
21
22 #include <linux/netfilter/x_tables.h>
23
24 #define ARPT_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN
25 #define ARPT_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN
26
27 #define ARPT_DEV_ADDR_LEN_MAX 16
28
29 struct arpt_devaddr_info {
30         char addr[ARPT_DEV_ADDR_LEN_MAX];
31         char mask[ARPT_DEV_ADDR_LEN_MAX];
32 };
33
34 /* Yes, Virginia, you have to zero the padding. */
35 struct arpt_arp {
36         /* Source and target IP addr */
37         struct in_addr src, tgt;
38         /* Mask for src and target IP addr */
39         struct in_addr smsk, tmsk;
40
41         /* Device hw address length, src+target device addresses */
42         u_int8_t arhln, arhln_mask;
43         struct arpt_devaddr_info src_devaddr;
44         struct arpt_devaddr_info tgt_devaddr;
45
46         /* ARP operation code. */
47         __be16 arpop, arpop_mask;
48
49         /* ARP hardware address and protocol address format. */
50         __be16 arhrd, arhrd_mask;
51         __be16 arpro, arpro_mask;
52
53         /* The protocol address length is only accepted if it is 4
54          * so there is no use in offering a way to do filtering on it.
55          */
56
57         char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
58         unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
59
60         /* Flags word */
61         u_int8_t flags;
62         /* Inverse flags */
63         u_int16_t invflags;
64 };
65
66 #define arpt_entry_target xt_entry_target
67 #define arpt_standard_target xt_standard_target
68
69 /* Values for "flag" field in struct arpt_ip (general arp structure).
70  * No flags defined yet.
71  */
72 #define ARPT_F_MASK             0x00    /* All possible flag bits mask. */
73
74 /* Values for "inv" field in struct arpt_arp. */
75 #define ARPT_INV_VIA_IN         0x0001  /* Invert the sense of IN IFACE. */
76 #define ARPT_INV_VIA_OUT        0x0002  /* Invert the sense of OUT IFACE */
77 #define ARPT_INV_SRCIP          0x0004  /* Invert the sense of SRC IP. */
78 #define ARPT_INV_TGTIP          0x0008  /* Invert the sense of TGT IP. */
79 #define ARPT_INV_SRCDEVADDR     0x0010  /* Invert the sense of SRC DEV ADDR. */
80 #define ARPT_INV_TGTDEVADDR     0x0020  /* Invert the sense of TGT DEV ADDR. */
81 #define ARPT_INV_ARPOP          0x0040  /* Invert the sense of ARP OP. */
82 #define ARPT_INV_ARPHRD         0x0080  /* Invert the sense of ARP HRD. */
83 #define ARPT_INV_ARPPRO         0x0100  /* Invert the sense of ARP PRO. */
84 #define ARPT_INV_ARPHLN         0x0200  /* Invert the sense of ARP HLN. */
85 #define ARPT_INV_MASK           0x03FF  /* All possible flag bits mask. */
86
87 /* This structure defines each of the firewall rules.  Consists of 3
88    parts which are 1) general ARP header stuff 2) match specific
89    stuff 3) the target to perform if the rule matches */
90 struct arpt_entry
91 {
92         struct arpt_arp arp;
93
94         /* Size of arpt_entry + matches */
95         u_int16_t target_offset;
96         /* Size of arpt_entry + matches + target */
97         u_int16_t next_offset;
98
99         /* Back pointer */
100         unsigned int comefrom;
101
102         /* Packet and byte counters. */
103         struct xt_counters counters;
104
105         /* The matches (if any), then the target. */
106         unsigned char elems[0];
107 };
108
109 /*
110  * New IP firewall options for [gs]etsockopt at the RAW IP level.
111  * Unlike BSD Linux inherits IP options so you don't have to use a raw
112  * socket for this. Instead we check rights in the calls.
113  *
114  * ATTENTION: check linux/in.h before adding new number here.
115  */
116 #define ARPT_BASE_CTL           96
117
118 #define ARPT_SO_SET_REPLACE             (ARPT_BASE_CTL)
119 #define ARPT_SO_SET_ADD_COUNTERS        (ARPT_BASE_CTL + 1)
120 #define ARPT_SO_SET_MAX                 ARPT_SO_SET_ADD_COUNTERS
121
122 #define ARPT_SO_GET_INFO                (ARPT_BASE_CTL)
123 #define ARPT_SO_GET_ENTRIES             (ARPT_BASE_CTL + 1)
124 /* #define ARPT_SO_GET_REVISION_MATCH   (APRT_BASE_CTL + 2) */
125 #define ARPT_SO_GET_REVISION_TARGET     (ARPT_BASE_CTL + 3)
126 #define ARPT_SO_GET_MAX                 (ARPT_SO_GET_REVISION_TARGET)
127
128 /* CONTINUE verdict for targets */
129 #define ARPT_CONTINUE XT_CONTINUE
130
131 /* For standard target */
132 #define ARPT_RETURN XT_RETURN
133
134 /* The argument to ARPT_SO_GET_INFO */
135 struct arpt_getinfo {
136         /* Which table: caller fills this in. */
137         char name[ARPT_TABLE_MAXNAMELEN];
138
139         /* Kernel fills these in. */
140         /* Which hook entry points are valid: bitmask */
141         unsigned int valid_hooks;
142
143         /* Hook entry points: one per netfilter hook. */
144         unsigned int hook_entry[NF_ARP_NUMHOOKS];
145
146         /* Underflow points. */
147         unsigned int underflow[NF_ARP_NUMHOOKS];
148
149         /* Number of entries */
150         unsigned int num_entries;
151
152         /* Size of entries. */
153         unsigned int size;
154 };
155
156 /* The argument to ARPT_SO_SET_REPLACE. */
157 struct arpt_replace {
158         /* Which table. */
159         char name[ARPT_TABLE_MAXNAMELEN];
160
161         /* Which hook entry points are valid: bitmask.  You can't
162            change this. */
163         unsigned int valid_hooks;
164
165         /* Number of entries */
166         unsigned int num_entries;
167
168         /* Total size of new entries */
169         unsigned int size;
170
171         /* Hook entry points. */
172         unsigned int hook_entry[NF_ARP_NUMHOOKS];
173
174         /* Underflow points. */
175         unsigned int underflow[NF_ARP_NUMHOOKS];
176
177         /* Information about old entries: */
178         /* Number of counters (must be equal to current number of entries). */
179         unsigned int num_counters;
180         /* The old entries' counters. */
181         struct xt_counters __user *counters;
182
183         /* The entries (hang off end: not really an array). */
184         struct arpt_entry entries[0];
185 };
186
187 /* The argument to ARPT_SO_ADD_COUNTERS. */
188 #define arpt_counters_info xt_counters_info
189 #define arpt_counters xt_counters
190
191 /* The argument to ARPT_SO_GET_ENTRIES. */
192 struct arpt_get_entries {
193         /* Which table: user fills this in. */
194         char name[ARPT_TABLE_MAXNAMELEN];
195
196         /* User fills this in: total entry size. */
197         unsigned int size;
198
199         /* The entries. */
200         struct arpt_entry entrytable[0];
201 };
202
203 /* Standard return verdict, or do jump. */
204 #define ARPT_STANDARD_TARGET XT_STANDARD_TARGET
205 /* Error verdict. */
206 #define ARPT_ERROR_TARGET XT_ERROR_TARGET
207
208 /* Helper functions */
209 static __inline__ struct arpt_entry_target *arpt_get_target(struct arpt_entry *e)
210 {
211         return (void *)e + e->target_offset;
212 }
213
214 /* fn returns 0 to continue iteration */
215 #define ARPT_ENTRY_ITERATE(entries, size, fn, args...) \
216         XT_ENTRY_ITERATE(struct arpt_entry, entries, size, fn, ## args)
217
218 /*
219  *      Main firewall chains definitions and global var's definitions.
220  */
221 #ifdef __KERNEL__
222
223 /* Standard entry. */
224 struct arpt_standard {
225         struct arpt_entry entry;
226         struct arpt_standard_target target;
227 };
228
229 struct arpt_error_target {
230         struct arpt_entry_target target;
231         char errorname[ARPT_FUNCTION_MAXNAMELEN];
232 };
233
234 struct arpt_error {
235         struct arpt_entry entry;
236         struct arpt_error_target target;
237 };
238
239 #define ARPT_ENTRY_INIT(__size)                                                \
240 {                                                                              \
241         .target_offset  = sizeof(struct arpt_entry),                           \
242         .next_offset    = (__size),                                            \
243 }
244
245 #define ARPT_STANDARD_INIT(__verdict)                                          \
246 {                                                                              \
247         .entry          = ARPT_ENTRY_INIT(sizeof(struct arpt_standard)),       \
248         .target         = XT_TARGET_INIT(ARPT_STANDARD_TARGET,                 \
249                                          sizeof(struct arpt_standard_target)), \
250         .target.verdict = -(__verdict) - 1,                                    \
251 }
252
253 #define ARPT_ERROR_INIT                                                        \
254 {                                                                              \
255         .entry          = ARPT_ENTRY_INIT(sizeof(struct arpt_error)),          \
256         .target         = XT_TARGET_INIT(ARPT_ERROR_TARGET,                    \
257                                          sizeof(struct arpt_error_target)),    \
258         .target.errorname = "ERROR",                                           \
259 }
260
261 extern struct xt_table *arpt_register_table(struct net *net,
262                                             const struct xt_table *table,
263                                             const struct arpt_replace *repl);
264 extern void arpt_unregister_table(struct xt_table *table);
265 extern unsigned int arpt_do_table(struct sk_buff *skb,
266                                   unsigned int hook,
267                                   const struct net_device *in,
268                                   const struct net_device *out,
269                                   struct xt_table *table);
270
271 #define ARPT_ALIGN(s) XT_ALIGN(s)
272
273 #ifdef CONFIG_COMPAT
274 #include <net/compat.h>
275
276 struct compat_arpt_entry {
277         struct arpt_arp arp;
278         u_int16_t target_offset;
279         u_int16_t next_offset;
280         compat_uint_t comefrom;
281         struct compat_xt_counters counters;
282         unsigned char elems[0];
283 };
284
285 static inline struct arpt_entry_target *
286 compat_arpt_get_target(struct compat_arpt_entry *e)
287 {
288         return (void *)e + e->target_offset;
289 }
290
291 #define COMPAT_ARPT_ALIGN(s)    COMPAT_XT_ALIGN(s)
292
293 /* fn returns 0 to continue iteration */
294 #define COMPAT_ARPT_ENTRY_ITERATE(entries, size, fn, args...) \
295         XT_ENTRY_ITERATE(struct compat_arpt_entry, entries, size, fn, ## args)
296
297 #define COMPAT_ARPT_ENTRY_ITERATE_CONTINUE(entries, size, n, fn, args...) \
298         XT_ENTRY_ITERATE_CONTINUE(struct compat_arpt_entry, entries, size, n, \
299                                   fn, ## args)
300
301 #endif /* CONFIG_COMPAT */
302 #endif /*__KERNEL__*/
303 #endif /* _ARPTABLES_H */