From b8c3c5d25b84b358fc93eea0e885372dcad01480 Mon Sep 17 00:00:00 2001 From: brain Date: Fri, 4 Aug 2006 11:03:21 +0000 Subject: Safety wrapper defines for ipv6 code on ipv4 ircds git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4697 e03df62e-2008-0410-955e-edbf42e46eb7 --- configure | 19 ++++++++++++++++--- src/dns.cpp | 7 ++++++- src/users.cpp | 25 +++++++++++-------------- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/configure b/configure index a46a22e9e..e44f3a595 100755 --- a/configure +++ b/configure @@ -38,8 +38,9 @@ $config{HAS_STDINT} = "false"; # stdint.h check $config{HAS_EXECINFO} = "0"; # execinfo.h Check. $config{USE_KQUEUE} = "y"; # kqueue enabled $config{USE_EPOLL} = "y"; # epoll enabled -$config{THREADED_DNS} = "n"; # threaded dns (experimental) +$config{THREADED_DNS} = "n"; # threaded dns $config{IPV6} = "n"; # IPv6 support (experimental) +$config{SUPPORT_IP6LINKS} = "y"; # IPv4 supporting IPv6 links (experimental) $config{STATIC_LINK} = "no"; # are doing static modules? chomp($config{MAX_CLIENT_T} = `sh -c \"ulimit -n\"`); # FD Limit chomp($config{MAX_DESCRIPTORS} = `sh -c \"ulimit -n\"`); # Hard FD Limit @@ -360,9 +361,17 @@ if (!$chose_hiperf) { print "not to enable one. Defaulting to select() engine.\n\n"; } -yesno(IPV6,"Would you like to enable experimental IPv6 support?"); +yesno(IPV6,"Would you like to build InspIRCd with IPv6 support?"); print "\n"; +if ($config{IPV6} eq "y") { + print "You have chosen to build an \033[1;32mIPV6-only\033[0m server.\nTo accept IPV4 users, you must use the '::ffff:' notation of addresses.\n\n"; + $config{SUPPORT_IP6LINKS} = "y"; +} else { + yesno(SUPPORT_IP6LINKS,"You have chosen to build an \033[1;32mIPV4-only\033[0m server.\nWould you like to enable support for linking to IPV6-enabled\nInspIRCd servers which are using '::ffff:' notation?\nIf you are using a recent operating\nsystem and are unsure, answer yes."); + print "\n"; +} + if (($config{HAS_GNUTLS} eq "y") && ($config{HAS_OPENSSL} eq "y")) { print "I have detected both GnuTLS and OpenSSL on your system.\n"; print "I will default to GnuTLS. If you wish to use OpenSSL\n"; @@ -673,6 +682,7 @@ print "\033[0mCompiler program:\033[1;32m\t\t$config{CC}\033[0m\n"; print "\033[0mStatic modules:\033[1;32m\t\t\t$config{STATIC_LINK}\033[0m\n"; print "\033[0mMultithread DNS:\033[1;32m\t\t$config{THREADED_DNS}\033[0m\n"; print "\033[0mIPv6 Support:\033[1;32m\t\t\t$config{IPV6}\033[0m\n"; +print "\033[0mIPv6 to IPv4 Links:\033[1;32m\t\t\$config{SUPPORT_IP6LINKS}\033[0m\n"; print "\033[0mGnuTLS Support:\033[1;32m\t\t\t$config{USE_GNUTLS}\033[0m\n"; print "\033[0mOpenSSL Support:\033[1;32m\t\t$config{USE_OPENSSL}\033[0m\n\n"; @@ -1013,9 +1023,12 @@ EOF if ($config{THREADED_DNS} =~ /y/i) { print FILEHANDLE "#define THREADED_DNS\n"; } - if ($config{IPV6} =~/y/i) { + if ($config{IPV6} =~ /y/i) { print FILEHANDLE "#define IPV6\n"; } + if ($config{SUPPORT_IP6LINKS} =~ /y/i) { + print FILEHANDLE "#define SUPPORT_IP6LINKS\n"; + } my $use_hiperf = 0; if (($has_kqueue) && ($config{USE_KQUEUE} eq "y")) { print FILEHANDLE "#define USE_KQUEUE\n"; diff --git a/src/dns.cpp b/src/dns.cpp index 42db21424..0a22b28d8 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -453,7 +453,7 @@ int DNS::GetNameForce(const char *ip, ForceProtocol fp) DNSHeader h; int id; int length; - +#ifdef SUPPORT_IP6LINKS if (fp == PROTOCOL_IPV6) { in6_addr i; @@ -466,6 +466,7 @@ int DNS::GetNameForce(const char *ip, ForceProtocol fp) return -1; } else +#endif { in_addr i; if (inet_aton(ip, &i)) @@ -493,6 +494,7 @@ int DNS::GetNameForce(const char *ip, ForceProtocol fp) void DNS::MakeIP6Int(char* query, const in6_addr *ip) { +#ifdef SUPPORT_IP6LINKS const char* hex = "0123456789abcdef"; for (int index = 31; index >= 0; index--) /* for() loop steps twice per byte */ { @@ -505,6 +507,9 @@ void DNS::MakeIP6Int(char* query, const in6_addr *ip) *query++ = '.'; /* Seperator */ } strcpy(query,"ip6.arpa"); /* Suffix the string */ +#else + *query = 0; +#endif } /* Return the next id which is ready, and the result attached to it */ diff --git a/src/users.cpp b/src/users.cpp index 85d64d462..74f70b458 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -895,20 +895,11 @@ long FindMatchingGlobal(userrec* user) long x = 0; for (user_hash::const_iterator a = clientlist.begin(); a != clientlist.end(); a++) { -#ifdef IPV6 - /* I dont think theres any faster way of matching two ipv6 addresses than memcmp - * Let me know if you think of one. - */ - in6_addr* s1 = &(((sockaddr_in6*)&a->second->ip)->sin6_addr); - in6_addr* s2 = &(((sockaddr_in6*)&user->ip)->sin6_addr); - if (!memcmp(s1->s6_addr, s2->s6_addr, sizeof(in6_addr))) - x++; -#else - 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 + /* We have to match ip's as strings - we don't know what protocol + * a remote user may be using + */ + if (!strcasecmp(a->second->GetIPString(), user->GetIPString())) + x++; } return x; } @@ -1111,6 +1102,7 @@ void userrec::SetSockAddr(int protocol_family, const char* ip, int port) { switch (protocol_family) { +#ifdef SUPPORT_IP6LINKS case AF_INET6: { sockaddr_in6* sin = (sockaddr_in6*)&this->ip; @@ -1119,6 +1111,7 @@ void userrec::SetSockAddr(int protocol_family, const char* ip, int port) inet_pton(AF_INET6, ip, &sin->sin6_addr); } break; +#endif case AF_INET: { sockaddr_in* sin = (sockaddr_in*)&this->ip; @@ -1137,12 +1130,14 @@ int userrec::GetPort() { switch (this->GetProtocolFamily()) { +#ifdef SUPPORT_IP6LINKS case AF_INET6: { sockaddr_in6* sin = (sockaddr_in6*)&this->ip; return sin->sin6_port; } break; +#endif case AF_INET: { sockaddr_in* sin = (sockaddr_in*)&this->ip; @@ -1168,6 +1163,7 @@ const char* userrec::GetIPString() switch (this->GetProtocolFamily()) { +#ifdef SUPPORT_IP6LINKS case AF_INET6: { sockaddr_in6* sin = (sockaddr_in6*)&this->ip; @@ -1175,6 +1171,7 @@ const char* userrec::GetIPString() return buf; } break; +#endif case AF_INET: { sockaddr_in* sin = (sockaddr_in*)&this->ip; -- cgit v1.2.3