File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import (
1313 "github.com/sagernet/gvisor/pkg/tcpip/header"
1414 "github.com/sagernet/gvisor/pkg/tcpip/stack"
1515 "github.com/sagernet/sing/common/buf"
16+ E "github.com/sagernet/sing/common/exceptions"
1617 M "github.com/sagernet/sing/common/metadata"
1718 N "github.com/sagernet/sing/common/network"
1819 "github.com/sagernet/sing/common/udpnat"
@@ -62,6 +63,12 @@ type UDPBackWriter struct {
6263}
6364
6465func (w * UDPBackWriter ) WritePacket (packetBuffer * buf.Buffer , destination M.Socksaddr ) error {
66+ if destination .IsIPv4 () && w .sourceNetwork == header .IPv6ProtocolNumber {
67+ destination = M .SocksaddrFrom (netip .AddrFrom16 (destination .Addr .As16 ()), destination .Port )
68+ } else if destination .IsIPv6 () && (w .sourceNetwork == header .IPv4AddressSizeBits ) {
69+ return E .New ("send IPv6 packet to IPv4 connection" )
70+ }
71+
6572 defer packetBuffer .Release ()
6673
6774 route , err := w .stack .FindRoute (
You can’t perform that action at this time.
0 commit comments