diff --git a/proxy/dokodemo/dokodemo.go b/proxy/dokodemo/dokodemo.go index 4ae5047ae..0c4136d3b 100644 --- a/proxy/dokodemo/dokodemo.go +++ b/proxy/dokodemo/dokodemo.go @@ -7,8 +7,6 @@ import ( "runtime" "time" - gonet "net" - "v2ray.com/core/app" "v2ray.com/core/app/dispatcher" "v2ray.com/core/app/log" @@ -95,14 +93,13 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in if !d.config.FollowRedirect { writer = buf.NewSequentialWriter(conn) } else { - srca := gonet.UDPAddr{IP: dest.Address.IP(), Port: int(dest.Port.Value())} + srca := net.UDPAddr{IP: dest.Address.IP(), Port: int(dest.Port.Value())} origsend, err := udp.TransmitSocket(&srca, conn.RemoteAddr()) if err != nil { return err } writer = buf.NewSequentialWriter(origsend) } - } if err := buf.Copy(inboundRay.InboundOutput(), writer, buf.UpdateActivity(timer)); err != nil { diff --git a/transport/internet/udp/sourceForgeSender_bad.go b/transport/internet/udp/sourceForgeSender_bad.go deleted file mode 100644 index dadd40234..000000000 --- a/transport/internet/udp/sourceForgeSender_bad.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build !linux - -package udp - -import ( - "errors" - "net" -) - -func TransmitionSocket(src net.Addr, dst net.Addr) (net.Conn, error) { - return nil, errors.New("Using an Linux only functionality on an non-Linux OS.") -} diff --git a/transport/internet/udp/source_forging.go b/transport/internet/udp/source_forging.go new file mode 100644 index 000000000..caa935343 --- /dev/null +++ b/transport/internet/udp/source_forging.go @@ -0,0 +1,11 @@ +// +build !linux + +package udp + +import ( + "net" +) + +func TransmitSocket(src net.Addr, dst net.Addr) (net.Conn, error) { + return nil, newError("forging source address is not supported on non-Linux platform.").AtWarning() +} diff --git a/transport/internet/udp/sourceForgeSender.go b/transport/internet/udp/source_forging_linux.go similarity index 69% rename from transport/internet/udp/sourceForgeSender.go rename to transport/internet/udp/source_forging_linux.go index 31d03a9e8..238519b37 100644 --- a/transport/internet/udp/sourceForgeSender.go +++ b/transport/internet/udp/source_forging_linux.go @@ -14,16 +14,16 @@ func TransmitSocket(src net.Addr, dst net.Addr) (net.Conn, error) { var err error fd, err = syscall.Socket(syscall.AF_INET, syscall.SOCK_DGRAM, 0) if err != nil { - return nil, err + return nil, newError("failed to create fd").Base(err).AtWarning() } err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1) if err != nil { - return nil, err + return nil, newError("failed to set resuse_addr").Base(err).AtWarning() } err = syscall.SetsockoptInt(fd, syscall.SOL_IP, syscall.IP_TRANSPARENT, 1) if err != nil { - return nil, err + return nil, newError("failed to set transparent").Base(err).AtWarning() } ip := src.(*net.UDPAddr).IP.To4() @@ -34,7 +34,7 @@ func TransmitSocket(src net.Addr, dst net.Addr) (net.Conn, error) { srcaddr.Port = src.(*net.UDPAddr).Port err = syscall.Bind(fd, &srcaddr) if err != nil { - return nil, err + return nil, newError("failed to bind source address").Base(err).AtWarning() } ipd := dst.(*net.UDPAddr).IP.To4() var ip2d [4]byte @@ -44,12 +44,12 @@ func TransmitSocket(src net.Addr, dst net.Addr) (net.Conn, error) { dstaddr.Port = dst.(*net.UDPAddr).Port err = syscall.Connect(fd, &dstaddr) if err != nil { - return nil, err + return nil, newError("failed to connect to source address").Base(err).AtWarning() } fdf := os.NewFile(uintptr(fd), "/dev/udp/") c, err := net.FileConn(fdf) if err != nil { - return nil, err + return nil, newError("failed to create file conn").Base(err).AtWarning() } return c, nil }