~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/netfilter/ipset/ip_set_timeout.h

Version: ~ [ linux-5.1-rc5 ] ~ [ linux-5.0.7 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.34 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.111 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.168 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.178 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.138 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.65 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #ifndef _IP_SET_TIMEOUT_H
  2 #define _IP_SET_TIMEOUT_H
  3 
  4 /* Copyright (C) 2003-2011 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
  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 
 20 /* Set is defined without timeout support: timeout value may be 0 */
 21 #define IPSET_NO_TIMEOUT        UINT_MAX
 22 
 23 #define with_timeout(timeout)   ((timeout) != IPSET_NO_TIMEOUT)
 24 
 25 static inline unsigned int
 26 ip_set_timeout_uget(struct nlattr *tb)
 27 {
 28         unsigned int timeout = ip_set_get_h32(tb);
 29 
 30         /* Userspace supplied TIMEOUT parameter: adjust crazy size */
 31         return timeout == IPSET_NO_TIMEOUT ? IPSET_NO_TIMEOUT - 1 : timeout;
 32 }
 33 
 34 #ifdef IP_SET_BITMAP_TIMEOUT
 35 
 36 /* Bitmap specific timeout constants and macros for the entries */
 37 
 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)
 42 
 43 static inline bool
 44 ip_set_timeout_test(unsigned long timeout)
 45 {
 46         return timeout != IPSET_ELEM_UNSET &&
 47                (timeout == IPSET_ELEM_PERMANENT ||
 48                 time_is_after_jiffies(timeout));
 49 }
 50 
 51 static inline bool
 52 ip_set_timeout_expired(unsigned long timeout)
 53 {
 54         return timeout != IPSET_ELEM_UNSET &&
 55                timeout != IPSET_ELEM_PERMANENT &&
 56                time_is_before_jiffies(timeout);
 57 }
 58 
 59 static inline unsigned long
 60 ip_set_timeout_set(u32 timeout)
 61 {
 62         unsigned long t;
 63 
 64         if (!timeout)
 65                 return IPSET_ELEM_PERMANENT;
 66 
 67         t = msecs_to_jiffies(timeout * 1000) + jiffies;
 68         if (t == IPSET_ELEM_UNSET || t == IPSET_ELEM_PERMANENT)
 69                 /* Bingo! */
 70                 t++;
 71 
 72         return t;
 73 }
 74 
 75 static inline u32
 76 ip_set_timeout_get(unsigned long timeout)
 77 {
 78         return timeout == IPSET_ELEM_PERMANENT ? 0 : 
 79                 jiffies_to_msecs(timeout - jiffies)/1000;
 80 }
 81 
 82 #else
 83 
 84 /* Hash specific timeout constants and macros for the entries */
 85 
 86 /* Hash entry is set with no timeout value */
 87 #define IPSET_ELEM_PERMANENT    0
 88 
 89 static inline bool
 90 ip_set_timeout_test(unsigned long timeout)
 91 {
 92         return timeout == IPSET_ELEM_PERMANENT ||
 93                time_is_after_jiffies(timeout);
 94 }
 95 
 96 static inline bool
 97 ip_set_timeout_expired(unsigned long timeout)
 98 {
 99         return timeout != IPSET_ELEM_PERMANENT &&
100                time_is_before_jiffies(timeout);
101 }
102 
103 static inline unsigned long
104 ip_set_timeout_set(u32 timeout)
105 {
106         unsigned long t;
107 
108         if (!timeout)
109                 return IPSET_ELEM_PERMANENT;
110 
111         t = msecs_to_jiffies(timeout * 1000) + jiffies;
112         if (t == IPSET_ELEM_PERMANENT)
113                 /* Bingo! :-) */
114                 t++;
115 
116         return t;
117 }
118 
119 static inline u32
120 ip_set_timeout_get(unsigned long timeout)
121 {
122         return timeout == IPSET_ELEM_PERMANENT ? 0 :
123                 jiffies_to_msecs(timeout - jiffies)/1000;
124 }
125 #endif /* ! IP_SET_BITMAP_TIMEOUT */
126 
127 #endif  /* __KERNEL__ */
128 
129 #endif /* _IP_SET_TIMEOUT_H */
130 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp