• Home
  • Raw
  • Download

Lines Matching refs:statp

267 static int res_ourserver_p(const res_state statp, const sockaddr* sa) {  in res_ourserver_p()  argument
275 for (ns = 0; ns < statp->nscount; ns++) { in res_ourserver_p()
276 srv = (struct sockaddr_in*) (void*) get_nsaddr(statp, (size_t) ns); in res_ourserver_p()
284 if (statp->_u._ext.ext == NULL) break; in res_ourserver_p()
286 for (ns = 0; ns < statp->nscount; ns++) { in res_ourserver_p()
287 srv6 = (struct sockaddr_in6*) (void*) get_nsaddr(statp, (size_t) ns); in res_ourserver_p()
376 int res_nsend(res_state statp, const u_char* buf, int buflen, u_char* ans, int anssiz, int* rcode, in res_nsend() argument
389 v_circuit = (statp->options & RES_USEVC) || buflen > PACKETSZ; in res_nsend()
394 cache_status = _resolv_cache_lookup(statp->netid, buf, buflen, ans, anssiz, &anslen, flags); in res_nsend()
403 _resolv_populate_res_for_net(statp); in res_nsend()
405 if (statp->nscount == 0) { in res_nsend()
409 _resolv_cache_query_failed(statp->netid, buf, buflen, flags); in res_nsend()
420 if (statp->_u._ext.nscount != 0) { in res_nsend()
425 if (statp->_u._ext.nscount != statp->nscount) { in res_nsend()
428 for (int ns = 0; ns < statp->nscount; ns++) { in res_nsend()
429 if (statp->nsaddr_list[ns].sin_family && in res_nsend()
430 !sock_eq((struct sockaddr*) (void*) &statp->nsaddr_list[ns], in res_nsend()
431 (struct sockaddr*) (void*) &statp->_u._ext.ext->nsaddrs[ns])) { in res_nsend()
436 if (statp->_u._ext.nssocks[ns] == -1) continue; in res_nsend()
438 if (getpeername(statp->_u._ext.nssocks[ns], (struct sockaddr*) (void*) &peer, in res_nsend()
443 if (!sock_eq((struct sockaddr*) (void*) &peer, get_nsaddr(statp, (size_t) ns))) { in res_nsend()
450 res_nclose(statp); in res_nsend()
451 statp->_u._ext.nscount = 0; in res_nsend()
458 if (statp->_u._ext.nscount == 0) { in res_nsend()
459 for (int ns = 0; ns < statp->nscount; ns++) { in res_nsend()
460 statp->_u._ext.nstimes[ns] = RES_MAXTIME; in res_nsend()
461 statp->_u._ext.nssocks[ns] = -1; in res_nsend()
462 if (!statp->nsaddr_list[ns].sin_family) continue; in res_nsend()
463 statp->_u._ext.ext->nsaddrs[ns].sin = statp->nsaddr_list[ns]; in res_nsend()
465 statp->_u._ext.nscount = statp->nscount; in res_nsend()
472 if ((statp->options & RES_ROTATE) != 0U && (statp->options & RES_BLAST) == 0U) { in res_nsend()
475 int lastns = statp->nscount - 1; in res_nsend()
479 if (statp->_u._ext.ext != NULL) inu = statp->_u._ext.ext->nsaddrs[0]; in res_nsend()
480 ina = statp->nsaddr_list[0]; in res_nsend()
481 fd = statp->_u._ext.nssocks[0]; in res_nsend()
482 nstime = statp->_u._ext.nstimes[0]; in res_nsend()
484 if (statp->_u._ext.ext != NULL) in res_nsend()
485 statp->_u._ext.ext->nsaddrs[ns] = statp->_u._ext.ext->nsaddrs[ns + 1]; in res_nsend()
486 statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1]; in res_nsend()
487 statp->_u._ext.nssocks[ns] = statp->_u._ext.nssocks[ns + 1]; in res_nsend()
488 statp->_u._ext.nstimes[ns] = statp->_u._ext.nstimes[ns + 1]; in res_nsend()
490 if (statp->_u._ext.ext != NULL) statp->_u._ext.ext->nsaddrs[lastns] = inu; in res_nsend()
491 statp->nsaddr_list[lastns] = ina; in res_nsend()
492 statp->_u._ext.nssocks[lastns] = fd; in res_nsend()
493 statp->_u._ext.nstimes[lastns] = nstime; in res_nsend()
498 int revision_id = resolv_cache_get_resolver_stats(statp->netid, &params, stats); in res_nsend()
506 &params, stats, statp->nscount, usable_servers); in res_nsend()
513 res_set_usable_server(selectedServer, statp->nscount, usable_servers); in res_nsend()
523 for (int ns = 0; ns < statp->nscount; ns++) { in res_nsend()
530 nsap = get_nsaddr(statp, (size_t) ns); in res_nsend()
537 if (!statp->use_local_nameserver) { in res_nsend()
539 resplen = res_tls_send(statp, Slice(const_cast<u_char*>(buf), buflen), in res_nsend()
543 _resolv_cache_add(statp->netid, buf, buflen, ans, resplen); in res_nsend()
548 _resolv_cache_query_failed(statp->netid, buf, buflen, flags); in res_nsend()
549 res_nclose(statp); in res_nsend()
566 n = send_vc(statp, &params, buf, buflen, ans, anssiz, &terrno, ns, &now, rcode, in res_nsend()
577 _resolv_cache_add_resolver_stats_sample(statp->netid, revision_id, ns, &sample, in res_nsend()
584 _resolv_cache_query_failed(statp->netid, buf, buflen, flags); in res_nsend()
585 res_nclose(statp); in res_nsend()
594 n = send_dg(statp, &params, buf, buflen, ans, anssiz, &terrno, ns, &v_circuit, in res_nsend()
601 _resolv_cache_add_resolver_stats_sample(statp->netid, revision_id, ns, &sample, in res_nsend()
608 _resolv_cache_query_failed(statp->netid, buf, buflen, flags); in res_nsend()
609 res_nclose(statp); in res_nsend()
621 _resolv_cache_add(statp->netid, buf, buflen, ans, resplen); in res_nsend()
628 if ((v_circuit && (statp->options & RES_USEVC) == 0U) || in res_nsend()
629 (statp->options & RES_STAYOPEN) == 0U) { in res_nsend()
630 res_nclose(statp); in res_nsend()
636 res_nclose(statp); in res_nsend()
650 _resolv_cache_query_failed(statp->netid, buf, buflen, flags); in res_nsend()
668 static struct sockaddr* get_nsaddr(res_state statp, size_t n) { in get_nsaddr() argument
669 if (!statp->nsaddr_list[n].sin_family && statp->_u._ext.ext) { in get_nsaddr()
675 return (struct sockaddr*) (void*) &statp->_u._ext.ext->nsaddrs[n]; in get_nsaddr()
682 return (struct sockaddr*) (void*) &statp->nsaddr_list[n]; in get_nsaddr()
686 static struct timespec get_timeout(const res_state statp, const res_params* params, const int ns) { in get_timeout() argument
693 msec /= statp->nscount; in get_timeout()
707 static int send_vc(res_state statp, res_params* params, const u_char* buf, int buflen, u_char* ans, in send_vc() argument
721 nsap = get_nsaddr(statp, (size_t) ns); in send_vc()
731 if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) { in send_vc()
736 if (getpeername(statp->_vcsock, (struct sockaddr*) (void*) &peer, &size) < 0 || in send_vc()
738 getsockopt(statp->_vcsock, SOL_SOCKET, SO_MARK, &old_mark, &mark_size) < 0 || in send_vc()
739 old_mark != statp->_mark) { in send_vc()
740 res_nclose(statp); in send_vc()
741 statp->_flags &= ~RES_F_VC; in send_vc()
745 if (statp->_vcsock < 0 || (statp->_flags & RES_F_VC) == 0) { in send_vc()
746 if (statp->_vcsock >= 0) res_nclose(statp); in send_vc()
748 statp->_vcsock = socket(nsap->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0); in send_vc()
749 if (statp->_vcsock < 0) { in send_vc()
754 Perror(statp, "socket(vc)", errno); in send_vc()
758 Perror(statp, "socket(vc)", errno); in send_vc()
762 fchown(statp->_vcsock, AID_DNS, -1); in send_vc()
763 if (statp->_mark != MARK_UNSET) { in send_vc()
764 if (setsockopt(statp->_vcsock, SOL_SOCKET, SO_MARK, &statp->_mark, in send_vc()
765 sizeof(statp->_mark)) < 0) { in send_vc()
767 Perror(statp, "setsockopt", errno); in send_vc()
772 if (random_bind(statp->_vcsock, nsap->sa_family) < 0) { in send_vc()
774 Aerror(statp, "bind/vc", errno, nsap, nsaplen); in send_vc()
775 res_nclose(statp); in send_vc()
778 if (connect_with_timeout(statp->_vcsock, nsap, (socklen_t) nsaplen, in send_vc()
779 get_timeout(statp, params, ns)) < 0) { in send_vc()
781 Aerror(statp, "connect/vc", errno, nsap, nsaplen); in send_vc()
782 res_nclose(statp); in send_vc()
794 statp->_flags |= RES_F_VC; in send_vc()
803 if (writev(statp->_vcsock, iov, 2) != (INT16SZ + buflen)) { in send_vc()
805 Perror(statp, "write failed", errno); in send_vc()
806 res_nclose(statp); in send_vc()
815 while ((n = read(statp->_vcsock, (char*) cp, (size_t) len)) > 0) { in send_vc()
821 Perror(statp, "read failed", errno); in send_vc()
822 res_nclose(statp); in send_vc()
834 res_nclose(statp); in send_vc()
837 res_nclose(statp); in send_vc()
853 res_nclose(statp); in send_vc()
857 while (len != 0 && (n = read(statp->_vcsock, (char*) cp, (size_t) len)) > 0) { in send_vc()
863 Perror(statp, "read(vc)", errno); in send_vc()
864 res_nclose(statp); in send_vc()
877 n = read(statp->_vcsock, junk, (len > sizeof junk) ? sizeof junk : len); in send_vc()
973 static int send_dg(res_state statp, res_params* params, const u_char* buf, int buflen, u_char* ans, in send_dg() argument
987 nsap = get_nsaddr(statp, (size_t) ns); in send_dg()
989 if (statp->_u._ext.nssocks[ns] == -1) { in send_dg()
990 statp->_u._ext.nssocks[ns] = socket(nsap->sa_family, SOCK_DGRAM | SOCK_CLOEXEC, 0); in send_dg()
991 if (statp->_u._ext.nssocks[ns] < 0) { in send_dg()
996 Perror(statp, "socket(dg)", errno); in send_dg()
1000 Perror(statp, "socket(dg)", errno); in send_dg()
1005 fchown(statp->_u._ext.nssocks[ns], AID_DNS, -1); in send_dg()
1006 if (statp->_mark != MARK_UNSET) { in send_dg()
1007 if (setsockopt(statp->_u._ext.nssocks[ns], SOL_SOCKET, SO_MARK, &(statp->_mark), in send_dg()
1008 sizeof(statp->_mark)) < 0) { in send_dg()
1009 res_nclose(statp); in send_dg()
1025 if (random_bind(statp->_u._ext.nssocks[ns], nsap->sa_family) < 0) { in send_dg()
1026 Aerror(statp, "bind(dg)", errno, nsap, nsaplen); in send_dg()
1027 res_nclose(statp); in send_dg()
1030 if (connect(statp->_u._ext.nssocks[ns], nsap, (socklen_t) nsaplen) < 0) { in send_dg()
1031 Aerror(statp, "connect(dg)", errno, nsap, nsaplen); in send_dg()
1032 res_nclose(statp); in send_dg()
1038 s = statp->_u._ext.nssocks[ns]; in send_dg()
1041 Perror(statp, "send", errno); in send_dg()
1042 res_nclose(statp); in send_dg()
1047 Aerror(statp, "sendto", errno, nsap, nsaplen); in send_dg()
1048 res_nclose(statp); in send_dg()
1054 timeout = get_timeout(statp, params, ns); in send_dg()
1067 Perror(statp, "poll", errno); in send_dg()
1068 res_nclose(statp); in send_dg()
1076 Perror(statp, "recvfrom", errno); in send_dg()
1077 res_nclose(statp); in send_dg()
1087 res_nclose(statp); in send_dg()
1100 if (!(statp->options & RES_INSECURE1) && in send_dg()
1101 !res_ourserver_p(statp, (struct sockaddr*) (void*) &from)) { in send_dg()
1111 if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0U) { in send_dg()
1120 statp->_flags |= RES_F_EDNS0ERR; in send_dg()
1121 res_nclose(statp); in send_dg()
1124 if (!(statp->options & RES_INSECURE2) && in send_dg()
1140 res_nclose(statp); in send_dg()
1144 if (!(statp->options & RES_IGNTC) && anhp->tc) { in send_dg()
1151 res_nclose(statp); in send_dg()
1164 static void Aerror(const res_state statp, const char* string, int error, in Aerror() argument
1171 if ((statp->options & RES_DEBUG) != 0U) { in Aerror()
1185 static void Perror(const res_state statp, const char* string, int error) { in Perror() argument
1186 if ((statp->options & RES_DEBUG) != 0U) { in Perror()
1214 static int res_tls_send(res_state statp, const Slice query, const Slice answer, int* rcode, in res_tls_send() argument
1217 const unsigned netId = statp->netid; in res_tls_send()
1218 const unsigned mark = statp->_mark; in res_tls_send()