Merge tag 'for-v3.18' of git://git.infradead.org/battery-2.6
[deliverable/linux.git] / include / linux / netfilter / ipset / ip_set_timeout.h
CommitLineData
72205fc6
JK
1#ifndef _IP_SET_TIMEOUT_H
2#define _IP_SET_TIMEOUT_H
3
075e64c0 4/* Copyright (C) 2003-2013 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
72205fc6
JK
5 *
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 */
10
11#ifdef __KERNEL__
12
13/* How often should the gc be run by default */
14#define IPSET_GC_TIME (3 * 60)
15
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)
19
075e64c0
JK
20/* Entry is set with no timeout value */
21#define IPSET_ELEM_PERMANENT 0
72205fc6 22
075e64c0
JK
23/* Set is defined with timeout support: timeout value may be 0 */
24#define IPSET_NO_TIMEOUT UINT_MAX
72205fc6 25
ca134ce8
JK
26#define ip_set_adt_opt_timeout(opt, set) \
27((opt)->ext.timeout != IPSET_NO_TIMEOUT ? (opt)->ext.timeout : (set)->timeout)
ac8cc925 28
72205fc6
JK
29static inline unsigned int
30ip_set_timeout_uget(struct nlattr *tb)
31{
32 unsigned int timeout = ip_set_get_h32(tb);
33
127f5591
JK
34 /* Normalize to fit into jiffies */
35 if (timeout > UINT_MAX/MSEC_PER_SEC)
36 timeout = UINT_MAX/MSEC_PER_SEC;
37
72205fc6
JK
38 /* Userspace supplied TIMEOUT parameter: adjust crazy size */
39 return timeout == IPSET_NO_TIMEOUT ? IPSET_NO_TIMEOUT - 1 : timeout;
40}
41
72205fc6
JK
42static inline bool
43ip_set_timeout_test(unsigned long timeout)
44{
45 return timeout == IPSET_ELEM_PERMANENT ||
249ddc79 46 time_is_after_jiffies(timeout);
72205fc6
JK
47}
48
49static inline bool
075e64c0 50ip_set_timeout_expired(unsigned long *timeout)
72205fc6 51{
075e64c0
JK
52 return *timeout != IPSET_ELEM_PERMANENT &&
53 time_is_before_jiffies(*timeout);
72205fc6
JK
54}
55
075e64c0
JK
56static inline void
57ip_set_timeout_set(unsigned long *timeout, u32 t)
72205fc6 58{
075e64c0
JK
59 if (!t) {
60 *timeout = IPSET_ELEM_PERMANENT;
61 return;
62 }
72205fc6 63
075e64c0
JK
64 *timeout = msecs_to_jiffies(t * 1000) + jiffies;
65 if (*timeout == IPSET_ELEM_PERMANENT)
72205fc6 66 /* Bingo! :-) */
075e64c0 67 (*timeout)--;
72205fc6
JK
68}
69
70static inline u32
075e64c0 71ip_set_timeout_get(unsigned long *timeout)
72205fc6 72{
075e64c0
JK
73 return *timeout == IPSET_ELEM_PERMANENT ? 0 :
74 jiffies_to_msecs(*timeout - jiffies)/1000;
72205fc6 75}
72205fc6
JK
76
77#endif /* __KERNEL__ */
72205fc6 78#endif /* _IP_SET_TIMEOUT_H */
This page took 0.471101 seconds and 5 git commands to generate.