mirror of https://github.com/fail2ban/fail2ban
invalidate IP/DNS caches by reload, so inter alia would allow to recognize IPv6IsAllowed immediately, previously retarded up to cache max-time (5m);
closes gh-2804pull/1833/merge
parent
913c37db80
commit
3700a9e523
|
@ -33,7 +33,7 @@ import stat
|
|||
import sys
|
||||
|
||||
from .jails import Jails
|
||||
from .filter import FileFilter, JournalFilter
|
||||
from .filter import DNSUtils, FileFilter, JournalFilter
|
||||
from .transmitter import Transmitter
|
||||
from .asyncserver import AsyncServer, AsyncServerException
|
||||
from .. import version
|
||||
|
@ -274,6 +274,11 @@ class Server:
|
|||
for name in self.__jails.keys():
|
||||
self.delJail(name, stop=False, join=True)
|
||||
|
||||
def clearCaches(self):
|
||||
# we need to clear caches, to be able to recognize new IPs/families etc:
|
||||
DNSUtils.CACHE_nameToIp.clear()
|
||||
DNSUtils.CACHE_ipToName.clear()
|
||||
|
||||
def reloadJails(self, name, opts, begin):
|
||||
if begin:
|
||||
# begin reload:
|
||||
|
@ -295,6 +300,8 @@ class Server:
|
|||
if "--restart" in opts:
|
||||
self.stopJail(name)
|
||||
else:
|
||||
# invalidate caches by reload
|
||||
self.clearCaches()
|
||||
# first unban all ips (will be not restored after (re)start):
|
||||
if "--unban" in opts:
|
||||
self.setUnbanIP()
|
||||
|
|
|
@ -320,6 +320,7 @@ def initTests(opts):
|
|||
|
||||
# precache all invalid ip's (TEST-NET-1, ..., TEST-NET-3 according to RFC 5737):
|
||||
c = DNSUtils.CACHE_ipToName
|
||||
c.clear = lambda: logSys.warn('clear CACHE_ipToName is disabled in test suite')
|
||||
# increase max count and max time (too many entries, long time testing):
|
||||
c.setOptions(maxCount=10000, maxTime=5*60)
|
||||
for i in xrange(256):
|
||||
|
@ -337,6 +338,7 @@ def initTests(opts):
|
|||
c.set('8.8.4.4', 'dns.google')
|
||||
# precache all dns to ip's used in test cases:
|
||||
c = DNSUtils.CACHE_nameToIp
|
||||
c.clear = lambda: logSys.warn('clear CACHE_nameToIp is disabled in test suite')
|
||||
for i in (
|
||||
('999.999.999.999', set()),
|
||||
('abcdef.abcdef', set()),
|
||||
|
|
Loading…
Reference in New Issue