Unverified Commit f66d97b6 authored by Alibek.Jorajev's avatar Alibek.Jorajev Committed by Daniel Stenberg
Browse files

CURLOPT_RESOLVE: always purge old entry first

If there's an existing entry using the selected name.

Closes #2622
parent a115c6bb
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -50,6 +50,11 @@ HOST+PORT will instead use your provided ADDRESS. Addresses set with
\fICURLOPT_RESOLVE(3)\fP will not time-out from the DNS cache like ordinary
entries.

If the DNS cache already have an entry for the given host+port pair, then
this entry will be removed and a new entry will be created. This is because
old entry may have have different addresses or be ordinary entries with
time-outs.

The provided ADDRESS set by this option will be used even if
\fICURLOPT_IPRESOLVE(3)\fP is set to make libcurl use another IP version.

+19 −15
Original line number Diff line number Diff line
@@ -1010,11 +1010,22 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data)
      /* See if its already in our dns cache */
      dns = Curl_hash_pick(data->dns.hostcache, entry_id, entry_len + 1);

      if(dns) {
        infof(data, "RESOLVE %s:%d is - old addresses discarded!\n",
                hostname, port);
        /* delete old entry entry, there are two reasons for this
         1. old entry may have different addresses.
         2. even if entry with correct addresses is already in the cache,
            but if it is close to expire, then by the time next http
            request is made, it can get expired and pruned because old
            entry is not necessarily marked as added by CURLOPT_RESOLVE. */

        Curl_hash_delete(data->dns.hostcache, entry_id, entry_len + 1);
      }
      /* free the allocated entry_id again */
      free(entry_id);

      if(!dns) {
        /* if not in the cache already, put this host in the cache */
      /* put this new host in the cache */
      dns = Curl_cache_addr(data, head, hostname, port);
      if(dns) {
        dns->timestamp = 0; /* mark as added by CURLOPT_RESOLVE */
@@ -1022,13 +1033,6 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data)
         * entry alive: */
            dns->inuse--;
      }
      }
      else {
        /* this is a duplicate, free it again */
        infof(data, "RESOLVE %s:%d is already cached, %s not stored!\n",
              hostname, port, addresses);
        Curl_freeaddrinfo(head);
      }

      if(data->share)
        Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
+1 −1
Original line number Diff line number Diff line
@@ -177,7 +177,7 @@ test1533 test1534 test1535 test1536 test1537 test1538 \
test1540 \
test1550 test1551 test1552 test1553 test1554 test1555 test1556 \
test1600 test1601 test1602 test1603 test1604 test1605 test1606 test1607 \
test1608 \
test1608 test1609 \
\
test1700 test1701 test1702 \
\

tests/data/test1609

0 → 100644
+26 −0
Original line number Diff line number Diff line
<testcase>
<info>
<keywords>
unittest
CURLOPT_RESOLVE
</keywords>
</info>

#
# Client-side
<client>
<server>
none
</server>
<features>
unittest
</features>
 <name>
CURLOPT_RESOLVE parsing
 </name>
<tool>
unit1609
</tool>
</client>

</testcase>
+4 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ UNITPROGS = unit1300 unit1301 unit1302 unit1303 unit1304 unit1305 unit1307 \
 unit1330 unit1394 unit1395 unit1396 unit1397 unit1398	\
 unit1399	\
 unit1600 unit1601 unit1602 unit1603 unit1604 unit1605 unit1606 unit1607 \
 unit1608
 unit1608 unit1609

unit1300_SOURCES = unit1300.c $(UNITFILES)
unit1300_CPPFLAGS = $(AM_CPPFLAGS)
@@ -92,3 +92,6 @@ unit1607_CPPFLAGS = $(AM_CPPFLAGS)

unit1608_SOURCES = unit1608.c $(UNITFILES)
unit1608_CPPFLAGS = $(AM_CPPFLAGS)

unit1609_SOURCES = unit1609.c $(UNITFILES)
unit1609_CPPFLAGS = $(AM_CPPFLAGS)
Loading