mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-05-05 19:58:41 +00:00
Feat: sniffer exclude domain & ip
This commit is contained in:
parent
14189eba07
commit
06fc82bad1
31 changed files with 653 additions and 411 deletions
|
@ -1,4 +1,4 @@
|
|||
package conf
|
||||
package common
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
@ -9,6 +9,8 @@ import (
|
|||
"github.com/xtls/xray-core/common/protocol"
|
||||
)
|
||||
|
||||
//go:generate go run github.com/xtls/xray-core/common/errors/errorgen
|
||||
|
||||
type StringList []string
|
||||
|
||||
func NewStringList(raw []string) *StringList {
|
|
@ -1,4 +1,4 @@
|
|||
package conf_test
|
||||
package common_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
@ -11,7 +11,7 @@ import (
|
|||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
. "github.com/xtls/xray-core/infra/conf"
|
||||
. "github.com/xtls/xray-core/infra/conf/common"
|
||||
)
|
||||
|
||||
func TestStringListUnmarshalError(t *testing.T) {
|
9
infra/conf/common/errors.generated.go
Normal file
9
infra/conf/common/errors.generated.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package common
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -2,6 +2,8 @@ package conf
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/xtls/xray-core/common/matcher/geoip"
|
||||
"github.com/xtls/xray-core/infra/conf/common"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
|
@ -13,24 +15,24 @@ import (
|
|||
)
|
||||
|
||||
type NameServerConfig struct {
|
||||
Address *Address
|
||||
Address *common.Address
|
||||
Port uint16
|
||||
Domains []string
|
||||
ExpectIPs StringList
|
||||
ExpectIPs common.StringList
|
||||
}
|
||||
|
||||
func (c *NameServerConfig) UnmarshalJSON(data []byte) error {
|
||||
var address Address
|
||||
var address common.Address
|
||||
if err := json.Unmarshal(data, &address); err == nil {
|
||||
c.Address = &address
|
||||
return nil
|
||||
}
|
||||
|
||||
var advanced struct {
|
||||
Address *Address `json:"address"`
|
||||
Port uint16 `json:"port"`
|
||||
Domains []string `json:"domains"`
|
||||
ExpectIPs StringList `json:"expectIps"`
|
||||
Address *common.Address `json:"address"`
|
||||
Port uint16 `json:"port"`
|
||||
Domains []string `json:"domains"`
|
||||
ExpectIPs common.StringList `json:"expectIps"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &advanced); err == nil {
|
||||
c.Address = advanced.Address
|
||||
|
@ -52,7 +54,7 @@ func (c *NameServerConfig) Build() (*dns.NameServer, error) {
|
|||
var originalRules []*dns.NameServer_OriginalRule
|
||||
|
||||
for _, rule := range c.Domains {
|
||||
parsedDomain, err := conf.ParaseDomainRule(rule)
|
||||
parsedDomain, err := conf.ParseDomainRule(rule)
|
||||
if err != nil {
|
||||
return nil, newError("invalid domain rule: ", rule).Base(err)
|
||||
}
|
||||
|
@ -69,7 +71,7 @@ func (c *NameServerConfig) Build() (*dns.NameServer, error) {
|
|||
})
|
||||
}
|
||||
|
||||
geoipList, err := toCidrList(c.ExpectIPs)
|
||||
geoipList, err := geoip.ParaseIPList(c.ExpectIPs)
|
||||
if err != nil {
|
||||
return nil, newError("invalid IP rule: ", c.ExpectIPs).Base(err)
|
||||
}
|
||||
|
@ -88,15 +90,15 @@ func (c *NameServerConfig) Build() (*dns.NameServer, error) {
|
|||
|
||||
// DNSConfig is a JSON serializable object for dns.Config.
|
||||
type DNSConfig struct {
|
||||
Servers []*NameServerConfig `json:"servers"`
|
||||
Hosts map[string]*Address `json:"hosts"`
|
||||
ClientIP *Address `json:"clientIp"`
|
||||
Tag string `json:"tag"`
|
||||
QueryStrategy string `json:"queryStrategy"`
|
||||
DisableCache bool `json:"disableCache"`
|
||||
Servers []*NameServerConfig `json:"servers"`
|
||||
Hosts map[string]*common.Address `json:"hosts"`
|
||||
ClientIP *common.Address `json:"clientIp"`
|
||||
Tag string `json:"tag"`
|
||||
QueryStrategy string `json:"queryStrategy"`
|
||||
DisableCache bool `json:"disableCache"`
|
||||
}
|
||||
|
||||
func getHostMapping(addr *Address) *dns.Config_HostMapping {
|
||||
func getHostMapping(addr *common.Address) *dns.Config_HostMapping {
|
||||
if addr.Family().IsIP() {
|
||||
return &dns.Config_HostMapping{
|
||||
Ip: [][]byte{[]byte(addr.IP())},
|
||||
|
|
|
@ -3,13 +3,14 @@ package conf
|
|||
import (
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/infra/conf/common"
|
||||
"github.com/xtls/xray-core/proxy/dns"
|
||||
)
|
||||
|
||||
type DNSOutboundConfig struct {
|
||||
Network Network `json:"network"`
|
||||
Address *Address `json:"address"`
|
||||
Port uint16 `json:"port"`
|
||||
Network common.Network `json:"network"`
|
||||
Address *common.Address `json:"address"`
|
||||
Port uint16 `json:"port"`
|
||||
}
|
||||
|
||||
func (c *DNSOutboundConfig) Build() (proto.Message, error) {
|
||||
|
|
|
@ -2,16 +2,17 @@ package conf
|
|||
|
||||
import (
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/xtls/xray-core/infra/conf/common"
|
||||
"github.com/xtls/xray-core/proxy/dokodemo"
|
||||
)
|
||||
|
||||
type DokodemoConfig struct {
|
||||
Host *Address `json:"address"`
|
||||
PortValue uint16 `json:"port"`
|
||||
NetworkList *NetworkList `json:"network"`
|
||||
TimeoutValue uint32 `json:"timeout"`
|
||||
Redirect bool `json:"followRedirect"`
|
||||
UserLevel uint32 `json:"userLevel"`
|
||||
Host *common.Address `json:"address"`
|
||||
PortValue uint16 `json:"port"`
|
||||
NetworkList *common.NetworkList `json:"network"`
|
||||
TimeoutValue uint32 `json:"timeout"`
|
||||
Redirect bool `json:"followRedirect"`
|
||||
UserLevel uint32 `json:"userLevel"`
|
||||
}
|
||||
|
||||
func (v *DokodemoConfig) Build() (proto.Message, error) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package conf
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/xtls/xray-core/infra/conf/common"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
|
@ -46,7 +47,7 @@ func (c *HTTPServerConfig) Build() (proto.Message, error) {
|
|||
}
|
||||
|
||||
type HTTPRemoteConfig struct {
|
||||
Address *Address `json:"address"`
|
||||
Address *common.Address `json:"address"`
|
||||
Port uint16 `json:"port"`
|
||||
Users []json.RawMessage `json:"users"`
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package conf
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/xtls/xray-core/infra/conf/common"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -10,7 +11,6 @@ import (
|
|||
"github.com/xtls/xray-core/common/matcher/geoip"
|
||||
"github.com/xtls/xray-core/common/matcher/geosite"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/platform/filesystem"
|
||||
)
|
||||
|
||||
type RouterRulesConfig struct {
|
||||
|
@ -19,8 +19,8 @@ type RouterRulesConfig struct {
|
|||
}
|
||||
|
||||
type BalancingRule struct {
|
||||
Tag string `json:"tag"`
|
||||
Selectors StringList `json:"selector"`
|
||||
Tag string `json:"tag"`
|
||||
Selectors common.StringList `json:"selector"`
|
||||
}
|
||||
|
||||
func (r *BalancingRule) Build() (*router.BalancingRule, error) {
|
||||
|
@ -148,108 +148,20 @@ func ParseIP(s string) (*geoip.CIDR, error) {
|
|||
}
|
||||
}
|
||||
|
||||
var (
|
||||
FileCache = make(map[string][]byte)
|
||||
IPCache = make(map[string]*geoip.GeoIP)
|
||||
)
|
||||
|
||||
func loadFile(file string) ([]byte, error) {
|
||||
if FileCache[file] == nil {
|
||||
bs, err := filesystem.ReadAsset(file)
|
||||
if err != nil {
|
||||
return nil, newError("failed to open file: ", file).Base(err)
|
||||
}
|
||||
if len(bs) == 0 {
|
||||
return nil, newError("empty file: ", file)
|
||||
}
|
||||
// Do not cache file, may save RAM when there
|
||||
// are many files, but consume CPU each time.
|
||||
return bs, nil
|
||||
FileCache[file] = bs
|
||||
}
|
||||
return FileCache[file], nil
|
||||
}
|
||||
|
||||
func toCidrList(ips StringList) ([]*geoip.GeoIP, error) {
|
||||
var geoipList []*geoip.GeoIP
|
||||
var customCidrs []*geoip.CIDR
|
||||
|
||||
for _, ip := range ips {
|
||||
if strings.HasPrefix(ip, "geoip:") {
|
||||
country := ip[6:]
|
||||
geoipc, err := geoip.LoadGeoIP(strings.ToUpper(country))
|
||||
if err != nil {
|
||||
return nil, newError("failed to load GeoIP: ", country).Base(err)
|
||||
}
|
||||
|
||||
geoipList = append(geoipList, &geoip.GeoIP{
|
||||
CountryCode: strings.ToUpper(country),
|
||||
Cidr: geoipc,
|
||||
})
|
||||
continue
|
||||
}
|
||||
var isExtDatFile = 0
|
||||
{
|
||||
const prefix = "ext:"
|
||||
if strings.HasPrefix(ip, prefix) {
|
||||
isExtDatFile = len(prefix)
|
||||
}
|
||||
const prefixQualified = "ext-ip:"
|
||||
if strings.HasPrefix(ip, prefixQualified) {
|
||||
isExtDatFile = len(prefixQualified)
|
||||
}
|
||||
}
|
||||
if isExtDatFile != 0 {
|
||||
kv := strings.Split(ip[isExtDatFile:], ":")
|
||||
if len(kv) != 2 {
|
||||
return nil, newError("invalid external resource: ", ip)
|
||||
}
|
||||
|
||||
filename := kv[0]
|
||||
country := kv[1]
|
||||
geoipc, err := geoip.LoadIPFile(filename, strings.ToUpper(country))
|
||||
if err != nil {
|
||||
return nil, newError("failed to load IPs: ", country, " from ", filename).Base(err)
|
||||
}
|
||||
|
||||
geoipList = append(geoipList, &geoip.GeoIP{
|
||||
CountryCode: strings.ToUpper(filename + "_" + country),
|
||||
Cidr: geoipc,
|
||||
})
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
ipRule, err := ParseIP(ip)
|
||||
if err != nil {
|
||||
return nil, newError("invalid IP: ", ip).Base(err)
|
||||
}
|
||||
customCidrs = append(customCidrs, ipRule)
|
||||
}
|
||||
|
||||
if len(customCidrs) > 0 {
|
||||
geoipList = append(geoipList, &geoip.GeoIP{
|
||||
Cidr: customCidrs,
|
||||
})
|
||||
}
|
||||
|
||||
return geoipList, nil
|
||||
}
|
||||
|
||||
func parseFieldRule(msg json.RawMessage) (*router.RoutingRule, error) {
|
||||
type RawFieldRule struct {
|
||||
RouterRule
|
||||
Domain *StringList `json:"domain"`
|
||||
Domains *StringList `json:"domains"`
|
||||
IP *StringList `json:"ip"`
|
||||
Port *PortList `json:"port"`
|
||||
Network *NetworkList `json:"network"`
|
||||
SourceIP *StringList `json:"source"`
|
||||
SourcePort *PortList `json:"sourcePort"`
|
||||
User *StringList `json:"user"`
|
||||
InboundTag *StringList `json:"inboundTag"`
|
||||
Protocols *StringList `json:"protocol"`
|
||||
Attributes string `json:"attrs"`
|
||||
Domain *common.StringList `json:"domain"`
|
||||
Domains *common.StringList `json:"domains"`
|
||||
IP *common.StringList `json:"ip"`
|
||||
Port *common.PortList `json:"port"`
|
||||
Network *common.NetworkList `json:"network"`
|
||||
SourceIP *common.StringList `json:"source"`
|
||||
SourcePort *common.PortList `json:"sourcePort"`
|
||||
User *common.StringList `json:"user"`
|
||||
InboundTag *common.StringList `json:"inboundTag"`
|
||||
Protocols *common.StringList `json:"protocol"`
|
||||
Attributes string `json:"attrs"`
|
||||
}
|
||||
rawFieldRule := new(RawFieldRule)
|
||||
err := json.Unmarshal(msg, rawFieldRule)
|
||||
|
@ -273,7 +185,7 @@ func parseFieldRule(msg json.RawMessage) (*router.RoutingRule, error) {
|
|||
|
||||
if rawFieldRule.Domain != nil {
|
||||
for _, domain := range *rawFieldRule.Domain {
|
||||
rules, err := conf.ParaseDomainRule(domain)
|
||||
rules, err := conf.ParseDomainRule(domain)
|
||||
if err != nil {
|
||||
return nil, newError("failed to parse domain rule: ", domain).Base(err)
|
||||
}
|
||||
|
@ -283,7 +195,7 @@ func parseFieldRule(msg json.RawMessage) (*router.RoutingRule, error) {
|
|||
|
||||
if rawFieldRule.Domains != nil {
|
||||
for _, domain := range *rawFieldRule.Domains {
|
||||
rules, err := conf.ParaseDomainRule(domain)
|
||||
rules, err := conf.ParseDomainRule(domain)
|
||||
if err != nil {
|
||||
return nil, newError("failed to parse domain rule: ", domain).Base(err)
|
||||
}
|
||||
|
@ -292,7 +204,7 @@ func parseFieldRule(msg json.RawMessage) (*router.RoutingRule, error) {
|
|||
}
|
||||
|
||||
if rawFieldRule.IP != nil {
|
||||
geoipList, err := toCidrList(*rawFieldRule.IP)
|
||||
geoipList, err := geoip.ParaseIPList(*rawFieldRule.IP)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -308,7 +220,7 @@ func parseFieldRule(msg json.RawMessage) (*router.RoutingRule, error) {
|
|||
}
|
||||
|
||||
if rawFieldRule.SourceIP != nil {
|
||||
geoipList, err := toCidrList(*rawFieldRule.SourceIP)
|
||||
geoipList, err := geoip.ParaseIPList(*rawFieldRule.SourceIP)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package conf
|
||||
|
||||
import (
|
||||
"github.com/xtls/xray-core/infra/conf/common"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
@ -46,7 +47,7 @@ type ShadowsocksServerConfig struct {
|
|||
Level byte `json:"level"`
|
||||
Email string `json:"email"`
|
||||
Users []*ShadowsocksUserConfig `json:"clients"`
|
||||
NetworkList *NetworkList `json:"network"`
|
||||
NetworkList *common.NetworkList `json:"network"`
|
||||
}
|
||||
|
||||
func (v *ShadowsocksServerConfig) Build() (proto.Message, error) {
|
||||
|
@ -93,12 +94,12 @@ func (v *ShadowsocksServerConfig) Build() (proto.Message, error) {
|
|||
}
|
||||
|
||||
type ShadowsocksServerTarget struct {
|
||||
Address *Address `json:"address"`
|
||||
Port uint16 `json:"port"`
|
||||
Cipher string `json:"method"`
|
||||
Password string `json:"password"`
|
||||
Email string `json:"email"`
|
||||
Level byte `json:"level"`
|
||||
Address *common.Address `json:"address"`
|
||||
Port uint16 `json:"port"`
|
||||
Cipher string `json:"method"`
|
||||
Password string `json:"password"`
|
||||
Email string `json:"email"`
|
||||
Level byte `json:"level"`
|
||||
}
|
||||
|
||||
type ShadowsocksClientConfig struct {
|
||||
|
|
|
@ -2,6 +2,7 @@ package conf
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/xtls/xray-core/infra/conf/common"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
|
@ -30,7 +31,7 @@ type SocksServerConfig struct {
|
|||
AuthMethod string `json:"auth"`
|
||||
Accounts []*SocksAccount `json:"accounts"`
|
||||
UDP bool `json:"udp"`
|
||||
Host *Address `json:"ip"`
|
||||
Host *common.Address `json:"ip"`
|
||||
Timeout uint32 `json:"timeout"`
|
||||
UserLevel uint32 `json:"userLevel"`
|
||||
}
|
||||
|
@ -65,7 +66,7 @@ func (v *SocksServerConfig) Build() (proto.Message, error) {
|
|||
}
|
||||
|
||||
type SocksRemoteConfig struct {
|
||||
Address *Address `json:"address"`
|
||||
Address *common.Address `json:"address"`
|
||||
Port uint16 `json:"port"`
|
||||
Users []json.RawMessage `json:"users"`
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package conf
|
||||
|
||||
import (
|
||||
"github.com/xtls/xray-core/infra/conf/common"
|
||||
"sort"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
@ -57,13 +58,13 @@ func (DTLSAuthenticator) Build() (proto.Message, error) {
|
|||
}
|
||||
|
||||
type AuthenticatorRequest struct {
|
||||
Version string `json:"version"`
|
||||
Method string `json:"method"`
|
||||
Path StringList `json:"path"`
|
||||
Headers map[string]*StringList `json:"headers"`
|
||||
Version string `json:"version"`
|
||||
Method string `json:"method"`
|
||||
Path common.StringList `json:"path"`
|
||||
Headers map[string]*common.StringList `json:"headers"`
|
||||
}
|
||||
|
||||
func sortMapKeys(m map[string]*StringList) []string {
|
||||
func sortMapKeys(m map[string]*common.StringList) []string {
|
||||
var keys []string
|
||||
for key := range m {
|
||||
keys = append(keys, key)
|
||||
|
@ -133,10 +134,10 @@ func (v *AuthenticatorRequest) Build() (*http.RequestConfig, error) {
|
|||
}
|
||||
|
||||
type AuthenticatorResponse struct {
|
||||
Version string `json:"version"`
|
||||
Status string `json:"status"`
|
||||
Reason string `json:"reason"`
|
||||
Headers map[string]*StringList `json:"headers"`
|
||||
Version string `json:"version"`
|
||||
Status string `json:"status"`
|
||||
Reason string `json:"reason"`
|
||||
Headers map[string]*common.StringList `json:"headers"`
|
||||
}
|
||||
|
||||
func (v *AuthenticatorResponse) Build() (*http.ResponseConfig, error) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package conf
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/xtls/xray-core/infra/conf/common"
|
||||
"math"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
@ -179,8 +180,8 @@ func (c *WebSocketConfig) Build() (proto.Message, error) {
|
|||
}
|
||||
|
||||
type HTTPConfig struct {
|
||||
Host *StringList `json:"host"`
|
||||
Path string `json:"path"`
|
||||
Host *common.StringList `json:"host"`
|
||||
Path string `json:"path"`
|
||||
}
|
||||
|
||||
// Build implements Buildable.
|
||||
|
@ -311,16 +312,16 @@ func (c *TLSCertConfig) Build() (*tls.Certificate, error) {
|
|||
}
|
||||
|
||||
type TLSConfig struct {
|
||||
Insecure bool `json:"allowInsecure"`
|
||||
Certs []*TLSCertConfig `json:"certificates"`
|
||||
ServerName string `json:"serverName"`
|
||||
ALPN *StringList `json:"alpn"`
|
||||
EnableSessionResumption bool `json:"enableSessionResumption"`
|
||||
DisableSystemRoot bool `json:"disableSystemRoot"`
|
||||
MinVersion string `json:"minVersion"`
|
||||
MaxVersion string `json:"maxVersion"`
|
||||
CipherSuites string `json:"cipherSuites"`
|
||||
PreferServerCipherSuites bool `json:"preferServerCipherSuites"`
|
||||
Insecure bool `json:"allowInsecure"`
|
||||
Certs []*TLSCertConfig `json:"certificates"`
|
||||
ServerName string `json:"serverName"`
|
||||
ALPN *common.StringList `json:"alpn"`
|
||||
EnableSessionResumption bool `json:"enableSessionResumption"`
|
||||
DisableSystemRoot bool `json:"disableSystemRoot"`
|
||||
MinVersion string `json:"minVersion"`
|
||||
MaxVersion string `json:"maxVersion"`
|
||||
CipherSuites string `json:"cipherSuites"`
|
||||
PreferServerCipherSuites bool `json:"preferServerCipherSuites"`
|
||||
}
|
||||
|
||||
// Build implements Buildable.
|
||||
|
@ -401,16 +402,16 @@ func (c *XTLSCertConfig) Build() (*xtls.Certificate, error) {
|
|||
}
|
||||
|
||||
type XTLSConfig struct {
|
||||
Insecure bool `json:"allowInsecure"`
|
||||
Certs []*XTLSCertConfig `json:"certificates"`
|
||||
ServerName string `json:"serverName"`
|
||||
ALPN *StringList `json:"alpn"`
|
||||
EnableSessionResumption bool `json:"enableSessionResumption"`
|
||||
DisableSystemRoot bool `json:"disableSystemRoot"`
|
||||
MinVersion string `json:"minVersion"`
|
||||
MaxVersion string `json:"maxVersion"`
|
||||
CipherSuites string `json:"cipherSuites"`
|
||||
PreferServerCipherSuites bool `json:"preferServerCipherSuites"`
|
||||
Insecure bool `json:"allowInsecure"`
|
||||
Certs []*XTLSCertConfig `json:"certificates"`
|
||||
ServerName string `json:"serverName"`
|
||||
ALPN *common.StringList `json:"alpn"`
|
||||
EnableSessionResumption bool `json:"enableSessionResumption"`
|
||||
DisableSystemRoot bool `json:"disableSystemRoot"`
|
||||
MinVersion string `json:"minVersion"`
|
||||
MaxVersion string `json:"maxVersion"`
|
||||
CipherSuites string `json:"cipherSuites"`
|
||||
PreferServerCipherSuites bool `json:"preferServerCipherSuites"`
|
||||
}
|
||||
|
||||
// Build implements Buildable.
|
||||
|
|
|
@ -2,6 +2,7 @@ package conf
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/xtls/xray-core/infra/conf/common"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
@ -16,12 +17,12 @@ import (
|
|||
|
||||
// TrojanServerTarget is configuration of a single trojan server
|
||||
type TrojanServerTarget struct {
|
||||
Address *Address `json:"address"`
|
||||
Port uint16 `json:"port"`
|
||||
Password string `json:"password"`
|
||||
Email string `json:"email"`
|
||||
Level byte `json:"level"`
|
||||
Flow string `json:"flow"`
|
||||
Address *common.Address `json:"address"`
|
||||
Port uint16 `json:"port"`
|
||||
Password string `json:"password"`
|
||||
Email string `json:"email"`
|
||||
Level byte `json:"level"`
|
||||
Flow string `json:"flow"`
|
||||
}
|
||||
|
||||
// TrojanClientConfig is configuration of trojan servers
|
||||
|
|
|
@ -2,6 +2,7 @@ package conf
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/xtls/xray-core/infra/conf/common"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
@ -137,7 +138,7 @@ func (c *VLessInboundConfig) Build() (proto.Message, error) {
|
|||
}
|
||||
|
||||
type VLessOutboundVnext struct {
|
||||
Address *Address `json:"address"`
|
||||
Address *common.Address `json:"address"`
|
||||
Port uint16 `json:"port"`
|
||||
Users []json.RawMessage `json:"users"`
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package conf
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/xtls/xray-core/infra/conf/common"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
@ -123,7 +124,7 @@ func (c *VMessInboundConfig) Build() (proto.Message, error) {
|
|||
}
|
||||
|
||||
type VMessOutboundTarget struct {
|
||||
Address *Address `json:"address"`
|
||||
Address *common.Address `json:"address"`
|
||||
Port uint16 `json:"port"`
|
||||
Users []json.RawMessage `json:"users"`
|
||||
}
|
||||
|
|
|
@ -2,6 +2,10 @@ package conf
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/xtls/xray-core/common/matcher/domain"
|
||||
"github.com/xtls/xray-core/common/matcher/domain/conf"
|
||||
"github.com/xtls/xray-core/common/matcher/geoip"
|
||||
"github.com/xtls/xray-core/infra/conf/common"
|
||||
"github.com/xtls/xray-core/transport/internet"
|
||||
"log"
|
||||
"os"
|
||||
|
@ -59,10 +63,11 @@ func toProtocolList(s []string) ([]proxyman.KnownProtocols, error) {
|
|||
}
|
||||
|
||||
type SniffingConfig struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
DestOverride *StringList `json:"destOverride"`
|
||||
DomainsExcluded *StringList `json:"domainsExcluded"`
|
||||
MetadataOnly bool `json:"metadataOnly"`
|
||||
Enabled bool `json:"enabled"`
|
||||
DestOverride *common.StringList `json:"destOverride"`
|
||||
DomainsExcluded *common.StringList `json:"domainsExcluded"`
|
||||
IPsExcluded *common.StringList `json:"ipsExcluded"`
|
||||
MetadataOnly bool `json:"metadataOnly"`
|
||||
}
|
||||
|
||||
// Build implements Buildable.
|
||||
|
@ -83,17 +88,31 @@ func (c *SniffingConfig) Build() (*proxyman.SniffingConfig, error) {
|
|||
}
|
||||
}
|
||||
|
||||
var d []string
|
||||
var exDomain []*domain.Domain
|
||||
if c.DomainsExcluded != nil {
|
||||
for _, domain := range *c.DomainsExcluded {
|
||||
d = append(d, strings.ToLower(domain))
|
||||
for _, dmr := range *c.DomainsExcluded {
|
||||
if dm, err := conf.ParseDomainRule(dmr); err == nil {
|
||||
exDomain = append(exDomain, dm...)
|
||||
} else {
|
||||
return nil, newError("failed to parse excluded domain").Base(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var exIP []*geoip.GeoIP
|
||||
if c.IPsExcluded != nil {
|
||||
exip, err := geoip.ParaseIPList(*c.IPsExcluded)
|
||||
if err != nil {
|
||||
return nil, newError("failed to parse excluded ip").Base(err)
|
||||
}
|
||||
exIP = exip
|
||||
}
|
||||
|
||||
return &proxyman.SniffingConfig{
|
||||
Enabled: c.Enabled,
|
||||
DestinationOverride: p,
|
||||
DomainsExcluded: d,
|
||||
DomainsExcluded: exDomain,
|
||||
IpsExcluded: exIP,
|
||||
MetadataOnly: c.MetadataOnly,
|
||||
}, nil
|
||||
}
|
||||
|
@ -156,13 +175,13 @@ func (c *InboundDetourAllocationConfig) Build() (*proxyman.AllocationStrategy, e
|
|||
|
||||
type InboundDetourConfig struct {
|
||||
Protocol string `json:"protocol"`
|
||||
PortRange *PortRange `json:"port"`
|
||||
ListenOn *Address `json:"listen"`
|
||||
PortRange *common.PortRange `json:"port"`
|
||||
ListenOn *common.Address `json:"listen"`
|
||||
Settings *json.RawMessage `json:"settings"`
|
||||
Tag string `json:"tag"`
|
||||
Allocation *InboundDetourAllocationConfig `json:"allocate"`
|
||||
StreamSetting *StreamConfig `json:"streamSettings"`
|
||||
DomainOverride *StringList `json:"domainOverride"`
|
||||
DomainOverride *common.StringList `json:"domainOverride"`
|
||||
SniffingConfig *SniffingConfig `json:"sniffing"`
|
||||
}
|
||||
|
||||
|
@ -264,7 +283,7 @@ func (c *InboundDetourConfig) Build() (*core.InboundHandlerConfig, error) {
|
|||
|
||||
type OutboundDetourConfig struct {
|
||||
Protocol string `json:"protocol"`
|
||||
SendThrough *Address `json:"sendThrough"`
|
||||
SendThrough *common.Address `json:"sendThrough"`
|
||||
Tag string `json:"tag"`
|
||||
Settings *json.RawMessage `json:"settings"`
|
||||
StreamSetting *StreamConfig `json:"streamSettings"`
|
||||
|
@ -622,7 +641,7 @@ func (c *Config) Build() (*core.Config, error) {
|
|||
|
||||
// Backward compatibility.
|
||||
if len(inbounds) > 0 && inbounds[0].PortRange == nil && c.Port > 0 {
|
||||
inbounds[0].PortRange = &PortRange{
|
||||
inbounds[0].PortRange = &common.PortRange{
|
||||
From: uint32(c.Port),
|
||||
To: uint32(c.Port),
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package conf_test
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/xtls/xray-core/common/matcher/domain"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
|
@ -372,6 +373,52 @@ func TestMuxConfig_Build(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSniffingConfig_Build(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
fields string
|
||||
want *proxyman.SniffingConfig
|
||||
}{
|
||||
{"default", `
|
||||
{
|
||||
"enabled": true,
|
||||
"destOverride": ["tls"],
|
||||
"domainsExcluded": ["domain:google.com"],
|
||||
"ipsExcluded": ["8.8.8.8"]
|
||||
}`, &proxyman.SniffingConfig{
|
||||
Enabled: true,
|
||||
DestinationOverride: []string{"tls"},
|
||||
DomainsExcluded: []*domain.Domain{
|
||||
{
|
||||
Type: domain.MatchingType_Subdomain,
|
||||
Value: "google.com",
|
||||
},
|
||||
},
|
||||
IpsExcluded: []*geoip.GeoIP{
|
||||
{
|
||||
Cidr: []*geoip.CIDR{{Ip: []byte{8, 8, 8, 8}, Prefix: 32}},
|
||||
},
|
||||
},
|
||||
}},
|
||||
{"empty def", `{}`, &proxyman.SniffingConfig{
|
||||
Enabled: false,
|
||||
}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &SniffingConfig{}
|
||||
common.Must(json.Unmarshal([]byte(tt.fields), m))
|
||||
got, err := m.Build()
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("SniffingConfig.Build() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfig_Override(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue