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