summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/modules.h7
-rw-r--r--include/usermanager.h6
-rw-r--r--include/users.h27
-rw-r--r--src/listensocket.cpp2
-rw-r--r--src/modules.cpp4
-rw-r--r--src/modules/extra/m_ssl_gnutls.cpp8
-rw-r--r--src/modules/extra/m_ssl_openssl.cpp6
-rw-r--r--src/modules/extra/m_ziplink.cpp2
-rw-r--r--src/modules/m_cgiirc.cpp55
-rw-r--r--src/modules/m_cloaking.cpp27
-rw-r--r--src/modules/m_connectban.cpp2
-rw-r--r--src/modules/m_ident.cpp102
-rw-r--r--src/modules/m_spanningtree/uid.cpp2
-rw-r--r--src/modules/m_spanningtree/utils.cpp2
-rw-r--r--src/user_resolver.cpp4
-rw-r--r--src/usermanager.cpp25
-rw-r--r--src/users.cpp65
17 files changed, 125 insertions, 221 deletions
diff --git a/include/modules.h b/include/modules.h
index a539f3185..932ef3d19 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -1301,7 +1301,7 @@ class CoreExport Module : public Extensible
*/
virtual int OnDelBan(User* source, Channel* channel,const std::string &banmask);
- virtual void OnHookUserIO(User* user, const std::string &targetip);
+ virtual void OnHookUserIO(User* user);
/** Called immediately after any connection is accepted. This is intended for raw socket
* processing (e.g. modules which wrap the tcp connection within another library) and provides
@@ -1309,10 +1309,11 @@ class CoreExport Module : public Extensible
* There are no return values from this call as all modules get an opportunity if required to
* process the connection.
* @param fd The file descriptor returned from accept()
- * @param ip The IP address of the connecting user
+ * @param client The client IP address and port
+ * @param server The server IP address and port
* @param localport The local port number the user connected to
*/
- virtual void OnRawSocketAccept(int fd, const std::string &ip, int localport);
+ virtual void OnRawSocketAccept(int fd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
/** Called immediately before any write() operation on a user's socket in the core. Because
* this event is a low level event no user information is associated with it. It is intended
diff --git a/include/usermanager.h b/include/usermanager.h
index c2f89729a..a6b5f74e4 100644
--- a/include/usermanager.h
+++ b/include/usermanager.h
@@ -73,12 +73,12 @@ class CoreExport UserManager : public Extensible
* initialize it as not yet registered, and add it to the socket engine.
* @param Instance a pointer to the server instance
* @param socket The socket id (file descriptor) this user is on
- * @param port The port number this user connected on
* @param iscached This variable is reserved for future use
- * @param ip The IP address of the user
+ * @param client The IP address and client port of the user
+ * @param server The server IP address and port used by the user
* @return This function has no return value, but a call to AddClient may remove the user.
*/
- void AddUser(InspIRCd* Instance, int socket, int port, bool iscached, irc::sockets::sockaddrs* ip, const std::string &targetip);
+ void AddUser(InspIRCd* Instance, int socket, bool iscached, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
/** Disconnect a user gracefully
* @param user The user to remove
diff --git a/include/users.h b/include/users.h
index e681ef326..39b0ebdca 100644
--- a/include/users.h
+++ b/include/users.h
@@ -472,23 +472,32 @@ class CoreExport User : public EventHandler
*/
bool quitting;
- /** IPV4 or IPV6 ip address, binary format. Use SetSockAddr to set this and
- * GetIPString/GetPort to obtain its value in a readable manner
+ /** Server address and port that this user is connected to.
+ * If unknown, address family is AF_UNKNOWN
*/
- irc::sockets::sockaddrs ip;
+ irc::sockets::sockaddrs server_sa;
+ /** Client address that the user is connected from.
+ * Port number is only valid if local.
+ *
+ * Do not modify this value directly, use SetClientIP() to change it
+ */
+ irc::sockets::sockaddrs client_sa;
- /** Initialize the clients sockaddr
- * @param ip A human-readable IP address for this user
- * @param port The port number of this user (zero if unknown)
+ /** Sets the client IP for this user
+ * @return true if the conversion was successful
*/
- void SetSockAddr(const char* ip, int port);
+ bool SetClientIP(const char* sip);
- /** Get port number from sockaddr
+ /**
* @return The port number of this user.
*/
int GetServerPort();
+ /**
+ * @return The server IP address
+ */
+ std::string GetServerIP();
- /** Get IP string from sockaddr, using static internal buffer
+ /** Get client IP string from sockaddr, using static internal buffer
* @return The IP string
*/
const char* GetIPString();
diff --git a/src/listensocket.cpp b/src/listensocket.cpp
index 452925bf3..f40afd123 100644
--- a/src/listensocket.cpp
+++ b/src/listensocket.cpp
@@ -154,5 +154,5 @@ void ListenSocketBase::HandleEvent(EventType e, int err)
void ClientListenSocket::OnAcceptReady(const std::string &ipconnectedto, int nfd, const std::string &incomingip)
{
- ServerInstance->Users->AddUser(ServerInstance, nfd, bind_port, false, &client, ipconnectedto);
+ ServerInstance->Users->AddUser(ServerInstance, nfd, false, &client, &server);
}
diff --git a/src/modules.cpp b/src/modules.cpp
index fbede2c0a..ab8ff37d4 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -159,7 +159,7 @@ void Module::OnGlobalOper(User*) { }
void Module::OnPostConnect(User*) { }
int Module::OnAddBan(User*, Channel*, const std::string &) { return 0; }
int Module::OnDelBan(User*, Channel*, const std::string &) { return 0; }
-void Module::OnRawSocketAccept(int, const std::string&, int) { }
+void Module::OnRawSocketAccept(int, irc::sockets::sockaddrs*, irc::sockets::sockaddrs*) { }
int Module::OnRawSocketWrite(int, const char*, int) { return 0; }
void Module::OnRawSocketClose(int) { }
void Module::OnRawSocketConnect(int) { }
@@ -197,7 +197,7 @@ void Module::OnText(User*, void*, int, const std::string&, char, CUList&) { }
void Module::OnRunTestSuite() { }
void Module::OnNamesListItem(User*, User*, Channel*, std::string&, std::string&) { }
int Module::OnNumeric(User*, unsigned int, const std::string&) { return 0; }
-void Module::OnHookUserIO(User*, const std::string&) { }
+void Module::OnHookUserIO(User*) { }
bool Module::OnHostCycle(User* user) { return false; }
ModuleManager::ModuleManager(InspIRCd* Ins) : ModCount(0), Instance(Ins)
diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp
index 2fa060360..b2b59e612 100644
--- a/src/modules/extra/m_ssl_gnutls.cpp
+++ b/src/modules/extra/m_ssl_gnutls.cpp
@@ -81,7 +81,7 @@ class CommandStartTLS : public Command
{
user->WriteNumeric(670, "%s :STARTTLS successful, go ahead with TLS handshake", user->nick.c_str());
user->AddIOHook(Caller);
- Caller->OnRawSocketAccept(user->GetFd(), user->GetIPString(), user->GetServerPort());
+ Caller->OnRawSocketAccept(user->GetFd(), NULL, NULL);
}
else
user->WriteNumeric(691, "%s :STARTTLS failure", user->nick.c_str());
@@ -347,9 +347,9 @@ class ModuleSSLGnuTLS : public Module
output.append(" STARTTLS");
}
- virtual void OnHookUserIO(User* user, const std::string &targetip)
+ virtual void OnHookUserIO(User* user)
{
- if (!user->GetIOHook() && isin(targetip,user->GetServerPort(),listenports))
+ if (!user->GetIOHook() && isin(user->GetServerIP(),user->GetServerPort(),listenports))
{
/* Hook the user with our module */
user->AddIOHook(this);
@@ -421,7 +421,7 @@ class ModuleSSLGnuTLS : public Module
}
- virtual void OnRawSocketAccept(int fd, const std::string &ip, int localport)
+ virtual void OnRawSocketAccept(int fd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
{
/* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */
if ((fd < 0) || (fd > ServerInstance->SE->GetMaxFds() - 1))
diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp
index 0259c105a..447f35940 100644
--- a/src/modules/extra/m_ssl_openssl.cpp
+++ b/src/modules/extra/m_ssl_openssl.cpp
@@ -157,9 +157,9 @@ class ModuleSSLOpenSSL : public Module
ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
}
- virtual void OnHookUserIO(User* user, const std::string &targetip)
+ virtual void OnHookUserIO(User* user)
{
- if (!user->GetIOHook() && isin(targetip,user->GetServerPort(), listenports))
+ if (!user->GetIOHook() && isin(user->GetServerIP(),user->GetServerPort(), listenports))
{
/* Hook the user with our module */
user->AddIOHook(this);
@@ -424,7 +424,7 @@ class ModuleSSLOpenSSL : public Module
}
- virtual void OnRawSocketAccept(int fd, const std::string &ip, int localport)
+ virtual void OnRawSocketAccept(int fd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
{
/* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */
if ((fd < 0) || (fd > ServerInstance->SE->GetMaxFds() - 1))
diff --git a/src/modules/extra/m_ziplink.cpp b/src/modules/extra/m_ziplink.cpp
index b42d18f8c..efff13644 100644
--- a/src/modules/extra/m_ziplink.cpp
+++ b/src/modules/extra/m_ziplink.cpp
@@ -211,7 +211,7 @@ class ModuleZLib : public Module
session->status = IZIP_OPEN;
}
- virtual void OnRawSocketAccept(int fd, const std::string &ip, int localport)
+ virtual void OnRawSocketAccept(int fd, irc::sockets::sockaddrs*, irc::sockets::sockaddrs*)
{
/* Nothing special needs doing here compared to connect() */
OnRawSocketConnect(fd);
diff --git a/src/modules/m_cgiirc.cpp b/src/modules/m_cgiirc.cpp
index 85acae8ab..1467d0f68 100644
--- a/src/modules/m_cgiirc.cpp
+++ b/src/modules/m_cgiirc.cpp
@@ -117,7 +117,7 @@ class CGIResolver : public Resolver
them->host.assign(result,0, 64);
them->dhost.assign(result, 0, 64);
if (querytype)
- them->SetSockAddr(result.c_str(), them->GetServerPort());
+ them->SetClientIP(result.c_str());
them->ident.assign("~cgiirc", 0, 8);
them->InvalidateCache();
them->CheckLines(true);
@@ -318,7 +318,7 @@ public:
if(user->GetExt("cgiirc_webirc_ip", webirc_ip))
{
ServerInstance->Users->RemoveCloneCounts(user);
- user->SetSockAddr(webirc_ip->c_str(), user->GetServerPort());
+ user->SetClientIP(webirc_ip->c_str());
delete webirc_ip;
user->InvalidateCache();
user->Shrink("cgiirc_webirc_ip");
@@ -341,15 +341,7 @@ public:
bool valid = false;
ServerInstance->Users->RemoveCloneCounts(user);
-#ifdef IPV6
- if (user->ip.sa.sa_family == AF_INET6)
- valid = (inet_pton(AF_INET6, user->password.c_str(), &user->ip.in6.sin6_addr) > 0);
- else
- valid = (inet_aton(user->password.c_str(), &user->ip.in4.sin_addr));
-#else
- if (inet_aton(user->password.c_str(), &((sockaddr_in*)user->ip)->sin_addr))
- valid = true;
-#endif
+ valid = user->SetClientIP(user->password.c_str());
ServerInstance->Users->AddLocalClone(user);
ServerInstance->Users->AddGlobalClone(user);
user->CheckClass();
@@ -386,10 +378,9 @@ public:
bool CheckIdent(User* user)
{
- int ip[4];
const char* ident;
- char newip[16];
int len = user->ident.length();
+ in_addr newip;
if(len == 8)
ident = user->ident.c_str();
@@ -398,34 +389,32 @@ public:
else
return false;
- for(int i = 0; i < 4; i++)
- if(!HexToInt(ip[i], ident + i*2))
- return false;
-
- snprintf(newip, 16, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
+ errno = 0;
+ unsigned long ipaddr = strtoul(ident, NULL, 16);
+ if (errno)
+ return false;
+ newip.s_addr = htonl(ipaddr);
+ char* newipstr = inet_ntoa(newip);
user->Extend("cgiirc_realhost", new std::string(user->host));
user->Extend("cgiirc_realip", new std::string(user->GetIPString()));
ServerInstance->Users->RemoveCloneCounts(user);
- user->SetSockAddr(newip, user->GetServerPort());
+ user->SetClientIP(newipstr);
ServerInstance->Users->AddLocalClone(user);
ServerInstance->Users->AddGlobalClone(user);
user->CheckClass();
+ user->host = newipstr;
+ user->dhost = newipstr;
+ user->ident.assign("~cgiirc", 0, 8);
try
{
- user->host.assign(newip, 0, 16);
- user->dhost.assign(newip, 0, 16);
- user->ident.assign("~cgiirc", 0, 8);
bool cached;
- CGIResolver* r = new CGIResolver(this, ServerInstance, NotifyOpers, newip, false, user, user->GetFd(), "IDENT", cached);
+ CGIResolver* r = new CGIResolver(this, ServerInstance, NotifyOpers, newipstr, false, user, user->GetFd(), "IDENT", cached);
ServerInstance->AddResolver(r, cached);
}
catch (...)
{
- user->host.assign(newip, 0, 16);
- user->dhost.assign(newip, 0, 16);
- user->ident.assign("~cgiirc", 0, 8);
user->InvalidateCache();
if(NotifyOpers)
@@ -491,20 +480,6 @@ public:
return true;
}
- bool HexToInt(int &out, const char* in)
- {
- char ip[3];
- ip[0] = in[0];
- ip[1] = in[1];
- ip[2] = 0;
- out = strtol(ip, NULL, 16);
-
- if(out > 255 || out < 0)
- return false;
-
- return true;
- }
-
virtual ~ModuleCgiIRC()
{
}
diff --git a/src/modules/m_cloaking.cpp b/src/modules/m_cloaking.cpp
index 29a5e1421..a17577702 100644
--- a/src/modules/m_cloaking.cpp
+++ b/src/modules/m_cloaking.cpp
@@ -410,35 +410,20 @@ class ModuleCloaking : public Module
* Their ISP shouldnt go to town on subdomains, or they shouldnt have a kiddie
* vhost.
*/
-#ifdef IPV6
in6_addr testaddr;
- in_addr testaddr2;
- if ((dest->ip.sa.sa_family == AF_INET6) && (inet_pton(AF_INET6,dest->host.c_str(),&testaddr) < 1) && (hostcloak.length() <= 64))
- /* Invalid ipv6 address, and ipv6 user (resolved host) */
- b = hostcloak;
- else if ((dest->ip.sa.sa_family == AF_INET) && (inet_aton(dest->host.c_str(),&testaddr2) < 1) && (hostcloak.length() <= 64))
- /* Invalid ipv4 address, and ipv4 user (resolved host) */
- b = hostcloak;
- else
- /* Valid ipv6 or ipv4 address (not resolved) ipv4 or ipv6 user */
- b = ((!strchr(dest->host.c_str(),':')) ? cu->Cloak4(dest->host.c_str()) : cu->Cloak6(dest->host.c_str()));
-#else
- in_addr testaddr;
- if ((inet_aton(dest->host.c_str(),&testaddr) < 1) && (hostcloak.length() <= 64))
- /* Invalid ipv4 address, and ipv4 user (resolved host) */
+ if (inet_pton(dest->client_sa.sa.sa_family, dest->host.c_str(), &testaddr) < 1 && (hostcloak.length() <= 64))
+ /* not a valid address, must have been a host, so cloak as a host */
b = hostcloak;
+ else if (dest->client_sa.sa.sa_family == AF_INET6)
+ b = cu->Cloak6(dest->GetIPString());
else
- /* Valid ipv4 address (not resolved) ipv4 user */
- b = cu->Cloak4(dest->host.c_str());
-#endif
+ b = cu->Cloak4(dest->GetIPString());
}
else
{
-#ifdef IPV6
- if (dest->ip.sa.sa_family == AF_INET6)
+ if (dest->client_sa.sa.sa_family == AF_INET6)
b = cu->Cloak6(dest->GetIPString());
else
-#endif
b = cu->Cloak4(dest->GetIPString());
}
diff --git a/src/modules/m_connectban.cpp b/src/modules/m_connectban.cpp
index a00fc6733..ae464a16c 100644
--- a/src/modules/m_connectban.cpp
+++ b/src/modules/m_connectban.cpp
@@ -72,7 +72,7 @@ class ModuleConnectBan : public Module
int range = 32;
clonemap::iterator i;
- switch (u->ip.sa.sa_family)
+ switch (u->client_sa.sa.sa_family)
{
case AF_INET6:
range = ipv6_cidr;
diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp
index d5ca20836..80f2c0b99 100644
--- a/src/modules/m_ident.cpp
+++ b/src/modules/m_ident.cpp
@@ -80,60 +80,36 @@ class IdentRequestSocket : public EventHandler
std::string result; /* Holds the ident string if done */
public:
- IdentRequestSocket(InspIRCd *Server, User* u, const std::string &bindip) : user(u), ServerInstance(Server), result(u->ident)
+ IdentRequestSocket(InspIRCd *Server, User* u) : user(u), ServerInstance(Server), result(u->ident)
{
socklen_t size = 0;
-#ifdef IPV6
- /* Does this look like a v6 ip address? */
- bool v6 = false;
- if ((bindip.empty()) || bindip.find(':') != std::string::npos)
- v6 = true;
-
- if (v6)
- SetFd(socket(AF_INET6, SOCK_STREAM, 0));
- else
-#endif
- SetFd(socket(AF_INET, SOCK_STREAM, 0));
+
+ SetFd(socket(user->server_sa.sa.sa_family, SOCK_STREAM, 0));
if (GetFd() == -1)
throw ModuleException("Could not create socket");
done = false;
- /* We allocate two of these because sizeof(sockaddr_in6) > sizeof(sockaddr_in) */
- irc::sockets::sockaddrs s;
- irc::sockets::sockaddrs addr;
+ irc::sockets::sockaddrs bindaddr;
+ irc::sockets::sockaddrs connaddr;
+
+ memcpy(&bindaddr, &user->server_sa, sizeof(bindaddr));
+ memcpy(&connaddr, &user->client_sa, sizeof(connaddr));
-#ifdef IPV6
- /* Horrid icky nasty ugly berkely socket crap. */
- if (v6)
+ if (connaddr.sa.sa_family == AF_INET6)
{
- if (inet_pton(AF_INET6, user->GetIPString(), &addr.in6.sin6_addr) > 0)
- {
- addr.in6.sin6_family = AF_INET6;
- addr.in6.sin6_port = htons(113);
- size = sizeof(sockaddr_in6);
- inet_pton(AF_INET6, bindip.c_str(), &s.in6.sin6_addr);
- s.in6.sin6_family = AF_INET6;
- s.in6.sin6_port = 0;
- }
+ bindaddr.in6.sin6_port = 0;
+ connaddr.in6.sin6_port = htons(113);
}
else
-#endif
{
- if (inet_aton(user->GetIPString(), &addr.in4.sin_addr) > 0)
- {
- addr.in4.sin_family = AF_INET;
- addr.in4.sin_port = htons(113);
- size = sizeof(sockaddr_in);
- inet_aton(bindip.c_str(), &s.in4.sin_addr);
- s.in4.sin_family = AF_INET;
- s.in4.sin_port = 0;
- }
+ bindaddr.in4.sin_port = 0;
+ connaddr.in4.sin_port = htons(113);
}
/* Attempt to bind (ident requests must come from the ip the query is referring to */
- if (ServerInstance->SE->Bind(GetFd(), &s.sa, size) < 0)
+ if (ServerInstance->SE->Bind(GetFd(), &bindaddr.sa, size) < 0)
{
this->Close();
throw ModuleException("failed to bind()");
@@ -142,7 +118,7 @@ class IdentRequestSocket : public EventHandler
ServerInstance->SE->NonBlocking(GetFd());
/* Attempt connection (nonblocking) */
- if (ServerInstance->SE->Connect(this, &addr.sa, size) == -1 && errno != EINPROGRESS)
+ if (ServerInstance->SE->Connect(this, &connaddr.sa, size) == -1 && errno != EINPROGRESS)
{
this->Close();
throw ModuleException("connect() failed");
@@ -165,30 +141,16 @@ class IdentRequestSocket : public EventHandler
{
ServerInstance->Logs->Log("m_ident",DEBUG,"OnConnected()");
- /* Both sockaddr_in and sockaddr_in6 can be safely casted to sockaddr, especially since the
- * only members we use are in a part of the struct that should always be identical (at the
- * byte level). */
- irc::sockets::sockaddrs laddr, raddr;
-
- socklen_t laddrsz = sizeof(laddr);
- socklen_t raddrsz = sizeof(raddr);
-
- if ((getsockname(user->GetFd(), &laddr.sa, &laddrsz) != 0) || (getpeername(user->GetFd(), &raddr.sa, &raddrsz) != 0))
- {
- done = true;
- return;
- }
-
char req[32];
/* Build request in the form 'localport,remoteport\r\n' */
int req_size;
-#ifdef IPV6
- if (raddr.sa.sa_family == AF_INET6)
- req_size = snprintf(req, sizeof(req), "%d,%d\r\n", ntohs(raddr.in6.sin6_port), ntohs(laddr.in6.sin6_port));
+ if (user->client_sa.sa.sa_family == AF_INET6)
+ req_size = snprintf(req, sizeof(req), "%d,%d\r\n",
+ ntohs(user->client_sa.in6.sin6_port), ntohs(user->server_sa.in6.sin6_port));
else
-#endif
- req_size = snprintf(req, sizeof(req), "%d,%d\r\n", ntohs(raddr.in4.sin_port), ntohs(laddr.in4.sin_port));
+ req_size = snprintf(req, sizeof(req), "%d,%d\r\n",
+ ntohs(user->client_sa.in4.sin_port), ntohs(user->server_sa.in4.sin_port));
/* Send failed if we didnt write the whole ident request --
* might as well give up if this happens!
@@ -371,36 +333,16 @@ class ModuleIdent : public Module
user->WriteServ("NOTICE Auth :*** Looking up your ident...");
- // Get the IP that the user is connected to, and bind to that for the outgoing connection
- irc::sockets::sockaddrs laddr;
- socklen_t laddrsz = sizeof(laddr);
-
- if (getsockname(user->GetFd(), &laddr.sa, &laddrsz) != 0)
- {
- user->WriteServ("NOTICE Auth :*** Could not find your ident, using %s instead.", user->ident.c_str());
- return 0;
- }
-
- char ip[INET6_ADDRSTRLEN + 1];
-#ifdef IPV6
- if (laddr.sa.sa_family == AF_INET6)
- inet_ntop(laddr.in6.sin6_family, &laddr.in6.sin6_addr, ip, INET6_ADDRSTRLEN);
- else
-#endif
- inet_ntop(laddr.in4.sin_family, &laddr.in4.sin_addr, ip, INET6_ADDRSTRLEN);
-
- IdentRequestSocket *isock = NULL;
try
{
- isock = new IdentRequestSocket(ServerInstance, user, ip);
+ IdentRequestSocket *isock = new IdentRequestSocket(ServerInstance, user);
+ user->Extend("ident_socket", isock);
}
catch (ModuleException &e)
{
ServerInstance->Logs->Log("m_ident",DEBUG,"Ident exception: %s", e.GetReason());
- return 0;
}
- user->Extend("ident_socket", isock);
return 0;
}
diff --git a/src/modules/m_spanningtree/uid.cpp b/src/modules/m_spanningtree/uid.cpp
index 5b155e188..7565be337 100644
--- a/src/modules/m_spanningtree/uid.cpp
+++ b/src/modules/m_spanningtree/uid.cpp
@@ -157,7 +157,7 @@ bool TreeSocket::ParseUID(const std::string &source, std::deque<std::string> &pa
if (params[8][0] != '+')
params[8] = "+" + params[8];
- _new->SetSockAddr(params[6].c_str(), 0);
+ _new->SetClientIP(params[6].c_str());
ServerInstance->Users->AddGlobalClone(_new);
diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp
index 116ac741f..8a17baf84 100644
--- a/src/modules/m_spanningtree/utils.cpp
+++ b/src/modules/m_spanningtree/utils.cpp
@@ -56,7 +56,7 @@ void ServerSocketListener::OnAcceptReady(const std::string &ipconnectedto, int n
if (this->GetIOHook())
{
- this->GetIOHook()->OnRawSocketAccept(newsock, incomingip.c_str(), this->bind_port);
+ this->GetIOHook()->OnRawSocketAccept(newsock, &client, &server);
}
/* we don't need a pointer to this, creating it stores it in the necessary places */
diff --git a/src/user_resolver.cpp b/src/user_resolver.cpp
index 95fa13eaf..d0270f7d8 100644
--- a/src/user_resolver.cpp
+++ b/src/user_resolver.cpp
@@ -35,7 +35,7 @@ void UserResolver::OnLookupComplete(const std::string &result, unsigned int ttl,
{
bool lcached = false;
#ifdef IPV6
- if (this->bound_user->ip.sa.sa_family == AF_INET6)
+ if (this->bound_user->client_sa.sa.sa_family == AF_INET6)
{
/* IPV6 forward lookup */
res_forward = new UserResolver(this->ServerInstance, this->bound_user, result, DNS_QUERY_AAAA, lcached);
@@ -59,7 +59,7 @@ void UserResolver::OnLookupComplete(const std::string &result, unsigned int ttl,
{
/* Both lookups completed */
- irc::sockets::sockaddrs* user_ip = &this->bound_user->ip;
+ irc::sockets::sockaddrs* user_ip = &this->bound_user->client_sa;
bool rev_match = false;
#ifdef IPV6
if (user_ip->sa.sa_family == AF_INET6)
diff --git a/src/usermanager.cpp b/src/usermanager.cpp
index 5dd9cb054..f62daf892 100644
--- a/src/usermanager.cpp
+++ b/src/usermanager.cpp
@@ -18,7 +18,7 @@
#include "bancache.h"
/* add a client connection to the sockets list */
-void UserManager::AddUser(InspIRCd* Instance, int socket, int port, bool iscached, irc::sockets::sockaddrs* ip, const std::string &targetip)
+void UserManager::AddUser(InspIRCd* Instance, int socket, bool iscached, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
{
/* NOTE: Calling this one parameter constructor for User automatically
* allocates a new UUID and places it in the hash_map.
@@ -36,22 +36,17 @@ void UserManager::AddUser(InspIRCd* Instance, int socket, int port, bool iscache
}
New->SetFd(socket);
- memcpy(&New->ip, ip, sizeof(*ip));
- // change the port number of their stored sockaddr to be the server port rather than the client port
- if (New->ip.sa.sa_family == AF_INET6)
- New->ip.in6.sin6_port = port;
- else
- New->ip.in4.sin_port = port;
-
+ memcpy(&New->client_sa, client, sizeof(irc::sockets::sockaddrs));
+ memcpy(&New->server_sa, server, sizeof(irc::sockets::sockaddrs));
/* Give each of the modules an attempt to hook the user for I/O */
- FOREACH_MOD_I(Instance, I_OnHookUserIO, OnHookUserIO(New, targetip));
+ FOREACH_MOD_I(Instance, I_OnHookUserIO, OnHookUserIO(New));
if (New->GetIOHook())
{
try
{
- New->GetIOHook()->OnRawSocketAccept(socket, New->GetIPString(), port);
+ New->GetIOHook()->OnRawSocketAccept(socket, client, server);
}
catch (CoreException& modexcept)
{
@@ -218,7 +213,7 @@ void UserManager::AddLocalClone(User *user)
{
int range = 32;
clonemap::iterator x;
- switch (user->ip.sa.sa_family)
+ switch (user->client_sa.sa.sa_family)
{
case AF_INET6:
range = ServerInstance->Config->c_ipv6_range;
@@ -239,7 +234,7 @@ void UserManager::AddGlobalClone(User *user)
{
int range = 32;
clonemap::iterator x;
- switch (user->ip.sa.sa_family)
+ switch (user->client_sa.sa.sa_family)
{
case AF_INET6:
range = ServerInstance->Config->c_ipv6_range;
@@ -259,7 +254,7 @@ void UserManager::AddGlobalClone(User *user)
void UserManager::RemoveCloneCounts(User *user)
{
int range = 32;
- switch (user->ip.sa.sa_family)
+ switch (user->client_sa.sa.sa_family)
{
case AF_INET6:
range = ServerInstance->Config->c_ipv6_range;
@@ -293,7 +288,7 @@ void UserManager::RemoveCloneCounts(User *user)
unsigned long UserManager::GlobalCloneCount(User *user)
{
int range = 32;
- switch (user->ip.sa.sa_family)
+ switch (user->client_sa.sa.sa_family)
{
case AF_INET6:
range = ServerInstance->Config->c_ipv6_range;
@@ -312,7 +307,7 @@ unsigned long UserManager::GlobalCloneCount(User *user)
unsigned long UserManager::LocalCloneCount(User *user)
{
int range = 32;
- switch (user->ip.sa.sa_family)
+ switch (user->client_sa.sa.sa_family)
{
case AF_INET6:
range = ServerInstance->Config->c_ipv6_range;
diff --git a/src/users.cpp b/src/users.cpp
index 7c752165c..7663a63b2 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -107,7 +107,7 @@ void User::StartDNSLookup()
const char* sip = this->GetIPString();
UserResolver *res_reverse;
- QueryType resolvtype = this->ip.sa.sa_family == AF_INET6 ? DNS_QUERY_PTR6 : DNS_QUERY_PTR4;
+ QueryType resolvtype = this->client_sa.sa.sa_family == AF_INET6 ? DNS_QUERY_PTR6 : DNS_QUERY_PTR4;
res_reverse = new UserResolver(this->ServerInstance, this, sip, resolvtype, cached);
this->ServerInstance->AddResolver(res_reverse, cached);
@@ -213,7 +213,8 @@ User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance
bytes_in = bytes_out = cmds_in = cmds_out = 0;
quietquit = quitting = exempt = haspassed = dns_done = false;
fd = -1;
- ip.sa.sa_family = AF_UNSPEC;
+ server_sa.sa.sa_family = AF_UNSPEC;
+ client_sa.sa.sa_family = AF_UNSPEC;
recvq.clear();
sendq.clear();
Visibility = NULL;
@@ -262,7 +263,7 @@ User::~User()
this->InvalidateCache();
this->DecrementModes();
- if (ip.sa.sa_family != AF_UNSPEC)
+ if (client_sa.sa.sa_family != AF_UNSPEC)
ServerInstance->Users->RemoveCloneCounts(this);
ServerInstance->Users->uuidlist->erase(uuid);
@@ -1060,36 +1061,14 @@ bool User::ForceNickChange(const char* newnick)
return false;
}
-void User::SetSockAddr(const char* sip, int port)
-{
- this->cachedip = "";
-
- if (inet_pton(AF_INET, sip, &ip.in4.sin_addr))
- {
- ip.in4.sin_family = AF_INET;
- ip.in4.sin_port = port;
- return;
- }
- else if (inet_pton(AF_INET6, sip, &ip.in6.sin6_addr))
- {
- ip.in6.sin6_family = AF_INET6;
- ip.in6.sin6_port = port;
- }
- else
- {
- ServerInstance->Logs->Log("USERS",DEBUG,"Uh oh, I dont know how to read IP '%s' on '%s'!",
- sip, this->nick.c_str());
- }
-}
-
int User::GetServerPort()
{
- switch (this->ip.sa.sa_family)
+ switch (this->server_sa.sa.sa_family)
{
case AF_INET6:
- return this->ip.in6.sin6_port;
+ return this->server_sa.in6.sin6_port;
case AF_INET:
- return this->ip.in4.sin_port;
+ return this->server_sa.in4.sin_port;
}
return 0;
}
@@ -1105,7 +1084,7 @@ const char* User::GetCIDRMask(int range)
* Original code written by Oliver Lupton (Om).
* Integrated by me. Thanks. :) -- w00t
*/
- switch (this->ip.sa.sa_family)
+ switch (this->client_sa.sa.sa_family)
{
case AF_INET6:
{
@@ -1135,7 +1114,7 @@ const char* User::GetCIDRMask(int range)
*/
for(i = 0; i < (16 - bytestozero); i++)
{
- v6.s6_addr[i] = ip.in6.sin6_addr.s6_addr[i];
+ v6.s6_addr[i] = client_sa.in6.sin6_addr.s6_addr[i];
}
/* And zero all the remaining bytes in the IP. */
@@ -1160,7 +1139,7 @@ const char* User::GetCIDRMask(int range)
throw "CIDR mask width greater than address width (IPv4, 32 bit)";
/* Users already have a sockaddr* pointer (User::ip) which contains either a v4 or v6 structure */
- v4.s_addr = ip.in4.sin_addr.s_addr;
+ v4.s_addr = client_sa.in4.sin_addr.s_addr;
/* To create the CIDR mask we want to set all the bits after 'range' bits of the address
* to zero. This means the last (32 - range) bits of the address must be set to zero.
@@ -1197,13 +1176,13 @@ const char* User::GetIPString()
if (!this->cachedip.empty())
return this->cachedip.c_str();
- switch (this->ip.sa.sa_family)
+ switch (this->client_sa.sa.sa_family)
{
case AF_INET6:
{
static char temp[41];
- inet_ntop(ip.in6.sin6_family, &ip.in6.sin6_addr, buf, sizeof(buf));
+ inet_ntop(client_sa.in6.sin6_family, &client_sa.in6.sin6_addr, buf, sizeof(buf));
/* IP addresses starting with a : on irc are a Bad Thing (tm) */
if (*buf == ':')
{
@@ -1219,7 +1198,7 @@ const char* User::GetIPString()
break;
case AF_INET:
{
- inet_ntop(ip.in4.sin_family, &ip.in4.sin_addr, buf, sizeof(buf));
+ inet_ntop(client_sa.in4.sin_family, &client_sa.in4.sin_addr, buf, sizeof(buf));
this->cachedip = buf;
return buf;
}
@@ -1232,6 +1211,24 @@ const char* User::GetIPString()
return "";
}
+bool User::SetClientIP(const char* sip)
+{
+ this->cachedip = "";
+ if (inet_pton(AF_INET, sip, &client_sa.in4.sin_addr))
+ {
+ client_sa.in4.sin_family = AF_INET;
+ client_sa.in4.sin_port = 0;
+ return true;
+ }
+ else if (inet_pton(AF_INET6, sip, &client_sa.in6.sin6_addr))
+ {
+ client_sa.in6.sin6_family = AF_INET6;
+ client_sa.in6.sin6_port = 0;
+ return true;
+ }
+ return false;
+}
+
/** NOTE: We cannot pass a const reference to this method.
* The string is changed by the workings of the method,
* so that if we pass const ref, we end up copying it to