dns icon indicating copy to clipboard operation
dns copied to clipboard

provide a way to set socket options

Open balboah opened this issue 2 months ago • 6 comments

What

  • ~~Allow 3rd parties to control socket options~~
  • Provide a way to retrieve the OOB destination information
  • Expose net.Conn, to be able to read unix.TCP_INFO

How

  • ~~Created a new listener param to set Control of net.ListenConfig~~
  • ~~Exposed internal OOB state with a new PacketConnState~~
  • Introduce parts of v2 dns that exposes a Session and Conn with the help of Conner interface

Why

I need this change to allow my CoreDNS plugin to:

  • ~~set the freebind socket option~~
  • read the destination IP from OOB information when using freebind sockopts
  • provide TCP RTT stats on linux by reading GetsockoptTCPInfo

If this gets accepted, I'll follow up with a PR in the CoreDNS repo for the socket control options

balboah avatar Nov 12 '25 11:11 balboah

I dunno

func ActivateAndServe(l net.Listener, p net.PacketConn, handler Handler) error { exists you can give it a listener and packetconn so any setup can be done when creating those, so this can be all handled externally.

miekg avatar Nov 12 '25 12:11 miekg

Thanks for the quick feedback! I totally missed that ActivateAndServe, you're right.

I've slimmed this PR down to focus on the exposing of OOB information and to be able to reach the net.Conn.

balboah avatar Nov 13 '25 10:11 balboah

I think what is need is to just expose the Conn in some way. In https://codeberg.org/miekg/dns/src/branch/main/response.go#L24 Conn() is an interface on responsewriter but we can't do this here. So instead of micro managing all access we should just defined a Conner interface and let the default response writer implement that and return the net.Conn is used. Then you can just do whatever the hell you want with the thing

miekg avatar Nov 13 '25 16:11 miekg

alright, I've made the changes regarding Conn. This works for my use-case of reading TCP_INFO.

But for the OOB destination data, this can't be fetched with the Conner interface, since this data is lost once the read happens. Would you be OK with keeping the PacketConnStater?

balboah avatar Nov 14 '25 10:11 balboah

I rather copy this than https://codeberg.org/miekg/dns/src/branch/main/response.go#L30

Have a Conner interface that returns a net.Conn plus a Session. So

type Conner interface {
     Conn() net.Conn
    Session() *Session
}

And copy the session code as well

miekg avatar Nov 15 '25 08:11 miekg

done and done!

balboah avatar Nov 17 '25 10:11 balboah