blob: 590ac3d6d5d67e349b28a146be534d14cefa29c3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/in.h>
15#include <linux/if_arp.h>
16#include <linux/skbuff.h>
17#endif
Patrick McHardyc8942f12008-05-21 14:08:38 -070018#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/compiler.h>
20#include <linux/netfilter_arp.h>
21
Harald Welte2e4e6a12006-01-12 13:30:04 -080022#include <linux/netfilter/x_tables.h>
23
24#define ARPT_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN
25#define ARPT_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
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. */
Al Viro59b8bfd2006-09-28 14:21:07 -070047 __be16 arpop, arpop_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49 /* ARP hardware address and protocol address format. */
Al Viro59b8bfd2006-09-28 14:21:07 -070050 __be16 arhrd, arhrd_mask;
51 __be16 arpro, arpro_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
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
Dmitry Mishin1e30a012006-03-22 13:56:56 -080066#define arpt_entry_target xt_entry_target
67#define arpt_standard_target xt_standard_target
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Linus Torvalds1da177e2005-04-16 15:20:36 -070069/* 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. */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800103 struct xt_counters counters;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
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.
Yasuyuki Kozakaib96e7ec2006-11-14 19:48:48 -0800113 *
114 * ATTENTION: check linux/in.h before adding new number here.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 */
Yasuyuki Kozakaib96e7ec2006-11-14 19:48:48 -0800116#define ARPT_BASE_CTL 96
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Yasuyuki Kozakaib96e7ec2006-11-14 19:48:48 -0800118#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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Yasuyuki Kozakaib96e7ec2006-11-14 19:48:48 -0800122#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)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128/* CONTINUE verdict for targets */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800129#define ARPT_CONTINUE XT_CONTINUE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131/* For standard target */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800132#define ARPT_RETURN XT_RETURN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134/* The argument to ARPT_SO_GET_INFO */
135struct arpt_getinfo
136{
137 /* Which table: caller fills this in. */
138 char name[ARPT_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. */
158struct arpt_replace
159{
160 /* Which table. */
161 char name[ARPT_TABLE_MAXNAMELEN];
162
163 /* Which hook entry points are valid: bitmask. You can't
164 change this. */
165 unsigned int valid_hooks;
166
167 /* Number of entries */
168 unsigned int num_entries;
169
170 /* Total size of new entries */
171 unsigned int size;
172
173 /* Hook entry points. */
174 unsigned int hook_entry[NF_ARP_NUMHOOKS];
175
176 /* Underflow points. */
177 unsigned int underflow[NF_ARP_NUMHOOKS];
178
179 /* Information about old entries: */
180 /* Number of counters (must be equal to current number of entries). */
181 unsigned int num_counters;
182 /* The old entries' counters. */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800183 struct xt_counters __user *counters;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 /* The entries (hang off end: not really an array). */
186 struct arpt_entry entries[0];
187};
188
189/* The argument to ARPT_SO_ADD_COUNTERS. */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800190#define arpt_counters_info xt_counters_info
Bart De Schuymer8c82d8d2007-01-09 14:33:11 -0800191#define arpt_counters xt_counters
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193/* The argument to ARPT_SO_GET_ENTRIES. */
194struct arpt_get_entries
195{
196 /* Which table: user fills this in. */
197 char name[ARPT_TABLE_MAXNAMELEN];
198
199 /* User fills this in: total entry size. */
200 unsigned int size;
201
202 /* The entries. */
203 struct arpt_entry entrytable[0];
204};
205
206/* Standard return verdict, or do jump. */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800207#define ARPT_STANDARD_TARGET XT_STANDARD_TARGET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208/* Error verdict. */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800209#define ARPT_ERROR_TARGET XT_ERROR_TARGET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211/* Helper functions */
212static __inline__ struct arpt_entry_target *arpt_get_target(struct arpt_entry *e)
213{
214 return (void *)e + e->target_offset;
215}
216
217/* fn returns 0 to continue iteration */
Patrick McHardy89c002d2007-12-17 21:46:59 -0800218#define ARPT_ENTRY_ITERATE(entries, size, fn, args...) \
219 XT_ENTRY_ITERATE(struct arpt_entry, entries, size, fn, ## args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221/*
222 * Main firewall chains definitions and global var's definitions.
223 */
224#ifdef __KERNEL__
225
Patrick McHardy3c2ad462007-05-10 14:14:16 -0700226/* Standard entry. */
227struct arpt_standard
228{
229 struct arpt_entry entry;
230 struct arpt_standard_target target;
231};
232
233struct arpt_error_target
234{
235 struct arpt_entry_target target;
236 char errorname[ARPT_FUNCTION_MAXNAMELEN];
237};
238
239struct arpt_error
240{
241 struct arpt_entry entry;
242 struct arpt_error_target target;
243};
244
245#define ARPT_ENTRY_INIT(__size) \
246{ \
247 .target_offset = sizeof(struct arpt_entry), \
248 .next_offset = (__size), \
249}
250
251#define ARPT_STANDARD_INIT(__verdict) \
252{ \
253 .entry = ARPT_ENTRY_INIT(sizeof(struct arpt_standard)), \
254 .target = XT_TARGET_INIT(ARPT_STANDARD_TARGET, \
255 sizeof(struct arpt_standard_target)), \
256 .target.verdict = -(__verdict) - 1, \
257}
258
259#define ARPT_ERROR_INIT \
260{ \
261 .entry = ARPT_ENTRY_INIT(sizeof(struct arpt_error)), \
262 .target = XT_TARGET_INIT(ARPT_ERROR_TARGET, \
263 sizeof(struct arpt_error_target)), \
264 .target.errorname = "ERROR", \
265}
266
Jan Engelhardt4abff072008-04-14 11:15:43 +0200267extern struct xt_table *arpt_register_table(struct net *net,
268 struct xt_table *table,
269 const struct arpt_replace *repl);
270extern void arpt_unregister_table(struct xt_table *table);
Herbert Xu3db05fe2007-10-15 00:53:15 -0700271extern unsigned int arpt_do_table(struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 unsigned int hook,
273 const struct net_device *in,
274 const struct net_device *out,
Jan Engelhardt4abff072008-04-14 11:15:43 +0200275 struct xt_table *table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Patrick McHardy0495cf92007-12-17 21:55:34 -0800277#define ARPT_ALIGN(s) XT_ALIGN(s)
Patrick McHardyd6a2ba02007-12-17 22:26:54 -0800278
279#ifdef CONFIG_COMPAT
280#include <net/compat.h>
281
282struct compat_arpt_entry
283{
284 struct arpt_arp arp;
285 u_int16_t target_offset;
286 u_int16_t next_offset;
287 compat_uint_t comefrom;
288 struct compat_xt_counters counters;
289 unsigned char elems[0];
290};
291
292static inline struct arpt_entry_target *
293compat_arpt_get_target(struct compat_arpt_entry *e)
294{
295 return (void *)e + e->target_offset;
296}
297
298#define COMPAT_ARPT_ALIGN(s) COMPAT_XT_ALIGN(s)
299
300/* fn returns 0 to continue iteration */
301#define COMPAT_ARPT_ENTRY_ITERATE(entries, size, fn, args...) \
302 XT_ENTRY_ITERATE(struct compat_arpt_entry, entries, size, fn, ## args)
303
304#define COMPAT_ARPT_ENTRY_ITERATE_CONTINUE(entries, size, n, fn, args...) \
305 XT_ENTRY_ITERATE_CONTINUE(struct compat_arpt_entry, entries, size, n, \
306 fn, ## args)
307
308#endif /* CONFIG_COMPAT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309#endif /*__KERNEL__*/
310#endif /* _ARPTABLES_H */