Lines Matching refs:statp

223 res_ourserver_p(const res_state statp, const struct sockaddr *sa) {  in res_ourserver_p()  argument
231 for (ns = 0; ns < statp->nscount; ns++) { in res_ourserver_p()
232 srv = (struct sockaddr_in *)(void *)get_nsaddr(statp, (size_t)ns); in res_ourserver_p()
241 if (EXT(statp).ext == NULL) in res_ourserver_p()
244 for (ns = 0; ns < statp->nscount; ns++) { in res_ourserver_p()
245 srv6 = (struct sockaddr_in6 *)(void *)get_nsaddr(statp, (size_t)ns); in res_ourserver_p()
351 res_nsend(res_state statp, in res_nsend() argument
362 DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_QUERY), in res_nsend()
364 v_circuit = (statp->options & RES_USEVC) || buflen > PACKETSZ; in res_nsend()
370 statp->netid, buf, buflen, in res_nsend()
378 _resolv_populate_res_for_net(statp); in res_nsend()
380 if (statp->nscount == 0) { in res_nsend()
384 _resolv_cache_query_failed(statp->netid, buf, buflen); in res_nsend()
393 if (EXT(statp).nscount != 0) { in res_nsend()
398 if (EXT(statp).nscount != statp->nscount) { in res_nsend()
401 for (ns = 0; ns < statp->nscount; ns++) { in res_nsend()
402 if (statp->nsaddr_list[ns].sin_family && in res_nsend()
403 !sock_eq((struct sockaddr *)(void *)&statp->nsaddr_list[ns], in res_nsend()
404 (struct sockaddr *)(void *)&EXT(statp).ext->nsaddrs[ns])) { in res_nsend()
409 if (EXT(statp).nssocks[ns] == -1) in res_nsend()
412 if (getpeername(EXT(statp).nssocks[ns], in res_nsend()
418 get_nsaddr(statp, (size_t)ns))) { in res_nsend()
425 res_nclose(statp); in res_nsend()
426 EXT(statp).nscount = 0; in res_nsend()
433 if (EXT(statp).nscount == 0) { in res_nsend()
434 for (ns = 0; ns < statp->nscount; ns++) { in res_nsend()
435 EXT(statp).nstimes[ns] = RES_MAXTIME; in res_nsend()
436 EXT(statp).nssocks[ns] = -1; in res_nsend()
437 if (!statp->nsaddr_list[ns].sin_family) in res_nsend()
439 EXT(statp).ext->nsaddrs[ns].sin = in res_nsend()
440 statp->nsaddr_list[ns]; in res_nsend()
442 EXT(statp).nscount = statp->nscount; in res_nsend()
449 if ((statp->options & RES_ROTATE) != 0U && in res_nsend()
450 (statp->options & RES_BLAST) == 0U) { in res_nsend()
453 int lastns = statp->nscount - 1; in res_nsend()
457 if (EXT(statp).ext != NULL) in res_nsend()
458 inu = EXT(statp).ext->nsaddrs[0]; in res_nsend()
459 ina = statp->nsaddr_list[0]; in res_nsend()
460 fd = EXT(statp).nssocks[0]; in res_nsend()
461 nstime = EXT(statp).nstimes[0]; in res_nsend()
463 if (EXT(statp).ext != NULL) in res_nsend()
464 EXT(statp).ext->nsaddrs[ns] = in res_nsend()
465 EXT(statp).ext->nsaddrs[ns + 1]; in res_nsend()
466 statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1]; in res_nsend()
467 EXT(statp).nssocks[ns] = EXT(statp).nssocks[ns + 1]; in res_nsend()
468 EXT(statp).nstimes[ns] = EXT(statp).nstimes[ns + 1]; in res_nsend()
470 if (EXT(statp).ext != NULL) in res_nsend()
471 EXT(statp).ext->nsaddrs[lastns] = inu; in res_nsend()
472 statp->nsaddr_list[lastns] = ina; in res_nsend()
473 EXT(statp).nssocks[lastns] = fd; in res_nsend()
474 EXT(statp).nstimes[lastns] = nstime; in res_nsend()
480 for (try = 0; try < statp->retry; try++) { in res_nsend()
483 int revision_id = _resolv_cache_get_resolver_stats(statp->netid, &params, stats); in res_nsend()
485 android_net_res_stats_get_usable_servers(&params, stats, statp->nscount, in res_nsend()
488 for (ns = 0; ns < statp->nscount; ns++) { in res_nsend()
495 nsap = get_nsaddr(statp, (size_t)ns); in res_nsend()
497 statp->_flags &= ~RES_F_LASTMASK; in res_nsend()
498 statp->_flags |= (ns << RES_F_LASTSHIFT); in res_nsend()
501 if (statp->qhook) { in res_nsend()
507 act = (*statp->qhook)(&nsap, &buf, &buflen, in res_nsend()
514 res_nclose(statp); in res_nsend()
518 _resolv_cache_add(statp->netid, buf, buflen, in res_nsend()
535 Dprint(((statp->options & RES_DEBUG) && in res_nsend()
544 try = statp->retry; in res_nsend()
546 n = send_vc(statp, &params, buf, buflen, ans, anssiz, &terrno, in res_nsend()
557 _resolv_cache_add_resolver_stats_sample(statp->netid, revision_id, in res_nsend()
577 n = send_dg(statp, &params, buf, buflen, ans, anssiz, &terrno, in res_nsend()
584 _resolv_cache_add_resolver_stats_sample(statp->netid, revision_id, in res_nsend()
605 Dprint((statp->options & RES_DEBUG) || in res_nsend()
606 ((statp->pfcode & RES_PRF_REPLY) && in res_nsend()
607 (statp->pfcode & RES_PRF_HEAD1)), in res_nsend()
610 DprintQ((statp->options & RES_DEBUG) || in res_nsend()
611 (statp->pfcode & RES_PRF_REPLY), in res_nsend()
616 _resolv_cache_add(statp->netid, buf, buflen, in res_nsend()
624 if ((v_circuit && (statp->options & RES_USEVC) == 0U) || in res_nsend()
625 (statp->options & RES_STAYOPEN) == 0U) { in res_nsend()
626 res_nclose(statp); in res_nsend()
628 if (statp->rhook) { in res_nsend()
634 act = (*statp->rhook)(nsap, buf, buflen, in res_nsend()
642 res_nclose(statp); in res_nsend()
661 res_nclose(statp); in res_nsend()
670 _resolv_cache_query_failed(statp->netid, buf, buflen); in res_nsend()
675 _resolv_cache_query_failed(statp->netid, buf, buflen); in res_nsend()
676 res_nclose(statp); in res_nsend()
705 get_nsaddr(statp, n) in get_nsaddr() argument
706 res_state statp; in get_nsaddr()
710 if (!statp->nsaddr_list[n].sin_family && EXT(statp).ext) {
716 return (struct sockaddr *)(void *)&EXT(statp).ext->nsaddrs[n];
723 return (struct sockaddr *)(void *)&statp->nsaddr_list[n];
727 static struct timespec get_timeout(const res_state statp, const struct __res_params* params, const … in get_timeout() argument
737 msec = (statp->retrans * 1000) << ns; in get_timeout()
739 msec /= statp->nscount; in get_timeout()
756 send_vc(res_state statp, struct __res_params* params, in send_vc() argument
777 nsap = get_nsaddr(statp, (size_t)ns); in send_vc()
787 if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) { in send_vc()
792 if (getpeername(statp->_vcsock, in send_vc()
795 getsockopt(statp->_vcsock, SOL_SOCKET, SO_MARK, &old_mark, &mark_size) < 0 || in send_vc()
796 old_mark != statp->_mark) { in send_vc()
797 res_nclose(statp); in send_vc()
798 statp->_flags &= ~RES_F_VC; in send_vc()
802 if (statp->_vcsock < 0 || (statp->_flags & RES_F_VC) == 0) { in send_vc()
803 if (statp->_vcsock >= 0) in send_vc()
804 res_nclose(statp); in send_vc()
806 statp->_vcsock = socket(nsap->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0); in send_vc()
807 if (statp->_vcsock < 0) { in send_vc()
814 Perror(statp, stderr, "socket(vc)", errno); in send_vc()
818 Perror(statp, stderr, "socket(vc)", errno); in send_vc()
822 fchown(statp->_vcsock, AID_DNS, -1); in send_vc()
823 if (statp->_mark != MARK_UNSET) { in send_vc()
824 if (setsockopt(statp->_vcsock, SOL_SOCKET, in send_vc()
825 SO_MARK, &statp->_mark, sizeof(statp->_mark)) < 0) { in send_vc()
827 Perror(statp, stderr, "setsockopt", errno); in send_vc()
832 if (random_bind(statp->_vcsock,nsap->sa_family) < 0) { in send_vc()
834 Aerror(statp, stderr, "bind/vc", errno, nsap, in send_vc()
836 res_nclose(statp); in send_vc()
839 if (connect_with_timeout(statp->_vcsock, nsap, (socklen_t)nsaplen, in send_vc()
840 get_timeout(statp, params, ns)) < 0) { in send_vc()
842 Aerror(statp, stderr, "connect/vc", errno, nsap, in send_vc()
844 res_nclose(statp); in send_vc()
856 statp->_flags |= RES_F_VC; in send_vc()
866 if (writev(statp->_vcsock, iov, 2) != (INT16SZ + buflen)) { in send_vc()
868 Perror(statp, stderr, "write failed", errno); in send_vc()
869 res_nclose(statp); in send_vc()
878 while ((n = read(statp->_vcsock, (char *)cp, (size_t)len)) > 0) { in send_vc()
885 Perror(statp, stderr, "read failed", errno); in send_vc()
886 res_nclose(statp); in send_vc()
898 res_nclose(statp); in send_vc()
901 res_nclose(statp); in send_vc()
906 Dprint(statp->options & RES_DEBUG, in send_vc()
917 Dprint(statp->options & RES_DEBUG, in send_vc()
920 res_nclose(statp); in send_vc()
924 while (len != 0 && (n = read(statp->_vcsock, (char *)cp, (size_t)len)) > 0){ in send_vc()
930 Perror(statp, stderr, "read(vc)", errno); in send_vc()
931 res_nclose(statp); in send_vc()
944 n = read(statp->_vcsock, junk, in send_vc()
960 DprintQ((statp->options & RES_DEBUG) || in send_vc()
961 (statp->pfcode & RES_PRF_REPLY), in send_vc()
1070 send_dg(res_state statp, struct __res_params* params, in send_dg() argument
1087 nsap = get_nsaddr(statp, (size_t)ns); in send_dg()
1089 if (EXT(statp).nssocks[ns] == -1) { in send_dg()
1090 EXT(statp).nssocks[ns] = socket(nsap->sa_family, SOCK_DGRAM | SOCK_CLOEXEC, 0); in send_dg()
1091 if (EXT(statp).nssocks[ns] < 0) { in send_dg()
1098 Perror(statp, stderr, "socket(dg)", errno); in send_dg()
1102 Perror(statp, stderr, "socket(dg)", errno); in send_dg()
1107 fchown(EXT(statp).nssocks[ns], AID_DNS, -1); in send_dg()
1108 if (statp->_mark != MARK_UNSET) { in send_dg()
1109 if (setsockopt(EXT(statp).nssocks[ns], SOL_SOCKET, in send_dg()
1110 SO_MARK, &(statp->_mark), sizeof(statp->_mark)) < 0) { in send_dg()
1111 res_nclose(statp); in send_dg()
1127 if (random_bind(EXT(statp).nssocks[ns], nsap->sa_family) < 0) { in send_dg()
1128 Aerror(statp, stderr, "bind(dg)", errno, nsap, in send_dg()
1130 res_nclose(statp); in send_dg()
1133 if (__connect(EXT(statp).nssocks[ns], nsap, (socklen_t)nsaplen) < 0) { in send_dg()
1134 Aerror(statp, stderr, "connect(dg)", errno, nsap, in send_dg()
1136 res_nclose(statp); in send_dg()
1140 Dprint(statp->options & RES_DEBUG, in send_dg()
1144 s = EXT(statp).nssocks[ns]; in send_dg()
1147 Perror(statp, stderr, "send", errno); in send_dg()
1148 res_nclose(statp); in send_dg()
1154 Aerror(statp, stderr, "sendto", errno, nsap, nsaplen); in send_dg()
1155 res_nclose(statp); in send_dg()
1163 timeout = get_timeout(statp, params, ns); in send_dg()
1171 Dprint(statp->options & RES_DEBUG, (stdout, ";; timeout\n")); in send_dg()
1176 Perror(statp, stderr, "poll", errno); in send_dg()
1177 res_nclose(statp); in send_dg()
1185 Perror(statp, stderr, "recvfrom", errno); in send_dg()
1186 res_nclose(statp); in send_dg()
1194 Dprint(statp->options & RES_DEBUG, in send_dg()
1198 res_nclose(statp); in send_dg()
1207 DprintQ((statp->options & RES_DEBUG) || in send_dg()
1208 (statp->pfcode & RES_PRF_REPLY), in send_dg()
1213 if (!(statp->options & RES_INSECURE1) && in send_dg()
1214 !res_ourserver_p(statp, (struct sockaddr *)(void *)&from)) { in send_dg()
1220 DprintQ((statp->options & RES_DEBUG) || in send_dg()
1221 (statp->pfcode & RES_PRF_REPLY), in send_dg()
1227 if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0U) { in send_dg()
1233 DprintQ(statp->options & RES_DEBUG, in send_dg()
1237 statp->_flags |= RES_F_EDNS0ERR; in send_dg()
1238 res_nclose(statp); in send_dg()
1242 if (!(statp->options & RES_INSECURE2) && in send_dg()
1250 DprintQ((statp->options & RES_DEBUG) || in send_dg()
1251 (statp->pfcode & RES_PRF_REPLY), in send_dg()
1261 DprintQ(statp->options & RES_DEBUG, in send_dg()
1264 res_nclose(statp); in send_dg()
1266 if (!statp->pfcode) { in send_dg()
1271 if (!(statp->options & RES_IGNTC) && anhp->tc) { in send_dg()
1276 Dprint(statp->options & RES_DEBUG, in send_dg()
1279 res_nclose(statp); in send_dg()
1293 Aerror(const res_state statp, FILE *file, const char *string, int error, in Aerror() argument
1300 if ((statp->options & RES_DEBUG) != 0U) { in Aerror()
1315 Perror(const res_state statp, FILE *file, const char *string, int error) { in Perror() argument
1318 if ((statp->options & RES_DEBUG) != 0U) in Perror()