mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 09:18:34 +00:00
Enhance DNS and Dialer (#341)
This commit is contained in:
parent
ad1807dd99
commit
db32ce6fd9
22 changed files with 682 additions and 290 deletions
|
@ -19,6 +19,7 @@ type LogConfig struct {
|
|||
AccessLog string `json:"access"`
|
||||
ErrorLog string `json:"error"`
|
||||
LogLevel string `json:"loglevel"`
|
||||
DNSLog bool `json:"dnsLog"`
|
||||
}
|
||||
|
||||
func (v *LogConfig) Build() *log.Config {
|
||||
|
@ -28,6 +29,7 @@ func (v *LogConfig) Build() *log.Config {
|
|||
config := &log.Config{
|
||||
ErrorLogType: log.LogType_Console,
|
||||
AccessLogType: log.LogType_Console,
|
||||
EnableDnsLog: v.DNSLog,
|
||||
}
|
||||
|
||||
if v.AccessLog == "none" {
|
||||
|
|
|
@ -2,7 +2,7 @@ package conf
|
|||
|
||||
import (
|
||||
"github.com/xtls/xray-core/common/serial"
|
||||
"github.com/xtls/xray-core/transport"
|
||||
"github.com/xtls/xray-core/transport/global"
|
||||
"github.com/xtls/xray-core/transport/internet"
|
||||
)
|
||||
|
||||
|
@ -16,8 +16,8 @@ type TransportConfig struct {
|
|||
}
|
||||
|
||||
// Build implements Buildable.
|
||||
func (c *TransportConfig) Build() (*transport.Config, error) {
|
||||
config := new(transport.Config)
|
||||
func (c *TransportConfig) Build() (*global.Config, error) {
|
||||
config := new(global.Config)
|
||||
|
||||
if c.TCPConfig != nil {
|
||||
ts, err := c.TCPConfig.Build()
|
||||
|
|
|
@ -455,6 +455,8 @@ type SocketConfig struct {
|
|||
TFO interface{} `json:"tcpFastOpen"`
|
||||
TProxy string `json:"tproxy"`
|
||||
AcceptProxyProtocol bool `json:"acceptProxyProtocol"`
|
||||
DomainStrategy string `json:"domainStrategy"`
|
||||
DialerProxy string `json:"dialerProxy"`
|
||||
}
|
||||
|
||||
// Build implements Buildable.
|
||||
|
@ -487,11 +489,23 @@ func (c *SocketConfig) Build() (*internet.SocketConfig, error) {
|
|||
tproxy = internet.SocketConfig_Off
|
||||
}
|
||||
|
||||
var dStrategy = internet.DomainStrategy_AS_IS
|
||||
switch strings.ToLower(c.DomainStrategy) {
|
||||
case "useip", "use_ip":
|
||||
dStrategy = internet.DomainStrategy_USE_IP
|
||||
case "useip4", "useipv4", "use_ipv4", "use_ip_v4", "use_ip4":
|
||||
dStrategy = internet.DomainStrategy_USE_IP4
|
||||
case "useip6", "useipv6", "use_ipv6", "use_ip_v6", "use_ip6":
|
||||
dStrategy = internet.DomainStrategy_USE_IP6
|
||||
}
|
||||
|
||||
return &internet.SocketConfig{
|
||||
Mark: c.Mark,
|
||||
Tfo: tfo,
|
||||
Tproxy: tproxy,
|
||||
DomainStrategy: dStrategy,
|
||||
AcceptProxyProtocol: c.AcceptProxyProtocol,
|
||||
DialerProxy: c.DialerProxy,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -628,6 +642,9 @@ func (c *StreamConfig) Build() (*internet.StreamConfig, error) {
|
|||
|
||||
type ProxyConfig struct {
|
||||
Tag string `json:"tag"`
|
||||
|
||||
// TransportLayerProxy: For compatibility.
|
||||
TransportLayerProxy bool `json:"transportLayer"`
|
||||
}
|
||||
|
||||
// Build implements Buildable.
|
||||
|
@ -636,6 +653,7 @@ func (v *ProxyConfig) Build() (*internet.ProxyConfig, error) {
|
|||
return nil, newError("Proxy tag is not set.")
|
||||
}
|
||||
return &internet.ProxyConfig{
|
||||
Tag: v.Tag,
|
||||
Tag: v.Tag,
|
||||
TransportLayerProxy: v.TransportLayerProxy,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/common/serial"
|
||||
. "github.com/xtls/xray-core/infra/conf"
|
||||
"github.com/xtls/xray-core/transport"
|
||||
"github.com/xtls/xray-core/transport/global"
|
||||
"github.com/xtls/xray-core/transport/internet"
|
||||
"github.com/xtls/xray-core/transport/internet/headers/http"
|
||||
"github.com/xtls/xray-core/transport/internet/headers/noop"
|
||||
|
@ -34,12 +34,16 @@ func TestSocketConfig(t *testing.T) {
|
|||
{
|
||||
Input: `{
|
||||
"mark": 1,
|
||||
"tcpFastOpen": true
|
||||
"tcpFastOpen": true,
|
||||
"domainStrategy": "UseIP",
|
||||
"dialerProxy": "tag"
|
||||
}`,
|
||||
Parser: createParser(),
|
||||
Output: &internet.SocketConfig{
|
||||
Mark: 1,
|
||||
Tfo: 256,
|
||||
Mark: 1,
|
||||
Tfo: 256,
|
||||
DomainStrategy: internet.DomainStrategy_USE_IP,
|
||||
DialerProxy: "tag",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
@ -119,7 +123,7 @@ func TestTransportConfig(t *testing.T) {
|
|||
}
|
||||
}`,
|
||||
Parser: createParser(),
|
||||
Output: &transport.Config{
|
||||
Output: &global.Config{
|
||||
TransportSettings: []*internet.TransportConfig{
|
||||
{
|
||||
ProtocolName: "tcp",
|
||||
|
|
|
@ -2,6 +2,7 @@ package conf
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/xtls/xray-core/transport/internet"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
@ -267,9 +268,22 @@ type OutboundDetourConfig struct {
|
|||
MuxSettings *MuxConfig `json:"mux"`
|
||||
}
|
||||
|
||||
func (c *OutboundDetourConfig) checkChainProxyConfig() error {
|
||||
if c.StreamSetting == nil || c.ProxySettings == nil || c.StreamSetting.SocketSettings == nil {
|
||||
return nil
|
||||
}
|
||||
if len(c.ProxySettings.Tag) > 0 && len(c.StreamSetting.SocketSettings.DialerProxy) > 0 {
|
||||
return newError("proxySettings.tag is conflicted with sockopt.dialerProxy").AtWarning()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Build implements Buildable.
|
||||
func (c *OutboundDetourConfig) Build() (*core.OutboundHandlerConfig, error) {
|
||||
senderSettings := &proxyman.SenderConfig{}
|
||||
if err := c.checkChainProxyConfig(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if c.SendThrough != nil {
|
||||
address := c.SendThrough
|
||||
|
@ -295,6 +309,18 @@ func (c *OutboundDetourConfig) Build() (*core.OutboundHandlerConfig, error) {
|
|||
if err != nil {
|
||||
return nil, newError("invalid outbound detour proxy settings.").Base(err)
|
||||
}
|
||||
if ps.TransportLayerProxy {
|
||||
if senderSettings.StreamSettings != nil {
|
||||
if senderSettings.StreamSettings.SocketSettings != nil {
|
||||
senderSettings.StreamSettings.SocketSettings.DialerProxy = ps.Tag
|
||||
} else {
|
||||
senderSettings.StreamSettings.SocketSettings = &internet.SocketConfig{DialerProxy: ps.Tag}
|
||||
}
|
||||
} else {
|
||||
senderSettings.StreamSettings = &internet.StreamConfig{SocketSettings: &internet.SocketConfig{DialerProxy: ps.Tag}}
|
||||
}
|
||||
ps = nil
|
||||
}
|
||||
senderSettings.ProxySettings = ps
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue