]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: Fix endiness issue in DNS header creation code
authorNenad Merdanovic <nmerdan@anine.io>
Wed, 13 Jul 2016 12:03:43 +0000 (14:03 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 13 Jul 2016 12:47:58 +0000 (14:47 +0200)
Alexander Lebedev reported that the response bit is set on SPARC when
DNS queries are sent. This has been tracked to the endianess issue, so
this patch makes the code portable.

Signed-off-by: Nenad Merdanovic <nmerdan@anine.io>
include/types/dns.h
src/dns.c

index 50636fd1fa71396c472b01eb6dada5fbe7b36c74..1b240fae4ce17819dc17fb2f9b6cbfa8b36e605a 100644 (file)
 
 /* DNS request or response header structure */
 struct dns_header {
-       unsigned short  id:16;          /* identifier */
-       unsigned char   rd :1;          /* recursion desired 0: no, 1: yes */
-       unsigned char   tc :1;          /* truncation 0:no, 1: yes */
-       unsigned char   aa :1;          /* authoritative answer 0: no, 1: yes */
-       unsigned char   opcode :4;      /* operation code */
-       unsigned char   qr :1;          /* query/response 0: query, 1: response */
-       unsigned char   rcode :4;       /* response code */
-       unsigned char   cd :1;          /* checking disabled */
-       unsigned char   ad :1;          /* authentic data */
-       unsigned char   z :1;           /* not used */
-       unsigned char   ra :1;          /* recursion available 0: no, 1: yes */
-       unsigned short  qdcount :16;    /* question count */
-       unsigned short  ancount :16;    /* answer count */
-       unsigned short  nscount :16;    /* authority count */
-       unsigned short  arcount :16;    /* additional count */
-};
+       uint16_t id;
+       uint16_t flags;
+       uint16_t qdcount;
+       uint16_t ancount;
+       uint16_t nscount;
+       uint16_t arcount;
+} __attribute__ ((packed));
 
 /* short structure to describe a DNS question */
 struct dns_question {
index bf5baa0c721f480f83aed34307d57b6900bce223..7f4c59ad972b3cd9a8eaedfe1b727c3d69424243 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -988,14 +988,7 @@ int dns_build_query(int query_id, int query_type, char *hostname_dn, int hostnam
        /* set dns query headers */
        dns = (struct dns_header *)ptr;
        dns->id = (unsigned short) htons(query_id);
-       dns->qr = 0;                    /* query */
-       dns->opcode = 0;
-       dns->aa = 0;
-       dns->tc = 0;
-       dns->rd = 1;                    /* recursion desired */
-       dns->ra = 0;
-       dns->z = 0;
-       dns->rcode = 0;
+       dns->flags = htons(0x0100); /* qr=0, opcode=0, aa=0, tc=0, rd=1, ra=0, z=0, rcode=0 */
        dns->qdcount = htons(1);        /* 1 question */
        dns->ancount = 0;
        dns->nscount = 0;