X Tutup
Skip to content

Commit fa4e74b

Browse files
committed
resolved: add new DnsAnswerFlags indicating originating section when parsing
Let's beef up our parser a bit: let's store in the DnsAnswerFlags field (that is stored as part of DnsAnswerItem) which DNS packet section (i.e. answer, authoritative, additional) an RR originates from. This is useful when propagating answers from an upstream DNS server eventually, as we can place the data in the right sections downstream too.
1 parent 9c5fcb8 commit fa4e74b

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

src/resolve/resolved-dns-answer.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,12 @@ void dns_answer_dump(DnsAnswer *answer, FILE *f) {
807807
fputs(" cache-flush", f);
808808
if (item->flags & DNS_ANSWER_GOODBYE)
809809
fputs(" goodbye", f);
810+
if (item->flags & DNS_ANSWER_SECTION_ANSWER)
811+
fputs(" section-answer", f);
812+
if (item->flags & DNS_ANSWER_SECTION_AUTHORITY)
813+
fputs(" section-authority", f);
814+
if (item->flags & DNS_ANSWER_SECTION_ADDITIONAL)
815+
fputs(" section-additional", f);
810816

811817
fputc('\n', f);
812818
}

src/resolve/resolved-dns-answer.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@ typedef struct DnsAnswerItem DnsAnswerItem;
88
#include "resolved-dns-rr.h"
99
#include "set.h"
1010

11-
/* A simple array of resource records. We keep track of the
12-
* originating ifindex for each RR where that makes sense, so that we
13-
* can qualify A and AAAA RRs referring to a local link with the
14-
* right ifindex.
11+
/* A simple array of resource records. We keep track of the originating ifindex for each RR where that makes
12+
* sense, so that we can qualify A and AAAA RRs referring to a local link with the right ifindex.
1513
*
1614
* Note that we usually encode the empty DnsAnswer object as a simple NULL. */
1715

1816
typedef enum DnsAnswerFlags {
19-
DNS_ANSWER_AUTHENTICATED = 1 << 0, /* Item has been authenticated */
20-
DNS_ANSWER_CACHEABLE = 1 << 1, /* Item is subject to caching */
21-
DNS_ANSWER_SHARED_OWNER = 1 << 2, /* For mDNS: RRset may be owner by multiple peers */
22-
DNS_ANSWER_CACHE_FLUSH = 1 << 3, /* For mDNS: sets cache-flush bit in the rrclass of response records */
23-
DNS_ANSWER_GOODBYE = 1 << 4, /* For mDNS: item is subject to disappear */
17+
DNS_ANSWER_AUTHENTICATED = 1 << 0, /* Item has been authenticated */
18+
DNS_ANSWER_CACHEABLE = 1 << 1, /* Item is subject to caching */
19+
DNS_ANSWER_SHARED_OWNER = 1 << 2, /* For mDNS: RRset may be owner by multiple peers */
20+
DNS_ANSWER_CACHE_FLUSH = 1 << 3, /* For mDNS: sets cache-flush bit in the rrclass of response records */
21+
DNS_ANSWER_GOODBYE = 1 << 4, /* For mDNS: item is subject to disappear */
22+
DNS_ANSWER_SECTION_ANSWER = 1 << 5, /* When parsing: RR originates from answer section */
23+
DNS_ANSWER_SECTION_AUTHORITY = 1 << 6, /* When parsing: RR originates from authority section */
24+
DNS_ANSWER_SECTION_ADDITIONAL = 1 << 7, /* When parsing: RR originates from additional section */
2425
} DnsAnswerFlags;
2526

2627
struct DnsAnswerItem {

src/resolve/resolved-dns-packet.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,12 +2322,20 @@ static int dns_packet_extract_answer(DnsPacket *p, DnsAnswer **ret_answer) {
23222322
assert(p->rindex >= start);
23232323
p->opt_size = p->rindex - start;
23242324
} else {
2325-
/* According to RFC 4795, section 2.9. only the RRs from the Answer section
2326-
* shall be cached. Hence mark only those RRs as cacheable by default, but
2327-
* not the ones from the Additional or Authority sections. */
2328-
DnsAnswerFlags flags =
2329-
(i < DNS_PACKET_ANCOUNT(p) ? DNS_ANSWER_CACHEABLE : 0) |
2330-
(p->protocol == DNS_PROTOCOL_MDNS && !cache_flush ? DNS_ANSWER_SHARED_OWNER : 0);
2325+
DnsAnswerFlags flags = 0;
2326+
2327+
if (p->protocol == DNS_PROTOCOL_MDNS && !cache_flush)
2328+
flags |= DNS_ANSWER_SHARED_OWNER;
2329+
2330+
/* According to RFC 4795, section 2.9. only the RRs from the Answer section shall be
2331+
* cached. Hence mark only those RRs as cacheable by default, but not the ones from
2332+
* the Additional or Authority sections. */
2333+
if (i < DNS_PACKET_ANCOUNT(p))
2334+
flags |= DNS_ANSWER_CACHEABLE|DNS_ANSWER_SECTION_ANSWER;
2335+
else if (i < DNS_PACKET_ANCOUNT(p) + DNS_PACKET_NSCOUNT(p))
2336+
flags |= DNS_ANSWER_SECTION_AUTHORITY;
2337+
else
2338+
flags |= DNS_ANSWER_SECTION_ADDITIONAL;
23312339

23322340
r = dns_answer_add(answer, rr, p->ifindex, flags);
23332341
if (r < 0)

0 commit comments

Comments
 (0)
X Tutup