netfilter: ipset: bitmap:ip set type support
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / linux / netfilter / ipset / ip_set_timeout.h
blob9f30c5f2ec1cfcd6f02bb3d76413f4e223402827
1 #ifndef _IP_SET_TIMEOUT_H
2 #define _IP_SET_TIMEOUT_H
4 /* Copyright (C) 2003-2011 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
11 #ifdef __KERNEL__
13 /* How often should the gc be run by default */
14 #define IPSET_GC_TIME (3 * 60)
16 /* Timeout period depending on the timeout value of the given set */
17 #define IPSET_GC_PERIOD(timeout) \
18 ((timeout/3) ? min_t(u32, (timeout)/3, IPSET_GC_TIME) : 1)
20 /* Set is defined without timeout support: timeout value may be 0 */
21 #define IPSET_NO_TIMEOUT UINT_MAX
23 #define with_timeout(timeout) ((timeout) != IPSET_NO_TIMEOUT)
25 static inline unsigned int
26 ip_set_timeout_uget(struct nlattr *tb)
28 unsigned int timeout = ip_set_get_h32(tb);
30 /* Userspace supplied TIMEOUT parameter: adjust crazy size */
31 return timeout == IPSET_NO_TIMEOUT ? IPSET_NO_TIMEOUT - 1 : timeout;
34 #ifdef IP_SET_BITMAP_TIMEOUT
36 /* Bitmap specific timeout constants and macros for the entries */
38 /* Bitmap entry is unset */
39 #define IPSET_ELEM_UNSET 0
40 /* Bitmap entry is set with no timeout value */
41 #define IPSET_ELEM_PERMANENT (UINT_MAX/2)
43 static inline bool
44 ip_set_timeout_test(unsigned long timeout)
46 return timeout != IPSET_ELEM_UNSET &&
47 (timeout == IPSET_ELEM_PERMANENT ||
48 time_after(timeout, jiffies));
51 static inline bool
52 ip_set_timeout_expired(unsigned long timeout)
54 return timeout != IPSET_ELEM_UNSET &&
55 timeout != IPSET_ELEM_PERMANENT &&
56 time_before(timeout, jiffies);
59 static inline unsigned long
60 ip_set_timeout_set(u32 timeout)
62 unsigned long t;
64 if (!timeout)
65 return IPSET_ELEM_PERMANENT;
67 t = timeout * HZ + jiffies;
68 if (t == IPSET_ELEM_UNSET || t == IPSET_ELEM_PERMANENT)
69 /* Bingo! */
70 t++;
72 return t;
75 static inline u32
76 ip_set_timeout_get(unsigned long timeout)
78 return timeout == IPSET_ELEM_PERMANENT ? 0 : (timeout - jiffies)/HZ;
81 #else
83 /* Hash specific timeout constants and macros for the entries */
85 /* Hash entry is set with no timeout value */
86 #define IPSET_ELEM_PERMANENT 0
88 static inline bool
89 ip_set_timeout_test(unsigned long timeout)
91 return timeout == IPSET_ELEM_PERMANENT ||
92 time_after(timeout, jiffies);
95 static inline bool
96 ip_set_timeout_expired(unsigned long timeout)
98 return timeout != IPSET_ELEM_PERMANENT &&
99 time_before(timeout, jiffies);
102 static inline unsigned long
103 ip_set_timeout_set(u32 timeout)
105 unsigned long t;
107 if (!timeout)
108 return IPSET_ELEM_PERMANENT;
110 t = timeout * HZ + jiffies;
111 if (t == IPSET_ELEM_PERMANENT)
112 /* Bingo! :-) */
113 t++;
115 return t;
118 static inline u32
119 ip_set_timeout_get(unsigned long timeout)
121 return timeout == IPSET_ELEM_PERMANENT ? 0 : (timeout - jiffies)/HZ;
123 #endif /* ! IP_SET_BITMAP_TIMEOUT */
125 #endif /* __KERNEL__ */
127 #endif /* _IP_SET_TIMEOUT_H */