summaryrefslogtreecommitdiff
path: root/lib/hostip.c
Commit message (Collapse)AuthorAgeFilesLines
* hostip: include easy_lock.h before using GLOBAL_INIT_IS_THREADSAFEDaniel Stenberg2023-05-171-6/+4
| | | | | | | | | | Since that header file is the only place that define can be defined. Reported-by: Marc Deslauriers Follow-up to 13718030ad4b3209 Closes #11121
* hostip: use time_t for storing oldest DNS entryDaniel Stenberg2023-05-091-6/+10
| | | | | | | | | | Theoretically, the oldest time could overflow an int. In practice that won't happen, but let's do this to please analyzers. Follow-up to 9ed7d56e044f5aa1b2928ccde6245d0 Pointed out by Coverity. Closes #11094
* hostip: enforce a maximum DNS cache size independent of timeout valueDaniel Stenberg2023-05-081-11/+32
| | | | | | | | | | To reduce the damage an application can cause if using -1 or other ridiculous timeout values and letting the cache live long times. The maximum number of entries in the DNS cache is now totally arbitrarily and hard-coded set to 29999. Closes #11084
* hostip: store dns timeout as 'int'Daniel Stenberg2023-05-081-2/+2
| | | | | ... because it set and held as an 'int' elsewhere and can never be larger.
* hostip: add locks around use of global buffer for alarm()Harry Sintonen2023-04-261-4/+15
| | | | | | | When building with the sync name resolver and timeout ability we now require thread-safety to be present to enable it. Closes #11030
* hostip: refuse to resolve the .onion TLDMatt Jolly2023-03-301-0/+8
| | | | | | | | | | | | | | | | | RFC 7686 states that: > Applications that do not implement the Tor > protocol SHOULD generate an error upon the use of .onion and > SHOULD NOT perform a DNS lookup. Let's do that. https://www.rfc-editor.org/rfc/rfc7686#section-2 Add test 1471 and 1472 to verify Fixes #543 Closes #10705
* hostip: avoid sscanf and extra buffer copiesDaniel Stenberg2023-02-271-41/+50
| | | | | | Also made create_hostcache_id() return the id length. Closes #10601
* copyright: update all copyright lines and remove year rangesDaniel Stenberg2023-01-031-1/+1
| | | | | | | | | | | | - they are mostly pointless in all major jurisdictions - many big corporations and projects already don't use them - saves us from pointless churn - git keeps history for us - the year range is kept in COPYING checksrc is updated to allow non-year using copyright statements Closes #10205
* tidy-up: process.h detection and useViktor Szakats2022-11-011-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch aims to cleanup the use of `process.h` header and the macro `HAVE_PROCESS_H` associated with it. - `process.h` is always available on Windows. In curl, it is required only for `_beginthreadex()` in `lib/curl_threads.c`. - `process.h` is also available in MS-DOS. In curl, its only use was in `lib/smb.c` for `getpid()`. But `getpid()` is in fact declared by `unistd.h`, which is always enabled via `lib/config-dos.h`. So the header is not necessary. - `HAVE_PROCESS_H` was detected by CMake, forced to 1 on Windows and left to real detection for other platforms. It was also set to always-on in `lib/config-win32.h` and `lib/config-dos.h`. In autotools builds, there was no detection and the macro was never set. Based on these observations, in this patch we: - Rework Windows `getpid` logic in `lib/smb.c` to always use the equivalent direct Win32 API function `GetCurrentProcessId()`, as we already did for Windows UWP apps. This makes `process.h` unnecessary here on Windows. - Stop #including `process.h` into files where it was not necessary. This is everywhere, except `lib/curl_threads.c`. > Strangely enough, `lib/curl_threads.c` compiled fine with autotools > because `process.h` is also indirecty included via `unistd.h`. This > might have been broken in autotools MSVC builds, where the latter > header is missing. - Delete all remaining `HAVE_PROCESS_H` feature guards, for they were unnecessary. - Delete `HAVE_PROCESS_H` detection from CMake and predefined values from `lib/config-*.h` headers. Reviewed-by: Jay Satiro Closes #9703
* hostip: guard PF_INET6 useViktor Szakats2022-10-181-0/+2
| | | | | | | | | | | | | | | | | | Some platforms (e.g. Amiga OS) do not have `PF_INET6`. Adjust the code for these. ``` hostip.c: In function 'fetch_addr': hostip.c:308:12: error: 'PF_INET6' undeclared (first use in this function) pf = PF_INET6; ^~~~~~~~ ``` Regression from 1902e8fc511078fb5e26fc2b907b4cce77e1240d Reviewed-by: Daniel Stenberg Closes #9760
* hostip: lazily wait to figure out if IPv6 works until neededDaniel Stenberg2022-09-221-1/+5
| | | | | | | | The check may take many milliseconds, so now it is performed once the value is first needed. Also, this change makes sure that the value is not used if the resolve is set to be IPv4-only. Closes #9553
* resolve: make forced IPv4 resolve only use A queriesDmitry Karpov2022-09-201-0/+23
| | | | | | | | This protects IPv4-only transfers from undesired bad IPv6-related side effects and make IPv4 transfers in dual-stack libcurl behave the same way as in IPv4 single-stack libcurl. Closes #9540
* ctype: remove all use of <ctype.h>, use our own versionsDaniel Stenberg2022-09-061-1/+1
| | | | | | Except in the test servers. Closes #9433
* misc: spelling fixesViktor Szakats2022-08-311-1/+1
| | | | | | | | | Found using codespell 2.2.1. Also delete the redundant protocol designator from an archive.org URL. Reviewed-by: Daniel Stenberg Closes #9403
* multi: use larger dns hash table for multi interfaceDaniel Stenberg2022-08-291-2/+2
| | | | | | | | | | | | Have curl_multi_init() use a much larger DNS hash table than used for the easy interface to scale and perform better when used with _many_ host names. curl_share_init() sets an in-between size. Inspired-by: Ivan Tsybulin See #9340 Closes #9376
* hostip: resolve *.localhost to 127.0.0.1/::1Daniel Stenberg2022-08-111-12/+24
| | | | | | | | | | | Following the footsteps of other clients like Firefox/Chrome. RFC 6761 says clients SHOULD do this. Add test 389 to verify. Reported-by: TheKnarf on github Fixes #9192 Closes #9296
* copyright: make repository REUSE compliantmax.mehl2022-06-131-0/+2
| | | | | | | | | | | Add licensing and copyright information for all files in this repository. This either happens in the file itself as a comment header or in the file `.reuse/dep5`. This commit also adds a Github workflow to check pull requests and adapts copyright.pl to the changes. Closes #8869
* conn: fix typo 'connnection' -> 'connection' in two function namesAdam Rosenfield2022-04-271-1/+1
| | | | Closes #8759
* lib: remove exclamation marksDaniel Stenberg2022-04-161-5/+5
| | | | | | ... from infof() and failf() calls. Make them less attention seeking. Closes #8713
* hostip: avoid unused parameter error in Curl_resolv_checkStewart Gebbie2022-02-241-1/+2
| | | | | | | | | | | | | | When built without DNS-over-HTTP and without asynchronous resolvers, neither the dns nor the data parameters are used. That is Curl_resolv_check appears to call Curl_resolver_is_resolved(data, dns). But, with CURL_DISABLE_DOH without CURLRES_ASYNCH, the call is actually elided via a macro definition. This fix resolves the resultant: "unused parameter 'data'" error. Closes #8505
* misc: remove unused doh flags when CURL_DISABLE_DOH is definedMAntoniak2021-12-151-1/+16
| | | | Closes #8148
* hash: lazy-alloc the table in Curl_hash_add()bagder/hash-lazyallocDaniel Stenberg2021-12-101-4/+4
| | | | | | This makes Curl_hash_init() infallible which saves error paths. Closes #8132
* hostip: Move allocation to clarify there is no memleakRikard Falkeborn2021-09-301-3/+3
| | | | | | | | | | By just glancing at the code, it looks like there is a memleak if the call to Curl_inet_pton() fails. Looking closer, it is clear that the call to Curl_inet_pton() can not fail, so the code will never leak memory. However, we can make this obvious by moving the allocation after the if-statement. Closes https://github.com/curl/curl/pull/7796
* strerror.h: remove the #include from files not using itDaniel Stenberg2021-09-091-1/+0
|
* hostip: Make Curl_ipv6works function independent of getaddrinfoJay Satiro2021-08-101-3/+35
| | | | | | | | | | | | | | | | | | | | | - Do not assume IPv6 is not working when getaddrinfo is not present. The check to see if IPv6 actually works is now independent of whether there is any resolver that can potentially resolve a hostname to IPv6. Prior to this change if getaddrinfo() was not found at compile time then Curl_ipv6works() would be defined as a macro that returns FALSE. When getaddrinfo is not found then libcurl is built with CURLRES_IPV4 defined instead of CURLRES_IPV6, meaning that it cannot do IPv6 lookups in the traditional way. With this commit if libcurl is built with IPv6 support (ENABLE_IPV6) but without getaddrinfo (CURLRES_IPV6), and the IPv6 stack is actually working, then it is possible for libcurl to resolve IPv6 addresses by using DoH. Ref: https://github.com/curl/curl/issues/7483#issuecomment-890765378 Closes https://github.com/curl/curl/pull/7529
* cleanup: spell DoH with a lowercase oJosh Soref2021-07-161-1/+1
| | | | | | Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> Closes #7413
* infof: remove newline from format strings, always append itDaniel Stenberg2021-07-071-9/+9
| | | | | | | | | | | | | | | | - the data needs to be "line-based" anyway since it's also passed to the debug callback/application - it makes infof() work like failf() and consistency is good - there's an assert that triggers on newlines in the format string - Also removes a few instances of "..." - Removes the code that would append "..." to the end of the data *iff* it was truncated in infof() Closes #7357
* hostip: (macOS) free returned memory of SCDynamicStoreCopyProxiesGregory Muchka2021-06-211-11/+14
| | | | | | | | | | | | | | From Apples documentation on SCDynamicStoreCopyProxies, "Return Value: A dictionary of key-value pairs that represent the current internet proxy settings, or NULL if no proxy settings have been defined or if an error occurred. You must release the returned value." Failure to release the returned value of SCDynamicStoreCopyProxies can result in a memory leak. Source: https://developer.apple.com/documentation/systemconfiguration/1517088-scdynamicstorecopyproxies Closes #7265
* hostip: bad CURLOPT_RESOLVE syntax now returns errorAlexis Vachette2021-06-031-2/+2
| | | | | | Added test 3019 Fixes #7170 Closes #7174
* hostip: fix 3 coverity complaintsDaniel Stenberg2021-06-011-3/+6
| | | | | | | | | | | | | | Follow-up to 1a0ebf6632f889eed - Check the return code to Curl_inet_pton() in two instances, even though we know the input is valid so the functions won't fail. - Clear the 'struct sockaddr_in' struct before use so that the 'sin_zero' field isn't left uninitialized. Detected by Coverity. Assisted-by: Harry Sintonen Closes #7163
* hostip: make 'localhost' return fixed valuesDaniel Stenberg2021-05-311-2/+73
| | | | | | | | | | | | Resolving the case insensitive host name 'localhost' now returns the addresses 127.0.0.1 and (if IPv6 is enabled) ::1 without using any resolver. This removes the risk that users accidentally resolves 'localhost' to something else. By making sure 'localhost' is always local, we can assume a "secure context" for such transfers (for cookies etc). Closes #7039
* hsts: ignore numberical IP address hostsDaniel Stenberg2021-05-301-0/+19
| | | | | | | | | Also, use a single function library-wide for detecting if a given hostname is a numerical IP address. Reported-by: Harry Sintonen Fixes #7146 Closes #7149
* hostip: fix broken macOS/CMake/GCC buildsRadek Zajic2021-05-261-1/+1
| | | | | | | Follow-up to 31f631a142d855f06 Fixes #7128 Closes #7129
* lib/hostip6.c: make NAT64 address synthesis on macOS workRadek Zajic2021-05-251-0/+17
| | | | Closes #7121
* hostip: remove the debug code for LocalHostDaniel Stenberg2021-05-111-11/+1
| | | | | | | | | | | | The Curl_resolv() had special code (when built in debug mode) for when resolving the host name "LocalHost" (using that exact casing). It would then get the host name from the --interface option instead. This development-only feature was not used by anything (anymore) and we have the --resolve feature if we want to play similar tricks properly going forward. Closes #7044
* configure: remove use of RETSIGTYPEMichael Forney2021-04-071-1/+1
| | | | | | | | | | | This was previously defined by the obsolete AC_TYPE_SIGNAL macro, which was removed in 2682e5f5. The deprecation text says > Your code may safely assume C89 semantics that RETSIGTYPE is void. So, remove it and just use void instead. Closes #6861
* hostip: Fix for builds that disable all asynchronous DNSJay Satiro2021-04-021-0/+2
| | | | | | | | | | | | | | | - Define Curl_resolver_error function only when USE_CURL_ASYNC. Prior to this change building curl without an asynchronous resolver backend (c-ares or threaded) and without DoH (DNS-over-HTTPS, which is also asynchronous but independent of resolver backend) would cause a build error since Curl_resolver_error is called by and evaluates variables only available in asynchronous builds. Reported-by: Benbuck Nason Fixes https://github.com/curl/curl/issues/6831 Closes https://github.com/curl/curl/pull/6832
* urldata: merge "struct DynamicStatic" into "struct UrlState"Daniel Stenberg2021-03-261-5/+5
| | | | | | | | Both were used for the same purposes and there was no logical separation between them. Combined, this also saves 16 bytes in less holes in my test build. Closes #6798
* asyn-ares: use consistent resolve error messageDaniel Stenberg2021-02-181-0/+29
| | | | | | | | | | | ... with the help of Curl_resolver_error() which now is moved from asyn-thead.c and is provided globally for this purpose. Follow-up to 35ca04ce1b77636 Makes test 1188 work for c-ares builds Closes #6626
* hostip: fix crash in sync resolver builds that use DOHJay Satiro2021-02-131-4/+4
| | | | | | | | | | | | | | | - Guard some Curl_async accesses with USE_CURL_ASYNC instead of !CURLRES_SYNCH. This is another follow-up to 8335c64 which moved the async struct from the connectdata struct into the Curl_easy struct. A previous follow-up 6cd167a fixed building for sync resolver by guarding some async struct accesses with !CURLRES_SYNCH. The problem is since DOH (DNS-over-HTTPS) is available as an asynchronous secondary resolver the async struct may be used even when libcurl is built for the sync resolver. That means that CURLRES_SYNCH and USE_CURL_ASYNC may be defined at the same time. Closes https://github.com/curl/curl/pull/6603
* hostip: fix build with sync resolverDaniel Stenberg2021-02-051-2/+10
| | | | | | | Reported-by: David Goerger Follow-up from 8335c6417 Fixes #6566 Closes #6568
* hostip/proxy: remove conn->data useDaniel Stenberg2021-01-261-2/+1
| | | | Closes #6513
* url: reduce conn->data referencesDaniel Stenberg2021-01-261-1/+1
| | | | | | ... there are a few left but let's keep them to last Closes #6512
* hostip: remove conn->data from resolver functionsDaniel Stenberg2021-01-221-34/+29
| | | | | | | This also moves the 'async' struct from the connectdata struct into the Curl_easy struct, which seems like a better home for it. Closes #6497
* lib: pass in 'struct Curl_easy *' to most functionsDaniel Stenberg2021-01-171-1/+1
| | | | | | | | | | | | | | | | | | | | | ... in most cases instead of 'struct connectdata *' but in some cases in addition to. - We mostly operate on transfers and not connections. - We need the transfer handle to log, store data and more. Everything in libcurl is driven by a transfer (the CURL * in the public API). - This work clarifies and separates the transfers from the connections better. - We should avoid "conn->data". Since individual connections can be used by many transfers when multiplexing, making sure that conn->data points to the current and correct transfer at all times is difficult and has been notoriously error-prone over the years. The goal is to ultimately remove the conn->data pointer for this reason. Closes #6425
* language: s/behaviour/behavior/gEmil Engler2021-01-021-2/+2
| | | | | | | | We currently use both spellings the british "behaviour" and the american "behavior". However "behavior" is more used in the project so I think it's worth dropping the british name. Closes #6395
* dns: extend CURLOPT_RESOLVE syntax for adding non-permanent entriesPaul Groke2020-12-291-12/+24
| | | | | | | | | | | | | | | | | | Extend the syntax of CURLOPT_RESOLVE strings: allow using a '+' prefix (similar to the existing '-' prefix for removing entries) to add DNS cache entries that will time out just like entries that are added by libcurl itself. Append " (non-permanent)" to info log message in case a non-permanent entry is added. Adjust relevant comments to reflect the new behavior. Adjust documentation. Extend unit1607 to test the new functionality. Closes #6294
* curl.se: new homeDaniel Stenberg2020-11-041-1/+1
| | | | Closes #6172
* hash: make it 'struct Curl_hash'Daniel Stenberg2020-09-021-3/+3
| | | | | | As internal global names should use captical C. Closes #5906
* hostip: fix the memory-leak introduced in 67d2802Daniel Stenberg2020-06-021-6/+15
| | | | | Fixes #5503 Closes #5504