aboutsummaryrefslogtreecommitdiff
path: root/src/bitcoinrpc.cpp
diff options
context:
space:
mode:
authorGiel van Schijndel <me@mortis.eu>2011-08-10 14:21:43 +0200
committerGiel van Schijndel <me@mortis.eu>2012-05-25 07:27:24 +0200
commit43b6dafa6ed4abee14828333596f9c611d40e213 (patch)
treecf4c75977edf65e3eee9f609083c1eba73118938 /src/bitcoinrpc.cpp
parentc1ecab818c3d26e49bb68111c31bd8bd68956e1e (diff)
downloadbitcoin-43b6dafa6ed4abee14828333596f9c611d40e213.tar.xz
Allow clients on the IPv6 loopback as well
Signed-off-by: Giel van Schijndel <me@mortis.eu>
Diffstat (limited to 'src/bitcoinrpc.cpp')
-rw-r--r--src/bitcoinrpc.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index 293c3793de..08425b40ef 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -2548,10 +2548,19 @@ void ErrorReply(std::ostream& stream, const Object& objError, const Value& id)
stream << HTTPReply(nStatus, strReply, false) << std::flush;
}
-bool ClientAllowed(const string& strAddress)
+bool ClientAllowed(const boost::asio::ip::address& address)
{
- if (strAddress == asio::ip::address_v4::loopback().to_string())
+ // Make sure that IPv4-compatible and IPv4-mapped IPv6 addresses are treated as IPv4 addresses
+ if (address.is_v6()
+ && (address.to_v6().is_v4_compatible()
+ || address.to_v6().is_v4_mapped()))
+ return ClientAllowed(address.to_v6().to_v4());
+
+ if (address == asio::ip::address_v4::loopback()
+ || address == asio::ip::address_v6::loopback())
return true;
+
+ const string strAddress = address.to_string();
const vector<string>& vAllow = mapMultiArgs["-rpcallowip"];
BOOST_FOREACH(string strAllow, vAllow)
if (WildcardMatch(strAddress, strAllow))
@@ -2696,7 +2705,7 @@ static void RPCAcceptHandler(boost::shared_ptr<ip::tcp::acceptor> acceptor,
// Restrict callers by IP. It is important to
// do this before starting client thread, to filter out
// certain DoS and misbehaving clients.
- else if (!ClientAllowed(conn->peer.address().to_string()))
+ else if (!ClientAllowed(conn->peer.address()))
{
// Only send a 403 if we're not using SSL to prevent a DoS during the SSL handshake.
if (!fUseSSL)