Loading tests/dns_responder/dns_tls_frontend.cpp +10 −14 Original line number Original line Diff line number Diff line Loading @@ -64,10 +64,6 @@ namespace test { bool DnsTlsFrontend::startServer() { bool DnsTlsFrontend::startServer() { OpenSSL_add_ssl_algorithms(); OpenSSL_add_ssl_algorithms(); // reset queries_ to 0 every time startServer called // which would help us easy to check queries_ via calling waitForQueries queries_ = 0; ctx_.reset(SSL_CTX_new(TLS_server_method())); ctx_.reset(SSL_CTX_new(TLS_server_method())); if (!ctx_) { if (!ctx_) { LOG(ERROR) << "SSL context creation failed"; LOG(ERROR) << "SSL context creation failed"; Loading Loading @@ -218,10 +214,7 @@ void DnsTlsFrontend::requestHandler() { LOG(INFO) << "SSL negotiation failure"; LOG(INFO) << "SSL negotiation failure"; } else { } else { LOG(DEBUG) << "SSL handshake complete"; LOG(DEBUG) << "SSL handshake complete"; // Increment queries_ as late as possible, because it represents handleRequests(ssl.get(), client.get()); // a query that is fully processed, and the response returned to the // client, including cleanup actions. queries_ += handleRequests(ssl.get(), client.get()); } } if (passiveClose_) { if (passiveClose_) { Loading @@ -233,7 +226,7 @@ void DnsTlsFrontend::requestHandler() { LOG(DEBUG) << "Ending loop"; LOG(DEBUG) << "Ending loop"; } } int DnsTlsFrontend::handleRequests(SSL* ssl, int clientFd) { void DnsTlsFrontend::handleRequests(SSL* ssl, int clientFd) { int queryCounts = 0; int queryCounts = 0; std::vector<uint8_t> reply; std::vector<uint8_t> reply; bool isDotProbe = false; bool isDotProbe = false; Loading @@ -243,7 +236,7 @@ again: uint8_t queryHeader[2]; uint8_t queryHeader[2]; if (SSL_read(ssl, &queryHeader, 2) != 2) { if (SSL_read(ssl, &queryHeader, 2) != 2) { LOG(INFO) << "Not enough header bytes"; LOG(INFO) << "Not enough header bytes"; return queryCounts; return; } } const uint16_t qlen = (queryHeader[0] << 8) | queryHeader[1]; const uint16_t qlen = (queryHeader[0] << 8) | queryHeader[1]; uint8_t query[qlen]; uint8_t query[qlen]; Loading @@ -252,14 +245,14 @@ again: int ret = SSL_read(ssl, query + qbytes, qlen - qbytes); int ret = SSL_read(ssl, query + qbytes, qlen - qbytes); if (ret <= 0) { if (ret <= 0) { LOG(INFO) << "Error while reading query"; LOG(INFO) << "Error while reading query"; return queryCounts; return; } } qbytes += ret; qbytes += ret; } } int sent = send(backend_socket_.get(), query, qlen, 0); int sent = send(backend_socket_.get(), query, qlen, 0); if (sent != qlen) { if (sent != qlen) { LOG(INFO) << "Failed to send query"; LOG(INFO) << "Failed to send query"; return queryCounts; return; } } if (!isDotProbe) { if (!isDotProbe) { Loading @@ -279,7 +272,7 @@ again: int rlen = recv(backend_socket_.get(), recv_buffer, max_size, 0); int rlen = recv(backend_socket_.get(), recv_buffer, max_size, 0); if (rlen <= 0) { if (rlen <= 0) { LOG(INFO) << "Failed to receive response"; LOG(INFO) << "Failed to receive response"; return queryCounts; return; } } uint8_t responseHeader[2]; uint8_t responseHeader[2]; responseHeader[0] = rlen >> 8; responseHeader[0] = rlen >> 8; Loading @@ -287,6 +280,9 @@ again: reply.insert(reply.end(), responseHeader, responseHeader + 2); reply.insert(reply.end(), responseHeader, responseHeader + 2); reply.insert(reply.end(), recv_buffer, recv_buffer + rlen); reply.insert(reply.end(), recv_buffer, recv_buffer + rlen); // Increment queries_ before the answers are sent. This makes sure that a test always // reads the updated value returned from queries() after receiving the DNS answers. ++queries_; ++queryCounts; ++queryCounts; if (queryCounts >= delayQueries_) { if (queryCounts >= delayQueries_) { break; break; Loading Loading @@ -315,7 +311,7 @@ again: } } LOG(DEBUG) << __func__ << " return: " << queryCounts; LOG(DEBUG) << __func__ << " return: " << queryCounts; return queryCounts; return; } } bool DnsTlsFrontend::stopServer() { bool DnsTlsFrontend::stopServer() { Loading tests/dns_responder/dns_tls_frontend.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -76,7 +76,7 @@ class DnsTlsFrontend { private: private: void requestHandler(); void requestHandler(); int handleRequests(SSL* ssl, int clientFd); void handleRequests(SSL* ssl, int clientFd); // Trigger the handler thread to terminate. // Trigger the handler thread to terminate. bool sendToEventFd(); bool sendToEventFd(); Loading Loading
tests/dns_responder/dns_tls_frontend.cpp +10 −14 Original line number Original line Diff line number Diff line Loading @@ -64,10 +64,6 @@ namespace test { bool DnsTlsFrontend::startServer() { bool DnsTlsFrontend::startServer() { OpenSSL_add_ssl_algorithms(); OpenSSL_add_ssl_algorithms(); // reset queries_ to 0 every time startServer called // which would help us easy to check queries_ via calling waitForQueries queries_ = 0; ctx_.reset(SSL_CTX_new(TLS_server_method())); ctx_.reset(SSL_CTX_new(TLS_server_method())); if (!ctx_) { if (!ctx_) { LOG(ERROR) << "SSL context creation failed"; LOG(ERROR) << "SSL context creation failed"; Loading Loading @@ -218,10 +214,7 @@ void DnsTlsFrontend::requestHandler() { LOG(INFO) << "SSL negotiation failure"; LOG(INFO) << "SSL negotiation failure"; } else { } else { LOG(DEBUG) << "SSL handshake complete"; LOG(DEBUG) << "SSL handshake complete"; // Increment queries_ as late as possible, because it represents handleRequests(ssl.get(), client.get()); // a query that is fully processed, and the response returned to the // client, including cleanup actions. queries_ += handleRequests(ssl.get(), client.get()); } } if (passiveClose_) { if (passiveClose_) { Loading @@ -233,7 +226,7 @@ void DnsTlsFrontend::requestHandler() { LOG(DEBUG) << "Ending loop"; LOG(DEBUG) << "Ending loop"; } } int DnsTlsFrontend::handleRequests(SSL* ssl, int clientFd) { void DnsTlsFrontend::handleRequests(SSL* ssl, int clientFd) { int queryCounts = 0; int queryCounts = 0; std::vector<uint8_t> reply; std::vector<uint8_t> reply; bool isDotProbe = false; bool isDotProbe = false; Loading @@ -243,7 +236,7 @@ again: uint8_t queryHeader[2]; uint8_t queryHeader[2]; if (SSL_read(ssl, &queryHeader, 2) != 2) { if (SSL_read(ssl, &queryHeader, 2) != 2) { LOG(INFO) << "Not enough header bytes"; LOG(INFO) << "Not enough header bytes"; return queryCounts; return; } } const uint16_t qlen = (queryHeader[0] << 8) | queryHeader[1]; const uint16_t qlen = (queryHeader[0] << 8) | queryHeader[1]; uint8_t query[qlen]; uint8_t query[qlen]; Loading @@ -252,14 +245,14 @@ again: int ret = SSL_read(ssl, query + qbytes, qlen - qbytes); int ret = SSL_read(ssl, query + qbytes, qlen - qbytes); if (ret <= 0) { if (ret <= 0) { LOG(INFO) << "Error while reading query"; LOG(INFO) << "Error while reading query"; return queryCounts; return; } } qbytes += ret; qbytes += ret; } } int sent = send(backend_socket_.get(), query, qlen, 0); int sent = send(backend_socket_.get(), query, qlen, 0); if (sent != qlen) { if (sent != qlen) { LOG(INFO) << "Failed to send query"; LOG(INFO) << "Failed to send query"; return queryCounts; return; } } if (!isDotProbe) { if (!isDotProbe) { Loading @@ -279,7 +272,7 @@ again: int rlen = recv(backend_socket_.get(), recv_buffer, max_size, 0); int rlen = recv(backend_socket_.get(), recv_buffer, max_size, 0); if (rlen <= 0) { if (rlen <= 0) { LOG(INFO) << "Failed to receive response"; LOG(INFO) << "Failed to receive response"; return queryCounts; return; } } uint8_t responseHeader[2]; uint8_t responseHeader[2]; responseHeader[0] = rlen >> 8; responseHeader[0] = rlen >> 8; Loading @@ -287,6 +280,9 @@ again: reply.insert(reply.end(), responseHeader, responseHeader + 2); reply.insert(reply.end(), responseHeader, responseHeader + 2); reply.insert(reply.end(), recv_buffer, recv_buffer + rlen); reply.insert(reply.end(), recv_buffer, recv_buffer + rlen); // Increment queries_ before the answers are sent. This makes sure that a test always // reads the updated value returned from queries() after receiving the DNS answers. ++queries_; ++queryCounts; ++queryCounts; if (queryCounts >= delayQueries_) { if (queryCounts >= delayQueries_) { break; break; Loading Loading @@ -315,7 +311,7 @@ again: } } LOG(DEBUG) << __func__ << " return: " << queryCounts; LOG(DEBUG) << __func__ << " return: " << queryCounts; return queryCounts; return; } } bool DnsTlsFrontend::stopServer() { bool DnsTlsFrontend::stopServer() { Loading
tests/dns_responder/dns_tls_frontend.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -76,7 +76,7 @@ class DnsTlsFrontend { private: private: void requestHandler(); void requestHandler(); int handleRequests(SSL* ssl, int clientFd); void handleRequests(SSL* ssl, int clientFd); // Trigger the handler thread to terminate. // Trigger the handler thread to terminate. bool sendToEventFd(); bool sendToEventFd(); Loading