From 3d1ad0939fae743f9e10c07d1200665491c61012 Mon Sep 17 00:00:00 2001 From: brain Date: Fri, 6 Apr 2007 14:03:06 +0000 Subject: Fix bug #224 by refreshing the security ip cache every hour. The easier solution of course is not use crappy dynamic ips :p git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6745 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_spanningtree/link.h | 1 + src/modules/m_spanningtree/main.cpp | 5 +++ src/modules/m_spanningtree/main.h | 3 ++ src/modules/m_spanningtree/timesynctimer.cpp | 9 +++++ src/modules/m_spanningtree/timesynctimer.h | 11 ++++++ src/modules/m_spanningtree/utils.cpp | 51 ++++++++++++++++++++++++++++ src/modules/m_spanningtree/utils.h | 3 ++ 7 files changed, 83 insertions(+) (limited to 'src') diff --git a/src/modules/m_spanningtree/link.h b/src/modules/m_spanningtree/link.h index 5d15e5898..4cc7b9b80 100644 --- a/src/modules/m_spanningtree/link.h +++ b/src/modules/m_spanningtree/link.h @@ -15,6 +15,7 @@ class Link : public classbase int Port; std::string SendPass; std::string RecvPass; + std::string AllowMask; unsigned long AutoConnect; time_t NextConnectTime; bool HiddenFromStats; diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index ed2d73efa..471e7ba4d 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -50,6 +50,9 @@ ModuleSpanningTree::ModuleSpanningTree(InspIRCd* Me) } else SyncTimer = NULL; + + RefreshTimer = new CacheRefreshTimer(ServerInstance, Utils); + ServerInstance->Timers->AddTimer(RefreshTimer); } void ModuleSpanningTree::ShowLinks(TreeServer* Current, userrec* user, int hops) @@ -1301,6 +1304,8 @@ ModuleSpanningTree::~ModuleSpanningTree() if (SyncTimer) ServerInstance->Timers->DelTimer(SyncTimer); + ServerInstance->Timers->DelTimer(RefreshTimer); + ServerInstance->DoneWithInterface("InspSocketHook"); } diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h index 062ee283b..4949f60dc 100644 --- a/src/modules/m_spanningtree/main.h +++ b/src/modules/m_spanningtree/main.h @@ -20,6 +20,7 @@ const long ProtocolVersion = 1105; class cmd_rconnect; class SpanningTreeUtilities; class TimeSyncTimer; +class CacheRefreshTimer; class TreeServer; class Link; @@ -39,6 +40,8 @@ class ModuleSpanningTree : public Module */ TimeSyncTimer *SyncTimer; + CacheRefreshTimer *RefreshTimer; + /** Constructor */ ModuleSpanningTree(InspIRCd* Me); diff --git a/src/modules/m_spanningtree/timesynctimer.cpp b/src/modules/m_spanningtree/timesynctimer.cpp index 6e7316932..22038a2fe 100644 --- a/src/modules/m_spanningtree/timesynctimer.cpp +++ b/src/modules/m_spanningtree/timesynctimer.cpp @@ -28,3 +28,12 @@ void TimeSyncTimer::Tick(time_t TIME) Module->BroadcastTimeSync(); } +CacheRefreshTimer::CacheRefreshTimer(InspIRCd *Inst, SpanningTreeUtilities *Util) : InspTimer(3600, Inst->Time(), true), Instance(Inst), Utils(Util) +{ +} + +void CacheRefreshTimer::Tick(time_t TIME) +{ + Utils->RefreshIPCache(); +} + diff --git a/src/modules/m_spanningtree/timesynctimer.h b/src/modules/m_spanningtree/timesynctimer.h index 0354ac99a..6195c2492 100644 --- a/src/modules/m_spanningtree/timesynctimer.h +++ b/src/modules/m_spanningtree/timesynctimer.h @@ -4,6 +4,7 @@ #include "timer.h" class ModuleSpanningTree; +class SpanningTreeUtilities; class InspIRCd; /** Create a timer which recurs every second, we inherit from InspTimer. @@ -20,4 +21,14 @@ class TimeSyncTimer : public InspTimer virtual void Tick(time_t TIME); }; +class CacheRefreshTimer : public InspTimer +{ + private: + InspIRCd *Instance; + SpanningTreeUtilities *Utils; + public: + CacheRefreshTimer(InspIRCd *Instance, SpanningTreeUtilities* Util); + virtual void Tick(time_t TIME); +}; + #endif diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index 03203a97d..7d02e5c90 100644 --- a/src/modules/m_spanningtree/utils.cpp +++ b/src/modules/m_spanningtree/utils.cpp @@ -332,6 +332,56 @@ bool SpanningTreeUtilities::DoOneToOne(const std::string &prefix, const std::str } } +void SpanningTreeUtilities::RefreshIPCache() +{ + ValidIPs.clear(); + for (std::vector::iterator L = LinkBlocks.begin(); L != LinkBlocks.end(); L++) + { + if ((L->IPAddr != "") && (L->RecvPass != "") && (L->SendPass != "") && (L->Name != "") && (L->Port)) + { + ValidIPs.push_back(L->IPAddr); + + if (L->AllowMask.length()) + ValidIPs.push_back(L->AllowMask); + + /* Needs resolving */ + bool ipvalid = true; + QueryType start_type = DNS_QUERY_A; +#ifdef IPV6 + start_type = DNS_QUERY_AAAA; + if (strchr(L->IPAddr.c_str(),':')) + { + in6_addr n; + if (inet_pton(AF_INET6, L->IPAddr.c_str(), &n) < 1) + ipvalid = false; + } + else + { + in_addr n; + if (inet_aton(L->IPAddr.c_str(),&n) < 1) + ipvalid = false; + } +#else + in_addr n; + if (inet_aton(L->IPAddr.c_str(),&n) < 1) + ipvalid = false; +#endif + if (!ipvalid) + { + try + { + bool cached; + SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L->IPAddr, *L, cached, start_type); + ServerInstance->AddResolver(sr, cached); + } + catch (ModuleException& e) + { + } + } + } + } +} + void SpanningTreeUtilities::ReadConfiguration(bool rebind) { ConfigReader* Conf = new ConfigReader(ServerInstance); @@ -386,6 +436,7 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind) Link L; std::string Allow = Conf->ReadValue("link", "allowmask", j); L.Name = (Conf->ReadValue("link", "name", j)).c_str(); + L.AllowMask = Allow; L.IPAddr = Conf->ReadValue("link", "ipaddr", j); L.FailOver = Conf->ReadValue("link", "failover", j).c_str(); L.Port = Conf->ReadInteger("link", "port", j, true); diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h index 0194d461c..e031fdeb5 100644 --- a/src/modules/m_spanningtree/utils.h +++ b/src/modules/m_spanningtree/utils.h @@ -136,6 +136,9 @@ class SpanningTreeUtilities /** Find a link tag from a server name */ Link* FindLink(const std::string& name); + /** Refresh the IP cache used for allowing inbound connections + */ + void RefreshIPCache(); }; #endif -- cgit v1.2.3