[ISSUE-95] Send replies from the right source IP address

Fixes #95

I didn't test this enough, but lets see what you have to say about it :)
I tried to keep it as simple as possible.

This has to be tested with IPv6. I guess that IPv6 is not supported yet (shouldn't be too hard to add IPv6 support though), but first lets make sure it doesn't break it.
[ Quoting <notifications@github.com> in "Re: [dns] [ISSUE-95] Send replies f..." ]
>> @@ -44,9 +44,10 @@ type response struct {
>>  	tsigTimersOnly bool
>>  	tsigRequestMAC string
>>  	tsigSecret     map[string]string // the tsig secrets
>> -	udp            *net.UDPConn      // i/o connection if UDP was used
>> -	tcp            *net.TCPConn      // i/o connection if TCP was used
>> -	remoteAddr     net.Addr          // address of the client
>> +	udp            *UDPConn          // i/o connection if UDP was used
>
>1. I didn't want to rewrite it too much, but here's what I had in mind:
>Because DNS is a request-response protocol, can we make the handling of UDP requests and TCP requests the same?
>i.e., you'll be dispatched with req, resp objects, once req is processed, you call resp.Write() with the response

Well, the current dns code tries to do this as so far this is possible with Go 
and the DNS protocol.

>2. Without the additional `setsockopt`, the OOB buffer is empty. Other than the 
>   memory overhead that you mentioned before, it doesn't really make a 
>   difference.
>   If the memory overhead is an issue (it'll probably be <128 bytes and not 
>   1024 like it is right now), we could try to think of a way of solving this.

As it stands I think Go DNS could do with less memory, so I'm a bit hesitant of 
just adding more.

>Why are you worried about this being enabled to 0.0.0.0 as well?

? The case we are solving is an edge case for UDP when listening on all 
interfaces. This being such an edge case I want protect the current code as much 
as possible (if possible).

>3. I mentioned that currently IPv6 is not supported, but it shouldn't break it 
>   (as I said, when the flags are missing, the OOB will simply be empty)
>IPv6 support should be pretty simple (as much as adding another `setsockopt`), I just need some to help testing it

I can help with that.

>As for a test case, what would you like it to test? Because this affects _all_ 
>requests, there's no point in testing the edge cases (like the one I presented 
>in my Vagrantfile)

As said, this will be longer term. I would like a test case that fails to reply 
with this disabled and working when enabled. But this is (I think) non trivial.

/Miek

-- 
Miek Gieben