Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only treat a *net.UnixConn of unixgram as a packet conn #1322

Merged
merged 4 commits into from Dec 28, 2021

Conversation

tmthrgd
Copy link
Collaborator

@tmthrgd tmthrgd commented Dec 28, 2021

Go supports three different types of unix connections SOCK_STREAM (unix), SOCK_DGRAM (unixgram) and SOCK_SEQPACKET (unixpacket) all of which are *net.UnixConns. That means *net.UnixConn always implements net.PacketConn regardless of the socket type, though certain methods will return errors.

SOCK_DGRAM is the only one we want to treat as a packet connection and use the UDP framing for (IIUC). To do this we special case *net.UnixConns and only treat SOCK_DGRAM as a net.PacketConn.

This will make it possible to properly use the DNS client over unix SOCK_STREAM connections (the most common type).

Fixes #1321

@tmthrgd tmthrgd requested a review from miekg December 28, 2021 13:34
@tmthrgd tmthrgd mentioned this pull request Dec 28, 2021
@tmthrgd
Copy link
Collaborator Author

tmthrgd commented Dec 28, 2021

@jan-bar Could you please test this and see if it fixes your issue?

@miekg miekg merged commit 0544c8b into miekg:master Dec 28, 2021
@jan-bar
Copy link

jan-bar commented Dec 28, 2021

@jan-bar Could you please test this and see if it fixes your issue?

Unfortunately, the server I need to connect to is of the unix type, I tried to use the unixgram type, and the server returned an error connect: protocol wrong type for socket. But if I modify the unixgram in your code to unix, it can be used normally. Thank you for your contribution.

@tmthrgd tmthrgd deleted the unixconn branch December 31, 2021 01:25
joliveirinha added a commit to joliveirinha/dns that referenced this pull request Jun 8, 2022
miekg pushed a commit that referenced this pull request Jun 8, 2022
aanm pushed a commit to cilium/dns that referenced this pull request Jul 29, 2022
* Refactor net.PacketConn checks into helper function

* Only treat a *net.UnixConn of unixgram as a packet conn

* Handle wrapped net.Conn types in isPacketConn

* Use Error instead of Fatal where appropriate in TestIsPacketConn
aanm pushed a commit to cilium/dns that referenced this pull request Jul 29, 2022
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.

not support unix socks
3 participants