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/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
22#define ARPT_FUNCTION_MAXNAMELEN 30
23#define ARPT_TABLE_MAXNAMELEN 32
24
25#define ARPT_DEV_ADDR_LEN_MAX 16
26
27struct arpt_devaddr_info {
28 char addr[ARPT_DEV_ADDR_LEN_MAX];
29 char mask[ARPT_DEV_ADDR_LEN_MAX];
30};
31
32
33struct arpt_arp {
34
35 struct in_addr src, tgt;
36
37 struct in_addr smsk, tmsk;
38
39
40 u_int8_t arhln, arhln_mask;
41 struct arpt_devaddr_info src_devaddr;
42 struct arpt_devaddr_info tgt_devaddr;
43
44
45 u_int16_t arpop, arpop_mask;
46
47
48 u_int16_t arhrd, arhrd_mask;
49 u_int16_t arpro, arpro_mask;
50
51
52
53
54
55 char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
56 unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
57
58
59 u_int8_t flags;
60
61 u_int16_t invflags;
62};
63
64struct arpt_entry_target
65{
66 union {
67 struct {
68 u_int16_t target_size;
69
70
71 char name[ARPT_FUNCTION_MAXNAMELEN];
72 } user;
73 struct {
74 u_int16_t target_size;
75
76
77 struct arpt_target *target;
78 } kernel;
79
80
81 u_int16_t target_size;
82 } u;
83
84 unsigned char data[0];
85};
86
87struct arpt_standard_target
88{
89 struct arpt_entry_target target;
90 int verdict;
91};
92
93struct arpt_counters
94{
95 u_int64_t pcnt, bcnt;
96};
97
98
99
100
101#define ARPT_F_MASK 0x00
102
103
104#define ARPT_INV_VIA_IN 0x0001
105#define ARPT_INV_VIA_OUT 0x0002
106#define ARPT_INV_SRCIP 0x0004
107#define ARPT_INV_TGTIP 0x0008
108#define ARPT_INV_SRCDEVADDR 0x0010
109#define ARPT_INV_TGTDEVADDR 0x0020
110#define ARPT_INV_ARPOP 0x0040
111#define ARPT_INV_ARPHRD 0x0080
112#define ARPT_INV_ARPPRO 0x0100
113#define ARPT_INV_ARPHLN 0x0200
114#define ARPT_INV_MASK 0x03FF
115
116
117
118
119struct arpt_entry
120{
121 struct arpt_arp arp;
122
123
124 u_int16_t target_offset;
125
126 u_int16_t next_offset;
127
128
129 unsigned int comefrom;
130
131
132 struct arpt_counters counters;
133
134
135 unsigned char elems[0];
136};
137
138
139
140
141
142
143#define ARPT_BASE_CTL 96
144
145#define ARPT_SO_SET_REPLACE (ARPT_BASE_CTL)
146#define ARPT_SO_SET_ADD_COUNTERS (ARPT_BASE_CTL + 1)
147#define ARPT_SO_SET_MAX ARPT_SO_SET_ADD_COUNTERS
148
149#define ARPT_SO_GET_INFO (ARPT_BASE_CTL)
150#define ARPT_SO_GET_ENTRIES (ARPT_BASE_CTL + 1)
151#define ARPT_SO_GET_MAX ARPT_SO_GET_ENTRIES
152
153
154#define ARPT_CONTINUE 0xFFFFFFFF
155
156
157#define ARPT_RETURN (-NF_MAX_VERDICT - 1)
158
159
160struct arpt_getinfo
161{
162
163 char name[ARPT_TABLE_MAXNAMELEN];
164
165
166
167 unsigned int valid_hooks;
168
169
170 unsigned int hook_entry[NF_ARP_NUMHOOKS];
171
172
173 unsigned int underflow[NF_ARP_NUMHOOKS];
174
175
176 unsigned int num_entries;
177
178
179 unsigned int size;
180};
181
182
183struct arpt_replace
184{
185
186 char name[ARPT_TABLE_MAXNAMELEN];
187
188
189
190 unsigned int valid_hooks;
191
192
193 unsigned int num_entries;
194
195
196 unsigned int size;
197
198
199 unsigned int hook_entry[NF_ARP_NUMHOOKS];
200
201
202 unsigned int underflow[NF_ARP_NUMHOOKS];
203
204
205
206 unsigned int num_counters;
207
208 struct arpt_counters __user *counters;
209
210
211 struct arpt_entry entries[0];
212};
213
214
215struct arpt_counters_info
216{
217
218 char name[ARPT_TABLE_MAXNAMELEN];
219
220 unsigned int num_counters;
221
222
223 struct arpt_counters counters[0];
224};
225
226
227struct arpt_get_entries
228{
229
230 char name[ARPT_TABLE_MAXNAMELEN];
231
232
233 unsigned int size;
234
235
236 struct arpt_entry entrytable[0];
237};
238
239
240#define ARPT_STANDARD_TARGET ""
241
242#define ARPT_ERROR_TARGET "ERROR"
243
244
245static __inline__ struct arpt_entry_target *arpt_get_target(struct arpt_entry *e)
246{
247 return (void *)e + e->target_offset;
248}
249
250
251#define ARPT_ENTRY_ITERATE(entries, size, fn, args...) \
252({ \
253 unsigned int __i; \
254 int __ret = 0; \
255 struct arpt_entry *__entry; \
256 \
257 for (__i = 0; __i < (size); __i += __entry->next_offset) { \
258 __entry = (void *)(entries) + __i; \
259 \
260 __ret = fn(__entry , ## args); \
261 if (__ret != 0) \
262 break; \
263 } \
264 __ret; \
265})
266
267
268
269
270#ifdef __KERNEL__
271
272
273struct arpt_target
274{
275 struct list_head list;
276
277 const char name[ARPT_FUNCTION_MAXNAMELEN];
278
279
280 unsigned int (*target)(struct sk_buff **pskb,
281 unsigned int hooknum,
282 const struct net_device *in,
283 const struct net_device *out,
284 const void *targinfo,
285 void *userdata);
286
287
288
289
290
291 int (*checkentry)(const char *tablename,
292 const struct arpt_entry *e,
293 void *targinfo,
294 unsigned int targinfosize,
295 unsigned int hook_mask);
296
297
298 void (*destroy)(void *targinfo, unsigned int targinfosize);
299
300
301 struct module *me;
302};
303
304extern int arpt_register_target(struct arpt_target *target);
305extern void arpt_unregister_target(struct arpt_target *target);
306
307
308struct arpt_table
309{
310 struct list_head list;
311
312
313 char name[ARPT_TABLE_MAXNAMELEN];
314
315
316 struct arpt_replace *table;
317
318
319 unsigned int valid_hooks;
320
321
322 rwlock_t lock;
323
324
325 struct arpt_table_info *private;
326
327
328 struct module *me;
329};
330
331extern int arpt_register_table(struct arpt_table *table);
332extern void arpt_unregister_table(struct arpt_table *table);
333extern unsigned int arpt_do_table(struct sk_buff **pskb,
334 unsigned int hook,
335 const struct net_device *in,
336 const struct net_device *out,
337 struct arpt_table *table,
338 void *userdata);
339
340#define ARPT_ALIGN(s) (((s) + (__alignof__(struct arpt_entry)-1)) & ~(__alignof__(struct arpt_entry)-1))
341#endif
342#endif
343