}
ServerPolicy::NumberedServerVector servers;
for (size_t idx = 1; idx <= 10; idx++) {
- servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53")) });
+ servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53"), ComboAddress(), 0, std::string(), 1, false) });
servers.at(idx - 1).second->setUp();
/* we need to have a weight of at least 1000 to get an optimal repartition with the consistent hashing algo */
servers.at(idx - 1).second->setWeight(1000);
ServerPolicy pol{"firstAvailable", firstAvailable, false};
ServerPolicy::NumberedServerVector servers;
- servers.push_back({ 1, std::make_shared<DownstreamState>(ComboAddress("192.0.2.1:53")) });
+ servers.push_back({ 1, std::make_shared<DownstreamState>(ComboAddress("192.0.2.1:53"), ComboAddress(), 0, std::string(), 1, false) });
/* servers start as 'down' */
auto server = pol.getSelectedBackend(servers, dq);
BOOST_CHECK(server != nullptr);
/* add a second server, we should still get the first one */
- servers.push_back({ 2, std::make_shared<DownstreamState>(ComboAddress("192.0.2.2:53")) });
+ servers.push_back({ 2, std::make_shared<DownstreamState>(ComboAddress("192.0.2.2:53"), ComboAddress(), 0, std::string(), 1, false) });
server = pol.getSelectedBackend(servers, dq);
BOOST_REQUIRE(server != nullptr);
BOOST_CHECK(server == servers.at(0).second);
ServerPolicy pol{"firstAvailable", firstAvailable, false};
ServerPolicy::NumberedServerVector servers;
- servers.push_back({ 1, std::make_shared<DownstreamState>(ComboAddress("192.0.2.1:53")) });
- servers.push_back({ 2, std::make_shared<DownstreamState>(ComboAddress("192.0.2.2:53")) });
+ servers.push_back({ 1, std::make_shared<DownstreamState>(ComboAddress("192.0.2.1:53"), ComboAddress(), 0, std::string(), 1, false) });
+ servers.push_back({ 2, std::make_shared<DownstreamState>(ComboAddress("192.0.2.2:53"), ComboAddress(), 0, std::string(), 1, false) });
/* Second server has a higher order, so most queries should be routed to the first (remember that
we need to keep them ordered!).
However the first server has a QPS limit at 10 qps, so any query above that should be routed
auto server = pol.getSelectedBackend(servers, dq);
BOOST_CHECK(server == nullptr);
- servers.push_back({ 1, std::make_shared<DownstreamState>(ComboAddress("192.0.2.1:53")) });
+ servers.push_back({ 1, std::make_shared<DownstreamState>(ComboAddress("192.0.2.1:53"), ComboAddress(), 0, std::string(), 1, false) });
/* servers start as 'down' but the RR policy returns a server unless g_roundrobinFailOnNoServer is set */
g_roundrobinFailOnNoServer = true;
BOOST_CHECK(server != nullptr);
/* add a second server, we should get the first one then the second one */
- servers.push_back({ 2, std::make_shared<DownstreamState>(ComboAddress("192.0.2.2:53")) });
+ servers.push_back({ 2, std::make_shared<DownstreamState>(ComboAddress("192.0.2.2:53"), ComboAddress(), 0, std::string(), 1, false) });
servers.at(1).second->setUp();
server = pol.getSelectedBackend(servers, dq);
BOOST_REQUIRE(server != nullptr);
ServerPolicy pol{"leastOutstanding", leastOutstanding, false};
ServerPolicy::NumberedServerVector servers;
- servers.push_back({ 1, std::make_shared<DownstreamState>(ComboAddress("192.0.2.1:53")) });
+ servers.push_back({ 1, std::make_shared<DownstreamState>(ComboAddress("192.0.2.1:53"), ComboAddress(), 0, std::string(), 1, false) });
/* servers start as 'down' */
auto server = pol.getSelectedBackend(servers, dq);
BOOST_CHECK(server != nullptr);
/* add a second server, we should still get the first one */
- servers.push_back({ 2, std::make_shared<DownstreamState>(ComboAddress("192.0.2.2:53")) });
+ servers.push_back({ 2, std::make_shared<DownstreamState>(ComboAddress("192.0.2.2:53"), ComboAddress(), 0, std::string(), 1, false) });
server = pol.getSelectedBackend(servers, dq);
BOOST_REQUIRE(server != nullptr);
BOOST_CHECK(server == servers.at(0).second);
ServerPolicy::NumberedServerVector servers;
std::map<std::shared_ptr<DownstreamState>, uint64_t> serversMap;
for (size_t idx = 1; idx <= 10; idx++) {
- servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53")) });
+ servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53"), ComboAddress(), 0, std::string(), 1, false) });
serversMap[servers.at(idx - 1).second] = 0;
servers.at(idx - 1).second->setUp();
}
ServerPolicy::NumberedServerVector servers;
std::map<std::shared_ptr<DownstreamState>, uint64_t> serversMap;
for (size_t idx = 1; idx <= 10; idx++) {
- servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53")) });
+ servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53"), ComboAddress(), 0, std::string(), 1, false) });
serversMap[servers.at(idx - 1).second] = 0;
servers.at(idx - 1).second->setUp();
}
ServerPolicy::NumberedServerVector servers;
std::map<std::shared_ptr<DownstreamState>, uint64_t> serversMap;
for (size_t idx = 1; idx <= 10; idx++) {
- servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53")) });
+ servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53"), ComboAddress(), 0, std::string(), 1, false) });
serversMap[servers.at(idx - 1).second] = 0;
servers.at(idx - 1).second->setUp();
/* we need to have a weight of at least 1000 to get an optimal repartition with the consistent hashing algo */
ServerPolicy::NumberedServerVector servers;
std::map<std::shared_ptr<DownstreamState>, uint64_t> serversMap;
for (size_t idx = 1; idx <= 10; idx++) {
- servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53")) });
+ servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53"), ComboAddress(), 0, std::string(), 1, false) });
serversMap[servers.at(idx - 1).second] = 0;
servers.at(idx - 1).second->setUp();
}
ServerPolicy::NumberedServerVector servers;
std::map<std::shared_ptr<DownstreamState>, uint64_t> serversMap;
for (size_t idx = 1; idx <= 10; idx++) {
- servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53")) });
+ servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53"), ComboAddress(), 0, std::string(), 1, false) });
serversMap[servers.at(idx - 1).second] = 0;
servers.at(idx - 1).second->setUp();
}
ServerPolicy::NumberedServerVector servers;
std::map<std::shared_ptr<DownstreamState>, uint64_t> serversMap;
for (size_t idx = 1; idx <= 10; idx++) {
- servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53")) });
+ servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53"), ComboAddress(), 0, std::string(), 1, false) });
serversMap[servers.at(idx - 1).second] = 0;
servers.at(idx - 1).second->setUp();
}
ServerPolicy::NumberedServerVector servers;
std::map<std::shared_ptr<DownstreamState>, uint64_t> serversMap;
for (size_t idx = 1; idx <= 10; idx++) {
- servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53")) });
+ servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53"), ComboAddress(), 0, std::string(), 1, false) });
serversMap[servers.at(idx - 1).second] = 0;
servers.at(idx - 1).second->setUp();
}
ServerPolicy::NumberedServerVector servers;
std::map<std::shared_ptr<DownstreamState>, uint64_t> serversMap;
for (size_t idx = 1; idx <= 10; idx++) {
- servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53")) });
+ servers.push_back({ idx, std::make_shared<DownstreamState>(ComboAddress("192.0.2." + std::to_string(idx) + ":53"), ComboAddress(), 0, std::string(), 1, false) });
serversMap[servers.at(idx - 1).second] = 0;
servers.at(idx - 1).second->setUp();
/* we need to have a weight of at least 1000 to get an optimal repartition with the consistent hashing algo */
#include "dnsdist-proxy-protocol.hh"
#include "dnsdist-rings.hh"
#include "dnsdist-nghttp2.hh"
+#include "sstuff.hh"
#ifdef HAVE_NGHTTP2
#include <nghttp2/nghttp2.h>
bool d_error{false};
};
+static bool isIPv6Supported()
+{
+ try {
+ ComboAddress addr("[2001:db8:53::1]:53");
+ auto socket = std::make_unique<Socket>(addr.sin4.sin_family, SOCK_STREAM, 0);
+ socket->setNonBlocking();
+ int res = SConnectWithTimeout(socket->getHandle(), addr, timeval{0, 0});
+ if (res == 0 || res == EINPROGRESS) {
+ return true;
+ }
+ return false;
+ }
+ catch (const std::exception& e) {
+ return false;
+ }
+}
+
+static ComboAddress getBackendAddress(const std::string& lastDigit, uint16_t port)
+{
+ static const bool useV6 = isIPv6Supported();
+
+ if (useV6) {
+ return ComboAddress("2001:db8:53::" + lastDigit, port);
+ }
+
+ return ComboAddress("192.0.2." + lastDigit, port);
+}
+
static std::unique_ptr<FDMultiplexer> s_mplexer;
struct TestFixture
BOOST_FIXTURE_TEST_CASE(test_SingleQuery, TestFixture)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
auto tlsCtx = std::make_shared<MockupTLSCtx>();
localCS.tlsFrontend = std::make_shared<TLSFrontend>(tlsCtx);
s_responses[counter] = {query, response};
- auto backend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto backend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
backend->d_tlsCtx = tlsCtx;
backend->d_tlsSubjectName = "backend.powerdns.com";
backend->d_dohPath = "/dns-query";
BOOST_FIXTURE_TEST_CASE(test_ConcurrentQueries, TestFixture)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
auto tlsCtx = std::make_shared<MockupTLSCtx>();
localCS.tlsFrontend = std::make_shared<TLSFrontend>(tlsCtx);
struct timeval now;
gettimeofday(&now, nullptr);
- auto backend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto backend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
backend->d_tlsCtx = tlsCtx;
backend->d_tlsSubjectName = "backend.powerdns.com";
backend->d_dohPath = "/dns-query";
BOOST_FIXTURE_TEST_CASE(test_ConnectionReuse, TestFixture)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
auto tlsCtx = std::make_shared<MockupTLSCtx>();
localCS.tlsFrontend = std::make_shared<TLSFrontend>(tlsCtx);
struct timeval now;
gettimeofday(&now, nullptr);
- auto backend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto backend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
backend->d_tlsCtx = tlsCtx;
backend->d_tlsSubjectName = "backend.powerdns.com";
backend->d_dohPath = "/dns-query";
BOOST_FIXTURE_TEST_CASE(test_InvalidDNSAnswer, TestFixture)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
auto tlsCtx = std::make_shared<MockupTLSCtx>();
localCS.tlsFrontend = std::make_shared<TLSFrontend>(tlsCtx);
response.resize(11);
s_responses[counter] = {query, response};
- auto backend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto backend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
backend->d_tlsCtx = tlsCtx;
backend->d_tlsSubjectName = "backend.powerdns.com";
backend->d_dohPath = "/dns-query";
BOOST_FIXTURE_TEST_CASE(test_TimeoutWhileWriting, TestFixture)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
auto tlsCtx = std::make_shared<MockupTLSCtx>();
localCS.tlsFrontend = std::make_shared<TLSFrontend>(tlsCtx);
struct timeval now;
gettimeofday(&now, nullptr);
- auto backend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto backend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
backend->d_tlsCtx = tlsCtx;
backend->d_tlsSubjectName = "backend.powerdns.com";
backend->d_dohPath = "/dns-query";
BOOST_FIXTURE_TEST_CASE(test_TimeoutWhileReading, TestFixture)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
auto tlsCtx = std::make_shared<MockupTLSCtx>();
localCS.tlsFrontend = std::make_shared<TLSFrontend>(tlsCtx);
struct timeval now;
gettimeofday(&now, nullptr);
- auto backend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto backend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
backend->d_tlsCtx = tlsCtx;
backend->d_tlsSubjectName = "backend.powerdns.com";
backend->d_dohPath = "/dns-query";
BOOST_FIXTURE_TEST_CASE(test_ShortWrite, TestFixture)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
auto tlsCtx = std::make_shared<MockupTLSCtx>();
localCS.tlsFrontend = std::make_shared<TLSFrontend>(tlsCtx);
struct timeval now;
gettimeofday(&now, nullptr);
- auto backend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto backend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
backend->d_tlsCtx = tlsCtx;
backend->d_tlsSubjectName = "backend.powerdns.com";
backend->d_dohPath = "/dns-query";
BOOST_FIXTURE_TEST_CASE(test_ShortRead, TestFixture)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
auto tlsCtx = std::make_shared<MockupTLSCtx>();
localCS.tlsFrontend = std::make_shared<TLSFrontend>(tlsCtx);
struct timeval now;
gettimeofday(&now, nullptr);
- auto backend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto backend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
backend->d_tlsCtx = tlsCtx;
backend->d_tlsSubjectName = "backend.powerdns.com";
backend->d_dohPath = "/dns-query";
BOOST_FIXTURE_TEST_CASE(test_ConnectionClosedWhileReading, TestFixture)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
auto tlsCtx = std::make_shared<MockupTLSCtx>();
localCS.tlsFrontend = std::make_shared<TLSFrontend>(tlsCtx);
struct timeval now;
gettimeofday(&now, nullptr);
- auto backend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto backend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
backend->d_tlsCtx = tlsCtx;
backend->d_tlsSubjectName = "backend.powerdns.com";
backend->d_dohPath = "/dns-query";
BOOST_FIXTURE_TEST_CASE(test_ConnectionClosedWhileWriting, TestFixture)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
auto tlsCtx = std::make_shared<MockupTLSCtx>();
localCS.tlsFrontend = std::make_shared<TLSFrontend>(tlsCtx);
struct timeval now;
gettimeofday(&now, nullptr);
- auto backend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto backend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
backend->d_tlsCtx = tlsCtx;
backend->d_tlsSubjectName = "backend.powerdns.com";
backend->d_dohPath = "/dns-query";
BOOST_FIXTURE_TEST_CASE(test_GoAwayFromServer, TestFixture)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
auto tlsCtx = std::make_shared<MockupTLSCtx>();
localCS.tlsFrontend = std::make_shared<TLSFrontend>(tlsCtx);
struct timeval now;
gettimeofday(&now, nullptr);
- auto backend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto backend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
backend->d_tlsCtx = tlsCtx;
backend->d_tlsSubjectName = "backend.powerdns.com";
backend->d_dohPath = "/dns-query";
BOOST_FIXTURE_TEST_CASE(test_HTTP500FromServer, TestFixture)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
auto tlsCtx = std::make_shared<MockupTLSCtx>();
localCS.tlsFrontend = std::make_shared<TLSFrontend>(tlsCtx);
struct timeval now;
gettimeofday(&now, nullptr);
- auto backend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto backend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
backend->d_tlsCtx = tlsCtx;
backend->d_tlsSubjectName = "backend.powerdns.com";
backend->d_dohPath = "/dns-query";
BOOST_FIXTURE_TEST_CASE(test_WrongStreamID, TestFixture)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
auto tlsCtx = std::make_shared<MockupTLSCtx>();
localCS.tlsFrontend = std::make_shared<TLSFrontend>(tlsCtx);
struct timeval now;
gettimeofday(&now, nullptr);
- auto backend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto backend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
backend->d_tlsCtx = tlsCtx;
backend->d_tlsSubjectName = "backend.powerdns.com";
backend->d_dohPath = "/dns-query";
BOOST_FIXTURE_TEST_CASE(test_ProxyProtocol, TestFixture)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
auto tlsCtx = std::make_shared<MockupTLSCtx>();
tlsCtx->d_needProxyProtocol = true;
struct timeval now;
gettimeofday(&now, nullptr);
- auto backend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto backend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
backend->d_tlsCtx = tlsCtx;
backend->d_tlsSubjectName = "backend.powerdns.com";
backend->d_dohPath = "/dns-query";
std::set<int> ready;
};
+static bool isIPv6Supported()
+{
+ try {
+ ComboAddress addr("[2001:db8:53::1]:53");
+ auto socket = std::make_unique<Socket>(addr.sin4.sin_family, SOCK_STREAM, 0);
+ socket->setNonBlocking();
+ int res = SConnectWithTimeout(socket->getHandle(), addr, timeval{0, 0});
+ if (res == 0 || res == EINPROGRESS) {
+ return true;
+ }
+ return false;
+ }
+ catch (const std::exception& e) {
+ return false;
+ }
+}
+
+static ComboAddress getBackendAddress(const std::string& lastDigit, uint16_t port)
+{
+ static const bool useV6 = isIPv6Supported();
+
+ if (useV6) {
+ return ComboAddress("2001:db8:53::" + lastDigit, port);
+ }
+
+ return ComboAddress("192.0.2." + lastDigit, port);
+}
+
static void testInit(const std::string& name, TCPClientThreadData& threadData)
{
#if 0
BOOST_AUTO_TEST_CASE(test_IncomingConnection_SelfAnswered)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
auto tlsCtx = std::make_shared<MockupTLSCtx>();
localCS.tlsFrontend = std::make_shared<TLSFrontend>(tlsCtx);
return ProcessQueryResult::Drop;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), 0U);
}
return ProcessQueryResult::SendAnswer;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), query.size());
BOOST_CHECK(s_writeBuffer == query);
/* mark the incoming FD as always ready */
dynamic_cast<MockupFDMultiplexer*>(threadData.mplexer.get())->setReady(-1);
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
while (threadData.mplexer->getWatchedFDCount(false) != 0 || threadData.mplexer->getWatchedFDCount(true) != 0) {
threadData.mplexer->run(&now);
throw std::runtime_error("Something unexpected happened");
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), 0U);
}
return ProcessQueryResult::SendAnswer;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), query.size() * count);
#endif
/* mark the incoming FD as NOT ready */
dynamic_cast<MockupFDMultiplexer*>(threadData.mplexer.get())->setNotReady(-1);
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(threadData.mplexer->run(&now), 0);
struct timeval later = now;
/* mark the incoming FD as NOT ready */
dynamic_cast<MockupFDMultiplexer*>(threadData.mplexer.get())->setNotReady(-1);
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(threadData.mplexer->run(&now), 0);
struct timeval later = now;
return ProcessQueryResult::SendAnswer;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), 0U);
}
BOOST_AUTO_TEST_CASE(test_IncomingConnectionWithProxyProtocol_SelfAnswered)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
auto tlsCtx = std::make_shared<MockupTLSCtx>();
localCS.tlsFrontend = std::make_shared<TLSFrontend>(tlsCtx);
TEST_INIT("=> reading PP");
g_proxyProtocolACL.addMask("0.0.0.0/0");
+ g_proxyProtocolACL.addMask("::0/0");
auto proxyPayload = makeProxyHeader(true, ComboAddress("192.0.2.1"), ComboAddress("192.0.2.2"), {});
BOOST_REQUIRE_GT(proxyPayload.size(), s_proxyProtocolMinimumHeaderSize);
/* mark the incoming FD as NOT ready */
dynamic_cast<MockupFDMultiplexer*>(threadData.mplexer.get())->setNotReady(-1);
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(threadData.mplexer->run(&now), 0);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), query.size() * 2U);
TEST_INIT("=> Invalid PP");
g_proxyProtocolACL.addMask("0.0.0.0/0");
+ g_proxyProtocolACL.addMask("::0/0");
auto proxyPayload = std::vector<uint8_t>(s_proxyProtocolMinimumHeaderSize);
std::fill(proxyPayload.begin(), proxyPayload.end(), 0);
return ProcessQueryResult::SendAnswer;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), 0U);
TEST_INIT("=> timeout while reading PP");
g_proxyProtocolACL.addMask("0.0.0.0/0");
+ g_proxyProtocolACL.addMask("::0/0");
auto proxyPayload = makeProxyHeader(true, ComboAddress("192.0.2.1"), ComboAddress("192.0.2.2"), {});
BOOST_REQUIRE_GT(proxyPayload.size(), s_proxyProtocolMinimumHeaderSize);
s_readBuffer = query;
/* mark the incoming FD as NOT ready */
dynamic_cast<MockupFDMultiplexer*>(threadData.mplexer.get())->setNotReady(-1);
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(threadData.mplexer->run(&now), 0);
struct timeval later = now;
BOOST_AUTO_TEST_CASE(test_IncomingConnection_BackendNoOOOR)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
auto tlsCtx = std::make_shared<MockupTLSCtx>();
localCS.tlsFrontend = std::make_shared<TLSFrontend>(tlsCtx);
const uint8_t sizeBytes[] = { static_cast<uint8_t>(querySize / 256), static_cast<uint8_t>(querySize % 256) };
query.insert(query.begin(), sizeBytes, sizeBytes + 2);
- auto backend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto backend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
backend->d_tlsCtx = tlsCtx;
{
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), query.size());
BOOST_CHECK(s_writeBuffer == query);
throw std::runtime_error("Unexpected error while processing the response");
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), 0U);
BOOST_CHECK_EQUAL(s_backendWriteBuffer.size(), query.size());
return false;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), 0U);
BOOST_CHECK_EQUAL(s_backendWriteBuffer.size(), query.size());
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), 0U);
BOOST_CHECK_EQUAL(s_backendWriteBuffer.size(), query.size());
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), 0U);
BOOST_CHECK_EQUAL(s_backendWriteBuffer.size(), 0U);
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), 0U);
BOOST_CHECK_EQUAL(s_backendWriteBuffer.size(), query.size());
/* set the incoming descriptor as ready! */
dynamic_cast<MockupFDMultiplexer*>(threadData.mplexer.get())->setReady(-1);
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
while (threadData.mplexer->getWatchedFDCount(false) != 0 || threadData.mplexer->getWatchedFDCount(true) != 0) {
threadData.mplexer->run(&now);
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), 0U);
BOOST_CHECK_EQUAL(s_backendWriteBuffer.size(), 0U);
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
struct timeval later = now;
later.tv_sec += backend->tcpSendTimeout + 1;
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
struct timeval later = now;
later.tv_sec += backend->tcpRecvTimeout + 1;
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), 0U);
BOOST_CHECK_EQUAL(s_backendWriteBuffer.size(), 0U);
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), query.size());
BOOST_CHECK(s_writeBuffer == query);
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), 0U);
BOOST_CHECK_EQUAL(s_backendWriteBuffer.size(), 0U);
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), 0U);
BOOST_CHECK_EQUAL(s_backendWriteBuffer.size(), query.size() * backend->d_retries);
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), query.size());
BOOST_CHECK(s_writeBuffer == query);
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), 0U);
BOOST_CHECK_EQUAL(s_backendWriteBuffer.size(), query.size());
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
BOOST_CHECK_EQUAL(s_writeBuffer.size(), query.size() * count);
BOOST_CHECK_EQUAL(backend->outstanding.load(), 0U);
BOOST_AUTO_TEST_CASE(test_IncomingConnectionOOOR_BackendOOOR)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
/* enable out-of-order on the front side */
localCS.d_maxInFlightQueriesPerConn = 65536;
auto tlsCtx = std::make_shared<MockupTLSCtx>();
localCS.tlsFrontend = std::make_shared<TLSFrontend>(tlsCtx);
- auto backend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ ConnectionInfo connInfo(&localCS);
+ connInfo.remote = getBackendAddress("84", 4242);
+
+ auto backend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
backend->d_tlsCtx = tlsCtx;
/* enable out-of-order on the backend side as well */
backend->d_maxInFlightQueriesPerConn = 65536;
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
while (threadData.mplexer->getWatchedFDCount(false) != 0 || threadData.mplexer->getWatchedFDCount(true) != 0) {
threadData.mplexer->run(&now);
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
while (!timeout && (threadData.mplexer->getWatchedFDCount(false) != 0 || threadData.mplexer->getWatchedFDCount(true) != 0)) {
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
while (!timeout && (threadData.mplexer->getWatchedFDCount(false) != 0 || threadData.mplexer->getWatchedFDCount(true) != 0)) {
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
while (!timeout && (threadData.mplexer->getWatchedFDCount(false) != 0 || threadData.mplexer->getWatchedFDCount(true) != 0)) {
threadData.mplexer->run(&now);
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
while ((threadData.mplexer->getWatchedFDCount(false) != 0 || threadData.mplexer->getWatchedFDCount(true) != 0)) {
threadData.mplexer->run(&now);
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
while (!timeout && (threadData.mplexer->getWatchedFDCount(false) != 0 || threadData.mplexer->getWatchedFDCount(true) != 0)) {
threadData.mplexer->run(&now);
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
while (threadData.mplexer->getWatchedFDCount(false) != 0 || threadData.mplexer->getWatchedFDCount(true) != 0) {
threadData.mplexer->run(&now);
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
while (!timeout && (threadData.mplexer->getWatchedFDCount(false) != 0 || threadData.mplexer->getWatchedFDCount(true) != 0)) {
threadData.mplexer->run(&now);
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
while (!timeout && (threadData.mplexer->getWatchedFDCount(false) != 0 || threadData.mplexer->getWatchedFDCount(true) != 0)) {
threadData.mplexer->run(&now);
PacketBuffer expectedWriteBuffer;
PacketBuffer expectedBackendWriteBuffer;
- auto proxyPayload = makeProxyHeader(true, ComboAddress("0.0.0.0"), local, {});
+ auto proxyPayload = makeProxyHeader(true, getBackendAddress("84", 4242), local, {});
BOOST_REQUIRE_GT(proxyPayload.size(), s_proxyProtocolMinimumHeaderSize);
s_readBuffer.insert(s_readBuffer.end(), queries.at(0).begin(), queries.at(0).end());
s_readBuffer.insert(s_readBuffer.end(), queries.at(1).begin(), queries.at(1).end());
s_readBuffer.insert(s_readBuffer.end(), queries.at(2).begin(), queries.at(2).end());
- auto proxyEnabledBackend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto proxyEnabledBackend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
proxyEnabledBackend->d_tlsCtx = tlsCtx;
/* enable out-of-order on the backend side as well */
proxyEnabledBackend->d_maxInFlightQueriesPerConn = 65536;
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
while (threadData.mplexer->getWatchedFDCount(false) != 0 || threadData.mplexer->getWatchedFDCount(true) != 0) {
threadData.mplexer->run(&now);
PacketBuffer expectedWriteBuffer;
PacketBuffer expectedBackendWriteBuffer;
- auto proxyPayload = makeProxyHeader(true, ComboAddress("0.0.0.0"), local, {});
+ auto proxyPayload = makeProxyHeader(true, getBackendAddress("84", 4242), local, {});
BOOST_REQUIRE_GT(proxyPayload.size(), s_proxyProtocolMinimumHeaderSize);
s_readBuffer.insert(s_readBuffer.end(), queries.at(0).begin(), queries.at(0).end());
s_readBuffer.insert(s_readBuffer.end(), queries.at(1).begin(), queries.at(1).end());
s_readBuffer.insert(s_readBuffer.end(), queries.at(2).begin(), queries.at(2).end());
- auto proxyEnabledBackend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto proxyEnabledBackend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
proxyEnabledBackend->d_tlsCtx = tlsCtx;
/* enable out-of-order on the backend side as well */
proxyEnabledBackend->d_maxInFlightQueriesPerConn = 65536;
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
while (threadData.mplexer->getWatchedFDCount(false) != 0 || threadData.mplexer->getWatchedFDCount(true) != 0) {
threadData.mplexer->run(&now);
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
while (!timeout && (threadData.mplexer->getWatchedFDCount(false) != 0 || threadData.mplexer->getWatchedFDCount(true) != 0)) {
threadData.mplexer->run(&now);
expectedWriteBuffer = s_backendReadBuffer;
- auto backend1 = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto backend1 = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
backend1->d_tlsCtx = tlsCtx;
/* only two queries in flight! */
backend1->d_maxInFlightQueriesPerConn = 2;
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
while (threadData.mplexer->getWatchedFDCount(false) != 0 || threadData.mplexer->getWatchedFDCount(true) != 0) {
threadData.mplexer->run(&now);
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
while (!timeout && (threadData.mplexer->getWatchedFDCount(false) != 0 || threadData.mplexer->getWatchedFDCount(true) != 0)) {
threadData.mplexer->run(&now);
BOOST_AUTO_TEST_CASE(test_IncomingConnectionOOOR_BackendNotOOOR)
{
- ComboAddress local("192.0.2.1:80");
+ auto local = getBackendAddress("1", 80);
ClientState localCS(local, true, false, false, "", {});
/* enable out-of-order on the front side */
localCS.d_maxInFlightQueriesPerConn = 65536;
auto tlsCtx = std::make_shared<MockupTLSCtx>();
localCS.tlsFrontend = std::make_shared<TLSFrontend>(tlsCtx);
- auto backend = std::make_shared<DownstreamState>(ComboAddress("192.0.2.42:53"), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
+ auto backend = std::make_shared<DownstreamState>(getBackendAddress("42", 53), ComboAddress("0.0.0.0:0"), 0, std::string(), 1, false);
backend->d_tlsCtx = tlsCtx;
/* shorter than the client one */
backend->tcpRecvTimeout = 1;
return true;
};
- auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS), threadData, now);
+ auto state = std::make_shared<IncomingTCPConnectionState>(ConnectionInfo(&localCS, getBackendAddress("84", 4242)), threadData, now);
IncomingTCPConnectionState::handleIO(state, now);
while (threadData.mplexer->getWatchedFDCount(false) != 0 || threadData.mplexer->getWatchedFDCount(true) != 0) {
threadData.mplexer->run(&now);