summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/connection.h73
-rw-r--r--src/InspIRCd.layout72
-rw-r--r--src/connection.cpp298
-rw-r--r--src/inspircd.cpp306
4 files changed, 395 insertions, 354 deletions
diff --git a/include/connection.h b/include/connection.h
index 57e970431..a18d201ef 100644
--- a/include/connection.h
+++ b/include/connection.h
@@ -18,10 +18,54 @@
#ifndef __CONNECTION_H__
#define __CONNECTION_H__
-#define PT_SYN_ONLY 0
-#define PT_ACK_ONLY 1
-#define PT_SYN_WITH_DATA 2
-#define PT_KEY_EXCHANGE 3
+#define STATE_DISCONNECTED 0
+#define STATE_CONNECTED 1
+#define STATE_SYNC 2
+#define STATE_NOAUTH_INBOUND 3
+#define STATE_NOAUTH_OUTBOUND 4
+
+/** Each connection has one or more of these
+ * each represents ONE outbound connection to another ircd
+ * so each inbound has multiple outbounds.
+ */
+class ircd_connector : public classbase
+{
+ private:
+ /** Sockaddr of the outbound ip and port
+ */
+ sockaddr_in addr;
+
+ /** File descriptor of the outbound connection
+ */
+ int fd;
+
+ /** Server name
+ */
+ std::string servername;
+
+ /** Server names of servers that this server is linked to
+ * So for A->B->C, if this was the record for B it would contain A and C
+ * whilever both servers are connected to B.
+ */
+ std::vector<std::string> routes;
+
+ /** State. STATE_NOAUTH_INBOUND, STATE_NOAUTH_OUTBOUND
+ * STATE_SYNC, STATE_DISCONNECTED, STATE_CONNECTED
+ */
+ int state;
+
+ bool SetHostAddress(char* host, int port);
+
+ public:
+
+ bool MakeOutboundConnection(char* host, int port);
+ std::string GetServerName();
+ void SetServerName(std::string serv);
+ int GetDescriptor();
+ void SetDescriptor(int fd);
+ int GetState();
+ void SetState(int state);
+};
class packet : public classbase
@@ -36,15 +80,6 @@ class packet : public classbase
~packet();
};
-class packet_buf : public classbase
-{
- public:
- packet p;
- char host[128];
- int port;
-};
-
-
class connection : public classbase
{
@@ -68,16 +103,16 @@ class connection : public classbase
time_t nping;
char internal_addr[1024];
int internal_port;
- std::vector<packet_buf> buffer;
+ std::vector<ircd_connector> connectors;
connection();
bool CreateListener(char* host, int p);
- bool BeginLink(char* targethost, int port, char* password);
+ bool BeginLink(char* targethost, int port, char* password, char* servername);
void TerminateLink(char* targethost);
- bool SendPacket(char *message, char* host, int port, long ourkey);
- bool RecvPacket(char *message, char* host, int &prt, long &theirkey);
- bool SendSYN(char* host, int port);
- bool SendACK(char* host, int port, int reply_id);
+ bool SendPacket(char *message, char* host);
+ bool RecvPacket(char *message, char* host);
+ ircd_connector* FindHost(std::string host);
+ bool AddIncoming(int fd,char* targethost);
long GenKey();
};
diff --git a/src/InspIRCd.layout b/src/InspIRCd.layout
index 34d5aea86..eb5b47e83 100644
--- a/src/InspIRCd.layout
+++ b/src/InspIRCd.layout
@@ -1,6 +1,6 @@
[Editors]
Focused=1
-Order=1,2,-1,4,6,3,7,25,5,24
+Order=1,2,4,6,3,7,25,5,24,-1
[Editor_0]
Open=0
@@ -13,9 +13,9 @@ LeftChar=1
[Editor_1]
Open=1
Top=1
-CursorCol=16
-CursorRow=7310
-TopLine=7256
+CursorCol=27
+CursorRow=6771
+TopLine=6743
LeftChar=1
[Editor_2]
@@ -31,7 +31,7 @@ Open=1
Top=0
CursorCol=3
CursorRow=81
-TopLine=26
+TopLine=2
LeftChar=1
[Editor_4]
@@ -67,7 +67,7 @@ TopLine=6
LeftChar=1
[Editor_8]
-Open=1
+Open=0
Top=0
CursorCol=1
CursorRow=33
@@ -75,7 +75,7 @@ TopLine=1
LeftChar=1
[Editor_9]
-Open=1
+Open=0
Top=0
CursorCol=1
CursorRow=113
@@ -83,7 +83,7 @@ TopLine=58
LeftChar=1
[Editor_10]
-Open=1
+Open=0
Top=0
CursorCol=1
CursorRow=102
@@ -99,7 +99,7 @@ TopLine=1
LeftChar=1
[Editor_12]
-Open=1
+Open=0
Top=0
CursorCol=12
CursorRow=104
@@ -109,13 +109,13 @@ LeftChar=1
[Editor_13]
Open=1
Top=0
-CursorCol=18
-CursorRow=16
-TopLine=1
+CursorCol=28
+CursorRow=21
+TopLine=4
LeftChar=1
[Editor_14]
-Open=1
+Open=0
Top=0
CursorCol=1
CursorRow=45
@@ -131,7 +131,7 @@ TopLine=50
LeftChar=1
[Editor_16]
-Open=1
+Open=0
Top=0
CursorCol=6
CursorRow=32
@@ -139,7 +139,7 @@ TopLine=1
LeftChar=1
[Editor_17]
-Open=1
+Open=0
Top=0
CursorCol=47
CursorRow=118
@@ -147,7 +147,7 @@ TopLine=64
LeftChar=1
[Editor_18]
-Open=1
+Open=0
Top=0
CursorCol=69
CursorRow=31
@@ -155,7 +155,7 @@ TopLine=1
LeftChar=1
[Editor_19]
-Open=1
+Open=0
Top=0
CursorCol=21
CursorRow=7
@@ -163,7 +163,7 @@ TopLine=1
LeftChar=1
[Editor_20]
-Open=1
+Open=0
Top=0
CursorCol=69
CursorRow=37
@@ -171,7 +171,7 @@ TopLine=1
LeftChar=1
[Editor_21]
-Open=1
+Open=0
Top=0
CursorCol=1
CursorRow=63
@@ -179,7 +179,7 @@ TopLine=14
LeftChar=1
[Editor_22]
-Open=1
+Open=0
Top=0
CursorCol=15
CursorRow=121
@@ -187,7 +187,7 @@ TopLine=83
LeftChar=1
[Editor_23]
-Open=1
+Open=0
Top=0
CursorCol=1
CursorRow=1
@@ -197,9 +197,9 @@ LeftChar=1
[Editor_24]
Open=1
Top=0
-CursorCol=13
-CursorRow=83
-TopLine=56
+CursorCol=36
+CursorRow=177
+TopLine=149
LeftChar=1
[Editor_25]
Open=1
@@ -216,84 +216,84 @@ CursorRow=13
TopLine=23
LeftChar=1
[Editor_27]
-Open=1
+Open=0
Top=0
CursorCol=3
CursorRow=67
TopLine=34
LeftChar=1
[Editor_28]
-Open=1
+Open=0
Top=0
CursorCol=87
CursorRow=20
TopLine=5
LeftChar=1
[Editor_29]
-Open=1
+Open=0
Top=0
CursorCol=70
CursorRow=21
TopLine=1
LeftChar=1
[Editor_30]
-Open=1
+Open=0
Top=0
CursorCol=87
CursorRow=21
TopLine=1
LeftChar=4
[Editor_31]
-Open=1
+Open=0
Top=0
CursorCol=2
CursorRow=40
TopLine=8
LeftChar=1
[Editor_32]
-Open=1
+Open=0
Top=0
CursorCol=1
CursorRow=1
TopLine=1
LeftChar=1
[Editor_33]
-Open=1
+Open=0
Top=0
CursorCol=23
CursorRow=36
TopLine=1
LeftChar=1
[Editor_34]
-Open=1
+Open=0
Top=0
CursorCol=38
CursorRow=35
TopLine=8
LeftChar=1
[Editor_35]
-Open=1
+Open=0
Top=0
CursorCol=1
CursorRow=29
TopLine=1
LeftChar=1
[Editor_36]
-Open=1
+Open=0
Top=0
CursorCol=1
CursorRow=34
TopLine=1
LeftChar=1
[Editor_37]
-Open=1
+Open=0
Top=0
CursorCol=20
CursorRow=103
TopLine=70
LeftChar=1
[Editor_38]
-Open=1
+Open=0
Top=0
CursorCol=1
CursorRow=70
diff --git a/src/connection.cpp b/src/connection.cpp
index 4867cc55b..e2be63c33 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -4,14 +4,19 @@
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/utsname.h>
+#include <vector>
+#include <string>
#include "inspircd.h"
#include "modules.h"
+using namespace std;
+
extern std::vector<Module*> modules;
extern std::vector<ircd_module*> factory;
extern int MODCOUNT;
+
packet::packet()
{
srand(time(NULL));
@@ -37,7 +42,7 @@ bool connection::CreateListener(char* host, int p)
int on = 0;
struct linger linger = { 0 };
- fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd <= 0)
{
return false;
@@ -81,195 +86,200 @@ bool connection::CreateListener(char* host, int p)
int recvbuf = 32768;
setsockopt(fd,SOL_SOCKET,SO_SNDBUF,(const void *)&sendbuf,sizeof(sendbuf));
setsockopt(fd,SOL_SOCKET,SO_RCVBUF,(const void *)&recvbuf,sizeof(sendbuf));
+
+ listen(this->fd,5);
return true;
}
+bool ircd_connector::SetHostAddress(char* host, int port)
+{
+ memset((void*)&addr, 0, sizeof(addr));
+ addr.sin_family = AF_INET;
+ inet_aton(host,&addr.sin_addr);
+ addr.sin_port = htons(port);
+ return true;
+}
+
+bool ircd_connector::MakeOutboundConnection(char* host, int port)
+{
+ hostent* hoste = gethostbyname(host);
+ if (!hoste)
+ {
+ WriteOpers("Failed to look up hostname for %s, using as an ip address",host);
+ this->SetHostAddress(host,port);
+ }
+ else
+ {
+ WriteOpers("Found hostname for %s",host);
+ this->SetHostAddress(hoste->h_addr,port);
+ }
+
+ this->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (this->fd >= 0)
+ {
+ if(connect(this->fd, (sockaddr*)&addr,sizeof(addr)))
+ {
+ WriteOpers("connect() failed for %s",host);
+ return false;
+ }
+ int flags = fcntl(this->fd, F_GETFL, 0);
+ fcntl(this->fd, F_SETFL, flags | O_NONBLOCK);
+ int sendbuf = 32768;
+ int recvbuf = 32768;
+ setsockopt(this->fd,SOL_SOCKET,SO_SNDBUF,(const void *)&sendbuf,sizeof(sendbuf));
+ setsockopt(this->fd,SOL_SOCKET,SO_RCVBUF,(const void *)&recvbuf,sizeof(sendbuf));
+ return true;
+ }
+ else
+ {
+ WriteOpers("socket() failed!");
+ }
+
+ return false;
+}
+
-bool connection::BeginLink(char* targethost, int port, char* password)
+bool connection::BeginLink(char* targethost, int port, char* password, char* servername)
{
char connect[MAXBUF];
+ ircd_connector connector;
+
if (this->fd)
{
- sprintf(connect,"S %s %s :%s",getservername().c_str(),password,getserverdesc().c_str());
- this->haspassed = false;
- return this->SendPacket(connect, targethost, port, 0);
+ if (connector.MakeOutboundConnection(targethost,port))
+ {
+ // targethost has been turned into an ip...
+ // we dont want this as the server name.
+ connector.SetServerName(servername);
+ sprintf(connect,"S %s %s :%s",getservername().c_str(),password,getserverdesc().c_str());
+ connector.SetState(STATE_NOAUTH_OUTBOUND);
+ this->connectors.push_back(connector);
+ return this->SendPacket(connect, servername);
+ }
+ else
+ {
+ WriteOpers("Could not create outbound connection to %s:%d",targethost,port);
+ }
}
return false;
}
-// targethost: in dot notation a.b.c.d
-void connection::TerminateLink(char* targethost)
+bool connection::AddIncoming(int fd,char* targethost)
{
+ char connect[MAXBUF];
+
+ ircd_connector connector;
+
+ // targethost has been turned into an ip...
+ // we dont want this as the server name.
+ connector.SetServerName(targethost);
+ connector.SetDescriptor(fd);
+ connector.SetState(STATE_NOAUTH_INBOUND);
+ this->connectors.push_back(connector);
+ return true;
}
-// host: in dot notation a.b.c.d
-// port: host byte order
-bool connection::SendPacket(char *message, char* host, int port, long ourkey)
+void connection::TerminateLink(char* targethost)
{
- sockaddr_in host_address;
- in_addr addy;
- packet p;
-
- memset((void*)&host_address, 0, sizeof(host_address));
-
- host_address.sin_family = AF_INET;
- inet_aton(host,&addy);
- host_address.sin_addr = addy;
-
- host_address.sin_port = htons(port);
-
- strcpy(p.data,message);
- p.type = PT_SYN_WITH_DATA;
- p.key = ourkey;
-
-
- FOREACH_MOD OnPacketTransmit(p.data);
+ // this locates the targethost in the connection::connectors vector of the class,
+ // and terminates it by sending it an SQUIT token and closing its descriptor.
+ // TerminateLink with a null string causes a terminate of ALL links
+}
- log(DEBUG,"main: Connection::SendPacket() sent '%s' to %s:%d",p.data,host,port);
- // returns false if the packet could not be sent (e.g. target host down)
- if (sendto(this->fd,&p,sizeof(p),0,(sockaddr*)&host_address,sizeof(host_address))<0)
+// Returns a pointer to the connector for 'host'
+ircd_connector* connection::FindHost(std::string host)
+{
+ for (int i = 0; i < this->connectors.size(); i++)
{
- log(DEBUG,"sendto() failed for Connection::SendPacket() with a packet of size %d",sizeof(p));
- return false;
+ if (this->connectors[i].GetServerName() == host)
+ {
+ return &this->connectors[i];
+ }
}
- return true;
-
+ return NULL;
}
-bool connection::SendSYN(char* host, int port)
+std::string ircd_connector::GetServerName()
{
- sockaddr_in host_address;
- in_addr addy;
- packet p;
-
- memset((void*)&host_address, 0, sizeof(host_address));
-
- host_address.sin_family = AF_INET;
- inet_aton(host,&addy);
- host_address.sin_addr = addy;
-
- host_address.sin_port = htons(port);
-
- p.type = PT_SYN_ONLY;
- p.key = key;
- strcpy(p.data,"");
-
- if (sendto(fd,&p,sizeof(p),0,(sockaddr*)&host_address,sizeof(host_address))<0)
- {
- return false;
- }
- return true;
-
+ return this->servername;
}
-bool connection::SendACK(char* host, int port, int reply_id)
+void ircd_connector::SetServerName(std::string serv)
{
- sockaddr_in host_address;
- in_addr addy;
- packet p;
-
- memset((void*)&host_address, 0, sizeof(host_address));
-
- host_address.sin_family = AF_INET;
- inet_aton(host,&addy);
- host_address.sin_addr = addy;
-
- host_address.sin_port = htons(port);
+ this->servername = serv;
+}
- p.type = PT_ACK_ONLY;
- p.key = key;
- p.id = reply_id;
- strcpy(p.data,"");
- if (sendto(fd,&p,sizeof(p),0,(sockaddr*)&host_address,sizeof(host_address))<0)
- {
- return false;
- }
- return true;
+int ircd_connector::GetDescriptor()
+{
+ return this->fd;
+}
+int ircd_connector::GetState()
+{
+ return this->state;
}
-// Generates a server key. This is pseudo-random.
-// the server always uses the same server-key in all communications
-// across the network. All other servers must remember the server key
-// of servers in the network, e.g.:
-//
-// ServerA: key=5555555555
-// ServerB: key=6666666666
-// I am ServerC: key=77777777777
-//
-// If ServerC sees a packet from ServerA, and the key stored for ServerA
-// is 0, then cache the key as the servers key.
-// after this point, any packet from ServerA which does not contain its key,
-// 555555555, will be silently dropped.
-// This should prevent blind spoofing, as to fake a server you must know its
-// assigned key, and to do that you must receive messages that are origintated
-// from it or hack the running executable.
-//
-// During the AUTH phase (when server passwords are checked, the key in any
-// packet MUST be 0). Only the initial SERVER/PASS packets may have a key
-// of 0 (and any ACK responses to them).
-//
+void ircd_connector::SetState(int state)
+{
+ this->state = state;
+}
-long connection::GenKey()
+void ircd_connector::SetDescriptor(int fd)
{
- srand(time(NULL));
- return (random()*time(NULL));
+ this->fd = fd;
}
-// host: in dot notation a.b.c.d
-// port: host byte order
-bool connection::RecvPacket(char *message, char* host, int &prt, long &theirkey)
+bool connection::SendPacket(char *message, char* host)
{
- // returns false if no packet waiting for receive, e.g. EAGAIN or ECONNRESET
- sockaddr_in host_address;
- socklen_t host_address_size;
- packet p;
+ ircd_connector* cn = this->FindHost(host);
- memset((void*)&host_address, 0, sizeof(host_address));
-
- host_address.sin_family=AF_INET;
- host_address_size=sizeof(host_address);
-
- if (recvfrom(fd,&p,sizeof(p),0,(sockaddr*)&host_address,&host_address_size)<0)
+ if (cn)
{
- return false;
- }
-
- log(DEBUG,"connection::RecvPacket(): received packet type %d '%s'",p.type,p.data);
-
- if (p.type == PT_SYN_ONLY)
- {
- strcpy(message,p.data);
- strcpy(host,inet_ntoa(host_address.sin_addr));
- prt = ntohs(host_address.sin_port);
- SendACK(host,this->port,p.id);
- return false;
+ log(DEBUG,"main: Connection::SendPacket() sent '%s' to %s",message,cn->GetServerName().c_str());
+
+ strncat(message,"\n",MAXBUF);
+ // returns false if the packet could not be sent (e.g. target host down)
+ if (send(cn->GetDescriptor(),message,strlen(message),0)<0)
+ {
+ log(DEBUG,"send() failed for Connection::SendPacket(): %s",strerror(errno));
+ return false;
+ }
+ return true;
}
+}
- if (p.type == PT_ACK_ONLY)
- {
- strcpy(message,p.data);
- strcpy(host,inet_ntoa(host_address.sin_addr));
- prt = ntohs(host_address.sin_port);
- return false;
- }
+// receives a packet from any where there is data waiting, first come, first served
+// fills the message and host values with the host where the data came from.
- if (p.type == PT_SYN_WITH_DATA)
+bool connection::RecvPacket(char *message, char* host)
+{
+ for (int i = 0; i < this->connectors.size(); i++)
{
- strcpy(message,p.data);
- strcpy(host,inet_ntoa(host_address.sin_addr));
- theirkey = p.key;
- prt = ntohs(host_address.sin_port);
- SendACK(host,this->port,p.id);
- return true;
+ // returns false if the packet could not be sent (e.g. target host down)
+ int rcvsize = 0;
+ if (rcvsize = recv(this->connectors[i].GetDescriptor(),message,MAXBUF,0))
+ {
+ if (rcvsize > 0)
+ {
+ // something new on this socket, fill the return values and bail
+ strncpy(host,this->connectors[i].GetServerName().c_str(),160);
+ message[rcvsize-1] = 0;
+ return true;
+ }
+ }
}
+ // nothing new yet -- message and host will be undefined
+ return false;
+}
- log(DEBUG,"connection::RecvPacket(): Invalid packet type %d (protocol error)",p.type);
- return true;
+long connection::GenKey()
+{
+ srand(time(NULL));
+ return (random()*time(NULL));
}
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 597705015..044719b7e 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -960,7 +960,7 @@ void ChangeName(userrec* user, const char* gecos)
{
if (strcmp(servers[j]->name,ServerName))
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent a token");
}
}
@@ -978,7 +978,7 @@ void ChangeDisplayedHost(userrec* user, const char* host)
{
if (strcmp(servers[j]->name,ServerName))
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent b token");
}
}
@@ -1021,7 +1021,7 @@ void WriteWallOps(userrec *source, bool local_only, char* text, ...)
{
if (strcmp(servers[j]->name,ServerName))
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent @ token");
}
}
@@ -1654,7 +1654,7 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
{
if (servers[j] != NULL)
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent J token");
}
}
@@ -1726,7 +1726,7 @@ chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool
{
if (servers[j] != NULL)
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent L token (with reason)");
}
}
@@ -1744,7 +1744,7 @@ chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool
{
if (servers[j] != NULL)
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent L token (no reason)");
}
}
@@ -2678,7 +2678,7 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
{
if (strcmp(servers[j]->name,ServerName))
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent M token");
}
}
@@ -2700,7 +2700,7 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
{
if (strcmp(servers[j]->name,ServerName))
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent m token");
}
}
@@ -2995,7 +2995,7 @@ void handle_mode(char **parameters, int pcnt, userrec *user)
{
if (strcmp(servers[j]->name,ServerName))
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent m token");
}
}
@@ -3220,7 +3220,7 @@ void server_mode(char **parameters, int pcnt, userrec *user)
{
if (strcmp(servers[j]->name,ServerName))
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent m token");
}
}
@@ -3850,7 +3850,7 @@ void handle_kick(char **parameters, int pcnt, userrec *user)
{
if (servers[j] != NULL)
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent k token");
}
}
@@ -3921,7 +3921,7 @@ void kill_link(userrec *user,const char* r)
{
if (strcmp(servers[j]->name,ServerName))
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent Q token");
}
}
@@ -3979,7 +3979,7 @@ void handle_kill(char **parameters, int pcnt, userrec *user)
{
if (strcmp(servers[j]->name,ServerName))
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent K token");
}
}
@@ -4116,7 +4116,7 @@ void handle_invite(char **parameters, int pcnt, userrec *user)
{
if (strcmp(servers[j]->name,ServerName))
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent i token");
}
}
@@ -4185,7 +4185,7 @@ void handle_topic(char **parameters, int pcnt, userrec *user)
{
if (strcmp(servers[j]->name,ServerName))
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent t token");
}
}
@@ -4492,7 +4492,7 @@ void handle_privmsg(char **parameters, int pcnt, userrec *user)
{
if (ChanAnyOnThisServer(chan,servers[j]->name))
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
}
}
}
@@ -4539,7 +4539,7 @@ void handle_privmsg(char **parameters, int pcnt, userrec *user)
// direct write, same server
char buffer[MAXBUF];
snprintf(buffer,MAXBUF,"P %s %s :%s",user->nick,dest->nick,parameters[1]);
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
}
}
}
@@ -4595,7 +4595,7 @@ void handle_notice(char **parameters, int pcnt, userrec *user)
{
if (ChanAnyOnThisServer(chan,servers[j]->name))
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
}
}
}
@@ -4634,7 +4634,7 @@ void handle_notice(char **parameters, int pcnt, userrec *user)
// direct write, same server
char buffer[MAXBUF];
snprintf(buffer,MAXBUF,"V %s %s :%s",user->nick,dest->nick,parameters[1]);
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
}
}
}
@@ -4764,7 +4764,7 @@ void send_network_quit(const char* nick, const char* reason)
{
if (servers[j] != NULL)
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent Q token");
}
}
@@ -4801,7 +4801,7 @@ void handle_quit(char **parameters, int pcnt, userrec *user)
{
if (servers[j] != NULL)
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent Q token");
}
}
@@ -4818,7 +4818,7 @@ void handle_quit(char **parameters, int pcnt, userrec *user)
{
if (servers[j] != NULL)
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent Q token");
}
}
@@ -5106,7 +5106,7 @@ void ConnectUser(userrec *user)
{
if (strcmp(servers[j]->name,ServerName))
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent N token");
}
}
@@ -5455,13 +5455,9 @@ void handle_connect(char **parameters, int pcnt, userrec *user)
servers[j] = new serverrec;
//servers[j]->initiator = true;
strcpy(servers[j]->internal_addr,Link_IPAddr);
- servers[j]->internal_port = LinkPort;
strcpy(servers[j]->name,Link_ServerName);
log(DEBUG,"Allocated new serverrec");
- if (!me[defaultRoute]->BeginLink(Link_IPAddr,LinkPort,Link_Pass))
- {
- WriteServ(user->fd,"NOTICE %s :*** Failed to send auth packet to %s!",user->nick,Link_IPAddr);
- }
+ me[defaultRoute]->BeginLink(Link_IPAddr,LinkPort,Link_Pass,Link_ServerName);
return;
}
}
@@ -5648,7 +5644,7 @@ void handle_nick(char **parameters, int pcnt, userrec *user)
{
if (strcmp(servers[j]->name,ServerName))
{
- me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+ me[defaultRoute]->SendPacket(buffer,servers[j]->name);
log(DEBUG,"Sent n token");
}
}
@@ -6097,51 +6093,51 @@ void process_buffer(const char* cmdbuf,userrec *user)
}
}
-void DoSync(serverrec* serv, char* udp_host,int udp_port, long MyKey)
+void DoSync(serverrec* serv, char* udp_host)
{
char data[MAXBUF];
// send start of sync marker: Y <timestamp>
// at this point the ircd receiving it starts broadcasting this netburst to all ircds
// except the ones its receiving it from.
snprintf(data,MAXBUF,"Y %d",time(NULL));
- serv->SendPacket(data,udp_host,udp_port,MyKey);
+ serv->SendPacket(data,udp_host);
// send users and channels
for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
{
snprintf(data,MAXBUF,"N %d %s %s %s %s +%s %s :%s",u->second->age,u->second->nick,u->second->host,u->second->dhost,u->second->ident,u->second->modes,u->second->server,u->second->fullname);
- serv->SendPacket(data,udp_host,udp_port,MyKey);
+ serv->SendPacket(data,udp_host);
if (strcmp(chlist(u->second),""))
{
snprintf(data,MAXBUF,"J %s %s",u->second->nick,chlist(u->second));
- serv->SendPacket(data,udp_host,udp_port,MyKey);
+ serv->SendPacket(data,udp_host);
}
}
// send channel modes, topics etc...
for (chan_hash::iterator c = chanlist.begin(); c != chanlist.end(); c++)
{
snprintf(data,MAXBUF,"M %s +%s",c->second->name,chanmodes(c->second));
- serv->SendPacket(data,udp_host,udp_port,MyKey);
+ serv->SendPacket(data,udp_host);
if (strcmp(c->second->topic,""))
{
snprintf(data,MAXBUF,"T %d %s %s :%s",c->second->topicset,c->second->setby,c->second->name,c->second->topic);
- serv->SendPacket(data,udp_host,udp_port,MyKey);
+ serv->SendPacket(data,udp_host);
}
// send current banlist
for (BanList::iterator b = c->second->bans.begin(); b != c->second->bans.end(); b++)
{
snprintf(data,MAXBUF,"M %s +b %s",b->set_time,c->second->name,b->data);
- serv->SendPacket(data,udp_host,udp_port,MyKey);
+ serv->SendPacket(data,udp_host);
}
}
// send end of sync marker: E <timestamp>
snprintf(data,MAXBUF,"F %d",time(NULL));
- serv->SendPacket(data,udp_host,udp_port,MyKey);
+ serv->SendPacket(data,udp_host);
// ircd sends its serverlist after the end of sync here
}
-void handle_V(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+void handle_V(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
char* src = strtok(params," ");
char* dest = strtok(NULL," :");
@@ -6170,7 +6166,7 @@ void handle_V(char token,char* params,serverrec* source,serverrec* reply, char*
}
-void handle_P(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+void handle_P(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
char* src = strtok(params," ");
char* dest = strtok(NULL," :");
@@ -6198,7 +6194,7 @@ void handle_P(char token,char* params,serverrec* source,serverrec* reply, char*
}
-void handle_i(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+void handle_i(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
char* nick = strtok(params," ");
char* from = strtok(NULL," ");
@@ -6213,7 +6209,7 @@ void handle_i(char token,char* params,serverrec* source,serverrec* reply, char*
}
}
-void handle_t(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+void handle_t(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
char* setby = strtok(params," ");
char* channel = strtok(NULL," :");
@@ -6230,7 +6226,7 @@ void handle_t(char token,char* params,serverrec* source,serverrec* reply, char*
}
-void handle_T(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+void handle_T(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
char* tm = strtok(params," ");
char* setby = strtok(NULL," ");
@@ -6251,7 +6247,7 @@ void handle_T(char token,char* params,serverrec* source,serverrec* reply, char*
}
}
-void handle_M(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+void handle_M(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
char* pars[128];
char original[MAXBUF],target[MAXBUF];
@@ -6277,7 +6273,7 @@ void handle_M(char token,char* params,serverrec* source,serverrec* reply, char*
// m is modes set by users only (not servers) valid targets are channels or users.
-void handle_m(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+void handle_m(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
// m blah #chatspike +b *!test@*4
char* pars[128];
@@ -6311,7 +6307,7 @@ void handle_m(char token,char* params,serverrec* source,serverrec* reply, char*
}
-void handle_L(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+void handle_L(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
char* nick = strtok(params," ");
char* channel = strtok(NULL," :");
@@ -6331,7 +6327,7 @@ void handle_L(char token,char* params,serverrec* source,serverrec* reply, char*
}
}
-void handle_K(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+void handle_K(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
char* src = strtok(params," ");
char* nick = strtok(NULL," :");
@@ -6351,7 +6347,7 @@ void handle_K(char token,char* params,serverrec* source,serverrec* reply, char*
}
}
-void handle_Q(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+void handle_Q(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
char* nick = strtok(params," :");
char* reason = strtok(NULL,"\r\n");
@@ -6384,7 +6380,7 @@ void handle_Q(char token,char* params,serverrec* source,serverrec* reply, char*
}
}
-void handle_n(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+void handle_n(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
char* oldnick = strtok(params," ");
char* newnick = strtok(NULL," ");
@@ -6403,7 +6399,7 @@ void handle_n(char token,char* params,serverrec* source,serverrec* reply, char*
}
// k <SOURCE> <DEST> <CHANNEL> :<REASON>
-void handle_k(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+void handle_k(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
char* src = strtok(params," ");
char* dest = strtok(NULL," ");
@@ -6419,7 +6415,7 @@ void handle_k(char token,char* params,serverrec* source,serverrec* reply, char*
}
}
-void handle_AT(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+void handle_AT(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
char* who = strtok(params," :");
char* text = strtok(NULL,"\r\n");
@@ -6432,7 +6428,7 @@ void handle_AT(char token,char* params,serverrec* source,serverrec* reply, char*
}
-void handle_N(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+void handle_N(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
char* tm = strtok(params," ");
char* nick = strtok(NULL," ");
@@ -6483,14 +6479,14 @@ void handle_N(char token,char* params,serverrec* source,serverrec* reply, char*
}
}
-void handle_F(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+void handle_F(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
long tdiff = time(NULL) - atoi(params);
if (tdiff)
WriteOpers("TS split for %s -> %s: %d",source->name,reply->name,tdiff);
}
-void handle_a(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+void handle_a(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
char* nick = strtok(params," :");
char* gecos = strtok(NULL,"\r\n");
@@ -6501,7 +6497,7 @@ void handle_a(char token,char* params,serverrec* source,serverrec* reply, char*
strncpy(user->fullname,gecos,MAXBUF);
}
-void handle_b(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+void handle_b(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
char* nick = strtok(params," :");
char* host = strtok(NULL,"\r\n");
@@ -6513,7 +6509,7 @@ void handle_b(char token,char* params,serverrec* source,serverrec* reply, char*
}
-void handle_J(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port)
+void handle_J(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
// IMPORTANT NOTE
// The J token currently has no timestamp - this needs looking at
@@ -6565,7 +6561,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,int udp_port)
+void process_restricted_commands(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
switch(token)
{
@@ -6578,7 +6574,7 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve
// ?
// ping
case '?':
- reply->SendPacket("!",udp_host,udp_port,MyKey);
+ reply->SendPacket("!",udp_host);
break;
// ?
// pong
@@ -6591,95 +6587,98 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve
// N <TS> <NICK> <HOST> <DHOST> <IDENT> <MODES> <SERVER> :<GECOS>
// introduce remote client
case 'N':
- handle_N(token,params,source,reply,udp_host,udp_port);
+ handle_N(token,params,source,reply,udp_host);
break;
// a <NICK> :<GECOS>
// change GECOS (SETNAME)
case 'a':
- handle_a(token,params,source,reply,udp_host,udp_port);
+ handle_a(token,params,source,reply,udp_host);
break;
// b <NICK> :<HOST>
// change displayed host (SETHOST)
case 'b':
- handle_b(token,params,source,reply,udp_host,udp_port);
+ handle_b(token,params,source,reply,udp_host);
break;
// t <NICK> <CHANNEL> :<TOPIC>
// change a channel topic
case 't':
- handle_t(token,params,source,reply,udp_host,udp_port);
+ handle_t(token,params,source,reply,udp_host);
break;
// i <NICK> <CHANNEL>
// invite a user to a channel
case 'i':
- handle_i(token,params,source,reply,udp_host,udp_port);
+ handle_i(token,params,source,reply,udp_host);
break;
// k <SOURCE> <DEST> <CHANNEL> :<REASON>
// kick a user from a channel
case 'k':
- handle_k(token,params,source,reply,udp_host,udp_port);
+ handle_k(token,params,source,reply,udp_host);
break;
// n <NICK> <NEWNICK>
// change nickname of client -- a server should only be able to
// change the nicknames of clients that reside on it unless
// they are ulined.
case 'n':
- handle_n(token,params,source,reply,udp_host,udp_port);
+ handle_n(token,params,source,reply,udp_host);
break;
// J <NICK> <CHANLIST>
// Join user to channel list, merge channel permissions
case 'J':
- handle_J(token,params,source,reply,udp_host,udp_port);
+ handle_J(token,params,source,reply,udp_host);
break;
// T <TS> <CHANNEL> <TOPICSETTER> :<TOPIC>
// change channel topic (netburst only)
case 'T':
- handle_T(token,params,source,reply,udp_host,udp_port);
+ handle_T(token,params,source,reply,udp_host);
break;
// M <TARGET> <MODES> [MODE-PARAMETERS]
// Server setting modes on an object
case 'M':
- handle_M(token,params,source,reply,udp_host,udp_port);
+ handle_M(token,params,source,reply,udp_host);
break;
// m <SOURCE> <TARGET> <MODES> [MODE-PARAMETERS]
// User setting modes on an object
case 'm':
- handle_m(token,params,source,reply,udp_host,udp_port);
+ handle_m(token,params,source,reply,udp_host);
break;
// P <SOURCE> <TARGET> :<TEXT>
// Send a private/channel message
case 'P':
- handle_P(token,params,source,reply,udp_host,udp_port);
+ handle_P(token,params,source,reply,udp_host);
break;
// V <SOURCE> <TARGET> :<TEXT>
// Send a private/channel notice
case 'V':
- handle_V(token,params,source,reply,udp_host,udp_port);
+ handle_V(token,params,source,reply,udp_host);
break;
// L <SOURCE> <CHANNEL> :<REASON>
// User parting a channel
case 'L':
- handle_L(token,params,source,reply,udp_host,udp_port);
+ handle_L(token,params,source,reply,udp_host);
break;
// Q <SOURCE> :<REASON>
// user quitting
case 'Q':
- handle_Q(token,params,source,reply,udp_host,udp_port);
+ handle_Q(token,params,source,reply,udp_host);
break;
// K <SOURCE> <DEST> :<REASON>
// remote kill
case 'K':
- handle_K(token,params,source,reply,udp_host,udp_port);
+ handle_K(token,params,source,reply,udp_host);
break;
// @ <SOURCE> :<TEXT>
// wallops
case '@':
- handle_AT(token,params,source,reply,udp_host,udp_port);
+ handle_AT(token,params,source,reply,udp_host);
break;
// F <TS>
// end netburst
case 'F':
WriteOpers("Server %s has completed netburst. (%d secs)",source->name,time(NULL)-nb_start);
- handle_F(token,params,source,reply,udp_host,udp_port);
+ handle_F(token,params,source,reply,udp_host);
+ WriteOpers("Sending my netburst to %s",source->name);
+ DoSync(serv,udp_host);
+ WriteOpers("Send of netburst to %s completed",source->name);
break;
// anything else
default:
@@ -6689,7 +6688,7 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve
}
-void handle_link_packet(long theirkey, char* udp_msg, char* udp_host, int udp_port, serverrec *serv)
+void handle_link_packet(char* udp_msg, char* udp_host, serverrec *serv)
{
char response[10240];
char token = udp_msg[0];
@@ -6724,65 +6723,43 @@ void handle_link_packet(long theirkey, char* udp_msg, char* udp_host, int udp_po
ConfValue("link","sendpass",i,Link_SendPass,&config_f);
log(DEBUG,"(%d) Comparing against name='%s', ipaddr='%s', port='%s', recvpass='%s'",i,Link_ServerName,Link_IPAddr,Link_Port,Link_Pass);
LinkPort = atoi(Link_Port);
- if (!strcasecmp(Link_ServerName,servername)) {
- if (!strcasecmp(Link_IPAddr,udp_host)) {
- if (LinkPort == udp_port) {
- // we have a matching link line -
- // send a 'diminutive' server message back...
- snprintf(response,10240,"s %s %s :%s",ServerName,Link_SendPass,ServerDesc);
- serv->SendPacket(response,udp_host,udp_port,0);
- WriteOpers("CONNECT from %s accepted, authenticating",servername);
- for (int j = 0; j < 255; j++) {
- if (servers[j] == NULL) {
- servers[j] = new serverrec;
- strcpy(servers[j]->internal_addr,udp_host);
- strcpy(servers[j]->name,servername);
- strcpy(servers[j]->description,serverdesc);
- servers[j]->internal_port = udp_port;
- // create a server record for this server
- WriteOpers("Server %s authenticated, exchanging server keys...",servername);
- snprintf(response,10240,"O %d",MyKey);
- serv->SendPacket(response,udp_host,udp_port,0);
- return;
- }
+ if (!strcasecmp(Link_ServerName,servername))
+ {
+ if (!strcasecmp(Link_IPAddr,udp_host))
+ {
+ // we have a matching link line -
+ // send a 'diminutive' server message back...
+ snprintf(response,10240,"s %s %s :%s",ServerName,Link_SendPass,ServerDesc);
+ serv->SendPacket(response,udp_host);
+ WriteOpers("CONNECT from %s accepted, authenticating",servername);
+ for (int j = 0; j < 255; j++)
+ {
+ if (servers[j] == NULL)
+ {
+ servers[j] = new serverrec;
+ strcpy(servers[j]->internal_addr,udp_host);
+ strcpy(servers[j]->name,servername);
+ strcpy(servers[j]->description,serverdesc);
+ // create a server record for this server
+ WriteOpers("Server %s authenticated, exchanging server keys...",servername);
+ snprintf(response,10240,"O %d",MyKey);
+ serv->SendPacket(response,udp_host);
+ return;
}
- WriteOpers("Internal error connecting to %s, failed to create server record!",servername);
- return;
}
- else {
- log(DEBUG,"Port numbers '%d' and '%d' don't match",LinkPort,udp_port);
- }
- }
- else {
- log(DEBUG,"IP Addresses '%s' and '%s' don't match",Link_IPAddr,udp_host);
+ WriteOpers("Internal error connecting to %s, failed to create server record!",servername);
+ return;
}
}
else {
log(DEBUG,"Server names '%s' and '%s' don't match",Link_ServerName,servername);
}
}
- serv->SendPacket("E :Access is denied (no matching link block)",udp_host,udp_port,0);
+ serv->SendPacket("E :Access is denied (no matching link block)",udp_host);
WriteOpers("CONNECT from %s denied, no matching link block",servername);
return;
}
else
- if (token == 'O') {
- // if this is received, this means the server-ip that sent it said "OK" to credentials.
- // only when a server says this do we exchange keys. The server MUST have an entry in the servers
- // array, which is only added by an 'S' packet or BeginLink().
- for (int i = 0; i < 255; i++) {
- if (servers[i] != NULL) {
- if (!strcasecmp(servers[i]->internal_addr,udp_host)) {
- servers[i]->key = atoi(params);
- log(DEBUG,"Key for this server is now %d",servers[i]->key);
- DoSync(serv,udp_host,udp_port,MyKey);
- return;
- }
- }
- }
- WriteOpers("\2WARNING!\2 Server ip %s attempted a key exchange, but is not in the authentication state! Possible intrusion attempt!",udp_host);
- }
- else
if (token == 's') {
// S test.chatspike.net password :ChatSpike InspIRCd test server
char* servername = strtok(params," ");
@@ -6817,30 +6794,26 @@ void handle_link_packet(long theirkey, char* udp_msg, char* udp_host, int udp_po
ConfValue("link","sendpass",i,Link_SendPass,&config_f);
log(DEBUG,"(%d) Comparing against name='%s', ipaddr='%s', port='%s', recvpass='%s'",i,Link_ServerName,Link_IPAddr,Link_Port,Link_Pass);
LinkPort = atoi(Link_Port);
- if (!strcasecmp(Link_ServerName,servername)) {
- if (!strcasecmp(Link_IPAddr,udp_host)) {
- if (LinkPort == udp_port) {
- // matching link at this end too, we're all done!
- // at this point we must begin key exchange and insert this
- // server into our 'active' table.
- for (int j = 0; j < 255; j++) {
- if (servers[j] != NULL) {
- if (!strcasecmp(servers[j]->internal_addr,udp_host)) {
- strcpy(servers[j]->description,serverdesc);
- WriteOpers("Server %s authenticated, exchanging server keys...",servername);
- snprintf(response,10240,"O %d",MyKey);
- serv->SendPacket(response,udp_host,udp_port,0);
- return;
- }
+ if (!strcasecmp(Link_ServerName,servername))
+ {
+ if (!strcasecmp(Link_IPAddr,udp_host))
+ {
+ // matching link at this end too, we're all done!
+ // at this point we must begin key exchange and insert this
+ // server into our 'active' table.
+ for (int j = 0; j < 255; j++) {
+ if (servers[j] != NULL) {
+ if (!strcasecmp(servers[j]->name,udp_host)) {
+ strcpy(servers[j]->description,serverdesc);
+ WriteOpers("Server %s authenticated, exchanging server keys...",servername);
+ DoSync(serv,udp_host);
+ return;
}
}
WriteOpers("\2WARNING!\2 %s sent us an authentication packet but we are not authenticating with this server right noe! Possible intrusion attempt!",udp_host);
return;
}
- else {
- log(DEBUG,"Port numbers '%d' and '%d' don't match",LinkPort,udp_port);
- }
}
else {
log(DEBUG,"IP Addresses '%s' and '%s' don't match",Link_IPAddr,udp_host);
@@ -6850,7 +6823,7 @@ void handle_link_packet(long theirkey, char* udp_msg, char* udp_host, int udp_po
log(DEBUG,"Server names '%s' and '%s' don't match",Link_ServerName,servername);
}
}
- serv->SendPacket("E :Access is denied (no matching link block)",udp_host,udp_port,0);
+ serv->SendPacket("E :Access is denied (no matching link block)",udp_host);
WriteOpers("CONNECT from %s denied, no matching link block",servername);
return;
}
@@ -6861,7 +6834,7 @@ void handle_link_packet(long theirkey, char* udp_msg, char* udp_host, int udp_po
// remove this server from any lists
for (int j = 0; j < 255; j++) {
if (servers[j] != NULL) {
- if (!strcasecmp(servers[j]->internal_addr,udp_host)) {
+ if (!strcasecmp(servers[j]->name,udp_host)) {
delete servers[j];
return;
}
@@ -6875,17 +6848,17 @@ void handle_link_packet(long theirkey, char* udp_msg, char* udp_host, int udp_po
for (int j = 0; j < 255; j++) {
if (servers[j] != NULL) {
- if (!strcasecmp(servers[j]->internal_addr,udp_host)) {
- if (servers[j]->key == theirkey) {
+ if (!strcasecmp(servers[j]->name,udp_host)) {
+ if (servers[j]->haspassed) {
// found a valid key for this server, can process restricted stuff here
- process_restricted_commands(token,params,servers[j],serv,udp_host,udp_port);
+ process_restricted_commands(token,params,servers[j],serv,udp_host);
return;
}
}
}
}
- log(DEBUG,"Unrecognised token or unauthenticated host in datagram from %s:%d: %c",udp_host,udp_port,token);
+ log(DEBUG,"Unrecognised token or unauthenticated host in datagram from %s: %c",udp_host,token);
}
}
@@ -7064,8 +7037,8 @@ int InspIRCd(void)
return (ERROR);
}
+
length = sizeof (client);
- int flip_flop = 0, udp_port = 0;
char udp_msg[MAXBUF], udp_host[MAXBUF];
/* main loop, this never returns */
@@ -7095,23 +7068,46 @@ int InspIRCd(void)
reap_counter=0;
}
+ fd_set serverfds;
+ FD_ZERO(&serverfds);
+ timeval tvs;
+
+ for (int x = 0; x != UDPportCount; x++)
+ {
+ FD_SET(me[x]->fd, &serverfds);
+ }
+
+ tvs.tv_usec = 0;
+ tvs.tv_sec = 0;
+
+ int servresult = select(32767, &serverfds, NULL, NULL, &tvs);
+ if (servresult > 0)
+ {
+ for (int x = 0; x != UDPportCount; x++)
+ {
+ if (FD_ISSET (me[x]->fd, &serverfds))
+ {
+ char remotehost[MAXBUF];
+ incomingSockfd = accept (me[x]->fd, (sockaddr *) &client, &length);
+ strncpy (remotehost,(char *) inet_ntoa (client.sin_addr),MAXBUF);
+ // add to this connections ircd_connector vector
+ me[x]->AddIncoming(incomingSockfd,remotehost);
+ }
+ }
+ }
for (int x = 0; x != UDPportCount; x++)
{
long theirkey = 0;
- if (me[x]->RecvPacket(udp_msg, udp_host, udp_port, theirkey))
+ if (me[x]->RecvPacket(udp_msg, udp_host))
{
if (strlen(udp_msg)<1) {
- log(DEBUG,"Invalid datagram from %s:%d:%d [route%d]",udp_host,udp_port,me[x]->port,x);
+ log(DEBUG,"Invalid string from %s [route%d]",udp_host,x);
}
else
{
FOREACH_MOD OnPacketReceive(udp_msg);
- // Packets must go back via the route they arrived on :)
- handle_link_packet(theirkey, udp_msg, udp_host, udp_port, me[x]);
- // link packets can manipulate the usertable so beware of
- // any loops here watching the user or channels hash
- log(DEBUG,"Sync: exit 3");
+ handle_link_packet(udp_msg, udp_host, me[x]);
goto label;
}
}