summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-04 01:59:41 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-04 01:59:41 +0000
commitf25755bbe748f65eb17f8e25507160569f8f4041 (patch)
tree31c4e662f99cd6e2b3c38ab01b32c55a29f9f3eb
parente5843dde4dda51de3160de62b7b8811cb9465d1b (diff)
Change to using userrec::ip as a sockaddr to store port, ip and address family, rather than userrec::ip4 and userrec::port.
This allows us to handle remote ipv6 users on an ipv4 server, and vice versa. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4694 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--docs/inspircd.conf.example31
-rw-r--r--include/connection.h12
-rw-r--r--include/users.h18
-rw-r--r--src/channels.cpp2
-rw-r--r--src/cmd_stats.cpp4
-rw-r--r--src/cmd_whois.cpp2
-rw-r--r--src/commands.cpp2
-rw-r--r--src/helperfuncs.cpp22
-rw-r--r--src/modules/extra/m_ssl_gnutls.cpp4
-rw-r--r--src/modules/extra/m_ssl_openssl.cpp4
-rw-r--r--src/modules/m_cgiirc.cpp26
-rw-r--r--src/modules/m_check.cpp37
-rw-r--r--src/modules/m_ident.cpp2
-rw-r--r--src/modules/m_spanningtree.cpp12
-rw-r--r--src/modules/m_userip.cpp2
-rw-r--r--src/userprocess.cpp18
-rw-r--r--src/users.cpp128
-rw-r--r--src/xline.cpp2
18 files changed, 224 insertions, 104 deletions
diff --git a/docs/inspircd.conf.example b/docs/inspircd.conf.example
index 1e49fae93..34852bf4a 100644
--- a/docs/inspircd.conf.example
+++ b/docs/inspircd.conf.example
@@ -108,6 +108,12 @@
# <bind address="ip or host" port="port" type="clients"> #
# <bind address="ip or host" port="port" type="servers"> #
# #
+# If InspIRCd is built for IPV6, and you wish to accept IPV4 clients, #
+# then you must specify your IPV6 clients in the following form: #
+# ::ffff:1.2.3.4, where 1.2.3.4 is the IPV4 address to bind the #
+# port on. If InspIRCd is built for IPV4 connections (this is the #
+# default) then you do not need to prefix your addresses like this. #
+# #
<bind address="" port="6660" type="clients">
<bind address="" port="7000" type="servers">
@@ -214,6 +220,7 @@
<connect allow="*" timeout="60" flood="10" threshold="60" pingfreq="120" sendq="262144" recvq="4096" localmax="3" globalmax="3">
<connect deny="69.254.*">
+<connect deny="3ffe:*">
#-#-#-#-#-#-#-#-#-#-#-#- CLASS CONFIGURATION -#-#-#-#-#-#-#-#-#-#-#-
@@ -354,6 +361,12 @@
# that server to operoverride modes. This should only be used for #
# services and protected oper servers! #
# #
+# NOTE: If you have built InspIRCd with IPV6 support, and you want #
+# to link to an IPV4 server, you must specify the IP address in the #
+# form '::ffff:1.2.3.4' where 1.2.3.4 is the IP address of the target #
+# server. If you have built InspIRCd for IPV4 (this is the default) #
+# you should not prefix your IP addresses in this fashion. #
+# #
# ____ _ _____ _ _ ____ _ _ _ #
# | _ \ ___ __ _ __| | |_ _| |__ (_)___ | __ )(_) |_| | #
# | |_) / _ \/ _` |/ _` | | | | '_ \| / __| | _ \| | __| | #
@@ -414,9 +427,22 @@
# resolving even though the DNS server appears to be up! Most ISP and #
# hosting provider DNS servers support recursive lookups. #
# #
+# NOTE: If you have built InspIRCd with IPV6 support, and you want #
+# to use an IPV4 nameserver, you must specify the IP address in the #
+# form '::ffff:1.2.3.4' where 1.2.3.4 is the IP address of the target #
+# server. If you have built InspIRCd for IPV4 (this is the default) #
+# you should not prefix your IP addresses in this fashion. #
+# #
+# IF YOUR RESOLV.CONF CONTAINS ONLY IPV4 ADDRESSES, AND YOU ARE USING #
+# IPV6, YOU MUST DEFINE THE <DNS SERVER> TAG, AND USE THE ::FFFF #
+# PREFIX NOTATION. IF YOU DO NOT, HOSTS WILL *NOT* RESOLVE. #
+# #
<dns server="127.0.0.1" timeout="5">
+# An example of using IPV4 nameservers over IPV6
+#<dns server="::ffff:127.0.0.1" timeout="5">
+
#-#-#-#-#-#-#-#-#-#-#-#-#-#-# PID FILE -#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# #
# Define the path to the PID file here. The PID file can be used to #
@@ -449,8 +475,8 @@
# 'registered' (e.g. after the initial USER/NICK/PASS on connection) #
# so for example disabling NICK will not cripple your network. #
# #
-# <disabled commands="TOPIC MODE"> #
-# #
+
+#<disabled commands="TOPIC MODE">
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#- RTFM LINE -#-#-#-#-#-#-#-#-#-#-#-#-#-#
@@ -471,6 +497,7 @@
# loglevel - specifies what detail of messages to log in the #
# log file. You may select from debug, verbose, #
# default, sparse and none. #
+# #
# allowhalfop - allows the +h channel mode #
# #
# noservices - If noservices is true, yes, or 1, then the first #
diff --git a/include/connection.h b/include/connection.h
index 6f918204d..2855fa226 100644
--- a/include/connection.h
+++ b/include/connection.h
@@ -21,8 +21,6 @@
#include "inspircd_config.h"
#include "base.h"
-/** Please note: classes serverrec and userrec both inherit from class connection.
- */
class connection : public Extensible
{
public:
@@ -30,7 +28,7 @@ class connection : public Extensible
*/
int fd;
- /** Hostname of connection. Not used if this is a serverrec
+ /** Hostname of connection
*/
char host[65];
@@ -50,16 +48,10 @@ class connection : public Extensible
*/
int cmds_out;
- /** True if server/user has authenticated, false if otherwise
+ /** True if user has authenticated, false if otherwise
*/
bool haspassed;
- /** Port number
- * For a userrec, this is the port they connected to the network on.
- * For a serverrec this is the current listening port of the serverrec object.
- */
- int port;
-
/** Used by userrec to indicate the registration status of the connection
*/
char registered;
diff --git a/include/users.h b/include/users.h
index 13dc33709..19116a130 100644
--- a/include/users.h
+++ b/include/users.h
@@ -268,7 +268,23 @@ class userrec : public connection
/** IPV4 ip address
*/
- insp_inaddr ip4;
+ sockaddr ip;
+
+ /** Initialize the clients sockaddr
+ */
+ void SetSockAddr(int protocol_family, const char* ip, int port);
+
+ /** Get port number from sockaddr
+ */
+ int GetPort();
+
+ /** Get protocol family from sockaddr
+ */
+ int GetProtocolFamily();
+
+ /** Get IP string from sockaddr
+ */
+ const char* GetIPString();
/* Write error string
*/
diff --git a/src/channels.cpp b/src/channels.cpp
index 85097684f..03bb3cc79 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -352,7 +352,7 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
{
for (BanList::iterator i = Ptr->bans.begin(); i != Ptr->bans.end(); i++)
{
- if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match((char*)insp_ntoa(user->ip4),i->data)))
+ if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match(user->GetIPString(),i->data)))
{
WriteServ(user->fd,"474 %s %s :Cannot join channel (You're banned)",user->nick, Ptr->name);
return NULL;
diff --git a/src/cmd_stats.cpp b/src/cmd_stats.cpp
index a79c34803..b5b1ab561 100644
--- a/src/cmd_stats.cpp
+++ b/src/cmd_stats.cpp
@@ -217,11 +217,11 @@ void DoStats(char statschar, userrec* user, string_list &results)
{
if (isnick(i->second->nick))
{
- results.push_back(sn+" 211 "+user->nick+" :"+i->second->server+":"+ConvToStr(i->second->port)+" "+i->second->nick+" "+ConvToStr(i->second->bytes_in)+" "+ConvToStr(i->second->cmds_in)+" "+ConvToStr(i->second->bytes_out)+" "+ConvToStr(i->second->cmds_out));
+ results.push_back(sn+" 211 "+user->nick+" :"+i->second->server+":"+ConvToStr(i->second->GetPort())+" "+i->second->nick+" "+ConvToStr(i->second->bytes_in)+" "+ConvToStr(i->second->cmds_in)+" "+ConvToStr(i->second->bytes_out)+" "+ConvToStr(i->second->cmds_out));
}
else
{
- results.push_back(sn+" 211 "+user->nick+" :"+i->second->server+":"+ConvToStr(i->second->port)+" (unknown@"+ConvToStr(i->second->fd)+") "+ConvToStr(i->second->bytes_in)+" "+ConvToStr(i->second->cmds_in)+" "+ConvToStr(i->second->bytes_out)+" "+ConvToStr(i->second->cmds_out));
+ results.push_back(sn+" 211 "+user->nick+" :"+i->second->server+":"+ConvToStr(i->second->GetPort())+" (unknown@"+ConvToStr(i->second->fd)+") "+ConvToStr(i->second->bytes_in)+" "+ConvToStr(i->second->cmds_in)+" "+ConvToStr(i->second->bytes_out)+" "+ConvToStr(i->second->cmds_out));
}
}
diff --git a/src/cmd_whois.cpp b/src/cmd_whois.cpp
index 0914f75f4..efa8b44aa 100644
--- a/src/cmd_whois.cpp
+++ b/src/cmd_whois.cpp
@@ -48,7 +48,7 @@ void do_whois(userrec* user, userrec* dest,unsigned long signon, unsigned long i
WriteServ(user->fd,"311 %s %s %s %s * :%s",user->nick, dest->nick, dest->ident, dest->dhost, dest->fullname);
if ((user == dest) || (*user->oper))
{
- WriteServ(user->fd,"378 %s %s :is connecting from *@%s %s",user->nick, dest->nick, dest->host, insp_ntoa(dest->ip4));
+ WriteServ(user->fd,"378 %s %s :is connecting from *@%s %s",user->nick, dest->nick, dest->host, dest->GetIPString());
}
std::string cl = chlist(dest,user);
if (cl.length())
diff --git a/src/commands.cpp b/src/commands.cpp
index 247fc89b7..bcdf4971d 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -239,7 +239,7 @@ bool ip_matches_everyone(const std::string &ip, userrec* user)
for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
{
- if (match(insp_ntoa(u->second->ip4),ip.c_str()))
+ if (match(u->second->GetIPString(),ip.c_str()))
matches++;
}
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index 26f92c4df..9ba9d7b39 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -165,11 +165,11 @@ void Write_NoFormat(int sock, const char *text)
{
bytes = snprintf(tb,MAXBUF,"%s\r\n",text);
- if (Config->GetIOHook(fd_ref_table[sock]->port))
+ if (Config->GetIOHook(fd_ref_table[sock]->GetPort()))
{
try
{
- Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ Config->GetIOHook(fd_ref_table[sock]->GetPort())->OnRawSocketWrite(sock,tb,bytes);
}
catch (ModuleException& modexcept)
{
@@ -213,11 +213,11 @@ void Write(int sock, char *text, ...)
va_end(argsPtr);
bytes = snprintf(tb,MAXBUF,"%s\r\n",textbuffer);
- if (Config->GetIOHook(fd_ref_table[sock]->port))
+ if (Config->GetIOHook(fd_ref_table[sock]->GetPort()))
{
try
{
- Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ Config->GetIOHook(fd_ref_table[sock]->GetPort())->OnRawSocketWrite(sock,tb,bytes);
}
catch (ModuleException& modexcept)
{
@@ -249,11 +249,11 @@ void WriteServ_NoFormat(int sock, const char* text)
{
bytes = snprintf(tb,MAXBUF,":%s %s\r\n",Config->ServerName,text);
- if (Config->GetIOHook(fd_ref_table[sock]->port))
+ if (Config->GetIOHook(fd_ref_table[sock]->GetPort()))
{
try
{
- Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ Config->GetIOHook(fd_ref_table[sock]->GetPort())->OnRawSocketWrite(sock,tb,bytes);
}
catch (ModuleException& modexcept)
{
@@ -313,11 +313,11 @@ void WriteFrom_NoFormat(int sock, userrec *user, const char* text)
{
bytes = snprintf(tb,MAXBUF,":%s %s\r\n",user->GetFullHost(),text);
- if (Config->GetIOHook(fd_ref_table[sock]->port))
+ if (Config->GetIOHook(fd_ref_table[sock]->GetPort()))
{
try
{
- Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ Config->GetIOHook(fd_ref_table[sock]->GetPort())->OnRawSocketWrite(sock,tb,bytes);
}
catch (ModuleException& modexcept)
{
@@ -360,11 +360,11 @@ void WriteFrom(int sock, userrec *user,char* text, ...)
va_end(argsPtr);
bytes = snprintf(tb,MAXBUF,":%s %s\r\n",user->GetFullHost(),textbuffer);
- if (Config->GetIOHook(fd_ref_table[sock]->port))
+ if (Config->GetIOHook(fd_ref_table[sock]->GetPort()))
{
try
{
- Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ Config->GetIOHook(fd_ref_table[sock]->GetPort())->OnRawSocketWrite(sock,tb,bytes);
}
catch (ModuleException& modexcept)
{
@@ -1405,7 +1405,7 @@ ConnectClass GetClass(userrec *user)
{
for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
{
- if ((match(insp_ntoa(user->ip4),i->host.c_str())) || (match(user->host,i->host.c_str())))
+ if ((match(user->GetIPString(),i->host.c_str())) || (match(user->host,i->host.c_str())))
{
return *i;
}
diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp
index 2ab89533c..ce9099d53 100644
--- a/src/modules/extra/m_ssl_gnutls.cpp
+++ b/src/modules/extra/m_ssl_gnutls.cpp
@@ -203,7 +203,7 @@ class ModuleSSLGnuTLS : public Module
{
userrec* user = (userrec*)item;
- if(user->GetExt("ssl", dummy) && isin(user->port, listenports))
+ if(user->GetExt("ssl", dummy) && isin(user->GetPort(), listenports))
{
// User is using SSL, they're a local user, and they're using one of *our* SSL ports.
// Potentially there could be multiple SSL modules loaded at once on different ports.
@@ -461,7 +461,7 @@ class ModuleSSLGnuTLS : public Module
virtual void OnWhois(userrec* source, userrec* dest)
{
// Bugfix, only send this numeric for *our* SSL users
- if(dest->GetExt("ssl", dummy) || (IS_LOCAL(dest) && isin(dest->port, listenports)))
+ if(dest->GetExt("ssl", dummy) || (IS_LOCAL(dest) && isin(dest->GetPort(), listenports)))
{
WriteServ(source->fd, "320 %s %s :is using a secure connection", source->nick, dest->nick);
}
diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp
index 031df5c71..c9b9d42aa 100644
--- a/src/modules/extra/m_ssl_openssl.cpp
+++ b/src/modules/extra/m_ssl_openssl.cpp
@@ -227,7 +227,7 @@ class ModuleSSLOpenSSL : public Module
{
userrec* user = (userrec*)item;
- if(user->GetExt("ssl", dummy) && IS_LOCAL(user) && isin(user->port, listenports))
+ if(user->GetExt("ssl", dummy) && IS_LOCAL(user) && isin(user->GetPort(), listenports))
{
// User is using SSL, they're a local user, and they're using one of *our* SSL ports.
// Potentially there could be multiple SSL modules loaded at once on different ports.
@@ -533,7 +533,7 @@ class ModuleSSLOpenSSL : public Module
virtual void OnWhois(userrec* source, userrec* dest)
{
// Bugfix, only send this numeric for *our* SSL users
- if(dest->GetExt("ssl", dummy) || (IS_LOCAL(dest) && isin(dest->port, listenports)))
+ if(dest->GetExt("ssl", dummy) || (IS_LOCAL(dest) && isin(dest->GetPort(), listenports)))
{
WriteServ(source->fd, "320 %s %s :is using a secure connection", source->nick, dest->nick);
}
diff --git a/src/modules/m_cgiirc.cpp b/src/modules/m_cgiirc.cpp
index a063a0849..dea13d114 100644
--- a/src/modules/m_cgiirc.cpp
+++ b/src/modules/m_cgiirc.cpp
@@ -198,16 +198,16 @@ public:
virtual void OnUserRegister(userrec* user)
{
- log(DEBUG, "m_cgiirc.so: User %s registering, %s %s", user->nick,user->host,insp_ntoa(user->ip4));
+ log(DEBUG, "m_cgiirc.so: User %s registering, %s %s", user->nick,user->host,user->GetIPString());
for(CGIHostlist::iterator iter = Hosts.begin(); iter != Hosts.end(); iter++)
{
- log(DEBUG, "m_cgiirc.so: Matching %s against (%s or %s)", iter->hostmask.c_str(), user->host, insp_ntoa(user->ip4));
+ log(DEBUG, "m_cgiirc.so: Matching %s against (%s or %s)", iter->hostmask.c_str(), user->host, user->GetIPString());
- if(Srv->MatchText(user->host, iter->hostmask) || Srv->MatchText(insp_ntoa(user->ip4), iter->hostmask))
+ if(Srv->MatchText(user->host, iter->hostmask) || Srv->MatchText(user->GetIPString(), iter->hostmask))
{
// Deal with it...
- log(DEBUG, "m_cgiirc.so: Handling CGI:IRC user: %s (%s) matched %s", user->GetFullRealHost(), insp_ntoa(user->ip4), iter->hostmask.c_str());
+ log(DEBUG, "m_cgiirc.so: Handling CGI:IRC user: %s (%s) matched %s", user->GetFullRealHost(), user->GetIPString(), iter->hostmask.c_str());
if(iter->type == PASS)
{
@@ -240,11 +240,15 @@ public:
if(IsValidHost(user->password))
{
user->Extend("cgiirc_realhost", new std::string(user->host));
- user->Extend("cgiirc_realip", new std::string(insp_ntoa(user->ip4)));
+ user->Extend("cgiirc_realip", new std::string(user->GetIPString()));
strlcpy(user->host, user->password, 64);
strlcpy(user->dhost, user->password, 64);
- if(insp_aton(user->password, &user->ip4))
+#ifdef IPV6
+ if (insp_aton(user->password, (insp_inaddr*)&((sockaddr_in*)&user->ip)->sin6_addr))
+#else
+ if (insp_aton(user->password, (insp_inaddr*)&((sockaddr_in*)&user->ip)->sin_addr))
+#endif
{
/* We were given a IP in the password, we don't do DNS so they get this is as their host as well. */
log(DEBUG, "m_cgiirc.so: Got an IP in the user's password");
@@ -305,9 +309,13 @@ public:
snprintf(newip, 16, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
user->Extend("cgiirc_realhost", new std::string(user->host));
- user->Extend("cgiirc_realip", new std::string(insp_ntoa(user->ip4)));
- insp_aton(newip, &user->ip4);
-
+ user->Extend("cgiirc_realip", new std::string(user->GetIPString()));
+#ifdef IPV6
+ insp_aton(newip, (insp_inaddr*)&((sockaddr_in*)&user->ip)->sin6_addr);
+#else
+ insp_aton(newip, (insp_inaddr*)&((sockaddr_in*)&user->ip)->sin_addr);
+#endif
+
try
{
log(DEBUG,"MAKE RESOLVER: %s %d %s",newip, user->fd, "IDENT");
diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp
index 70c17ba1b..a00d32b9e 100644
--- a/src/modules/m_check.cpp
+++ b/src/modules/m_check.cpp
@@ -86,7 +86,7 @@ class cmd_check : public command_t
if (IS_LOCAL(targuser))
{
/* port information is only held for a local user! */
- Srv->SendTo(NULL, user, checkstr + " onport " + ConvToStr(targuser->port));
+ Srv->SendTo(NULL, user, checkstr + " onport " + ConvToStr(targuser->GetPort()));
}
chliststr = chlist(targuser, targuser);
@@ -158,38 +158,21 @@ class cmd_check : public command_t
else
{
/* /check on an IP address, or something that doesn't exist */
- insp_sockaddr addr;
long x = 0;
-#ifdef IPV6
- if (insp_aton(parameters[0], &addr.sin6_addr) == 0)
-#else
- if (insp_aton(parameters[0], &addr.sin_addr) == 0)
-#endif
+
+ /* hostname or other */
+ for (user_hash::const_iterator a = clientlist.begin(); a != clientlist.end(); a++)
{
- /* hostname or other */
- for (user_hash::const_iterator a = clientlist.begin(); a != clientlist.end(); a++)
+ if (match(a->second->host, parameters[0]) || match(a->second->dhost, parameters[0]))
{
- if (match(a->second->host, parameters[0]) || match(a->second->dhost, parameters[0]))
- {
- /* host or vhost matches mask */
- Srv->SendTo(NULL, user, checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
- }
+ /* host or vhost matches mask */
+ Srv->SendTo(NULL, user, checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
}
- }
- else
- {
/* IP address */
- for (user_hash::const_iterator a = clientlist.begin(); a != clientlist.end(); a++)
+ else if (match(a->second->GetIPString(), parameters[0]))
{
-#ifdef IPV6
- if (!memcmp(addr.sin6_addr.s6_addr, a->second->ip4.s6_addr, sizeof(in6_addr)))
-#else
- if (addr.sin_addr.s_addr == a->second->ip4.s_addr)
-#endif
- {
- /* same IP. */
- Srv->SendTo(NULL, user, checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
- }
+ /* same IP. */
+ Srv->SendTo(NULL, user, checkstr + " match " + ConvToStr(++x) + " " + a->second->GetFullRealHost());
}
}
diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp
index 76518d5c1..fe697e4b7 100644
--- a/src/modules/m_ident.cpp
+++ b/src/modules/m_ident.cpp
@@ -43,7 +43,7 @@ class RFC1413 : public InspSocket
userrec* u; // user record that the lookup is associated with
int ufd;
- RFC1413(userrec* user, int maxtime, Server* S) : InspSocket((char*)insp_ntoa(user->ip4), 113, false, maxtime), Srv(S), u(user), ufd(user->fd)
+ RFC1413(userrec* user, int maxtime, Server* S) : InspSocket(user->GetIPString(), 113, false, maxtime), Srv(S), u(user), ufd(user->fd)
{
Srv->Log(DEBUG,"Ident: associated.");
}
diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp
index f64f24013..071da8ac3 100644
--- a/src/modules/m_spanningtree.cpp
+++ b/src/modules/m_spanningtree.cpp
@@ -1563,9 +1563,13 @@ class TreeSocket : public InspSocket
{
clientlist[tempnick]->modes[(*v)-65] = 1;
}
- insp_aton(params[6].c_str(),&clientlist[tempnick]->ip4);
- WriteOpers("*** Client connecting at %s: %s!%s@%s [%s]",clientlist[tempnick]->server,clientlist[tempnick]->nick,clientlist[tempnick]->ident,clientlist[tempnick]->host, insp_ntoa(clientlist[tempnick]->ip4));
+ if (params[6].find_first_of(":") != std::string::npos)
+ clientlist[tempnick]->SetSockAddr(AF_INET6, params[6].c_str(), 0);
+ else
+ clientlist[tempnick]->SetSockAddr(AF_INET, params[6].c_str(), 0);
+
+ WriteOpers("*** Client connecting at %s: %s!%s@%s [%s]",clientlist[tempnick]->server,clientlist[tempnick]->nick,clientlist[tempnick]->ident,clientlist[tempnick]->host, clientlist[tempnick]->GetIPString());
params[7] = ":" + params[7];
DoOneToAllButSender(source,"NICK",params,source);
@@ -1770,7 +1774,7 @@ class TreeSocket : public InspSocket
{
if (u->second->registered == REG_ALL)
{
- snprintf(data,MAXBUF,":%s NICK %lu %s %s %s %s +%s %s :%s",u->second->server,(unsigned long)u->second->age,u->second->nick,u->second->host,u->second->dhost,u->second->ident,u->second->FormatModes(),insp_ntoa(u->second->ip4),u->second->fullname);
+ snprintf(data,MAXBUF,":%s NICK %lu %s %s %s %s +%s %s :%s",u->second->server,(unsigned long)u->second->age,u->second->nick,u->second->host,u->second->dhost,u->second->ident,u->second->FormatModes(),u->second->GetIPString(),u->second->fullname);
this->WriteLine(data);
if (*u->second->oper)
{
@@ -4167,7 +4171,7 @@ class ModuleSpanningTree : public Module
params.push_back(user->dhost);
params.push_back(user->ident);
params.push_back("+"+std::string(user->FormatModes()));
- params.push_back((char*)insp_ntoa(user->ip4));
+ params.push_back(user->GetIPString());
params.push_back(":"+std::string(user->fullname));
DoOneToMany(Srv->GetServerName(),"NICK",params);
diff --git a/src/modules/m_userip.cpp b/src/modules/m_userip.cpp
index d7126684d..df633af80 100644
--- a/src/modules/m_userip.cpp
+++ b/src/modules/m_userip.cpp
@@ -45,7 +45,7 @@ class cmd_userip : public command_t
userrec *u = Find(parameters[i]);
if (u)
{
- snprintf(junk,MAXBUF,"%s%s=+%s@%s ",u->nick,*u->oper ? "*" : "",u->ident,(char*)insp_ntoa(u->ip4));
+ snprintf(junk,MAXBUF,"%s%s=+%s@%s ",u->nick,*u->oper ? "*" : "",u->ident,u->GetIPString());
strlcat(Return,junk,MAXBUF);
}
}
diff --git a/src/userprocess.cpp b/src/userprocess.cpp
index 22a48fdcc..7468d0890 100644
--- a/src/userprocess.cpp
+++ b/src/userprocess.cpp
@@ -79,14 +79,14 @@ void ProcessUser(userrec* cu)
log(DEBUG,"Processing user with fd %d",cu->fd);
- if (Config->GetIOHook(cu->port))
+ if (Config->GetIOHook(cu->GetPort()))
{
int result2 = 0;
int MOD_RESULT = 0;
try
{
- MOD_RESULT = Config->GetIOHook(cu->port)->OnRawSocketRead(cu->fd,data,65535,result2);
+ MOD_RESULT = Config->GetIOHook(cu->GetPort())->OnRawSocketRead(cu->fd,data,65535,result2);
log(DEBUG,"Data result returned by module: %d",MOD_RESULT);
}
catch (ModuleException& modexcept)
@@ -168,9 +168,9 @@ void ProcessUser(userrec* cu)
}
else
{
- WriteOpers("*** Excess flood from %s",(char*)insp_ntoa(current->ip4));
- log(DEFAULT,"Excess flood from: %s",(char*)insp_ntoa(current->ip4));
- add_zline(120,Config->ServerName,"Flood from unregistered connection",(char*)insp_ntoa(current->ip4));
+ WriteOpers("*** Excess flood from %s",current->GetIPString());
+ log(DEFAULT,"Excess flood from: %s",current->GetIPString());
+ add_zline(120,Config->ServerName,"Flood from unregistered connection",current->GetIPString());
apply_lines(APPLY_ZLINES);
}
@@ -185,9 +185,9 @@ void ProcessUser(userrec* cu)
}
else
{
- WriteOpers("*** Excess flood from %s",(char*)insp_ntoa(current->ip4));
- log(DEFAULT,"Excess flood from: %s",(char*)insp_ntoa(current->ip4));
- add_zline(120,Config->ServerName,"Flood from unregistered connection",(char*)insp_ntoa(current->ip4));
+ WriteOpers("*** Excess flood from %s",current->GetIPString());
+ log(DEFAULT,"Excess flood from: %s",current->GetIPString());
+ add_zline(120,Config->ServerName,"Flood from unregistered connection",current->GetIPString());
apply_lines(APPLY_ZLINES);
}
@@ -221,7 +221,7 @@ void ProcessUser(userrec* cu)
}
else
{
- add_zline(120,Config->ServerName,"Flood from unregistered connection",(char*)insp_ntoa(current->ip4));
+ add_zline(120,Config->ServerName,"Flood from unregistered connection",current->GetIPString());
apply_lines(APPLY_ZLINES);
}
diff --git a/src/users.cpp b/src/users.cpp
index 661dc905b..258bb725a 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -139,7 +139,7 @@ void userrec::StartDNSLookup()
log(DEBUG,"Commencing reverse lookup");
try
{
- res_reverse = new UserResolver(this, insp_ntoa(this->ip4), false);
+ res_reverse = new UserResolver(this, this->GetIPString(), false);
MyServer->AddResolver(res_reverse);
}
catch (ModuleException& e)
@@ -173,7 +173,7 @@ void UserResolver::OnLookupComplete(const std::string &result)
else if ((this->fwd) && (fd_ref_table[this->bound_fd] == this->bound_user))
{
/* Both lookups completed */
- if (insp_ntoa(this->bound_user->ip4) == result)
+ if (this->bound_user->GetIPString() == result)
{
std::string hostname = this->bound_user->stored_host;
if (hostname.length() < 65)
@@ -185,12 +185,12 @@ void UserResolver::OnLookupComplete(const std::string &result)
}
else
{
- WriteServ(this->bound_fd, "NOTICE Auth :*** Your hostname is longer than the maximum of 64 characters, using your IP address (%s) instead.", insp_ntoa(this->bound_user->ip4));
+ WriteServ(this->bound_fd, "NOTICE Auth :*** Your hostname is longer than the maximum of 64 characters, using your IP address (%s) instead.", this->bound_user->GetIPString());
}
}
else
{
- WriteServ(this->bound_fd, "NOTICE Auth :*** Your hostname does not match up with your IP address. Sorry, using your IP address (%s) instead.", insp_ntoa(this->bound_user->ip4));
+ WriteServ(this->bound_fd, "NOTICE Auth :*** Your hostname does not match up with your IP address. Sorry, using your IP address (%s) instead.", this->bound_user->GetIPString());
}
}
}
@@ -200,7 +200,7 @@ void UserResolver::OnError(ResolverError e, const std::string &errormessage)
if (fd_ref_table[this->bound_fd] == this->bound_user)
{
/* Error message here */
- WriteServ(this->bound_fd, "NOTICE Auth :*** Could not resolve your hostname, using your IP address (%s) instead.", insp_ntoa(this->bound_user->ip4));
+ WriteServ(this->bound_fd, "NOTICE Auth :*** Could not resolve your hostname, using your IP address (%s) instead.", this->bound_user->GetIPString());
this->bound_user->dns_done = true;
}
}
@@ -263,7 +263,7 @@ userrec::userrec()
server = (char*)FindServerNamePtr(Config->ServerName);
reset_due = TIME;
lines_in = fd = lastping = signon = idle_lastmsg = nping = registered = 0;
- timeout = flood = port = bytes_in = bytes_out = cmds_in = cmds_out = 0;
+ timeout = flood = bytes_in = bytes_out = cmds_in = cmds_out = 0;
haspassed = dns_done = false;
recvq = "";
sendq = "";
@@ -650,11 +650,11 @@ void kill_link(userrec *user,const char* r)
if (IS_LOCAL(user))
{
- if (Config->GetIOHook(user->port))
+ if (Config->GetIOHook(user->GetPort()))
{
try
{
- Config->GetIOHook(user->port)->OnRawSocketClose(user->fd);
+ Config->GetIOHook(user->GetPort())->OnRawSocketClose(user->fd);
}
catch (ModuleException& modexcept)
{
@@ -766,11 +766,11 @@ void MaintainWhoWas(time_t TIME)
}
/* add a client connection to the sockets list */
-void AddClient(int socket, int port, bool iscached, insp_inaddr ip4)
+void AddClient(int socket, int port, bool iscached, insp_inaddr ip)
{
std::string tempnick = ConvToStr(socket) + "-unknown";
user_hash::iterator iter = clientlist.find(tempnick);
- const char *ipaddr = insp_ntoa(ip4);
+ const char *ipaddr = insp_ntoa(ip);
userrec* _new;
int j = 0;
@@ -809,8 +809,7 @@ void AddClient(int socket, int port, bool iscached, insp_inaddr ip4)
_new->registered = REG_NONE;
_new->signon = TIME + Config->dns_timeout;
_new->lastping = 1;
- _new->ip4 = ip4;
- _new->port = port;
+ _new->SetSockAddr(AF_FAMILY, inet_ntoa(ip), port);
// set the registration timeout for this user
unsigned long class_regtimeout = 90;
@@ -900,10 +899,14 @@ long FindMatchingGlobal(userrec* user)
/* I dont think theres any faster way of matching two ipv6 addresses than memcmp
* Let me know if you think of one.
*/
- if (!memcmp(a->second->ip4.s6_addr, user->ip4.s6_addr, sizeof(in6_addr)))
+ in6_addr* s1 = &(((sockaddr_in*)&a->second->ip)->sin6_addr);
+ in6_addr* s2 = &(((sockaddr_in*)&user->ip)->sin6_addr);
+ if (!memcmp(s1->s6_addr, s2->s6_addr, sizeof(in6_addr)))
x++;
#else
- if (a->second->ip4.s_addr == user->ip4.s_addr)
+ in_addr* s1 = &((sockaddr_in*)&a->second->ip)->sin_addr;
+ in_addr* s2 = &((sockaddr_in*)&user->ip)->sin_addr;
+ if (s1->s_addr == s2->s_addr)
x++;
#endif
}
@@ -918,10 +921,14 @@ long FindMatchingLocal(userrec* user)
userrec* comp = *a;
#ifdef IPV6
/* I dont think theres any faster way of matching two ipv6 addresses than memcmp */
- if (!memcmp(comp->ip4.s6_addr, user->ip4.s6_addr, sizeof(in6_addr)))
+ in6_addr* s1 = &(((sockaddr_in*)&comp->ip)->sin6_addr);
+ in6_addr* s2 = &(((sockaddr_in*)&user->ip)->sin6_addr);
+ if (!memcmp(s1->s6_addr, s2->s6_addr, sizeof(in6_addr)))
x++;
#else
- if (comp->ip4.s_addr == user->ip4.s_addr)
+ in_addr* s1 = &((sockaddr_in*)&comp->ip)->sin_addr;
+ in_addr* s2 = &((sockaddr_in*)&user->ip)->sin_addr;
+ if (s1->s_addr == s2->s_addr)
x++;
#endif
}
@@ -951,13 +958,13 @@ void FullConnectUser(userrec* user, CullList* Goners)
if (FindMatchingLocal(user) > a.maxlocal)
{
Goners->AddItem(user,"No more connections allowed from your host via this connect class (local)");
- WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s",a.maxlocal,insp_ntoa(user->ip4));
+ WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s",a.maxlocal,user->GetIPString());
return;
}
else if (FindMatchingGlobal(user) > a.maxglobal)
{
Goners->AddItem(user,"No more connections allowed from your host via this connect class (global)");
- WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s",a.maxglobal,insp_ntoa(user->ip4));
+ WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s",a.maxglobal,user->GetIPString());
return;
}
@@ -1025,7 +1032,7 @@ void FullConnectUser(userrec* user, CullList* Goners)
FOREACH_MOD(I_OnUserConnect,OnUserConnect(user));
FOREACH_MOD(I_OnGlobalConnect,OnGlobalConnect(user));
user->registered = REG_ALL;
- WriteOpers("*** Client connecting on port %lu: %s!%s@%s [%s]",(unsigned long)user->port,user->nick,user->ident,user->host,insp_ntoa(user->ip4));
+ WriteOpers("*** Client connecting on port %d: %s!%s@%s [%s]",user->GetPort(),user->nick,user->ident,user->host,user->GetIPString());
}
/** ReHashNick()
@@ -1099,3 +1106,86 @@ void force_nickchange(userrec* user,const char* newnick)
}
}
}
+
+void userrec::SetSockAddr(int protocol_family, const char* ip, int port)
+{
+ switch (protocol_family)
+ {
+ case AF_INET6:
+ {
+ sockaddr_in6* sin = (sockaddr_in6*)&this->ip;
+ sin->sin6_family = AF_INET6;
+ sin->sin6_port = port;
+ inet_pton(AF_INET6, ip, &sin->sin6_addr);
+ }
+ break;
+ case AF_INET:
+ {
+ sockaddr_in* sin = (sockaddr_in*)&this->ip;
+ sin->sin_family = AF_INET;
+ sin->sin_port = port;
+ inet_pton(AF_INET, ip, &sin->sin_addr);
+ }
+ break;
+ default:
+ log(DEBUG,"Ut oh, I dont know protocol %d to be set on '%s'!", protocol_family, this->nick);
+ break;
+ }
+}
+
+int userrec::GetPort()
+{
+ switch (this->GetProtocolFamily())
+ {
+ case AF_INET6:
+ {
+ sockaddr_in6* sin = (sockaddr_in6*)&this->ip;
+ return sin->sin6_port;
+ }
+ break;
+ case AF_INET:
+ {
+ sockaddr_in* sin = (sockaddr_in*)&this->ip;
+ return sin->sin_port;
+ }
+ break;
+ default:
+ log(DEBUG,"Ut oh, '%s' has an unknown protocol family!",this->nick);
+ break;
+ }
+ return 0;
+}
+
+int userrec::GetProtocolFamily()
+{
+ sockaddr_in* sin = (sockaddr_in*)&this->ip;
+ return sin->sin_family;
+}
+
+const char* userrec::GetIPString()
+{
+ static char buf[1024];
+
+ switch (this->GetProtocolFamily())
+ {
+ case AF_INET6:
+ {
+ sockaddr_in6* sin = (sockaddr_in6*)&this->ip;
+ inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
+ return buf;
+ }
+ break;
+ case AF_INET:
+ {
+ sockaddr_in* sin = (sockaddr_in*)&this->ip;
+ inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
+ return buf;
+ }
+ break;
+ default:
+ log(DEBUG,"Ut oh, '%s' has an unknown protocol family!",this->nick);
+ break;
+ }
+ return "";
+}
+
diff --git a/src/xline.cpp b/src/xline.cpp
index 740f9cb49..7970f977e 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -703,7 +703,7 @@ void apply_lines(const int What)
}
if ((What & APPLY_ZLINES) && (zlines.size() || pzlines.size()))
{
- if ((check = matches_zline(insp_ntoa(u->ip4))))
+ if ((check = matches_zline(u->GetIPString())))
{
snprintf(reason,MAXBUF,"Z-Lined: %s",check);
Goners->AddItem(u,reason);