provide a way to set socket options
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
Connerinterface
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
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.
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.
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
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?
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
done and done!