////////////////////////////////////////////////////////////////////////// Name : OSDNSLookup Description: called after the DNS lookup of origin server name Details : normally called after Start. may be called more than once, however, if the dns lookup fails. this may be because it was not possible to resolve the name after several attempts. the next action depends. since this function
| 1897 | // |
| 1898 | /////////////////////////////////////////////////////////////////////////////// |
| 1899 | void |
| 1900 | HttpTransact::OSDNSLookup(State *s) |
| 1901 | { |
| 1902 | ink_assert(s->dns_info.looking_up == ResolveInfo::UpstreamResolveStyle::ORIGIN_SERVER); |
| 1903 | |
| 1904 | TxnDbg(dbg_ctl_http_trans, "Entering HttpTransact::OSDNSLookup"); |
| 1905 | |
| 1906 | if (!s->dns_info.resolved_p) { |
| 1907 | if (ResolveInfo::OS_Addr::TRY_HOSTDB == s->dns_info.os_addr_style) { |
| 1908 | /* Transparent case: We tried to connect to client target address, failed and tried to use a different addr |
| 1909 | * but that failed to resolve therefore keep on with the CTA. |
| 1910 | */ |
| 1911 | s->dns_info.addr.assign(s->state_machine->get_ua_txn()->get_netvc()->get_local_addr()); // fetch CTA |
| 1912 | s->dns_info.resolved_p = true; |
| 1913 | s->dns_info.os_addr_style = ResolveInfo::OS_Addr::USE_CLIENT; |
| 1914 | TxnDbg(dbg_ctl_http_seq, "DNS lookup unsuccessful, using client target address"); |
| 1915 | } else { |
| 1916 | TxnDbg(dbg_ctl_http_seq, "DNS Lookup unsuccessful"); |
| 1917 | char const *log_msg; |
| 1918 | |
| 1919 | // Even with unsuccessful DNS lookup, return stale object from cache if applicable |
| 1920 | if (is_cache_hit(s->cache_lookup_result) && is_stale_cache_response_returnable(s)) { |
| 1921 | s->source = SOURCE_CACHE; |
| 1922 | TxnDbg(dbg_ctl_http_trans, "[hscno] serving stale doc to client"); |
| 1923 | build_response_from_cache(s, HTTP_WARNING_CODE_REVALIDATION_FAILED); |
| 1924 | return; |
| 1925 | } |
| 1926 | // output the DNS failure error message |
| 1927 | SET_VIA_STRING(VIA_DETAIL_TUNNEL, VIA_DETAIL_TUNNEL_NO_FORWARD); |
| 1928 | if (!s->dns_info.record || s->dns_info.record->is_failed()) { |
| 1929 | // Set to internal server error so later logging will pick up SQUID_LOG_ERR_DNS_FAIL |
| 1930 | build_error_response(s, HTTP_STATUS_INTERNAL_SERVER_ERROR, "Cannot find server.", Dns_error_body); |
| 1931 | log_msg = "looking up"; |
| 1932 | } else { |
| 1933 | build_error_response(s, HTTP_STATUS_INTERNAL_SERVER_ERROR, "No valid server.", "connect#all_down"); |
| 1934 | log_msg = "no valid server"; |
| 1935 | } |
| 1936 | char *url_str = s->hdr_info.client_request.url_string_get(&s->arena, nullptr); |
| 1937 | swoc::bwprint(error_bw_buffer, "DNS Error: {} {}", log_msg, swoc::bwf::FirstOf(url_str, "<none>")); |
| 1938 | Log::error("%s", error_bw_buffer.c_str()); |
| 1939 | // s->cache_info.action = CACHE_DO_NO_ACTION; |
| 1940 | TRANSACT_RETURN(SM_ACTION_SEND_ERROR_CACHE_NOOP, nullptr); |
| 1941 | } |
| 1942 | return; |
| 1943 | } |
| 1944 | |
| 1945 | // The dns lookup succeeded |
| 1946 | ink_assert(s->dns_info.resolved_p); |
| 1947 | TxnDbg(dbg_ctl_http_seq, "DNS Lookup successful"); |
| 1948 | |
| 1949 | // It's never valid to connect *to* INADDR_ANY, so let's reject the request now. |
| 1950 | if (ats_is_ip_any(s->dns_info.addr)) { |
| 1951 | TxnDbg(dbg_ctl_http_trans, "[OSDNSLookup] Invalid request IP: INADDR_ANY"); |
| 1952 | build_error_response(s, HTTP_STATUS_BAD_REQUEST, "Bad Destination Address", "request#syntax_error"); |
| 1953 | SET_VIA_STRING(VIA_DETAIL_TUNNEL, VIA_DETAIL_TUNNEL_NO_FORWARD); |
| 1954 | TRANSACT_RETURN(SM_ACTION_SEND_ERROR_CACHE_NOOP, nullptr); |
| 1955 | } |
| 1956 |
nothing calls this directly
no test coverage detected