blob: 584cd1b18f12db6b2ed8520e86343fe9949f7858 [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>
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
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
26#define arpt_target xt_target
27#define arpt_table xt_table
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29#define ARPT_DEV_ADDR_LEN_MAX 16
30
31struct arpt_devaddr_info {
32 char addr[ARPT_DEV_ADDR_LEN_MAX];
33 char mask[ARPT_DEV_ADDR_LEN_MAX];
34};
35
36/* Yes, Virginia, you have to zero the padding. */
37struct arpt_arp {
38 /* Source and target IP addr */
39 struct in_addr src, tgt;
40 /* Mask for src and target IP addr */
41 struct in_addr smsk, tmsk;
42
43 /* Device hw address length, src+target device addresses */
44 u_int8_t arhln, arhln_mask;
45 struct arpt_devaddr_info src_devaddr;
46 struct arpt_devaddr_info tgt_devaddr;
47
48 /* ARP operation code. */
Al Viro59b8bfd2006-09-28 14:21:07 -070049 __be16 arpop, arpop_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51 /* ARP hardware address and protocol address format. */
Al Viro59b8bfd2006-09-28 14:21:07 -070052 __be16 arhrd, arhrd_mask;
53 __be16 arpro, arpro_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55 /* The protocol address length is only accepted if it is 4
56 * so there is no use in offering a way to do filtering on it.
57 */
58
59 char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
60 unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
61
62 /* Flags word */
63 u_int8_t flags;
64 /* Inverse flags */
65 u_int16_t invflags;
66};
67
Dmitry Mishin1e30a012006-03-22 13:56:56 -080068#define arpt_entry_target xt_entry_target
69#define arpt_standard_target xt_standard_target
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/* Values for "flag" field in struct arpt_ip (general arp structure).
72 * No flags defined yet.
73 */
74#define ARPT_F_MASK 0x00 /* All possible flag bits mask. */
75
76/* Values for "inv" field in struct arpt_arp. */
77#define ARPT_INV_VIA_IN 0x0001 /* Invert the sense of IN IFACE. */
78#define ARPT_INV_VIA_OUT 0x0002 /* Invert the sense of OUT IFACE */
79#define ARPT_INV_SRCIP 0x0004 /* Invert the sense of SRC IP. */
80#define ARPT_INV_TGTIP 0x0008 /* Invert the sense of TGT IP. */
81#define ARPT_INV_SRCDEVADDR 0x0010 /* Invert the sense of SRC DEV ADDR. */
82#define ARPT_INV_TGTDEVADDR 0x0020 /* Invert the sense of TGT DEV ADDR. */
83#define ARPT_INV_ARPOP 0x0040 /* Invert the sense of ARP OP. */
84#define ARPT_INV_ARPHRD 0x0080 /* Invert the sense of ARP HRD. */
85#define ARPT_INV_ARPPRO 0x0100 /* Invert the sense of ARP PRO. */
86#define ARPT_INV_ARPHLN 0x0200 /* Invert the sense of ARP HLN. */
87#define ARPT_INV_MASK 0x03FF /* All possible flag bits mask. */
88
89/* This structure defines each of the firewall rules. Consists of 3
90 parts which are 1) general ARP header stuff 2) match specific
91 stuff 3) the target to perform if the rule matches */
92struct arpt_entry
93{
94 struct arpt_arp arp;
95
96 /* Size of arpt_entry + matches */
97 u_int16_t target_offset;
98 /* Size of arpt_entry + matches + target */
99 u_int16_t next_offset;
100
101 /* Back pointer */
102 unsigned int comefrom;
103
104 /* Packet and byte counters. */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800105 struct xt_counters counters;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107 /* The matches (if any), then the target. */
108 unsigned char elems[0];
109};
110
111/*
112 * New IP firewall options for [gs]etsockopt at the RAW IP level.
113 * Unlike BSD Linux inherits IP options so you don't have to use a raw
114 * socket for this. Instead we check rights in the calls.
Yasuyuki Kozakaib96e7ec2006-11-14 19:48:48 -0800115 *
116 * ATTENTION: check linux/in.h before adding new number here.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 */
Yasuyuki Kozakaib96e7ec2006-11-14 19:48:48 -0800118#define ARPT_BASE_CTL 96
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Yasuyuki Kozakaib96e7ec2006-11-14 19:48:48 -0800120#define ARPT_SO_SET_REPLACE (ARPT_BASE_CTL)
121#define ARPT_SO_SET_ADD_COUNTERS (ARPT_BASE_CTL + 1)
122#define ARPT_SO_SET_MAX ARPT_SO_SET_ADD_COUNTERS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Yasuyuki Kozakaib96e7ec2006-11-14 19:48:48 -0800124#define ARPT_SO_GET_INFO (ARPT_BASE_CTL)
125#define ARPT_SO_GET_ENTRIES (ARPT_BASE_CTL + 1)
126/* #define ARPT_SO_GET_REVISION_MATCH (APRT_BASE_CTL + 2) */
127#define ARPT_SO_GET_REVISION_TARGET (ARPT_BASE_CTL + 3)
128#define ARPT_SO_GET_MAX (ARPT_SO_GET_REVISION_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130/* CONTINUE verdict for targets */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800131#define ARPT_CONTINUE XT_CONTINUE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133/* For standard target */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800134#define ARPT_RETURN XT_RETURN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136/* The argument to ARPT_SO_GET_INFO */
137struct arpt_getinfo
138{
139 /* Which table: caller fills this in. */
140 char name[ARPT_TABLE_MAXNAMELEN];
141
142 /* Kernel fills these in. */
143 /* Which hook entry points are valid: bitmask */
144 unsigned int valid_hooks;
145
146 /* Hook entry points: one per netfilter hook. */
147 unsigned int hook_entry[NF_ARP_NUMHOOKS];
148
149 /* Underflow points. */
150 unsigned int underflow[NF_ARP_NUMHOOKS];
151
152 /* Number of entries */
153 unsigned int num_entries;
154
155 /* Size of entries. */
156 unsigned int size;
157};
158
159/* The argument to ARPT_SO_SET_REPLACE. */
160struct arpt_replace
161{
162 /* Which table. */
163 char name[ARPT_TABLE_MAXNAMELEN];
164
165 /* Which hook entry points are valid: bitmask. You can't
166 change this. */
167 unsigned int valid_hooks;
168
169 /* Number of entries */
170 unsigned int num_entries;
171
172 /* Total size of new entries */
173 unsigned int size;
174
175 /* Hook entry points. */
176 unsigned int hook_entry[NF_ARP_NUMHOOKS];
177
178 /* Underflow points. */
179 unsigned int underflow[NF_ARP_NUMHOOKS];
180
181 /* Information about old entries: */
182 /* Number of counters (must be equal to current number of entries). */
183 unsigned int num_counters;
184 /* The old entries' counters. */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800185 struct xt_counters __user *counters;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187 /* The entries (hang off end: not really an array). */
188 struct arpt_entry entries[0];
189};
190
191/* The argument to ARPT_SO_ADD_COUNTERS. */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800192#define arpt_counters_info xt_counters_info
Bart De Schuymer8c82d8d2007-01-09 14:33:11 -0800193#define arpt_counters xt_counters
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195/* The argument to ARPT_SO_GET_ENTRIES. */
196struct arpt_get_entries
197{
198 /* Which table: user fills this in. */
199 char name[ARPT_TABLE_MAXNAMELEN];
200
201 /* User fills this in: total entry size. */
202 unsigned int size;
203
204 /* The entries. */
205 struct arpt_entry entrytable[0];
206};
207
208/* Standard return verdict, or do jump. */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800209#define ARPT_STANDARD_TARGET XT_STANDARD_TARGET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210/* Error verdict. */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800211#define ARPT_ERROR_TARGET XT_ERROR_TARGET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213/* Helper functions */
214static __inline__ struct arpt_entry_target *arpt_get_target(struct arpt_entry *e)
215{
216 return (void *)e + e->target_offset;
217}
218
219/* fn returns 0 to continue iteration */
220#define ARPT_ENTRY_ITERATE(entries, size, fn, args...) \
221({ \
222 unsigned int __i; \
223 int __ret = 0; \
224 struct arpt_entry *__entry; \
225 \
226 for (__i = 0; __i < (size); __i += __entry->next_offset) { \
227 __entry = (void *)(entries) + __i; \
228 \
229 __ret = fn(__entry , ## args); \
230 if (__ret != 0) \
231 break; \
232 } \
233 __ret; \
234})
235
236/*
237 * Main firewall chains definitions and global var's definitions.
238 */
239#ifdef __KERNEL__
240
Patrick McHardy3c2ad462007-05-10 14:14:16 -0700241/* Standard entry. */
242struct arpt_standard
243{
244 struct arpt_entry entry;
245 struct arpt_standard_target target;
246};
247
248struct arpt_error_target
249{
250 struct arpt_entry_target target;
251 char errorname[ARPT_FUNCTION_MAXNAMELEN];
252};
253
254struct arpt_error
255{
256 struct arpt_entry entry;
257 struct arpt_error_target target;
258};
259
260#define ARPT_ENTRY_INIT(__size) \
261{ \
262 .target_offset = sizeof(struct arpt_entry), \
263 .next_offset = (__size), \
264}
265
266#define ARPT_STANDARD_INIT(__verdict) \
267{ \
268 .entry = ARPT_ENTRY_INIT(sizeof(struct arpt_standard)), \
269 .target = XT_TARGET_INIT(ARPT_STANDARD_TARGET, \
270 sizeof(struct arpt_standard_target)), \
271 .target.verdict = -(__verdict) - 1, \
272}
273
274#define ARPT_ERROR_INIT \
275{ \
276 .entry = ARPT_ENTRY_INIT(sizeof(struct arpt_error)), \
277 .target = XT_TARGET_INIT(ARPT_ERROR_TARGET, \
278 sizeof(struct arpt_error_target)), \
279 .target.errorname = "ERROR", \
280}
281
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -0800282#define arpt_register_target(tgt) \
283({ (tgt)->family = NF_ARP; \
284 xt_register_target(tgt); })
285#define arpt_unregister_target(tgt) xt_unregister_target(tgt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287extern int arpt_register_table(struct arpt_table *table,
288 const struct arpt_replace *repl);
289extern void arpt_unregister_table(struct arpt_table *table);
290extern unsigned int arpt_do_table(struct sk_buff **pskb,
291 unsigned int hook,
292 const struct net_device *in,
293 const struct net_device *out,
Patrick McHardyfe1cb102006-08-22 00:35:47 -0700294 struct arpt_table *table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296#define ARPT_ALIGN(s) (((s) + (__alignof__(struct arpt_entry)-1)) & ~(__alignof__(struct arpt_entry)-1))
297#endif /*__KERNEL__*/
298#endif /* _ARPTABLES_H */