Merge to Fedora kernel-2.6.18-1.2260_FC5 patched with stable patch-2.6.18.5-vs2.0...
[linux-2.6.git] / include / linux / netfilter_ipv4 / ip_set_nethash.h
1 #ifndef __IP_SET_NETHASH_H
2 #define __IP_SET_NETHASH_H
3
4 #include <linux/netfilter_ipv4/ip_set.h>
5
6 #define SETTYPE_NAME "nethash"
7 #define MAX_RANGE 0x0000FFFF
8
9 struct ip_set_nethash {
10         ip_set_ip_t *members;           /* the nethash proper */
11         uint32_t elements;              /* number of elements */
12         uint32_t hashsize;              /* hash size */
13         uint16_t probes;                /* max number of probes  */
14         uint16_t resize;                /* resize factor in percent */
15         unsigned char cidr[30];         /* CIDR sizes */
16         void *initval[0];               /* initvals for jhash_1word */
17 };
18
19 struct ip_set_req_nethash_create {
20         uint32_t hashsize;
21         uint16_t probes;
22         uint16_t resize;
23 };
24
25 struct ip_set_req_nethash {
26         ip_set_ip_t ip;
27         unsigned char cidr;
28 };
29
30 static unsigned char shifts[] = {255, 253, 249, 241, 225, 193, 129, 1};
31
32 static inline ip_set_ip_t 
33 pack(ip_set_ip_t ip, unsigned char cidr)
34 {
35         ip_set_ip_t addr, *paddr = &addr;
36         unsigned char n, t, *a;
37
38         addr = htonl(ip & (0xFFFFFFFF << (32 - (cidr))));
39 #ifdef __KERNEL__
40         DP("ip:%u.%u.%u.%u/%u", NIPQUAD(addr), cidr);
41 #endif
42         n = cidr / 8;
43         t = cidr % 8;   
44         a = &((unsigned char *)paddr)[n];
45         *a = *a /(1 << (8 - t)) + shifts[t];
46 #ifdef __KERNEL__
47         DP("n: %u, t: %u, a: %u", n, t, *a);
48         DP("ip:%u.%u.%u.%u/%u, %u.%u.%u.%u",
49            HIPQUAD(ip), cidr, NIPQUAD(addr));
50 #endif
51
52         return ntohl(addr);
53 }
54
55 #endif  /* __IP_SET_NETHASH_H */