• Home
  • Raw
  • Download

Lines Matching refs:statp

146 static int send_vc(res_state statp, res_params* params, const uint8_t* buf, int buflen,
149 static int send_dg(res_state statp, res_params* params, const uint8_t* buf, int buflen,
295 static int res_ourserver_p(res_state statp, const sockaddr* sa) { in res_ourserver_p() argument
303 for (const IPSockAddr& ipsa : statp->nsaddrs) { in res_ourserver_p()
315 for (const IPSockAddr& ipsa : statp->nsaddrs) { in res_ourserver_p()
420 int res_nsend(res_state statp, const uint8_t* buf, int buflen, uint8_t* ans, int anssiz, int* rcode, in res_nsend() argument
435 resolv_cache_lookup(statp->netid, buf, buflen, ans, anssiz, &anslen, flags); in res_nsend()
440 DnsQueryEvent* dnsQueryEvent = addDnsQueryEvent(statp->event); in res_nsend()
448 resolv_populate_res_for_net(statp); in res_nsend()
450 if (statp->nameserverCount() == 0) { in res_nsend()
454 _resolv_cache_query_failed(statp->netid, buf, buflen, flags); in res_nsend()
467 if (!(statp->netcontext_flags & NET_CONTEXT_FLAG_USE_LOCAL_NAMESERVERS)) { in res_nsend()
469 int resplen = res_tls_send(statp, Slice(const_cast<uint8_t*>(buf), buflen), in res_nsend()
475 resolv_cache_add(statp->netid, buf, buflen, ans, resplen); in res_nsend()
480 _resolv_cache_query_failed(statp->netid, buf, buflen, flags); in res_nsend()
487 int revision_id = resolv_cache_get_resolver_stats(statp->netid, &params, stats, statp->nsaddrs); in res_nsend()
495 &params, stats, statp->nameserverCount(), usable_servers); in res_nsend()
497 if (statp->sort_nameservers) { in res_nsend()
500 for (int i = 0; i < statp->nameserverCount(); i++) { in res_nsend()
511 res_set_usable_server(selectedServer, statp->nameserverCount(), usable_servers); in res_nsend()
522 for (size_t ns = 0; ns < statp->nsaddrs.size(); ++ns) { in res_nsend()
528 const IPSockAddr& serverSockAddr = statp->nsaddrs[ns]; in res_nsend()
546 resplen = send_vc(statp, &params, buf, buflen, ans, anssiz, &terrno, ns, in res_nsend()
550 statp->tc_mode == aidl::android::net::IDnsResolver::TC_MODE_UDP_TCP) { in res_nsend()
558 resplen = send_dg(statp, &params, buf, buflen, ans, anssiz, &terrno, &actualNs, in res_nsend()
565 const IPSockAddr& receivedServerAddr = statp->nsaddrs[actualNs]; in res_nsend()
566 DnsQueryEvent* dnsQueryEvent = addDnsQueryEvent(statp->event); in res_nsend()
597 statp->netid, revision_id, serverSockAddr, sample, params.max_samples); in res_nsend()
598 resolv_stats_add(statp->netid, receivedServerAddr, dnsQueryEvent); in res_nsend()
608 _resolv_cache_query_failed(statp->netid, buf, buflen, flags); in res_nsend()
609 statp->closeSockets(); in res_nsend()
617 resolv_cache_add(statp->netid, buf, buflen, ans, resplen); in res_nsend()
619 statp->closeSockets(); in res_nsend()
623 statp->closeSockets(); in res_nsend()
630 _resolv_cache_query_failed(statp->netid, buf, buflen, flags); in res_nsend()
634 static struct timespec get_timeout(res_state statp, const res_params* params, const int ns) { in get_timeout() argument
641 msec /= statp->nameserverCount(); in get_timeout()
655 static int send_vc(res_state statp, res_params* params, const uint8_t* buf, int buflen, in send_vc() argument
670 if (ns >= statp->nsaddrs.size()) { in send_vc()
676 sockaddr_storage ss = statp->nsaddrs[ns]; in send_vc()
687 if (statp->tcp_nssock >= 0 && (statp->_flags & RES_F_VC) != 0) { in send_vc()
692 if (getpeername(statp->tcp_nssock, (struct sockaddr*)(void*)&peer, &size) < 0 || in send_vc()
694 getsockopt(statp->tcp_nssock, SOL_SOCKET, SO_MARK, &old_mark, &mark_size) < 0 || in send_vc()
695 old_mark != statp->_mark) { in send_vc()
696 statp->closeSockets(); in send_vc()
700 if (statp->tcp_nssock < 0 || (statp->_flags & RES_F_VC) == 0) { in send_vc()
701 if (statp->tcp_nssock >= 0) statp->closeSockets(); in send_vc()
703 statp->tcp_nssock.reset(socket(nsap->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)); in send_vc()
704 if (statp->tcp_nssock < 0) { in send_vc()
716 const uid_t uid = statp->enforce_dns_uid ? AID_DNS : statp->uid; in send_vc()
717 resolv_tag_socket(statp->tcp_nssock, uid, statp->pid); in send_vc()
718 if (statp->_mark != MARK_UNSET) { in send_vc()
719 if (setsockopt(statp->tcp_nssock, SOL_SOCKET, SO_MARK, &statp->_mark, in send_vc()
720 sizeof(statp->_mark)) < 0) { in send_vc()
727 if (random_bind(statp->tcp_nssock, nsap->sa_family) < 0) { in send_vc()
730 statp->closeSockets(); in send_vc()
733 if (connect_with_timeout(statp->tcp_nssock, nsap, (socklen_t)nsaplen, in send_vc()
734 get_timeout(statp, params, ns)) < 0) { in send_vc()
737 statp->closeSockets(); in send_vc()
749 statp->_flags |= RES_F_VC; in send_vc()
760 if (writev(statp->tcp_nssock, iov, 2) != (INT16SZ + buflen)) { in send_vc()
763 statp->closeSockets(); in send_vc()
772 while ((n = read(statp->tcp_nssock, (char*)cp, (size_t)len)) > 0) { in send_vc()
779 statp->closeSockets(); in send_vc()
808 statp->closeSockets(); in send_vc()
812 while (len != 0 && (n = read(statp->tcp_nssock, (char*)cp, (size_t)len)) > 0) { in send_vc()
819 statp->closeSockets(); in send_vc()
832 n = read(statp->tcp_nssock, junk, (len > sizeof junk) ? sizeof junk : len); in send_vc()
932 static std::vector<pollfd> extractUdpFdset(res_state statp, const short events = POLLIN) { in extractUdpFdset() argument
933 std::vector<pollfd> fdset(statp->nsaddrs.size()); in extractUdpFdset()
934 for (size_t i = 0; i < statp->nsaddrs.size(); ++i) { in extractUdpFdset()
935 fdset[i] = {.fd = statp->nssocks[i], .events = events}; in extractUdpFdset()
940 static Result<std::vector<int>> udpRetryingPoll(res_state statp, const timespec* finish) { in udpRetryingPoll() argument
946 std::vector<pollfd> fdset = extractUdpFdset(statp); in udpRetryingPoll()
966 static Result<std::vector<int>> udpRetryingPollWrapper(res_state statp, int ns, in udpRetryingPollWrapper() argument
970 if (keepListeningUdp) return udpRetryingPoll(statp, finish); in udpRetryingPollWrapper()
972 if (int n = retrying_poll(statp->nssocks[ns], POLLIN, finish); n <= 0) { in udpRetryingPollWrapper()
975 return std::vector<int>{statp->nssocks[ns]}; in udpRetryingPollWrapper()
978 bool ignoreInvalidAnswer(res_state statp, const sockaddr_storage& from, const uint8_t* buf, in ignoreInvalidAnswer() argument
987 if (*receivedFromNs = res_ourserver_p(statp, (sockaddr*)(void*)&from); *receivedFromNs < 0) { in ignoreInvalidAnswer()
1000 static int send_dg(res_state statp, res_params* params, const uint8_t* buf, int buflen, in send_dg() argument
1004 if (*ns >= statp->nsaddrs.size()) { in send_dg()
1012 const sockaddr_storage ss = statp->nsaddrs[*ns]; in send_dg()
1016 if (statp->nssocks[*ns] == -1) { in send_dg()
1017 statp->nssocks[*ns].reset(socket(nsap->sa_family, SOCK_DGRAM | SOCK_CLOEXEC, 0)); in send_dg()
1018 if (statp->nssocks[*ns] < 0) { in send_dg()
1031 const uid_t uid = statp->enforce_dns_uid ? AID_DNS : statp->uid; in send_dg()
1032 resolv_tag_socket(statp->nssocks[*ns], uid, statp->pid); in send_dg()
1033 if (statp->_mark != MARK_UNSET) { in send_dg()
1034 if (setsockopt(statp->nssocks[*ns], SOL_SOCKET, SO_MARK, &(statp->_mark), in send_dg()
1035 sizeof(statp->_mark)) < 0) { in send_dg()
1037 statp->closeSockets(); in send_dg()
1045 if (random_bind(statp->nssocks[*ns], nsap->sa_family) < 0) { in send_dg()
1048 statp->closeSockets(); in send_dg()
1051 if (connect(statp->nssocks[*ns], nsap, (socklen_t)nsaplen) < 0) { in send_dg()
1054 statp->closeSockets(); in send_dg()
1059 if (send(statp->nssocks[*ns], (const char*)buf, (size_t)buflen, 0) != buflen) { in send_dg()
1062 statp->closeSockets(); in send_dg()
1066 timespec timeout = get_timeout(statp, params, *ns); in send_dg()
1071 auto result = udpRetryingPollWrapper(statp, *ns, &finish); in send_dg()
1080 if (!isTimeout) statp->closeSockets(); in send_dg()
1106 ignoreInvalidAnswer(statp, from, buf, buflen, ans, anssiz, &receivedFromNs); in send_dg()
1113 if (anhp->rcode == FORMERR && (statp->netcontext_flags & NET_CONTEXT_FLAG_USE_EDNS)) { in send_dg()
1120 statp->_flags |= RES_F_EDNS0ERR; in send_dg()
1207 static int res_tls_send(res_state statp, const Slice query, const Slice answer, int* rcode, in res_tls_send() argument
1210 const unsigned netId = statp->netid; in res_tls_send()
1214 statp->event->set_private_dns_modes(convertEnumType(privateDnsStatus.mode)); in res_tls_send()
1256 statp, query, answer, &resplen); in res_tls_send()