mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-15 01:09:20 +02:00
Parse port in dns address
This commit is contained in:
parent
710b283204
commit
486f96838d
|
@ -3,6 +3,7 @@ package conf
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/app/dns"
|
"github.com/xtls/xray-core/app/dns"
|
||||||
|
@ -19,28 +20,39 @@ type NameServerConfig struct {
|
||||||
ExpectIPs StringList
|
ExpectIPs StringList
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *NameServerConfig) UnmarshalJSON(data []byte) error {
|
func (c *NameServerConfig) UnmarshalJSON(data []byte) (err error) {
|
||||||
var address Address
|
var address Address
|
||||||
if err := json.Unmarshal(data, &address); err == nil {
|
if err = json.Unmarshal(data, &address); err == nil {
|
||||||
c.Address = &address
|
c.Address = &address
|
||||||
return nil
|
} else {
|
||||||
|
var advanced struct {
|
||||||
|
Address *Address `json:"address"`
|
||||||
|
ClientIP *Address `json:"clientIp"`
|
||||||
|
Port uint16 `json:"port"`
|
||||||
|
SkipFallback bool `json:"skipFallback"`
|
||||||
|
Domains []string `json:"domains"`
|
||||||
|
ExpectIPs StringList `json:"expectIps"`
|
||||||
|
}
|
||||||
|
if err = json.Unmarshal(data, &advanced); err == nil {
|
||||||
|
c.Address = advanced.Address
|
||||||
|
c.ClientIP = advanced.ClientIP
|
||||||
|
c.Port = advanced.Port
|
||||||
|
c.SkipFallback = advanced.SkipFallback
|
||||||
|
c.Domains = advanced.Domains
|
||||||
|
c.ExpectIPs = advanced.ExpectIPs
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var advanced struct {
|
if err == nil {
|
||||||
Address *Address `json:"address"`
|
if c.Port == 0 && c.Address.Family().IsDomain() {
|
||||||
ClientIP *Address `json:"clientIp"`
|
if host, port, err := net.SplitHostPort(c.Address.Domain()); err == nil {
|
||||||
Port uint16 `json:"port"`
|
port, err := strconv.Atoi(port)
|
||||||
SkipFallback bool `json:"skipFallback"`
|
if err == nil {
|
||||||
Domains []string `json:"domains"`
|
c.Address = &Address{Address: net.ParseAddress(host)}
|
||||||
ExpectIPs StringList `json:"expectIps"`
|
c.Port = uint16(port)
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(data, &advanced); err == nil {
|
}
|
||||||
c.Address = advanced.Address
|
}
|
||||||
c.ClientIP = advanced.ClientIP
|
|
||||||
c.Port = advanced.Port
|
|
||||||
c.SkipFallback = advanced.SkipFallback
|
|
||||||
c.Domains = advanced.Domains
|
|
||||||
c.ExpectIPs = advanced.ExpectIPs
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue