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()
704 get_nsaddr(res_state statp, size_t n) in get_nsaddr() argument
707 if (!statp->nsaddr_list[n].sin_family && EXT(statp).ext) { in get_nsaddr()
713 return (struct sockaddr *)(void *)&EXT(statp).ext->nsaddrs[n]; in get_nsaddr()
720 return (struct sockaddr *)(void *)&statp->nsaddr_list[n]; in get_nsaddr()
724 static struct timespec get_timeout(const res_state statp, const struct __res_params* params, const … in get_timeout() argument
734 msec = (statp->retrans * 1000) << ns; in get_timeout()
736 msec /= statp->nscount; in get_timeout()
753 send_vc(res_state statp, struct __res_params* params, in send_vc() argument
774 nsap = get_nsaddr(statp, (size_t)ns); in send_vc()
784 if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) { in send_vc()
789 if (getpeername(statp->_vcsock, in send_vc()
792 getsockopt(statp->_vcsock, SOL_SOCKET, SO_MARK, &old_mark, &mark_size) < 0 || in send_vc()
793 old_mark != statp->_mark) { in send_vc()
794 res_nclose(statp); in send_vc()
795 statp->_flags &= ~RES_F_VC; in send_vc()
799 if (statp->_vcsock < 0 || (statp->_flags & RES_F_VC) == 0) { in send_vc()
800 if (statp->_vcsock >= 0) in send_vc()
801 res_nclose(statp); in send_vc()
803 statp->_vcsock = socket(nsap->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0); in send_vc()
804 if (statp->_vcsock < 0) { in send_vc()
811 Perror(statp, stderr, "socket(vc)", errno); in send_vc()
815 Perror(statp, stderr, "socket(vc)", errno); in send_vc()
819 fchown(statp->_vcsock, AID_DNS, -1); in send_vc()
820 if (statp->_mark != MARK_UNSET) { in send_vc()
821 if (setsockopt(statp->_vcsock, SOL_SOCKET, in send_vc()
822 SO_MARK, &statp->_mark, sizeof(statp->_mark)) < 0) { in send_vc()
824 Perror(statp, stderr, "setsockopt", errno); in send_vc()
829 if (random_bind(statp->_vcsock,nsap->sa_family) < 0) { in send_vc()
831 Aerror(statp, stderr, "bind/vc", errno, nsap, in send_vc()
833 res_nclose(statp); in send_vc()
836 if (connect_with_timeout(statp->_vcsock, nsap, (socklen_t)nsaplen, in send_vc()
837 get_timeout(statp, params, ns)) < 0) { in send_vc()
839 Aerror(statp, stderr, "connect/vc", errno, nsap, in send_vc()
841 res_nclose(statp); in send_vc()
853 statp->_flags |= RES_F_VC; in send_vc()
863 if (writev(statp->_vcsock, iov, 2) != (INT16SZ + buflen)) { in send_vc()
865 Perror(statp, stderr, "write failed", errno); in send_vc()
866 res_nclose(statp); in send_vc()
875 while ((n = read(statp->_vcsock, (char *)cp, (size_t)len)) > 0) { in send_vc()
882 Perror(statp, stderr, "read failed", errno); in send_vc()
883 res_nclose(statp); in send_vc()
895 res_nclose(statp); in send_vc()
898 res_nclose(statp); in send_vc()
903 Dprint(statp->options & RES_DEBUG, in send_vc()
914 Dprint(statp->options & RES_DEBUG, in send_vc()
917 res_nclose(statp); in send_vc()
921 while (len != 0 && (n = read(statp->_vcsock, (char *)cp, (size_t)len)) > 0){ in send_vc()
927 Perror(statp, stderr, "read(vc)", errno); in send_vc()
928 res_nclose(statp); in send_vc()
941 n = read(statp->_vcsock, junk, in send_vc()
959 DprintQ((statp->options & RES_DEBUG) || in send_vc()
960 (statp->pfcode & RES_PRF_REPLY), in send_vc()
1069 send_dg(res_state statp, struct __res_params* params, in send_dg() argument
1086 nsap = get_nsaddr(statp, (size_t)ns); in send_dg()
1088 if (EXT(statp).nssocks[ns] == -1) { in send_dg()
1089 EXT(statp).nssocks[ns] = socket(nsap->sa_family, SOCK_DGRAM | SOCK_CLOEXEC, 0); in send_dg()
1090 if (EXT(statp).nssocks[ns] < 0) { in send_dg()
1097 Perror(statp, stderr, "socket(dg)", errno); in send_dg()
1101 Perror(statp, stderr, "socket(dg)", errno); in send_dg()
1106 fchown(EXT(statp).nssocks[ns], AID_DNS, -1); in send_dg()
1107 if (statp->_mark != MARK_UNSET) { in send_dg()
1108 if (setsockopt(EXT(statp).nssocks[ns], SOL_SOCKET, in send_dg()
1109 SO_MARK, &(statp->_mark), sizeof(statp->_mark)) < 0) { in send_dg()
1110 res_nclose(statp); in send_dg()
1126 if (random_bind(EXT(statp).nssocks[ns], nsap->sa_family) < 0) { in send_dg()
1127 Aerror(statp, stderr, "bind(dg)", errno, nsap, in send_dg()
1129 res_nclose(statp); in send_dg()
1132 if (__connect(EXT(statp).nssocks[ns], nsap, (socklen_t)nsaplen) < 0) { in send_dg()
1133 Aerror(statp, stderr, "connect(dg)", errno, nsap, in send_dg()
1135 res_nclose(statp); in send_dg()
1139 Dprint(statp->options & RES_DEBUG, in send_dg()
1143 s = EXT(statp).nssocks[ns]; in send_dg()
1146 Perror(statp, stderr, "send", errno); in send_dg()
1147 res_nclose(statp); in send_dg()
1153 Aerror(statp, stderr, "sendto", errno, nsap, nsaplen); in send_dg()
1154 res_nclose(statp); in send_dg()
1162 timeout = get_timeout(statp, params, ns); in send_dg()
1170 Dprint(statp->options & RES_DEBUG, (stdout, ";; timeout\n")); in send_dg()
1175 Perror(statp, stderr, "poll", errno); in send_dg()
1176 res_nclose(statp); in send_dg()
1184 Perror(statp, stderr, "recvfrom", errno); in send_dg()
1185 res_nclose(statp); in send_dg()
1193 Dprint(statp->options & RES_DEBUG, in send_dg()
1197 res_nclose(statp); in send_dg()
1206 DprintQ((statp->options & RES_DEBUG) || in send_dg()
1207 (statp->pfcode & RES_PRF_REPLY), in send_dg()
1212 if (!(statp->options & RES_INSECURE1) && in send_dg()
1213 !res_ourserver_p(statp, (struct sockaddr *)(void *)&from)) { in send_dg()
1219 DprintQ((statp->options & RES_DEBUG) || in send_dg()
1220 (statp->pfcode & RES_PRF_REPLY), in send_dg()
1226 if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0U) { in send_dg()
1232 DprintQ(statp->options & RES_DEBUG, in send_dg()
1236 statp->_flags |= RES_F_EDNS0ERR; in send_dg()
1237 res_nclose(statp); in send_dg()
1241 if (!(statp->options & RES_INSECURE2) && in send_dg()
1249 DprintQ((statp->options & RES_DEBUG) || in send_dg()
1250 (statp->pfcode & RES_PRF_REPLY), in send_dg()
1260 DprintQ(statp->options & RES_DEBUG, in send_dg()
1263 res_nclose(statp); in send_dg()
1265 if (!statp->pfcode) { in send_dg()
1270 if (!(statp->options & RES_IGNTC) && anhp->tc) { in send_dg()
1275 Dprint(statp->options & RES_DEBUG, in send_dg()
1278 res_nclose(statp); in send_dg()
1292 Aerror(const res_state statp, FILE *file, const char *string, int error, in Aerror() argument
1299 if ((statp->options & RES_DEBUG) != 0U) { in Aerror()
1314 Perror(const res_state statp, FILE *file, const char *string, int error) { in Perror() argument
1317 if ((statp->options & RES_DEBUG) != 0U) in Perror()