2424#include "resolved-llmnr.h"
2525#include "resolved-dns-transaction.h"
2626#include "random-util.h"
27+ #include "dns-domain.h"
2728
2829DnsTransaction * dns_transaction_free (DnsTransaction * t ) {
2930 DnsQuery * q ;
@@ -34,7 +35,7 @@ DnsTransaction* dns_transaction_free(DnsTransaction *t) {
3435
3536 sd_event_source_unref (t -> timeout_event_source );
3637
37- dns_question_unref (t -> question );
38+ dns_resource_key_unref (t -> key );
3839 dns_packet_unref (t -> sent );
3940 dns_packet_unref (t -> received );
4041 dns_answer_unref (t -> cached );
@@ -76,13 +77,13 @@ void dns_transaction_gc(DnsTransaction *t) {
7677 dns_transaction_free (t );
7778}
7879
79- int dns_transaction_new (DnsTransaction * * ret , DnsScope * s , DnsQuestion * q ) {
80+ int dns_transaction_new (DnsTransaction * * ret , DnsScope * s , DnsResourceKey * key ) {
8081 _cleanup_ (dns_transaction_freep ) DnsTransaction * t = NULL ;
8182 int r ;
8283
8384 assert (ret );
8485 assert (s );
85- assert (q );
86+ assert (key );
8687
8788 r = hashmap_ensure_allocated (& s -> manager -> dns_transactions , NULL );
8889 if (r < 0 )
@@ -94,7 +95,7 @@ int dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsQuestion *q) {
9495
9596 t -> dns_fd = -1 ;
9697
97- t -> question = dns_question_ref ( q );
98+ t -> key = dns_resource_key_ref ( key );
9899
99100 do
100101 random_bytes (& t -> id , sizeof (t -> id ));
@@ -266,7 +267,8 @@ static int dns_transaction_open_tcp(DnsTransaction *t) {
266267 /* Otherwise, try to talk to the owner of a
267268 * the IP address, in case this is a reverse
268269 * PTR lookup */
269- r = dns_question_extract_reverse_address (t -> question , & family , & address );
270+
271+ r = dns_name_address (DNS_RESOURCE_KEY_NAME (t -> key ), & family , & address );
270272 if (r < 0 )
271273 return r ;
272274 if (r == 0 )
@@ -428,8 +430,7 @@ void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p) {
428430 }
429431
430432 /* Only consider responses with equivalent query section to the request */
431- r = dns_question_is_equal (p -> question , t -> question );
432- if (r <= 0 ) {
433+ if (p -> question -> n_keys != 1 || dns_resource_key_equal (p -> question -> keys [0 ], t -> key ) <= 0 ) {
433434 dns_transaction_complete (t , DNS_TRANSACTION_INVALID_REPLY );
434435 return ;
435436 }
@@ -518,7 +519,6 @@ static int on_transaction_timeout(sd_event_source *s, usec_t usec, void *userdat
518519
519520static int dns_transaction_make_packet (DnsTransaction * t ) {
520521 _cleanup_ (dns_packet_unrefp ) DnsPacket * p = NULL ;
521- unsigned n , added = 0 ;
522522 int r ;
523523
524524 assert (t );
@@ -530,24 +530,17 @@ static int dns_transaction_make_packet(DnsTransaction *t) {
530530 if (r < 0 )
531531 return r ;
532532
533- for (n = 0 ; n < t -> question -> n_keys ; n ++ ) {
534- r = dns_scope_good_key (t -> scope , t -> question -> keys [n ]);
535- if (r < 0 )
536- return r ;
537- if (r == 0 )
538- continue ;
539-
540- r = dns_packet_append_key (p , t -> question -> keys [n ], NULL );
541- if (r < 0 )
542- return r ;
543-
544- added ++ ;
545- }
546-
547- if (added <= 0 )
533+ r = dns_scope_good_key (t -> scope , t -> key );
534+ if (r < 0 )
535+ return r ;
536+ if (r == 0 )
548537 return - EDOM ;
549538
550- DNS_PACKET_HEADER (p )-> qdcount = htobe16 (added );
539+ r = dns_packet_append_key (p , t -> key , NULL );
540+ if (r < 0 )
541+ return r ;
542+
543+ DNS_PACKET_HEADER (p )-> qdcount = htobe16 (1 );
551544 DNS_PACKET_HEADER (p )-> id = t -> id ;
552545
553546 t -> sent = p ;
@@ -621,7 +614,7 @@ int dns_transaction_go(DnsTransaction *t) {
621614 /* Let's then prune all outdated entries */
622615 dns_cache_prune (& t -> scope -> cache );
623616
624- r = dns_cache_lookup (& t -> scope -> cache , t -> question , & t -> cached_rcode , & t -> cached );
617+ r = dns_cache_lookup (& t -> scope -> cache , t -> key , & t -> cached_rcode , & t -> cached );
625618 if (r < 0 )
626619 return r ;
627620 if (r > 0 ) {
@@ -674,8 +667,8 @@ int dns_transaction_go(DnsTransaction *t) {
674667 return r ;
675668
676669 if (t -> scope -> protocol == DNS_PROTOCOL_LLMNR &&
677- (dns_question_endswith ( t -> question , "in-addr.arpa" ) > 0 ||
678- dns_question_endswith ( t -> question , "ip6.arpa" ) > 0 )) {
670+ (dns_name_endswith ( DNS_RESOURCE_KEY_NAME ( t -> key ) , "in-addr.arpa" ) > 0 ||
671+ dns_name_endswith ( DNS_RESOURCE_KEY_NAME ( t -> key ) , "ip6.arpa" ) > 0 )) {
679672
680673 /* RFC 4795, Section 2.4. says reverse lookups shall
681674 * always be made via TCP on LLMNR */
0 commit comments