You've already forked v2ray-core
Apply sockopt from inbound config to dokodemo tproxy's response connection
This commit is contained in:
@@ -27,7 +27,7 @@ func init() {
|
||||
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
||||
d := new(DokodemoDoor)
|
||||
err := core.RequireFeatures(ctx, func(pm policy.Manager) error {
|
||||
return d.Init(config.(*Config), pm)
|
||||
return d.Init(config.(*Config), pm, session.SockoptFromContext(ctx))
|
||||
})
|
||||
return d, err
|
||||
}))
|
||||
@@ -38,10 +38,11 @@ type DokodemoDoor struct {
|
||||
config *Config
|
||||
address net.Address
|
||||
port net.Port
|
||||
sockopt *session.Sockopt
|
||||
}
|
||||
|
||||
// Init initializes the DokodemoDoor instance with necessary parameters.
|
||||
func (d *DokodemoDoor) Init(config *Config, pm policy.Manager) error {
|
||||
func (d *DokodemoDoor) Init(config *Config, pm policy.Manager, sockopt *session.Sockopt) error {
|
||||
if (config.NetworkList == nil || len(config.NetworkList.Network) == 0) && len(config.Networks) == 0 {
|
||||
return newError("no network specified")
|
||||
}
|
||||
@@ -49,6 +50,7 @@ func (d *DokodemoDoor) Init(config *Config, pm policy.Manager) error {
|
||||
d.address = config.GetPredefinedAddress()
|
||||
d.port = net.Port(config.Port)
|
||||
d.policyManager = pm
|
||||
d.sockopt = sockopt
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -165,6 +167,9 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
|
||||
sockopt.BindAddress = dest.Address.IP()
|
||||
sockopt.BindPort = uint32(dest.Port)
|
||||
}
|
||||
if d.sockopt != nil {
|
||||
sockopt.Mark = d.sockopt.Mark
|
||||
}
|
||||
tConn, err := internet.DialSystem(ctx, net.DestinationFromAddr(conn.RemoteAddr()), sockopt)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user