Skip to content
Snippets Groups Projects
Commit cfce3686 authored by Logan Dethrow's avatar Logan Dethrow
Browse files

STORM-1112 Fixed network buffers that need to have space for the SOCKS proxy header.

parent b750a5af
No related branches found
No related tags found
No related merge requests found
...@@ -533,7 +533,7 @@ void LLCurl::Easy::prepRequest(const std::string& url, ...@@ -533,7 +533,7 @@ void LLCurl::Easy::prepRequest(const std::string& url,
if (post) setoptString(CURLOPT_ENCODING, ""); if (post) setoptString(CURLOPT_ENCODING, "");
//setopt(CURLOPT_VERBOSE, 1); // usefull for debugging //setopt(CURLOPT_VERBOSE, 1); // useful for debugging
setopt(CURLOPT_NOSIGNAL, 1); setopt(CURLOPT_NOSIGNAL, 1);
// Set the CURL options for either Socks or HTTP proxy // Set the CURL options for either Socks or HTTP proxy
......
...@@ -227,13 +227,13 @@ S32 LLPacketRing::receivePacket (S32 socket, char *datap) ...@@ -227,13 +227,13 @@ S32 LLPacketRing::receivePacket (S32 socket, char *datap)
// no delay, pull straight from net // no delay, pull straight from net
if (LLProxy::isEnabled()) if (LLProxy::isEnabled())
{ {
U8 buffer[NET_BUFFER_SIZE]; U8 buffer[NET_BUFFER_SIZE + SOCKS_HEADER_SIZE];
packet_size = receive_packet(socket, reinterpret_cast<char *>(buffer)); packet_size = receive_packet(socket, reinterpret_cast<char *>(buffer));
if (packet_size > 10) if (packet_size > SOCKS_HEADER_SIZE)
{ {
// *FIX We are assuming ATYP is 0x01 (IPv4), not 0x03 (hostname) or 0x04 (IPv6) // *FIX We are assuming ATYP is 0x01 (IPv4), not 0x03 (hostname) or 0x04 (IPv6)
memcpy(datap, buffer + 10, packet_size - 10); memcpy(datap, buffer + SOCKS_HEADER_SIZE, packet_size - SOCKS_HEADER_SIZE);
proxywrap_t * header = reinterpret_cast<proxywrap_t *>(buffer); proxywrap_t * header = reinterpret_cast<proxywrap_t *>(buffer);
mLastSender.setAddress(header->addr); mLastSender.setAddress(header->addr);
mLastSender.setPort(ntohs(header->port)); mLastSender.setPort(ntohs(header->port));
...@@ -274,7 +274,7 @@ BOOL LLPacketRing::sendPacket(int h_socket, char * send_buffer, S32 buf_size, LL ...@@ -274,7 +274,7 @@ BOOL LLPacketRing::sendPacket(int h_socket, char * send_buffer, S32 buf_size, LL
BOOL status = TRUE; BOOL status = TRUE;
if (!mUseOutThrottle) if (!mUseOutThrottle)
{ {
return doSendPacket(h_socket, send_buffer, buf_size, host ); return sendPacketImpl(h_socket, send_buffer, buf_size, host );
} }
else else
{ {
...@@ -295,7 +295,7 @@ BOOL LLPacketRing::sendPacket(int h_socket, char * send_buffer, S32 buf_size, LL ...@@ -295,7 +295,7 @@ BOOL LLPacketRing::sendPacket(int h_socket, char * send_buffer, S32 buf_size, LL
mOutBufferLength -= packetp->getSize(); mOutBufferLength -= packetp->getSize();
packet_size = packetp->getSize(); packet_size = packetp->getSize();
status = doSendPacket(h_socket, packetp->getData(), packet_size, packetp->getHost()); status = sendPacketImpl(h_socket, packetp->getData(), packet_size, packetp->getHost());
delete packetp; delete packetp;
// Update the throttle // Update the throttle
...@@ -304,7 +304,7 @@ BOOL LLPacketRing::sendPacket(int h_socket, char * send_buffer, S32 buf_size, LL ...@@ -304,7 +304,7 @@ BOOL LLPacketRing::sendPacket(int h_socket, char * send_buffer, S32 buf_size, LL
else else
{ {
// If the queue's empty, we can just send this packet right away. // If the queue's empty, we can just send this packet right away.
status = doSendPacket(h_socket, send_buffer, buf_size, host ); status = sendPacketImpl(h_socket, send_buffer, buf_size, host );
packet_size = buf_size; packet_size = buf_size;
// Update the throttle // Update the throttle
...@@ -343,7 +343,7 @@ BOOL LLPacketRing::sendPacket(int h_socket, char * send_buffer, S32 buf_size, LL ...@@ -343,7 +343,7 @@ BOOL LLPacketRing::sendPacket(int h_socket, char * send_buffer, S32 buf_size, LL
return status; return status;
} }
BOOL LLPacketRing::doSendPacket(int h_socket, const char * send_buffer, S32 buf_size, LLHost host) BOOL LLPacketRing::sendPacketImpl(int h_socket, const char * send_buffer, S32 buf_size, LLHost host)
{ {
if (!LLProxy::isEnabled()) if (!LLProxy::isEnabled())
...@@ -351,14 +351,14 @@ BOOL LLPacketRing::doSendPacket(int h_socket, const char * send_buffer, S32 buf_ ...@@ -351,14 +351,14 @@ BOOL LLPacketRing::doSendPacket(int h_socket, const char * send_buffer, S32 buf_
return send_packet(h_socket, send_buffer, buf_size, host.getAddress(), host.getPort()); return send_packet(h_socket, send_buffer, buf_size, host.getAddress(), host.getPort());
} }
proxywrap_t *socks_header = (proxywrap_t *)&mProxyWrappedSendBuffer; proxywrap_t *socks_header = reinterpret_cast<proxywrap_t *>(&mProxyWrappedSendBuffer);
socks_header->rsv = 0; socks_header->rsv = 0;
socks_header->addr = host.getAddress(); socks_header->addr = host.getAddress();
socks_header->port = htons(host.getPort()); socks_header->port = htons(host.getPort());
socks_header->atype = ADDRESS_IPV4; socks_header->atype = ADDRESS_IPV4;
socks_header->frag = 0; socks_header->frag = 0;
memcpy(mProxyWrappedSendBuffer + 10, send_buffer, buf_size); memcpy(mProxyWrappedSendBuffer + SOCKS_HEADER_SIZE, send_buffer, buf_size);
return send_packet(h_socket, (const char*) mProxyWrappedSendBuffer, buf_size + 10, LLProxy::getInstance()->getUDPProxy().getAddress(), LLProxy::getInstance()->getUDPProxy().getPort()); return send_packet(h_socket, (const char*) mProxyWrappedSendBuffer, buf_size + 10, LLProxy::getInstance()->getUDPProxy().getAddress(), LLProxy::getInstance()->getUDPProxy().getPort());
} }
...@@ -30,11 +30,11 @@ ...@@ -30,11 +30,11 @@
#include <queue> #include <queue>
#include "llpacketbuffer.h"
#include "llhost.h" #include "llhost.h"
#include "net.h" #include "llpacketbuffer.h"
#include "llproxy.h"
#include "llthrottle.h" #include "llthrottle.h"
#include "net.h"
class LLPacketRing class LLPacketRing
{ {
...@@ -83,8 +83,11 @@ class LLPacketRing ...@@ -83,8 +83,11 @@ class LLPacketRing
LLHost mLastSender; LLHost mLastSender;
LLHost mLastReceivingIF; LLHost mLastReceivingIF;
BOOL doSendPacket(int h_socket, const char * send_buffer, S32 buf_size, LLHost host);
U8 mProxyWrappedSendBuffer[NET_BUFFER_SIZE]; U8 mProxyWrappedSendBuffer[NET_BUFFER_SIZE + SOCKS_HEADER_SIZE];
private:
BOOL sendPacketImpl(int h_socket, const char * send_buffer, S32 buf_size, LLHost host);
}; };
......
...@@ -49,6 +49,8 @@ ...@@ -49,6 +49,8 @@
#define SOCKS_VERSION 0x05 // we are using SOCKS 5 #define SOCKS_VERSION 0x05 // we are using SOCKS 5
#define SOCKS_HEADER_SIZE 10
// SOCKS 5 address/hostname types // SOCKS 5 address/hostname types
#define ADDRESS_IPV4 0x01 #define ADDRESS_IPV4 0x01
#define ADDRESS_HOSTNAME 0x03 #define ADDRESS_HOSTNAME 0x03
...@@ -139,7 +141,7 @@ struct proxywrap_t { ...@@ -139,7 +141,7 @@ struct proxywrap_t {
#pragma pack(pop) /* restore original alignment from stack */ #pragma pack(pop) /* restore original alignment from stack */
// Currently selected http proxy type // Currently selected HTTP proxy type
enum LLHttpProxyType enum LLHttpProxyType
{ {
LLPROXY_SOCKS = 0, LLPROXY_SOCKS = 0,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment