Lines Matching +full:class +full:- +full:dg
1 /*-
2 * SPDX-License-Identifier: (ISC AND BSD-3-Clause)
4 * Portions Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC")
5 * Portions Copyright (C) 1996-2003 Internet Software Consortium.
113 #include "un-namespace.h"
122 #define EXT(res) ((res)->_u._ext)
125 static const int highestFD = FD_SETSIZE - 1;
172 switch (sa->sa_family) { in res_ourserver_p()
175 for (ns = 0; ns < statp->nscount; ns++) { in res_ourserver_p()
177 if (srv->sin_family == inp->sin_family && in res_ourserver_p()
178 srv->sin_port == inp->sin_port && in res_ourserver_p()
179 (srv->sin_addr.s_addr == INADDR_ANY || in res_ourserver_p()
180 srv->sin_addr.s_addr == inp->sin_addr.s_addr)) in res_ourserver_p()
188 for (ns = 0; ns < statp->nscount; ns++) { in res_ourserver_p()
190 if (srv6->sin6_family == in6p->sin6_family && in res_ourserver_p()
191 srv6->sin6_port == in6p->sin6_port && in res_ourserver_p()
193 (srv6->sin6_scope_id == 0 || in res_ourserver_p()
194 srv6->sin6_scope_id == in6p->sin6_scope_id) && in res_ourserver_p()
196 (IN6_IS_ADDR_UNSPECIFIED(&srv6->sin6_addr) || in res_ourserver_p()
197 IN6_ARE_ADDR_EQUAL(&srv6->sin6_addr, &in6p->sin6_addr))) in res_ourserver_p()
208 * look for (name,type,class) in the query section of packet (buf,eom)
214 *\li -1 : format error
222 res_nameinquery(const char *name, int type, int class, in res_nameinquery() argument
226 int qdcount = ntohs(((const HEADER*)buf)->qdcount); in res_nameinquery()
228 while (qdcount-- > 0) { in res_nameinquery()
234 return (-1); in res_nameinquery()
237 return (-1); in res_nameinquery()
240 if (ttype == type && tclass == class && in res_nameinquery()
248 * is there a 1:1 mapping of (name,type,class)
252 *\li -1 : format error
264 int qdcount = ntohs(((const HEADER*)buf1)->qdcount); in res_queriesmatch()
267 return (-1); in res_queriesmatch()
273 if ((((const HEADER *)buf1)->opcode == ns_o_update) && in res_queriesmatch()
274 (((const HEADER *)buf2)->opcode == ns_o_update)) in res_queriesmatch()
277 if (qdcount != ntohs(((const HEADER*)buf2)->qdcount)) in res_queriesmatch()
279 while (qdcount-- > 0) { in res_queriesmatch()
285 return (-1); in res_queriesmatch()
288 return (-1); in res_queriesmatch()
308 if (statp->nscount == 0 || EXT(statp).ext == NULL) { in res_nsend()
310 return (-1); in res_nsend()
314 return (-1); in res_nsend()
316 DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_QUERY), in res_nsend()
318 v_circuit = (statp->options & RES_USEVC) || buflen > PACKETSZ; in res_nsend()
325 return (-1); in res_nsend()
338 if (EXT(statp).nscount != statp->nscount) in res_nsend()
341 for (ns = 0; ns < statp->nscount; ns++) { in res_nsend()
342 if (statp->nsaddr_list[ns].sin_family && in res_nsend()
343 !sock_eq((struct sockaddr *)&statp->nsaddr_list[ns], in res_nsend()
344 (struct sockaddr *)&EXT(statp).ext->nsaddrs[ns])) { in res_nsend()
349 if (EXT(statp).nssocks[ns] == -1) in res_nsend()
373 for (ns = 0; ns < statp->nscount; ns++) { in res_nsend()
375 EXT(statp).nssocks[ns] = -1; in res_nsend()
376 if (!statp->nsaddr_list[ns].sin_family) in res_nsend()
378 EXT(statp).ext->nsaddrs[ns].sin = in res_nsend()
379 statp->nsaddr_list[ns]; in res_nsend()
381 EXT(statp).nscount = statp->nscount; in res_nsend()
388 if ((statp->options & RES_ROTATE) != 0U && in res_nsend()
389 (statp->options & RES_BLAST) == 0U) { in res_nsend()
392 int lastns = statp->nscount - 1; in res_nsend()
397 inu = EXT(statp).ext->nsaddrs[0]; in res_nsend()
398 ina = statp->nsaddr_list[0]; in res_nsend()
403 EXT(statp).ext->nsaddrs[ns] = in res_nsend()
404 EXT(statp).ext->nsaddrs[ns + 1]; in res_nsend()
405 statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1]; in res_nsend()
410 EXT(statp).ext->nsaddrs[lastns] = inu; in res_nsend()
411 statp->nsaddr_list[lastns] = ina; in res_nsend()
419 for (tries = 0; tries < statp->retry; tries++) { in res_nsend()
420 for (ns = 0; ns < statp->nscount; ns++) { in res_nsend()
425 statp->_flags &= ~RES_F_LASTMASK; in res_nsend()
426 statp->_flags |= (ns << RES_F_LASTSHIFT); in res_nsend()
428 if (statp->qhook) { in res_nsend()
434 act = (*statp->qhook)(&nsap, &buf, &buflen, in res_nsend()
461 Dprint(((statp->options & RES_DEBUG) && in res_nsend()
470 tries = statp->retry; in res_nsend()
495 Dprint((statp->options & RES_DEBUG) || in res_nsend()
496 ((statp->pfcode & RES_PRF_REPLY) && in res_nsend()
497 (statp->pfcode & RES_PRF_HEAD1)), in res_nsend()
500 DprintQ((statp->options & RES_DEBUG) || in res_nsend()
501 (statp->pfcode & RES_PRF_REPLY), in res_nsend()
510 if ((v_circuit && (statp->options & RES_USEVC) == 0U) || in res_nsend()
511 (statp->options & RES_STAYOPEN) == 0U) { in res_nsend()
514 if (statp->rhook) { in res_nsend()
520 act = (*statp->rhook)(nsap, buf, buflen, in res_nsend()
561 return (-1); in res_nsend()
567 return (-1); in res_nsend()
578 if (sa->sa_len) in get_salen()
579 return (sa->sa_len); in get_salen()
582 if (sa->sa_family == AF_INET) in get_salen()
584 else if (sa->sa_family == AF_INET6) in get_salen()
597 if (!statp->nsaddr_list[n].sin_family && EXT(statp).ext) { in get_nsaddr()
599 * - EXT(statp).ext->nsaddrs[n] holds an address that is larger in get_nsaddr()
601 * - user code did not update statp->nsaddr_list[n]. in get_nsaddr()
603 return (struct sockaddr *)(void *)&EXT(statp).ext->nsaddrs[n]; in get_nsaddr()
606 * - user code updated statp->nsaddr_list[n], or in get_nsaddr()
607 * - statp->nsaddr_list[n] has the same content as in get_nsaddr()
608 * EXT(statp).ext->nsaddrs[n]. in get_nsaddr()
610 return (struct sockaddr *)(void *)&statp->nsaddr_list[n]; in get_nsaddr()
640 if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) { in send_vc()
644 if (_getpeername(statp->_vcsock, in send_vc()
648 statp->_flags &= ~RES_F_VC; in send_vc()
652 if (statp->_vcsock < 0 || (statp->_flags & RES_F_VC) == 0) { in send_vc()
653 if (statp->_vcsock >= 0) in send_vc()
656 statp->_vcsock = _socket(nsap->sa_family, SOCK_STREAM | in send_vc()
659 if (statp->_vcsock > highestFD) { in send_vc()
664 if (statp->_vcsock < 0) { in send_vc()
676 return (-1); in send_vc()
682 * socket. Write should return -1 and set errno to EPIPE in send_vc()
687 (void)_setsockopt(statp->_vcsock, SOL_SOCKET, SO_NOSIGPIPE, &on, in send_vc()
691 if (_connect(statp->_vcsock, nsap, nsaplen) < 0) { in send_vc()
698 statp->_flags |= RES_F_VC; in send_vc()
708 if (_writev(statp->_vcsock, iov, 2) != (INT16SZ + buflen)) { in send_vc()
720 while ((n = _read(statp->_vcsock, (char *)cp, (int)len)) > 0) { in send_vc()
722 if ((len -= n) == 0) in send_vc()
748 Dprint(statp->options & RES_DEBUG, in send_vc()
759 Dprint(statp->options & RES_DEBUG, in send_vc()
767 (n = _read(statp->_vcsock, (char *)cp, (int)len)) > 0) { in send_vc()
769 len -= n; in send_vc()
781 anhp->tc = 1; in send_vc()
782 len = resplen - anssiz; in send_vc()
786 n = _read(statp->_vcsock, junk, in send_vc()
789 len -= n; in send_vc()
801 if (hp->id != anhp->id) { in send_vc()
802 DprintQ((statp->options & RES_DEBUG) || in send_vc()
803 (statp->pfcode & RES_PRF_REPLY), in send_vc()
846 if (EXT(statp).nssocks[ns] == -1) { in send_dg()
847 EXT(statp).nssocks[ns] = _socket(nsap->sa_family, in send_dg()
862 Perror(statp, stderr, "socket(dg)", errno); in send_dg()
866 Perror(statp, stderr, "socket(dg)", errno); in send_dg()
867 return (-1); in send_dg()
889 if (!(statp->options & RES_INSECURE1) && in send_dg()
891 Aerror(statp, stderr, "connect(dg)", errno, nsap, in send_dg()
897 Dprint(statp->options & RES_DEBUG, in send_dg()
898 (stdout, ";; new DG socket\n")) in send_dg()
902 if (statp->options & RES_INSECURE1) { in send_dg()
926 seconds = (statp->retrans << tries); in send_dg()
928 seconds /= statp->nscount; in send_dg()
963 Dprint(statp->options & RES_DEBUG, (stdout, ";; timeout\n")); in send_dg()
1000 Dprint(statp->options & RES_DEBUG, in send_dg()
1007 if (hp->id != anhp->id) { in send_dg()
1010 * XXX - potential security hazard could in send_dg()
1013 DprintQ((statp->options & RES_DEBUG) || in send_dg()
1014 (statp->pfcode & RES_PRF_REPLY), in send_dg()
1019 if (!(statp->options & RES_INSECURE1) && in send_dg()
1023 * XXX - potential security hazard could in send_dg()
1026 DprintQ((statp->options & RES_DEBUG) || in send_dg()
1027 (statp->pfcode & RES_PRF_REPLY), in send_dg()
1033 if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0U) { in send_dg()
1039 DprintQ(statp->options & RES_DEBUG, in send_dg()
1043 statp->_flags |= RES_F_EDNS0ERR; in send_dg()
1048 if (!(statp->options & RES_INSECURE2) && in send_dg()
1053 * XXX - potential security hazard could in send_dg()
1056 DprintQ((statp->options & RES_DEBUG) || in send_dg()
1057 (statp->pfcode & RES_PRF_REPLY), in send_dg()
1062 if (anhp->rcode == SERVFAIL || in send_dg()
1063 anhp->rcode == NOTIMP || in send_dg()
1064 anhp->rcode == REFUSED) { in send_dg()
1065 DprintQ(statp->options & RES_DEBUG, in send_dg()
1070 if (!statp->pfcode) in send_dg()
1073 if (!(statp->options & RES_IGNTC) && anhp->tc) { in send_dg()
1078 Dprint(statp->options & RES_DEBUG, in send_dg()
1099 if ((statp->options & RES_DEBUG) != 0U) { in Aerror()
1102 strncpy(hbuf, "?", sizeof(hbuf) - 1); in Aerror()
1103 hbuf[sizeof(hbuf) - 1] = '\0'; in Aerror()
1104 strncpy(sbuf, "?", sizeof(sbuf) - 1); in Aerror()
1105 sbuf[sizeof(sbuf) - 1] = '\0'; in Aerror()
1117 if ((statp->options & RES_DEBUG) != 0U) in Perror()
1128 if (a->sa_family != b->sa_family) in sock_eq()
1130 switch (a->sa_family) { in sock_eq()
1134 return a4->sin_port == b4->sin_port && in sock_eq()
1135 a4->sin_addr.s_addr == b4->sin_addr.s_addr; in sock_eq()
1139 return a6->sin6_port == b6->sin6_port && in sock_eq()
1141 a6->sin6_scope_id == b6->sin6_scope_id && in sock_eq()
1143 IN6_ARE_ADDR_EQUAL(&a6->sin6_addr, &b6->sin6_addr); in sock_eq()