summaryrefslogtreecommitdiffstats
path: root/libc/inet/resolv.c
Commit message (Collapse)AuthorAgeFilesLines
* resolv.c fails for /etc/hosts lookupsPhilip Nye2010-11-231-8/+12
| | | | | | | | | | | | Patch attached: Fix a bug in offset calculations when parsing /etc/hosts in resolv.c. Formerly a miscalculation meant that having found the correct line, the code was trashing its own result data. Signed-off-by: Philip Nye <philipn@engarts.com> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
* Fix resolver broken in NPTL buildTimo Teräs2010-08-281-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The combination of commit aab4df0fb51660300559f5f29290709db2f7bfee resolv.c: add support for per thread res_state commit cca45baf8353d1e338d232f5bdb2d1d6b357f1da /etc/resolv.conf: support "timeout:n" and "attempts:n" options .. and NPTL results in broken resolver in very annoying ways. Now, it seems that most of the uclibc code does not work well if res_state is TLS variable. Technically, this is the correct thing to do since this gives proper per-thread resolving behavior, and it also makes the config options overridable per thread. This probably what apps expect as glibc does it too. But alas, most places use _res to sync up static global variables which results in breakage. It gets more or less randomly selected which threads options get applied. Also in case of multiple servers it looks like the retry logic is shared between all threads, e.g. two concurrent resolutions can make other resolvers skip nameservers due to shared "last_ns_num". And finally the timeout/attempts commit breaks the accumulated stuff horribly. What happens is: 1. multithreaded application startups, initializes resolver, resolves things just fine 2. resolv.conf gets changed, application calls res_init after res_init uclibc will call res_sync on all resolver functions to refresh globals from the TLS variable _res 3. res_init was called only in one thread, so other thread's _res contains all zeroes (yes, this is correct app usage: res_init should be called only from one thread) 4. threads not calling res_init get broken resolver due to timeout being set to zero Now, one proper solution would be to: 1. make __open_nameservers return the configuration options 2. pass the config options struct to res_sync_func so it can do the proper overrides from per-thread _res 3. remove the related globals and use locally config options from __open_nameservers But technically, the correct thing (as in glibc does this) is: - res_init increases global "res_init timestamp" - use _res (or pointer within there) for resolver retries etc. get proper per-thread behavior - resolvers functions call "maybe_init" which reinitialize the TLS'ed resolver state (e.g. reload resolv.conf) if their res_init timestamp is out dated As an immediate emergency kludge fix, the following might do: resolv: fix options handling for TLS _res If _res is in TLS (NPTL), it might not get initialized. Assume zeroes mean default values. Signed-off-by: Timo Teräs <timo.teras@iki.fi> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* resolv: simplify MAXALIAS handlingBernhard Reutner-Fischer2010-08-191-16/+7
| | | | Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
* resolver: switch to config parserBernhard Reutner-Fischer2010-08-051-136/+119
| | | | Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
* Immediately try next nameserver on recv() failureIngo van Lil2010-07-281-1/+3
| | | | | | | | | | | | If there is a problem communicating with a nameserver the __dns_lookup() function will not immediately advance to the next nameserver but instead continue waiting until the timeout expires. This will cause a 30 second delay even if no nameserver is configured in resolv.conf and no DNS is running on localhost. Signed-off-by: Ingo van Lil <inguin@gmx.de> Acked-by: Roman I Khimov <khimov@altell.ru> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
* resolv: various memory corruption and off by one fixesTimo Teras2010-05-071-4/+8
| | | | | | | Fixes resolution of names with AAAA entries and gethostbyaddr issues. Signed-off-by: Timo Teras <timo.teras@iki.fi> Signed-off-by: Austin Foxley <austinf@cetoncorp.com>
* resolv: tentatively fix usage of uninitialized DNS parametersDenys Vlasenko2010-04-091-4/+2
| | | | | | | See "Possible regression from timeout commit for resolv.conf" thread. Also remove superfluous NULL check. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Fix use-after-free bug in __dns_lookupGabor Juhos2010-04-061-3/+1
| | | | | | | | | | | If the type of the first answer does not match with the requested type, then the dotted name was freed. If there are no further answers in the DNS reply, this pointer was used later on in the same function. Additionally it is passed to the caller, and caused strange behaviour. Signed-off-by: Gabor Juhos <juhosg@openwrt.org> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
* resolv: DEBUG-print nameserver we talk toBernhard Reutner-Fischer2010-03-301-2/+18
| | | | Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
* /etc/resolv.conf: support "timeout:n" and "attempts:n" optionsDenys Vlasenko2010-02-031-13/+41
| | | | | | | | | | | | | | text data bss dec hex filename - 1745 2 4 1751 6d7 libc/inet/dnslookup.o + 1760 2 4 1766 6e6 libc/inet/dnslookup.o - 962 0 4 966 3c6 libc/inet/opennameservers.o + 1099 0 4 1103 44f libc/inet/opennameservers.o - 462 4 472 938 3aa libc/inet/res_init.o + 454 4 468 926 39e libc/inet/res_init.o - 870 0 0 870 366 libc/inet/res_query.o + 867 0 0 867 363 libc/inet/res_query.o Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* errno: hide __libc_resp, __libc_errno, and __libc_h_errnoKhem Raj2010-02-011-1/+1
| | | | Signed-off-by: Khem Raj <raj.khem@gmail.com>
* libc/inet: mark other odd /etc/conf/ spotBernhard Reutner-Fischer2010-01-231-0/+2
| | | | | | and wrap it in FALLBACK_TO_CONFIG_RESOLVCONF too. -24b Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
* check stat("/etc/resolv.conf") for errorsDenys Vlasenko2009-10-141-1/+2
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* libc/inet/resolv.c: reread resolv.conf if its mtime was changedBernhard Reutner-Fischer2009-10-131-6/+9
| | | | | Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* link-time warning for obsolescent/removed network funcsBernhard Reutner-Fischer2009-10-081-0/+4
| | | | Signed-off-by: aldot <rep.dot.nop@gmail.com>
* resolv.c: add support for per thread res_stateAustin Foxley2009-09-261-3/+52
| | | | Signed-off-by: Austin Foxley <austinf@cetoncorp.com>
* libc/inet/resolv.c:Denis Vlasenko2009-04-181-276/+465
| | | | | | | | | | | | | | | | Collapse __length_dotted into __length_question (the sole user of it). Make __length_question and __decode_answer static, they are used only once by only one function. Delete __decode_question, it is unused. All in all, four less .o files in libc.a. Document what __dns_lookup returns (length of the packet). Propagate packet len into __decode_answer, __length_question, __decode_dotted and check that we do not use data past the end of the packet. Rename some variables/parameters to better names (len -> packet_len, data -> packet etc). Add mini-doc how DNS packets look like. Style cleanup.
* resolver:Denis Vlasenko2009-03-101-63/+7
| | | | | | | res_query: do not unconditionally set h_errno to TRY_AGAIN (closes bug 173). cleanups: s/__dn_expand/dn_expand/, remove superfluous dn_expand declaration, remove libc_hidden_proto junk
* - fix comment style to make it compile againBernhard Reutner-Fischer2009-02-131-27/+37
| | | | - add note about "/etc/config/" and the resolver code per se.
* resolv: fix testcase failureDenis Vlasenko2008-12-171-2/+2
| | | | | test/regex/tst-regex2.c: fix testcase to compile with just "gcc <file>.c"
* remove __libc_getdomainname alias. google says only we have it.Denis Vlasenko2008-12-101-6/+1
|
* resolver: make new name resolutions reread /etc/resolv.confDenis Vlasenko2008-12-061-219/+197
| | | | | | | | | | | | | | | | if 256+ seconds passed since last read; fix cases where we switch to next search domain instead of switching to new server optimize ip4/ip6 combined cases; rewrite for(;;) loops so that it's clearer what's going on; document buffer usage; add TODOs and FIXMEs (for one, gethostbyname2 does not fill ->h_aliases field in the result AT ALL, and is iffy in general) text data bss dec hex filename - 245898 1403 11904 259205 3f485 libuClibc-0.9.30-svn.so + 245785 1403 11904 259092 3f414 libuClibc-0.9.30-svn.so
* random: use smaller data fields where appropriateDenis Vlasenko2008-12-011-0/+1
| | | | | | | | | text data bss dec hex filename - 130 156 0 286 11e libc/stdlib/random.o + 130 148 0 278 116 libc/stdlib/random.o - 586 0 0 586 24a libc/stdlib/random_r.o + 570 0 0 570 23a libc/stdlib/random_r.o
* gethostbyname can use gethostbyname2, saving one nearly 0.5k static bufferDenis Vlasenko2008-12-011-15/+20
| | | | | | | text data bss dec hex filename - 45 0 480 525 20d libc/inet/gethostbyname.o + 18 0 0 18 12 libc/inet/gethostbyname.o
* Last portion of libc_hidden_proto removal.Denis Vlasenko2008-11-201-28/+29
| | | | | Appears to build fine (several .configs tried)
* next portion of libc_hidden_proto removalDenis Vlasenko2008-11-201-6/+6
|
* libc_hidden_proto removal, a few more functionsDenis Vlasenko2008-11-181-4/+4
|
* libc_hidden_proto removal, just a few functionsDenis Vlasenko2008-11-181-1/+1
|
* resolver: use timeout of 5 (glibc uses that).Denis Vlasenko2008-11-171-10/+7
| | | | | delete some duplication in constants.
* resolver: separate gethostent and gethostent_r into two .o files;Denis Vlasenko2008-11-171-131/+134
| | | | | delete two stray files which compile to nothing
* resolver: move large code blocks to arrange related functions closer.Denis Vlasenko2008-11-171-510/+489
| | | | | almost no code changes
* resolver: fix some previous TODOs, add new ones.Denis Vlasenko2008-11-171-179/+198
|
* resolver: improved support for overriding DNS server addressesDenis Vlasenko2008-11-161-48/+114
| | | | | in _res structure. Used by busybox's nslookup.
* resolver: make getaddrinfo actually respect _res.nsaddr_list;Denis Vlasenko2008-11-161-202/+335
| | | | | | add largish comment explaining what we are doing, and why; fixes to make IPv6-only resolver possible
* resolver: more locking fixes.Denis Vlasenko2008-11-151-108/+138
|
* fixing resolver part 3: fix completely bogus lockingDenis Vlasenko2008-11-141-304/+311
| | | | | in __dns_lookup.
* fixing resolver part 2: make _res structure membersDenis Vlasenko2008-11-141-11/+17
| | | | | configurable. we don't use most of it anyway.
* fixing resolver, part 1Denis Vlasenko2008-11-141-90/+136
|
* resolver: reinstate searching if search domains accidentally nukedDenis Vlasenko2008-11-021-4/+15
| | | | | in one of recent commits :)
* __dns_lookup: document and optimize a bitDenis Vlasenko2008-11-011-33/+45
| | | | | | | text data bss dec hex filename - 1545 2 4 1551 60f libc/inet/dnslookup.o + 1528 2 4 1534 5fe libc/inet/dnslookup.o
* resolver: partially fix bug 660 -Denis Vlasenko2008-11-011-21/+42
| | | | | do not treat negative response as error
* resolver: fix part of bug 1468:Denis Vlasenko2008-11-011-7/+20
| | | | | "gethostbyname() fails if DNS server returns more than 23 addresses"
* resolver: trivial code trasformations for readability.Denis Vlasenko2008-11-011-89/+96
| | | | | No logic changes. Code size is the same too.
* trivial code shrink by making some strings staticDenis Vlasenko2008-11-011-2/+4
| | | | | | | | | text data bss dec hex filename - 259 0 0 259 103 libc/inet/herror.o + 243 0 0 243 f3 libc/inet/herror.o - 720 0 0 720 2d0 libc/inet/ns_name.o + 710 0 0 710 2c6 libc/inet/ns_name.o
* make getaddrinfo to NOT query DNS for IPv6 address if host is inDenis Vlasenko2008-10-281-17/+31
| | | | | | | | | | | /etc/hosts and it has IPv4 address there. The most common example is "127.0.0.1 localhost". We don't want "ping localhost" to stall and time out on IPv6 queries to, say, inaccessible DNS server, right? - 655 0 0 655 28f libc/inet/gethostbyname2_r.o + 685 0 0 685 2ad libc/inet/gethostbyname2_r.o
* Revert revision 19343 and also remove libc_hidden_proto for __uc_malloc.Bernd Schmidt2008-06-121-34/+16
| | | | | For now, a straight revert; we can decide later wheter we want to do something more.
* Remove superfluous attribute_hidden from functionDenis Vlasenko2008-06-061-1/+1
| | | | | | | | | | | definition. I seems to produce spurious warning: libc/inet/resolv.c:1549: warning: 'visibility' attribute ignored on non-class types (seems like gcc bug) and it is not really needed - attribute_hidden was already specified in function _declaration_ so it is not necessary here. No code changes (verified with objdump).
* Use more natural way to return a value in __read_etc_hosts_r:Denis Vlasenko2008-06-061-24/+21
| | | | | | | | | | | text data bss dec hex filename - 230 0 9 239 ef libc/inet/gethostent.o + 224 0 9 233 e9 libc/inet/gethostent.o - 782 0 0 782 30e libc/inet/read_etc_hosts_r.o + 767 0 0 767 2ff libc/inet/read_etc_hosts_r.o Run tested.
* Fix failure in test/inet/gethost_r-align:Denis Vlasenko2008-06-061-4/+8
| | | | | | | | | | | | we were closing a FILE, but did not record that fact by setting a variable to NULL, and then we used it for reading! While at it, small reduction in bss. Run tested. text data bss dec hex filename - 210 0 12 222 de libc/inet/gethostent.o + 230 0 9 239 ef libc/inet/gethostent.o
* This fixes a problem with the move of libc_hidden_proto to string.h.Bernd Schmidt2008-06-041-1/+0
| | | | | | | | | | | | | The obsolete functions bcopy, index, etc. are not supposed to be used within uClibc itself. Hence, there is no libc_hidden_def for them, but the previous patch did not just move libc_hidden_protos, it also added new ones for the legacy functions. As a result, programs which use these functions can no longer link with uClibc. This fixes it by removing the unnecessary libc_hidden_protos. I've also removed all inclusions of <strings.h> from uClibc source files: since we define _GNU_SOURCE, it is sufficient to include <string.h>. We then do not need to duplicate the libc_hidden_proto block in <strings.h>.