@@ -403,24 +403,24 @@ static int dns_cache_put_negative(
403403
404404int dns_cache_put (
405405 DnsCache * c ,
406- DnsQuestion * q ,
406+ DnsResourceKey * key ,
407407 int rcode ,
408408 DnsAnswer * answer ,
409409 unsigned max_rrs ,
410410 usec_t timestamp ,
411411 int owner_family ,
412412 const union in_addr_union * owner_address ) {
413413
414+ DnsResourceRecord * soa = NULL ;
414415 unsigned cache_keys , i ;
415416 int r ;
416417
417418 assert (c );
418419
419- if (q ) {
420- /* First, if we were passed a question , delete all matching old RRs,
420+ if (key ) {
421+ /* First, if we were passed a key , delete all matching old RRs,
421422 * so that we only keep complete by_key in place. */
422- for (i = 0 ; i < q -> n_keys ; i ++ )
423- dns_cache_remove (c , q -> keys [i ]);
423+ dns_cache_remove (c , key );
424424 }
425425
426426 if (!answer )
@@ -438,8 +438,8 @@ int dns_cache_put(
438438
439439 cache_keys = answer -> n_rrs ;
440440
441- if (q )
442- cache_keys += q -> n_keys ;
441+ if (key )
442+ cache_keys ++ ;
443443
444444 /* Make some space for our new entries */
445445 dns_cache_make_space (c , cache_keys );
@@ -454,44 +454,38 @@ int dns_cache_put(
454454 goto fail ;
455455 }
456456
457- if (!q )
457+ if (!key )
458458 return 0 ;
459459
460- /* Third, add in negative entries for all keys with no RR */
461- for (i = 0 ; i < q -> n_keys ; i ++ ) {
462- DnsResourceRecord * soa = NULL ;
463-
464- r = dns_answer_contains (answer , q -> keys [i ]);
465- if (r < 0 )
466- goto fail ;
467- if (r > 0 )
468- continue ;
460+ /* Third, add in negative entries if the key has no RR */
461+ r = dns_answer_contains (answer , key );
462+ if (r < 0 )
463+ goto fail ;
464+ if (r > 0 )
465+ return 0 ;
469466
470- /* See https://tools.ietf.org/html/rfc2308, which
471- * say that a matching SOA record in the packet
472- * is used to to enable negative caching. */
467+ /* See https://tools.ietf.org/html/rfc2308, which
468+ * say that a matching SOA record in the packet
469+ * is used to to enable negative caching. */
473470
474- r = dns_answer_find_soa (answer , q -> keys [ i ] , & soa );
475- if (r < 0 )
476- goto fail ;
477- if (r == 0 )
478- continue ;
471+ r = dns_answer_find_soa (answer , key , & soa );
472+ if (r < 0 )
473+ goto fail ;
474+ if (r == 0 )
475+ return 0 ;
479476
480- r = dns_cache_put_negative (c , q -> keys [i ], rcode , timestamp , MIN (soa -> soa .minimum , soa -> ttl ), owner_family , owner_address );
481- if (r < 0 )
482- goto fail ;
483- }
477+ r = dns_cache_put_negative (c , key , rcode , timestamp , MIN (soa -> soa .minimum , soa -> ttl ), owner_family , owner_address );
478+ if (r < 0 )
479+ goto fail ;
484480
485481 return 0 ;
486482
487483fail :
488484 /* Adding all RRs failed. Let's clean up what we already
489485 * added, just in case */
490486
491- if (q ) {
492- for (i = 0 ; i < q -> n_keys ; i ++ )
493- dns_cache_remove (c , q -> keys [i ]);
494- }
487+ if (key )
488+ dns_cache_remove (c , key );
495489
496490 for (i = 0 ; i < answer -> n_rrs ; i ++ )
497491 dns_cache_remove (c , answer -> items [i ].rr -> key );
0 commit comments