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