]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.cpp
91b8dd239f4288a6a24598dac4a4f8c7ac72eddf
[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://www.inspircd.org/wiki/index.php/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 "m_spanningtree/main.h"
23 #include "m_spanningtree/utils.h"
24 #include "m_spanningtree/treeserver.h"
25 #include "m_spanningtree/link.h"
26 #include "m_spanningtree/treesocket.h"
27 #include "m_spanningtree/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(const std::string &ipconnectedto, int newsock, const std::string &incomingip)
33 {
34         bool found = false;
35         char *ip = (char *)incomingip.c_str(); // XXX ugly cast
36
37         found = (std::find(Utils->ValidIPs.begin(), Utils->ValidIPs.end(), ip) != Utils->ValidIPs.end());
38         if (!found)
39         {
40                 for (std::vector<std::string>::iterator i = Utils->ValidIPs.begin(); i != Utils->ValidIPs.end(); i++)
41                 {
42                         if (*i == "*" || irc::sockets::MatchCIDR(ip, *i))
43                         {
44                                 found = true;
45                                 break;
46                         }
47                 }
48
49                 if (!found)
50                 {
51                         this->ServerInstance->SNO->WriteToSnoMask('l', "Server connection from %s denied (no link blocks with that IP address)", ip);
52                         ServerInstance->SE->Close(newsock);
53                         return;
54                 }
55         }
56
57         if (this->GetIOHook())
58         {
59                 this->GetIOHook()->OnRawSocketAccept(newsock, incomingip.c_str(), this->bind_port);
60         }
61
62         /* we don't need a pointer to this, creating it stores it in the necessary places */
63         new TreeSocket(this->Utils, this->ServerInstance, newsock, ip, this->GetIOHook());
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 (this->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(InspIRCd* Instance, ModuleSpanningTree* C) : ServerInstance(Instance), Creator(C)
151 {
152         Bindings.clear();
153
154         ServerInstance->Logs->Log("m_spanningtree",DEBUG,"***** Using SID for hash: %s *****", ServerInstance->Config->GetSID().c_str());
155
156         this->TreeRoot = new TreeServer(this, ServerInstance, ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc, ServerInstance->Config->GetSID());
157
158         this->ReadConfiguration(true);
159 }
160
161 SpanningTreeUtilities::~SpanningTreeUtilities()
162 {
163         for (unsigned int i = 0; i < Bindings.size(); i++)
164         {
165                 delete Bindings[i];
166         }
167
168         while (TreeRoot->ChildCount())
169         {
170                 TreeServer* child_server = TreeRoot->GetChild(0);
171                 if (child_server)
172                 {
173                         TreeSocket* sock = child_server->GetSocket();
174                         ServerInstance->SE->DelFd(sock);
175                         sock->Close();
176                 }
177         }
178         delete TreeRoot;
179         ServerInstance->BufferedSocketCull();
180 }
181
182 void SpanningTreeUtilities::AddThisServer(TreeServer* server, TreeServerList &list)
183 {
184         if (list.find(server) == list.end())
185                 list[server] = server;
186 }
187
188 /* returns a list of DIRECT servernames for a specific channel */
189 void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list)
190 {
191         CUList *ulist = c->GetUsers();
192
193         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
194         {
195                 if (IS_LOCAL(i->first))
196                         continue;
197
198                 if (status && !strchr(c->GetAllPrefixChars(i->first), status))
199                         continue;
200
201                 if (exempt_list.find(i->first) == exempt_list.end())
202                 {
203                         TreeServer* best = this->BestRouteTo(i->first->server);
204                         if (best)
205                                 AddThisServer(best,list);
206                 }
207         }
208         return;
209 }
210
211 bool SpanningTreeUtilities::DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, std::deque<std::string> &params)
212 {
213         char pfx = 0;
214         TreeServer* omitroute = this->BestRouteTo(omit);
215         if ((command == "NOTICE") || (command == "PRIVMSG"))
216         {
217                 if (params.size() >= 2)
218                 {
219                         /* Prefixes */
220                         if (ServerInstance->Modes->FindPrefix(params[0][0]))
221                         {
222                                 pfx = params[0][0];
223                                 params[0] = params[0].substr(1, params[0].length()-1);
224                         }
225                         if ((*(params[0].c_str()) != '#') && (*(params[0].c_str()) != '$'))
226                         {
227                                 // special routing for private messages/notices
228                                 User* d = ServerInstance->FindNick(params[0]);
229                                 if (d)
230                                 {
231                                         std::deque<std::string> par;
232                                         par.push_back(params[0]);
233                                         par.push_back(":"+params[1]);
234                                         this->DoOneToOne(prefix,command.c_str(),par,d->server);
235                                         return true;
236                                 }
237                         }
238                         else if (*(params[0].c_str()) == '$')
239                         {
240                                 std::deque<std::string> par;
241                                 par.push_back(params[0]);
242                                 par.push_back(":"+params[1]);
243                                 this->DoOneToAllButSender(prefix,command.c_str(),par,omitroute->GetName());
244                                 return true;
245                         }
246                         else
247                         {
248                                 Channel* c = ServerInstance->FindChan(params[0]);
249                                 User* u = ServerInstance->FindNick(prefix);
250                                 if (c)
251                                 {
252                                         CUList elist;
253                                         TreeServerList list;
254                                         FOREACH_MOD(I_OnBuildExemptList, OnBuildExemptList((command == "PRIVMSG" ? MSG_PRIVMSG : MSG_NOTICE), c, u, pfx, elist, params[1]));
255                                         GetListOfServersForChannel(c,list,pfx,elist);
256
257                                         for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
258                                         {
259                                                 TreeSocket* Sock = i->second->GetSocket();
260                                                 if ((Sock) && (i->second->GetName() != omit) && (omitroute != i->second))
261                                                 {
262                                                         Sock->WriteLine(data);
263                                                 }
264                                         }
265                                         return true;
266                                 }
267                         }
268                 }
269         }
270         unsigned int items =this->TreeRoot->ChildCount();
271         for (unsigned int x = 0; x < items; x++)
272         {
273                 TreeServer* Route = this->TreeRoot->GetChild(x);
274                 if ((Route) && (Route->GetSocket()) && (Route->GetName() != omit) && (omitroute != Route))
275                 {
276                         TreeSocket* Sock = Route->GetSocket();
277                         if (Sock)
278                                 Sock->WriteLine(data);
279                 }
280         }
281         return true;
282 }
283
284 bool SpanningTreeUtilities::DoOneToAllButSender(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string omit)
285 {
286         TreeServer* omitroute = this->BestRouteTo(omit);
287         std::string FullLine = ":" + prefix + " " + command;
288         unsigned int words = params.size();
289         for (unsigned int x = 0; x < words; x++)
290         {
291                 FullLine = FullLine + " " + params[x];
292         }
293         unsigned int items = this->TreeRoot->ChildCount();
294         for (unsigned int x = 0; x < items; x++)
295         {
296                 TreeServer* Route = this->TreeRoot->GetChild(x);
297                 // Send the line IF:
298                 // The route has a socket (its a direct connection)
299                 // The route isnt the one to be omitted
300                 // The route isnt the path to the one to be omitted
301                 if ((Route) && (Route->GetSocket()) && (Route->GetName() != omit) && (omitroute != Route))
302                 {
303                         TreeSocket* Sock = Route->GetSocket();
304                         if (Sock)
305                                 Sock->WriteLine(FullLine);
306                 }
307         }
308         return true;
309 }
310
311 bool SpanningTreeUtilities::DoOneToMany(const std::string &prefix, const std::string &command, std::deque<std::string> &params)
312 {
313         std::string FullLine = ":" + prefix + " " + command;
314         unsigned int words = params.size();
315         for (unsigned int x = 0; x < words; x++)
316         {
317                 FullLine = FullLine + " " + params[x];
318         }
319         unsigned int items = this->TreeRoot->ChildCount();
320         for (unsigned int x = 0; x < items; x++)
321         {
322                 TreeServer* Route = this->TreeRoot->GetChild(x);
323                 if (Route && Route->GetSocket())
324                 {
325                         TreeSocket* Sock = Route->GetSocket();
326                         if (Sock)
327                                 Sock->WriteLine(FullLine);
328                 }
329         }
330         return true;
331 }
332
333 bool SpanningTreeUtilities::DoOneToMany(const char* prefix, const char* command, std::deque<std::string> &params)
334 {
335         std::string spfx = prefix;
336         std::string scmd = command;
337         return this->DoOneToMany(spfx, scmd, params);
338 }
339
340 bool SpanningTreeUtilities::DoOneToAllButSender(const char* prefix, const char* command, std::deque<std::string> &params, std::string omit)
341 {
342         std::string spfx = prefix;
343         std::string scmd = command;
344         return this->DoOneToAllButSender(spfx, scmd, params, omit);
345 }
346
347 bool SpanningTreeUtilities::DoOneToOne(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string target)
348 {
349         TreeServer* Route = this->BestRouteTo(target);
350         if (Route)
351         {
352                 std::string FullLine = ":" + prefix + " " + command;
353                 unsigned int words = params.size();
354                 for (unsigned int x = 0; x < words; x++)
355                 {
356                         FullLine = FullLine + " " + params[x];
357                 }
358                 if (Route && Route->GetSocket())
359                 {
360                         TreeSocket* Sock = Route->GetSocket();
361                         if (Sock)
362                                 Sock->WriteLine(FullLine);
363                 }
364                 return true;
365         }
366         else
367         {
368                 return false;
369         }
370 }
371
372 void SpanningTreeUtilities::RefreshIPCache()
373 {
374         ValidIPs.clear();
375         for (std::vector<Link>::iterator L = LinkBlocks.begin(); L != LinkBlocks.end(); L++)
376         {
377                 if (L->IPAddr.empty() || L->RecvPass.empty() || L->SendPass.empty() || L->Name.empty() || !L->Port)
378                 {
379                         if (L->Name.empty())
380                         {
381                                 ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"m_spanningtree: Ignoring a malformed link block (all link blocks require a name!)");
382                         }
383                         else
384                         {
385                                 ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"m_spanningtree: Ignoring a link block missing recvpass, sendpass, port or ipaddr.");
386                         }
387
388                         /* Invalid link block */
389                         continue;
390                 }
391
392                 ValidIPs.push_back(L->IPAddr);
393
394                 if (L->AllowMask.length())
395                         ValidIPs.push_back(L->AllowMask);
396
397                 /* Needs resolving */
398                 bool ipvalid = true;
399                 QueryType start_type = DNS_QUERY_A;
400 #ifdef IPV6
401                 start_type = DNS_QUERY_AAAA;
402                 if (strchr(L->IPAddr.c_str(),':'))
403                 {
404                         in6_addr n;
405                         if (inet_pton(AF_INET6, L->IPAddr.c_str(), &n) < 1)
406                                 ipvalid = false;
407                 }
408                 else
409 #endif
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((Module*)this->Creator, this, ServerInstance, 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(ServerInstance);
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                 ServerInstance->BufferedSocketCull();
465                 Bindings.clear();
466
467                 for (int j = 0; j < Conf->Enumerate("bind"); j++)
468                 {
469                         std::string Type = Conf->ReadValue("bind","type",j);
470                         std::string IP = Conf->ReadValue("bind","address",j);
471                         std::string Port = Conf->ReadValue("bind","port",j);
472                         std::string transport = Conf->ReadValue("bind","transport",j);
473                         if (Type == "servers")
474                         {
475                                 irc::portparser portrange(Port, false);
476                                 int portno = -1;
477
478                                 if (IP == "*")
479                                         IP.clear();
480
481                                 while ((portno = portrange.GetToken()))
482                                 {
483                                         if ((!transport.empty()) && (hooks.find(transport.c_str()) ==  hooks.end()))
484                                         {
485                                                 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?");
486                                                 break;
487                                         }
488
489                                         ServerSocketListener *listener = new ServerSocketListener(ServerInstance, this, portno, (char *)IP.c_str());
490                                         if (listener->GetFd() == -1)
491                                         {
492                                                 delete listener;
493                                                 continue;
494                                         }
495
496                                         if (!transport.empty())
497                                                 listener->AddIOHook(hooks[transport.c_str()]);
498
499                                         Bindings.push_back(listener);
500                                 }
501                         }
502                 }
503         }
504         FlatLinks = Conf->ReadFlag("security","flatlinks",0);
505         HideULines = Conf->ReadFlag("security","hideulines",0);
506         AnnounceTSChange = Conf->ReadFlag("options","announcets",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         LinkBlocks.clear();
519         ValidIPs.clear();
520         for (int j = 0; j < Conf->Enumerate("link"); j++)
521         {
522                 Link L;
523                 std::string Allow = Conf->ReadValue("link", "allowmask", j);
524                 L.Name = (Conf->ReadValue("link", "name", j)).c_str();
525                 L.AllowMask = Allow;
526                 L.IPAddr = Conf->ReadValue("link", "ipaddr", j);
527                 L.FailOver = Conf->ReadValue("link", "failover", j).c_str();
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.AutoConnect = Conf->ReadInteger("link", "autoconnect", j, true);
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                 // Fix: Only trip autoconnects if this wouldn't delay autoconnect..
546                 if (L.NextConnectTime > ((time_t)(ServerInstance->Time() + L.AutoConnect)))
547                         L.NextConnectTime = ServerInstance->Time() + L.AutoConnect;
548
549                 if (L.Name.find('.') == std::string::npos)
550                         throw CoreException("The link name '"+assign(L.Name)+"' is invalid and must contain at least one '.' character");
551
552                 if (L.Name.length() > 64)
553                         throw CoreException("The link name '"+assign(L.Name)+"' is longer than 64 characters!");
554
555                 if ((!L.IPAddr.empty()) && (!L.RecvPass.empty()) && (!L.SendPass.empty()) && (!L.Name.empty()) && (L.Port))
556                 {
557                         if (Allow.length())
558                                 ValidIPs.push_back(Allow);
559
560                         ValidIPs.push_back(L.IPAddr);
561
562                         /* Needs resolving */
563                         bool ipvalid = true;
564                         QueryType start_type = DNS_QUERY_A;
565 #ifdef IPV6
566                         start_type = DNS_QUERY_AAAA;
567                         if (strchr(L.IPAddr.c_str(),':'))
568                         {
569                                 in6_addr n;
570                                 if (inet_pton(AF_INET6, L.IPAddr.c_str(), &n) < 1)
571                                         ipvalid = false;
572                         }
573                         else
574                         {
575                                 in_addr n;
576                                 if (inet_aton(L.IPAddr.c_str(),&n) < 1)
577                                         ipvalid = false;
578                         }
579 #else
580                         in_addr n;
581                         if (inet_aton(L.IPAddr.c_str(),&n) < 1)
582                                 ipvalid = false;
583 #endif
584
585                         if (!ipvalid)
586                         {
587                                 try
588                                 {
589                                         bool cached;
590                                         SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L.IPAddr, L, cached, start_type);
591                                         ServerInstance->AddResolver(sr, cached);
592                                 }
593                                 catch (...)
594                                 {
595                                 }
596                         }
597                 }
598                 else
599                 {
600                         if (L.IPAddr.empty())
601                         {
602                                 L.IPAddr = "*";
603                                 ValidIPs.push_back("*");
604                                 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.");
605                         }
606
607                         if (L.RecvPass.empty())
608                         {
609                                 throw CoreException("Invalid configuration for server '"+assign(L.Name)+"', recvpass not defined!");
610                         }
611
612                         if (L.SendPass.empty())
613                         {
614                                 throw CoreException("Invalid configuration for server '"+assign(L.Name)+"', sendpass not defined!");
615                         }
616
617                         if (L.Name.empty())
618                         {
619                                 throw CoreException("Invalid configuration, link tag without a name! IP address: "+L.IPAddr);
620                         }
621
622                         if (!L.Port)
623                         {
624                                 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.");
625                         }
626                 }
627
628                 LinkBlocks.push_back(L);
629         }
630         delete Conf;
631 }
632
633 void SpanningTreeUtilities::DoFailOver(Link* x)
634 {
635         if (x->FailOver.length())
636         {
637                 if (x->FailOver == x->Name)
638                 {
639                         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());
640                         return;
641                 }
642                 Link* TryThisOne = this->FindLink(x->FailOver.c_str());
643                 if (TryThisOne)
644                 {
645                         TreeServer* CheckDupe = this->FindServer(x->FailOver.c_str());
646                         if (CheckDupe)
647                         {
648                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Skipping existing failover: %s", x->FailOver.c_str());
649                         }
650                         else
651                         {
652                                 this->ServerInstance->SNO->WriteToSnoMask('l', "FAILOVER: Trying failover link for \002%s\002: \002%s\002...", x->Name.c_str(), TryThisOne->Name.c_str());
653                                 Creator->ConnectServer(TryThisOne);
654                         }
655                 }
656                 else
657                 {
658                         this->ServerInstance->SNO->WriteToSnoMask('l', "FAILOVER: Invalid failover server specified for server \002%s\002, will not follow!", x->Name.c_str());
659                 }
660         }
661 }
662
663 Link* SpanningTreeUtilities::FindLink(const std::string& name)
664 {
665         for (std::vector<Link>::iterator x = LinkBlocks.begin(); x < LinkBlocks.end(); x++)
666         {
667                 if (InspIRCd::Match(x->Name.c_str(), name.c_str()))
668                 {
669                         return &(*x);
670                 }
671         }
672         return NULL;
673 }