Lines Matching +full:ipv4 +full:- +full:multi +full:- +full:target

21  * SPDX-License-Identifier: curl
71 /* alarm-based timeouts can only be used with all the dependencies satisfied */
83 * The main COMPILE-TIME DEFINES to keep in mind when reading the host*.c
86 * CURLRES_IPV6 - this host has getaddrinfo() and family, and thus we use
88 * take that into account. Hosts that are not IPv6-enabled have CURLRES_IPV4
91 * CURLRES_ARES - is defined if libcurl is built to use c-ares for
94 * CURLRES_THREADED - is defined if libcurl is built to run under (native)
96 * supported API will be the same as for ares-builds.
104 * hostip.c - method-independent resolver functions and utility functions
105 * hostasyn.c - functions for asynchronous name resolves
106 * hostsyn.c - functions for synchronous name resolves
107 * hostip4.c - IPv4 specific functions
108 * hostip6.c - IPv6 specific functions
111 * asyn-ares.c - functions for ares-using name resolves
112 * asyn-thread.c - functions for threaded name resolves
132 * If the conversion fails, the target buffer is empty.
140 switch(ai->ai_family) { in Curl_printable_address()
142 const struct sockaddr_in *sa4 = (const void *)ai->ai_addr; in Curl_printable_address()
143 const struct in_addr *ipaddr4 = &sa4->sin_addr; in Curl_printable_address()
144 (void)Curl_inet_ntop(ai->ai_family, (const void *)ipaddr4, buf, bufsize); in Curl_printable_address()
149 const struct sockaddr_in6 *sa6 = (const void *)ai->ai_addr; in Curl_printable_address()
150 const struct in6_addr *ipaddr6 = &sa6->sin6_addr; in Curl_printable_address()
151 (void)Curl_inet_ntop(ai->ai_family, (const void *)ipaddr6, buf, bufsize); in Curl_printable_address()
171 if(len > (buflen - 7)) in create_hostcache_id()
172 len = buflen - 7; in create_hostcache_id()
188 * Returning non-zero means remove the entry, return 0 to keep it in the
198 if(dns->timestamp) { in hostcache_entry_is_stale()
200 time_t age = prune->now - dns->timestamp; in hostcache_entry_is_stale()
201 if(age >= prune->max_age_sec) in hostcache_entry_is_stale()
203 if(age > prune->oldest) in hostcache_entry_is_stale()
204 prune->oldest = age; in hostcache_entry_is_stale()
231 * Library-wide function for pruning the DNS cache. This function takes and
237 /* the timeout may be set -1 (forever) */ in Curl_hostcache_prune()
238 int timeout = data->set.dns_cache_timeout; in Curl_hostcache_prune()
240 if(!data->dns.hostcache) in Curl_hostcache_prune()
244 if(data->share) in Curl_hostcache_prune()
251 time_t oldest = hostcache_prune(data->dns.hostcache, timeout, now); in Curl_hostcache_prune()
256 timeout = INT_MAX - 1; in Curl_hostcache_prune()
261 (Curl_hash_count(data->dns.hostcache) > MAX_DNS_CACHE_SIZE)); in Curl_hostcache_prune()
263 if(data->share) in Curl_hostcache_prune()
270 is not thread-safe stuff. */
288 dns = Curl_hash_pick(data->dns.hostcache, entry_id, entry_len + 1); in fetch_addr()
291 if(!dns && data->state.wildcard_resolve) { in fetch_addr()
295 dns = Curl_hash_pick(data->dns.hostcache, entry_id, entry_len + 1); in fetch_addr()
298 if(dns && (data->set.dns_cache_timeout != -1)) { in fetch_addr()
303 user.max_age_sec = data->set.dns_cache_timeout; in fetch_addr()
309 Curl_hash_delete(data->dns.hostcache, entry_id, entry_len + 1); in fetch_addr()
314 if(dns && data->conn->ip_version != CURL_IPRESOLVE_WHATEVER) { in fetch_addr()
317 struct Curl_addrinfo *addr = dns->addr; in fetch_addr()
320 if(data->conn->ip_version == CURL_IPRESOLVE_V6) in fetch_addr()
325 if(addr->ai_family == pf) { in fetch_addr()
329 addr = addr->ai_next; in fetch_addr()
335 Curl_hash_delete(data->dns.hostcache, entry_id, entry_len + 1); in fetch_addr()
362 if(data->share) in Curl_fetch_addr()
368 dns->refcount++; /* we use it! */ in Curl_fetch_addr()
370 if(data->share) in Curl_fetch_addr()
384 addr = addr->ai_next; in num_addresses()
394 * struct by re-linking its linked list.
423 nodes[i] = nodes[i-1]->ai_next; in Curl_shuffle_addr()
428 /* Fisher-Yates shuffle */ in Curl_shuffle_addr()
431 for(i = num_addrs - 1; i > 0; i--) { in Curl_shuffle_addr()
439 nodes[i-1]->ai_next = nodes[i]; in Curl_shuffle_addr()
442 nodes[num_addrs-1]->ai_next = NULL; in Curl_shuffle_addr()
482 if(data->set.dns_shuffle_addresses) { in Curl_cache_addr()
501 dns->refcount = 1; /* the cache has the first reference */ in Curl_cache_addr()
502 dns->addr = addr; /* this is the address(es) */ in Curl_cache_addr()
504 dns->timestamp = 0; /* an entry that never goes stale */ in Curl_cache_addr()
506 dns->timestamp = time(NULL); in Curl_cache_addr()
507 if(dns->timestamp == 0) in Curl_cache_addr()
508 dns->timestamp = 1; in Curl_cache_addr()
510 dns->hostport = port; in Curl_cache_addr()
512 memcpy(dns->hostname, hostname, hostlen); in Curl_cache_addr()
515 dns2 = Curl_hash_add(data->dns.hostcache, entry_id, entry_len + 1, in Curl_cache_addr()
523 dns->refcount++; /* mark entry as in-use */ in Curl_cache_addr()
549 ca->ai_flags = 0; in get_localhost6()
550 ca->ai_family = AF_INET6; in get_localhost6()
551 ca->ai_socktype = SOCK_STREAM; in get_localhost6()
552 ca->ai_protocol = IPPROTO_TCP; in get_localhost6()
553 ca->ai_addrlen = (curl_socklen_t)ss_size; in get_localhost6()
554 ca->ai_next = NULL; in get_localhost6()
555 ca->ai_addr = (void *)((char *)ca + sizeof(struct Curl_addrinfo)); in get_localhost6()
556 memcpy(ca->ai_addr, &sa6, ss_size); in get_localhost6()
557 ca->ai_canonname = (char *)ca->ai_addr + ss_size; in get_localhost6()
558 strcpy(ca->ai_canonname, name); in get_localhost6()
565 /* return a static IPv4 127.0.0.1 for the given name */
573 unsigned int ipv4; in get_localhost() local
580 if(Curl_inet_pton(AF_INET, "127.0.0.1", (char *)&ipv4) < 1) in get_localhost()
582 memcpy(&sa.sin_addr, &ipv4, sizeof(ipv4)); in get_localhost()
587 ca->ai_flags = 0; in get_localhost()
588 ca->ai_family = AF_INET; in get_localhost()
589 ca->ai_socktype = SOCK_STREAM; in get_localhost()
590 ca->ai_protocol = IPPROTO_TCP; in get_localhost()
591 ca->ai_addrlen = (curl_socklen_t)ss_size; in get_localhost()
592 ca->ai_addr = (void *)((char *)ca + sizeof(struct Curl_addrinfo)); in get_localhost()
593 memcpy(ca->ai_addr, &sa, ss_size); in get_localhost()
594 ca->ai_canonname = (char *)ca->ai_addr + ss_size; in get_localhost()
595 strcpy(ca->ai_canonname, name); in get_localhost()
600 ca6->ai_next = ca; in get_localhost()
615 DEBUGASSERT(data->multi); in Curl_ipv6works()
616 if(data->multi->ipv6_up == IPV6_UNKNOWN) { in Curl_ipv6works()
618 data->multi->ipv6_up = works ? IPV6_WORKS : IPV6_DEAD; in Curl_ipv6works()
620 return data->multi->ipv6_up == IPV6_WORKS; in Curl_ipv6works()
623 int ipv6_works = -1; in Curl_ipv6works()
639 * Curl_host_is_ipnum() returns TRUE if the given string is a numerical IPv4
665 return strncasecompare(part, &full[flen - plen], plen); in tailmatch()
680 * CURLRESOLV_ERROR (-1) = error, no pointer
694 struct connectdata *conn = data->conn; in Curl_resolv()
698 (curl_strequal(&hostname[hostname_len - 6], ".onion") || in Curl_resolv()
699 curl_strequal(&hostname[hostname_len - 7], ".onion."))) { in Curl_resolv()
705 conn->bits.doh = FALSE; /* default is not */ in Curl_resolv()
710 if(data->share) in Curl_resolv()
717 dns->refcount++; /* we use it! */ in Curl_resolv()
721 if(data->share) in Curl_resolv()
740 if(data->set.resolver_start) { in Curl_resolv()
743 st = data->set.resolver_start( in Curl_resolv()
745 data->state.async.resolver, in Curl_resolv()
750 data->set.resolver_start_client); in Curl_resolv()
757 /* First check if this is an IPv4 address string */ in Curl_resolv()
759 /* This is a dotted IP address 123.123.123.123-style */ in Curl_resolv()
779 /* First check if this is an IPv4 address string */ in Curl_resolv()
781 /* This is a dotted IP address 123.123.123.123-style */ in Curl_resolv()
797 if(conn->ip_version == CURL_IPRESOLVE_V6 && !Curl_ipv6works(data)) in Curl_resolv()
804 else if(allowDOH && data->set.doh && !ipnum) in Curl_resolv()
813 non-zero value indicating that we need to wait for the response to in Curl_resolv()
833 if(data->share) in Curl_resolv()
839 if(data->share) in Curl_resolv()
887 * CURLRESOLV_TIMEDOUT(-2) = warning, time too short or previous alarm expired
888 * CURLRESOLV_ERROR (-1) = error, no pointer
921 if(data->set.no_signal) in Curl_resolv_timeout()
939 /* This allows us to time-out from the name resolver, as the timeout in Curl_resolv_timeout()
964 /* HP-UX does not have SA_RESTART but defaults to that behavior! */ in Curl_resolv_timeout()
1022 data->conn->created) / 1000; in Curl_resolv_timeout()
1025 unsigned long alarm_set = (unsigned long)(prev_alarm - elapsed_secs); in Curl_resolv_timeout()
1029 /* if the alarm time-left reached zero or turned "negative" (counted in Curl_resolv_timeout()
1056 if(data && data->share) in Curl_resolv_unlink()
1061 if(data && data->share) in Curl_resolv_unlink()
1066 * File-internal: release cache dns entry reference, free if inuse drops to 0
1071 DEBUGASSERT(dns && (dns->refcount > 0)); in hostcache_unlink_entry()
1073 dns->refcount--; in hostcache_unlink_entry()
1074 if(dns->refcount == 0) { in hostcache_unlink_entry()
1075 Curl_freeaddrinfo(dns->addr); in hostcache_unlink_entry()
1077 if(dns->hinfo) { in hostcache_unlink_entry()
1078 if(dns->hinfo->target) in hostcache_unlink_entry()
1079 free(dns->hinfo->target); in hostcache_unlink_entry()
1080 if(dns->hinfo->alpns) in hostcache_unlink_entry()
1081 free(dns->hinfo->alpns); in hostcache_unlink_entry()
1082 if(dns->hinfo->ipv4hints) in hostcache_unlink_entry()
1083 free(dns->hinfo->ipv4hints); in hostcache_unlink_entry()
1084 if(dns->hinfo->echconfiglist) in hostcache_unlink_entry()
1085 free(dns->hinfo->echconfiglist); in hostcache_unlink_entry()
1086 if(dns->hinfo->ipv6hints) in hostcache_unlink_entry()
1087 free(dns->hinfo->ipv6hints); in hostcache_unlink_entry()
1088 if(dns->hinfo->val) in hostcache_unlink_entry()
1089 free(dns->hinfo->val); in hostcache_unlink_entry()
1090 free(dns->hinfo); in hostcache_unlink_entry()
1116 if(data && data->share) in Curl_hostcache_clean()
1121 if(data && data->share) in Curl_hostcache_clean()
1132 data->state.wildcard_resolve = FALSE; in Curl_loadhostpairs()
1134 for(hostp = data->state.resolve; hostp; hostp = hostp->next) { in Curl_loadhostpairs()
1136 if(!hostp->data) in Curl_loadhostpairs()
1138 if(hostp->data[0] == '-') { in Curl_loadhostpairs()
1142 host_end = strchr(&hostp->data[1], ':'); in Curl_loadhostpairs()
1145 hlen = host_end - &hostp->data[1]; in Curl_loadhostpairs()
1152 hostp->data); in Curl_loadhostpairs()
1156 entry_len = create_hostcache_id(&hostp->data[1], hlen, (int)num, in Curl_loadhostpairs()
1158 if(data->share) in Curl_loadhostpairs()
1162 Curl_hash_delete(data->dns.hostcache, entry_id, entry_len + 1); in Curl_loadhostpairs()
1164 if(data->share) in Curl_loadhostpairs()
1183 char *host_begin = hostp->data; in Curl_loadhostpairs()
1193 hlen = host_end - host_begin; in Curl_loadhostpairs()
1217 if(addr_end == addr_begin || *(addr_end - 1) != ']') in Curl_loadhostpairs()
1220 --addr_end; in Curl_loadhostpairs()
1223 alen = addr_end - addr_begin; in Curl_loadhostpairs()
1248 tail->ai_next = ai; in Curl_loadhostpairs()
1249 tail = tail->ai_next; in Curl_loadhostpairs()
1263 hostp->data); in Curl_loadhostpairs()
1272 if(data->share) in Curl_loadhostpairs()
1276 dns = Curl_hash_pick(data->dns.hostcache, entry_id, entry_len + 1); in Curl_loadhostpairs()
1279 infof(data, "RESOLVE %.*s:%d - old addresses discarded", in Curl_loadhostpairs()
1287 3. when adding a non-permanent entry, we want it to remove and in Curl_loadhostpairs()
1289 4. when adding a non-permanent entry, we want it to get a "fresh" in Curl_loadhostpairs()
1292 Curl_hash_delete(data->dns.hostcache, entry_id, entry_len + 1); in Curl_loadhostpairs()
1300 dns->refcount--; in Curl_loadhostpairs()
1303 if(data->share) in Curl_loadhostpairs()
1313 permanent ? "" : " (non-permanent)"); in Curl_loadhostpairs()
1319 data->state.wildcard_resolve = TRUE; in Curl_loadhostpairs()
1323 data->state.resolve = NULL; /* dealt with now */ in Curl_loadhostpairs()
1342 if(!data->set.verbose || in show_resolve_info()
1344 !dns->hostname[0] || Curl_host_is_ipnum(dns->hostname)) in show_resolve_info()
1347 a = dns->addr; in show_resolve_info()
1350 (dns->hostname[0] ? dns->hostname : "(none)"), dns->hostport); in show_resolve_info()
1360 a->ai_family == PF_INET6 || in show_resolve_info()
1362 a->ai_family == PF_INET) { in show_resolve_info()
1364 struct dynbuf *d = &out[(a->ai_family != PF_INET)]; in show_resolve_info()
1375 a = a->ai_next; in show_resolve_info()
1382 infof(data, "IPv4: %s", in show_resolve_info()
1402 if(data->conn->bits.doh) { in Curl_resolv_check()
1418 if(data->conn->bits.doh) in Curl_resolv_getsock()
1439 struct connectdata *conn = data->conn; in Curl_once_resolved()
1442 if(data->state.async.dns) { in Curl_once_resolved()
1443 conn->dns_entry = data->state.async.dns; in Curl_once_resolved()
1444 data->state.async.dns = NULL; in Curl_once_resolved()
1469 struct connectdata *conn = data->conn; in Curl_resolver_error()
1470 if(conn->bits.httpproxy) { in Curl_resolver_error()
1482 data->state.async.hostname); in Curl_resolver_error()