Hi Nenad,

On Wed, Jul 13, 2016 at 03:47:39AM +0200, Nenad Merdanovic wrote:
> Hello Alexander,
> 
> On 7/12/2016 2:57 PM, Nenad Merdanovic wrote:
> > Hello,
> > 
> > On 7/12/2016 1:13 PM, Alexander Lebedev wrote:
> >> Hi! On Solaris10/SPARC I see this issue with 1.6.6 and 1.6.3 (before
> >> Vincent commit).
> >> Haproxy sends queries with "response" bit.
> >> Maybe it is again alignment issue?
> 
> Can you try the attached patch? I don't have access to a SPARC machine
> (or anything big-endian TBH), so can't test myself. I tested on
> Linux/x86 and it works correctly.

I have one, with Solaris 8. I can start it (but not before this week-end
because its battery is dead and every time I have to recall how to pass
the boot parameters by hand).

Also for endian issues, PPC and MIPS are often in big endian. Similarly
for uncommon conventions, most ARM platform use unsigned chars by default
and some/most PPC do as well. When your code runs on at least a MIPS, an
ARM and an x86_64, you can consider you're quite safe.

I'll send you some instructions to build for your aloha pocket when I
have time, you'll see that things can break more often than you expect
on un safe code :-)

Just two comments below :

>  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));

I didn't remember we had this. It's pretty clear that the bit-oriented
code cannot work without a #ifdef for endianess reasons!

>  /* short structure to describe a DNS question */
>  struct dns_question {
> diff --git a/src/dns.c b/src/dns.c
> index 3b3dfc5..2e4d889 100644
> --- 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);

Do you mean that these bits are never used anywhere else ? If this
code works (I think it will), please add a comment at the end of the
0x100 to mention the bit values, in case someone wants to modify one
later or just for testing purposes. Eg here it will be something like
aa=0, rc=0, rd=1 etc...

thanks!
Willy

Reply via email to