fix: UDP packet should not return io.EOF

This commit is contained in:
wwqgtxx 2023-05-15 19:06:58 +08:00
parent 872a28a5eb
commit 1a9104c003
4 changed files with 11 additions and 8 deletions

View File

@ -3,7 +3,6 @@
package packet package packet
import ( import (
"io"
"net" "net"
"strconv" "strconv"
"syscall" "syscall"
@ -34,6 +33,7 @@ func (c *enhanceUDPConn) WaitReadFrom() (data []byte, put func(), addr net.Addr,
} else { } else {
put() put()
put = nil put = nil
data = nil
} }
if readErr == syscall.EAGAIN { if readErr == syscall.EAGAIN {
return false return false
@ -48,9 +48,10 @@ func (c *enhanceUDPConn) WaitReadFrom() (data []byte, put func(), addr net.Addr,
addr = &net.UDPAddr{IP: ip[:], Port: from.Port, Zone: strconv.FormatInt(int64(from.ZoneId), 10)} addr = &net.UDPAddr{IP: ip[:], Port: from.Port, Zone: strconv.FormatInt(int64(from.ZoneId), 10)}
} }
} }
if readN == 0 { // udp should not convert readN == 0 to io.EOF
readErr = io.EOF //if readN == 0 {
} // readErr = io.EOF
//}
return true return true
}) })
if err != nil { if err != nil {

2
go.mod
View File

@ -21,7 +21,7 @@ require (
github.com/mdlayher/netlink v1.7.2 github.com/mdlayher/netlink v1.7.2
github.com/metacubex/quic-go v0.33.3-0.20230510010206-687b537b6a58 github.com/metacubex/quic-go v0.33.3-0.20230510010206-687b537b6a58
github.com/metacubex/sing-shadowsocks v0.2.2-0.20230509230448-a5157cc00a1c github.com/metacubex/sing-shadowsocks v0.2.2-0.20230509230448-a5157cc00a1c
github.com/metacubex/sing-shadowsocks2 v0.0.0-20230511124108-b20f64384bdd github.com/metacubex/sing-shadowsocks2 v0.0.0-20230515071211-0c3604faef69
github.com/metacubex/sing-tun v0.1.5-0.20230509224930-30065d4b6376 github.com/metacubex/sing-tun v0.1.5-0.20230509224930-30065d4b6376
github.com/metacubex/sing-wireguard v0.0.0-20230426030325-41db09ae771a github.com/metacubex/sing-wireguard v0.0.0-20230426030325-41db09ae771a
github.com/miekg/dns v1.1.54 github.com/miekg/dns v1.1.54

4
go.sum
View File

@ -98,8 +98,8 @@ github.com/metacubex/quic-go v0.33.3-0.20230510010206-687b537b6a58 h1:E/sNW9tugF
github.com/metacubex/quic-go v0.33.3-0.20230510010206-687b537b6a58/go.mod h1:9nOiGX6kqV3+ZbkDKdTNzdFD726QQHPH6WDb36jUSpA= github.com/metacubex/quic-go v0.33.3-0.20230510010206-687b537b6a58/go.mod h1:9nOiGX6kqV3+ZbkDKdTNzdFD726QQHPH6WDb36jUSpA=
github.com/metacubex/sing-shadowsocks v0.2.2-0.20230509230448-a5157cc00a1c h1:LpVNvlW/xE+mR8z76xJeYZlYznZXEmU4TeWeuygYdJg= github.com/metacubex/sing-shadowsocks v0.2.2-0.20230509230448-a5157cc00a1c h1:LpVNvlW/xE+mR8z76xJeYZlYznZXEmU4TeWeuygYdJg=
github.com/metacubex/sing-shadowsocks v0.2.2-0.20230509230448-a5157cc00a1c/go.mod h1:4uQQReKMTU7KTfOykVBe/oGJ00pl38d+BYJ99+mx26s= github.com/metacubex/sing-shadowsocks v0.2.2-0.20230509230448-a5157cc00a1c/go.mod h1:4uQQReKMTU7KTfOykVBe/oGJ00pl38d+BYJ99+mx26s=
github.com/metacubex/sing-shadowsocks2 v0.0.0-20230511124108-b20f64384bdd h1:RXdD763CbvqaJOyFLAh6xa8xg7BZTkOJ0p8fBc7kB+w= github.com/metacubex/sing-shadowsocks2 v0.0.0-20230515071211-0c3604faef69 h1:6mwe6TyQUqjpqu8QwRlY5xR5VjENzXtM3LVRhjq00nw=
github.com/metacubex/sing-shadowsocks2 v0.0.0-20230511124108-b20f64384bdd/go.mod h1:r+JnKYxqLJIkRhpT9xb3b11icXsvM6yVjCxr2Smp1Og= github.com/metacubex/sing-shadowsocks2 v0.0.0-20230515071211-0c3604faef69/go.mod h1:r+JnKYxqLJIkRhpT9xb3b11icXsvM6yVjCxr2Smp1Og=
github.com/metacubex/sing-tun v0.1.5-0.20230509224930-30065d4b6376 h1:zKNsbFQyleMFAP7NJYRew9sEMJuniuODH3V0FdWnEtk= github.com/metacubex/sing-tun v0.1.5-0.20230509224930-30065d4b6376 h1:zKNsbFQyleMFAP7NJYRew9sEMJuniuODH3V0FdWnEtk=
github.com/metacubex/sing-tun v0.1.5-0.20230509224930-30065d4b6376/go.mod h1:BMfG00enVf90/CzcdX9PK3Dymgl7BZqHXJfexEyB7Cc= github.com/metacubex/sing-tun v0.1.5-0.20230509224930-30065d4b6376/go.mod h1:BMfG00enVf90/CzcdX9PK3Dymgl7BZqHXJfexEyB7Cc=
github.com/metacubex/sing-wireguard v0.0.0-20230426030325-41db09ae771a h1:cWKym33Qvl6HA3hj4/YuYD8hHyqQPb47wT5cJRAPgco= github.com/metacubex/sing-wireguard v0.0.0-20230426030325-41db09ae771a h1:cWKym33Qvl6HA3hj4/YuYD8hHyqQPb47wT5cJRAPgco=

View File

@ -55,7 +55,9 @@ func handleUDPToLocal(packet C.UDPPacket, pc N.EnhancePacketConn, key string, oA
} }
_, err = packet.WriteBack(data, fromUDPAddr) _, err = packet.WriteBack(data, fromUDPAddr)
if put != nil {
put() put()
}
if err != nil { if err != nil {
return return
} }