Btrfs: don't walk around with task->state != TASK_RUNNING
[deliverable/linux.git] / include / linux / netfilter_arp / arp_tables.h
CommitLineData
1da177e4
LT
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>
1da177e4
LT
14#include <linux/in.h>
15#include <linux/if_arp.h>
16#include <linux/skbuff.h>
17#endif
c8942f1f 18#include <linux/types.h>
1da177e4
LT
19#include <linux/compiler.h>
20#include <linux/netfilter_arp.h>
21
2e4e6a17
HW
22#include <linux/netfilter/x_tables.h>
23
24#define ARPT_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN
25#define ARPT_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN
1da177e4
LT
26
27#define ARPT_DEV_ADDR_LEN_MAX 16
28
29struct 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. */
35struct 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. */
59b8bfd8 47 __be16 arpop, arpop_mask;
1da177e4
LT
48
49 /* ARP hardware address and protocol address format. */
59b8bfd8
AV
50 __be16 arhrd, arhrd_mask;
51 __be16 arpro, arpro_mask;
1da177e4
LT
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
1e30a014
DM
66#define arpt_entry_target xt_entry_target
67#define arpt_standard_target xt_standard_target
1da177e4 68
1da177e4
LT
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 */
90struct 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. */
2e4e6a17 103 struct xt_counters counters;
1da177e4
LT
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.
b96e7ecb
YK
113 *
114 * ATTENTION: check linux/in.h before adding new number here.
1da177e4 115 */
b96e7ecb
YK
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)
1da177e4
LT
127
128/* CONTINUE verdict for targets */
2e4e6a17 129#define ARPT_CONTINUE XT_CONTINUE
1da177e4
LT
130
131/* For standard target */
2e4e6a17 132#define ARPT_RETURN XT_RETURN
1da177e4
LT
133
134/* The argument to ARPT_SO_GET_INFO */
d94d9fee 135struct arpt_getinfo {
1da177e4
LT
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. */
d94d9fee 157struct arpt_replace {
1da177e4
LT
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. */
2e4e6a17 181 struct xt_counters __user *counters;
1da177e4
LT
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. */
2e4e6a17 188#define arpt_counters_info xt_counters_info
8c82d8df 189#define arpt_counters xt_counters
1da177e4
LT
190
191/* The argument to ARPT_SO_GET_ENTRIES. */
d94d9fee 192struct arpt_get_entries {
1da177e4
LT
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. */
2e4e6a17 204#define ARPT_STANDARD_TARGET XT_STANDARD_TARGET
1da177e4 205/* Error verdict. */
2e4e6a17 206#define ARPT_ERROR_TARGET XT_ERROR_TARGET
1da177e4
LT
207
208/* Helper functions */
209static __inline__ struct arpt_entry_target *arpt_get_target(struct arpt_entry *e)
210{
211 return (void *)e + e->target_offset;
212}
213
72b2b1dd 214#ifndef __KERNEL__
1da177e4 215/* fn returns 0 to continue iteration */
89c002d6
PM
216#define ARPT_ENTRY_ITERATE(entries, size, fn, args...) \
217 XT_ENTRY_ITERATE(struct arpt_entry, entries, size, fn, ## args)
72b2b1dd 218#endif
1da177e4
LT
219
220/*
221 * Main firewall chains definitions and global var's definitions.
222 */
223#ifdef __KERNEL__
224
3c2ad469 225/* Standard entry. */
d94d9fee 226struct arpt_standard {
3c2ad469
PM
227 struct arpt_entry entry;
228 struct arpt_standard_target target;
229};
230
d94d9fee 231struct arpt_error_target {
3c2ad469
PM
232 struct arpt_entry_target target;
233 char errorname[ARPT_FUNCTION_MAXNAMELEN];
234};
235
d94d9fee 236struct arpt_error {
3c2ad469
PM
237 struct arpt_entry entry;
238 struct arpt_error_target target;
239};
240
241#define ARPT_ENTRY_INIT(__size) \
242{ \
243 .target_offset = sizeof(struct arpt_entry), \
244 .next_offset = (__size), \
245}
246
247#define ARPT_STANDARD_INIT(__verdict) \
248{ \
249 .entry = ARPT_ENTRY_INIT(sizeof(struct arpt_standard)), \
250 .target = XT_TARGET_INIT(ARPT_STANDARD_TARGET, \
251 sizeof(struct arpt_standard_target)), \
252 .target.verdict = -(__verdict) - 1, \
253}
254
255#define ARPT_ERROR_INIT \
256{ \
257 .entry = ARPT_ENTRY_INIT(sizeof(struct arpt_error)), \
258 .target = XT_TARGET_INIT(ARPT_ERROR_TARGET, \
259 sizeof(struct arpt_error_target)), \
260 .target.errorname = "ERROR", \
261}
262
e3eaa991 263extern void *arpt_alloc_initial_table(const struct xt_table *);
4abff077 264extern struct xt_table *arpt_register_table(struct net *net,
35aad0ff 265 const struct xt_table *table,
4abff077
JE
266 const struct arpt_replace *repl);
267extern void arpt_unregister_table(struct xt_table *table);
3db05fea 268extern unsigned int arpt_do_table(struct sk_buff *skb,
1da177e4
LT
269 unsigned int hook,
270 const struct net_device *in,
271 const struct net_device *out,
4abff077 272 struct xt_table *table);
1da177e4 273
0495cf95 274#define ARPT_ALIGN(s) XT_ALIGN(s)
d6a2ba07
PM
275
276#ifdef CONFIG_COMPAT
277#include <net/compat.h>
278
d94d9fee 279struct compat_arpt_entry {
d6a2ba07
PM
280 struct arpt_arp arp;
281 u_int16_t target_offset;
282 u_int16_t next_offset;
283 compat_uint_t comefrom;
284 struct compat_xt_counters counters;
285 unsigned char elems[0];
286};
287
288static inline struct arpt_entry_target *
289compat_arpt_get_target(struct compat_arpt_entry *e)
290{
291 return (void *)e + e->target_offset;
292}
293
294#define COMPAT_ARPT_ALIGN(s) COMPAT_XT_ALIGN(s)
295
d6a2ba07 296#endif /* CONFIG_COMPAT */
1da177e4
LT
297#endif /*__KERNEL__*/
298#endif /* _ARPTABLES_H */
This page took 0.983385 seconds and 5 git commands to generate.