summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/m_spanningtree/link.h1
-rw-r--r--src/modules/m_spanningtree/main.cpp5
-rw-r--r--src/modules/m_spanningtree/main.h3
-rw-r--r--src/modules/m_spanningtree/timesynctimer.cpp9
-rw-r--r--src/modules/m_spanningtree/timesynctimer.h11
-rw-r--r--src/modules/m_spanningtree/utils.cpp51
-rw-r--r--src/modules/m_spanningtree/utils.h3
7 files changed, 83 insertions, 0 deletions
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<Link>::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