Giter Site home page Giter Site logo

Comments (9)

andrewtj avatar andrewtj commented on July 19, 2024

Bert from PowerDNS blogged about this a while back. It's the wrong end of the day for me so I haven't refreshed myself on the details or dug into go's syscall/net interfaces to see how much trouble it'd be. I'll take a look tomorrow if no one else does.

from dns.

miekg avatar miekg commented on July 19, 2024

Some magic syscall.SetsockOptInt might do the trick. I have a bug open for this on skydns as well

from dns.

omribahumi avatar omribahumi commented on July 19, 2024

I've played with this a bit, got it working on Linux, but not on OSX.
I'll keep trying

Here is my progress:
https://gist.github.com/omribahumi/5da8517497042152691e

from dns.

miekg avatar miekg commented on July 19, 2024

[ Quoting [email protected] in "Re: [dns] Send UDP DNS responses fr..." ]

I've played with this a bit, got it working on Linux, but not on OSX.
I'll keep trying

Here is my progress:
https://gist.github.com/omribahumi/5da8517497042152691e

And the magic there is this line?

 syscall.SetsockoptInt(int(file.Fd()), syscall.IPPROTO_IP, 
 syscall.IP_PKTINFO, 1)

Sadly not portable as you say.

I wonder if this is a broader Go UDP issue, i.e. if we should look
for a solution in Go itself instead of fixing it here.

Thanks for your effort(s), I might have some time this weekend to also look
into this.

/Miek

Miek Gieben

from dns.

omribahumi avatar omribahumi commented on July 19, 2024

Not that simple. You should also be using ReadMsgUDP() instead of RecvFromUDP().
Then, the oob data contains the structs syscall.Cmsghdr and syscall.Inet4Pktinfo, which contains the information we need.

According to Google (and the BSD man pages), the exact same implementation should be working with OSX, just by changing the setsockopt() line to:

syscall.SetsockoptInt(int(file.Fd()), syscall.IPPROTO_IP, syscall.IP_RECVDSTADDR, 1)

But it returns invalid argument err. I've also tried

syscall.SetsockoptByte(int(file.Fd()), syscall.IPPROTO_IP, syscall.IP_RECVDSTADDR, 1)

But it yields the same results (setsockopt() failing). I'm not sure why.
The setsockopt() call works in Python. I even made sure the constants are right (0 and 7, respectively).

As for the Go way of solving this - I couldn't find any, but maybe the force is just stronger with you :)

Waiting for your feedback. Thanks

from dns.

miekg avatar miekg commented on July 19, 2024

Hmm. Thanks for the thorough update.

To frame the problem state properly: this is only a problem when listening
on 0.0.0.0.for UDP.

But I also agree a elegant solution would be nice.
On 4 Jul 2014 22:13, "Omri Bahumi" [email protected] wrote:

Not that simple. You should also be using ReadMsgUDP() instead of
RecvFromUDP().
Then, the oob data contains the structs syscall.Cmsghdr and
syscall.Inet4Pktinfo, which contains the information we need.

According to Google (and the BSD man pages), the exact same implementation
should be working with OSX, just by changing the setsockopt() line to:

syscall.SetsockoptInt(int(file.Fd()), syscall.IPPROTO_IP, syscall.IP_RECVDSTADDR, 1)

But it returns invalid argument err. I've also tried

syscall.SetsockoptByte(int(file.Fd()), syscall.IPPROTO_IP, syscall.IP_RECVDSTADDR, 1)

But it yields the same results (setsockopt() failing). I'm not sure why.
The setsockopt() call works in Python. I even made sure the constants are
right (0 and 7, respectively).

As for the Go way of solving this - I couldn't find any, but maybe the
force is just stronger with you :)

Waiting for your feedback. Thanks


Reply to this email directly or view it on GitHub
#95 (comment).

from dns.

omribahumi avatar omribahumi commented on July 19, 2024

Another update:
https://code.google.com/p/go/issues/detail?id=8329&thanks=8329&ts=1404510948

:)

from dns.

omribahumi avatar omribahumi commented on July 19, 2024

@miekg how would you feel about it if I'd fix it only for Linux (preserving the old behavior for OSX)?

from dns.

miekg avatar miekg commented on July 19, 2024

[ Quoting [email protected] in "Re: [dns] Send UDP DNS responses fr..." ]

@miekg how would you feel about it if I'd fix it only for Linux (preserving the old behavior for OSX)?

I think that is OK and having an pull request make it easier to reason about it.

It might be worth putting this in a seperate file to make it easier to contain
(think that is needed anyway to make it compile for Linux only)

/Miek

Miek Gieben

from dns.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.