• Home
  • Raw
  • Download

Lines Matching +full:ipv4 +full:- +full:only +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 >= (time_t)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.
400 * Not declared static only to make it easy to use in a unit test!
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()
551 ca->ai_flags = 0; in get_localhost6()
552 ca->ai_family = AF_INET6; in get_localhost6()
553 ca->ai_socktype = SOCK_STREAM; in get_localhost6()
554 ca->ai_protocol = IPPROTO_TCP; in get_localhost6()
555 ca->ai_addrlen = (curl_socklen_t)ss_size; in get_localhost6()
556 ca->ai_next = NULL; in get_localhost6()
557 ca->ai_addr = (void *)((char *)ca + sizeof(struct Curl_addrinfo)); in get_localhost6()
558 memcpy(ca->ai_addr, &sa6, ss_size); in get_localhost6()
559 ca->ai_canonname = (char *)ca->ai_addr + ss_size; in get_localhost6()
560 strcpy(ca->ai_canonname, name); in get_localhost6()
567 /* return a static IPv4 127.0.0.1 for the given name */
575 unsigned int ipv4; in get_localhost() local
582 if(Curl_inet_pton(AF_INET, "127.0.0.1", (char *)&ipv4) < 1) in get_localhost()
584 memcpy(&sa.sin_addr, &ipv4, sizeof(ipv4)); in get_localhost()
589 ca->ai_flags = 0; in get_localhost()
590 ca->ai_family = AF_INET; in get_localhost()
591 ca->ai_socktype = SOCK_STREAM; in get_localhost()
592 ca->ai_protocol = IPPROTO_TCP; in get_localhost()
593 ca->ai_addrlen = (curl_socklen_t)ss_size; in get_localhost()
594 ca->ai_addr = (void *)((char *)ca + sizeof(struct Curl_addrinfo)); in get_localhost()
595 memcpy(ca->ai_addr, &sa, ss_size); in get_localhost()
596 ca->ai_canonname = (char *)ca->ai_addr + ss_size; in get_localhost()
597 strcpy(ca->ai_canonname, name); in get_localhost()
602 ca6->ai_next = ca; in get_localhost()
614 during a program's lifetime so we only probe the first time and then we in Curl_ipv6works()
617 DEBUGASSERT(data->multi); in Curl_ipv6works()
618 if(data->multi->ipv6_up == IPV6_UNKNOWN) { in Curl_ipv6works()
620 data->multi->ipv6_up = works ? IPV6_WORKS : IPV6_DEAD; in Curl_ipv6works()
622 return data->multi->ipv6_up == IPV6_WORKS; in Curl_ipv6works()
625 int ipv6_works = -1; in Curl_ipv6works()
641 * Curl_host_is_ipnum() returns TRUE if the given string is a numerical IPv4
667 return strncasecompare(part, &full[flen - plen], plen); in tailmatch()
682 * CURLRESOLV_ERROR (-1) = error, no pointer
696 struct connectdata *conn = data->conn; in Curl_resolv()
700 (curl_strequal(&hostname[hostname_len - 6], ".onion") || in Curl_resolv()
701 curl_strequal(&hostname[hostname_len - 7], ".onion."))) { in Curl_resolv()
707 conn->bits.doh = FALSE; /* default is not */ in Curl_resolv()
712 if(data->share) in Curl_resolv()
719 dns->refcount++; /* we use it! */ in Curl_resolv()
723 if(data->share) in Curl_resolv()
742 if(data->set.resolver_start) { in Curl_resolv()
745 st = data->set.resolver_start( in Curl_resolv()
747 data->state.async.resolver, in Curl_resolv()
752 data->set.resolver_start_client); in Curl_resolv()
759 /* First check if this is an IPv4 address string */ in Curl_resolv()
761 /* This is a dotted IP address 123.123.123.123-style */ in Curl_resolv()
781 /* First check if this is an IPv4 address string */ in Curl_resolv()
783 /* This is a dotted IP address 123.123.123.123-style */ in Curl_resolv()
799 if(conn->ip_version == CURL_IPRESOLVE_V6 && !Curl_ipv6works(data)) in Curl_resolv()
808 else if(allowDOH && data->set.doh && !ipnum) in Curl_resolv()
817 non-zero value indicating that we need to wait for the response to in Curl_resolv()
837 if(data->share) in Curl_resolv()
843 if(data->share) in Curl_resolv()
891 * CURLRESOLV_TIMEDOUT(-2) = warning, time too short or previous alarm expired
892 * CURLRESOLV_ERROR (-1) = error, no pointer
925 if(data->set.no_signal) in Curl_resolv_timeout()
936 /* The alarm() function only provides integer second resolution, so if in Curl_resolv_timeout()
943 /* This allows us to time-out from the name resolver, as the timeout in Curl_resolv_timeout()
968 /* HP-UX does not have SA_RESTART but defaults to that behavior! */ in Curl_resolv_timeout()
1026 data->conn->created) / 1000; in Curl_resolv_timeout()
1029 unsigned long alarm_set = (unsigned long)(prev_alarm - elapsed_secs); in Curl_resolv_timeout()
1033 /* if the alarm time-left reached zero or turned "negative" (counted in Curl_resolv_timeout()
1052 * that only one unlink is made for each Curl_resolv() call.
1060 if(data && data->share) in Curl_resolv_unlink()
1065 if(data && data->share) in Curl_resolv_unlink()
1070 * File-internal: release cache dns entry reference, free if inuse drops to 0
1075 DEBUGASSERT(dns && (dns->refcount > 0)); in hostcache_unlink_entry()
1077 dns->refcount--; in hostcache_unlink_entry()
1078 if(dns->refcount == 0) { in hostcache_unlink_entry()
1079 Curl_freeaddrinfo(dns->addr); in hostcache_unlink_entry()
1081 if(dns->hinfo) { in hostcache_unlink_entry()
1082 free(dns->hinfo->target); in hostcache_unlink_entry()
1083 free(dns->hinfo->ipv4hints); in hostcache_unlink_entry()
1084 free(dns->hinfo->echconfiglist); in hostcache_unlink_entry()
1085 free(dns->hinfo->ipv6hints); in hostcache_unlink_entry()
1086 free(dns->hinfo); in hostcache_unlink_entry()
1112 if(data && data->share) in Curl_hostcache_clean()
1117 if(data && data->share) in Curl_hostcache_clean()
1128 data->state.wildcard_resolve = FALSE; in Curl_loadhostpairs()
1130 for(hostp = data->state.resolve; hostp; hostp = hostp->next) { in Curl_loadhostpairs()
1132 if(!hostp->data) in Curl_loadhostpairs()
1134 if(hostp->data[0] == '-') { in Curl_loadhostpairs()
1138 host_end = strchr(&hostp->data[1], ':'); in Curl_loadhostpairs()
1141 hlen = host_end - &hostp->data[1]; in Curl_loadhostpairs()
1148 hostp->data); in Curl_loadhostpairs()
1152 entry_len = create_hostcache_id(&hostp->data[1], hlen, (int)num, in Curl_loadhostpairs()
1154 if(data->share) in Curl_loadhostpairs()
1158 Curl_hash_delete(data->dns.hostcache, entry_id, entry_len + 1); in Curl_loadhostpairs()
1160 if(data->share) in Curl_loadhostpairs()
1179 char *host_begin = hostp->data; in Curl_loadhostpairs()
1189 hlen = host_end - host_begin; in Curl_loadhostpairs()
1213 if(addr_end == addr_begin || *(addr_end - 1) != ']') in Curl_loadhostpairs()
1216 --addr_end; in Curl_loadhostpairs()
1219 alen = addr_end - addr_begin; in Curl_loadhostpairs()
1244 tail->ai_next = ai; in Curl_loadhostpairs()
1245 tail = tail->ai_next; in Curl_loadhostpairs()
1259 hostp->data); in Curl_loadhostpairs()
1268 if(data->share) in Curl_loadhostpairs()
1272 dns = Curl_hash_pick(data->dns.hostcache, entry_id, entry_len + 1); in Curl_loadhostpairs()
1275 infof(data, "RESOLVE %.*s:%d - old addresses discarded", in Curl_loadhostpairs()
1283 3. when adding a non-permanent entry, we want it to remove and in Curl_loadhostpairs()
1285 4. when adding a non-permanent entry, we want it to get a "fresh" in Curl_loadhostpairs()
1288 Curl_hash_delete(data->dns.hostcache, entry_id, entry_len + 1); in Curl_loadhostpairs()
1296 dns->refcount--; in Curl_loadhostpairs()
1299 if(data->share) in Curl_loadhostpairs()
1309 permanent ? "" : " (non-permanent)"); in Curl_loadhostpairs()
1315 data->state.wildcard_resolve = TRUE; in Curl_loadhostpairs()
1319 data->state.resolve = NULL; /* dealt with now */ in Curl_loadhostpairs()
1338 if(!data->set.verbose || in show_resolve_info()
1340 !dns->hostname[0] || Curl_host_is_ipnum(dns->hostname)) in show_resolve_info()
1343 a = dns->addr; in show_resolve_info()
1346 (dns->hostname[0] ? dns->hostname : "(none)"), dns->hostport); in show_resolve_info()
1356 a->ai_family == PF_INET6 || in show_resolve_info()
1358 a->ai_family == PF_INET) { in show_resolve_info()
1360 struct dynbuf *d = &out[(a->ai_family != PF_INET)]; in show_resolve_info()
1371 a = a->ai_next; in show_resolve_info()
1378 infof(data, "IPv4: %s", in show_resolve_info()
1398 if(data->conn->bits.doh) { in Curl_resolv_check()
1414 if(data->conn->bits.doh) in Curl_resolv_getsock()
1435 struct connectdata *conn = data->conn; in Curl_once_resolved()
1438 if(data->state.async.dns) { in Curl_once_resolved()
1439 conn->dns_entry = data->state.async.dns; in Curl_once_resolved()
1440 data->state.async.dns = NULL; in Curl_once_resolved()
1465 struct connectdata *conn = data->conn; in Curl_resolver_error()
1466 if(conn->bits.httpproxy) { in Curl_resolver_error()
1478 data->state.async.hostname); in Curl_resolver_error()