summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-07-16 18:03:46 +0200
committerLennart Poettering <lennart@poettering.net>2014-07-16 18:03:46 +0200
commit3cb10d3a0b1b6a7c44f307f2abb5215104e16941 (patch)
treeb6e20ffbbbb982bdff0766e69304866a5004c72e
parentacbc5016027950efd543e0b054e6370a8a4e17f9 (diff)
dns-domain: introduce macros for accessing all DNS header fields
-rw-r--r--src/resolve/resolved-bus.c14
-rw-r--r--src/resolve/resolved-dns-packet.c11
-rw-r--r--src/resolve/resolved-dns-packet.h33
-rw-r--r--src/resolve/resolved-manager.c4
4 files changed, 31 insertions, 31 deletions
diff --git a/src/resolve/resolved-bus.c b/src/resolve/resolved-bus.c
index e73bdacbbf..02e971dbf3 100644
--- a/src/resolve/resolved-bus.c
+++ b/src/resolve/resolved-bus.c
@@ -86,10 +86,9 @@ static void bus_method_resolve_hostname_complete(DnsQuery *q) {
if (r < 0)
goto finish;
- n = be16toh(DNS_PACKET_HEADER(q->packet)->ancount) +
- be16toh(DNS_PACKET_HEADER(q->packet)->nscount) +
- be16toh(DNS_PACKET_HEADER(q->packet)->arcount);
-
+ n = DNS_PACKET_ANCOUNT(q->packet) +
+ DNS_PACKET_NSCOUNT(q->packet) +
+ DNS_PACKET_ARCOUNT(q->packet);
for (i = 0; i < n; i++) {
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
@@ -292,10 +291,9 @@ static void bus_method_resolve_address_complete(DnsQuery *q) {
if (r < 0)
goto finish;
- n = be16toh(DNS_PACKET_HEADER(q->packet)->ancount) +
- be16toh(DNS_PACKET_HEADER(q->packet)->nscount) +
- be16toh(DNS_PACKET_HEADER(q->packet)->arcount);
-
+ n = DNS_PACKET_ANCOUNT(q->packet) +
+ DNS_PACKET_NSCOUNT(q->packet) +
+ DNS_PACKET_ARCOUNT(q->packet);
for (i = 0; i < n; i++) {
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c
index a503b01506..9aa0734213 100644
--- a/src/resolve/resolved-dns-packet.c
+++ b/src/resolve/resolved-dns-packet.c
@@ -116,7 +116,6 @@ int dns_packet_validate(DnsPacket *p) {
}
int dns_packet_validate_reply(DnsPacket *p) {
- DnsPacketHeader *h;
int r;
assert(p);
@@ -125,14 +124,10 @@ int dns_packet_validate_reply(DnsPacket *p) {
if (r < 0)
return r;
- h = DNS_PACKET_HEADER(p);
-
- /* Check QR field */
- if ((be16toh(h->flags) & 1) == 0)
+ if (DNS_PACKET_QR(p) == 0)
return -EBADMSG;
- /* Check opcode field */
- if (((be16toh(h->flags) >> 1) & 15) != 0)
+ if (DNS_PACKET_OPCODE(p) != 0)
return -EBADMSG;
return 0;
@@ -699,7 +694,7 @@ int dns_packet_skip_question(DnsPacket *p) {
unsigned i, n;
assert(p);
- n = be16toh(DNS_PACKET_HEADER(p)->qdcount);
+ n = DNS_PACKET_QDCOUNT(p);
for (i = 0; i < n; i++) {
_cleanup_(dns_resource_key_free) DnsResourceKey key = {};
diff --git a/src/resolve/resolved-dns-packet.h b/src/resolve/resolved-dns-packet.h
index 18ed4ba0d7..77edc05a19 100644
--- a/src/resolve/resolved-dns-packet.h
+++ b/src/resolve/resolved-dns-packet.h
@@ -62,6 +62,26 @@ static inline uint8_t* DNS_PACKET_DATA(DnsPacket *p) {
}
#define DNS_PACKET_HEADER(p) ((DnsPacketHeader*) DNS_PACKET_DATA(p))
+#define DNS_PACKET_ID(p) DNS_PACKET_HEADER(p)->id
+#define DNS_PACKET_QR(p) ((be16toh(DNS_PACKET_HEADER(p)->flags) >> 15) & 1)
+#define DNS_PACKET_OPCODE(p) ((be16toh(DNS_PACKET_HEADER(p)->flags) >> 11) & 15)
+#define DNS_PACKET_RCODE(p) (be16toh(DNS_PACKET_HEADER(p)->flags) & 15)
+#define DNS_PACKET_QDCOUNT(p) be16toh(DNS_PACKET_HEADER(p)->qdcount)
+#define DNS_PACKET_ANCOUNT(p) be16toh(DNS_PACKET_HEADER(p)->ancount)
+#define DNS_PACKET_NSCOUNT(p) be16toh(DNS_PACKET_HEADER(p)->nscount)
+#define DNS_PACKET_ARCOUNT(p) be16toh(DNS_PACKET_HEADER(p)->arcount)
+
+#define DNS_PACKET_MAKE_FLAGS(qr, opcode, aa, tc, rd, ra, ad, cd, rcode) \
+ (((uint16_t) !!qr << 15) | \
+ ((uint16_t) (opcode & 15) << 11) | \
+ ((uint16_t) !!aa << 10) | \
+ ((uint16_t) !!tc << 9) | \
+ ((uint16_t) !!rd << 8) | \
+ ((uint16_t) !!ra << 7) | \
+ ((uint16_t) !!ad << 5) | \
+ ((uint16_t) !!cd << 4) | \
+ ((uint16_t) (rcode & 15)))
+
int dns_packet_new(DnsPacket **p, size_t mtu);
int dns_packet_new_query(DnsPacket **p, size_t mtu);
@@ -92,19 +112,6 @@ int dns_packet_read_rr(DnsPacket *p, DnsResourceRecord **ret, size_t *start);
int dns_packet_skip_question(DnsPacket *p);
-#define DNS_PACKET_MAKE_FLAGS(qr, opcode, aa, tc, rd, ra, ad, cd, rcode) \
- (((uint16_t) !!qr << 15) | \
- ((uint16_t) (opcode & 15) << 11) | \
- ((uint16_t) !!aa << 10) | \
- ((uint16_t) !!tc << 9) | \
- ((uint16_t) !!rd << 8) | \
- ((uint16_t) !!ra << 7) | \
- ((uint16_t) !!ad << 5) | \
- ((uint16_t) !!cd << 4) | \
- ((uint16_t) (rcode & 15)))
-
-#define DNS_PACKET_RCODE(p) (be16toh(DNS_PACKET_HEADER(p)->flags) & 15)
-
enum {
DNS_RCODE_SUCCESS = 0,
DNS_RCODE_FORMERR = 1,
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index 8718ea40b2..09b758f3f4 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -653,7 +653,7 @@ static int on_dns_ipv4_packet(sd_event_source *s, int fd, uint32_t revents, void
if (r <= 0)
return r;
- t = hashmap_get(m->dns_query_transactions, UINT_TO_PTR(DNS_PACKET_HEADER(p)->id));
+ t = hashmap_get(m->dns_query_transactions, UINT_TO_PTR(DNS_PACKET_ID(p)));
if (!t)
return 0;
@@ -670,7 +670,7 @@ static int on_dns_ipv6_packet(sd_event_source *s, int fd, uint32_t revents, void
if (r <= 0)
return r;
- t = hashmap_get(m->dns_query_transactions, UINT_TO_PTR(DNS_PACKET_HEADER(p)->id));
+ t = hashmap_get(m->dns_query_transactions, UINT_TO_PTR(DNS_PACKET_ID(p)));
if (!t)
return 0;