summaryrefslogtreecommitdiff
path: root/indra/llmessage
diff options
context:
space:
mode:
authorLogan Dethrow <log@lindenlab.com>2011-06-28 19:54:53 -0400
committerLogan Dethrow <log@lindenlab.com>2011-06-28 19:54:53 -0400
commit7717b6f647feb250c0b94d038f72a640a7888915 (patch)
treeb021d01c78cd8fde5df522b11e2a71ebef9ed34b /indra/llmessage
parentf91d40c25949ee8c5b1d5c1babab62d6dd90d0c8 (diff)
STORM-1112 More cleanup of SOCKS 5 proxy code.
Renamed llsocks5.cpp to llproxy.cpp.
Diffstat (limited to 'indra/llmessage')
-rw-r--r--indra/llmessage/CMakeLists.txt4
-rw-r--r--indra/llmessage/llcurl.cpp38
-rw-r--r--indra/llmessage/lliosocket.h2
-rw-r--r--indra/llmessage/llpacketring.cpp40
-rw-r--r--indra/llmessage/llproxy.cpp (renamed from indra/llmessage/llsocks5.cpp)65
-rw-r--r--indra/llmessage/llproxy.h (renamed from indra/llmessage/llsocks5.h)17
-rw-r--r--indra/llmessage/net.cpp2
7 files changed, 77 insertions, 91 deletions
diff --git a/indra/llmessage/CMakeLists.txt b/indra/llmessage/CMakeLists.txt
index 4b679ef6a5..0f40a670fa 100644
--- a/indra/llmessage/CMakeLists.txt
+++ b/indra/llmessage/CMakeLists.txt
@@ -65,6 +65,7 @@ set(llmessage_SOURCE_FILES
llpacketbuffer.cpp
llpacketring.cpp
llpartdata.cpp
+ llproxy.cpp
llpumpio.cpp
llregionpresenceverifier.cpp
llsdappservices.cpp
@@ -76,7 +77,6 @@ set(llmessage_SOURCE_FILES
llsdrpcserver.cpp
llservicebuilder.cpp
llservice.cpp
- llsocks5.cpp
llstoredmessage.cpp
lltemplatemessagebuilder.cpp
lltemplatemessagedispatcher.cpp
@@ -162,6 +162,7 @@ set(llmessage_HEADER_FILES
llpacketring.h
llpartdata.h
llpumpio.h
+ llproxy.h
llqueryflags.h
llregionflags.h
llregionhandle.h
@@ -175,7 +176,6 @@ set(llmessage_HEADER_FILES
llsdrpcserver.h
llservice.h
llservicebuilder.h
- llsocks5.h
llstoredmessage.h
lltaskname.h
llteleportflags.h
diff --git a/indra/llmessage/llcurl.cpp b/indra/llmessage/llcurl.cpp
index 32dd438e68..0b368196d2 100644
--- a/indra/llmessage/llcurl.cpp
+++ b/indra/llmessage/llcurl.cpp
@@ -46,12 +46,12 @@
#endif
#include "llbufferstream.h"
-#include "llstl.h"
#include "llsdserialize.h"
+#include "llproxy.h"
+#include "llstl.h"
#include "llthread.h"
#include "lltimer.h"
-#include "llsocks5.h"
//////////////////////////////////////////////////////////////////////////////
/*
@@ -357,27 +357,6 @@ LLCurl::Easy* LLCurl::Easy::getEasy()
// multi handles cache if they are added to one.
CURLcode result = curl_easy_setopt(easy->mCurlEasyHandle, CURLOPT_DNS_CACHE_TIMEOUT, 0);
check_curl_code(result);
-
- //Set the CURL options for either Socks or HTTP proxy
- if (LLSocks::getInstance()->isHTTPProxyEnabled())
- {
- std::string address = LLSocks::getInstance()->getHTTPProxy().getIPString();
- U16 port = LLSocks::getInstance()->getHTTPProxy().getPort();
- curl_easy_setopt(easy->mCurlEasyHandle, CURLOPT_PROXY,address.c_str());
- curl_easy_setopt(easy->mCurlEasyHandle, CURLOPT_PROXYPORT,port);
- if (LLSocks::getInstance()->getHTTPProxyType() == LLPROXY_SOCKS)
- {
- curl_easy_setopt(easy->mCurlEasyHandle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
- if(LLSocks::getInstance()->getSelectedAuthMethod()==METHOD_PASSWORD)
- {
- curl_easy_setopt(easy->mCurlEasyHandle, CURLOPT_PROXYUSERPWD,LLSocks::getInstance()->getProxyUserPwd().c_str());
- }
- }
- else
- {
- curl_easy_setopt(easy->mCurlEasyHandle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
- }
- }
++gCurlEasyCount;
return easy;
@@ -557,18 +536,19 @@ void LLCurl::Easy::prepRequest(const std::string& url,
//setopt(CURLOPT_VERBOSE, 1); // usefull for debugging
setopt(CURLOPT_NOSIGNAL, 1);
- if (LLSocks::getInstance()->isHTTPProxyEnabled())
+ // Set the CURL options for either Socks or HTTP proxy
+ if (LLProxy::getInstance()->isHTTPProxyEnabled())
{
- std::string address = LLSocks::getInstance()->getHTTPProxy().getIPString();
- U16 port = LLSocks::getInstance()->getHTTPProxy().getPort();
+ std::string address = LLProxy::getInstance()->getHTTPProxy().getIPString();
+ U16 port = LLProxy::getInstance()->getHTTPProxy().getPort();
setoptString(CURLOPT_PROXY, address.c_str());
setopt(CURLOPT_PROXYPORT, port);
- if (LLSocks::getInstance()->getHTTPProxyType() == LLPROXY_SOCKS)
+ if (LLProxy::getInstance()->getHTTPProxyType() == LLPROXY_SOCKS)
{
setopt(CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
- if(LLSocks::getInstance()->getSelectedAuthMethod()==METHOD_PASSWORD)
+ if(LLProxy::getInstance()->getSelectedAuthMethod()==METHOD_PASSWORD)
{
- setoptString(CURLOPT_PROXYUSERPWD,LLSocks::getInstance()->getProxyUserPwd());
+ setoptString(CURLOPT_PROXYUSERPWD, LLProxy::getInstance()->getProxyUserPwdCURL());
}
}
else
diff --git a/indra/llmessage/lliosocket.h b/indra/llmessage/lliosocket.h
index 6806e5084a..ec60470459 100644
--- a/indra/llmessage/lliosocket.h
+++ b/indra/llmessage/lliosocket.h
@@ -159,7 +159,7 @@ protected:
public:
/**
- * @brief Do not call this directly.
+ * @brief Do not call this directly. Use LLSocket::ptr_t.reset() instead.
*/
~LLSocket();
diff --git a/indra/llmessage/llpacketring.cpp b/indra/llmessage/llpacketring.cpp
index 62aaca0672..91ab1df149 100644
--- a/indra/llmessage/llpacketring.cpp
+++ b/indra/llmessage/llpacketring.cpp
@@ -37,19 +37,13 @@
// linden library includes
#include "llerror.h"
-#include "message.h"
-#include "llsocks5.h"
#include "lltimer.h"
-#include "timing.h"
+#include "llproxy.h"
#include "llrand.h"
+#include "message.h"
+#include "timing.h"
#include "u64.h"
-
-
-
-
-
-
///////////////////////////////////////////////////////////
LLPacketRing::LLPacketRing () :
mUseInThrottle(FALSE),
@@ -231,28 +225,28 @@ S32 LLPacketRing::receivePacket (S32 socket, char *datap)
else
{
// no delay, pull straight from net
- if (LLSocks::isEnabled())
+ if (LLProxy::isEnabled())
{
- U8 buffer[MAX_BUFFER_SIZE];
- packet_size = receive_packet(socket, (char*)buffer);
+ U8 buffer[NET_BUFFER_SIZE];
+ packet_size = receive_packet(socket, reinterpret_cast<char *>(buffer));
if (packet_size > 10)
{
- memcpy(datap,buffer+10,packet_size-10);
+ // *FIX We are assuming ATYP is 0x01 (IPv4), not 0x03 (hostname) or 0x04 (IPv6)
+ memcpy(datap, buffer + 10, packet_size - 10);
+ proxywrap_t * header = reinterpret_cast<proxywrap_t *>(buffer);
+ mLastSender.setAddress(header->addr);
+ mLastSender.setPort(ntohs(header->port));
}
else
{
- packet_size=0;
+ packet_size = 0;
}
-
- proxywrap_t * header = (proxywrap_t *)buffer;
- mLastSender.setAddress(header->addr);
- mLastSender.setPort(ntohs(header->port));
}
else
{
- packet_size = receive_packet(socket, datap);
- mLastSender = ::get_sender();
+ packet_size = receive_packet(socket, datap);
+ mLastSender = ::get_sender();
}
mLastReceivingIF = ::get_receiving_interface();
@@ -352,7 +346,7 @@ BOOL LLPacketRing::sendPacket(int h_socket, char * send_buffer, S32 buf_size, LL
BOOL LLPacketRing::doSendPacket(int h_socket, const char * send_buffer, S32 buf_size, LLHost host)
{
- if (!LLSocks::isEnabled())
+ if (!LLProxy::isEnabled())
{
return send_packet(h_socket, send_buffer, buf_size, host.getAddress(), host.getPort());
}
@@ -364,7 +358,7 @@ BOOL LLPacketRing::doSendPacket(int h_socket, const char * send_buffer, S32 buf_
socks_header->atype = ADDRESS_IPV4;
socks_header->frag = 0;
- memcpy(mProxyWrappedSendBuffer+10, send_buffer, buf_size);
+ memcpy(mProxyWrappedSendBuffer + 10, send_buffer, buf_size);
- return send_packet(h_socket,(const char*) mProxyWrappedSendBuffer, buf_size+10, LLSocks::getInstance()->getUDPProxy().getAddress(), LLSocks::getInstance()->getUDPProxy().getPort());
+ return send_packet(h_socket,(const char*) mProxyWrappedSendBuffer, buf_size + 10, LLProxy::getInstance()->getUDPProxy().getAddress(), LLProxy::getInstance()->getUDPProxy().getPort());
}
diff --git a/indra/llmessage/llsocks5.cpp b/indra/llmessage/llproxy.cpp
index 278350bf25..6bc9e8b62b 100644
--- a/indra/llmessage/llsocks5.cpp
+++ b/indra/llmessage/llproxy.cpp
@@ -26,7 +26,7 @@
#include "linden_common.h"
-#include "llsocks5.h"
+#include "llproxy.h"
#include <string>
@@ -40,26 +40,37 @@
// We want this to be static to avoid excessive indirection on every
// incoming packet just to do a simple bool test. The getter for this
// member is also static
-bool LLSocks::sUDPProxyEnabled;
-bool LLSocks::sHTTPProxyEnabled;
+bool LLProxy::sUDPProxyEnabled = false;
+bool LLProxy::sHTTPProxyEnabled = false;
// Some helpful TCP functions
-static LLSocket::ptr_t tcp_open_channel(LLHost host); // Open a TCP channel to a given host
+static LLSocket::ptr_t tcp_open_channel(apr_pool_t* pool, LLHost host); // Open a TCP channel to a given host
static void tcp_close_channel(LLSocket::ptr_t handle); // Close an open TCP channel
static int tcp_handshake(LLSocket::ptr_t handle, char * dataout, apr_size_t outlen, char * datain, apr_size_t maxinlen); // Do a TCP data handshake
-LLSocks::LLSocks()
+LLProxy::LLProxy():
+ mProxyType(LLPROXY_SOCKS),
+ mUDPProxy(),
+ mTCPProxy(),
+ mHTTPProxy(),
+ mAuthMethodSelected(METHOD_NOAUTH),
+ mSocksUsername(),
+ mSocksPassword(),
+ mPool(gAPRPoolp)
{
+}
+
+LLProxy::~LLProxy()
+{
+ tcp_close_channel(mProxyControlChannel);
sUDPProxyEnabled = false;
sHTTPProxyEnabled = false;
- mProxyControlChannel.reset();
- mProxyType = LLPROXY_SOCKS;
}
// Perform a SOCKS 5 authentication and UDP association to the proxy
// specified by proxy, and associate UDP port message_port
-int LLSocks::proxyHandshake(LLHost proxy, U32 message_port)
+int LLProxy::proxyHandshake(LLHost proxy, U32 message_port)
{
int result;
@@ -71,7 +82,7 @@ int LLSocks::proxyHandshake(LLHost proxy, U32 message_port)
socks_auth_request.num_methods = 1; // Sending 1 method.
socks_auth_request.methods = mAuthMethodSelected; // Send only the selected method.
- result = tcp_handshake(mProxyControlChannel, (char*)&socks_auth_request, sizeof(socks_auth_request_t), (char*)&socks_auth_response, sizeof(socks_auth_response_t));
+ result = tcp_handshake(mProxyControlChannel, (char*)&socks_auth_request, sizeof(socks_auth_request), (char*)&socks_auth_response, sizeof(socks_auth_response));
if (result != 0)
{
llwarns << "SOCKS authentication request failed, error on TCP control channel : " << result << llendl;
@@ -95,7 +106,7 @@ int LLSocks::proxyHandshake(LLHost proxy, U32 message_port)
password_auth[0] = 0x01;
password_auth[1] = mSocksUsername.size();
memcpy(&password_auth[2], mSocksUsername.c_str(), mSocksUsername.size());
- password_auth[mSocksUsername.size()+2] = mSocksPassword.size();
+ password_auth[mSocksUsername.size() + 2] = mSocksPassword.size();
memcpy(&password_auth[mSocksUsername.size()+3], mSocksPassword.c_str(), mSocksPassword.size());
authmethod_password_reply_t password_reply;
@@ -129,7 +140,7 @@ int LLSocks::proxyHandshake(LLHost proxy, U32 message_port)
connect_request.atype = ADDRESS_IPV4;
connect_request.address = htonl(0); // 0.0.0.0
connect_request.port = htons(0); // 0
- // "If the client is not in possesion of the information at the time of the UDP ASSOCIATE,
+ // "If the client is not in possession of the information at the time of the UDP ASSOCIATE,
// the client MUST use a port number and address of all zeros. RFC 1928"
result = tcp_handshake(mProxyControlChannel, (char*)&connect_request, sizeof(socks_command_request_t), (char*)&connect_reply, sizeof(socks_command_response_t));
@@ -155,38 +166,37 @@ int LLSocks::proxyHandshake(LLHost proxy, U32 message_port)
return SOCKS_OK;
}
-int LLSocks::startProxy(LLHost proxy, U32 message_port)
+int LLProxy::startProxy(std::string host, U32 port)
{
- int status;
+ mTCPProxy.setHostByName(host);
+ mTCPProxy.setPort(port);
- mTCPProxy = proxy;
+ int status;
if (mProxyControlChannel)
{
tcp_close_channel(mProxyControlChannel);
}
- mProxyControlChannel = tcp_open_channel(mTCPProxy);
+ mProxyControlChannel = tcp_open_channel(mPool, mTCPProxy);
if (!mProxyControlChannel)
{
return SOCKS_HOST_CONNECT_FAILED;
}
- status = proxyHandshake(proxy, message_port);
+ status = proxyHandshake(mTCPProxy, (U32)gMessageSystem->mPort);
if (status == SOCKS_OK)
{
sUDPProxyEnabled = true;
}
+ else
+ {
+ stopProxy();
+ }
return status;
-}
-int LLSocks::startProxy(std::string host, U32 port)
-{
- mTCPProxy.setHostByName(host);
- mTCPProxy.setPort(port);
- return startProxy(mTCPProxy, (U32)gMessageSystem->mPort);
}
-void LLSocks::stopProxy()
+void LLProxy::stopProxy()
{
sUDPProxyEnabled = false;
@@ -205,19 +215,19 @@ void LLSocks::stopProxy()
}
}
-void LLSocks::setAuthNone()
+void LLProxy::setAuthNone()
{
mAuthMethodSelected = METHOD_NOAUTH;
}
-void LLSocks::setAuthPassword(std::string username, std::string password)
+void LLProxy::setAuthPassword(const std::string &username, const std::string &password)
{
mAuthMethodSelected = METHOD_PASSWORD;
mSocksUsername = username;
mSocksPassword = password;
}
-void LLSocks::enableHTTPProxy(LLHost httpHost, LLHttpProxyType type)
+void LLProxy::enableHTTPProxy(LLHost httpHost, LLHttpProxyType type)
{
sHTTPProxyEnabled = true;
mHTTPProxy = httpHost;
@@ -266,7 +276,7 @@ static int tcp_handshake(LLSocket::ptr_t handle, char * dataout, apr_size_t outl
return 0;
}
-static LLSocket::ptr_t tcp_open_channel(LLHost host)
+static LLSocket::ptr_t tcp_open_channel(apr_pool_t* pool, LLHost host)
{
LLSocket::ptr_t socket = LLSocket::create(gAPRPoolp, LLSocket::STREAM_TCP);
bool connected = socket->blockingConnect(host);
@@ -282,4 +292,3 @@ static void tcp_close_channel(LLSocket::ptr_t handle)
{
handle.reset();
}
-
diff --git a/indra/llmessage/llsocks5.h b/indra/llmessage/llproxy.h
index 3c10f661de..979514a7e0 100644
--- a/indra/llmessage/llsocks5.h
+++ b/indra/llmessage/llproxy.h
@@ -24,8 +24,8 @@
* $/LicenseInfo$
*/
-#ifndef LL_SOCKS5_H
-#define LL_SOCKS5_H
+#ifndef LL_PROXY_H
+#define LL_PROXY_H
#include "llhost.h"
#include "lliosocket.h"
@@ -154,20 +154,20 @@ enum LLSocks5AuthType
METHOD_PASSWORD = 0x02 // Client supports username/password
};
-class LLSocks: public LLSingleton<LLSocks>
+class LLProxy: public LLSingleton<LLProxy>
{
public:
- LLSocks();
+ LLProxy();
+ ~LLProxy();
// Start a connection to the SOCKS 5 proxy
int startProxy(std::string host, U32 port);
- int startProxy(LLHost proxy, U32 messagePort);
// Disconnect and clean up any connection to the SOCKS 5 proxy
void stopProxy();
// Set up to use Password auth when connecting to the SOCKS proxy
- void setAuthPassword(std::string username, std::string password);
+ void setAuthPassword(const std::string &username, const std::string &password);
// Set up to use No Auth when connecting to the SOCKS proxy
void setAuthNone();
@@ -201,7 +201,10 @@ public:
LLHttpProxyType getHTTPProxyType() const { return mProxyType; }
// Get the username password in a curl compatible format
- std::string getProxyUserPwd() const { return (mSocksUsername + ":" + mSocksPassword); }
+ std::string getProxyUserPwdCURL() const { return (mSocksUsername + ":" + mSocksPassword); }
+
+ std::string getSocksPwd() const { return mSocksPassword; }
+ std::string getSocksUser() const { return mSocksUsername; }
private:
diff --git a/indra/llmessage/net.cpp b/indra/llmessage/net.cpp
index e2d185b959..f8ab55143c 100644
--- a/indra/llmessage/net.cpp
+++ b/indra/llmessage/net.cpp
@@ -50,7 +50,7 @@
#include "lltimer.h"
#include "indra_constants.h"
-#include "llsocks5.h"
+#include "llproxy.h"
// Globals
#if LL_WINDOWS