net: cleanup include/linux
[pandora-kernel.git] / include / linux / netfilter_bridge / ebt_among.h
1 #ifndef __LINUX_BRIDGE_EBT_AMONG_H
2 #define __LINUX_BRIDGE_EBT_AMONG_H
3
4 #define EBT_AMONG_DST 0x01
5 #define EBT_AMONG_SRC 0x02
6
7 /* Grzegorz Borowiak <grzes@gnu.univ.gda.pl> 2003
8  * 
9  * Write-once-read-many hash table, used for checking if a given
10  * MAC address belongs to a set or not and possibly for checking
11  * if it is related with a given IPv4 address.
12  *
13  * The hash value of an address is its last byte.
14  * 
15  * In real-world ethernet addresses, values of the last byte are
16  * evenly distributed and there is no need to consider other bytes.
17  * It would only slow the routines down.
18  *
19  * For MAC address comparison speedup reasons, we introduce a trick.
20  * MAC address is mapped onto an array of two 32-bit integers.
21  * This pair of integers is compared with MAC addresses in the
22  * hash table, which are stored also in form of pairs of integers
23  * (in `cmp' array). This is quick as it requires only two elementary
24  * number comparisons in worst case. Further, we take advantage of
25  * fact that entropy of 3 last bytes of address is larger than entropy
26  * of 3 first bytes. So first we compare 4 last bytes of addresses and
27  * if they are the same we compare 2 first.
28  *
29  * Yes, it is a memory overhead, but in 2003 AD, who cares?
30  */
31
32 struct ebt_mac_wormhash_tuple {
33         uint32_t cmp[2];
34         __be32 ip;
35 };
36
37 struct ebt_mac_wormhash {
38         int table[257];
39         int poolsize;
40         struct ebt_mac_wormhash_tuple pool[0];
41 };
42
43 #define ebt_mac_wormhash_size(x) ((x) ? sizeof(struct ebt_mac_wormhash) \
44                 + (x)->poolsize * sizeof(struct ebt_mac_wormhash_tuple) : 0)
45
46 struct ebt_among_info {
47         int wh_dst_ofs;
48         int wh_src_ofs;
49         int bitmask;
50 };
51
52 #define EBT_AMONG_DST_NEG 0x1
53 #define EBT_AMONG_SRC_NEG 0x2
54
55 #define ebt_among_wh_dst(x) ((x)->wh_dst_ofs ? \
56         (struct ebt_mac_wormhash*)((char*)(x) + (x)->wh_dst_ofs) : NULL)
57 #define ebt_among_wh_src(x) ((x)->wh_src_ofs ? \
58         (struct ebt_mac_wormhash*)((char*)(x) + (x)->wh_src_ofs) : NULL)
59
60 #define EBT_AMONG_MATCH "among"
61
62 #endif