5
* Bart De Schuymer <bdschuym@pandora.be>
7
* ebtables.c,v 2.0, April, 2002
9
* This code is stongly inspired on the iptables code which is
10
* Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
13
#ifndef __LINUX_BRIDGE_EFF_H
14
#define __LINUX_BRIDGE_EFF_H
16
#include <linux/netfilter_bridge.h>
17
#include <linux/if_ether.h>
19
#define EBT_TABLE_MAXNAMELEN 32
20
#define EBT_CHAIN_MAXNAMELEN EBT_TABLE_MAXNAMELEN
21
#define EBT_FUNCTION_MAXNAMELEN EBT_TABLE_MAXNAMELEN
23
/* verdicts >0 are "branches" */
26
#define EBT_CONTINUE -3
28
#define NUM_STANDARD_TARGETS 4
29
/* ebtables target modules store the verdict inside an int. We can
30
* reclaim a part of this int for backwards compatible extensions.
31
* The 4 lsb are more than enough to store the verdict. */
32
#define EBT_VERDICT_BITS 0x0000000F
42
char name[EBT_TABLE_MAXNAMELEN];
43
unsigned int valid_hooks;
44
/* nr of rules in the table */
45
unsigned int nentries;
46
/* total size of the entries */
47
unsigned int entries_size;
48
/* start of the chains */
49
struct ebt_entries __user *hook_entry[NF_BR_NUMHOOKS];
50
/* nr of counters userspace expects back */
51
unsigned int num_counters;
52
/* where the kernel will put the old counters */
53
struct ebt_counter __user *counters;
57
struct ebt_replace_kernel
59
char name[EBT_TABLE_MAXNAMELEN];
60
unsigned int valid_hooks;
61
/* nr of rules in the table */
62
unsigned int nentries;
63
/* total size of the entries */
64
unsigned int entries_size;
65
/* start of the chains */
66
struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
67
/* nr of counters userspace expects back */
68
unsigned int num_counters;
69
/* where the kernel will put the old counters */
70
struct ebt_counter *counters;
75
/* this field is always set to zero
76
* See EBT_ENTRY_OR_ENTRIES.
77
* Must be same size as ebt_entry.bitmask */
78
unsigned int distinguisher;
80
char name[EBT_CHAIN_MAXNAMELEN];
81
/* counter offset for this chain */
82
unsigned int counter_offset;
83
/* one standard (accept, drop, return) per hook */
86
unsigned int nentries;
88
char data[0] __attribute__ ((aligned (__alignof__(struct ebt_replace))));
91
/* used for the bitmask of struct ebt_entry */
93
/* This is a hack to make a difference between an ebt_entry struct and an
94
* ebt_entries struct when traversing the entries from start to end.
95
* Using this simplifies the code alot, while still being able to use
97
* Contrary, iptables doesn't use something like ebt_entries and therefore uses
98
* different techniques for naming the policy and such. So, iptables doesn't
99
* need a hack like this.
101
#define EBT_ENTRY_OR_ENTRIES 0x01
102
/* these are the normal masks */
103
#define EBT_NOPROTO 0x02
104
#define EBT_802_3 0x04
105
#define EBT_SOURCEMAC 0x08
106
#define EBT_DESTMAC 0x10
107
#define EBT_F_MASK (EBT_NOPROTO | EBT_802_3 | EBT_SOURCEMAC | EBT_DESTMAC \
108
| EBT_ENTRY_OR_ENTRIES)
110
#define EBT_IPROTO 0x01
112
#define EBT_IOUT 0x04
113
#define EBT_ISOURCE 0x8
114
#define EBT_IDEST 0x10
115
#define EBT_ILOGICALIN 0x20
116
#define EBT_ILOGICALOUT 0x40
117
#define EBT_INV_MASK (EBT_IPROTO | EBT_IIN | EBT_IOUT | EBT_ILOGICALIN \
118
| EBT_ILOGICALOUT | EBT_ISOURCE | EBT_IDEST)
120
struct ebt_entry_match
123
char name[EBT_FUNCTION_MAXNAMELEN];
124
struct ebt_match *match;
127
unsigned int match_size;
128
unsigned char data[0] __attribute__ ((aligned (__alignof__(struct ebt_replace))));
131
struct ebt_entry_watcher
134
char name[EBT_FUNCTION_MAXNAMELEN];
135
struct ebt_watcher *watcher;
138
unsigned int watcher_size;
139
unsigned char data[0] __attribute__ ((aligned (__alignof__(struct ebt_replace))));
142
struct ebt_entry_target
145
char name[EBT_FUNCTION_MAXNAMELEN];
146
struct ebt_target *target;
149
unsigned int target_size;
150
unsigned char data[0] __attribute__ ((aligned (__alignof__(struct ebt_replace))));
153
#define EBT_STANDARD_TARGET "standard"
154
struct ebt_standard_target
156
struct ebt_entry_target target;
162
/* this needs to be the first field */
163
unsigned int bitmask;
164
unsigned int invflags;
166
/* the physical in-dev */
168
/* the logical in-dev */
169
char logical_in[IFNAMSIZ];
170
/* the physical out-dev */
172
/* the logical out-dev */
173
char logical_out[IFNAMSIZ];
174
unsigned char sourcemac[ETH_ALEN];
175
unsigned char sourcemsk[ETH_ALEN];
176
unsigned char destmac[ETH_ALEN];
177
unsigned char destmsk[ETH_ALEN];
178
/* sizeof ebt_entry + matches */
179
unsigned int watchers_offset;
180
/* sizeof ebt_entry + matches + watchers */
181
unsigned int target_offset;
182
/* sizeof ebt_entry + matches + watchers + target */
183
unsigned int next_offset;
184
unsigned char elems[0] __attribute__ ((aligned (__alignof__(struct ebt_replace))));
187
/* {g,s}etsockopt numbers */
188
#define EBT_BASE_CTL 128
190
#define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
191
#define EBT_SO_SET_COUNTERS (EBT_SO_SET_ENTRIES+1)
192
#define EBT_SO_SET_MAX (EBT_SO_SET_COUNTERS+1)
194
#define EBT_SO_GET_INFO (EBT_BASE_CTL)
195
#define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO+1)
196
#define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES+1)
197
#define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO+1)
198
#define EBT_SO_GET_MAX (EBT_SO_GET_INIT_ENTRIES+1)
202
/* return values for match() functions */
204
#define EBT_NOMATCH 1
208
struct list_head list;
209
const char name[EBT_FUNCTION_MAXNAMELEN];
210
/* 0 == it matches */
211
int (*match)(const struct sk_buff *skb, const struct net_device *in,
212
const struct net_device *out, const void *matchdata,
213
unsigned int datalen);
215
int (*check)(const char *tablename, unsigned int hookmask,
216
const struct ebt_entry *e, void *matchdata, unsigned int datalen);
217
void (*destroy)(void *matchdata, unsigned int datalen);
223
struct list_head list;
224
const char name[EBT_FUNCTION_MAXNAMELEN];
225
void (*watcher)(const struct sk_buff *skb, unsigned int hooknr,
226
const struct net_device *in, const struct net_device *out,
227
const void *watcherdata, unsigned int datalen);
229
int (*check)(const char *tablename, unsigned int hookmask,
230
const struct ebt_entry *e, void *watcherdata, unsigned int datalen);
231
void (*destroy)(void *watcherdata, unsigned int datalen);
237
struct list_head list;
238
const char name[EBT_FUNCTION_MAXNAMELEN];
239
/* returns one of the standard verdicts */
240
int (*target)(struct sk_buff **pskb, unsigned int hooknr,
241
const struct net_device *in, const struct net_device *out,
242
const void *targetdata, unsigned int datalen);
244
int (*check)(const char *tablename, unsigned int hookmask,
245
const struct ebt_entry *e, void *targetdata, unsigned int datalen);
246
void (*destroy)(void *targetdata, unsigned int datalen);
250
/* used for jumping from and into user defined chains (udc) */
251
struct ebt_chainstack
253
struct ebt_entries *chaininfo; /* pointer to chain data */
254
struct ebt_entry *e; /* pointer to entry data */
255
unsigned int n; /* n'th entry */
258
struct ebt_table_info
260
/* total size of the entries */
261
unsigned int entries_size;
262
unsigned int nentries;
263
/* pointers to the start of the chains */
264
struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
265
/* room to maintain the stack used for jumping from and into udc */
266
struct ebt_chainstack **chainstack;
268
struct ebt_counter counters[0] ____cacheline_aligned;
273
struct list_head list;
274
char name[EBT_TABLE_MAXNAMELEN];
275
struct ebt_replace_kernel *table;
276
unsigned int valid_hooks;
278
/* e.g. could be the table explicitly only allows certain
279
* matches, targets, ... 0 == let it in */
280
int (*check)(const struct ebt_table_info *info,
281
unsigned int valid_hooks);
282
/* the data used by the kernel */
283
struct ebt_table_info *private;
287
#define EBT_ALIGN(s) (((s) + (__alignof__(struct ebt_replace)-1)) & \
288
~(__alignof__(struct ebt_replace)-1))
289
extern int ebt_register_table(struct ebt_table *table);
290
extern void ebt_unregister_table(struct ebt_table *table);
291
extern int ebt_register_match(struct ebt_match *match);
292
extern void ebt_unregister_match(struct ebt_match *match);
293
extern int ebt_register_watcher(struct ebt_watcher *watcher);
294
extern void ebt_unregister_watcher(struct ebt_watcher *watcher);
295
extern int ebt_register_target(struct ebt_target *target);
296
extern void ebt_unregister_target(struct ebt_target *target);
297
extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff **pskb,
298
const struct net_device *in, const struct net_device *out,
299
struct ebt_table *table);
301
/* Used in the kernel match() functions */
302
#define FWINV(bool,invflg) ((bool) ^ !!(info->invflags & invflg))
303
/* True if the hook mask denotes that the rule is in a base chain,
304
* used in the check() functions */
305
#define BASE_CHAIN (hookmask & (1 << NF_BR_NUMHOOKS))
306
/* Clear the bit in the hook mask that tells if the rule is on a base chain */
307
#define CLEAR_BASE_CHAIN_BIT (hookmask &= ~(1 << NF_BR_NUMHOOKS))
308
/* True if the target is not a standard target */
309
#define INVALID_TARGET (info->target < -NUM_STANDARD_TARGETS || info->target >= 0)
311
#endif /* __KERNEL__ */
313
/* blatently stolen from ip_tables.h
314
* fn returns 0 to continue iteration */
315
#define EBT_MATCH_ITERATE(e, fn, args...) \
319
struct ebt_entry_match *__match; \
321
for (__i = sizeof(struct ebt_entry); \
322
__i < (e)->watchers_offset; \
323
__i += __match->match_size + \
324
sizeof(struct ebt_entry_match)) { \
325
__match = (void *)(e) + __i; \
327
__ret = fn(__match , ## args); \
332
if (__i != (e)->watchers_offset) \
338
#define EBT_WATCHER_ITERATE(e, fn, args...) \
342
struct ebt_entry_watcher *__watcher; \
344
for (__i = e->watchers_offset; \
345
__i < (e)->target_offset; \
346
__i += __watcher->watcher_size + \
347
sizeof(struct ebt_entry_watcher)) { \
348
__watcher = (void *)(e) + __i; \
350
__ret = fn(__watcher , ## args); \
355
if (__i != (e)->target_offset) \
361
#define EBT_ENTRY_ITERATE(entries, size, fn, args...) \
365
struct ebt_entry *__entry; \
367
for (__i = 0; __i < (size);) { \
368
__entry = (void *)(entries) + __i; \
369
__ret = fn(__entry , ## args); \
372
if (__entry->bitmask != 0) \
373
__i += __entry->next_offset; \
375
__i += sizeof(struct ebt_entries); \