1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

Merge pull request #1525 from SAPikachu/dokodemo-udp

Fix UDP issue in Dokodemo TPROXY mode
This commit is contained in:
Victoria Raymond 2019-01-27 21:54:49 +01:00 committed by GitHub
commit 7bb5db712d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -117,6 +117,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
return nil
}
var tConn net.Conn
responseDone := func() error {
defer timer.SetTimeout(plcy.Timeouts.UplinkOnly)
@ -135,14 +136,28 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
sockopt.BindAddress = dest.Address.IP()
sockopt.BindPort = uint32(dest.Port)
}
tConn, err := internet.DialSystem(ctx, net.DestinationFromAddr(conn.RemoteAddr()), sockopt)
var err error
tConn, err = internet.DialSystem(ctx, net.DestinationFromAddr(conn.RemoteAddr()), sockopt)
if err != nil {
return err
}
writer = &buf.SequentialWriter{Writer: tConn}
tReader := buf.NewReader(tConn)
go func() {
defer tConn.Close()
defer common.Close(link.Writer)
if err := buf.Copy(tReader, link.Writer, buf.UpdateActivity(timer)); err != nil {
newError("failed to transport request (TPROXY conn)").Base(err).WriteToLog()
}
}()
}
}
defer func() {
if tConn != nil {
tConn.Close()
}
}()
if err := buf.Copy(link.Reader, writer, buf.UpdateActivity(timer)); err != nil {
return newError("failed to transport response").Base(err)
}
@ -153,6 +168,9 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
if err := task.Run(ctx, task.OnSuccess(requestDone, task.Close(link.Writer)), responseDone); err != nil {
common.Interrupt(link.Reader)
common.Interrupt(link.Writer)
if tConn != nil {
tConn.Close()
}
return newError("connection ends").Base(err)
}

View File

@ -70,6 +70,11 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
}
func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) error {
if config.Mark != 0 {
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_MARK, int(config.Mark)); err != nil {
return newError("failed to set SO_MARK").Base(err)
}
}
if isTCPSocket(network) {
switch config.Tfo {
case SocketConfig_Enable: