]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
layer/pktcache: fixed max-ttl for packet cache
authorMarek Vavruša <marek.vavrusa@nic.cz>
Fri, 29 May 2015 00:53:42 +0000 (02:53 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Fri, 29 May 2015 00:53:42 +0000 (02:53 +0200)
lib/layer/pktcache.c

index fe88de0160abe00e96cb4070d1e4ca3f5dae7ee7..14d7ff5c5c7e33eddf456389817d905c721279ff 100644 (file)
@@ -135,7 +135,8 @@ static int peek(knot_layer_t *ctx, knot_pkt_t *pkt)
 
 static uint32_t packet_ttl(knot_pkt_t *pkt)
 {
-       uint32_t ttl = DEFAULT_NOTTL;
+       bool has_ttl = false;
+       uint32_t ttl = UINT32_MAX;
        /* Fetch SOA from authority. */
        const knot_pktsection_t *ns = knot_pkt_section(pkt, KNOT_AUTHORITY);
        for (unsigned i = 0; i < ns->count; ++i) {
@@ -158,10 +159,15 @@ static uint32_t packet_ttl(knot_pkt_t *pkt)
                                knot_rdata_t *rd = knot_rdataset_at(&rr->rrs, i);
                                if (knot_rdata_ttl(rd) < ttl) {
                                        ttl = knot_rdata_ttl(rd);
+                                       has_ttl = true;
                                }
                        }
                }
        }
+       /* Get default if no valid TTL present */
+       if (!has_ttl) {
+               ttl = DEFAULT_NOTTL;
+       }
        return limit_ttl(ttl);
 }