]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.cpp
Remove InspIRCd* parameters and fields
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / utils.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "socket.h"
16 #include "xline.h"
17 #include "../transport.h"
18 #include "socketengine.h"
19
20 #include "main.h"
21 #include "utils.h"
22 #include "treeserver.h"
23 #include "link.h"
24 #include "treesocket.h"
25 #include "resolvers.h"
26
27 /* $ModDep: m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h */
28
29 /* Create server sockets off a listener. */
30 void ServerSocketListener::OnAcceptReady(int newsock)
31 {
32         bool found = false;
33         int port;
34         std::string incomingip;
35         irc::sockets::satoap(&client, incomingip, port);
36         char *ip = const_cast<char*>(incomingip.c_str());
37
38         found = (std::find(Utils->ValidIPs.begin(), Utils->ValidIPs.end(), ip) != Utils->ValidIPs.end());
39         if (!found)
40         {
41                 for (std::vector<std::string>::iterator i = Utils->ValidIPs.begin(); i != Utils->ValidIPs.end(); i++)
42                 {
43                         if (*i == "*" || irc::sockets::MatchCIDR(ip, *i))
44                         {
45                                 found = true;
46                                 break;
47                         }
48                 }
49
50                 if (!found)
51                 {
52                         ServerInstance->SNO->WriteToSnoMask('l', "Server connection from %s denied (no link blocks with that IP address)", ip);
53                         ServerInstance->SE->Close(newsock);
54                         return;
55                 }
56         }
57
58         /* we don't need to do anything with the pointer, creating it stores it in the necessary places */
59         TreeSocket* ts = new TreeSocket(Utils, newsock, ip, NULL, Hook);
60
61         if (Hook)
62                 Hook->OnStreamSocketAccept(ts, &client, &server);
63
64         return;
65 }
66
67 /** Yay for fast searches!
68  * This is hundreds of times faster than recursion
69  * or even scanning a linked list, especially when
70  * there are more than a few servers to deal with.
71  * (read as: lots).
72  */
73 TreeServer* SpanningTreeUtilities::FindServer(const std::string &ServerName)
74 {
75         if (ServerInstance->IsSID(ServerName))
76                 return this->FindServerID(ServerName);
77
78         server_hash::iterator iter = serverlist.find(ServerName.c_str());
79         if (iter != serverlist.end())
80         {
81                 return iter->second;
82         }
83         else
84         {
85                 return NULL;
86         }
87 }
88
89 /** Returns the locally connected server we must route a
90  * message through to reach server 'ServerName'. This
91  * only applies to one-to-one and not one-to-many routing.
92  * See the comments for the constructor of TreeServer
93  * for more details.
94  */
95 TreeServer* SpanningTreeUtilities::BestRouteTo(const std::string &ServerName)
96 {
97         if (ServerName.c_str() == TreeRoot->GetName() || ServerName == ServerInstance->Config->GetSID())
98                 return NULL;
99         TreeServer* Found = FindServer(ServerName);
100         if (Found)
101         {
102                 return Found->GetRoute();
103         }
104         else
105         {
106                 // Cheat a bit. This allows for (better) working versions of routing commands with nick based prefixes, without hassle
107                 User *u = ServerInstance->FindNick(ServerName);
108                 if (u)
109                 {
110                         Found = FindServer(u->server);
111                         if (Found)
112                                 return Found->GetRoute();
113                 }
114
115                 return NULL;
116         }
117 }
118
119 /** Find the first server matching a given glob mask.
120  * Theres no find-using-glob method of hash_map [awwww :-(]
121  * so instead, we iterate over the list using an iterator
122  * and match each one until we get a hit. Yes its slow,
123  * deal with it.
124  */
125 TreeServer* SpanningTreeUtilities::FindServerMask(const std::string &ServerName)
126 {
127         for (server_hash::iterator i = serverlist.begin(); i != serverlist.end(); i++)
128         {
129                 if (InspIRCd::Match(i->first,ServerName))
130                         return i->second;
131         }
132         return NULL;
133 }
134
135 TreeServer* SpanningTreeUtilities::FindServerID(const std::string &id)
136 {
137         server_hash::iterator iter = sidlist.find(id);
138         if (iter != sidlist.end())
139                 return iter->second;
140         else
141                 return NULL;
142 }
143
144 /* A convenient wrapper that returns true if a server exists */
145 bool SpanningTreeUtilities::IsServer(const std::string &ServerName)
146 {
147         return (FindServer(ServerName) != NULL);
148 }
149
150 SpanningTreeUtilities::SpanningTreeUtilities(ModuleSpanningTree* C) : Creator(C)
151 {
152         ServerInstance->Logs->Log("m_spanningtree",DEBUG,"***** Using SID for hash: %s *****", ServerInstance->Config->GetSID().c_str());
153
154         this->TreeRoot = new TreeServer(this, ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc, ServerInstance->Config->GetSID());
155         ServerUser = new FakeUser(TreeRoot->GetID());
156
157         this->ReadConfiguration(true);
158 }
159
160 SpanningTreeUtilities::~SpanningTreeUtilities()
161 {
162         for (unsigned int i = 0; i < Bindings.size(); i++)
163         {
164                 delete Bindings[i];
165         }
166
167         while (TreeRoot->ChildCount())
168         {
169                 TreeServer* child_server = TreeRoot->GetChild(0);
170                 if (child_server)
171                 {
172                         TreeSocket* sock = child_server->GetSocket();
173                         ServerInstance->SE->DelFd(sock);
174                         sock->Close();
175                 }
176         }
177         
178         // This avoids a collision on reload
179         ServerUser->uuid = TreeRoot->GetID();
180         delete TreeRoot;
181         delete ServerUser;
182 }
183
184 void SpanningTreeUtilities::AddThisServer(TreeServer* server, TreeServerList &list)
185 {
186         if (list.find(server) == list.end())
187                 list[server] = server;
188 }
189
190 /* returns a list of DIRECT servernames for a specific channel */
191 void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list)
192 {
193         const UserMembList *ulist = c->GetUsers();
194
195         for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++)
196         {
197                 if (IS_LOCAL(i->first))
198                         continue;
199
200                 if (status && !strchr(c->GetAllPrefixChars(i->first), status))
201                         continue;
202
203                 if (exempt_list.find(i->first) == exempt_list.end())
204                 {
205                         TreeServer* best = this->BestRouteTo(i->first->server);
206                         if (best)
207                                 AddThisServer(best,list);
208                 }
209         }
210         return;
211 }
212
213 bool SpanningTreeUtilities::DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, parameterlist &params)
214 {
215         char pfx = 0;
216         TreeServer* omitroute = this->BestRouteTo(omit);
217         if ((command == "NOTICE") || (command == "PRIVMSG"))
218         {
219                 if (params.size() >= 2)
220                 {
221                         /* Prefixes */
222                         if (ServerInstance->Modes->FindPrefix(params[0][0]))
223                         {
224                                 pfx = params[0][0];
225                                 params[0] = params[0].substr(1, params[0].length()-1);
226                         }
227                         if ((*(params[0].c_str()) != '#') && (*(params[0].c_str()) != '$'))
228                         {
229                                 // special routing for private messages/notices
230                                 User* d = ServerInstance->FindNick(params[0]);
231                                 if (d)
232                                 {
233                                         parameterlist par;
234                                         par.push_back(params[0]);
235                                         par.push_back(":"+params[1]);
236                                         this->DoOneToOne(prefix,command.c_str(),par,d->server);
237                                         return true;
238                                 }
239                         }
240                         else if (*(params[0].c_str()) == '$')
241                         {
242                                 parameterlist par;
243                                 par.push_back(params[0]);
244                                 par.push_back(":"+params[1]);
245                                 this->DoOneToAllButSender(prefix,command.c_str(),par,omitroute->GetName());
246                                 return true;
247                         }
248                         else
249                         {
250                                 Channel* c = ServerInstance->FindChan(params[0]);
251                                 User* u = ServerInstance->FindNick(prefix);
252                                 if (c)
253                                 {
254                                         CUList elist;
255                                         TreeServerList list;
256                                         FOREACH_MOD(I_OnBuildExemptList, OnBuildExemptList((command == "PRIVMSG" ? MSG_PRIVMSG : MSG_NOTICE), c, u, pfx, elist, params[1]));
257                                         GetListOfServersForChannel(c,list,pfx,elist);
258
259                                         for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
260                                         {
261                                                 TreeSocket* Sock = i->second->GetSocket();
262                                                 if ((Sock) && (i->second->GetName() != omit) && (omitroute != i->second))
263                                                 {
264                                                         Sock->WriteLine(data);
265                                                 }
266                                         }
267                                         return true;
268                                 }
269                         }
270                 }
271         }
272         unsigned int items =this->TreeRoot->ChildCount();
273         for (unsigned int x = 0; x < items; x++)
274         {
275                 TreeServer* Route = this->TreeRoot->GetChild(x);
276                 if ((Route) && (Route->GetSocket()) && (Route->GetName() != omit) && (omitroute != Route))
277                 {
278                         TreeSocket* Sock = Route->GetSocket();
279                         if (Sock)
280                                 Sock->WriteLine(data);
281                 }
282         }
283         return true;
284 }
285
286 bool SpanningTreeUtilities::DoOneToAllButSender(const std::string &prefix, const std::string &command, parameterlist &params, std::string omit)
287 {
288         TreeServer* omitroute = this->BestRouteTo(omit);
289         std::string FullLine = ":" + prefix + " " + command;
290         unsigned int words = params.size();
291         for (unsigned int x = 0; x < words; x++)
292         {
293                 FullLine = FullLine + " " + params[x];
294         }
295         unsigned int items = this->TreeRoot->ChildCount();
296         for (unsigned int x = 0; x < items; x++)
297         {
298                 TreeServer* Route = this->TreeRoot->GetChild(x);
299                 // Send the line IF:
300                 // The route has a socket (its a direct connection)
301                 // The route isnt the one to be omitted
302                 // The route isnt the path to the one to be omitted
303                 if ((Route) && (Route->GetSocket()) && (Route->GetName() != omit) && (omitroute != Route))
304                 {
305                         TreeSocket* Sock = Route->GetSocket();
306                         if (Sock)
307                                 Sock->WriteLine(FullLine);
308                 }
309         }
310         return true;
311 }
312
313 bool SpanningTreeUtilities::DoOneToMany(const std::string &prefix, const std::string &command, parameterlist &params)
314 {
315         std::string FullLine = ":" + prefix + " " + command;
316         unsigned int words = params.size();
317         for (unsigned int x = 0; x < words; x++)
318         {
319                 FullLine = FullLine + " " + params[x];
320         }
321         unsigned int items = this->TreeRoot->ChildCount();
322         for (unsigned int x = 0; x < items; x++)
323         {
324                 TreeServer* Route = this->TreeRoot->GetChild(x);
325                 if (Route && Route->GetSocket())
326                 {
327                         TreeSocket* Sock = Route->GetSocket();
328                         if (Sock)
329                                 Sock->WriteLine(FullLine);
330                 }
331         }
332         return true;
333 }
334
335 bool SpanningTreeUtilities::DoOneToMany(const char* prefix, const char* command, parameterlist &params)
336 {
337         std::string spfx = prefix;
338         std::string scmd = command;
339         return this->DoOneToMany(spfx, scmd, params);
340 }
341
342 bool SpanningTreeUtilities::DoOneToAllButSender(const char* prefix, const char* command, parameterlist &params, std::string omit)
343 {
344         std::string spfx = prefix;
345         std::string scmd = command;
346         return this->DoOneToAllButSender(spfx, scmd, params, omit);
347 }
348
349 bool SpanningTreeUtilities::DoOneToOne(const std::string &prefix, const std::string &command, parameterlist &params, std::string target)
350 {
351         TreeServer* Route = this->BestRouteTo(target);
352         if (Route)
353         {
354                 std::string FullLine = ":" + prefix + " " + command;
355                 unsigned int words = params.size();
356                 for (unsigned int x = 0; x < words; x++)
357                 {
358                         FullLine = FullLine + " " + params[x];
359                 }
360                 if (Route && Route->GetSocket())
361                 {
362                         TreeSocket* Sock = Route->GetSocket();
363                         if (Sock)
364                                 Sock->WriteLine(FullLine);
365                 }
366                 return true;
367         }
368         else
369         {
370                 return false;
371         }
372 }
373
374 void SpanningTreeUtilities::RefreshIPCache()
375 {
376         ValidIPs.clear();
377         for (std::vector<Link>::iterator L = LinkBlocks.begin(); L != LinkBlocks.end(); L++)
378         {
379                 if (L->IPAddr.empty() || L->RecvPass.empty() || L->SendPass.empty() || L->Name.empty() || !L->Port)
380                 {
381                         if (L->Name.empty())
382                         {
383                                 ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"m_spanningtree: Ignoring a malformed link block (all link blocks require a name!)");
384                         }
385                         else
386                         {
387                                 ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"m_spanningtree: Ignoring a link block missing recvpass, sendpass, port or ipaddr.");
388                         }
389
390                         /* Invalid link block */
391                         continue;
392                 }
393
394                 ValidIPs.push_back(L->IPAddr);
395
396                 if (L->AllowMask.length())
397                         ValidIPs.push_back(L->AllowMask);
398
399                 /* Needs resolving */
400                 bool ipvalid = true;
401                 QueryType start_type = DNS_QUERY_A;
402                 start_type = DNS_QUERY_AAAA;
403                 if (strchr(L->IPAddr.c_str(),':'))
404                 {
405                         in6_addr n;
406                         if (inet_pton(AF_INET6, L->IPAddr.c_str(), &n) < 1)
407                                 ipvalid = false;
408                 }
409                 else
410                 {
411                         in_addr n;
412                         if (inet_aton(L->IPAddr.c_str(),&n) < 1)
413                                 ipvalid = false;
414                 }
415
416                 if (!ipvalid)
417                 {
418                         try
419                         {
420                                 bool cached;
421                                 SecurityIPResolver* sr = new SecurityIPResolver(Creator, this, L->IPAddr, *L, cached, start_type);
422                                 ServerInstance->AddResolver(sr, cached);
423                         }
424                         catch (...)
425                         {
426                         }
427                 }
428         }
429 }
430
431 void SpanningTreeUtilities::ReadConfiguration(bool rebind)
432 {
433         ConfigReader* Conf = new ConfigReader;
434
435         /* We don't need to worry about these being *unloaded* on the fly, only loaded,
436          * because we 'use' the interface locking the module in memory.
437          */
438         hooks.clear();
439         hooknames.clear();
440         modulelist* ml = ServerInstance->Modules->FindInterface("BufferedSocketHook");
441
442         /* Did we find any modules? */
443         if (ml)
444         {
445                 /* Yes, enumerate them all to find out the hook name */
446                 for (modulelist::iterator m = ml->begin(); m != ml->end(); m++)
447                 {
448                         /* Make a request to it for its name, its implementing
449                          * BufferedSocketHook so we know its safe to do this
450                          */
451                         std::string name = BufferedSocketNameRequest((Module*)Creator, *m).Send();
452                         /* Build a map of them */
453                         hooks[name.c_str()] = *m;
454                         hooknames.push_back(name);
455                 }
456         }
457
458         if (rebind)
459         {
460                 for (unsigned int i = 0; i < Bindings.size(); i++)
461                 {
462                         delete Bindings[i];
463                 }
464                 Bindings.clear();
465
466                 for (int j = 0; j < Conf->Enumerate("bind"); j++)
467                 {
468                         std::string Type = Conf->ReadValue("bind","type",j);
469                         std::string IP = Conf->ReadValue("bind","address",j);
470                         std::string Port = Conf->ReadValue("bind","port",j);
471                         std::string transport = Conf->ReadValue("bind","transport",j);
472                         if (Type == "servers")
473                         {
474                                 irc::portparser portrange(Port, false);
475                                 int portno = -1;
476
477                                 if (IP == "*")
478                                         IP.clear();
479
480                                 while ((portno = portrange.GetToken()))
481                                 {
482                                         if ((!transport.empty()) && (hooks.find(transport.c_str()) ==  hooks.end()))
483                                         {
484                                                 throw CoreException("Can't find transport type '"+transport+"' for port "+IP+":"+Port+" - maybe you forgot to load it BEFORE m_spanningtree in your config file?");
485                                                 break;
486                                         }
487
488                                         ServerSocketListener *listener = new ServerSocketListener(this, portno, (char *)IP.c_str());
489                                         if (listener->GetFd() == -1)
490                                         {
491                                                 delete listener;
492                                                 continue;
493                                         }
494
495                                         if (!transport.empty())
496                                                 listener->Hook = hooks[transport.c_str()];
497
498                                         Bindings.push_back(listener);
499                                 }
500                         }
501                 }
502         }
503         FlatLinks = Conf->ReadFlag("security","flatlinks",0);
504         HideULines = Conf->ReadFlag("security","hideulines",0);
505         AnnounceTSChange = Conf->ReadFlag("options","announcets",0);
506         AllowOptCommon = Conf->ReadFlag("options", "allowmismatch", 0);
507         ChallengeResponse = !Conf->ReadFlag("security", "disablehmac", 0);
508         quiet_bursts = Conf->ReadFlag("performance", "quietbursts", 0);
509         PingWarnTime = Conf->ReadInteger("options", "pingwarning", 0, true);
510         PingFreq = Conf->ReadInteger("options", "serverpingfreq", 0, true);
511
512         if (PingFreq == 0)
513                 PingFreq = 60;
514
515         if (PingWarnTime < 0 || PingWarnTime > PingFreq - 1)
516                 PingWarnTime = 0;
517
518         AutoconnectBlocks.clear();
519         LinkBlocks.clear();
520         ValidIPs.clear();
521         for (int j = 0; j < Conf->Enumerate("link"); ++j)
522         {
523                 Link L;
524                 std::string Allow = Conf->ReadValue("link", "allowmask", j);
525                 L.Name = (Conf->ReadValue("link", "name", j)).c_str();
526                 L.AllowMask = Allow;
527                 L.IPAddr = Conf->ReadValue("link", "ipaddr", j);
528                 L.Port = Conf->ReadInteger("link", "port", j, true);
529                 L.SendPass = Conf->ReadValue("link", "sendpass", j);
530                 L.RecvPass = Conf->ReadValue("link", "recvpass", j);
531                 L.Fingerprint = Conf->ReadValue("link", "fingerprint", j);
532                 L.HiddenFromStats = Conf->ReadFlag("link", "statshidden", j);
533                 L.Timeout = Conf->ReadInteger("link", "timeout", j, true);
534                 L.Hook = Conf->ReadValue("link", "transport", j);
535                 L.Bind = Conf->ReadValue("link", "bind", j);
536                 L.Hidden = Conf->ReadFlag("link", "hidden", j);
537
538                 if ((!L.Hook.empty()) && (hooks.find(L.Hook.c_str()) ==  hooks.end()))
539                 {
540                         throw CoreException("Can't find transport type '"+L.Hook+"' for link '"+assign(L.Name)+"' - maybe you forgot to load it BEFORE m_spanningtree in your config file? Skipping <link> tag completely.");
541                         continue;
542
543                 }
544
545                 if (L.Name.find('.') == std::string::npos)
546                         throw CoreException("The link name '"+assign(L.Name)+"' is invalid and must contain at least one '.' character");
547
548                 if (L.Name.length() > 64)
549                         throw CoreException("The link name '"+assign(L.Name)+"' is longer than 64 characters!");
550
551                 if ((!L.IPAddr.empty()) && (!L.RecvPass.empty()) && (!L.SendPass.empty()) && (!L.Name.empty()) && (L.Port))
552                 {
553                         if (Allow.length())
554                                 ValidIPs.push_back(Allow);
555
556                         ValidIPs.push_back(L.IPAddr);
557
558                         /* Needs resolving */
559                         bool ipvalid = true;
560                         QueryType start_type = DNS_QUERY_A;
561                         start_type = DNS_QUERY_AAAA;
562                         if (strchr(L.IPAddr.c_str(),':'))
563                         {
564                                 in6_addr n;
565                                 if (inet_pton(AF_INET6, L.IPAddr.c_str(), &n) < 1)
566                                         ipvalid = false;
567                         }
568                         else
569                         {
570                                 in_addr n;
571                                 if (inet_aton(L.IPAddr.c_str(),&n) < 1)
572                                         ipvalid = false;
573                         }
574
575                         if (!ipvalid)
576                         {
577                                 try
578                                 {
579                                         bool cached;
580                                         SecurityIPResolver* sr = new SecurityIPResolver(Creator, this, L.IPAddr, L, cached, start_type);
581                                         ServerInstance->AddResolver(sr, cached);
582                                 }
583                                 catch (...)
584                                 {
585                                 }
586                         }
587                 }
588                 else
589                 {
590                         if (L.IPAddr.empty())
591                         {
592                                 L.IPAddr = "*";
593                                 ValidIPs.push_back("*");
594                                 ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"Configuration warning: Link block " + assign(L.Name) + " has no IP defined! This will allow any IP to connect as this server, and MAY not be what you want.");
595                         }
596
597                         if (L.RecvPass.empty())
598                         {
599                                 throw CoreException("Invalid configuration for server '"+assign(L.Name)+"', recvpass not defined!");
600                         }
601
602                         if (L.SendPass.empty())
603                         {
604                                 throw CoreException("Invalid configuration for server '"+assign(L.Name)+"', sendpass not defined!");
605                         }
606
607                         if (L.Name.empty())
608                         {
609                                 throw CoreException("Invalid configuration, link tag without a name! IP address: "+L.IPAddr);
610                         }
611
612                         if (!L.Port)
613                         {
614                                 ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"Configuration warning: Link block " + assign(L.Name) + " has no port defined, you will not be able to /connect it.");
615                         }
616                 }
617
618                 LinkBlocks.push_back(L);
619         }
620
621         for (int j = 0; j < Conf->Enumerate("autoconnect"); ++j)
622         {
623                 Autoconnect A;
624                 A.Period = Conf->ReadInteger("autoconnect", "period", j, true);
625                 A.Server = Conf->ReadValue("autoconnect", "server", j);
626                 A.FailOver = Conf->ReadValue("autoconnect", "failover", j).c_str();
627
628                 // Fix: Only trip autoconnects if this wouldn't delay autoconnect..
629                 if (A.NextConnectTime > ((time_t)(ServerInstance->Time() + A.Period)))
630                         A.NextConnectTime = ServerInstance->Time() + A.Period;
631
632                 if (A.Period <= 0)
633                 {
634                         throw CoreException("Invalid configuration for autoconnect, period not a positive integer!");
635                 }
636
637                 if (A.Server.empty())
638                 {
639                         throw CoreException("Invalid configuration for autoconnect, server cannot be empty!");
640                 }
641
642                 AutoconnectBlocks.push_back(A);
643         }
644
645         delete Conf;
646 }
647
648 void SpanningTreeUtilities::DoFailOver(Autoconnect* x)
649 {
650         if (x && x->FailOver.length())
651         {
652                 if (x->FailOver == x->Server)
653                 {
654                         ServerInstance->SNO->WriteToSnoMask('l', "FAILOVER: Some muppet configured the failover for server \002%s\002 to point at itself. Not following it!", x->Server.c_str());
655                         return;
656                 }
657                 Link* TryThisOne = this->FindLink(x->FailOver.c_str());
658                 if (TryThisOne)
659                 {
660                         TreeServer* CheckDupe = this->FindServer(x->FailOver.c_str());
661                         if (CheckDupe)
662                         {
663                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Skipping existing failover: %s", x->FailOver.c_str());
664                         }
665                         else
666                         {
667                                 ServerInstance->SNO->WriteToSnoMask('l', "FAILOVER: Trying failover link for \002%s\002: \002%s\002...", x->Server.c_str(), TryThisOne->Name.c_str());
668                                 Creator->ConnectServer(TryThisOne, NULL);
669                         }
670                 }
671                 else
672                 {
673                         ServerInstance->SNO->WriteToSnoMask('l', "FAILOVER: Invalid failover server specified for server \002%s\002, will not follow!", x->Server.c_str());
674                 }
675         }
676 }
677
678 Link* SpanningTreeUtilities::FindLink(const std::string& name)
679 {
680         for (std::vector<Link>::iterator x = LinkBlocks.begin(); x != LinkBlocks.end(); x++)
681         {
682                 if (InspIRCd::Match(x->Name.c_str(), name.c_str()))
683                 {
684                         return &(*x);
685                 }
686         }
687         return NULL;
688 }