1
2
3
4
5
6
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
29struct arpt_devaddr_info {
30 char addr[ARPT_DEV_ADDR_LEN_MAX];
31 char mask[ARPT_DEV_ADDR_LEN_MAX];
32};
33
34
35struct arpt_arp {
36
37 struct in_addr src, tgt;
38
39 struct in_addr smsk, tmsk;
40
41
42 u_int8_t arhln, arhln_mask;
43 struct arpt_devaddr_info src_devaddr;
44 struct arpt_devaddr_info tgt_devaddr;
45
46
47 __be16 arpop, arpop_mask;
48
49
50 __be16 arhrd, arhrd_mask;
51 __be16 arpro, arpro_mask;
52
53
54
55
56
57 char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
58 unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
59
60
61 u_int8_t flags;
62
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
70
71
72#define ARPT_F_MASK 0x00
73
74
75#define ARPT_INV_VIA_IN 0x0001
76#define ARPT_INV_VIA_OUT 0x0002
77#define ARPT_INV_SRCIP 0x0004
78#define ARPT_INV_TGTIP 0x0008
79#define ARPT_INV_SRCDEVADDR 0x0010
80#define ARPT_INV_TGTDEVADDR 0x0020
81#define ARPT_INV_ARPOP 0x0040
82#define ARPT_INV_ARPHRD 0x0080
83#define ARPT_INV_ARPPRO 0x0100
84#define ARPT_INV_ARPHLN 0x0200
85#define ARPT_INV_MASK 0x03FF
86
87
88
89
90struct arpt_entry
91{
92 struct arpt_arp arp;
93
94
95 u_int16_t target_offset;
96
97 u_int16_t next_offset;
98
99
100 unsigned int comefrom;
101
102
103 struct xt_counters counters;
104
105
106 unsigned char elems[0];
107};
108
109
110
111
112
113
114
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
125#define ARPT_SO_GET_REVISION_TARGET (ARPT_BASE_CTL + 3)
126#define ARPT_SO_GET_MAX (ARPT_SO_GET_REVISION_TARGET)
127
128
129#define ARPT_CONTINUE XT_CONTINUE
130
131
132#define ARPT_RETURN XT_RETURN
133
134
135struct arpt_getinfo
136{
137
138 char name[ARPT_TABLE_MAXNAMELEN];
139
140
141
142 unsigned int valid_hooks;
143
144
145 unsigned int hook_entry[NF_ARP_NUMHOOKS];
146
147
148 unsigned int underflow[NF_ARP_NUMHOOKS];
149
150
151 unsigned int num_entries;
152
153
154 unsigned int size;
155};
156
157
158struct arpt_replace
159{
160
161 char name[ARPT_TABLE_MAXNAMELEN];
162
163
164
165 unsigned int valid_hooks;
166
167
168 unsigned int num_entries;
169
170
171 unsigned int size;
172
173
174 unsigned int hook_entry[NF_ARP_NUMHOOKS];
175
176
177 unsigned int underflow[NF_ARP_NUMHOOKS];
178
179
180
181 unsigned int num_counters;
182
183 struct xt_counters __user *counters;
184
185
186 struct arpt_entry entries[0];
187};
188
189
190#define arpt_counters_info xt_counters_info
191#define arpt_counters xt_counters
192
193
194struct arpt_get_entries
195{
196
197 char name[ARPT_TABLE_MAXNAMELEN];
198
199
200 unsigned int size;
201
202
203 struct arpt_entry entrytable[0];
204};
205
206
207#define ARPT_STANDARD_TARGET XT_STANDARD_TARGET
208
209#define ARPT_ERROR_TARGET XT_ERROR_TARGET
210
211
212static __inline__ struct arpt_entry_target *arpt_get_target(struct arpt_entry *e)
213{
214 return (void *)e + e->target_offset;
215}
216
217
218#define ARPT_ENTRY_ITERATE(entries, size, fn, args...) \
219 XT_ENTRY_ITERATE(struct arpt_entry, entries, size, fn, ## args)
220
221
222
223
224#ifdef __KERNEL__
225
226
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
267extern struct xt_table *arpt_register_table(struct net *net,
268 const struct xt_table *table,
269 const struct arpt_replace *repl);
270extern void arpt_unregister_table(struct xt_table *table);
271extern unsigned int arpt_do_table(struct sk_buff *skb,
272 unsigned int hook,
273 const struct net_device *in,
274 const struct net_device *out,
275 struct xt_table *table);
276
277#define ARPT_ALIGN(s) XT_ALIGN(s)
278
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
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
309#endif
310#endif
311