Conversation
…haining In chained proxy scenarios where shadowsocks_2022 is preceded by another proxy (or another shadowsocks_2022 instance), parentDialer.DialContext returns a netproxy.Conn (such as FakeNetPacketConn or other protocol UDP wrappers) that does not implement standard library net.Conn. Previously, ListenPacket performed an unchecked type assertion conn.(net.Conn), causing a runtime panic: interface conversion: *FakeNetPacketConn is not net.Conn: missing method LocalAddr Changes: - UdpConn: embed netproxy.Conn instead of net.Conn (UdpConn only invokes Read/Write/Close and deadline controls from the underlay). - NewUdpConn / NewUdpConnWithContext: accept netproxy.Conn directly. - ListenPacket: pass the netproxy.Conn returned by parentDialer without an unsafe type assertion to net.Conn. - UdpConn & FakeNetPacketConn: add LocalAddr() and RemoteAddr() forwarding methods so they continue to satisfy net.Conn for any external consumer that asserts it. - dialer_test: add regression tests for chained UDP underlays backed by bare netproxy.Conn and chained shadowsocks_2022 dialers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
shadowsocks_2022is used as a downstream hop in a proxy chain (encountered in practice when runningdaewith chained-proxy nodes containing SS2022), UDP dialing triggers a runtime panic:In
ListenPacket,parentDialer.DialContext(...)returns anetproxy.Conn. For chained transports, the underlying connection satisfiesnetproxy.Connbut does not necessarily implement standard librarynet.Conn(LocalAddr/RemoteAddr). The unchecked type assertionconn.(net.Conn)panics.Solution
netproxy.Connfor UDP underlays:UdpConnonly requiresRead,Write,Close, and deadline controls from the underlying transport—it does not rely onLocalAddrorRemoteAddr. ChangedUdpConnto embednetproxy.Connand updated constructors accordingly.ListenPacket: Passed thenetproxy.Conndirectly without the unsafenet.Connassertion.LocalAddr()andRemoteAddr()to bothUdpConnandFakeNetPacketConnto forward inner transport addresses (or resolve the target address onFakeNetPacketConn), ensuring they satisfynet.Connfor any external callers asserting it.netproxy.Connunderlays and nestedshadowsocks_2022instances.