mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-07-03 10:18:42 +00:00
Config: Rename network/address/port in Tunnel inbound and DNS outbound (#6084)
https://github.com/XTLS/Xray-core/pull/6083#issuecomment-4387702965 https://github.com/XTLS/Xray-core/pull/6084#issuecomment-4395333530
This commit is contained in:
+24
-12
@@ -58,25 +58,37 @@ func (c *DNSOutboundRuleConfig) Build() (*dns.DNSRuleConfig, error) {
|
||||
}
|
||||
|
||||
type DNSOutboundConfig struct {
|
||||
Network Network `json:"network"`
|
||||
Address *Address `json:"address"`
|
||||
Port uint16 `json:"port"`
|
||||
UserLevel uint32 `json:"userLevel"`
|
||||
Rules []*DNSOutboundRuleConfig `json:"rules"`
|
||||
NonIPQuery *string `json:"nonIPQuery"` // todo: remove legacy
|
||||
BlockTypes *[]int32 `json:"blockTypes"` // todo: remove legacy
|
||||
RewriteNetwork Network `json:"rewriteNetwork"`
|
||||
RewriteAddress *Address `json:"rewriteAddress"`
|
||||
RewritePort uint16 `json:"rewritePort"`
|
||||
Network Network `json:"network"`
|
||||
Address *Address `json:"address"`
|
||||
Port uint16 `json:"port"`
|
||||
UserLevel uint32 `json:"userLevel"`
|
||||
Rules []*DNSOutboundRuleConfig `json:"rules"`
|
||||
NonIPQuery *string `json:"nonIPQuery"` // todo: remove legacy
|
||||
BlockTypes *[]int32 `json:"blockTypes"` // todo: remove legacy
|
||||
}
|
||||
|
||||
func (c *DNSOutboundConfig) Build() (proto.Message, error) {
|
||||
if len(c.Network) > 0 {
|
||||
c.RewriteNetwork = c.Network
|
||||
}
|
||||
if c.Address != nil {
|
||||
c.RewriteAddress = c.Address
|
||||
}
|
||||
if c.Port != 0 {
|
||||
c.RewritePort = c.Port
|
||||
}
|
||||
config := &dns.Config{
|
||||
Server: &net.Endpoint{
|
||||
Network: c.Network.Build(),
|
||||
Port: uint32(c.Port),
|
||||
RewriteServer: &net.Endpoint{
|
||||
Network: c.RewriteNetwork.Build(),
|
||||
Port: uint32(c.RewritePort),
|
||||
},
|
||||
UserLevel: c.UserLevel,
|
||||
}
|
||||
if c.Address != nil {
|
||||
config.Server.Address = c.Address.Build()
|
||||
if c.RewriteAddress != nil {
|
||||
config.RewriteServer.Address = c.RewriteAddress.Build()
|
||||
}
|
||||
|
||||
// todo: remove legacy
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestDnsProxyConfig(t *testing.T) {
|
||||
}`,
|
||||
Parser: loadJSON(creator),
|
||||
Output: &dns.Config{
|
||||
Server: &net.Endpoint{
|
||||
RewriteServer: &net.Endpoint{
|
||||
Network: net.Network_TCP,
|
||||
Address: net.NewIPOrDomain(net.IPAddress([]byte{8, 8, 8, 8})),
|
||||
Port: 53,
|
||||
@@ -44,7 +44,7 @@ func TestDnsProxyConfig(t *testing.T) {
|
||||
}`,
|
||||
Parser: loadJSON(creator),
|
||||
Output: &dns.Config{
|
||||
Server: &net.Endpoint{},
|
||||
RewriteServer: &net.Endpoint{},
|
||||
Rule: []*dns.DNSRuleConfig{
|
||||
{
|
||||
Action: dns.RuleAction_Direct,
|
||||
@@ -84,7 +84,7 @@ func TestDnsProxyConfig(t *testing.T) {
|
||||
}`,
|
||||
Parser: loadJSON(creator),
|
||||
Output: &dns.Config{
|
||||
Server: &net.Endpoint{},
|
||||
RewriteServer: &net.Endpoint{},
|
||||
Rule: []*dns.DNSRuleConfig{
|
||||
{
|
||||
Action: dns.RuleAction_Reject,
|
||||
@@ -111,7 +111,7 @@ func TestDnsProxyConfig(t *testing.T) {
|
||||
}`,
|
||||
Parser: loadJSON(creator),
|
||||
Output: &dns.Config{
|
||||
Server: &net.Endpoint{},
|
||||
RewriteServer: &net.Endpoint{},
|
||||
Rule: []*dns.DNSRuleConfig{
|
||||
{
|
||||
Action: dns.RuleAction_Drop,
|
||||
@@ -136,7 +136,7 @@ func TestDnsProxyConfigLegacyCompatibility(t *testing.T) {
|
||||
}`,
|
||||
Parser: loadJSON(creator),
|
||||
Output: &dns.Config{
|
||||
Server: &net.Endpoint{},
|
||||
RewriteServer: &net.Endpoint{},
|
||||
Rule: []*dns.DNSRuleConfig{
|
||||
{
|
||||
Action: dns.RuleAction_Hijack,
|
||||
@@ -154,7 +154,7 @@ func TestDnsProxyConfigLegacyCompatibility(t *testing.T) {
|
||||
}`,
|
||||
Parser: loadJSON(creator),
|
||||
Output: &dns.Config{
|
||||
Server: &net.Endpoint{},
|
||||
RewriteServer: &net.Endpoint{},
|
||||
Rule: []*dns.DNSRuleConfig{
|
||||
{
|
||||
Action: dns.RuleAction_Reject,
|
||||
@@ -177,7 +177,7 @@ func TestDnsProxyConfigLegacyCompatibility(t *testing.T) {
|
||||
}`,
|
||||
Parser: loadJSON(creator),
|
||||
Output: &dns.Config{
|
||||
Server: &net.Endpoint{},
|
||||
RewriteServer: &net.Endpoint{},
|
||||
Rule: []*dns.DNSRuleConfig{
|
||||
{
|
||||
Action: dns.RuleAction_Drop,
|
||||
@@ -200,7 +200,7 @@ func TestDnsProxyConfigLegacyCompatibility(t *testing.T) {
|
||||
}`,
|
||||
Parser: loadJSON(creator),
|
||||
Output: &dns.Config{
|
||||
Server: &net.Endpoint{},
|
||||
RewriteServer: &net.Endpoint{},
|
||||
Rule: []*dns.DNSRuleConfig{
|
||||
{
|
||||
Action: dns.RuleAction_Drop,
|
||||
|
||||
+18
-6
@@ -8,27 +8,39 @@ import (
|
||||
)
|
||||
|
||||
type DokodemoConfig struct {
|
||||
AllowedNetwork *NetworkList `json:"allowedNetwork"`
|
||||
RewriteAddress *Address `json:"rewriteAddress"`
|
||||
RewritePort uint16 `json:"rewritePort"`
|
||||
Network *NetworkList `json:"network"`
|
||||
Address *Address `json:"address"`
|
||||
Port uint16 `json:"port"`
|
||||
PortMap map[string]string `json:"portMap"`
|
||||
Network *NetworkList `json:"network"`
|
||||
FollowRedirect bool `json:"followRedirect"`
|
||||
UserLevel uint32 `json:"userLevel"`
|
||||
}
|
||||
|
||||
func (v *DokodemoConfig) Build() (proto.Message, error) {
|
||||
config := new(dokodemo.Config)
|
||||
if v.Address != nil {
|
||||
config.Address = v.Address.Build()
|
||||
if v.Network != nil {
|
||||
v.AllowedNetwork = v.Network
|
||||
}
|
||||
config.Port = uint32(v.Port)
|
||||
if v.Address != nil {
|
||||
v.RewriteAddress = v.Address
|
||||
}
|
||||
if v.Port != 0 {
|
||||
v.RewritePort = v.Port
|
||||
}
|
||||
config := new(dokodemo.Config)
|
||||
config.AllowedNetworks = v.AllowedNetwork.Build()
|
||||
if v.RewriteAddress != nil {
|
||||
config.RewriteAddress = v.RewriteAddress.Build()
|
||||
}
|
||||
config.RewritePort = uint32(v.RewritePort)
|
||||
config.PortMap = v.PortMap
|
||||
for _, v := range config.PortMap {
|
||||
if _, _, err := net.SplitHostPort(v); err != nil {
|
||||
return nil, errors.New("invalid portMap: ", v).Base(err)
|
||||
}
|
||||
}
|
||||
config.Networks = v.Network.Build()
|
||||
config.FollowRedirect = v.FollowRedirect
|
||||
config.UserLevel = v.UserLevel
|
||||
return config, nil
|
||||
|
||||
@@ -24,15 +24,15 @@ func TestDokodemoConfig(t *testing.T) {
|
||||
}`,
|
||||
Parser: loadJSON(creator),
|
||||
Output: &dokodemo.Config{
|
||||
Address: &net.IPOrDomain{
|
||||
RewriteAddress: &net.IPOrDomain{
|
||||
Address: &net.IPOrDomain_Ip{
|
||||
Ip: []byte{8, 8, 8, 8},
|
||||
},
|
||||
},
|
||||
Port: 53,
|
||||
Networks: []net.Network{net.Network_TCP},
|
||||
FollowRedirect: true,
|
||||
UserLevel: 1,
|
||||
RewritePort: 53,
|
||||
AllowedNetworks: []net.Network{net.Network_TCP},
|
||||
FollowRedirect: true,
|
||||
UserLevel: 1,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user