mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-30 05:56:54 -05:00
cleanup
This commit is contained in:
parent
1a8ed61b9b
commit
12a0d6e0b9
@ -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 {
|
||||
|
@ -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.")
|
||||
}
|
11
transport/internet/udp/source_forging.go
Normal file
11
transport/internet/udp/source_forging.go
Normal file
@ -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()
|
||||
}
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user