Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 13 additions & 23 deletions proxy/http/HttpSM.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ namespace
// Unique state machine identifier
std::atomic<int64_t> next_sm_id(0);

/// Buffer for some error logs.
thread_local std::string error_bw_buffer;

/**
Outbound PROXY Protocol

Expand Down Expand Up @@ -4168,27 +4171,18 @@ HttpSM::check_sni_host()
Warning("No SNI for TLS request with hostname %.*s action=%s", host_len, host_name, action_value);
SMDebug("ssl_sni", "No SNI for TLS request with hostname %.*s action=%s", host_len, host_name, action_value);
if (host_sni_policy == 2) {
Log::error("%s", lbw()
.clip(1)
.print("No SNI for TLS request: connecting to {} for host='{}', returning a 403",
t_state.client_info.dst_addr, std::string_view{host_name, static_cast<size_t>(host_len)})
.extend(1)
.write('\0')
.data());
ts::bwprint(error_bw_buffer, "No SNI for TLS request: connecting to {} for host='{}', returning a 403",
t_state.client_info.dst_addr, std::string_view{host_name, static_cast<size_t>(host_len)});
Log::error("%s", error_bw_buffer.c_str());
this->t_state.client_connection_enabled = false;
}
} else if (strncasecmp(host_name, sni_value, host_len) != 0) { // Name mismatch
Warning("SNI/hostname mismatch sni=%s host=%.*s action=%s", sni_value, host_len, host_name, action_value);
SMDebug("ssl_sni", "SNI/hostname mismatch sni=%s host=%.*s action=%s", sni_value, host_len, host_name, action_value);
if (host_sni_policy == 2) {
Log::error("%s", lbw()
.clip(1)
.print("SNI/hostname mismatch: connecting to {} for host='{}' sni='{}', returning a 403",
t_state.client_info.dst_addr, std::string_view{host_name, static_cast<size_t>(host_len)},
sni_value)
.extend(1)
.write('\0')
.data());
ts::bwprint(error_bw_buffer, "SNI/hostname mismatch: connecting to {} for host='{}' sni='{}', returning a 403",
t_state.client_info.dst_addr, std::string_view{host_name, static_cast<size_t>(host_len)}, sni_value);
Log::error("%s", error_bw_buffer.c_str());
this->t_state.client_connection_enabled = false;
}
} else {
Expand Down Expand Up @@ -5556,14 +5550,10 @@ HttpSM::mark_host_failure(HostDBInfo *info, time_t time_down)
int host_len;
const char *host_name_ptr = t_state.unmapped_url.host_get(&host_len);
std::string_view host_name{host_name_ptr, size_t(host_len)};
Log::error("%s", lbw()
.clip(1)
.print("CONNECT: {::s} connecting to {} for host='{}' url='{}' marking down",
ts::bwf::Errno(t_state.current.server->connect_result), t_state.current.server->dst_addr,
host_name, ts::bwf::FirstOf(url_str, "<none>"))
.extend(1)
.write('\0')
.data());
ts::bwprint(error_bw_buffer, "CONNECT: {::s} connecting to {} for host='{}' url='{}' marking down",
ts::bwf::Errno(t_state.current.server->connect_result), t_state.current.server->dst_addr, host_name,
ts::bwf::FirstOf(url_str, "<none>"));
Log::error("%s", error_bw_buffer.c_str());

if (url_str) {
t_state.arena.str_free(url_str);
Expand Down
43 changes: 18 additions & 25 deletions proxy/http/HttpTransact.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
namespace
{
char const Dns_error_body[] = "connect#dns_failed";
}

/// Buffer for some error logs.
thread_local std::string error_bw_buffer;
} // namespace

// Support ip_resolve override.
const MgmtConverter HttpTransact::HOST_RES_CONV{[](const void *data) -> std::string_view {
Expand Down Expand Up @@ -95,9 +98,6 @@ static char range_type[] = "multipart/byteranges; boundary=RANGE_SEPARATOR";

extern HttpBodyFactory *body_factory;

// Handy typedef for short (single line) message generation.
using lbw = ts::LocalBufferWriter<256>;

// wrapper to choose between a remap next hop strategy or use parent.config
// remap next hop strategy is preferred
inline static bool
Expand Down Expand Up @@ -908,13 +908,9 @@ HttpTransact::OriginDead(State *s)
int host_len;
const char *host_name_ptr = s->unmapped_url.host_get(&host_len);
std::string_view host_name{host_name_ptr, size_t(host_len)};
Log::error("%s", lbw()
.clip(1)
.print("CONNECT: dead server no request to {} for host='{}' url='{}'", s->current.server->dst_addr, host_name,
ts::bwf::FirstOf(url_str, "<none>"))
.extend(1)
.write('\0')
.data());
ts::bwprint(error_bw_buffer, "CONNECT: dead server no request to {} for host='{}' url='{}'", s->current.server->dst_addr,
host_name, ts::bwf::FirstOf(url_str, "<none>"));
Log::error("%s", error_bw_buffer.c_str());
s->arena.str_free(url_str);

TRANSACT_RETURN(SM_ACTION_SEND_ERROR_CACHE_NOOP, nullptr);
Expand Down Expand Up @@ -1891,8 +1887,8 @@ HttpTransact::ReDNSRoundRobin(State *s)
s->next_action = SM_ACTION_SEND_ERROR_CACHE_NOOP;
// s->next_action = PROXY_INTERNAL_CACHE_NOOP;
char *url_str = s->hdr_info.client_request.url_string_get(&s->arena, nullptr);
Log::error("%s",
lbw().clip(1).print("DNS Error: looking up {}", ts::bwf::FirstOf(url_str, "<none>")).extend(1).write('\0').data());
ts::bwprint(error_bw_buffer, "DNS Error: looking up {}", ts::bwf::FirstOf(url_str, "<none>"));
Log::error("%s", error_bw_buffer.c_str());
}

return;
Expand Down Expand Up @@ -1963,8 +1959,8 @@ HttpTransact::OSDNSLookup(State *s)
// Set to internal server error so later logging will pick up SQUID_LOG_ERR_DNS_FAIL
build_error_response(s, HTTP_STATUS_INTERNAL_SERVER_ERROR, "Cannot find server.", "connect#dns_failed");
char *url_str = s->hdr_info.client_request.url_string_get(&s->arena, nullptr);
Log::error("%s",
lbw().clip(1).print("DNS Error: looking up {}", ts::bwf::FirstOf(url_str, "<none>")).extend(1).write('\0').data());
ts::bwprint(error_bw_buffer, "DNS Error: looking up {}", ts::bwf::FirstOf(url_str, "<none>"));
Log::error("%s", error_bw_buffer.c_str());
// s->cache_info.action = CACHE_DO_NO_ACTION;
TRANSACT_RETURN(SM_ACTION_SEND_ERROR_CACHE_NOOP, nullptr);
}
Expand Down Expand Up @@ -3906,16 +3902,13 @@ HttpTransact::error_log_connection_failure(State *s, ServerState_t conn_state)
host_name_ptr = s->unmapped_url.host_get(&host_len);
}
std::string_view host_name{host_name_ptr, size_t(host_len)};
Log::error("%s", lbw()
.clip(1)
.print("CONNECT: attempt fail [{}] to {} for host='{}' "
"connection_result={::s} error={::s} attempts={} url='{}'",
HttpDebugNames::get_server_state_name(conn_state), s->current.server->dst_addr, host_name,
ts::bwf::Errno(s->current.server->connect_result), ts::bwf::Errno(s->cause_of_death_errno),
s->current.attempts, ts::bwf::FirstOf(url_str, "<none>"))
.extend(1)
.write('\0')
.data());
ts::bwprint(error_bw_buffer,
"CONNECT: attempt fail [{}] to {} for host='{}' "
"connection_result={::s} error={::s} attempts={} url='{}'",
HttpDebugNames::get_server_state_name(conn_state), s->current.server->dst_addr, host_name,
ts::bwf::Errno(s->current.server->connect_result), ts::bwf::Errno(s->cause_of_death_errno), s->current.attempts,
ts::bwf::FirstOf(url_str, "<none>"));
Log::error("%s", error_bw_buffer.c_str());

s->arena.str_free(url_str);
}
Expand Down