Skip to content

provide a way to set socket options#1687

Open
balboah wants to merge 1 commit intomiekg:masterfrom
balboah:feature/socket_controls
Open

provide a way to set socket options#1687
balboah wants to merge 1 commit intomiekg:masterfrom
balboah:feature/socket_controls

Conversation

@balboah
Copy link

@balboah balboah commented Nov 12, 2025

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 balboah force-pushed the feature/socket_controls branch from f76c74f to 9c6a757 Compare November 12, 2025 12:29
@miekg
Copy link
Owner

miekg commented Nov 12, 2025

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.

@balboah balboah force-pushed the feature/socket_controls branch 2 times, most recently from e72ce07 to de4f5c0 Compare November 13, 2025 10:22
@balboah
Copy link
Author

balboah commented Nov 13, 2025

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.

@miekg
Copy link
Owner

miekg commented Nov 13, 2025

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

@balboah balboah force-pushed the feature/socket_controls branch from de4f5c0 to a45e3dc Compare November 14, 2025 10:39
@balboah
Copy link
Author

balboah commented Nov 14, 2025

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?

@miekg
Copy link
Owner

miekg commented Nov 15, 2025

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

- Allow 3rd parties to control socket options
- Provide a way to retrieve oob destination information
@balboah balboah force-pushed the feature/socket_controls branch from a45e3dc to 29f17b4 Compare November 17, 2025 10:18
@balboah
Copy link
Author

balboah commented Nov 17, 2025

done and done!

@miekg
Copy link
Owner

miekg commented Jan 15, 2026

been busy, but I'll take a look.

this is likely that last feature-PR that will be merged here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants