]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Mesh tweaks (wasnt sending the ip in the + packet)
[user/henk/code/inspircd.git] / src / inspircd.cpp
index ca1041e691e5c9fc9caa7ae7ffb64c78bf798016..ca587b58d328649c0a7ff052deac6de4a2784ccc 100644 (file)
@@ -892,6 +892,8 @@ void NetSendToCommon(userrec* u, char* s)
        char buffer[MAXBUF];
        snprintf(buffer,MAXBUF,"%s",s);
        
+       log(DEBUG,"NetSendToCommon: '%s' '%s'",u->nick,s);
+
        for (int j = 0; j < 32; j++)
        {
                if (me[j] != NULL)
@@ -913,6 +915,8 @@ void NetSendToAll(char* s)
        char buffer[MAXBUF];
        snprintf(buffer,MAXBUF,"%s",s);
        
+       log(DEBUG,"NetSendToAll: '%s'",s);
+
        for (int j = 0; j < 32; j++)
        {
                if (me[j] != NULL)
@@ -931,6 +935,8 @@ void NetSendToOne(char* target,char* s)
        char buffer[MAXBUF];
        snprintf(buffer,MAXBUF,"%s",s);
        
+       log(DEBUG,"NetSendToOne: '%s' '%s'",target,s);
+
        for (int j = 0; j < 32; j++)
        {
                if (me[j] != NULL)
@@ -951,6 +957,8 @@ void NetSendToAllExcept(char* target,char* s)
        char buffer[MAXBUF];
        snprintf(buffer,MAXBUF,"%s",s);
        
+       log(DEBUG,"NetSendToAllExcept: '%s' '%s'",target,s);
+       
        for (int j = 0; j < 32; j++)
        {
                if (me[j] != NULL)
@@ -6322,7 +6330,7 @@ void handle_N(char token,char* params,serverrec* source,serverrec* reply, char*
        strncpy(clientlist[nick]->host, host,160);
        strncpy(clientlist[nick]->dhost, dhost,160);
        strncpy(clientlist[nick]->server, server,256);
-       strncpy(clientlist[nick]->ident, ident,10); // +1 char to compensate for '~'
+       strncpy(clientlist[nick]->ident, ident,10); // +1 char to compensate for tilde
        strncpy(clientlist[nick]->fullname, gecos,128);
        clientlist[nick]->signon = TS;
        clientlist[nick]->nping = 0; // this is ignored for a remote user anyway.
@@ -6373,7 +6381,11 @@ void handle_plus(char token,char* params,serverrec* source,serverrec* reply, cha
        char* ipaddr = strtok(NULL," ");
        char* ipport = strtok(NULL," ");
        char* cookie = strtok(NULL," ");
+       log(DEBUG," ");
+       log(DEBUG," ");
+       log(DEBUG,"*** Connecting back to %s:%d",ipaddr,ipport);
        me[defaultRoute]->MeshCookie(ipaddr,atoi(ipport),atoi(cookie),servername);
+       log(DEBUG," ");
 }
 
 
@@ -6432,6 +6444,7 @@ void handle_J(char token,char* params,serverrec* source,serverrec* reply, char*
 void process_restricted_commands(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,char* ipaddr,int port)
 {
        long authcookie = rand()*rand();
+       char buffer[MAXBUF];
 
        switch(token)
        {
@@ -6442,11 +6455,13 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve
                        WriteOpers("Server %s is starting netburst.",udp_host);
                        // now broadcast this new servers address out to all servers that are linked to us,
                        // except the newcomer. They'll all attempt to connect back to it.
-                       char buffer[MAXBUF];
-                       snprintf(buffer,MAXBUF,"+ %s %s %d %d",udp_host,ipaddr,port,authcookie);
-                       NetSendToAllExcept(buffer,udp_host);
+
+                       // give the server its authcookie.
                        snprintf(buffer,MAXBUF,"~ %d",authcookie);
-                       NetSendToAllExcept(buffer,udp_host);
+                       source->SendPacket(buffer,udp_host);
+                       // tell all the other servers to use this authcookie to connect back again
+                       snprintf(buffer,MAXBUF,"+ %s %s %d %d",udp_host,ipaddr,port,authcookie);
+                       NetSendToAllExcept(udp_host,buffer);
                break;
                // ~
                // Store authcookie
@@ -6454,7 +6469,7 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve
                // without user or password, using it.
                case '~':
                        auth_cookies.push_back(atoi(params));
-                       log(DEBUG,"Stored auth cookie, will permit servers with auth-cookie %d",atoi(params));
+                       log(DEBUG,"*** Stored auth cookie, will permit servers with auth-cookie %d",atoi(params));
                break;
                // connect back to a server using an authcookie
                case '+':
@@ -6603,6 +6618,26 @@ void handle_link_packet(char* udp_msg, char* udp_host, serverrec *serv)
                        if (auth_cookies[u] == atoi(cookie))
                        {
                                WriteOpers("Allowed cookie from %s, is now part of the mesh",servername);
+
+
+                               for (int j = 0; j < 32; j++)
+                               {
+                                       if (me[j] != NULL)
+                                       {
+                                               for (int k = 0; k < me[j]->connectors.size(); k++)
+                                               {
+                                                       if (!strcasecmp(me[j]->connectors[k].GetServerName().c_str(),udp_host))
+                                                       {
+                                                               me[j]->connectors[k].SetServerName(servername);
+                                                               return;
+                                                       }
+                                               }
+                                       }
+                                       WriteOpers("\2WARNING!\2 %s sent us an authentication packet but we are not authenticating with this server right now! Possible intrusion attempt!",udp_host);
+                                       return;
+                               }
+
+
                                return;
                        }
                }
@@ -7015,7 +7050,7 @@ int InspIRCd(void)
                                        // during a netburst, send all data to all other linked servers
                                        if ((nb_start>0) && (udp_msg[0] != 'Y') && (udp_msg[0] != 'X') && (udp_msg[0] != 'F'))
                                        {
-                                               NetSendToAllExcept(udp_msg,udp_host);
+                                               NetSendToAllExcept(udp_host,udp_msg);
                                        }
                                        FOREACH_MOD OnPacketReceive(udp_msg);
                                        handle_link_packet(udp_msg, udp_host, me[x]);