Home | History | Annotate | Download | only in resolv

Lines Matching refs:statp

233 res_ourserver_p(const res_state statp, const struct sockaddr *sa) {
241 for (ns = 0; ns < statp->nscount; ns++) {
242 srv = (struct sockaddr_in *)(void *)get_nsaddr(statp, (size_t)ns);
251 if (EXT(statp).ext == NULL)
254 for (ns = 0; ns < statp->nscount; ns++) {
255 srv6 = (struct sockaddr_in6 *)(void *)get_nsaddr(statp, (size_t)ns);
361 res_nsend(res_state statp,
372 DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_QUERY),
374 v_circuit = (statp->options & RES_USEVC) || buflen > PACKETSZ;
380 statp->netid, buf, buflen,
388 _resolv_populate_res_for_net(statp);
390 if (statp->nscount == 0) {
394 _resolv_cache_query_failed(statp->netid, buf, buflen);
403 if (EXT(statp).nscount != 0) {
408 if (EXT(statp).nscount != statp->nscount) {
411 for (ns = 0; ns < statp->nscount; ns++) {
412 if (statp->nsaddr_list[ns].sin_family &&
413 !sock_eq((struct sockaddr *)(void *)&statp->nsaddr_list[ns],
414 (struct sockaddr *)(void *)&EXT(statp).ext->nsaddrs[ns])) {
419 if (EXT(statp).nssocks[ns] == -1)
422 if (getpeername(EXT(statp).nssocks[ns],
428 get_nsaddr(statp, (size_t)ns))) {
435 res_nclose(statp);
436 EXT(statp).nscount = 0;
443 if (EXT(statp).nscount == 0) {
444 for (ns = 0; ns < statp->nscount; ns++) {
445 EXT(statp).nstimes[ns] = RES_MAXTIME;
446 EXT(statp).nssocks[ns] = -1;
447 if (!statp->nsaddr_list[ns].sin_family)
449 EXT(statp).ext->nsaddrs[ns].sin =
450 statp->nsaddr_list[ns];
452 EXT(statp).nscount = statp->nscount;
459 if ((statp->options & RES_ROTATE) != 0U &&
460 (statp->options & RES_BLAST) == 0U) {
463 int lastns = statp->nscount - 1;
467 if (EXT(statp).ext != NULL)
468 inu = EXT(statp).ext->nsaddrs[0];
469 ina = statp->nsaddr_list[0];
470 fd = EXT(statp).nssocks[0];
471 nstime = EXT(statp).nstimes[0];
473 if (EXT(statp).ext != NULL)
474 EXT(statp).ext->nsaddrs[ns] =
475 EXT(statp).ext->nsaddrs[ns + 1];
476 statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1];
477 EXT(statp).nssocks[ns] = EXT(statp).nssocks[ns + 1];
478 EXT(statp).nstimes[ns] = EXT(statp).nstimes[ns + 1];
480 if (EXT(statp).ext != NULL)
481 EXT(statp).ext->nsaddrs[lastns] = inu;
482 statp->nsaddr_list[lastns] = ina;
483 EXT(statp).nssocks[lastns] = fd;
484 EXT(statp).nstimes[lastns] = nstime;
490 for (try = 0; try < statp->retry; try++) {
493 int revision_id = _resolv_cache_get_resolver_stats(statp->netid, &params, stats);
495 android_net_res_stats_get_usable_servers(&params, stats, statp->nscount,
498 for (ns = 0; ns < statp->nscount; ns++) {
505 nsap = get_nsaddr(statp, (size_t)ns);
507 statp->_flags &= ~RES_F_LASTMASK;
508 statp->_flags |= (ns << RES_F_LASTSHIFT);
511 if (statp->qhook) {
517 act = (*statp->qhook)(&nsap, &buf, &buflen,
524 res_nclose(statp);
528 _resolv_cache_add(statp->netid, buf, buflen,
545 statp->options & RES_DEBUG) &&
554 try = statp->retry;
556 n = send_vc(statp, buf, buflen, ans, anssiz, &terrno,
567 _resolv_cache_add_resolver_stats_sample(statp->netid, revision_id,
587 n = send_dg(statp, buf, buflen, ans, anssiz, &terrno,
594 _resolv_cache_add_resolver_stats_sample(statp->netid, revision_id,
615 Dprint((statp->options & RES_DEBUG) ||
616 ((statp->pfcode & RES_PRF_REPLY) &&
617 (statp->pfcode & RES_PRF_HEAD1)),
620 DprintQ((statp->options & RES_DEBUG) ||
621 (statp->pfcode & RES_PRF_REPLY),
626 _resolv_cache_add(statp->netid, buf, buflen,
634 if ((v_circuit && (statp->options & RES_USEVC) == 0U) ||
635 (statp->options & RES_STAYOPEN) == 0U) {
636 res_nclose(statp);
638 if (statp->rhook) {
644 act = (*statp->rhook)(nsap, buf, buflen,
652 res_nclose(statp);
671 res_nclose(statp);
680 _resolv_cache_query_failed(statp->netid, buf, buflen);
685 _resolv_cache_query_failed(statp->netid, buf, buflen);
686 res_nclose(statp);
715 get_nsaddr(statp, n)
716 res_state statp;
720 if (!statp->nsaddr_list[n].sin_family && EXT(statp).ext) {
722 * - EXT(statp).ext->nsaddrs[n] holds an address that is larger
724 * - user code did not update statp->nsaddr_list[n].
726 return (struct sockaddr *)(void *)&EXT(statp).ext->nsaddrs[n];
729 * - user code updated statp->nsaddr_list[n], or
730 * - statp->nsaddr_list[n] has the same content as
731 * EXT(statp).ext->nsaddrs[n].
733 return (struct sockaddr *)(void *)&statp->nsaddr_list[n];
737 static int get_timeout(const res_state statp, const int ns)
739 int timeout = (statp->retrans << ns);
741 timeout /= statp->nscount;
754 send_vc(res_state statp,
775 nsap = get_nsaddr(statp, (size_t)ns);
785 if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) {
790 if (getpeername(statp->_vcsock,
793 getsockopt(statp->_vcsock, SOL_SOCKET, SO_MARK, &old_mark, &mark_size) < 0 ||
794 old_mark != statp->_mark) {
795 res_nclose(statp);
796 statp->_flags &= ~RES_F_VC;
800 if (statp->_vcsock < 0 || (statp->_flags & RES_F_VC) == 0) {
801 if (statp->_vcsock >= 0)
802 res_nclose(statp);
804 statp->_vcsock = socket(nsap->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0);
805 if (statp->_vcsock > highestFD) {
806 res_nclose(statp);
809 if (statp->_vcsock < 0) {
816 Perror(statp, stderr, "socket(vc)", errno);
820 Perror(statp, stderr, "socket(vc)", errno);
824 fchown(statp->_vcsock, AID_DNS, -1);
825 if (statp->_mark != MARK_UNSET) {
826 if (setsockopt(statp->_vcsock, SOL_SOCKET,
827 SO_MARK, &statp->_mark, sizeof(statp->_mark)) < 0) {
829 Perror(statp, stderr, "setsockopt", errno);
834 if (random_bind(statp->_vcsock,nsap->sa_family) < 0) {
836 Aerror(statp, stderr, "bind/vc", errno, nsap,
838 res_nclose(statp);
841 if (connect_with_timeout(statp->_vcsock, nsap, (socklen_t)nsaplen,
842 get_timeout(statp, ns)) < 0) {
844 Aerror(statp, stderr, "connect/vc", errno, nsap,
846 res_nclose(statp);
858 statp->_flags |= RES_F_VC;
868 if (writev(statp->_vcsock, iov, 2) != (INT16SZ + buflen)) {
870 Perror(statp, stderr, "write failed", errno);
871 res_nclose(statp);
880 while ((n = read(statp->_vcsock, (char *)cp, (size_t)len)) > 0) {
887 Perror(statp, stderr, "read failed", errno);
888 res_nclose(statp);
900 res_nclose(statp);
903 res_nclose(statp);
908 Dprint(statp->options & RES_DEBUG,
919 Dprint(statp->options & RES_DEBUG,
922 res_nclose(statp);
926 while (len != 0 && (n = read(statp->_vcsock, (char *)cp, (size_t)len)) > 0){
932 Perror(statp, stderr, "read(vc)", errno);
933 res_nclose(statp);
946 n = read(statp->_vcsock, junk,
962 DprintQ((statp->options & RES_DEBUG) ||
963 (statp->pfcode & RES_PRF_REPLY),
1085 send_dg(res_state statp,
1103 nsap = get_nsaddr(statp, (size_t)ns);
1105 if (EXT(statp).nssocks[ns] == -1) {
1106 EXT(statp).nssocks[ns] = socket(nsap->sa_family, SOCK_DGRAM | SOCK_CLOEXEC, 0);
1107 if (EXT(statp).nssocks[ns] > highestFD) {
1108 res_nclose(statp);
1111 if (EXT(statp).nssocks[ns] < 0) {
1118 Perror(statp, stderr, "socket(dg)", errno);
1122 Perror(statp, stderr, "socket(dg)", errno);
1127 fchown(EXT(statp).nssocks[ns], AID_DNS, -1);
1128 if (statp->_mark != MARK_UNSET) {
1129 if (setsockopt(EXT(statp).nssocks[ns], SOL_SOCKET,
1130 SO_MARK, &(statp->_mark), sizeof(statp->_mark)) < 0) {
1131 res_nclose(statp);
1147 if (random_bind(EXT(statp).nssocks[ns], nsap->sa_family) < 0) {
1148 Aerror(statp, stderr, "bind(dg)", errno, nsap,
1150 res_nclose(statp);
1153 if (__connect(EXT(statp).nssocks[ns], nsap, (socklen_t)nsaplen) < 0) {
1154 Aerror(statp, stderr, "connect(dg)", errno, nsap,
1156 res_nclose(statp);
1160 Dprint(statp->options & RES_DEBUG,
1164 s = EXT(statp).nssocks[ns];
1167 Perror(statp, stderr, "send", errno);
1168 res_nclose(statp);
1174 Aerror(statp, stderr, "sendto", errno, nsap, nsaplen);
1175 res_nclose(statp);
1183 seconds = get_timeout(statp, ns);
1192 Dprint(statp->options & RES_DEBUG, (stdout, ";; timeout\n"));
1197 Perror(statp, stderr, "select", errno);
1198 res_nclose(statp);
1206 Perror(statp, stderr, "recvfrom", errno);
1207 res_nclose(statp);
1215 Dprint(statp->options & RES_DEBUG,
1219 res_nclose(statp);
1228 DprintQ((statp->options & RES_DEBUG) ||
1229 (statp->pfcode & RES_PRF_REPLY),
1234 if (!(statp->options & RES_INSECURE1) &&
1235 !res_ourserver_p(statp, (struct sockaddr *)(void *)&from)) {
1241 DprintQ((statp->options & RES_DEBUG) ||
1242 (statp->pfcode & RES_PRF_REPLY),
1248 if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0U) {
1254 DprintQ(statp->options & RES_DEBUG,
1258 statp->_flags |= RES_F_EDNS0ERR;
1259 res_nclose(statp);
1263 if (!(statp->options & RES_INSECURE2) &&
1271 DprintQ((statp->options & RES_DEBUG) ||
1272 (statp->pfcode & RES_PRF_REPLY),
1282 DprintQ(statp->options & RES_DEBUG,
1285 res_nclose(statp);
1287 if (!statp->pfcode) {
1292 if (!(statp->options & RES_IGNTC) && anhp->tc) {
1297 Dprint(statp->options & RES_DEBUG,
1300 res_nclose(statp);
1314 Aerror(const res_state statp, FILE *file, const char *string, int error,
1321 if ((statp->options & RES_DEBUG) != 0U) {
1336 Perror(const res_state statp, FILE *file, const char *string, int error) {
1339 if ((statp->options & RES_DEBUG) != 0U)