Metaswitch/cpp-common — pull request #226 by rkd-msw (2014-12-30 13:19:00+00:00)
Title: [Reviewer: Ellie] Further CNAME work

Builds on #225 to fix #224 more fully (but I think it's a bit more controversial which is why I pulled #225 out separately). With this change, if we get a DNS answer that contains a CNAME pointing at Y, and then some A/AAAA records for Y, we'll use them. For example, this will work:

```
news.bbc.co.uk 599 IN CNAME newswww.bbc.net.uk
newswww.bbc.net.uk 300 IN A 212.58.246.130
newswww.bbc.net.uk 300 IN A 212.58.246.129
```

but

```
newswww.bbc.net.uk 300 IN A 212.58.246.130
newswww.bbc.net.uk 300 IN A 212.58.246.129
news.bbc.co.uk 599 IN CNAME newswww.bbc.net.uk
```

will result in the two A records being thrown away with a LOG_WARNING. And if we just get:

`news.bbc.co.uk 599 IN CNAME newswww.bbc.net.uk`

we won't go away and do further A record lookups on the record pointed to by CNAME, we'll just report finding 0 A/AAAA records. Fortunately, the first style of answer is the only one I've seen, and I think RFC 1034 mandates it:

```
If recursive service is requested and available, the recursive response
to a query will be one of the following:

- The answer to the query, possibly preface by one or more CNAME
RRs that specify aliases encountered on the way to an answer.
```

so I think this is a good enough fix for the real world, and even in weird edge cases the behaviour will be reasonable (but not perfect).