This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / linux / netfilter_ipv4 / ip_set_ipmap.h
1 #ifndef __IP_SET_IPMAP_H
2 #define __IP_SET_IPMAP_H
3
4 #include <linux/netfilter_ipv4/ip_set.h>
5
6 #define SETTYPE_NAME "ipmap"
7 #define MAX_RANGE 0x0000FFFF
8
9 struct ip_set_ipmap {
10         void *members;                  /* the ipmap proper */
11         ip_set_ip_t first_ip;           /* host byte order, included in range */
12         ip_set_ip_t last_ip;            /* host byte order, included in range */
13         ip_set_ip_t netmask;            /* subnet netmask */
14         ip_set_ip_t sizeid;             /* size of set in IPs */
15         ip_set_ip_t hosts;              /* number of hosts in a subnet */
16 };
17
18 struct ip_set_req_ipmap_create {
19         ip_set_ip_t from;
20         ip_set_ip_t to;
21         ip_set_ip_t netmask;
22 };
23
24 struct ip_set_req_ipmap {
25         ip_set_ip_t ip;
26 };
27
28 unsigned int
29 mask_to_bits(ip_set_ip_t mask)
30 {
31         unsigned int bits = 32;
32         ip_set_ip_t maskaddr;
33         
34         if (mask == 0xFFFFFFFF)
35                 return bits;
36         
37         maskaddr = 0xFFFFFFFE;
38         while (--bits >= 0 && maskaddr != mask)
39                 maskaddr <<= 1;
40         
41         return bits;
42 }
43
44 ip_set_ip_t
45 range_to_mask(ip_set_ip_t from, ip_set_ip_t to, unsigned int *bits)
46 {
47         ip_set_ip_t mask = 0xFFFFFFFE;
48         
49         *bits = 32;
50         while (--(*bits) >= 0 && mask && (to & mask) != from)
51                 mask <<= 1;
52                 
53         return mask;
54 }
55         
56 #endif /* __IP_SET_IPMAP_H */