netfilter: ipset: bitmap:ip set type support
[cascardo/linux.git] / include / linux / netfilter / ipset / ip_set_bitmap.h
1 #ifndef __IP_SET_BITMAP_H
2 #define __IP_SET_BITMAP_H
3
4 /* Bitmap type specific error codes */
5 enum {
6         /* The element is out of the range of the set */
7         IPSET_ERR_BITMAP_RANGE = IPSET_ERR_TYPE_SPECIFIC,
8         /* The range exceeds the size limit of the set type */
9         IPSET_ERR_BITMAP_RANGE_SIZE,
10 };
11
12 #ifdef __KERNEL__
13 #define IPSET_BITMAP_MAX_RANGE  0x0000FFFF
14
15 /* Common functions */
16
17 static inline u32
18 range_to_mask(u32 from, u32 to, u8 *bits)
19 {
20         u32 mask = 0xFFFFFFFE;
21
22         *bits = 32;
23         while (--(*bits) > 0 && mask && (to & mask) != from)
24                 mask <<= 1;
25
26         return mask;
27 }
28
29 #endif /* __KERNEL__ */
30
31 #endif /* __IP_SET_BITMAP_H */