2011-02-01 07:33:17 -07:00
|
|
|
#ifndef _IP_SET_TIMEOUT_H
|
|
|
|
#define _IP_SET_TIMEOUT_H
|
|
|
|
|
2019-06-10 05:00:24 -06:00
|
|
|
/* Copyright (C) 2003-2013 Jozsef Kadlecsik <kadlec@netfilter.org>
|
2011-02-01 07:33:17 -07:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
|
|
|
/* How often should the gc be run by default */
|
|
|
|
#define IPSET_GC_TIME (3 * 60)
|
|
|
|
|
|
|
|
/* Timeout period depending on the timeout value of the given set */
|
|
|
|
#define IPSET_GC_PERIOD(timeout) \
|
|
|
|
((timeout/3) ? min_t(u32, (timeout)/3, IPSET_GC_TIME) : 1)
|
|
|
|
|
2013-04-27 06:28:55 -06:00
|
|
|
/* Entry is set with no timeout value */
|
|
|
|
#define IPSET_ELEM_PERMANENT 0
|
2011-02-01 07:33:17 -07:00
|
|
|
|
2013-04-27 06:28:55 -06:00
|
|
|
/* Set is defined with timeout support: timeout value may be 0 */
|
|
|
|
#define IPSET_NO_TIMEOUT UINT_MAX
|
2011-02-01 07:33:17 -07:00
|
|
|
|
2018-06-05 03:53:35 -06:00
|
|
|
/* Max timeout value, see msecs_to_jiffies() in jiffies.h */
|
|
|
|
#define IPSET_MAX_TIMEOUT (UINT_MAX >> 1)/MSEC_PER_SEC
|
|
|
|
|
2013-09-06 16:10:07 -06:00
|
|
|
#define ip_set_adt_opt_timeout(opt, set) \
|
|
|
|
((opt)->ext.timeout != IPSET_NO_TIMEOUT ? (opt)->ext.timeout : (set)->timeout)
|
2011-06-16 10:42:40 -06:00
|
|
|
|
2011-02-01 07:33:17 -07:00
|
|
|
static inline unsigned int
|
|
|
|
ip_set_timeout_uget(struct nlattr *tb)
|
|
|
|
{
|
|
|
|
unsigned int timeout = ip_set_get_h32(tb);
|
|
|
|
|
2012-05-06 20:35:44 -06:00
|
|
|
/* Normalize to fit into jiffies */
|
2018-06-05 03:53:35 -06:00
|
|
|
if (timeout > IPSET_MAX_TIMEOUT)
|
|
|
|
timeout = IPSET_MAX_TIMEOUT;
|
2012-05-06 20:35:44 -06:00
|
|
|
|
2018-06-05 03:53:35 -06:00
|
|
|
return timeout;
|
2011-02-01 07:33:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
2016-11-10 03:24:15 -07:00
|
|
|
ip_set_timeout_expired(const unsigned long *t)
|
2011-02-01 07:33:17 -07:00
|
|
|
{
|
2015-06-13 06:22:25 -06:00
|
|
|
return *t != IPSET_ELEM_PERMANENT && time_is_before_jiffies(*t);
|
2011-02-01 07:33:17 -07:00
|
|
|
}
|
|
|
|
|
2013-04-27 06:28:55 -06:00
|
|
|
static inline void
|
2015-06-13 06:22:25 -06:00
|
|
|
ip_set_timeout_set(unsigned long *timeout, u32 value)
|
2011-02-01 07:33:17 -07:00
|
|
|
{
|
2015-06-13 06:22:25 -06:00
|
|
|
unsigned long t;
|
|
|
|
|
|
|
|
if (!value) {
|
2013-04-27 06:28:55 -06:00
|
|
|
*timeout = IPSET_ELEM_PERMANENT;
|
|
|
|
return;
|
|
|
|
}
|
2011-02-01 07:33:17 -07:00
|
|
|
|
2015-06-13 06:22:25 -06:00
|
|
|
t = msecs_to_jiffies(value * MSEC_PER_SEC) + jiffies;
|
|
|
|
if (t == IPSET_ELEM_PERMANENT)
|
2011-02-01 07:33:17 -07:00
|
|
|
/* Bingo! :-) */
|
2015-06-13 06:22:25 -06:00
|
|
|
t--;
|
|
|
|
*timeout = t;
|
2011-02-01 07:33:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32
|
2016-11-10 03:24:15 -07:00
|
|
|
ip_set_timeout_get(const unsigned long *timeout)
|
2011-02-01 07:33:17 -07:00
|
|
|
{
|
2018-05-31 10:45:21 -06:00
|
|
|
u32 t;
|
|
|
|
|
|
|
|
if (*timeout == IPSET_ELEM_PERMANENT)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
t = jiffies_to_msecs(*timeout - jiffies)/MSEC_PER_SEC;
|
|
|
|
/* Zero value in userspace means no timeout */
|
|
|
|
return t == 0 ? 1 : t;
|
2011-02-01 07:33:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
#endif /* _IP_SET_TIMEOUT_H */
|