Record TTL also for DNS PTR queries

Message ID mvm7frbgbkg.fsf@hawking.suse.de
State Committed
Headers

Commit Message

Andreas Schwab June 10, 2015, 9:25 a.m. UTC
  This allows nscd to manage proper TTL for GETHOSTBYADDR[v6] requests.

Andreas.

	[BZ #18513]
	* resolv/nss_dns/dns-host.c (getanswer_r): Record TTL also for
	PTR queries.
---
 resolv/nss_dns/dns-host.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Ondrej Bilka June 16, 2015, 5:19 p.m. UTC | #1
On Wed, Jun 10, 2015 at 11:25:03AM +0200, Andreas Schwab wrote:
> This allows nscd to manage proper TTL for GETHOSTBYADDR[v6] requests.
> 
> Andreas.
>
I looked into code and its bit suspect, gaih_getanswer_slice updates
ttl when following holds.

 if (type == T_CNAME)
        {

I couldn't find from code when exacly we need to update ttl and when
not. Ideally I would put conditions to update ttl just after reading
that where its easily checkable.


> 	[BZ #18513]
> 	* resolv/nss_dns/dns-host.c (getanswer_r): Record TTL also for
> 	PTR queries.
> ---
>  resolv/nss_dns/dns-host.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
> index d8c5579..357ac04 100644
> --- a/resolv/nss_dns/dns-host.c
> +++ b/resolv/nss_dns/dns-host.c
> @@ -800,6 +800,10 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
>  
>        if (qtype == T_PTR && type == T_CNAME)
>  	{
> +	  /* A CNAME could also have a TTL entry.  */
> +	  if (ttlp != NULL && ttl < *ttlp)
> +	      *ttlp = ttl;
> +
>  	  n = dn_expand (answer->buf, end_of_message, cp, tbuf, sizeof tbuf);
>  	  if (__glibc_unlikely (n < 0 || res_dnok (tbuf) == 0))
>  	    {
> @@ -863,6 +867,8 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
>  	      ++had_error;
>  	      break;
>  	    }
> +	  if (ttlp != NULL && ttl < *ttlp)
> +	      *ttlp = ttl;
>  	  /* bind would put multiple PTR records as aliases, but we don't do
>  	     that.  */
>  	  result->h_name = bp;
> -- 
> 2.4.3
> 
> -- 
> Andreas Schwab, SUSE Labs, schwab@suse.de
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> "And now for something completely different."
  
Andreas Schwab June 17, 2015, 8:18 a.m. UTC | #2
Ondřej Bílka <neleai@seznam.cz> writes:

> I looked into code and its bit suspect, gaih_getanswer_slice updates

gaih_getanswer_slice is used for gethostbyname and getaddrinfo.  This is
unrelated to gethostbyaddr.

Andreas.
  
Siddhesh Poyarekar June 22, 2015, 2:12 a.m. UTC | #3
On Wed, Jun 10, 2015 at 11:25:03AM +0200, Andreas Schwab wrote:
> This allows nscd to manage proper TTL for GETHOSTBYADDR[v6] requests.
> 
> Andreas.
> 
> 	[BZ #18513]
> 	* resolv/nss_dns/dns-host.c (getanswer_r): Record TTL also for
> 	PTR queries.

Looks good to me.

Siddhesh
  

Patch

diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
index d8c5579..357ac04 100644
--- a/resolv/nss_dns/dns-host.c
+++ b/resolv/nss_dns/dns-host.c
@@ -800,6 +800,10 @@  getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
 
       if (qtype == T_PTR && type == T_CNAME)
 	{
+	  /* A CNAME could also have a TTL entry.  */
+	  if (ttlp != NULL && ttl < *ttlp)
+	      *ttlp = ttl;
+
 	  n = dn_expand (answer->buf, end_of_message, cp, tbuf, sizeof tbuf);
 	  if (__glibc_unlikely (n < 0 || res_dnok (tbuf) == 0))
 	    {
@@ -863,6 +867,8 @@  getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
 	      ++had_error;
 	      break;
 	    }
+	  if (ttlp != NULL && ttl < *ttlp)
+	      *ttlp = ttl;
 	  /* bind would put multiple PTR records as aliases, but we don't do
 	     that.  */
 	  result->h_name = bp;