Skip to content

Commit

Permalink
unified tproxy option
Browse files Browse the repository at this point in the history
  • Loading branch information
DarienRaymond committed Sep 17, 2018
1 parent 7f69766 commit 383b84e
Show file tree
Hide file tree
Showing 66 changed files with 503 additions and 335 deletions.
10 changes: 6 additions & 4 deletions app/commander/config.pb.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package commander

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import serial "v2ray.com/core/common/serial"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
serial "v2ray.com/core/common/serial"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
Expand Down
8 changes: 5 additions & 3 deletions app/dispatcher/config.pb.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package dispatcher

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
Expand Down
10 changes: 6 additions & 4 deletions app/dns/config.pb.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package dns

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import net "v2ray.com/core/common/net"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
net "v2ray.com/core/common/net"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
Expand Down
9 changes: 6 additions & 3 deletions app/log/command/config.pb.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package command

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
fmt "fmt"
math "math"

proto "github.com/golang/protobuf/proto"
)

import (
"context"
Expand Down
10 changes: 6 additions & 4 deletions app/log/config.pb.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package log

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import log "v2ray.com/core/common/log"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
log "v2ray.com/core/common/log"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
Expand Down
8 changes: 5 additions & 3 deletions app/policy/config.pb.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package policy

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
Expand Down
15 changes: 9 additions & 6 deletions app/proxyman/command/command.pb.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package command

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import core "v2ray.com/core"
import protocol "v2ray.com/core/common/protocol"
import serial "v2ray.com/core/common/serial"
import (
fmt "fmt"
math "math"

proto "github.com/golang/protobuf/proto"
core "v2ray.com/core"
protocol "v2ray.com/core/common/protocol"
serial "v2ray.com/core/common/serial"
)

import (
"context"
Expand Down
14 changes: 8 additions & 6 deletions app/proxyman/config.pb.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package proxyman

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import net "v2ray.com/core/common/net"
import serial "v2ray.com/core/common/serial"
import internet "v2ray.com/core/transport/internet"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
net "v2ray.com/core/common/net"
serial "v2ray.com/core/common/serial"
internet "v2ray.com/core/transport/internet"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
Expand Down
22 changes: 17 additions & 5 deletions app/proxyman/inbound/always.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,25 @@ func NewAlwaysOnInboundHandler(ctx context.Context, tag string, receiverConfig *
if address == nil {
address = net.AnyIP
}

mss, err := internet.ToMemoryStreamConfig(receiverConfig.StreamSettings)
if err != nil {
return nil, newError("failed to parse stream config").Base(err).AtWarning()
}

if receiverConfig.ReceiveOriginalDestination {
if mss.SocketSettings == nil {
mss.SocketSettings = &internet.SocketConfig{}
}
if mss.SocketSettings.Tproxy == internet.SocketConfig_Off {
mss.SocketSettings.Tproxy = internet.SocketConfig_Redirect
}
mss.SocketSettings.ReceiveOriginalDestAddress = true
}

for port := pr.From; port <= pr.To; port++ {
if nl.HasNetwork(net.Network_TCP) {
newError("creating stream worker on ", address, ":", port).AtDebug().WriteToLog()
mss, err := internet.ToMemoryStreamConfig(receiverConfig.StreamSettings)
if err != nil {
return nil, newError("failed to parse stream config").Base(err).AtWarning()
}

worker := &tcpWorker{
address: address,
Expand All @@ -98,10 +110,10 @@ func NewAlwaysOnInboundHandler(ctx context.Context, tag string, receiverConfig *
proxy: p,
address: address,
port: net.Port(port),
recvOrigDest: receiverConfig.ReceiveOriginalDestination,
dispatcher: h.mux,
uplinkCounter: uplinkCounter,
downlinkCounter: downlinkCounter,
stream: mss,
}
h.workers = append(h.workers, worker)
}
Expand Down
11 changes: 10 additions & 1 deletion app/proxyman/inbound/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ func NewDynamicInboundHandler(ctx context.Context, tag string, receiverConfig *p
if err != nil {
return nil, newError("failed to parse stream settings").Base(err).AtWarning()
}
if receiverConfig.ReceiveOriginalDestination {
if mss.SocketSettings == nil {
mss.SocketSettings = &internet.SocketConfig{}
}
if mss.SocketSettings.Tproxy == internet.SocketConfig_Off {
mss.SocketSettings.Tproxy = internet.SocketConfig_Redirect
}
mss.SocketSettings.ReceiveOriginalDestAddress = true
}

h.streamSettings = mss

Expand Down Expand Up @@ -139,10 +148,10 @@ func (h *DynamicInboundHandler) refresh() error {
proxy: p,
address: address,
port: port,
recvOrigDest: h.receiverConfig.ReceiveOriginalDestination,
dispatcher: h.mux,
uplinkCounter: uplinkCounter,
downlinkCounter: downlinkCounter,
stream: h.streamSettings,
}
if err := worker.Start(); err != nil {
newError("failed to create UDP worker").Base(err).AtWarning().WriteToLog()
Expand Down
5 changes: 3 additions & 2 deletions app/proxyman/inbound/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ type udpWorker struct {
hub *udp.Hub
address net.Address
port net.Port
recvOrigDest bool
tag string
stream *internet.MemoryStreamConfig
dispatcher core.Dispatcher
uplinkCounter core.StatCounter
downlinkCounter core.StatCounter
Expand Down Expand Up @@ -322,7 +322,8 @@ func (w *udpWorker) clean() error {

func (w *udpWorker) Start() error {
w.activeConn = make(map[connID]*udpConn, 16)
h, err := udp.ListenUDP(w.address, w.port, udp.HubReceiveOriginalDestination(w.recvOrigDest), udp.HubCapacity(256))
ctx := internet.ContextWithStreamSettings(context.Background(), w.stream)
h, err := udp.ListenUDP(ctx, w.address, w.port, udp.HubCapacity(256))
if err != nil {
return err
}
Expand Down
10 changes: 6 additions & 4 deletions app/router/config.pb.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package router

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import net "v2ray.com/core/common/net"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
net "v2ray.com/core/common/net"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
Expand Down
9 changes: 6 additions & 3 deletions app/stats/command/command.pb.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package command

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
fmt "fmt"
math "math"

proto "github.com/golang/protobuf/proto"
)

import (
"context"
Expand Down
8 changes: 5 additions & 3 deletions app/stats/config.pb.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package stats

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
Expand Down
8 changes: 5 additions & 3 deletions common/log/log.pb.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package log

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
Expand Down
8 changes: 5 additions & 3 deletions common/net/address.pb.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
Expand Down
8 changes: 5 additions & 3 deletions common/net/destination.pb.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
Expand Down
8 changes: 5 additions & 3 deletions common/net/network.pb.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
Expand Down
8 changes: 5 additions & 3 deletions common/net/port.pb.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
Expand Down
12 changes: 7 additions & 5 deletions common/protocol/command.pb.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package protocol

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import serial "v2ray.com/core/common/serial"
import internet "v2ray.com/core/transport/internet"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
serial "v2ray.com/core/common/serial"
internet "v2ray.com/core/transport/internet"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
Expand Down
8 changes: 5 additions & 3 deletions common/protocol/headers.pb.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package protocol

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
Expand Down
10 changes: 6 additions & 4 deletions common/protocol/server_spec.pb.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package protocol

import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import net "v2ray.com/core/common/net"
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
net "v2ray.com/core/common/net"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
Expand Down
Loading

0 comments on commit 383b84e

Please sign in to comment.