summaryrefslogtreecommitdiff
path: root/libc/inet/resolv.c
AgeCommit message (Collapse)Author
2016-12-30inet: fix getnameinfo problem found by new test casesWaldemar Brodkorb
Follow documented behaviour: http://man7.org/linux/man-pages/man3/getnameinfo.3.html Sync with GNU libc behaviour.
2016-12-30remove inline changelog, we have gitWaldemar Brodkorb
2016-06-24inet/resolv: Try search domains first for unqualified namesIngo van Lil
When resolving an unqualified host name, the resolver tries the original name first before appending the domains from the search list. If a TLD with the same name exists, the query will succeed (but yield no A record) and the resolver will return HOST_NOT_FOUND without trying the search domains. This patch changes the lookup order for unqualified host names (without dots) to try the search domains first and the original name last. Signed-off-by: Ingo van Lil <inguin@gmx.de>
2016-06-01remove MJN only debug messagesWaldemar Brodkorb
2016-03-10DNS: Don't apply search domains to PTR lookupsTim Hockin
This lessens the load on upstream DNS servers (and it was just nonsensical). Signed-off-by: Tim Hockin <thockin@google.com>
2016-03-10DNS: don't count search-path miss as a retryTim Hockin
Currently a miss on a search-path entry is counted as a retry. This means that users with more than (num_nameservers * retries) entries in their search path list fail before trying all search paths. Concretely, a single nameserver with 4 search paths will never try the 4th search because the default retry is 3. The code doesn't currently retry a given nameserver in case of an error, so retries is sort of meaningless (though there are some comments indicating it might come). This change only treats total failure of a nameserver (try next server) as a retry. Signed-off-by: Tim Hockin <thockin@google.com>
2016-02-24Replace /etc/resolv.conf with _PATH_RESCONF to allow portability of the code ↵Ubaldo Porcheddu
on system where resolv.conf is not in /etc . Signed-off-by: Ubaldo Porcheddu <ubaldo@eja.it>
2016-01-31Make sure to always terminate decoded stringWaldemar Brodkorb
Write a terminating '\0' to dest when the first byte of the encoded data is 0. This corner case was previously missed. Signed-off-by: Daniel Fahlgren <daniel@fahlgren.se> Signed-off-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
2016-01-31Do not follow compressed items forever.Waldemar Brodkorb
It is possible to get stuck in an infinite loop when receiving a specially crafted DNS reply. Exit the loop after a number of iteration and consider the packet invalid. Signed-off-by: Daniel Fahlgren <daniel@fahlgren.se> Signed-off-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
2016-01-02libc/inet: Unbreak gethostent()Waldemar Brodkorb
Although gethostent() is obsoleted, there is no reason to keep it broken. Fix two problems: * commit f65e66078b "resolver: switch to config parser" leave an extra break statement in case of GETHOSTENT in __read_etc_hosts_r. In result, output buffer wasn't initialized at all. * gethostent static buffer has insufficient size to store aliases, so __read_etc_hosts_r always returns ERANGE. Restore ALIAS_DIM define. Add test-case. Signed-off-by: Leonid Lisovskiy <lly.dev@gmail.com>
2016-01-02Use dynamic buffers for gethostent/gethostbyname/gethostbyaddrWaldemar Brodkorb
Save ~1k static space (.bss) text data bss dec hex filename - 68 0 126 194 c2 libc/inet/gethostent.os - 79 0 460 539 21b libc/inet/gethostbyname2.os - 83 0 460 543 21f libc/inet/gethostbyaddr.os + 98 0 24 122 7a libc/inet/gethostent.os + 110 0 24 134 86 libc/inet/gethostbyname2.os + 113 0 24 137 89 libc/inet/gethostbyaddr.os ================================================================== +91 -974 Signed-off-by: Leonid Lisovskiy <lly.dev@gmail.com>
2015-12-22resolv: fix gethostbyname2_r to match gethostbyname_r, fixing bugs with AAAA ↵Waldemar Brodkorb
lookups The latter half of gethostbyname2_r (doing AAAA queries) is rather dramatically different from the corresponding portion of gethostbyname_r (doing A queries). This leads to problems like calls to getaddrinfo only returning one IPv6 address, even when multiple exist. Seems to be entirely a case of divergent evolution -- a half-decade of fixes for the IPv4 code but no love for IPv6. Until now. ;) DNS behaviour for IPv6 is really no different than for IPv4 -- beyond the difference in address sizes, there's no need for the functions to be so different. Consequently, this patch really is almost just a cut-and-paste of gethostbyname_r, with the appropriate substitutions of in6_addr, AF_INET6, etc; while holding on to the few extra bits that actually belong in there (eg #ifdef __UCLIBC_HAS_IPV6__). Signed-off-by: Wes Campaigne <westacular@gmail.com>
2015-12-22inet/resolv: Fix broken h_aliases list terminator after 2dab3f5Waldemar Brodkorb
Commit 2dab3f5a "resolv: tiny shrinkage in /etc/hosts handling" leads to that read_etc_hosts_r() provide garbage pointer at the end of h_aliases list if more than four hostnames follow a dotted quad in /etc/hosts Test-case: Add following line to /etc/hosts 63.63.0.2 host1 alias2 alias3 alias4 alias5 #include <stdio.h> #include <errno.h> #include <netdb.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> int main (void) { int i; char *a; struct hostent *he; struct in_addr ipv4addr; inet_pton(AF_INET, "63.63.0.2", &ipv4addr); he = gethostbyaddr(&ipv4addr, sizeof ipv4addr, AF_INET); if (he == NULL) exit(1); printf("Host name: '%s'\n", he->h_name); i = 0; while ((a = he->h_aliases[i]) != NULL) { printf("Host alias: '%s'\n", a); ++i; } return 0; } Wrong output: Host name: 'host1' Host alias: 'alias2' Host alias: 'alias3' Host alias: 'alias4' Host alias: 'alias5' Host alias: '??' Signed-off-by: Leonid Lisovskiy <lly.dev@gmail.com> Signed-off-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
2015-12-17resolv: __dns_lookup - immediately switch to next server in case of poll() ↵Waldemar Brodkorb
set error events https://bugs.busybox.net/show_bug.cgi?id=3211 Signed-off-by: Leonid Lisovskiy <lly.dev@gmail.com> Signed-off-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
2015-04-12remove link warningsWaldemar Brodkorb
As recently discussed on the pgsql mailinglist, this warnings are more or less useless and some configure scripts are failing when these warnings are enabled. http://www.postgresql.org/message-id/20150320132351.GS3636@alvh.no-ip.org
2015-03-16resolv: fix unaligned tmp buffer corner-caseAlexey Brodkin
On execution of "inet/gethost_r-align" test I noticed failure due to unaligned access (instaed of 4-byte aligned 1-byte aligned address was attempted to be accessed). Further investigation confirmed this nice and helpful test failure. Following commit removed usage of ALIGN_BUFFER_OFFSET on entry to __read_etc_hosts_r(): http://git.uclibc.org/uClibc/commit/?id=f65e66078b9f4d2d7f0fc336dee36e78fc467c0f So indeed if target architecture doesn't allow unaligned access and provided tmp buffer is not word aligned (and we will deal with pointers which means word-sized data units), then CPU will fail during execution. In case of ARC we'll see "Unaligned access" exception like this: --->8--- # potentially unexpected fatal signal 7. Path: /root/uClibc/test/inet/gethost_r-align CPU: 0 PID: 5514 Comm: gethost_r-align Not tainted 3.13.11 #2 task: 8f42a580 ti: 8f40e000 task.ti: 8f40e000 [ECR ]: 0x00230400 => Misaligned r/w from 0x5fdab341 [EFA ]: 0x5fdab341 [BLINK ]: 0x20032a18 [ERET ]: 0x20032a3c @off 0x12a3c in [/lib/libuClibc-0.9.34-git.so] VMA: 0x20020000 to 0x20062000 [STAT32]: 0x00000086 : U E2 E1 BTA: 0x20046014 SP: 0x5fdab260 FP: 0x00000000 LPS: 0x20046064 LPE: 0x20046068 LPC: 0x00000000 r00: 0x5fdab341 r01: 0x00000005 r02: 0x00000015 r03: 0x00000000 r04: 0x5fdab358 r05: 0x00000000 r06: 0x0a0a0a00 r07: 0x00000000 r08: 0x0000003f r09: 0x20067050 r10: 0x00000000 r11: 0x00000014 r12: 0x00000001 r13: 0x00000000 r14: 0x20060660 r15: 0x20060661 r16: 0x00000006 r17: 0x5fdab371 r18: 0x00000018 r19: 0x5fdab2b4 r20: 0x00020000 r21: 0x00000000 r22: 0x00029068 r23: 0x5fdab371 r24: 0x00010000 r25: 0x00000000 --->8--- To fix this problem we'll re-introduce tmp buffer force alignment before config parser invocation. Signed-off-by: Alexey Brodkin <Alexey.Brodkin@synopsys.com> Cc: Vineet Gupta <vgupta@synopsys.com> Cc: Waldemar Brodkorb <wbx@openadk.org> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2014-04-23resolv: try next server on SERVFAILMichel Stam
Commit e1420eca7374cd8f583e9d774c890645a205aaee fixed a bug where a response code should mean the next server is tried. However, it tries only the next search domain, and never skips to the next server. This fix makes sure we try the next server on SERVFAIL. Signed-off-by: Michel Stam <michel@reverze.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2013-12-20inet: Fix threaded res_initKenneth Soerensen
In a multi-threaded application where res_init() was called either directly or implicitly, getaddrinfo() and others failed to add the DNS search domain to hostnames. This problem made it not possible to look up a hostname without its domain appended. The problem is caused by res_sync_func() overwriting the configuration read by __open_nameservers() immediately after it is read. The suggested solutin is to disable res_sync_func() while reading name server configuration in res_init(). Signed-off-by: Kenneth Soerensen <kenneth.sorensen@spectralink.com> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2013-11-12Make res_init() thread safe.Kenneth Soerensen
res_init() was not atomic, which could give undesired behaviour. Now res_init() is completely locked under one lock and the locking is removed from __res_vinit(). Signed-off-by: Kenneth Soerensen <kenneth.sorensen@spectralink.com> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2013-11-12Fix threaded use of res_ functions.Sørensen, Kenneth
Commit aab4df0fb51660300559f5f29290709db2f7bfee says that the line with after res_init() function. Commit 7f74de5d4d6d10baafab4b37bb3d472f5c5f0e8c moves the res_init() function below the line with #undef _res. This commit moves res_init() back above #undef _res. Signed-off-by: Kenneth Soerensen <kenneth.sorensen@spectralink.com> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2013-07-19inet: fix unsafe access to _res.options in res_mkquery()Vanya Sergeev
res_mkquery() takes out __resolv_lock to copy _res.options to function local _res_options on line 4204, but later unsafely accesses _res.options without a lock, instead of its local copy _res_options, on line 4221. Looks like a period / underscore typo. Signed-off-by: Vanya Sergeev <vsergeev@gmail.com> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2013-03-29inet: fix getting the nameserver from _res state after res_init.Felix Fietkau
Fixes displaying the nameserver in busybox nslookup. Signed-off-by: Felix Fietkau <nbd@openwrt.org> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2013-03-20inet: do not filter responses in res_queryTimo Teräs
Fixes bug #5342 res_query was silently rejecting responses against T_ANY DNS questions. Remove the type-filtering from res_query altogether. __dns_lookup is supposed to return the proper stuff that you asked for (and only that). Signed-off-by: Timo Teräs <timo.teras@iki.fi> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2013-03-20inet: Fix LT{.old,} compilation due to res_icloseBernhard Reutner-Fischer
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2013-03-14inet: res_nclose: free user-buffer, not global _resBernhard Reutner-Fischer
In res_iclose we were operating on the global _res even if called via res_nclose where we are supposed to operate on the user provided res_state. Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2013-02-20inet: remove noreturn attribute from res_ncloseBernhard Reutner-Fischer
Partially revert e9af4dfbd328e9f3bba235fdb2d1027dd2dbbcde Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-08-04libc/inet/resolv.c: Use IE model for TLS data.Will Newton
All other TLS data in uClibc is explicitly using the IE model, so use it for __resp too. This generates smaller and faster code. Signed-off-by: Will Newton <will.newton@imgtec.com> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-08-04libc/inet/resolv.c: Remove obsolete comment.Will Newton
The definition of __resp has been hidden for some years (commit 22de495d). Remove the comment suggesting that it is not. Signed-off-by: Will Newton <will.newton@imgtec.com> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15resolv.c: shrink code a bit in getnameinfo.Peter S. Mazinger
Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15fix a bunch of build warningsPeter S. Mazinger
Added attribute_noreturn even if it has return at the end of function Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15resolv.c,time.c,_atexit.c: hide 3 locksPeter S. Mazinger
Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15resolv.c: include param.h and use MIN instead of minPeter S. Mazinger
Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15resolv.c: remove duplicated attribute_hiddenPeter S. Mazinger
while there add one for future (currently in unused code) Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15remove __FORCE_GLIBCPeter S. Mazinger
Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-04-17resolv: tiny shrinkage in /etc/hosts handlingBernhard Reutner-Fischer
-4b Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-04-17resolv: remove unused variablesBernhard Reutner-Fischer
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-04-17resolv: Fix /etc/hosts for more than MAXALIASES aliasesBernhard Reutner-Fischer
PR networking/4916 Reserve space for the terminating 0 alias and zero out the scratch-buffer so the last entry of the alias list is empty. Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2011-11-27make ARRAY_SIZE commonly available internallyMike Frysinger
Some places have opencoded the ARRAY_SIZE macro, so move it to a global internal location so other places can leverage it. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2011-11-17resolv: hide relocationsBernhard Reutner-Fischer
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2011-10-21resolv: fix memory leakBernhard Reutner-Fischer
Timothy Holdener writes: small memory leak in __dns_lookup() when the A record in the DNS answer is preceded by one or more CNAME records. Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2011-10-20resolv: commentary typo fixBernhard Reutner-Fischer
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2011-10-20gethostbyname_r: set correct h_errno upon failureBernhard Reutner-Fischer
previously gethostbyname_r(ipv6.google.com);herror("ERROR:") gave Answer name = |ipv6.google.com| Answer type = |5| herrno=1 h_errno=0 ERROR:: Error 0 herrno=1 h_errno=1 ERROR:: Unknown host Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2011-10-20resolv: fix compilationBernhard Reutner-Fischer
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2011-09-10resolv: simple optimizations and style/readability fixesDenys Vlasenko
text data bss dec hex filename - 2915 0 0 2915 b63 libc/inet/ns_name_old.o + 2656 0 0 2656 a60 libc/inet/ns_name.o - 958 0 0 958 3be libc/inet/ns_parse_old.o + 898 0 0 898 382 libc/inet/ns_parse.o Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-08-26inet/resolv: add res_ninit and res_ncloseDaniel Mack
Some reordering of existing functions was necessary in order to provide this functionality. Signed-off-by: Daniel Mack <zonque@gmail.com>
2011-08-26inet/resolv: add res_mkqueryDaniel Mack
Signed-off-by: Daniel Mack <zonque@gmail.com>
2011-08-26inet/resolv: add ns_initparse, ns_parserr, ns_skiprr and ns_msg_getflagDaniel Mack
There are build 'ifdef L_ns_parse'. Signed-off-by: Daniel Mack <zonque@gmail.com>
2011-08-26inet/resolv: add dn_skipname and ns_name_skipDaniel Mack
One uses the other, so add them in one go. Signed-off-by: Daniel Mack <zonque@gmail.com>
2011-08-26inet/resolv: Add dn_compDaniel Mack
Signed-off-by: Daniel Mack <zonque@gmail.com>
2011-08-26inet/resolv: add ns_name_pton, ns_name_pack and ns_name_compressDaniel Mack
These are built '#ifdef L_ns_name' Signed-off-by: Daniel Mack <zonque@gmail.com>