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