This commit was manufactured by cvs2svn to create branch 'vserver'.
[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 hashsize;              /* hash size */
12         uint16_t probes;                /* max number of probes  */
13         uint16_t resize;                /* resize factor in percent */
14         unsigned char cidr[30];         /* CIDR sizes */
15         void *initval[0];               /* initvals for jhash_1word */
16 };
17
18 struct ip_set_req_nethash_create {
19         uint32_t hashsize;
20         uint16_t probes;
21         uint16_t resize;
22 };
23
24 struct ip_set_req_nethash {
25         ip_set_ip_t ip;
26         unsigned char cidr;
27 };
28
29 static unsigned char shifts[] = {255, 253, 249, 241, 225, 193, 129, 1};
30
31 static inline ip_set_ip_t 
32 pack(ip_set_ip_t ip, unsigned char cidr)
33 {
34         ip_set_ip_t addr, *paddr = &addr;
35         unsigned char n, t, *a;
36
37         addr = htonl(ip & (0xFFFFFFFF << (32 - (cidr))));
38 #ifdef __KERNEL__
39         DP("ip:%u.%u.%u.%u/%u", NIPQUAD(addr), cidr);
40 #endif
41         n = cidr / 8;
42         t = cidr % 8;   
43         a = &((unsigned char *)paddr)[n];
44         *a = *a /(1 << (8 - t)) + shifts[t];
45 #ifdef __KERNEL__
46         DP("n: %u, t: %u, a: %u", n, t, *a);
47         DP("ip:%u.%u.%u.%u/%u, %u.%u.%u.%u",
48            HIPQUAD(ip), cidr, NIPQUAD(addr));
49 #endif
50
51         return ntohl(addr);
52 }
53
54 #endif  /* __IP_SET_NETHASH_H */