RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / include / linux / netfilter_ipv4 / ip_set_ipmap.h
blobd16c0ae4c0823c9f06680adbd3d518e97290bd0a
1 #ifndef __IP_SET_IPMAP_H
2 #define __IP_SET_IPMAP_H
4 #include <linux/netfilter_ipv4/ip_set.h>
5 #include <linux/netfilter_ipv4/ip_set_bitmaps.h>
7 #define SETTYPE_NAME "ipmap"
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 u_int32_t size; /* size of the ipmap proper */
19 struct ip_set_req_ipmap_create {
20 ip_set_ip_t from;
21 ip_set_ip_t to;
22 ip_set_ip_t netmask;
25 struct ip_set_req_ipmap {
26 ip_set_ip_t ip;
29 static inline unsigned int
30 mask_to_bits(ip_set_ip_t mask)
32 unsigned int bits = 32;
33 ip_set_ip_t maskaddr;
35 if (mask == 0xFFFFFFFF)
36 return bits;
38 maskaddr = 0xFFFFFFFE;
39 while (--bits > 0 && maskaddr != mask)
40 maskaddr <<= 1;
42 return bits;
45 static inline ip_set_ip_t
46 range_to_mask(ip_set_ip_t from, ip_set_ip_t to, unsigned int *bits)
48 ip_set_ip_t mask = 0xFFFFFFFE;
50 *bits = 32;
51 while (--(*bits) > 0 && mask && (to & mask) != from)
52 mask <<= 1;
54 return mask;
57 #endif /* __IP_SET_IPMAP_H */