This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH][BZ #13928] Use minimum ttl value from dns query


Hi,

When a queried dns name is a CNAME record with a TTL, the TTL of the A
or AAAA record that the CNAME finally resolves to is considered as its
TTL, which results in incorrect cache timeouts for such CNAME records
in nscd.

AFAICT, the ttl is only used by nscd and this behaviour affects how long
nscd caches a DNS entry before it looks to reload it. The correct
approach in this case for nscd ought to be to have the minimum of the
TTL values in the entire chain of results (CNAME -> CNAME -> ... ->
A|AAAA) as the cache timeout value for the DNS entry.

The bugzilla has detailed steps to reproduce the problem and verify
the fix. I have tested the patch with HEAD and it gives the minimum ttl
value. Following scenarios (dns entries) were tested to confirm minimum
ttl values. The default ttl is 1200 and zone is foo.net (as detailed in
the bz):

* query bad.foo.net and cad.foo.net:

ad   IN  AAAA      ::8
cad 30  IN  CNAME  ad
bad 15  IN  CNAME  cad

* query bad.foo.net and cad.foo.net:

ad   IN  A      1.0.0.1
cad 30  IN  CNAME  ad
bad 15  IN  CNAME  cad

* query bed.foo.net and ced.foo.net

ed   IN AAAA ::9
ced 15 IN CNAME ed
bed 30 IN CNAME ced

* query id.foo.net and od.foo.net

id 15 A 1.0.0.1
od 15 AAAA ::1

Regards,
Siddhesh


ChangeLog:

2012-03-29  Siddhesh Poyarekar  <siddhesh@redhat.com>

	[BZ #13928]
	* resolv/nss_dns/dns-host.c (getanswer_r): Also consider ttl
	from a CNAME entry and return the minimum ttl for the query.
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
index 10aecb8..871b0d0 100644
--- a/resolv/nss_dns/dns-host.c
+++ b/resolv/nss_dns/dns-host.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2004, 2007-2009, 2010 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2004, 2007-2009, 2010, 2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Extended from original form by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
@@ -744,6 +744,10 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
 
       if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME)
 	{
+	  /* A CNAME could also have a TTL entry.  */
+	  if (ttlp != NULL && ttl < *ttlp)
+	      *ttlp = ttl;
+
 	  if (ap >= &host_data->aliases[MAX_NR_ALIASES - 1])
 	    continue;
 	  n = dn_expand (answer->buf, end_of_message, cp, tbuf, sizeof tbuf);
@@ -905,7 +909,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
 	    {
 	      register int nn;
 
-	      if (ttlp != NULL)
+	      if (ttlp != NULL && ttl < *ttlp)
 		*ttlp = ttl;
 	      if (canonp != NULL)
 		*canonp = bp;
-- 
1.7.7.6


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]