about summary refs log tree commit diff
path: root/resolv/res_send.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Assume that SOCK_CLOEXEC is available and worksFlorian Weimer2015-10-171-45/+4
| | | | | This fixes (harmless) data races when accessing the various __have_sock_cloexec variables.
* Simplify handling of nameserver configuration in resolverAndreas Schwab2015-05-211-94/+70
| | | | | | | Remove use of ext.nsmap member of struct __res_state and always use an identity mapping betwen the nsaddr_list array and the ext.nsaddrs array. The fact that a nameserver has an IPv6 address is signalled by setting nsaddr_list[].sin_family to zero.
* Fix the 'array subscript is above array bounds' warning correctlySiddhesh Poyarekar2014-12-161-1/+7
| | | | | Use DIAG_IGNORE_NEEDS_COMMENT instead since the compiler should have seen that NS never goes beyond MAXNS.
* Fix 'array subscript is above array bounds' warning in res_send.cSiddhesh Poyarekar2014-12-161-1/+1
| | | | | | | | | | I see this warning in my build on F21 x86_64, which seems to be due to a weak check for array bounds. Fixed by making the bounds check stronger. This is not an actual bug since nscount is never set to anything greater than MAXNS. The compiler however does not know this, so we need the stronger bounds check to quieten the compiler.
* resolv: Suppress maybe uninitialized warningStefan Liebler2014-12-121-1/+26
| | | | | | | | | | | In send_vc function at resolv/res_send.c, There is the following warning on some architectures: 'resplen' may be used uninitialized in this function [-Wmaybe-uninitialized] And this is a false positive. This patch suppress the compiler warning.
* Fix invalid file descriptor reuse while sending DNS query (BZ #15946)Andreas Schwab2014-06-031-0/+1
|
* Do not fail if one of the two responses to AF_UNSPEC fails (BZ #14308)Siddhesh Poyarekar2014-04-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [Fixes BZ #14308, #12994, #13651] AF_UNSPEC results in sending two queries in parallel, one for the A record and the other for the AAAA record. If one of these is a referral, then the query fails, which is wrong. It should return at least the one successful response. The fix has two parts. The first part makes the referral fall back to the SERVFAIL path, which results in using the successful response. There is a bug in that path however, due to which the second part is necessary. The bug here is that if the first response is a failure and the second succeeds, __libc_res_nsearch does not detect that and assumes a failure. The case where the first response is a success and the second fails, works correctly. This condition is produced by buggy routers, so here's a crude interposable library that can simulate such a condition. The library overrides the recvfrom syscall and modifies the header of the packet received to reproduce this scenario. It has two key variables: mod_packet and first_error. The mod_packet variable when set to 0, results in odd packets being modified to be a referral. When set to 1, even packets are modified to be a referral. The first_error causes the first response to be a failure so that a domain-appended search is performed to test the second part of the __libc_nsearch fix. The driver for this fix is a simple getaddrinfo program that does an AF_UNSPEC query. I have omitted this since it should be easy to implement. I have tested this on x86_64. The interceptor library source: /* Override recvfrom and modify the header of the first DNS response to make it a referral and reproduce bz #845218. We have to resort to this ugly hack because we cannot make bind return the buggy response of a referral for the AAAA record and an authoritative response for the A record. */ #define _GNU_SOURCE #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <stdbool.h> #include <endian.h> #include <dlfcn.h> #include <stdlib.h> /* Lifted from resolv/arpa/nameser_compat.h. */ typedef struct { unsigned id :16; /*%< query identification number */ #if BYTE_ORDER == BIG_ENDIAN /* fields in third byte */ unsigned qr: 1; /*%< response flag */ unsigned opcode: 4; /*%< purpose of message */ unsigned aa: 1; /*%< authoritive answer */ unsigned tc: 1; /*%< truncated message */ unsigned rd: 1; /*%< recursion desired */ /* fields * in * fourth * byte * */ unsigned ra: 1; /*%< recursion available */ unsigned unused :1; /*%< unused bits (MBZ as of 4.9.3a3) */ unsigned ad: 1; /*%< authentic data from named */ unsigned cd: 1; /*%< checking disabled by resolver */ unsigned rcode :4; /*%< response code */ #endif #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN /* fields * in * third * byte * */ unsigned rd :1; /*%< recursion desired */ unsigned tc :1; /*%< truncated message */ unsigned aa :1; /*%< authoritive answer */ unsigned opcode :4; /*%< purpose of message */ unsigned qr :1; /*%< response flag */ /* fields * in * fourth * byte * */ unsigned rcode :4; /*%< response code */ unsigned cd: 1; /*%< checking disabled by resolver */ unsigned ad: 1; /*%< authentic data from named */ unsigned unused :1; /*%< unused bits (MBZ as of 4.9.3a3) */ unsigned ra :1; /*%< recursion available */ #endif /* remaining * bytes * */ unsigned qdcount :16; /*%< number of question entries */ unsigned ancount :16; /*%< number of answer entries */ unsigned nscount :16; /*%< number of authority entries */ unsigned arcount :16; /*%< number of resource entries */ } HEADER; static int done = 0; /* Packets to modify. 0 for the odd packets and 1 for even packets. */ static const int mod_packet = 0; /* Set to true if the first request should result in an error, resulting in a search query. */ static bool first_error = true; static ssize_t (*real_recvfrom) (int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen); void __attribute__ ((constructor)) init (void) { real_recvfrom = dlsym (RTLD_NEXT, "recvfrom"); if (real_recvfrom == NULL) { printf ("Failed to get reference to recvfrom: %s\n", dlerror ()); printf ("Cannot simulate test\n"); abort (); } } /* Modify the second packet that we receive to set the header in a manner as to reproduce BZ #845218. */ static void mod_buf (HEADER *h, int port) { if (done % 2 == mod_packet || (first_error && done == 1)) { printf ("(Modifying header)"); if (first_error && done == 1) h->rcode = 3; else h->rcode = 0; /* NOERROR == 0. */ h->ancount = 0; h->aa = 0; h->ra = 0; h->arcount = 0; } done++; } ssize_t recvfrom (int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen) { ssize_t ret = real_recvfrom (sockfd, buf, len, flags, src_addr, addrlen); int port = htons (((struct sockaddr_in *) src_addr)->sin_port); struct in_addr addr = ((struct sockaddr_in *) src_addr)->sin_addr; const char *host = inet_ntoa (addr); printf ("\n*** From %s:%d: ", host, port); mod_buf (buf, port); printf ("returned %zd\n", ret); return ret; }
* Define _STRING_ARCH_unaligned unconditionallyAdhemerval Zanella2014-04-091-2/+2
| | | | | | | This patch defines _STRING_ARCH_unaligned to 0 on default bits/string.h header to avoid undefined compiler warnings on platforms that do not define it. It also make adjustments in code where tests checked if macro existed or not.
* Properly fix memory leak in _nss_dns_gethostbyname4_r with big DNS answerAndreas Schwab2014-02-191-8/+13
| | | | | Instead of trying to guess whether the second buffer needs to be freed set a flag at the place it is allocated
* Use glibc_likely instead __builtin_expect.Ondřej Bílka2014-02-101-18/+18
|
* Correctly copy resolver address. Fixes bug #13028.Ondřej Bílka2013-10-141-1/+1
|
* Don't try to use ioctl unless [FIONREAD].Roland McGrath2013-08-271-1/+4
|
* Fix typos.Ondřej Bílka2013-08-211-1/+1
|
* Remove lots of inline keywords.Roland McGrath2013-02-071-2/+2
|
* Add recvmmsg and sendmmsg to the generic glibc API.Thomas Schwinge2012-11-201-1/+1
|
* Better error handling for sendmmsg use in res_sendUlrich Drepper2012-03-301-5/+7
|
* Correct check for DNS request send successUlrich Drepper2012-03-301-1/+1
| | | | | | This predates the sendmmsg use. The two requests can use different request sizes but the check for successful transfer always only used buflen.
* Speed up DNS by avoiding a system call if possibleUlrich Drepper2012-03-301-17/+83
|
* Fix typo in recent resolver change which causes segvsUlrich Drepper2011-06-151-2/+2
|
* Handle DNS server failures in case of AF_UNSPEC lookups correctlyUlrich Drepper2011-05-301-4/+8
|
* Fix debug statements in resolverAndreas Schwab2010-03-171-7/+10
|
* Fix DEBUG statements in resolv/res_send.cYann Droneaud2010-03-051-19/+20
|
* Always use IPv4 sockets for IPv4 addresses.Ulrich Drepper2010-01-141-35/+9
|
* Initialize local variable in resolver.Ulrich Drepper2009-10-291-1/+2
| | | | | When the DNS server doesn't reply at all we possibly tested an unitialized variable.
* Fix mixing IPv4 and IPv6 name server in resolv.conf.Petar Bogdanovic2009-10-291-26/+26
|
* Handle SERVFAIL, NOTIMP, REFUSED replies from DNS server better.Ulrich Drepper2009-07-261-5/+1
| | | | | When doing IPv4+6 lookups we have to pass up the error record from send_dg.
* Implement second fallback mode for DNS requests.Ulrich Drepper2009-06-261-19/+49
| | | | | | | | | | | | There is some more shardware/software out there which has problems if two DNS requests are sent using the same tuple (source addr, source port, dest addr, dest port) This can range from firewalls to load balancers. Some of the vendors already fixed it in response to this problem. Still, we need a way to make glibc work with broken environments. The single-request-reopen flag can be used or we fall back automatically to this mode.
* Remember we switched to single-request mode.Ulrich Drepper2009-06-111-1/+2
| | | | | This change prevents repetition in most later calls of the resolver in case the DNS server or the network connection is broken.
* (send_dg): Don't just ignore the result we got in case we only receive one ↵Ulrich Drepper2009-04-161-6/+10
| | | | reply in single-request mode.
* * resolv/res_send.c (send_dg): Don't switch into single-requestUlrich Drepper2009-04-161-1/+3
| | | | mode if we already are in it.
* * resolv/resolv.h (RES_SNGLKUP): Define. cvs/fedora-glibc-20090407T0545Ulrich Drepper2009-04-071-11/+26
| | | | | | | * resolv/res_init.c (res_setoptions): Recognize single-request option. * resolv/res_send.c (send_dg): If we sent two requests at once and only get one reply before timeout switch to mode where we send the second request only after the first answer has been received.
* * resolv/res_send.c (send_dg): Use correct guards for SOCK_CLOEXECUlrich Drepper2008-12-081-3/+3
| | | | | | | use. * sysdeps/unix/sysv/linux/kernel-features.h: Fix typo in accept4 handling.
* * resolv/res_send.c (send_dg): Create sockets with non-blockingUlrich Drepper2008-12-021-11/+47
| | | | flag already set.
* [BZ #6942]Ulrich Drepper2008-10-311-1/+9
| | | | | | | 2008-10-07 Andreas Schwab <schwab@suse.de> [BZ #6942] * resolv/res_send.c (send_vc): Fix last change. (send_dg): Align here as well.
* * grp/initgroups.c (internal_getgrouplist): Don't prematurelyUlrich Drepper2008-10-301-1/+1
| | | | abort if there is no initgroups_dyn function.
* * resolv/res_send.c (send_dg): On timeout, only return nonzeroUlrich Drepper2008-10-301-1/+1
| | | | result if any of the queries really provided an answer.
* (send_vc): Fix use of unaligned address. Properly handle partial reads.Ulrich Drepper2008-10-061-3/+11
|
* * resolv/res_send.c (__libc_res_nsend): Take additional parameter. cvs/fedora-glibc-20080728T2320Ulrich Drepper2008-07-281-27/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use it instead of locally defined resplen2 variable. (res_nsend): Adjust for __libc_res_nsend interface change. (send_vc): Initialize *resplen2 if necessary. Read length of package into an appropriately aligned variable. Store converted length in new variable and use it appropriately. Add branch prediction help. * resolv/res_query.c (__libc_res_nquery): Take additional parameter and pass it on to __libc_res_nsend. Adjust all callers. (__libc_res_nsearch): Likewise. (__libc_res_nqeurydomain): Likewise. * resolv/nss_dns/dns-host.c: Adjust for __libc_res_nsearch interface change. (_nss_dns_gethostbyname4): Don't unconditionally allocate tmp array. Define resplen2 variable and pass it to __libc_res_nsearch and then to gaih_getanswer. (getanswer_r): In case of incorrect DNS data don't overread buffer. Add branch prediction. (gaih_getanswer_slice): Likewise. Check for invalid data types. (gaih_getanswer): Don't decode second slice if first one failed due to a too small buffer. Don't let not found status of second decoder shadow results of the first. * resolv/gethnamaddr.c (gethostbyname2): Adjust for __libc_res_nsearch and __libc_res_nquery interface changes (gethostbyaddr): Adjust for __libc_res_nquery interface change. * include/resolv.h: Adjust prototypes for __libc_res_nquery, __libc_res_nsearch, and __libc_res_nsend. * resolv/nss_dns/dns-canon.c: Adjust for __libc_res_nquery interface change. * resolv/nss_dns/dns-network.c: Adjust for __libc_res_nquery and __libc_res_nsearch interface changes.
* * resolv/res_send.c: Remove unnecessary res_pquery prototype.Ulrich Drepper2008-07-091-1/+0
|
* * resolv/res_send.c (send_dg): If we already have one of twoUlrich Drepper2008-05-241-6/+24
| | | | | answers and the server reports SERVFAI, NOTIMP, or REFUSED, then use the one answer insted of failing.
* * resolv/res_query.c (__libc_res_nquery): In case one of twoUlrich Drepper2008-05-191-0/+7
| | | | | | | | answer was too short don't try to read that answer's header. * resolv/res_send.c (send_dg): In case of timeout and there are two queries and one has been answered, return value indicating success.
* * include/resolv.h: Adjust __libc_res_nquery and __libc_res_nsendUlrich Drepper2008-05-101-81/+242
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | prototypes. * include/arpa/nameser_compat.h: Define T_UNSPEC. * nis/Versions (libnss_nis): Export _nss_nis_gethostbyname4_r. (libnss_nisplus): Export _nss_nisplus_gethostbyname4_r. * nis/nss_nis/nis-hosts.c (LINE_PARSER): Change to also handle af==AF_UNSPEC. (_nss_nis_gethostbyname4_r): New function. * nis/nss_nisplus/nisplus-hosts.c (_nss_nisplus_parse_hostent): Change to also handle af==AF_UNSPEC. (get_tablename): New function. Use it to avoid duplication. (_nss_nisplus_gethostbyname4_r): New function. * nscd/aicache.c (addhstaiX): Use gethostbyname4_r function is available. * nss/Versions (libnss_files): Export _nss_files_gethostbyname4_r. * nss/nss.h: Define struct gaih_addrtuple. * nss/nss_files/files-hosts.c (LINE_PARSER): Change to also handle af==AF_UNSPEC. (_nss_files_gethostbyname4_r): New function. * resolv/Versions (libnss_dns): Export _nss_dns_gethostbyname4_r. * resolv/gethnmaddr.c: Adjust __libc_res_nsearch and __libc_res_nquery calls. * resolv/res_query.c (__libc_res_nquery): Take two additional parameters for second answer buffer. Handle type=T_UNSPEC to mean look up IPv4 and IPv6. Change all callers. * resolv/res_send.c (__libc_res_nsend): Take five aditional parameters for an additional query and answer buffer. Pass to send_vc and send_dg. (send_vc): Send possibly two requests and receive two answers. (send_dg): Likewise. * resolv/nss_dns/dns-host.c: Adjust calls to __libc_res_nsearch and __libc_res_nquery. (_nss_dns_gethostbyname4_r): New function. (gaih_getanswer_slice): Likewise. (gaih_getanswer): Likewise. * resolv/nss_dns/dns-canon.c (_nss_dns_getcanonname_r): Adjust __libc_res_nquery call. * resolv/nss_dns/dns-network.c (_nss_dns_getnetbyaddr_r): Likewise. (_nss_dns_getnetbyname_r): Adjust __libc_res_nsearch call. * sysdeps/posix/getaddrinfo.c: Use gethostbyname4_r function is available.
* [BZ #4726]Ulrich Drepper2007-08-221-3/+6
| | | | | * resolv/res_send.c (__libc_res_nsend): Initialize all of the memory allocated for the name server address.
* [BZ #4647]Ulrich Drepper2007-06-181-7/+8
| | | | | | | | | | | | | | | | Tomas Janousek <tjanouse@redhat.com> Ulrich Drepper <drepper@redhat.com> [BZ #4647] * resolv/res_send.c (send_dg): Remove socket_pf. Use ipv6_unavail member in __res_state, only convaddr4to6 if nssocks[ns] is a PF_INET6 socket. * resolv/resolv.h (__res_state): Add ipv6_unavail member. Make unused member a bitmap. * resolv/res_init.c (__res_vinit): Reset ipv6_unavail if IPv6 servers are configured. 2007-06-18 Jakub Jelinek <jakub@redhat.com>
* * resolv/res_init.c (res_setoptions): Recognize edns0 option.Ulrich Drepper2007-02-091-0/+18
| | | | | | | | | | * resolv/res_mkquery.c: Define __res_nopt. * resolv/res_query.c (__libc_res_nquery): If RES_USE_EDNS0 is set try adding EDNS0 record. * resolv/res_send.c (send_dg): If request failed with FORMERR and EDNS0 record was send make sure we don't try it again. * resolv/resolv.h: Define RES_F_EDNS0ERR and RES_USE_EDNS0. * include/resolv.h: Declare __res_nopt.
* * include/arpa/nameser.h: Also optimize NS_PUT16 and NS_PUT32.Ulrich Drepper2006-05-061-1/+1
| | | | | | | | * resolv/res_mkquery.c: Use NS_PUT16 and NS_PUT32 instead of __putshort and __putlong respectively. Correct buffer overflow check for NS_NOTIFY_OP. * resolv/res_send.c (send_vc): Use ns_put16 instead of putshort.
* * resolv/res_send.c (res_queriesmatch): Fix typo in comment.Ulrich Drepper2006-05-061-22/+14
| | | | | (send_dg): Rewrite error handling to be more compact and avoid double recomputation of timeouts. Pass MSG_NOSIGNAL to send.
* * include/arpa/nameser.h: Add optimizations for NS_GET16 and NS_GET32.Ulrich Drepper2006-05-061-8/+13
| | | | | | * resolv/res_send.c (res_nameinquery): Use NS_GET16 directly instead of ns_get16. (res_queriesmatch): Likewise. Minor optimization.
* * resolv/res_init.c (__res_iclose): New function. Broken out ofUlrich Drepper2005-11-011-24/+22
| | | | | | | | | | | | | | | | | res_nclose. Take addition parameter which determines whether addresses should be freed. (res_nclose): Call __res_iclose. (res_thread_freeres): Likewise. * resolv/res_data.c (res_close): Call __res_iclose. * resolv/res_libc.c (res_init): No need to separately free the addresses. (__res_maybe_init): Likewise. * resolv/res_send.c: Use __res_iclose instead of res_nclose. * resolv/Versions [GLIBC_PRIVATE]: Add __res_iclose. * include/resolv.h: Declare __res_iclose. Add libc_hidden_proto for __res_iclose. * hesiod/hesiod.c (__hesiod_res_set): No need to free name server addresses here again.
* * resolv/res_send.c (Aerror): Fix printing IP address. cvs/fedora-glibc-20050822T0727Ulrich Drepper2005-08-221-2/+7
|