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 aren't 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(c->timestamp) { in hostcache_timestamp_remove()
200 time_t age = prune->now - c->timestamp; in hostcache_timestamp_remove()
201 if(age >= prune->cache_timeout) in hostcache_timestamp_remove()
203 if(age > prune->oldest) in hostcache_timestamp_remove()
204 prune->oldest = age; in hostcache_timestamp_remove()
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()
260 } while(timeout && (data->dns.hostcache->size > MAX_DNS_CACHE_SIZE)); in Curl_hostcache_prune()
262 if(data->share) in Curl_hostcache_prune()
269 is not thread-safe stuff. */
287 dns = Curl_hash_pick(data->dns.hostcache, entry_id, entry_len + 1); in fetch_addr()
290 if(!dns && data->state.wildcard_resolve) { in fetch_addr()
294 dns = Curl_hash_pick(data->dns.hostcache, entry_id, entry_len + 1); in fetch_addr()
297 if(dns && (data->set.dns_cache_timeout != -1)) { in fetch_addr()
302 user.cache_timeout = data->set.dns_cache_timeout; in fetch_addr()
308 Curl_hash_delete(data->dns.hostcache, entry_id, entry_len + 1); in fetch_addr()
313 if(dns && data->conn->ip_version != CURL_IPRESOLVE_WHATEVER) { in fetch_addr()
316 struct Curl_addrinfo *addr = dns->addr; in fetch_addr()
319 if(data->conn->ip_version == CURL_IPRESOLVE_V6) in fetch_addr()
324 if(addr->ai_family == pf) { in fetch_addr()
328 addr = addr->ai_next; in fetch_addr()
334 Curl_hash_delete(data->dns.hostcache, entry_id, entry_len + 1); in fetch_addr()
361 if(data->share) in Curl_fetch_addr()
367 dns->inuse++; /* we use it! */ in Curl_fetch_addr()
369 if(data->share) in Curl_fetch_addr()
383 addr = addr->ai_next; in num_addresses()
393 * struct by re-linking its linked list.
422 nodes[i] = nodes[i-1]->ai_next; in Curl_shuffle_addr()
427 /* Fisher-Yates shuffle */ in Curl_shuffle_addr()
430 for(i = num_addrs - 1; i > 0; i--) { in Curl_shuffle_addr()
438 nodes[i-1]->ai_next = nodes[i]; in Curl_shuffle_addr()
441 nodes[num_addrs-1]->ai_next = NULL; in Curl_shuffle_addr()
480 if(data->set.dns_shuffle_addresses) { in Curl_cache_addr()
499 dns->inuse = 1; /* the cache has the first reference */ in Curl_cache_addr()
500 dns->addr = addr; /* this is the address(es) */ in Curl_cache_addr()
501 time(&dns->timestamp); in Curl_cache_addr()
502 if(dns->timestamp == 0) in Curl_cache_addr()
503 dns->timestamp = 1; /* zero indicates permanent CURLOPT_RESOLVE entry */ in Curl_cache_addr()
504 dns->hostport = port; in Curl_cache_addr()
506 memcpy(dns->hostname, hostname, hostlen); in Curl_cache_addr()
509 dns2 = Curl_hash_add(data->dns.hostcache, entry_id, entry_len + 1, in Curl_cache_addr()
517 dns->inuse++; /* mark entry as in-use */ in Curl_cache_addr()
543 ca->ai_flags = 0; in get_localhost6()
544 ca->ai_family = AF_INET6; in get_localhost6()
545 ca->ai_socktype = SOCK_STREAM; in get_localhost6()
546 ca->ai_protocol = IPPROTO_TCP; in get_localhost6()
547 ca->ai_addrlen = (curl_socklen_t)ss_size; in get_localhost6()
548 ca->ai_next = NULL; in get_localhost6()
549 ca->ai_addr = (void *)((char *)ca + sizeof(struct Curl_addrinfo)); in get_localhost6()
550 memcpy(ca->ai_addr, &sa6, ss_size); in get_localhost6()
551 ca->ai_canonname = (char *)ca->ai_addr + ss_size; in get_localhost6()
552 strcpy(ca->ai_canonname, name); in get_localhost6()
559 /* return a static IPv4 127.0.0.1 for the given name */
567 unsigned int ipv4; in get_localhost() local
574 if(Curl_inet_pton(AF_INET, "127.0.0.1", (char *)&ipv4) < 1) in get_localhost()
576 memcpy(&sa.sin_addr, &ipv4, sizeof(ipv4)); in get_localhost()
581 ca->ai_flags = 0; in get_localhost()
582 ca->ai_family = AF_INET; in get_localhost()
583 ca->ai_socktype = SOCK_STREAM; in get_localhost()
584 ca->ai_protocol = IPPROTO_TCP; in get_localhost()
585 ca->ai_addrlen = (curl_socklen_t)ss_size; in get_localhost()
586 ca->ai_addr = (void *)((char *)ca + sizeof(struct Curl_addrinfo)); in get_localhost()
587 memcpy(ca->ai_addr, &sa, ss_size); in get_localhost()
588 ca->ai_canonname = (char *)ca->ai_addr + ss_size; in get_localhost()
589 strcpy(ca->ai_canonname, name); in get_localhost()
594 ca6->ai_next = ca; in get_localhost()
609 DEBUGASSERT(data->multi); in Curl_ipv6works()
610 if(data->multi->ipv6_up == IPV6_UNKNOWN) { in Curl_ipv6works()
612 data->multi->ipv6_up = works ? IPV6_WORKS : IPV6_DEAD; in Curl_ipv6works()
614 return data->multi->ipv6_up == IPV6_WORKS; in Curl_ipv6works()
617 int ipv6_works = -1; in Curl_ipv6works()
633 * Curl_host_is_ipnum() returns TRUE if the given string is a numerical IPv4
659 return strncasecompare(part, &full[flen - plen], plen); in tailmatch()
674 * CURLRESOLV_ERROR (-1) = error, no pointer
688 struct connectdata *conn = data->conn; in Curl_resolv()
692 (curl_strequal(&hostname[hostname_len - 6], ".onion") || in Curl_resolv()
693 curl_strequal(&hostname[hostname_len - 7], ".onion."))) { in Curl_resolv()
699 conn->bits.doh = FALSE; /* default is not */ in Curl_resolv()
704 if(data->share) in Curl_resolv()
711 dns->inuse++; /* we use it! */ in Curl_resolv()
715 if(data->share) in Curl_resolv()
734 if(data->set.resolver_start) { in Curl_resolv()
737 st = data->set.resolver_start( in Curl_resolv()
739 data->state.async.resolver, in Curl_resolv()
744 data->set.resolver_start_client); in Curl_resolv()
751 /* First check if this is an IPv4 address string */ in Curl_resolv()
753 /* This is a dotted IP address 123.123.123.123-style */ in Curl_resolv()
773 /* First check if this is an IPv4 address string */ in Curl_resolv()
775 /* This is a dotted IP address 123.123.123.123-style */ in Curl_resolv()
791 if(conn->ip_version == CURL_IPRESOLVE_V6 && !Curl_ipv6works(data)) in Curl_resolv()
798 else if(allowDOH && data->set.doh && !ipnum) in Curl_resolv()
807 non-zero value indicating that we need to wait for the response to in Curl_resolv()
827 if(data->share) in Curl_resolv()
833 if(data->share) in Curl_resolv()
881 * CURLRESOLV_TIMEDOUT(-2) = warning, time too short or previous alarm expired
882 * CURLRESOLV_ERROR (-1) = error, no pointer
915 if(data->set.no_signal) in Curl_resolv_timeout()
933 /* This allows us to time-out from the name resolver, as the timeout in Curl_resolv_timeout()
1016 data->conn->created) / 1000; in Curl_resolv_timeout()
1019 unsigned long alarm_set = (unsigned long)(prev_alarm - elapsed_secs); in Curl_resolv_timeout()
1023 /* if the alarm time-left reached zero or turned "negative" (counted in Curl_resolv_timeout()
1048 if(data && data->share) in Curl_resolv_unlock()
1053 if(data && data->share) in Curl_resolv_unlock()
1058 * File-internal: release cache dns entry reference, free if inuse drops to 0
1063 DEBUGASSERT(dns && (dns->inuse>0)); in freednsentry()
1065 dns->inuse--; in freednsentry()
1066 if(dns->inuse == 0) { in freednsentry()
1067 Curl_freeaddrinfo(dns->addr); in freednsentry()
1069 if(dns->hinfo) { in freednsentry()
1070 if(dns->hinfo->target) in freednsentry()
1071 free(dns->hinfo->target); in freednsentry()
1072 if(dns->hinfo->alpns) in freednsentry()
1073 free(dns->hinfo->alpns); in freednsentry()
1074 if(dns->hinfo->ipv4hints) in freednsentry()
1075 free(dns->hinfo->ipv4hints); in freednsentry()
1076 if(dns->hinfo->echconfiglist) in freednsentry()
1077 free(dns->hinfo->echconfiglist); in freednsentry()
1078 if(dns->hinfo->ipv6hints) in freednsentry()
1079 free(dns->hinfo->ipv6hints); in freednsentry()
1080 if(dns->hinfo->val) in freednsentry()
1081 free(dns->hinfo->val); in freednsentry()
1082 free(dns->hinfo); in freednsentry()
1108 if(data && data->share) in Curl_hostcache_clean()
1113 if(data && data->share) in Curl_hostcache_clean()
1124 data->state.wildcard_resolve = false; in Curl_loadhostpairs()
1126 for(hostp = data->state.resolve; hostp; hostp = hostp->next) { in Curl_loadhostpairs()
1128 if(!hostp->data) in Curl_loadhostpairs()
1130 if(hostp->data[0] == '-') { in Curl_loadhostpairs()
1134 host_end = strchr(&hostp->data[1], ':'); in Curl_loadhostpairs()
1137 hlen = host_end - &hostp->data[1]; in Curl_loadhostpairs()
1144 hostp->data); in Curl_loadhostpairs()
1148 entry_len = create_hostcache_id(&hostp->data[1], hlen, (int)num, in Curl_loadhostpairs()
1150 if(data->share) in Curl_loadhostpairs()
1154 Curl_hash_delete(data->dns.hostcache, entry_id, entry_len + 1); in Curl_loadhostpairs()
1156 if(data->share) in Curl_loadhostpairs()
1175 char *host_begin = hostp->data; in Curl_loadhostpairs()
1185 hlen = host_end - host_begin; in Curl_loadhostpairs()
1209 if(addr_end == addr_begin || *(addr_end - 1) != ']') in Curl_loadhostpairs()
1212 --addr_end; in Curl_loadhostpairs()
1215 alen = addr_end - addr_begin; in Curl_loadhostpairs()
1240 tail->ai_next = ai; in Curl_loadhostpairs()
1241 tail = tail->ai_next; in Curl_loadhostpairs()
1255 hostp->data); in Curl_loadhostpairs()
1264 if(data->share) in Curl_loadhostpairs()
1268 dns = Curl_hash_pick(data->dns.hostcache, entry_id, entry_len + 1); in Curl_loadhostpairs()
1271 infof(data, "RESOLVE %.*s:%d - old addresses discarded", in Curl_loadhostpairs()
1279 3. when adding a non-permanent entry, we want it to remove and in Curl_loadhostpairs()
1281 4. when adding a non-permanent entry, we want it to get a "fresh" in Curl_loadhostpairs()
1284 Curl_hash_delete(data->dns.hostcache, entry_id, entry_len + 1); in Curl_loadhostpairs()
1291 dns->timestamp = 0; /* mark as permanent */ in Curl_loadhostpairs()
1294 dns->inuse--; in Curl_loadhostpairs()
1297 if(data->share) in Curl_loadhostpairs()
1307 permanent ? "" : " (non-permanent)"); in Curl_loadhostpairs()
1313 data->state.wildcard_resolve = true; in Curl_loadhostpairs()
1317 data->state.resolve = NULL; /* dealt with now */ in Curl_loadhostpairs()
1336 if(!data->set.verbose || in show_resolve_info()
1338 !dns->hostname[0] || Curl_host_is_ipnum(dns->hostname)) in show_resolve_info()
1341 a = dns->addr; in show_resolve_info()
1344 (dns->hostname[0] ? dns->hostname : "(none)"), dns->hostport); in show_resolve_info()
1354 a->ai_family == PF_INET6 || in show_resolve_info()
1356 a->ai_family == PF_INET) { in show_resolve_info()
1358 struct dynbuf *d = &out[(a->ai_family != PF_INET)]; in show_resolve_info()
1369 a = a->ai_next; in show_resolve_info()
1376 infof(data, "IPv4: %s", in show_resolve_info()
1396 if(data->conn->bits.doh) { in Curl_resolv_check()
1412 if(data->conn->bits.doh) in Curl_resolv_getsock()
1433 struct connectdata *conn = data->conn; in Curl_once_resolved()
1436 if(data->state.async.dns) { in Curl_once_resolved()
1437 conn->dns_entry = data->state.async.dns; in Curl_once_resolved()
1438 data->state.async.dns = NULL; in Curl_once_resolved()
1464 struct connectdata *conn = data->conn; in Curl_resolver_error()
1465 if(conn->bits.httpproxy) { in Curl_resolver_error()
1477 data->state.async.hostname); in Curl_resolver_error()